Rename CompletionLabel
to CodeLabel
and add Project::symbols
This only works locally for now and we haven't implemented the `RustLsp::label_for_symbol` method yet.
This commit is contained in:
parent
8f375a5026
commit
8a8ae0fbcd
7 changed files with 107 additions and 51 deletions
|
@ -7,7 +7,7 @@ pub use crate::{
|
|||
use crate::{
|
||||
diagnostic_set::{DiagnosticEntry, DiagnosticGroup},
|
||||
outline::OutlineItem,
|
||||
range_from_lsp, CompletionLabel, Outline, ToLspPosition,
|
||||
range_from_lsp, CodeLabel, Outline, ToLspPosition,
|
||||
};
|
||||
use anyhow::{anyhow, Result};
|
||||
use clock::ReplicaId;
|
||||
|
@ -117,7 +117,7 @@ pub struct Diagnostic {
|
|||
pub struct Completion {
|
||||
pub old_range: Range<Anchor>,
|
||||
pub new_text: String,
|
||||
pub label: CompletionLabel,
|
||||
pub label: CodeLabel,
|
||||
pub lsp_completion: lsp::CompletionItem,
|
||||
}
|
||||
|
||||
|
|
|
@ -77,21 +77,19 @@ pub trait LspExt: 'static + Send + Sync {
|
|||
) -> BoxFuture<'static, Result<PathBuf>>;
|
||||
fn cached_server_binary(&self, download_dir: Arc<Path>) -> BoxFuture<'static, Option<PathBuf>>;
|
||||
fn process_diagnostics(&self, diagnostics: &mut lsp::PublishDiagnosticsParams);
|
||||
fn label_for_completion(
|
||||
&self,
|
||||
_: &lsp::CompletionItem,
|
||||
_: &Language,
|
||||
) -> Option<CompletionLabel> {
|
||||
fn label_for_completion(&self, _: &lsp::CompletionItem, _: &Language) -> Option<CodeLabel> {
|
||||
None
|
||||
}
|
||||
fn label_for_symbol(&self, _: &lsp::SymbolInformation, _: &Language) -> Option<CodeLabel> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CompletionLabel {
|
||||
pub struct CodeLabel {
|
||||
pub text: String,
|
||||
pub runs: Vec<(Range<usize>, HighlightId)>,
|
||||
pub filter_range: Range<usize>,
|
||||
pub left_aligned_len: usize,
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize)]
|
||||
|
@ -431,15 +429,16 @@ impl Language {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn label_for_completion(
|
||||
&self,
|
||||
completion: &lsp::CompletionItem,
|
||||
) -> Option<CompletionLabel> {
|
||||
pub fn label_for_completion(&self, completion: &lsp::CompletionItem) -> Option<CodeLabel> {
|
||||
self.lsp_ext
|
||||
.as_ref()?
|
||||
.label_for_completion(completion, self)
|
||||
}
|
||||
|
||||
pub fn label_for_symbol(&self, symbol: &lsp::SymbolInformation) -> Option<CodeLabel> {
|
||||
self.lsp_ext.as_ref()?.label_for_symbol(symbol, self)
|
||||
}
|
||||
|
||||
pub fn highlight_text<'a>(
|
||||
&'a self,
|
||||
text: &'a Rope,
|
||||
|
@ -507,16 +506,15 @@ impl Grammar {
|
|||
}
|
||||
}
|
||||
|
||||
impl CompletionLabel {
|
||||
pub fn plain(completion: &lsp::CompletionItem) -> Self {
|
||||
impl CodeLabel {
|
||||
pub fn plain(text: String, filter_text: Option<&str>) -> Self {
|
||||
let mut result = Self {
|
||||
text: completion.label.clone(),
|
||||
runs: Vec::new(),
|
||||
left_aligned_len: completion.label.len(),
|
||||
filter_range: 0..completion.label.len(),
|
||||
filter_range: 0..text.len(),
|
||||
text,
|
||||
};
|
||||
if let Some(filter_text) = &completion.filter_text {
|
||||
if let Some(ix) = completion.label.find(filter_text) {
|
||||
if let Some(filter_text) = filter_text {
|
||||
if let Some(ix) = result.text.find(filter_text) {
|
||||
result.filter_range = ix..ix + filter_text.len();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
diagnostic_set::DiagnosticEntry, CodeAction, Completion, CompletionLabel, Diagnostic, Language,
|
||||
diagnostic_set::DiagnosticEntry, CodeAction, CodeLabel, Completion, Diagnostic, Language,
|
||||
Operation,
|
||||
};
|
||||
use anyhow::{anyhow, Result};
|
||||
|
@ -421,7 +421,10 @@ pub fn deserialize_completion(
|
|||
new_text: completion.new_text,
|
||||
label: language
|
||||
.and_then(|l| l.label_for_completion(&lsp_completion))
|
||||
.unwrap_or(CompletionLabel::plain(&lsp_completion)),
|
||||
.unwrap_or(CodeLabel::plain(
|
||||
lsp_completion.label.clone(),
|
||||
lsp_completion.filter_text.as_deref(),
|
||||
)),
|
||||
lsp_completion,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue