Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Uncaught TypeError: Cannot read property '0' of undefined #6982

Closed

Description

@dxue2012

[Enter steps to reproduce below:]

  1. ...
  2. ...

Atom Version: 0.202.0
System: Mac OS X 10.10.3
Thrown From: Atom Core

Stack Trace

Uncaught TypeError: Cannot read property '0' of undefined

At /Applications/Atom.app/Contents/Resources/app.asar/src/tokenized-line.js:89

TypeError: Cannot read property '0' of undefined
    at TokenizedLine.module.exports.TokenizedLine.transformContent (/Applications/Atom.app/Contents/Resources/app.asar/src/tokenized-line.js:89:38)
    at new TokenizedLine (/Applications/Atom.app/Contents/Resources/app.asar/src/tokenized-line.js:71:12)
    at TokenizedBuffer.module.exports.TokenizedBuffer.buildTokenizedLineForRowWithText (/Applications/Atom.app/Contents/Resources/app.asar/src/tokenized-buffer.js:521:14)
    at TokenizedBuffer.module.exports.TokenizedBuffer.buildTokenizedLineForRow (/Applications/Atom.app/Contents/Resources/app.asar/src/tokenized-buffer.js:506:19)
    at TokenizedBuffer.module.exports.TokenizedBuffer.tokenizeNextChunk (/Applications/Atom.app/Contents/Resources/app.asar/src/tokenized-buffer.js:286:43)
    at /Applications/Atom.app/Contents/Resources/app.asar/src/tokenized-buffer.js:263:26
    at /Applications/Atom.app/Contents/Resources/app.asar/node_modules/underscore-plus/node_modules/underscore/underscore.js:666:47

Commands

Config

{
  "core": {
    "disabledPackages": [
      "language-glsl",
      "autocomplete-glsl",
      "symbols-view",
      "symbols-tree-view",
      "theme-switcher",
      "atom-typescript-tools",
      "language-typescript",
      "atom-django",
      "script",
      "linter-tslint",
      "minimap-highlight-selected",
      "minimap"
    ],
    "themes": [
      "one-dark-ui",
      "solarized-dark-syntax"
    ]
  },
  "editor": {
    "invisibles": {},
    "tabLength": 4,
    "softWrap": true
  }
}

Installed Packages

# User
.bin, vundefined
atom-ctags, v3.2.0
atom-html-preview, v0.1.6
atom-ternjs, v0.6.3
atom-typescript, v4.5.2
autoclose-html, v0.17.0
autocomplete-paths, v1.0.2
color-picker, v1.7.0
git-log, v0.3.0
git-projects, v1.13.0
highlight-selected, v0.9.1
less-autocompile, v1.0.0
linter, v0.12.6
linter-less, v0.4.0
save-session, v0.15.3
vim-mode, v0.49.0
wakatime, v4.0.9

# Dev
No dev packages

Activity

  1. basarat commented on May 27, 2015

    @basarat
    Contributor

    I believe my custom grammar stuff for atom-typescript is the issue. Investigating.

    Note: Broken with atom v0.202

    @dxue2012 did you have a .ts file open by chance?

  2. dxue2012 commented on May 27, 2015

    @dxue2012
    Author

    @basarat Yes I did.

    In fact I don't recall this issue being present before I updated atom-typescript to v4.5.2. Thank you for investigating!

  3. basarat commented on May 27, 2015

    @basarat
    Contributor

    before I updated atom-typescript to v4.5.2

    Worth mentioning: its not atom-typescript that's changed. Its atom that's changed that broken this < not blaming ... just pointing the path of investigation for those interested 🌹

  4. kevinsawicki commented on May 27, 2015

    @kevinsawicki
    Contributor
  5. basarat commented on May 28, 2015

    @basarat
    Contributor

    Its because of addition of tags. Still going through the code. For anybody interested this is my code : https://github.com/TypeStrong/atom-typescript/blob/master/lib/main/atom/typescriptGrammar.ts#L181-L227

    Tags where added to firstmate : https://github.com/atom/first-mate/blob/94604652a81cfebb5eae57e7d7c666905912f19f/src/grammar.coffee#L93-L96

    Investigating what I should be returning (and functions I should be calling) from my custom tokenizeLine.

  6. nathansobo commented on May 28, 2015

    @nathansobo
    Contributor

    @basarat So you're constructing TokenizedLines on your own?

  7. basarat commented on May 28, 2015

    @basarat
    Contributor
  8. nathansobo commented on May 28, 2015

    @nathansobo
    Contributor

    Ah yes, I see now. I describe the new encoding here: #6757

    It's for memory savings purposes. Basically I'm interleaving scope starts/stops (represented by negative integers) with positive integers representing tokens (by their length). You'll need to interact with methods on the grammar registry to translate scopes to numeric ids, but it should be doable.

  9. basarat commented on May 28, 2015

    @basarat
    Contributor

    @nathansobo cool. That helps a lot. I'll make a hotfix to move back to cson driven grammar so people can still use and investigate the rest later tonight 🌹

  10. added a commit that references this issue on May 28, 2015
  11. basarat commented on May 28, 2015

    @basarat
    Contributor

    Thanks for the guidance. Published atom-typescript:v4.5.3 with hotfix 🌹

    FWIW the other package I know that uses similar custom grammar code is by @p-e-w https://github.com/p-e-w/language-javascript-semantic

  12. JonathanMEdwards commented on May 28, 2015

    @JonathanMEdwards

    I'm getting same trap on .ts files with with atom 0.204.0 and atom-typescript 4.5.5

  13. nathansobo commented on May 28, 2015

    @nathansobo
    Contributor

    @basarat you shouldn't be overriding the grammar in this new version right? Hard to explain how this error could happen otherwise. @JonathanMEdwards are you sure you're upgraded? You may need to reload your editor as we don't yet reload code properly after upgrades due to module caching issues.

  14. JonathanMEdwards commented on May 28, 2015

    @JonathanMEdwards

    Duh - yeah restart fixes.

  15. nathansobo commented on May 28, 2015

    @nathansobo
    Contributor

    It's not obvious a restart should be required and we need to fix it, but yeah, glad it worked.

  16. nathansobo commented on May 28, 2015

    @nathansobo
    Contributor

    Going to close this out as it's a package erroring on a private API. I definitely wouldn't discourage this kind of hacking but also can't guarantee things won't break. @basarat I'd love to see you keep experimenting with this approach. It might inform how we could give you a better official interface to hook into your own parser someday.

  17. wcandillon commented on Jun 1, 2015

    @wcandillon

    @nathansobo I appear to have the same issue in my plugin. What is the private API that causes this issue? Here's my plugin: https://github.com/wcandillon/language-jsoniq/blob/master/lib/jsoniq-grammar.js

  18. wcandillon commented on Jun 1, 2015

    @wcandillon

    @nathansobo my tokenizeLine implementation used to return the following format:

    [
      {
        "start": "source.jq"
      },
      {
        "value": "import module namespace",
        "scopes": [
          "source.jq.keyword"
        ],
        "bufferDelta": 23,
        "firstNonWhitespaceIndex": null,
        "firstTrailingWhitespaceIndex": null,
        "screenDelta": 23
      },
      {
        "value": " ",
        "scopes": [
          "source.jq.text"
        ],
        "bufferDelta": 1,
        "firstNonWhitespaceIndex": null,
        "firstTrailingWhitespaceIndex": null,
        "screenDelta": 1
      },
      {
        "value": "xmldb",
        "scopes": [
          "source.jq.text"
        ],
        "bufferDelta": 5,
        "firstNonWhitespaceIndex": null,
        "firstTrailingWhitespaceIndex": null,
        "screenDelta": 5
      },
      {
        "value": "=",
        "scopes": [
          "source.jq.keyword.operator"
        ],
        "bufferDelta": 1,
        "firstNonWhitespaceIndex": null,
        "firstTrailingWhitespaceIndex": null,
        "screenDelta": 1
      },
      {
        "value": "\"",
        "scopes": [
          "source.jq.string"
        ],
        "bufferDelta": 1,
        "firstNonWhitespaceIndex": null,
        "firstTrailingWhitespaceIndex": null,
        "screenDelta": 1
      },
      {
        "value": "http://28.io/modules/exist-db",
        "scopes": [
          "source.jq.string"
        ],
        "bufferDelta": 29,
        "firstNonWhitespaceIndex": null,
        "firstTrailingWhitespaceIndex": null,
        "screenDelta": 29
      },
      {
        "value": "\"",
        "scopes": [
          "source.jq.string"
        ],
        "bufferDelta": 1,
        "firstNonWhitespaceIndex": null,
        "firstTrailingWhitespaceIndex": null,
        "screenDelta": 1
      },
      {
        "value": ";",
        "scopes": [
          "source.jq.text"
        ],
        "bufferDelta": 1,
        "firstNonWhitespaceIndex": null,
        "firstTrailingWhitespaceIndex": null,
        "screenDelta": 1
      },
      {
        "value": "",
        "scopes": [
          "source.jq"
        ],
        "bufferDelta": 0,
        "firstNonWhitespaceIndex": null,
        "firstTrailingWhitespaceIndex": null,
        "screenDelta": 0
      }
    ]

    I modified the implementation to return the following:

    [
      {
        "start": "source.jq"
      },
      {
        "start": "keyword"
      },
      "import module namespace",
      {
        "end": "keyword"
      },
      {
        "start": "text"
      },
      " ",
      {
        "end": "text"
      },
      {
        "start": "text"
      },
      "xmldb",
      {
        "end": "text"
      },
      {
        "start": "keyword.operator"
      },
      "=",
      {
        "end": "keyword.operator"
      },
      {
        "start": "string"
      },
      "\"",
      {
        "end": "string"
      },
      {
        "start": "string"
      },
      "http://28.io/modules/exist-db",
      {
        "end": "string"
      },
      {
        "start": "string"
      },
      "\"",
      {
        "end": "string"
      },
      {
        "start": "text"
      },
      ";",
      {
        "end": "text"
      }
    ]

    Does this new output format look good? It doesn't appear to work.

  19. nathansobo commented on Jun 1, 2015

    @nathansobo
    Contributor

    You're on the right track. Read lower in that explanation and you'll find the true format that more efficiently represent the same concept, with integers. It's pretty cryptic but the other representations ate too much memory.

  20. basarat commented on Jun 1, 2015

    @basarat
    Contributor

    @wcandillon tip (not related to the issue though) ... no need to override tokenizeLine**s** as the default implementation is similar to what you came up with : https://github.com/atom/first-mate/blob/1c2b006ed2bf119f2662e87f64a3b21beca481e9/src/grammar.coffee#L73-L80 (as far as I can see).

  21. michaelkrog commented on Jun 2, 2015

    @michaelkrog

    +1

  22. nathansobo commented on Jun 2, 2015

    @nathansobo
    Contributor

    May I ask why you're +1-ing this issue? The author has fixed the problem in a subsequent release. If you upgrade and reload Atom, the issue should disappear.

  23. p-e-w commented on Jun 5, 2015

    @p-e-w
    Contributor

    @basarat, @wcandillon: With some key hints from @nathansobo in #7124, I managed to port my package language-javascript-semantic to the new format and it now features a working CoffeeScript-provided grammar again. The relevant code is here.

  24. lock commented on Jan 22, 2019

    @lock

    This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks!

  25. locked as resolved and limited conversation to collaborators on Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions