@@ -262,8 +262,7 @@ impl Component for Completion {
262262 .cursor(doc.text().slice(..));
263263 let cursor_pos = (helix_core::coords_at_pos(doc.text().slice(..), cursor_pos).row
264264 - view.offset.row) as u16;
265−
266− let mut doc = match &option.documentation {
265+ let mut markdown_doc = match &option.documentation {
267266 Some(lsp::Documentation::String(contents))
268267 | Some(lsp::Documentation::MarkupContent(lsp::MarkupContent {
269268 kind: lsp::MarkupKind::PlainText,
@@ -311,24 +310,42 @@ impl Component for Completion {
311310 None => return,
312311 };
313312
314− let half = area.height / 2;
315− let height = 15.min(half);
316− // we want to make sure the cursor is visible (not hidden behind the documentation)
317− let y = if cursor_pos + area.y
318− >= (cx.editor.tree.area().height - height - 2/* statusline + commandline */)
319− {
320− 0
313+ let (popup_x, popup_y) = self.popup.get_rel_position(area, cx);
314+ let (popup_width, _popup_height) = self.popup.get_size();
315+ let mut width = area
316+ .width
317+ .saturating_sub(popup_x)
318+ .saturating_sub(popup_width);
319+ let area = if width > 30 {
320+ let mut height = area.height.saturating_sub(popup_y);
321+ let x = popup_x + popup_width;
322+ let y = popup_y;
323+
324+ if let Some((rel_width, rel_height)) = markdown_doc.required_size((width, height)) {
325+ width = rel_width;
326+ height = rel_height;
327+ }
328+ Rect::new(x, y, width, height)
321329 } else {
322− // -2 to subtract command line + statusline. a bit of a hack, because of splits.
323− area.height.saturating_sub(height).saturating_sub(2)
324− };
330+ let half = area.height / 2;
331+ let height = 15.min(half);
332+ // we want to make sure the cursor is visible (not hidden behind the documentation)
333+ let y = if cursor_pos + area.y
334+ >= (cx.editor.tree.area().height - height - 2/* statusline + commandline */)
335+ {
336+ 0
337+ } else {
338+ // -2 to subtract command line + statusline. a bit of a hack, because of splits.
339+ area.height.saturating_sub(height).saturating_sub(2)
340+ };
325341
326− let area = Rect::new(0, y, area.width, height);
342+ Rect::new(0, y, area.width, height)
343+ };
327344
328345 // clear area
329346 let background = cx.editor.theme.get("ui.popup");
330347 surface.clear_with(area, background);
331− doc.render(area, surface, cx);
348+ markdown_doc.render(area, surface, cx);
332349 }
333350 }
334351}