mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
internal: Add config to specifiy lru capacities for all queries
This commit is contained in:
parent
27c076a367
commit
5616d91b73
8 changed files with 202 additions and 9 deletions
|
@ -7,7 +7,7 @@
|
|||
//! configure the server itself, feature flags are passed into analysis, and
|
||||
//! tweak things like automatic insertion of `()` in completions.
|
||||
|
||||
use std::{fmt, iter, path::PathBuf};
|
||||
use std::{fmt, iter, ops::Not, path::PathBuf};
|
||||
|
||||
use flycheck::FlycheckConfig;
|
||||
use ide::{
|
||||
|
@ -418,6 +418,8 @@ config_data! {
|
|||
|
||||
/// Number of syntax trees rust-analyzer keeps in memory. Defaults to 128.
|
||||
lru_capacity: Option<usize> = "null",
|
||||
/// Sets the LRU capacity of the specified queries.
|
||||
lru_query_capacities: FxHashMap<Box<str>, usize> = "{}",
|
||||
|
||||
/// Whether to show `can't find Cargo.toml` error message.
|
||||
notifications_cargoTomlNotFound: bool = "true",
|
||||
|
@ -1085,10 +1087,14 @@ impl Config {
|
|||
extra_env
|
||||
}
|
||||
|
||||
pub fn lru_capacity(&self) -> Option<usize> {
|
||||
pub fn lru_parse_query_capacity(&self) -> Option<usize> {
|
||||
self.data.lru_capacity
|
||||
}
|
||||
|
||||
pub fn lru_query_capacities(&self) -> Option<&FxHashMap<Box<str>, usize>> {
|
||||
self.data.lru_query_capacities.is_empty().not().then(|| &self.data.lru_query_capacities)
|
||||
}
|
||||
|
||||
pub fn proc_macro_srv(&self) -> Option<(AbsPathBuf, /* is path explicitly set */ bool)> {
|
||||
if !self.data.procMacro_enable {
|
||||
return None;
|
||||
|
@ -2020,6 +2026,9 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
|
|||
"FxHashMap<String, String>" => set! {
|
||||
"type": "object",
|
||||
},
|
||||
"FxHashMap<Box<str>, usize>" => set! {
|
||||
"type": "object",
|
||||
},
|
||||
"Option<usize>" => set! {
|
||||
"type": ["null", "integer"],
|
||||
"minimum": 0,
|
||||
|
|
|
@ -139,7 +139,10 @@ impl GlobalState {
|
|||
Handle { handle, receiver }
|
||||
};
|
||||
|
||||
let analysis_host = AnalysisHost::new(config.lru_capacity());
|
||||
let mut analysis_host = AnalysisHost::new(config.lru_parse_query_capacity());
|
||||
if let Some(capacities) = config.lru_query_capacities() {
|
||||
analysis_host.update_lru_capacities(capacities);
|
||||
}
|
||||
let (flycheck_sender, flycheck_receiver) = unbounded();
|
||||
let mut this = GlobalState {
|
||||
sender,
|
||||
|
|
|
@ -73,8 +73,13 @@ impl GlobalState {
|
|||
pub(crate) fn update_configuration(&mut self, config: Config) {
|
||||
let _p = profile::span("GlobalState::update_configuration");
|
||||
let old_config = mem::replace(&mut self.config, Arc::new(config));
|
||||
if self.config.lru_capacity() != old_config.lru_capacity() {
|
||||
self.analysis_host.update_lru_capacity(self.config.lru_capacity());
|
||||
if self.config.lru_parse_query_capacity() != old_config.lru_parse_query_capacity() {
|
||||
self.analysis_host.update_lru_capacity(self.config.lru_parse_query_capacity());
|
||||
}
|
||||
if self.config.lru_query_capacities() != old_config.lru_query_capacities() {
|
||||
self.analysis_host.update_lru_capacities(
|
||||
&self.config.lru_query_capacities().cloned().unwrap_or_default(),
|
||||
);
|
||||
}
|
||||
if self.config.linked_projects() != old_config.linked_projects() {
|
||||
self.fetch_workspaces_queue.request_op("linked projects changed".to_string())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue