-
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
Conversation
Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @amcasey, @mjbvz, @minestarks for you. Feel free to loop in other consumers/maintainers if necessary |
src/server/editorServices.ts
Outdated
@@ -3515,7 +3523,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.inferTypings === false) { |
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.
Just to clarify - does applySafeList
only apply in the "infer from filenames" case?
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.
It removes any project files that appear in the safe list from the project, and adds them to the include
list (for which typings are installed unconditionally).
If there is a case where we want to avoid adding files to the include list and remove them from the project, then this would be wrong (but I'm not sure what that is).
src/server/editorServices.ts
Outdated
@@ -3632,6 +3640,7 @@ namespace ts.server { | |||
if (proj.typeAcquisition.enable === undefined) { | |||
proj.typeAcquisition.enable = hasNoTypeScriptSource(proj.rootFiles.map(f => f.fileName)); | |||
} | |||
proj.typeAcquisition.inferTypings = this.hostConfiguration.typeAcquisition?.inferTypings ?? true; |
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'm a little surprised by this - it seems like whatever the editor sends on the specific project is unconditionally overwritten by the host config. Is that intended?
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.
That was my intent. Do you think we should sent the setting with openExternalProjects
rather than making it configurable through configure
?
I guess I don't understand why we would prefer that way.
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.
Yes.. This should be part of open external projects
src/server/editorServices.ts
Outdated
@@ -3632,6 +3640,7 @@ namespace ts.server { | |||
if (proj.typeAcquisition.enable === undefined) { | |||
proj.typeAcquisition.enable = hasNoTypeScriptSource(proj.rootFiles.map(f => f.fileName)); | |||
} | |||
proj.typeAcquisition.inferTypings = this.hostConfiguration.typeAcquisition?.inferTypings ?? true; |
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.
This seems incorrect.. host.typeAcquisition shouldnt mean for all projects.. external project can configure its on options so it shouldnt use default configured thing at all
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 did intend for it to be global. For VS this would be under tools > options. Is there a more preferred way of configuring external projects?
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.
Should openExternalProjects
handle the setting typeAcquisition
for external projects and then only inferred
projects get the setting from the host configuration?
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.
IMO you would at least want to allow an external project to specify what it wants and fall back to the host config.
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.
The setting should be only for inferred projects rather than all.. You should look at compilerOptions for inferred project as they can also differ with projectRoot. You would want similar.
src/server/editorServices.ts
Outdated
@@ -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 comment
The 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
src/compiler/types.ts
Outdated
@@ -5844,7 +5844,8 @@ namespace ts { | |||
enable?: boolean; | |||
include?: string[]; | |||
exclude?: string[]; | |||
[option: string]: string[] | boolean | undefined; | |||
inferTypingsFromFilenames?: boolean; |
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 like Enable/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.
src/server/protocol.ts
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
ExternalProject
has options called typeAcquisition
so this type shouldnt be changed.
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.
You can create different type instead you should create a type
export type InferredProjectCompilerOptions = ExternalProjectCompilerOptions & TypeAcquisition
and update the usage.
src/server/project.ts
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if if this.typeAcquisition and set method should be moved to Project
since 3 project types use the same method.
src/server/project.ts
Outdated
enable: allRootFilesAreJsOrDts(this), | ||
include: ts.emptyArray, | ||
exclude: ts.emptyArray | ||
exclude: ts.emptyArray, | ||
disableFilenameBasedTypeAcquisition: false |
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 dont think you need to set this since this is optional
You would want to wait for this merge if this is for 4.2 instead of 4.1 though |
@sheetalkamat because it is a new feature rather than a bug fix, or because of the protocol changes? |
New feature.. i think we are past merging features to 4.1 .. @DanielRosenwasser and @RyanCavanaugh are keeping track of schedule. |
I think this is OK for 4.1 but I'll double check with @DanielRosenwasser / @RyanCavanaugh |
I think that's probably okay, we can always pull it out post-release if we see issues with VS or VS Code Insiders. @mjbvz just to ensure everyone's aware that we're making ATA changes for JS projects. |
Filename-based ATA is sometimes undesirable in external and inferred projects. This change allows that behavior to be configured without needing to add a tsconfig.
disableFilenameBasedTypeAcquisition
totypeAcquisition
, to control whether or not typings are inferred based on .js filenames.typeAcquisition
to be configured by editors for non-configured (no tsconfig) projects.Fixes #40123