test rust lsp
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "features"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
anyhow = { workspace = true }
|
||||
lsp-types = { workspace = true }
|
||||
analysis = { path = "../analysis" }
|
||||
text = { path = "../text" }
|
||||
url = { workspace = true }
|
||||
@@ -0,0 +1,31 @@
|
||||
use anyhow::Result;
|
||||
use analysis::ProcIndex;
|
||||
use lsp_types as lsp;
|
||||
use text::DocumentStore;
|
||||
|
||||
pub fn completion(
|
||||
docs: &DocumentStore,
|
||||
index: &ProcIndex,
|
||||
params: &lsp::CompletionParams
|
||||
) -> Result<Option<lsp::CompletionResponse>> {
|
||||
let uri = ¶ms.text_document_position.text_document.uri;
|
||||
let Some(_doc) = docs.get(uri) else {
|
||||
return Ok(None);
|
||||
};
|
||||
let Some(procs) = index.get(uri) else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let items: Vec<lsp::CompletionItem> = procs
|
||||
.iter()
|
||||
.map(|p| lsp::CompletionItem {
|
||||
label: p.name.clone(),
|
||||
kind: Some(lsp::CompletionItemKind::FUNCTION),
|
||||
detail: Some(format!("proc {}", p.params.join(" "))),
|
||||
insert_text: Some(p.name.clone()),
|
||||
..Default::default()
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(Some(lsp::CompletionResponse::Array(items)))
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
use anyhow::Result;
|
||||
use analysis::ProcIndex;
|
||||
use lsp_types as lsp;
|
||||
use text::DocumentStore;
|
||||
|
||||
pub fn definition(
|
||||
docs: &DocumentStore,
|
||||
index: &ProcIndex,
|
||||
params: &lsp::GotoDefinitionParams
|
||||
) -> Result<Option<lsp::GotoDefinitionResponse>> {
|
||||
let uri = ¶ms.text_document_position_params.text_document.uri;
|
||||
let pos = params.text_document_position_params.position;
|
||||
let Some(doc) = docs.get(uri) else {
|
||||
return Ok(None);
|
||||
};
|
||||
let Some((word, _range)) = doc.word_under_position(pos) else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let Some(procs) = index.get(uri) else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
if let Some(p) = procs.iter().find(|p| p.name == word) {
|
||||
let loc = lsp::Location {
|
||||
uri: uri.clone(),
|
||||
range: doc.byte_range_to_lsp_range(p.byte_start, p.byte_end),
|
||||
};
|
||||
return Ok(Some(lsp::GotoDefinitionResponse::Scalar(loc)));
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
use anyhow::Result;
|
||||
use analysis::ProcIndex;
|
||||
use lsp_types as lsp;
|
||||
use text::DocumentStore;
|
||||
|
||||
pub fn document_symbol(
|
||||
docs: &DocumentStore,
|
||||
index: &ProcIndex,
|
||||
uri: &lsp::Uri
|
||||
) -> Result<Option<lsp::DocumentSymbolResponse>> {
|
||||
let Some(doc) = docs.get(uri) else {
|
||||
return Ok(None);
|
||||
};
|
||||
let Some(procs) = index.get(uri) else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let mut symbols = Vec::new();
|
||||
for p in procs {
|
||||
let range = doc.byte_range_to_lsp_range(p.byte_start, p.byte_end);
|
||||
symbols.push(lsp::DocumentSymbol {
|
||||
name: p.name.clone(),
|
||||
detail: Some(format!("proc {}", p.params.join(" "))),
|
||||
kind: lsp::SymbolKind::FUNCTION,
|
||||
range,
|
||||
selection_range: range,
|
||||
children: None,
|
||||
tags: None,
|
||||
deprecated: None,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(Some(lsp::DocumentSymbolResponse::Nested(symbols)))
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
mod document_symbol;
|
||||
mod definition;
|
||||
mod completion;
|
||||
|
||||
pub use document_symbol::document_symbol;
|
||||
pub use definition::definition;
|
||||
pub use completion::completion;
|
||||
Reference in New Issue
Block a user