pulsar-edit / pulsar

A Community-led Hyper-Hackable Text Editor
https://pulsar-edit.dev
Other
3.24k stars 137 forks source link

editor.languageMode.rowRangeForCodeFoldAtBufferRow is not a function (python script) #319

Closed LRydin closed 1 year ago

LRydin commented 1 year ago

Thanks in advance for your bug report!

What happened?

Prerequisites

Description

Classic shift-Enter to run single line on python (Hydrogen) throws error.

Steps to Reproduce

  1. create any python file (.py) and attempt to run anything (e.g. import os)

Expected behavior:

run (equivalent to hydrogen:run)

Actual behavior:

throws error: editor.languageMode.rowRangeForCodeFoldAtBufferRow is not a function

Versions

Atom: 1.100.0-beta x64 Electron: 12.2.3 OS: Ubuntu 22.10 Thrown From: Hydrogen package 2.16.3

Stack Trace

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

At /home/leo/.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:83:45)
    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

     -4:59.2.0 hydrogen:run-and-move-down (input.hidden-input)
     -4:59.2.0 autocomplete-plus:cancel (atom-text-editor.editor.is-focused)
     -2:18.7.0 hydrogen:run (span.syntax--keyword.syntax--control)
     -2:18.7.0 autocomplete-plus:cancel (atom-text-editor.editor.is-focused.has-selection)
     -2:16 hydrogen:run-and-move-down (input.hidden-input)
     -2:16 autocomplete-plus:cancel (atom-text-editor.editor.is-focused)

Non-Core Packages

Hydrogen 2.16.3 

Which OS does this happen on?

🐧 Debian based (Linux Mint, Ubuntu, etc.)

OS details

Ubuntu 22.10 (Kernel: 5.19.17-051917-generic)

Which CPU architecture are you running this on?

64-bit(x86_64)

What steps are needed to reproduce this?

Description

Classic shift-Enter to run single line on python (Hydrogen) throws error.

Steps to Reproduce

  1. create any python file (.py) and attempt to run anything (e.g. import os)

Expected behavior:

run (equivalent to hydrogen:run)

Actual behavior:

throws error: editor.languageMode.rowRangeForCodeFoldAtBufferRow is not a function

Additional Information:

mauricioszabo commented 1 year ago

Nothing much we can do here - this should be fixed in Hydrogen package.

I'm not even sure what's supposed to be editor.languageMode, considering that the text editor never had this as a documented API...

mauricioszabo commented 1 year ago

Found the error - this condition is invalid as to get a version (parseFloat should not be used to get semantic versions or any version in general): https://github.com/nteract/hydrogen/blob/621cb9990705a19bc9f7d3d2f0d0819c23ce2295/lib/utils.tsx#L221

Please, ask for Hydrogen authors to fix this condition - we literally have nothing we can do in this situation, sorry...

shr00mie commented 1 year ago

Found the error - this condition is invalid as to get a version (parseFloat should not be used to get semantic versions or any version in general): https://github.com/nteract/hydrogen/blob/621cb9990705a19bc9f7d3d2f0d0819c23ce2295/lib/utils.tsx#L221

Please, ask for Hydrogen authors to fix this condition - we literally have nothing we can do in this situation, sorry...

If that's the case, then why does running code via Hydrogen work when executing via Packages -> Hydrogen -> Run from the Pulsar menu options?

Disclaimer: I have absolutely no idea how packages are constructed within Pulsar, which means it's entirely possible the Hydrogen team borked something with the code responsible for executing code via keyboard shortcuts, but not via the menu options.

LRydin commented 1 year ago

@mauricioszabo:

If that's the case, then why does running code via Hydrogen work when executing via Packages -> Hydrogen -> Run from the Pulsar menu options?

This is exactly why I believe this is Pulsar-related and not Hydrogen related. How can it run with a right-click hydrogen:run but not with shift-Enter on the editor? (thanks @shr00mie).

mauricioszabo commented 1 year ago

Folks, I don't know - maybe when running via the menu it doesn't detect the active text editor the same way, and uses a different path? For example, on these lines, it basically exits the process without calling the offending function if some conditions fails: https://github.com/nteract/hydrogen/blob/621cb9990705a19bc9f7d3d2f0d0819c23ce2295/lib/code-manager.ts#L132-L135

There's also another situation on the code where it bails of if the conditions are different, and they can be different because of different focus at the time, etc.

What I do know is that the Hydrogen code is not correct - there isn't a .languageMode on text editors, and you can't parse versions with parseFloat - and these are the issues we're seeing. Somebody that's interested could run inside Atom (an old version) and try to see in which conditions that error occurs.

Or, you can open your init script and "patch" atom.getVersion to always return something that satisfies that version, like atom.getVersion = () => '1.7'. These are work-arounds, but they won't fix the Hydrogen package - and we also can't fix on our end, because their code is wrong...

LRydin commented 1 year ago

That's fair. I'll move this to Hydrogen then, to see what they make of it. Thanks again @mauricioszabo!

mauricioszabo commented 1 year ago

@LRydin I did a PR: https://github.com/nteract/hydrogen/pull/2162

LRydin commented 1 year ago

Sweet! You move fast @mauricioszabo :P. Cheers!