-
Notifications
You must be signed in to change notification settings - Fork 830
Inline parameter name hints for F# #14215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0bd9051
9a6ee2a
f577d31
56d9576
64cd0fe
dd66736
68cfc48
0061c1b
8d5c19e
5e65f1e
e13b3a2
04c0aaf
cdc562b
17f42e2
9b7f5a4
1a52097
476b541
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
|
||
| namespace Microsoft.VisualStudio.FSharp.Editor.Hints | ||
|
|
||
| open FSharp.Compiler.Text | ||
|
|
||
| module Hints = | ||
|
|
||
| type HintKind = | ||
| | TypeHint | ||
| | ParameterNameHint | ||
|
|
||
| // Relatively convenient for testing | ||
| type NativeHint = { | ||
| Kind: HintKind | ||
| Range: range | ||
| Parts: TaggedText list | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
|
||
| namespace Microsoft.VisualStudio.FSharp.Editor.Hints | ||
|
|
||
| open Microsoft.VisualStudio.FSharp.Editor | ||
| open FSharp.Compiler.CodeAnalysis | ||
| open FSharp.Compiler.Symbols | ||
| open FSharp.Compiler.Text | ||
| open Hints | ||
|
|
||
| module InlineParameterNameHints = | ||
|
|
||
| let private getHint (range: range, parameter: FSharpParameter) = | ||
| { | ||
| Kind = HintKind.ParameterNameHint | ||
| Range = range.StartRange | ||
| Parts = [ TaggedText(TextTag.Text, $"{parameter.DisplayName} = ") ] | ||
| } | ||
|
|
||
| let private doesParameterNameExist (parameter: FSharpParameter) = | ||
| parameter.DisplayName <> "" | ||
|
|
||
| let isValidForHint (symbol: FSharpMemberOrFunctionOrValue) = | ||
| // is there a better way? | ||
psfinaki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let isNotBuiltInOperator = | ||
| symbol.DeclaringEntity | ||
| |> Option.exists (fun entity -> entity.CompiledName <> "Operators") | ||
vzarytovskii marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| symbol.IsFunction | ||
| && isNotBuiltInOperator // arguably, hints for those would be rather useless | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is missing a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, so the behavior is by coincidence :) Yes, this will be a valid check, thanks. |
||
|
|
||
| let getHints | ||
| (parseResults: FSharpParseFileResults) | ||
| (symbol: FSharpMemberOrFunctionOrValue) | ||
| (symbolUse: FSharpSymbolUse) = | ||
|
|
||
| let parameters = symbol.CurriedParameterGroups |> Seq.concat | ||
| let ranges = parseResults.GetAllArgumentsForFunctionApplicationAtPosition symbolUse.Range.Start | ||
|
|
||
| match ranges with | ||
| | Some ranges -> | ||
| parameters | ||
| |> Seq.zip ranges | ||
| |> Seq.where (snd >> doesParameterNameExist) | ||
| |> Seq.map getHint | ||
| |> Seq.toList | ||
|
|
||
| // this is the case at least for custom operators | ||
| | None -> [] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
|
||
| namespace Microsoft.VisualStudio.FSharp.Editor.Hints | ||
|
|
||
| open Microsoft.VisualStudio.FSharp.Editor | ||
| open FSharp.Compiler.CodeAnalysis | ||
| open FSharp.Compiler.Symbols | ||
| open FSharp.Compiler.Text | ||
| open Hints | ||
|
|
||
| module InlineTypeHints = | ||
|
|
||
| let private getHintParts | ||
| (symbol: FSharpMemberOrFunctionOrValue) | ||
| (symbolUse: FSharpSymbolUse) = | ||
|
|
||
| match symbol.GetReturnTypeLayout symbolUse.DisplayContext with | ||
| | Some typeInfo -> | ||
| let colon = TaggedText(TextTag.Text, ": ") | ||
| colon :: (typeInfo |> Array.toList) | ||
|
|
||
| // not sure when this can happen | ||
| | None -> | ||
| [] | ||
|
|
||
| let private getHint symbol (symbolUse: FSharpSymbolUse) = | ||
| { | ||
| Kind = HintKind.TypeHint | ||
| Range = symbolUse.Range.EndRange | ||
| Parts = getHintParts symbol symbolUse | ||
| } | ||
|
|
||
| let isValidForHint | ||
| (parseFileResults: FSharpParseFileResults) | ||
| (symbol: FSharpMemberOrFunctionOrValue) | ||
| (symbolUse: FSharpSymbolUse) = | ||
|
|
||
| let isNotAnnotatedManually = | ||
| not (parseFileResults.IsTypeAnnotationGivenAtPosition symbolUse.Range.Start) | ||
|
|
||
| let isNotAfterDot = | ||
| symbolUse.IsFromDefinition | ||
| && not symbol.IsMemberThisValue | ||
|
|
||
| let isNotTypeAlias = | ||
| not symbol.IsConstructorThisValue | ||
|
|
||
| symbol.IsValue // we'll be adding other stuff gradually here | ||
| && isNotAnnotatedManually | ||
| && isNotAfterDot | ||
| && isNotTypeAlias | ||
|
|
||
| let getHints symbol symbolUse = | ||
| [ getHint symbol symbolUse ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
|
||
| namespace Microsoft.VisualStudio.FSharp.Editor.Hints | ||
|
|
||
| open Microsoft.VisualStudio.FSharp.Editor | ||
| open Hints | ||
|
|
||
| module OptionParser = | ||
|
|
||
| let getHintKinds options = | ||
| Set | ||
| [ if options.IsInlineTypeHintsEnabled then | ||
| HintKind.TypeHint | ||
|
|
||
| if options.IsInlineParameterNameHintsEnabled then | ||
| HintKind.ParameterNameHint ] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.