-
Notifications
You must be signed in to change notification settings - Fork 9
Add advanced language features for Csound via custom Tree-sitter–based LSP #42
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
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. :) |
|
At the moment, I’m working on parsing UDOs, specifically their signatures, including argument validation and output checking. or or and ... |
|
I think the first one is good as it can be used with doxygen to document .csd files. But I think opinions will be mixed on this one. |
|
@rorywalsh thanks! I’ve fixed the strange behaviors you pointed out. |
|
Great, I'm seeing no more squiggly lines 👏 Here is how the JSON looks now:
It's definitely better, but still not very accessible in terms of highlighting. keys and values often have the same colouring. Btw, those "//" comments are decorated by the cabbage extension, so they can be ignored. The documentation is here: |
|
Fantastic! This way, we can guide the compilation of a Cabbage block and maybe display the documentation separately, just like it’s done for the Csound manual. This could make everything much smoother. Let me know what you would like to have readily available. Keep in mind that Cabbage opcodes might currently show an error because I don’t think they are present in the Csound opcodes (repo). Check json now. The official tree-sitter-json query for keys uses the type |
|
@PasqualeMainolfi The documentation style is interesting. I've used javadocs, jsdoc/tsdoc, and doxygen, and their all similar. I checked and jsdoc and doxygen don't appear to work without knowing the underlying language. I also realized I had done a small script in my live-code system to generate docs from UDOs and instruments. I think it would be nice to create a csdoc project that can generate docs from orc code. If we do that, we can specify exact tags and format and the LSP can share a standard. Most likely something like the first example would be my preference. I'll see if I can use my csdoc.py file from csound-live-code as a starting point and convert into a standalone project that has documentation for standards and things. I think I could release it on pypi so that it could be used with uv/uvx. I'll reply here shortly on how that goes. |
|
Ah, I thought doxygen was one of the few tools that would work without knowing the underlying language. My bad. |
|
FYI: I created an initial version of csdoc here: https://github.com/kunstmusik/csdoc Generates documentation site like the following:
Probably a few more things to add but usable already. Only a few tags supported, LMK what you think about the format and tags. |
|
I think your proposal is very efficient. From my experience, less is often better. |
|
With regard to the JSON stuff, it’s all working well now. I’m going to start testing with Cabbage 3 next. I’ll be very happy to remove all of my ad-hoc error-reporting code in lieu of this. 🙂 |
|
@PasqualeMainolfi Not sure I understand the syntax tree idea exactly but happy to accept PR's. For tags, not sure we need @description as the body of the comment can be that. @Signature I'm also wary of as it's something to keep in sync with @params and @return, so it might be good to just generate. @author, @deprecated, and @example all make sense to me. |
|
One thing I noticed @PasqualeMainolfi, when I add something like this above my Cabbage section it breaks the parsing: The question is whether this is legal or not. I can't include comments in the JSON, but felt the need to warn people about this. Anything outside of a matched tags should be ignored, but is this feasible, or does it complicate things? I don't want you to waste time on this if it's not straightforward. |
|
@PasqualeMainolfi How difficult would it be to tap into the existing |
|
Regarding the issues you showed me, I think a relatively simple fix should resolve everything. |
|
For now the main concern is Csound :) Your appraisal of the JSON seems to match what my brief ressearch shows. In this case I might as well handle this myself from within my own extension. It probably makes more sense this way too. Let me know when you have a fi for the other issue and I will test. I've a lot of Csound7 orchestras to throw at it! |
|
Great, looking good now. Did something change with the Cabbage section though? The custom highlighting seems broken again.
It might be the SVG path string that preceeds this 🤔 I've attached the file, I had to rename it to allow uploading. |




























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.