Zig: Implement language server protocol

Created on 16 Nov 2017  Â·  18Comments  Â·  Source: ziglang/zig

enhancement stage2

Most helpful comment

If anyone is still actively looking for a language server, I'm one of the maintainers of zls, an almost full featured language server for Zig! It has local, global, and package completions and tons of other features such as goto, hover definitions, and document outlines coming soon.

You can check it out here.

All 18 comments

Does it make sense to tie this to the self-hosting Issue (https://github.com/zig-lang/zig/issues/89), or do you think separate pieces of the functionality required for LSP should be delegated into a pipeline of (caching?) components which perhaps the core compiler functionality would also rely on?

My plan is to solve this only in the self-hosted compiler.

I'd be interested in investigating the differences between the LSP and what the Dart analyzer (API spec) provides, as JetBrains is actually able to use Dart's analyzer to fully power their Dart support due to the different features provided. Additionally, it looks like you can shim Dart's Analysis Server API to provide the Language Server Protocol without too much trouble.

I know @thejoshwolfe has some bones to pick with the language server protocol in particular. I think in the end we will likely support a custom protocol that is more powerful than LSP, and theoretically you could implement a proxy that consumes the former and provides the latter. Perhaps zig can support both.

I know @thejoshwolfe has some bones to pick with the language server protocol in particular.

No matter what, this will make working with zig so much easier 🥇

  1. editor completion support but also the whole ecosystem

one more example:
really nice code navigation https://about.sourcegraph.com/blog/sourcegraph-is-now-open-source/

This isn't contributor friendly yet. Lots to solve before work on this begins.

I found this https://github.com/ice1000/intellij-zig
It looks promising

@andrewrk is this your idea?: to have a language server implemented as a function in the std lib, so can be called from the build script. and then spawn the process with 'zig run-lsp ...args'. I think some basic methods can be implemented from the LSP spec with what zig have right now.

You pinged the wrong account.

On Fri., 5 Jul. 2019, 12:54 pm Patricio Villalobos, <
[email protected]> wrote:

@andrewk https://github.com/andrewk is this your idea?: to have a
language server implemented as a function in the std lib, so can be called
from the build script. and then spawn the process with 'zig run-lsp
...args'. I think some basic methods can be implemented from the LSP spec
with what zig have right now.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/ziglang/zig/issues/615?email_source=notifications&email_token=AAAJIOXUZCHXUKAXEWGFXX3P52ZVDA5CNFSM4EECL752YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZINCKI#issuecomment-508612905,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAJIOWFIP67ELBFBJRWQVDP52ZVDANCNFSM4EECL75Q
.

I found this https://github.com/ice1000/intellij-zig
It looks promising

Maybe not, hasn't been updated for a while

why?

Because I'm busy. As an alpha-stage language, Zig is changing its syntax from time to time, while the IntelliJ plugin parsers zig code using its own parser (created by me).

I haven't implemented complicated reference resolution, thus you cannot have cross-file jumps and type inference. Zig is really unfriendly for IDE due to the C-interop hacks (you can use C references, which requires your IDE to understand C. For a language server, you also need to provide C source information, while you have LLVM in the Zig compiler to make things easier).

Please be aware that for best results the language parser should be error tolerant.
https://code.visualstudio.com/api/language-extensions/language-server-extension-guide#error-tolerant-parser-for-language-server

Currently the JSON dumps @andrewrk suggested to use in #3429 are not generated in case of a compilation error.
I do not know the compiler internals, how feasible is error tolerance when generating the JSON dump in stage1 and stage2 compiler?

Also, I presume the JSON format isn't planned to drastically change in the self-hosted compiler, is that correct?
I would be happy to start writing the language server.
In what directory in the repo should the server code be placed?

You can don't have an error-tolerant parser.
You can do: obtain AST each time when the code is well-formed, listen to programmer typing dots or explicitly invoke completion, and use the AST you obtained just now to provide completion.

Although this is definitely less good than error-tolerant parser (which is available in the unmaintained intellij-zig).

Correct. I just wanted make sure that new code is written to allow for error tolerance if possible.

I am currently implementing JSON-RPC.

If anyone is still actively looking for a language server, I'm one of the maintainers of zls, an almost full featured language server for Zig! It has local, global, and package completions and tons of other features such as goto, hover definitions, and document outlines coming soon.

You can check it out here.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrewrk picture andrewrk  Â·  3Comments

jayschwa picture jayschwa  Â·  3Comments

daurnimator picture daurnimator  Â·  3Comments

bheads picture bheads  Â·  3Comments

andersfr picture andersfr  Â·  3Comments