otfried / ipe

The Ipe extensible drawing editor
http://ipe.otfried.org
125 stars 9 forks source link

Using VS Code as external editor #463

Closed LenAgain closed 1 year ago

LenAgain commented 1 year ago

I've just discovered this gem of a project and I'm trying to use VS Code as the external editor with no luck.

I've made an ipelet (verified the ipelet is loaded as it can change other settings) with prefs.external_editor = "code --wait %s" in, but once that's set the "Editor" button just does nothing when clicked.

I also tried changing the setting in prefs.lua to no avail. Scanning through some of the issues here it seems like I'm doing the right thing? Changing the editor to a shell script that logs its invocation did absolutely nothing, I'm not sure how I'd go about debugging it further.

Am I being really stupid here? Cheers.

otfried commented 1 year ago

What operating system are you on?

I have just tried it. In my ~/.ipe/ipelets/customization.lua, I added the line

prefs.external_editor = "code --wait %s"

Then I started Ipe and checked in Help -> Show configuration:

image

So Ipe has correctly picked up the setting.

And when I now create a text object, when I press the Editor button, VS code opens.

LenAgain commented 1 year ago

I'm on Windows 11 22H2.

Using the exact same setup as you've described I can see the external editor is set correctly when using the show configuration tool, but again the Editor button does nothing.

With a fresh install of VS Code and Ipe on another user I'm still running into the same problem.

otfried commented 1 year ago

Is VS code actually on your path? If you open a command line and type code, does it start?

LenAgain commented 1 year ago

Yes it's in my user's PATH

otfried commented 1 year ago

The default on Windows is notepad.exe %s, does that setting work?

So nothing at all happens when you press the Editor button - you don't get to see the small window saying "Waiting for external editor" ?

LenAgain commented 1 year ago

Yes it works with notepad and with notepad++.

With those two I see the "Waiting for external editor" dialog but when I set it to use VS Code the Editor button responds visually that it's been clicked but nothing happens after that.

otfried commented 1 year ago

That's a very strong indication that Ipe simply cannot start VS code with this specification. Have you tried putting the full pathname, that is setting

prefs.external_editor = "\"C:\\Users\\otfried\\AppData\\Local\\Programs\\Microsoft VS Code\\code.exe\" --wait %s"

(changing the path to match your local setup, of course).

For what it is worth: Ipe starts the editor using CreateProcessW(nullptr, cmd, ...), where cmd is prefs.external_editor with %s replaced by the actual filename. There are some caveats about this function finding the module, see https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw

otfried commented 1 year ago

Aha, so one caveat is that CreateProcessW appends .exe to the module name - but apparently VS code is called code.cmd. So perhaps it's enough to change it to

prefs.external_editor = "code.cmd --wait %s"
LenAgain commented 1 year ago

Yup that was the one!

Changing it to code.cmd --wait %s did the trick. I never thought to check that there wasn't some funkiness around the file extensions.

Cheers for the trouble on this one.