| 
61 | 61 |   :type 'integer  | 
62 | 62 |   :group 'lsp-ui-peek)  | 
63 | 63 | 
 
  | 
64 |  | -(defcustom lsp-ui-peek-force-fontify t  | 
65 |  | -  "Force to fontify chunks of code (use semantics colors).  | 
66 |  | -WARNING: This can heavily slow the processing when `lsp-ui-peek-expand-function'  | 
 | 64 | +(defcustom lsp-ui-peek-fontify 'on-demand  | 
 | 65 | +  "Whether to fontify chunks of code (use semantics colors).  | 
 | 66 | +WARNING: 'always can heavily slow the processing when `lsp-ui-peek-expand-function'  | 
67 | 67 | expands more than 1 file.  It is recommended to keeps the default value of  | 
68 |  | -`lsp-ui-peek-expand-function' when this variable is non-nil."  | 
69 |  | -  :type 'boolean  | 
 | 68 | +`lsp-ui-peek-expand-function' when this variable is 'always."  | 
 | 69 | +  :type '(choice (const :tag "Never" never)  | 
 | 70 | +                 (const :tag "On demand" on-demand)  | 
 | 71 | +                 (const :tag "Always" always))  | 
70 | 72 |   :group 'lsp-ui-peek)  | 
71 | 73 | 
 
  | 
72 | 74 | (defcustom lsp-ui-peek-always-show nil  | 
@@ -138,8 +140,8 @@ The function takes one parameter: a list of cons where the car is the  | 
138 | 140 | filename and the cdr is the number of references in that file.  | 
139 | 141 | It should returns a list of filenames to expand.  | 
140 | 142 | WARNING: If you change this variable and expand more than 1 file, it is  | 
141 |  | -recommended to set `lsp-ui-peek-force-fontify' to nil, otherwise it will cause  | 
142 |  | -performances issues.")  | 
 | 143 | +recommended to set `lsp-ui-peek-fontify' to 'never or 'on-demand, otherwise it  | 
 | 144 | +will cause performances issues.")  | 
143 | 145 | 
 
  | 
144 | 146 | (defvar-local lsp-ui-peek--overlay nil)  | 
145 | 147 | (defvar-local lsp-ui-peek--list nil)  | 
@@ -320,13 +322,26 @@ XREFS is a list of references/definitions."  | 
320 | 322 |         (append list (-repeat (- min-len len) ""))  | 
321 | 323 |       list)))  | 
322 | 324 | 
 
  | 
 | 325 | +(defun lsp-ui-peek--render (major string)  | 
 | 326 | +  (with-temp-buffer  | 
 | 327 | +    (insert string)  | 
 | 328 | +    (delay-mode-hooks  | 
 | 329 | +      (let ((inhibit-message t))  | 
 | 330 | +        (funcall major))  | 
 | 331 | +      (ignore-errors  | 
 | 332 | +        (font-lock-ensure)))  | 
 | 333 | +    (buffer-string)))  | 
 | 334 | + | 
323 | 335 | (defun lsp-ui-peek--peek ()  | 
324 | 336 |   "Show reference's chunk of code."  | 
325 | 337 |   (-let* ((xref (lsp-ui-peek--get-selection))  | 
326 | 338 |           ((&plist :file file :chunk chunk) (or xref lsp-ui-peek--last-xref))  | 
327 | 339 |           (header (concat " " (lsp-ui--workspace-path file) "\n"))  | 
328 | 340 |           (header2 (format " %s %s" lsp-ui-peek--size-list (symbol-name lsp-ui-peek--kind)))  | 
329 | 341 |           (ref-view (--> chunk  | 
 | 342 | +                         (if (eq lsp-ui-peek-fontify 'on-demand)  | 
 | 343 | +                             (lsp-ui-peek--render major-mode it)  | 
 | 344 | +                           chunk)  | 
330 | 345 |                          (subst-char-in-string ?\t ?\s it)  | 
331 | 346 |                          (concat header it)  | 
332 | 347 |                          (split-string it "\n")))  | 
@@ -636,7 +651,7 @@ LOCATION can be either a LSP Location or SymbolInformation."  | 
636 | 651 |           :len (- end start))))  | 
637 | 652 | 
 
  | 
638 | 653 | (defun lsp-ui-peek--fontify-buffer (filename)  | 
639 |  | -  (when lsp-ui-peek-force-fontify  | 
 | 654 | +  (when (eq lsp-ui-peek-fontify 'always)  | 
640 | 655 |     (unless buffer-file-name  | 
641 | 656 |       (make-local-variable 'delay-mode-hooks)  | 
642 | 657 |       (let ((buffer-file-name filename)  | 
 | 
0 commit comments