Early preview of my NPP LSP plugin.
-
I mentioned in the other thread that I was also working on a Language Server Protocol plugin for Notepad++. I’m now ready to share a very early preview of it. If you’d like to try it out, you can download it here. Note that this is a debug build, so it not only contains all of the logging that I have been using for development, but will also open a console for the server to log into. As such it’s not the most pleasant plugin to use at the moment, it is very much meant just for testing the functionality.
The only methods implemented so far are textDocument/publishDiagnostics and textDocument/completion. I have implemented most of the optional features for these, all the ones that seemed like they could reasonably be implemented in Notepad++. I am somewhat suspicious of bugs in the completion implementation, as it is a mess of concurrent code.
Options are configured using a JSON file called “Notepad++ LSP.json” in your plugin configs directory, by default that is “<User>\AppData\Roaming\Notepad++\plugins\config”. You will need to edit this to add the LSP server that you wish to use. I have provided an example options file here, which should illustrate the structure.
My next task is to do a lot of refactoring, as the code has become a bit of a mess lately. After that I will continue adding more methods. I think most of them will be much easier than completion was. At some point I would also like to add more options (for example, to turn on and off features, and to configure the appearance of diagnostics), as well as create an options UI.
Contributions are welcome if anyone is up to the challenge.
-
-
Sorry to abuse your thread, but have you ever encountered a situation where the lsp client and a language server were responsible for Npp “hanging”?
That is, after I stopped the language server, Npp responded as usual.
I thought the idea of a client-server mechanism was to, ensure that the app hosting the client doesn’t hang if the server goes crazy.
Any idea what could have caused this? Haven’t found a way to reproduce this yet, unfortunately.
My client writes to the server stdin on the main plugin thread but reads from the server stdout on another thread. -
@ekopalypse I haven’t looked at your code, but I can think of two possibilities: Perhaps you are waiting on a response from the server that never arrives, or it could be a deadlock between your threads.
The client-server model does provide separation between NPP and the server, but it is up to the client (in other words, us) to implement the communication with the server. If the pipe (stdin/stdout) closes unexpectedly, you need to make sure that your code doesn’t hang. And if you’re using multiple threads, you need to make sure there are no potential deadlocks between the threads.
In my plugin I use three separate threads: One thread sends on stdout. One thread is receives from stdin. One thread is used to callback to the client for notifications and responses. These threads communicate using channels (essentially a thread safe queue). When a user thread sends a request, that request is put into a channel, it is picked up by the send thread and written to stdout. When a response or notification arrives from on stdin, it is put into a different channel, and is picked up by the callback thread. This ensures that send and receive are never blocked, and that callbacks do not block the main thread.
When the client shuts down all three threads are closed. A shutdown could be triggered by the client, or by the server (such as if the server crashes), and it could originate from any of the threads. If the shutdown comes from the client, we want to notify the server first and wait for a response, but if the shutdown comes from the server we can’t notify or wait for a response. If there are any pending callbacks they receive a cancellation exception. So all of this has to be done carefully to ensure no deadlocks.
-
Thank you so much for taking the time to answer my question, I really appreciate it.
I think I’m starting to understand where my problem is.
I’ll dig through the code and see if I understand what I’m missing in my implementation. -
Hi @Derek-Brown, first of all, I wish you success with integrating the now essential LSP capabilities into Notepad++ through your plugin (my wishes also go to @Ekopalypse).
I would like to ask if there is a 32-bit version of your plugin available for testing? Unfortunately, my Notepad++ version is 32 bit, and I would be very happy to help with some testing.
-
@pidgeon777 Yes, my plugin can be built in both 32-bit and 64-bit. I will warn though that the 32-bit build is completely untested. But I have uploaded it here, so please check it out.
-
-
To Derek-Brown: I’m not sure if this is the right place for this, but I’m experiencing a weird bug. I set the plugin to work with Python, using the .json you provided and the Jedi python server. The plugin correctly points my python code mistakes by showing a small annotation popup. That function is working fine. The problem is: if I type any LETTER in my code, npp crashes (when typing special characters or numbers it doesn’t crash. It only happens when I type letters). Maybe it has something to do with the fact that I live in Brazil and my keyboard uses a different layout?
By the way, I’m using the latest version of notepad++ (v8.6 x64) and I just downloaded the plugin .DLL (x64) from the sourceforge link you provided (so I believe it’s the latest version for the plugin as well). Running it all on Windows 10 x64.