Analysis

Struct Analysis 

Source
pub struct Analysis {
    pub(crate) db: RootDatabase,
}
Expand description

Analysis is a snapshot of a world state at a moment in time. It is the main entry point for asking semantic information about the world. When the world state is advanced using AnalysisHost::apply_change method, all existing Analysis are canceled (most method return Err(Canceled)).

Fields§

§db: RootDatabase

Implementations§

Source§

impl Analysis

Source

pub const SUPPORTED_TRIGGER_CHARS: &[char] = typing::TRIGGER_CHARS

Source

pub fn from_single_file(text: String) -> (Analysis, FileId)

Source

pub(crate) fn from_ra_fixture( sema: &Semantics<'_, RootDatabase>, literal: String, expanded: &String, minicore: MiniCore<'_>, ) -> Option<(Analysis, RaFixtureAnalysis)>

Source

pub(crate) fn from_ra_fixture_with_on_cursor( sema: &Semantics<'_, RootDatabase>, literal: String, expanded: &String, minicore: MiniCore<'_>, on_cursor: &mut dyn FnMut(TextRange), ) -> Option<(Analysis, RaFixtureAnalysis)>

Like Analysis::from_ra_fixture(), but also calls on_cursor with the cursor position.

Source

pub fn status(&self, file_id: Option<FileId>) -> Cancellable<String>

Debug info about the current state of the analysis.

Source

pub fn source_root_id(&self, file_id: FileId) -> Cancellable<SourceRootId>

Source

pub fn is_local_source_root( &self, source_root_id: SourceRootId, ) -> Cancellable<bool>

Source

pub fn parallel_prime_caches<F>( &self, num_worker_threads: usize, cb: F, ) -> Cancellable<()>

Source

pub fn file_text(&self, file_id: FileId) -> Cancellable<Arc<str>>

Gets the text of the source file.

Source

pub fn parse(&self, file_id: FileId) -> Cancellable<SourceFile>

Gets the syntax tree of the file.

Source

pub fn is_library_file(&self, file_id: FileId) -> Cancellable<bool>

Returns true if this file belongs to an immutable library.

Source

pub fn file_line_index(&self, file_id: FileId) -> Cancellable<Arc<LineIndex>>

Gets the file’s LineIndex: data structure to convert between absolute offsets and line/column representation.

Source

pub fn extend_selection(&self, frange: FileRange) -> Cancellable<TextRange>

Selects the next syntactic nodes encompassing the range.

Source

pub fn matching_brace( &self, position: FilePosition, ) -> Cancellable<Option<TextSize>>

Returns position of the matching brace (all types of braces are supported).

Source

pub fn view_syntax_tree(&self, file_id: FileId) -> Cancellable<String>

Source

pub fn view_hir(&self, position: FilePosition) -> Cancellable<String>

Source

pub fn view_mir(&self, position: FilePosition) -> Cancellable<String>

Source

pub fn interpret_function(&self, position: FilePosition) -> Cancellable<String>

Source

pub fn view_item_tree(&self, file_id: FileId) -> Cancellable<String>

Source

pub fn discover_test_roots(&self) -> Cancellable<Vec<TestItem>>

Source

pub fn discover_tests_in_crate_by_test_id( &self, crate_id: &str, ) -> Cancellable<Vec<TestItem>>

Source

pub fn discover_tests_in_crate( &self, crate_id: Crate, ) -> Cancellable<Vec<TestItem>>

Source

pub fn discover_tests_in_file( &self, file_id: FileId, ) -> Cancellable<Vec<TestItem>>

Source

pub fn view_crate_graph( &self, full: bool, ) -> Cancellable<Result<String, String>>

Renders the crate graph to GraphViz “dot” syntax.

Source

pub fn fetch_crates(&self) -> Cancellable<FxIndexSet<CrateInfo>>

Source

pub fn expand_macro( &self, position: FilePosition, ) -> Cancellable<Option<ExpandedMacro>>

Source

pub fn join_lines( &self, config: &JoinLinesConfig, frange: FileRange, ) -> Cancellable<TextEdit>

Returns an edit to remove all newlines in the range, cleaning up minor stuff like trailing commas.

Source

pub fn on_enter(&self, position: FilePosition) -> Cancellable<Option<TextEdit>>

Returns an edit which should be applied when opening a new line, fixing up minor stuff like continuing the comment. The edit will be a snippet (with $0).

Source

pub fn on_char_typed( &self, position: FilePosition, char_typed: char, ) -> Cancellable<Option<SourceChange>>

Returns an edit which should be applied after a character was typed.

This is useful for some on-the-fly fixups, like adding ; to let = automatically.

Source

pub fn file_structure( &self, config: &FileStructureConfig, file_id: FileId, ) -> Cancellable<Vec<StructureNode>>

Returns a tree representation of symbols in the file. Useful to draw a file outline.

Source

pub fn inlay_hints( &self, config: &InlayHintsConfig<'_>, file_id: FileId, range: Option<TextRange>, ) -> Cancellable<Vec<InlayHint>>

Returns a list of the places in the file where type hints can be displayed.

Source

pub fn inlay_hints_resolve( &self, config: &InlayHintsConfig<'_>, file_id: FileId, resolve_range: TextRange, hash: u64, hasher: impl Fn(&InlayHint) -> u64 + Send + UnwindSafe, ) -> Cancellable<Option<InlayHint>>

Source

pub fn folding_ranges(&self, file_id: FileId) -> Cancellable<Vec<Fold>>

Returns the set of folding ranges.

Fuzzy searches for a symbol.

Source

pub fn goto_definition( &self, position: FilePosition, config: &GotoDefinitionConfig<'_>, ) -> Cancellable<Option<RangeInfo<Vec<NavigationTarget>>>>

Returns the definitions from the symbol at position.

Source

pub fn goto_declaration( &self, position: FilePosition, config: &GotoDefinitionConfig<'_>, ) -> Cancellable<Option<RangeInfo<Vec<NavigationTarget>>>>

Returns the declaration from the symbol at position.

Source

pub fn goto_implementation( &self, config: &GotoImplementationConfig, position: FilePosition, ) -> Cancellable<Option<RangeInfo<Vec<NavigationTarget>>>>

Returns the impls from the symbol at position.

Source

pub fn goto_type_definition( &self, position: FilePosition, ) -> Cancellable<Option<RangeInfo<Vec<NavigationTarget>>>>

Returns the type definitions for the symbol at position.

Source

pub fn find_all_refs( &self, position: FilePosition, config: &FindAllRefsConfig<'_>, ) -> Cancellable<Option<Vec<ReferenceSearchResult>>>

Source

pub fn hover( &self, config: &HoverConfig<'_>, range: FileRange, ) -> Cancellable<Option<RangeInfo<HoverResult>>>

Returns a short text describing element at position.

Source

pub fn moniker( &self, position: FilePosition, ) -> Cancellable<Option<RangeInfo<Vec<MonikerResult>>>>

Returns moniker of symbol at position.

Source

pub fn external_docs( &self, position: FilePosition, target_dir: Option<&str>, sysroot: Option<&str>, ) -> Cancellable<DocumentationLinks>

Returns URL(s) for the documentation of the symbol under the cursor.

§Arguments
  • position - Position in the file.
  • target_dir - Directory where the build output is stored.
Source

pub fn signature_help( &self, position: FilePosition, ) -> Cancellable<Option<SignatureHelp>>

Computes parameter information at the given position.

Source

pub fn call_hierarchy( &self, position: FilePosition, config: &CallHierarchyConfig<'_>, ) -> Cancellable<Option<RangeInfo<Vec<NavigationTarget>>>>

Computes call hierarchy candidates for the given file position.

Source

pub fn incoming_calls( &self, config: &CallHierarchyConfig<'_>, position: FilePosition, ) -> Cancellable<Option<Vec<CallItem>>>

Computes incoming calls for the given file position.

Source

pub fn outgoing_calls( &self, config: &CallHierarchyConfig<'_>, position: FilePosition, ) -> Cancellable<Option<Vec<CallItem>>>

Computes outgoing calls for the given file position.

Source

pub fn parent_module( &self, position: FilePosition, ) -> Cancellable<Vec<NavigationTarget>>

Returns a mod name; declaration which created the current module.

Source

pub fn child_modules( &self, position: FilePosition, ) -> Cancellable<Vec<NavigationTarget>>

Returns vec of mod name; declaration which are created by the current module.

Source

pub fn crates_for(&self, file_id: FileId) -> Cancellable<Vec<Crate>>

Returns crates that this file belongs to.

Source

pub fn transitive_rev_deps(&self, crate_id: Crate) -> Cancellable<Vec<Crate>>

Returns crates that this file belongs to.

Source

pub fn relevant_crates_for(&self, file_id: FileId) -> Cancellable<Vec<Crate>>

Returns crates that this file might belong to.

Source

pub fn crate_edition(&self, crate_id: Crate) -> Cancellable<Edition>

Returns the edition of the given crate.

Source

pub fn is_proc_macro_crate(&self, crate_id: Crate) -> Cancellable<bool>

Returns whether the given crate is a proc macro.

Source

pub fn is_crate_no_std(&self, crate_id: Crate) -> Cancellable<bool>

Returns true if this crate has no_std or no_core specified.

Source

pub fn crate_root(&self, crate_id: Crate) -> Cancellable<FileId>

Returns the root file of the given crate.

Source

pub fn runnables(&self, file_id: FileId) -> Cancellable<Vec<Runnable>>

Returns the set of possible targets to run for the current file.

Source

pub fn related_tests( &self, position: FilePosition, search_scope: Option<SearchScope>, ) -> Cancellable<Vec<Runnable>>

Returns the set of tests for the given file position.

Computes all ranges to highlight for a given item in a file.

Source

pub fn highlight( &self, highlight_config: HighlightConfig<'_>, file_id: FileId, ) -> Cancellable<Vec<HlRange>>

Computes syntax highlighting for the given file

Source

pub fn highlight_range( &self, highlight_config: HighlightConfig<'_>, frange: FileRange, ) -> Cancellable<Vec<HlRange>>

Computes syntax highlighting for the given file range.

Source

pub fn highlight_as_html_with_config( &self, config: HighlightConfig<'_>, file_id: FileId, rainbow: bool, ) -> Cancellable<String>

Computes syntax highlighting for the given file.

Source

pub fn highlight_as_html( &self, file_id: FileId, rainbow: bool, ) -> Cancellable<String>

Computes syntax highlighting for the given file.

Source

pub fn completions( &self, config: &CompletionConfig<'_>, position: FilePosition, trigger_character: Option<char>, ) -> Cancellable<Option<Vec<CompletionItem>>>

Computes completions at the given position.

Source

pub fn resolve_completion_edits( &self, config: &CompletionConfig<'_>, position: FilePosition, imports: impl IntoIterator<Item = String> + UnwindSafe, ) -> Cancellable<Vec<TextEdit>>

Resolves additional completion data at the position given.

Source

pub fn syntax_diagnostics( &self, config: &DiagnosticsConfig, file_id: FileId, ) -> Cancellable<Vec<Diagnostic>>

Computes the set of parser level diagnostics for the given file.

Source

pub fn semantic_diagnostics( &self, config: &DiagnosticsConfig, resolve: AssistResolveStrategy, file_id: FileId, ) -> Cancellable<Vec<Diagnostic>>

Computes the set of semantic diagnostics for the given file.

Source

pub fn full_diagnostics( &self, config: &DiagnosticsConfig, resolve: AssistResolveStrategy, file_id: FileId, ) -> Cancellable<Vec<Diagnostic>>

Computes the set of both syntax and semantic diagnostics for the given file.

Source

pub fn assists_with_fixes( &self, assist_config: &AssistConfig, diagnostics_config: &DiagnosticsConfig, resolve: AssistResolveStrategy, frange: FileRange, ) -> Cancellable<Vec<Assist>>

Convenience function to return assists + quick fixes for diagnostics

Source

pub fn rename( &self, position: FilePosition, new_name: &str, config: &RenameConfig, ) -> Cancellable<Result<SourceChange, RenameError>>

Returns the edit required to rename reference at the position to the new name.

Source

pub fn prepare_rename( &self, position: FilePosition, ) -> Cancellable<Result<RangeInfo<()>, RenameError>>

Source

pub fn will_rename_file( &self, file_id: FileId, new_name_stem: &str, config: &RenameConfig, ) -> Cancellable<Option<SourceChange>>

Source

pub fn structural_search_replace( &self, query: &str, parse_only: bool, resolve_context: FilePosition, selections: Vec<FileRange>, ) -> Cancellable<Result<SourceChange, SsrError>>

Source

pub fn annotations( &self, config: &AnnotationConfig<'_>, file_id: FileId, ) -> Cancellable<Vec<Annotation>>

Source

pub fn resolve_annotation( &self, config: &AnnotationConfig<'_>, annotation: Annotation, ) -> Cancellable<Annotation>

Source

pub fn move_item( &self, range: FileRange, direction: Direction, ) -> Cancellable<Option<TextEdit>>

Source

pub fn get_recursive_memory_layout( &self, position: FilePosition, ) -> Cancellable<Option<RecursiveMemoryLayout>>

Source

pub fn get_failed_obligations( &self, offset: TextSize, file_id: FileId, ) -> Cancellable<String>

Source

pub fn editioned_file_id_to_vfs(&self, file_id: EditionedFileId) -> FileId

Source

pub(crate) fn with_db<F, T>(&self, f: F) -> Cancellable<T>
where F: FnOnce(&RootDatabase) -> T + UnwindSafe,

Performs an operation on the database that may be canceled.

rust-analyzer needs to be able to answer semantic questions about the code while the code is being modified. A common problem is that a long-running query is being calculated when a new change arrives.

We can’t just apply the change immediately: this will cause the pending query to see inconsistent state (it will observe an absence of repeatable read). So what we do is we cancel all pending queries before applying the change.

Salsa implements cancellation by unwinding with a special value and catching it on the API boundary.

Trait Implementations§

Source§

impl Debug for Analysis

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T, R> CollectAndApply<T, R> for T

§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

§

type Output = R

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoBox<dyn Any> for T
where T: Any,

§

fn into_box(self) -> Box<dyn Any>

Convert self into the appropriate boxed form.
§

impl<T> IntoBox<dyn Any + Send> for T
where T: Any + Send,

§

fn into_box(self) -> Box<dyn Any + Send>

Convert self into the appropriate boxed form.
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<I, T, U> Upcast<I, U> for T
where U: UpcastFrom<I, T>,

§

fn upcast(self, interner: I) -> U

§

impl<I, T> UpcastFrom<I, T> for T

§

fn upcast_from(from: T, _tcx: I) -> T

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

§

impl<T> ErasedDestructor for T
where T: 'static,