fix jsdoc errors in .ts in tsserver (#54185)

This commit is contained in:
Nathan Shively-Sanders
2023-05-09 10:00:48 -07:00
committed by GitHub
parent 7c03f7b500
commit 59d3a38180
14 changed files with 457 additions and 2 deletions

View File

@@ -3407,6 +3407,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (nameNotFoundMessage) {
addLazyDiagnostic(() => {
if (!errorLocation ||
errorLocation.parent.kind !== SyntaxKind.JSDocLink &&
!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg!) && // TODO: GH#18217
!checkAndReportErrorForInvalidInitializer() &&
!checkAndReportErrorForExtendingInterface(errorLocation) &&
@@ -45526,11 +45527,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const symbol = getIntrinsicTagSymbol(name.parent as JsxOpeningLikeElement);
return symbol === unknownSymbol ? undefined : symbol;
}
const result = resolveEntityName(name, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/ true, getHostSignatureFromJSDoc(name));
const result = resolveEntityName(name, meaning, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, getHostSignatureFromJSDoc(name));
if (!result && isJSDoc) {
const container = findAncestor(name, or(isClassLike, isInterfaceDeclaration));
if (container) {
return resolveJSDocMemberName(name, /*ignoreErrors*/ false, getSymbolOfDeclaration(container));
return resolveJSDocMemberName(name, /*ignoreErrors*/ true, getSymbolOfDeclaration(container));
}
}
if (result && isJSDoc) {

View File

@@ -54,6 +54,7 @@ import "./unittests/services/extract/functions";
import "./unittests/services/extract/symbolWalker";
import "./unittests/services/extract/ranges";
import "./unittests/services/findAllReferences";
import "./unittests/services/goToDefinition";
import "./unittests/services/hostNewLineSupport";
import "./unittests/services/languageService";
import "./unittests/services/organizeImports";

View File

@@ -0,0 +1,140 @@
import { protocol } from "../../_namespaces/ts.server";
import { baselineTsserverLogs, createLoggerWithInMemoryLogs, createSession } from "../helpers/tsserver";
import { createServerHost, File } from "../helpers/virtualFileSystemWithWatch";
describe("unittests:: services:: goToDefinition", () => {
it("does not issue errors on jsdoc in TS", () => {
const files: File[] = [
{
path: "/packages/babel-loader/tsconfig.json",
content:
`
{
"compilerOptions": {
"target": "ES2018",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"rootDir": "src",
"outDir": "dist"
},
"include": ["src"],
}
`
},
{
path: "/packages/babel-loader/src/index.ts",
content:
`
declare class Stuff {
/** For more thorough tests, use {@link checkFooIs} */
checkFooLengthIs(len: number): void;
checkFooIs(value: object): void;
}
`
},
];
const host = createServerHost(files);
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
// Open files in the two configured projects
session.executeCommandSeq<protocol.UpdateOpenRequest>({
command: protocol.CommandTypes.UpdateOpen,
arguments: {
openFiles: [
{
file: files[1].path, // babel-loader/src/index.ts
fileContent: files[1].content,
}
]
}
});
session.executeCommandSeq<protocol.DefinitionRequest>({
command: protocol.CommandTypes.Definition,
arguments: {
line: 3,
offset: 45,
file: "/packages/babel-loader/src/index.ts",
},
});
// Now change `babel-loader` project to no longer import `core` project
session.executeCommandSeq<protocol.SemanticDiagnosticsSyncRequest>({
command: protocol.CommandTypes.SemanticDiagnosticsSync,
arguments: {
file: "/packages/babel-loader/src/index.ts",
}
});
baselineTsserverLogs("goToDefinition", "does not issue errors on jsdoc in TS", session);
});
it("does not issue errors on jsdoc in TS", () => {
const files: File[] = [
{
path: "/packages/babel-loader/tsconfig.json",
content:
`
{
"compilerOptions": {
"target": "ES2018",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"rootDir": "src",
"outDir": "dist"
},
"include": ["src"],
}
`
},
{
path: "/packages/babel-loader/src/index.ts",
content:
`
declare class Stuff {
/**
* Register a function to be run on mod initialization...
*
* {@link https://lua-api.factorio.com/latest/LuaBootstrap.html#LuaBootstrap.on_init View documentation}
* @param f The handler for this event. Passing nil will unregister it.
* @remarks For more context, refer to the {@link https://lua-api.factorio.com/latest/Data-Lifecycle.html Data Lifecycle} page.
* @example Initialize a players table in global for later use.
*
*/
on_init(f: (() => void) | undefined): void
}
`
},
];
const host = createServerHost(files);
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
// Open files in the two configured projects
session.executeCommandSeq<protocol.UpdateOpenRequest>({
command: protocol.CommandTypes.UpdateOpen,
arguments: {
openFiles: [
{
file: files[1].path, // babel-loader/src/index.ts
fileContent: files[1].content,
}
]
}
});
session.executeCommandSeq<protocol.DefinitionRequest>({
command: protocol.CommandTypes.Definition,
arguments: {
line: 6,
offset: 13,
file: "/packages/babel-loader/src/index.ts",
},
});
// Now change `babel-loader` project to no longer import `core` project
session.executeCommandSeq<protocol.SemanticDiagnosticsSyncRequest>({
command: protocol.CommandTypes.SemanticDiagnosticsSync,
arguments: {
file: "/packages/babel-loader/src/index.ts",
}
});
baselineTsserverLogs("goToDefinition", "does not issue errors on jsdoc in TS2", session);
});
});

View File

@@ -7,6 +7,7 @@ class CCC {
y: number = aaa;
>y : Symbol(CCC.y, Decl(classMemberInitializerScoping.ts, 1, 11))
>aaa : Symbol(aaa, Decl(classMemberInitializerScoping.ts, 0, 3))
static staticY: number = aaa; // This shouldnt be error
>staticY : Symbol(CCC.staticY, Decl(classMemberInitializerScoping.ts, 2, 20))

View File

@@ -7,6 +7,7 @@ class C {
p = x
>p : Symbol(C.p, Decl(classMemberInitializerScoping2.ts, 1, 9))
>x : Symbol(x, Decl(classMemberInitializerScoping2.ts, 0, 5))
constructor(x: string) { }
>x : Symbol(x, Decl(classMemberInitializerScoping2.ts, 3, 16))

View File

@@ -7,6 +7,7 @@ class C {
p = x
>p : Symbol(C.p, Decl(classMemberInitializerScoping2.ts, 1, 9))
>x : Symbol(x, Decl(classMemberInitializerScoping2.ts, 0, 5))
constructor(x: string) { }
>x : Symbol(x, Decl(classMemberInitializerScoping2.ts, 3, 16))

View File

@@ -7,6 +7,7 @@ class C {
p = x
>p : Symbol(C.p, Decl(classMemberInitializerScoping2.ts, 1, 9))
>x : Symbol(x, Decl(classMemberInitializerScoping2.ts, 0, 5))
constructor(x: string) { }
>x : Symbol(x, Decl(classMemberInitializerScoping2.ts, 3, 16))

View File

@@ -66,6 +66,7 @@ class Test1 {
>console.log : Symbol(log, Decl(classMemberInitializerWithLamdaScoping.ts, 0, 22))
>console : Symbol(console, Decl(classMemberInitializerWithLamdaScoping.ts, 0, 11))
>log : Symbol(log, Decl(classMemberInitializerWithLamdaScoping.ts, 0, 22))
>field1 : Symbol(field1, Decl(classMemberInitializerWithLamdaScoping.ts, 17, 3))
// but since this code would be generated inside constructor, in generated js
// it would resolve to private field1 and thats not what user intended here.

View File

@@ -24,6 +24,7 @@ class Test1 {
>console.log : Symbol(log, Decl(classMemberInitializerWithLamdaScoping2_1.ts, 0, 22))
>console : Symbol(console, Decl(classMemberInitializerWithLamdaScoping2_1.ts, 0, 11))
>log : Symbol(log, Decl(classMemberInitializerWithLamdaScoping2_1.ts, 0, 22))
>field1 : Symbol(field1, Decl(classMemberInitializerWithLamdaScoping2_0.ts, 0, 3))
// but since this code would be generated inside constructor, in generated js
// it would resolve to private field1 and thats not what user intended here.

View File

@@ -24,6 +24,7 @@ export class Test1 {
>console.log : Symbol(log, Decl(classMemberInitializerWithLamdaScoping3_1.ts, 0, 22))
>console : Symbol(console, Decl(classMemberInitializerWithLamdaScoping3_1.ts, 0, 11))
>log : Symbol(log, Decl(classMemberInitializerWithLamdaScoping3_1.ts, 0, 22))
>field1 : Symbol(field1, Decl(classMemberInitializerWithLamdaScoping3_0.ts, 0, 3))
// but since this code would be generated inside constructor, in generated js
// it would resolve to private field1 and thats not what user intended here.

View File

@@ -12,6 +12,7 @@ class C {
b = x; // error, evaluated in scope of constructor, cannot reference x
>b : Symbol(C.b, Decl(constructorParameterShadowsOuterScopes.ts, 6, 9))
>x : Symbol(x, Decl(constructorParameterShadowsOuterScopes.ts, 5, 3))
constructor(x: string) {
>x : Symbol(x, Decl(constructorParameterShadowsOuterScopes.ts, 8, 16))
@@ -29,6 +30,7 @@ class D {
b = y; // error, evaluated in scope of constructor, cannot reference y
>b : Symbol(D.b, Decl(constructorParameterShadowsOuterScopes.ts, 14, 9))
>y : Symbol(y, Decl(constructorParameterShadowsOuterScopes.ts, 13, 3))
constructor(x: string) {
>x : Symbol(x, Decl(constructorParameterShadowsOuterScopes.ts, 16, 16))

View File

@@ -7,6 +7,7 @@ class A {
private a = x;
>a : Symbol(A.a, Decl(constructorParametersThatShadowExternalNamesInVariableDeclarations.ts, 1, 9))
>x : Symbol(x, Decl(constructorParametersThatShadowExternalNamesInVariableDeclarations.ts, 0, 3))
constructor(x: number) {
>x : Symbol(x, Decl(constructorParametersThatShadowExternalNamesInVariableDeclarations.ts, 3, 16))
@@ -18,6 +19,7 @@ class B {
private a = x;
>a : Symbol(B.a, Decl(constructorParametersThatShadowExternalNamesInVariableDeclarations.ts, 7, 9))
>x : Symbol(x, Decl(constructorParametersThatShadowExternalNamesInVariableDeclarations.ts, 0, 3))
constructor() {
var x = "";

View File

@@ -0,0 +1,158 @@
currentDirectory:: / useCaseSensitiveFileNames: false
Info seq [hh:mm:ss:mss] Provided types map file "/a/lib/typesMap.json" doesn't exist
Before request
//// [/packages/babel-loader/tsconfig.json]
{
"compilerOptions": {
"target": "ES2018",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"rootDir": "src",
"outDir": "dist"
},
"include": ["src"],
}
//// [/packages/babel-loader/src/index.ts]
declare class Stuff {
/** For more thorough tests, use {@link checkFooIs} */
checkFooLengthIs(len: number): void;
checkFooIs(value: object): void;
}
Info seq [hh:mm:ss:mss] request:
{
"command": "updateOpen",
"arguments": {
"openFiles": [
{
"file": "/packages/babel-loader/src/index.ts",
"fileContent": "\ndeclare class Stuff {\n /** For more thorough tests, use {@link checkFooIs} */\n checkFooLengthIs(len: number): void;\n\n checkFooIs(value: object): void;\n}\n"
}
]
},
"seq": 1,
"type": "request"
}
Info seq [hh:mm:ss:mss] Search path: /packages/babel-loader/src
Info seq [hh:mm:ss:mss] For info: /packages/babel-loader/src/index.ts :: Config file name: /packages/babel-loader/tsconfig.json
Info seq [hh:mm:ss:mss] Creating configuration project /packages/babel-loader/tsconfig.json
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /packages/babel-loader/tsconfig.json 2000 undefined Project: /packages/babel-loader/tsconfig.json WatchType: Config file
Info seq [hh:mm:ss:mss] Config: /packages/babel-loader/tsconfig.json : {
"rootNames": [
"/packages/babel-loader/src/index.ts"
],
"options": {
"target": 5,
"module": 1,
"strict": true,
"esModuleInterop": true,
"rootDir": "/packages/babel-loader/src",
"outDir": "/packages/babel-loader/dist",
"configFilePath": "/packages/babel-loader/tsconfig.json"
}
}
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /packages/babel-loader/src 1 undefined Config: /packages/babel-loader/tsconfig.json WatchType: Wild card directory
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /packages/babel-loader/src 1 undefined Config: /packages/babel-loader/tsconfig.json WatchType: Wild card directory
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /packages/babel-loader/tsconfig.json
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /a/lib/lib.es2018.full.d.ts 500 undefined Project: /packages/babel-loader/tsconfig.json WatchType: Missing file
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /packages/babel-loader/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms
Info seq [hh:mm:ss:mss] Project '/packages/babel-loader/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (1)
/packages/babel-loader/src/index.ts SVC-1-0 "\ndeclare class Stuff {\n /** For more thorough tests, use {@link checkFooIs} */\n checkFooLengthIs(len: number): void;\n\n checkFooIs(value: object): void;\n}\n"
src/index.ts
Matched by include pattern 'src' in 'tsconfig.json'
Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Project '/packages/babel-loader/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (1)
Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Open files:
Info seq [hh:mm:ss:mss] FileName: /packages/babel-loader/src/index.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /packages/babel-loader/tsconfig.json
Info seq [hh:mm:ss:mss] response:
{
"response": true,
"responseRequired": true
}
After request
PolledWatches::
/a/lib/lib.es2018.full.d.ts: *new*
{"pollingInterval":500}
FsWatches::
/packages/babel-loader/tsconfig.json: *new*
{}
FsWatchesRecursive::
/packages/babel-loader/src: *new*
{}
Before request
Info seq [hh:mm:ss:mss] request:
{
"command": "definition",
"arguments": {
"line": 3,
"offset": 45,
"file": "/packages/babel-loader/src/index.ts"
},
"seq": 2,
"type": "request"
}
Info seq [hh:mm:ss:mss] response:
{
"response": [
{
"file": "/packages/babel-loader/src/index.ts",
"start": {
"line": 6,
"offset": 5
},
"end": {
"line": 6,
"offset": 15
},
"contextStart": {
"line": 6,
"offset": 5
},
"contextEnd": {
"line": 6,
"offset": 37
}
}
],
"responseRequired": true
}
After request
Before request
Info seq [hh:mm:ss:mss] request:
{
"command": "semanticDiagnosticsSync",
"arguments": {
"file": "/packages/babel-loader/src/index.ts"
},
"seq": 3,
"type": "request"
}
Info seq [hh:mm:ss:mss] response:
{
"response": [],
"responseRequired": true
}
After request

View File

@@ -0,0 +1,144 @@
currentDirectory:: / useCaseSensitiveFileNames: false
Info seq [hh:mm:ss:mss] Provided types map file "/a/lib/typesMap.json" doesn't exist
Before request
//// [/packages/babel-loader/tsconfig.json]
{
"compilerOptions": {
"target": "ES2018",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"rootDir": "src",
"outDir": "dist"
},
"include": ["src"],
}
//// [/packages/babel-loader/src/index.ts]
declare class Stuff {
/**
* Register a function to be run on mod initialization...
*
* {@link https://lua-api.factorio.com/latest/LuaBootstrap.html#LuaBootstrap.on_init View documentation}
* @param f The handler for this event. Passing nil will unregister it.
* @remarks For more context, refer to the {@link https://lua-api.factorio.com/latest/Data-Lifecycle.html Data Lifecycle} page.
* @example Initialize a players table in global for later use.
*
*/
on_init(f: (() => void) | undefined): void
}
Info seq [hh:mm:ss:mss] request:
{
"command": "updateOpen",
"arguments": {
"openFiles": [
{
"file": "/packages/babel-loader/src/index.ts",
"fileContent": "\ndeclare class Stuff {\n /**\n * Register a function to be run on mod initialization...\n *\n * {@link https://lua-api.factorio.com/latest/LuaBootstrap.html#LuaBootstrap.on_init View documentation}\n * @param f The handler for this event. Passing nil will unregister it.\n * @remarks For more context, refer to the {@link https://lua-api.factorio.com/latest/Data-Lifecycle.html Data Lifecycle} page.\n * @example Initialize a players table in global for later use.\n *\n */\n on_init(f: (() => void) | undefined): void\n}\n"
}
]
},
"seq": 1,
"type": "request"
}
Info seq [hh:mm:ss:mss] Search path: /packages/babel-loader/src
Info seq [hh:mm:ss:mss] For info: /packages/babel-loader/src/index.ts :: Config file name: /packages/babel-loader/tsconfig.json
Info seq [hh:mm:ss:mss] Creating configuration project /packages/babel-loader/tsconfig.json
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /packages/babel-loader/tsconfig.json 2000 undefined Project: /packages/babel-loader/tsconfig.json WatchType: Config file
Info seq [hh:mm:ss:mss] Config: /packages/babel-loader/tsconfig.json : {
"rootNames": [
"/packages/babel-loader/src/index.ts"
],
"options": {
"target": 5,
"module": 1,
"strict": true,
"esModuleInterop": true,
"rootDir": "/packages/babel-loader/src",
"outDir": "/packages/babel-loader/dist",
"configFilePath": "/packages/babel-loader/tsconfig.json"
}
}
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /packages/babel-loader/src 1 undefined Config: /packages/babel-loader/tsconfig.json WatchType: Wild card directory
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /packages/babel-loader/src 1 undefined Config: /packages/babel-loader/tsconfig.json WatchType: Wild card directory
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /packages/babel-loader/tsconfig.json
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /a/lib/lib.es2018.full.d.ts 500 undefined Project: /packages/babel-loader/tsconfig.json WatchType: Missing file
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /packages/babel-loader/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms
Info seq [hh:mm:ss:mss] Project '/packages/babel-loader/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (1)
/packages/babel-loader/src/index.ts SVC-1-0 "\ndeclare class Stuff {\n /**\n * Register a function to be run on mod initialization...\n *\n * {@link https://lua-api.factorio.com/latest/LuaBootstrap.html#LuaBootstrap.on_init View documentation}\n * @param f The handler for this event. Passing nil will unregister it.\n * @remarks For more context, refer to the {@link https://lua-api.factorio.com/latest/Data-Lifecycle.html Data Lifecycle} page.\n * @example Initialize a players table in global for later use.\n *\n */\n on_init(f: (() => void) | undefined): void\n}\n"
src/index.ts
Matched by include pattern 'src' in 'tsconfig.json'
Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Project '/packages/babel-loader/tsconfig.json' (Configured)
Info seq [hh:mm:ss:mss] Files (1)
Info seq [hh:mm:ss:mss] -----------------------------------------------
Info seq [hh:mm:ss:mss] Open files:
Info seq [hh:mm:ss:mss] FileName: /packages/babel-loader/src/index.ts ProjectRootPath: undefined
Info seq [hh:mm:ss:mss] Projects: /packages/babel-loader/tsconfig.json
Info seq [hh:mm:ss:mss] response:
{
"response": true,
"responseRequired": true
}
After request
PolledWatches::
/a/lib/lib.es2018.full.d.ts: *new*
{"pollingInterval":500}
FsWatches::
/packages/babel-loader/tsconfig.json: *new*
{}
FsWatchesRecursive::
/packages/babel-loader/src: *new*
{}
Before request
Info seq [hh:mm:ss:mss] request:
{
"command": "definition",
"arguments": {
"line": 6,
"offset": 13,
"file": "/packages/babel-loader/src/index.ts"
},
"seq": 2,
"type": "request"
}
Info seq [hh:mm:ss:mss] response:
{
"response": [],
"responseRequired": true
}
After request
Before request
Info seq [hh:mm:ss:mss] request:
{
"command": "semanticDiagnosticsSync",
"arguments": {
"file": "/packages/babel-loader/src/index.ts"
},
"seq": 3,
"type": "request"
}
Info seq [hh:mm:ss:mss] response:
{
"response": [],
"responseRequired": true
}
After request