You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reacted by Remy Adriaanse, Marcel Lanz, Roland Tepp, Janusz Dziurzyński, James Hochadel, Robert Craigie, Jan van Valburg, Morlay, Thomas Krampl, Alex and 51 more
To get a better idea of what this should look like: what kind of functionality and analysis would people want to see supported by a LSP implementation?
To get a better idea of what this should look like: what kind of functionality and analysis would people want to see supported by a LSP implementation?
Syntax checking/validation (basically, show errors without having to run cue eval first)
Symbols for completion, documentation and jumping to definition
basically, I'd like the same editing experience for Kubernetes objects in CUE as you can get for YAML in VS Code
To get a better idea of what this should look like: what kind of functionality and analysis would people want to see supported by a LSP implementation?
find all locations contributing to a current position
expand implied fields into current struct, to allow editing them as if it were a form
grey out or otherwise mark fields that could be removed with trim (highly important fields)
remove unchanged implied fields (implied fields could be marked with @Implied()
Long term goal, I'd like to build something like Barlin.
This gets into some very meta concepts underpinning cue but theoretically a cue evaluator could be written in cue similar to the way Barlin utilizes a scheme interpreter implemented in MiniKanren which implemented scheme 🤔
Probably worth starting with simple diagnostics. That will allow us to flesh out a basic skeleton for what the LSP server should look like (including how to handle modules, a la Go modules).
AFAIK, syntax definitions fall outside the spec of LSP. I plan to implement a Vim plugin in Go using govim for AST driven syntax highlighting to try out the parser/AST.
I've talked to @mpvl at FOSDEM and it might be worth checking out the Prometheus Language Server@slrtbtfs created as part of his internship in our team. It reuses parts of gopls but in a more general purpose way. @slrtbtfs should have more details about why things needed to be changed, in case you have questions. That should already get this going a bit quicker :)
I've had a quick look at cue, and it should probably be possible to reuse parts of the PromQL language server for the cue language server.
What is definitely reusable and turned out be very useful is the golang.org/x/tools/internal/lsp/proctocol package, which contains (almost) all the types defined in the LSP specification.
What could be useful for you, too, is forking the github.com/prometheus-community/promql-langserver/langserver/cache package, removing all the PromQL stuff there and replacing the yaml parser with the cue parser. This package basically takes care of all the statekeeping in the language server.
Then the only thing left to do is implementing the protocol.Server interface. You can start with leaving everything unimplemented and then add more and more language features over time.
Another more recent development related to language servers is The Language Server Index Format (LSIF).
Basically the idea is to spit out the analysis to a JSON file. Sourcegraph (a code search tool) lets you upload the LSIF file and gives you language-server-like code navigation (but without the language server even running!).
Perhaps cue could spit out the LSIF JSON data?
I've just grep'ed for my notes on the topic and thought I'd share them here in case they are helpful. See below.
Loving cue at the moment and the vscode-cue plugin. Can't wait for a language server!
lsif-protocol: Protocol defined as TypeScript interfaces
lsif-util: Utility tools for LSIF development
lsif-tsc: LSIF indexer for TypeScript
lsif-npm: Linker for NPM monikers
I semi-hacked together a working implementation (using promql as a base) over the past two days. You can see it running in action in vscode below :). Currently, I have the following working:
Diagnostics: parse errors, compile errors and even output of cue vet
Definition: navigate to definition (including multiple, see GIF)
Hovering: showing definition on hover + comments, works decentish, but could use some work
Completion: Extremely basic at the moment, would need a lot more work here
(There might be one or two crashes though 😅 )
Should I fork this project and add what I have up until know, then open a PR?
Or should I just commit it to a personal repo, that's separate?
Some thoughts I had during my implementation, most of these are probably my fault for not being familiar with the codebase though 😛 :
It is very annoying that compilation fails immediately, if there is any error (or maybe I haven't found the correct options yet?). At the moment I need to keep the last Instance of a document around, otherwise I only have the AST. Seems to be possible by using build.Instance instead. However, if a top level identifier is unknown, inst.Value() will still return nothing, so would need to access some internal stuff.
Navigating the AST and Instance is very annoying. I wrote my own Cursor for the AST, but nothing yet for Instance.
Matching between something in the AST and a corresponding Value is even more annoying, that code is very messy and should probably be reworked. Currently, I iterate through all Values in the Instance and check if val.Source() == node (node is an ast.Node).
There doesn't seem to be a way to get a Value corresponding to a field definition, which made some stuff a lot harder.
Mapping between source locations is also not trivial and seems to be the cause of one of the crashes.
There doesn't seem to be a distinction between an ast.Ident when used e.g. a: b (i.e. one is field definition label, the other field definition type?). Ideally, there was a way to know which one is which, since certain stuff (like auto complete or hover), have different info based on that (at least the way I implemented it at the moment).
Lastly, I wanted to say, that I really love this project! I think it's really cool and we plan on using it in our new infrastructure for all config management (hence why I decided to spend some time implementing this :)).
With cue lsp shipping in v0.15.0 with many features, I believe we can close this as resolved now; we will continue to post updates and announcements relating to the LSP via #1776 and the #lsp channels on Discord and Slack :)
Please send your thanks to @cuematthew, who has done the majority of the work in the LSP!
Reacted by Bill Kaguru Wanjohi, James Qualls, Tom van Dinther, げ and str4ngeMD
Activity
cueckoo commentedon Jul 3, 2021
Original reply by @rudolph9 in cuelang/cue#142 (comment)
Somewhat related, looks like someone made a vim plugin https://github.com/jjo/vim-cue
cueckoo commentedon Jul 3, 2021
Original reply by @jlongtine in cuelang/cue#142 (comment)
Some other links as well:
I was chatting with @mpvl about this a bit at KubeCon this week, and I think this could be highly valuable for CUE.
cueckoo commentedon Jul 3, 2021
Original reply by @mpvl in cuelang/cue#142 (comment)
To get a better idea of what this should look like: what kind of functionality and analysis would people want to see supported by a LSP implementation?
cueckoo commentedon Jul 3, 2021
Original reply by @mxey in cuelang/cue#142 (comment)
cue evalfirst)basically, I'd like the same editing experience for Kubernetes objects in CUE as you can get for YAML in VS Code
cueckoo commentedon Jul 3, 2021
Original reply by @mpvl in cuelang/cue#142 (comment)
cueckoo commentedon Jul 3, 2021
Original reply by @rudolph9 in cuelang/cue#142 (comment)
Long term goal, I'd like to build something like Barlin.
This gets into some very meta concepts underpinning cue but theoretically a cue evaluator could be written in cue similar to the way Barlin utilizes a scheme interpreter implemented in MiniKanren which implemented scheme 🤔
cueckoo commentedon Jul 3, 2021
Original reply by @zchee in cuelang/cue#142 (comment)
I created packages that lsp for Go. (for my project, Neovim LSP plugin written in Go :D)
It almost works IIRC. I'm using zchee/nvim-lsp (private).
If we develop lsp for CUE written in Go, it might be helpful that package.
cueckoo commentedon Jul 3, 2021
Original reply by @myitcv in cuelang/cue#142 (comment)
We can likely reuse some of the work in
golang.org/x/tools/internal/lsp/...to get us started.Probably worth starting with simple diagnostics. That will allow us to flesh out a basic skeleton for what the LSP server should look like (including how to handle modules, a la Go modules).
AFAIK, syntax definitions fall outside the spec of LSP. I plan to implement a Vim plugin in Go using
govimfor AST driven syntax highlighting to try out the parser/AST.cueckoo commentedon Jul 3, 2021
Original reply by @metalmatze in cuelang/cue#142 (comment)
I've talked to @mpvl at FOSDEM and it might be worth checking out the Prometheus Language Server @slrtbtfs created as part of his internship in our team. It reuses parts of gopls but in a more general purpose way. @slrtbtfs should have more details about why things needed to be changed, in case you have questions. That should already get this going a bit quicker :)
cueckoo commentedon Jul 3, 2021
Original reply by @slrtbtfs in cuelang/cue#142 (comment)
Hi,
I've had a quick look at cue, and it should probably be possible to reuse parts of the PromQL language server for the cue language server.
What is definitely reusable and turned out be very useful is the golang.org/x/tools/internal/lsp/proctocol package, which contains (almost) all the types defined in the LSP specification.
What could be useful for you, too, is forking the
github.com/prometheus-community/promql-langserver/langserver/cachepackage, removing all the PromQL stuff there and replacing the yaml parser with the cue parser. This package basically takes care of all the statekeeping in the language server.Then the only thing left to do is implementing the
protocol.Serverinterface. You can start with leaving everything unimplemented and then add more and more language features over time.Feel free to reach out if you have any questions.
cueckoo commentedon Jul 3, 2021
Original reply by @mikelnrd in cuelang/cue#142 (comment)
Another more recent development related to language servers is The Language Server Index Format (LSIF).
Basically the idea is to spit out the analysis to a JSON file. Sourcegraph (a code search tool) lets you upload the LSIF file and gives you language-server-like code navigation (but without the language server even running!).
Perhaps cue could spit out the LSIF JSON data?
I've just grep'ed for my notes on the topic and thought I'd share them here in case they are helpful. See below.
Loving cue at the moment and the vscode-cue plugin. Can't wait for a language server!
..............................................................
https://code.visualstudio.com/blogs/2019/02/19/lsif
https://github.com/microsoft/lsif-node/blob/master/README.md
https://github.com/Microsoft/language-server-protocol/blob/master/indexFormat/specification.md
vscode extension (to serve LSP from the file)
https://github.com/microsoft/lsif-node/blob/master/README.md#lsif-extension
https://about.sourcegraph.com/blog/sourcegraph-3.9
https://about.sourcegraph.com/blog/writing-an-lsif-indexer
https://about.sourcegraph.com/blog/sourcegraph-3.8
https://about.sourcegraph.com/blog/code-intelligence-with-lsif
https://docs.sourcegraph.com/user/code_intelligence/lsif
https://github.com/sourcegraph/lsif-go
https://www.youtube.com/watch?v=fMIRKRj_A88
https://youtu.be/fMIRKRj_A88?t=218
https://github.com/microsoft/lsif-node/tree/master/tsc
lsif-protocol: Protocol defined as TypeScript interfaces
lsif-util: Utility tools for LSIF development
lsif-tsc: LSIF indexer for TypeScript
lsif-npm: Linker for NPM monikers
cueckoo commentedon Jul 3, 2021
Original reply by @galli-leo in cuelang/cue#142 (comment)
Hi,
I semi-hacked together a working implementation (using
promqlas a base) over the past two days. You can see it running in action invscodebelow :). Currently, I have the following working:cue vet(There might be one or two crashes though 😅 )
Should I fork this project and add what I have up until know, then open a PR?
Or should I just commit it to a personal repo, that's separate?
Some thoughts I had during my implementation, most of these are probably my fault for not being familiar with the codebase though 😛 :
It is very annoying that compilation fails immediately, if there is any error (or maybe I haven't found the correct options yet?). At the moment I need to keep the lastSeems to be possible by usingInstanceof a document around, otherwise I only have the AST.build.Instanceinstead. However, if a top level identifier is unknown,inst.Value()will still return nothing, so would need to access some internal stuff.Instanceis very annoying. I wrote my ownCursorfor the AST, but nothing yet forInstance.Valueis even more annoying, that code is very messy and should probably be reworked. Currently, I iterate through allValues in theInstanceand check ifval.Source() == node(nodeis anast.Node).Valuecorresponding to a field definition, which made some stuff a lot harder.ast.Identwhen used e.g.a: b(i.e. one is field definition label, the other field definition type?). Ideally, there was a way to know which one is which, since certain stuff (like auto complete or hover), have different info based on that (at least the way I implemented it at the moment).Lastly, I wanted to say, that I really love this project! I think it's really cool and we plan on using it in our new infrastructure for all config management (hence why I decided to spend some time implementing this :)).
187 remaining items
cuepls: first integration test
cuepls: remove more server implementation
cuepls: support .cue filetype
cuepls: support formatting of CUE files
cuepls: implement parsecue package
cuepls: temporary top-of-stack CL
[-]x/tools: Language Server Protocol Support[/-][+]lsp: Language Server Protocol Support[/+]cuematthew commentedon Sep 3, 2025
For everyone waiting on this, there is now good progress on CUE's LSP server, and regular announcements will be added to #1776 going forwards.
mvdan commentedon Dec 6, 2025
With
cue lspshipping in v0.15.0 with many features, I believe we can close this as resolved now; we will continue to post updates and announcements relating to the LSP via #1776 and the#lspchannels on Discord and Slack :)Please send your thanks to @cuematthew, who has done the majority of the work in the LSP!