mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 01:16:18 +04:00
refactor(lsp): handle out-of-range active_signature
(#11825)
This commit is contained in:
parent
162028d444
commit
f6d39cbc1d
@ -96,7 +96,10 @@ fn handle_event(&mut self, event: &Event, _cx: &mut Context) -> EventResult {
|
|||||||
fn render(&mut self, area: Rect, surface: &mut Buffer, cx: &mut Context) {
|
fn render(&mut self, area: Rect, surface: &mut Buffer, cx: &mut Context) {
|
||||||
let margin = Margin::horizontal(1);
|
let margin = Margin::horizontal(1);
|
||||||
|
|
||||||
let signature = &self.signatures[self.active_signature];
|
let signature = self
|
||||||
|
.signatures
|
||||||
|
.get(self.active_signature)
|
||||||
|
.unwrap_or_else(|| &self.signatures[0]);
|
||||||
|
|
||||||
let active_param_span = signature.active_param_range.map(|(start, end)| {
|
let active_param_span = signature.active_param_range.map(|(start, end)| {
|
||||||
vec![(
|
vec![(
|
||||||
@ -108,9 +111,13 @@ fn render(&mut self, area: Rect, surface: &mut Buffer, cx: &mut Context) {
|
|||||||
)]
|
)]
|
||||||
});
|
});
|
||||||
|
|
||||||
let sig = &self.signatures[self.active_signature];
|
let signature = self
|
||||||
|
.signatures
|
||||||
|
.get(self.active_signature)
|
||||||
|
.unwrap_or_else(|| &self.signatures[0]);
|
||||||
|
|
||||||
let sig_text = crate::ui::markdown::highlighted_code_block(
|
let sig_text = crate::ui::markdown::highlighted_code_block(
|
||||||
sig.signature.as_str(),
|
signature.signature.as_str(),
|
||||||
&self.language,
|
&self.language,
|
||||||
Some(&cx.editor.theme),
|
Some(&cx.editor.theme),
|
||||||
Arc::clone(&self.config_loader),
|
Arc::clone(&self.config_loader),
|
||||||
@ -130,7 +137,7 @@ fn render(&mut self, area: Rect, surface: &mut Buffer, cx: &mut Context) {
|
|||||||
let sig_text_para = Paragraph::new(&sig_text).wrap(Wrap { trim: false });
|
let sig_text_para = Paragraph::new(&sig_text).wrap(Wrap { trim: false });
|
||||||
sig_text_para.render(sig_text_area, surface);
|
sig_text_para.render(sig_text_area, surface);
|
||||||
|
|
||||||
if sig.signature_doc.is_none() {
|
if signature.signature_doc.is_none() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +149,7 @@ fn render(&mut self, area: Rect, surface: &mut Buffer, cx: &mut Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let sig_doc = match &sig.signature_doc {
|
let sig_doc = match &signature.signature_doc {
|
||||||
None => return,
|
None => return,
|
||||||
Some(doc) => Markdown::new(doc.clone(), Arc::clone(&self.config_loader)),
|
Some(doc) => Markdown::new(doc.clone(), Arc::clone(&self.config_loader)),
|
||||||
};
|
};
|
||||||
@ -160,12 +167,15 @@ fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
|
|||||||
const PADDING: u16 = 2;
|
const PADDING: u16 = 2;
|
||||||
const SEPARATOR_HEIGHT: u16 = 1;
|
const SEPARATOR_HEIGHT: u16 = 1;
|
||||||
|
|
||||||
let sig = &self.signatures[self.active_signature];
|
let signature = self
|
||||||
|
.signatures
|
||||||
|
.get(self.active_signature)
|
||||||
|
.unwrap_or_else(|| &self.signatures[0]);
|
||||||
|
|
||||||
let max_text_width = viewport.0.saturating_sub(PADDING).clamp(10, 120);
|
let max_text_width = viewport.0.saturating_sub(PADDING).clamp(10, 120);
|
||||||
|
|
||||||
let signature_text = crate::ui::markdown::highlighted_code_block(
|
let signature_text = crate::ui::markdown::highlighted_code_block(
|
||||||
sig.signature.as_str(),
|
signature.signature.as_str(),
|
||||||
&self.language,
|
&self.language,
|
||||||
None,
|
None,
|
||||||
Arc::clone(&self.config_loader),
|
Arc::clone(&self.config_loader),
|
||||||
@ -174,7 +184,7 @@ fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
|
|||||||
let (sig_width, sig_height) =
|
let (sig_width, sig_height) =
|
||||||
crate::ui::text::required_size(&signature_text, max_text_width);
|
crate::ui::text::required_size(&signature_text, max_text_width);
|
||||||
|
|
||||||
let (width, height) = match sig.signature_doc {
|
let (width, height) = match signature.signature_doc {
|
||||||
Some(ref doc) => {
|
Some(ref doc) => {
|
||||||
let doc_md = Markdown::new(doc.clone(), Arc::clone(&self.config_loader));
|
let doc_md = Markdown::new(doc.clone(), Arc::clone(&self.config_loader));
|
||||||
let doc_text = doc_md.parse(None);
|
let doc_text = doc_md.parse(None);
|
||||||
|
Loading…
Reference in New Issue
Block a user