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

@ -7,97 +7,88 @@
//! code. Currently it provides:
//! + language queries defined by the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/).
mod adt;
pub use analysis::{CompletionFeat, LocalContext, LocalContextGuard, LspWorldExt};
pub use completion::{CompletionRequest, PostfixSnippet};
pub use typlite::ColorTheme;
pub use upstream::with_vm;
pub use code_action::*;
pub use code_context::*;
pub use code_lens::*;
pub use color_presentation::*;
pub use diagnostics::*;
pub use document_color::*;
pub use document_highlight::*;
pub use document_link::*;
pub use document_metrics::*;
pub use document_symbol::*;
pub use folding_range::*;
pub use goto_declaration::*;
pub use goto_definition::*;
pub use hover::*;
pub use inlay_hint::*;
pub use jump::*;
pub use lsp_typst_boundary::*;
pub use on_enter::*;
pub use prepare_rename::*;
pub use references::*;
pub use rename::*;
pub use selection_range::*;
pub use semantic_tokens_delta::*;
pub use semantic_tokens_full::*;
pub use signature_help::*;
pub use symbol::*;
pub use will_rename_files::*;
pub use workspace_label::*;
pub mod analysis;
pub mod docs;
pub mod package;
pub mod syntax;
pub mod testing;
pub mod ty;
mod upstream;
pub use analysis::{CompletionFeat, LocalContext, LocalContextGuard, LspWorldExt};
pub use completion::PostfixSnippet;
pub use upstream::with_vm;
mod diagnostics;
pub use diagnostics::*;
mod code_action;
pub use code_action::*;
mod code_context;
pub use code_context::*;
mod code_lens;
pub use code_lens::*;
mod completion;
pub use completion::CompletionRequest;
mod color_presentation;
pub use color_presentation::*;
mod document_color;
pub use document_color::*;
mod document_highlight;
pub use document_highlight::*;
mod document_symbol;
pub use document_symbol::*;
mod document_link;
pub use document_link::*;
mod workspace_label;
pub use workspace_label::*;
mod document_metrics;
pub use document_metrics::*;
mod folding_range;
pub use folding_range::*;
mod goto_declaration;
pub use goto_declaration::*;
mod goto_definition;
pub use goto_definition::*;
mod hover;
pub use hover::*;
mod inlay_hint;
pub use inlay_hint::*;
mod jump;
pub use jump::*;
mod will_rename_files;
pub use will_rename_files::*;
mod rename;
pub use rename::*;
mod selection_range;
pub use selection_range::*;
mod semantic_tokens_full;
pub use semantic_tokens_full::*;
mod semantic_tokens_delta;
pub use semantic_tokens_delta::*;
mod signature_help;
pub use signature_help::*;
mod symbol;
pub use symbol::*;
mod on_enter;
pub use on_enter::*;
mod prepare_rename;
pub use prepare_rename::*;
mod references;
pub use references::*;
mod lsp_typst_boundary;
pub use lsp_typst_boundary::*;
mod prelude;
use tinymist_std::typst::TypstDocument;
use typst::syntax::Source;
/// The physical position in a document.
pub type FramePosition = typst::layout::Position;
pub use typlite::ColorTheme;
mod adt;
mod lsp_typst_boundary;
mod prelude;
/// A compiled document with an self-incremented logical version.
#[derive(Debug, Clone)]
pub struct VersionedDocument {
/// The version of the document.
pub version: usize,
/// The compiled document.
pub document: TypstDocument,
}
mod code_action;
mod code_context;
mod code_lens;
mod color_presentation;
mod completion;
mod diagnostics;
mod document_color;
mod document_highlight;
mod document_link;
mod document_metrics;
mod document_symbol;
mod folding_range;
mod goto_declaration;
mod goto_definition;
mod hover;
mod inlay_hint;
mod jump;
mod on_enter;
mod prepare_rename;
mod references;
mod rename;
mod selection_range;
mod semantic_tokens_delta;
mod semantic_tokens_full;
mod signature_help;
mod symbol;
mod upstream;
mod will_rename_files;
mod workspace_label;
use typst::syntax::Source;
use tinymist_analysis::log_debug_ct;
use tinymist_project::LspComputeGraph;
/// A request handler with given syntax information.
pub trait SyntaxRequest {
@ -121,22 +112,16 @@ pub trait SemanticRequest {
fn request(self, ctx: &mut LocalContext) -> Option<Self::Response>;
}
/// A request handler with given (semantic) analysis context and a versioned
/// document.
/// A request handler with given (semantic) analysis context and a project
/// snapshot.
pub trait StatefulRequest {
/// The response type of the request.
type Response;
/// Request the information from the given context.
fn request(
self,
ctx: &mut LocalContext,
doc: Option<VersionedDocument>,
) -> Option<Self::Response>;
fn request(self, ctx: &mut LocalContext, graph: LspComputeGraph) -> Option<Self::Response>;
}
use tinymist_analysis::log_debug_ct;
#[allow(missing_docs)]
mod polymorphic {
use completion::CompletionList;