@rangermauve/lsp-query
v1.0.0
Published
Talk to any LSP server from the command line. Outputs raw JSON for piping.
Downloads
32
Readme
lsp-query
Talk to any LSP server from the command line. Outputs raw JSON for piping.
Auto-detects the LSP server based on project files. Override with --lsp-command.
Uses vscode-jsonrpc for proper JSON-RPC framing.
npm install -g @rangermauve/lsp-queryUsage
lsp-query <method> [file] [--project-root <path>] [--lsp-command <cmd>] [args...]Project root defaults to current working directory. The file argument can be positional or file=<path>. Pass other params as key=value pairs (use position.line=7 dot-notation for nested objects) or --raw '{json}'.
Supported project types
| Marker file | LSP server |
| ----------------------------------------- | ---------------------------- |
| tsconfig.json, package.json | typescript-language-server |
| pyproject.toml, setup.py | basedpyright-langserver |
| Cargo.toml | rust-analyzer |
| go.mod | gopls |
| pom.xml, build.gradle | jdtls |
| Gemfile | solargraph |
| compile_commands.json, CMakeLists.txt | clangd |
| composer.json | phpactor |
| mix.exs | elixir-ls |
| build.zig | zls |
Examples
# auto-detect LSP from cwd, list symbols
lsp-query workspace/symbol src/types.ts
# search symbols, pipe to jq
lsp-query workspace/symbol src/types.ts query=Blob | jq '.[].name'
# hover info
lsp-query textDocument/hover index.js position.line=7 position.character=14 | jq '.contents'
# target a different project root
lsp-query workspace/symbol --project-root ../example-project src/index.ts
# override LSP server
lsp-query workspace/symbol --lsp-command rust-analyzer
# count symbols
lsp-query workspace/symbol index.js | jq length
# filter by kind (13 = constant, 12 = function)
lsp-query workspace/symbol index.js | jq '[.[] | select(.kind == 12)]'