Skip to content

Commit ee938a7

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
provide signature help for type provider static parameters at ctor call site (#5017)
1 parent 92948a2 commit ee938a7

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

src/fsharp/service/ServiceParamInfoLocations.fs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,27 @@ module internal NoteworthyParamInfoLocationsImpl =
144144
NotFound, Some inner
145145
| _ -> NotFound, Some inner
146146

147-
147+
let (|StaticParameters|_|) pos synType =
148+
match synType with
149+
| SynType.App(SynType.LongIdent(LongIdentWithDots(lid, _) as lidwd), Some(openm), args, commas, closemOpt, _pf, wholem) ->
150+
let lidm = lidwd.Range
151+
let betweenTheBrackets = mkRange wholem.FileName openm.Start wholem.End
152+
if AstTraversal.rangeContainsPosEdgesExclusive betweenTheBrackets pos && args |> List.forall isStaticArg then
153+
let commasAndCloseParen = [ for c in commas -> c.End ] @ [ wholem.End ]
154+
Some (FSharpNoteworthyParamInfoLocations(pathOfLid lid, lidm, openm.Start, commasAndCloseParen, closemOpt.IsSome, args |> List.map digOutIdentFromStaticArg))
155+
else
156+
None
157+
| _ ->
158+
None
148159

149160
let traverseInput(pos, parseTree) =
150-
151161
AstTraversal.Traverse(pos, parseTree, { new AstTraversal.AstVisitorBase<_>() with
152162
member this.VisitExpr(_path, traverseSynExpr, defaultTraverse, expr) =
153163
let expr = expr // fix debug locals
154164
match expr with
155165

156166
// new LID<tyarg1, ...., tyargN>(...) and error recovery of these
157-
| SynExpr.New(_, synType, synExpr, _range) ->
167+
| SynExpr.New(_, synType, synExpr, _) ->
158168
let constrArgsResult, cacheOpt = searchSynArgExpr traverseSynExpr pos synExpr
159169
match constrArgsResult, cacheOpt with
160170
| Found(parenLoc, args, isThereACloseParen), _ ->
@@ -163,7 +173,9 @@ module internal NoteworthyParamInfoLocationsImpl =
163173
| NotFound, Some cache ->
164174
cache
165175
| _ ->
166-
traverseSynExpr synExpr
176+
match synType with
177+
| StaticParameters pos loc -> Some loc
178+
| _ -> traverseSynExpr synExpr
167179

168180
// EXPR< = error recovery of a form of half-written TypeApp
169181
| SynExpr.App(_, _, SynExpr.App(_, true, SynExpr.Ident op, synExpr, openm), SynExpr.ArbitraryAfterError _, wholem) when op.idText = "op_LessThan" ->
@@ -221,18 +233,10 @@ module internal NoteworthyParamInfoLocationsImpl =
221233

222234
| _ -> defaultTraverse expr
223235

224-
member this.VisitTypeAbbrev(tyAbbrevRhs, _m) =
236+
member this.VisitTypeAbbrev(tyAbbrevRhs, _m) =
225237
match tyAbbrevRhs with
226-
| SynType.App(SynType.LongIdent(LongIdentWithDots(lid, _) as lidwd), Some(openm), args, commas, closemOpt, _pf, wholem) ->
227-
let lidm = lidwd.Range
228-
let betweenTheBrackets = mkRange wholem.FileName openm.Start wholem.End
229-
if AstTraversal.rangeContainsPosEdgesExclusive betweenTheBrackets pos && args |> List.forall isStaticArg then
230-
let commasAndCloseParen = [ for c in commas -> c.End ] @ [ wholem.End ]
231-
Some (FSharpNoteworthyParamInfoLocations(pathOfLid lid, lidm, openm.Start, commasAndCloseParen, closemOpt.IsSome, args |> List.map digOutIdentFromStaticArg))
232-
else
233-
None
234-
| _ ->
235-
None
238+
| StaticParameters pos loc -> Some loc
239+
| _ -> None
236240

237241
member this.VisitImplicitInherit(defaultTraverse, ty, expr, m) =
238242
match defaultTraverse expr with

vsintegration/tests/UnitTests/LegacyLanguageService/Tests.LanguageService.ParameterInfo.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,12 @@ We really need to rewrite some code paths here to use the real parse tree rather
16311631
type U = ^N1.T^<^ ,^$ ^>""",
16321632
additionalReferenceAssemblies = [PathRelativeToTestAssembly(@"UnitTests\MockTypeProviders\DummyProviderForLanguageServiceTesting.dll")])
16331633

1634+
[<Test>]
1635+
member public this.``LocationOfParams.TypeProviders.StaticParametersAtConstructorCallSite``() =
1636+
this.TestParameterInfoLocationOfParamsWithVariousSurroundingContexts("""
1637+
let x = new ^N1.T^<^ "fo$o",^ 42 ^>()""",
1638+
additionalReferenceAssemblies = [PathRelativeToTestAssembly(@"UnitTests\MockTypeProviders\DummyProviderForLanguageServiceTesting.dll")])
1639+
16341640
[<Test>]
16351641
member public this.``TypeProvider.FormatOfNamesOfSystemTypes``() =
16361642
let code = ["""type TTT = N1.T< "foo", ParamIgnored=42 > """]

0 commit comments

Comments
 (0)