Skip to content

Commit cf616dc

Browse files
committed
[in progress] project system work - path normalization
1 parent c8d37dc commit cf616dc

3 files changed

Lines changed: 51 additions & 55 deletions

File tree

src/server/editorServices.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -935,16 +935,14 @@ namespace ts.server {
935935
for (const p of rootFile.containingProjects) {
936936
if (p.projectKind !== ProjectKind.Inferred) {
937937
// file was included in non-inferred project - drop old inferred project
938-
infe
939-
break;
940938
}
941939
}
942-
if (inInferredProjectOnly) {
943-
openFileRoots.push(rootFile);
944-
}
945-
else {
940+
// if (inInferredProjectOnly) {
941+
// openFileRoots.push(rootFile);
942+
// }
943+
// else {
946944

947-
}
945+
// }
948946

949947
// const rootedProject = rootFile.defaultProject;
950948
// const referencingProjects = this.findReferencingProjects(rootFile, rootedProject);

src/server/project.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ namespace ts.server {
9494
}
9595
// signal language service to release files acquired from document registry
9696
this.languageService.dispose();
97-
9897
}
9998

10099
getCompilerOptions() {
@@ -167,21 +166,6 @@ namespace ts.server {
167166
this.projectStateVersion++;
168167
}
169168

170-
// remove a root file from project
171-
private removeRoot(info: ScriptInfo): boolean {
172-
if (this.isRoot(info)) {
173-
this.rootFiles = copyListRemovingItem(info, this.rootFiles);
174-
this.rootFilesMap.remove(info.path);
175-
this.lsHost.removeRoot(info);
176-
return true;
177-
}
178-
return false;
179-
}
180-
181-
private removeReferencedFile(info: ScriptInfo) {
182-
this.lsHost.removeReferencedFile(info)
183-
}
184-
185169
updateGraph() {
186170
if (!this.languageServiceEnabled) {
187171
return;
@@ -198,7 +182,7 @@ namespace ts.server {
198182
}
199183
}
200184

201-
getScriptInfoFromNormalizedPath(fileName: NormalizedPath) {
185+
getScriptInfoForNormalizedPath(fileName: NormalizedPath) {
202186
const scriptInfo = this.projectService.getOrCreateScriptInfoForNormalizedPath(fileName, /*openedByClient*/ false);
203187
if (scriptInfo && scriptInfo.attachToProject(this)) {
204188
this.markAsDirty();
@@ -207,7 +191,7 @@ namespace ts.server {
207191
}
208192

209193
getScriptInfo(uncheckedFileName: string) {
210-
return this.getScriptInfoFromNormalizedPath(toNormalizedPath(uncheckedFileName));
194+
return this.getScriptInfoForNormalizedPath(toNormalizedPath(uncheckedFileName));
211195
}
212196

213197
filesToString() {
@@ -240,7 +224,7 @@ namespace ts.server {
240224
}
241225

242226
reloadScript(filename: NormalizedPath, cb: () => void) {
243-
const script = this.getScriptInfoFromNormalizedPath(filename);
227+
const script = this.getScriptInfoForNormalizedPath(filename);
244228
if (script) {
245229
script.reloadFromFile(filename, cb);
246230
}
@@ -288,6 +272,21 @@ namespace ts.server {
288272
return { info, files: projectFileNames };
289273
}
290274
}
275+
276+
// remove a root file from project
277+
private removeRoot(info: ScriptInfo): boolean {
278+
if (this.isRoot(info)) {
279+
this.rootFiles = copyListRemovingItem(info, this.rootFiles);
280+
this.rootFilesMap.remove(info.path);
281+
this.lsHost.removeRoot(info);
282+
return true;
283+
}
284+
return false;
285+
}
286+
287+
private removeReferencedFile(info: ScriptInfo) {
288+
this.lsHost.removeReferencedFile(info)
289+
}
291290
}
292291

293292
export class InferredProject extends Project {

src/server/session.ts

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ namespace ts.server {
6868
}
6969
}
7070

71-
function formatDiag(fileName: string, project: Project, diag: ts.Diagnostic): protocol.Diagnostic {
72-
const scriptInfo = project.getScriptInfo(fileName);
71+
function formatDiag(fileName: NormalizedPath, project: Project, diag: ts.Diagnostic): protocol.Diagnostic {
72+
const scriptInfo = project.getScriptInfoForNormalizedPath(fileName);
7373
return {
7474
start: scriptInfo.positionToLineOffset(diag.start),
7575
end: scriptInfo.positionToLineOffset(diag.start + diag.length),
@@ -271,7 +271,7 @@ namespace ts.server {
271271
return { line, offset: offset + 1 };
272272
}
273273

274-
private semanticCheck(file: string, project: Project) {
274+
private semanticCheck(file: NormalizedPath, project: Project) {
275275
try {
276276
const diags = project.languageService.getSemanticDiagnostics(file);
277277

@@ -285,7 +285,7 @@ namespace ts.server {
285285
}
286286
}
287287

288-
private syntacticCheck(file: string, project: Project) {
288+
private syntacticCheck(file: NormalizedPath, project: Project) {
289289
try {
290290
const diags = project.languageService.getSyntacticDiagnostics(file);
291291
if (diags) {
@@ -397,7 +397,7 @@ namespace ts.server {
397397

398398
private getDiagnosticsWorker(args: protocol.FileRequestArgs, selector: (project: Project, file: string) => Diagnostic[]) {
399399
const { project, file } = this.getFileAndProject(args);
400-
const scriptInfo = project.getScriptInfoFromNormalizedPath(file);
400+
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
401401
const diagnostics = selector(project, file);
402402
return this.convertDiagnostics(diagnostics, scriptInfo);
403403
}
@@ -412,8 +412,7 @@ namespace ts.server {
412412

413413
private getDefinition(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.FileSpan[] | DefinitionInfo[] {
414414
const { file, project } = this.getFileAndProject(args);
415-
416-
const scriptInfo = project.getScriptInfo(file);
415+
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
417416
const position = this.getPosition(args, scriptInfo);
418417

419418
const definitions = project.languageService.getDefinitionAtPosition(file, position);
@@ -438,7 +437,7 @@ namespace ts.server {
438437

439438
private getTypeDefinition(args: protocol.FileLocationRequestArgs): protocol.FileSpan[] {
440439
const { file, project } = this.getFileAndProject(args)
441-
const scriptInfo = project.getScriptInfoFromNormalizedPath(file);
440+
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
442441
const position = this.getPosition(args, scriptInfo);
443442

444443
const definitions = project.languageService.getTypeDefinitionAtPosition(file, position);
@@ -458,7 +457,7 @@ namespace ts.server {
458457

459458
private getOccurrences(args: protocol.FileLocationRequestArgs): protocol.OccurrencesResponseItem[] {
460459
const { file, project } = this.getFileAndProject(args);
461-
const scriptInfo = project.getScriptInfoFromNormalizedPath(file);
460+
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
462461
const position = this.getPosition(args, scriptInfo);
463462

464463
const occurrences = project.languageService.getOccurrencesAtPosition(file, position);
@@ -483,7 +482,7 @@ namespace ts.server {
483482

484483
private getDocumentHighlights(args: protocol.DocumentHighlightsRequestArgs, simplifiedResult: boolean): protocol.DocumentHighlightsItem[] | DocumentHighlights[] {
485484
const { file, project } = this.getFileAndProject(args);
486-
const scriptInfo = project.getScriptInfoFromNormalizedPath(file);
485+
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
487486
const position = this.getPosition(args, scriptInfo);
488487

489488
const documentHighlights = project.languageService.getDocumentHighlights(file, position, args.filesToSearch);
@@ -533,7 +532,7 @@ namespace ts.server {
533532

534533
private getRenameInfo(args: protocol.FileLocationRequestArgs) {
535534
const { file, project } = this.getFileAndProject(args);
536-
const scriptInfo = project.getScriptInfoFromNormalizedPath(file);
535+
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
537536
const position = this.getPosition(args, scriptInfo);
538537
return project.languageService.getRenameInfo(file, position);
539538
}
@@ -559,8 +558,8 @@ namespace ts.server {
559558
}
560559

561560
private getRenameLocations(args: protocol.RenameRequestArgs, simplifiedResult: boolean): protocol.RenameResponseBody | RenameLocation[] {
562-
const file = ts.normalizePath(args.file);
563-
const info = this.projectService.getScriptInfo(file);
561+
const file = toNormalizedPath(args.file);
562+
const info = this.projectService.getScriptInfoForNormalizedPath(file);
564563
const position = this.getPosition(args, info);
565564
const projects = this.getProjects(args);
566565
if (simplifiedResult) {
@@ -661,11 +660,11 @@ namespace ts.server {
661660
}
662661

663662
private getReferences(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.ReferencesResponseBody | ReferencedSymbol[] {
664-
const file = ts.normalizePath(args.file);
663+
const file = toNormalizedPath(args.file);
665664
const projects = this.getProjects(args);
666665

667666
const defaultProject = projects[0];
668-
const scriptInfo = defaultProject.getScriptInfo(file);
667+
const scriptInfo = defaultProject.getScriptInfoForNormalizedPath(file);
669668
const position = this.getPosition(args, scriptInfo);
670669
if (simplifiedResult) {
671670
const nameInfo = defaultProject.languageService.getQuickInfoAtPosition(file, position);
@@ -771,39 +770,39 @@ namespace ts.server {
771770

772771
private getDocCommentTemplate(args: protocol.FileLocationRequestArgs) {
773772
const { file, project } = this.getFileAndProject(args);
774-
const scriptInfo = project.getScriptInfo(file);
773+
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
775774
const position = this.getPosition(args, scriptInfo);
776775
return project.languageService.getDocCommentTemplateAtPosition(file, position);
777776
}
778777

779778
private getIndentation(args: protocol.IndentationRequestArgs) {
780779
const { file, project } = this.getFileAndProject(args);
781-
const position = this.getPosition(args, project.getScriptInfo(file));
780+
const position = this.getPosition(args, project.getScriptInfoForNormalizedPath(file));
782781
const indentation = project.languageService.getIndentationAtPosition(file, position, args.options);
783782
return { position, indentation };
784783
}
785784

786785
private getBreakpointStatement(args: protocol.FileLocationRequestArgs) {
787786
const { file, project } = this.getFileAndProject(args);
788-
const position = this.getPosition(args, project.getScriptInfo(file));
787+
const position = this.getPosition(args, project.getScriptInfoForNormalizedPath(file));
789788
return project.languageService.getBreakpointStatementAtPosition(file, position);
790789
}
791790

792791
private getNameOrDottedNameSpan(args: protocol.FileLocationRequestArgs) {
793792
const { file, project } = this.getFileAndProject(args);
794-
const position = this.getPosition(args, project.getScriptInfo(file));
793+
const position = this.getPosition(args, project.getScriptInfoForNormalizedPath(file));
795794
return project.languageService.getNameOrDottedNameSpan(file, position, position);
796795
}
797796

798797
private isValidBraceCompletion(args: protocol.BraceCompletionRequestArgs) {
799798
const { file, project } = this.getFileAndProject(args);
800-
const position = this.getPosition(args, project.getScriptInfo(file));
799+
const position = this.getPosition(args, project.getScriptInfoForNormalizedPath(file));
801800
return project.languageService.isValidBraceCompletionAtPostion(file, position, args.openingBrace.charCodeAt(0));
802801
}
803802

804803
private getQuickInfoWorker(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.QuickInfoResponseBody | QuickInfo {
805804
const { file, project } = this.getFileAndProject(args);
806-
const scriptInfo = project.getScriptInfo(file);
805+
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
807806
const quickInfo = project.languageService.getQuickInfoAtPosition(file, this.getPosition(args, scriptInfo));
808807
if (!quickInfo) {
809808
return undefined;
@@ -828,7 +827,7 @@ namespace ts.server {
828827

829828
private getFormattingEditsForRange(args: protocol.FormatRequestArgs): protocol.CodeEdit[] {
830829
const { file, project } = this.getFileAndProject(args);
831-
const scriptInfo = project.getScriptInfo(file);
830+
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
832831

833832
const startPosition = scriptInfo.lineOffsetToPosition(args.line, args.offset);
834833
const endPosition = scriptInfo.lineOffsetToPosition(args.endLine, args.endOffset);
@@ -866,7 +865,7 @@ namespace ts.server {
866865

867866
private getFormattingEditsAfterKeystroke(args: protocol.FormatOnKeyRequestArgs): protocol.CodeEdit[] {
868867
const { file, project } = this.getFileAndProject(args);
869-
const scriptInfo = project.getScriptInfo(file);
868+
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
870869
const position = scriptInfo.lineOffsetToPosition(args.line, args.offset);
871870
const formatOptions = this.projectService.getFormatCodeOptions(file);
872871
const edits = project.languageService.getFormattingEditsAfterKeystroke(file, position, args.key,
@@ -933,7 +932,7 @@ namespace ts.server {
933932
const prefix = args.prefix || "";
934933
const { file, project } = this.getFileAndProject(args);
935934

936-
const scriptInfo = project.getScriptInfo(file);
935+
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
937936
const position = this.getPosition(args, scriptInfo);
938937

939938
const completions = project.languageService.getCompletionsAtPosition(file, position);
@@ -955,7 +954,7 @@ namespace ts.server {
955954

956955
private getCompletionEntryDetails(args: protocol.CompletionDetailsRequestArgs): protocol.CompletionEntryDetails[] {
957956
const { file, project } = this.getFileAndProject(args);
958-
const scriptInfo = project.getScriptInfo(file);
957+
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
959958
const position = this.getPosition(args, scriptInfo);
960959

961960
return args.entryNames.reduce((accum: protocol.CompletionEntryDetails[], entryName: string) => {
@@ -969,7 +968,7 @@ namespace ts.server {
969968

970969
private getSignatureHelpItems(args: protocol.SignatureHelpRequestArgs, simplifiedResult: boolean): protocol.SignatureHelpItems | SignatureHelpItems {
971970
const { file, project } = this.getFileAndProject(args);
972-
const scriptInfo = project.getScriptInfo(file);
971+
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
973972
const position = this.getPosition(args, scriptInfo);
974973
const helpItems = project.languageService.getSignatureHelpItems(file, position);
975974
if (!helpItems) {
@@ -1012,7 +1011,7 @@ namespace ts.server {
10121011
private change(args: protocol.ChangeRequestArgs) {
10131012
const { file, project } = this.getFileAndProject(args, /*errorOnMissingProject*/ false);
10141013
if (project) {
1015-
const scriptInfo = project.getScriptInfo(file);
1014+
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
10161015
const start = scriptInfo.lineOffsetToPosition(args.line, args.offset);
10171016
const end = scriptInfo.lineOffsetToPosition(args.endLine, args.endOffset);
10181017
if (start >= 0) {
@@ -1058,7 +1057,7 @@ namespace ts.server {
10581057
return undefined;
10591058
}
10601059

1061-
const scriptInfo = project.getScriptInfoFromNormalizedPath(fileName);
1060+
const scriptInfo = project.getScriptInfoForNormalizedPath(fileName);
10621061

10631062
return items.map(item => ({
10641063
text: item.text,
@@ -1167,7 +1166,7 @@ namespace ts.server {
11671166
private getBraceMatching(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.TextSpan[] | TextSpan[] {
11681167
const { file, project } = this.getFileAndProject(args);
11691168

1170-
const scriptInfo = project.getScriptInfo(file);
1169+
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
11711170
const position = this.getPosition(args, scriptInfo);
11721171

11731172
const spans = project.languageService.getBraceMatchingAtPosition(file, position);

0 commit comments

Comments
 (0)