Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions docs/release-notes/.VisualStudio/18.vNext.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Fixed Find All References crash when F# project contains non-F# files like `.cshtml`. ([Issue #16394](https://github.com/dotnet/fsharp/issues/16394), [PR #19252](https://github.com/dotnet/fsharp/pull/19252))
* Find All References for external DLL symbols now only searches projects that reference the specific assembly. ([Issue #10227](https://github.com/dotnet/fsharp/issues/10227), [PR #19252](https://github.com/dotnet/fsharp/pull/19252))
* Improve static compilation of state machines. ([PR #19297](https://github.com/dotnet/fsharp/pull/19297))
* Make Alt+F1 (momentary toggle) work for inlay hints. ([PR #19421](https://github.com/dotnet/fsharp/pull/19421))

### Changed

Expand Down
26 changes: 14 additions & 12 deletions vsintegration/src/FSharp.Editor/Hints/FSharpInlayHintsService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@ namespace Microsoft.VisualStudio.FSharp.Editor.Hints

open System.Collections.Immutable
open System.ComponentModel.Composition
open System.Threading.Tasks
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.InlineHints
open Microsoft.VisualStudio.FSharp.Editor
open Microsoft.VisualStudio.FSharp.Editor.Telemetry
open CancellableTasks
open System.Threading.Tasks

// So the Roslyn interface is called IFSharpInlineHintsService
// but our implementation is called just HintsService.
// That's because we'll likely use this API for things other than inlay hints,
// e.g. signature hints above the line, pipeline hints on the side and so on.

[<Export(typeof<IFSharpInlineHintsService>)>]
[<Export(typeof<IFSharpInlineHintsService2>)>]
type internal FSharpInlayHintsService [<ImportingConstructor>] (settings: EditorOptions) =

static let userOpName = "Hints"

interface IFSharpInlineHintsService with
member _.GetInlineHintsAsync(document, _, cancellationToken) =
let hintKinds = OptionParser.getHintKinds settings.Advanced
interface IFSharpInlineHintsService2 with
member _.GetInlineHintsAsync(document, textSpan, displayAllOverride, cancellationToken) =
let hintKinds =
if displayAllOverride then
Hints.allHintKinds
else
OptionParser.getHintKinds settings.Advanced

if hintKinds.IsEmpty then
Task.FromResult ImmutableArray.Empty
Expand All @@ -31,14 +34,13 @@ type internal FSharpInlayHintsService [<ImportingConstructor>] (settings: Editor
let! cancellationToken = CancellableTask.getCancellationToken ()

let! sourceText = document.GetTextAsync cancellationToken
let! nativeHints = HintService.getHintsForDocument sourceText document hintKinds userOpName
let! nativeHints = HintService.getHintsForDocument sourceText document hintKinds textSpan userOpName

let tasks =
let roslynHints =
nativeHints
|> Seq.map (fun hint -> NativeToRoslynHintConverter.convert sourceText hint cancellationToken)

let! roslynHints = Task.WhenAll(tasks)
|> Seq.map (NativeToRoslynHintConverter.convert sourceText)
|> ImmutableArray.CreateRange

return roslynHints.ToImmutableArray()
return roslynHints
}
|> CancellableTask.start cancellationToken
7 changes: 6 additions & 1 deletion vsintegration/src/FSharp.Editor/Hints/HintService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module HintService =
let hints = getHints sourceText parseResults hintKinds symbolUses symbol
Seq.concat hints

let getHintsForDocument sourceText (document: Document) hintKinds userOpName =
let getHintsForDocument (sourceText: SourceText) (document: Document) hintKinds (textSpan: TextSpan) userOpName =
cancellableTask {
if isSignatureFile document.FilePath then
return List.empty
Expand Down Expand Up @@ -75,3 +75,8 @@ module HintService =

return nativeHints
}
|> CancellableTask.map (
List.filter (fun hint ->
let hintSpan = RoslynHelpers.FSharpRangeToTextSpan(sourceText, hint.Range)
textSpan.IntersectsWith hintSpan)
)
3 changes: 3 additions & 0 deletions vsintegration/src/FSharp.Editor/Hints/Hints.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ module Hints =
| ParameterNameHint
| ReturnTypeHint

let allHintKinds =
Set [ HintKind.TypeHint; HintKind.ParameterNameHint; HintKind.ReturnTypeHint ]

// Relatively convenient for testing
type NativeHint =
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ module NativeToRoslynHintConverter =
}
|> CancellableTask.start ct

cancellableTask {
let span = rangeToSpan hint.Range sourceText
let displayParts = hint.Parts |> Seq.map nativeToRoslynText
let span = rangeToSpan hint.Range sourceText
let displayParts = hint.Parts |> Seq.map nativeToRoslynText

return FSharpInlineHint(span, displayParts.ToImmutableArray(), getDescriptionAsync)
}
FSharpInlineHint(span, displayParts.ToImmutableArray(), getDescriptionAsync)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace FSharp.Editor.Tests.Hints

open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Text
open Microsoft.VisualStudio.FSharp.Editor
open Microsoft.VisualStudio.FSharp.Editor.Hints
open Hints
Expand Down Expand Up @@ -47,7 +48,8 @@ module HintTestFramework =
}

let! sourceText = document.GetTextAsync ct |> Async.AwaitTask
let! hints = HintService.getHintsForDocument sourceText document hintKinds "test" ct
let textSpan = TextSpan(0, sourceText.Length)
let! hints = HintService.getHintsForDocument sourceText document hintKinds textSpan "test" ct
let! tooltips = hints |> Seq.map getTooltip |> Async.Parallel
return tooltips |> Seq.zip hints |> Seq.map convert
}
Expand Down
Loading