Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Tree-sitter missing variable.language scope #618

Open
chbk opened this issue Nov 1, 2018 · 3 comments
Open

Tree-sitter missing variable.language scope #618

chbk opened this issue Nov 1, 2018 · 3 comments

Comments

@chbk
Copy link

chbk commented Nov 1, 2018

Description

this, super, arguments and default used to be variable.language.js. There is no corresponding scope with tree-sitter.

Steps to Reproduce

  1. Enable Settings > Core > Use Tree Sitter Parsers
  2. Copy-paste:
arguments
this
super
import default

Expected behavior:

arguments, this, super and default should be variable.language.js.

Actual behavior:

arguments, this, super and default are source.js.

Versions

Atom : 1.32.1
Electron: 2.0.9
Chrome : 61.0.3163.100
Node : 8.9.3

@lee-dohm
Copy link
Contributor

@maxbrunsfeld can you give some more information here?

@maxbrunsfeld
Copy link
Contributor

Ok, #620 added back the scope for arguments and super. The default keyword is intentionally highlighted as keyword.control.

I'll leave this issue open because of the this variable. We're intentionally not highlighting this as language.variable because it causes this to be highlighted the same as object properties in most themes, and that was something we wanted to fix when updating from TextMate to Tree-sitter.

We have a PR open to figure out a different color for these kinds of special variables. When we finish that, we'll circle back here and update this to use that class.

@caleb531
Copy link
Contributor

caleb531 commented Mar 31, 2019

@chbk You might be pleased to know: I developed a hackish solution to inject highlighting for this and super into the built-in language-javascript grammar. This absolves you of any need to fork the language-javascript package, compile tree-sitter grammars, or rebuild Atom. Just place the following code in your init.coffee:

# Extend the JavaScript tree-sitter grammar with additional highlighting
extendJavaScriptTSGrammar = ->
  # All Atom grammars are loaded asynchronously, so use setImmediate() to
  # ensure that the JS grammar is only modified when it has fully loaded
  setImmediate ->
    jsGrammar = atom.grammars.treeSitterGrammarsById['source.js']
    if jsGrammar
      # Colorize `this`, `super`, and `arguments` in red (like other language keywords)
      jsGrammar.scopeMap.addSelector('this', 'variable.language.js')
      jsGrammar.scopeMap.addSelector('super', 'variable.language.js')
      jsGrammar.scopeMap.addSelector('super', 'variable.language.js')
      jsGrammar.scopeMap.addSelector('identifier', {
        match: /^arguments$/,
        scopes: 'variable.language.js'
      });
extendJavaScriptTSGrammar()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants