Skip to content

Commit

Permalink
Support more terminators for parsing jsdoc filepaths
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Jul 29, 2019
1 parent b902a71 commit 30aad9d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2428,17 +2428,19 @@ namespace ts {

function parseJSDocType(): TypeNode {
scanner.setInJSDocType(true);
const dotdotdot = parseOptionalToken(SyntaxKind.DotDotDotToken);
const moduleSpecifier = parseOptionalToken(SyntaxKind.ModuleKeyword);
let type = parseTypeOrTypePredicate();
scanner.setInJSDocType(false);
if (moduleSpecifier) {
const moduleTag = createNode(SyntaxKind.JSDocNamepathType, moduleSpecifier.pos) as JSDocNamepathType;
while (token() !== SyntaxKind.CloseBraceToken && token() !== SyntaxKind.EndOfFileToken) {
const terminators = [SyntaxKind.CloseBraceToken, SyntaxKind.EndOfFileToken, SyntaxKind.CommaToken, SyntaxKind.CloseParenToken];
while (terminators.indexOf(token()) < 0) {
nextTokenJSDoc();
}
type = finishNode(moduleTag);
return finishNode(moduleTag);
}

const dotdotdot = parseOptionalToken(SyntaxKind.DotDotDotToken);
let type = parseTypeOrTypePredicate();
scanner.setInJSDocType(false);
if (dotdotdot) {
const variadic = createNode(SyntaxKind.JSDocVariadicType, dotdotdot.pos) as JSDocVariadicType;
variadic.type = type;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,7 @@ namespace ts {
// First non-whitespace character on this line.
let firstNonWhitespace = 0;
// These initial values are special because the first line is:
// firstNonWhitespace = 0 to indicate that we want leading whitspace,
// firstNonWhitespace = 0 to indicate that we want leading whitespace,

while (pos < end) {
char = text.charCodeAt(pos);
Expand Down
4 changes: 4 additions & 0 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,10 @@ namespace FourSlash {

private verifySignatureHelpWorker(options: FourSlashInterface.VerifySignatureHelpOptions) {
const help = this.getSignatureHelp({ triggerReason: options.triggerReason })!;
if (!help) {
this.raiseError("Could not get a help signature");
}

const selectedItem = help.items[help.selectedItemIndex];
// Argument index may exceed number of parameters
const currentParameter = selectedItem.parameters[help.argumentIndex] as ts.SignatureHelpParameter | undefined;
Expand Down
1 change: 1 addition & 0 deletions src/services/classifier.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace ts {
/** The classifier is used for syntactic highlighting in editors via the TSServer */
export function createClassifier(): Classifier {
const scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false);

Expand Down
20 changes: 17 additions & 3 deletions tests/cases/fourslash/jsDocDontBreakWithNamespaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,27 @@
//// * @returns {module:@nodefuel/web~Webserver~wsServer#hello} Websocket server object
//// */
////function foo() { }
////foo(''/**/);
////foo(''/*foo*/);
////
/////**
//// * @type {module:xxxxx} */
//// */
////function bar() { }
////bar(''/*bar*/);


verify.signatureHelp({
marker: "",
marker: "foo",
text: "foo(): any",
docComment: "",
tags: [
{ name: "returns", text: "Websocket server object" },
{ name: "returns", text: "Websocket server object" },
],
});

verify.signatureHelp({
marker: "bar",
text: "bar(): void",
docComment: "",
tags: [],
});

0 comments on commit 30aad9d

Please sign in to comment.