Skip to content

Commit

Permalink
massive refactor/update for new vscode types (#1553)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
baronfel authored Aug 4, 2021
1 parent 842911b commit 363248c
Show file tree
Hide file tree
Showing 28 changed files with 765 additions and 583 deletions.
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
yarn 1.22.10
nodejs 12.16.3
8 changes: 4 additions & 4 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ GIT
(fc4cac6d9bc1787f54ce48bbc77bcbb1de8160ff)
GITHUB
remote: ionide/ionide-vscode-helpers
src/Fable.Import.Showdown.fs (3c6cc652db8f2d58d54636595679149904f93c31)
src/Fable.Import.VSCode.fs (3c6cc652db8f2d58d54636595679149904f93c31)
src/Fable.Import.VSCode.LanguageServer.fs (3c6cc652db8f2d58d54636595679149904f93c31)
src/Helpers.fs (3c6cc652db8f2d58d54636595679149904f93c31)
src/Fable.Import.Showdown.fs (58d7e3899a0402f86f4f52c0315152f5d44e6753)
src/Fable.Import.VSCode.fs (58d7e3899a0402f86f4f52c0315152f5d44e6753)
src/Fable.Import.VSCode.LanguageServer.fs (58d7e3899a0402f86f4f52c0315152f5d44e6753)
src/Helpers.fs (58d7e3899a0402f86f4f52c0315152f5d44e6753)
GROUP build
STORAGE: NONE
RESTRICTION: == netstandard2.0
Expand Down
18 changes: 9 additions & 9 deletions src/Components/CodeLensHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ namespace Ionide.VSCode.FSharp

open System
open Fable.Core.JsInterop
open Fable.Import.vscode
open Fable.Import.VSCode
open Fable.Import.VSCode.Vscode
open global.Node

module node = Node.Api

module CodeLensHelpers =

let showReferences (args: string) (args2: obj) (args3: obj[]) =
let uri = Uri.parse args
let pos = Position(!!args2?Line, !!args2?Character)
let uri = vscode.Uri.parse args
let pos = vscode.Position.Create(!!args2?Line, !!args2?Character)
let locs =
args3
|> Seq.map (fun f ->
let uri = Uri.parse !!f?Uri
let range = Range(!!f?Range?Start?Line, !!f?Range?Start?Character, !!f?Range?End?Line, !!f?Range?End?Character)
Location(uri, !^ range)
let uri = vscode.Uri.parse !!f?Uri
let range = vscode.Range.Create(!!f?Range?Start?Line, !!f?Range?Start?Character, !!f?Range?End?Line, !!f?Range?End?Character)
vscode.Location.Create(uri, !^ range)
)
|> ResizeArray
commands.executeCommand("editor.action.showReferences", uri, pos, locs )
commands.executeCommand("editor.action.showReferences", Some (box uri), Some (box pos), Some (box locs))

let activate (context : ExtensionContext) =

commands.registerCommand("fsharp.showReferences", showReferences |> objfy4 ) |> context.subscriptions.Add
commands.registerCommand("fsharp.showReferences", showReferences |> objfy4 ) |> context.Subscribe
35 changes: 19 additions & 16 deletions src/Components/Debugger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ namespace Ionide.VSCode.FSharp
open Fable.Core
open Fable.Core.JsInterop
open Fable.Import
open Fable.Import.vscode
open Fable.Import.VSCode
open Fable.Import.VSCode.Vscode
open global.Node
open Ionide.VSCode.Helpers
open DTO
Expand Down Expand Up @@ -48,8 +49,8 @@ module LaunchJsonVersion2 =

let assertVersion2 (cfg : WorkspaceConfiguration) =
promise {
do! cfg.update("version", "0.2.0", false)
do! cfg.update("configurations", ResizeArray<obj>(), false)
do! cfg.update("version", Some (box "0.2.0"), U2.Case2 false)
do! cfg.update("configurations", Some (box (ResizeArray<obj>())), U2.Case2 false)
}

module Debugger =
Expand All @@ -60,15 +61,15 @@ module Debugger =
let launcher = Project.getLauncherWithShell project
match launcher with
| None ->
window.showWarningMessage "Can't start project"
window.showWarningMessage("Can't start project", null)
|> ignore
| Some l ->
let! terminal = l ""
terminal.show()
}

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

// WORKAROUND the project.Output is the obj assembly, instead of bin assembly
Expand All @@ -87,16 +88,18 @@ module Debugger =
let cfg = LaunchJsonVersion2.createRequestLaunch ()
match debuggerRuntime project with
| None ->
window.showWarningMessage "Can't start debugger"
window.showWarningMessage("Can't start debugger", null)
|> ignore
| Some rntm ->
cfg |> setProgramPath project
cfg?``type`` <- rntm
cfg?preLaunchTask <- None
cfg?args <- args

let folder = workspace.workspaceFolders.[0]
let! _ = debug.startDebugging(folder, unbox cfg)
let debugConfiguration = cfg |> box |> unbox

let folder = workspace.workspaceFolders.Value.[0]
let! _ = debug.startDebugging(Some folder, U2.Case2 debugConfiguration)
return ()
}

Expand All @@ -107,21 +110,21 @@ module Debugger =
let cfg = LaunchJsonVersion2.createRequestLaunch ()
match debuggerRuntime project with
| None ->
window.showWarningMessage "Can't start debugger"
window.showWarningMessage("Can't start debugger", null)
|> ignore
| Some rntm ->
cfg |> setProgramPath project
cfg?``type`` <- rntm
cfg?preLaunchTask <- None
let debugConfiguration = cfg |> box |> unbox

let folder = workspace.workspaceFolders.[0]
let folder = workspace.workspaceFolders.Value.[0]
let! msbuildExit = MSBuild.buildProjectPath "Build" project
match msbuildExit.Code with
| Some code when code <> 0 ->
return! Promise.reject (sprintf "msbuild 'Build' failed with exit code %i" code)
| _ ->
// let! res = vscode.commands.executeCommand("vscode.startDebug", cfg)
let! res = debug.startDebugging(folder, unbox cfg)
let! res = debug.startDebugging(Some folder, U2.Case2 debugConfiguration)
return ()
}

Expand All @@ -130,7 +133,7 @@ module Debugger =

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

let chooseDefaultProject () =
promise {
Expand Down Expand Up @@ -181,9 +184,9 @@ module Debugger =


let activate (c : ExtensionContext) =
commands.registerCommand("fsharp.runDefaultProject", (buildAndRunDefault) |> objfy2 ) |> c.subscriptions.Add
commands.registerCommand("fsharp.debugDefaultProject", (buildAndDebugDefault) |> objfy2 ) |> c.subscriptions.Add
commands.registerCommand("fsharp.chooseDefaultProject", (chooseDefaultProject) |> objfy2 ) |> c.subscriptions.Add
commands.registerCommand("fsharp.runDefaultProject", (buildAndRunDefault) |> objfy2 ) |> c.Subscribe
commands.registerCommand("fsharp.debugDefaultProject", (buildAndDebugDefault) |> objfy2 ) |> c.Subscribe
commands.registerCommand("fsharp.chooseDefaultProject", (chooseDefaultProject) |> objfy2 ) |> c.Subscribe

context <- Some c
startup <- c.workspaceState.get<Project> "defaultProject"
55 changes: 27 additions & 28 deletions src/Components/Diagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ namespace Ionide.VSCode.FSharp
open System
open Fable.Core
open Fable.Import
open Fable.Import.vscode
open Fable.Import.VSCode
open Fable.Import.VSCode.Vscode
open global.Node

open Ionide.VSCode.Helpers
Expand Down Expand Up @@ -132,18 +133,17 @@ Error: %s

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

let edit = vscode.WorkspaceEdit()
edit.insert(newFile, vscode.Position(0., 0.), text)
let! success = vscode.workspace.applyEdit(edit)
let edit = vscode.WorkspaceEdit.Create()
edit.insert(newFile, vscode.Position.Create(0., 0.), text)
let! success = workspace.applyEdit(edit)
if success then
vscode.window.showTextDocument(document)
|> ignore
window.showTextDocument(document, ?options = None) |> ignore
else
vscode.window.showErrorMessage("Error when printing diagnostic report.")
window.showErrorMessage("Error when printing diagnostic report.", null)
|> ignore
}

Expand Down Expand Up @@ -175,32 +175,31 @@ Error: %s
writeStream.write(Logging.getIonideLogs ()) |> ignore
writeStream.close()
)
|> Promise.bind(fun path ->
vscode.window.showInformationMessage(
"FSAC logs exported to: " + path,
"Open file"
)
|> Promise.bind (fun action ->
match action with
| "Open file" ->
path
|> workspace.openTextDocument
|> Promise.bind (fun document ->
vscode.window.showTextDocument(document) |> ignore
JS.undefined
)
| _ -> JS.undefined
)
|> Promise.bind(fun path -> promise {
let! action =
window.showInformationMessage(
"FSAC logs exported to: " + path,
"Open file"
)
match action with
| Some "Open file" ->
return! promise {
let! document = workspace.openTextDocument path
window.showTextDocument(document, ?options = None) |> ignore
return JS.undefined
}
| _ -> return JS.undefined
}
)
|> Promise.onFail(fun error ->
Browser.Dom.console.error(error)
vscode.window.showErrorMessage("Couldn't retrieved the FSAC logs file") |> ignore
window.showErrorMessage("Couldn't retrieved the FSAC logs file", null) |> ignore
)


let activate (context : ExtensionContext) =
commands.registerCommand("fsharp.diagnostics.getInfos", getDiagnosticsInfos |> objfy2)
|> context.subscriptions.Add
|> context.Subscribe

commands.registerCommand("fsharp.diagnostics.getIonideLogs", getIonideLogs |> objfy2)
|> context.subscriptions.Add
|> context.Subscribe
13 changes: 7 additions & 6 deletions src/Components/FSharpLiterate.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Ionide.VSCode.FSharp

open Fable.Import.vscode
open Fable.Import.VSCode
open Fable.Import.VSCode.Vscode
open global.Node
open Fable.Core.JsInterop

Expand Down Expand Up @@ -241,7 +242,7 @@ module FSharpLiterate =
let private updatePanel () =
match Panel.panel with
| Some _ ->
let textEditor = window.activeTextEditor
let textEditor = window.activeTextEditor.Value
match textEditor.document with
| Document.FSharpScript | Document.Markdown -> Panel.update textEditor
| _ -> ()
Expand All @@ -255,10 +256,10 @@ module FSharpLiterate =
updatePanel ()

let fileSaved (event : TextDocument ) =
if event.fileName = window.activeTextEditor.document.fileName then updatePanel ()
if event.fileName = window.activeTextEditor.Value.document.fileName then updatePanel ()


let activate (context : ExtensionContext) =
workspace.onDidSaveTextDocument.Invoke(unbox fileSaved) |> context.subscriptions.Add
window.onDidChangeActiveTextEditor.Invoke(unbox updatePanel) |> context.subscriptions.Add
commands.registerCommand("fsharp.openFSharpLiterate", openPanel |> objfy2) |> context.subscriptions.Add
workspace.onDidSaveTextDocument.Invoke(unbox fileSaved) |> context.Subscribe
window.onDidChangeActiveTextEditor.Invoke(unbox updatePanel) |> context.Subscribe
commands.registerCommand("fsharp.openFSharpLiterate", openPanel |> objfy2) |> context.Subscribe
Loading

0 comments on commit 363248c

Please sign in to comment.