Community
    • Login

    New (incomplete) LSP client plugin

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    59 Posts 8 Posters 8.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Mark OlsonM
      Mark Olson
      last edited by

      It took some fiddling, but I got it to work and I have some preliminary thoughts (having used it with Python only):

      1. The most important failing I saw in the previous iteration was that when I tried to import a really big library like numpy, it caused Notepad++ to hang. This no longer happens. Great job!
      2. I would greatly prefer for syntax errors (e.g., referencing a variable not previously defined) to display over all formatting issues. If there is a way to configure this (including possibly disabling all formatting warnings), I would appreciate if the config file was more explicit about it.
      3. I think the default warning_color should be a fair amount darker, because the yellow is pretty hard to see on the white background of the default stylers.xml.
      Michael VincentM 1 Reply Last reply Reply Quote 1
      • rdipardoR
        rdipardo
        last edited by rdipardo

        I was going to ask why the DLL’s export table includes DllMain:

        $ readpe --exports NppLspClient.dll
        Exported functions
          Library
            Name:           NppLspClient.dll
            Functions
                Function
                    Ordinal:  1
                    Address:  0x7e10
                    Name:     DllMain
                Function
                    Ordinal:  2
                    Address:  0x3020
                    Name:     beNotified
                [ . . . ]
        

        I suppose it’s because Rust’s #[no_mangle] attribute implicitly exports whatever symbol it qualifies? https://github.com/rust-lang/rust/issues/67399

        The older V binaries export DllMain as well, so probably nothing to worry about.

        1 Reply Last reply Reply Quote 1
        • EkopalypseE
          Ekopalypse
          last edited by

          Thanks for testing and the nice comments.

          @Mark-Olson
          Doh, error_color and warning_color will be configurable again in the next version, sorry.
          Regarding the sorting of diagnostic messages, within a source file this is easily possible,
          but as far as sorting across files is concerned, as can be seen in the attached screenshot,
          it looks more difficult. The plugin cannot know in advance whether there will still be messages,
          which have a higher urgency than those already received, which means
          that sorting would have to take place after every message received …
          hmm … let’s see how this can be managed efficiently.

          4a9be5d3-e7f8-4a8f-9452-8738c717b85e-image.png

          @rdipardo
          Haha … I hadn’t even realized that yet. Yes, with V it was only possible to build a plugin
          if DllMain was also exported … it took me some time to find that out.
          I think this is also the case in C if you create a DLL with gcc today.
          If my memories don’t deceive me, I stumbled across a gcc thread back then that discussed this.

          1 Reply Last reply Reply Quote 4
          • EkopalypseE
            Ekopalypse
            last edited by Ekopalypse

            Version v.0.0.15-alpha published.

            Changes:

            • Error and warning colors are configurable again
            • Within a file, diagnostics are ordered by severity

            New:

            • Goto declaration/implementation/definition support
            • Hover support (see screenshot below)

            dfcbe5c2-c9a0-43a6-a0a8-f3ee674319fd-image.png

            1 Reply Last reply Reply Quote 2
            • Michael VincentM
              Michael Vincent @Mark Olson
              last edited by

              @Mark-Olson said in New (incomplete and x64 only) LSP client plugin:

              having used it with Python only

              Well done - can you please share the config file you used to get the Python LSP working?

              Cheers.

              Mark OlsonM 1 Reply Last reply Reply Quote 0
              • Mark OlsonM
                Mark Olson @Michael Vincent
                last edited by

                @Michael-Vincent

                [lspservers.python]
                mode = "io"
                executable = 'C:\path\to\Python311\Scripts\pylsp.exe'
                args = '--check-parent-process --log-file %AppData%\\Roaming\\Notepad++\\plugins\\config\\NppLspClient\\pylsp.log'
                auto_start_server = false
                

                It definitely does not work reliably without using Folder as Workspace. If you use Folder as Workspace, it’s definitely more reliable.

                Michael VincentM 1 Reply Last reply Reply Quote 0
                • Michael VincentM
                  Michael Vincent @Mark Olson
                  last edited by

                  @Mark-Olson said in New (incomplete and x64 only) LSP client plugin:

                  It definitely does not work reliably without using Folder as Workspace. If you use Folder as Workspace, it’s definitely more reliable.

                  Reply

                  Ahh, I have that exact config (with my paths of course) and it’s not doing anything. I never use Folder as Workspace though, wonder if that’s my issue? I’ll try …

                  Cheers.

                  EkopalypseE 1 Reply Last reply Reply Quote 0
                  • EkopalypseE
                    Ekopalypse @Michael Vincent
                    last edited by Ekopalypse

                    @Michael-Vincent
                    Yes, currently FAW must be used, and the logic is as follows

                    If the current file starts with a root path, then send the root path to the language server, otherwise do nothing.

                    The next version will use the current directory of the current file instead of doing nothing.

                    @Mark-Olson - what do you mean by “more reliable”?

                    Have you encountered a situation where it didn’t work with FAW? Reproducible?

                    Personally, I don’t like using the FAW dialog as it introduces some difficulties and even performance issues. But I didn’t want to create another “explorer-like” dialog either. But that would have its advantages, one could create a TreeList, then it could be used to see which files contain errors. Hmm … maybe I should go that way anyway … I’m still undecided.

                    Does anyone have any other ideas?

                    Mark OlsonM Michael VincentM 2 Replies Last reply Reply Quote 0
                    • Mark OlsonM
                      Mark Olson @Ekopalypse
                      last edited by

                      @Ekopalypse said in New (incomplete and x64 only) LSP client plugin:

                      Have you encountered a situation where it didn’t work with FAW? Reproducible?

                      Reproducible? I doubt it. I think what probably happened is that I opened of FAW, then closed it, then opened up a file.

                      I keep a lot of one-off scripts in my Python directory (the same directory as the executable) because it’s convenient to do so (can run python -m whatever from anywhere), but of course that’s a terrible place to open FAW because the Lib/site-packages subdirectory can have tens of thousands of files.

                      1 Reply Last reply Reply Quote 1
                      • Michael VincentM
                        Michael Vincent @Ekopalypse
                        last edited by

                        @Ekopalypse said in New (incomplete and x64 only) LSP client plugin:

                        The next version will use the current directory of the current file instead of doing nothing.

                        Sounds good. I did get it working with FAW - and that makes sense why.

                        One thing to think about and not seeing the code I’m just assuming based on the previous V version, you should just do autocompletes. Don’t bother checking if one is active. Maybe it’s my personal preference, but if I’m using a Language Server, I want those completions to be foremost presented, and then if that can’t find any, the “default” Notepad++ ones would show up based on the language or current text in the doc - depending on how it’s configured.

                        I see currently, you check:

                        https://github.com/Ekopalypse/NppLspClient/blob/6d8c054c733a5fa080a2f337b35bc794431fbb68/NppLsp.v#L288

                        I don’t bother with any of the autocomplete plugin stuff I do - I just present it and Scintilla autocomplete is “smart enough” that when there is no match, the autocomplete window no longer shows - freeing up Notepad++ default autocomplete (if configured) to do it’s thing through Scintilla.

                        I hope this is making sense. I just noticed when I was typing, I was getting all the Notepad++ autoComplete XML stuff and local doc stuff showing until there were no more options that matched, and then the Language Server started showing me its suggestions - which is what I wanted to see first.

                        Cheers.

                        EkopalypseE 1 Reply Last reply Reply Quote 0
                        • EkopalypseE
                          Ekopalypse @Michael Vincent
                          last edited by

                          @Michael-Vincent said in New (incomplete and x64 only) LSP client plugin:

                          which is what I wanted to see first.

                          … yeah, and I thought, what’s he talking about, I always get the completions from the language server first … and then ahh - because I disabled Npp’s autocomplete - - another doh moment :-D

                          v.0.0.16 puplished

                          Changes:

                          • The root directory is set to the current file directory if it cannot be found in the root directories of the workspace…

                          New:

                          • Format document support

                          Note that symbols and reference dialogs are not usable at the moment - I haven’t bothered to disable these functions.

                          Michael VincentM 1 Reply Last reply Reply Quote 1
                          • EkopalypseE
                            Ekopalypse
                            last edited by Ekopalypse

                            v.0.0.17 has been released and has thus reached the functional scope of the former Vlang version.

                            New:

                            • Support for symbols and references
                            • Provision of a help function for reloading the current file

                            8da952b0-04f3-4a2e-ace7-2d30abfd3924-image.png

                            1 Reply Last reply Reply Quote 1
                            • Michael VincentM
                              Michael Vincent @Ekopalypse
                              last edited by

                              @Ekopalypse said in New (incomplete and x64 only) LSP client plugin:

                              ahh - because I disabled Npp’s autocomplete

                              Not really an option for me. I use languages that I won’t have language servers for and I want autocomplete to work for them too. Turning it on and off would also be a pain.

                              Could there be a setting to skip the check?

                              Cheers.

                              EkopalypseE 1 Reply Last reply Reply Quote 1
                              • EkopalypseE
                                Ekopalypse @Michael Vincent
                                last edited by

                                @Michael-Vincent

                                Do you have any idea how to name such a flag?
                                I was thinking of a boolean value named send_completion_request_always and it should be available in both the global and lspserver sections.

                                The absence would mean `false" and has the current behavior, i.e. if a completion list is active, it will be used and not canceled.
                                If the boolean value is present in the global section, each lspserver inherits its value unless it explicitly overrides it.

                                Other ideas?

                                Michael VincentM 1 Reply Last reply Reply Quote 2
                                • Michael VincentM
                                  Michael Vincent @Ekopalypse
                                  last edited by

                                  @Ekopalypse

                                  I think that’s brilliant and flexible - to be globally and “locally” (per LS) override.

                                  Cheers.

                                  EkopalypseE 1 Reply Last reply Reply Quote 1
                                  • EkopalypseE
                                    Ekopalypse @Michael Vincent
                                    last edited by

                                    v.0.0.18 has been released

                                    @Michael-Vincent

                                    The new (experimental) flag complete_always has been introduced.

                                    b5aee544-0ad4-4f28-8df6-01e5e478cb9a-image.png

                                    To be honest, I’m not very happy with it - quite a bit of flickering. I’m still thinking about whether other solutions are possible/useful.

                                    Michael VincentM 1 Reply Last reply Reply Quote 1
                                    • Michael VincentM
                                      Michael Vincent @Ekopalypse
                                      last edited by Michael Vincent

                                      @Ekopalypse said in New (incomplete and x64 only) LSP client plugin:

                                      quite a bit of flickering

                                      Yes, that’s because every time a character is typed, autocompletion is called. The way you had it was “nicer” in that autocompletion was just called once and further typing didn’t “filter” (i.e., shorten and redisplay) the list, it just “narrowed” (i.e. moved to the closest match).

                                      This is a symptom of a rather immature autocomplete feature and the Notepad++ implementation and probably other “stuff”. Meaning, there can only be one active autocomplete list at a time, but there is no way to add to that list. So type a character and Notepad++ creates its own list based on the ‘autoComplete/LANG.xml’ file and any current words in the doc (depending on settings of course) and my QuickText plugin creates its list for the language if you match a snip and my TagLEET plugin creates a list based on all the CTags in the project and now your LSPClient creates a list, and on and on … last list wins? or maybe not?

                                      Of course, if you don’t have any of those plugins, you don’t see the issue, but it would be nice (not for you to solve) if Notepad++ / Scintilla had a sort of universal autocomplete where you don’t create the list, just submit your items to add to the list and the universal autocomplete compiles a consolidated list of all the available completions before displaying. That way, you can get the goodness of Notepad++ default fallback for non-LSP languages and the useful “other words in document” (great for typing documentation or README files where words / phrases are repeated) plus any plugin could make use of autocomplete sending suggestions (like the plugins I previously mentioned above) without conflicting with each other - rather cooperatively creating a curated list of the possible completions for the user.

                                      FOR NOW: definitely keep this “feature” disabled by default and maybe document the “issues” with enabling it. And if ultimately you don’t like it or it makes the maintenance difficult - you can remove it. I do appreciate you adding it in so quickly for me to test / play with. I’ve sorta gotten used to this subpar autocomplete experience (read: flickering and somewhat not reliable) so I may be a bad judge of how “well” this complete_always mode works.


                                      I also cannot stress enough how AWESOME it is that you are tackling LSP for Notepad++!! I have tried some quick Python frameworks running with PythonScript to no avail - which is also why your dockable-dialogs-from-PythonScript piqued my interest. LSP plugin is a daunting task - again, thank you!


                                      Cheers.

                                      rdipardoR 1 Reply Last reply Reply Quote 3
                                      • rdipardoR
                                        rdipardo @Michael Vincent
                                        last edited by

                                        @Michael-Vincent said in New (incomplete and x64 only) LSP client plugin:

                                        it would be nice [. . .] if Notepad++ / Scintilla had a sort of universal autocomplete where you don’t create the list, just submit your items to add to the list and the universal autocomplete compiles a consolidated list of all the available completions before displaying.

                                        #2403 Add an autocomplete popup mode doing no processing

                                        Michael VincentM 1 Reply Last reply Reply Quote 1
                                        • Michael VincentM
                                          Michael Vincent @rdipardo
                                          last edited by

                                          @rdipardo said in New (incomplete and x64 only) LSP client plugin:

                                          #2403 Add an autocomplete popup mode doing no processing

                                          Indeed - that describes the problem rather well. I see the proposed solution is a new autocomplete mode. So maybe that would help with LSP type flickering described, but I don’t think it address the “universal autocomplete” I’m talking about where other plugins (other than the Language Server) and Notepad++ itself could all create a list that gets displayed.

                                          Cheers.

                                          Mark OlsonM 1 Reply Last reply Reply Quote 0
                                          • Mark OlsonM
                                            Mark Olson @Michael Vincent
                                            last edited by Mark Olson

                                            It seems to me that the basic workflow for getting Notepad++ - style autocomplete alongside LSP autocomplete would be something like this:

                                            1. Whenever the current buffer is updated, make a list of words in the file
                                            2. Get a list of autocompletions from the language server
                                            3. filter the words in the file for ones that could be autocompletions
                                            4. Display language server autocompletions in lexicographic order with an icon to distinguish them, and then normal word-in-file autocompletions (with no icon) in lexicographic order.

                                            Obviously the devil is in the details, but implementing Notepad++ - style autocompletion is surely a lot easier than implementing a general-purpose LSP client.

                                            It might even be possible to provide autocompletions from all other open buffers from the FAW (similar to VSCode) if you did something like this:

                                            1. On NPPM_BUFFERACTIVATED, check if the activated buffer is in the FAW, and if its lexer language matches the LSP, list the words in that buffer.
                                            2. When a buffer from the FAW is navigated away from (but not closed), cache the words in that buffer in a data structure like a trie, so that they can easily be used for autocompletions.

                                            My idea of using a trie only really works for static, unchanging word lists (like the buffers that are open but not currently being edited), because constructing a trie is pretty expensive and doesn’t pay for itself until you’ve done a lot of searches.

                                            Michael VincentM 1 Reply Last reply Reply Quote 2
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors