-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enhancement: Try using tsserverlibrary's ProjectService to handle type-aware mode #6575
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
Comments
@bradzacher and I prototyped this in #6754 and left some questions there. It seems to work |
Is it possible for typescript-eslint to use the editor's tsserver instance if it exists? Or provide a way for an IDE extension such as vscode-eslint to provide access to the IDEs running tsserver instance? |
Even if there were some tsserver API to access everything, I'd think it'd be prohibitively slow to work with because eslint would be in a totally different process. You definitely don't want to be proxying everything across the wire. The only way to get direct access would be to write a tsserver plugin (which may work), but it's not clear to me how that would tie into eslint unless eslint itself ran entirely within said plugin. |
There is a 3rr party that has created an LSP plugin for ESLint but yeah they had to reimplement much of the eslint extension within the plugin and convert all the eslint errors to diagnostics... It's not clean or easy. |
cc @Quramy for the https://github.com/Quramy/typescript-eslint-language-service perspective. Would love any thoughts you have! I've had a long-standing todo to reach out about this a week or two after we merge #6754. |
Early user report: When I enabled type-aware mode (configured parserOptions & added 2 dependent rules: consistent-type-exports, require-array-sort-compare) on 2600 typescript modules (220k LOC) codebase, I faced:
Adding One bug made me revert this flag as well as parserOptions & rules that is likely related here:
Can be related to #6814?
|
Awesome, thanks for trying this out @erictheswift! Is this something you'd be able to (either or both of):
Really excited to see evidence of real life perf & memory improvements! 🚀 |
Another bit that I unfortunately only realized after the feature was merged; things might get "weird" when the "inferred" project is involved (this is exported as When tsserver doesn't have a tsconfig, it still needs to work on files that are open; these could be random TS/JS files that aren't normally built. That usually tends to cover things like dotfiles, TS's However, the default settings for an inferred project are typically set by the client, e.g. VS Code. The upshot is that the settings that ts-eslint may have here could be different than what is seen in the editor. And indeed, that is likely happening already, because VS Code sets much more reasonable defaults, e.g. turning on strictNullChecks and strictFunctionTypes, at least (and, they can be overridden by the user). Not quite sure what to do about that; potentially some new config that lets you set some Sidenote; this issue was closed when the PR was merged, but should we keep this issue open to gain feedback about this feature while it's being hacked on? Or is there some better mechanism to have these kinds of discussions? |
@bradzacher were chatting about this a bit - I think I'd like to let it sit for a version, then add explicit docs with a pinned discussion for it. |
Before You File a Proposal Please Confirm You Have Done The Following...
Relevant Package
typescript-estree
My proposal is suitable for this project
Description
This is a follow-up to #6172 and the TypeScript / ESLint meeting we had last week.
Currently, type-aware mode uses
ts.Program
to do its work. There are some problems with this approach:#6172 takes the approach of using the LanguageService to handle this stuff. This is a good step, and one taken by projects like ts-morph. However, a single LanguageService itself will only handle one project at a time, so is only a partial fix.
My idea is to go further, and use
tsserverlibrary
'sProjectService
instead. This is "the thing" that tsserver uses to load projects and respond to language server requests for the editor. The idea is that you can create a LanguageService, then act like a user does, opening files, making requests, closing files, and so on. This means:The general approach is as follows:
tsserverlibrary
instead oftypescript
.ProjectService
. Like everything else, it takes in a host, but nothing surprising.openClientFile
to mark the file as open (potentially providing contents), and then callgetScriptInfo
on its path.ScriptInfo
likegetScriptInfo(filename).getDefaultProject().getLanguageService(/*ensureSynchronized*/ true)
and so on until you get to Program / TypeChecker whatever else is needed.There are some problems:
tsserverlibrary
is an entirely different module thantypescript
. Will this break downstream rules which importtypescript
directly? Is that a thing people do? Do we have to move the API? (uh oh)tsserver
is already running? maybe it's not a problem becuase it's no worse than now.Fail
Pass
Additional Info
No response
The text was updated successfully, but these errors were encountered: