Skip to content

Commit d528943

Browse files
committed
Changes due to CR comments
1 parent 7a11453 commit d528943

File tree

8 files changed

+44
-33
lines changed

8 files changed

+44
-33
lines changed

src/compiler/commandLineParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ namespace ts {
841841
* @param basePath A root directory to resolve relative path entries in the config
842842
* file to. e.g. outDir
843843
*/
844-
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}, configFileName?: string, resolutionStack: Path[] = [], fileExtensionMap: FileExtensionMap = {}): ParsedCommandLine {
844+
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}, configFileName?: string, resolutionStack: Path[] = [], fileExtensionMap: FileExtensionMapItem[] = []): ParsedCommandLine {
845845
const errors: Diagnostic[] = [];
846846
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames);
847847
const resolvedPath = toPath(configFileName || "", basePath, getCanonicalFileName);
@@ -1185,7 +1185,7 @@ namespace ts {
11851185
* @param host The host used to resolve files and directories.
11861186
* @param errors An array for diagnostic reporting.
11871187
*/
1188-
function matchFileNames(fileNames: string[], include: string[], exclude: string[], basePath: string, options: CompilerOptions, host: ParseConfigHost, errors: Diagnostic[], fileExtensionMap: FileExtensionMap): ExpandResult {
1188+
function matchFileNames(fileNames: string[], include: string[], exclude: string[], basePath: string, options: CompilerOptions, host: ParseConfigHost, errors: Diagnostic[], fileExtensionMap: FileExtensionMapItem[]): ExpandResult {
11891189
basePath = normalizePath(basePath);
11901190

11911191
// The exclude spec list is converted into a regular expression, which allows us to quickly

src/compiler/core.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,12 +1942,12 @@ namespace ts {
19421942
export const supportedJavascriptExtensions = [".js", ".jsx"];
19431943
const allSupportedExtensions = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions);
19441944

1945-
export function getSupportedExtensions(options?: CompilerOptions, fileExtensionMap?: FileExtensionMap): string[] {
1945+
export function getSupportedExtensions(options?: CompilerOptions, fileExtensionMap?: FileExtensionMapItem[]): string[] {
19461946
let typeScriptHostExtensions: string[] = [];
19471947
let allHostExtensions: string[] = [];
19481948
if (fileExtensionMap) {
1949-
allHostExtensions = concatenate(concatenate(fileExtensionMap.javaScript, fileExtensionMap.typeScript), fileExtensionMap.mixedContent);
1950-
typeScriptHostExtensions = fileExtensionMap.typeScript;
1949+
allHostExtensions = ts.map(fileExtensionMap, item => item.extension);
1950+
typeScriptHostExtensions = ts.map(ts.filter(fileExtensionMap, item => item.scriptKind === ScriptKind.TS), item => item.extension);
19511951
}
19521952
const allTypeScriptExtensions = concatenate(supportedTypeScriptExtensions, typeScriptHostExtensions);
19531953
const allExtensions = concatenate(allSupportedExtensions, allHostExtensions);
@@ -1962,7 +1962,7 @@ namespace ts {
19621962
return forEach(supportedTypeScriptExtensions, extension => fileExtensionIs(fileName, extension));
19631963
}
19641964

1965-
export function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions, fileExtensionMap?: FileExtensionMap) {
1965+
export function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions, fileExtensionMap?: FileExtensionMapItem[]) {
19661966
if (!fileName) { return false; }
19671967

19681968
for (const extension of getSupportedExtensions(compilerOptions, fileExtensionMap)) {

src/compiler/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3086,10 +3086,10 @@ namespace ts {
30863086
ThisProperty
30873087
}
30883088

3089-
export interface FileExtensionMap {
3090-
javaScript?: string[];
3091-
typeScript?: string[];
3092-
mixedContent?: string[];
3089+
export interface FileExtensionMapItem {
3090+
extension: string;
3091+
scriptKind: ScriptKind;
3092+
isMixedContent: boolean;
30933093
}
30943094

30953095
export interface DiagnosticMessage {

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,8 @@ namespace ts.projectSystem {
15521552
checkProjectActualFiles(projectService.configuredProjects[0], [file1.path]);
15531553

15541554
// Specify .html extension as mixed content
1555-
const configureHostRequest = makeSessionRequest<protocol.ConfigureRequestArguments>(CommandNames.Configure, { fileExtensionMap: { mixedContent: [".html"] } });
1555+
const fileExtensionMap = [{ extension: ".html", scriptKind: ScriptKind.JS, isMixedContent: true }];
1556+
const configureHostRequest = makeSessionRequest<protocol.ConfigureRequestArguments>(CommandNames.Configure, { fileExtensionMap });
15561557
session.executeCommand(configureHostRequest).response;
15571558

15581559
// HTML file still not included in the project as it is closed

src/server/editorServices.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ namespace ts.server {
108108
export interface HostConfiguration {
109109
formatCodeOptions: FormatCodeSettings;
110110
hostInfo: string;
111-
fileExtensionMap?: FileExtensionMap;
111+
fileExtensionMap?: FileExtensionMapItem[];
112112
}
113113

114114
interface ConfigFileConversionResult {
@@ -133,13 +133,16 @@ namespace ts.server {
133133
interface FilePropertyReader<T> {
134134
getFileName(f: T): string;
135135
getScriptKind(f: T): ScriptKind;
136-
hasMixedContent(f: T, mixedContentExtensions: string[]): boolean;
136+
hasMixedContent(f: T, fileExtensionMap: FileExtensionMapItem[]): boolean;
137137
}
138138

139139
const fileNamePropertyReader: FilePropertyReader<string> = {
140140
getFileName: x => x,
141141
getScriptKind: _ => undefined,
142-
hasMixedContent: (fileName, mixedContentExtensions) => forEach(mixedContentExtensions, extension => fileExtensionIs(fileName, extension))
142+
hasMixedContent: (fileName, fileExtensionMap) => {
143+
const mixedContentExtensions = ts.map(ts.filter(fileExtensionMap, item => item.isMixedContent), item => item.extension);
144+
return forEach(mixedContentExtensions, extension => fileExtensionIs(fileName, extension))
145+
}
143146
};
144147

145148
const externalFilePropertyReader: FilePropertyReader<protocol.ExternalFile> = {
@@ -284,7 +287,7 @@ namespace ts.server {
284287
this.hostConfiguration = {
285288
formatCodeOptions: getDefaultFormatCodeSettings(this.host),
286289
hostInfo: "Unknown host",
287-
fileExtensionMap: {}
290+
fileExtensionMap: []
288291
};
289292

290293
this.documentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames, host.getCurrentDirectory());
@@ -646,7 +649,7 @@ namespace ts.server {
646649
for (const p of info.containingProjects) {
647650
if (p.projectKind === ProjectKind.Configured) {
648651
if (info.hasMixedContent) {
649-
info.hasChanges = true;
652+
info.registerFileUpdate();
650653
}
651654
// last open file in configured project - close it
652655
if ((<ConfiguredProject>p).deleteOpenRef() === 0) {
@@ -922,7 +925,7 @@ namespace ts.server {
922925
for (const f of files) {
923926
const rootFilename = propertyReader.getFileName(f);
924927
const scriptKind = propertyReader.getScriptKind(f);
925-
const hasMixedContent = propertyReader.hasMixedContent(f, this.hostConfiguration.fileExtensionMap.mixedContent);
928+
const hasMixedContent = propertyReader.hasMixedContent(f, this.hostConfiguration.fileExtensionMap);
926929
if (this.host.fileExists(rootFilename)) {
927930
const info = this.getOrCreateScriptInfoForNormalizedPath(toNormalizedPath(rootFilename), /*openedByClient*/ clientFileName == rootFilename, /*fileContent*/ undefined, scriptKind, hasMixedContent);
928931
project.addRoot(info);
@@ -968,7 +971,7 @@ namespace ts.server {
968971
rootFilesChanged = true;
969972
if (!scriptInfo) {
970973
const scriptKind = propertyReader.getScriptKind(f);
971-
const hasMixedContent = propertyReader.hasMixedContent(f, this.hostConfiguration.fileExtensionMap.mixedContent);
974+
const hasMixedContent = propertyReader.hasMixedContent(f, this.hostConfiguration.fileExtensionMap);
972975
scriptInfo = this.getOrCreateScriptInfoForNormalizedPath(normalizedPath, /*openedByClient*/ false, /*fileContent*/ undefined, scriptKind, hasMixedContent);
973976
}
974977
}
@@ -1123,7 +1126,7 @@ namespace ts.server {
11231126
if (openedByClient) {
11241127
info.isOpen = true;
11251128
if (hasMixedContent) {
1126-
info.hasChanges = true;
1129+
info.registerFileUpdate();
11271130
}
11281131
}
11291132
}
@@ -1225,12 +1228,12 @@ namespace ts.server {
12251228
}
12261229

12271230
openClientFileWithNormalizedPath(fileName: NormalizedPath, fileContent?: string, scriptKind?: ScriptKind, hasMixedContent?: boolean): OpenConfiguredProjectResult {
1228-
const info = this.getOrCreateScriptInfoForNormalizedPath(fileName, /*openedByClient*/ true, fileContent, scriptKind, hasMixedContent);
12291231
const { configFileName = undefined, configFileErrors = undefined }: OpenConfiguredProjectResult = this.findContainingExternalProject(fileName)
12301232
? {}
12311233
: this.openOrUpdateConfiguredProjectForFile(fileName);
12321234

12331235
// at this point if file is the part of some configured/external project then this project should be created
1236+
const info = this.getOrCreateScriptInfoForNormalizedPath(fileName, /*openedByClient*/ true, fileContent, scriptKind, hasMixedContent);
12341237
this.assignScriptInfoToInferredProjectIfNecessary(info, /*addToListOfOpenFiles*/ true);
12351238
this.printProjects();
12361239
return { configFileName, configFileErrors };

src/server/project.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ namespace ts.server {
187187
public languageServiceEnabled = true;
188188

189189
builder: Builder;
190+
/**
191+
* Set of files names that were updated since the last call to getChangesSinceVersion.
192+
*/
193+
private updatedFileNames: Map<string>;
190194
/**
191195
* Set of files that was returned from the last call to getChangesSinceVersion.
192196
*/
@@ -208,6 +212,7 @@ namespace ts.server {
208212
*/
209213
private projectStateVersion = 0;
210214

215+
211216
private typingFiles: SortedReadonlyArray<string>;
212217

213218
protected projectErrors: Diagnostic[];
@@ -480,6 +485,10 @@ namespace ts.server {
480485
this.markAsDirty();
481486
}
482487

488+
registerFileUpdate(fileName: string) {
489+
(this.updatedFileNames || (this.updatedFileNames = createMap<string>()))[fileName] = fileName;
490+
}
491+
483492
markAsDirty() {
484493
this.projectStateVersion++;
485494
}
@@ -562,10 +571,6 @@ namespace ts.server {
562571
return !hasChanges;
563572
}
564573

565-
private hasChangedFiles() {
566-
return this.rootFiles && forEach(this.rootFiles, info => info.hasChanges);
567-
}
568-
569574
private setTypings(typings: SortedReadonlyArray<string>): boolean {
570575
if (arrayIsEqualTo(this.typingFiles, typings)) {
571576
return false;
@@ -579,7 +584,7 @@ namespace ts.server {
579584
const oldProgram = this.program;
580585
this.program = this.languageService.getProgram();
581586

582-
let hasChanges = this.hasChangedFiles();
587+
let hasChanges = false;
583588
// bump up the version if
584589
// - oldProgram is not set - this is a first time updateGraph is called
585590
// - newProgram is different from the old program and structure of the old program was not reused.
@@ -674,7 +679,7 @@ namespace ts.server {
674679
// check if requested version is the same that we have reported last time
675680
if (this.lastReportedFileNames && lastKnownVersion === this.lastReportedVersion) {
676681
// if current structure version is the same - return info witout any changes
677-
if (this.projectStructureVersion == this.lastReportedVersion) {
682+
if (this.projectStructureVersion == this.lastReportedVersion && !this.updatedFileNames) {
678683
return { info, projectErrors: this.projectErrors };
679684
}
680685
// compute and return the difference
@@ -683,7 +688,7 @@ namespace ts.server {
683688

684689
const added: string[] = [];
685690
const removed: string[] = [];
686-
const updated = this.rootFiles.filter(info => info.hasChanges).map(info => info.fileName);
691+
const updated: string[] = getOwnKeys(this.updatedFileNames);
687692
for (const id in currentFiles) {
688693
if (!hasProperty(lastReportedFileNames, id)) {
689694
added.push(id);
@@ -694,11 +699,9 @@ namespace ts.server {
694699
removed.push(id);
695700
}
696701
}
697-
for (const root of this.rootFiles) {
698-
root.hasChanges = false;
699-
}
700702
this.lastReportedFileNames = currentFiles;
701703
this.lastReportedVersion = this.projectStructureVersion;
704+
this.updatedFileNames = undefined;
702705
return { info, changes: { added, removed, updated }, projectErrors: this.projectErrors };
703706
}
704707
else {

src/server/protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ namespace ts.server.protocol {
998998
/**
999999
* The host's supported file extension mappings
10001000
*/
1001-
fileExtensionMap?: FileExtensionMap;
1001+
fileExtensionMap?: FileExtensionMapItem[];
10021002
}
10031003

10041004
/**

src/server/scriptInfo.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ namespace ts.server {
2828
: getScriptKindFromFileName(fileName);
2929
}
3030

31-
public hasChanges = false;
32-
3331
getFormatCodeSettings() {
3432
return this.formatCodeSettings;
3533
}
@@ -91,6 +89,12 @@ namespace ts.server {
9189
return this.containingProjects[0];
9290
}
9391

92+
registerFileUpdate(): void {
93+
for (const p of this.containingProjects) {
94+
p.registerFileUpdate(this.path);
95+
}
96+
}
97+
9498
setFormatOptions(formatSettings: FormatCodeSettings): void {
9599
if (formatSettings) {
96100
if (!this.formatCodeSettings) {

0 commit comments

Comments
 (0)