mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
add config for import filtering
This commit is contained in:
parent
eba54c2fc9
commit
9f6553e1d6
6 changed files with 29 additions and 6 deletions
|
@ -158,6 +158,7 @@ pub(crate) fn resolve_annotation(db: &RootDatabase, mut annotation: Annotation)
|
||||||
&Semantics::new(db),
|
&Semantics::new(db),
|
||||||
FilePosition { file_id, offset: annotation.range.start() },
|
FilePosition { file_id, offset: annotation.range.start() },
|
||||||
None,
|
None,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.map(|result| {
|
.map(|result| {
|
||||||
result
|
result
|
||||||
|
|
|
@ -425,8 +425,11 @@ impl Analysis {
|
||||||
&self,
|
&self,
|
||||||
position: FilePosition,
|
position: FilePosition,
|
||||||
search_scope: Option<SearchScope>,
|
search_scope: Option<SearchScope>,
|
||||||
|
exclude_imports: bool,
|
||||||
) -> Cancellable<Option<Vec<ReferenceSearchResult>>> {
|
) -> Cancellable<Option<Vec<ReferenceSearchResult>>> {
|
||||||
self.with_db(|db| references::find_all_refs(&Semantics::new(db), position, search_scope))
|
self.with_db(|db| {
|
||||||
|
references::find_all_refs(&Semantics::new(db), position, search_scope, exclude_imports)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds all methods and free functions for the file. Does not return tests!
|
/// Finds all methods and free functions for the file. Does not return tests!
|
||||||
|
|
|
@ -54,6 +54,7 @@ pub(crate) fn find_all_refs(
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
position: FilePosition,
|
position: FilePosition,
|
||||||
search_scope: Option<SearchScope>,
|
search_scope: Option<SearchScope>,
|
||||||
|
exclude_imports: bool,
|
||||||
) -> Option<Vec<ReferenceSearchResult>> {
|
) -> Option<Vec<ReferenceSearchResult>> {
|
||||||
let _p = profile::span("find_all_refs");
|
let _p = profile::span("find_all_refs");
|
||||||
let syntax = sema.parse(position.file_id).syntax().clone();
|
let syntax = sema.parse(position.file_id).syntax().clone();
|
||||||
|
@ -79,7 +80,9 @@ pub(crate) fn find_all_refs(
|
||||||
retain_adt_literal_usages(&mut usages, def, sema);
|
retain_adt_literal_usages(&mut usages, def, sema);
|
||||||
}
|
}
|
||||||
|
|
||||||
retain_import_usages(&mut usages);
|
if exclude_imports {
|
||||||
|
filter_import_references(&mut usages);
|
||||||
|
}
|
||||||
|
|
||||||
let references = usages
|
let references = usages
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -114,7 +117,7 @@ pub(crate) fn find_all_refs(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn retain_import_usages(usages: &mut UsageSearchResult) {
|
fn filter_import_references(usages: &mut UsageSearchResult) {
|
||||||
// todo use this https://github.com/rust-lang/rust-analyzer/blob/master/crates/rust-analyzer/src/config.rs#L432
|
// todo use this https://github.com/rust-lang/rust-analyzer/blob/master/crates/rust-analyzer/src/config.rs#L432
|
||||||
|
|
||||||
for (_file_id, refs) in &mut usages.references {
|
for (_file_id, refs) in &mut usages.references {
|
||||||
|
@ -1109,7 +1112,7 @@ impl Foo {
|
||||||
|
|
||||||
fn check_with_scope(ra_fixture: &str, search_scope: Option<SearchScope>, expect: Expect) {
|
fn check_with_scope(ra_fixture: &str, search_scope: Option<SearchScope>, expect: Expect) {
|
||||||
let (analysis, pos) = fixture::position(ra_fixture);
|
let (analysis, pos) = fixture::position(ra_fixture);
|
||||||
let refs = analysis.find_all_refs(pos, search_scope).unwrap().unwrap();
|
let refs = analysis.find_all_refs(pos, search_scope, false).unwrap().unwrap();
|
||||||
|
|
||||||
let mut actual = String::new();
|
let mut actual = String::new();
|
||||||
for refs in refs {
|
for refs in refs {
|
||||||
|
|
|
@ -220,6 +220,9 @@ config_data! {
|
||||||
/// Controls file watching implementation.
|
/// Controls file watching implementation.
|
||||||
files_watcher: FilesWatcherDef = "\"client\"",
|
files_watcher: FilesWatcherDef = "\"client\"",
|
||||||
|
|
||||||
|
/// Exclude imports in "Find All References"
|
||||||
|
findAllRefs_excludeImports: bool = "false",
|
||||||
|
|
||||||
/// Enables highlighting of related references while the cursor is on `break`, `loop`, `while`, or `for` keywords.
|
/// Enables highlighting of related references while the cursor is on `break`, `loop`, `while`, or `for` keywords.
|
||||||
highlightRelated_breakPoints_enable: bool = "true",
|
highlightRelated_breakPoints_enable: bool = "true",
|
||||||
/// Enables highlighting of all exit points while the cursor is on any `return`, `?`, `fn`, or return type arrow (`->`).
|
/// Enables highlighting of all exit points while the cursor is on any `return`, `?`, `fn`, or return type arrow (`->`).
|
||||||
|
@ -1147,6 +1150,10 @@ impl Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn find_all_refs_exclude_imports(&self) -> bool {
|
||||||
|
self.data.findAllRefs_excludeImports
|
||||||
|
}
|
||||||
|
|
||||||
pub fn snippet_cap(&self) -> bool {
|
pub fn snippet_cap(&self) -> bool {
|
||||||
self.experimental("snippetTextEdit")
|
self.experimental("snippetTextEdit")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1012,7 +1012,9 @@ pub(crate) fn handle_references(
|
||||||
let _p = profile::span("handle_references");
|
let _p = profile::span("handle_references");
|
||||||
let position = from_proto::file_position(&snap, params.text_document_position)?;
|
let position = from_proto::file_position(&snap, params.text_document_position)?;
|
||||||
|
|
||||||
let refs = match snap.analysis.find_all_refs(position, None)? {
|
let exclude_imports = snap.config.find_all_refs_exclude_imports();
|
||||||
|
|
||||||
|
let refs = match snap.analysis.find_all_refs(position, None, exclude_imports)? {
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
Some(refs) => refs,
|
Some(refs) => refs,
|
||||||
};
|
};
|
||||||
|
@ -1652,7 +1654,9 @@ fn show_ref_command_link(
|
||||||
position: &FilePosition,
|
position: &FilePosition,
|
||||||
) -> Option<lsp_ext::CommandLinkGroup> {
|
) -> Option<lsp_ext::CommandLinkGroup> {
|
||||||
if snap.config.hover_actions().references && snap.config.client_commands().show_reference {
|
if snap.config.hover_actions().references && snap.config.client_commands().show_reference {
|
||||||
if let Some(ref_search_res) = snap.analysis.find_all_refs(*position, None).unwrap_or(None) {
|
if let Some(ref_search_res) =
|
||||||
|
snap.analysis.find_all_refs(*position, None, false).unwrap_or(None)
|
||||||
|
{
|
||||||
let uri = to_proto::url(snap, position.file_id);
|
let uri = to_proto::url(snap, position.file_id);
|
||||||
let line_index = snap.file_line_index(position.file_id).ok()?;
|
let line_index = snap.file_line_index(position.file_id).ok()?;
|
||||||
let position = to_proto::position(&line_index, position.offset);
|
let position = to_proto::position(&line_index, position.offset);
|
||||||
|
|
|
@ -839,6 +839,11 @@
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"minimum": 0
|
"minimum": 0
|
||||||
},
|
},
|
||||||
|
"rust-analyzer.findAllRefs.excludeImports": {
|
||||||
|
"markdownDescription": "Exclude imports from Find All References results",
|
||||||
|
"default": false,
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"rust-analyzer.inlayHints.closureReturnTypeHints.enable": {
|
"rust-analyzer.inlayHints.closureReturnTypeHints.enable": {
|
||||||
"markdownDescription": "Whether to show inlay type hints for return types of closures.",
|
"markdownDescription": "Whether to show inlay type hints for return types of closures.",
|
||||||
"default": "never",
|
"default": "never",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue