Community
    • Login

    Microsoft Language Server Protocol (LSP): A possible revolution for Notepad++?

    Scheduled Pinned Locked Moved General Discussion
    38 Posts 7 Posters 9.4k 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.
    • Michael VincentM
      Michael Vincent @Ekopalypse
      last edited by

      @Ekopalypse said in Microsoft Language Server Protocol (LSP): A possible revolution for Notepad++?:

      You need to pip-install pyflakes and jedi and use the PS3 alpha version.

      Sorry for the following probably basic Python questions, but I’m getting this error when running my startup.py:

      Traceback (most recent call last):
        File "C:\usr\bin\npp64\plugins\PythonScript\scripts\startup.py", line 31, in <module>
          from python_ide import IDE
        File "C:\usr\bin\npp64\plugins\PythonScript\scripts\python_ide.py", line 8, in <module>
          from pyflakes import api
      ModuleNotFoundError: No module named 'pyflakes'
      

      I’m assuming this is because PyFlakes is not installed in my PythonScript3 distro. I did a:

      python3 -mpip install pyflakes jedi

      and it worked to install to my OS python:

      PS VinsWorldcom C:\usr\bin\npp64\plugins\PythonScript > python3 -V
      Python 3.6.3
      PS VinsWorldcom C:\usr\bin\npp64\plugins\PythonScript > python3
      Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import jedi
      >>> import pyflakes
      

      So I’m guessing I need to have PythonScript3 find my local Python3 libraries or install PyFlakes and Jedi in the PythonScript3 lib/ directory.

      Any tips?

      Cheers.

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

        @Michael-Vincent

        which PS3 plugin did you install? Depending on it you have to use the correct python version and copy
        the pythonXX.dll to the PS plugin directory.
        Like I have the latest PS, hence I use python 3.8

        0d58770e-7268-4d24-a723-d0f18267a42f-image.png

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

          @Michael-Vincent

          Now I’m thinking that, if I remember correctly, you have to use python 3.8. PS3 started with this version.

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

            @Ekopalypse said in Microsoft Language Server Protocol (LSP): A possible revolution for Notepad++?:

            which PS3 plugin did you install? Depending on it you have to use the correct python version and copy
            the pythonXX.dll to the PS plugin directory.

            I installed v3.0.4 and have the DLL for python 3.8 (that was bundled with the above ZIP) already in place:

            PS VinsWorldcom C:\usr\bin\npp64\plugins\PythonScript > ls -al
            total 5680
            drwxr-x---  1 VinsWorldcom                0 Nov  5 15:00 .\
            drwxr-x---  1 VinsWorldcom                0 Nov  5 15:00 ..\
            drwxr-x---  1 VinsWorldcom                0 Sep  7 07:33 doc\
            drwxr-x---  1 VinsWorldcom                0 Nov  5 14:27 lib\
            -rw-r----a  1 VinsWorldcom          4209224 Jul 20 16:06 python38.dll
            -rw-r----a  1 VinsWorldcom          1606144 Sep  7 07:31 PythonScript.dll
            drwxr-x---  1 VinsWorldcom                0 Nov  5 14:34 scripts\
            

            Am I to understand that I need to upgrade my OS Python3.6 version to match the 3.8 for PythonScript?

            Cheers.

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

              @Michael-Vincent

              Yes, and copy the pythonXX.dll from the installation to C:\usr\bin\npp64\plugins\PythonScript
              then PS sees all your pip installed modules.
              In addition, check the prefer installed python libraries from PS configuration dialog.

              b83b6798-9b58-47cf-9c5c-ab5bc64325ed-image.png

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

                @Ekopalypse

                Thanks - I actually got it working by copying PyFlakes, Jedi (and Parso which seemed to be a Jedi dependency) install directories from my system Python3 to the PythonScript/lib folder.

                Autocompletion now works for “objects”:

                import socket
                
                addrs = socket.getaddrinfo("localhost", 12345, socket.AF_UNSPEC, socket.SOCK_DGRAM)
                sock = None
                
                for addr in addrs:
                    af, socktype, proto, cname, sa = addr
                
                    try:
                        sock = socket.socket(af, socktype, proto)
                [...]
                

                and then typing:

                sock. brings up a list of all methods I can call on the socket object - but it’s slow - noticeably slow in populating that autocomplete list.

                Pretty cool though! I’ll do some more playing with this and thanks for the script and help setting it up.

                Cheers.

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

                  @Michael-Vincent

                  it should be slow only for the first time it discovers an object. If you use certain objects more often
                  then others, you could try to preload them jedi.preload_module(['os','sys', ...])

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

                    @Ekopalypse said in Microsoft Language Server Protocol (LSP): A possible revolution for Notepad++?:

                    preload them jedi.preload_module([‘os’,‘sys’, …])

                    Thanks for the tip! Python is obviously not my strength; hence, the want for some “IDE-lite” help from Notepad++.

                    Cheers.

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

                      @Michael-Vincent

                      :-D - the same would happen to me if I try to write perl :-D

                      1 Reply Last reply Reply Quote 1
                      • TroshinDVT
                        TroshinDV
                        last edited by

                        @pidgeon777 said in Microsoft Language Server Protocol (LSP): A possible revolution for Notepad++?:

                        Microsoft Language Server Protocol (LSP) defines the protocol used between an editor or IDE and a language server that provides language features like autocomplete, go to definition, find all references etc.:

                        Screenshot_270.png
                        У меня есть немного для php, js, vbs, 1C, MySql.
                        https://github.com/trdm/jn-npp-scripts

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

                          @Ekopalypse said in Microsoft Language Server Protocol (LSP): A possible revolution for Notepad++?:

                          ok, this is my “lsp” script (called python_ide.py)

                          I wonder if this pylspclient can be used? It’s supposedly an LSP client written in Python so theoretically PythonScript could run it.

                          I’ve been playing with it from the command line with my system Python3 and not having much luck with the examples/python-language-server.py script included and having the python-language-server installed.

                          Cheers.

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

                            @Michael-Vincent

                            let me have a look and play with it a bit.

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

                              @Michael-Vincent

                              It looks like the main problem might be that this lspclient is written for Python2.
                              Let me see if I can make a working version. Probably in 6-7 hours.

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

                                @Ekopalypse said in Microsoft Language Server Protocol (LSP): A possible revolution for Notepad++?:

                                lspclient is written for Python2

                                Weird - it seems to “run” OK - not throwing any errors, but just not initializing with the language server:

                                PS VinsWorldcom ~\source\personal\pylspclient\examples > python3 .\python-language-server.py
                                2020-12-02 10:19:26,251 UTC - WARNING - pyls.config.config - Failed to load pyls entry point 'autopep8': No module named 'pycodestyle'
                                
                                2020-12-02 10:19:26,297 UTC - WARNING - pyls.config.config - Failed to load pyls entry point 'pycodestyle': No module named 'pycodestyle'
                                
                                2020-12-02 10:19:26,301 UTC - WARNING - pyls.config.config - Failed to load pyls entry point 'pydocstyle': No module named 'pydocstyle'
                                
                                2020-12-02 10:19:26,492 UTC - WARNING - pyls.config.config - Failed to load pyls entry point 'rope_completion': No module named 'rope'
                                
                                2020-12-02 10:19:26,496 UTC - WARNING - pyls.config.config - Failed to load pyls entry point 'rope_rename': No module named 'rope'
                                
                                {'capabilities': {'codeActionProvider': True, 'codeLensProvider': {'resolveProvider': False}, 'completionProvider': {'resolveProvider': False, 'triggerCharacters': ['.']}, 'documentFormattingProvider': True, 'documentHighlightProvider': True, 'documentRangeFormattingProvider': True, 'documentSymbolProvider': True, 'definitionProvider': True, 'executeCommandProvider': {'commands': []}, 'hoverProvider': True, 'referencesProvider': True, 'renameProvider': True, 'foldingRangeProvider': True, 'signatureHelpProvider': {'triggerCharacters': ['(', ',', '=']}, 'textDocumentSync': {'change': 2, 'save': {'includeText': True}, 'openClose': True}, 'workspace': {'workspaceFolders': {'supported': True, 'changeNotifications': True}}, 'experimental': {}}}
                                init =  None
                                

                                NOTE: I made 2 small changes to the the examples/python-language-server.py script:

                                diff --git a/examples/python-language-server.py b/examples/python-language-server.py
                                index 72026e5..0e67858 100644
                                --- a/examples/python-language-server.py
                                +++ b/examples/python-language-server.py
                                @@ -19,7 +19,7 @@ class ReadPipe(threading.Thread):
                                             line = self.pipe.readline().decode('utf-8')
                                
                                 if __name__ == "__main__":
                                -    pyls_cmd = ["python", "-m", "pyls"]
                                +    pyls_cmd = ["python3", "-m", "pyls"]
                                     p = subprocess.Popen(pyls_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                                     read_pipe = ReadPipe(p.stderr)
                                     read_pipe.start()
                                @@ -143,7 +143,7 @@ if __name__ == "__main__":
                                     root_uri = 'file:///path/to/python/project'
                                     workspace_folders = [{'name': 'python-lsp', 'uri': root_uri}]
                                     print(lsp_client.initialize(p.pid, None, root_uri, None, capabilities, "off", workspace_folders))
                                -    print(lsp_client.initialized())
                                +    print("init = ", lsp_client.initialized())
                                
                                     lsp_client.shutdown()
                                     lsp_client.exit()
                                

                                Cheers.

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

                                  @Michael-Vincent - I tried to make it work but after three
                                  Npp crashes I decided to make my implementation work with python3.
                                  I’ll keep working on it an updates will be made available via the github repo.

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

                                    @Ekopalypse said in Microsoft Language Server Protocol (LSP): A possible revolution for Notepad++?:

                                    I’ll keep working on it an updates will be made available via the github repo.

                                    I’ll keep checking back then - thanks!

                                    pidgeon777P 1 Reply Last reply Reply Quote 1
                                    • pidgeon777P
                                      pidgeon777 @Michael Vincent
                                      last edited by

                                      A plugin implementing an LSP client in Notepad++ has finally been released.

                                      https://github.com/Ekopalypse/NppLspClient

                                      Credits to @Ekopalypse for that.

                                      I encourage everyone to give it a try and report back for any found issue.

                                      EkopalypseE 1 Reply Last reply Reply Quote 2
                                      • EkopalypseE
                                        Ekopalypse @pidgeon777
                                        last edited by

                                        … but bear in mind that this is in an early alpha stage and that there is another plugin that already covers some pitfalls when it comes to implementing LSP for Npp and Scintilla.

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