tree-sitter / tree-sitter-javascript

Javascript grammar for tree-sitter
MIT License
363 stars 114 forks source link

Is it possible to disable TS-specific highlights from this grammar? #342

Closed rschristian closed 1 week ago

rschristian commented 1 week ago

Sorry in advance if this all sounds daft and confused -- I absolutely am slightly confused.


As of now I only have JS & a couple unrelated grammars installed (C, Lua, Vim, etc.) per :TSInstallInfo. However, upon opening a JS file, I run into this suspect highlight:

import { Foo } from './foo.js';
       // ^ `:Inspect` yields `@type.javascript`

I see nothing in this grammar that would trigger that (as far as I can tell) but I do see the following from the TS grammar that could be to blame?

((identifier) @type (#match? @type "^[A-Z]"))

https://github.com/tree-sitter/tree-sitter-typescript/blob/73c4447796b251295b498227bad028d88dc1918b/queries/highlights.scm#L6-L7


My specific problem is that this is an incredibly naive determination for a TS type. I get that there's limitations as to what you can do with the AST alone, and this is still a perfectly valid way to import types even if there's less ambiguous alternatives such as import type { ... } or import { type ... today. However, in a .js file it goes from being a weak assumption to one that's incorrect -- you cannot import types that way in JS.

Hence my confusion. I'm not sure how that TS-specific highlight is being added when I don't have the TS grammar installed, and I'm not sure why it's being applied to a .js file. :echo &filetype returns javascript so nothing appears to be fishy with the file type detection. I don't understand where this is coming from or why.

Thanks for anyone's time, I appreciate it.

ObserverOfTime commented 1 week ago

https://github.com/nvim-treesitter/nvim-treesitter

rschristian commented 1 week ago

Sorry, thanks! Didn't realize it was doing something different.