Skip to content

Commit 5dc0b09

Browse files
authored
Revert #705 (#707)
* Move require lsp-ui to each separat files * Remove predefined * rev indentation * First revert for now
1 parent ae1801e commit 5dc0b09

File tree

6 files changed

+128
-73
lines changed

6 files changed

+128
-73
lines changed

lsp-ui-doc.el

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
;;; Code:
3232

33+
(require 'lsp-ui-util)
34+
3335
(require 'lsp-protocol)
3436
(require 'lsp-mode)
3537
(require 'dash)
@@ -52,9 +54,6 @@
5254
(declare-function xwidget-webkit-execute-script-rv "ext:xwidget" (xwidget script &optional default))
5355
(declare-function xwidget-resize "ext:xwidget" (xwidget new-width new-height))
5456

55-
(declare-function lsp-ui-kill-timer 'lsp-ui)
56-
(declare-function lsp-ui-delete-overlay 'lsp-ui)
57-
5857
(defgroup lsp-ui-doc nil
5958
"Display informations of the current line."
6059
:group 'tools
@@ -65,8 +64,7 @@
6564

6665
(defcustom lsp-ui-doc-enable t
6766
"Whether or not to enable lsp-ui-doc.
68-
Displays documentation of the symbol at point on hover. This only takes effect
69-
when a buffer is started."
67+
Displays documentation of the symbol at point on hover. This only takes effect when a buffer is started."
7068
:type 'boolean
7169
:group 'lsp-ui)
7270

@@ -183,31 +181,31 @@ Only the `background' is used in this face."
183181
:group 'lsp-ui-doc)
184182

185183
(defvar lsp-ui-doc-frame-parameters
186-
'((left . -1)
187-
(no-focus-on-map . t)
188-
(min-width . 0)
189-
(width . 0)
190-
(min-height . 0)
191-
(height . 0)
192-
(internal-border-width . 1)
193-
(vertical-scroll-bars . nil)
194-
(horizontal-scroll-bars . nil)
195-
(right-fringe . 0)
196-
(menu-bar-lines . 0)
197-
(tool-bar-lines . 0)
198-
(tab-bar-lines . 0)
184+
'((left . -1)
185+
(no-focus-on-map . t)
186+
(min-width . 0)
187+
(width . 0)
188+
(min-height . 0)
189+
(height . 0)
190+
(internal-border-width . 1)
191+
(vertical-scroll-bars . nil)
192+
(horizontal-scroll-bars . nil)
193+
(right-fringe . 0)
194+
(menu-bar-lines . 0)
195+
(tool-bar-lines . 0)
196+
(tab-bar-lines . 0)
199197
(tab-bar-lines-keep-state . 0)
200-
(line-spacing . 0)
201-
(unsplittable . t)
202-
(undecorated . t)
203-
(top . -1)
204-
(visibility . nil)
205-
(mouse-wheel-frame . nil)
206-
(no-other-frame . t)
198+
(line-spacing . 0)
199+
(unsplittable . t)
200+
(undecorated . t)
201+
(top . -1)
202+
(visibility . nil)
203+
(mouse-wheel-frame . nil)
204+
(no-other-frame . t)
207205
(inhibit-double-buffering . t)
208-
(drag-internal-border . t)
209-
(no-special-glyphs . t)
210-
(desktop-dont-save . t))
206+
(drag-internal-border . t)
207+
(no-special-glyphs . t)
208+
(desktop-dont-save . t))
211209
"Frame parameters used to create the frame.")
212210

213211
(defvar lsp-ui-doc-render-function nil
@@ -246,8 +244,6 @@ Because some variables are buffer local.")
246244
(defvar-local lsp-ui-doc--from-mouse-current nil
247245
"Non nil when the current call is triggered by a mouse event")
248246

249-
(defvar-local lsp-ui-doc--unfocus-frame-timer nil)
250-
251247
(defconst lsp-ui-doc--buffer-prefix " *lsp-ui-doc-")
252248

253249
(defmacro lsp-ui-doc--with-buffer (&rest body)
@@ -426,8 +422,8 @@ We don't extract the string that `lps-line' is already displaying."
426422
"Hide the frame."
427423
(setq lsp-ui-doc--bounds nil
428424
lsp-ui-doc--from-mouse nil)
429-
(lsp-ui-delete-overlay lsp-ui-doc--inline-ov)
430-
(lsp-ui-delete-overlay lsp-ui-doc--highlight-ov)
425+
(lsp-ui-util-safe-delete-overlay lsp-ui-doc--inline-ov)
426+
(lsp-ui-util-safe-delete-overlay lsp-ui-doc--highlight-ov)
431427
(when-let ((frame (lsp-ui-doc--get-frame)))
432428
(when (frame-visible-p frame)
433429
(make-frame-invisible frame))))
@@ -893,15 +889,15 @@ HEIGHT is the documentation number of lines."
893889
(run-hook-with-args 'lsp-ui-doc-frame-hook frame window)
894890
(when lsp-ui-doc-use-webkit
895891
(define-key (current-global-map) [xwidget-event]
896-
(lambda ()
897-
(interactive)
898-
(let ((xwidget-event-type (nth 1 last-input-event)))
899-
;; (when (eq xwidget-event-type 'load-changed)
900-
;; (lsp-ui-doc--move-frame (lsp-ui-doc--get-frame)))
901-
(when (eq xwidget-event-type 'javascript-callback)
902-
(let ((proc (nth 3 last-input-event))
903-
(arg (nth 4 last-input-event)))
904-
(funcall proc arg))))))
892+
(lambda ()
893+
(interactive)
894+
(let ((xwidget-event-type (nth 1 last-input-event)))
895+
;; (when (eq xwidget-event-type 'load-changed)
896+
;; (lsp-ui-doc--move-frame (lsp-ui-doc--get-frame)))
897+
(when (eq xwidget-event-type 'javascript-callback)
898+
(let ((proc (nth 3 last-input-event))
899+
(arg (nth 4 last-input-event)))
900+
(funcall proc arg))))))
905901
(lsp-ui-doc--webkit-run-xwidget))
906902
frame))
907903

@@ -924,7 +920,7 @@ HEIGHT is the documentation number of lines."
924920
(and (looking-at "[[:graph:]]") (cons (point) (1+ (point))))))
925921
(unless (equal lsp-ui-doc--bounds bounds)
926922
(lsp-ui-doc--hide-frame)
927-
(lsp-ui-kill-timer lsp-ui-doc--timer)
923+
(lsp-ui-util-safe-kill-timer lsp-ui-doc--timer)
928924
(setq lsp-ui-doc--timer
929925
(run-with-idle-timer
930926
lsp-ui-doc-delay nil
@@ -1171,6 +1167,7 @@ It is supposed to be called from `lsp-ui--toggle'"
11711167
(interactive)
11721168
(lsp-ui-doc--hide-frame))
11731169

1170+
(defvar-local lsp-ui-doc--unfocus-frame-timer nil)
11741171
(defun lsp-ui-doc--glance-hide-frame ()
11751172
"Hook to hide hover information popup for `lsp-ui-doc-glance'."
11761173
(when (or (overlayp lsp-ui-doc--inline-ov)

lsp-ui-imenu.el

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535

3636
(require 'lsp-mode)
3737
(require 'dash)
38-
39-
(declare-function lsp-ui-kill-timer 'lsp-ui)
38+
(require 'lsp-ui-util)
4039

4140
(defgroup lsp-ui-imenu nil
4241
"Display imenu entries."
@@ -380,7 +379,7 @@ ITEMS are used when the kind position is 'left."
380379

381380
(defun lsp-ui-imenu--start-refresh (&rest _)
382381
"Starts the auto refresh timer."
383-
(lsp-ui-kill-timer lsp-ui-imenu--refresh-timer)
382+
(lsp-ui-util-safe-kill-timer lsp-ui-imenu--refresh-timer)
384383
(setq lsp-ui-imenu--refresh-timer
385384
(run-with-idle-timer lsp-ui-imenu-auto-refresh-delay nil #'lsp-ui-imenu--refresh)))
386385

lsp-ui-peek.el

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
(require 'xref)
4040
(require 'dash)
4141

42-
(declare-function lsp-ui--mute-apply 'lsp-ui)
43-
4442
(defgroup lsp-ui-peek nil
4543
"Improve version of xref with peek feature."
4644
:group 'tools
@@ -183,12 +181,12 @@ will cause performances issues.")
183181
(eval '(progn
184182
(evil-define-motion lsp-ui-peek-jump-backward (count)
185183
(lsp-ui-peek--with-evil-jumps
186-
(evil--jump-backward count)
187-
(run-hooks 'xref-after-return-hook)))
184+
(evil--jump-backward count)
185+
(run-hooks 'xref-after-return-hook)))
188186
(evil-define-motion lsp-ui-peek-jump-forward (count)
189187
(lsp-ui-peek--with-evil-jumps
190-
(evil--jump-forward count)
191-
(run-hooks 'xref-after-return-hook))))
188+
(evil--jump-forward count)
189+
(run-hooks 'xref-after-return-hook))))
192190
t))
193191

194192
(defmacro lsp-ui-peek--prop (prop &optional string)
@@ -348,8 +346,10 @@ XREFS is a list of references/definitions."
348346
(with-temp-buffer
349347
(insert string)
350348
(delay-mode-hooks
351-
(lsp-ui--mute-apply (funcall major))
352-
(ignore-errors (font-lock-ensure)))
349+
(let ((inhibit-message t))
350+
(funcall major))
351+
(ignore-errors
352+
(font-lock-ensure)))
353353
(buffer-string)))
354354

355355
(defun lsp-ui-peek--peek ()
@@ -635,8 +635,7 @@ EXTRA is a plist of extra parameters."
635635
(append extra (lsp--text-document-position-params))))
636636

637637
(defun lsp-ui-peek--extract-chunk-from-buffer (pos start end)
638-
"Return the chunk of code pointed to by POS (a Position object) in the current
639-
buffer.
638+
"Return the chunk of code pointed to by POS (a Position object) in the current buffer.
640639
START and END are delimiters."
641640
(let* ((point (lsp--position-to-point pos))
642641
(inhibit-field-text-motion t)

lsp-ui-sideline.el

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
;;; Code:
3232

33+
(require 'lsp-ui-util)
3334
(require 'lsp-protocol)
3435
(require 'lsp-mode)
3536
(require 'flycheck nil 'noerror)
@@ -43,8 +44,6 @@
4344
(declare-function flycheck-error-format-message-and-id "ext:flycheck.el")
4445
(declare-function flycheck-error-level "ext:flycheck.el")
4546

46-
(declare-function lsp-ui-line-number-display-width 'lsp-ui)
47-
4847
(defgroup lsp-ui-sideline nil
4948
"Display information for the current line."
5049
:group 'tools
@@ -326,8 +325,8 @@ CURRENT is non-nil when the point is on the symbol."
326325
(propertize str 'display (lsp-ui-sideline--compute-height)))))
327326

328327
(defun lsp-ui-sideline--check-duplicate (symbol info)
329-
"Check if there's already a SYMBOL containing INFO, unless
330-
`lsp-ui-sideline-ignore-duplicate' is set to t."
328+
"Check if there's already a SYMBOL containing INFO, unless `lsp-ui-sideline-ignore-duplicate'
329+
is set to t."
331330
(not (when lsp-ui-sideline-ignore-duplicate
332331
(--any (and (string= (overlay-get it 'symbol) symbol)
333332
(string= (overlay-get it 'info) info))
@@ -350,7 +349,7 @@ CURRENT is non-nil when the point is on the symbol."
350349
(if (< emacs-major-version 27)
351350
;; This was necessary with emacs < 27, recent versions take
352351
;; into account the display-line width with :align-to
353-
(lsp-ui-line-number-display-width)
352+
(lsp-ui-util-line-number-display-width)
354353
0)
355354
(if (or
356355
(bound-and-true-p whitespace-mode)
@@ -364,7 +363,7 @@ CURRENT is non-nil when the point is on the symbol."
364363
(or (and (>= emacs-major-version 27)
365364
;; We still need this number when calculating available space
366365
;; even with emacs >= 27
367-
(lsp-ui-line-number-display-width))
366+
(lsp-ui-util-line-number-display-width))
368367
0)))
369368

370369
(defun lsp-ui-sideline--valid-tag-p (tag mode)
@@ -436,8 +435,7 @@ CURRENT is non-nil when the point is on the symbol."
436435
(lsp-ui-sideline--toggle-current ov nil))))))
437436

438437
(defun lsp-ui-sideline--split-long-lines (lines)
439-
"Fill LINES so that they are not longer than
440-
`lsp-ui-sideline-diagnostic-max-line-length' characters."
438+
"Fill LINES so that they are not longer than `lsp-ui-sideline-diagnostic-max-line-length' characters."
441439
(cl-mapcan (lambda (line)
442440
(if (< (length line) lsp-ui-sideline-diagnostic-max-line-length)
443441
(list line)
@@ -451,8 +449,7 @@ CURRENT is non-nil when the point is on the symbol."
451449
(defun lsp-ui-sideline--diagnostics (buffer bol eol)
452450
"Show diagnostics belonging to the current line.
453451
Loop over flycheck errors with `flycheck-overlay-errors-in'.
454-
Find appropriate position for sideline overlays with
455-
`lsp-ui-sideline--find-line'.
452+
Find appropriate position for sideline overlays with `lsp-ui-sideline--find-line'.
456453
Push sideline overlays on `lsp-ui-sideline--ovs'."
457454
(when (and (bound-and-true-p flycheck-mode)
458455
(bound-and-true-p lsp-ui-sideline-mode)

lsp-ui-util.el

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
;;; lsp-ui-util.el --- Utility module for Lsp-Ui -*- lexical-binding: t -*-
2+
3+
;; Copyright (C) 2020 Shen, Jen-Chieh
4+
5+
;; Author: Jen-Chieh Shen <[email protected]>
6+
;; URL: https://github.com/emacs-lsp/lsp-ui
7+
;; Keywords: languages, tools
8+
;; Version: 6.2
9+
10+
;;; License
11+
;;
12+
;; This program is free software; you can redistribute it and/or modify
13+
;; it under the terms of the GNU General Public License as published by
14+
;; the Free Software Foundation; either version 3, or (at your option)
15+
;; any later version.
16+
17+
;; This program is distributed in the hope that it will be useful,
18+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
;; GNU General Public License for more details.
21+
22+
;; You should have received a copy of the GNU General Public License
23+
;; along with this program; see the file COPYING. If not, write to
24+
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
25+
;; Floor, Boston, MA 02110-1301, USA.
26+
27+
;;; Commentary:
28+
29+
;;
30+
;; Utility module for Lsp-Ui.
31+
;;
32+
33+
;;; Code:
34+
35+
(require 'face-remap)
36+
37+
(defun lsp-ui-util-safe-kill-timer (timer)
38+
"Safely kill the TIMER."
39+
(when (timerp timer) (cancel-timer timer)))
40+
41+
(defun lsp-ui-util-safe-delete-overlay (overlay)
42+
"Safely delete the OVERLAY."
43+
(when (overlayp overlay) (delete-overlay overlay)))
44+
45+
(defun lsp-ui-util-line-number-display-width ()
46+
"Safe way to get value from function `line-number-display-width'."
47+
(if (bound-and-true-p display-line-numbers-mode)
48+
;; For some reason, function `line-number-display-width' gave
49+
;; us error `args-out-of-range' even we do not pass anything towards
50+
;; to it function. See the following links,
51+
;;
52+
;; - https://github.com/emacs-lsp/lsp-ui/issues/294
53+
;; - https://github.com/emacs-lsp/lsp-ui/issues/533 (duplicate)
54+
(+ (or (ignore-errors (line-number-display-width)) 0) 2)
55+
0))
56+
57+
(defun lsp-ui-util-line-string (pos)
58+
"Return string at POS."
59+
(when (integerp pos) (save-excursion (goto-char pos) (thing-at-point 'line))))
60+
61+
(defun lsp-ui-util-column (&optional pos)
62+
"Return column at POS."
63+
(setq pos (or pos (point)))
64+
(save-excursion (goto-char pos) (current-column)))
65+
66+
(defun lsp-ui-util-text-scale-factor ()
67+
"Return the factor effect by `text-scale-mode'."
68+
(or (plist-get (cdr text-scale-mode-remapping) :height) 1))
69+
70+
(provide 'lsp-ui-util)
71+
;;; lsp-ui-util.el ends here

lsp-ui.el

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,6 @@
8181
(+ (or (ignore-errors (line-number-display-width)) 0) 2)
8282
0))
8383

84-
;;
85-
;;; Core
86-
87-
(require 'lsp-ui-sideline)
88-
(require 'lsp-ui-peek)
89-
(require 'lsp-ui-imenu)
90-
(require 'lsp-ui-doc)
91-
9284
(defconst lsp-ui-resources-dir
9385
(--> (or load-file-name (buffer-file-name))
9486
(file-name-directory it)

0 commit comments

Comments
 (0)