Skip to content

Commit f4a1d2a

Browse files
authored
Adding signature help tooltip coloring support for VS (#3821)
1 parent 7ce364c commit f4a1d2a

64 files changed

Lines changed: 29218 additions & 146 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/fourslash/_scripts/failingTests.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ TestAutoImportSortCaseSensitivity1
3333
TestAutoImportTypeImport4
3434
TestAutoImportTypeOnlyPreferred3
3535
TestAutoImportVerbatimTypeOnly1
36-
TestCalledUnionsOfDissimilarTyeshaveGoodDisplay
3736
TestCloduleTypeOf1
3837
TestCodeCompletionEscaping
3938
TestCodeFixAddParameterNames1
@@ -338,7 +337,6 @@ TestNoQuickInfoForLabel
338337
TestNoQuickInfoInWhitespace
339338
TestOverloadQuickInfo
340339
TestProtoVarVisibleWithOuterScopeUnderscoreProto
341-
TestQualifyModuleTypeNames
342340
TestQuickfixImplementInterfaceUnreachableTypeUsesRelativeImport
343341
TestQuickInfo_notInsideComment
344342
TestQuickinfo01
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestJsDocDontBreakWithNamespacesVS(t *testing.T) {
12+
t.Parallel()
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
const content = `// @allowJs: true
15+
// @Filename: jsDocDontBreakWithNamespaces.js
16+
/**
17+
* @returns {module:@nodefuel/web~Webserver~wsServer#hello} Websocket server object
18+
*/
19+
function foo() { }
20+
foo(''/*foo*/);
21+
22+
/**
23+
* @type {module:xxxxx} */
24+
*/
25+
function bar() { }
26+
bar(''/*bar*/);
27+
28+
/** @type {function(module:xxxx, module:xxxx): module:xxxxx} */
29+
function zee() { }
30+
zee(''/*zee*/);`
31+
f, done := fourslash.NewFourslash(t, &lsproto.ClientCapabilities{VSSupportsVisualStudioExtensions: new(true)}, content)
32+
defer done()
33+
f.VerifyBaselineSignatureHelp(t)
34+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestJsDocFunctionSignatures5VS(t *testing.T) {
12+
t.Parallel()
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
const content = `// @strict: true
15+
// @allowJs: true
16+
// @Filename: Foo.js
17+
/**
18+
* Filters a path based on a regexp or glob pattern.
19+
* @param {String} basePath The base path where the search will be performed.
20+
* @param {String} pattern A string defining a regexp of a glob pattern.
21+
* @param {String} type The search pattern type, can be a regexp or a glob.
22+
* @param {Object} options A object containing options to the search.
23+
* @return {Array} A list containing the filtered paths.
24+
*/
25+
function pathFilter(basePath, pattern, type, options){
26+
//...
27+
}
28+
pathFilter(/**/'foo', 'bar', 'baz', {});`
29+
f, done := fourslash.NewFourslash(t, &lsproto.ClientCapabilities{VSSupportsVisualStudioExtensions: new(true)}, content)
30+
defer done()
31+
f.VerifyBaselineSignatureHelp(t)
32+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestJsDocFunctionSignatures6VS(t *testing.T) {
12+
t.Parallel()
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
const content = `// @allowJs: true
15+
// @Filename: Foo.js
16+
/**
17+
* @param {string} p1 - A string param
18+
* @param {string?} p2 - An optional param
19+
* @param {string} [p3] - Another optional param
20+
* @param {string} [p4="test"] - An optional param with a default value
21+
*/
22+
function f1(p1, p2, p3, p4){}
23+
f1(/*1*/'foo', /*2*/'bar', /*3*/'baz', /*4*/'qux');`
24+
f, done := fourslash.NewFourslash(t, &lsproto.ClientCapabilities{VSSupportsVisualStudioExtensions: new(true)}, content)
25+
defer done()
26+
f.VerifyBaselineSignatureHelp(t)
27+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestJsdocReturnsTagVS(t *testing.T) {
12+
t.Parallel()
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
const content = `// @allowJs: true
15+
// @Filename: dummy.js
16+
/**
17+
* Find an item
18+
* @template T
19+
* @param {T[]} l
20+
* @param {T} x
21+
* @returns {?T} The names of the found item(s).
22+
*/
23+
function find(l, x) {
24+
}
25+
find(''/**/);`
26+
f, done := fourslash.NewFourslash(t, &lsproto.ClientCapabilities{VSSupportsVisualStudioExtensions: new(true)}, content)
27+
defer done()
28+
f.VerifyBaselineSignatureHelp(t)
29+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestQuickInfoJsDocTags13VS(t *testing.T) {
12+
t.Parallel()
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
const content = `// @allowJs: true
15+
// @checkJs: true
16+
// @filename: ./a.js
17+
/**
18+
* First overload
19+
* @overload
20+
* @param {number} a
21+
* @returns {void}
22+
*/
23+
24+
/**
25+
* Second overload
26+
* @overload
27+
* @param {string} a
28+
* @returns {void}
29+
*/
30+
31+
/**
32+
* @param {string | number} a
33+
* @returns {void}
34+
*/
35+
function f(a) {}
36+
37+
f(/*a*/1);
38+
f(/*b*/"");`
39+
f, done := fourslash.NewFourslash(t, &lsproto.ClientCapabilities{VSSupportsVisualStudioExtensions: new(true)}, content)
40+
defer done()
41+
f.VerifyBaselineSignatureHelp(t)
42+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestQuickInfoJsDocTextFormatting1VS(t *testing.T) {
12+
t.Parallel()
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
const content = `/**
15+
* @param {number} var1 **Highlighted text**
16+
* @param {string} var2 Another **Highlighted text**
17+
*/
18+
function f1(var1, var2) { }
19+
20+
/**
21+
* @param {number} var1 *Regular text with an asterisk
22+
* @param {string} var2 Another *Regular text with an asterisk
23+
*/
24+
function f2(var1, var2) { }
25+
26+
/**
27+
* @param {number} var1
28+
* *Regular text with an asterisk
29+
* @param {string} var2
30+
* Another *Regular text with an asterisk
31+
*/
32+
function f3(var1, var2) { }
33+
34+
/**
35+
* @param {number} var1
36+
* **Highlighted text**
37+
* @param {string} var2
38+
* Another **Highlighted text**
39+
*/
40+
function f4(var1, var2) { }
41+
42+
/**
43+
* @param {number} var1
44+
**Highlighted text**
45+
* @param {string} var2
46+
Another **Highlighted text**
47+
*/
48+
function f5(var1, var2) { }
49+
50+
f1(/*1*/);
51+
f2(/*2*/);
52+
f3(/*3*/);
53+
f4(/*4*/);
54+
f5(/*5*/);`
55+
f, done := fourslash.NewFourslash(t, &lsproto.ClientCapabilities{VSSupportsVisualStudioExtensions: new(true)}, content)
56+
defer done()
57+
f.VerifyBaselineSignatureHelp(t)
58+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestSignatureHelpAfterParameterVS(t *testing.T) {
12+
t.Parallel()
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
const content = `type Type = (a, b, c) => void
15+
const a: Type = (a/*1*/, b/*2*/) => {}
16+
const b: Type = function (a/*3*/, b/*4*/) {}
17+
const c: Type = ({ /*5*/a: { b/*6*/ }}/*7*/ = { }/*8*/, [b/*9*/]/*10*/, .../*11*/c/*12*/) => {}`
18+
f, done := fourslash.NewFourslash(t, &lsproto.ClientCapabilities{VSSupportsVisualStudioExtensions: new(true)}, content)
19+
defer done()
20+
f.VerifyBaselineSignatureHelp(t)
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestSignatureHelpAnonymousTypeVS(t *testing.T) {
12+
t.Parallel()
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
const content = `const comparers: Array<(a: any, b: any) => boolean> = [];
15+
16+
comparers.push((a,/**/ b) => true);`
17+
f, done := fourslash.NewFourslash(t, &lsproto.ClientCapabilities{VSSupportsVisualStudioExtensions: new(true)}, content)
18+
defer done()
19+
f.VerifyBaselineSignatureHelp(t)
20+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestSignatureHelpBindingPatternVS(t *testing.T) {
12+
t.Parallel()
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
const content = `
15+
/**
16+
* @param options An empty object binding pattern.
17+
*/
18+
function emptyObj({}) {}
19+
emptyObj(/*emptyObj*/)
20+
21+
/**
22+
* @param items An empty array binding pattern.
23+
*/
24+
function emptyArr([]) {}
25+
emptyArr(/*emptyArr*/)
26+
27+
/**
28+
* @param param An object with a and b properties.
29+
*/
30+
function nonEmptyObj({a, b}: {a: number, b: string}) {}
31+
nonEmptyObj(/*nonEmptyObj*/)
32+
33+
/**
34+
* @param tuple A tuple with two elements.
35+
*/
36+
function nonEmptyArr([x, y]: [number, string]) {}
37+
nonEmptyArr(/*nonEmptyArr*/)
38+
39+
/**
40+
* @param first The first number parameter.
41+
* @param second An object with a and b properties.
42+
*/
43+
function idLeading(first: number, {a, b}: {a: number, b: string}) {}
44+
idLeading(123/*idLeading*/, { a: 1, b: 2 }/*bindingTrailing*/)
45+
46+
/**
47+
* @param first An object with a and b properties.
48+
* @param last The last number parameter.
49+
*/
50+
function bindingLeading({a, b}: {a: number, b: string}, last: number) {}
51+
bindingLeading(/*bindingLeading*/{ a: 1, b: 2 }, 123 /*idTrailing*/)
52+
53+
/**
54+
* @param param1 {Object} The first parameter
55+
* @param param1.a {number} Comment a
56+
* @param param1.b {string} Comment b
57+
* @param param2 {Object} The second parameter
58+
* @param param2.c {boolean} Comment c
59+
* @param param2.d {unknown} Comment d
60+
*/
61+
function multipleBindings({ a, b }, { c, d }) {}
62+
multipleBindings({ a: 0, b: "" }/*firstObjParam*/, { c: true, d: "" }/*secondObjParam*/)
63+
`
64+
f, done := fourslash.NewFourslash(t, &lsproto.ClientCapabilities{VSSupportsVisualStudioExtensions: new(true)}, content)
65+
defer done()
66+
f.VerifyBaselineSignatureHelp(t)
67+
}

0 commit comments

Comments
 (0)