1pub use analysis::{CompletionFeat, LocalContext, LocalContextGuard, LspWorldExt};
11pub use completion::{CompletionRequest, PostfixSnippet};
12pub use typlite::ColorTheme;
13pub use upstream::with_vm;
14
15pub use check::*;
16pub use code_action::*;
17pub use code_context::*;
18pub use code_lens::*;
19pub use color_presentation::*;
20pub use diagnostics::*;
21pub use document_color::*;
22pub use document_highlight::*;
23pub use document_link::*;
24pub use document_metrics::*;
25pub use document_symbol::*;
26pub use folding_range::*;
27pub use goto_declaration::*;
28pub use goto_definition::*;
29pub use hover::*;
30pub use inlay_hint::*;
31pub use jump::*;
32pub use lsp_typst_boundary::*;
33pub use on_enter::*;
34pub use prepare_rename::*;
35pub use references::*;
36pub use rename::*;
37pub use selection_range::*;
38pub use semantic_tokens_delta::*;
39pub use semantic_tokens_full::*;
40pub use signature_help::*;
41pub use symbol::*;
42pub use will_rename_files::*;
43pub use workspace_label::*;
44
45pub mod analysis;
46pub mod docs;
47pub mod index;
48pub mod package;
49pub mod syntax;
50pub mod testing;
51pub use tinymist_analysis::{ty, upstream};
52
53pub type FramePosition = typst::layout::Position;
55
56mod adt;
57mod lsp_typst_boundary;
58mod prelude;
59
60mod bib;
61mod check;
62mod code_action;
63mod code_context;
64mod code_lens;
65mod color_presentation;
66mod completion;
67mod diagnostics;
68mod document_color;
69mod document_highlight;
70mod document_link;
71mod document_metrics;
72mod document_symbol;
73mod folding_range;
74mod goto_declaration;
75mod goto_definition;
76mod hover;
77mod inlay_hint;
78mod jump;
79mod on_enter;
80mod prepare_rename;
81mod references;
82mod rename;
83mod selection_range;
84mod semantic_tokens_delta;
85mod semantic_tokens_full;
86mod signature_help;
87mod symbol;
88mod will_rename_files;
89mod workspace_label;
90
91use typst::syntax::Source;
92
93use tinymist_analysis::{adt::interner::Interned, log_debug_ct};
94use tinymist_project::LspComputeGraph;
95
96pub(crate) type StrRef = Interned<str>;
98
99pub trait SyntaxRequest {
101 type Response;
103
104 fn request(
106 self,
107 source: &Source,
108 positing_encoding: PositionEncoding,
109 ) -> Option<Self::Response>;
110}
111
112pub trait SemanticRequest {
114 type Response;
116
117 fn request(self, ctx: &mut LocalContext) -> Option<Self::Response>;
119}
120
121pub trait StatefulRequest {
124 type Response;
126
127 fn request(self, ctx: &mut LocalContext, graph: LspComputeGraph) -> Option<Self::Response>;
129}
130
131mod polymorphic {
132 use completion::CompletionList;
133 use lsp_types::TextEdit;
134 use serde::{Deserialize, Serialize};
135 use tinymist_project::ProjectTask;
136 use typst::foundations::Dict;
137
138 use super::prelude::*;
139 use super::*;
140
141 #[derive(Debug, Clone)]
143 pub struct OnExportRequest {
144 pub path: PathBuf,
146 pub task: ProjectTask,
148 pub write: bool,
150 pub open: bool,
152 }
153
154 #[derive(Debug, Clone, Serialize, Deserialize)]
156 #[serde(untagged, rename_all = "camelCase")]
157 pub enum OnExportResponse {
158 Single {
160 path: Option<PathBuf>,
162 data: Option<String>,
164 },
165 Paged {
167 total_pages: usize,
169 items: Vec<PagedExportResponse>,
171 },
172 }
173
174 #[derive(Debug, Clone, Serialize, Deserialize)]
176 #[serde(rename_all = "camelCase")]
177 pub struct PagedExportResponse {
178 pub page: usize,
180 pub path: Option<PathBuf>,
182 pub data: Option<String>,
184 }
185
186 #[derive(Debug, Clone)]
188 pub struct FormattingRequest {
189 pub path: PathBuf,
191 }
192
193 #[derive(Debug, Clone)]
195 pub struct ServerInfoRequest {}
196
197 #[derive(Debug, Clone, Serialize, Deserialize)]
199 #[serde(rename_all = "camelCase")]
200 pub struct ServerInfoResponse {
201 pub root: Option<PathBuf>,
203 pub font_paths: Vec<PathBuf>,
205 pub inputs: Dict,
207 pub stats: HashMap<String, String>,
209 }
210
211 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
213 pub enum FoldRequestFeature {
214 PinnedFirst,
216 Unique,
218 Mergeable,
220 ContextFreeUnique,
222 }
223
224 #[derive(Debug, Clone, strum::IntoStaticStr)]
226 pub enum CompilerQueryRequest {
227 OnExport(OnExportRequest),
229 Hover(HoverRequest),
231 GotoDefinition(GotoDefinitionRequest),
233 GotoDeclaration(GotoDeclarationRequest),
235 References(ReferencesRequest),
237 InlayHint(InlayHintRequest),
239 DocumentColor(DocumentColorRequest),
241 DocumentLink(DocumentLinkRequest),
243 DocumentHighlight(DocumentHighlightRequest),
245 ColorPresentation(ColorPresentationRequest),
247 CodeAction(CodeActionRequest),
249 CodeLens(CodeLensRequest),
251 Completion(CompletionRequest),
253 SignatureHelp(SignatureHelpRequest),
255 Rename(RenameRequest),
257 WillRenameFiles(WillRenameFilesRequest),
259 PrepareRename(PrepareRenameRequest),
261 DocumentSymbol(DocumentSymbolRequest),
263 Symbol(SymbolRequest),
265 SemanticTokensFull(SemanticTokensFullRequest),
267 SemanticTokensDelta(SemanticTokensDeltaRequest),
269 Formatting(FormattingRequest),
271 FoldingRange(FoldingRangeRequest),
273 SelectionRange(SelectionRangeRequest),
275 InteractCodeContext(InteractCodeContextRequest),
277
278 OnEnter(OnEnterRequest),
280
281 DocumentMetrics(DocumentMetricsRequest),
283 WorkspaceLabel(WorkspaceLabelRequest),
285 ServerInfo(ServerInfoRequest),
287 }
288
289 impl CompilerQueryRequest {
290 pub fn fold_feature(&self) -> FoldRequestFeature {
292 use FoldRequestFeature::*;
293 match self {
294 Self::OnExport(..) => Mergeable,
295 Self::Hover(..) => PinnedFirst,
296 Self::GotoDefinition(..) => PinnedFirst,
297 Self::GotoDeclaration(..) => PinnedFirst,
298 Self::References(..) => PinnedFirst,
299 Self::InlayHint(..) => Unique,
300 Self::DocumentColor(..) => PinnedFirst,
301 Self::DocumentLink(..) => PinnedFirst,
302 Self::DocumentHighlight(..) => PinnedFirst,
303 Self::ColorPresentation(..) => ContextFreeUnique,
304 Self::CodeAction(..) => Unique,
305 Self::CodeLens(..) => Unique,
306 Self::Completion(..) => Mergeable,
307 Self::SignatureHelp(..) => PinnedFirst,
308 Self::Rename(..) => Mergeable,
309 Self::WillRenameFiles(..) => Mergeable,
310 Self::PrepareRename(..) => Mergeable,
311 Self::DocumentSymbol(..) => ContextFreeUnique,
312 Self::WorkspaceLabel(..) => Mergeable,
313 Self::Symbol(..) => Mergeable,
314 Self::SemanticTokensFull(..) => PinnedFirst,
315 Self::SemanticTokensDelta(..) => PinnedFirst,
316 Self::Formatting(..) => ContextFreeUnique,
317 Self::FoldingRange(..) => ContextFreeUnique,
318 Self::SelectionRange(..) => ContextFreeUnique,
319 Self::InteractCodeContext(..) => PinnedFirst,
320
321 Self::OnEnter(..) => ContextFreeUnique,
322
323 Self::DocumentMetrics(..) => PinnedFirst,
324 Self::ServerInfo(..) => Mergeable,
325 }
326 }
327
328 pub fn associated_path(&self) -> Option<&Path> {
330 Some(match self {
331 Self::OnExport(..) => return None,
332 Self::Hover(req) => &req.path,
333 Self::GotoDefinition(req) => &req.path,
334 Self::GotoDeclaration(req) => &req.path,
335 Self::References(req) => &req.path,
336 Self::InlayHint(req) => &req.path,
337 Self::DocumentColor(req) => &req.path,
338 Self::DocumentLink(req) => &req.path,
339 Self::DocumentHighlight(req) => &req.path,
340 Self::ColorPresentation(req) => &req.path,
341 Self::CodeAction(req) => &req.path,
342 Self::CodeLens(req) => &req.path,
343 Self::Completion(req) => &req.path,
344 Self::SignatureHelp(req) => &req.path,
345 Self::Rename(req) => &req.path,
346 Self::WillRenameFiles(..) => return None,
347 Self::PrepareRename(req) => &req.path,
348 Self::DocumentSymbol(req) => &req.path,
349 Self::Symbol(..) => return None,
350 Self::WorkspaceLabel(..) => return None,
351 Self::SemanticTokensFull(req) => &req.path,
352 Self::SemanticTokensDelta(req) => &req.path,
353 Self::Formatting(req) => &req.path,
354 Self::FoldingRange(req) => &req.path,
355 Self::SelectionRange(req) => &req.path,
356 Self::InteractCodeContext(req) => &req.path,
357
358 Self::OnEnter(req) => &req.path,
359
360 Self::DocumentMetrics(req) => &req.path,
361 Self::ServerInfo(..) => return None,
362 })
363 }
364 }
365
366 #[derive(Debug, Clone, Serialize, Deserialize)]
368 #[serde(untagged)]
369 pub enum CompilerQueryResponse {
370 OnExport(Option<OnExportResponse>),
372 Hover(Option<Hover>),
374 GotoDefinition(Option<GotoDefinitionResponse>),
376 GotoDeclaration(Option<GotoDeclarationResponse>),
378 References(Option<Vec<LspLocation>>),
380 InlayHint(Option<Vec<InlayHint>>),
382 DocumentColor(Option<Vec<ColorInformation>>),
384 DocumentLink(Option<Vec<DocumentLink>>),
386 DocumentHighlight(Option<Vec<DocumentHighlight>>),
388 ColorPresentation(Option<Vec<ColorPresentation>>),
390 CodeAction(Option<Vec<CodeAction>>),
392 CodeLens(Option<Vec<CodeLens>>),
394 Completion(Option<CompletionList>),
396 SignatureHelp(Option<SignatureHelp>),
398 PrepareRename(Option<PrepareRenameResponse>),
400 Rename(Option<WorkspaceEdit>),
402 WillRenameFiles(Option<WorkspaceEdit>),
404 DocumentSymbol(Option<DocumentSymbolResponse>),
406 Symbol(Option<Vec<SymbolInformation>>),
408 WorkspaceLabel(Option<Vec<SymbolInformation>>),
410 SemanticTokensFull(Option<SemanticTokensResult>),
412 SemanticTokensDelta(Option<SemanticTokensFullDeltaResult>),
414 Formatting(Option<Vec<TextEdit>>),
416 FoldingRange(Option<Vec<FoldingRange>>),
418 SelectionRange(Option<Vec<SelectionRange>>),
420 InteractCodeContext(Option<Vec<Option<InteractCodeContextResponse>>>),
422
423 OnEnter(Option<Vec<TextEdit>>),
425
426 DocumentMetrics(Option<DocumentMetricsResponse>),
428 ServerInfo(Option<HashMap<String, ServerInfoResponse>>),
430 }
431}
432
433pub use polymorphic::*;
434
435#[cfg(test)]
436mod tests;