Skip to content

Copy default compiler options for inferred projects from VS Code client #887

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

Merged
merged 3 commits into from
May 20, 2025

Conversation

andrewbranch
Copy link
Member

Taken from a TSServer config message, replacing allowSyntheticDefaultImports with esModuleInterop

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR aligns inferred project compiler options with VS Code client defaults, replacing allowSyntheticDefaultImports with esModuleInterop and adding commonly used flags.

  • Added comprehensive default compiler options (module, resolution, target, JSX, source maps, etc.)
  • Replaced allowSyntheticDefaultImports with esModuleInterop
  • Ensured inferred projects mirror editor behavior
Comments suppressed due to low confidence (3)

internal/project/service.go:719

  • [nitpick] Consider adding a comment explaining the origin of these defaults (e.g., VS Code client settings) and noting why each option is included.
compilerOptions := core.CompilerOptions{

internal/project/service.go:719

  • [nitpick] This large inline initialization could be extracted into a named constant or helper function to reduce duplication and improve readability.
compilerOptions := core.CompilerOptions{

internal/project/service.go:719

  • Add a unit test to verify that inferred projects are created with these default compiler options, ensuring future changes don't regress this behavior.
compilerOptions := core.CompilerOptions{

@@ -716,9 +716,19 @@ func (s *Service) getDefaultProjectForScript(scriptInfo *ScriptInfo) *Project {
}

func (s *Service) createInferredProject(currentDirectory string, projectRootPath tspath.Path) *Project {
// !!!
compilerOptions := core.CompilerOptions{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible for the extension to kind of use "SetCompilerOptionsForProjectRoot" - think tsserver uses that and there was some need of this in past though i am not aware of what as i wasnt around the time this was designed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I think we should try and avoid doing that for as long as possible; we're owning the LS now, so I think it makes sense for us to try and set this to what we think is a good idea. I think we'll need an extension point for sure, but I don't think it's needed until maybe VS or some other editor.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will eventually need the ability for the client to set certain options (e.g. strictNullChecks is exposed as a VS Code option), but we should also encode good defaults ourself. Empty options are really bad, and I’m guessing there are existing third party TS Server clients that don’t use setCompilerOptionsForInferredProjects and have really bad default behavior.

@jakebailey
Copy link
Member

Hm, tests do not like this 😄

@andrewbranch andrewbranch added this pull request to the merge queue May 20, 2025
Merged via the queue into microsoft:main with commit 2891e9c May 20, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants