Add back Completion::documentation
This commit is contained in:
parent
03b4c7c464
commit
781a95d2e3
3 changed files with 63 additions and 4 deletions
|
@ -7,6 +7,7 @@ pub use crate::{
|
||||||
use crate::{
|
use crate::{
|
||||||
diagnostic_set::{DiagnosticEntry, DiagnosticGroup},
|
diagnostic_set::{DiagnosticEntry, DiagnosticGroup},
|
||||||
language_settings::{language_settings, LanguageSettings},
|
language_settings::{language_settings, LanguageSettings},
|
||||||
|
markdown::parse_markdown,
|
||||||
outline::OutlineItem,
|
outline::OutlineItem,
|
||||||
syntax_map::{
|
syntax_map::{
|
||||||
SyntaxLayerInfo, SyntaxMap, SyntaxMapCapture, SyntaxMapCaptures, SyntaxMapMatches,
|
SyntaxLayerInfo, SyntaxMap, SyntaxMapCapture, SyntaxMapCaptures, SyntaxMapMatches,
|
||||||
|
@ -144,12 +145,52 @@ pub struct Diagnostic {
|
||||||
pub is_unnecessary: bool,
|
pub is_unnecessary: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn prepare_completion_documentation(
|
||||||
|
documentation: &lsp::Documentation,
|
||||||
|
language_registry: &Arc<LanguageRegistry>,
|
||||||
|
language: Option<Arc<Language>>,
|
||||||
|
) -> Documentation {
|
||||||
|
match documentation {
|
||||||
|
lsp::Documentation::String(text) => {
|
||||||
|
if text.lines().count() <= 1 {
|
||||||
|
Documentation::SingleLine(text.clone())
|
||||||
|
} else {
|
||||||
|
Documentation::MultiLinePlainText(text.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lsp::Documentation::MarkupContent(lsp::MarkupContent { kind, value }) => match kind {
|
||||||
|
lsp::MarkupKind::PlainText => {
|
||||||
|
if value.lines().count() <= 1 {
|
||||||
|
Documentation::SingleLine(value.clone())
|
||||||
|
} else {
|
||||||
|
Documentation::MultiLinePlainText(value.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lsp::MarkupKind::Markdown => {
|
||||||
|
let parsed = parse_markdown(value, language_registry, language).await;
|
||||||
|
Documentation::MultiLineMarkdown(parsed)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum Documentation {
|
||||||
|
Undocumented,
|
||||||
|
SingleLine(String),
|
||||||
|
MultiLinePlainText(String),
|
||||||
|
MultiLineMarkdown(ParsedMarkdown),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Completion {
|
pub struct Completion {
|
||||||
pub old_range: Range<Anchor>,
|
pub old_range: Range<Anchor>,
|
||||||
pub new_text: String,
|
pub new_text: String,
|
||||||
pub label: CodeLabel,
|
pub label: CodeLabel,
|
||||||
pub server_id: LanguageServerId,
|
pub server_id: LanguageServerId,
|
||||||
|
pub documentation: Option<Documentation>,
|
||||||
pub lsp_completion: lsp::CompletionItem,
|
pub lsp_completion: lsp::CompletionItem,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -482,6 +482,7 @@ pub async fn deserialize_completion(
|
||||||
lsp_completion.filter_text.as_deref(),
|
lsp_completion.filter_text.as_deref(),
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
|
documentation: None,
|
||||||
server_id: LanguageServerId(completion.server_id as usize),
|
server_id: LanguageServerId(completion.server_id as usize),
|
||||||
lsp_completion,
|
lsp_completion,
|
||||||
})
|
})
|
||||||
|
|
|
@ -10,7 +10,7 @@ use futures::future;
|
||||||
use gpui::{AppContext, AsyncAppContext, Model};
|
use gpui::{AppContext, AsyncAppContext, Model};
|
||||||
use language::{
|
use language::{
|
||||||
language_settings::{language_settings, InlayHintKind},
|
language_settings::{language_settings, InlayHintKind},
|
||||||
point_from_lsp, point_to_lsp,
|
point_from_lsp, point_to_lsp, prepare_completion_documentation,
|
||||||
proto::{deserialize_anchor, deserialize_version, serialize_anchor, serialize_version},
|
proto::{deserialize_anchor, deserialize_version, serialize_anchor, serialize_version},
|
||||||
range_from_lsp, range_to_lsp, Anchor, Bias, Buffer, BufferSnapshot, CachedLspAdapter, CharKind,
|
range_from_lsp, range_to_lsp, Anchor, Bias, Buffer, BufferSnapshot, CachedLspAdapter, CharKind,
|
||||||
CodeAction, Completion, OffsetRangeExt, PointUtf16, ToOffset, ToPointUtf16, Transaction,
|
CodeAction, Completion, OffsetRangeExt, PointUtf16, ToOffset, ToPointUtf16, Transaction,
|
||||||
|
@ -1339,7 +1339,7 @@ impl LspCommand for GetCompletions {
|
||||||
async fn response_from_lsp(
|
async fn response_from_lsp(
|
||||||
self,
|
self,
|
||||||
completions: Option<lsp::CompletionResponse>,
|
completions: Option<lsp::CompletionResponse>,
|
||||||
_: Model<Project>,
|
project: Model<Project>,
|
||||||
buffer: Model<Buffer>,
|
buffer: Model<Buffer>,
|
||||||
server_id: LanguageServerId,
|
server_id: LanguageServerId,
|
||||||
mut cx: AsyncAppContext,
|
mut cx: AsyncAppContext,
|
||||||
|
@ -1359,7 +1359,8 @@ impl LspCommand for GetCompletions {
|
||||||
Default::default()
|
Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let completions = buffer.update(&mut cx, |buffer, _| {
|
let completions = buffer.update(&mut cx, |buffer, cx| {
|
||||||
|
let language_registry = project.read(cx).languages().clone();
|
||||||
let language = buffer.language().cloned();
|
let language = buffer.language().cloned();
|
||||||
let snapshot = buffer.snapshot();
|
let snapshot = buffer.snapshot();
|
||||||
let clipped_position = buffer.clip_point_utf16(Unclipped(self.position), Bias::Left);
|
let clipped_position = buffer.clip_point_utf16(Unclipped(self.position), Bias::Left);
|
||||||
|
@ -1443,14 +1444,29 @@ impl LspCommand for GetCompletions {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let language_registry = language_registry.clone();
|
||||||
let language = language.clone();
|
let language = language.clone();
|
||||||
LineEnding::normalize(&mut new_text);
|
LineEnding::normalize(&mut new_text);
|
||||||
Some(async move {
|
Some(async move {
|
||||||
let mut label = None;
|
let mut label = None;
|
||||||
if let Some(language) = language {
|
if let Some(language) = language.as_ref() {
|
||||||
language.process_completion(&mut lsp_completion).await;
|
language.process_completion(&mut lsp_completion).await;
|
||||||
label = language.label_for_completion(&lsp_completion).await;
|
label = language.label_for_completion(&lsp_completion).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let documentation = if let Some(lsp_docs) = &lsp_completion.documentation {
|
||||||
|
Some(
|
||||||
|
prepare_completion_documentation(
|
||||||
|
lsp_docs,
|
||||||
|
&language_registry,
|
||||||
|
language.clone(),
|
||||||
|
)
|
||||||
|
.await,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
Completion {
|
Completion {
|
||||||
old_range,
|
old_range,
|
||||||
new_text,
|
new_text,
|
||||||
|
@ -1460,6 +1476,7 @@ impl LspCommand for GetCompletions {
|
||||||
lsp_completion.filter_text.as_deref(),
|
lsp_completion.filter_text.as_deref(),
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
|
documentation,
|
||||||
server_id,
|
server_id,
|
||||||
lsp_completion,
|
lsp_completion,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue