Start work on syntax highlighting completions

This commit is contained in:
Max Brunsfeld 2022-02-02 18:14:30 -08:00
parent 45898daf83
commit 439d12cb85
7 changed files with 349 additions and 221 deletions

View file

@ -7,7 +7,7 @@ pub use crate::{
use crate::{
diagnostic_set::{DiagnosticEntry, DiagnosticGroup},
outline::OutlineItem,
range_from_lsp, Outline, ToLspPosition,
range_from_lsp, CompletionLabel, Outline, ToLspPosition,
};
use anyhow::{anyhow, Result};
use clock::ReplicaId;
@ -114,7 +114,7 @@ pub struct Diagnostic {
pub struct Completion<T> {
pub old_range: Range<T>,
pub new_text: String,
pub label: Option<String>,
pub label: CompletionLabel,
pub lsp_completion: lsp::CompletionItem,
}
@ -1829,7 +1829,7 @@ impl Buffer {
Some(Completion {
old_range: this.anchor_before(old_range.start)..this.anchor_after(old_range.end),
new_text,
label: language.as_ref().and_then(|l| l.label_for_completion(&lsp_completion)),
label: language.as_ref().and_then(|l| l.label_for_completion(&lsp_completion)).unwrap_or_else(|| CompletionLabel::plain(&lsp_completion)),
lsp_completion,
})
} else {
@ -2664,28 +2664,12 @@ impl Default for Diagnostic {
}
impl<T> Completion<T> {
pub fn label(&self) -> &str {
self.label.as_deref().unwrap_or(&self.lsp_completion.label)
}
pub fn filter_range(&self) -> Range<usize> {
if let Some(filter_text) = self.lsp_completion.filter_text.as_deref() {
if let Some(start) = self.label().find(filter_text) {
start..start + filter_text.len()
} else {
0..self.label().len()
}
} else {
0..self.label().len()
}
}
pub fn sort_key(&self) -> (usize, &str) {
let kind_key = match self.lsp_completion.kind {
Some(lsp::CompletionItemKind::VARIABLE) => 0,
_ => 1,
};
(kind_key, &self.label()[self.filter_range()])
(kind_key, &self.label.text[self.label.filter_range.clone()])
}
pub fn is_snippet(&self) -> bool {