sublimelsp / LSP-pyright

Python support for Sublime's LSP plugin provided through microsoft/pyright.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No LSP functionality, no auto-completion

smetj opened this issue · comments

Hi,

I am running:

  • OS: Ubuntu
  • sublime: 4169
  • LSP: 1.26.0
  • LSP-Pyright: 1.2.62

Autocompletion has always worked but stopped working for unknown reasons.

The language server is able to start correctly when opening a python file:

$ ps -ef|grep lsp
/home/user123/.cache/sublime-text/Package Storage/lsp_utils/node-runtime/18.18.1/node/bin/node /home/user123/.cache/sublime-text/Package Storage/LSP-pyright/18.18.1/language-server/node_modules/pyright/langserver.index.js --stdio

Sublime console shows:

startup, version: 4169 linux x64 channel: stable
executable: /opt/sublime_text/sublime_text
application: /opt/sublime_text
working dir: /home/user123/data/projects/github/harvest
packages path: /home/user123/.config/sublime-text/Packages
state path: /home/user123/.config/sublime-text/Local
zip path: /opt/sublime_text/Packages
zip path: /home/user123/.config/sublime-text/Installed Packages
ignored_packages: ["Vintage"]
pre session restore time: 0.106602
startup time: 0.152661
git: using configuration from system git install
git: tracking working dir /home/user123/data/projects/github/harvest
first paint time: 0.155737
reloading python 3.3 plugin LSP-pyright.commands
reloading plugin Default.arithmetic
reloading plugin Default.auto_indent_tag
reloading plugin Default.block
reloading plugin Default.colors
reloading plugin Default.comment
reloading plugin Default.convert_color_scheme
reloading plugin Default.convert_syntax
reloading plugin Default.copy_path
reloading plugin Default.echo
reloading plugin Default.exec
reloading plugin Default.fold
reloading plugin Default.font
reloading plugin Default.goto_line
reloading plugin Default.history_list
reloading plugin Default.html_print
reloading plugin Default.indentation
reloading plugin Default.install_package_control
reloading plugin Default.keymap
reloading plugin Default.kill_ring
reloading plugin Default.mark
reloading plugin Default.new_templates
reloading plugin Default.open_context_url
reloading plugin Default.open_in_browser
reloading plugin Default.pane
reloading plugin Default.paragraph
reloading plugin Default.paste_from_history
reloading plugin Default.profile
reloading plugin Default.quick_panel
reloading plugin Default.rename
reloading plugin Default.run_syntax_tests
reloading plugin Default.save_on_focus_lost
reloading plugin Default.scroll
reloading plugin Default.set_unsaved_view_name
reloading plugin Default.settings
reloading plugin Default.show_scope_name
reloading plugin Default.side_bar
reloading plugin Default.sort
reloading plugin Default.switch_file
reloading plugin Default.symbol
reloading plugin Default.transform
reloading plugin Default.transpose
reloading plugin Default.ui
reloading plugin CSS.css_completions
reloading plugin Diff.diff
reloading plugin HTML.encode_html_entities
reloading plugin HTML.html_completions
reloading plugin NeoVintageous.plugin
reloading plugin Package Control.plugin
reloading python 3.3 plugin LSP-pyright.plugin
reloading python 3.3 plugin LSP.boot
plugins loaded
LSP: enabled configs: LSP-pyright
LSP: disabled configs: erlang-ls, ocaml, polymer-ide, ruby, sorbet
LSP: Resolved Node.js Runtime for package LSP-pyright: NodeRuntimeLocal(node: /home/user123/.cache/sublime-text/Package Storage/lsp_utils/node-runtime/18.18.1/node/bin/node, npm: /home/user123/.cache/sublime-text/Package Storage/lsp_utils/node-runtime/18.18.1/node/lib/node_modules/npm/bin/npm-cli.js, version: 18.18.1)
LSP-pyright: INFO: Using python path "/home/user123/data/python/virtualenv/default/bin/python"
LSP: starting ['/home/user123/.cache/sublime-text/Package Storage/lsp_utils/node-runtime/18.18.1/node/bin/node', '/home/user123/.cache/sublime-text/Package Storage/LSP-pyright/18.18.1/language-server/node_modules/pyright/langserver.index.js', '--stdio'] in /opt/sublime_text
LSP: LSP-pyright: supported code action kinds: ['quickfix', 'source.organizeImports']
Package Control: Skipping automatic upgrade, last run at 2023-12-14 09:02:43, next run at 2023-12-14 17:02:43 or after

All LSP configuration remained default. There is no autcompletion/suggestions whatsoever.
If I delete LSP then I get back sublimes text autocomplete

What can you recommend as next step to troubleshoot?

Run LSP: Troubleshoot server on the the file in question and post the results. Feel free to filter out sensitive data.

Ok, do you mean something like this:

$ /home/user123/.cache/sublime-text/Package\ Storage/lsp_utils/node-runtime/18.18.1/node/bin/node /home/user123/.cache/sublime-text/Package\ Storage/LSP-pyright/18.18.1/language-server/node_modules/pyright/langserver.index.js --stdio < hello_world.py 
Content-Length: 119

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Pyright language server 1.1.340 starting"}}Content-Length: 220

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Server root directory: file:///home/user123/.cache/sublime-text/Package%20Storage/LSP-pyright/18.18.1/language-server/node_modules/pyright/dist"}}

After which the server exits with 1

LSP: Troubleshoot server is a command available in the command palette.

Got it:

Troubleshooting: LSP-pyright

Version

  • LSP: 1.26.0
  • Sublime Text: 4169

Server Test Run

  • exit code: 0
  • output

Server Configuration

  • command
[
  "${node_bin}", 
  "${server_path}", 
  "--stdio"
]
  • shell command
"/home/user123/.cache/sublime-text/Package Storage/lsp_utils/node-runtime/18.18.1/node/bin/node" "/home/user123/.cache/sublime-text/Package Storage/LSP-pyright/18.18.1/language-server/node_modules/pyright/langserver.index.js" --stdio
  • selector
source.python
  • priority_selector
(source.python - source.python.lsp)
  • init_options
{}
  • settings
{
  "pyright": {
    "dev_environment": "", 
    "disableLanguageServices": false, 
    "disableOrganizeImports": false
  }, 
  "python": {
    "analysis": {
      "autoImportCompletions": true, 
      "autoSearchPaths": true, 
      "diagnosticMode": "openFilesOnly", 
      "diagnosticSeverityOverrides": {
        "reportDuplicateImport": "warning", 
        "reportImplicitStringConcatenation": "warning", 
        "reportMissingParameterType": "none", 
        "reportUnboundVariable": "warning", 
        "reportUninitializedInstanceVariable": "none", 
        "reportUnusedClass": "information", 
        "reportUnusedFunction": "information", 
        "reportUnusedImport": "information", 
        "reportUnusedVariable": "information"
      }, 
      "extraPaths": [], 
      "logLevel": "Information", 
      "stubPath": "./typings", 
      "typeCheckingMode": "basic", 
      "typeshedPaths": [], 
      "useLibraryCodeForTypes": true
    }, 
    "pythonPath": "/home/user123/data/python/virtualenv/default/bin/python", 
    "venvPath": ""
  }
}
  • env
{
  "PATH": "/home/user123/.cache/sublime-text/Package Storage/lsp_utils/node-runtime/18.18.1/node/bin:/home/user123/.cache/sublime-text/Package Storage/lsp_utils/node-runtime/18.18.1/node/bin:"
}

Active view

  • File name
/home/user123/data/hello_world/hello_world.py
  • Settings
{
  "auto_complete_selector": "meta.tag, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc", 
  "lsp_active": true, 
  "syntax": "Packages/Python/Python.sublime-syntax"
}
  • base scope
source.python

Project / Workspace

  • folders
[]
  • is project: False

LSP configuration

{
  "log_debug": true
}

System PATH

  • /home/user123/data/python/virtualenv/default/bin
  • /usr/local/sbin
  • /usr/local/bin
  • /usr/sbin
  • /usr/bin
  • /sbin
  • /bin
  • /usr/games
  • /usr/local/games
  • /snap/bin

That looks good.

What do you expect and what is happening exactly? Is this hellow_world file something you can share?

Also you can post logs from the "LSP Log Panel"

It looks like Pyright v1.1.340 has various issues: https://github.com/microsoft/pyright/issues?q=is%3Aissue+sort%3Aupdated-desc+is%3Aopen
I encounter none but rolling back to v1.1.339 can be an option too.

Lets see first what is the issue here.

the hello_world.py is just a silly script

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  hello_world.py
#

import sys

def incr_one(number: int) -> int:

    return number + 1

def main():

    print(incr_one(10))
    incr_one("10")

if __name__ == "__main__":
    main()

What I would expect

  • when I start to type incr_on... auto-complete starts to pop up including the signature of the function ...
  • when passing "10" there would be some complaints about expecting an int and passing a str
    I see basically see zero pyright feedback

log console looks like it's picking up on me editing

:: [16:21:44.784]  -> LSP-pyright textDocument/didChange: {'contentChanges': [{'rangeLength': 0, 'range': {'start': {'line': 15, 'character': 16}, 'end': {'line': 15, 'character': 16}}, 'text': '"'}], 'textDocument': {'version': 255, 'uri': 'file:///home/user123/data/hello_world.py'}}
:: [16:21:44.785] --> LSP-pyright textDocument/completion (361): {'textDocument': {'uri': 'file:///home/user123/data/hello_world.py'}, 'position': {'line': 15, 'character': 17}}
:: [16:21:45.041] --> LSP-pyright textDocument/documentHighlight (362): {'textDocument': {'uri': 'file:///home/user123/data/hello_world.py'}, 'position': {'line': 15, 'character': 17}}
:: [16:21:46.085] --> LSP-pyright textDocument/documentHighlight (363): {'textDocument': {'uri': 'file:///home/user123/data/hello_world.py'}, 'position': {'line': 15, 'character': 16}}
:: [16:21:46.088] --> LSP-pyright textDocument/codeAction (364): {'context': {'triggerKind': 2, 'diagnostics': []}, 'range': {'start': {'line': 15, 'character': 16}, 'end': {'line': 15, 'character': 16}}, 'textDocument': {'uri': 'file:///home/user123/data/hello_world.py'}}
:: [16:21:46.937]  -> LSP-pyright textDocument/didSave: {'textDocument': {'uri': 'file:///home/user123/data/hello_world.py'}}
:: [16:21:48.452] --> LSP-pyright textDocument/documentHighlight (365): {'textDocument': {'uri': 'file:///home/user123/data/hello_world.py'}, 'position': {'line': 18, 'character': 9}}
:: [16:21:48.455] --> LSP-pyright textDocument/codeAction (366): {'context': {'triggerKind': 2, 'diagnostics': []}, 'range': {'start': {'line': 18, 'character': 9}, 'end': {'line': 18, 'character': 9}}, 'textDocument': {'uri': 'file:///home/user123/data/hello_world.py'}}
:: [16:21:49.422] --> LSP-pyright textDocument/documentHighlight (367): {'textDocument': {'uri': 'file:///home/user123/data/hello_world.py'}, 'position': {'line': 14, 'character': 16}}
:: [16:21:49.426] --> LSP-pyright textDocument/codeAction (368): {'context': {'triggerKind': 2, 'diagnostics': []}, 'range': {'start': {'line': 14, 'character': 16}, 'end': {'line': 14, 'character': 16}}, 'textDocument': {'uri': 'file:///home/user123/data/hello_world.py'}}
:: [16:21:50.046] --> LSP-pyright textDocument/documentHighlight (369): {'textDocument': {'uri': 'file:///home/user123/data/hello_world.py'}, 'position': {'line': 16, 'character': 0}}
:: [16:21:50.049] --> LSP-pyright textDocument/codeAction (370): {'context': {'triggerKind': 2, 'diagnostics': []}, 'range': {'start': {'line': 16, 'character': 0}, 'end': {'line': 16, 'character': 0}}, 'textDocument': {'uri': 'file:///home/user123/data/hello_world.py'}}
:: [16:21:56.029] --> LSP-pyright textDocument/codeAction (371): {'context': {'triggerKind': 1, 'only': ['refactor', 'source'], 'diagnostics': []}, 'range': {'start': {'line': 16, 'character': 0}, 'end': {'line': 16, 'character': 0}}, 'textDocument': {'uri': 'file:///home/user123/data/hello_world.py'}}

Looks like server is not responding. Maybe rollback would help although that doesn't look like the issues reported in pyright repo.

Actually I can reproduce this in 1.2.62 but not in 1.2.61 so rollback might be a good idea.

I've just tagged a new tag with Pyright 1.1.339.

It looks like Pyright 1.1.340 doesn't response (internally infinite loop?) if the file is open in "single file mode". If it's opened within folder (i.e., ST project), it's working.

Thanks guys! Latest version works as expected 🙇 👍