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