]> git.lizzy.rs Git - rust.git/blob - crates/ide/src/lib.rs
internal: prepare to move assist definitions
[rust.git] / crates / ide / src / lib.rs
1 //! ide crate provides "ide-centric" APIs for the rust-analyzer. That is,
2 //! it generally operates with files and text ranges, and returns results as
3 //! Strings, suitable for displaying to the human.
4 //!
5 //! What powers this API are the `RootDatabase` struct, which defines a `salsa`
6 //! database, and the `hir` crate, where majority of the analysis happens.
7 //! However, IDE specific bits of the analysis (most notably completion) happen
8 //! in this crate.
9
10 // For proving that RootDatabase is RefUnwindSafe.
11 #![recursion_limit = "128"]
12
13 #[allow(unused)]
14 macro_rules! eprintln {
15     ($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
16 }
17
18 #[cfg(test)]
19 mod fixture;
20
21 mod markup;
22 mod prime_caches;
23 mod display;
24
25 mod annotations;
26 mod call_hierarchy;
27 mod expand_macro;
28 mod extend_selection;
29 mod file_structure;
30 mod folding_ranges;
31 mod goto_definition;
32 mod goto_implementation;
33 mod goto_type_definition;
34 mod view_hir;
35 mod hover;
36 mod inlay_hints;
37 mod join_lines;
38 mod matching_brace;
39 mod move_item;
40 mod parent_module;
41 mod references;
42 mod fn_references;
43 mod runnables;
44 mod ssr;
45 mod status;
46 mod syntax_highlighting;
47 mod syntax_tree;
48 mod typing;
49 mod markdown_remove;
50 mod doc_links;
51 mod view_crate_graph;
52 mod view_item_tree;
53
54 use std::sync::Arc;
55
56 use cfg::CfgOptions;
57
58 use ide_db::base_db::{
59     salsa::{self, ParallelDatabase},
60     Env, FileLoader, FileSet, SourceDatabase, VfsPath,
61 };
62 use ide_db::{
63     symbol_index::{self, FileSymbol},
64     LineIndexDatabase,
65 };
66 use syntax::SourceFile;
67
68 use crate::display::ToNav;
69
70 pub use crate::{
71     annotations::{Annotation, AnnotationConfig, AnnotationKind},
72     call_hierarchy::CallItem,
73     display::navigation_target::NavigationTarget,
74     expand_macro::ExpandedMacro,
75     file_structure::{StructureNode, StructureNodeKind},
76     folding_ranges::{Fold, FoldKind},
77     hover::{HoverAction, HoverConfig, HoverGotoTypeData, HoverResult},
78     inlay_hints::{InlayHint, InlayHintsConfig, InlayKind},
79     markup::Markup,
80     move_item::Direction,
81     prime_caches::PrimeCachesProgress,
82     references::{rename::RenameError, ReferenceSearchResult},
83     runnables::{Runnable, RunnableKind, TestId},
84     syntax_highlighting::{
85         tags::{Highlight, HlMod, HlMods, HlOperator, HlPunct, HlTag},
86         HlRange,
87     },
88 };
89 pub use hir::{Documentation, Semantics};
90 pub use ide_assists::{
91     Assist, AssistConfig, AssistId, AssistKind, AssistResolveStrategy, SingleResolve,
92 };
93 pub use ide_completion::{
94     CompletionConfig, CompletionItem, CompletionItemKind, CompletionRelevance, ImportEdit,
95     InsertTextFormat,
96 };
97 pub use ide_db::{
98     base_db::{
99         Cancelled, Change, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange,
100         SourceRoot, SourceRootId,
101     },
102     call_info::CallInfo,
103     label::Label,
104     line_index::{LineCol, LineColUtf16, LineIndex},
105     search::{ReferenceAccess, SearchScope},
106     source_change::{FileSystemEdit, SourceChange},
107     symbol_index::Query,
108     RootDatabase, SymbolKind,
109 };
110 pub use ide_diagnostics::{Diagnostic, DiagnosticsConfig, Severity};
111 pub use ide_ssr::SsrError;
112 pub use syntax::{TextRange, TextSize};
113 pub use text_edit::{Indel, TextEdit};
114
115 pub type Cancellable<T> = Result<T, Cancelled>;
116
117 /// Info associated with a text range.
118 #[derive(Debug)]
119 pub struct RangeInfo<T> {
120     pub range: TextRange,
121     pub info: T,
122 }
123
124 impl<T> RangeInfo<T> {
125     pub fn new(range: TextRange, info: T) -> RangeInfo<T> {
126         RangeInfo { range, info }
127     }
128 }
129
130 /// `AnalysisHost` stores the current state of the world.
131 #[derive(Debug)]
132 pub struct AnalysisHost {
133     db: RootDatabase,
134 }
135
136 impl AnalysisHost {
137     pub fn new(lru_capacity: Option<usize>) -> AnalysisHost {
138         AnalysisHost { db: RootDatabase::new(lru_capacity) }
139     }
140
141     pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) {
142         self.db.update_lru_capacity(lru_capacity);
143     }
144
145     /// Returns a snapshot of the current state, which you can query for
146     /// semantic information.
147     pub fn analysis(&self) -> Analysis {
148         Analysis { db: self.db.snapshot() }
149     }
150
151     /// Applies changes to the current state of the world. If there are
152     /// outstanding snapshots, they will be canceled.
153     pub fn apply_change(&mut self, change: Change) {
154         self.db.apply_change(change)
155     }
156
157     pub fn collect_garbage(&mut self) {
158         self.db.collect_garbage();
159     }
160     /// NB: this clears the database
161     pub fn per_query_memory_usage(&mut self) -> Vec<(String, profile::Bytes)> {
162         self.db.per_query_memory_usage()
163     }
164     pub fn request_cancellation(&mut self) {
165         self.db.request_cancellation();
166     }
167     pub fn raw_database(&self) -> &RootDatabase {
168         &self.db
169     }
170     pub fn raw_database_mut(&mut self) -> &mut RootDatabase {
171         &mut self.db
172     }
173 }
174
175 impl Default for AnalysisHost {
176     fn default() -> AnalysisHost {
177         AnalysisHost::new(None)
178     }
179 }
180
181 /// Analysis is a snapshot of a world state at a moment in time. It is the main
182 /// entry point for asking semantic information about the world. When the world
183 /// state is advanced using `AnalysisHost::apply_change` method, all existing
184 /// `Analysis` are canceled (most method return `Err(Canceled)`).
185 #[derive(Debug)]
186 pub struct Analysis {
187     db: salsa::Snapshot<RootDatabase>,
188 }
189
190 // As a general design guideline, `Analysis` API are intended to be independent
191 // from the language server protocol. That is, when exposing some functionality
192 // we should think in terms of "what API makes most sense" and not in terms of
193 // "what types LSP uses". Although currently LSP is the only consumer of the
194 // API, the API should in theory be usable as a library, or via a different
195 // protocol.
196 impl Analysis {
197     // Creates an analysis instance for a single file, without any extenal
198     // dependencies, stdlib support or ability to apply changes. See
199     // `AnalysisHost` for creating a fully-featured analysis.
200     pub fn from_single_file(text: String) -> (Analysis, FileId) {
201         let mut host = AnalysisHost::default();
202         let file_id = FileId(0);
203         let mut file_set = FileSet::default();
204         file_set.insert(file_id, VfsPath::new_virtual_path("/main.rs".to_string()));
205         let source_root = SourceRoot::new_local(file_set);
206
207         let mut change = Change::new();
208         change.set_roots(vec![source_root]);
209         let mut crate_graph = CrateGraph::default();
210         // FIXME: cfg options
211         // Default to enable test for single file.
212         let mut cfg_options = CfgOptions::default();
213         cfg_options.insert_atom("test".into());
214         crate_graph.add_crate_root(
215             file_id,
216             Edition::Edition2018,
217             None,
218             cfg_options,
219             Env::default(),
220             Default::default(),
221         );
222         change.change_file(file_id, Some(Arc::new(text)));
223         change.set_crate_graph(crate_graph);
224         host.apply_change(change);
225         (host.analysis(), file_id)
226     }
227
228     /// Debug info about the current state of the analysis.
229     pub fn status(&self, file_id: Option<FileId>) -> Cancellable<String> {
230         self.with_db(|db| status::status(&*db, file_id))
231     }
232
233     pub fn prime_caches<F>(&self, cb: F) -> Cancellable<()>
234     where
235         F: Fn(PrimeCachesProgress) + Sync + std::panic::UnwindSafe,
236     {
237         self.with_db(move |db| prime_caches::prime_caches(db, &cb))
238     }
239
240     /// Gets the text of the source file.
241     pub fn file_text(&self, file_id: FileId) -> Cancellable<Arc<String>> {
242         self.with_db(|db| db.file_text(file_id))
243     }
244
245     /// Gets the syntax tree of the file.
246     pub fn parse(&self, file_id: FileId) -> Cancellable<SourceFile> {
247         self.with_db(|db| db.parse(file_id).tree())
248     }
249
250     /// Returns true if this file belongs to an immutable library.
251     pub fn is_library_file(&self, file_id: FileId) -> Cancellable<bool> {
252         use ide_db::base_db::SourceDatabaseExt;
253         self.with_db(|db| db.source_root(db.file_source_root(file_id)).is_library)
254     }
255
256     /// Gets the file's `LineIndex`: data structure to convert between absolute
257     /// offsets and line/column representation.
258     pub fn file_line_index(&self, file_id: FileId) -> Cancellable<Arc<LineIndex>> {
259         self.with_db(|db| db.line_index(file_id))
260     }
261
262     /// Selects the next syntactic nodes encompassing the range.
263     pub fn extend_selection(&self, frange: FileRange) -> Cancellable<TextRange> {
264         self.with_db(|db| extend_selection::extend_selection(db, frange))
265     }
266
267     /// Returns position of the matching brace (all types of braces are
268     /// supported).
269     pub fn matching_brace(&self, position: FilePosition) -> Cancellable<Option<TextSize>> {
270         self.with_db(|db| {
271             let parse = db.parse(position.file_id);
272             let file = parse.tree();
273             matching_brace::matching_brace(&file, position.offset)
274         })
275     }
276
277     /// Returns a syntax tree represented as `String`, for debug purposes.
278     // FIXME: use a better name here.
279     pub fn syntax_tree(
280         &self,
281         file_id: FileId,
282         text_range: Option<TextRange>,
283     ) -> Cancellable<String> {
284         self.with_db(|db| syntax_tree::syntax_tree(db, file_id, text_range))
285     }
286
287     pub fn view_hir(&self, position: FilePosition) -> Cancellable<String> {
288         self.with_db(|db| view_hir::view_hir(db, position))
289     }
290
291     pub fn view_item_tree(&self, file_id: FileId) -> Cancellable<String> {
292         self.with_db(|db| view_item_tree::view_item_tree(db, file_id))
293     }
294
295     /// Renders the crate graph to GraphViz "dot" syntax.
296     pub fn view_crate_graph(&self) -> Cancellable<Result<String, String>> {
297         self.with_db(|db| view_crate_graph::view_crate_graph(db))
298     }
299
300     pub fn expand_macro(&self, position: FilePosition) -> Cancellable<Option<ExpandedMacro>> {
301         self.with_db(|db| expand_macro::expand_macro(db, position))
302     }
303
304     /// Returns an edit to remove all newlines in the range, cleaning up minor
305     /// stuff like trailing commas.
306     pub fn join_lines(&self, frange: FileRange) -> Cancellable<TextEdit> {
307         self.with_db(|db| {
308             let parse = db.parse(frange.file_id);
309             join_lines::join_lines(&parse.tree(), frange.range)
310         })
311     }
312
313     /// Returns an edit which should be applied when opening a new line, fixing
314     /// up minor stuff like continuing the comment.
315     /// The edit will be a snippet (with `$0`).
316     pub fn on_enter(&self, position: FilePosition) -> Cancellable<Option<TextEdit>> {
317         self.with_db(|db| typing::on_enter(db, position))
318     }
319
320     /// Returns an edit which should be applied after a character was typed.
321     ///
322     /// This is useful for some on-the-fly fixups, like adding `;` to `let =`
323     /// automatically.
324     pub fn on_char_typed(
325         &self,
326         position: FilePosition,
327         char_typed: char,
328     ) -> Cancellable<Option<SourceChange>> {
329         // Fast path to not even parse the file.
330         if !typing::TRIGGER_CHARS.contains(char_typed) {
331             return Ok(None);
332         }
333         self.with_db(|db| typing::on_char_typed(db, position, char_typed))
334     }
335
336     /// Returns a tree representation of symbols in the file. Useful to draw a
337     /// file outline.
338     pub fn file_structure(&self, file_id: FileId) -> Cancellable<Vec<StructureNode>> {
339         self.with_db(|db| file_structure::file_structure(&db.parse(file_id).tree()))
340     }
341
342     /// Returns a list of the places in the file where type hints can be displayed.
343     pub fn inlay_hints(
344         &self,
345         file_id: FileId,
346         config: &InlayHintsConfig,
347     ) -> Cancellable<Vec<InlayHint>> {
348         self.with_db(|db| inlay_hints::inlay_hints(db, file_id, config))
349     }
350
351     /// Returns the set of folding ranges.
352     pub fn folding_ranges(&self, file_id: FileId) -> Cancellable<Vec<Fold>> {
353         self.with_db(|db| folding_ranges::folding_ranges(&db.parse(file_id).tree()))
354     }
355
356     /// Fuzzy searches for a symbol.
357     pub fn symbol_search(&self, query: Query) -> Cancellable<Vec<NavigationTarget>> {
358         self.with_db(|db| {
359             symbol_index::world_symbols(db, query)
360                 .into_iter()
361                 .map(|s| s.to_nav(db))
362                 .collect::<Vec<_>>()
363         })
364     }
365
366     /// Returns the definitions from the symbol at `position`.
367     pub fn goto_definition(
368         &self,
369         position: FilePosition,
370     ) -> Cancellable<Option<RangeInfo<Vec<NavigationTarget>>>> {
371         self.with_db(|db| goto_definition::goto_definition(db, position))
372     }
373
374     /// Returns the impls from the symbol at `position`.
375     pub fn goto_implementation(
376         &self,
377         position: FilePosition,
378     ) -> Cancellable<Option<RangeInfo<Vec<NavigationTarget>>>> {
379         self.with_db(|db| goto_implementation::goto_implementation(db, position))
380     }
381
382     /// Returns the type definitions for the symbol at `position`.
383     pub fn goto_type_definition(
384         &self,
385         position: FilePosition,
386     ) -> Cancellable<Option<RangeInfo<Vec<NavigationTarget>>>> {
387         self.with_db(|db| goto_type_definition::goto_type_definition(db, position))
388     }
389
390     /// Finds all usages of the reference at point.
391     pub fn find_all_refs(
392         &self,
393         position: FilePosition,
394         search_scope: Option<SearchScope>,
395     ) -> Cancellable<Option<ReferenceSearchResult>> {
396         self.with_db(|db| references::find_all_refs(&Semantics::new(db), position, search_scope))
397     }
398
399     /// Finds all methods and free functions for the file. Does not return tests!
400     pub fn find_all_methods(&self, file_id: FileId) -> Cancellable<Vec<FileRange>> {
401         self.with_db(|db| fn_references::find_all_methods(db, file_id))
402     }
403
404     /// Returns a short text describing element at position.
405     pub fn hover(
406         &self,
407         position: FilePosition,
408         links_in_hover: bool,
409         markdown: bool,
410     ) -> Cancellable<Option<RangeInfo<HoverResult>>> {
411         self.with_db(|db| hover::hover(db, position, links_in_hover, markdown))
412     }
413
414     /// Return URL(s) for the documentation of the symbol under the cursor.
415     pub fn external_docs(
416         &self,
417         position: FilePosition,
418     ) -> Cancellable<Option<doc_links::DocumentationLink>> {
419         self.with_db(|db| doc_links::external_docs(db, &position))
420     }
421
422     /// Computes parameter information for the given call expression.
423     pub fn call_info(&self, position: FilePosition) -> Cancellable<Option<CallInfo>> {
424         self.with_db(|db| ide_db::call_info::call_info(db, position))
425     }
426
427     /// Computes call hierarchy candidates for the given file position.
428     pub fn call_hierarchy(
429         &self,
430         position: FilePosition,
431     ) -> Cancellable<Option<RangeInfo<Vec<NavigationTarget>>>> {
432         self.with_db(|db| call_hierarchy::call_hierarchy(db, position))
433     }
434
435     /// Computes incoming calls for the given file position.
436     pub fn incoming_calls(&self, position: FilePosition) -> Cancellable<Option<Vec<CallItem>>> {
437         self.with_db(|db| call_hierarchy::incoming_calls(db, position))
438     }
439
440     /// Computes incoming calls for the given file position.
441     pub fn outgoing_calls(&self, position: FilePosition) -> Cancellable<Option<Vec<CallItem>>> {
442         self.with_db(|db| call_hierarchy::outgoing_calls(db, position))
443     }
444
445     /// Returns a `mod name;` declaration which created the current module.
446     pub fn parent_module(&self, position: FilePosition) -> Cancellable<Vec<NavigationTarget>> {
447         self.with_db(|db| parent_module::parent_module(db, position))
448     }
449
450     /// Returns crates this file belongs too.
451     pub fn crate_for(&self, file_id: FileId) -> Cancellable<Vec<CrateId>> {
452         self.with_db(|db| parent_module::crate_for(db, file_id))
453     }
454
455     /// Returns the edition of the given crate.
456     pub fn crate_edition(&self, crate_id: CrateId) -> Cancellable<Edition> {
457         self.with_db(|db| db.crate_graph()[crate_id].edition)
458     }
459
460     /// Returns the root file of the given crate.
461     pub fn crate_root(&self, crate_id: CrateId) -> Cancellable<FileId> {
462         self.with_db(|db| db.crate_graph()[crate_id].root_file_id)
463     }
464
465     /// Returns the set of possible targets to run for the current file.
466     pub fn runnables(&self, file_id: FileId) -> Cancellable<Vec<Runnable>> {
467         self.with_db(|db| runnables::runnables(db, file_id))
468     }
469
470     /// Returns the set of tests for the given file position.
471     pub fn related_tests(
472         &self,
473         position: FilePosition,
474         search_scope: Option<SearchScope>,
475     ) -> Cancellable<Vec<Runnable>> {
476         self.with_db(|db| runnables::related_tests(db, position, search_scope))
477     }
478
479     /// Computes syntax highlighting for the given file
480     pub fn highlight(&self, file_id: FileId) -> Cancellable<Vec<HlRange>> {
481         self.with_db(|db| syntax_highlighting::highlight(db, file_id, None, false))
482     }
483
484     /// Computes syntax highlighting for the given file range.
485     pub fn highlight_range(&self, frange: FileRange) -> Cancellable<Vec<HlRange>> {
486         self.with_db(|db| {
487             syntax_highlighting::highlight(db, frange.file_id, Some(frange.range), false)
488         })
489     }
490
491     /// Computes syntax highlighting for the given file.
492     pub fn highlight_as_html(&self, file_id: FileId, rainbow: bool) -> Cancellable<String> {
493         self.with_db(|db| syntax_highlighting::highlight_as_html(db, file_id, rainbow))
494     }
495
496     /// Computes completions at the given position.
497     pub fn completions(
498         &self,
499         config: &CompletionConfig,
500         position: FilePosition,
501     ) -> Cancellable<Option<Vec<CompletionItem>>> {
502         self.with_db(|db| ide_completion::completions(db, config, position).map(Into::into))
503     }
504
505     /// Resolves additional completion data at the position given.
506     pub fn resolve_completion_edits(
507         &self,
508         config: &CompletionConfig,
509         position: FilePosition,
510         full_import_path: &str,
511         imported_name: String,
512     ) -> Cancellable<Vec<TextEdit>> {
513         Ok(self
514             .with_db(|db| {
515                 ide_completion::resolve_completion_edits(
516                     db,
517                     config,
518                     position,
519                     full_import_path,
520                     imported_name,
521                 )
522             })?
523             .unwrap_or_default())
524     }
525
526     /// Computes assists (aka code actions aka intentions) for the given
527     /// position. If `resolve == false`, computes enough info to show the
528     /// lightbulb list in the editor, but doesn't compute actual edits, to
529     /// improve performance.
530     pub fn assists(
531         &self,
532         config: &AssistConfig,
533         resolve: AssistResolveStrategy,
534         frange: FileRange,
535     ) -> Cancellable<Vec<Assist>> {
536         self.with_db(|db| {
537             let ssr_assists = ssr::ssr_assists(db, &resolve, frange);
538             let mut acc = ide_assists::assists(db, config, resolve, frange);
539             acc.extend(ssr_assists.into_iter());
540             acc
541         })
542     }
543
544     /// Computes the set of diagnostics for the given file.
545     pub fn diagnostics(
546         &self,
547         config: &DiagnosticsConfig,
548         resolve: AssistResolveStrategy,
549         file_id: FileId,
550     ) -> Cancellable<Vec<Diagnostic>> {
551         self.with_db(|db| ide_diagnostics::diagnostics(db, config, &resolve, file_id))
552     }
553
554     /// Convenience function to return assists + quick fixes for diagnostics
555     pub fn assists_with_fixes(
556         &self,
557         assist_config: &AssistConfig,
558         diagnostics_config: &DiagnosticsConfig,
559         resolve: AssistResolveStrategy,
560         frange: FileRange,
561     ) -> Cancellable<Vec<Assist>> {
562         let include_fixes = match &assist_config.allowed {
563             Some(it) => it.iter().any(|&it| it == AssistKind::None || it == AssistKind::QuickFix),
564             None => true,
565         };
566
567         self.with_db(|db| {
568             let ssr_assists = ssr::ssr_assists(db, &resolve, frange);
569             let diagnostic_assists = if include_fixes {
570                 ide_diagnostics::diagnostics(db, diagnostics_config, &resolve, frange.file_id)
571                     .into_iter()
572                     .flat_map(|it| it.fixes.unwrap_or_default())
573                     .filter(|it| it.target.intersect(frange.range).is_some())
574                     .collect()
575             } else {
576                 Vec::new()
577             };
578
579             let mut res = ide_assists::assists(db, assist_config, resolve, frange);
580             res.extend(ssr_assists.into_iter());
581             res.extend(diagnostic_assists.into_iter());
582
583             res
584         })
585     }
586
587     /// Returns the edit required to rename reference at the position to the new
588     /// name.
589     pub fn rename(
590         &self,
591         position: FilePosition,
592         new_name: &str,
593     ) -> Cancellable<Result<SourceChange, RenameError>> {
594         self.with_db(|db| references::rename::rename(db, position, new_name))
595     }
596
597     pub fn prepare_rename(
598         &self,
599         position: FilePosition,
600     ) -> Cancellable<Result<RangeInfo<()>, RenameError>> {
601         self.with_db(|db| references::rename::prepare_rename(db, position))
602     }
603
604     pub fn will_rename_file(
605         &self,
606         file_id: FileId,
607         new_name_stem: &str,
608     ) -> Cancellable<Option<SourceChange>> {
609         self.with_db(|db| references::rename::will_rename_file(db, file_id, new_name_stem))
610     }
611
612     pub fn structural_search_replace(
613         &self,
614         query: &str,
615         parse_only: bool,
616         resolve_context: FilePosition,
617         selections: Vec<FileRange>,
618     ) -> Cancellable<Result<SourceChange, SsrError>> {
619         self.with_db(|db| {
620             let rule: ide_ssr::SsrRule = query.parse()?;
621             let mut match_finder =
622                 ide_ssr::MatchFinder::in_context(db, resolve_context, selections);
623             match_finder.add_rule(rule)?;
624             let edits = if parse_only { Default::default() } else { match_finder.edits() };
625             Ok(SourceChange::from(edits))
626         })
627     }
628
629     pub fn annotations(
630         &self,
631         file_id: FileId,
632         config: AnnotationConfig,
633     ) -> Cancellable<Vec<Annotation>> {
634         self.with_db(|db| annotations::annotations(db, file_id, config))
635     }
636
637     pub fn resolve_annotation(&self, annotation: Annotation) -> Cancellable<Annotation> {
638         self.with_db(|db| annotations::resolve_annotation(db, annotation))
639     }
640
641     pub fn move_item(
642         &self,
643         range: FileRange,
644         direction: Direction,
645     ) -> Cancellable<Option<TextEdit>> {
646         self.with_db(|db| move_item::move_item(db, range, direction))
647     }
648
649     /// Performs an operation on the database that may be canceled.
650     ///
651     /// rust-analyzer needs to be able to answer semantic questions about the
652     /// code while the code is being modified. A common problem is that a
653     /// long-running query is being calculated when a new change arrives.
654     ///
655     /// We can't just apply the change immediately: this will cause the pending
656     /// query to see inconsistent state (it will observe an absence of
657     /// repeatable read). So what we do is we **cancel** all pending queries
658     /// before applying the change.
659     ///
660     /// Salsa implements cancelation by unwinding with a special value and
661     /// catching it on the API boundary.
662     fn with_db<F, T>(&self, f: F) -> Cancellable<T>
663     where
664         F: FnOnce(&RootDatabase) -> T + std::panic::UnwindSafe,
665     {
666         Cancelled::catch(|| f(&self.db))
667     }
668 }
669
670 #[test]
671 fn analysis_is_send() {
672     fn is_send<T: Send>() {}
673     is_send::<Analysis>();
674 }