Skip to content

Commit 5edad17

Browse files
authored
make inlayhint confg changes at the user-levelif no workspace is available (#2033)
1 parent a85ea31 commit 5edad17

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

src/Components/InlayHints.fs

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ let private logger =
1111
let mutable private toggleSupported = false
1212

1313
module Config =
14-
let enabled = "FSharp.inlayHints.enabled"
1514
let typeAnnotationsEnabled = "FSharp.inlayHints.typeAnnotations"
1615
let parameterNamesEnabled = "FSharp.inlayHints.parameterNames"
1716
let disableLongTooltip = "FSharp.inlayHints.disableLongTooltip"
@@ -31,37 +30,73 @@ let supportsToggle (vscodeVersion: string) =
3130
// toggle was introduced in 1.67.0, so any version of that should allow us to set the toggle
3231
Semver.semver.gte (U2.Case1 vscodeVersion, U2.Case1 "1.67.0", U2.Case2 compareOptions)
3332

33+
let setLocalOrGlobalConfiguration configKey configValue =
34+
if isUndefined workspace.workspaceFolders then
35+
// do the config update at the user-level since no workspace is open
36+
Configuration.setGlobal configKey configValue |> box |> Some
37+
else
38+
// do the config update at the workspace level
39+
Configuration.set configKey configValue |> box |> Some
40+
41+
let setLocalOrGlobalConfigurationForFSharpLanguage configKey configValue =
42+
if isUndefined workspace.workspaceFolders then
43+
// do the config update at the user-level since no workspace is open
44+
Configuration.setForFsharpLanguageOnly configKey configValue ConfigurationTarget.Global
45+
|> box
46+
|> Some
47+
else
48+
// do the config update at the workspace level
49+
Configuration.setForFsharpLanguageOnly configKey configValue ConfigurationTarget.Workspace
50+
|> box
51+
|> Some
52+
53+
3454
let activate (context: ExtensionContext) =
3555
toggleSupported <- supportsToggle vscode.version
3656

3757
commands.registerCommand (
3858
Commands.disableLongTooltip,
39-
(fun _ -> Configuration.set Config.disableLongTooltip (Some true) |> box |> Some)
59+
(fun _ ->
60+
setLocalOrGlobalConfiguration Config.disableLongTooltip (Some true)
61+
|> box
62+
|> Some)
4063
)
4164
|> context.Subscribe
4265

4366
if toggleSupported then
4467
commands.registerCommand (
4568
Commands.setToToggle,
4669
(fun _ ->
47-
Configuration.set Config.editorInlayHintsEnabled (Some "offUnlessPressed")
70+
setLocalOrGlobalConfiguration Config.editorInlayHintsEnabled (Some "offUnlessPressed")
4871
|> box
4972
|> Some)
5073
)
5174
|> context.Subscribe
5275

53-
commands.registerCommand (Commands.hideAll, (fun _ -> Configuration.set Config.enabled (Some false) |> box |> Some))
76+
commands.registerCommand (
77+
Commands.hideAll,
78+
(fun _ ->
79+
setLocalOrGlobalConfigurationForFSharpLanguage Config.editorInlayHintsEnabled (Some "off")
80+
|> box
81+
|> Some)
82+
)
5483
|> context.Subscribe
5584

5685
commands.registerCommand (
5786
Commands.hideParameterNames,
58-
(fun _ -> Configuration.set Config.parameterNamesEnabled (Some false) |> box |> Some)
87+
(fun _ ->
88+
setLocalOrGlobalConfiguration Config.parameterNamesEnabled (Some false)
89+
|> box
90+
|> Some)
5991
)
6092
|> context.Subscribe
6193

6294
commands.registerCommand (
6395
Commands.hideTypeAnnotations,
64-
(fun _ -> Configuration.set Config.typeAnnotationsEnabled (Some false) |> box |> Some)
96+
(fun _ ->
97+
setLocalOrGlobalConfiguration Config.typeAnnotationsEnabled (Some false)
98+
|> box
99+
|> Some)
65100
)
66101
|> context.Subscribe
67102

src/Core/Utils.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ module Configuration =
163163
.getConfiguration()
164164
.update (key, value, configurationTarget = U2.Case1 ConfigurationTarget.Global)
165165

166+
let setForFsharpLanguageOnly key value target =
167+
workspace
168+
.getConfiguration(scope = ConfigurationScope.Case4 {| languageId = "fsharp"; uri = None |})
169+
.update (key, value, configurationTarget = U2.Case1 target, overrideInLanguage = true)
170+
166171
[<AutoOpen>]
167172
module Utils =
168173
open Fable.Core

0 commit comments

Comments
 (0)