dev: stateful requests now accept snapshot (#1581)

* dev: stateful requests now accept snapshot

* dev: add some convenient methods

* dev: remove unused latest_doc state

* dev: use graph

* docs: comment

* fix: bad flag
This commit is contained in:
Myriad-Dreamin 2025-03-25 16:28:00 +08:00 committed by GitHub
parent 5b42231a77
commit 10ec787cc9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 383 additions and 504 deletions

View file

@ -41,11 +41,7 @@ pub struct CompletionRequest {
impl StatefulRequest for CompletionRequest {
type Response = CompletionList;
fn request(
self,
ctx: &mut LocalContext,
doc: Option<VersionedDocument>,
) -> Option<Self::Response> {
fn request(self, ctx: &mut LocalContext, graph: LspComputeGraph) -> Option<Self::Response> {
// These trigger characters are for completion on positional arguments,
// which follows the configuration item
// `tinymist.completion.triggerOnSnippetPlaceholders`.
@ -55,7 +51,7 @@ impl StatefulRequest for CompletionRequest {
return None;
}
let document = doc.as_ref().map(|doc| &doc.document);
let document = graph.snap.success_doc.as_ref();
let source = ctx.source_by_path(&self.path).ok()?;
let cursor = ctx.to_typst_pos_offset(&source, self.position, 0)?;
@ -134,7 +130,7 @@ mod tests {
let mut includes = HashSet::new();
let mut excludes = HashSet::new();
let doc = compile_doc_for_test(ctx, &properties);
let graph = compile_doc_for_test(ctx, &properties);
for kk in properties.get("contains").iter().flat_map(|v| v.split(',')) {
// split first char
@ -188,7 +184,7 @@ mod tests {
trigger_character,
};
let result = request
.request(ctx, doc.clone())
.request(ctx, graph.clone())
.map(|list| CompletionList {
is_incomplete: list.is_incomplete,
items: get_items(list.items),