forked from ionide/ionide-vscode-fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsharp.fs
144 lines (119 loc) · 5.61 KB
/
fsharp.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Ionide.VSCode.FSharp
open System
open Fable.Core
open Fable.Core.JsInterop
open Fable.Import.VSCode
open Fable.Import.VSCode.Vscode
open Ionide.VSCode.Helpers
open Ionide.VSCode.FSharp
open Node.ChildProcess
let private logger =
ConsoleAndOutputChannelLogger(Some "Main", Level.DEBUG, Some defaultOutputChannel, Some Level.DEBUG)
type Api =
{ ProjectLoadedEvent: Event<DTO.Project>
BuildProject: DTO.Project -> JS.Promise<string>
BuildProjectFast: DTO.Project -> JS.Promise<string>
GetProjectLauncher: OutputChannel -> DTO.Project -> (string list -> JS.Promise<ChildProcess>) option
DebugProject: DTO.Project -> string[] -> JS.Promise<unit> }
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<Api> =
let solutionExplorer = "FSharp.enableTreeView" |> Configuration.get true
let showExplorer = "FSharp.showExplorerOnStartup" |> Configuration.get false
let tryActivate label activationFn =
fun ctx ->
try
activationFn ctx
with ex ->
logger.Error $"Error while activating feature '{label}': {ex}"
Unchecked.defaultof<_>
LanguageService.start context
|> Promise.catch (fun e -> logger.Error $"Error activating FSAC: %A{e}") // prevent unhandled rejected promises
|> Promise.onSuccess (fun _ ->
let progressOpts = createEmpty<ProgressOptions>
progressOpts.location <- U2.Case1 ProgressLocation.Window
logger.Debug "Activating features"
window.withProgress (
progressOpts,
(fun p ctok ->
let pm =
{| message = Some "Loading projects"
increment = None |}
p.report pm
Project.activate context
|> Promise.catch (fun e -> logger.Error $"Error loading projects: %A{e}")
|> Promise.onSuccess (fun _ -> tryActivate "quickinfoproject" QuickInfoProject.activate context)
|> Promise.bind (fun _ ->
if showExplorer then
commands.executeCommand (VSCodeExtension.workbenchViewId ())
|> Promise.ofThenable
else
Promise.lift None)
|> Promise.bind (fun _ -> tryActivate "analyzers" LanguageService.loadAnalyzers ())
|> Promise.catch (fun e ->
logger.Error $"Error loading all projects: %A{e}"
let pm =
{| message = Some "Error loading projects"
increment = None |}
p.report pm)
|> Promise.toThenable)
)
|> ignore)
|> Promise.map (fun _ ->
if solutionExplorer then
tryActivate "solutionExplorer" SolutionExplorer.activate context
tryActivate "fsprojedit" FsProjEdit.activate context
tryActivate "diagnostics" Diagnostics.activate context
tryActivate "linelens" LineLens.Instance.activate context
tryActivate "quickinfo" QuickInfo.activate context
tryActivate "help" Help.activate context
tryActivate "msbuild" MSBuild.activate context
tryActivate "signaturedata" SignatureData.activate context
tryActivate "debugger" Debugger.activate context
tryActivate "fsdn" Fsdn.activate context
tryActivate "fsi" Fsi.activate context
tryActivate "scriptrunner" ScriptRunner.activate context
tryActivate "languageconfiguration" LanguageConfiguration.activate context
tryActivate "htmlconverter" HtmlConverter.activate context
tryActivate "infopanel" InfoPanel.activate context
tryActivate "codelens" CodeLensHelpers.activate context
tryActivate "gitignore" Gitignore.activate context
tryActivate "pipelinehints" PipelineHints.Instance.activate context
tryActivate "testExplorer" TestExplorer.activate context
tryActivate "inlayhints" InlayHints.activate context
tryActivate "languageservice" activateLanguageServiceRestart context
let buildProject project =
promise {
let! exit = MSBuild.buildProjectPath "Build" project
match exit.Code with
| Some code -> return code.ToString()
| None -> return ""
}
let buildProjectFast project =
promise {
let! exit = MSBuild.buildProjectPathFast project
match exit.Code with
| Some code -> return code.ToString()
| None -> return ""
}
let event = vscode.EventEmitter.Create<DTO.Project>()
Project.projectLoaded.Invoke(fun n -> !!(setTimeout (fun _ -> event.fire n) 500.))
|> ignore
{ ProjectLoadedEvent = event.event
BuildProject = buildProject
BuildProjectFast = buildProjectFast
GetProjectLauncher = Project.getLauncher
DebugProject = Debugger.debugProject })
|> Promise.catch (fun e ->
logger.Error $"Error activating features: %A{e}"
Unchecked.defaultof<_>)
let deactivate (disposables: Disposable[]) = LanguageService.stop ()