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::{stats::GLOBAL_STATS, 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};
94
95pub(crate) type StrRef = Interned<str>;
97
98pub trait SyntaxRequest {
100 type Response;
102
103 fn request(
105 self,
106 source: &Source,
107 positing_encoding: PositionEncoding,
108 ) -> Option<Self::Response>;
109}
110
111pub trait SemanticRequest {
113 type Response;
115
116 fn request(self, ctx: &mut LocalContext) -> Option<Self::Response>;
118}
119
120mod polymorphic {
121 use completion::CompletionList;
122 use lsp_types::TextEdit;
123 use serde::{Deserialize, Serialize};
124 use tinymist_project::ProjectTask;
125 use typst::foundations::Dict;
126
127 use super::prelude::*;
128 use super::*;
129
130 #[derive(Debug, Clone)]
132 pub struct OnExportRequest {
133 pub path: PathBuf,
135 pub task: ProjectTask,
137 pub write: bool,
139 pub open: bool,
141 }
142
143 #[derive(Debug, Clone)]
145 pub struct OnExportMdRequest {
146 pub path: PathBuf,
148 pub processor: Option<String>,
150 pub task: ProjectTask,
152 pub write: bool,
154 pub open: bool,
156 }
157
158 #[derive(Debug, Clone, Serialize, Deserialize)]
160 #[serde(untagged, rename_all = "camelCase")]
161 pub enum OnExportResponse {
162 Single {
164 path: Option<PathBuf>,
166 data: Option<String>,
168 },
169 Paged {
171 total_pages: usize,
173 items: Vec<PagedExportResponse>,
175 },
176 }
177
178 #[derive(Debug, Clone, Serialize, Deserialize)]
180 #[serde(rename_all = "camelCase")]
181 pub struct PagedExportResponse {
182 pub page: usize,
184 pub path: Option<PathBuf>,
186 pub data: Option<String>,
188 }
189
190 #[derive(Debug, Clone)]
192 pub struct FormattingRequest {
193 pub path: PathBuf,
195 }
196
197 #[derive(Debug, Clone)]
199 pub struct ServerInfoRequest {}
200
201 #[derive(Debug, Clone, Serialize, Deserialize)]
203 #[serde(rename_all = "camelCase")]
204 pub struct ServerInfoResponse {
205 pub root: Option<PathBuf>,
207 pub font_paths: Vec<PathBuf>,
209 pub inputs: Dict,
211 pub stats: HashMap<String, String>,
213 }
214
215 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
217 pub enum FoldRequestFeature {
218 PinnedFirst,
220 Unique,
222 Mergeable,
224 ContextFreeUnique,
226 }
227
228 #[derive(Debug, Clone, strum::IntoStaticStr)]
230 pub enum CompilerQueryRequest {
231 OnExport(OnExportRequest),
233 OnExportMd(OnExportMdRequest),
235 Hover(HoverRequest),
237 GotoDefinition(GotoDefinitionRequest),
239 GotoDeclaration(GotoDeclarationRequest),
241 References(ReferencesRequest),
243 InlayHint(InlayHintRequest),
245 DocumentColor(DocumentColorRequest),
247 DocumentLink(DocumentLinkRequest),
249 DocumentHighlight(DocumentHighlightRequest),
251 ColorPresentation(ColorPresentationRequest),
253 CodeAction(CodeActionRequest),
255 CodeLens(CodeLensRequest),
257 Completion(CompletionRequest),
259 SignatureHelp(SignatureHelpRequest),
261 Rename(RenameRequest),
263 WillRenameFiles(WillRenameFilesRequest),
265 PrepareRename(PrepareRenameRequest),
267 DocumentSymbol(DocumentSymbolRequest),
269 Symbol(SymbolRequest),
271 SemanticTokensFull(SemanticTokensFullRequest),
273 SemanticTokensDelta(SemanticTokensDeltaRequest),
275 Formatting(FormattingRequest),
277 FoldingRange(FoldingRangeRequest),
279 SelectionRange(SelectionRangeRequest),
281 InteractCodeContext(InteractCodeContextRequest),
283
284 OnEnter(OnEnterRequest),
286
287 DocumentMetrics(DocumentMetricsRequest),
289 WorkspaceLabel(WorkspaceLabelRequest),
291 ServerInfo(ServerInfoRequest),
293 }
294
295 impl CompilerQueryRequest {
296 pub fn fold_feature(&self) -> FoldRequestFeature {
298 use FoldRequestFeature::*;
299 match self {
300 Self::OnExport(..) => Mergeable,
301 Self::OnExportMd(..) => Mergeable,
302 Self::Hover(..) => PinnedFirst,
303 Self::GotoDefinition(..) => PinnedFirst,
304 Self::GotoDeclaration(..) => PinnedFirst,
305 Self::References(..) => PinnedFirst,
306 Self::InlayHint(..) => Unique,
307 Self::DocumentColor(..) => PinnedFirst,
308 Self::DocumentLink(..) => PinnedFirst,
309 Self::DocumentHighlight(..) => PinnedFirst,
310 Self::ColorPresentation(..) => ContextFreeUnique,
311 Self::CodeAction(..) => Unique,
312 Self::CodeLens(..) => Unique,
313 Self::Completion(..) => Mergeable,
314 Self::SignatureHelp(..) => PinnedFirst,
315 Self::Rename(..) => Mergeable,
316 Self::WillRenameFiles(..) => Mergeable,
317 Self::PrepareRename(..) => Mergeable,
318 Self::DocumentSymbol(..) => ContextFreeUnique,
319 Self::WorkspaceLabel(..) => Mergeable,
320 Self::Symbol(..) => Mergeable,
321 Self::SemanticTokensFull(..) => PinnedFirst,
322 Self::SemanticTokensDelta(..) => PinnedFirst,
323 Self::Formatting(..) => ContextFreeUnique,
324 Self::FoldingRange(..) => ContextFreeUnique,
325 Self::SelectionRange(..) => ContextFreeUnique,
326 Self::InteractCodeContext(..) => PinnedFirst,
327
328 Self::OnEnter(..) => ContextFreeUnique,
329
330 Self::DocumentMetrics(..) => PinnedFirst,
331 Self::ServerInfo(..) => Mergeable,
332 }
333 }
334
335 pub fn associated_path(&self) -> Option<&Path> {
337 Some(match self {
338 Self::OnExport(..) => return None,
339 Self::OnExportMd(..) => return None,
340 Self::Hover(req) => &req.path,
341 Self::GotoDefinition(req) => &req.path,
342 Self::GotoDeclaration(req) => &req.path,
343 Self::References(req) => &req.path,
344 Self::InlayHint(req) => &req.path,
345 Self::DocumentColor(req) => &req.path,
346 Self::DocumentLink(req) => &req.path,
347 Self::DocumentHighlight(req) => &req.path,
348 Self::ColorPresentation(req) => &req.path,
349 Self::CodeAction(req) => &req.path,
350 Self::CodeLens(req) => &req.path,
351 Self::Completion(req) => &req.path,
352 Self::SignatureHelp(req) => &req.path,
353 Self::Rename(req) => &req.path,
354 Self::WillRenameFiles(..) => return None,
355 Self::PrepareRename(req) => &req.path,
356 Self::DocumentSymbol(req) => &req.path,
357 Self::Symbol(..) => return None,
358 Self::WorkspaceLabel(..) => return None,
359 Self::SemanticTokensFull(req) => &req.path,
360 Self::SemanticTokensDelta(req) => &req.path,
361 Self::Formatting(req) => &req.path,
362 Self::FoldingRange(req) => &req.path,
363 Self::SelectionRange(req) => &req.path,
364 Self::InteractCodeContext(req) => &req.path,
365
366 Self::OnEnter(req) => &req.path,
367
368 Self::DocumentMetrics(req) => &req.path,
369 Self::ServerInfo(..) => return None,
370 })
371 }
372 }
373
374 #[derive(Debug, Clone, Serialize, Deserialize)]
376 #[serde(untagged)]
377 pub enum CompilerQueryResponse {
378 OnExport(Option<OnExportResponse>),
380 Hover(Option<Hover>),
382 GotoDefinition(Option<GotoDefinitionResponse>),
384 GotoDeclaration(Option<GotoDeclarationResponse>),
386 References(Option<Vec<LspLocation>>),
388 InlayHint(Option<Vec<InlayHint>>),
390 DocumentColor(Option<Vec<ColorInformation>>),
392 DocumentLink(Option<Vec<DocumentLink>>),
394 DocumentHighlight(Option<Vec<DocumentHighlight>>),
396 ColorPresentation(Option<Vec<ColorPresentation>>),
398 CodeAction(Option<Vec<CodeAction>>),
400 CodeLens(Option<Vec<CodeLens>>),
402 Completion(Option<CompletionList>),
404 SignatureHelp(Option<SignatureHelp>),
406 PrepareRename(Option<PrepareRenameResponse>),
408 Rename(Option<WorkspaceEdit>),
410 WillRenameFiles(Option<WorkspaceEdit>),
412 DocumentSymbol(Option<DocumentSymbolResponse>),
414 Symbol(Option<Vec<SymbolInformation>>),
416 WorkspaceLabel(Option<Vec<SymbolInformation>>),
418 SemanticTokensFull(Option<SemanticTokensResult>),
420 SemanticTokensDelta(Option<SemanticTokensFullDeltaResult>),
422 Formatting(Option<Vec<TextEdit>>),
424 FoldingRange(Option<Vec<FoldingRange>>),
426 SelectionRange(Option<Vec<SelectionRange>>),
428 InteractCodeContext(Option<Vec<Option<InteractCodeContextResponse>>>),
430
431 OnEnter(Option<Vec<TextEdit>>),
433
434 DocumentMetrics(Option<DocumentMetricsResponse>),
436 ServerInfo(Option<HashMap<String, ServerInfoResponse>>),
438 }
439}
440
441pub use polymorphic::*;
442
443#[cfg(test)]
444mod tests;