basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

No response from LSP when requesting documentSymbol

Open MimrrBrian opened this issue 1 year ago • 1 comments

Hey thanks for the LSP service.

I am trying to run the basedpyright-langserver --stdio which works fine for the first few calls from my custom client, however when I execute textDocument/documentSymbol there is no response from basedpyright

example command:

{"jsonrpc":"2.0","id":2,"method":"textDocument/documentSymbol","params":{"textDocument":{"uri":"file:///repo/setup.py"},"partialResultToken":"78ea1b0f-252c-4c25-90df-c533c6bf05e2"}}

The first initialise commands are sent and responded to:

{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"processId":null,"clientInfo":{"name":"ReSharperTestRunner, Version=2.16.1.109, Culture=neutral, PublicKeyToken=5c492ec4f3eccde3","version":"2.16.1.109"},"rootPath":"/repo","rootUri":"file:///repo","initializationOptions":null,"capabilities":{"workspace":{"symbol":{"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"dynamicRegistration":true},"workspaceFolders":true},"textDocument":{"documentSymbol":{"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true,"tagSupport":{"valueSet":[1]},"labelSupport":true,"dynamicRegistration":true},"publishDiagnostics":{}},"window":{"workDoneProgress":true},"general":{},"experimental":{}},"workspaceFolders":[{"uri":"file:///repo","name":"test"}]}}

"jsonrpc":"2.0","id":1,"result":{"capabilities":{"textDocumentSync":2,"definitionProvider":{"workDoneProgress":true},"declarationProvider":{"workDoneProgress":true},"typeDefinitionProvider":{"workDoneProgress":true},"referencesProvider":{"workDoneProgress":true},"documentSymbolProvider":{"workDoneProgress":true},"workspaceSymbolProvider":{"workDoneProgress":true},"hoverProvider":{"workDoneProgress":true},"documentHighlightProvider":{"workDoneProgress":true},"renameProvider":{"prepareProvider":true,"workDoneProgress":true},"completionProvider":{"triggerCharacters":[".","[","\"","'"],"resolveProvider":true,"workDoneProgress":true,"completionItem":{"labelDetailsSupport":true}},"signatureHelpProvider":{"triggerCharacters":["(",",",")"],"workDoneProgress":true},"codeActionProvider":{"codeActionKinds":["quickfix","source.organizeImports"],"workDoneProgress":true},"executeCommandProvider":{"commands":[],"workDoneProgress":true},"callHierarchyProvider":true,"inlayHintProvider":true,"semanticTokensProvider":{"legend":{"tokenTypes":["class","parameter","typeParameter","function","method","decorator","property","namespace","variable","type","keyword"],"tokenModifiers":["definition","declaration","async","readonly","defaultLibrary","builtin"]},"full":true},"workspace":{"fileOperations":{"willRename":{"filters":[{"pattern":{"glob":"**/*"}}]}},"workspaceFolders":{"supported":true,"changeNotifications":true}}}}}

Is there any way to enable more logging or am I missing something obvious.

Thanks

MimrrBrian avatar Oct 11 '24 00:10 MimrrBrian

I just noticed the first response from the LSP is

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Server root directory: file:///home/appuser/venv/lib/python3.11/site-packages/basedpyright/dist"}}

Should the root directory be this?

ghost avatar Oct 11 '24 10:10 ghost

closing this issue as this user seems to have deleted their account and there's not enough info for me to reproduce.

if you somehow still see this, here are some some things you can try:

  • set basedpyright.analysis.logLevel to "Trace" and see if anything useful appears in the log
  • make sure you're sending at the very least an empty object for the configuration. the language server will silently not work unless you do this (see #405)

I just noticed the first response from the LSP is

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Server root directory: file:///home/appuser/venv/lib/python3.11/site-packages/basedpyright/dist"}}

Should the root directory be this?

yeah thats correct. it refers to the directory where the basedpyright-langserver executable is located.

DetachHead avatar Oct 18 '24 11:10 DetachHead

@DetachHead

Thanks for replying with that information. I am trying to debug workspace/symbol, which does not seem to be working with basedpyright 1.32.1.

Given this tiny Python file:

def greet(name):
    return f"Hello, {name}!"

basedpyright returns an empty result for greet, but I expect line 1:

# vim lsp log file
10/23/25 21:34:37: Sent {'method': 'workspace/symbol', 'params': {'query': 'greet'}}
10/23/25 21:34:37: Received {'id': 4, 'jsonrpc': '2.0', 'result': []}

I added config to increase debug out, but nothing additional is being logged. (Unrelated, I want to use workspace mode, because eventually I want to search all files.)

pyrightconfig.json

{
  "basedpyright.analysis.diagnosticMode": "workspace",
  "basedpyright.analysis.logLevel": "Trace",
  "verboseOutput": true,
  "include": [
    "**/*.py"
  ],
  "pythonVersion": "3.13"
}

I'm using vim and the lsp plugin. I've configured lsp with verbose logging too, but still only JSON messages are logged to its log file:

" vimrc
call LspAddServer([#{name: 'basedpyright',
                 \   debug: 'true',
                 \   traceLevel: 'debug',
                 \   filetype: 'python',
                 \   path: 'uv',
                 \   args: ['run', 'basedpyright-langserver', '--stdio']
                 \ }])

vim lsp does list the server capabilities correctly:

'uv' Language Server Capabilities
=================================
callHierarchyProvider: true
codeActionProvider: {'workDoneProgress': true, 'codeActionKinds': ['quickfix', 'source.organizeImports']}
completionProvider: {'completionItem': {'labelDetailsSupport': true}, 'resolveProvider': true, 'triggerCharacters': ['.', '[', '"', ''''], 'workDoneProgress': true}
declarationProvider: {'workDoneProgress': true}
definitionProvider: {'workDoneProgress': true}
documentHighlightProvider: {'workDoneProgress': true}
documentOnTypeFormattingProvider: {'firstTriggerCharacter': '{'}
documentSymbolProvider: {'workDoneProgress': true}
executeCommandProvider: {'workDoneProgress': true, 'commands': ['basedpyright.createtypestub', 'basedpyright.restartserver', 'basedpyright.writeBaseline']}
hoverProvider: {'workDoneProgress': true}
inlayHintProvider: true
notebookDocumentSync: {'save': true, 'notebookSelector': [{'notebook': {'notebookType': 'jupyter-notebook', 'scheme': 'file'}, 'cells': [{'language': 'python'}]}]}
referencesProvider: {'workDoneProgress': true}
renameProvider: {'workDoneProgress': true, 'prepareProvider': true}
semanticTokensProvider: {'legend': {'tokenTypes': ['namespace', 'type', 'class', 'enum', 'typeParameter', 'parameter', 'variable', 'property', 'enumMember', 'function', 'method', 'keyword', 'decorator', 'selfParameter', 'clsParameter'], 'tokenModifiers': ['declaration', 'definition', 'readonly', 'static', 'async', 'defaultLibrary', 'builtin', 'classMember', 'parameter']}, 'full': true}
signatureHelpProvider: {'triggerCharacters': ['(', ',', ')'], 'workDoneProgress': true}
textDocumentSync: {'willSave': true, 'change': 2, 'openClose': true}
typeDefinitionProvider: {'workDoneProgress': true}
workspace: {'workspaceFolders': {'changeNotifications': true, 'supported': true}, 'fileOperations': {'willRename': {'filters': [{'pattern': {'glob': '**/*'}}]}}}
workspaceSymbolProvider: {'workDoneProgress': true}
~additionalInitResult_serverInfo: {'version': '1.32.1', 'name': 'basedpyright'}

By comparison, the tsgo LSP (TypeScript 7 / Go) works, so I don't think this a vim/lsp configuration problem:

# vim lsp log file
10/23/25 21:21:44: Sent {'method': 'workspace/symbol', 'params': {'query': 'add'}}
10/23/25 21:21:44: Received {'id': 5, 'jsonrpc': '2.0', 'result': [{'location': {'uri': 'file:///code/javascript/foo.js', 'range': {'end': {'character': 7, 'line': 11}, 'start': {'character': 4, 'line': 11}}}, 'name': 'add', 'kind': 6}]}

I've also used pylsp, but it doesn't support workspace/symbol, so I'm trying basedpyright.

Any suggestions? Thank you!

richardkmichael avatar Oct 24 '25 04:10 richardkmichael

i tried the same thing on both vscode and zed and it works for me:

// Send:
{"jsonrpc":"2.0","id":27,"method":"workspace/symbol","params":{"query":"greet"}}

// Receive:
{"jsonrpc":"2.0","id":27,"result":[{"name":"greet","kind":12,"location":{"uri":"file:///home/me/projects/test/bar.py","range":{"start":{"line":0,"character":4},"end":{"line":0,"character":9}}}},{"name":"greet","kind":12,"location":{"uri":"file:///home/me/projects/test/foo/asdf.py","range":{"start":{"line":0,"character":4},"end":{"line":0,"character":9}}}}]}

so it might be an issue with the vim lsp plugin you're using. does the issue persist if you try one of the other plugins mentioned at https://docs.basedpyright.com/latest/installation/ides/#neovim

DetachHead avatar Oct 24 '25 09:10 DetachHead

Thanks for the fast reply and the demo.

I tried VSCode and Zed, both work. (Zed used built-in basedpyright version 1.32.1. 👍 )

Do you know where I can find the entire LSP conversation? Can basedpyright log to a file, so I can avoid the editor? VSCode doesn't seem to log the JSON at all, and in Zed the LSP Logs > RPC Messages does not start at the beginning, so I can't see initialization, and early messages.

Also, both VSCode and Zed log errors about pyrightconfig.json. I guess I've misunderstood the documentation?

[Error - 10:41:31 AM] Config contains unrecognized setting "basedpyright.analysis.diagnosticMode".
[Error - 10:41:31 AM] Config contains unrecognized setting "basedpyright.analysis.logLevel".

I tried nested object notation, but it did not work either:

Config contains unrecognized setting "basedpyright".
Config nested notation
{
  "basedpyright": {
    "analysis": {
      "logLevel": "Trace",
      "diagnosticMode": "workspace"
    }
  },
  "verboseOutput": true,
  "include": [
    "**/*.py"
  ],
  "pythonVersion": "3.13"
}
Complete VSCode`Output` log
[Info  - 10:41:31 AM] basedpyright language server 1.32.1 starting
[Info  - 10:41:31 AM] Server root directory: file:///code/.vscode/extensions/detachhead.basedpyright-1.32.1/dist
[Info  - 10:41:31 AM] Starting service instance "python"
Received pythonPath from Python extension: /code/.pyenv/versions/3.13.5/bin/python
[Info  - 10:41:31 AM] Loading configuration file at /code/test/development/fixtures/python/pyrightconfig.json
[Error - 10:41:31 AM] Config contains unrecognized setting "basedpyright.analysis.diagnosticMode".
[Error - 10:41:31 AM] Config contains unrecognized setting "basedpyright.analysis.logLevel".
[Info  - 10:41:31 AM] Setting pythonPath for service "python": "/code/.pyenv/versions/3.13.5/bin/python"
[Info  - 10:41:31 AM] Auto-excluding **/node_modules
[Info  - 10:41:31 AM] Auto-excluding **/__pycache__
[Info  - 10:41:31 AM] Auto-excluding **/.*
[Info  - 10:41:31 AM] Execution environment: file:///code/.pyenv/versions/3.13.5/bin/python
[Info  - 10:41:31 AM]   Extra paths:
[Info  - 10:41:31 AM]     (none)
[Info  - 10:41:31 AM]   Python version: 3.13
[Info  - 10:41:31 AM]   Python platform: All
[Info  - 10:41:31 AM]   Search paths:
[Info  - 10:41:31 AM]     /code/.vscode/extensions/detachhead.basedpyright-1.32.1/dist/typeshed-fallback/stdlib
[Info  - 10:41:31 AM]     /code/test/development/fixtures/python
[Info  - 10:41:31 AM]     /code/test/development/fixtures/python/typings
[Info  - 10:41:31 AM]     /code/.vscode/extensions/detachhead.basedpyright-1.32.1/dist/typeshed-fallback/stubs/...
[Info  - 10:41:31 AM]     /code/.pyenv/versions/3.13.5/lib/python3.13
[Info  - 10:41:31 AM]     /code/.pyenv/versions/3.13.5/lib/python3.13/lib-dynload
[Info  - 10:41:31 AM]     /code/.pyenv/versions/3.13.5/lib/python3.13/site-packages
[Info  - 10:41:31 AM] Adding fs watcher for library directories:
 file:///code/.pyenv/versions/3.13.5/lib/python3.13
[Info  - 10:41:31 AM] Adding fs watcher for directories:
 file:///code/test/development/fixtures/python
[Info  - 10:41:31 AM] BG: Background analysis(1) root directory: file:///code/.vscode/extensions/detachhead.basedpyright-1.32.1/dist
[Info  - 10:41:31 AM] BG: Background analysis(1) started
[Info  - 10:41:31 AM] Found 2 source files
[Info  - 10:44:15 AM] Heap stats: total_memory_size=8192MB, total_free_size=23MB, total_heap_size=43MB, used_heap_size=32MB, cross_worker_used_heap_size=32MB, total_physical_size=43MB, total_available_size=3134MB, heap_size_limit=3168MB
[Info  - 10:44:15 AM] Could not import 'annotationlib' in file '/code/.vscode/extensions/detachhead.basedpyright-1.32.1/dist/typeshed-fallback/stdlib/typing_extensions.pyi'
[Info  - 10:44:15 AM] Could not import 'annotationlib' in file '/code/.vscode/extensions/detachhead.basedpyright-1.32.1/dist/typeshed-fallback/stdlib/typing.pyi'
[Info  - 10:44:15 AM] Could not import 'annotationlib' in file '/code/.vscode/extensions/detachhead.basedpyright-1.32.1/dist/typeshed-fallback/stdlib/typing.pyi'
[Info  - 10:44:15 AM] Could not import 'annotationlib' in file '/code/.vscode/extensions/detachhead.basedpyright-1.32.1/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi'
[Info  - 10:44:15 AM] BG: Heap stats: total_memory_size=8192MB, total_free_size=63MB, total_heap_size=23MB, used_heap_size=18MB, cross_worker_used_heap_size=51MB, total_physical_size=23MB, total_available_size=3152MB, heap_size_limit=3168MB
[Info  - 10:44:15 AM] BG: Could not import 'annotationlib' in file '/code/.vscode/extensions/detachhead.basedpyright-1.32.1/dist/typeshed-fallback/stdlib/typing_extensions.pyi'
[Info  - 10:44:15 AM] BG: Could not import 'annotationlib' in file '/code/.vscode/extensions/detachhead.basedpyright-1.32.1/dist/typeshed-fallback/stdlib/typing.pyi'
[Info  - 10:44:15 AM] BG: Could not import 'annotationlib' in file '/code/.vscode/extensions/detachhead.basedpyright-1.32.1/dist/typeshed-fallback/stdlib/typing.pyi'
[Info  - 10:44:15 AM] BG: Could not import 'annotationlib' in file '/code/.vscode/extensions/detachhead.basedpyright-1.32.1/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi'
[Info  - 10:46:47 AM] Heap stats: total_memory_size=8192MB, total_free_size=39MB, total_heap_size=33MB, used_heap_size=29MB, cross_worker_used_heap_size=60MB, total_physical_size=33MB, total_available_size=3138MB, heap_size_limit=3168MB
[Info  - 10:50:06 AM] Heap stats: total_memory_size=8192MB, total_free_size=39MB, total_heap_size=30MB, used_heap_size=29MB, cross_worker_used_heap_size=60MB, total_physical_size=30MB, total_available_size=3140MB, heap_size_limit=3168MB

richardkmichael avatar Oct 24 '25 18:10 richardkmichael

Do you know where I can find the entire LSP conversation? Can basedpyright log to a file, so I can avoid the editor? VSCode doesn't seem to log the JSON at all

in vscode's settings.json you can set "basedpyright.trace.server": "verbose" (which is an undocumented setting because it's part of the underlying LSP client library that the vscode extension uses. see #1578)

and in Zed the LSP Logs > RPC Messages does not start at the beginning, so I can't see initialization, and early messages.

yeah that's quite annoying, i ran into the same problem today when trying to debug #1598

what i usually do is run the language server through lsp-devtools. here's how you can configure zed to do that:

// .zed/settings.json
{
  "lsp": {
    "basedpyright": {
      "binary": {
        "path": ".venv/bin/lsp-devtools",
        "arguments": [
          "agent",
          "--",
          ".venv/bin/basedpyright-langserver",
          "--stdio"
        ]
      }
    }
  }
}

then you can connect to it and inspect all the logged messages using the command lsp-devtools inspect

Also, both VSCode and Zed log errors about pyrightconfig.json. I guess I've misunderstood the documentation?

[Error - 10:41:31 AM] Config contains unrecognized setting "basedpyright.analysis.diagnosticMode".
[Error - 10:41:31 AM] Config contains unrecognized setting "basedpyright.analysis.logLevel".

since these settings are specific to the language server, they can't be configured in pyrightconfig.json. you can see examples of how to configure the language server for different editors here

DetachHead avatar Oct 25 '25 09:10 DetachHead

Thanks again for your help and mentioning lsp-devtools. The issue can be closed again.

It was my lack of understanding, along with automatic client- and server-side config by some tooling.

Along the way I vibed full LSP logging to Zed, so I could see the initialization and capability messages. Kind of fun. :-)

Summarizing:

I compared LSP message logs from successful and unsuccessful configurations of different clients and servers.

  • VSCode and Zed with basedpyright worked
  • NeoVim and my custom client:
    • basedpyright did not work
    • astral/ty worked

My custom client was sending capability workspace/configuration: true but responding null when receiving workspace/configuration for items from the server, presumably confusing basedpyright. (Perhaps unrelated, workspaceFolders and rootUri were set correctly.) This capability and response mismatch didn't matter to astral/ty, it worked; this confused me. When I set workspace/configuration capability to false (for simplicity), basedpyright worked. I guess basedpyright does detection, but not after receiving null config and trying to honour it.

Checking with neovim also confused me, similarly because astral/ty didn't require configuration, and basedpyright did need root markers and the Python settings. (neovim constructed vim.NIL responses to server sent configuration requests until I set these).

vim.lsp.config('python', {
  filetypes = { 'python' },

  -- cmd = { 'uvx', 'ty', 'server' },
  cmd = { 'uv', 'run', 'basedpyright-langserver', '--stdio' },

  -- Basedpyright
  root_markers = { 'pyproject.toml' },
  settings = {
    python = {
      venvPath = vim.fn.getcwd() .. "/.venv",
      -- Or, specify the python executable directly
      -- pythonPath = vim.fn.getcwd() .. "/.venv/bin/python",
    }
  }
}

richardkmichael avatar Nov 11 '25 23:11 richardkmichael

yeah it's annoying how every language server and client has subtle differences like that, glad you got it working

DetachHead avatar Nov 13 '25 09:11 DetachHead