From 0028c457140086d339a3dbf71f831ea500958476 Mon Sep 17 00:00:00 2001 From: Felix Zeller Date: Wed, 27 Mar 2024 20:46:23 -0400 Subject: [PATCH] settings for semantic tokens --- src/config.rs | 4 +++- src/main.rs | 5 ++++- src/tokens.rs | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index 0923e825..d2a50905 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,7 +11,8 @@ pub struct Settings { pub dailynote: String, pub heading_completions: bool, pub title_headings: bool, - pub unresolved_diagnostics: bool + pub unresolved_diagnostics: bool, + pub semantic_tokens: bool } impl Settings { @@ -41,6 +42,7 @@ impl Settings { )? .set_default("unresolved_diagnostics", true)? .set_default("title_headings", true)? + .set_default("semantic_tokens", true)? .build() .map_err(|err| anyhow!("Build err: {err}"))?; diff --git a/src/main.rs b/src/main.rs index c65149f9..af04e0f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -599,9 +599,12 @@ impl LanguageServer for Backend { &self, params: SemanticTokensParams, ) -> Result> { + + let settings = self.bind_settings(|settings| Ok(settings.clone())).await?; + let path = params_path!(params)?; let res = self - .bind_vault(|vault| Ok(tokens::semantic_tokens_full(vault, &path, params))) + .bind_vault(|vault| Ok(tokens::semantic_tokens_full(vault, &path, params, &settings))) .await; return res; diff --git a/src/tokens.rs b/src/tokens.rs index b997c11b..d9371227 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -3,13 +3,18 @@ use std::{iter, path::Path}; use itertools::Itertools; use tower_lsp::lsp_types::{SemanticToken, SemanticTokensParams, SemanticTokensResult}; -use crate::vault::{Referenceable, Vault}; +use crate::{config::Settings, vault::{Referenceable, Vault}}; pub fn semantic_tokens_full( vault: &Vault, path: &Path, _params: SemanticTokensParams, + settings: &Settings, ) -> Option { + if !settings.semantic_tokens { + return None; + } + let references_in_file = vault.select_references(Some(path))?; let tokens = references_in_file