lsp-cli 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lsp_cli-0.1.1/PKG-INFO +302 -0
- lsp_cli-0.1.1/README.md +272 -0
- lsp_cli-0.1.1/pyproject.toml +51 -0
- lsp_cli-0.1.1/src/lsp_cli/__init__.py +0 -0
- lsp_cli-0.1.1/src/lsp_cli/__main__.py +65 -0
- lsp_cli-0.1.1/src/lsp_cli/cli/__init__.py +0 -0
- lsp_cli-0.1.1/src/lsp_cli/cli/definition.py +56 -0
- lsp_cli-0.1.1/src/lsp_cli/cli/hover.py +30 -0
- lsp_cli-0.1.1/src/lsp_cli/cli/locate.py +63 -0
- lsp_cli-0.1.1/src/lsp_cli/cli/main.py +25 -0
- lsp_cli-0.1.1/src/lsp_cli/cli/options.py +49 -0
- lsp_cli-0.1.1/src/lsp_cli/cli/outline.py +64 -0
- lsp_cli-0.1.1/src/lsp_cli/cli/reference.py +78 -0
- lsp_cli-0.1.1/src/lsp_cli/cli/rename.py +79 -0
- lsp_cli-0.1.1/src/lsp_cli/cli/search.py +67 -0
- lsp_cli-0.1.1/src/lsp_cli/cli/shared.py +92 -0
- lsp_cli-0.1.1/src/lsp_cli/cli/symbol.py +32 -0
- lsp_cli-0.1.1/src/lsp_cli/client.py +19 -0
- lsp_cli-0.1.1/src/lsp_cli/manager/__init__.py +51 -0
- lsp_cli-0.1.1/src/lsp_cli/manager/__main__.py +10 -0
- lsp_cli-0.1.1/src/lsp_cli/manager/capability.py +106 -0
- lsp_cli-0.1.1/src/lsp_cli/manager/client.py +161 -0
- lsp_cli-0.1.1/src/lsp_cli/manager/manager.py +168 -0
- lsp_cli-0.1.1/src/lsp_cli/manager/models.py +55 -0
- lsp_cli-0.1.1/src/lsp_cli/manager/server.py +73 -0
- lsp_cli-0.1.1/src/lsp_cli/server.py +85 -0
- lsp_cli-0.1.1/src/lsp_cli/settings.py +65 -0
- lsp_cli-0.1.1/src/lsp_cli/utils/__init__.py +0 -0
- lsp_cli-0.1.1/src/lsp_cli/utils/http.py +183 -0
- lsp_cli-0.1.1/src/lsp_cli/utils/socket.py +27 -0
- lsp_cli-0.1.1/src/lsp_cli/utils/sync.py +5 -0
lsp_cli-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: lsp-cli
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A powerful command-line interface for the Language Server Agent Protocol (LSAP)
|
|
5
|
+
Keywords: Language Server Protocol,LSP,CLI,Developer Tools,LSAP
|
|
6
|
+
Author: observerw
|
|
7
|
+
Author-email: observerw <wozluohd@gmail.com>
|
|
8
|
+
Classifier: Programming Language :: Python
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
12
|
+
Classifier: Operating System :: MacOS
|
|
13
|
+
Requires-Dist: anyio>=4.12.0
|
|
14
|
+
Requires-Dist: asyncer>=0.0.12
|
|
15
|
+
Requires-Dist: attrs>=25.4.0
|
|
16
|
+
Requires-Dist: httpx>=0.28.1
|
|
17
|
+
Requires-Dist: loguru>=0.7.3
|
|
18
|
+
Requires-Dist: platformdirs>=4.5.1
|
|
19
|
+
Requires-Dist: pydantic>=2.12.5
|
|
20
|
+
Requires-Dist: pydantic-settings>=2.12.0
|
|
21
|
+
Requires-Dist: typer>=0.20.1
|
|
22
|
+
Requires-Dist: uvicorn>=0.40.0
|
|
23
|
+
Requires-Dist: litestar>=2.19.0
|
|
24
|
+
Requires-Dist: xxhash>=3.6.0
|
|
25
|
+
Requires-Dist: tenacity>=9.1.2
|
|
26
|
+
Requires-Dist: lsp-client>=0.3.0
|
|
27
|
+
Requires-Dist: lsap-sdk>=0.1.0
|
|
28
|
+
Requires-Python: >=3.13
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# LSP CLI
|
|
32
|
+
|
|
33
|
+
[](https://pypi.org/project/lsp-cli/)
|
|
34
|
+
[](https://python.org)
|
|
35
|
+
[](LICENSE)
|
|
36
|
+
|
|
37
|
+
> **⚠️ Windows Temporary Not Supported**
|
|
38
|
+
> Due to implementation details, `lsp-cli` does not currently support Windows. Support for Windows will be added in the next version.
|
|
39
|
+
|
|
40
|
+
A powerful command-line interface for the [**Language Server Agent Protocol (LSAP)**](https://github.com/lsp-client/LSAP). `lsp-cli` provides a bridge between traditional [Language Server Protocol (LSP)](https://microsoft.github.io/language-server-protocol/) servers and high-level agentic workflows, offering structured data access and a robust background server management system.
|
|
41
|
+
|
|
42
|
+
Built on top of [lsp-client](https://github.com/lsp-client/lsp-client) and [LSAP](https://github.com/lsp-client/LSAP), this tool is designed for developers and AI agents who need reliable, fast, and structured access to language intelligence.
|
|
43
|
+
|
|
44
|
+
## Key Features
|
|
45
|
+
|
|
46
|
+
- **🤖 Built for Agents**: The CLI output is optimized for Coding Agents. By avoiding fancy TUI/UI elements and rich terminal formatting, it significantly reduces token consumption while maintaining high readability for LLMs.
|
|
47
|
+
- **🚀 Instant Analysis**: Quickly get definitions, references, hover info, and completions from the terminal.
|
|
48
|
+
- **🏢 Managed Server Lifecycle**: A background manager automatically handles language server processes, reusing them across requests for maximum performance.
|
|
49
|
+
- **🧩 LSAP Integration**: Leverages the Language Server Agent Protocol for structured, agent-friendly responses with built-in pagination and text-based location finding.
|
|
50
|
+
- **⚡ Async-First**: Built with `anyio` and `asyncer` for high-performance concurrent operations.
|
|
51
|
+
|
|
52
|
+
## Supported Languages
|
|
53
|
+
|
|
54
|
+
`lsp-cli` currently supports the following languages:
|
|
55
|
+
|
|
56
|
+
| Language | Language Server |
|
|
57
|
+
| :-------------------------- | :--------------------------- |
|
|
58
|
+
| **Python** | `basedpyright` |
|
|
59
|
+
| **Go** | `gopls` |
|
|
60
|
+
| **Rust** | `rust-analyzer` |
|
|
61
|
+
| **TypeScript / JavaScript** | `typescript-language-server` |
|
|
62
|
+
| **Deno** | `deno` |
|
|
63
|
+
|
|
64
|
+
More supported languages coming very soon!
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
uv tool install --python 3.13 lsp-cli
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Quick Start
|
|
71
|
+
|
|
72
|
+
The main entry point is the `lsp` command. It automatically detects the appropriate language server for your project.
|
|
73
|
+
|
|
74
|
+
### Find Definition
|
|
75
|
+
|
|
76
|
+
Find where a symbol is defined:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Using line scope
|
|
80
|
+
lsp definition --locate main.py:10
|
|
81
|
+
|
|
82
|
+
# Using text search to locate the symbol
|
|
83
|
+
lsp definition --locate "main.py@my_function<HERE>"
|
|
84
|
+
|
|
85
|
+
# Find declaration instead of definition
|
|
86
|
+
lsp definition --locate models.py:25 --decl
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Get Symbol Information
|
|
90
|
+
|
|
91
|
+
Get detailed information about a symbol at a specific location:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Get symbol info at line 15
|
|
95
|
+
lsp symbol --locate main.py:15
|
|
96
|
+
|
|
97
|
+
# Find and get symbol info
|
|
98
|
+
lsp symbol --locate "utils.py@UserClass<HERE>"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Find References
|
|
102
|
+
|
|
103
|
+
Find all references to a symbol:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Find references to a symbol at line 20
|
|
107
|
+
lsp reference --locate models.py:20
|
|
108
|
+
|
|
109
|
+
# Find references with text search
|
|
110
|
+
lsp reference --locate "models.py@UserClass<HERE>"
|
|
111
|
+
|
|
112
|
+
# Show more context lines around each reference
|
|
113
|
+
lsp reference --locate app.py:10 --context-lines 5
|
|
114
|
+
|
|
115
|
+
# Find implementations instead of references
|
|
116
|
+
lsp reference --locate interface.py:15 --impl
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Search Workspace Symbols
|
|
120
|
+
|
|
121
|
+
Search for symbols across the entire workspace by name:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
# Search for symbols containing "MyClass"
|
|
125
|
+
lsp search MyClass
|
|
126
|
+
|
|
127
|
+
# Search in a specific workspace
|
|
128
|
+
lsp search "UserModel" --workspace /path/to/project
|
|
129
|
+
|
|
130
|
+
# Filter by symbol kind
|
|
131
|
+
lsp search "test" --kind function --kind method
|
|
132
|
+
|
|
133
|
+
# Limit results
|
|
134
|
+
lsp search "Config" --max-items 10
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Get File Outline
|
|
138
|
+
|
|
139
|
+
Get a hierarchical outline of symbols in a file:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
# Get outline of main symbols (classes, functions, methods)
|
|
143
|
+
lsp outline main.py
|
|
144
|
+
|
|
145
|
+
# Include all symbols (variables, parameters, etc.)
|
|
146
|
+
lsp outline utils.py --all
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Get Hover Information
|
|
150
|
+
|
|
151
|
+
Get documentation and type information for a symbol:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Get hover info at a specific line
|
|
155
|
+
lsp hover --locate main.py:42
|
|
156
|
+
|
|
157
|
+
# Find symbol and get hover info
|
|
158
|
+
lsp hover --locate "models.py@process_data<HERE>"
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Commands
|
|
162
|
+
|
|
163
|
+
| Command | Description |
|
|
164
|
+
| ------------ | ------------------------------------------------------- |
|
|
165
|
+
| `definition` | Find symbol definition, declaration, or type definition |
|
|
166
|
+
| `hover` | Get hover information (type info, documentation) |
|
|
167
|
+
| `reference` | Find symbol references or implementations |
|
|
168
|
+
| `outline` | Get a structured symbol outline for a file |
|
|
169
|
+
| `symbol` | Get detailed symbol information at a specific location |
|
|
170
|
+
| `search` | Search for symbols across the entire workspace by name |
|
|
171
|
+
| `rename` | Rename a symbol across the workspace |
|
|
172
|
+
| `server` | Manage background LSP server processes |
|
|
173
|
+
| `locate` | Parse and verify a location string |
|
|
174
|
+
|
|
175
|
+
## Server Management
|
|
176
|
+
|
|
177
|
+
`lsp-cli` uses a **background manager process to keep language servers alive between command invocations**. This significantly reduces latency for repeated queries.
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
# List all running LSP servers
|
|
181
|
+
lsp server list
|
|
182
|
+
|
|
183
|
+
# Manually start a server for a path
|
|
184
|
+
lsp server start .
|
|
185
|
+
|
|
186
|
+
# Stop a server
|
|
187
|
+
lsp server stop .
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
The manager starts automatically when you run any analysis command.
|
|
191
|
+
|
|
192
|
+
## Usage Tips
|
|
193
|
+
|
|
194
|
+
### Locating Symbols
|
|
195
|
+
|
|
196
|
+
LSP CLI uses a unified `locate` string syntax (`-L` or `--locate`) to specify positions in your code. The format is `<file_path>[:<scope>][@<find>]`.
|
|
197
|
+
|
|
198
|
+
1. **Line-based**: Specify a line number (1-based)
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
lsp definition --locate main.py:42
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
2. **Range-based**: Specify a line range
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
lsp symbol --locate utils.py:10,20
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
3. **Text-based**: Search for text with a cursor marker `<HERE>` or `<|>`
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
lsp hover --locate "app.py@my_function<HERE>()"
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
4. **Symbol path**: Navigate using symbol hierarchy
|
|
217
|
+
```bash
|
|
218
|
+
lsp definition --locate models.py:UserClass.get_name
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Working with Results
|
|
222
|
+
|
|
223
|
+
Pagination for large result sets:
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
# Get first 50 results
|
|
227
|
+
lsp search "config" --max-items 50
|
|
228
|
+
|
|
229
|
+
# Get next page
|
|
230
|
+
lsp search "config" --max-items 50 --start-index 50
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Debugging
|
|
234
|
+
|
|
235
|
+
Enable debug mode to see detailed logs:
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
lsp --debug definition --locate main.py:10
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Configuration
|
|
242
|
+
|
|
243
|
+
`lsp-cli` can be configured via environment variables or a `config.toml` file.
|
|
244
|
+
|
|
245
|
+
- **Config File**: `~/.config/lsp-cli/config.toml` (on Linux) or `~/Library/Application Support/lsp-cli/config.toml` (on macOS).
|
|
246
|
+
- **Environment Variables**: Prefix with `LSP_` (e.g., `LSP_LOG_LEVEL=DEBUG`).
|
|
247
|
+
|
|
248
|
+
### Available Settings
|
|
249
|
+
|
|
250
|
+
Create a `config.toml` file at the location above with the following options:
|
|
251
|
+
|
|
252
|
+
```toml
|
|
253
|
+
# config.toml
|
|
254
|
+
|
|
255
|
+
# Enable debug mode (verbose logging)
|
|
256
|
+
debug = false
|
|
257
|
+
|
|
258
|
+
# Idle timeout for managed servers (in seconds)
|
|
259
|
+
idle_timeout = 600
|
|
260
|
+
|
|
261
|
+
# Log level: TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL
|
|
262
|
+
log_level = "INFO"
|
|
263
|
+
|
|
264
|
+
# Default maximum items for paginated results (search, reference, etc.)
|
|
265
|
+
# Set to null for no limit, or a number like 20
|
|
266
|
+
default_max_items = 20
|
|
267
|
+
|
|
268
|
+
# Default number of context lines for reference results
|
|
269
|
+
default_context_lines = 2
|
|
270
|
+
|
|
271
|
+
# Paths to ignore in search results (e.g., virtual environments, build directories)
|
|
272
|
+
ignore_paths = [".git", "node_modules", "venv", ".venv", "__pycache__", "dist", "build"]
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Environment Variables
|
|
276
|
+
|
|
277
|
+
All settings can be overridden via environment variables:
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
export LSP_DEBUG=true
|
|
281
|
+
export LSP_LOG_LEVEL=DEBUG
|
|
282
|
+
export LSP_DEFAULT_MAX_ITEMS=50
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Contributing
|
|
286
|
+
|
|
287
|
+
Contributions are welcome! Please see our [Contributing Guide](CONTRIBUTING.md) for details on:
|
|
288
|
+
|
|
289
|
+
- Development setup
|
|
290
|
+
- Adding new CLI commands
|
|
291
|
+
- Improving the server manager
|
|
292
|
+
- Development workflow
|
|
293
|
+
|
|
294
|
+
## License
|
|
295
|
+
|
|
296
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
297
|
+
|
|
298
|
+
## Acknowledgments
|
|
299
|
+
|
|
300
|
+
- [lsp-client](https://github.com/lsp-client/python-sdk): The underlying LSP client library.
|
|
301
|
+
- [LSAP](https://github.com/lsp-client/LSAP): The Language Server Agent Protocol.
|
|
302
|
+
- [lsprotocol](https://github.com/microsoft/lsprotocol): LSP type definitions.
|
lsp_cli-0.1.1/README.md
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
# LSP CLI
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/lsp-cli/)
|
|
4
|
+
[](https://python.org)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
> **⚠️ Windows Temporary Not Supported**
|
|
8
|
+
> Due to implementation details, `lsp-cli` does not currently support Windows. Support for Windows will be added in the next version.
|
|
9
|
+
|
|
10
|
+
A powerful command-line interface for the [**Language Server Agent Protocol (LSAP)**](https://github.com/lsp-client/LSAP). `lsp-cli` provides a bridge between traditional [Language Server Protocol (LSP)](https://microsoft.github.io/language-server-protocol/) servers and high-level agentic workflows, offering structured data access and a robust background server management system.
|
|
11
|
+
|
|
12
|
+
Built on top of [lsp-client](https://github.com/lsp-client/lsp-client) and [LSAP](https://github.com/lsp-client/LSAP), this tool is designed for developers and AI agents who need reliable, fast, and structured access to language intelligence.
|
|
13
|
+
|
|
14
|
+
## Key Features
|
|
15
|
+
|
|
16
|
+
- **🤖 Built for Agents**: The CLI output is optimized for Coding Agents. By avoiding fancy TUI/UI elements and rich terminal formatting, it significantly reduces token consumption while maintaining high readability for LLMs.
|
|
17
|
+
- **🚀 Instant Analysis**: Quickly get definitions, references, hover info, and completions from the terminal.
|
|
18
|
+
- **🏢 Managed Server Lifecycle**: A background manager automatically handles language server processes, reusing them across requests for maximum performance.
|
|
19
|
+
- **🧩 LSAP Integration**: Leverages the Language Server Agent Protocol for structured, agent-friendly responses with built-in pagination and text-based location finding.
|
|
20
|
+
- **⚡ Async-First**: Built with `anyio` and `asyncer` for high-performance concurrent operations.
|
|
21
|
+
|
|
22
|
+
## Supported Languages
|
|
23
|
+
|
|
24
|
+
`lsp-cli` currently supports the following languages:
|
|
25
|
+
|
|
26
|
+
| Language | Language Server |
|
|
27
|
+
| :-------------------------- | :--------------------------- |
|
|
28
|
+
| **Python** | `basedpyright` |
|
|
29
|
+
| **Go** | `gopls` |
|
|
30
|
+
| **Rust** | `rust-analyzer` |
|
|
31
|
+
| **TypeScript / JavaScript** | `typescript-language-server` |
|
|
32
|
+
| **Deno** | `deno` |
|
|
33
|
+
|
|
34
|
+
More supported languages coming very soon!
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
uv tool install --python 3.13 lsp-cli
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
The main entry point is the `lsp` command. It automatically detects the appropriate language server for your project.
|
|
43
|
+
|
|
44
|
+
### Find Definition
|
|
45
|
+
|
|
46
|
+
Find where a symbol is defined:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Using line scope
|
|
50
|
+
lsp definition --locate main.py:10
|
|
51
|
+
|
|
52
|
+
# Using text search to locate the symbol
|
|
53
|
+
lsp definition --locate "main.py@my_function<HERE>"
|
|
54
|
+
|
|
55
|
+
# Find declaration instead of definition
|
|
56
|
+
lsp definition --locate models.py:25 --decl
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Get Symbol Information
|
|
60
|
+
|
|
61
|
+
Get detailed information about a symbol at a specific location:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# Get symbol info at line 15
|
|
65
|
+
lsp symbol --locate main.py:15
|
|
66
|
+
|
|
67
|
+
# Find and get symbol info
|
|
68
|
+
lsp symbol --locate "utils.py@UserClass<HERE>"
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Find References
|
|
72
|
+
|
|
73
|
+
Find all references to a symbol:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Find references to a symbol at line 20
|
|
77
|
+
lsp reference --locate models.py:20
|
|
78
|
+
|
|
79
|
+
# Find references with text search
|
|
80
|
+
lsp reference --locate "models.py@UserClass<HERE>"
|
|
81
|
+
|
|
82
|
+
# Show more context lines around each reference
|
|
83
|
+
lsp reference --locate app.py:10 --context-lines 5
|
|
84
|
+
|
|
85
|
+
# Find implementations instead of references
|
|
86
|
+
lsp reference --locate interface.py:15 --impl
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Search Workspace Symbols
|
|
90
|
+
|
|
91
|
+
Search for symbols across the entire workspace by name:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Search for symbols containing "MyClass"
|
|
95
|
+
lsp search MyClass
|
|
96
|
+
|
|
97
|
+
# Search in a specific workspace
|
|
98
|
+
lsp search "UserModel" --workspace /path/to/project
|
|
99
|
+
|
|
100
|
+
# Filter by symbol kind
|
|
101
|
+
lsp search "test" --kind function --kind method
|
|
102
|
+
|
|
103
|
+
# Limit results
|
|
104
|
+
lsp search "Config" --max-items 10
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Get File Outline
|
|
108
|
+
|
|
109
|
+
Get a hierarchical outline of symbols in a file:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# Get outline of main symbols (classes, functions, methods)
|
|
113
|
+
lsp outline main.py
|
|
114
|
+
|
|
115
|
+
# Include all symbols (variables, parameters, etc.)
|
|
116
|
+
lsp outline utils.py --all
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Get Hover Information
|
|
120
|
+
|
|
121
|
+
Get documentation and type information for a symbol:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
# Get hover info at a specific line
|
|
125
|
+
lsp hover --locate main.py:42
|
|
126
|
+
|
|
127
|
+
# Find symbol and get hover info
|
|
128
|
+
lsp hover --locate "models.py@process_data<HERE>"
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Commands
|
|
132
|
+
|
|
133
|
+
| Command | Description |
|
|
134
|
+
| ------------ | ------------------------------------------------------- |
|
|
135
|
+
| `definition` | Find symbol definition, declaration, or type definition |
|
|
136
|
+
| `hover` | Get hover information (type info, documentation) |
|
|
137
|
+
| `reference` | Find symbol references or implementations |
|
|
138
|
+
| `outline` | Get a structured symbol outline for a file |
|
|
139
|
+
| `symbol` | Get detailed symbol information at a specific location |
|
|
140
|
+
| `search` | Search for symbols across the entire workspace by name |
|
|
141
|
+
| `rename` | Rename a symbol across the workspace |
|
|
142
|
+
| `server` | Manage background LSP server processes |
|
|
143
|
+
| `locate` | Parse and verify a location string |
|
|
144
|
+
|
|
145
|
+
## Server Management
|
|
146
|
+
|
|
147
|
+
`lsp-cli` uses a **background manager process to keep language servers alive between command invocations**. This significantly reduces latency for repeated queries.
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# List all running LSP servers
|
|
151
|
+
lsp server list
|
|
152
|
+
|
|
153
|
+
# Manually start a server for a path
|
|
154
|
+
lsp server start .
|
|
155
|
+
|
|
156
|
+
# Stop a server
|
|
157
|
+
lsp server stop .
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
The manager starts automatically when you run any analysis command.
|
|
161
|
+
|
|
162
|
+
## Usage Tips
|
|
163
|
+
|
|
164
|
+
### Locating Symbols
|
|
165
|
+
|
|
166
|
+
LSP CLI uses a unified `locate` string syntax (`-L` or `--locate`) to specify positions in your code. The format is `<file_path>[:<scope>][@<find>]`.
|
|
167
|
+
|
|
168
|
+
1. **Line-based**: Specify a line number (1-based)
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
lsp definition --locate main.py:42
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
2. **Range-based**: Specify a line range
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
lsp symbol --locate utils.py:10,20
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
3. **Text-based**: Search for text with a cursor marker `<HERE>` or `<|>`
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
lsp hover --locate "app.py@my_function<HERE>()"
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
4. **Symbol path**: Navigate using symbol hierarchy
|
|
187
|
+
```bash
|
|
188
|
+
lsp definition --locate models.py:UserClass.get_name
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Working with Results
|
|
192
|
+
|
|
193
|
+
Pagination for large result sets:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
# Get first 50 results
|
|
197
|
+
lsp search "config" --max-items 50
|
|
198
|
+
|
|
199
|
+
# Get next page
|
|
200
|
+
lsp search "config" --max-items 50 --start-index 50
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Debugging
|
|
204
|
+
|
|
205
|
+
Enable debug mode to see detailed logs:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
lsp --debug definition --locate main.py:10
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Configuration
|
|
212
|
+
|
|
213
|
+
`lsp-cli` can be configured via environment variables or a `config.toml` file.
|
|
214
|
+
|
|
215
|
+
- **Config File**: `~/.config/lsp-cli/config.toml` (on Linux) or `~/Library/Application Support/lsp-cli/config.toml` (on macOS).
|
|
216
|
+
- **Environment Variables**: Prefix with `LSP_` (e.g., `LSP_LOG_LEVEL=DEBUG`).
|
|
217
|
+
|
|
218
|
+
### Available Settings
|
|
219
|
+
|
|
220
|
+
Create a `config.toml` file at the location above with the following options:
|
|
221
|
+
|
|
222
|
+
```toml
|
|
223
|
+
# config.toml
|
|
224
|
+
|
|
225
|
+
# Enable debug mode (verbose logging)
|
|
226
|
+
debug = false
|
|
227
|
+
|
|
228
|
+
# Idle timeout for managed servers (in seconds)
|
|
229
|
+
idle_timeout = 600
|
|
230
|
+
|
|
231
|
+
# Log level: TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL
|
|
232
|
+
log_level = "INFO"
|
|
233
|
+
|
|
234
|
+
# Default maximum items for paginated results (search, reference, etc.)
|
|
235
|
+
# Set to null for no limit, or a number like 20
|
|
236
|
+
default_max_items = 20
|
|
237
|
+
|
|
238
|
+
# Default number of context lines for reference results
|
|
239
|
+
default_context_lines = 2
|
|
240
|
+
|
|
241
|
+
# Paths to ignore in search results (e.g., virtual environments, build directories)
|
|
242
|
+
ignore_paths = [".git", "node_modules", "venv", ".venv", "__pycache__", "dist", "build"]
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Environment Variables
|
|
246
|
+
|
|
247
|
+
All settings can be overridden via environment variables:
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
export LSP_DEBUG=true
|
|
251
|
+
export LSP_LOG_LEVEL=DEBUG
|
|
252
|
+
export LSP_DEFAULT_MAX_ITEMS=50
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Contributing
|
|
256
|
+
|
|
257
|
+
Contributions are welcome! Please see our [Contributing Guide](CONTRIBUTING.md) for details on:
|
|
258
|
+
|
|
259
|
+
- Development setup
|
|
260
|
+
- Adding new CLI commands
|
|
261
|
+
- Improving the server manager
|
|
262
|
+
- Development workflow
|
|
263
|
+
|
|
264
|
+
## License
|
|
265
|
+
|
|
266
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
267
|
+
|
|
268
|
+
## Acknowledgments
|
|
269
|
+
|
|
270
|
+
- [lsp-client](https://github.com/lsp-client/python-sdk): The underlying LSP client library.
|
|
271
|
+
- [LSAP](https://github.com/lsp-client/LSAP): The Language Server Agent Protocol.
|
|
272
|
+
- [lsprotocol](https://github.com/microsoft/lsprotocol): LSP type definitions.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "lsp-cli"
|
|
3
|
+
version = "0.1.1"
|
|
4
|
+
description = "A powerful command-line interface for the Language Server Agent Protocol (LSAP)"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [{ name = "observerw", email = "wozluohd@gmail.com" }]
|
|
7
|
+
requires-python = ">=3.13"
|
|
8
|
+
keywords = ["Language Server Protocol", "LSP", "CLI", "Developer Tools", "LSAP"]
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Programming Language :: Python",
|
|
11
|
+
"Programming Language :: Python :: 3.13",
|
|
12
|
+
"License :: OSI Approved :: MIT License",
|
|
13
|
+
"Operating System :: POSIX :: Linux",
|
|
14
|
+
"Operating System :: MacOS",
|
|
15
|
+
]
|
|
16
|
+
dependencies = [
|
|
17
|
+
"anyio>=4.12.0",
|
|
18
|
+
"asyncer>=0.0.12",
|
|
19
|
+
"attrs>=25.4.0",
|
|
20
|
+
"httpx>=0.28.1",
|
|
21
|
+
"loguru>=0.7.3",
|
|
22
|
+
"platformdirs>=4.5.1",
|
|
23
|
+
"pydantic>=2.12.5",
|
|
24
|
+
"pydantic-settings>=2.12.0",
|
|
25
|
+
"typer>=0.20.1",
|
|
26
|
+
"uvicorn>=0.40.0",
|
|
27
|
+
"litestar>=2.19.0",
|
|
28
|
+
"xxhash>=3.6.0",
|
|
29
|
+
"tenacity>=9.1.2",
|
|
30
|
+
"lsp-client>=0.3.0",
|
|
31
|
+
"lsap-sdk>=0.1.0",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.scripts]
|
|
35
|
+
lsp = "lsp_cli.__main__:run"
|
|
36
|
+
|
|
37
|
+
[build-system]
|
|
38
|
+
requires = ["uv_build>=0.9.9,<0.10.0"]
|
|
39
|
+
build-backend = "uv_build"
|
|
40
|
+
|
|
41
|
+
[dependency-groups]
|
|
42
|
+
dev = [
|
|
43
|
+
"pytest>=9.0.2",
|
|
44
|
+
"pytest-asyncio>=1.3.0",
|
|
45
|
+
"pytest-mock>=3.15.1",
|
|
46
|
+
"ruff>=0.14.10",
|
|
47
|
+
"ty>=0.0.8",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
[tool.pytest.ini_options]
|
|
51
|
+
norecursedirs = ["references"]
|
|
File without changes
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
import typer
|
|
5
|
+
|
|
6
|
+
from lsp_cli.cli import (
|
|
7
|
+
definition,
|
|
8
|
+
hover,
|
|
9
|
+
locate,
|
|
10
|
+
outline,
|
|
11
|
+
reference,
|
|
12
|
+
rename,
|
|
13
|
+
search,
|
|
14
|
+
symbol,
|
|
15
|
+
)
|
|
16
|
+
from lsp_cli.cli.main import main_callback
|
|
17
|
+
from lsp_cli.cli.shared import get_msg
|
|
18
|
+
from lsp_cli.server import app as server_app
|
|
19
|
+
from lsp_cli.settings import settings
|
|
20
|
+
|
|
21
|
+
app = typer.Typer(
|
|
22
|
+
help="LSP CLI: A command-line tool for interacting with Language Server Protocol (LSP) features.",
|
|
23
|
+
context_settings={
|
|
24
|
+
"help_option_names": ["-h", "--help"],
|
|
25
|
+
"max_content_width": 1000,
|
|
26
|
+
"terminal_width": 1000,
|
|
27
|
+
},
|
|
28
|
+
add_completion=False,
|
|
29
|
+
rich_markup_mode=None,
|
|
30
|
+
pretty_exceptions_enable=False,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
# Set callback
|
|
34
|
+
app.callback(invoke_without_command=True)(main_callback)
|
|
35
|
+
|
|
36
|
+
# Add sub-typers
|
|
37
|
+
app.add_typer(server_app)
|
|
38
|
+
app.add_typer(rename.app)
|
|
39
|
+
app.add_typer(definition.app)
|
|
40
|
+
app.add_typer(hover.app)
|
|
41
|
+
app.add_typer(locate.app)
|
|
42
|
+
app.add_typer(reference.app)
|
|
43
|
+
app.add_typer(outline.app)
|
|
44
|
+
app.add_typer(symbol.app)
|
|
45
|
+
app.add_typer(search.app)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def run():
|
|
49
|
+
# Suppress httpx INFO logs in CLI (unless debug mode)
|
|
50
|
+
if not settings.debug:
|
|
51
|
+
logging.getLogger("httpx").setLevel(logging.WARNING)
|
|
52
|
+
|
|
53
|
+
try:
|
|
54
|
+
app()
|
|
55
|
+
except (typer.Exit, typer.Abort):
|
|
56
|
+
pass
|
|
57
|
+
except Exception as e:
|
|
58
|
+
if settings.debug:
|
|
59
|
+
raise e
|
|
60
|
+
print(f"Error: {get_msg(e)}", file=sys.stderr)
|
|
61
|
+
sys.exit(1)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if __name__ == "__main__":
|
|
65
|
+
run()
|
|
File without changes
|