Most of getting completion documentation resolved & cached MD parsing
This commit is contained in:
parent
ca88717f0c
commit
77ba25328c
12 changed files with 217 additions and 76 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2404,7 +2404,6 @@ dependencies = [
|
||||||
"parking_lot 0.11.2",
|
"parking_lot 0.11.2",
|
||||||
"postage",
|
"postage",
|
||||||
"project",
|
"project",
|
||||||
"pulldown-cmark",
|
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"rich_text",
|
"rich_text",
|
||||||
"rpc",
|
"rpc",
|
||||||
|
@ -3990,6 +3989,7 @@ dependencies = [
|
||||||
"lsp",
|
"lsp",
|
||||||
"parking_lot 0.11.2",
|
"parking_lot 0.11.2",
|
||||||
"postage",
|
"postage",
|
||||||
|
"pulldown-cmark",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"regex",
|
"regex",
|
||||||
"rpc",
|
"rpc",
|
||||||
|
|
|
@ -57,7 +57,6 @@ log.workspace = true
|
||||||
ordered-float.workspace = true
|
ordered-float.workspace = true
|
||||||
parking_lot.workspace = true
|
parking_lot.workspace = true
|
||||||
postage.workspace = true
|
postage.workspace = true
|
||||||
pulldown-cmark = { version = "0.9.2", default-features = false }
|
|
||||||
rand.workspace = true
|
rand.workspace = true
|
||||||
schemars.workspace = true
|
schemars.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
|
|
|
@ -9,7 +9,6 @@ mod highlight_matching_bracket;
|
||||||
mod hover_popover;
|
mod hover_popover;
|
||||||
pub mod items;
|
pub mod items;
|
||||||
mod link_go_to_definition;
|
mod link_go_to_definition;
|
||||||
mod markdown;
|
|
||||||
mod mouse_context_menu;
|
mod mouse_context_menu;
|
||||||
pub mod movement;
|
pub mod movement;
|
||||||
pub mod multi_buffer;
|
pub mod multi_buffer;
|
||||||
|
@ -78,6 +77,7 @@ pub use multi_buffer::{
|
||||||
ToPoint,
|
ToPoint,
|
||||||
};
|
};
|
||||||
use ordered_float::OrderedFloat;
|
use ordered_float::OrderedFloat;
|
||||||
|
use parking_lot::RwLock;
|
||||||
use project::{FormatTrigger, Location, Project, ProjectPath, ProjectTransaction};
|
use project::{FormatTrigger, Location, Project, ProjectPath, ProjectTransaction};
|
||||||
use rand::{seq::SliceRandom, thread_rng};
|
use rand::{seq::SliceRandom, thread_rng};
|
||||||
use rpc::proto::PeerId;
|
use rpc::proto::PeerId;
|
||||||
|
@ -788,10 +788,14 @@ enum ContextMenu {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ContextMenu {
|
impl ContextMenu {
|
||||||
fn select_first(&mut self, cx: &mut ViewContext<Editor>) -> bool {
|
fn select_first(
|
||||||
|
&mut self,
|
||||||
|
project: Option<&ModelHandle<Project>>,
|
||||||
|
cx: &mut ViewContext<Editor>,
|
||||||
|
) -> bool {
|
||||||
if self.visible() {
|
if self.visible() {
|
||||||
match self {
|
match self {
|
||||||
ContextMenu::Completions(menu) => menu.select_first(cx),
|
ContextMenu::Completions(menu) => menu.select_first(project, cx),
|
||||||
ContextMenu::CodeActions(menu) => menu.select_first(cx),
|
ContextMenu::CodeActions(menu) => menu.select_first(cx),
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
@ -800,10 +804,14 @@ impl ContextMenu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_prev(&mut self, cx: &mut ViewContext<Editor>) -> bool {
|
fn select_prev(
|
||||||
|
&mut self,
|
||||||
|
project: Option<&ModelHandle<Project>>,
|
||||||
|
cx: &mut ViewContext<Editor>,
|
||||||
|
) -> bool {
|
||||||
if self.visible() {
|
if self.visible() {
|
||||||
match self {
|
match self {
|
||||||
ContextMenu::Completions(menu) => menu.select_prev(cx),
|
ContextMenu::Completions(menu) => menu.select_prev(project, cx),
|
||||||
ContextMenu::CodeActions(menu) => menu.select_prev(cx),
|
ContextMenu::CodeActions(menu) => menu.select_prev(cx),
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
@ -812,10 +820,14 @@ impl ContextMenu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_next(&mut self, cx: &mut ViewContext<Editor>) -> bool {
|
fn select_next(
|
||||||
|
&mut self,
|
||||||
|
project: Option<&ModelHandle<Project>>,
|
||||||
|
cx: &mut ViewContext<Editor>,
|
||||||
|
) -> bool {
|
||||||
if self.visible() {
|
if self.visible() {
|
||||||
match self {
|
match self {
|
||||||
ContextMenu::Completions(menu) => menu.select_next(cx),
|
ContextMenu::Completions(menu) => menu.select_next(project, cx),
|
||||||
ContextMenu::CodeActions(menu) => menu.select_next(cx),
|
ContextMenu::CodeActions(menu) => menu.select_next(cx),
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
@ -824,10 +836,14 @@ impl ContextMenu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_last(&mut self, cx: &mut ViewContext<Editor>) -> bool {
|
fn select_last(
|
||||||
|
&mut self,
|
||||||
|
project: Option<&ModelHandle<Project>>,
|
||||||
|
cx: &mut ViewContext<Editor>,
|
||||||
|
) -> bool {
|
||||||
if self.visible() {
|
if self.visible() {
|
||||||
match self {
|
match self {
|
||||||
ContextMenu::Completions(menu) => menu.select_last(cx),
|
ContextMenu::Completions(menu) => menu.select_last(project, cx),
|
||||||
ContextMenu::CodeActions(menu) => menu.select_last(cx),
|
ContextMenu::CodeActions(menu) => menu.select_last(cx),
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
@ -861,7 +877,7 @@ struct CompletionsMenu {
|
||||||
id: CompletionId,
|
id: CompletionId,
|
||||||
initial_position: Anchor,
|
initial_position: Anchor,
|
||||||
buffer: ModelHandle<Buffer>,
|
buffer: ModelHandle<Buffer>,
|
||||||
completions: Arc<[Completion]>,
|
completions: Arc<RwLock<Box<[Completion]>>>,
|
||||||
match_candidates: Vec<StringMatchCandidate>,
|
match_candidates: Vec<StringMatchCandidate>,
|
||||||
matches: Arc<[StringMatch]>,
|
matches: Arc<[StringMatch]>,
|
||||||
selected_item: usize,
|
selected_item: usize,
|
||||||
|
@ -869,34 +885,115 @@ struct CompletionsMenu {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CompletionsMenu {
|
impl CompletionsMenu {
|
||||||
fn select_first(&mut self, cx: &mut ViewContext<Editor>) {
|
fn select_first(
|
||||||
|
&mut self,
|
||||||
|
project: Option<&ModelHandle<Project>>,
|
||||||
|
cx: &mut ViewContext<Editor>,
|
||||||
|
) {
|
||||||
self.selected_item = 0;
|
self.selected_item = 0;
|
||||||
self.list.scroll_to(ScrollTarget::Show(self.selected_item));
|
self.list.scroll_to(ScrollTarget::Show(self.selected_item));
|
||||||
|
self.attempt_resolve_selected_completion(project, cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_prev(&mut self, cx: &mut ViewContext<Editor>) {
|
fn select_prev(
|
||||||
|
&mut self,
|
||||||
|
project: Option<&ModelHandle<Project>>,
|
||||||
|
cx: &mut ViewContext<Editor>,
|
||||||
|
) {
|
||||||
if self.selected_item > 0 {
|
if self.selected_item > 0 {
|
||||||
self.selected_item -= 1;
|
self.selected_item -= 1;
|
||||||
self.list.scroll_to(ScrollTarget::Show(self.selected_item));
|
self.list.scroll_to(ScrollTarget::Show(self.selected_item));
|
||||||
}
|
}
|
||||||
|
self.attempt_resolve_selected_completion(project, cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_next(&mut self, cx: &mut ViewContext<Editor>) {
|
fn select_next(
|
||||||
|
&mut self,
|
||||||
|
project: Option<&ModelHandle<Project>>,
|
||||||
|
cx: &mut ViewContext<Editor>,
|
||||||
|
) {
|
||||||
if self.selected_item + 1 < self.matches.len() {
|
if self.selected_item + 1 < self.matches.len() {
|
||||||
self.selected_item += 1;
|
self.selected_item += 1;
|
||||||
self.list.scroll_to(ScrollTarget::Show(self.selected_item));
|
self.list.scroll_to(ScrollTarget::Show(self.selected_item));
|
||||||
}
|
}
|
||||||
|
self.attempt_resolve_selected_completion(project, cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_last(&mut self, cx: &mut ViewContext<Editor>) {
|
fn select_last(
|
||||||
|
&mut self,
|
||||||
|
project: Option<&ModelHandle<Project>>,
|
||||||
|
cx: &mut ViewContext<Editor>,
|
||||||
|
) {
|
||||||
self.selected_item = self.matches.len() - 1;
|
self.selected_item = self.matches.len() - 1;
|
||||||
self.list.scroll_to(ScrollTarget::Show(self.selected_item));
|
self.list.scroll_to(ScrollTarget::Show(self.selected_item));
|
||||||
|
self.attempt_resolve_selected_completion(project, cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn attempt_resolve_selected_completion(
|
||||||
|
&mut self,
|
||||||
|
project: Option<&ModelHandle<Project>>,
|
||||||
|
cx: &mut ViewContext<Editor>,
|
||||||
|
) {
|
||||||
|
println!("attempt_resolve_selected_completion");
|
||||||
|
let index = self.matches[dbg!(self.selected_item)].candidate_id;
|
||||||
|
dbg!(index);
|
||||||
|
let Some(project) = project else {
|
||||||
|
println!("no project");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let completions = self.completions.clone();
|
||||||
|
let completions_guard = completions.read();
|
||||||
|
let completion = &completions_guard[index];
|
||||||
|
if completion.lsp_completion.documentation.is_some() {
|
||||||
|
println!("has existing documentation");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let server_id = completion.server_id;
|
||||||
|
let completion = completion.lsp_completion.clone();
|
||||||
|
drop(completions_guard);
|
||||||
|
|
||||||
|
let Some(server) = project.read(cx).language_server_for_id(server_id) else {
|
||||||
|
println!("no server");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let can_resolve = server
|
||||||
|
.capabilities()
|
||||||
|
.completion_provider
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|options| options.resolve_provider)
|
||||||
|
.unwrap_or(false);
|
||||||
|
if !dbg!(can_resolve) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cx.spawn(|this, mut cx| async move {
|
||||||
|
println!("in spawn");
|
||||||
|
let request = server.request::<lsp::request::ResolveCompletionItem>(completion);
|
||||||
|
let Some(completion_item) = request.await.log_err() else {
|
||||||
|
println!("errored");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
if completion_item.documentation.is_some() {
|
||||||
|
println!("got new documentation");
|
||||||
|
let mut completions = completions.write();
|
||||||
|
completions[index].lsp_completion.documentation = completion_item.documentation;
|
||||||
|
println!("notifying");
|
||||||
|
_ = this.update(&mut cx, |_, cx| cx.notify());
|
||||||
|
} else {
|
||||||
|
println!("did not get anything");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
|
||||||
fn visible(&self) -> bool {
|
fn visible(&self) -> bool {
|
||||||
!self.matches.is_empty()
|
!self.matches.is_empty()
|
||||||
}
|
}
|
||||||
|
@ -914,7 +1011,8 @@ impl CompletionsMenu {
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.max_by_key(|(_, mat)| {
|
.max_by_key(|(_, mat)| {
|
||||||
let completion = &self.completions[mat.candidate_id];
|
let completions = self.completions.read();
|
||||||
|
let completion = &completions[mat.candidate_id];
|
||||||
let documentation = &completion.lsp_completion.documentation;
|
let documentation = &completion.lsp_completion.documentation;
|
||||||
|
|
||||||
let mut len = completion.label.text.chars().count();
|
let mut len = completion.label.text.chars().count();
|
||||||
|
@ -938,6 +1036,7 @@ impl CompletionsMenu {
|
||||||
let style = style.clone();
|
let style = style.clone();
|
||||||
move |_, range, items, cx| {
|
move |_, range, items, cx| {
|
||||||
let start_ix = range.start;
|
let start_ix = range.start;
|
||||||
|
let completions = completions.read();
|
||||||
for (ix, mat) in matches[range].iter().enumerate() {
|
for (ix, mat) in matches[range].iter().enumerate() {
|
||||||
let completion = &completions[mat.candidate_id];
|
let completion = &completions[mat.candidate_id];
|
||||||
let documentation = &completion.lsp_completion.documentation;
|
let documentation = &completion.lsp_completion.documentation;
|
||||||
|
@ -1052,7 +1151,8 @@ impl CompletionsMenu {
|
||||||
.with_child(list)
|
.with_child(list)
|
||||||
.with_children({
|
.with_children({
|
||||||
let mat = &self.matches[selected_item];
|
let mat = &self.matches[selected_item];
|
||||||
let completion = &self.completions[mat.candidate_id];
|
let completions = self.completions.read();
|
||||||
|
let completion = &completions[mat.candidate_id];
|
||||||
let documentation = &completion.lsp_completion.documentation;
|
let documentation = &completion.lsp_completion.documentation;
|
||||||
|
|
||||||
if let Some(lsp::Documentation::MarkupContent(content)) = documentation {
|
if let Some(lsp::Documentation::MarkupContent(content)) = documentation {
|
||||||
|
@ -1069,13 +1169,12 @@ impl CompletionsMenu {
|
||||||
Some(
|
Some(
|
||||||
Flex::column()
|
Flex::column()
|
||||||
.scrollable::<CompletionDocsMarkdown>(0, None, cx)
|
.scrollable::<CompletionDocsMarkdown>(0, None, cx)
|
||||||
.with_child(crate::markdown::render_markdown(
|
// .with_child(language::markdown::render_markdown(
|
||||||
&content.value,
|
// &content.value,
|
||||||
®istry,
|
// ®istry,
|
||||||
&language,
|
// &language,
|
||||||
&style,
|
// &style,
|
||||||
cx,
|
// ))
|
||||||
))
|
|
||||||
.constrained()
|
.constrained()
|
||||||
.with_width(alongside_docs_width)
|
.with_width(alongside_docs_width)
|
||||||
.contained()
|
.contained()
|
||||||
|
@ -1130,17 +1229,20 @@ impl CompletionsMenu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let completions = self.completions.read();
|
||||||
matches.sort_unstable_by_key(|mat| {
|
matches.sort_unstable_by_key(|mat| {
|
||||||
let completion = &self.completions[mat.candidate_id];
|
let completion = &completions[mat.candidate_id];
|
||||||
(
|
(
|
||||||
completion.lsp_completion.sort_text.as_ref(),
|
completion.lsp_completion.sort_text.as_ref(),
|
||||||
Reverse(OrderedFloat(mat.score)),
|
Reverse(OrderedFloat(mat.score)),
|
||||||
completion.sort_key(),
|
completion.sort_key(),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
drop(completions);
|
||||||
|
|
||||||
for mat in &mut matches {
|
for mat in &mut matches {
|
||||||
let filter_start = self.completions[mat.candidate_id].label.filter_range.start;
|
let completions = self.completions.read();
|
||||||
|
let filter_start = completions[mat.candidate_id].label.filter_range.start;
|
||||||
for position in &mut mat.positions {
|
for position in &mut mat.positions {
|
||||||
*position += filter_start;
|
*position += filter_start;
|
||||||
}
|
}
|
||||||
|
@ -3187,7 +3289,7 @@ impl Editor {
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
buffer,
|
buffer,
|
||||||
completions: completions.into(),
|
completions: Arc::new(RwLock::new(completions.into())),
|
||||||
matches: Vec::new().into(),
|
matches: Vec::new().into(),
|
||||||
selected_item: 0,
|
selected_item: 0,
|
||||||
list: Default::default(),
|
list: Default::default(),
|
||||||
|
@ -3196,6 +3298,9 @@ impl Editor {
|
||||||
if menu.matches.is_empty() {
|
if menu.matches.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
_ = this.update(&mut cx, |editor, cx| {
|
||||||
|
menu.attempt_resolve_selected_completion(editor.project.as_ref(), cx);
|
||||||
|
});
|
||||||
Some(menu)
|
Some(menu)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -3252,7 +3357,8 @@ impl Editor {
|
||||||
.matches
|
.matches
|
||||||
.get(action.item_ix.unwrap_or(completions_menu.selected_item))?;
|
.get(action.item_ix.unwrap_or(completions_menu.selected_item))?;
|
||||||
let buffer_handle = completions_menu.buffer;
|
let buffer_handle = completions_menu.buffer;
|
||||||
let completion = completions_menu.completions.get(mat.candidate_id)?;
|
let completions = completions_menu.completions.read();
|
||||||
|
let completion = completions.get(mat.candidate_id)?;
|
||||||
|
|
||||||
let snippet;
|
let snippet;
|
||||||
let text;
|
let text;
|
||||||
|
@ -5372,7 +5478,7 @@ impl Editor {
|
||||||
if self
|
if self
|
||||||
.context_menu
|
.context_menu
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.map(|menu| menu.select_last(cx))
|
.map(|menu| menu.select_last(self.project.as_ref(), cx))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -5416,25 +5522,25 @@ impl Editor {
|
||||||
|
|
||||||
pub fn context_menu_first(&mut self, _: &ContextMenuFirst, cx: &mut ViewContext<Self>) {
|
pub fn context_menu_first(&mut self, _: &ContextMenuFirst, cx: &mut ViewContext<Self>) {
|
||||||
if let Some(context_menu) = self.context_menu.as_mut() {
|
if let Some(context_menu) = self.context_menu.as_mut() {
|
||||||
context_menu.select_first(cx);
|
context_menu.select_first(self.project.as_ref(), cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn context_menu_prev(&mut self, _: &ContextMenuPrev, cx: &mut ViewContext<Self>) {
|
pub fn context_menu_prev(&mut self, _: &ContextMenuPrev, cx: &mut ViewContext<Self>) {
|
||||||
if let Some(context_menu) = self.context_menu.as_mut() {
|
if let Some(context_menu) = self.context_menu.as_mut() {
|
||||||
context_menu.select_prev(cx);
|
context_menu.select_prev(self.project.as_ref(), cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn context_menu_next(&mut self, _: &ContextMenuNext, cx: &mut ViewContext<Self>) {
|
pub fn context_menu_next(&mut self, _: &ContextMenuNext, cx: &mut ViewContext<Self>) {
|
||||||
if let Some(context_menu) = self.context_menu.as_mut() {
|
if let Some(context_menu) = self.context_menu.as_mut() {
|
||||||
context_menu.select_next(cx);
|
context_menu.select_next(self.project.as_ref(), cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn context_menu_last(&mut self, _: &ContextMenuLast, cx: &mut ViewContext<Self>) {
|
pub fn context_menu_last(&mut self, _: &ContextMenuLast, cx: &mut ViewContext<Self>) {
|
||||||
if let Some(context_menu) = self.context_menu.as_mut() {
|
if let Some(context_menu) = self.context_menu.as_mut() {
|
||||||
context_menu.select_last(cx);
|
context_menu.select_last(self.project.as_ref(), cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
display_map::{InlayOffset, ToDisplayPoint},
|
display_map::{InlayOffset, ToDisplayPoint},
|
||||||
link_go_to_definition::{DocumentRange, InlayRange},
|
link_go_to_definition::{DocumentRange, InlayRange},
|
||||||
markdown::{self, RenderedRegion},
|
|
||||||
Anchor, AnchorRangeExt, DisplayPoint, Editor, EditorSettings, EditorSnapshot, EditorStyle,
|
Anchor, AnchorRangeExt, DisplayPoint, Editor, EditorSettings, EditorSnapshot, EditorStyle,
|
||||||
ExcerptId, RangeToAnchorExt,
|
ExcerptId, RangeToAnchorExt,
|
||||||
};
|
};
|
||||||
|
@ -13,7 +12,10 @@ use gpui::{
|
||||||
platform::{CursorStyle, MouseButton},
|
platform::{CursorStyle, MouseButton},
|
||||||
AnyElement, AppContext, CursorRegion, Element, ModelHandle, MouseRegion, Task, ViewContext,
|
AnyElement, AppContext, CursorRegion, Element, ModelHandle, MouseRegion, Task, ViewContext,
|
||||||
};
|
};
|
||||||
use language::{Bias, DiagnosticEntry, DiagnosticSeverity, Language, LanguageRegistry};
|
use language::{
|
||||||
|
markdown::{self, RenderedRegion},
|
||||||
|
Bias, DiagnosticEntry, DiagnosticSeverity, Language, LanguageRegistry,
|
||||||
|
};
|
||||||
use project::{HoverBlock, HoverBlockKind, InlayHintLabelPart, Project};
|
use project::{HoverBlock, HoverBlockKind, InlayHintLabelPart, Project};
|
||||||
use std::{ops::Range, sync::Arc, time::Duration};
|
use std::{ops::Range, sync::Arc, time::Duration};
|
||||||
use util::TryFutureExt;
|
use util::TryFutureExt;
|
||||||
|
|
|
@ -46,6 +46,7 @@ lazy_static.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
parking_lot.workspace = true
|
parking_lot.workspace = true
|
||||||
postage.workspace = true
|
postage.workspace = true
|
||||||
|
pulldown-cmark = { version = "0.9.2", default-features = false }
|
||||||
regex.workspace = true
|
regex.workspace = true
|
||||||
schemars.workspace = true
|
schemars.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
diagnostic_set::DiagnosticSet,
|
diagnostic_set::DiagnosticSet,
|
||||||
highlight_map::{HighlightId, HighlightMap},
|
highlight_map::{HighlightId, HighlightMap},
|
||||||
|
markdown::RenderedMarkdown,
|
||||||
proto, BracketPair, Grammar, Language, LanguageConfig, LanguageRegistry, PLAIN_TEXT,
|
proto, BracketPair, Grammar, Language, LanguageConfig, LanguageRegistry, PLAIN_TEXT,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -148,6 +149,7 @@ 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 alongside_documentation: Option<RenderedMarkdown>,
|
||||||
pub server_id: LanguageServerId,
|
pub server_id: LanguageServerId,
|
||||||
pub lsp_completion: lsp::CompletionItem,
|
pub lsp_completion: lsp::CompletionItem,
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ mod buffer;
|
||||||
mod diagnostic_set;
|
mod diagnostic_set;
|
||||||
mod highlight_map;
|
mod highlight_map;
|
||||||
pub mod language_settings;
|
pub mod language_settings;
|
||||||
|
pub mod markdown;
|
||||||
mod outline;
|
mod outline;
|
||||||
pub mod proto;
|
pub mod proto;
|
||||||
mod syntax_map;
|
mod syntax_map;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::{Language, LanguageRegistry};
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
elements::Text,
|
elements::Text,
|
||||||
|
@ -8,10 +9,50 @@ use gpui::{
|
||||||
platform::{CursorStyle, MouseButton},
|
platform::{CursorStyle, MouseButton},
|
||||||
CursorRegion, MouseRegion, ViewContext,
|
CursorRegion, MouseRegion, ViewContext,
|
||||||
};
|
};
|
||||||
use language::{Language, LanguageRegistry};
|
|
||||||
use pulldown_cmark::{CodeBlockKind, Event, Options, Parser, Tag};
|
use pulldown_cmark::{CodeBlockKind, Event, Options, Parser, Tag};
|
||||||
|
|
||||||
use crate::{Editor, EditorStyle};
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct RenderedMarkdown {
|
||||||
|
text: String,
|
||||||
|
highlights: Vec<(Range<usize>, HighlightStyle)>,
|
||||||
|
region_ranges: Vec<Range<usize>>,
|
||||||
|
regions: Vec<RenderedRegion>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// impl RenderedMarkdown {
|
||||||
|
// pub fn render(&self, style: &theme::Editor, cx: &mut ViewContext<Editor>) -> Text {
|
||||||
|
// let code_span_background_color = style.document_highlight_read_background;
|
||||||
|
// let view_id = cx.view_id();
|
||||||
|
// let mut region_id = 0;
|
||||||
|
// Text::new(text, style.text.clone())
|
||||||
|
// .with_highlights(highlights)
|
||||||
|
// .with_custom_runs(region_ranges, move |ix, bounds, scene, _| {
|
||||||
|
// region_id += 1;
|
||||||
|
// let region = regions[ix].clone();
|
||||||
|
// if let Some(url) = region.link_url {
|
||||||
|
// scene.push_cursor_region(CursorRegion {
|
||||||
|
// bounds,
|
||||||
|
// style: CursorStyle::PointingHand,
|
||||||
|
// });
|
||||||
|
// scene.push_mouse_region(
|
||||||
|
// MouseRegion::new::<Editor>(view_id, region_id, bounds)
|
||||||
|
// .on_click::<Editor, _>(MouseButton::Left, move |_, _, cx| {
|
||||||
|
// cx.platform().open_url(&url)
|
||||||
|
// }),
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// if region.code {
|
||||||
|
// scene.push_quad(gpui::Quad {
|
||||||
|
// bounds,
|
||||||
|
// background: Some(code_span_background_color),
|
||||||
|
// border: Default::default(),
|
||||||
|
// corner_radii: (2.0).into(),
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// .with_soft_wrap(true)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct RenderedRegion {
|
pub struct RenderedRegion {
|
||||||
|
@ -23,9 +64,8 @@ pub fn render_markdown(
|
||||||
markdown: &str,
|
markdown: &str,
|
||||||
language_registry: &Arc<LanguageRegistry>,
|
language_registry: &Arc<LanguageRegistry>,
|
||||||
language: &Option<Arc<Language>>,
|
language: &Option<Arc<Language>>,
|
||||||
style: &EditorStyle,
|
style: &theme::Editor,
|
||||||
cx: &mut ViewContext<Editor>,
|
) -> RenderedMarkdown {
|
||||||
) -> Text {
|
|
||||||
let mut text = String::new();
|
let mut text = String::new();
|
||||||
let mut highlights = Vec::new();
|
let mut highlights = Vec::new();
|
||||||
let mut region_ranges = Vec::new();
|
let mut region_ranges = Vec::new();
|
||||||
|
@ -42,43 +82,19 @@ pub fn render_markdown(
|
||||||
&mut regions,
|
&mut regions,
|
||||||
);
|
);
|
||||||
|
|
||||||
let code_span_background_color = style.document_highlight_read_background;
|
RenderedMarkdown {
|
||||||
let view_id = cx.view_id();
|
text,
|
||||||
let mut region_id = 0;
|
highlights,
|
||||||
Text::new(text, style.text.clone())
|
region_ranges,
|
||||||
.with_highlights(highlights)
|
regions,
|
||||||
.with_custom_runs(region_ranges, move |ix, bounds, scene, _| {
|
}
|
||||||
region_id += 1;
|
|
||||||
let region = regions[ix].clone();
|
|
||||||
if let Some(url) = region.link_url {
|
|
||||||
scene.push_cursor_region(CursorRegion {
|
|
||||||
bounds,
|
|
||||||
style: CursorStyle::PointingHand,
|
|
||||||
});
|
|
||||||
scene.push_mouse_region(
|
|
||||||
MouseRegion::new::<Editor>(view_id, region_id, bounds)
|
|
||||||
.on_click::<Editor, _>(MouseButton::Left, move |_, _, cx| {
|
|
||||||
cx.platform().open_url(&url)
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if region.code {
|
|
||||||
scene.push_quad(gpui::Quad {
|
|
||||||
bounds,
|
|
||||||
background: Some(code_span_background_color),
|
|
||||||
border: Default::default(),
|
|
||||||
corner_radii: (2.0).into(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.with_soft_wrap(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_markdown_block(
|
pub fn render_markdown_block(
|
||||||
markdown: &str,
|
markdown: &str,
|
||||||
language_registry: &Arc<LanguageRegistry>,
|
language_registry: &Arc<LanguageRegistry>,
|
||||||
language: &Option<Arc<Language>>,
|
language: &Option<Arc<Language>>,
|
||||||
style: &EditorStyle,
|
style: &theme::Editor,
|
||||||
text: &mut String,
|
text: &mut String,
|
||||||
highlights: &mut Vec<(Range<usize>, HighlightStyle)>,
|
highlights: &mut Vec<(Range<usize>, HighlightStyle)>,
|
||||||
region_ranges: &mut Vec<Range<usize>>,
|
region_ranges: &mut Vec<Range<usize>>,
|
||||||
|
@ -231,7 +247,7 @@ pub fn render_code(
|
||||||
highlights: &mut Vec<(Range<usize>, HighlightStyle)>,
|
highlights: &mut Vec<(Range<usize>, HighlightStyle)>,
|
||||||
content: &str,
|
content: &str,
|
||||||
language: &Arc<Language>,
|
language: &Arc<Language>,
|
||||||
style: &EditorStyle,
|
style: &theme::Editor,
|
||||||
) {
|
) {
|
||||||
let prev_len = text.len();
|
let prev_len = text.len();
|
||||||
text.push_str(content);
|
text.push_str(content);
|
|
@ -482,6 +482,7 @@ pub async fn deserialize_completion(
|
||||||
lsp_completion.filter_text.as_deref(),
|
lsp_completion.filter_text.as_deref(),
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
|
alongside_documentation: None,
|
||||||
server_id: LanguageServerId(completion.server_id as usize),
|
server_id: LanguageServerId(completion.server_id as usize),
|
||||||
lsp_completion,
|
lsp_completion,
|
||||||
})
|
})
|
||||||
|
|
|
@ -466,7 +466,10 @@ impl LanguageServer {
|
||||||
completion_item: Some(CompletionItemCapability {
|
completion_item: Some(CompletionItemCapability {
|
||||||
snippet_support: Some(true),
|
snippet_support: Some(true),
|
||||||
resolve_support: Some(CompletionItemCapabilityResolveSupport {
|
resolve_support: Some(CompletionItemCapabilityResolveSupport {
|
||||||
properties: vec!["additionalTextEdits".to_string()],
|
properties: vec![
|
||||||
|
"documentation".to_string(),
|
||||||
|
"additionalTextEdits".to_string(),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
@ -748,6 +751,15 @@ impl LanguageServer {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// some child of string literal (be it "" or ``) which is the child of an attribute
|
||||||
|
|
||||||
|
// <Foo className="bar" />
|
||||||
|
// <Foo className={`bar`} />
|
||||||
|
// <Foo className={something + "bar"} />
|
||||||
|
// <Foo className={something + "bar"} />
|
||||||
|
// const classes = "awesome ";
|
||||||
|
// <Foo className={classes} />
|
||||||
|
|
||||||
fn request_internal<T: request::Request>(
|
fn request_internal<T: request::Request>(
|
||||||
next_id: &AtomicUsize,
|
next_id: &AtomicUsize,
|
||||||
response_handlers: &Mutex<Option<HashMap<usize, ResponseHandler>>>,
|
response_handlers: &Mutex<Option<HashMap<usize, ResponseHandler>>>,
|
||||||
|
|
|
@ -1462,6 +1462,7 @@ impl LspCommand for GetCompletions {
|
||||||
lsp_completion.filter_text.as_deref(),
|
lsp_completion.filter_text.as_deref(),
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
|
alongside_documentation: None,
|
||||||
server_id,
|
server_id,
|
||||||
lsp_completion,
|
lsp_completion,
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,8 +128,8 @@ pub fn init(
|
||||||
"tsx",
|
"tsx",
|
||||||
tree_sitter_typescript::language_tsx(),
|
tree_sitter_typescript::language_tsx(),
|
||||||
vec![
|
vec![
|
||||||
Arc::new(typescript::TypeScriptLspAdapter::new(node_runtime.clone())),
|
// Arc::new(typescript::TypeScriptLspAdapter::new(node_runtime.clone())),
|
||||||
Arc::new(typescript::EsLintLspAdapter::new(node_runtime.clone())),
|
// Arc::new(typescript::EsLintLspAdapter::new(node_runtime.clone())),
|
||||||
Arc::new(tailwind::TailwindLspAdapter::new(node_runtime.clone())),
|
Arc::new(tailwind::TailwindLspAdapter::new(node_runtime.clone())),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue