Skip to content

Commit

Permalink
settings for semantic tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Feel-ix-343 committed Mar 28, 2024
1 parent 11db5fb commit 0028c45
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}"))?;

Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,12 @@ impl LanguageServer for Backend {
&self,
params: SemanticTokensParams,
) -> Result<Option<SemanticTokensResult>> {

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;
Expand Down
7 changes: 6 additions & 1 deletion src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SemanticTokensResult> {
if !settings.semantic_tokens {
return None;
}

let references_in_file = vault.select_references(Some(path))?;

let tokens = references_in_file
Expand Down

0 comments on commit 0028c45

Please sign in to comment.