From 8a851bf72de0f823f5635d2340611ce066809aa1 Mon Sep 17 00:00:00 2001 From: sheridanchris Date: Thu, 5 Oct 2023 05:20:32 -0500 Subject: [PATCH 1/2] Add command to restart language service --- release/package.json | 9 +++++++++ src/Core/LanguageService.fs | 11 +++++++++++ src/fsharp.fs | 1 + 3 files changed, 21 insertions(+) diff --git a/release/package.json b/release/package.json index 36b1a27f..79a1e2e5 100644 --- a/release/package.json +++ b/release/package.json @@ -408,6 +408,11 @@ "light": "./images/lock-open-solid-light.svg" }, "title": "Unlock Info Panel" + }, + { + "category": "F#", + "command": "fsharp.restartLanguageService", + "title": "Restart Language Service" } ], "configuration": { @@ -1231,6 +1236,10 @@ { "command": "fsharp.showDocumentation", "when": "false" + }, + { + "command": "fsharp.restartLanguageService", + "when": "editorLangId == \u0027fsharp\u0027" } ], "editor/context": [ diff --git a/src/Core/LanguageService.fs b/src/Core/LanguageService.fs index 67eb27e4..05e01f31 100644 --- a/src/Core/LanguageService.fs +++ b/src/Core/LanguageService.fs @@ -1004,3 +1004,14 @@ Consider: | Some cl -> return! cl.stop () | None -> return () } + + let activate (context: ExtensionContext) = + let restart () = + promise { + logger.Debug("Restarting F# langugae service") + do! stop () + do! start context + } + + commands.registerCommand ("fsharp.restartLanguageService", restart |> objfy2) + |> context.Subscribe diff --git a/src/fsharp.fs b/src/fsharp.fs index f0117aef..3102c97d 100644 --- a/src/fsharp.fs +++ b/src/fsharp.fs @@ -93,6 +93,7 @@ let activate (context: ExtensionContext) : JS.Promise = tryActivate "pipelinehints" PipelineHints.Instance.activate context tryActivate "testExplorer" TestExplorer.activate context tryActivate "inlayhints" InlayHints.activate context + tryActivate "languageservice" LanguageService.activate context let buildProject project = promise { From dd7adc237058af1693afadddf79806a20428c649 Mon Sep 17 00:00:00 2001 From: sheridanchris Date: Thu, 5 Oct 2023 15:28:40 -0500 Subject: [PATCH 2/2] Init workspace when language service restarts --- src/Core/LanguageService.fs | 11 ----------- src/fsharp.fs | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Core/LanguageService.fs b/src/Core/LanguageService.fs index 05e01f31..67eb27e4 100644 --- a/src/Core/LanguageService.fs +++ b/src/Core/LanguageService.fs @@ -1004,14 +1004,3 @@ Consider: | Some cl -> return! cl.stop () | None -> return () } - - let activate (context: ExtensionContext) = - let restart () = - promise { - logger.Debug("Restarting F# langugae service") - do! stop () - do! start context - } - - commands.registerCommand ("fsharp.restartLanguageService", restart |> objfy2) - |> context.Subscribe diff --git a/src/fsharp.fs b/src/fsharp.fs index 3102c97d..1d01d7e0 100644 --- a/src/fsharp.fs +++ b/src/fsharp.fs @@ -20,6 +20,19 @@ type Api = GetProjectLauncher: OutputChannel -> DTO.Project -> (string list -> JS.Promise) option DebugProject: DTO.Project -> string[] -> JS.Promise } + +let private activateLanguageServiceRestart (context: ExtensionContext) = + let restart () = + promise { + logger.Debug("Restarting F# language service") + do! LanguageService.stop () + do! LanguageService.start context + do! Project.initWorkspace () + } + + commands.registerCommand ("fsharp.restartLanguageService", restart |> objfy2) + |> context.Subscribe + let activate (context: ExtensionContext) : JS.Promise = let solutionExplorer = "FSharp.enableTreeView" |> Configuration.get true @@ -93,7 +106,7 @@ let activate (context: ExtensionContext) : JS.Promise = tryActivate "pipelinehints" PipelineHints.Instance.activate context tryActivate "testExplorer" TestExplorer.activate context tryActivate "inlayhints" InlayHints.activate context - tryActivate "languageservice" LanguageService.activate context + tryActivate "languageservice" activateLanguageServiceRestart context let buildProject project = promise {