Skip to content

Commit f0aa3b8

Browse files
authored
Revert "Merge pull request #11713 from Microsoft/PortSkipSemanticCheckToRelease-2-0-5" (#11802)
This reverts commit 3ab3d95, reversing changes made to cca3c1f.
1 parent 1d31716 commit f0aa3b8

File tree

7 files changed

+28
-207
lines changed

7 files changed

+28
-207
lines changed

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ namespace ts {
902902
basePath: string, errors: Diagnostic[], configFileName?: string): CompilerOptions {
903903

904904
const options: CompilerOptions = getBaseFileName(configFileName) === "jsconfig.json"
905-
? { allowJs: true, maxNodeModuleJsDepth: 2, allowSyntheticDefaultImports: true, skipLibCheck: true }
905+
? { allowJs: true, maxNodeModuleJsDepth: 2, allowSyntheticDefaultImports: true }
906906
: {};
907907
convertOptionsFromJson(optionDeclarations, jsonOptions, basePath, options, Diagnostics.Unknown_compiler_option_0, errors);
908908
return options;

src/harness/unittests/convertCompilerOptionsFromJson.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ namespace ts {
405405
allowJs: true,
406406
maxNodeModuleJsDepth: 2,
407407
allowSyntheticDefaultImports: true,
408-
skipLibCheck: true,
409408
module: ModuleKind.CommonJS,
410409
target: ScriptTarget.ES5,
411410
noImplicitAny: false,
@@ -434,7 +433,6 @@ namespace ts {
434433
allowJs: false,
435434
maxNodeModuleJsDepth: 2,
436435
allowSyntheticDefaultImports: true,
437-
skipLibCheck: true,
438436
module: ModuleKind.CommonJS,
439437
target: ScriptTarget.ES5,
440438
noImplicitAny: false,
@@ -458,8 +456,7 @@ namespace ts {
458456
{
459457
allowJs: true,
460458
maxNodeModuleJsDepth: 2,
461-
allowSyntheticDefaultImports: true,
462-
skipLibCheck: true
459+
allowSyntheticDefaultImports: true
463460
},
464461
errors: [{
465462
file: undefined,
@@ -480,8 +477,7 @@ namespace ts {
480477
{
481478
allowJs: true,
482479
maxNodeModuleJsDepth: 2,
483-
allowSyntheticDefaultImports: true,
484-
skipLibCheck: true
480+
allowSyntheticDefaultImports: true
485481
},
486482
errors: <Diagnostic[]>[]
487483
}

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 8 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace ts.projectSystem {
55
import TI = server.typingsInstaller;
6-
import protocol = server.protocol;
76
import CommandNames = server.CommandNames;
87

98
const safeList = {
@@ -126,7 +125,7 @@ namespace ts.projectSystem {
126125
return combinePaths(getDirectoryPath(libFile.path), "tsc.js");
127126
}
128127

129-
export function toExternalFile(fileName: string): protocol.ExternalFile {
128+
export function toExternalFile(fileName: string): server.protocol.ExternalFile {
130129
return { fileName };
131130
}
132131

@@ -552,7 +551,7 @@ namespace ts.projectSystem {
552551
}
553552

554553
export function makeSessionRequest<T>(command: string, args: T) {
555-
const newRequest: protocol.Request = {
554+
const newRequest: server.protocol.Request = {
556555
seq: 0,
557556
type: "request",
558557
command,
@@ -563,7 +562,7 @@ namespace ts.projectSystem {
563562

564563
export function openFilesForSession(files: FileOrFolder[], session: server.Session) {
565564
for (const file of files) {
566-
const request = makeSessionRequest<protocol.OpenRequestArgs>(CommandNames.Open, { file: file.path });
565+
const request = makeSessionRequest<server.protocol.OpenRequestArgs>(CommandNames.Open, { file: file.path });
567566
session.executeCommand(request);
568567
}
569568
}
@@ -1776,7 +1775,7 @@ namespace ts.projectSystem {
17761775
});
17771776

17781777
describe("navigate-to for javascript project", () => {
1779-
function containsNavToItem(items: protocol.NavtoItem[], itemName: string, itemKind: string) {
1778+
function containsNavToItem(items: server.protocol.NavtoItem[], itemName: string, itemKind: string) {
17801779
return find(items, item => item.name === itemName && item.kind === itemKind) !== undefined;
17811780
}
17821781

@@ -1794,12 +1793,12 @@ namespace ts.projectSystem {
17941793
openFilesForSession([file1], session);
17951794

17961795
// Try to find some interface type defined in lib.d.ts
1797-
const libTypeNavToRequest = makeSessionRequest<protocol.NavtoRequestArgs>(CommandNames.Navto, { searchValue: "Document", file: file1.path, projectFileName: configFile.path });
1798-
const items: protocol.NavtoItem[] = session.executeCommand(libTypeNavToRequest).response;
1796+
const libTypeNavToRequest = makeSessionRequest<server.protocol.NavtoRequestArgs>(CommandNames.Navto, { searchValue: "Document", file: file1.path, projectFileName: configFile.path });
1797+
const items: server.protocol.NavtoItem[] = session.executeCommand(libTypeNavToRequest).response;
17991798
assert.isFalse(containsNavToItem(items, "Document", "interface"), `Found lib.d.ts symbol in JavaScript project nav to request result.`);
18001799

1801-
const localFunctionNavToRequst = makeSessionRequest<protocol.NavtoRequestArgs>(CommandNames.Navto, { searchValue: "foo", file: file1.path, projectFileName: configFile.path });
1802-
const items2: protocol.NavtoItem[] = session.executeCommand(localFunctionNavToRequst).response;
1800+
const localFunctionNavToRequst = makeSessionRequest<server.protocol.NavtoRequestArgs>(CommandNames.Navto, { searchValue: "foo", file: file1.path, projectFileName: configFile.path });
1801+
const items2: server.protocol.NavtoItem[] = session.executeCommand(localFunctionNavToRequst).response;
18031802
assert.isTrue(containsNavToItem(items2, "foo", "function"), `Cannot find function symbol "foo".`);
18041803
});
18051804
});
@@ -2246,82 +2245,7 @@ namespace ts.projectSystem {
22462245
// verify content
22472246
const snap2 = projectServiice.getScriptInfo(f1.path).snap();
22482247
assert.equal(snap2.getText(0, snap2.getLength()), f1.content, "content should be equal to the content of original file");
2249-
});
2250-
});
2251-
2252-
describe("skipLibCheck", () => {
2253-
it("should be turned on for js-only inferred projects", () => {
2254-
const file1 = {
2255-
path: "/a/b/file1.js",
2256-
content: `
2257-
/// <reference path="file2.d.ts" />
2258-
var x = 1;`
2259-
};
2260-
const file2 = {
2261-
path: "/a/b/file2.d.ts",
2262-
content: `
2263-
interface T {
2264-
name: string;
2265-
};
2266-
interface T {
2267-
name: number;
2268-
};`
2269-
};
2270-
const host = createServerHost([file1, file2]);
2271-
const session = createSession(host);
2272-
openFilesForSession([file1, file2], session);
2273-
2274-
const file2GetErrRequest = makeSessionRequest<protocol.SemanticDiagnosticsSyncRequestArgs>(
2275-
CommandNames.SemanticDiagnosticsSync,
2276-
{ file: file2.path }
2277-
);
2278-
let errorResult = <protocol.Diagnostic[]>session.executeCommand(file2GetErrRequest).response;
2279-
assert.isTrue(errorResult.length === 0);
22802248

2281-
const closeFileRequest = makeSessionRequest<protocol.FileRequestArgs>(CommandNames.Close, { file: file1.path });
2282-
session.executeCommand(closeFileRequest);
2283-
errorResult = <protocol.Diagnostic[]>session.executeCommand(file2GetErrRequest).response;
2284-
assert.isTrue(errorResult.length !== 0);
2285-
2286-
openFilesForSession([file1], session);
2287-
errorResult = <protocol.Diagnostic[]>session.executeCommand(file2GetErrRequest).response;
2288-
assert.isTrue(errorResult.length === 0);
2289-
});
2290-
2291-
it("should be turned on for js-only external projects", () => {
2292-
const jsFile = {
2293-
path: "/a/b/file1.js",
2294-
content: "let x =1;"
2295-
};
2296-
const dTsFile = {
2297-
path: "/a/b/file2.d.ts",
2298-
content: `
2299-
interface T {
2300-
name: string;
2301-
};
2302-
interface T {
2303-
name: number;
2304-
};`
2305-
};
2306-
const host = createServerHost([jsFile, dTsFile]);
2307-
const session = createSession(host);
2308-
2309-
const openExternalProjectRequest = makeSessionRequest<protocol.OpenExternalProjectArgs>(
2310-
CommandNames.OpenExternalProject,
2311-
{
2312-
projectFileName: "project1",
2313-
rootFiles: toExternalFiles([jsFile.path, dTsFile.path]),
2314-
options: {}
2315-
}
2316-
);
2317-
session.executeCommand(openExternalProjectRequest);
2318-
2319-
const dTsFileGetErrRequest = makeSessionRequest<protocol.SemanticDiagnosticsSyncRequestArgs>(
2320-
CommandNames.SemanticDiagnosticsSync,
2321-
{ file: dTsFile.path }
2322-
);
2323-
const errorResult = <protocol.Diagnostic[]>session.executeCommand(dTsFileGetErrRequest).response;
2324-
assert.isTrue(errorResult.length === 0);
23252249
});
23262250
});
23272251
}

src/server/client.ts

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -397,41 +397,11 @@ namespace ts.server {
397397
}
398398

399399
getSyntacticDiagnostics(fileName: string): Diagnostic[] {
400-
const args: protocol.SyntacticDiagnosticsSyncRequestArgs = { file: fileName, includeLinePosition: true };
401-
402-
const request = this.processRequest<protocol.SyntacticDiagnosticsSyncRequest>(CommandNames.SyntacticDiagnosticsSync, args);
403-
const response = this.processResponse<protocol.SyntacticDiagnosticsSyncResponse>(request);
404-
405-
return (<protocol.DiagnosticWithLinePosition[]>response.body).map(entry => this.convertDiagnostic(entry, fileName));
400+
throw new Error("Not Implemented Yet.");
406401
}
407402

408403
getSemanticDiagnostics(fileName: string): Diagnostic[] {
409-
const args: protocol.SemanticDiagnosticsSyncRequestArgs = { file: fileName, includeLinePosition: true };
410-
411-
const request = this.processRequest<protocol.SemanticDiagnosticsSyncRequest>(CommandNames.SemanticDiagnosticsSync, args);
412-
const response = this.processResponse<protocol.SemanticDiagnosticsSyncResponse>(request);
413-
414-
return (<protocol.DiagnosticWithLinePosition[]>response.body).map(entry => this.convertDiagnostic(entry, fileName));
415-
}
416-
417-
convertDiagnostic(entry: protocol.DiagnosticWithLinePosition, fileName: string): Diagnostic {
418-
let category: DiagnosticCategory;
419-
for (const id in DiagnosticCategory) {
420-
if (typeof id === "string" && entry.category === id.toLowerCase()) {
421-
category = (<any>DiagnosticCategory)[id];
422-
}
423-
}
424-
425-
Debug.assert(category !== undefined, "convertDiagnostic: category should not be undefined");
426-
427-
return {
428-
file: undefined,
429-
start: entry.start,
430-
length: entry.length,
431-
messageText: entry.message,
432-
category: category,
433-
code: entry.code
434-
};
404+
throw new Error("Not Implemented Yet.");
435405
}
436406

437407
getCompilerOptionsDiagnostics(): Diagnostic[] {

src/server/project.ts

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,16 @@ namespace ts.server {
2020
}
2121
}
2222

23-
function countEachFileTypes(infos: ScriptInfo[]): { js: number, jsx: number, ts: number, tsx: number, dts: number } {
24-
const result = { js: 0, jsx: 0, ts: 0, tsx: 0, dts: 0 };
25-
for (const info of infos) {
26-
switch (info.scriptKind) {
27-
case ScriptKind.JS:
28-
result.js += 1;
29-
break;
30-
case ScriptKind.JSX:
31-
result.jsx += 1;
32-
break;
33-
case ScriptKind.TS:
34-
fileExtensionIs(info.fileName, ".d.ts")
35-
? result.dts += 1
36-
: result.ts += 1;
37-
break;
38-
case ScriptKind.TSX:
39-
result.tsx += 1;
40-
break;
41-
}
42-
}
43-
return result;
44-
}
45-
46-
function hasOneOrMoreJsAndNoTsFiles(project: Project) {
47-
const counts = countEachFileTypes(project.getScriptInfos());
48-
return counts.js > 0 && counts.ts === 0 && counts.tsx === 0;
23+
function isJsOrDtsFile(info: ScriptInfo) {
24+
return info.scriptKind === ScriptKind.JS || info.scriptKind == ScriptKind.JSX || fileExtensionIs(info.fileName, ".d.ts");
4925
}
5026

5127
export function allRootFilesAreJsOrDts(project: Project): boolean {
52-
const counts = countEachFileTypes(project.getRootScriptInfos());
53-
return counts.ts === 0 && counts.tsx === 0;
28+
return project.getRootScriptInfos().every(isJsOrDtsFile);
5429
}
5530

5631
export function allFilesAreJsOrDts(project: Project): boolean {
57-
const counts = countEachFileTypes(project.getScriptInfos());
58-
return counts.ts === 0 && counts.tsx === 0;
32+
return project.getScriptInfos().every(isJsOrDtsFile);
5933
}
6034

6135
export interface ProjectFilesWithTSDiagnostics extends protocol.ProjectFiles {
@@ -97,14 +71,9 @@ namespace ts.server {
9771

9872
public typesVersion = 0;
9973

100-
public isNonTsProject() {
101-
this.updateGraph();
102-
return allFilesAreJsOrDts(this);
103-
}
104-
10574
public isJsOnlyProject() {
10675
this.updateGraph();
107-
return hasOneOrMoreJsAndNoTsFiles(this);
76+
return allFilesAreJsOrDts(this);
10877
}
10978

11079
constructor(

src/server/session.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@ namespace ts.server {
1414
return ((1e9 * seconds) + nanoseconds) / 1000000.0;
1515
}
1616

17-
function shouldSkipSemanticCheck(project: Project) {
18-
if (project.getCompilerOptions().skipLibCheck !== undefined) {
19-
return false;
20-
}
21-
22-
if ((project.projectKind === ProjectKind.Inferred || project.projectKind === ProjectKind.External) && project.isJsOnlyProject()) {
23-
return true;
24-
}
25-
return false;
26-
}
27-
2817
interface FileStart {
2918
file: string;
3019
start: ILineInfo;
@@ -266,13 +255,12 @@ namespace ts.server {
266255

267256
private semanticCheck(file: NormalizedPath, project: Project) {
268257
try {
269-
let diags: Diagnostic[] = [];
270-
if (!shouldSkipSemanticCheck(project)) {
271-
diags = project.getLanguageService().getSemanticDiagnostics(file);
272-
}
258+
const diags = project.getLanguageService().getSemanticDiagnostics(file);
273259

274-
const bakedDiags = diags.map((diag) => formatDiag(file, project, diag));
275-
this.event({ file: file, diagnostics: bakedDiags }, "semanticDiag");
260+
if (diags) {
261+
const bakedDiags = diags.map((diag) => formatDiag(file, project, diag));
262+
this.event({ file: file, diagnostics: bakedDiags }, "semanticDiag");
263+
}
276264
}
277265
catch (err) {
278266
this.logError(err, "semantic check");
@@ -383,11 +371,8 @@ namespace ts.server {
383371
});
384372
}
385373

386-
private getDiagnosticsWorker(args: protocol.FileRequestArgs, isSemantic: boolean, selector: (project: Project, file: string) => Diagnostic[], includeLinePosition: boolean) {
374+
private getDiagnosticsWorker(args: protocol.FileRequestArgs, selector: (project: Project, file: string) => Diagnostic[], includeLinePosition: boolean) {
387375
const { project, file } = this.getFileAndProject(args);
388-
if (isSemantic && shouldSkipSemanticCheck(project)) {
389-
return [];
390-
}
391376
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
392377
const diagnostics = selector(project, file);
393378
return includeLinePosition
@@ -466,11 +451,11 @@ namespace ts.server {
466451
}
467452

468453
private getSyntacticDiagnosticsSync(args: protocol.SyntacticDiagnosticsSyncRequestArgs): protocol.Diagnostic[] | protocol.DiagnosticWithLinePosition[] {
469-
return this.getDiagnosticsWorker(args, /*isSemantic*/ false, (project, file) => project.getLanguageService().getSyntacticDiagnostics(file), args.includeLinePosition);
454+
return this.getDiagnosticsWorker(args, (project, file) => project.getLanguageService().getSyntacticDiagnostics(file), args.includeLinePosition);
470455
}
471456

472457
private getSemanticDiagnosticsSync(args: protocol.SemanticDiagnosticsSyncRequestArgs): protocol.Diagnostic[] | protocol.DiagnosticWithLinePosition[] {
473-
return this.getDiagnosticsWorker(args, /*isSemantic*/ true, (project, file) => project.getLanguageService().getSemanticDiagnostics(file), args.includeLinePosition);
458+
return this.getDiagnosticsWorker(args, (project, file) => project.getLanguageService().getSemanticDiagnostics(file), args.includeLinePosition);
474459
}
475460

476461
private getDocumentHighlights(args: protocol.DocumentHighlightsRequestArgs, simplifiedResult: boolean): protocol.DocumentHighlightsItem[] | DocumentHighlights[] {
@@ -1137,7 +1122,7 @@ namespace ts.server {
11371122
return combineProjectOutput(
11381123
projects,
11391124
project => {
1140-
const navItems = project.getLanguageService().getNavigateToItems(args.searchValue, args.maxResultCount, /*excludeDts*/ project.isNonTsProject());
1125+
const navItems = project.getLanguageService().getNavigateToItems(args.searchValue, args.maxResultCount, /*excludeDts*/ project.isJsOnlyProject());
11411126
if (!navItems) {
11421127
return [];
11431128
}
@@ -1175,7 +1160,7 @@ namespace ts.server {
11751160
else {
11761161
return combineProjectOutput(
11771162
projects,
1178-
project => project.getLanguageService().getNavigateToItems(args.searchValue, args.maxResultCount, /*excludeDts*/ project.isNonTsProject()),
1163+
project => project.getLanguageService().getNavigateToItems(args.searchValue, args.maxResultCount, /*excludeDts*/ project.isJsOnlyProject()),
11791164
/*comparer*/ undefined,
11801165
navigateToItemIsEqualTo);
11811166
}

0 commit comments

Comments
 (0)