Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
72f19ef
Initial scribbles
sandersn Sep 10, 2020
c08258b
Compiles but provides spans instead of location pairs
sandersn Sep 11, 2020
2f1d113
Switch to DocumentSpan
sandersn Sep 11, 2020
256a60a
Merge branch 'master' into editor-support-for-links
sandersn Nov 24, 2020
8ba5dc8
Builds w/protocol types + conversions
sandersn Nov 24, 2020
ca1b273
cleanup:better names and scrub TODOs
sandersn Nov 24, 2020
867ab34
fix test harness too
sandersn Nov 30, 2020
5d518d6
Misc
sandersn Nov 30, 2020
c07fe40
Parse and store links in the compiler
sandersn Dec 2, 2020
82c11fe
Merge branch 'master' into editor-support-for-links
sandersn Dec 3, 2020
90feb3e
more tests and some fixes
sandersn Dec 3, 2020
035bb4a
Merge branch 'master' into editor-support-for-links
sandersn Dec 4, 2020
fc813c2
Fix other failing tests
sandersn Dec 7, 2020
917314c
Merge branch 'master' into editor-support-for-links
sandersn Dec 7, 2020
7dd7cab
fix bad merge
sandersn Dec 7, 2020
c0e8d47
polish parser
sandersn Dec 7, 2020
8bbc8b4
improve names and array types
sandersn Dec 8, 2020
070da0b
slight tweaks
sandersn Dec 8, 2020
fce33f1
remove some done TODOs
sandersn Dec 8, 2020
7ac40d4
more tests + resulting fixes
sandersn Dec 8, 2020
6b1d4ce
add+fix cross-module tests
sandersn Dec 8, 2020
e4f111e
Support `@see {@link`
sandersn Dec 8, 2020
64baa18
add server test
sandersn Dec 8, 2020
681cc64
Merge branch 'master' into editor-support-for-links
sandersn Dec 8, 2020
c307c03
Make comments actually part of the AST
sandersn Dec 11, 2020
1a3e95b
Add span for link.name in language service/protocol
sandersn Dec 11, 2020
6631745
Merge branch 'master' into editor-support-for-links
sandersn Dec 14, 2020
ce966fc
Make checker optional in getJSDocTags
sandersn Dec 14, 2020
fdb67a6
Use getTokenValue instead of getTokenText
sandersn Dec 14, 2020
543b6ab
Add missing support for top-level links
sandersn Dec 15, 2020
36b1224
add string back to comment type in node constructors
sandersn Dec 15, 2020
38100f9
Merge branch 'master' into editor-support-for-links
sandersn Dec 18, 2020
d90244e
Merge branch 'master' into editor-support-for-links
sandersn Feb 18, 2021
bfefd33
Full parse of link tags and jsdoc comment text
sandersn Feb 24, 2021
d216e93
fix lint
sandersn Feb 24, 2021
6b2bd81
Fix missing newlines in inferFromUsage codefix
sandersn Feb 25, 2021
1f1250e
Merge branch 'master' into editor-support-for-links
sandersn Mar 2, 2021
3c35584
Merge branch 'master' into editor-support-for-links
sandersn Mar 3, 2021
6bdd493
Merge branch 'master' into editor-support-for-links
sandersn Mar 3, 2021
624c8f7
Parse jsdoc comments as text node/link array
sandersn Mar 3, 2021
6dbc6ce
Fix fourslash tests
sandersn Mar 3, 2021
ff2aba6
Improve types and documentation
sandersn Mar 3, 2021
8c5c650
Test+fix @link emit, scrub other TODOs
sandersn Mar 3, 2021
f93e131
update API baselines
sandersn Mar 4, 2021
c67946e
test that goto-def works with @link
sandersn Mar 4, 2021
36aa091
Split link displaypart into 3
sandersn Mar 5, 2021
c3883b7
update baselines
sandersn Mar 5, 2021
89e4955
Provide JSDocTagInfo.text: string to full clients by default
sandersn Mar 5, 2021
52d64db
Real server tests
sandersn Mar 8, 2021
5a21851
Disambiguate {@link} and @param x {type}
sandersn Mar 8, 2021
ab340f4
Add explanatory comment in test
sandersn Mar 8, 2021
3e5aa10
Merge branch 'master' into editor-support-for-links
sandersn Mar 8, 2021
618bcec
Merge branch 'master' into editor-support-for-links
sandersn Mar 10, 2021
5a29c2e
fix location in richResponse in protocol
sandersn Mar 10, 2021
67c4966
update API baseline
sandersn Mar 10, 2021
2da204a
Merge branch 'master' into editor-support-for-links
sandersn Mar 16, 2021
d0f3048
Address PR comments
sandersn Mar 16, 2021
4cfdaee
use arraysEqual from core
sandersn Mar 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix other failing tests
  • Loading branch information
sandersn committed Dec 7, 2020
commit fc813c2b728d6bb1cb3372220c16147f62a37128
4 changes: 2 additions & 2 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3512,7 +3512,7 @@ namespace ts {
//
function emitJSDoc(node: JSDoc) {
write("/**");
if (node.comment) {
if (node.comment?.text) {
const lines = node.comment.text.split(/\r\n?|\n/g);
for (const line of lines) {
writeLine();
Expand Down Expand Up @@ -3653,7 +3653,7 @@ namespace ts {
}

function emitJSDocComment(comment: JSDocComment | undefined) {
if (comment) {
if (comment?.text) {
writeSpace();
write(comment.text);
}
Expand Down
26 changes: 12 additions & 14 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7359,7 +7359,7 @@ namespace ts {
state = JSDocState.SavingComments;
// TODO: Maybe shouldn't use 1 as the length of { ?
const link = parseLink(scanner.getTextPos() - 1);
links.push(link)
links.push(link);
pushComment(scanner.getText().slice(link.pos, link.end));
break;
}
Expand Down Expand Up @@ -7588,9 +7588,9 @@ namespace ts {
// TODO: Put a manual `tok = nextTokenJSDoc()` here and only call `lookAhead` if its AtToken.
// THat means I'll have to save getTextPos *before* the nextTokenJSDoc and unconditionally `continue` afterward
if (lookAhead(() => nextTokenJSDoc() === SyntaxKind.AtToken && tokenIsIdentifierOrKeyword(nextTokenJSDoc()) && scanner.getTokenText() === "link")) {
const link = parseLink(scanner.getTextPos() - 1)
links.push(link)
pushComment(scanner.getText().slice(link.pos, link.end))
const link = parseLink(scanner.getTextPos() - 1);
links.push(link);
pushComment(scanner.getText().slice(link.pos, link.end));
}
else {
pushComment(scanner.getTokenText());
Expand Down Expand Up @@ -7632,19 +7632,17 @@ namespace ts {
function parseLink(start: number) {
nextTokenJSDoc(); // @
nextTokenJSDoc(); // link
nextTokenJSDoc(); // ' ' TODO: make sure that each of these tokens after @link are actually the expected ones
nextTokenJSDoc(); // first token TODO: Skip multiple whitespace/newlines
// TODO: When failing, decide whether to parse a trailing }. Probably doesn't matter since the only thing we're interested inside comment text is `@` (and *, newline, etc)
// oh, except for `{@link}` should parse correctly
const name = tokenIsIdentifierOrKeyword(token()) ? parseEntityName(/*allowReservedWords*/ true) : createMissingNode<Identifier>(SyntaxKind.Identifier, false); // don't try to parseEntityName, it'll assert
// TODO: I'm pretty sure you getting a MissingIdentifier for a bad parse, or soething like that
// in any case, most of the time you'll have `http` as the first identifier and you'll be fine
// now skip past everything including a close brace.
// .. also stop at newlines (TODO: Measure this (it's probably fine, and the penalty for being wrong is just a too-small span), and then write tests)

nextTokenJSDoc(); // start at token after link, then skip any whitespace
skipWhitespace();
// parseEntityName logs an error for non-identifier, so create a MissingNode ourselves to avoid the error
const name = tokenIsIdentifierOrKeyword(token())
? parseEntityName(/*allowReservedWords*/ true)
: createMissingNode<Identifier>(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false);
while (token() !== SyntaxKind.CloseBraceToken && token() !== SyntaxKind.NewLineTrivia) {
nextTokenJSDoc();
}
return finishNode(factory.createJSDocLinkNode(name), start, scanner.getTextPos())
return finishNode(factory.createJSDocLinkNode(name), start, scanner.getTextPos());
}

function parseUnknownTag(start: number, tagName: Identifier, indent: number, indentText: string) {
Expand Down
12 changes: 7 additions & 5 deletions src/harness/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ namespace ts.server {
lineMap = lineMap || this.getLineMap(fileName);
return createTextSpanFromBounds(
this.lineOffsetToPosition(fileName, span.start, lineMap),
this.lineOffsetToPosition(fileName, span.end, lineMap));
this.lineOffsetToPosition(fileName, Debug.checkDefined(span.end, JSON.stringify(span)), lineMap));
}

private decodeLink(tags: readonly protocol.JSDocTagInfo[]): readonly JSDocTagInfo[] {
Expand All @@ -527,11 +527,12 @@ namespace ts.server {
links: tag.links?.map(link => ({
...link,
target: {
textSpan: this.decodeSpan(link.target),
// TODO: May still need to decode MOST of the link.targets
textSpan: link.target as unknown as TextSpan,
fileName: link.target.file,
}
}))
}))
}));
}

getNameOrDottedNameSpan(_fileName: string, _startPos: number, _endPos: number): TextSpan {
Expand All @@ -554,8 +555,9 @@ namespace ts.server {

const { items: encodedItems, applicableSpan: encodedApplicableSpan, selectedItemIndex, argumentIndex, argumentCount } = response.body;

const applicableSpan = this.decodeSpan(encodedApplicableSpan, fileName);
const items = encodedItems.map(item => ({ ...item, tags: this.decodeLink(item.tags) }))
// TODO: I thought that applicable span was a protocol span now?! I guess not.
const applicableSpan = encodedApplicableSpan as unknown as TextSpan; //this.decodeSpan(encodedApplicableSpan, fileName);
const items = encodedItems.map(item => ({ ...item, tags: this.decodeLink(item.tags) }));

return { items, applicableSpan, selectedItemIndex, argumentIndex, argumentCount };
}
Expand Down
2 changes: 1 addition & 1 deletion src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ namespace FourSlash {
// assert.equal(actualDetails.kind, actual.kind);
assert.equal(actualDetails.kindModifiers, actual.kindModifiers, "Expected 'kindModifiers' properties to match");
assert.equal(actualDetails.source && ts.displayPartsToString(actualDetails.source), expected.sourceDisplay, "Expected 'sourceDisplay' property to match 'source' display parts string");
assert.deepEqual(actualDetails.tags, expected.tags);
assert.deepEqual(actualDetails.tags, expected.tags, "Try harder, chai:" + JSON.stringify(actualDetails) + "\n" + JSON.stringify(expected) + " at " + this.lastKnownMarker);
}
else {
assert(expected.documentation === undefined && expected.tags === undefined && expected.sourceDisplay === undefined, "If specifying completion details, should specify 'text'");
Expand Down
2 changes: 1 addition & 1 deletion src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ namespace ts.server {
links: links?.map(link => ({
...link,
target: this.toFileSpan(link.target.fileName, link.target.textSpan, project),
}))}))
}))}));
}

private mapDefinitionInfo(definitions: readonly DefinitionInfo[], project: Project): readonly protocol.FileSpanWithContext[] {
Expand Down
14 changes: 7 additions & 7 deletions src/services/jsDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,22 @@ namespace ts.JsDoc {
}

function getLinks(tag: JSDocTag, checker: TypeChecker): JSDocLink[] | undefined {
const links = tag.comment?.links
const links = tag.comment?.links;
if (links) {
return mapDefined(links, link => {
if (!link.name) return
if (!link.name) return;
// TODO: Test this, I think getSymbolAtLocation eventually calls checkQualifiedName and then returns resolvedSymbol, but it's hard to be sure
const symbol = checker.getSymbolAtLocation(link.name)
if (!symbol || !symbol.valueDeclaration) return
const symbol = checker.getSymbolAtLocation(link.name);
if (!symbol || !symbol.valueDeclaration) return;
return {
fileName: getSourceFileOfNode(see).fileName,
textSpan: createTextSpanFromNode(see),
target: {
fileName: getSourceFileOfNode(symbol.valueDeclaration).fileName,
textSpan: createTextSpanFromNode(symbol.valueDeclaration)
}
}
})
};
});
}
const see = tag as JSDocSeeTag;
}
Expand Down Expand Up @@ -175,7 +175,7 @@ namespace ts.JsDoc {
}

function addComment(s: string) {
return comment === undefined ? s : `${s} ${comment}`;
return comment === undefined ? s : `${s} ${comment.text}`;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/jsDocParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ oh.no
}
* Forgot to close this one {@link https://typescriptlang.org
* But it's still OK.
* And it shouldn't mess up subsequent margins (I hope).
* Although it skips the newline so parses the asterisks in the wrong state.
* This shouldn't work: {@link
* nope
* }, because of the intermediate asterisks.
Expand Down
3 changes: 2 additions & 1 deletion src/testRunner/unittests/tsserver/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ namespace ts.projectSystem {
kindModifiers: ScriptElementKindModifier.exportedModifier,
name: "foo",
source: [{ text: "./a", kind: "text" }],
tags: undefined,
};
assert.deepEqual<readonly protocol.CompletionEntryDetails[] | undefined>(detailsResponse, [
{
Expand All @@ -90,6 +89,7 @@ namespace ts.projectSystem {
commands: undefined,
},
],
tags: [],
...detailsCommon,
},
]);
Expand All @@ -116,6 +116,7 @@ namespace ts.projectSystem {
commands: undefined,
}
],
tags: undefined,
...detailsCommon,
}
]);
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/APISample_jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function parseCommentsIntoDefinition(this: any,
}

// jsdocs are separate from comments
const jsdocs = symbol.getJsDocTags();
const jsdocs = symbol.getJsDocTags(this.checker);
jsdocs.forEach(doc => {
// if we have @TJS-... annotations, we have to parse them
const { name, text } = doc;
Expand All @@ -59,7 +59,7 @@ function getAnnotations(this: any, node: ts.Node): Annotations | undefined {
return undefined;
}

const jsDocTags: ts.JSDocTagInfo[] = symbol.getJsDocTags();
const jsDocTags: ts.JSDocTagInfo[] = symbol.getJsDocTags(this.checker);
if (!jsDocTags || !jsDocTags.length) {
return undefined;
}
Expand Down Expand Up @@ -143,7 +143,7 @@ function parseCommentsIntoDefinition(symbol, definition, otherAnnotations) {
definition.description = comments.map(function (comment) { return comment.kind === "lineBreak" ? comment.text : comment.text.trim().replace(/\r\n/g, "\n"); }).join("");
}
// jsdocs are separate from comments
var jsdocs = symbol.getJsDocTags();
var jsdocs = symbol.getJsDocTags(this.checker);
jsdocs.forEach(function (doc) {
// if we have @TJS-... annotations, we have to parse them
var name = doc.name, text = doc.text;
Expand All @@ -162,7 +162,7 @@ function getAnnotations(node) {
if (!symbol) {
return undefined;
}
var jsDocTags = symbol.getJsDocTags();
var jsDocTags = symbol.getJsDocTags(this.checker);
if (!jsDocTags || !jsDocTags.length) {
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 646,
"end": 674,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
Expand Down Expand Up @@ -104,7 +104,7 @@
"1": {
"kind": "JSDocParameterTag",
"pos": 102,
"end": 569,
"end": 589,
"modifierFlagsCache": 0,
"transformFlags": 0,
"tagName": {
Expand Down Expand Up @@ -161,9 +161,99 @@
"escapedText": "Complex"
}
}
},
{
"kind": "JSDocLink",
"pos": 203,
"end": 210,
"modifierFlagsCache": 0,
"transformFlags": 0,
"name": {
"kind": "Identifier",
"pos": 209,
"end": 209,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": ""
}
},
{
"kind": "JSDocLink",
"pos": 244,
"end": 262,
"modifierFlagsCache": 0,
"transformFlags": 0,
"name": {
"kind": "Identifier",
"pos": 252,
"end": 259,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "doubled"
}
},
{
"kind": "JSDocLink",
"pos": 326,
"end": 340,
"modifierFlagsCache": 0,
"transformFlags": 0,
"name": {
"kind": "FirstNode",
"pos": 333,
"end": 338,
"modifierFlagsCache": 0,
"transformFlags": 0,
"left": {
"kind": "Identifier",
"pos": 333,
"end": 335,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "oh"
},
"right": {
"kind": "Identifier",
"pos": 336,
"end": 338,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "no"
}
}
},
{
"kind": "JSDocLink",
"pos": 369,
"end": 403,
"modifierFlagsCache": 0,
"transformFlags": 0,
"name": {
"kind": "Identifier",
"pos": 376,
"end": 381,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "https"
}
},
{
"kind": "JSDocLink",
"pos": 526,
"end": 541,
"modifierFlagsCache": 0,
"transformFlags": 0,
"name": {
"kind": "Identifier",
"pos": 534,
"end": 534,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": ""
}
}
],
"text": "Or see {@link http://www.zombocom.com }\n{@link Standalone.Complex }"
"text": "Or see {@link http://www.zombocom.com }\n{@link Standalone.Complex }\nThis empty one: {@link} is OK.\nThis double-space one: {@link doubled } is OK too.\nThis should work, despite being badly formatted: {@link\noh.no\n}\nForgot to close this one {@link https://typescriptlang.org\n * But it's still OK.\nAlthough it skips the newline so parses the asterisks in the wrong state.\nThis shouldn't work: {@link\n * nope\n * }, because of the intermediate asterisks."
},
"name": {
"kind": "Identifier",
Expand All @@ -176,9 +266,44 @@
"isNameFirst": true,
"isBracketed": false
},
"length": 2,
"2": {
"kind": "JSDocAuthorTag",
"pos": 589,
"end": 672,
"modifierFlagsCache": 0,
"transformFlags": 0,
"tagName": {
"kind": "Identifier",
"pos": 590,
"end": 596,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "author"
},
"comment": {
"links": [
{
"kind": "JSDocLink",
"pos": 643,
"end": 670,
"modifierFlagsCache": 0,
"transformFlags": 0,
"name": {
"kind": "Identifier",
"pos": 650,
"end": 655,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "https"
}
}
],
"text": "Alfa Romero <[email protected]> See my home page: {@link https://example.com}"
}
},
"length": 3,
"pos": 59,
"end": 644,
"end": 672,
"hasTrailingComma": false,
"transformFlags": 0
}
Expand Down
Loading