|
|
@ -262,8 +262,7 @@ impl Component for Completion {
|
|
|
|
.cursor(doc.text().slice(..));
|
|
|
|
.cursor(doc.text().slice(..));
|
|
|
|
let cursor_pos = (helix_core::coords_at_pos(doc.text().slice(..), cursor_pos).row
|
|
|
|
let cursor_pos = (helix_core::coords_at_pos(doc.text().slice(..), cursor_pos).row
|
|
|
|
- view.offset.row) as u16;
|
|
|
|
- view.offset.row) as u16;
|
|
|
|
|
|
|
|
let mut markdown_doc = match &option.documentation {
|
|
|
|
let mut doc = match &option.documentation {
|
|
|
|
|
|
|
|
Some(lsp::Documentation::String(contents))
|
|
|
|
Some(lsp::Documentation::String(contents))
|
|
|
|
| Some(lsp::Documentation::MarkupContent(lsp::MarkupContent {
|
|
|
|
| Some(lsp::Documentation::MarkupContent(lsp::MarkupContent {
|
|
|
|
kind: lsp::MarkupKind::PlainText,
|
|
|
|
kind: lsp::MarkupKind::PlainText,
|
|
|
@ -311,24 +310,42 @@ impl Component for Completion {
|
|
|
|
None => return,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let half = area.height / 2;
|
|
|
|
let (popup_x, popup_y) = self.popup.get_rel_position(area, cx);
|
|
|
|
let height = 15.min(half);
|
|
|
|
let (popup_width, _popup_height) = self.popup.get_size();
|
|
|
|
// we want to make sure the cursor is visible (not hidden behind the documentation)
|
|
|
|
let mut width = area
|
|
|
|
let y = if cursor_pos + area.y
|
|
|
|
.width
|
|
|
|
>= (cx.editor.tree.area().height - height - 2/* statusline + commandline */)
|
|
|
|
.saturating_sub(popup_x)
|
|
|
|
{
|
|
|
|
.saturating_sub(popup_width);
|
|
|
|
0
|
|
|
|
let area = if width > 30 {
|
|
|
|
|
|
|
|
let mut height = area.height.saturating_sub(popup_y);
|
|
|
|
|
|
|
|
let x = popup_x + popup_width;
|
|
|
|
|
|
|
|
let y = popup_y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let Some((rel_width, rel_height)) = markdown_doc.required_size((width, height)) {
|
|
|
|
|
|
|
|
width = rel_width;
|
|
|
|
|
|
|
|
height = rel_height;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect::new(x, y, width, height)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// -2 to subtract command line + statusline. a bit of a hack, because of splits.
|
|
|
|
let half = area.height / 2;
|
|
|
|
area.height.saturating_sub(height).saturating_sub(2)
|
|
|
|
let height = 15.min(half);
|
|
|
|
};
|
|
|
|
// we want to make sure the cursor is visible (not hidden behind the documentation)
|
|
|
|
|
|
|
|
let y = if cursor_pos + area.y
|
|
|
|
|
|
|
|
>= (cx.editor.tree.area().height - height - 2/* statusline + commandline */)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// -2 to subtract command line + statusline. a bit of a hack, because of splits.
|
|
|
|
|
|
|
|
area.height.saturating_sub(height).saturating_sub(2)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let area = Rect::new(0, y, area.width, height);
|
|
|
|
Rect::new(0, y, area.width, height)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// clear area
|
|
|
|
// clear area
|
|
|
|
let background = cx.editor.theme.get("ui.popup");
|
|
|
|
let background = cx.editor.theme.get("ui.popup");
|
|
|
|
surface.clear_with(area, background);
|
|
|
|
surface.clear_with(area, background);
|
|
|
|
doc.render(area, surface, cx);
|
|
|
|
markdown_doc.render(area, surface, cx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|