From cdbb7712224472c7554b46e2b64bd87e016f5f91 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Sat, 29 Jul 2023 13:15:17 -0500 Subject: [PATCH 01/14] first pass at detecting csharp --- release/package.json | 74 +++++++------- src/Components/CSharpExtensionSupport.fs | 34 +++++++ src/Components/Debugger.fs | 34 ++++--- src/Components/MSBuild.fs | 120 ++++++++++++----------- src/Ionide.FSharp.fsproj | 1 + 5 files changed, 157 insertions(+), 106 deletions(-) create mode 100644 src/Components/CSharpExtensionSupport.fs diff --git a/release/package.json b/release/package.json index 5ee8b254..ee475dd1 100644 --- a/release/package.json +++ b/release/package.json @@ -155,43 +155,53 @@ }, { "command": "MSBuild.buildCurrent", - "title": "MSBuild: Build current project" + "title": "MSBuild: Build current project", + "when": "fsharp.debuggerAvailable" }, { "command": "MSBuild.buildSelected", - "title": "MSBuild: Build project" + "title": "MSBuild: Build project", + "when": "fsharp.debuggerAvailable" }, { "command": "MSBuild.rebuildCurrent", - "title": "MSBuild: Rebuild current project" + "title": "MSBuild: Rebuild current project", + "when": "fsharp.debuggerAvailable" }, { "command": "MSBuild.rebuildSelected", - "title": "MSBuild: Rebuild project" + "title": "MSBuild: Rebuild project", + "when": "fsharp.debuggerAvailable" }, { "command": "MSBuild.cleanCurrent", - "title": "MSBuild: Clean current project" + "title": "MSBuild: Clean current project", + "when": "fsharp.debuggerAvailable" }, { "command": "MSBuild.cleanSelected", - "title": "MSBuild: Clean project" + "title": "MSBuild: Clean project", + "when": "fsharp.debuggerAvailable" }, { "command": "MSBuild.restoreSelected", - "title": "MSBuild: Restore project" + "title": "MSBuild: Restore project", + "when": "fsharp.debuggerAvailable" }, { "command": "MSBuild.buildCurrentSolution", - "title": "MSBuild: Build current solution" + "title": "MSBuild: Build current solution", + "when": "fsharp.debuggerAvailable" }, { "command": "MSBuild.rebuildCurrentSolution", - "title": "MSBuild: Rebuild current solution" + "title": "MSBuild: Rebuild current solution", + "when": "fsharp.debuggerAvailable" }, { "command": "MSBuild.cleanCurrentSolution", - "title": "MSBuild: Clean current solution" + "title": "MSBuild: Clean current solution", + "when": "fsharp.debuggerAvailable" }, { "command": "fsharp.explorer.moveUp", @@ -968,12 +978,12 @@ { "command": "MSBuild.buildCurrent", "key": "ctrl\u002Balt\u002Bb", - "when": "fsharp.project.any \u0026\u0026 editorFocus \u0026\u0026 editorLangId == \u0027fsharp\u0027" + "when": "fsharp.project.any \u0026\u0026 editorFocus \u0026\u0026 editorLangId == \u0027fsharp\u0027 && fsharp.debuggerAvailable" }, { "command": "MSBuild.buildCurrentSolution", "key": "ctrl\u002Balt\u002Bshift\u002Bb", - "when": "fsharp.project.any" + "when": "fsharp.project.any && fsharp.debuggerAvailable" }, { "command": "fsharp.openInfoPanel", @@ -1165,15 +1175,15 @@ }, { "command": "MSBuild.buildCurrent", - "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027" + "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 && fsharp.debuggerAvailable" }, { "command": "MSBuild.rebuildCurrent", - "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027" + "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 && fsharp.debuggerAvailable" }, { "command": "MSBuild.cleanCurrent", - "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027" + "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 && fsharp.debuggerAvailable" }, { "command": "fsharp.clearCache", @@ -1181,43 +1191,43 @@ }, { "command": "MSBuild.buildSelected", - "when": "fsharp.project.any" + "when": "fsharp.project.any && fsharp.debuggerAvailable" }, { "command": "MSBuild.rebuildSelected", - "when": "fsharp.project.any" + "when": "fsharp.project.any && fsharp.debuggerAvailable" }, { "command": "MSBuild.cleanSelected", - "when": "fsharp.project.any" + "when": "fsharp.project.any && fsharp.debuggerAvailable" }, { "command": "MSBuild.restoreSelected", - "when": "fsharp.project.any" + "when": "fsharp.project.any && fsharp.debuggerAvailable" }, { "command": "MSBuild.buildCurrentSolution", - "when": "fsharp.project.any" + "when": "fsharp.project.any && fsharp.debuggerAvailable" }, { "command": "MSBuild.rebuildCurrentSolution", - "when": "fsharp.project.any" + "when": "fsharp.project.any && fsharp.debuggerAvailable" }, { "command": "MSBuild.cleanCurrentSolution", - "when": "fsharp.project.any" + "when": "fsharp.project.any && fsharp.debuggerAvailable" }, { "command": "fsharp.runDefaultProject", - "when": "fsharp.project.any" + "when": "fsharp.project.any && fsharp.debuggerAvailable" }, { "command": "fsharp.debugDefaultProject", - "when": "fsharp.project.any" + "when": "fsharp.project.any && fsharp.debuggerAvailable" }, { "command": "fsharp.chooseDefaultProject", - "when": "fsharp.project.any" + "when": "fsharp.project.any && fsharp.debuggerAvailable" }, { "command": "fsharp.NewProject", @@ -1261,12 +1271,12 @@ { "command": "fsharp.debugDefaultProject", "group": "fsharp", - "when": "fsharp.project.any \u0026\u0026 config.FSharp.enableTouchBar" + "when": "fsharp.project.any \u0026\u0026 config.FSharp.enableTouchBar && fsharp.debuggerAvailable" }, { "command": "fsharp.runDefaultProject", "group": "fsharp", - "when": "fsharp.project.any \u0026\u0026 config.FSharp.enableTouchBar" + "when": "fsharp.project.any \u0026\u0026 config.FSharp.enableTouchBar && fsharp.debuggerAvailable" }, { "command": "fsharp.NewProject", @@ -1536,12 +1546,12 @@ { "command": "fsharp.explorer.project.debug", "group": "1_run@2", - "when": "viewItem == ionide.projectExplorer.projectExe" + "when": "viewItem == ionide.projectExplorer.projectExe && fsharp.debuggerAvailable" }, { "command": "fsharp.explorer.project.debug", "group": "inline@2", - "when": "viewItem == ionide.projectExplorer.projectExe" + "when": "viewItem == ionide.projectExplorer.projectExe && fsharp.debuggerAvailable" }, { "command": "fsharp.explorer.project.setDefault", @@ -1733,9 +1743,7 @@ "engines": { "vscode": "^0.10.0" }, - "extensionDependencies": [ - "ms-dotnettools.csharp" - ], + "extensionDependencies": [], "homepage": "http://ionide.io", "icon": "images/logo.png", "license": "MIT", @@ -1748,4 +1756,4 @@ "url": "https://github.com/ionide/ionide-vscode-fsharp.git" }, "version": "7.8.5" -} \ No newline at end of file +} diff --git a/src/Components/CSharpExtensionSupport.fs b/src/Components/CSharpExtensionSupport.fs new file mode 100644 index 00000000..45e68df7 --- /dev/null +++ b/src/Components/CSharpExtensionSupport.fs @@ -0,0 +1,34 @@ +namespace Ionide.VSCode.FSharp + +open Fable.Import.VSCode.Vscode + +module CSharpExtension = + + let private msCSharpExtensionName = "ms-vscode.csharp" + let private openvsixCSharpExtensionName = "ms-vscode.csharp" + + let mutable private hasLookedForCSharp = false + let mutable private hasCSharp = false + let mutable private csharpExtension: Extension = null + let private csharpAvailableContext: bool -> unit = + let fn = Context.cachedSetter "fsharp.debuggerAvailable" + fun value -> + hasCSharp <- value + fn value + + let isCSharpAvailable () = hasCSharp + + let tryFindCSharpExtension() = + if hasLookedForCSharp + then hasCSharp + else + match extensions.getExtension msCSharpExtensionName with + | None -> + csharpAvailableContext false + | Some e -> + csharpExtension <- e + csharpAvailableContext true + hasLookedForCSharp <- true + hasCSharp + + let warnAboutMissingCSharpExtension() = () diff --git a/src/Components/Debugger.fs b/src/Components/Debugger.fs index cb944034..8c5a1e2f 100644 --- a/src/Components/Debugger.fs +++ b/src/Components/Debugger.fs @@ -386,23 +386,27 @@ module Debugger = ProviderResult.Some(U2.Case1 debugConfiguration) } let activate (c: ExtensionContext) = - commands.registerCommand ("fsharp.runDefaultProject", (buildAndRunDefault) |> objfy2) - |> c.Subscribe - commands.registerCommand ("fsharp.debugDefaultProject", (buildAndDebugDefault) |> objfy2) - |> c.Subscribe + match CSharpExtension.tryFindCSharpExtension() with + | false -> CSharpExtension.warnAboutMissingCSharpExtension() + | true -> + commands.registerCommand ("fsharp.runDefaultProject", (buildAndRunDefault) |> objfy2) + |> c.Subscribe - commands.registerCommand ("fsharp.chooseDefaultProject", (chooseDefaultProject) |> objfy2) - |> c.Subscribe + commands.registerCommand ("fsharp.debugDefaultProject", (buildAndDebugDefault) |> objfy2) + |> c.Subscribe - logger.Info "registering debug provider" + commands.registerCommand ("fsharp.chooseDefaultProject", (chooseDefaultProject) |> objfy2) + |> c.Subscribe - debug.registerDebugConfigurationProvider ( - "coreclr", - launchSettingProvider, - DebugConfigurationProviderTriggerKind.Dynamic - ) - |> c.Subscribe + logger.Info "registering debug provider" - context <- Some c - startup <- c.workspaceState.get "defaultProject" + debug.registerDebugConfigurationProvider ( + "coreclr", + launchSettingProvider, + DebugConfigurationProviderTriggerKind.Dynamic + ) + |> c.Subscribe + + context <- Some c + startup <- c.workspaceState.get "defaultProject" diff --git a/src/Components/MSBuild.fs b/src/Components/MSBuild.fs index cda685fe..abbf02bd 100644 --- a/src/Components/MSBuild.fs +++ b/src/Components/MSBuild.fs @@ -454,65 +454,69 @@ module MSBuild = let initWorkspace _n = Project.initWorkspace () - let solutionWatcher = workspace.createFileSystemWatcher (U2.Case1 "**/*.sln") + match CSharpExtension.tryFindCSharpExtension() with + | false -> CSharpExtension.warnAboutMissingCSharpExtension() + | true -> - solutionWatcher.onDidCreate.Invoke(fun n -> unlessIgnored n.fsPath initWorkspace |> unbox) - |> ignore + let solutionWatcher = workspace.createFileSystemWatcher (U2.Case1 "**/*.sln") - solutionWatcher.onDidChange.Invoke(fun n -> unlessIgnored n.fsPath initWorkspace |> unbox) - |> ignore - - //Restore any project that returns NotRestored status - Project.projectNotRestoredLoaded.Invoke(fun n -> restoreProjectAsync n |> unbox) - |> context.Subscribe - - let registerCommand com (action: unit -> _) = - commands.registerCommand (com, action |> objfy2) |> context.Subscribe - - let registerCommand2 com (action: obj -> obj -> _) = - commands.registerCommand (com, action |> objfy3) |> context.Subscribe - - /// typed msbuild cmd. Optional project and msbuild host - let typedMsbuildCmd f projOpt = - let p = - if JS.isDefined projOpt then - Some(unbox (projOpt)) - else - None - - fun _ -> f p - - tasks.registerTaskProvider ("msbuild", msbuildBuildTaskProvider) - |> context.Subscribe - - registerCommand "MSBuild.buildCurrent" (fun _ -> buildCurrentProject "Build") - registerCommand "MSBuild.rebuildCurrent" (fun _ -> buildCurrentProject "Rebuild") - registerCommand "MSBuild.cleanCurrent" (fun _ -> buildCurrentProject "Clean") - - registerCommand "MSBuild.buildCurrentSolution" (fun _ -> buildCurrentSolution "Build") - registerCommand "MSBuild.rebuildCurrentSolution" (fun _ -> buildCurrentSolution "Rebuild") - registerCommand "MSBuild.cleanCurrentSolution" (fun _ -> buildCurrentSolution "Clean") - - commands.registerCommand ( - "MSBuild.buildSelected", - fun _ -> buildProject "Build" |> Promise.map box |> box |> Some - ) - |> context.Subscribe - - commands.registerCommand ( - "MSBuild.rebuildSelected", - fun _ -> buildProject "Rebuild" |> Promise.map box |> box |> Some - ) - |> context.Subscribe + solutionWatcher.onDidCreate.Invoke(fun n -> unlessIgnored n.fsPath initWorkspace |> unbox) + |> ignore - commands.registerCommand ( - "MSBuild.cleanSelected", - fun _ -> buildProject "Clean" |> Promise.map box |> box |> Some - ) - |> context.Subscribe + solutionWatcher.onDidChange.Invoke(fun n -> unlessIgnored n.fsPath initWorkspace |> unbox) + |> ignore - commands.registerCommand ( - "MSBuild.restoreSelected", - fun _ -> restoreProjectCmd () |> Promise.map box |> box |> Some - ) - |> context.Subscribe + //Restore any project that returns NotRestored status + Project.projectNotRestoredLoaded.Invoke(fun n -> restoreProjectAsync n |> unbox) + |> context.Subscribe + + let registerCommand com (action: unit -> _) = + commands.registerCommand (com, action |> objfy2) |> context.Subscribe + + let registerCommand2 com (action: obj -> obj -> _) = + commands.registerCommand (com, action |> objfy3) |> context.Subscribe + + /// typed msbuild cmd. Optional project and msbuild host + let typedMsbuildCmd f projOpt = + let p = + if JS.isDefined projOpt then + Some(unbox (projOpt)) + else + None + + fun _ -> f p + + tasks.registerTaskProvider ("msbuild", msbuildBuildTaskProvider) + |> context.Subscribe + + registerCommand "MSBuild.buildCurrent" (fun _ -> buildCurrentProject "Build") + registerCommand "MSBuild.rebuildCurrent" (fun _ -> buildCurrentProject "Rebuild") + registerCommand "MSBuild.cleanCurrent" (fun _ -> buildCurrentProject "Clean") + + registerCommand "MSBuild.buildCurrentSolution" (fun _ -> buildCurrentSolution "Build") + registerCommand "MSBuild.rebuildCurrentSolution" (fun _ -> buildCurrentSolution "Rebuild") + registerCommand "MSBuild.cleanCurrentSolution" (fun _ -> buildCurrentSolution "Clean") + + commands.registerCommand ( + "MSBuild.buildSelected", + fun _ -> buildProject "Build" |> Promise.map box |> box |> Some + ) + |> context.Subscribe + + commands.registerCommand ( + "MSBuild.rebuildSelected", + fun _ -> buildProject "Rebuild" |> Promise.map box |> box |> Some + ) + |> context.Subscribe + + commands.registerCommand ( + "MSBuild.cleanSelected", + fun _ -> buildProject "Clean" |> Promise.map box |> box |> Some + ) + |> context.Subscribe + + commands.registerCommand ( + "MSBuild.restoreSelected", + fun _ -> restoreProjectCmd () |> Promise.map box |> box |> Some + ) + |> context.Subscribe diff --git a/src/Ionide.FSharp.fsproj b/src/Ionide.FSharp.fsproj index f7f2bd1b..85da7bac 100644 --- a/src/Ionide.FSharp.fsproj +++ b/src/Ionide.FSharp.fsproj @@ -30,6 +30,7 @@ + From f2256977971a89ba628a618d5f940087f2f28178 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Sat, 29 Jul 2023 13:28:01 -0500 Subject: [PATCH 02/14] warning message --- src/Components/CSharpExtensionSupport.fs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Components/CSharpExtensionSupport.fs b/src/Components/CSharpExtensionSupport.fs index 45e68df7..fea420e1 100644 --- a/src/Components/CSharpExtensionSupport.fs +++ b/src/Components/CSharpExtensionSupport.fs @@ -7,9 +7,13 @@ module CSharpExtension = let private msCSharpExtensionName = "ms-vscode.csharp" let private openvsixCSharpExtensionName = "ms-vscode.csharp" + let private resolvedCSharpExtensionName = msCSharpExtensionName + let mutable private hasLookedForCSharp = false let mutable private hasCSharp = false let mutable private csharpExtension: Extension = null + let mutable private hasWarned = false + let private csharpAvailableContext: bool -> unit = let fn = Context.cachedSetter "fsharp.debuggerAvailable" fun value -> @@ -19,16 +23,19 @@ module CSharpExtension = let isCSharpAvailable () = hasCSharp let tryFindCSharpExtension() = - if hasLookedForCSharp - then hasCSharp - else - match extensions.getExtension msCSharpExtensionName with + if not hasLookedForCSharp + then + match extensions.getExtension resolvedCSharpExtensionName with | None -> csharpAvailableContext false | Some e -> csharpExtension <- e csharpAvailableContext true hasLookedForCSharp <- true - hasCSharp + hasCSharp - let warnAboutMissingCSharpExtension() = () + let warnAboutMissingCSharpExtension() = + if not hasWarned then + window.showWarningMessage($"The {resolvedCSharpExtensionName} extension isn't installed, so debugging and some build tools will not be available. Consider installing the {resolvedCSharpExtensionName} extension to enable those features.") + |> ignore + hasWarned <- true From e969eeb8b37ff64eacb6552b42198753b01fe486 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Mon, 31 Jul 2023 16:43:46 -0500 Subject: [PATCH 03/14] choose different C# extension based on execution state --- src/Components/CSharpExtensionSupport.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Components/CSharpExtensionSupport.fs b/src/Components/CSharpExtensionSupport.fs index fea420e1..187e0061 100644 --- a/src/Components/CSharpExtensionSupport.fs +++ b/src/Components/CSharpExtensionSupport.fs @@ -7,7 +7,8 @@ module CSharpExtension = let private msCSharpExtensionName = "ms-vscode.csharp" let private openvsixCSharpExtensionName = "ms-vscode.csharp" - let private resolvedCSharpExtensionName = msCSharpExtensionName + let private resolvedCSharpExtensionName = + if env.appName = 'VS Code' then msCSharpExtensionName else openvsixCSharpExtensionName let mutable private hasLookedForCSharp = false let mutable private hasCSharp = false From 2891cc74fb5030cb4a16e855ebc81a719d90152d Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Mon, 31 Jul 2023 16:53:41 -0500 Subject: [PATCH 04/14] listen to extension changes to make sure enablement works --- src/Components/CSharpExtensionSupport.fs | 11 ++++++++++- src/fsharp.fs | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Components/CSharpExtensionSupport.fs b/src/Components/CSharpExtensionSupport.fs index 187e0061..36c8e2d5 100644 --- a/src/Components/CSharpExtensionSupport.fs +++ b/src/Components/CSharpExtensionSupport.fs @@ -8,7 +8,7 @@ module CSharpExtension = let private openvsixCSharpExtensionName = "ms-vscode.csharp" let private resolvedCSharpExtensionName = - if env.appName = 'VS Code' then msCSharpExtensionName else openvsixCSharpExtensionName + if env.appName = "VS Code" then msCSharpExtensionName else openvsixCSharpExtensionName let mutable private hasLookedForCSharp = false let mutable private hasCSharp = false @@ -40,3 +40,12 @@ module CSharpExtension = window.showWarningMessage($"The {resolvedCSharpExtensionName} extension isn't installed, so debugging and some build tools will not be available. Consider installing the {resolvedCSharpExtensionName} extension to enable those features.") |> ignore hasWarned <- true + + let activate () = + // when extensions are installed or removed we need to update our state for the C# extension + // so enablement/disablement works correctly + extensions.onDidChange.Invoke(fun _ -> + tryFindCSharpExtension() + |> ignore + None + ) diff --git a/src/fsharp.fs b/src/fsharp.fs index 7a5c6ce1..5f876883 100644 --- a/src/fsharp.fs +++ b/src/fsharp.fs @@ -33,6 +33,8 @@ let activate (context: ExtensionContext) : JS.Promise = logger.Error $"Error while activating feature '{label}': {ex}" Unchecked.defaultof<_> + CSharpExtensionSupport.activate() + LanguageService.start context |> Promise.catch (fun e -> logger.Error $"Error activating FSAC: %A{e}") // prevent unhandled rejected promises |> Promise.onSuccess (fun _ -> From a86b015097a10bf02ef0e955df1f4436d204c563 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Mon, 31 Jul 2023 16:56:47 -0500 Subject: [PATCH 05/14] markdown link to extension gallery --- src/Components/CSharpExtensionSupport.fs | 33 ++++++++++++++---------- src/Components/Debugger.fs | 4 +-- src/Components/MSBuild.fs | 4 +-- src/fsharp.fs | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/Components/CSharpExtensionSupport.fs b/src/Components/CSharpExtensionSupport.fs index 36c8e2d5..071456da 100644 --- a/src/Components/CSharpExtensionSupport.fs +++ b/src/Components/CSharpExtensionSupport.fs @@ -5,10 +5,15 @@ open Fable.Import.VSCode.Vscode module CSharpExtension = let private msCSharpExtensionName = "ms-vscode.csharp" - let private openvsixCSharpExtensionName = "ms-vscode.csharp" + let private openvsixCSharpExtensionName = "muhammad-sammy.csharp" let private resolvedCSharpExtensionName = - if env.appName = "VS Code" then msCSharpExtensionName else openvsixCSharpExtensionName + if env.appName = "VS Code" then + msCSharpExtensionName + else + openvsixCSharpExtensionName + + let private extensionLink = $"[C#](vscode:extension/{resolvedCSharpExtensionName})" let mutable private hasLookedForCSharp = false let mutable private hasCSharp = false @@ -17,35 +22,37 @@ module CSharpExtension = let private csharpAvailableContext: bool -> unit = let fn = Context.cachedSetter "fsharp.debuggerAvailable" + fun value -> hasCSharp <- value fn value let isCSharpAvailable () = hasCSharp - let tryFindCSharpExtension() = - if not hasLookedForCSharp - then + let tryFindCSharpExtension () = + if not hasLookedForCSharp then match extensions.getExtension resolvedCSharpExtensionName with - | None -> - csharpAvailableContext false + | None -> csharpAvailableContext false | Some e -> csharpExtension <- e csharpAvailableContext true + hasLookedForCSharp <- true + hasCSharp - let warnAboutMissingCSharpExtension() = + let warnAboutMissingCSharpExtension () = if not hasWarned then - window.showWarningMessage($"The {resolvedCSharpExtensionName} extension isn't installed, so debugging and some build tools will not be available. Consider installing the {resolvedCSharpExtensionName} extension to enable those features.") + window.showWarningMessage ( + $"The {extensionLink} extension isn't installed, so debugging and some build tools will not be available. Consider installing the {extensionLink} extension to enable those features." + ) |> ignore + hasWarned <- true let activate () = // when extensions are installed or removed we need to update our state for the C# extension // so enablement/disablement works correctly extensions.onDidChange.Invoke(fun _ -> - tryFindCSharpExtension() - |> ignore - None - ) + tryFindCSharpExtension () |> ignore + None) diff --git a/src/Components/Debugger.fs b/src/Components/Debugger.fs index 8c5a1e2f..777afe73 100644 --- a/src/Components/Debugger.fs +++ b/src/Components/Debugger.fs @@ -387,8 +387,8 @@ module Debugger = let activate (c: ExtensionContext) = - match CSharpExtension.tryFindCSharpExtension() with - | false -> CSharpExtension.warnAboutMissingCSharpExtension() + match CSharpExtension.tryFindCSharpExtension () with + | false -> CSharpExtension.warnAboutMissingCSharpExtension () | true -> commands.registerCommand ("fsharp.runDefaultProject", (buildAndRunDefault) |> objfy2) |> c.Subscribe diff --git a/src/Components/MSBuild.fs b/src/Components/MSBuild.fs index abbf02bd..72696d77 100644 --- a/src/Components/MSBuild.fs +++ b/src/Components/MSBuild.fs @@ -454,8 +454,8 @@ module MSBuild = let initWorkspace _n = Project.initWorkspace () - match CSharpExtension.tryFindCSharpExtension() with - | false -> CSharpExtension.warnAboutMissingCSharpExtension() + match CSharpExtension.tryFindCSharpExtension () with + | false -> CSharpExtension.warnAboutMissingCSharpExtension () | true -> let solutionWatcher = workspace.createFileSystemWatcher (U2.Case1 "**/*.sln") diff --git a/src/fsharp.fs b/src/fsharp.fs index 5f876883..2fa8c521 100644 --- a/src/fsharp.fs +++ b/src/fsharp.fs @@ -33,7 +33,7 @@ let activate (context: ExtensionContext) : JS.Promise = logger.Error $"Error while activating feature '{label}': {ex}" Unchecked.defaultof<_> - CSharpExtensionSupport.activate() + CSharpExtensionSupport.activate () LanguageService.start context |> Promise.catch (fun e -> logger.Error $"Error activating FSAC: %A{e}") // prevent unhandled rejected promises From aa18afb7529b500928c257976513a9ddb947fbf7 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Tue, 1 Aug 2023 09:40:41 -0500 Subject: [PATCH 06/14] fix MS c# extension name --- src/Components/CSharpExtensionSupport.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/CSharpExtensionSupport.fs b/src/Components/CSharpExtensionSupport.fs index 071456da..58a8bf48 100644 --- a/src/Components/CSharpExtensionSupport.fs +++ b/src/Components/CSharpExtensionSupport.fs @@ -4,7 +4,7 @@ open Fable.Import.VSCode.Vscode module CSharpExtension = - let private msCSharpExtensionName = "ms-vscode.csharp" + let private msCSharpExtensionName = "ms-dotnettools.csharp" let private openvsixCSharpExtensionName = "muhammad-sammy.csharp" let private resolvedCSharpExtensionName = From 683dade6a5025d15e6a0963d427728c1b7d3e7f2 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Tue, 1 Aug 2023 09:55:04 -0500 Subject: [PATCH 07/14] fix hookup --- src/Components/CSharpExtensionSupport.fs | 10 ++++++---- src/fsharp.fs | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Components/CSharpExtensionSupport.fs b/src/Components/CSharpExtensionSupport.fs index 58a8bf48..491f6cb2 100644 --- a/src/Components/CSharpExtensionSupport.fs +++ b/src/Components/CSharpExtensionSupport.fs @@ -50,9 +50,11 @@ module CSharpExtension = hasWarned <- true - let activate () = + let activate (context: ExtensionContext) = // when extensions are installed or removed we need to update our state for the C# extension // so enablement/disablement works correctly - extensions.onDidChange.Invoke(fun _ -> - tryFindCSharpExtension () |> ignore - None) + context.Subscribe( + extensions.onDidChange.Invoke(fun _ -> + tryFindCSharpExtension () |> ignore + None) + ) diff --git a/src/fsharp.fs b/src/fsharp.fs index 2fa8c521..518a4943 100644 --- a/src/fsharp.fs +++ b/src/fsharp.fs @@ -33,7 +33,7 @@ let activate (context: ExtensionContext) : JS.Promise = logger.Error $"Error while activating feature '{label}': {ex}" Unchecked.defaultof<_> - CSharpExtensionSupport.activate () + CSharpExtension.activate(context) LanguageService.start context |> Promise.catch (fun e -> logger.Error $"Error activating FSAC: %A{e}") // prevent unhandled rejected promises From 6a15bf4d2dea2dac5480e202314268a6d2ebd1e2 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Sat, 5 Aug 2023 09:58:02 -0500 Subject: [PATCH 08/14] bump structured logger dependency --- build/paket.references | 3 ++- paket.dependencies | 3 ++- paket.lock | 29 ++++++++++++++--------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/build/paket.references b/build/paket.references index 30d05729..1c8b5b0e 100644 --- a/build/paket.references +++ b/build/paket.references @@ -14,4 +14,5 @@ Fake.IO.Zip Fake.Api.GitHub Fake.Tools.Git Fake.JavaScript.Yarn -Octokit \ No newline at end of file +Octokit +MSBuild.StructuredLogger \ No newline at end of file diff --git a/paket.dependencies b/paket.dependencies index 076491a4..7f95b422 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -43,4 +43,5 @@ group build nuget Fake.Api.GitHub nuget Fake.Tools.Git nuget Fake.JavaScript.Yarn - nuget Octokit <= 0.49.0 \ No newline at end of file + nuget Octokit <= 0.49.0 + nuget MSBuild.StructuredLogger \ No newline at end of file diff --git a/paket.lock b/paket.lock index 5b7c3193..ac488e87 100644 --- a/paket.lock +++ b/paket.lock @@ -178,24 +178,25 @@ NUGET FSharp.Core (>= 4.7.2) System.Reactive (>= 5.0 < 6.0) FSharp.Core (7.0.200) - Microsoft.Build.Framework (17.4) - System.Security.Permissions (>= 6.0) - Microsoft.Build.Utilities.Core (17.4) - Microsoft.Build.Framework (>= 17.4) - Microsoft.NET.StringTools (>= 17.4) - System.Collections.Immutable (>= 6.0) - System.Configuration.ConfigurationManager (>= 6.0) - Microsoft.NET.StringTools (17.4) - System.Memory (>= 4.5.5) - System.Runtime.CompilerServices.Unsafe (>= 6.0) + Microsoft.Build.Framework (17.6.3) + System.Security.Permissions (>= 7.0) + Microsoft.Build.Utilities.Core (17.6.3) + Microsoft.Build.Framework (>= 17.6.3) + Microsoft.NET.StringTools (>= 17.6.3) + Microsoft.VisualStudio.Setup.Configuration.Interop (>= 3.2.2146) + System.Collections.Immutable (>= 7.0) + System.Configuration.ConfigurationManager (>= 7.0) + System.Security.Permissions (>= 7.0) + Microsoft.NET.StringTools (17.6.3) + Microsoft.VisualStudio.Setup.Configuration.Interop (3.6.2115) Microsoft.Win32.Registry (5.0) System.Security.AccessControl (>= 5.0) System.Security.Principal.Windows (>= 5.0) Microsoft.Win32.SystemEvents (7.0) Mono.Posix.NETStandard (1.0) - MSBuild.StructuredLogger (2.1.768) - Microsoft.Build.Framework (>= 16.10) - Microsoft.Build.Utilities.Core (>= 16.10) + MSBuild.StructuredLogger (2.1.844) + Microsoft.Build.Framework (>= 17.5) + Microsoft.Build.Utilities.Core (>= 17.5) Newtonsoft.Json (13.0.2) NuGet.Common (6.4) NuGet.Frameworks (>= 6.4) @@ -222,9 +223,7 @@ NUGET System.Drawing.Common (7.0) Microsoft.Win32.SystemEvents (>= 7.0) System.Formats.Asn1 (7.0) - System.Memory (4.5.5) System.Reactive (5.0) - System.Runtime.CompilerServices.Unsafe (6.0) System.Security.AccessControl (6.0) System.Security.Cryptography.Cng (5.0) System.Formats.Asn1 (>= 5.0) From ed848c479f6406bc2dbfd66b86f7f95b2cf234d5 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Sat, 5 Aug 2023 09:58:33 -0500 Subject: [PATCH 09/14] corerctly link to extension install page for prompt --- src/Components/CSharpExtensionSupport.fs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Components/CSharpExtensionSupport.fs b/src/Components/CSharpExtensionSupport.fs index 491f6cb2..c40750ee 100644 --- a/src/Components/CSharpExtensionSupport.fs +++ b/src/Components/CSharpExtensionSupport.fs @@ -1,5 +1,6 @@ namespace Ionide.VSCode.FSharp +open Fable.Import.VSCode open Fable.Import.VSCode.Vscode module CSharpExtension = @@ -8,13 +9,11 @@ module CSharpExtension = let private openvsixCSharpExtensionName = "muhammad-sammy.csharp" let private resolvedCSharpExtensionName = - if env.appName = "VS Code" then + if env.appName = "Visual Studio Code" then msCSharpExtensionName else openvsixCSharpExtensionName - let private extensionLink = $"[C#](vscode:extension/{resolvedCSharpExtensionName})" - let mutable private hasLookedForCSharp = false let mutable private hasCSharp = false let mutable private csharpExtension: Extension = null @@ -44,9 +43,22 @@ module CSharpExtension = let warnAboutMissingCSharpExtension () = if not hasWarned then window.showWarningMessage ( - $"The {extensionLink} extension isn't installed, so debugging and some build tools will not be available. Consider installing the {extensionLink} extension to enable those features." + $"The C# extension isn't installed, so debugging and some build tools will not be available. Consider installing the C# extension to enable those features.", + [| "Install C# Extension" |] + ) + |> Promise.ofThenable + |> Promise.bind (fun c -> + if c = Some "Install C# Extension" then + commands.executeCommand("extension.open", [| Some (box resolvedCSharpExtensionName) |]) + |> Promise.ofThenable + else + Promise.empty + ) + |> Promise.catch (fun e -> + printfn $"Error installing C# extension: {Fable.Core.JS.JSON.stringify e}" + Promise.empty ) - |> ignore + |> ignore> hasWarned <- true From 3c48c3f443beaceaf5be8031d735f2f4a2dee155 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Sat, 5 Aug 2023 10:04:49 -0500 Subject: [PATCH 10/14] let users know when debugging functionality lights up --- src/Components/CSharpExtensionSupport.fs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Components/CSharpExtensionSupport.fs b/src/Components/CSharpExtensionSupport.fs index c40750ee..a6e0e060 100644 --- a/src/Components/CSharpExtensionSupport.fs +++ b/src/Components/CSharpExtensionSupport.fs @@ -62,11 +62,24 @@ module CSharpExtension = hasWarned <- true + let private notifyUserThatDebuggingWorks() = + window.showInformationMessage ($"The C# extension is installed, so debugging and build tools are now available for F# projects.") + |> ignore> + let activate (context: ExtensionContext) = // when extensions are installed or removed we need to update our state for the C# extension // so enablement/disablement works correctly context.Subscribe( extensions.onDidChange.Invoke(fun _ -> - tryFindCSharpExtension () |> ignore - None) + let previousCSharpValue = hasCSharp + hasLookedForCSharp <- false + let currentCSharpValue = tryFindCSharpExtension () + match previousCSharpValue, currentCSharpValue with + | false, true -> notifyUserThatDebuggingWorks() + | true, false -> + hasWarned <- false + warnAboutMissingCSharpExtension() + | _ -> () + None + ) ) From 52407fe340bccc4c60a2c11ac6d0352a27280abf Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Sat, 19 Aug 2023 14:53:36 -0500 Subject: [PATCH 11/14] fix after merge --- src/Components/CSharpExtensionSupport.fs | 23 ++++++++++++----------- src/Components/LineLens/LineLens.fs | 4 +++- src/Ionide.FSharp.fsproj | 1 - src/fsharp.fs | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Components/CSharpExtensionSupport.fs b/src/Components/CSharpExtensionSupport.fs index a6e0e060..46d3e651 100644 --- a/src/Components/CSharpExtensionSupport.fs +++ b/src/Components/CSharpExtensionSupport.fs @@ -49,21 +49,21 @@ module CSharpExtension = |> Promise.ofThenable |> Promise.bind (fun c -> if c = Some "Install C# Extension" then - commands.executeCommand("extension.open", [| Some (box resolvedCSharpExtensionName) |]) + commands.executeCommand ("extension.open", [| Some(box resolvedCSharpExtensionName) |]) |> Promise.ofThenable else - Promise.empty - ) + Promise.empty) |> Promise.catch (fun e -> printfn $"Error installing C# extension: {Fable.Core.JS.JSON.stringify e}" - Promise.empty - ) + Promise.empty) |> ignore> hasWarned <- true - let private notifyUserThatDebuggingWorks() = - window.showInformationMessage ($"The C# extension is installed, so debugging and build tools are now available for F# projects.") + let private notifyUserThatDebuggingWorks () = + window.showInformationMessage ( + $"The C# extension is installed, so debugging and build tools are now available for F# projects." + ) |> ignore> let activate (context: ExtensionContext) = @@ -74,12 +74,13 @@ module CSharpExtension = let previousCSharpValue = hasCSharp hasLookedForCSharp <- false let currentCSharpValue = tryFindCSharpExtension () + match previousCSharpValue, currentCSharpValue with - | false, true -> notifyUserThatDebuggingWorks() + | false, true -> notifyUserThatDebuggingWorks () | true, false -> hasWarned <- false - warnAboutMissingCSharpExtension() + warnAboutMissingCSharpExtension () | _ -> () - None - ) + + None) ) diff --git a/src/Components/LineLens/LineLens.fs b/src/Components/LineLens/LineLens.fs index dcd17636..47652b00 100644 --- a/src/Components/LineLens/LineLens.fs +++ b/src/Components/LineLens/LineLens.fs @@ -101,7 +101,9 @@ module DecorationUpdate = LanguageService.signatureData uri range.StartLine (range.StartColumn - 1) |> Async.AwaitPromise - return signaturesResult |> Option.map (fun r -> range|>CodeRange.fromDTO, formatSignature r.Data) + return + signaturesResult + |> Option.map (fun r -> range |> CodeRange.fromDTO, formatSignature r.Data) with e -> logger.Error("Error getting signature %o", e) return None diff --git a/src/Ionide.FSharp.fsproj b/src/Ionide.FSharp.fsproj index ea1244fc..2f17c46d 100644 --- a/src/Ionide.FSharp.fsproj +++ b/src/Ionide.FSharp.fsproj @@ -49,7 +49,6 @@ - diff --git a/src/fsharp.fs b/src/fsharp.fs index 1b4c57c1..f1441a62 100644 --- a/src/fsharp.fs +++ b/src/fsharp.fs @@ -33,7 +33,7 @@ let activate (context: ExtensionContext) : JS.Promise = logger.Error $"Error while activating feature '{label}': {ex}" Unchecked.defaultof<_> - CSharpExtension.activate(context) + CSharpExtension.activate (context) LanguageService.start context |> Promise.catch (fun e -> logger.Error $"Error activating FSAC: %A{e}") // prevent unhandled rejected promises From c5340d31ace07ed5faf9a5e9ba55fc60187b822b Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Sat, 19 Aug 2023 14:59:03 -0500 Subject: [PATCH 12/14] rename context key --- release/package.json | 60 ++++++++++++------------ src/Components/CSharpExtensionSupport.fs | 2 +- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/release/package.json b/release/package.json index 54675852..3d9438fe 100644 --- a/release/package.json +++ b/release/package.json @@ -156,52 +156,52 @@ { "command": "MSBuild.buildCurrent", "title": "MSBuild: Build current project", - "when": "fsharp.debuggerAvailable" + "when": "fsharp.debugger.available" }, { "command": "MSBuild.buildSelected", "title": "MSBuild: Build project", - "when": "fsharp.debuggerAvailable" + "when": "fsharp.debugger.available" }, { "command": "MSBuild.rebuildCurrent", "title": "MSBuild: Rebuild current project", - "when": "fsharp.debuggerAvailable" + "when": "fsharp.debugger.available" }, { "command": "MSBuild.rebuildSelected", "title": "MSBuild: Rebuild project", - "when": "fsharp.debuggerAvailable" + "when": "fsharp.debugger.available" }, { "command": "MSBuild.cleanCurrent", "title": "MSBuild: Clean current project", - "when": "fsharp.debuggerAvailable" + "when": "fsharp.debugger.available" }, { "command": "MSBuild.cleanSelected", "title": "MSBuild: Clean project", - "when": "fsharp.debuggerAvailable" + "when": "fsharp.debugger.available" }, { "command": "MSBuild.restoreSelected", "title": "MSBuild: Restore project", - "when": "fsharp.debuggerAvailable" + "when": "fsharp.debugger.available" }, { "command": "MSBuild.buildCurrentSolution", "title": "MSBuild: Build current solution", - "when": "fsharp.debuggerAvailable" + "when": "fsharp.debugger.available" }, { "command": "MSBuild.rebuildCurrentSolution", "title": "MSBuild: Rebuild current solution", - "when": "fsharp.debuggerAvailable" + "when": "fsharp.debugger.available" }, { "command": "MSBuild.cleanCurrentSolution", "title": "MSBuild: Clean current solution", - "when": "fsharp.debuggerAvailable" + "when": "fsharp.debugger.available" }, { "command": "fsharp.explorer.moveUp", @@ -978,12 +978,12 @@ { "command": "MSBuild.buildCurrent", "key": "ctrl\u002Balt\u002Bb", - "when": "fsharp.project.any \u0026\u0026 editorFocus \u0026\u0026 editorLangId == \u0027fsharp\u0027 && fsharp.debuggerAvailable" + "when": "fsharp.project.any \u0026\u0026 editorFocus \u0026\u0026 editorLangId == \u0027fsharp\u0027 && fsharp.debugger.available" }, { "command": "MSBuild.buildCurrentSolution", "key": "ctrl\u002Balt\u002Bshift\u002Bb", - "when": "fsharp.project.any && fsharp.debuggerAvailable" + "when": "fsharp.project.any && fsharp.debugger.available" }, { "command": "fsharp.openInfoPanel", @@ -1175,15 +1175,15 @@ }, { "command": "MSBuild.buildCurrent", - "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 && fsharp.debuggerAvailable" + "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 && fsharp.debugger.available" }, { "command": "MSBuild.rebuildCurrent", - "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 && fsharp.debuggerAvailable" + "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 && fsharp.debugger.available" }, { "command": "MSBuild.cleanCurrent", - "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 && fsharp.debuggerAvailable" + "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 && fsharp.debugger.available" }, { "command": "fsharp.clearCache", @@ -1191,43 +1191,43 @@ }, { "command": "MSBuild.buildSelected", - "when": "fsharp.project.any && fsharp.debuggerAvailable" + "when": "fsharp.project.any && fsharp.debugger.available" }, { "command": "MSBuild.rebuildSelected", - "when": "fsharp.project.any && fsharp.debuggerAvailable" + "when": "fsharp.project.any && fsharp.debugger.available" }, { "command": "MSBuild.cleanSelected", - "when": "fsharp.project.any && fsharp.debuggerAvailable" + "when": "fsharp.project.any && fsharp.debugger.available" }, { "command": "MSBuild.restoreSelected", - "when": "fsharp.project.any && fsharp.debuggerAvailable" + "when": "fsharp.project.any && fsharp.debugger.available" }, { "command": "MSBuild.buildCurrentSolution", - "when": "fsharp.project.any && fsharp.debuggerAvailable" + "when": "fsharp.project.any && fsharp.debugger.available" }, { "command": "MSBuild.rebuildCurrentSolution", - "when": "fsharp.project.any && fsharp.debuggerAvailable" + "when": "fsharp.project.any && fsharp.debugger.available" }, { "command": "MSBuild.cleanCurrentSolution", - "when": "fsharp.project.any && fsharp.debuggerAvailable" + "when": "fsharp.project.any && fsharp.debugger.available" }, { "command": "fsharp.runDefaultProject", - "when": "fsharp.project.any && fsharp.debuggerAvailable" + "when": "fsharp.project.any && fsharp.debugger.available" }, { "command": "fsharp.debugDefaultProject", - "when": "fsharp.project.any && fsharp.debuggerAvailable" + "when": "fsharp.project.any && fsharp.debugger.available" }, { "command": "fsharp.chooseDefaultProject", - "when": "fsharp.project.any && fsharp.debuggerAvailable" + "when": "fsharp.project.any && fsharp.debugger.available" }, { "command": "fsharp.NewProject", @@ -1271,12 +1271,12 @@ { "command": "fsharp.debugDefaultProject", "group": "fsharp", - "when": "fsharp.project.any \u0026\u0026 config.FSharp.enableTouchBar && fsharp.debuggerAvailable" + "when": "fsharp.project.any \u0026\u0026 config.FSharp.enableTouchBar && fsharp.debugger.available" }, { "command": "fsharp.runDefaultProject", "group": "fsharp", - "when": "fsharp.project.any \u0026\u0026 config.FSharp.enableTouchBar && fsharp.debuggerAvailable" + "when": "fsharp.project.any \u0026\u0026 config.FSharp.enableTouchBar && fsharp.debugger.available" }, { "command": "fsharp.NewProject", @@ -1546,12 +1546,12 @@ { "command": "fsharp.explorer.project.debug", "group": "1_run@2", - "when": "viewItem == ionide.projectExplorer.projectExe && fsharp.debuggerAvailable" + "when": "viewItem == ionide.projectExplorer.projectExe && fsharp.debugger.available" }, { "command": "fsharp.explorer.project.debug", "group": "inline@2", - "when": "viewItem == ionide.projectExplorer.projectExe && fsharp.debuggerAvailable" + "when": "viewItem == ionide.projectExplorer.projectExe && fsharp.debugger.available" }, { "command": "fsharp.explorer.project.setDefault", @@ -1762,4 +1762,4 @@ "url": "https://github.com/ionide/ionide-vscode-fsharp.git" }, "version": "7.8.5" -} +} \ No newline at end of file diff --git a/src/Components/CSharpExtensionSupport.fs b/src/Components/CSharpExtensionSupport.fs index 46d3e651..f8ea8ef5 100644 --- a/src/Components/CSharpExtensionSupport.fs +++ b/src/Components/CSharpExtensionSupport.fs @@ -20,7 +20,7 @@ module CSharpExtension = let mutable private hasWarned = false let private csharpAvailableContext: bool -> unit = - let fn = Context.cachedSetter "fsharp.debuggerAvailable" + let fn = Context.cachedSetter "fsharp.debugger.available" fun value -> hasCSharp <- value From 2c0e40ae06f1c8c01edcf1c6c822db132a5ccd32 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Sat, 19 Aug 2023 15:16:22 -0500 Subject: [PATCH 13/14] disable more commands when debugging is missing --- release/package.json | 70 +++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/release/package.json b/release/package.json index 3d9438fe..1efbcd08 100644 --- a/release/package.json +++ b/release/package.json @@ -294,35 +294,43 @@ }, { "command": "fsharp.explorer.msbuild.build", - "title": "Build" + "title": "Build", + "enablement": "fsharp.debugger.available" }, { "command": "fsharp.explorer.msbuild.rebuild", - "title": "Rebuild" + "title": "Rebuild", + "enablement": "fsharp.debugger.available" }, { "command": "fsharp.explorer.msbuild.clean", - "title": "Clean" + "title": "Clean", + "enablement": "fsharp.debugger.available" }, { "command": "fsharp.explorer.msbuild.restore", - "title": "Restore" + "title": "Restore", + "enablement": "fsharp.debugger.available" }, { "command": "fsharp.explorer.solution.build", - "title": "Build" + "title": "Build", + "enablement": "fsharp.debugger.available" }, { "command": "fsharp.explorer.solution.rebuild", - "title": "Rebuild" + "title": "Rebuild", + "enablement": "fsharp.debugger.available" }, { "command": "fsharp.explorer.solution.clean", - "title": "Clean" + "title": "Clean", + "enablement": "fsharp.debugger.available" }, { "command": "fsharp.explorer.solution.restore", - "title": "Restore" + "title": "Restore", + "enablement": "fsharp.debugger.available" }, { "command": "fsharp.explorer.project.run", @@ -338,7 +346,8 @@ "dark": "./images/debug-mono-dark.svg", "light": "./images/debug-mono-light.svg" }, - "title": "Debug" + "title": "Debug", + "enablement": "fsharp.debugger.available" }, { "command": "fsharp.explorer.project.setDefault", @@ -360,7 +369,8 @@ { "command": "fsharp.debugDefaultProject", "icon": "./images/debug.png", - "title": "F#: Debug Default Project" + "title": "F#: Debug Default Project", + "enablement": "fsharp.debugger.available" }, { "command": "fsharp.chooseDefaultProject", @@ -978,12 +988,12 @@ { "command": "MSBuild.buildCurrent", "key": "ctrl\u002Balt\u002Bb", - "when": "fsharp.project.any \u0026\u0026 editorFocus \u0026\u0026 editorLangId == \u0027fsharp\u0027 && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 editorFocus \u0026\u0026 editorLangId == \u0027fsharp\u0027 \u0026\u0026 fsharp.debugger.available" }, { "command": "MSBuild.buildCurrentSolution", "key": "ctrl\u002Balt\u002Bshift\u002Bb", - "when": "fsharp.project.any && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" }, { "command": "fsharp.openInfoPanel", @@ -1175,15 +1185,15 @@ }, { "command": "MSBuild.buildCurrent", - "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 \u0026\u0026 fsharp.debugger.available" }, { "command": "MSBuild.rebuildCurrent", - "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 \u0026\u0026 fsharp.debugger.available" }, { "command": "MSBuild.cleanCurrent", - "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 \u0026\u0026 fsharp.debugger.available" }, { "command": "fsharp.clearCache", @@ -1191,43 +1201,43 @@ }, { "command": "MSBuild.buildSelected", - "when": "fsharp.project.any && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" }, { "command": "MSBuild.rebuildSelected", - "when": "fsharp.project.any && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" }, { "command": "MSBuild.cleanSelected", - "when": "fsharp.project.any && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" }, { "command": "MSBuild.restoreSelected", - "when": "fsharp.project.any && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" }, { "command": "MSBuild.buildCurrentSolution", - "when": "fsharp.project.any && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" }, { "command": "MSBuild.rebuildCurrentSolution", - "when": "fsharp.project.any && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" }, { "command": "MSBuild.cleanCurrentSolution", - "when": "fsharp.project.any && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" }, { "command": "fsharp.runDefaultProject", - "when": "fsharp.project.any && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" }, { "command": "fsharp.debugDefaultProject", - "when": "fsharp.project.any && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" }, { "command": "fsharp.chooseDefaultProject", - "when": "fsharp.project.any && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" }, { "command": "fsharp.NewProject", @@ -1271,12 +1281,12 @@ { "command": "fsharp.debugDefaultProject", "group": "fsharp", - "when": "fsharp.project.any \u0026\u0026 config.FSharp.enableTouchBar && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 config.FSharp.enableTouchBar \u0026\u0026 fsharp.debugger.available" }, { "command": "fsharp.runDefaultProject", "group": "fsharp", - "when": "fsharp.project.any \u0026\u0026 config.FSharp.enableTouchBar && fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 config.FSharp.enableTouchBar \u0026\u0026 fsharp.debugger.available" }, { "command": "fsharp.NewProject", @@ -1466,7 +1476,7 @@ { "command": "fsharp.explorer.solution.clean", "group": "1_navigation@3", - "when": "viewItem == ionide.projectExplorer.solution" + "when": "viewItem == ionide.projectExplorer.solution " }, { "command": "fsharp.explorer.solution.restore", @@ -1546,12 +1556,12 @@ { "command": "fsharp.explorer.project.debug", "group": "1_run@2", - "when": "viewItem == ionide.projectExplorer.projectExe && fsharp.debugger.available" + "when": "viewItem == ionide.projectExplorer.projectExe \u0026\u0026 fsharp.debugger.available" }, { "command": "fsharp.explorer.project.debug", "group": "inline@2", - "when": "viewItem == ionide.projectExplorer.projectExe && fsharp.debugger.available" + "when": "viewItem == ionide.projectExplorer.projectExe \u0026\u0026 fsharp.debugger.available" }, { "command": "fsharp.explorer.project.setDefault", From ba0db66223c55615b4872af9b976b7dd368be0c1 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Sat, 19 Aug 2023 15:59:10 -0500 Subject: [PATCH 14/14] reenable build commands, and make debug commands more reactive --- release/package.json | 84 +++++++++++++--------------------- src/Components/Debugger.fs | 94 +++++++++++++++++++------------------- src/Components/MSBuild.fs | 93 +++++++++++++++---------------------- 3 files changed, 119 insertions(+), 152 deletions(-) diff --git a/release/package.json b/release/package.json index 1efbcd08..8ff592c2 100644 --- a/release/package.json +++ b/release/package.json @@ -155,53 +155,43 @@ }, { "command": "MSBuild.buildCurrent", - "title": "MSBuild: Build current project", - "when": "fsharp.debugger.available" + "title": "MSBuild: Build current project" }, { "command": "MSBuild.buildSelected", - "title": "MSBuild: Build project", - "when": "fsharp.debugger.available" + "title": "MSBuild: Build project" }, { "command": "MSBuild.rebuildCurrent", - "title": "MSBuild: Rebuild current project", - "when": "fsharp.debugger.available" + "title": "MSBuild: Rebuild current project" }, { "command": "MSBuild.rebuildSelected", - "title": "MSBuild: Rebuild project", - "when": "fsharp.debugger.available" + "title": "MSBuild: Rebuild project" }, { "command": "MSBuild.cleanCurrent", - "title": "MSBuild: Clean current project", - "when": "fsharp.debugger.available" + "title": "MSBuild: Clean current project" }, { "command": "MSBuild.cleanSelected", - "title": "MSBuild: Clean project", - "when": "fsharp.debugger.available" + "title": "MSBuild: Clean project" }, { "command": "MSBuild.restoreSelected", - "title": "MSBuild: Restore project", - "when": "fsharp.debugger.available" + "title": "MSBuild: Restore project" }, { "command": "MSBuild.buildCurrentSolution", - "title": "MSBuild: Build current solution", - "when": "fsharp.debugger.available" + "title": "MSBuild: Build current solution" }, { "command": "MSBuild.rebuildCurrentSolution", - "title": "MSBuild: Rebuild current solution", - "when": "fsharp.debugger.available" + "title": "MSBuild: Rebuild current solution" }, { "command": "MSBuild.cleanCurrentSolution", - "title": "MSBuild: Clean current solution", - "when": "fsharp.debugger.available" + "title": "MSBuild: Clean current solution" }, { "command": "fsharp.explorer.moveUp", @@ -294,43 +284,35 @@ }, { "command": "fsharp.explorer.msbuild.build", - "title": "Build", - "enablement": "fsharp.debugger.available" + "title": "Build" }, { "command": "fsharp.explorer.msbuild.rebuild", - "title": "Rebuild", - "enablement": "fsharp.debugger.available" + "title": "Rebuild" }, { "command": "fsharp.explorer.msbuild.clean", - "title": "Clean", - "enablement": "fsharp.debugger.available" + "title": "Clean" }, { "command": "fsharp.explorer.msbuild.restore", - "title": "Restore", - "enablement": "fsharp.debugger.available" + "title": "Restore" }, { "command": "fsharp.explorer.solution.build", - "title": "Build", - "enablement": "fsharp.debugger.available" + "title": "Build" }, { "command": "fsharp.explorer.solution.rebuild", - "title": "Rebuild", - "enablement": "fsharp.debugger.available" + "title": "Rebuild" }, { "command": "fsharp.explorer.solution.clean", - "title": "Clean", - "enablement": "fsharp.debugger.available" + "title": "Clean" }, { "command": "fsharp.explorer.solution.restore", - "title": "Restore", - "enablement": "fsharp.debugger.available" + "title": "Restore" }, { "command": "fsharp.explorer.project.run", @@ -988,12 +970,12 @@ { "command": "MSBuild.buildCurrent", "key": "ctrl\u002Balt\u002Bb", - "when": "fsharp.project.any \u0026\u0026 editorFocus \u0026\u0026 editorLangId == \u0027fsharp\u0027 \u0026\u0026 fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 editorFocus \u0026\u0026 editorLangId == \u0027fsharp\u0027" }, { "command": "MSBuild.buildCurrentSolution", "key": "ctrl\u002Balt\u002Bshift\u002Bb", - "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" + "when": "fsharp.project.any" }, { "command": "fsharp.openInfoPanel", @@ -1185,15 +1167,15 @@ }, { "command": "MSBuild.buildCurrent", - "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 \u0026\u0026 fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027" }, { "command": "MSBuild.rebuildCurrent", - "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 \u0026\u0026 fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027" }, { "command": "MSBuild.cleanCurrent", - "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027 \u0026\u0026 fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 editorLangId == \u0027fsharp\u0027" }, { "command": "fsharp.clearCache", @@ -1201,35 +1183,35 @@ }, { "command": "MSBuild.buildSelected", - "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" + "when": "fsharp.project.any" }, { "command": "MSBuild.rebuildSelected", - "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" + "when": "fsharp.project.any" }, { "command": "MSBuild.cleanSelected", - "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" + "when": "fsharp.project.any" }, { "command": "MSBuild.restoreSelected", - "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" + "when": "fsharp.project.any" }, { "command": "MSBuild.buildCurrentSolution", - "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" + "when": "fsharp.project.any" }, { "command": "MSBuild.rebuildCurrentSolution", - "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" + "when": "fsharp.project.any" }, { "command": "MSBuild.cleanCurrentSolution", - "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" + "when": "fsharp.project.any" }, { "command": "fsharp.runDefaultProject", - "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" + "when": "fsharp.project.any" }, { "command": "fsharp.debugDefaultProject", @@ -1237,7 +1219,7 @@ }, { "command": "fsharp.chooseDefaultProject", - "when": "fsharp.project.any \u0026\u0026 fsharp.debugger.available" + "when": "fsharp.project.any" }, { "command": "fsharp.NewProject", @@ -1286,7 +1268,7 @@ { "command": "fsharp.runDefaultProject", "group": "fsharp", - "when": "fsharp.project.any \u0026\u0026 config.FSharp.enableTouchBar \u0026\u0026 fsharp.debugger.available" + "when": "fsharp.project.any \u0026\u0026 config.FSharp.enableTouchBar" }, { "command": "fsharp.NewProject", diff --git a/src/Components/Debugger.fs b/src/Components/Debugger.fs index 777afe73..2aa9cf05 100644 --- a/src/Components/Debugger.fs +++ b/src/Components/Debugger.fs @@ -336,34 +336,39 @@ module Debugger = { new DebugConfigurationProvider with override x.provideDebugConfigurations(folder: option, token: option) = let generate () = - promise { - logger.Info("Evaluating launch settings configurations for %O", folder) - let projects = Project.getLoaded () - let! msbuildTasks = tasks.fetchTasks (msbuildTasksFilter) - - let tasks = - projects - |> List.collect (fun (p: Project) -> - [ let projectFile = node.path.basename p.Project - - let buildTaskForProject = - msbuildTasks - |> Seq.tryFind (fun t -> - t.group = Some vscode.TaskGroup.Build && t.name = projectFile) - // emit configurations for any launchsettings for this project - match readSettingsForProject p with - | Some launchSettings -> - yield! configsForProject (p, launchSettings, buildTaskForProject) - | None -> () - // emit a default configuration for this project if it is an executable - match defaultConfigForProject (p, buildTaskForProject) with - | Some p -> yield p - | None -> () ]) - - return ResizeArray tasks - } - - generate () // this bix/unbox is a hack because JS types + match CSharpExtension.tryFindCSharpExtension () with + | false -> + CSharpExtension.warnAboutMissingCSharpExtension () + promise { return ResizeArray() } + | true -> + promise { + logger.Info("Evaluating launch settings configurations for %O", folder) + let projects = Project.getLoaded () + let! msbuildTasks = tasks.fetchTasks (msbuildTasksFilter) + + let tasks = + projects + |> List.collect (fun (p: Project) -> + [ let projectFile = node.path.basename p.Project + + let buildTaskForProject = + msbuildTasks + |> Seq.tryFind (fun t -> + t.group = Some vscode.TaskGroup.Build && t.name = projectFile) + // emit configurations for any launchsettings for this project + match readSettingsForProject p with + | Some launchSettings -> + yield! configsForProject (p, launchSettings, buildTaskForProject) + | None -> () + // emit a default configuration for this project if it is an executable + match defaultConfigForProject (p, buildTaskForProject) with + | Some p -> yield p + | None -> () ]) + + return ResizeArray tasks + } + + generate () // this box/unbox is a hack because JS types |> box |> unbox @@ -387,26 +392,23 @@ module Debugger = let activate (c: ExtensionContext) = - match CSharpExtension.tryFindCSharpExtension () with - | false -> CSharpExtension.warnAboutMissingCSharpExtension () - | true -> - commands.registerCommand ("fsharp.runDefaultProject", (buildAndRunDefault) |> objfy2) - |> c.Subscribe + commands.registerCommand ("fsharp.runDefaultProject", (buildAndRunDefault) |> objfy2) + |> c.Subscribe - commands.registerCommand ("fsharp.debugDefaultProject", (buildAndDebugDefault) |> objfy2) - |> c.Subscribe + commands.registerCommand ("fsharp.debugDefaultProject", (buildAndDebugDefault) |> objfy2) + |> c.Subscribe - commands.registerCommand ("fsharp.chooseDefaultProject", (chooseDefaultProject) |> objfy2) - |> c.Subscribe + commands.registerCommand ("fsharp.chooseDefaultProject", (chooseDefaultProject) |> objfy2) + |> c.Subscribe - logger.Info "registering debug provider" + logger.Info "registering debug provider" - debug.registerDebugConfigurationProvider ( - "coreclr", - launchSettingProvider, - DebugConfigurationProviderTriggerKind.Dynamic - ) - |> c.Subscribe + debug.registerDebugConfigurationProvider ( + "coreclr", + launchSettingProvider, + DebugConfigurationProviderTriggerKind.Dynamic + ) + |> c.Subscribe - context <- Some c - startup <- c.workspaceState.get "defaultProject" + context <- Some c + startup <- c.workspaceState.get "defaultProject" diff --git a/src/Components/MSBuild.fs b/src/Components/MSBuild.fs index 2c0cd633..c24bc0a0 100644 --- a/src/Components/MSBuild.fs +++ b/src/Components/MSBuild.fs @@ -527,69 +527,52 @@ module MSBuild = let initWorkspace _n = Project.initWorkspace () - match CSharpExtension.tryFindCSharpExtension () with - | false -> CSharpExtension.warnAboutMissingCSharpExtension () - | true -> + let solutionWatcher = workspace.createFileSystemWatcher (U2.Case1 "**/*.sln") - let solutionWatcher = workspace.createFileSystemWatcher (U2.Case1 "**/*.sln") + solutionWatcher.onDidCreate.Invoke(fun n -> unlessIgnored n.fsPath initWorkspace |> unbox) + |> ignore - solutionWatcher.onDidCreate.Invoke(fun n -> unlessIgnored n.fsPath initWorkspace |> unbox) - |> ignore - - solutionWatcher.onDidChange.Invoke(fun n -> unlessIgnored n.fsPath initWorkspace |> unbox) - |> ignore - - //Restore any project that returns NotRestored status - Project.projectNotRestoredLoaded.Invoke(fun n -> restoreProjectAsync n |> unbox) - |> context.Subscribe + solutionWatcher.onDidChange.Invoke(fun n -> unlessIgnored n.fsPath initWorkspace |> unbox) + |> ignore - let registerCommand com (action: unit -> _) = - commands.registerCommand (com, action |> objfy2) |> context.Subscribe + //Restore any project that returns NotRestored status + Project.projectNotRestoredLoaded.Invoke(fun n -> restoreProjectAsync n |> unbox) + |> context.Subscribe - let registerCommand2 com (action: obj -> obj -> _) = - commands.registerCommand (com, action |> objfy3) |> context.Subscribe + let registerCommand com (action: unit -> _) = + commands.registerCommand (com, action |> objfy2) |> context.Subscribe - /// typed msbuild cmd. Optional project and msbuild host - let typedMsbuildCmd f projOpt = - let p = - if JS.isDefined projOpt then - Some(unbox (projOpt)) - else - None + tasks.registerTaskProvider ("msbuild", msbuildBuildTaskProvider) + |> context.Subscribe - fun _ -> f p + registerCommand "MSBuild.buildCurrent" (fun _ -> buildCurrentProject "Build") + registerCommand "MSBuild.rebuildCurrent" (fun _ -> buildCurrentProject "Rebuild") + registerCommand "MSBuild.cleanCurrent" (fun _ -> buildCurrentProject "Clean") - tasks.registerTaskProvider ("msbuild", msbuildBuildTaskProvider) - |> context.Subscribe + registerCommand "MSBuild.buildCurrentSolution" (fun _ -> buildCurrentSolution "Build") + registerCommand "MSBuild.rebuildCurrentSolution" (fun _ -> buildCurrentSolution "Rebuild") + registerCommand "MSBuild.cleanCurrentSolution" (fun _ -> buildCurrentSolution "Clean") - registerCommand "MSBuild.buildCurrent" (fun _ -> buildCurrentProject "Build") - registerCommand "MSBuild.rebuildCurrent" (fun _ -> buildCurrentProject "Rebuild") - registerCommand "MSBuild.cleanCurrent" (fun _ -> buildCurrentProject "Clean") - - registerCommand "MSBuild.buildCurrentSolution" (fun _ -> buildCurrentSolution "Build") - registerCommand "MSBuild.rebuildCurrentSolution" (fun _ -> buildCurrentSolution "Rebuild") - registerCommand "MSBuild.cleanCurrentSolution" (fun _ -> buildCurrentSolution "Clean") - - commands.registerCommand ( - "MSBuild.buildSelected", - fun _ -> buildProject "Build" |> Promise.map box |> box |> Some - ) - |> context.Subscribe + commands.registerCommand ( + "MSBuild.buildSelected", + fun _ -> buildProject "Build" |> Promise.map box |> box |> Some + ) + |> context.Subscribe - commands.registerCommand ( - "MSBuild.rebuildSelected", - fun _ -> buildProject "Rebuild" |> Promise.map box |> box |> Some - ) - |> context.Subscribe + commands.registerCommand ( + "MSBuild.rebuildSelected", + fun _ -> buildProject "Rebuild" |> Promise.map box |> box |> Some + ) + |> context.Subscribe - commands.registerCommand ( - "MSBuild.cleanSelected", - fun _ -> buildProject "Clean" |> Promise.map box |> box |> Some - ) - |> context.Subscribe + commands.registerCommand ( + "MSBuild.cleanSelected", + fun _ -> buildProject "Clean" |> Promise.map box |> box |> Some + ) + |> context.Subscribe - commands.registerCommand ( - "MSBuild.restoreSelected", - fun _ -> restoreProjectCmd () |> Promise.map box |> box |> Some - ) - |> context.Subscribe + commands.registerCommand ( + "MSBuild.restoreSelected", + fun _ -> restoreProjectCmd () |> Promise.map box |> box |> Some + ) + |> context.Subscribe