Use StringMatchCandidate::new to construct candidates more conveniently
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
1e96fc98e7
commit
bd2527e691
4 changed files with 25 additions and 19 deletions
|
@ -98,6 +98,16 @@ impl<'a> MatchCandidate for PathMatchCandidate<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl StringMatchCandidate {
|
||||||
|
pub fn new(id: usize, string: String) -> Self {
|
||||||
|
Self {
|
||||||
|
id,
|
||||||
|
char_bag: CharBag::from(string.as_str()),
|
||||||
|
string,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> MatchCandidate for &'a StringMatchCandidate {
|
impl<'a> MatchCandidate for &'a StringMatchCandidate {
|
||||||
fn has_chars(&self, bag: CharBag) -> bool {
|
fn has_chars(&self, bag: CharBag) -> bool {
|
||||||
self.char_bag.is_superset(bag)
|
self.char_bag.is_superset(bag)
|
||||||
|
|
|
@ -7,7 +7,7 @@ pub use crate::{
|
||||||
use crate::{
|
use crate::{
|
||||||
diagnostic_set::{DiagnosticEntry, DiagnosticGroup},
|
diagnostic_set::{DiagnosticEntry, DiagnosticGroup},
|
||||||
outline::OutlineItem,
|
outline::OutlineItem,
|
||||||
range_from_lsp, Outline,
|
range_from_lsp, Outline, ToLspPosition,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use clock::ReplicaId;
|
use clock::ReplicaId;
|
||||||
|
@ -589,14 +589,8 @@ impl Buffer {
|
||||||
.collect();
|
.collect();
|
||||||
lsp::TextDocumentContentChangeEvent {
|
lsp::TextDocumentContentChangeEvent {
|
||||||
range: Some(lsp::Range::new(
|
range: Some(lsp::Range::new(
|
||||||
lsp::Position::new(
|
edit_start.to_lsp_position(),
|
||||||
edit_start.row,
|
edit_end.to_lsp_position(),
|
||||||
edit_start.column,
|
|
||||||
),
|
|
||||||
lsp::Position::new(
|
|
||||||
edit_end.row,
|
|
||||||
edit_end.column,
|
|
||||||
),
|
|
||||||
)),
|
)),
|
||||||
range_length: None,
|
range_length: None,
|
||||||
text: new_text,
|
text: new_text,
|
||||||
|
|
|
@ -39,6 +39,10 @@ pub trait ToPointUtf16 {
|
||||||
fn to_point_utf16(self) -> PointUtf16;
|
fn to_point_utf16(self) -> PointUtf16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait ToLspPosition {
|
||||||
|
fn to_lsp_position(self) -> lsp::Position;
|
||||||
|
}
|
||||||
|
|
||||||
pub trait DiagnosticProcessor: 'static + Send + Sync {
|
pub trait DiagnosticProcessor: 'static + Send + Sync {
|
||||||
fn process_diagnostics(&self, diagnostics: &mut lsp::PublishDiagnosticsParams);
|
fn process_diagnostics(&self, diagnostics: &mut lsp::PublishDiagnosticsParams);
|
||||||
}
|
}
|
||||||
|
@ -286,6 +290,12 @@ impl ToPointUtf16 for lsp::Position {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToLspPosition for PointUtf16 {
|
||||||
|
fn to_lsp_position(self) -> lsp::Position {
|
||||||
|
lsp::Position::new(self.row, self.column)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn range_from_lsp(range: lsp::Range) -> Range<PointUtf16> {
|
pub fn range_from_lsp(range: lsp::Range) -> Range<PointUtf16> {
|
||||||
let start = PointUtf16::new(range.start.line, range.start.character);
|
let start = PointUtf16::new(range.start.line, range.start.character);
|
||||||
let end = PointUtf16::new(range.end.line, range.end.character);
|
let end = PointUtf16::new(range.end.line, range.end.character);
|
||||||
|
|
|
@ -45,16 +45,8 @@ impl<T> Outline<T> {
|
||||||
.map(|range| &item.text[range.start as usize..range.end as usize])
|
.map(|range| &item.text[range.start as usize..range.end as usize])
|
||||||
.collect::<String>();
|
.collect::<String>();
|
||||||
|
|
||||||
path_candidates.push(StringMatchCandidate {
|
path_candidates.push(StringMatchCandidate::new(id, path_text.clone()));
|
||||||
id,
|
candidates.push(StringMatchCandidate::new(id, candidate_text));
|
||||||
char_bag: path_text.as_str().into(),
|
|
||||||
string: path_text.clone(),
|
|
||||||
});
|
|
||||||
candidates.push(StringMatchCandidate {
|
|
||||||
id,
|
|
||||||
char_bag: candidate_text.as_str().into(),
|
|
||||||
string: candidate_text,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue