Unnamed repository; edit this file 'description' to name the repository.
Merge #10802
10802: Allow clients to configure the global workspace search limit r=Veykril a=knutwalker Playing around with [helix](https://helix-editor.com) I realized that the global worksapce symbol search works different compared to vs-code. Helix requires all possible symbols in one query and does no subsequent refinement searched. This PR adds a configuration option to override the default search limit with the default being the currently hardocded value. Helix users can increment this limit for their instance with a config like ```toml [[language]] name = "rust" language-server = { command = "rust-analyzer" } [language.config] workspace = { symbol = { search = { limit = 65536 }}} ``` Other editors are not affected by this change. Co-authored-by: Paul Horn <[email protected]>
bors[bot] 2022-04-03
parent 5b5ca0b · parent 553bb7f · commit bc0825d
-rw-r--r--crates/rust-analyzer/src/config.rs10
-rw-r--r--crates/rust-analyzer/src/handlers.rs14
-rw-r--r--docs/user/generated_config.adoc7
-rw-r--r--editors/code/package.json6
4 files changed, 29 insertions, 8 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 8fbf10072c..958ff1fcee 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -354,6 +354,10 @@ config_data! {
workspace_symbol_search_scope: WorkspaceSymbolSearchScopeDef = "\"workspace\"",
/// Workspace symbol search kind.
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",
}
}
@@ -487,8 +491,10 @@ pub struct RunnablesConfig {
pub struct WorkspaceSymbolConfig {
/// In what scope should the symbol be searched in.
pub search_scope: WorkspaceSymbolSearchScope,
- /// What kind of symbol is being search for.
+ /// What kind of symbol is being searched for.
pub search_kind: WorkspaceSymbolSearchKind,
+ /// How many items are returned at most.
+ pub search_limit: usize,
}
pub struct ClientCommandsConfig {
@@ -995,6 +1001,7 @@ impl Config {
WorkspaceSymbolSearchKindDef::OnlyTypes => WorkspaceSymbolSearchKind::OnlyTypes,
WorkspaceSymbolSearchKindDef::AllSymbols => WorkspaceSymbolSearchKind::AllSymbols,
},
+ search_limit: self.data.workspace_symbol_search_limit,
}
}
@@ -1298,6 +1305,7 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
match ty {
"bool" => set!("type": "boolean"),
+ "usize" => set!("type": "integer", "minimum": 0),
"String" => set!("type": "string"),
"Vec<String>" => set! {
"type": "array",
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 15f4978367..78118764fa 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -33,7 +33,7 @@ use vfs::AbsPathBuf;
use crate::{
cargo_target_spec::CargoTargetSpec,
- config::RustfmtConfig,
+ config::{RustfmtConfig, WorkspaceSymbolConfig},
diff::diff,
from_proto,
global_state::{GlobalState, GlobalStateSnapshot},
@@ -403,7 +403,9 @@ pub(crate) fn handle_workspace_symbol(
) -> Result<Option<Vec<SymbolInformation>>> {
let _p = profile::span("handle_workspace_symbol");
- let (all_symbols, libs) = decide_search_scope_and_kind(&params, &snap);
+ let config = snap.config.workspace_symbol();
+ let (all_symbols, libs) = decide_search_scope_and_kind(&params, &config);
+ let limit = config.search_limit;
let query = {
let query: String = params.query.chars().filter(|&c| c != '#' && c != '*').collect();
@@ -414,13 +416,13 @@ pub(crate) fn handle_workspace_symbol(
if libs {
q.libs();
}
- q.limit(128);
+ q.limit(limit);
q
};
let mut res = exec_query(&snap, query)?;
if res.is_empty() && !all_symbols {
let mut query = Query::new(params.query);
- query.limit(128);
+ query.limit(limit);
res = exec_query(&snap, query)?;
}
@@ -428,14 +430,12 @@ pub(crate) fn handle_workspace_symbol(
fn decide_search_scope_and_kind(
params: &WorkspaceSymbolParams,
- snap: &GlobalStateSnapshot,
+ config: &WorkspaceSymbolConfig,
) -> (bool, bool) {
// Support old-style parsing of markers in the query.
let mut all_symbols = 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
// use global config.
if !all_symbols {
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index 1617ac5a7f..d552982768 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -558,3 +558,10 @@ Workspace symbol search scope.
--
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.
+--
diff --git a/editors/code/package.json b/editors/code/package.json
index a62b80b461..b7bc60a3b8 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -1014,6 +1014,12 @@
"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": {}
}
},