atom / toggle-quotes

An Atom package to toggle between single and double quotes
MIT License
77 stars 36 forks source link

Broken with tree-sitter parsers enabled #57

Closed steventango closed 6 years ago

steventango commented 6 years ago

Steps to Reproduce

  1. Enable Tree Sitter Parsers in Settings
  2. Place mouse in between two quotes.
  3. Use Command Palette to run 'Toggle Quotes: Toggle' or use the default key binding CTRL+SHIFT+'

Expected behavior:

Quote types are toggled.

Actual behavior:

Nothing.

Reproduces how often:

100%

Versions

Windows 10 Atom 1.28.2 toggle-quotes 1.1.0

jasonrudolph commented 6 years ago

@maxbrunsfeld @queerviolet: Would you mind taking a look at this issue when you have a moment?

queerviolet commented 6 years ago

Hi there,

@TangSteven, what language are you trying to toggle quotes in? I can't repro this on master under JS. We also landed significant changes to this code relatively recently, so it may have been fixed.

maxbrunsfeld commented 6 years ago

@queerviolet This bug should be reproducible in any JS file; the package currently use textmate-specific scopes to detect strings, so I think it should fail to work in any file that's using Tree-sitter.

queerviolet commented 6 years ago

Oh, my bad. I have local changes that fix it 🤦🏾‍♀️.

Aerijo commented 6 years ago

@TangSteven Does this still happen when using the latest version of this package (v1.1.1)?

steventango commented 6 years ago

No, but it's not working for a different reason this time, instead it gives this error (same error as #59)

Atom: 1.29.0 x64 Electron: 2.0.5 OS: Microsoft Windows 10 Home Thrown From: toggle-quotes package 1.1.1

Stack Trace

Uncaught TypeError: Character index must be a number

At C:\Users\Steven\AppData\Local\atom\app-1.29.0\resources\app\node_modules\text-buffer\lib\text-buffer.js:980

TypeError: Character index must be a number
    at SyntaxNode.descendantForIndex (/app.asar/node_modules/tree-sitter/index.js:195:19)
    at TreeSitterLanguageMode.getRangeForSyntaxNodeContainingRange (~/AppData/Local/atom/app-1.29.0/resources/app/src/tree-sitter-language-mode.js:335:41)
    at TreeSitterLanguageMode.bufferRangeForScopeAtPosition (~/AppData/Local/atom/app-1.29.0/resources/app/src/tree-sitter-language-mode.js:343:23)
    at TextEditor.bufferRangeForScopeAtPosition (~/AppData/Local/atom/app-1.29.0/resources/app/src/text-editor.js:3867:48)
    at toggleQuoteAtPosition (/packages/toggle-quotes/lib/toggle-quotes.js:34:20)
    at /packages/toggle-quotes/lib/toggle-quotes.js:7:7
    at TextBuffer.module.exports.TextBuffer.transact (~/AppData/Local/atom/app-1.29.0/resources/app/node_modules/text-buffer/lib/text-buffer.js:973:24)
    at TextEditor.transact (~/AppData/Local/atom/app-1.29.0/resources/app/src/text-editor.js:2002:30)
    at toggleQuotes (/packages/toggle-quotes/lib/toggle-quotes.js:4:10)
    at /packages/toggle-quotes/lib/main.js:13:9)
    at CommandRegistry.handleCommandEvent (~/AppData/Local/atom/app-1.29.0/resources/app/src/command-registry.js:384:49)
    at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (~/AppData/Local/atom/app-1.29.0/resources/app/node_modules/atom-keymap/lib/keymap-manager.js:621:22)
    at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (~/AppData/Local/atom/app-1.29.0/resources/app/node_modules/atom-keymap/lib/keymap-manager.js:412:28)
    at WindowEventHandler.handleDocumentKeyEvent (~/AppData/Local/atom/app-1.29.0/resources/app/src/window-event-handler.js:110:40)

Commands

     -1:45.7.0 toggle-quotes:toggle (input.hidden-input)
     -1:42 core:select-all (input.hidden-input)
     -1:41.6.0 core:cut (input.hidden-input)
     -1:40.9.0 fuzzy-finder:toggle-file-finder (input.hidden-input)
     -1:38 grammar-selector:show (atom-text-editor.editor.is-focused)
  3x -1:32.3.0 editor:move-to-beginning-of-word (input.hidden-input)
  3x -1:30.6.0 editor:move-to-end-of-word (input.hidden-input)
     -1:27.3.0 core:move-left (input.hidden-input)
     -1:27 core:paste (input.hidden-input)
     -1:26.6.0 core:move-left (input.hidden-input)
     -1:26 core:undo (input.hidden-input)
  2x -1:22.5.0 toggle-quotes:toggle (input.hidden-input)
     -1:08.3.0 grammar-selector:show (atom-text-editor.editor.is-focused)
     -1:06.5.0 core:confirm (input.hidden-input)
     -1:01.8.0 window:toggle-dev-tools (input.hidden-input)
  7x -0:58.5.0 toggle-quotes:toggle (input.hidden-input)
Ben3eeE commented 6 years ago

@TangSteven Since you are getting the same exception as #59. I will close this as a duplicate of #59.