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

Many symbols without scopes #137

Open

Description

@benogle

The support for js is pretty bad. Most of the issues are in the way of parsing variable names.

Load this example into atom. When I say something is not tagged I mean its scope is only .source.js.

import * as p from 'point';  //test
import { x as y } from 'coordinates';  //test
const ANSWER = 42;            // ANSWER not tagged (fixed by #138, #140)

var one, two, three, four;    // variables not tagged
var five = 5, six = 6;        // variables not tagged

function someFunc(arg1, arg2, arg3) {
  var aVariable = 'ok';       // aVariable not tagged
  aVariable = 'nope';         // aVariable not tagged
  var anArray = new Array()   // anArray not tagged (fixed)
  anArray.slice()             // anArray not tagged (fixed)
  anArray.otherMethod()       // anArray, otherMethod not tagged (fixed)
  randomGlobal.prop.omg()     // not tagged (fixed)

  var anObject = {
    key1: 'val1'              // key1 not tagged
    key2: function(one, two) {
    }
  }
}

var funcVar = function(arg1, arg2, arg3) {
}

class Car extends Vehicle {
  constructor(speed, cost) {
    super(speed);

    var cindex = Symbol('cost'); // cindex not tagged
    this[cindex] = cost;      // cindex not tagged

    this.intro = `This is a car runs at ${speed}.`;
  }
}

for (let num of [1, 2, 3]) {  // num not tagged
  console.log(num + 0b111110111);
}

Giving these symbols correct scopes will greatly improve the support in the coming SymbolProvider in the soon-to-be-bundled-in-core autocomplete-plus.

Activity

  1. czxtm commented on May 6, 2015

    @czxtm
  2. off-by-some commented on May 6, 2015

    @off-by-some
  3. JamesMowery commented on May 10, 2015

    @JamesMowery

    👍

    I'd love to see better JS support, as I'd really like to see this made possible: https://discuss.atom.io/t/is-it-possible-to-change-the-color-of-declared-variables/16731/1

    It's the one thing that keeps me from being totally in love with Atom.

  4. bobrocke commented on May 25, 2015

    @bobrocke

    Here are some other examples:

    open-a-terminal - atom

    But there are many others. This grammar appears to be pretty young.

  5. jonkwheeler commented on May 29, 2015

    @jonkwheeler

    screenshot 2015-05-29 12 44 09

    Here's a simple one. Most text is white. Objects, Methods, Props all the same.

    I came here from this Atom thread.

    It would really help me if the highlighting worked right.

  6. czxtm commented on May 29, 2015

    @czxtm

    I've temporarily worked around this by having my theme manually wrap any unwrapped scopes, and then adding a data-word attribute containing the 1st word. Here's the relevant code if anyone wants:

    Observer:

        # ____________________________________________________
        # Custom text wraps
        @textWrapObservers ||= new CompositeDisposable()
        @textWrapObservers.add atom.workspace.observeTextEditors (editor) =>
          @textWrapObservers.add editor.onDidStopChanging =>
            editorView = atom.views.getView editor
            @wrapTextNodes editorView, '.line > .source', '<span class="apathy-span"/>'

    Method that does the wrapping:

      ###*
       * Looks for text nodes and wraps them with a tag. Assuming we have the
       *  following HTML:
       *   <span>
       *     <span>lorem</span>
       *     hello // wraps this since we can't select just this via CSS otherwise.
       *   </span>
       *  There's no way to select just 'hello' with a CSS selector. Therefore, this
       *  method looks for these and wraps them with a `<span>` to make them
       *  selectable, and adds the first word in the tag into data-word attribute.
       * @method wrapTextNodes
       * @param  {string}      selector - Selector to .source.grammar nodes.
       * @param  {string}      wrapWith - String that will be used to generate a
       *                                  jQuery object to wrap matched text nodes
       *                                  with. example: '<span class="js"></span>'.
      ###
      wrapTextNodes: (editorView, selector, wrapWith) ->
        @customWrappedTextNodes ?= []
        self = this
        # FIXME Currently this doesn't happen until the 1st time the cursor
        #       moves, because jQuery.ready fires BEFORE the text has been added
        #       to the buffer. Need to get it to run just once on activation at the
        #       right time.
        $(editorView.shadowRoot).find(selector).each ->
          contents = $(this).contents()
          $.each contents, (i,val) ->
            if val.nodeType is 3
              # add tag which can be used for CSS
              match = $(this).text().trim().match /\b[\w]+\b/g
              firstWord = match?[0]
              # wrap the text
              $wrapped = $(this).wrap wrapWith
              $wrapped.parent().attr 'data-apathy-word', firstWord
              self.customWrappedTextNodes.push $wrapped
      ###*
       * Unwrap nodes wrapped by @wrapTextNodes().
       * @method unwrapTextNodes
      ###
      unwrapTextNodes: ->
        for node in @customWrappedTextNodes
          $(node).unwrap()
  7. junewunder commented on Jun 5, 2015

    @junewunder

    Another issue I have with the highlighting is that some variables will get special coloring, and others won't, example here:
    screen shot 2015-06-04 at 8 14 10 pm
    x and y are in orange, but z isn't the same color. This is annoying when working with 3D, but it would be nice if all the variables were the same color. Thanks

  8. winstliu commented on Jun 5, 2015

    @winstliu
    Contributor

    Hi @jaywunder, I actually just fixed that. If you upgrade to Atom 0.206.0, z should be highlighted as well ✨.

  9. junewunder commented on Jun 5, 2015

    @junewunder

    I seem to not be getting the 0.206.0 update pushed to my computer so I guess I'll get the fix tomorrow. Thanks for the quick response! 💖

  10. winstliu commented on Jun 5, 2015

    @winstliu
    Contributor

    Actually, sorry for the false information. A fix was pushed, but a new version wasn't published and integrated into Atom 😦. Maybe 0.207.0 then. Sorry!

  11. braver commented on Oct 16, 2015

    @braver

    Is this just a question of expanding the grammar? Sublime Text 3 recently pulled the JavaScript Next package into core to improve highlighting. Perhaps it would be a good idea to look at that as a basis to improve our JS support?

  12. bobrocke commented on Oct 16, 2015

    @bobrocke

    Won't Atom essentially "just use" .tmLanguage files?

  13. braver commented on Oct 17, 2015

    @braver

    Well you convert them first, but that's basically what happens.

  14. bobrocke commented on Oct 17, 2015

    @bobrocke

    @braver I see instructions for converting themes and bundles. Are there some for .tmLanguage files?

  15. mgenev commented on Oct 19, 2015

    @mgenev
  16. The-8-Bit-Zombie commented on Nov 4, 2015

    @The-8-Bit-Zombie
  17. Victorystick commented on Nov 4, 2015

    @Victorystick
    Contributor

    The import statement

    import {x, y} as p from 'point'; 

    isn't valid JavaScript, so it isn't strange for the highlighting to be broken. This on the other hand works fine

    import * as p from 'point'; 
    import { x as y } from 'coordinates';
  18. winstliu commented on Nov 4, 2015

    @winstliu
    Contributor

    @Victorystick thanks, updated the post.

  19. winstliu commented on Nov 18, 2015

    @winstliu
    Contributor

    Getting closer...pretty much the only issue left is tokenizing variables. That's also the hardest one, however 😔. The only other one I see is key1 not getting tokenized: we'll know for sure once Linguist picks up v0.101.0.

  20. dkimot commented on Aug 9, 2017

    @dkimot

    While not very helpful, FYI the subtle gradient solves all of these problems. You do have to take into account the fact that the master branch is ~10 commits ahead of the published version, but the RegEx is good from the repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions