Skip to content

Commit 6642b0a

Browse files
authored
Quick Info fixes (#1971)
1 parent 4037f3a commit 6642b0a

10 files changed

+46
-38
lines changed

internal/fourslash/_scripts/failingTests.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ TestCompletionListInvalidMemberNames2
118118
TestCompletionListInvalidMemberNames_escapeQuote
119119
TestCompletionListInvalidMemberNames_startWithSpace
120120
TestCompletionListInvalidMemberNames_withExistingIdentifier
121-
TestCompletionListObjectMembersInTypeLocationWithTypeof
122121
TestCompletionListOfGenericSymbol
123122
TestCompletionListOnAliases
124123
TestCompletionListStringParenthesizedExpression
@@ -251,7 +250,6 @@ TestGetJavaScriptQuickInfo7
251250
TestGetJavaScriptQuickInfo8
252251
TestGetJavaScriptSyntacticDiagnostics24
253252
TestGetOccurrencesIfElseBroken
254-
TestGetQuickInfoForIntersectionTypes
255253
TestHoverOverComment
256254
TestImportCompletionsPackageJsonExportsSpecifierEndsInTs
257255
TestImportCompletionsPackageJsonExportsTrailingSlash1
@@ -425,7 +423,6 @@ TestQuickInfoJSDocFunctionThis
425423
TestQuickInfoJSExport
426424
TestQuickInfoJsDocGetterSetterNoCrash1
427425
TestQuickInfoJsDocNonDiscriminatedUnionSharedProp
428-
TestQuickInfoJsPropertyAssignedAfterMethodDeclaration
429426
TestQuickInfoJsdocTypedefMissingType
430427
TestQuickInfoMappedSpreadTypes
431428
TestQuickInfoMappedType

internal/fourslash/tests/gen/completionListObjectMembersInTypeLocationWithTypeof_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func TestCompletionListObjectMembersInTypeLocationWithTypeof(t *testing.T) {
1313
t.Parallel()
14-
t.Skip()
14+
1515
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1616
const content = `// @strict: true
1717
const languageService = { getCompletions() {} }

internal/fourslash/tests/gen/getQuickInfoForIntersectionTypes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
func TestGetQuickInfoForIntersectionTypes(t *testing.T) {
1111
t.Parallel()
12-
t.Skip()
12+
1313
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1414
const content = `function f(): string & {(): any} {
1515
return <any>{};

internal/fourslash/tests/gen/quickInfoJsPropertyAssignedAfterMethodDeclaration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
func TestQuickInfoJsPropertyAssignedAfterMethodDeclaration(t *testing.T) {
1111
t.Parallel()
12-
t.Skip()
12+
1313
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1414
const content = `// @noLib: true
1515
// @allowJs: true

internal/ls/hover.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol
129129
}
130130
}
131131
flags := symbol.Flags
132+
if flags&ast.SymbolFlagsProperty != 0 && declaration != nil && ast.IsMethodDeclaration(declaration) {
133+
flags = ast.SymbolFlagsMethod
134+
}
132135
if flags&ast.SymbolFlagsType != 0 && (ast.IsPartOfTypeNode(node) || ast.IsTypeDeclarationName(node)) {
133136
// If the symbol has a type meaning and we're in a type context, remove value-only meanings
134137
flags &^= ast.SymbolFlagsVariable | ast.SymbolFlagsFunction
@@ -165,7 +168,11 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol
165168
}
166169
b.WriteString(c.SymbolToStringEx(symbol, container, ast.SymbolFlagsNone, symbolFormatFlags))
167170
b.WriteString(": ")
168-
b.WriteString(c.TypeToStringEx(c.GetTypeOfSymbolAtLocation(symbol, node), container, typeFormatFlags))
171+
if callNode := getCallOrNewExpression(node); callNode != nil {
172+
b.WriteString(c.SignatureToStringEx(c.GetResolvedSignature(callNode), container, typeFormatFlags|checker.TypeFormatFlagsWriteCallStyleSignature|checker.TypeFormatFlagsWriteTypeArgumentsOfSignature|checker.TypeFormatFlagsWriteArrowStyleSignature))
173+
} else {
174+
b.WriteString(c.TypeToStringEx(c.GetTypeOfSymbolAtLocation(symbol, node), container, typeFormatFlags))
175+
}
169176
case flags&ast.SymbolFlagsEnumMember != 0:
170177
b.WriteString("(enum member) ")
171178
t := c.GetTypeOfSymbol(symbol)
@@ -176,22 +183,26 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol
176183
}
177184
case flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod) != 0:
178185
signatures := getSignaturesAtLocation(c, symbol, checker.SignatureKindCall, node)
179-
if len(signatures) == 1 && signatures[0].Declaration() != nil {
180-
declaration = signatures[0].Declaration()
186+
if len(signatures) == 1 {
187+
if d := signatures[0].Declaration(); d != nil && d.Flags&ast.NodeFlagsJSDoc == 0 {
188+
declaration = d
189+
}
181190
}
182-
prefix := core.IfElse(symbol.Flags&ast.SymbolFlagsMethod != 0, "(method) ", "function ")
191+
prefix := core.IfElse(flags&ast.SymbolFlagsMethod != 0, "(method) ", "function ")
183192
writeSignatures(&b, c, signatures, container, prefix, symbol)
184193
case flags&ast.SymbolFlagsConstructor != 0:
185194
signatures := getSignaturesAtLocation(c, symbol.Parent, checker.SignatureKindConstruct, node)
186-
if len(signatures) == 1 && signatures[0].Declaration() != nil {
187-
declaration = signatures[0].Declaration()
195+
if len(signatures) == 1 {
196+
if d := signatures[0].Declaration(); d != nil && d.Flags&ast.NodeFlagsJSDoc == 0 {
197+
declaration = d
198+
}
188199
}
189200
writeSignatures(&b, c, signatures, container, "constructor ", symbol.Parent)
190201
case flags&(ast.SymbolFlagsClass|ast.SymbolFlagsInterface) != 0:
191202
if node.Kind == ast.KindThisKeyword || ast.IsThisInTypeQuery(node) {
192203
b.WriteString("this")
193204
} else {
194-
b.WriteString(core.IfElse(symbol.Flags&ast.SymbolFlagsClass != 0, "class ", "interface "))
205+
b.WriteString(core.IfElse(flags&ast.SymbolFlagsClass != 0, "class ", "interface "))
195206
b.WriteString(c.SymbolToStringEx(symbol, container, ast.SymbolFlagsNone, symbolFormatFlags))
196207
params := c.GetDeclaredTypeOfSymbol(symbol).AsInterfaceType().LocalTypeParameters()
197208
writeTypeParams(&b, c, params)
@@ -288,7 +299,7 @@ func getCallOrNewExpression(node *ast.Node) *ast.Node {
288299
if ast.IsPropertyAccessExpression(node.Parent) && node.Parent.Name() == node {
289300
node = node.Parent
290301
}
291-
if ast.IsCallExpression(node.Parent) || ast.IsNewExpression(node.Parent) {
302+
if (ast.IsCallExpression(node.Parent) || ast.IsNewExpression(node.Parent)) && node.Parent.Expression() == node {
292303
return node.Parent
293304
}
294305
return nil

testdata/baselines/reference/fourslash/quickInfo/quickInfoDisplayPartsConst.baseline

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@
121121
// ^
122122
// | ----------------------------------------------------------------------
123123
// | ```tsx
124-
// | const h: { (a: string): number; (a: number): string; }
124+
// | const h: (a: number) => string
125125
// | ```
126126
// |
127127
// | ----------------------------------------------------------------------
128128
// h("hello");
129129
// ^
130130
// | ----------------------------------------------------------------------
131131
// | ```tsx
132-
// | const h: { (a: string): number; (a: number): string; }
132+
// | const h: (a: string) => number
133133
// | ```
134134
// |
135135
// | ----------------------------------------------------------------------
@@ -525,7 +525,7 @@
525525
"item": {
526526
"contents": {
527527
"kind": "markdown",
528-
"value": "```tsx\nconst h: { (a: string): number; (a: number): string; }\n```\n"
528+
"value": "```tsx\nconst h: (a: number) => string\n```\n"
529529
},
530530
"range": {
531531
"start": {
@@ -552,7 +552,7 @@
552552
"item": {
553553
"contents": {
554554
"kind": "markdown",
555-
"value": "```tsx\nconst h: { (a: string): number; (a: number): string; }\n```\n"
555+
"value": "```tsx\nconst h: (a: string) => number\n```\n"
556556
},
557557
"range": {
558558
"start": {

testdata/baselines/reference/fourslash/quickInfo/quickInfoDisplayPartsInterfaceMembers.baseline

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
// ^^^^^^^^^
5555
// | ----------------------------------------------------------------------
5656
// | ```tsx
57-
// | var iInstance: I
57+
// | var iInstance: () => string
5858
// | ```
5959
// |
6060
// | ----------------------------------------------------------------------
@@ -69,7 +69,7 @@
6969
// ^^^^^^^^^
7070
// | ----------------------------------------------------------------------
7171
// | ```tsx
72-
// | var iInstance: I
72+
// | var iInstance: () => I
7373
// | ```
7474
// |
7575
// | ----------------------------------------------------------------------
@@ -249,7 +249,7 @@
249249
"item": {
250250
"contents": {
251251
"kind": "markdown",
252-
"value": "```tsx\nvar iInstance: I\n```\n"
252+
"value": "```tsx\nvar iInstance: () => string\n```\n"
253253
},
254254
"range": {
255255
"start": {
@@ -303,7 +303,7 @@
303303
"item": {
304304
"contents": {
305305
"kind": "markdown",
306-
"value": "```tsx\nvar iInstance: I\n```\n"
306+
"value": "```tsx\nvar iInstance: () => I\n```\n"
307307
},
308308
"range": {
309309
"start": {

testdata/baselines/reference/fourslash/quickInfo/quickInfoDisplayPartsLet.baseline

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@
121121
// ^
122122
// | ----------------------------------------------------------------------
123123
// | ```tsx
124-
// | let h: { (a: string): number; (a: number): string; }
124+
// | let h: (a: number) => string
125125
// | ```
126126
// |
127127
// | ----------------------------------------------------------------------
128128
// h("hello");
129129
// ^
130130
// | ----------------------------------------------------------------------
131131
// | ```tsx
132-
// | let h: { (a: string): number; (a: number): string; }
132+
// | let h: (a: string) => number
133133
// | ```
134134
// |
135135
// | ----------------------------------------------------------------------
@@ -525,7 +525,7 @@
525525
"item": {
526526
"contents": {
527527
"kind": "markdown",
528-
"value": "```tsx\nlet h: { (a: string): number; (a: number): string; }\n```\n"
528+
"value": "```tsx\nlet h: (a: number) => string\n```\n"
529529
},
530530
"range": {
531531
"start": {
@@ -552,7 +552,7 @@
552552
"item": {
553553
"contents": {
554554
"kind": "markdown",
555-
"value": "```tsx\nlet h: { (a: string): number; (a: number): string; }\n```\n"
555+
"value": "```tsx\nlet h: (a: string) => number\n```\n"
556556
},
557557
"range": {
558558
"start": {

testdata/baselines/reference/fourslash/quickInfo/quickInfoDisplayPartsTypeParameterInInterface.baseline

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@
171171
// ^^^^
172172
// | ----------------------------------------------------------------------
173173
// | ```tsx
174-
// | var iVal: I<string>
174+
// | var iVal: <"hello">(a: "hello", b: string) => "hello"
175175
// | ```
176176
// |
177177
// | ----------------------------------------------------------------------
178178
// iVal("hello", "hello");
179179
// ^^^^
180180
// | ----------------------------------------------------------------------
181181
// | ```tsx
182-
// | var iVal: I<string>
182+
// | var iVal: <"hello">(a: "hello", b: string) => "hello"
183183
// | ```
184184
// |
185185
// | ----------------------------------------------------------------------
@@ -404,7 +404,7 @@
404404
// ^^^^^
405405
// | ----------------------------------------------------------------------
406406
// | ```tsx
407-
// | var iVal1: I1<I<string>>
407+
// | var iVal1: <I<string>>(a: I<string>, b: I<string>) => I<string>
408408
// | ```
409409
// |
410410
// | ----------------------------------------------------------------------
@@ -426,7 +426,7 @@
426426
// ^^^^^
427427
// | ----------------------------------------------------------------------
428428
// | ```tsx
429-
// | var iVal1: I1<I<string>>
429+
// | var iVal1: <I<string>>(a: I<string>, b: I<string>) => I<string>
430430
// | ```
431431
// |
432432
// | ----------------------------------------------------------------------
@@ -1108,7 +1108,7 @@
11081108
"item": {
11091109
"contents": {
11101110
"kind": "markdown",
1111-
"value": "```tsx\nvar iVal: I<string>\n```\n"
1111+
"value": "```tsx\nvar iVal: <\"hello\">(a: \"hello\", b: string) => \"hello\"\n```\n"
11121112
},
11131113
"range": {
11141114
"start": {
@@ -1135,7 +1135,7 @@
11351135
"item": {
11361136
"contents": {
11371137
"kind": "markdown",
1138-
"value": "```tsx\nvar iVal: I<string>\n```\n"
1138+
"value": "```tsx\nvar iVal: <\"hello\">(a: \"hello\", b: string) => \"hello\"\n```\n"
11391139
},
11401140
"range": {
11411141
"start": {
@@ -1972,7 +1972,7 @@
19721972
"item": {
19731973
"contents": {
19741974
"kind": "markdown",
1975-
"value": "```tsx\nvar iVal1: I1<I<string>>\n```\n"
1975+
"value": "```tsx\nvar iVal1: <I<string>>(a: I<string>, b: I<string>) => I<string>\n```\n"
19761976
},
19771977
"range": {
19781978
"start": {
@@ -2053,7 +2053,7 @@
20532053
"item": {
20542054
"contents": {
20552055
"kind": "markdown",
2056-
"value": "```tsx\nvar iVal1: I1<I<string>>\n```\n"
2056+
"value": "```tsx\nvar iVal1: <I<string>>(a: I<string>, b: I<string>) => I<string>\n```\n"
20572057
},
20582058
"range": {
20592059
"start": {

testdata/baselines/reference/fourslash/quickInfo/quickInfoDisplayPartsVar.baseline

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@
101101
// ^
102102
// | ----------------------------------------------------------------------
103103
// | ```tsx
104-
// | var h: { (a: string): number; (a: number): string; }
104+
// | var h: (a: number) => string
105105
// | ```
106106
// |
107107
// | ----------------------------------------------------------------------
108108
// h("hello");
109109
// ^
110110
// | ----------------------------------------------------------------------
111111
// | ```tsx
112-
// | var h: { (a: string): number; (a: number): string; }
112+
// | var h: (a: string) => number
113113
// | ```
114114
// |
115115
// | ----------------------------------------------------------------------
@@ -451,7 +451,7 @@
451451
"item": {
452452
"contents": {
453453
"kind": "markdown",
454-
"value": "```tsx\nvar h: { (a: string): number; (a: number): string; }\n```\n"
454+
"value": "```tsx\nvar h: (a: number) => string\n```\n"
455455
},
456456
"range": {
457457
"start": {
@@ -478,7 +478,7 @@
478478
"item": {
479479
"contents": {
480480
"kind": "markdown",
481-
"value": "```tsx\nvar h: { (a: string): number; (a: number): string; }\n```\n"
481+
"value": "```tsx\nvar h: (a: string) => number\n```\n"
482482
},
483483
"range": {
484484
"start": {

0 commit comments

Comments
 (0)