Skip to content

Commit bd5970e

Browse files
authoredJun 19, 2018
[lsp-ui-peek] Generalize lsp-ui-peek-force-fontify to lsp-ui-peek-fontify and add another choice 'on-demand (#148)
'on-demand fontifies the chunk when the selection changes.
1 parent ee259fd commit bd5970e

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed
 

‎lsp-ui-peek.el

+23-8
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@
6161
:type 'integer
6262
:group 'lsp-ui-peek)
6363

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'
6767
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))
7072
:group 'lsp-ui-peek)
7173

7274
(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
138140
filename and the cdr is the number of references in that file.
139141
It should returns a list of filenames to expand.
140142
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.")
143145

144146
(defvar-local lsp-ui-peek--overlay nil)
145147
(defvar-local lsp-ui-peek--list nil)
@@ -320,13 +322,26 @@ XREFS is a list of references/definitions."
320322
(append list (-repeat (- min-len len) ""))
321323
list)))
322324

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+
323335
(defun lsp-ui-peek--peek ()
324336
"Show reference's chunk of code."
325337
(-let* ((xref (lsp-ui-peek--get-selection))
326338
((&plist :file file :chunk chunk) (or xref lsp-ui-peek--last-xref))
327339
(header (concat " " (lsp-ui--workspace-path file) "\n"))
328340
(header2 (format " %s %s" lsp-ui-peek--size-list (symbol-name lsp-ui-peek--kind)))
329341
(ref-view (--> chunk
342+
(if (eq lsp-ui-peek-fontify 'on-demand)
343+
(lsp-ui-peek--render major-mode it)
344+
chunk)
330345
(subst-char-in-string ?\t ?\s it)
331346
(concat header it)
332347
(split-string it "\n")))
@@ -636,7 +651,7 @@ LOCATION can be either a LSP Location or SymbolInformation."
636651
:len (- end start))))
637652

638653
(defun lsp-ui-peek--fontify-buffer (filename)
639-
(when lsp-ui-peek-force-fontify
654+
(when (eq lsp-ui-peek-fontify 'always)
640655
(unless buffer-file-name
641656
(make-local-variable 'delay-mode-hooks)
642657
(let ((buffer-file-name filename)

‎lsp-ui.el

+12
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@
4646
(require 'lsp-ui-imenu)
4747
(require 'lsp-ui-doc)
4848

49+
(defun lsp-ui-peek--render (major string)
50+
(with-temp-buffer
51+
(insert string)
52+
(delay-mode-hooks
53+
(let ((inhibit-message t))
54+
(funcall major))
55+
(ignore-errors
56+
(font-lock-ensure)))
57+
(buffer-string))
58+
)
59+
60+
4961
(defun lsp-ui--workspace-path (path)
5062
"Return the PATH relative to the workspace.
5163
If the PATH is not in the workspace, it returns the original PATH."

0 commit comments

Comments
 (0)
Please sign in to comment.