-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Adding tsconfig.json mixed content (script block) support #12153
Changes from 11 commits
da7f824
7dd30db
891173c
464bc0e
12971d2
64dad30
1c3689e
7a11453
d528943
4cb5a36
5f46e48
05160ca
30bd841
5829ca8
c40508c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1924,8 +1924,16 @@ namespace ts { | |
export const supportedJavascriptExtensions = [".js", ".jsx"]; | ||
const allSupportedExtensions = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions); | ||
|
||
export function getSupportedExtensions(options?: CompilerOptions): string[] { | ||
return options && options.allowJs ? allSupportedExtensions : supportedTypeScriptExtensions; | ||
export function getSupportedExtensions(options?: CompilerOptions, fileExtensionMap?: FileExtensionMapItem[]): string[] { | ||
let typeScriptHostExtensions: string[] = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor nit to reduce allocations: let allExtensions: string[];
let allTypeScriptExtensions: string[];
const needAllExtensions = options && options.allowJs;
if (!extraFileExtensions) {
return needAllExtensions ? allSupportedExtensions : supportedTypeScriptExtensions;
}
const extensions = (needAllExtensions ? allSupportedExtensions : supportedTypeScriptExtensions).slice(0);
for (const ext of extraExtensions) {
if (!needAllExtensions || ext.scriptKind === ScriptKind.TS) {
extensions.push(ext.fileName);
}
}
return extensions; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clever - testing this change and will update |
||
let allHostExtensions: string[] = []; | ||
if (fileExtensionMap) { | ||
allHostExtensions = ts.map(fileExtensionMap, item => item.extension); | ||
typeScriptHostExtensions = ts.map(ts.filter(fileExtensionMap, item => item.scriptKind === ScriptKind.TS), item => item.extension); | ||
} | ||
const allTypeScriptExtensions = concatenate(supportedTypeScriptExtensions, typeScriptHostExtensions); | ||
const allExtensions = concatenate(allSupportedExtensions, allHostExtensions); | ||
return options && options.allowJs ? allExtensions : allTypeScriptExtensions; | ||
} | ||
|
||
export function hasJavaScriptFileExtension(fileName: string) { | ||
|
@@ -1936,10 +1944,10 @@ namespace ts { | |
return forEach(supportedTypeScriptExtensions, extension => fileExtensionIs(fileName, extension)); | ||
} | ||
|
||
export function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions) { | ||
export function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions, fileExtensionMap?: FileExtensionMapItem[]) { | ||
if (!fileName) { return false; } | ||
|
||
for (const extension of getSupportedExtensions(compilerOptions)) { | ||
for (const extension of getSupportedExtensions(compilerOptions, fileExtensionMap)) { | ||
if (fileExtensionIs(fileName, extension)) { | ||
return true; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/// <reference path="..\services\services.ts" /> | ||
/// <reference path="..\services\services.ts" /> | ||
/// <reference path="utilities.ts"/> | ||
/// <reference path="scriptInfo.ts"/> | ||
/// <reference path="lsHost.ts"/> | ||
|
@@ -187,6 +187,10 @@ namespace ts.server { | |
public languageServiceEnabled = true; | ||
|
||
builder: Builder; | ||
/** | ||
* Set of files names that were updated since the last call to getChangesSinceVersion. | ||
*/ | ||
private updatedFileNames: Map<string>; | ||
/** | ||
* Set of files that was returned from the last call to getChangesSinceVersion. | ||
*/ | ||
|
@@ -480,6 +484,10 @@ namespace ts.server { | |
this.markAsDirty(); | ||
} | ||
|
||
registerFileUpdate(fileName: string) { | ||
(this.updatedFileNames || (this.updatedFileNames = createMap<string>()))[fileName] = fileName; | ||
} | ||
|
||
markAsDirty() { | ||
this.projectStateVersion++; | ||
} | ||
|
@@ -670,7 +678,7 @@ namespace ts.server { | |
// check if requested version is the same that we have reported last time | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would make it more like let updatedFileNames = this.updatedFileNames;
this.updatedFileNames = undefined;
/// use local updatedFileNames - this way we'll know that set of names is definitely cleared There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes - good idea |
||
if (this.lastReportedFileNames && lastKnownVersion === this.lastReportedVersion) { | ||
// if current structure version is the same - return info witout any changes | ||
if (this.projectStructureVersion == this.lastReportedVersion) { | ||
if (this.projectStructureVersion == this.lastReportedVersion && !this.updatedFileNames) { | ||
return { info, projectErrors: this.projectErrors }; | ||
} | ||
// compute and return the difference | ||
|
@@ -679,6 +687,7 @@ namespace ts.server { | |
|
||
const added: string[] = []; | ||
const removed: string[] = []; | ||
const updated: string[] = getOwnKeys(this.updatedFileNames); | ||
for (const id in currentFiles) { | ||
if (!hasProperty(lastReportedFileNames, id)) { | ||
added.push(id); | ||
|
@@ -691,7 +700,8 @@ namespace ts.server { | |
} | ||
this.lastReportedFileNames = currentFiles; | ||
this.lastReportedVersion = this.projectStructureVersion; | ||
return { info, changes: { added, removed }, projectErrors: this.projectErrors }; | ||
this.updatedFileNames = undefined; | ||
return { info, changes: { added, removed, updated }, projectErrors: this.projectErrors }; | ||
} | ||
else { | ||
// unknown version - return everything | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it not really a map anymore. maybe
extraExtensions: ExtensionInfo[]
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good - will switch to extraFileExtensions: FileExtensionInfo[]