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

[typescript] use the language service for tokenization #11580

Closed
thorn0 opened this issue Sep 6, 2016 · 7 comments
Closed

[typescript] use the language service for tokenization #11580

thorn0 opened this issue Sep 6, 2016 · 7 comments
Assignees
Labels
feature-request Request for new features or functionality *question Issue represents a question, should be posted to StackOverflow (VS Code) typescript Typescript support issues
Milestone

Comments

@thorn0
Copy link

thorn0 commented Sep 6, 2016

There is too many issues with the TM grammar, many of which seem to be impossible to fix.

E.g. in microsoft/TypeScript-TmLanguage#121, we can read this:

I think it's possible that this might never be completely fixed, due to limitations of the textmate grammar system.

Isn't it better to try another approach (the one that Visual Studio uses) instead of trying to fix the unfixable?

@ramya-rao-a ramya-rao-a added typescript Typescript support issues *question Issue represents a question, should be posted to StackOverflow (VS Code) labels Sep 6, 2016
@dbaeumer dbaeumer assigned aeschli and unassigned dbaeumer Sep 7, 2016
@aeschli aeschli changed the title Proper syntax highlighting for TypeScript: ditch the TM grammar, use the language service instead [typescript] use the language service for tokenization Sep 7, 2016
@aeschli
Copy link
Contributor

aeschli commented Sep 7, 2016

I also think that tokenizers implemented by language servers is an interesting idea that we should evaluate again.
The current strategy is chosen for performance reasons. Tokenizing happens in the renderer process and is line base, optimized for colorizing as you type.
A language server tokenizer needs cross process communication, and likely analyses the whole file in order to not have the same problems as a text mate tokenizer: Not seeing more than the tokens on the current line as well as not being able to change the tokens on previous lines.
@egamma @alexandrudima

@aeschli aeschli added this to the Backlog milestone Sep 7, 2016
@aeschli aeschli added the feature-request Request for new features or functionality label Sep 7, 2016
@dbaeumer
Copy link
Member

dbaeumer commented Sep 8, 2016

Agree on this. I think we need to distinguish between syntax classification which happens in the render and semantic classification which happens in the language server. Syntax classification should be simple.

@thorn0
Copy link
Author

thorn0 commented Sep 8, 2016

Writing a parser for Scheme: an hour of satisfying coding
Writing a parser for JS/ES2015: years of confusion, probably still not right

— Marijn Haverbeke (@marijnjh) September 7, 2016

As the syntax of JS and TS isn't simple, its classification can't be simple. It needs a parser, you can't get by with a bunch of regexps here.

E.g. string is a type, but also it can be a name of a variable. Always using the same color for it is confusing rather than helpful. On the other hand, a name of a class always refers to the same thing both in type annotations and in expressions. Visual Studio consistently uses the same color for class names, which can be really helpful sometimes. It's just a couple of examples from the top of my head. If you need more, just see https://github.com/Microsoft/TypeScript-TmLanguage/issues

On this screenshot, VS is on the left, VS Code on the right. See how Foo gets different colors depending on whether it's a class or a variable: The highlighting is really helpful in VS, and confusing and distracting in Code.

image

@alexdima
Copy link
Member

alexdima commented Sep 8, 2016

I am in favor of adding extension host API where a semantic classifier can complement a "dumb" top-down colorizer. NB even without further API this can be accomplished today through decorations, although I would not recommend it :)

@basarat
Copy link
Contributor

basarat commented Sep 19, 2016

Was annoyed by TM as well and one of the key reasons for alm. Some docs on how that was done : https://basarat.gitbooks.io/alm/content/contributing/syntax.html 🌹

@nfour
Copy link

nfour commented May 14, 2017

I'm looking to interact with the TS language server in order to deliver decorations for:

  • background colors based on primitive type & other stylistic crap
  • decorations based on variable scope depth
  • control flow decorations
  • expanded interface structures on hover

Is this blocking something like what I have in mind? Or could someone point me towards resources for interacting with the TS server, such as how it provides inferred type info on hover?

@aeschli
Copy link
Contributor

aeschli commented Nov 23, 2017

duplicate of #216

@aeschli aeschli closed this as completed Nov 23, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality *question Issue represents a question, should be posted to StackOverflow (VS Code) typescript Typescript support issues
Projects
None yet
Development

No branches or pull requests

7 participants