Skip to content

fix jsdoc errors in .ts in tsserver #54185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/testRunner/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
140 changes: 140 additions & 0 deletions src/testRunner/unittests/services/goToDefinition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { protocol } from "../../_namespaces/ts.server";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this file to unittests/tsserver instead.. All the tests throgh tsserver are in there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied findAllReferences in this same directory. Should I move that one too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes pls.

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);

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 = "";
Expand Down
Loading