refactor: split completion functions by topics (#1083)

This commit is contained in:
Myriad-Dreamin 2024-12-28 12:45:45 +08:00 committed by GitHub
parent c5981b81db
commit 81d3ea64c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 2197 additions and 2163 deletions

View file

@ -70,26 +70,25 @@ impl StatefulRequest for CompletionRequest {
// assume that the completion is not explicit.
let explicit = false;
let doc = doc.as_ref().map(|doc| doc.document.as_ref());
let document = doc.as_ref().map(|doc| doc.document.as_ref());
let source = ctx.source_by_path(&self.path).ok()?;
let cursor = ctx.to_typst_pos_offset(&source, self.position, 0)?;
let mut cursor = CompletionCursor::new(ctx.shared_(), &source, cursor)?;
let worker = CompletionWorker::new(ctx, doc, explicit, self.trigger_character)?;
let (worker_incomplete, items) = worker.work(&mut cursor)?;
let mut worker = CompletionWorker::new(ctx, document, explicit, self.trigger_character)?;
worker.work(&mut cursor)?;
// todo: define it well, we were needing it because we wanted to do interactive
// path completion, but now we've scanned all the paths at the same time.
// is_incomplete = ic;
let _ = worker_incomplete;
let _ = worker.incomplete;
// To response completions in fine-grained manner, we need to mark result as
// incomplete. This follows what rust-analyzer does.
// https://github.com/rust-lang/rust-analyzer/blob/f5a9250147f6569d8d89334dc9cca79c0322729f/crates/rust-analyzer/src/handlers/request.rs#L940C55-L940C75
Some(CompletionList {
is_incomplete: false,
items,
items: worker.completions,
})
}
}