@@ -599,6 +599,24 @@ FN is the function to call on click."
599599 (frame-parameter nil 'lsp-ui-doc--no-focus )
600600 (select-frame (frame-parent ) t )))
601601
602+ (defun lsp-ui-doc--fill-document ()
603+ " Better wrap the document so it fits the doc window."
604+ (let ((fill-column (- lsp-ui-doc-max-width 5 ))
605+ start ; record start for `fill-region'
606+ first-line) ; first line in paragraph
607+ (save-excursion
608+ (goto-char (point-min ))
609+ (setq start (point )
610+ first-line (thing-at-point 'line ))
611+ (while (re-search-forward " ^[ \t ]*\n " nil t )
612+ (setq first-line (thing-at-point 'line ))
613+ (when (< fill-column (length first-line))
614+ (fill-region start (point )))
615+ (setq start (point )))
616+ ; ; Fill the last paragraph
617+ (when (< fill-column (length first-line))
618+ (fill-region start (point-max ))))))
619+
602620(defun lsp-ui-doc--make-smaller-empty-lines nil
603621 " Make empty lines half normal lines."
604622 (progn ; Customize line before header
@@ -664,9 +682,8 @@ FN is the function to call on click."
664682 'lsp-ui-doc--webkit-resize-callback ))
665683 (erase-buffer )
666684 (insert (s-trim string))
667- (let ((fill-column (- lsp-ui-doc-max-width 5 )))
668- (fill-region (point-min ) (point-max )))
669685 (unless (lsp-ui-doc--inline-p)
686+ (lsp-ui-doc--fill-document)
670687 (lsp-ui-doc--make-smaller-empty-lines)
671688 (lsp-ui-doc--handle-hr-lines))
672689 (add-text-properties 1 (point ) '(line-height 1 ))
0 commit comments