Skip to content

Commit

Permalink
Added a setting to limit the "workspace symbols" request to only the …
Browse files Browse the repository at this point in the history
…workspace when needed #53 #54
  • Loading branch information
SpontanCombust committed Aug 16, 2024
1 parent 9fc6a27 commit 59700cc
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 32 deletions.
33 changes: 15 additions & 18 deletions crates/lsp/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use crate::Backend;
pub struct Config {
pub game_directory: PathBuf,
pub content_repositories: Vec<PathBuf>,
pub enable_syntax_analysis: bool
pub enable_syntax_analysis: bool,
pub extended_search_for_workspace_symbols: bool
}

#[derive(Debug, Error)]
Expand All @@ -25,10 +26,11 @@ pub enum ConfigError {
}

impl Config {
const CONFIG_ITEM_SECTIONS: [&'static str; 3] = [
const CONFIG_ITEM_SECTIONS: [&'static str; 4] = [
"witcherscript-ide.gameDirectory",
"witcherscript-ide.contentRepositories",
"witcherscript-ide.languageServer.syntaxAnalysis"
"witcherscript-ide.languageServer.syntaxAnalysis",
"witcherscript-ide.languageServer.extendedSearchForWorkspaceSymbols"
];

pub async fn fetch(client: &Client) -> Result<Self, ConfigError> {
Expand All @@ -42,7 +44,8 @@ impl Config {
Ok(Self {
game_directory: serde_json::from_value(values[0].clone())?,
content_repositories: serde_json::from_value(values[1].clone())?,
enable_syntax_analysis: serde_json::from_value(values[2].clone())?
enable_syntax_analysis: serde_json::from_value(values[2].clone())?,
extended_search_for_workspace_symbols: serde_json::from_value(values[3].clone())?
})
}
}
Expand Down Expand Up @@ -73,39 +76,33 @@ impl Backend {
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ConfigDifference {
pub game_directory_changed: bool,
pub content_repositories_changed: bool,
pub enable_syntax_analysis_changed: bool
pub enable_syntax_analysis_changed: bool,
pub extended_search_for_workspace_symbols_changed: bool
}

impl ConfigDifference {
fn from_comparison(old_config: &Config, new_config: &Config) -> Self {
let game_directory_changed = old_config.game_directory != new_config.game_directory;
let content_repositories_changed = old_config.content_repositories != new_config.content_repositories;
let enable_syntax_analysis_changed = old_config.enable_syntax_analysis != new_config.enable_syntax_analysis;
let extended_search_for_workspace_symbols_changed = old_config.extended_search_for_workspace_symbols != new_config.extended_search_for_workspace_symbols;

ConfigDifference {
game_directory_changed,
content_repositories_changed,
enable_syntax_analysis_changed
enable_syntax_analysis_changed,
extended_search_for_workspace_symbols_changed
}
}

pub fn any_changed(&self) -> bool {
self.game_directory_changed ||
self.content_repositories_changed ||
self.enable_syntax_analysis_changed
self.enable_syntax_analysis_changed ||
self.extended_search_for_workspace_symbols_changed
}
}

impl Default for ConfigDifference {
fn default() -> Self {
Self {
game_directory_changed: false,
content_repositories_changed: false,
enable_syntax_analysis_changed: false
}
}
}
4 changes: 4 additions & 0 deletions crates/lsp/src/providers/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ impl Backend {

self.reporter.commit_all_diagnostics().await;
}

if diff.extended_search_for_workspace_symbols_changed {
self.cache.workspace_symbols.write().await.should_refresh = true;
}
}
}
31 changes: 19 additions & 12 deletions crates/lsp/src/providers/workspace_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ impl Backend {
}

async fn refresh_workspace_symbols_cache(&self) {
let only_from_workspace = !self.config.read().await.extended_search_for_workspace_symbols;

let content_names: HashMap<AbsPath, String> =
self.content_graph
.read().await
.nodes()
.map(|n| (n.content.path().to_owned(), n.content.content_name().to_string()))
.collect();
self.content_graph
.read().await
.nodes()
.filter(|n| if only_from_workspace { n.in_workspace } else { true })
.map(|n| (n.content.path().to_owned(), n.content.content_name().to_string()))
.collect();

self.cache.workspace_symbols
.write().await
Expand All @@ -67,10 +70,14 @@ impl Backend {
let symtabs = self.symtabs.read().await;

for (content_path, st) in symtabs.iter() {
let content_name = content_names
.get(content_path)
.map(|n| n.to_string())
.unwrap_or_default();
// if the name is not in the map this means that content was filtered out
// based on the extended_search_for_workspace_symbols setting
let content_name;
if let Some(name) = content_names.get(content_path) {
content_name = name.to_string();
} else {
continue;
}

let content_symdata_iter = st.iter()
.par_bridge()
Expand All @@ -83,9 +90,9 @@ impl Backend {
}

self.cache.workspace_symbols
.write().await
.unqueried_data
.par_sort_unstable_by(|a, b| b.cmp(a));
.write().await
.unqueried_data
.par_sort_unstable_by(|a, b| b.cmp(a));

self.cache.workspace_symbols
.write().await
Expand Down
10 changes: 8 additions & 2 deletions editors/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,22 @@
"order": 5,
"markdownDescription": "Enables syntax analysis in the language server."
},
"witcherscript-ide.languageServer.extendedSearchForWorkspaceSymbols": {
"type": "boolean",
"default": true,
"order": 6,
"markdownDescription": "Search for code symbols in both workspace projects and their dependencies outside the workspace when using the \"Go to Symbol in Workspace\" feature"
},
"witcherscript-ide.languageServer.rayonThreads": {
"type": "integer",
"default": 0,
"order": 6,
"order": 7,
"markdownDescription": "Number of threads allocated to parallel data computation. Leave at 0 for automatic configuration. (change requires extension reload)"
},
"witcherscript-ide.debug.enableDebugFeatures": {
"type": "boolean",
"default": false,
"order": 7,
"order": 8,
"markdownDescription": "Enable debug features (change requires extension reload)."
}
}
Expand Down

0 comments on commit 59700cc

Please sign in to comment.