SuperCollider VSCode / Language Server Protocol support

Just copying the missing libraries won’t work since the loader path from libsndfile still points to an arbitrary path outside the bundle. You would need to also replace the libsndfile dylib itself since the one in the 3.13 has the correct loader paths. @prko you probably could try that, I would suggest anyway moving to a new thread if you still have issues since this problem seems no longer about VSC LSP support.

2 Likes

Now the development version works again and it runs in vscode too!

I have two questions:

  • What hotkey do you use to open a help document? Currently I use ctrl + alt + d. I would like to know if there is a more common hotkey that is preferred by advanced users.
  • Currently sclang starts automatically when I open an SCD file. However, I could not find a shortcut to recompile sclang. How do I do this?
    Sorry for these questions. It is not easy for me to use an editor other than SC-IDE for sclang…

There’s a command “Restart sclang” which will restart your sclang instance (this, of course, recompiles also). I don’t currently have a command to ONLY recompile without restarting, as this workflow is difficult to implement in VSCode - but restarting only takes a second or so longer than recompiling, so this is really more of a nice-to-have feature.

IIRC the standard Cmd+D help key from the ScIDE is used by VSCode for some other common operation - you can always overwrite this key combo if you don’t care about the VSCode default.

Also, fwiw: the current behavior when VSCode is unable to connect to sclang because e.g. of a compile error is a LITTLE rough around the edges. In case of a compile error or sclang for some reason becoming unresponsive, “Restart sclang” command will eventually force-restart the sclang instance. Sometimes, it might take a few seconds due to waiting for time-outs, and sometimes you might have to restart a second time before it works. I’d like to improve this in the future: disconnecting / reconnecting a language server in VSCode is very undocumented, so it’s a lot of trial and error to get the behavior right.

1 Like

BTW: I’ve been supporting this effort by using vscodium for non-production SC noodling (e.g. hacking at code examples for the forum) and, where I see something dodgy in the language server, if I can find it then I’ll put in a PR to fix it. I’m up to 4 PRs, for little things that scztt now won’t have to debug. I imagine others could do the same.

Almost overlooked this… the one debugging feature in sclang that requires recompiling without quitting and relaunching the process is Process.tailCallOptimize = false; – agreed that this is only nice to have, but, I have occasionally run into some cases where tail call optimization obscured the code path, and it was nice to be able to run the code without that optimization.

Probably the solution for vscode, though, would be to set the flag at startup rather than interactively: a commandline switch, or an option in the language config file. My gut feeling is that the commandline switch might be better: I can’t think of a good reason to disable tail call optimization permanently, and it would be less convenient to switch it on and off in a json file.

hjh

1 Like

I’m joining this discussion and have thoroughly read through all the details. First off, I’d like to express my appreciation for the LSP support—it’s a fantastic development, so thank you for that!

I’ve been attempting to install the VSCode extension, carefully following the provided guidelines. However, I’ve encountered an issue during the extension’s activation phase (when installing the LanguageServer.quark). Below is the error message that appears in VSCode:

image

Additionally, the VSCode exthost.log is showing the following error (I can share the full log if needed):

2024-02-27 15:48:54.038 [error] Activating extension Scott Carver.vscode-supercollider failed due to an error:
2024-02-27 15:48:54.038 [error] Error: \\?\c:\Portableapps\VSCode 1.86.2\data\extensions\scott carver.vscode-supercollider-0.0.2\node_modules\@vscode\windows-registry\build\Release\winregistry.node is not a valid Win32 application.
\\?\c:\Portableapps\VSCode 1.86.2\data\extensions\scott carver.vscode-supercollider-0.0.2\node_modules\@vscode\windows-registry\build\Release\winregistry.node
    at process.func [as dlopen] (node:electron/js2c/asar_bundle:2:2131)
    at Object.<anonymous> (node:internal/modules/cjs/loader:1403:18)
    [...additional log content...]

Has anyone else experienced this issue, or does anyone have suggestions on how to resolve it? Any assistance would be greatly appreciated!

Git is installed on your machine?

Have you tried it on Windows? I believe LSP support does not work on Windows…

I experienced the same error:

I have not resolved the problem on Windows:

It is probably trying to use git for an automated download of the latest version.

I haven’t tried in awhile, but some years ago, I was never able to get SC to run git commands successfully. AFAIK Quarks updates via git don’t work in Windows I’ll downgrade that to “may run into problems in Windows that don’t occur in other platforms.”

As a workaround, you could go to the LanguageServer quark’s repository and download it manually, and put it into the user-app support directory’s downloaded-quarks folder. (The default SC-IDE has a File menu command to open the user app support directory.)

hjh

Using a special YAML file for each workspace can make things more adaptable (a normal list of needed quarks , or even other add-ons for the workspace), for example, moving your project between computers. So all that is needed would be in that folder. I tried that once and thought it would be straightforward (starting sclang with arguments pointing to local config files and quark repos etc, all edited in the vscode workspace config file), but it didn’t work for me.

Besides, if the LSP is aware of other files in the project, it will improve word completions and similar tools, etc.

EDIT: One slightly unfortunate thing that I noticed is that vscode (in general, not specific to sclang projects) is one of the few programs that are capable of interrupting the audio on my Linux system. I don’t know why, other than vscode needing system resources with the same/higher priority in relation to audio/jack (or maybe some accessibility feature doing something).

Thank you for your response. However, I believe the issue extends beyond the initial diagnosis. I’m encountering the same error across all LSP extension commands, even after manually installing the Quark. It appears there might be an underlying issue with the extension’s compatibility on Windows, potentially related to a problem with compiled node modules.

Yes, and looking at the log, it doesn’t seem to be a GIT issue.

[error] Error: \\?\c:\Portableapps\VSCode 1.86.2\data\extensions\scott carver.vscode-supercollider-0.0.2\node_modules\@vscode\windows-registry\build\Release\winregistry.node is not a valid Win32 application.

Interesting - I wonder if this is a packaging issue on my side? Packaging is pretty point-and-click with vscode so I wouldn’t expect problems, but I also haven’t looked closely at this either so maybe theres more I need to do.

@scztt Thanks for all the hard work here. I have some time to help work on this as I’d love to get a neovim dev environment working. I’ve been hacking away on a branch and have it mostly working now, building off @dannyZyg’s python wrapper.

I had a tweak a few things in the server - would you like a pull request or two?

2 Likes

Yes, I spent a few hours / days investigating, and it seems that the windows-registry native node module and the windows registry paths are the culprits.

I first recompiled and replaced the windows-registry native node module (with Node, Visual Studio, Desktop development with C++ workload and Spectre libraries) and this time the extension would pass the activation phase.

However, there were still problems with the Windows registry paths which were incorrect (“Key not found”). I checked regedit and the key is located at HKEY_CURRENT_USER\Software\SuperCollider\3.13.0.

So for the sake of testing, I then simply removed the windows-registry native node module and hardcoded my Supercollider install paths in out/util/default.js and src/util/default.ts (const installPath = ‘c:\Audio\SuperCollider3.14-dev’;), and… it worked (LSP READY)!

Well, almost completely. Everything seems to be working as expected, but I am still facing a few issues:

  1. There’s an error at extension startup:
[error] TypeError: Cannot read properties of undefined (reading 'isRunning')
    at SuperColliderContext.<anonymous> (c:\Portableapps\VSCode\data\extensions\scott carver.vscode-supercollider-0.0.2\src\context.ts:96:25)
    at Generator.next (<anonymous>)
    at c:\Portableapps\VSCode\data\extensions\scott carver.vscode-supercollider-0.0.2\out\context.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (c:\Portableapps\VSCode\data\extensions\scott carver.vscode-supercollider-0.0.2\out\context.js:4:12)
    at SuperColliderContext.cleanup (c:\Portableapps\VSCode\data\extensions\scott carver.vscode-supercollider-0.0.2\out\context.js:77:16)
    at SuperColliderContext.<anonymous> (c:\Portableapps\VSCode\data\extensions\scott carver.vscode-supercollider-0.0.2\src\context.ts:116:14)
[Etc...]
  1. For some reason, the server won’t boot with my external MOTU Ultralite mk5 ASIO sound card (“Server ‘localhost’ exited with exit code 1” / “Deferred(-554665169)”). I am currently investigating, but I still don’t see where the problem comes from. This ASIO sound card works flawlessly with SC IDE. The server does boot with my laptop Realtek audio card though, but there is little point to use SuperCollider with this sound card.

  2. Go to Definition, Go to Declaration, Go to Implementations, Go to References don’t work, probably due to the absence of the windows-registry native node module.

  3. Show node tree doesn’t work ([error] Error: Command doesn’t exist: supercollider.internal.showNodeTree)

Go to Declaration returns this error in the Extension Host log:

2024-03-13 12:11:04.383 [error] [Scott Carver.vscode-supercollider] provider FAILED
2024-03-13 12:11:04.383 [error] Error: Wrong type.
    at handleResponse (c:\Portableapps\VSCode\data\extensions\scott carver.vscode-supercollider-0.0.2\node_modules\vscode-jsonrpc\lib\common\connection.js:565:48)
    at handleMessage (c:\Portableapps\VSCode\data\extensions\scott carver.vscode-supercollider-0.0.2\node_modules\vscode-jsonrpc\lib\common\connection.js:345:13)
    at processMessageQueue (c:\Portableapps\VSCode\data\extensions\scott carver.vscode-supercollider-0.0.2\node_modules\vscode-jsonrpc\lib\common\connection.js:362:17)
    at Immediate.<anonymous> (c:\Portableapps\VSCode\data\extensions\scott carver.vscode-supercollider-0.0.2\node_modules\vscode-jsonrpc\lib\common\connection.js:334:13)
    at processImmediate (node:internal/timers:476:21)

Everything else seems to be okay. I would be so glad to use this fantastic LSP extension with SuperCollider. I did what I could to drill down the issues, but I am afraid my skills and understanding of the extension codebase do not allow me to dig any further at this point. I’m happy to help if needed, though.

Hope this can help : )

Windows 11 user here. I drove myself crazy yesterday trying to figure this out. I managed to get just a bit further from where you left off. The undefined error is due to a faulty try/catch thing (? in js syntax, I’m not too familiar). I believe the most recent push in the vscode-supercollider github fixes the error.

I’ve been trying to build this plugin on my own to adjust it further. This is on a new PC, so I’m rusty with windows. The way packages are handled makes me very uncomfortable coming from max/linux and 5 years separated from windows. I reinstalled supercollider and rebuilt things many times until it regressed into the quarks crashing and being unable to fetch from the language server git on the main IDE.

Should Quarks.install(“\path\yadda\yadda\LanguageServer.quark”) be able to fetch that from the get go? I’ve been gaslit by supercollider and now I’m not even sure how it got there in the first place without me cloning the git.

Here’s a thought, has anyone tried getting this working on WSL? I love WSL because of how freely I can nuke the whole OS when everything fails.

One more, @scztt, how would one best repackage the repo into vscode? I’ve just been copying my builds into the .vscode folder.

I’ll report back later after attempt 2: electric boogaloo of energetic disassembly and diminishing sanity. I totally cleared git/npm/python off my computer just to make things pure.

Quarks.install – I was never able to get this to work reliably in Windows. SC reports success but the command may fail in the background.

hjh

Hey all - pushed a new version with some fixes and minor features:

To answer a few previous questions…

I’ve been trying to build this plugin on my own to adjust it further. This is on a new PC, so I’m rusty with windows. The way packages are handled makes me very uncomfortable coming from max/linux and 5 years separated from windows. I reinstalled supercollider and rebuilt things many times until it regressed into the quarks crashing and being unable to fetch from the language server git on the main IDE.

To run it from a local dev repo, you can either build it (in vscode, “Run Build Task” → “cpm compile”) and then simply run from vscode. Or, you can package it with vsce package, and then load that via the … menu in the Extensions panel in VSCode (more here: Publishing Extensions | Visual Studio Code Extension API)

However, there were still problems with the Windows registry paths which were incorrect (“Key not found”). I checked regedit and the key is located at HKEY_CURRENT_USER\Software\SuperCollider\3.13.0.

In the current code, I believe I am properly null checking this - I may have only added that after you encountered this problem, so try the new version? I’m curious if you still have the same problem.

There’s an error at extension startup:

This should be fixed I believe - but also, this was due to not finding the sclang path, so it would have failed elsewhere eventually. This should behave a bit better now?

For some reason, the server won’t boot with my external MOTU Ultralite mk5 ASIO sound card

I have this problem often with my MOTU. Sometimes it helps to set an explicit sample rate, but that could be unrelated - the problem is intermittent. I think this is unrelated to the LSP.

Show node tree doesn’t work ([error] Error: Command doesn’t exist: supercollider.internal.showNodeTree)

Fixed.

2 Likes

Thanks for the update! Good timing too, I was driving myself mad trying to get into the works of VSCode extensions. I got it working on windows 11 64 bit with only a few adjustments.


First, for those who are trying to install it, here’s my neurotic/pedantic process.

-1. Get nvm-windows and git for windows.

  1. Reboot, I suppose.

  2. Install SC 3.13.0 via the windows exe. Don’t run it yet

  3. Download the dev build that comes with SC and copy/replace all the files in \Program Files\SuperCollider (you can choose the name when installing the exe in step 1)

  4. Run it the first time as administrator. Then reload, it replaces the help files. It will be right when the default help says 3.14-dev. Compile some code, run the server, try to install some quarks. Add supernova + scsynth.exe to the windows defender exclusion list. Honestly, reboot to be safe. I’m not saying these are necessary steps, but it certainly rules out my trust issues with SC now that I’ve seen how stable it is.

3.5. Reboot again, I suppose

  1. Install the VSIX

At this point, the windows registry module causes some complaints that can be observed on the dev console of vscode

  1. Navigate to
C:\Users\[you]\.vscode\extensions\scott carver.vscode-supercollider-0.0.3
  1. Delete node_modules. Open a terminal in the main directory of the extension (right click → Open in Terminal) and run:
npm install
  1. This will have a ton of complaints about vulnerabilities. These don’t break anything, but you might feel better about your life if you run:
npm audit fix

You can also run it with the --force tag, it did not seem to break anything. I did revert to the original package.json and package-lock.json just to be sure about the dependencies. --force pushes all necessary updates that audit finds, so it could push a non-backwards-compatible one.

  1. Open regedit. We have to find the correct SC registry entry. The correct one will point to the Program Files directory of SC. It could vary on Windows, but on my Windows 11 it was:
HKEY_CURRENT_USER\Software\SuperCollider\3.13.0
  1. Go back to the extension’s directory folder. Navigate to
\out\util\defaults.js

Open this file and edit the field of line 44 col 72 that puts together the registry address. I had to change Current Version to 3.13.0 and HKEY_LOCAL_MACHINE to HKEY_CURRENT_USER.

I’m not the most familiar with Typescript, but I believe since these files are compiled from TS, changing them is fine. You don’t have to rebuild the plugin with said changes.

  1. Edit the paths in User Preferences to find a copy of your yaml config and sclang.exe. (basically follow scztt’s instructions from here)

  2. You should be good to use the command palette in VSCode to install the Language Server quark. It failed on me the first time, but was fine the second time. It ran silently, so I was confused, but it then loaded up the next time I opened a .scd file.

  3. Try booting the server and running code and making a synthdef. Check the output of the dev console in vscode to see if anything is failing. If not, you did it!


So, here are the existing issues that I found.

  • The vscode\windows-registry module that installs by default is not up to date with the package.json.
  • It seems like a lot more showed up in the node_modules folder after I cleared it and did a fresh install
  • The Supercollider registry entry has a hardcoded version number and is in the wrong parent category as the scripts are trying to find, causing crashes.
  • I don’t know why it’s bothering with the Win Registry search. It’s an easy fix but I don’t know if/how that changes with other windows versions
  • SC’s windows dev build instructions are unclear and should really come with an installer. If you’re not supposed to overwrite the files of 3.13.0, that should be clear. I don’t believe this causes a problem other than that the SC version tends to point towards 3.13.0 sometimes. So, this is an SC development issue. I tried to build an exe on windows but some of the dependencies were unclear and the build guide is super out-of-date. And the DX sound libraries were failing to install on win 11.

And a new problem that seems to be unrelated to the problems I previously encountered:

While the sclang command shortcuts work fine, the evaluate block message that you can click physically above a region is broken.

Clicking a region of

(
postln("hello world")
)

causes the following error

ERROR: syntax error, unexpected end of file, expecting DOTDOT or ':' or ',' or ')'
  in interpreted text
  line 5 char 1:

   
   
-----------------------------------
ERROR: Command line parse failed

I tried debugging this and I wasn’t able to find the solution. Essentially, when that evaluate message is clicked, the closing parenthesis is left out. When the same command is executed via shortcut, the closing parenthesis is included. That’s what I inferred from the following debug logs.

Clicking Evaluate Region:

{"id": 18,"result": [{"range": {"start": {"line": 0,"depth": 0,"character": 0},"end": {"character": 0,"line": 2}},"command": {"title": "▶ Evaluate block","command": "supercollider.evaluateSelection","arguments": [{"start": {"line": 0,"depth": 0,"character": 0},"end": {"character": 0,"line": 2}}]}}]}


{"jsonrpc":"2.0","id":19,"method":"textDocument/evaluateSelection","params":{"textDocument":{"uri":"file:///c%3A/Users/Hamish/Documents/sc/test2.scd"},"sourceCode":"(\r\n    postln(\"hello world\")\r\n"}}

ctrl enter:

{"id": 22,"result": [{"range": {"start": {"line": 0,"depth": 0,"character": 0},"end": {"character": 0,"line": 2}},"command": {"title": "▶ Evaluate block","command": "supercollider.evaluateSelection","arguments": [{"start": {"line": 0,"depth": 0,"character": 0},"end": {"character": 0,"line": 2}}]}}]}

{"jsonrpc":"2.0","id":23,"method":"textDocument/evaluateSelection","params":{"textDocument":{"uri":"file:///c%3A/Users/Hamish/Documents/sc/test2.scd"},"sourceCode":"(\r\n    postln(\"hello world\")\r\n)"}}
1 Like

Thanks for the thorough report!

  • I’m basically working blind without a Windows system so your information was very helpful, I fixed some obvious errors with the window registry checking, and added checks for specific version numbers rather than CurrentVersion, which apparently we don’t write to when we install? This should AT LEAST automatically pick up common release version of sc, but ofc if you have a dev version / weird install location you’ll still need to point to it in the settings.

  • I have no idea what the deal is with the registry package - I’m installing the latest version. I’m being more careful about errors now, so at least that should take care of some failure cases.

  • I don’t know why it’s bothering with the Win Registry search. It’s an easy fix but I don’t know if/how that changes with other windows versions

The intent here is to try to find the path where SuperCollider is installed. so users don’t have to go digging around for an sclang.exe file in basic cases where they just did a normal SuperCollider install. After the change I just pushed, the current workflow is:

  1. IF you don’t specify a SuperCollider path in the vscode settings…
  2. First, check the registry for installed versions, based on common version numbers (we have to basically guess…).
  3. If that fails, try c:/Program Files/SuperCollider
  4. If that fails, show the user an error and direct them to the settings.

I believe I fixed some/all of the registry problems, and the region issue. Sending you a private build later today if you wanna test.

1 Like

@molossus I came to similar conclusions, and this was my workaround: https://github.com/scztt/vscode-supercollider/issues/42#issuecomment-2065583963.