Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when using hydrogen with pulsar #2163

Open
ttxtea opened this issue Jan 21, 2023 · 4 comments
Open

TypeError when using hydrogen with pulsar #2163

ttxtea opened this issue Jan 21, 2023 · 4 comments
Labels
bug 🐛 For unexpected issues

Comments

@ttxtea
Copy link

ttxtea commented Jan 21, 2023

Description

When running a cell the TypeError: editor.languageMode.rowRangeForCodeFoldAtBufferRow is not a function, see below happens.

Prerequisites

Versions

Atom: 1.101.0-beta x64
Electron: 12.2.3
OS: Ubuntu 22.04.1
Thrown From: Hydrogen package 2.16.3

Stack Trace

Uncaught TypeError: editor.languageMode.rowRangeForCodeFoldAtBufferRow is not a function

At $HOME/.pulsar/packages/Hydrogen/dist/utils.js:177

TypeError: editor.languageMode.rowRangeForCodeFoldAtBufferRow is not a function
    at Object.rowRangeForCodeFoldAtBufferRow (/packages/Hydrogen/dist/utils.js:177:36)
    at Object.findCodeBlock (/packages/Hydrogen/dist/code-manager.js:357:31)
    at run (/packages/Hydrogen/dist/main.js:258:35)
    at /packages/Hydrogen/dist/main.js:80:31)
    at CommandRegistry.handleCommandEvent (/app.asar/src/command-registry.js:405:43)
    at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:617:16)
    at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:408:22)
    at WindowEventHandler.handleDocumentKeyEvent (/app.asar/src/window-event-handler.js:153:34)

Commands

     -0:05.8.0 hydrogen:run (input.hidden-input)
     -0:05.8.0 autocomplete-plus:cancel (atom-text-editor.editor.is-focused)

Non-Core Packages

Hydrogen 2.16.3 
@ttxtea ttxtea added the bug 🐛 For unexpected issues label Jan 21, 2023
@contang0
Copy link
Contributor

Same here. I'm always using the "Run cell and move down" command, but it only works if I highlight the code to be run. If I don't, I get the error @ttxtea mentions. Meanwhile, the "Run cell" command runs everything in the file, whereas it should really only run current line / block or what is highlighted.

@antonscharton
Copy link

antonscharton commented Mar 29, 2023

Had the same issue and this bugged me a lot. I came up with a small workaround
to restore original behavior of the hydrogen run command.

Add to the init.js script

atom.commands.add('atom-text-editor', 'custom:hydrogen-run', function () {
  const editor = this.getModel();
  atom.commands.dispatch(atom.views.getView(editor), 'editor:select-line');
  atom.commands.dispatch(atom.views.getView(editor), 'hydrogen:run');
  atom.commands.dispatch(atom.views.getView(editor), 'editor:move-to-end-of-line');
});

and map a key-binding to this function in the keymap, e.g.:

'atom-text-editor':
  'shift-enter': 'custom:hydrogen-run'

EDIT:

If you want it to work with (python) indent-blocks, e.g. function definitions in python, you could do the following.
This would allow you to put the cursor on the first line and the code will figure out the corresponding indent block.

atom.commands.add('atom-text-editor', 'custom:hydrogen-run', function () {
  const editor = this.getModel();

  atom.commands.dispatch(atom.views.getView(editor), 'editor:select-line');
  const row = editor.getLastSelection().getBufferRange().start.row;
  var k = 1;
  
  while (/^\s+$/.test(editor.getTextInBufferRange([[row+k, 0], [row+k, 1]]))) {
    atom.commands.dispatch(atom.views.getView(editor), 'core:select-down');
    k = k + 1;
  }
  if (k != 1){
    atom.commands.dispatch(atom.views.getView(editor), 'editor:select-to-end-of-line');
  }

  atom.commands.dispatch(atom.views.getView(editor), 'hydrogen:run');
  atom.commands.dispatch(atom.views.getView(editor), 'editor:move-to-end-of-line');
});

@contang0
Copy link
Contributor

@antonscharton this worked great! The second snippet is exactly what I needed.

@AJSchiller
Copy link

Thanks @antonscharton ! This restores expected behaviour for me, but I still get the error pop-up everytime. Does it do that for anyone else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 For unexpected issues
Projects
None yet
Development

No branches or pull requests

4 participants