mirror of
https://github.com/oxalica/nil.git
synced 2024-11-29 16:12:12 +03:00
Refactor and improve completion from nowhere or manual trigger
- Regroup completion cases under `Context` in a OOP-like manner to simplify parameter passing. - Handle more cases for complete from nowhere (between expressions or bindings). This helps 24x7 completion and manually triggered completion (Ctrl-Space) in various places to list all options without any identifier as filter.
This commit is contained in:
parent
26c5d73015
commit
bd93024db6
File diff suppressed because it is too large
Load Diff
@ -164,7 +164,7 @@ impl Analysis {
|
|||||||
&self,
|
&self,
|
||||||
pos: FilePos,
|
pos: FilePos,
|
||||||
trigger_char: Option<char>,
|
trigger_char: Option<char>,
|
||||||
) -> Cancellable<Option<Vec<CompletionItem>>> {
|
) -> Cancellable<Vec<CompletionItem>> {
|
||||||
self.with_db(|db| completion::completions(db, pos, trigger_char))
|
self.with_db(|db| completion::completions(db, pos, trigger_char))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ pub(crate) fn to_completion_item(line_map: &LineMap, item: CompletionItem) -> ls
|
|||||||
// We don't support indentation yet.
|
// We don't support indentation yet.
|
||||||
insert_text_mode: Some(lsp::InsertTextMode::ADJUST_INDENTATION),
|
insert_text_mode: Some(lsp::InsertTextMode::ADJUST_INDENTATION),
|
||||||
text_edit: Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit {
|
text_edit: Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit {
|
||||||
range: to_range(line_map, item.source_range),
|
range: to_range(line_map, item.replace_range),
|
||||||
new_text: item.replace.into(),
|
new_text: item.replace.into(),
|
||||||
})),
|
})),
|
||||||
detail: item.description,
|
detail: item.description,
|
||||||
|
@ -76,9 +76,7 @@ pub(crate) fn completion(
|
|||||||
let trigger_char = params
|
let trigger_char = params
|
||||||
.context
|
.context
|
||||||
.and_then(|ctx| ctx.trigger_character?.chars().next());
|
.and_then(|ctx| ctx.trigger_character?.chars().next());
|
||||||
let Some(items) = snap.analysis.completions(fpos, trigger_char)? else {
|
let items = snap.analysis.completions(fpos, trigger_char)?;
|
||||||
return Ok(None);
|
|
||||||
};
|
|
||||||
let items = items
|
let items = items
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|item| convert::to_completion_item(&line_map, item))
|
.map(|item| convert::to_completion_item(&line_map, item))
|
||||||
|
Loading…
Reference in New Issue
Block a user