1
1
mirror of https://github.com/oxalica/nil.git synced 2024-11-22 02:55:39 +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:
oxalica 2023-10-19 18:10:01 +08:00
parent 26c5d73015
commit bd93024db6
4 changed files with 563 additions and 369 deletions

File diff suppressed because it is too large Load Diff

View File

@ -164,7 +164,7 @@ impl Analysis {
&self,
pos: FilePos,
trigger_char: Option<char>,
) -> Cancellable<Option<Vec<CompletionItem>>> {
) -> Cancellable<Vec<CompletionItem>> {
self.with_db(|db| completion::completions(db, pos, trigger_char))
}

View File

@ -147,7 +147,7 @@ pub(crate) fn to_completion_item(line_map: &LineMap, item: CompletionItem) -> ls
// We don't support indentation yet.
insert_text_mode: Some(lsp::InsertTextMode::ADJUST_INDENTATION),
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(),
})),
detail: item.description,

View File

@ -76,9 +76,7 @@ pub(crate) fn completion(
let trigger_char = params
.context
.and_then(|ctx| ctx.trigger_character?.chars().next());
let Some(items) = snap.analysis.completions(fpos, trigger_char)? else {
return Ok(None);
};
let items = snap.analysis.completions(fpos, trigger_char)?;
let items = items
.into_iter()
.map(|item| convert::to_completion_item(&line_map, item))