Skip to content

Commit

Permalink
Upgrade LSP types to 0.70.0, final fixes to incremental highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
jackguo380 committed Jan 21, 2020
1 parent 064d17d commit 9dc369d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 41 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ serde_derive = "1"
serde_json = "1"
crossbeam = "0.7.3"
jsonrpc-core = "12"
lsp-types = { version = "0.68.1", features = ["proposed"] }
lsp-types = { version = "0.70.0", features = ["proposed"] }
url = "2"
pathdiff = "0"
diff = "0"
Expand Down
84 changes: 47 additions & 37 deletions src/language_server_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2304,52 +2304,62 @@ impl LanguageClient {
return Ok(());
}

let mut highlights = Vec::new();
/*
* Currently servers update entire regions of text at a time or a
* single line so simply clear between the first and last line to
* ensure no highlights are left dangling
*/
let mut clear_region: Option<(u64, u64)> = None;
let mut highlights = Vec::with_capacity(semantic_hl_state.symbols.len());

for line in &semantic_hl_state.symbols {
for token in &line.tokens {
if token.length == 0 {
continue;
if let Some(tokens) = &line.tokens {
for token in tokens {
if token.length == 0 {
continue;
}

if let Some(Some(group)) = hl_table.get(token.scope as usize) {
highlights.push(Highlight {
line: line.line as u64,
character_start: token.character as u64,
character_end: token.character as u64 + token.length as u64,
group: group.clone(),
text: String::new(),
});
}
}

if let Some(Some(group)) = hl_table.get(token.scope as usize) {
highlights.push(Highlight {
line: line.line as u64,
character_start: token.character as u64,
character_end: token.character as u64 + token.length as u64,
group: group.clone(),
text: String::new(),
});
match clear_region {
Some((begin, _)) => {
clear_region = Some((begin, line.line as u64 + 1));
}
None => {
clear_region = Some((line.line as u64, line.line as u64 + 1));
}
}
}
}

let mut clears = Vec::new();
let clear_begin;
let clear_end; // exclusive
info!("Semantic Highlighting Region [{}, {}]:",
semantic_hl_state.symbols.first().map_or(-1, |h| h.line as i64),
semantic_hl_state.symbols.last().map_or(-1, |h| h.line as i64)
);

/*
* Currently servers update entire regions of text at a time or a
* single line so simply clear between the first and last line to
* ensure no highlights are left dangling
*/
match (
semantic_hl_state.symbols.first(),
semantic_hl_state.symbols.last(),
) {
(Some(start), Some(end)) => {
info!("Semantic Highlighting Region (Parsed) [{}, {}]:",
highlights.first().map_or(-1, |h| h.line as i64),
highlights.last().map_or(-1, |h| h.line as i64)
);

let mut clears = Vec::new();
match clear_region {
Some((begin, end)) => {
clears.push(ClearNamespace {
line_start: start.line as u64,
line_end: end.line as u64 + 1,
line_start: begin,
line_end: end,
});

clear_begin = start.line as u64;
clear_end = end.line as u64 + 1;
}
(_, _) => {
clear_begin = 0 as u64;
clear_end = 0 as u64;
}
None => {}
}

let mut num_semantic_hls = 0;
Expand Down Expand Up @@ -2386,8 +2396,8 @@ impl LanguageClient {

match existing_hl.line.cmp(&new_hl.line) {
Ordering::Less => {
if clear_begin <= existing_hl.line
&& existing_hl.line < clear_end
if clear_region.unwrap_or((0, 0)).0 <= existing_hl.line
&& existing_hl.line < clear_region.unwrap_or((0, 0)).1
{
// within clear region, this highlight gets cleared
existing_hls.next();
Expand Down Expand Up @@ -3241,7 +3251,7 @@ impl LanguageClient {
let mut symbols = Vec::new();

for sym in hl_state.symbols {
for token in sym.tokens {
for token in sym.tokens.unwrap_or_default() {
symbols.push(json!({
"line": sym.line as u64,
"character_start": token.character as u64,
Expand Down

0 comments on commit 9dc369d

Please sign in to comment.