2026-07-13 08:12:02 +07:00
|
|
|
#![allow(clippy::cast_possible_truncation, clippy::cast_sign_loss, clippy::cast_precision_loss, clippy::cast_possible_wrap)]
|
|
|
|
|
use std::fmt::Write;
|
2026-07-12 13:40:58 +07:00
|
|
|
use serde_json::{json, Value};
|
|
|
|
|
use anyhow::{Result, anyhow};
|
|
|
|
|
|
|
|
|
|
use crate::tool::{Tool, ToolCtx};
|
|
|
|
|
use crate::app::lsp::path_to_lsp_uri;
|
|
|
|
|
|
|
|
|
|
pub struct LspConnect;
|
|
|
|
|
|
|
|
|
|
impl Tool for LspConnect {
|
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
|
"lsp_connect"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn description(&self) -> &'static str {
|
2026-07-12 14:47:01 +07:00
|
|
|
"Connect to a Language Server Protocol (LSP) server for a programming language. \
|
|
|
|
|
Known file extensions for the language are auto-registered, enabling other lsp_* \
|
|
|
|
|
tools to auto-detect this server when `server` is omitted."
|
2026-07-12 13:40:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn parameters(&self) -> Value {
|
|
|
|
|
json!({
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
|
|
|
|
"name": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"description": "Short name for this LSP connection (e.g. 'rust', 'typescript')"
|
|
|
|
|
},
|
|
|
|
|
"command": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"description": "The LSP server binary to spawn (e.g. 'rust-analyzer', 'typescript-language-server')"
|
|
|
|
|
},
|
|
|
|
|
"args": {
|
|
|
|
|
"type": "array",
|
|
|
|
|
"items": { "type": "string" },
|
|
|
|
|
"description": "Command-line arguments for the LSP server"
|
|
|
|
|
},
|
|
|
|
|
"language_id": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"description": "Language identifier (e.g. 'rust', 'typescript', 'python')"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"required": ["name", "command", "language_id"]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String> {
|
|
|
|
|
let name = args.get("name")
|
|
|
|
|
.and_then(|v| v.as_str())
|
|
|
|
|
.ok_or_else(|| anyhow!("missing required argument: name"))?;
|
|
|
|
|
let command = args.get("command")
|
|
|
|
|
.and_then(|v| v.as_str())
|
|
|
|
|
.ok_or_else(|| anyhow!("missing required argument: command"))?;
|
|
|
|
|
let language_id = args.get("language_id")
|
|
|
|
|
.and_then(|v| v.as_str())
|
|
|
|
|
.ok_or_else(|| anyhow!("missing required argument: language_id"))?;
|
|
|
|
|
let extra_args: Vec<String> = args.get("args")
|
|
|
|
|
.and_then(|v| v.as_array())
|
|
|
|
|
.map(|arr| arr.iter().filter_map(|v| v.as_str().map(String::from)).collect())
|
|
|
|
|
.unwrap_or_default();
|
|
|
|
|
|
|
|
|
|
let mut manager = ctx.lsp_manager.lock()
|
2026-07-13 08:12:02 +07:00
|
|
|
.map_err(|e| anyhow!("LSP manager lock error: {e}"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
manager.connect(name, command, &extra_args, language_id)?;
|
|
|
|
|
|
2026-07-12 14:47:01 +07:00
|
|
|
// Auto-register this server's known extensions so lsp_diagnostics /
|
|
|
|
|
// lsp_hover / lsp_completion / lsp_definition / lsp_references can
|
|
|
|
|
// auto-detect it later without an explicit `server` argument.
|
|
|
|
|
let known_exts = known_extensions_for(language_id);
|
|
|
|
|
if !known_exts.is_empty() {
|
|
|
|
|
manager.register_extensions(name, known_exts);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-12 13:40:58 +07:00
|
|
|
let client_arc = manager.get_client(name);
|
2026-07-12 14:47:01 +07:00
|
|
|
let caps = client_arc.and_then(|c| {
|
2026-07-12 13:40:58 +07:00
|
|
|
c.lock().ok().map(|guard| guard.server_capabilities().clone())
|
2026-07-12 14:47:01 +07:00
|
|
|
}).unwrap_or_default();
|
2026-07-12 13:40:58 +07:00
|
|
|
|
|
|
|
|
let caps_summary = serde_json::to_string_pretty(&caps)
|
|
|
|
|
.unwrap_or_else(|_| "{}".to_string());
|
|
|
|
|
|
|
|
|
|
Ok(format!(
|
2026-07-13 08:12:02 +07:00
|
|
|
"Connected to LSP server '{name}' (language: {language_id})\nServer capabilities:\n{caps_summary}"
|
2026-07-12 13:40:58 +07:00
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct LspDiagnostics;
|
|
|
|
|
|
|
|
|
|
impl Tool for LspDiagnostics {
|
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
|
"lsp_diagnostics"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn description(&self) -> &'static str {
|
2026-07-12 14:47:01 +07:00
|
|
|
"Get diagnostics (errors, warnings, hints) for a file from an LSP server. \
|
|
|
|
|
`server` is optional — if omitted, the server is auto-detected from the file's extension."
|
2026-07-12 13:40:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn parameters(&self) -> Value {
|
|
|
|
|
json!({
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
|
|
|
|
"server": {
|
|
|
|
|
"type": "string",
|
2026-07-12 14:47:01 +07:00
|
|
|
"description": "Name of the connected LSP server. Optional — auto-detected from the file extension if omitted."
|
2026-07-12 13:40:58 +07:00
|
|
|
},
|
|
|
|
|
"path": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"description": "Path to the file to analyze (relative to workspace root)"
|
|
|
|
|
},
|
|
|
|
|
"text": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"description": "The full text content of the file"
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-07-12 14:47:01 +07:00
|
|
|
"required": ["path", "text"]
|
2026-07-12 13:40:58 +07:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String> {
|
|
|
|
|
let rel_path = args.get("path")
|
|
|
|
|
.and_then(|v| v.as_str())
|
|
|
|
|
.ok_or_else(|| anyhow!("missing required argument: path"))?;
|
|
|
|
|
let text = args.get("text")
|
|
|
|
|
.and_then(|v| v.as_str())
|
|
|
|
|
.ok_or_else(|| anyhow!("missing required argument: text"))?;
|
2026-07-12 14:47:01 +07:00
|
|
|
let server_name = resolve_server_name(ctx, args, rel_path)?;
|
|
|
|
|
let server_name = server_name.as_str();
|
2026-07-12 13:40:58 +07:00
|
|
|
|
|
|
|
|
let abs_path = crate::tool::resolve_path(&ctx.workspaces, rel_path)?;
|
|
|
|
|
let uri = path_to_lsp_uri(&abs_path.to_string_lossy());
|
|
|
|
|
|
|
|
|
|
let manager = ctx.lsp_manager.lock()
|
2026-07-13 08:12:02 +07:00
|
|
|
.map_err(|e| anyhow!("LSP manager lock error: {e}"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
let language_id = manager.get_language_id(server_name)
|
2026-07-13 08:12:02 +07:00
|
|
|
.ok_or_else(|| anyhow!("LSP server '{server_name}' not found. Use lsp_connect first."))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
let client_arc = manager.get_client(server_name)
|
2026-07-13 08:12:02 +07:00
|
|
|
.ok_or_else(|| anyhow!("LSP server '{server_name}' not found"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
drop(manager);
|
|
|
|
|
|
|
|
|
|
let mut client = client_arc.lock()
|
2026-07-13 08:12:02 +07:00
|
|
|
.map_err(|e| anyhow!("LSP client lock error: {e}"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
|
|
|
|
|
match client.collect_diagnostics(&uri, &language_id, text) {
|
|
|
|
|
Ok(diags) => {
|
|
|
|
|
let diags_array = diags.as_array().cloned().unwrap_or_default();
|
|
|
|
|
if diags_array.is_empty() {
|
|
|
|
|
return Ok("No diagnostics found for this file.".to_string());
|
|
|
|
|
}
|
|
|
|
|
let mut output = String::from("Diagnostics:\n");
|
|
|
|
|
for d in &diags_array {
|
|
|
|
|
let range = d.get("range").and_then(|r| r.get("start"));
|
2026-07-13 08:12:02 +07:00
|
|
|
let severity = match d.get("severity").and_then(serde_json::Value::as_i64).unwrap_or(0) {
|
2026-07-12 13:40:58 +07:00
|
|
|
1 => "ERROR",
|
|
|
|
|
2 => "WARNING",
|
|
|
|
|
3 => "INFO",
|
|
|
|
|
4 => "HINT",
|
|
|
|
|
_ => "NOTE",
|
|
|
|
|
};
|
|
|
|
|
let message = d.get("message").and_then(|m| m.as_str()).unwrap_or("?");
|
2026-07-13 08:12:02 +07:00
|
|
|
let line = range.and_then(|r| r.get("line")).and_then(serde_json::Value::as_i64).unwrap_or(0);
|
|
|
|
|
let col = range.and_then(|r| r.get("character")).and_then(serde_json::Value::as_i64).unwrap_or(0);
|
2026-07-12 13:40:58 +07:00
|
|
|
let code = d.get("code")
|
|
|
|
|
.and_then(|c| c.as_str().or_else(|| c.as_i64().map(|n| Box::leak(Box::new(n.to_string()))).map(|s| s.as_str())))
|
|
|
|
|
.unwrap_or("");
|
2026-07-13 08:12:02 +07:00
|
|
|
let code_str = if code.is_empty() { String::new() } else { format!(" [{code}]") };
|
|
|
|
|
writeln!(output, " {}:{}:{} - {}{}: {}", rel_path, line + 1, col, severity, code_str, message).unwrap();
|
2026-07-12 13:40:58 +07:00
|
|
|
}
|
|
|
|
|
Ok(output)
|
|
|
|
|
}
|
|
|
|
|
Err(e) => {
|
|
|
|
|
if e.to_string().contains("timed out") {
|
|
|
|
|
Ok("Diagnostics request timed out. The server may still be initializing. Try again in a moment.".to_string())
|
|
|
|
|
} else {
|
|
|
|
|
Err(e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct LspHover;
|
|
|
|
|
|
|
|
|
|
impl Tool for LspHover {
|
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
|
"lsp_hover"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn description(&self) -> &'static str {
|
2026-07-12 14:47:01 +07:00
|
|
|
"Get hover information (type signature, documentation) at a cursor position in a file. \
|
|
|
|
|
`server` is optional — if omitted, the server is auto-detected from the file's extension."
|
2026-07-12 13:40:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn parameters(&self) -> Value {
|
|
|
|
|
json!({
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
|
|
|
|
"server": {
|
|
|
|
|
"type": "string",
|
2026-07-12 14:47:01 +07:00
|
|
|
"description": "Name of the connected LSP server. Optional — auto-detected from the file extension if omitted."
|
2026-07-12 13:40:58 +07:00
|
|
|
},
|
|
|
|
|
"path": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"description": "Path to the file (relative to workspace root)"
|
|
|
|
|
},
|
|
|
|
|
"line": {
|
|
|
|
|
"type": "integer",
|
|
|
|
|
"description": "Line number (0-based)"
|
|
|
|
|
},
|
|
|
|
|
"column": {
|
|
|
|
|
"type": "integer",
|
|
|
|
|
"description": "Column number (0-based)"
|
|
|
|
|
},
|
|
|
|
|
"language_id": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"description": "Language identifier (e.g. 'rust', 'typescript'). Optional if already set via lsp_connect."
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-07-12 14:47:01 +07:00
|
|
|
"required": ["path", "line", "column"]
|
2026-07-12 13:40:58 +07:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String> {
|
|
|
|
|
let rel_path = args.get("path")
|
|
|
|
|
.and_then(|v| v.as_str())
|
|
|
|
|
.ok_or_else(|| anyhow!("missing required argument: path"))?;
|
|
|
|
|
let line = args.get("line")
|
2026-07-13 08:12:02 +07:00
|
|
|
.and_then(serde_json::Value::as_i64)
|
2026-07-12 13:40:58 +07:00
|
|
|
.ok_or_else(|| anyhow!("missing required argument: line"))? as u32;
|
|
|
|
|
let column = args.get("column")
|
2026-07-13 08:12:02 +07:00
|
|
|
.and_then(serde_json::Value::as_i64)
|
2026-07-12 13:40:58 +07:00
|
|
|
.ok_or_else(|| anyhow!("missing required argument: column"))? as u32;
|
2026-07-12 14:47:01 +07:00
|
|
|
let server_name = resolve_server_name(ctx, args, rel_path)?;
|
|
|
|
|
let server_name = server_name.as_str();
|
2026-07-12 13:40:58 +07:00
|
|
|
|
|
|
|
|
let abs_path = crate::tool::resolve_path(&ctx.workspaces, rel_path)?;
|
|
|
|
|
let uri = path_to_lsp_uri(&abs_path.to_string_lossy());
|
|
|
|
|
|
|
|
|
|
let file_content = std::fs::read_to_string(&abs_path)
|
2026-07-13 08:12:02 +07:00
|
|
|
.map_err(|e| anyhow!("failed to read file '{rel_path}': {e}"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
|
|
|
|
|
let manager = ctx.lsp_manager.lock()
|
2026-07-13 08:12:02 +07:00
|
|
|
.map_err(|e| anyhow!("LSP manager lock error: {e}"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
let language_id = manager.get_language_id(server_name)
|
|
|
|
|
.unwrap_or_else(|| {
|
|
|
|
|
args.get("language_id").and_then(|v| v.as_str()).unwrap_or("plaintext").to_string()
|
|
|
|
|
});
|
|
|
|
|
let client_arc = manager.get_client(server_name)
|
2026-07-13 08:12:02 +07:00
|
|
|
.ok_or_else(|| anyhow!("LSP server '{server_name}' not found. Use lsp_connect first."))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
drop(manager);
|
|
|
|
|
|
|
|
|
|
let mut client = client_arc.lock()
|
2026-07-13 08:12:02 +07:00
|
|
|
.map_err(|e| anyhow!("LSP client lock error: {e}"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
|
|
|
|
|
client.did_open(&uri, &language_id, 1, &file_content)?;
|
|
|
|
|
let result = client.hover(&uri, line, column);
|
|
|
|
|
let _ = client.did_close(&uri);
|
|
|
|
|
|
|
|
|
|
match result {
|
|
|
|
|
Ok(hover_result) => {
|
|
|
|
|
if hover_result == Value::Null {
|
|
|
|
|
return Ok("No hover information available at this position.".to_string());
|
|
|
|
|
}
|
|
|
|
|
let contents = hover_result.get("contents");
|
|
|
|
|
let range = hover_result.get("range");
|
|
|
|
|
let mut output = String::new();
|
|
|
|
|
if let Some(range_val) = range {
|
|
|
|
|
if let Some(start) = range_val.get("start") {
|
2026-07-13 08:12:02 +07:00
|
|
|
let rl = start.get("line").and_then(serde_json::Value::as_i64).unwrap_or(0);
|
|
|
|
|
let rc = start.get("character").and_then(serde_json::Value::as_i64).unwrap_or(0);
|
|
|
|
|
writeln!(output, "Range: {}:{}", rl + 1, rc + 1).unwrap();
|
2026-07-12 13:40:58 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if let Some(contents_val) = contents {
|
|
|
|
|
output.push_str(&format_hover_contents(contents_val));
|
|
|
|
|
} else {
|
|
|
|
|
output.push_str(&serde_json::to_string_pretty(&hover_result).unwrap_or_default());
|
|
|
|
|
}
|
|
|
|
|
Ok(output)
|
|
|
|
|
}
|
|
|
|
|
Err(e) => Err(e),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn format_hover_contents(contents: &Value) -> String {
|
|
|
|
|
let mut out = String::new();
|
|
|
|
|
match contents {
|
|
|
|
|
Value::String(s) => {
|
|
|
|
|
out.push_str(s);
|
|
|
|
|
}
|
|
|
|
|
Value::Object(map) => {
|
|
|
|
|
if let Some(kind) = map.get("kind").and_then(|k| k.as_str()) {
|
2026-07-13 08:12:02 +07:00
|
|
|
write!(out, "[{kind}] ").unwrap();
|
2026-07-12 13:40:58 +07:00
|
|
|
}
|
|
|
|
|
if let Some(value) = map.get("value").and_then(|v| v.as_str()) {
|
|
|
|
|
out.push_str(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Value::Array(arr) => {
|
|
|
|
|
for (i, item) in arr.iter().enumerate() {
|
|
|
|
|
if i > 0 {
|
|
|
|
|
out.push('\n');
|
|
|
|
|
}
|
|
|
|
|
out.push_str(&format_hover_contents(item));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => {
|
|
|
|
|
out.push_str(&serde_json::to_string_pretty(contents).unwrap_or_default());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
out
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct LspCompletion;
|
|
|
|
|
|
|
|
|
|
impl Tool for LspCompletion {
|
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
|
"lsp_completion"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn description(&self) -> &'static str {
|
2026-07-12 14:47:01 +07:00
|
|
|
"Get code completion suggestions at a cursor position from an LSP server. \
|
|
|
|
|
`server` is optional — if omitted, the server is auto-detected from the file's extension."
|
2026-07-12 13:40:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn parameters(&self) -> Value {
|
|
|
|
|
json!({
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
|
|
|
|
"server": {
|
|
|
|
|
"type": "string",
|
2026-07-12 14:47:01 +07:00
|
|
|
"description": "Name of the connected LSP server. Optional — auto-detected from the file extension if omitted."
|
2026-07-12 13:40:58 +07:00
|
|
|
},
|
|
|
|
|
"path": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"description": "Path to the file (relative to workspace root)"
|
|
|
|
|
},
|
|
|
|
|
"line": {
|
|
|
|
|
"type": "integer",
|
|
|
|
|
"description": "Line number (0-based)"
|
|
|
|
|
},
|
|
|
|
|
"column": {
|
|
|
|
|
"type": "integer",
|
|
|
|
|
"description": "Column number (0-based)"
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-07-12 14:47:01 +07:00
|
|
|
"required": ["path", "line", "column"]
|
2026-07-12 13:40:58 +07:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String> {
|
|
|
|
|
let rel_path = args.get("path")
|
|
|
|
|
.and_then(|v| v.as_str())
|
|
|
|
|
.ok_or_else(|| anyhow!("missing required argument: path"))?;
|
|
|
|
|
let line = args.get("line")
|
2026-07-13 08:12:02 +07:00
|
|
|
.and_then(serde_json::Value::as_i64)
|
2026-07-12 13:40:58 +07:00
|
|
|
.ok_or_else(|| anyhow!("missing required argument: line"))? as u32;
|
|
|
|
|
let column = args.get("column")
|
2026-07-13 08:12:02 +07:00
|
|
|
.and_then(serde_json::Value::as_i64)
|
2026-07-12 13:40:58 +07:00
|
|
|
.ok_or_else(|| anyhow!("missing required argument: column"))? as u32;
|
2026-07-12 14:47:01 +07:00
|
|
|
let server_name = resolve_server_name(ctx, args, rel_path)?;
|
|
|
|
|
let server_name = server_name.as_str();
|
2026-07-12 13:40:58 +07:00
|
|
|
|
|
|
|
|
let abs_path = crate::tool::resolve_path(&ctx.workspaces, rel_path)?;
|
|
|
|
|
let uri = path_to_lsp_uri(&abs_path.to_string_lossy());
|
|
|
|
|
|
|
|
|
|
let file_content = std::fs::read_to_string(&abs_path)
|
2026-07-13 08:12:02 +07:00
|
|
|
.map_err(|e| anyhow!("failed to read file '{rel_path}': {e}"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
|
|
|
|
|
let manager = ctx.lsp_manager.lock()
|
2026-07-13 08:12:02 +07:00
|
|
|
.map_err(|e| anyhow!("LSP manager lock error: {e}"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
let language_id = manager.get_language_id(server_name)
|
|
|
|
|
.unwrap_or_else(|| "plaintext".to_string());
|
|
|
|
|
let client_arc = manager.get_client(server_name)
|
2026-07-13 08:12:02 +07:00
|
|
|
.ok_or_else(|| anyhow!("LSP server '{server_name}' not found. Use lsp_connect first."))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
drop(manager);
|
|
|
|
|
|
|
|
|
|
let mut client = client_arc.lock()
|
2026-07-13 08:12:02 +07:00
|
|
|
.map_err(|e| anyhow!("LSP client lock error: {e}"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
|
|
|
|
|
client.did_open(&uri, &language_id, 1, &file_content)?;
|
|
|
|
|
let result = client.completion(&uri, line, column);
|
|
|
|
|
let _ = client.did_close(&uri);
|
|
|
|
|
|
|
|
|
|
match result {
|
|
|
|
|
Ok(completion_result) => {
|
|
|
|
|
let items = if let Some(items) = completion_result.as_array() {
|
|
|
|
|
items.clone()
|
|
|
|
|
} else if let Some(arr) = completion_result.get("items").and_then(|v| v.as_array()) {
|
|
|
|
|
arr.clone()
|
|
|
|
|
} else {
|
|
|
|
|
Vec::new()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if items.is_empty() {
|
|
|
|
|
return Ok("No completions available at this position.".to_string());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut output = format!("{} completion suggestions at {}:{}:\n", items.len(), line + 1, column + 1);
|
|
|
|
|
for (i, item) in items.iter().enumerate().take(50) {
|
|
|
|
|
let label = item.get("label").and_then(|l| l.as_str()).unwrap_or("?");
|
2026-07-13 08:12:02 +07:00
|
|
|
let kind = match item.get("kind").and_then(serde_json::Value::as_i64).unwrap_or(0) {
|
2026-07-12 13:40:58 +07:00
|
|
|
1 => "Text",
|
|
|
|
|
2 => "Method",
|
|
|
|
|
3 => "Function",
|
|
|
|
|
4 => "Constructor",
|
|
|
|
|
5 => "Field",
|
|
|
|
|
6 => "Variable",
|
|
|
|
|
7 => "Class",
|
|
|
|
|
8 => "Interface",
|
|
|
|
|
9 => "Module",
|
|
|
|
|
10 => "Property",
|
|
|
|
|
11 => "Unit",
|
|
|
|
|
12 => "Value",
|
|
|
|
|
13 => "Enum",
|
|
|
|
|
14 => "Keyword",
|
|
|
|
|
15 => "Snippet",
|
|
|
|
|
16 => "Color",
|
|
|
|
|
17 => "File",
|
|
|
|
|
18 => "Reference",
|
|
|
|
|
19 => "Folder",
|
|
|
|
|
20 => "EnumMember",
|
|
|
|
|
21 => "Constant",
|
|
|
|
|
22 => "Struct",
|
|
|
|
|
23 => "Event",
|
|
|
|
|
24 => "Operator",
|
|
|
|
|
25 => "TypeParameter",
|
|
|
|
|
_ => "Other",
|
|
|
|
|
};
|
|
|
|
|
let detail = item.get("detail").and_then(|d| d.as_str()).unwrap_or("");
|
2026-07-13 08:12:02 +07:00
|
|
|
let detail_str = if detail.is_empty() { String::new() } else { format!(" - {detail}") };
|
|
|
|
|
writeln!(output, " {}. [{}] {}{}", i + 1, kind, label, detail_str).unwrap();
|
2026-07-12 13:40:58 +07:00
|
|
|
}
|
|
|
|
|
if items.len() > 50 {
|
2026-07-13 08:12:02 +07:00
|
|
|
writeln!(output, " ... and {} more", items.len() - 50).unwrap();
|
2026-07-12 13:40:58 +07:00
|
|
|
}
|
|
|
|
|
Ok(output)
|
|
|
|
|
}
|
|
|
|
|
Err(e) => Err(e),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct LspDefinition;
|
|
|
|
|
|
|
|
|
|
impl Tool for LspDefinition {
|
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
|
"lsp_definition"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn description(&self) -> &'static str {
|
2026-07-12 14:47:01 +07:00
|
|
|
"Go to definition: find the location where a symbol is defined. \
|
|
|
|
|
`server` is optional — if omitted, the server is auto-detected from the file's extension."
|
2026-07-12 13:40:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn parameters(&self) -> Value {
|
|
|
|
|
json!({
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
|
|
|
|
"server": {
|
|
|
|
|
"type": "string",
|
2026-07-12 14:47:01 +07:00
|
|
|
"description": "Name of the connected LSP server. Optional — auto-detected from the file extension if omitted."
|
2026-07-12 13:40:58 +07:00
|
|
|
},
|
|
|
|
|
"path": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"description": "Path to the file (relative to workspace root)"
|
|
|
|
|
},
|
|
|
|
|
"line": {
|
|
|
|
|
"type": "integer",
|
|
|
|
|
"description": "Line number (0-based)"
|
|
|
|
|
},
|
|
|
|
|
"column": {
|
|
|
|
|
"type": "integer",
|
|
|
|
|
"description": "Column number (0-based)"
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-07-12 14:47:01 +07:00
|
|
|
"required": ["path", "line", "column"]
|
2026-07-12 13:40:58 +07:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String> {
|
|
|
|
|
let rel_path = args.get("path")
|
|
|
|
|
.and_then(|v| v.as_str())
|
|
|
|
|
.ok_or_else(|| anyhow!("missing required argument: path"))?;
|
|
|
|
|
let line = args.get("line")
|
2026-07-13 08:12:02 +07:00
|
|
|
.and_then(serde_json::Value::as_i64)
|
2026-07-12 13:40:58 +07:00
|
|
|
.ok_or_else(|| anyhow!("missing required argument: line"))? as u32;
|
|
|
|
|
let column = args.get("column")
|
2026-07-13 08:12:02 +07:00
|
|
|
.and_then(serde_json::Value::as_i64)
|
2026-07-12 13:40:58 +07:00
|
|
|
.ok_or_else(|| anyhow!("missing required argument: column"))? as u32;
|
2026-07-12 14:47:01 +07:00
|
|
|
let server_name = resolve_server_name(ctx, args, rel_path)?;
|
|
|
|
|
let server_name = server_name.as_str();
|
2026-07-12 13:40:58 +07:00
|
|
|
|
|
|
|
|
let abs_path = crate::tool::resolve_path(&ctx.workspaces, rel_path)?;
|
|
|
|
|
let uri = path_to_lsp_uri(&abs_path.to_string_lossy());
|
|
|
|
|
|
|
|
|
|
let file_content = std::fs::read_to_string(&abs_path)
|
2026-07-13 08:12:02 +07:00
|
|
|
.map_err(|e| anyhow!("failed to read file '{rel_path}': {e}"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
|
|
|
|
|
let manager = ctx.lsp_manager.lock()
|
2026-07-13 08:12:02 +07:00
|
|
|
.map_err(|e| anyhow!("LSP manager lock error: {e}"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
let language_id = manager.get_language_id(server_name)
|
|
|
|
|
.unwrap_or_else(|| "plaintext".to_string());
|
|
|
|
|
let client_arc = manager.get_client(server_name)
|
2026-07-13 08:12:02 +07:00
|
|
|
.ok_or_else(|| anyhow!("LSP server '{server_name}' not found. Use lsp_connect first."))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
drop(manager);
|
|
|
|
|
|
|
|
|
|
let mut client = client_arc.lock()
|
2026-07-13 08:12:02 +07:00
|
|
|
.map_err(|e| anyhow!("LSP client lock error: {e}"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
|
|
|
|
|
client.did_open(&uri, &language_id, 1, &file_content)?;
|
|
|
|
|
let result = client.goto_definition(&uri, line, column);
|
|
|
|
|
let _ = client.did_close(&uri);
|
|
|
|
|
|
|
|
|
|
match result {
|
|
|
|
|
Ok(def_result) => {
|
|
|
|
|
if def_result == Value::Null {
|
|
|
|
|
return Ok("No definition found at this position.".to_string());
|
|
|
|
|
}
|
|
|
|
|
let locations = if let Some(loc) = def_result.as_array() {
|
|
|
|
|
loc.clone()
|
|
|
|
|
} else {
|
|
|
|
|
vec![def_result.clone()]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if locations.is_empty() {
|
|
|
|
|
return Ok("No definition found.".to_string());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut output = String::from("Definition(s):\n");
|
|
|
|
|
for (i, loc) in locations.iter().enumerate().take(10) {
|
|
|
|
|
let target_uri = loc.get("uri").and_then(|u| u.as_str()).unwrap_or("?");
|
|
|
|
|
let target_range = loc.get("range").or_else(|| loc.get("targetRange"));
|
|
|
|
|
let target_start = target_range.and_then(|r| r.get("start"));
|
2026-07-13 08:12:02 +07:00
|
|
|
let tl = target_start.and_then(|s| s.get("line")).and_then(serde_json::Value::as_i64).unwrap_or(0);
|
|
|
|
|
let tc = target_start.and_then(|s| s.get("character")).and_then(serde_json::Value::as_i64).unwrap_or(0);
|
2026-07-12 13:40:58 +07:00
|
|
|
let path_str = target_uri.strip_prefix("file://").unwrap_or(target_uri);
|
2026-07-13 08:12:02 +07:00
|
|
|
writeln!(output, " {}. {}:{}:{}", i + 1, path_str, tl + 1, tc + 1).unwrap();
|
2026-07-12 13:40:58 +07:00
|
|
|
}
|
|
|
|
|
if locations.len() > 10 {
|
2026-07-13 08:12:02 +07:00
|
|
|
writeln!(output, " ... and {} more", locations.len() - 10).unwrap();
|
2026-07-12 13:40:58 +07:00
|
|
|
}
|
|
|
|
|
Ok(output)
|
|
|
|
|
}
|
|
|
|
|
Err(e) => Err(e),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct LspReferences;
|
|
|
|
|
|
|
|
|
|
impl Tool for LspReferences {
|
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
|
"lsp_references"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn description(&self) -> &'static str {
|
2026-07-12 14:47:01 +07:00
|
|
|
"Find all references to a symbol at a cursor position. \
|
|
|
|
|
`server` is optional — if omitted, the server is auto-detected from the file's extension."
|
2026-07-12 13:40:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn parameters(&self) -> Value {
|
|
|
|
|
json!({
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
|
|
|
|
"server": {
|
|
|
|
|
"type": "string",
|
2026-07-12 14:47:01 +07:00
|
|
|
"description": "Name of the connected LSP server. Optional — auto-detected from the file extension if omitted."
|
2026-07-12 13:40:58 +07:00
|
|
|
},
|
|
|
|
|
"path": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"description": "Path to the file (relative to workspace root)"
|
|
|
|
|
},
|
|
|
|
|
"line": {
|
|
|
|
|
"type": "integer",
|
|
|
|
|
"description": "Line number (0-based)"
|
|
|
|
|
},
|
|
|
|
|
"column": {
|
|
|
|
|
"type": "integer",
|
|
|
|
|
"description": "Column number (0-based)"
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-07-12 14:47:01 +07:00
|
|
|
"required": ["path", "line", "column"]
|
2026-07-12 13:40:58 +07:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String> {
|
|
|
|
|
let rel_path = args.get("path")
|
|
|
|
|
.and_then(|v| v.as_str())
|
|
|
|
|
.ok_or_else(|| anyhow!("missing required argument: path"))?;
|
|
|
|
|
let line = args.get("line")
|
2026-07-13 08:12:02 +07:00
|
|
|
.and_then(serde_json::Value::as_i64)
|
2026-07-12 13:40:58 +07:00
|
|
|
.ok_or_else(|| anyhow!("missing required argument: line"))? as u32;
|
|
|
|
|
let column = args.get("column")
|
2026-07-13 08:12:02 +07:00
|
|
|
.and_then(serde_json::Value::as_i64)
|
2026-07-12 13:40:58 +07:00
|
|
|
.ok_or_else(|| anyhow!("missing required argument: column"))? as u32;
|
2026-07-12 14:47:01 +07:00
|
|
|
let server_name = resolve_server_name(ctx, args, rel_path)?;
|
|
|
|
|
let server_name = server_name.as_str();
|
2026-07-12 13:40:58 +07:00
|
|
|
|
|
|
|
|
let abs_path = crate::tool::resolve_path(&ctx.workspaces, rel_path)?;
|
|
|
|
|
let uri = path_to_lsp_uri(&abs_path.to_string_lossy());
|
|
|
|
|
|
|
|
|
|
let file_content = std::fs::read_to_string(&abs_path)
|
2026-07-13 08:12:02 +07:00
|
|
|
.map_err(|e| anyhow!("failed to read file '{rel_path}': {e}"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
|
|
|
|
|
let manager = ctx.lsp_manager.lock()
|
2026-07-13 08:12:02 +07:00
|
|
|
.map_err(|e| anyhow!("LSP manager lock error: {e}"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
let language_id = manager.get_language_id(server_name)
|
|
|
|
|
.unwrap_or_else(|| "plaintext".to_string());
|
|
|
|
|
let client_arc = manager.get_client(server_name)
|
2026-07-13 08:12:02 +07:00
|
|
|
.ok_or_else(|| anyhow!("LSP server '{server_name}' not found. Use lsp_connect first."))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
drop(manager);
|
|
|
|
|
|
|
|
|
|
let mut client = client_arc.lock()
|
2026-07-13 08:12:02 +07:00
|
|
|
.map_err(|e| anyhow!("LSP client lock error: {e}"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
|
|
|
|
|
client.did_open(&uri, &language_id, 1, &file_content)?;
|
|
|
|
|
let result = client.references(&uri, line, column);
|
|
|
|
|
let _ = client.did_close(&uri);
|
|
|
|
|
|
|
|
|
|
match result {
|
|
|
|
|
Ok(ref_result) => {
|
|
|
|
|
let locations = ref_result.as_array().cloned().unwrap_or_default();
|
|
|
|
|
if locations.is_empty() {
|
|
|
|
|
return Ok("No references found for this symbol.".to_string());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut output = format!("{} reference(s) found:\n", locations.len());
|
|
|
|
|
for (i, loc) in locations.iter().enumerate().take(50) {
|
|
|
|
|
let target_uri = loc.get("uri").and_then(|u| u.as_str()).unwrap_or("?");
|
|
|
|
|
let range = loc.get("range").and_then(|r| r.get("start"));
|
2026-07-13 08:12:02 +07:00
|
|
|
let rl = range.and_then(|s| s.get("line")).and_then(serde_json::Value::as_i64).unwrap_or(0);
|
|
|
|
|
let rc = range.and_then(|s| s.get("character")).and_then(serde_json::Value::as_i64).unwrap_or(0);
|
2026-07-12 13:40:58 +07:00
|
|
|
let path_str = target_uri.strip_prefix("file://").unwrap_or(target_uri);
|
2026-07-13 08:12:02 +07:00
|
|
|
writeln!(output, " {}. {}:{}:{}", i + 1, path_str, rl + 1, rc + 1).unwrap();
|
2026-07-12 13:40:58 +07:00
|
|
|
}
|
|
|
|
|
if locations.len() > 50 {
|
2026-07-13 08:12:02 +07:00
|
|
|
writeln!(output, " ... and {} more references", locations.len() - 50).unwrap();
|
2026-07-12 13:40:58 +07:00
|
|
|
}
|
|
|
|
|
Ok(output)
|
|
|
|
|
}
|
|
|
|
|
Err(e) => Err(e),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct LspDisconnect;
|
|
|
|
|
|
|
|
|
|
impl Tool for LspDisconnect {
|
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
|
"lsp_disconnect"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn description(&self) -> &'static str {
|
|
|
|
|
"Disconnect from a running LSP server and release its resources"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn parameters(&self) -> Value {
|
|
|
|
|
json!({
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
|
|
|
|
"name": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"description": "Name of the LSP server to disconnect"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"required": ["name"]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String> {
|
|
|
|
|
let name = args.get("name")
|
|
|
|
|
.and_then(|v| v.as_str())
|
|
|
|
|
.ok_or_else(|| anyhow!("missing required argument: name"))?;
|
|
|
|
|
|
|
|
|
|
let mut manager = ctx.lsp_manager.lock()
|
2026-07-13 08:12:02 +07:00
|
|
|
.map_err(|e| anyhow!("LSP manager lock error: {e}"))?;
|
2026-07-12 13:40:58 +07:00
|
|
|
|
|
|
|
|
if manager.disconnect(name) {
|
2026-07-13 08:12:02 +07:00
|
|
|
Ok(format!("Disconnected from LSP server '{name}'"))
|
2026-07-12 13:40:58 +07:00
|
|
|
} else {
|
2026-07-13 08:12:02 +07:00
|
|
|
Err(anyhow!("LSP server '{name}' not found"))
|
2026-07-12 13:40:58 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-12 14:47:01 +07:00
|
|
|
|
|
|
|
|
/// Return the default file extensions associated with a language id.
|
|
|
|
|
///
|
|
|
|
|
/// Flow: pure `match` on `language_id` -> static slice of extension
|
|
|
|
|
/// strings (with leading dot). Returns an empty slice for unknown
|
|
|
|
|
/// languages, so callers can safely chain lookups without a special case.
|
|
|
|
|
///
|
|
|
|
|
/// Used by `lsp_connect` to auto-register extensions for a newly connected
|
|
|
|
|
/// server, and by `auto_detect_server` as a fallback when the manager's own
|
|
|
|
|
/// `extension_registry` has no entry yet.
|
|
|
|
|
fn known_extensions_for(language_id: &str) -> &[&'static str] {
|
|
|
|
|
match language_id {
|
|
|
|
|
"rust" => &[".rs"],
|
|
|
|
|
"typescript" => &[".ts", ".tsx", ".js", ".jsx"],
|
|
|
|
|
"go" => &[".go"],
|
|
|
|
|
"java" => &[".java"],
|
|
|
|
|
_ => &[],
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Guess which connected LSP server should handle `path` based on its extension.
|
|
|
|
|
///
|
|
|
|
|
/// Flow: extract extension from `path` -> for each connected server, check
|
|
|
|
|
/// whether `known_extensions_for(server.language_id)` contains the extension
|
|
|
|
|
/// -> return the first match's name.
|
|
|
|
|
///
|
|
|
|
|
/// This is a fallback used only when the caller omits `server` and the file's
|
|
|
|
|
/// extension is not (yet) present in `LspManager::extension_registry` — e.g.
|
|
|
|
|
/// a server connected without an explicit `register_extensions` call. Returns
|
|
|
|
|
/// `None` if the path has no extension, the lock is poisoned, or no
|
|
|
|
|
/// connected server's language is known to use that extension.
|
|
|
|
|
fn auto_detect_server(ctx: &ToolCtx, path: &str) -> Option<String> {
|
|
|
|
|
let ext = std::path::Path::new(path).extension().and_then(|e| e.to_str())?;
|
2026-07-13 08:12:02 +07:00
|
|
|
let dot_ext = format!(".{ext}");
|
2026-07-12 14:47:01 +07:00
|
|
|
if let Ok(mgr) = ctx.lsp_manager.lock() {
|
|
|
|
|
for s in &mgr.servers {
|
|
|
|
|
let exts = known_extensions_for(&s.language_id);
|
|
|
|
|
if exts.contains(&dot_ext.as_str()) {
|
|
|
|
|
return Some(s.name.clone());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Resolve the LSP server name to use for a tool call: explicit `server`
|
|
|
|
|
/// argument if present, otherwise auto-detected from `path`'s extension.
|
|
|
|
|
///
|
|
|
|
|
/// Flow: `args["server"]` present -> use it as-is. Otherwise -> try
|
|
|
|
|
/// `LspManager::find_server_for_path`-style registry lookup by delegating to
|
|
|
|
|
/// `auto_detect_server`. If that also fails, build a helpful error message
|
|
|
|
|
/// listing the currently connected servers (via `LspManager::list_servers`)
|
|
|
|
|
/// so the caller knows whether to connect one first.
|
|
|
|
|
///
|
|
|
|
|
/// Return: `Ok(server_name)` on success. `Err` only when no `server` was
|
|
|
|
|
/// given and auto-detection could not resolve one — never fails just
|
|
|
|
|
/// because the caller provided an explicit (possibly wrong) server name,
|
|
|
|
|
/// since downstream `get_client`/`get_language_id` calls report that error.
|
|
|
|
|
fn resolve_server_name(ctx: &ToolCtx, args: &Value, path: &str) -> Result<String> {
|
|
|
|
|
if let Some(server) = args.get("server").and_then(|v| v.as_str()) {
|
|
|
|
|
return Ok(server.to_string());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(name) = auto_detect_server(ctx, path) {
|
|
|
|
|
return Ok(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let ext = std::path::Path::new(path)
|
|
|
|
|
.extension()
|
2026-07-13 08:12:02 +07:00
|
|
|
.and_then(|e| e.to_str()).map_or_else(|| "<none>".to_string(), |e| format!(".{e}"));
|
2026-07-12 14:47:01 +07:00
|
|
|
|
|
|
|
|
let available = ctx.lsp_manager.lock().ok()
|
|
|
|
|
.map(|mgr| {
|
|
|
|
|
mgr.list_servers()
|
|
|
|
|
.iter()
|
2026-07-13 08:12:02 +07:00
|
|
|
.map(|(name, lang, _)| format!("{name} ({lang})"))
|
2026-07-12 14:47:01 +07:00
|
|
|
.collect::<Vec<_>>()
|
|
|
|
|
.join(", ")
|
|
|
|
|
})
|
|
|
|
|
.unwrap_or_default();
|
|
|
|
|
let available = if available.is_empty() { "none".to_string() } else { available };
|
|
|
|
|
|
|
|
|
|
Err(anyhow!(
|
2026-07-13 08:12:02 +07:00
|
|
|
"LSP server not found for extension '{ext}'. Use lsp_connect to connect one. Available servers: {available}"
|
2026-07-12 14:47:01 +07:00
|
|
|
))
|
|
|
|
|
}
|