-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Add editor configurable filename-based ATA #40952
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
Changes from 8 commits
187576c
52bc8b0
4113e91
45ae636
d3a2d41
67fda70
554a98f
48eccaa
a187137
aa46e02
b6ee490
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 |
---|---|---|
|
@@ -263,6 +263,16 @@ namespace ts.server { | |
return result; | ||
} | ||
|
||
export function convertTypeAcquisition(protocolOptions: protocol.ExternalProjectCompilerOptions): TypeAcquisition | undefined { | ||
let result: TypeAcquisition | undefined; | ||
typeAcquisitionDeclarations.forEach((option) => { | ||
const propertyValue = protocolOptions[option.name]; | ||
if (propertyValue === undefined) return; | ||
(result || (result = {}))[option.name] = propertyValue; | ||
}); | ||
return result; | ||
} | ||
|
||
export function tryConvertScriptKindName(scriptKindName: protocol.ScriptKindName | ScriptKind): ScriptKind { | ||
return isString(scriptKindName) ? convertScriptKindName(scriptKindName) : scriptKindName; | ||
} | ||
|
@@ -294,6 +304,7 @@ namespace ts.server { | |
hostInfo: string; | ||
extraFileExtensions?: FileExtensionInfo[]; | ||
watchOptions?: WatchOptions; | ||
typeAcquisition?: TypeAcquisition; | ||
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. You shouldn’t need this since the options are per project and there isn’t anything in host |
||
} | ||
|
||
export interface OpenConfiguredProjectResult { | ||
|
@@ -642,6 +653,8 @@ namespace ts.server { | |
private compilerOptionsForInferredProjectsPerProjectRoot = new Map<string, CompilerOptions>(); | ||
private watchOptionsForInferredProjects: WatchOptions | undefined; | ||
private watchOptionsForInferredProjectsPerProjectRoot = new Map<string, WatchOptions | false>(); | ||
private typeAcquisitionForInferredProjects: TypeAcquisition | undefined; | ||
private typeAcquisitionForInferredProjectsPerProjectRoot = new Map<string, TypeAcquisition | undefined>(); | ||
/** | ||
* Project size for configured or external projects | ||
*/ | ||
|
@@ -988,6 +1001,7 @@ namespace ts.server { | |
|
||
const compilerOptions = convertCompilerOptions(projectCompilerOptions); | ||
const watchOptions = convertWatchOptions(projectCompilerOptions); | ||
const typeAcquisition = convertTypeAcquisition(projectCompilerOptions); | ||
|
||
// always set 'allowNonTsExtensions' for inferred projects since user cannot configure it from the outside | ||
// previously we did not expose a way for user to change these settings and this option was enabled by default | ||
|
@@ -996,10 +1010,12 @@ namespace ts.server { | |
if (canonicalProjectRootPath) { | ||
this.compilerOptionsForInferredProjectsPerProjectRoot.set(canonicalProjectRootPath, compilerOptions); | ||
this.watchOptionsForInferredProjectsPerProjectRoot.set(canonicalProjectRootPath, watchOptions || false); | ||
this.typeAcquisitionForInferredProjectsPerProjectRoot.set(canonicalProjectRootPath, typeAcquisition); | ||
} | ||
else { | ||
this.compilerOptionsForInferredProjects = compilerOptions; | ||
this.watchOptionsForInferredProjects = watchOptions; | ||
this.typeAcquisitionForInferredProjects = typeAcquisition; | ||
} | ||
|
||
for (const project of this.inferredProjects) { | ||
|
@@ -2299,13 +2315,18 @@ namespace ts.server { | |
private createInferredProject(currentDirectory: string | undefined, isSingleInferredProject?: boolean, projectRootPath?: NormalizedPath): InferredProject { | ||
const compilerOptions = projectRootPath && this.compilerOptionsForInferredProjectsPerProjectRoot.get(projectRootPath) || this.compilerOptionsForInferredProjects!; // TODO: GH#18217 | ||
let watchOptions: WatchOptions | false | undefined; | ||
let typeAcquisition: TypeAcquisition | undefined; | ||
if (projectRootPath) { | ||
watchOptions = this.watchOptionsForInferredProjectsPerProjectRoot.get(projectRootPath); | ||
typeAcquisition = this.typeAcquisitionForInferredProjectsPerProjectRoot.get(projectRootPath); | ||
} | ||
if (watchOptions === undefined) { | ||
watchOptions = this.watchOptionsForInferredProjects; | ||
} | ||
const project = new InferredProject(this, this.documentRegistry, compilerOptions, watchOptions || undefined, projectRootPath, currentDirectory, this.currentPluginConfigOverrides); | ||
if (typeAcquisition === undefined) { | ||
typeAcquisition = this.typeAcquisitionForInferredProjects; | ||
} | ||
const project = new InferredProject(this, this.documentRegistry, compilerOptions, watchOptions || undefined, projectRootPath, currentDirectory, this.currentPluginConfigOverrides, typeAcquisition); | ||
if (isSingleInferredProject) { | ||
this.inferredProjects.unshift(project); | ||
} | ||
|
@@ -3515,7 +3536,7 @@ namespace ts.server { | |
const typeAcquisition = proj.typeAcquisition!; | ||
Debug.assert(!!typeAcquisition, "proj.typeAcquisition should be set by now"); | ||
// If type acquisition has been explicitly disabled, do not exclude anything from the project | ||
if (typeAcquisition.enable === false) { | ||
if (typeAcquisition.enable === false || typeAcquisition.inferTypingsFromFilenames === false) { | ||
return []; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1732,6 +1732,8 @@ namespace ts.server { | |
|
||
private _isJsInferredProject = false; | ||
|
||
private typeAcquisition: TypeAcquisition | undefined; | ||
|
||
toggleJsInferredProject(isJsInferredProject: boolean) { | ||
if (isJsInferredProject !== this._isJsInferredProject) { | ||
this._isJsInferredProject = isJsInferredProject; | ||
|
@@ -1770,7 +1772,8 @@ namespace ts.server { | |
watchOptions: WatchOptions | undefined, | ||
projectRootPath: NormalizedPath | undefined, | ||
currentDirectory: string | undefined, | ||
pluginConfigOverrides: ESMap<string, any> | undefined) { | ||
pluginConfigOverrides: ESMap<string, any> | undefined, | ||
typeAcquisition: TypeAcquisition | undefined) { | ||
super(InferredProject.newName(), | ||
ProjectKind.Inferred, | ||
projectService, | ||
|
@@ -1783,6 +1786,7 @@ namespace ts.server { | |
watchOptions, | ||
projectService.host, | ||
currentDirectory); | ||
this.typeAcquisition = typeAcquisition; | ||
this.projectRootPath = projectRootPath && projectService.toCanonicalFileName(projectRootPath); | ||
if (!projectRootPath && !projectService.useSingleInferredProject) { | ||
this.canonicalCurrentDirectory = projectService.toCanonicalFileName(this.currentDirectory); | ||
|
@@ -1827,11 +1831,16 @@ namespace ts.server { | |
super.close(); | ||
} | ||
|
||
setTypeAcquisition(newTypeAcquisition: TypeAcquisition): void { | ||
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. Wonder if if this.typeAcquisition and set method should be moved to |
||
this.typeAcquisition = this.removeLocalTypingsFromTypeAcquisition(newTypeAcquisition); | ||
} | ||
|
||
getTypeAcquisition(): TypeAcquisition { | ||
return { | ||
return this.typeAcquisition || { | ||
enable: allRootFilesAreJsOrDts(this), | ||
include: ts.emptyArray, | ||
exclude: ts.emptyArray | ||
exclude: ts.emptyArray, | ||
inferTypingsFromFilenames: true | ||
}; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1333,7 +1333,7 @@ namespace ts.server.protocol { | |
* For external projects, some of the project settings are sent together with | ||
* compiler settings. | ||
*/ | ||
export type ExternalProjectCompilerOptions = CompilerOptions & CompileOnSaveMixin & WatchOptions; | ||
export type ExternalProjectCompilerOptions = CompilerOptions & CompileOnSaveMixin & WatchOptions & TypeAcquisition; | ||
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.
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. You can create different type instead you should create a type |
||
|
||
/** | ||
* Contains information about current project version | ||
|
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.
I think you want apposite of this option so that current type acquisitions in config file behave as if this option is set to false. Ideally you want new behavior to kick in only when the option is set
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.
I think I accounted for that, making so that the behavior is only disabled if explicitly set to
false
. I was imagining something likeEnable/disable filename-based ATA
as the text of the setting on the editor side, with it checked by default.I suppose
disableFilenameBasedTypeAcquisition
works just as well.