cue icon indicating copy to clipboard operation
cue copied to clipboard

lsp announcements

Open myitcv opened this issue 3 years ago • 2 comments

Placeholder issue for cuepls announcements

myitcv avatar Jun 28 '22 05:06 myitcv

Hello! Since April this year, I've been working pretty much full-time on CUE's LSP server implementation. A lot of time has been spent building the foundations, but over the last month that has started to pay off and a few useful features are now implemented.

Right now, CUE's LSP server supports:

  1. jump to definition. This works for both usages and field-declarations. For example:
x: y: a.b
a: b: 5
a: b: 6

If you place your cursor on the a in line 1, then jump to dfn will take you to the a: declarations on lines 2 and 3. If you place your cursor on the b in line 1, then jump to dfn will take you to the b: declarations on lines 2 and 3.

If you place you cursor on either the a: or b: declarations on lines 2 and 3, then jump to dfn will take you to both of the appropriate declarations.

Jump to dfn will happily follow imports, and will even take you into downloaded CUE modules within your CUE_CACHE_DIR.

  1. completions. This builds on jump to definition. It works both for suggestion field names, e.g.:
#Schema: {
	foo?: #Foo
}

#Foo: {
	bar?: int
}

something: #Schema
something: {
	foo: {
		b| // If your cursor is here, "bar" will be suggested
	}
}

and also field values / embedded values, e.g.:

givenname: "Matthew"
surname: "Sackman"
fullname: givenname + sur| // If your cursor is here, "surname" will be suggested
  1. formatting. The LSP server supports formatting, so you can configure your editor to "format on save" and that should all work just fine.

There are some restrictions though, of which the biggest is that currently, the LSP server only supports CUE files that have a package declaration and exist within a module. So "standalone" CUE files are currently not supported at all. This will change in time - hopefully within the next month. None of these features have made it yet to a release, but they are all on our master branch and so from the next alpha-release onwards, these features should start making it out to main releases. CUE's LSP server is known to work with at least vscode, emacs, neovim. It's a normal LSP server. If you're configuring your own editor, the command you want is cue lsp serve.

I'll make announcements here as more features are implemented. As usual, we're also on slack and discord, and there are LSP channels on both where you can find me. Any problems, crashes, bugs you find, please do file issues on github.

cuematthew avatar Sep 03 '25 12:09 cuematthew

Nearly two months have passed since my last update here and a couple of big new features have arrived in the LSP. These new features are currently on our master branch and will slowly make their way out to full releases of cue in the normal way.

  1. Support for "standalone" files. A major caveat of the initial work on the jump-to-definition and completions features was that they did not work for "standalone" files. A "standalone" file is any cue file where:
    • The cue file has no valid package declaration; or
    • No cue.mod/module.cue file could be found in any of the cue file's ancestor directories; or
    • The cue.mod/module.cue file is invalid.

This restriction has now been lifted and all features of the LSP now work on standalone files. One remaining wrinkle is that standalone files which are within a valid module but have no package declaration do not get their import declarations processed by the LSP. This limitation will be addressed soon.

  1. Find-references. The LSP now supports find-references functionality. This is most easily thought of as the opposite of jump-to-definition: it will attempt to find usages of thing under the cursor. This is much more open-ended though: exactly what is the search space? Which extra packages do you load in order to try and give as complete an answer as possible? This feature does build on the same code base as jump-to-definition (and completions) so it has the same limitations (such not attempting pattern matching, not attempting to understand dynamic fields, very limited support for dynamic indexing).

As usual, we're also on slack and discord, and there are LSP channels on both where you can find me. Any problems, crashes, bugs you find, please do reach out to us and file issues on github.

cuematthew avatar Oct 23 '25 13:10 cuematthew