Skip to content

Commit

Permalink
Test explorer (#1671)
Browse files Browse the repository at this point in the history
Co-authored-by: Krzysztof-Cieslak <krzysztof_cieslak@windowslive.com>
Co-authored-by: Chet Husk <chusk3@gmail.com>
  • Loading branch information
3 people authored Apr 14, 2022
1 parent 3871171 commit 639b9c0
Show file tree
Hide file tree
Showing 17 changed files with 596 additions and 62 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",
"ws": "^7.3.1",
"xhr2": "^0.2.0"
"xhr2": "^0.2.0",
"xmldom": "^0.6.0",
"xpath": "^0.0.32"
},
"engines": {
"node": ">=14.0.0"
}
}
}
2 changes: 1 addition & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ nuget Thoth.Json

git https://github.com/ionide/ionide-fsgrammar.git master

github ionide/ionide-vscode-helpers src/Fable.Import.VSCode.fs
github ionide/ionide-vscode-helpers:c307f41dff3ca1f68b6327c3945e361323667300 src/Fable.Import.VSCode.fs
github ionide/ionide-vscode-helpers src/Helpers.fs
github ionide/ionide-vscode-helpers src/Fable.Import.Showdown.fs
github ionide/ionide-vscode-helpers src/Fable.Import.VSCode.LanguageServer.fs
Expand Down
21 changes: 11 additions & 10 deletions src/Components/Fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ module Fsi =
let! choice =
window.showInformationMessage (
"You are running .Net Core version of FsAutoComplete, we recommend also using .Net Core version of F# REPL (`dotnet fsi`). Should we change your settings (`FSharp.useSdkScripts`). This requires .Net Core 3.X?",
"Update settings",
"Ignore",
"Don't show again"
[| Message.choice "Update settings"
Message.choice "Ignore"
Message.choice "Don't show again" |]
)

match choice with
| Some "Update settings" -> do! setUseSdk ()
| Some "Ignore" -> do! disablePromptForProject ()
| Some "Don't show again" -> do! disablePromptGlobally ()
| Some (HasTitle "Update settings") -> do! setUseSdk ()
| Some (HasTitle "Ignore") -> do! disablePromptForProject ()
| Some (HasTitle "Don't show again") -> do! disablePromptGlobally ()
| _ -> ()
}

Expand Down Expand Up @@ -102,12 +102,13 @@ module Fsi =
let! res =
window.showInformationMessage (
"FSI Watcher is an experimental feature, and it needs to be enabled with `FSharp.addFsiWatcher` setting",
"Enable",
"Ignore"
[| Message.choice "Enable"
Message.choice "Ignore" |]
)

if res = Some "Enable" then
do! Configuration.setGlobal "FSharp.addFsiWatcher" (Some(box true))
match res with
| Some (HasTitle "Enable") -> do! Configuration.setGlobal "FSharp.addFsiWatcher" (Some(box true))
| _ -> ()
else
match panel with
| Some p -> p.reveal (!! -2, true)
Expand Down
14 changes: 8 additions & 6 deletions src/Components/Gitignore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Gitignore =
open Fable.Import.VSCode
open Fable.Import.VSCode.Vscode
open Ionide.VSCode.FSharp
open Fable.Core.JsInterop

let GITIGNORE_KEY = "FSharp.suggestGitignore"

Expand Down Expand Up @@ -66,18 +67,19 @@ module Gitignore =
| FileNotFound -> ()
| MissingPatterns [] -> ()
| MissingPatterns patternsToAdd ->

let! choice =
window.showInformationMessage (
"You are missing entries in your .gitignore for Ionide-specific data files. Would you like to add them?",
"Add entries",
"Ignore",
"Don't show again"
[| Message.choice "Add entries"
Message.choice "Ignore"
Message.choice "Don't show again" |]
)

match choice with
| Some "Add entries" -> writePatternsToGitignore patternsToAdd
| Some "Ignore" -> do! disablePromptForProject ()
| Some "Don't show again" -> do! disablePromptGlobally ()
| Some (HasTitle "Add entries") -> writePatternsToGitignore patternsToAdd
| Some (HasTitle "Ignore") -> do! disablePromptForProject ()
| Some (HasTitle "Don't show again") -> do! disablePromptGlobally ()
| _ -> ()
}

Expand Down
77 changes: 54 additions & 23 deletions src/Components/InlayHints.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@ open Fable.Core.JsInterop
let private logger =
ConsoleAndOutputChannelLogger(Some "InlayHints", Level.DEBUG, None, Some Level.DEBUG)

let enabled() : bool =
let enabled () : bool =
Configuration.getUnsafe "FSharp.inlayHints.enabled"


let allowTypeAnnotations() : bool =
let allowTypeAnnotations () : bool =
Configuration.getUnsafe "FSharp.inlayHints.typeAnnotations"

let allowParameterNames(): bool =
let allowParameterNames () : bool =
Configuration.getUnsafe "FSharp.inlayHints.parameterNames"

let actuallyEnabled() =
enabled() && (allowTypeAnnotations() || allowParameterNames())
let actuallyEnabled () =
enabled ()
&& (allowTypeAnnotations () || allowParameterNames ())

let toInlayHint (fsacHint: LanguageService.Types.InlayHint): InlayHint =
let toInlayHint (fsacHint: LanguageService.Types.InlayHint) : InlayHint =
let h = createEmpty<InlayHint>
h.position <- vscode.Position.Create(fsacHint.pos.line, fsacHint.pos.character)
h.label <- U2.Case1 fsacHint.text

match fsacHint.kind with
| "Type" ->
h.paddingLeft <- Some true
Expand All @@ -34,52 +36,81 @@ let toInlayHint (fsacHint: LanguageService.Types.InlayHint): InlayHint =
h.paddingRight <- Some true
h.kind <- Some InlayHintKind.Parameter
| _ -> ()

h

let inlayProvider () =
let events = vscode.EventEmitter.Create()
let mutable ev = events.event
let disposables = ResizeArray()
workspace.onDidChangeTextDocument.Invoke(fun e ->
if e.document.languageId = "fsharp" then events.fire()
None
) |> disposables.Add
workspace.onDidChangeConfiguration.Invoke((fun _ -> events.fire(); None))

workspace.onDidChangeTextDocument.Invoke (fun e ->
if e.document.languageId = "fsharp" then
events.fire ()

None)
|> disposables.Add

workspace.onDidChangeConfiguration.Invoke(
(fun _ ->
events.fire ()
None)
)
|> disposables.Add

{ new InlayHintsProvider with
member x.onDidChangeInlayHints = Some ev

member x.provideInlayHints(document: TextDocument, range: Range, token: CancellationToken) =
let doThing () =
promise {
logger.Info ("Getting inlay hints for %s", document.fileName)
logger.Info("Getting inlay hints for %s", document.fileName)

let! hints =
LanguageService.inlayHints (
document.uri,
{ start = range.start
``end`` = range.``end`` }
)

let! hints = LanguageService.inlayHints(document.uri, { start = range.start; ``end`` = range.``end`` })
let allowedHints =
match allowParameterNames(), allowTypeAnnotations() with
match allowParameterNames (), allowTypeAnnotations () with
| true, true -> hints
| false, true -> hints |> Array.filter (fun h -> h.kind = "Type")
| true, false -> hints |> Array.filter (fun h -> h.kind = "Parameter")
| true, false ->
hints
|> Array.filter (fun h -> h.kind = "Parameter")
| false, false -> [||] // not actually a thing, covered by the actuallyEnabled
return allowedHints |> Seq.map toInlayHint |> ResizeArray |> Some

return
allowedHints
|> Seq.map toInlayHint
|> ResizeArray
|> Some
}
|> Promise.toThenable
if not (actuallyEnabled()) then

if not (actuallyEnabled ()) then
ProviderResult.None
else
ProviderResult.Some (U2.Case2 (doThing()))
ProviderResult.Some(U2.Case2(doThing ()))

member x.resolveInlayHint(hint, token: CancellationToken) = None
member x.onDidChangeInlayHints with set v =
v |> Option.iter (fun v -> ev <- v)
}, disposables

member x.onDidChangeInlayHints
with set v = v |> Option.iter (fun v -> ev <- v) },
disposables

let activate (context: ExtensionContext) =
let provider, disposables = inlayProvider()
let provider, disposables = inlayProvider ()

let selector =
createObj [ "language" ==> "fsharp" ]
|> unbox<DocumentFilter>
languages.registerInlayHintsProvider(DocumentSelector.Case1 selector, provider)

languages.registerInlayHintsProvider (DocumentSelector.Case1 selector, provider)
|> context.Subscribe

disposables |> Seq.iter context.Subscribe

logger.Info "Activating F# inlay hints"
Expand Down
38 changes: 32 additions & 6 deletions src/Components/MSBuild.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,38 @@ module MSBuild =
window.withProgress (
progressOpts,
(fun p ctok ->
let pm =
{| message = Some("Running MsBuild " + target)
increment = None |}
promise {
let pm =
{| message = Some $"Running MSBuild '{target}' target on '{project}'"
increment = None |}

p.report pm
let! response = executeWithHost ()

match response.Code with
| Some 0 ->
p.report (
{| message = Some "MSBuild completed successfully"
increment = None |}
)

return response
| Some code ->
p.report (
{| message = Some $"MSBuild failed with code %d{code}"
increment = None |}
)

p.report pm
executeWithHost () |> Promise.toThenable)
return response
| None ->
p.report (
{| message = Some "MSBuild failed with an unknown error"
increment = None |}
)

return response
}
|> Promise.toThenable)
)
|> Promise.ofThenable

Expand Down Expand Up @@ -215,7 +241,7 @@ module MSBuild =
progressOpts,
(fun p ctok ->
let pm =
{| message = Some(sprintf "Restoring: %s" path)
{| message = Some("Restoring " + path)
increment = None |}

p.report pm
Expand Down
1 change: 1 addition & 0 deletions src/Components/QuickInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open Fable.Import
open Fable.Import.VSCode
open Fable.Import.VSCode.Vscode
open Ionide.VSCode.Helpers
open Fable.Core

module Fsdn =

Expand Down
4 changes: 1 addition & 3 deletions src/Components/QuickInfoProject.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ module QuickInfoProject =
"$(circuit-board) Not in a F# project"
+ loadingInfo

item.Value.tooltip <-
Some(U2.Case1(sprintf "%s is not in any project known to Ionide" fileNameOnly))

item.Value.tooltip <- Some(U2.Case1 $"%s{fileNameOnly} is not in any project known to Ionide")
item.Value.command <- Some(U2.Case1 "fsharp.AddFileToProject")

item.Value.color <-
Expand Down
Loading

0 comments on commit 639b9c0

Please sign in to comment.