-
Notifications
You must be signed in to change notification settings - Fork 294
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
x/tools: Language Server Protocol Support #142
Comments
Original reply by @rudolph9 in cuelang/cue#142 (comment) Somewhat related, looks like someone made a vim plugin https://github.com/jjo/vim-cue |
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. |
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? |
Original reply by @mxey in cuelang/cue#142 (comment)
basically, I'd like the same editing experience for Kubernetes objects in CUE as you can get for YAML in VS Code |
Original reply by @mpvl in cuelang/cue#142 (comment)
|
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 🤔 |
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) If we develop lsp for CUE written in Go, it might be helpful that package. |
Original reply by @myitcv in cuelang/cue#142 (comment) We can likely reuse some of the work in 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 |
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 :) |
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 Then the only thing left to do is implementing the Feel free to reach out if you have any questions. |
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://github.com/microsoft/lsif-node/blob/master/README.md vscode extension (to serve LSP from the file) https://about.sourcegraph.com/blog/sourcegraph-3.9 https://docs.sourcegraph.com/user/code_intelligence/lsif go get -u github.com/sourcegraph/lsif-go/cmd/lsif-go https://github.com/sourcegraph/lsif-go https://github.com/microsoft/lsif-node/tree/master/tsc lsif-protocol: Protocol defined as TypeScript interfaces |
Original reply by @galli-leo in cuelang/cue#142 (comment) Hi, I semi-hacked together a working implementation (using
(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? Some thoughts I had during my implementation, most of these are probably my fault for not being familiar with the codebase though 😛 :
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 :)). |
Original reply by @verdverm in cuelang/cue#142 (comment) @galli-leo this is awesome! Have you signed the Google CLA? If not, we can get you a link to the instructions Cue accepts PRs from here or Gerrit, with some preference for Gerrit as it is the actual source of truth for the code. Gerrit uses a slightly different commit methodology which is pretty cool to experience if you are up for it. Depending on which method you prefer, we'll follow up with more details. Are you aware the syntax is changing slightly? In particular, I see your example (really cool by the way) has the old style definitions with There are some other changes that may impact the lang-server implementation, and hopefully they will only make it easier. As a general FYI, Cue is going through some bigger changes right now on its way to stability later this year. Have you joined the slack group? (link to join is here: https://cuelang.org/community) |
Original reply by @galli-leo in cuelang/cue#142 (comment)
Yep signed it already.
I prefer Github, since I don't have experience with gerrit. But I am also fine with using gerrit, if that makes it easier for you :)
I am now ;) To be honest, I delved into this without having familiarized myself 100%!((MISSING)probably not even 80%!:(MISSING)P) with the language spec (in hindsight maybe not the best idea).
I saw the issues regarding that. Is there a central document detailing those changes?
Yep! Will ask further questions there. |
Original reply by @buremba in cuelang/cue#142 (comment) @galli-leo looks great! Any plans to open-source the LSP? |
Original reply by @myitcv in cuelang/cue#142 (comment) LSP is close to the top of the list to be worked on in the near future... so this will get some attention soon. |
Original reply by @alex-de-oliveira in cuelang/cue#142 (comment) This would be absolutely invaluable |
Original reply by @uhthomas in cuelang/cue#142 (comment) I haven't seen any mention of Sublime Text 4 yet, so I'll share some quick thoughts. Sublime Text 4 has a generic LSP implementation which works pretty well. I've been using it in conjunction with gopls for about a year now and both have improved significantly in that time. It's an exciting prospect to have a similar LSP for CUE. |
Original reply by @eadlam in cuelang/cue#142 (comment) @myitcv I'm interested in helping with the LSP |
Original reply by @myitcv in cuelang/cue#142 (comment) I am now starting work on a first cut of This first cut of Once we have the right "structure" in place ( I will now tag all LSP-related issues with That said, any contribution will of course be greatly appreciated! Because when we have an initial implementation of |
Original reply by @samschlegel in cuelang/cue#142 (comment) Also interested with helping with this as this is the main thing blocking our adoption of CUE, and I really want to adopt it 😄 |
Original reply by @eadlam in cuelang/cue#142 (comment) This is also the main thing blocking CUE adoption at my org. |
Original reply by @leoluk in cuelang/cue#142 (comment) Note that while there's no LSP yet, there are a number of language/syntax plugins for various editors: ...and probably more. That might be good enough to unblock adoption while waiting for full autocompletion :) The IntellIj one in particular is commercially supported by us and has a full parser/lexer and will highlight syntax errors. |
Original reply by @myitcv in cuelang/cue#142 (comment) Thanks for everyone's patience here. This is in progress; we very much understand the importance of good editor support for the success of CUE. |
Original reply by @samschlegel in cuelang/cue#142 (comment) Let me know if there's any way I could help!
Yeah I've been using those for some things I've been trying out, but in order to kick off replacing all of our Jsonnet we're going to need things like go to definition, type information, and autocomplete for both VSCode and IntelliJ |
Basic integration test to ensure that everything is plumbed together. Notice how this integration test actually opens a Go file. We haven't at this stage made changes to cuepls (formerly gopls) to know about CUE files. That follows in a later CL. This integration test confirms that we have a working end-to-end setup. Which then allows for more aggressive tidy up to take place. For now we do not run the integration test on Windows because it doesn't work. That is covered by https://cuelang.org/issue/2752. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: I036c4a344dd1b1d339cf744db029c60789e547cb
Now that we have an integration test in place we can more easily remove server implementation and see that it doesn't break things. Of major note, the cache package still needs a major trim down. But that is one of many changes that can follow in a later CL. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: If512615401bb099274d9481ca862288cf62b0a53
The initial skeleton of cuepls is based on gopls. Which means that there is already support for .go, go.mod, and go.work files. This CL adds support for .cue files alongside the existing file types. More vestiges of Go (gopls) code will be removed in later CLs. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: Ia5028fbf7e27b3d48c9865ec803e3f73f0278f34
Add support for the formatting of CUE files. While we are here, create a cuelang package alongside the existing golang package. Lots more formatting required in later CLs, but again this is a good bootstrap. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: I13ab83c1251714182e69d06bb53ed08f94bac709
WIP DO NOT REVIEW DO NOT SUBMIT For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: Iaa3e7beedecd7d5d7cbf5337e70020556556d45a
DO NOT REVIEW DO NOT SUBMIT For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: I9d055b11422654c9a753f807af618f275bf4bc55
As mentioned in previous CL commit messages, we are maintaining cmd/cuepls as a separate entry point for now largely because of the complications in adapting the flag handling between the flag-based approach of gopls (cuepls) and the cobra-based approach of cmd/cue. We will fix/unify those approaches in a later CL, but for now we are in the mindset of making minimal changes to get a working cuepls. This commit creates the cmd/cuepls entrypoint. An integration test follows in a later CL. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: I533b875155f4d2da999ff1c1ef20d32eea3c4ff4
Various temp files/directories etc contain the name "gopls". Rename a number of those that we have encountered at this point to "cuepls". Much more tidy up and renaming will following in later CLs. Again, the focus is on minimal changes to get a working cuepls. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: I1c10236b5e8b012030b405307aa870637a93e83d
Basic integration test to ensure that everything is plumbed together. Notice how this integration test actually opens a Go file. We haven't at this stage made changes to cuepls (formerly gopls) to know about CUE files. That follows in a later CL. This integration test confirms that we have a working end-to-end setup. Which then allows for more aggressive tidy up to take place. For now we do not run the integration test on Windows because it doesn't work. That is covered by https://cuelang.org/issue/2752. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: I036c4a344dd1b1d339cf744db029c60789e547cb
Now that we have an integration test in place we can more easily remove server implementation and see that it doesn't break things. Of major note, the cache package still needs a major trim down. But that is one of many changes that can follow in a later CL. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: If512615401bb099274d9481ca862288cf62b0a53
The initial skeleton of cuepls is based on gopls. Which means that there is already support for .go, go.mod, and go.work files. This CL adds support for .cue files alongside the existing file types. More vestiges of Go (gopls) code will be removed in later CLs. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: Ia5028fbf7e27b3d48c9865ec803e3f73f0278f34
Add support for the formatting of CUE files. While we are here, create a cuelang package alongside the existing golang package. Lots more formatting required in later CLs, but again this is a good bootstrap. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: I13ab83c1251714182e69d06bb53ed08f94bac709
WIP DO NOT REVIEW DO NOT SUBMIT For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: Iaa3e7beedecd7d5d7cbf5337e70020556556d45a
DO NOT REVIEW DO NOT SUBMIT For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: I9d055b11422654c9a753f807af618f275bf4bc55
Our approach for creating an initial version of cuepls (named after gopls) is to start with the gopls implementation, then cut it down, refactor rename. This approach (that found in this stack of changes) is the third such iteration. The first also started with a working gopls server, but cut it down and refactored things in a more drastic way. This ultimately caused us to get bogged down in too much aggressive refactoring early on. The second attempt started from a blank page, with "as-required" copying and adapting of existing gopls code to build out a new LSP server bit by bit. This meant the "time to a working server" was significantly longer. This approach again starts with a verbatim copy of gopls but using "vendored" code from golang.org/x/... This CL prepares for that "vendor" to define a script that will help with the vendoring. This script will be used to vendor parts of golang.org/x/..., after which we will cut things down by hand. This is a very basic hard-coded script for now. It might be that we only use it once. The goal for now is not reuse, just getting the job done. It's also unclear whether we will ever re-run the script. Again, the focus is on the initial import, not later reuse. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: Ibdd55f25a66772e06fcab65a8678950e40d81857 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1174163 Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> TryBot-Result: CUEcueckoo <cueckoo@gmail.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
This "vendors" parts of golang.org/x/... internally within the CUE code base. This creates some duplicate packages which we will later tidy up. The focus for now is on making minimal changes to the gopls code-based to create a cuepls equivalent, working end-to-end with integration tests. Refactoring, deduplication etc can follow later. Note that the dependencies added by go mod tidy tidy all get removed in https://cuelang.org/cl/1174165, which removes the (third party) hooks, and later CLs which cut down the server implementation. For #142 [git-generate] ./internal/golangorgx/revendorToolsInternal.sh Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: I78baa78259a903f08c9fc8296173cc9b5fe44bea Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1174164 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: CUEcueckoo <cueckoo@gmail.com> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
For now we do not need a hooks package for loading third-party aspects of cuepls. These can follow later, and removing these now makes the "vendoring" of gopls (as cuepls) a ~zero dependency thing. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: Ic64db387e9670c3fab4105f7c013b4ffaf4764c2 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1174165 TryBot-Result: CUEcueckoo <cueckoo@gmail.com> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
As part of "vendoring" the golang.org/x/tools/... packages (including the gopls module) we also "vendored" a dependency on golang.org/x/telemetry. The goal is to (at some point in a later commit) enable telemetry on an opt-in basis. For now, make minimal changes to ensure that we do not use Go configuration/endpoints for telemetry, even though there is no way to turn it on right now. That will follow in a later CL. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: I775de9799ad9f5c996a1d4bfb2d04bac25c44d13 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1174166 TryBot-Result: CUEcueckoo <cueckoo@gmail.com> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
CUE does not (yet) have the concept of a vulnerability server. It might never have one, but with the presence of Wasm artefacts in modules it might. For now we don't need a mention of vulnerability in our code so we should remove it. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: I6d5864debdbd3765e87f8e91ebadf5fba9faf178 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1174167 TryBot-Result: CUEcueckoo <cueckoo@gmail.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
For now we are maintaining cmd/cuepls as a separate binary from cmd/cue. In later changes we might merge the former into the latter to create a single entry point for doing all things CUE. Doing so will require quite a lot of open heart surgery on cmd/cuepls, to adapt/move away from the existing flag-based approach to commands and subcommands. cmd/cue (as a reminder) uses cobra, and the two are not compatible at least as far as UX is concerned. It also complicates code/flag handling. In order to create a minimal working end-to-end cuepls command with integration tests, we only need a serve command for now. Therefore remove all other commands to limit the surface area of cmd/cuepls exposed. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: Ic6e6d933a12d43a1fee69a7505eaaf23870a453f Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1174169 Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> TryBot-Result: CUEcueckoo <cueckoo@gmail.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
As mentioned in previous CL commit messages, we are maintaining cmd/cuepls as a separate entry point for now largely because of the complications in adapting the flag handling between the flag-based approach of gopls (cuepls) and the cobra-based approach of cmd/cue. We will fix/unify those approaches in a later CL, but for now we are in the mindset of making minimal changes to get a working cuepls. This commit creates the cmd/cuepls entrypoint. An integration test follows in a later CL. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: I533b875155f4d2da999ff1c1ef20d32eea3c4ff4 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1174170 Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: CUEcueckoo <cueckoo@gmail.com>
Various temp files/directories etc contain the name "gopls". Rename a number of those that we have encountered at this point to "cuepls". Much more tidy up and renaming will following in later CLs. Again, the focus is on minimal changes to get a working cuepls. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: I1c10236b5e8b012030b405307aa870637a93e83d Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1174171 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> TryBot-Result: CUEcueckoo <cueckoo@gmail.com>
Basic integration test to ensure that everything is plumbed together. Notice how this integration test actually opens a Go file. We haven't at this stage made changes to cuepls (formerly gopls) to know about CUE files. That follows in a later CL. This integration test confirms that we have a working end-to-end setup. Which then allows for more aggressive tidy up to take place. For now we do not run the integration test on Windows because it doesn't work. That is covered by https://cuelang.org/issue/2752. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: I036c4a344dd1b1d339cf744db029c60789e547cb Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1174172 TryBot-Result: CUEcueckoo <cueckoo@gmail.com> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Now that we have an integration test in place we can more easily remove server implementation and see that it doesn't break things. Of major note, the cache package still needs a major trim down. But that is one of many changes that can follow in a later CL. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: If512615401bb099274d9481ca862288cf62b0a53 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1174173 TryBot-Result: CUEcueckoo <cueckoo@gmail.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
The initial skeleton of cuepls is based on gopls. Which means that there is already support for .go, go.mod, and go.work files. This CL adds support for .cue files alongside the existing file types. More vestiges of Go (gopls) code will be removed in later CLs. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: Ia5028fbf7e27b3d48c9865ec803e3f73f0278f34 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1174176 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> TryBot-Result: CUEcueckoo <cueckoo@gmail.com>
Add support for the formatting of CUE files. While we are here, create a cuelang package alongside the existing golang package. Lots more formatting required in later CLs, but again this is a good bootstrap. For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: I13ab83c1251714182e69d06bb53ed08f94bac709 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1174174 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: CUEcueckoo <cueckoo@gmail.com> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
WIP DO NOT REVIEW DO NOT SUBMIT For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: Iaa3e7beedecd7d5d7cbf5337e70020556556d45a
DO NOT REVIEW DO NOT SUBMIT For #142 Signed-off-by: Paul Jolly <paul@myitcv.io> Change-Id: I9d055b11422654c9a753f807af618f275bf4bc55
Originally opened by @rudolph9 in cuelang/cue#142
Here is an example of a YAML file LSP https://github.com/redhat-developer/yaml-language-server
I've never created one so I can't say for certian how much work it would be but it would be great for integrations in to vim, emacs, VSCode, etc.
https://langserver.org/
The text was updated successfully, but these errors were encountered: