Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make inlayhint config changes at the user-level if no workspace is available #2033

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading