Skip to content
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

Light up Parameter Hints for Constructors and Methods #1176

Merged
merged 3 commits into from
Oct 14, 2023
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
23 changes: 16 additions & 7 deletions src/FsAutoComplete.Core/InlayHints.fs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ let private getFirstPositionAfterParen (str: string) startPos =
match str with
| null -> -1
| str when startPos > str.Length -> -1
| str -> str.IndexOf('(') + 1
| str -> str.IndexOf('(', startPos) + 1

let private maxHintLength = 30

Expand Down Expand Up @@ -946,7 +946,8 @@ let provideHints
parameterHints.Add hint

| :? FSharpMemberOrFunctionOrValue as methodOrConstructor when
hintConfig.ShowParameterHints && methodOrConstructor.IsConstructor
hintConfig.ShowParameterHints
&& (methodOrConstructor.IsConstructor || methodOrConstructor.IsMethod)
-> // TODO: support methods when this API comes into FCS
let endPosForMethod = symbolUse.Range.End
let line, _ = Position.toZ endPosForMethod
Expand All @@ -970,13 +971,18 @@ let provideHints
methodOrConstructor.CurriedParameterGroups |> Seq.concat |> Array.ofSeq // TODO: need ArgumentLocations to be surfaced

for idx = 0 to parameters.Length - 1 do
// let paramLocationInfo = tupledParamInfos.ArgumentLocations.[idx]
let paramLocationInfo = tupledParamInfos.ArgumentLocations.[idx]
let param = parameters.[idx]
let paramName = param.DisplayName
// PLI.IsNamedArgument is true if the user has provided a name here. There's no since in providing a hint
// for a named argument, so skip it
if paramLocationInfo.IsNamedArgument then
()
// otherwise apply our 'should we make a hint' logic to the argument text
else if ShouldCreate.paramHint methodOrConstructor param "" then
let hint = createParamHint paramLocationInfo.ArgumentRange paramName
parameterHints.Add(hint)

// if shouldCreateHint param && paramLocationInfo.IsNamedArgument then
// let hint = { Text = paramName + " ="; Pos = paramLocationInfo.ArgumentRange.Start; Kind = Parameter }
// parameterHints.Add(hint)
()

// This will only happen for curried methods defined in F#.
Expand All @@ -999,7 +1005,10 @@ let provideHints
for (definitionArg, appliedArgRange) in parms do
let! appliedArgText = text[appliedArgRange]

if ShouldCreate.paramHint methodOrConstructor definitionArg appliedArgText then
let shouldCreate =
ShouldCreate.paramHint methodOrConstructor definitionArg appliedArgText

if shouldCreate then
let hint = createParamHint appliedArgRange definitionArg.DisplayName
parameterHints.Add(hint)

Expand Down
Loading