Skip to content
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

Question: will there be a tsserver plugin? #254

Closed
Swatinem opened this issue Feb 11, 2019 · 12 comments
Closed

Question: will there be a tsserver plugin? #254

Swatinem opened this issue Feb 11, 2019 · 12 comments
Labels
question Questions! (i.e. not a bug / enhancment / documentation)

Comments

@Swatinem
Copy link

I was just wondering…

How does the endorsement of typescript-eslint in favor of tslint effect the usecase for https://github.com/Microsoft/typescript-tslint-plugin ?
Is there something similar planned for eslint?

I just saw this also mentioned here: #243 (comment)

@bradzacher bradzacher added the question Questions! (i.e. not a bug / enhancment / documentation) label Feb 12, 2019
@bradzacher
Copy link
Member

Just so I'm understanding correctly - the language server plugin exists to:

  • let you reuse the program already setup by the language server so it's faster.
  • let you provide your warnings/errors via the typescript LS instead of via an IDE plugin

Does it give you any other benefits at compile time? i.e. if I run tsc, will it report the errors from my plugin on the command line?

@mohsen1
Copy link
Contributor

mohsen1 commented Feb 12, 2019

Does it give you any other benefits at compile time?

No microsoft/TypeScript#16607

@Swatinem
Copy link
Author

* let you provide your warnings/errors via the typescript LS instead of via an IDE plugin

Plus, integrates with the codefix suggestions, so autofix all problems or autofix on save works more seamlessly.

@nstepien
Copy link
Contributor

@mohsen1 I was under the impression that this ticket was only about allowing plugins to modify the transpilation output, not the command line output?

@mohsen1
Copy link
Contributor

mohsen1 commented Feb 12, 2019

@MayhemYDG My understanding is that plugins are only for tsserver. They can provide errors, warnings and QuickFixes but when using the compiler command line tool (tsc) plugin is ignored

@nstepien
Copy link
Contributor

Ah I see, that makes sense. Unfortunate that tsc doesn't use the plugins.

@Swatinem
Copy link
Author

Just for reference, I found some docs about that here: https://github.com/Microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin

@Quramy
Copy link

Quramy commented Jul 28, 2019

Hi guys. I'm loving tsserver and TypeScript's language service.

So I've created a language service plugin for ESLint, https://github.com/Quramy/typescript-eslint-language-service . To use this plugin, npm i typescript-eslint-language-service and configure your tsconfig.json such as:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "plugins": [
      {
        "name": "typescript-eslint-language-service"
      }
    ]
  }
}

This plugin depends on only the following packages:

  • typescript
  • eslint
  • @typescript-eslint/parser

And this plugin gets ts.sourceFile instance from LanguageService's program and creates ESLint SourceCode instance with parsing to estree AST from the ts.sourceFile instance. In other words, this plugin re-uses the language service's tokenized result.

I'm welcome for PRs or feedbacks ;)

@JamesHenry
Copy link
Member

Thanks a lot for putting that together @Quramy! I can see a few areas for improvement:

  1. Don't deep import private symbols from the packages you depend on, this makes your code more likely to break as those things are subject to change at any time given they are not part of the public API

  2. Reduce areas of duplication: right now it looks like you are having duplicate (or create code very similar to) quite a few different parts of our codebase

For (1) and (2) if there are APIs/points of extension we don't currently provide from our packages, just let us know and we can look at providing them where it makes sense!

  1. Be explicit about the fact that you do actually depend on typescript-estree as well, not just parser

Thanks again for all your work on this, it's great to have different choices available for IDE setups!

@Quramy
Copy link

Quramy commented Jul 29, 2019

@JamesHenry Thanks for your feedback.

You’re right. For now, I use some internal APIs and duplicate some codes to directly convert from ts AST(not text) to ESLint AST. I want some public APIs so I’ll report them later.

About (3), using typescript-estree is temporary. If the above duplication is removed, I can remove the dependency.

@tsujp
Copy link

tsujp commented Sep 18, 2019

@Quramy amazing! Thank you.

Usage with Sublime Text LSP is flawless.

@bradzacher
Copy link
Member

I'm going to close this as it's not something we're going to look to support ourselves now or in the near future.

Quramy has done a great job and has an existing solution that people can use if they wish.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Questions! (i.e. not a bug / enhancment / documentation)
Projects
None yet
Development

No branches or pull requests

7 participants