Skip to content

Commit 363248c

Browse files
authored
massive refactor/update for new vscode types (ionide#1553)
* massive refactor/update * fix error in handler * cleaner way to handle subscriptions * use terminal profile provider to have nicer UI * simplify registrations * fix typo * fix old registration usage * use ctok * even more type updates * swap back to mainline branch for dependencies
1 parent 842911b commit 363248c

28 files changed

+765
-583
lines changed

.tool-versions

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yarn 1.22.10
2+
nodejs 12.16.3

paket.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ GIT
5252
(fc4cac6d9bc1787f54ce48bbc77bcbb1de8160ff)
5353
GITHUB
5454
remote: ionide/ionide-vscode-helpers
55-
src/Fable.Import.Showdown.fs (3c6cc652db8f2d58d54636595679149904f93c31)
56-
src/Fable.Import.VSCode.fs (3c6cc652db8f2d58d54636595679149904f93c31)
57-
src/Fable.Import.VSCode.LanguageServer.fs (3c6cc652db8f2d58d54636595679149904f93c31)
58-
src/Helpers.fs (3c6cc652db8f2d58d54636595679149904f93c31)
55+
src/Fable.Import.Showdown.fs (58d7e3899a0402f86f4f52c0315152f5d44e6753)
56+
src/Fable.Import.VSCode.fs (58d7e3899a0402f86f4f52c0315152f5d44e6753)
57+
src/Fable.Import.VSCode.LanguageServer.fs (58d7e3899a0402f86f4f52c0315152f5d44e6753)
58+
src/Helpers.fs (58d7e3899a0402f86f4f52c0315152f5d44e6753)
5959
GROUP build
6060
STORAGE: NONE
6161
RESTRICTION: == netstandard2.0

src/Components/CodeLensHelpers.fs

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ namespace Ionide.VSCode.FSharp
22

33
open System
44
open Fable.Core.JsInterop
5-
open Fable.Import.vscode
5+
open Fable.Import.VSCode
6+
open Fable.Import.VSCode.Vscode
67
open global.Node
78

89
module node = Node.Api
910

1011
module CodeLensHelpers =
1112

1213
let showReferences (args: string) (args2: obj) (args3: obj[]) =
13-
let uri = Uri.parse args
14-
let pos = Position(!!args2?Line, !!args2?Character)
14+
let uri = vscode.Uri.parse args
15+
let pos = vscode.Position.Create(!!args2?Line, !!args2?Character)
1516
let locs =
1617
args3
1718
|> Seq.map (fun f ->
18-
let uri = Uri.parse !!f?Uri
19-
let range = Range(!!f?Range?Start?Line, !!f?Range?Start?Character, !!f?Range?End?Line, !!f?Range?End?Character)
20-
Location(uri, !^ range)
19+
let uri = vscode.Uri.parse !!f?Uri
20+
let range = vscode.Range.Create(!!f?Range?Start?Line, !!f?Range?Start?Character, !!f?Range?End?Line, !!f?Range?End?Character)
21+
vscode.Location.Create(uri, !^ range)
2122
)
2223
|> ResizeArray
23-
commands.executeCommand("editor.action.showReferences", uri, pos, locs )
24+
commands.executeCommand("editor.action.showReferences", Some (box uri), Some (box pos), Some (box locs))
2425

2526
let activate (context : ExtensionContext) =
26-
27-
commands.registerCommand("fsharp.showReferences", showReferences |> objfy4 ) |> context.subscriptions.Add
27+
commands.registerCommand("fsharp.showReferences", showReferences |> objfy4 ) |> context.Subscribe

src/Components/Debugger.fs

+19-16
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ namespace Ionide.VSCode.FSharp
33
open Fable.Core
44
open Fable.Core.JsInterop
55
open Fable.Import
6-
open Fable.Import.vscode
6+
open Fable.Import.VSCode
7+
open Fable.Import.VSCode.Vscode
78
open global.Node
89
open Ionide.VSCode.Helpers
910
open DTO
@@ -48,8 +49,8 @@ module LaunchJsonVersion2 =
4849

4950
let assertVersion2 (cfg : WorkspaceConfiguration) =
5051
promise {
51-
do! cfg.update("version", "0.2.0", false)
52-
do! cfg.update("configurations", ResizeArray<obj>(), false)
52+
do! cfg.update("version", Some (box "0.2.0"), U2.Case2 false)
53+
do! cfg.update("configurations", Some (box (ResizeArray<obj>())), U2.Case2 false)
5354
}
5455

5556
module Debugger =
@@ -60,15 +61,15 @@ module Debugger =
6061
let launcher = Project.getLauncherWithShell project
6162
match launcher with
6263
| None ->
63-
window.showWarningMessage "Can't start project"
64+
window.showWarningMessage("Can't start project", null)
6465
|> ignore
6566
| Some l ->
6667
let! terminal = l ""
6768
terminal.show()
6869
}
6970

7071
let setProgramPath project (cfg : LaunchJsonVersion2.RequestLaunch) =
71-
let relativeOutPath = node.path.relative(workspace.rootPath, project.Output).Replace("\\", "/")
72+
let relativeOutPath = node.path.relative(workspace.rootPath.Value, project.Output).Replace("\\", "/")
7273
let programPath = sprintf "${workspaceRoot}/%s" relativeOutPath
7374

7475
// WORKAROUND the project.Output is the obj assembly, instead of bin assembly
@@ -87,16 +88,18 @@ module Debugger =
8788
let cfg = LaunchJsonVersion2.createRequestLaunch ()
8889
match debuggerRuntime project with
8990
| None ->
90-
window.showWarningMessage "Can't start debugger"
91+
window.showWarningMessage("Can't start debugger", null)
9192
|> ignore
9293
| Some rntm ->
9394
cfg |> setProgramPath project
9495
cfg?``type`` <- rntm
9596
cfg?preLaunchTask <- None
9697
cfg?args <- args
9798

98-
let folder = workspace.workspaceFolders.[0]
99-
let! _ = debug.startDebugging(folder, unbox cfg)
99+
let debugConfiguration = cfg |> box |> unbox
100+
101+
let folder = workspace.workspaceFolders.Value.[0]
102+
let! _ = debug.startDebugging(Some folder, U2.Case2 debugConfiguration)
100103
return ()
101104
}
102105

@@ -107,21 +110,21 @@ module Debugger =
107110
let cfg = LaunchJsonVersion2.createRequestLaunch ()
108111
match debuggerRuntime project with
109112
| None ->
110-
window.showWarningMessage "Can't start debugger"
113+
window.showWarningMessage("Can't start debugger", null)
111114
|> ignore
112115
| Some rntm ->
113116
cfg |> setProgramPath project
114117
cfg?``type`` <- rntm
115118
cfg?preLaunchTask <- None
119+
let debugConfiguration = cfg |> box |> unbox
116120

117-
let folder = workspace.workspaceFolders.[0]
121+
let folder = workspace.workspaceFolders.Value.[0]
118122
let! msbuildExit = MSBuild.buildProjectPath "Build" project
119123
match msbuildExit.Code with
120124
| Some code when code <> 0 ->
121125
return! Promise.reject (sprintf "msbuild 'Build' failed with exit code %i" code)
122126
| _ ->
123-
// let! res = vscode.commands.executeCommand("vscode.startDebug", cfg)
124-
let! res = debug.startDebugging(folder, unbox cfg)
127+
let! res = debug.startDebugging(Some folder, U2.Case2 debugConfiguration)
125128
return ()
126129
}
127130

@@ -130,7 +133,7 @@ module Debugger =
130133

131134
let setDefaultProject(project : Project) =
132135
startup <- Some project
133-
context |> Option.iter (fun c -> c.workspaceState.update("defaultProject", project) |> ignore )
136+
context |> Option.iter (fun c -> c.workspaceState.update("defaultProject", Some (box project)) |> ignore )
134137

135138
let chooseDefaultProject () =
136139
promise {
@@ -181,9 +184,9 @@ module Debugger =
181184

182185

183186
let activate (c : ExtensionContext) =
184-
commands.registerCommand("fsharp.runDefaultProject", (buildAndRunDefault) |> objfy2 ) |> c.subscriptions.Add
185-
commands.registerCommand("fsharp.debugDefaultProject", (buildAndDebugDefault) |> objfy2 ) |> c.subscriptions.Add
186-
commands.registerCommand("fsharp.chooseDefaultProject", (chooseDefaultProject) |> objfy2 ) |> c.subscriptions.Add
187+
commands.registerCommand("fsharp.runDefaultProject", (buildAndRunDefault) |> objfy2 ) |> c.Subscribe
188+
commands.registerCommand("fsharp.debugDefaultProject", (buildAndDebugDefault) |> objfy2 ) |> c.Subscribe
189+
commands.registerCommand("fsharp.chooseDefaultProject", (chooseDefaultProject) |> objfy2 ) |> c.Subscribe
187190

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

src/Components/Diagnostics.fs

+27-28
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ namespace Ionide.VSCode.FSharp
33
open System
44
open Fable.Core
55
open Fable.Import
6-
open Fable.Import.vscode
6+
open Fable.Import.VSCode
7+
open Fable.Import.VSCode.Vscode
78
open global.Node
89

910
open Ionide.VSCode.Helpers
@@ -132,18 +133,17 @@ Error: %s
132133

133134
let writeToFile (text : string) =
134135
promise {
135-
let path = node.path.join(workspace.rootPath, "Diagnostic info")
136-
let newFile = Uri.parse ("untitled:" + path)
136+
let path = node.path.join(workspace.rootPath.Value, "Diagnostic info")
137+
let newFile = vscode.Uri.parse ("untitled:" + path)
137138
let! document = newFile |> workspace.openTextDocument
138139

139-
let edit = vscode.WorkspaceEdit()
140-
edit.insert(newFile, vscode.Position(0., 0.), text)
141-
let! success = vscode.workspace.applyEdit(edit)
140+
let edit = vscode.WorkspaceEdit.Create()
141+
edit.insert(newFile, vscode.Position.Create(0., 0.), text)
142+
let! success = workspace.applyEdit(edit)
142143
if success then
143-
vscode.window.showTextDocument(document)
144-
|> ignore
144+
window.showTextDocument(document, ?options = None) |> ignore
145145
else
146-
vscode.window.showErrorMessage("Error when printing diagnostic report.")
146+
window.showErrorMessage("Error when printing diagnostic report.", null)
147147
|> ignore
148148
}
149149

@@ -175,32 +175,31 @@ Error: %s
175175
writeStream.write(Logging.getIonideLogs ()) |> ignore
176176
writeStream.close()
177177
)
178-
|> Promise.bind(fun path ->
179-
vscode.window.showInformationMessage(
180-
"FSAC logs exported to: " + path,
181-
"Open file"
182-
)
183-
|> Promise.bind (fun action ->
184-
match action with
185-
| "Open file" ->
186-
path
187-
|> workspace.openTextDocument
188-
|> Promise.bind (fun document ->
189-
vscode.window.showTextDocument(document) |> ignore
190-
JS.undefined
191-
)
192-
| _ -> JS.undefined
193-
)
178+
|> Promise.bind(fun path -> promise {
179+
let! action =
180+
window.showInformationMessage(
181+
"FSAC logs exported to: " + path,
182+
"Open file"
183+
)
184+
match action with
185+
| Some "Open file" ->
186+
return! promise {
187+
let! document = workspace.openTextDocument path
188+
window.showTextDocument(document, ?options = None) |> ignore
189+
return JS.undefined
190+
}
191+
| _ -> return JS.undefined
192+
}
194193
)
195194
|> Promise.onFail(fun error ->
196195
Browser.Dom.console.error(error)
197-
vscode.window.showErrorMessage("Couldn't retrieved the FSAC logs file") |> ignore
196+
window.showErrorMessage("Couldn't retrieved the FSAC logs file", null) |> ignore
198197
)
199198

200199

201200
let activate (context : ExtensionContext) =
202201
commands.registerCommand("fsharp.diagnostics.getInfos", getDiagnosticsInfos |> objfy2)
203-
|> context.subscriptions.Add
202+
|> context.Subscribe
204203

205204
commands.registerCommand("fsharp.diagnostics.getIonideLogs", getIonideLogs |> objfy2)
206-
|> context.subscriptions.Add
205+
|> context.Subscribe

src/Components/FSharpLiterate.fs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace Ionide.VSCode.FSharp
22

3-
open Fable.Import.vscode
3+
open Fable.Import.VSCode
4+
open Fable.Import.VSCode.Vscode
45
open global.Node
56
open Fable.Core.JsInterop
67

@@ -241,7 +242,7 @@ module FSharpLiterate =
241242
let private updatePanel () =
242243
match Panel.panel with
243244
| Some _ ->
244-
let textEditor = window.activeTextEditor
245+
let textEditor = window.activeTextEditor.Value
245246
match textEditor.document with
246247
| Document.FSharpScript | Document.Markdown -> Panel.update textEditor
247248
| _ -> ()
@@ -255,10 +256,10 @@ module FSharpLiterate =
255256
updatePanel ()
256257

257258
let fileSaved (event : TextDocument ) =
258-
if event.fileName = window.activeTextEditor.document.fileName then updatePanel ()
259+
if event.fileName = window.activeTextEditor.Value.document.fileName then updatePanel ()
259260

260261

261262
let activate (context : ExtensionContext) =
262-
workspace.onDidSaveTextDocument.Invoke(unbox fileSaved) |> context.subscriptions.Add
263-
window.onDidChangeActiveTextEditor.Invoke(unbox updatePanel) |> context.subscriptions.Add
264-
commands.registerCommand("fsharp.openFSharpLiterate", openPanel |> objfy2) |> context.subscriptions.Add
263+
workspace.onDidSaveTextDocument.Invoke(unbox fileSaved) |> context.Subscribe
264+
window.onDidChangeActiveTextEditor.Invoke(unbox updatePanel) |> context.Subscribe
265+
commands.registerCommand("fsharp.openFSharpLiterate", openPanel |> objfy2) |> context.Subscribe

0 commit comments

Comments
 (0)