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

Break direct C# dependency and instead light up debug/build functionality at runtime #1903

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
74 changes: 41 additions & 33 deletions release/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -1165,59 +1175,59 @@
},
{
"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",
"when": "fsharp.project.any"
},
{
"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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -1733,9 +1743,7 @@
"engines": {
"vscode": "^0.10.0"
},
"extensionDependencies": [
"ms-dotnettools.csharp"
],
"extensionDependencies": [],
"homepage": "http://ionide.io",
"icon": "images/logo.png",
"license": "MIT",
Expand All @@ -1748,4 +1756,4 @@
"url": "https://github.com/ionide/ionide-vscode-fsharp.git"
},
"version": "7.8.5"
}
}
51 changes: 51 additions & 0 deletions src/Components/CSharpExtensionSupport.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace Ionide.VSCode.FSharp

open Fable.Import.VSCode.Vscode

module CSharpExtension =

let private msCSharpExtensionName = "ms-vscode.csharp"
let private openvsixCSharpExtensionName = "ms-vscode.csharp"

let private resolvedCSharpExtensionName =
if env.appName = "VS Code" then msCSharpExtensionName else openvsixCSharpExtensionName

let mutable private hasLookedForCSharp = false
let mutable private hasCSharp = false
let mutable private csharpExtension: Extension<obj> = null
let mutable private hasWarned = false

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
match extensions.getExtension resolvedCSharpExtensionName with
| None ->
csharpAvailableContext false
| Some e ->
csharpExtension <- e
csharpAvailableContext true
hasLookedForCSharp <- true
hasCSharp

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

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
)
34 changes: 19 additions & 15 deletions src/Components/Debugger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> "defaultProject"
debug.registerDebugConfigurationProvider (
"coreclr",
launchSettingProvider,
DebugConfigurationProviderTriggerKind.Dynamic
)
|> c.Subscribe

context <- Some c
startup <- c.workspaceState.get<Project> "defaultProject"
Loading