Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guidance to writing LSP Client

I have a personal Editor that implements its own "protocol" for Code completion and would like to switch to Language server protocol to relieve myself from some development burden. However I have not been able to fully comprehend the LSP Documentation concerning client implementation. It's mixed up with Server implementation and cannot find clear difference between the two.

Much of online documentation (including questions on SO) revolved around VSCode extensions of which I have zero knowledge and are not helpful.

I would appreciate any help to get started writing a simple client that just queries autocomplete. I write my editor in C++ and would appreciate any tutorial that explains how to create client. I can understand Python, C, C#, Pure JavaScript, C++, PHP and similar languages, so I can easily follow any tutorial in those languages.

If anything is not clear let me know so that I can explain (this being my first post in LSP :) )

like image 412
Stefano Mtangoo Avatar asked Mar 23 '19 10:03

Stefano Mtangoo


People also ask

What is LSP client?

The LSP Client plugin provides many language features such as code completion, code navigation or finding references based on the Language Server Protocol. Once you have enabled the LSP Client in the plugin page, a new page called LSP Client will appear in your Kate configuration dialog.

How do you make LSP?

Go to Tools > Options > File Locations > System > Expand section 'Support Files Search Path' , On righ side click on New tab and Browse and select folder D:\LISP Files (Move up this path) > Apply and Ok. Restart DraftSight or Open New file startup. lsp file will load automatically .

How does an LSP work?

The way this happens with LSP is: The client opens the file and sends textDocument/didOpen to the server. The server analyzes the file and sends the textDocument/publishDiagnostics notification. The client parses the results and displays error indicators in the editor.

What is LSP in VS Code?

The Language Server Protocol (LSP) is a common protocol, in the form of JSON RPC v2. 0, used to provide language service features to various code editors.


2 Answers

Mattie of course lead me to the right direction. The most difficult was for me to understand the request/response. LSP have a very helpful page on that with unfortunate name (IMHO) that had misled me , "inspection". It turns out to be a good example on request/response.

like image 121
Stefano Mtangoo Avatar answered Oct 16 '22 00:10

Stefano Mtangoo


I've successfully written a client that receives completion results from a server. Here's (approximately) what it does:

  • send an initialize
  • send an initialized notification
  • send a textDocument/didOpen

At this point, your server should be ready to answer the textDocument/completion request. Depending on the response, you may also need to use completionItem/resolve as well. To date, I've never needed this for the servers I've used, however.

Good luck!

like image 38
Mattie Avatar answered Oct 16 '22 02:10

Mattie