feat(lsp): bring over some stuff for completions, it basically doesn't work right though
This commit is contained in:
parent
02eaefce21
commit
c033cab79e
|
@ -51,14 +51,15 @@ pub fn start() -> Result<(), Error> {
|
||||||
|
|
||||||
fn capabilities() -> lsp_types::ServerCapabilities {
|
fn capabilities() -> lsp_types::ServerCapabilities {
|
||||||
lsp_types::ServerCapabilities {
|
lsp_types::ServerCapabilities {
|
||||||
completion_provider: Some(lsp_types::CompletionOptions {
|
// THIS IS STILL WEIRD, ONLY ENABLE IF DEVELOPING
|
||||||
resolve_provider: None,
|
// completion_provider: Some(lsp_types::CompletionOptions {
|
||||||
trigger_characters: Some(vec![".".into(), " ".into()]),
|
// resolve_provider: None,
|
||||||
all_commit_characters: None,
|
// trigger_characters: Some(vec![".".into(), " ".into()]),
|
||||||
work_done_progress_options: lsp_types::WorkDoneProgressOptions {
|
// all_commit_characters: None,
|
||||||
work_done_progress: None,
|
// work_done_progress_options: lsp_types::WorkDoneProgressOptions {
|
||||||
},
|
// work_done_progress: None,
|
||||||
}),
|
// },
|
||||||
|
// }),
|
||||||
document_formatting_provider: Some(lsp_types::OneOf::Left(true)),
|
document_formatting_provider: Some(lsp_types::OneOf::Left(true)),
|
||||||
definition_provider: Some(lsp_types::OneOf::Left(true)),
|
definition_provider: Some(lsp_types::OneOf::Left(true)),
|
||||||
hover_provider: Some(lsp_types::HoverProviderCapability::Simple(true)),
|
hover_provider: Some(lsp_types::HoverProviderCapability::Simple(true)),
|
||||||
|
|
|
@ -261,12 +261,70 @@ impl Server {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Completion::METHOD => {
|
||||||
|
let params = cast_request::<Completion>(request).expect("cast Completion");
|
||||||
|
|
||||||
|
let completions = self.completion(params);
|
||||||
|
|
||||||
|
Ok(lsp_server::Response {
|
||||||
|
id,
|
||||||
|
error: None,
|
||||||
|
result: Some(serde_json::to_value(completions)?),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
unsupported => Err(ServerError::UnsupportedLspRequest {
|
unsupported => Err(ServerError::UnsupportedLspRequest {
|
||||||
request: unsupported.to_string(),
|
request: unsupported.to_string(),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn completion(
|
||||||
|
&self,
|
||||||
|
params: lsp_types::CompletionParams,
|
||||||
|
) -> Option<Vec<lsp_types::CompletionItem>> {
|
||||||
|
let found = self
|
||||||
|
.node_at_position(¶ms.text_document_position)
|
||||||
|
.map(|(_, found)| found);
|
||||||
|
|
||||||
|
match found {
|
||||||
|
// TODO: test
|
||||||
|
None | Some(Located::Definition(Definition::Use(Use { .. }))) => {
|
||||||
|
self.completion_for_import()
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: autocompletion for other definitions
|
||||||
|
Some(Located::Definition(_expression)) => None,
|
||||||
|
|
||||||
|
// TODO: autocompletion for expressions
|
||||||
|
Some(Located::Expression(_expression)) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn completion_for_import(&self) -> Option<Vec<lsp_types::CompletionItem>> {
|
||||||
|
let compiler = self.compiler.as_ref()?;
|
||||||
|
|
||||||
|
// TODO: Test
|
||||||
|
let dependencies_modules = compiler.project.importable_modules();
|
||||||
|
|
||||||
|
// TODO: Test
|
||||||
|
let project_modules = compiler.modules.keys().cloned();
|
||||||
|
|
||||||
|
let modules = dependencies_modules
|
||||||
|
.into_iter()
|
||||||
|
.chain(project_modules)
|
||||||
|
.sorted()
|
||||||
|
.map(|label| lsp_types::CompletionItem {
|
||||||
|
label,
|
||||||
|
kind: None,
|
||||||
|
documentation: None,
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Some(modules)
|
||||||
|
}
|
||||||
|
|
||||||
fn goto_definition(
|
fn goto_definition(
|
||||||
&self,
|
&self,
|
||||||
params: lsp_types::GotoDefinitionParams,
|
params: lsp_types::GotoDefinitionParams,
|
||||||
|
|
|
@ -125,6 +125,10 @@ where
|
||||||
self.checked_modules.values().cloned().collect()
|
self.checked_modules.values().cloned().collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn importable_modules(&self) -> Vec<String> {
|
||||||
|
self.module_types.keys().cloned().collect()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn checkpoint(&self) -> Checkpoint {
|
pub fn checkpoint(&self) -> Checkpoint {
|
||||||
Checkpoint {
|
Checkpoint {
|
||||||
module_types: self.module_types.clone(),
|
module_types: self.module_types.clone(),
|
||||||
|
|
Loading…
Reference in New Issue