You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently in ecmascript files strings matching "use strict" exactly are highlighted using @keyword.directive, this is mostly fine as most of the time you'll actually see this string is in a valid context, however the current query also highlights this string in places where it makes no sense, for example in const x = "use strict"
I have created some queries that fix the issue, however they are kinda ugly and i hope there is a better way of fixing this:
(program ; matches "use strict" if its the first expression in the file
.
(expression_statement
.
(string
(string_fragment) @keyword.directive
(#eq? @keyword.directive "use strict"))))
(function_declaration ; matches use strict if its the first expression in a function
body:
(statement_block
.
(expression_statement
(string
(string_fragment) @keyword.directive
(#eq? @keyword.directive "use strict")))))
(arrow_function ; same as above but for arrow functions with blocks
body:
(statement_block
.
(expression_statement
(string
(string_fragment) @keyword.directive
(#eq? @keyword.directive "use strict")))))
Thank you for this! It is unfortunate that the query has to be so complicated, though. Additionally, I think it would need to support comments before the 'use strict' as well as having the directive highlighted in a function_expression, something like
consta=function(){'use strict'}
at which point it may not be worth the effort. My guess is it is pretty uncommon to just have a random string be 'use strict'?
Hmm, its not too hard to fix both of those, I did it in a couple of minutes (you can find the updated queries here) but I agree that it might be more trouble than its worth.
At the very least I'd like to see it not highlighted when it isnt an expression (e.g. when its passed as an argument or if its a variable), this dosent fix highlighting the expression in invalid context but its a much simpler query
Describe the highlighting problem
Currently in ecmascript files strings matching "use strict" exactly are highlighted using
@keyword.directive
, this is mostly fine as most of the time you'll actually see this string is in a valid context, however the current query also highlights this string in places where it makes no sense, for example inconst x = "use strict"
I have created some queries that fix the issue, however they are kinda ugly and i hope there is a better way of fixing this:
Example snippet that causes the problem
Tree-sitter parsing result
Example screenshot
Expected behavior
The Query should only highlight the use strict directive when it actually means something
Output of
:checkhealth nvim-treesitter
Output of
nvim --version
Additional context
No response
The text was updated successfully, but these errors were encountered: