Skip to content

Commit 30aad9d

Browse files
committed
Support more terminators for parsing jsdoc filepaths
1 parent b902a71 commit 30aad9d

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

src/compiler/parser.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -2428,17 +2428,19 @@ namespace ts {
24282428

24292429
function parseJSDocType(): TypeNode {
24302430
scanner.setInJSDocType(true);
2431-
const dotdotdot = parseOptionalToken(SyntaxKind.DotDotDotToken);
24322431
const moduleSpecifier = parseOptionalToken(SyntaxKind.ModuleKeyword);
2433-
let type = parseTypeOrTypePredicate();
2434-
scanner.setInJSDocType(false);
24352432
if (moduleSpecifier) {
24362433
const moduleTag = createNode(SyntaxKind.JSDocNamepathType, moduleSpecifier.pos) as JSDocNamepathType;
2437-
while (token() !== SyntaxKind.CloseBraceToken && token() !== SyntaxKind.EndOfFileToken) {
2434+
const terminators = [SyntaxKind.CloseBraceToken, SyntaxKind.EndOfFileToken, SyntaxKind.CommaToken, SyntaxKind.CloseParenToken];
2435+
while (terminators.indexOf(token()) < 0) {
24382436
nextTokenJSDoc();
24392437
}
2440-
type = finishNode(moduleTag);
2438+
return finishNode(moduleTag);
24412439
}
2440+
2441+
const dotdotdot = parseOptionalToken(SyntaxKind.DotDotDotToken);
2442+
let type = parseTypeOrTypePredicate();
2443+
scanner.setInJSDocType(false);
24422444
if (dotdotdot) {
24432445
const variadic = createNode(SyntaxKind.JSDocVariadicType, dotdotdot.pos) as JSDocVariadicType;
24442446
variadic.type = type;

src/compiler/scanner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,7 @@ namespace ts {
19831983
// First non-whitespace character on this line.
19841984
let firstNonWhitespace = 0;
19851985
// These initial values are special because the first line is:
1986-
// firstNonWhitespace = 0 to indicate that we want leading whitspace,
1986+
// firstNonWhitespace = 0 to indicate that we want leading whitespace,
19871987

19881988
while (pos < end) {
19891989
char = text.charCodeAt(pos);

src/harness/fourslash.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,10 @@ namespace FourSlash {
12681268

12691269
private verifySignatureHelpWorker(options: FourSlashInterface.VerifySignatureHelpOptions) {
12701270
const help = this.getSignatureHelp({ triggerReason: options.triggerReason })!;
1271+
if (!help) {
1272+
this.raiseError("Could not get a help signature");
1273+
}
1274+
12711275
const selectedItem = help.items[help.selectedItemIndex];
12721276
// Argument index may exceed number of parameters
12731277
const currentParameter = selectedItem.parameters[help.argumentIndex] as ts.SignatureHelpParameter | undefined;

src/services/classifier.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
namespace ts {
2+
/** The classifier is used for syntactic highlighting in editors via the TSServer */
23
export function createClassifier(): Classifier {
34
const scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false);
45

tests/cases/fourslash/jsDocDontBreakWithNamespaces.ts

+17-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,27 @@
55
//// * @returns {module:@nodefuel/web~Webserver~wsServer#hello} Websocket server object
66
//// */
77
////function foo() { }
8-
////foo(''/**/);
8+
////foo(''/*foo*/);
9+
////
10+
/////**
11+
//// * @type {module:xxxxx} */
12+
//// */
13+
////function bar() { }
14+
////bar(''/*bar*/);
15+
916

1017
verify.signatureHelp({
11-
marker: "",
18+
marker: "foo",
1219
text: "foo(): any",
1320
docComment: "",
1421
tags: [
15-
{ name: "returns", text: "Websocket server object" },
22+
{ name: "returns", text: "Websocket server object" },
1623
],
1724
});
25+
26+
verify.signatureHelp({
27+
marker: "bar",
28+
text: "bar(): void",
29+
docComment: "",
30+
tags: [],
31+
});

0 commit comments

Comments
 (0)