pub mod workspace;
pub mod hover;
pub mod definition;
pub mod references;
pub mod completion;
pub mod diagnostics;
pub mod symbols;
pub mod rename;
use crate::error::Result;
use crate::lsp::LanguageServerManager;
use lsp_types::Position;
use std::path::Path;
use std::sync::Arc;
use url::Url;
pub fn file_to_url(path: &Path) -> Result<Url> {
Url::from_file_path(path).map_err(|_| {
crate::error::LspMcpError::FileNotFound(path.to_path_buf())
})
}
pub fn url_to_path_string(url: &Url) -> String {
url.to_file_path()
.map(|p| p.to_string_lossy().to_string())
.unwrap_or_else(|_| url.to_string())
}
pub fn read_file(path: &Path) -> Result<String> {
std::fs::read_to_string(path).map_err(|e| crate::error::LspMcpError::Io(e))
}
pub fn make_position(line: u32, character: u32) -> Position {
Position { line, character }
}
pub fn ensure_document_open(
manager: &LanguageServerManager,
file_path: &Path,
) -> Result<(Arc<crate::lsp::LspClient>, Url)> {
let client = manager.get_client_for_file(file_path)?;
let uri = file_to_url(file_path)?;
let content = read_file(file_path)?;
let language_id = client.language().language_id();
client.open_document(&uri, &content, language_id)?;
Ok((client, uri))
}