use std::sync::Arc;
use std::path::PathBuf;
use matrixcode_core::lsp::{LspClientRegistry, LspServerConfig};
use matrixcode_core::tools::Tool;
use serde_json::json;
#[tokio::test]
async fn test_lsp_registry_creation() {
let registry = Arc::new(LspClientRegistry::new());
assert!(!registry.has_active_clients().await);
assert_eq!(registry.active_languages().await.len(), 0);
}
#[test]
fn test_lsp_config_creation() {
let config = LspServerConfig::new("rust-analyzer", "rust");
assert_eq!(config.command, "rust-analyzer");
assert_eq!(config.language, "rust");
assert!(config.enabled);
assert_eq!(config.args.len(), 0);
}
#[test]
fn test_lsp_config_with_args() {
let config = LspServerConfig::new("typescript-language-server", "typescript")
.with_args(vec!["--stdio".to_string()]);
assert_eq!(config.args.len(), 1);
assert_eq!(config.args[0], "--stdio");
}
#[tokio::test]
#[ignore] async fn test_lsp_registry_register() {
let registry = Arc::new(LspClientRegistry::new());
let config = LspServerConfig::new("rust-analyzer", "rust");
let project_root = std::env::current_dir().unwrap();
let result = registry.register(&config, &project_root).await;
match result {
Ok(_) => {
assert!(registry.has_active_clients().await);
assert!(registry.get_client("rust").await.is_some());
}
Err(_) => {
}
}
}
#[tokio::test]
async fn test_lsp_hover_tool_without_client() {
use matrixcode_core::lsp::LspHoverTool;
let registry = Arc::new(LspClientRegistry::new());
let tool = LspHoverTool::new(registry);
let file = PathBuf::from("test.rs");
let params = json!({
"file": file.to_string_lossy(),
"line": 0,
"column": 0
});
let result = tool.execute(params).await;
assert!(result.is_err());
}
#[tokio::test]
async fn test_lsp_definition_tool_without_client() {
use matrixcode_core::lsp::LspDefinitionTool;
let registry = Arc::new(LspClientRegistry::new());
let tool = LspDefinitionTool::new(registry);
let file = PathBuf::from("test.rs");
let params = json!({
"file": file.to_string_lossy(),
"line": 0,
"column": 0
});
let result = tool.execute(params).await;
assert!(result.is_err());
}
#[tokio::test]
async fn test_lsp_references_tool_without_client() {
use matrixcode_core::lsp::LspReferencesTool;
let registry = Arc::new(LspClientRegistry::new());
let tool = LspReferencesTool::new(registry);
let file = PathBuf::from("test.rs");
let params = json!({
"file": file.to_string_lossy(),
"line": 0,
"column": 0,
"include_declaration": true
});
let result = tool.execute(params).await;
assert!(result.is_err());
}
#[tokio::test]
async fn test_lsp_diagnostics_tool_without_client() {
use matrixcode_core::lsp::LspDiagnosticsTool;
let registry = Arc::new(LspClientRegistry::new());
let tool = LspDiagnosticsTool::new(registry);
let file = PathBuf::from("test.rs");
let params = json!({
"file": file.to_string_lossy()
});
let result = tool.execute(params).await;
assert!(result.is_err());
}