Skip to content

Commit

Permalink
semantic tokens for unresolved links
Browse files Browse the repository at this point in the history
  • Loading branch information
Feel-ix-343 committed Mar 25, 2024
1 parent 8220445 commit 0b8d466
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ impl LanguageServer for Backend {
full: Some(SemanticTokensFullOptions::Bool(true)),
range: Some(false),
legend: SemanticTokensLegend {
token_types: vec![SemanticTokenType::DECORATOR],
token_modifiers: vec![SemanticTokenModifier::DECLARATION],
token_types: vec![SemanticTokenType::DECORATOR, SemanticTokenType::COMMENT],
token_modifiers: vec![SemanticTokenModifier::DECLARATION, SemanticTokenModifier::DEPRECATED],
},
..Default::default()
},
Expand Down
16 changes: 10 additions & 6 deletions src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{iter, path::Path};
use itertools::Itertools;
use tower_lsp::lsp_types::{SemanticToken, SemanticTokensParams, SemanticTokensResult};

use crate::vault::Vault;
use crate::vault::{Referenceable, Vault};

pub fn semantic_tokens_full(
vault: &Vault,
Expand All @@ -20,18 +20,22 @@ pub fn semantic_tokens_full(
reference.data().range.start.character,
)
})
.fold(vec![], |acc, (_, reference)| {
.fold(vec![], |acc, (path, reference)| {
let range = reference.data().range;

let is_unresolved = vault.select_referenceables_for_reference(reference, path)
.into_iter()
.any(|referenceable| referenceable.is_unresolved());

match acc[..] {
[] => vec![(
reference,
SemanticToken {
delta_line: range.start.line,
delta_start: range.start.character,
length: range.end.character - range.start.character,
token_type: 0,
token_modifiers_bitset: 0,
token_type: if is_unresolved { 1 } else { 0 },
token_modifiers_bitset: 0
},
)],
[.., (prev_ref, _)] => acc
Expand All @@ -46,8 +50,8 @@ pub fn semantic_tokens_full(
range.start.character
},
length: range.end.character - range.start.character,
token_type: 0,
token_modifiers_bitset: 0,
token_type: if is_unresolved { 1 } else { 0 },
token_modifiers_bitset: 0
},
)))
.collect_vec(),
Expand Down

0 comments on commit 0b8d466

Please sign in to comment.