-
-
Notifications
You must be signed in to change notification settings - Fork 284
/
Copy pathLanguageConfiguration.fs
75 lines (58 loc) · 2.75 KB
/
LanguageConfiguration.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
namespace Ionide.VSCode.FSharp
open Fable.Core.JsInterop
open Fable.Import.VSCode.Vscode
open System.Text.RegularExpressions
module LanguageConfiguration =
let mutable private reference: Disposable option = None
let indentationRules =
jsOptions<IndentationRule> (fun o ->
o.increaseIndentPattern <-
Regex(
"""^(\s*(module|type|let|static member|member)\b.*=\s*)$|^(\s*(with get|and set)\b.*=.*)$|^(\s*(if|elif|then|else|static member|member)).*$"""
)
o.decreaseIndentPattern <- Regex("""^(\s*(else|elif|and)).*$"""))
let setLanguageConfiguration (triggerNotification: bool) =
// Config always setted
let config =
jsOptions<LanguageConfiguration> (fun o ->
o.onEnterRules <-
Some
<| ResizeArray<OnEnterRule>(
[|
// Doc single-line comment
// Example: ///
jsOptions<OnEnterRule> (fun rule ->
rule.action <-
jsOptions<EnterAction> (fun action ->
action.indentAction <- IndentAction.None
action.appendText <- Some "/// ")
rule.beforeText <- Regex("^\s*\/{3}.*$"))
|]
))
let activateSmartIndent = "FSharp.smartIndent" |> Configuration.get false
if activateSmartIndent then
config.indentationRules <- Some indentationRules
match reference with
| Some oldReference ->
// Disable previous language configuration if there was one
oldReference.dispose () |> ignore
| None -> ()
let disp = languages.setLanguageConfiguration ("fsharp", config)
reference <- Some disp
// Notify the user if needed
if triggerNotification then
let msg =
if activateSmartIndent then
"Smart indent has been activated for F#"
else
"Smart indent has been deactivated for F#"
window.showInformationMessage (msg) |> ignore
let onDidChangeConfiguration (ev: ConfigurationChangeEvent) =
let triggerNotification = ev.affectsConfiguration ("FSharp.smartIndent")
setLanguageConfiguration triggerNotification
let activate (context: ExtensionContext) =
// We listen for config change so we can update on the fly the language configuration
workspace.onDidChangeConfiguration
$ (onDidChangeConfiguration, (), context.subscriptions)
|> ignore
setLanguageConfiguration false