Skip to content

Commit

Permalink
make inlayhint confg changes at the user-levelif no workspace is avai…
Browse files Browse the repository at this point in the history
…lable (#2033)
  • Loading branch information
baronfel authored Aug 19, 2024
1 parent a85ea31 commit 5edad17
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
47 changes: 41 additions & 6 deletions src/Components/InlayHints.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ let private logger =
let mutable private toggleSupported = false

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

let setLocalOrGlobalConfiguration configKey configValue =
if isUndefined workspace.workspaceFolders then
// do the config update at the user-level since no workspace is open
Configuration.setGlobal configKey configValue |> box |> Some
else
// do the config update at the workspace level
Configuration.set configKey configValue |> box |> Some

let setLocalOrGlobalConfigurationForFSharpLanguage configKey configValue =
if isUndefined workspace.workspaceFolders then
// do the config update at the user-level since no workspace is open
Configuration.setForFsharpLanguageOnly configKey configValue ConfigurationTarget.Global
|> box
|> Some
else
// do the config update at the workspace level
Configuration.setForFsharpLanguageOnly configKey configValue ConfigurationTarget.Workspace
|> box
|> Some


let activate (context: ExtensionContext) =
toggleSupported <- supportsToggle vscode.version

commands.registerCommand (
Commands.disableLongTooltip,
(fun _ -> Configuration.set Config.disableLongTooltip (Some true) |> box |> Some)
(fun _ ->
setLocalOrGlobalConfiguration Config.disableLongTooltip (Some true)
|> box
|> Some)
)
|> context.Subscribe

if toggleSupported then
commands.registerCommand (
Commands.setToToggle,
(fun _ ->
Configuration.set Config.editorInlayHintsEnabled (Some "offUnlessPressed")
setLocalOrGlobalConfiguration Config.editorInlayHintsEnabled (Some "offUnlessPressed")
|> box
|> Some)
)
|> context.Subscribe

commands.registerCommand (Commands.hideAll, (fun _ -> Configuration.set Config.enabled (Some false) |> box |> Some))
commands.registerCommand (
Commands.hideAll,
(fun _ ->
setLocalOrGlobalConfigurationForFSharpLanguage Config.editorInlayHintsEnabled (Some "off")
|> box
|> Some)
)
|> context.Subscribe

commands.registerCommand (
Commands.hideParameterNames,
(fun _ -> Configuration.set Config.parameterNamesEnabled (Some false) |> box |> Some)
(fun _ ->
setLocalOrGlobalConfiguration Config.parameterNamesEnabled (Some false)
|> box
|> Some)
)
|> context.Subscribe

commands.registerCommand (
Commands.hideTypeAnnotations,
(fun _ -> Configuration.set Config.typeAnnotationsEnabled (Some false) |> box |> Some)
(fun _ ->
setLocalOrGlobalConfiguration Config.typeAnnotationsEnabled (Some false)
|> box
|> Some)
)
|> context.Subscribe

Expand Down
5 changes: 5 additions & 0 deletions src/Core/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ module Configuration =
.getConfiguration()
.update (key, value, configurationTarget = U2.Case1 ConfigurationTarget.Global)

let setForFsharpLanguageOnly key value target =
workspace
.getConfiguration(scope = ConfigurationScope.Case4 {| languageId = "fsharp"; uri = None |})
.update (key, value, configurationTarget = U2.Case1 target, overrideInLanguage = true)

[<AutoOpen>]
module Utils =
open Fable.Core
Expand Down

0 comments on commit 5edad17

Please sign in to comment.