client
code_context_agent.tools.lsp.client ¶
LSP JSON-RPC client over stdio.
This module implements a Language Server Protocol client that communicates with language servers using JSON-RPC 2.0 over stdio with Content-Length framing.
Reference: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/
LspClient ¶
LSP client using JSON-RPC 2.0 over stdio.
This client manages communication with an LSP server subprocess, handling the Content-Length message framing and request/response correlation.
Attributes:
| Name | Type | Description |
|---|---|---|
workspace_path | str | Path to the workspace root. |
server_cmd | list[str] | Command to start the LSP server. |
Example
client = LspClient() await client.start(["typescript-language-server", "--stdio"], "/path/to/workspace") symbols = await client.document_symbols("/path/to/file.ts") await client.shutdown()
Initialize the LSP client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_timeout | float | Timeout in seconds for LSP requests (default 30.0). | 30.0 |
workspace_settings | dict[str, Any] | None | Settings dict used to respond to workspace/configuration requests from the server. Keys are dot-notation sections (e.g., | None |
Source code in src/code_context_agent/tools/lsp/client.py
start async ¶
Start LSP server and initialize the connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server_cmd | list[str] | Command and arguments to start the LSP server. | required |
workspace_path | str | Absolute path to the workspace root. | required |
startup_timeout | float | Maximum seconds to wait for server initialization. | 30.0 |
initialization_options | dict[str, Any] | None | Optional initialization options for the server. | None |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Server capabilities from the initialize response. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If server fails to start or initialize within timeout. |
Source code in src/code_context_agent/tools/lsp/client.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
did_open async ¶
Notify server that a document was opened.
Skips the notification if the document was already opened (unless force=True), avoiding redundant file reads and server re-parsing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path | str | Absolute path to the file. | required |
language_id | str | None | Language identifier (auto-detected if not provided). | None |
force | bool | If True, re-send didOpen even if already tracked. | False |
Raises:
| Type | Description |
|---|---|
FileNotFoundError | If the file does not exist. |
Source code in src/code_context_agent/tools/lsp/client.py
document_symbols async ¶
Get document symbols (outline).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path | str | Absolute path to the file. | required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | List of DocumentSymbol or SymbolInformation objects. |
Source code in src/code_context_agent/tools/lsp/client.py
hover async ¶
Get hover information at position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path | str | Absolute path to the file. | required |
line | int | 0-indexed line number. | required |
character | int | 0-indexed column number. | required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None | Hover information with contents, or None if not available. |
Source code in src/code_context_agent/tools/lsp/client.py
references async ¶
Find all references to symbol at position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path | str | Absolute path to the file. | required |
line | int | 0-indexed line number. | required |
character | int | 0-indexed column number. | required |
include_declaration | bool | Whether to include the declaration. | True |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | List of Location objects with uri and range. |
Source code in src/code_context_agent/tools/lsp/client.py
definition async ¶
Go to definition of symbol at position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path | str | Absolute path to the file. | required |
line | int | 0-indexed line number. | required |
character | int | 0-indexed column number. | required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | List of Location objects. |
Source code in src/code_context_agent/tools/lsp/client.py
workspace_symbols async ¶
Search for workspace symbols matching query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query | str | Search query string (partial name matching). | required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | List of SymbolInformation objects. |
Source code in src/code_context_agent/tools/lsp/client.py
diagnostics async ¶
Get diagnostics for a file. Uses textDocument/diagnostic (pull model).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_uri | str | File URI (file:///path/to/file). | required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | List of Diagnostic objects. |
Source code in src/code_context_agent/tools/lsp/client.py
shutdown async ¶
Shutdown the LSP server gracefully.