Skip to content

Commit

Permalink
Preparation for removing token requirement on semantic tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Feb 24, 2024
1 parent d983515 commit fd0f99f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
26 changes: 19 additions & 7 deletions src/dev_aid/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,22 @@ fn to_position_range(range : std::ops::Range<CharLine>) -> lsp_types::Range {
lsp_types::Range{start : to_position(range.start), end : to_position(range.end)}
}

fn do_syntax_highlight(file_data : &FileData, linker : &Linker) -> Vec<SemanticToken> {
let ide_tokens = create_token_ide_info(&file_data, linker);

fn convert_to_semantic_tokens(file_data : &FileData, ide_tokens : &mut[(IDEToken, Span)]) -> Vec<SemanticToken> {
ide_tokens.sort_by(|a, b| a.1.cmp(&b.1));
let mut cursor = Position {line : 0, character : 0};
let mut semantic_tokens = Vec::with_capacity(file_data.tokens.len());

for (tok_idx, ide_tok) in ide_tokens.iter().enumerate() {
let typ = get_semantic_token_type_from_ide_token(ide_tok);
let mod_bits = get_modifiers_for_token(ide_tok);
for (ide_kind, span) in ide_tokens.iter() {
let typ = get_semantic_token_type_from_ide_token(ide_kind);
let mod_bits = get_modifiers_for_token(ide_kind);

let tok_range = file_data.file_text.get_token_linechar_range(tok_idx);
let tok_range = file_data.file_text.get_span_linechar_range(*span);
let start_pos = to_position(tok_range.start);
let end_pos = to_position(tok_range.end);

assert!(end_pos.line == start_pos.line);

let delta_line = start_pos.line - cursor.line;

if delta_line != 0 {
Expand All @@ -203,6 +205,16 @@ fn do_syntax_highlight(file_data : &FileData, linker : &Linker) -> Vec<SemanticT
semantic_tokens
}

fn do_syntax_highlight(file_data : &FileData, linker : &Linker) -> Vec<SemanticToken> {
let ide_tokens = create_token_ide_info(&file_data, linker);

let mut ide_tokens : Vec<(IDEToken, Span)> = ide_tokens.iter().enumerate().map(|(idx, tok_typ)| (*tok_typ, Span::new_single_token(idx))).collect();



convert_to_semantic_tokens(file_data, &mut ide_tokens)
}

use lsp_types::Diagnostic;

fn cvt_span_to_lsp_range(ch_sp : Span, file_text : &FileText) -> lsp_types::Range {
Expand Down
11 changes: 10 additions & 1 deletion src/file_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,16 @@ impl BracketSpan {
}
}


impl PartialOrd for Span {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.0.partial_cmp(&other.0)
}
}
impl Ord for Span {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.0.cmp(&other.0)
}
}

#[derive(Clone, Copy, PartialEq, Eq)]
pub struct CharLine {
Expand Down

0 comments on commit fd0f99f

Please sign in to comment.