Add advanced language features for Csound via custom Tree-sitter–based LSP#42
Add advanced language features for Csound via custom Tree-sitter–based LSP#42PasqualeMainolfi wants to merge 33 commits intocsound:masterfrom
Conversation
|
Just wanted to note that I saw this PR but it came in while I was traveling for holidays. I'm on another trip now so will look at this when I return home in a couple days. Apologies @PasqualeMainolfi for the delay in review! |
|
@PasqualeMainolfi One thing I did want to ask is if you tested this as a Web Extension (i.e., when installed and running in github.dev). I didn't see code to support that but may have just missed it. |
|
No worries. |
There was a problem hiding this comment.
Thank you @PasqualeMainolfi, it's going to be very nice to have this feature. I am going to leave the technical review to @kunstmusik as he is more familiar with these things, but I am concerned that this PR overwrites the project's readme file. This removes all the historical context for the existing project as well as removing valuable information about live-coding and using the UDP server. Would you mind reverting the README to the original master branch version. We can then update accordingly after any merge.
|
I’ve restored the original README to preserve the historical context and existing information. Additionally, I’ve added release notes to the PR, without referencing any version numbers. |
|
Thanks @PasqualeMainolfi - I know Steven is extremely busy right now, but hopefully we can get this merged and into the extension in time for the first release of Csound 7 👍 |
|
I was wondering if there is any approximate timeline available for the release of Csound7. Having a rough idea of the release date would help me plan the remaining work and properly schedule the effort needed to deliver a stable version of the LSP. I am already quite close, and only a few final adjustments are still missing. Thanks in advance for any information you can share. |
|
Good question. I think most of the tasks have been completed at this stage. So it could be in the next few weeks but I don't think any hard deadline has been set. |
src/utils.ts
Outdated
| try { | ||
| await vscode.window.withProgress({ | ||
| location: vscode.ProgressLocation.Notification, | ||
| title: `Installazione Csound LSP (${binaryName})...`, |
There was a problem hiding this comment.
This should be in English to match the rest of the plugin. (I haven't done I18N for vscode plugins before; we could investigate that in a separate PR)
|
@PasqualeMainolfi I ran this in the extension development host. It requested installing the LSP and then reported success in installing the LSP. I checked before and after and CSD and ORC code looks no difference with little syntax highlighting. I did not get any manual entries, autocomplete, etc. I am on MacOS. Unsure if something's gone wrong in installation or what but it's not operating as (I assume) expected.
|
|
I think I have fixed the bugs you showed me. |
|
@PasqualeMainolfi I tried the latest and when I start up the extension host it asks to download a newer version of LSP. I says yet and then it errors:
|
|
Thanks for the report! |
|
One other note, I asked Opus about using tree-sitter in Javascript so that we can use it in the web extension version of this plugin. Looks like compiling to WASM would be an option, which is promising. Looking at this PR, your concern is valid. The PR introduces a Csound Language Server built on a custom Tree-sitter grammar, which typically compiles to native binaries. This would indeed be incompatible with running as a VS Code web extension. The Good NewsYes, Tree-sitter parsers can run in JavaScript/WebAssembly. Tree-sitter supports compiling grammars to WASM, which can then be loaded and run in JavaScript environments (including browsers and VS Code web extensions). How to Make It Work for Web ExtensionsThe tree-sitter-csound grammar would need to be compiled to WASM instead of (or in addition to) native binaries. Here's what's typically required:
Recommendations for the PR
|
|
Yes, I can. |
|
I think we're on the same page, offer what we can in each environment. I think this will work out nicely and users will be happy. :) |
|
@rorywalsh check the LSP version in the lsp-bin folder, it should be 1.4.6. The web version is separate from the desktop one, so they don't touch each other. I did a fresh test from scratch just to be sure, and it all works fine. Additionally, verify that the
|
|
@rorywalsh If you'd like, feel free to send me the entire script. There might be something breaking the syntax that I'm missing just by looking at the photo. |
|
Thank @PasqualeMainolfi I can confirm I'm using the latest build, at this point 1.5.0. I think I also found the source of my woes. When I am in edito mode in Cabbage, i can drag and move UI components. When I do, it dynamically updates the .csd text. It's at this point all my opcodes get squiggly lines under them. I'm pretty sure the problem is on my end. I need to make sure I'm inserting the text in the correct way. 👍 |
|
Found the issue, it appears to have been an issue with a stale editor reference. I've updated my extension code and I no longer get any issues when my Cabbage extensions update any JSON code 👍 |
|
@rorywalsh Perfect! At this point, I think we could make sure this no longer causes issues with the syntax. |
|
Yes, or before those tags. My extension inserts json code into a Cabbage block. But the latest syntax errors were a result of my extension breaking the LSP. I've fixed this now on my end, so I think we're in the clear 👍 |
|
Hi @PasqualeMainolfi I'm still getting some odd behaviour with this every now and then. For example:
and:
You'll notice how writePointer in the last image is not coloured correctly. This code appear before the first image I sent, maybe it's throwing something off? |
|
Thanks @PasqualeMainolfi, looking good now 👍 |
|
@rorywalsh this one was quite difficult to fix. Csound’s syntax can be very ambiguous when it wants to be!
|
|
FWIW, there is no need to support the old-style Cabbage 2 syntax. Everything will be JSON moving forward. Apologies if you've spent time on this. I thought I had made it clear that it's only Cabbage JSON sections that are relevant here. |
|
@PasqualeMainolfi I have updated the structure of the code block to use a top level object instead of any array, which was the wrong choice to begin with. It now looks like this: This change from |
|
@rorywalsh Yes, of course. I also have another fix planned to include. As soon as I finish teaching my students, I’ll add it. |
|
Thanks @PasqualeMainolfi - oh and one other thing, I've add ARA support which is handled by a new JSON block. If you could add that too it would be great :) |
|
Ok, I can add it, but I need a bit more information. Can the block be placed inside the Cabbage block, or is it a standalone block? Does an ARA block have a specific key, or does it contain something specific? Could you show me a few examples so I can understand how it should look and parse it correctly? Also, please tell me which fields it contains and whether they are fixed by convention or configurable. Sorry, but I’ve never had the chance to work with this block before 😊. |
|
Apologies, I should have been more specific. It's a satandalone block. There shouldn't ever be a Cabbage and CabbageARA block in the same csd, and the contents are a single a top JSON object |
|
@rorywalsh check now if it’s correct.
|
|
Thanks @PasqualeMainolfi this looks super. I won't get a chance to check it properly till later, but I appreciate the prompt turnaround as always. |
|
Checking in, there's a couple concerns I have:
|
|
@kunstmusik Hi Steven, |
|
I tried the latest here and could not run the web version without fixing a typescript error and also updating npm dependency to 11.10.0 due to security constraint. Even then, trying to play the document did not work, it just hangs. I also tried to use Also to note, once I modified package.json and package-lock.json was rebuilt, seems like I can't build/run the extension here now. There's also a "Csound: Play Active Document" and a "Csound: Run Active Document". It's awkward as one works in web and other works in desktop, but they both show up for both environments. Would rather we keep to one command that adapts to work in browser or desktop. For the md files, can't we just load from csound maual github repo? Perhaps cache it? I'm trying to think of a solution that doesn't require having a large resource added to this repo that can go stale. |
|
@kunstmusik Steven should now be able to compile without errors. I removed the toolbar because the API causes issues in the web version, at least based on what I could see. |

















Csound vscode
This PR introduces a new Csound extension for Visual Studio Code built on top of a custom Csound Language Server (LSP) and a Csound Tree-sitter grammar specifically designed for Csound.
The extension aims to provide a modern, semantically aware editing experience for Csound users, fully compatible with Csound7.
Key Features
LSP
Editor
Completion & Hover
Commands exposed by the Language Server
The server exposes the following commands:
csound-lsp.run_file— run the current Csound scriptcsound-lsp.to_audio_file— render and save output to an audio filecsound-lsp.open_manual— open the Csound reference manualOffline Manual (Web Preview)
Language Injections
Technical Notes
Future Work
Planned next steps include:
This PR lays the groundwork for a complete and modern Csound development environment in VS Code, aligned with current language-server–based tooling.
Feedback and testing are highly appreciated.