mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Allow clients to configure the global workspace search limit
This commit is contained in:
parent
cfa26c3ac3
commit
553bb7f50a
4 changed files with 29 additions and 8 deletions
|
@ -288,6 +288,10 @@ config_data! {
|
||||||
workspace_symbol_search_scope: WorkspaceSymbolSearchScopeDef = "\"workspace\"",
|
workspace_symbol_search_scope: WorkspaceSymbolSearchScopeDef = "\"workspace\"",
|
||||||
/// Workspace symbol search kind.
|
/// Workspace symbol search kind.
|
||||||
workspace_symbol_search_kind: WorkspaceSymbolSearchKindDef = "\"only_types\"",
|
workspace_symbol_search_kind: WorkspaceSymbolSearchKindDef = "\"only_types\"",
|
||||||
|
/// Limits the number of items returned from a workspace symbol search (Defaults to 128).
|
||||||
|
/// Some clients like vs-code issue new searches on result filtering and don't require all results to be returned in the initial search.
|
||||||
|
/// Other clients requires all results upfront and might require a higher limit.
|
||||||
|
workspace_symbol_search_limit: usize = "128",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,8 +425,10 @@ pub struct RunnablesConfig {
|
||||||
pub struct WorkspaceSymbolConfig {
|
pub struct WorkspaceSymbolConfig {
|
||||||
/// In what scope should the symbol be searched in.
|
/// In what scope should the symbol be searched in.
|
||||||
pub search_scope: WorkspaceSymbolSearchScope,
|
pub search_scope: WorkspaceSymbolSearchScope,
|
||||||
/// What kind of symbol is being search for.
|
/// What kind of symbol is being searched for.
|
||||||
pub search_kind: WorkspaceSymbolSearchKind,
|
pub search_kind: WorkspaceSymbolSearchKind,
|
||||||
|
/// How many items are returned at most.
|
||||||
|
pub search_limit: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ClientCommandsConfig {
|
pub struct ClientCommandsConfig {
|
||||||
|
@ -893,6 +899,7 @@ impl Config {
|
||||||
WorkspaceSymbolSearchKindDef::OnlyTypes => WorkspaceSymbolSearchKind::OnlyTypes,
|
WorkspaceSymbolSearchKindDef::OnlyTypes => WorkspaceSymbolSearchKind::OnlyTypes,
|
||||||
WorkspaceSymbolSearchKindDef::AllSymbols => WorkspaceSymbolSearchKind::AllSymbols,
|
WorkspaceSymbolSearchKindDef::AllSymbols => WorkspaceSymbolSearchKind::AllSymbols,
|
||||||
},
|
},
|
||||||
|
search_limit: self.data.workspace_symbol_search_limit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1159,6 +1166,7 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
|
||||||
|
|
||||||
match ty {
|
match ty {
|
||||||
"bool" => set!("type": "boolean"),
|
"bool" => set!("type": "boolean"),
|
||||||
|
"usize" => set!("type": "integer", "minimum": 0),
|
||||||
"String" => set!("type": "string"),
|
"String" => set!("type": "string"),
|
||||||
"Vec<String>" => set! {
|
"Vec<String>" => set! {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
|
|
|
@ -34,7 +34,7 @@ use vfs::AbsPathBuf;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cargo_target_spec::CargoTargetSpec,
|
cargo_target_spec::CargoTargetSpec,
|
||||||
config::RustfmtConfig,
|
config::{RustfmtConfig, WorkspaceSymbolConfig},
|
||||||
diff::diff,
|
diff::diff,
|
||||||
from_proto,
|
from_proto,
|
||||||
global_state::{GlobalState, GlobalStateSnapshot},
|
global_state::{GlobalState, GlobalStateSnapshot},
|
||||||
|
@ -392,7 +392,9 @@ pub(crate) fn handle_workspace_symbol(
|
||||||
) -> Result<Option<Vec<SymbolInformation>>> {
|
) -> Result<Option<Vec<SymbolInformation>>> {
|
||||||
let _p = profile::span("handle_workspace_symbol");
|
let _p = profile::span("handle_workspace_symbol");
|
||||||
|
|
||||||
let (all_symbols, libs) = decide_search_scope_and_kind(¶ms, &snap);
|
let config = snap.config.workspace_symbol();
|
||||||
|
let (all_symbols, libs) = decide_search_scope_and_kind(¶ms, &config);
|
||||||
|
let limit = config.search_limit;
|
||||||
|
|
||||||
let query = {
|
let query = {
|
||||||
let query: String = params.query.chars().filter(|&c| c != '#' && c != '*').collect();
|
let query: String = params.query.chars().filter(|&c| c != '#' && c != '*').collect();
|
||||||
|
@ -403,13 +405,13 @@ pub(crate) fn handle_workspace_symbol(
|
||||||
if libs {
|
if libs {
|
||||||
q.libs();
|
q.libs();
|
||||||
}
|
}
|
||||||
q.limit(128);
|
q.limit(limit);
|
||||||
q
|
q
|
||||||
};
|
};
|
||||||
let mut res = exec_query(&snap, query)?;
|
let mut res = exec_query(&snap, query)?;
|
||||||
if res.is_empty() && !all_symbols {
|
if res.is_empty() && !all_symbols {
|
||||||
let mut query = Query::new(params.query);
|
let mut query = Query::new(params.query);
|
||||||
query.limit(128);
|
query.limit(limit);
|
||||||
res = exec_query(&snap, query)?;
|
res = exec_query(&snap, query)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,14 +419,12 @@ pub(crate) fn handle_workspace_symbol(
|
||||||
|
|
||||||
fn decide_search_scope_and_kind(
|
fn decide_search_scope_and_kind(
|
||||||
params: &WorkspaceSymbolParams,
|
params: &WorkspaceSymbolParams,
|
||||||
snap: &GlobalStateSnapshot,
|
config: &WorkspaceSymbolConfig,
|
||||||
) -> (bool, bool) {
|
) -> (bool, bool) {
|
||||||
// Support old-style parsing of markers in the query.
|
// Support old-style parsing of markers in the query.
|
||||||
let mut all_symbols = params.query.contains('#');
|
let mut all_symbols = params.query.contains('#');
|
||||||
let mut libs = params.query.contains('*');
|
let mut libs = params.query.contains('*');
|
||||||
|
|
||||||
let config = snap.config.workspace_symbol();
|
|
||||||
|
|
||||||
// If no explicit marker was set, check request params. If that's also empty
|
// If no explicit marker was set, check request params. If that's also empty
|
||||||
// use global config.
|
// use global config.
|
||||||
if !all_symbols {
|
if !all_symbols {
|
||||||
|
|
|
@ -461,3 +461,10 @@ Workspace symbol search scope.
|
||||||
--
|
--
|
||||||
Workspace symbol search kind.
|
Workspace symbol search kind.
|
||||||
--
|
--
|
||||||
|
[[rust-analyzer.workspace.symbol.search.limit]]rust-analyzer.workspace.symbol.search.limit (default: `128`)::
|
||||||
|
+
|
||||||
|
--
|
||||||
|
Limits the number of items returned from a workspace symbol search (Defaults to 128).
|
||||||
|
Some clients like vs-code issue new searches on result filtering and don't require all results to be returned in the initial search.
|
||||||
|
Other clients requires all results upfront and might require a higher limit.
|
||||||
|
--
|
||||||
|
|
|
@ -929,6 +929,12 @@
|
||||||
"Search for all symbols kinds"
|
"Search for all symbols kinds"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"rust-analyzer.workspace.symbol.search.limit": {
|
||||||
|
"markdownDescription": "Limits the number of items returned from a workspace symbol search (Defaults to 128).\nSome clients like vs-code issue new searches on result filtering and don't require all results to be returned in the initial search.\nOther clients requires all results upfront and might require a higher limit.",
|
||||||
|
"default": 128,
|
||||||
|
"type": "integer",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
"$generated-end": {}
|
"$generated-end": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue