-
-
Notifications
You must be signed in to change notification settings - Fork 945
Implemented code lenses support in lsp-mode #595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lsp-mode.el
Outdated
|
|
||
| (defun lsp--lenses-display (lenses) | ||
| "Show LENSES." | ||
| (let ((overlays (->> lenses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some new lines here to reduce indentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restructured the code + deleted one variable which wasn't used.
lsp-mode.el
Outdated
| "Face used for highlighting symbols being written to." | ||
| :group 'lsp-faces) | ||
|
|
||
| (defcustom lsp-lenses-check-interval 0.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Singular form may be good enough... codeLens is in its singular form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense, will change it everywhere.
lsp-mode.el
Outdated
| "Delete all lenses." | ||
| (interactive) | ||
| (let ((scroll-preserve-screen-position t)) | ||
| (-each lsp--lenses-overlays 'delete-overlay) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Builtin mapc suffices.. No need for -each
lsp-mode.el
Outdated
| (goto-char (overlay-start ov)) | ||
| (overlay-put ov | ||
| 'before-string | ||
| (format "%s%s\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
concat?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do
lsp-mode.el
Outdated
| "Create iddle function for buffer BUFFER." | ||
| (when (or (not buffer) (eq (current-buffer) buffer)) | ||
| (cond | ||
| ((not (equal (buffer-modified-tick) lsp--lenses-modified-tick)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For numbers, which is more common, = or eql?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will change it to =
cec57ff to
b5b7cfd
Compare
|
Addressed comments |
lsp-mode.el
Outdated
| (defvar-local lsp--lens-idle-timer nil | ||
| "Pair of points which holds the last window location the lenses were loaded.") | ||
|
|
||
| (defvar-local lsp--lences-data nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lsp--lens-data
|
Typo in description. clain -> claim "was adapter" > "adapted" ... CCLS can be referred in its lower case form.. |
| (or (car (cl-remove-if-not (lambda (ov) (lsp--lens-overlay-matches-pos ov pos)) lsp--lens-overlays)) | ||
| (let* ((ov (save-excursion | ||
| (goto-char pos) | ||
| (make-overlay (point-at-bol) (1+ (point-at-eol)))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set front-advance but unset rear-advance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(make-overlay (point-at-bol) (1+ (point-at-eol) nil 'front-advance)
Oh, this does not matter if the overlay is on its own line. It matters when the overlay is on the same line of the text.
lsp-mode.el
Outdated
| "Create iddle function for buffer BUFFER." | ||
| (when (or (not buffer) (eq (current-buffer) buffer)) | ||
| (cond | ||
| ((not (eq (buffer-modified-tick) lsp--lens-modified-tick)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/=
lsp-mode.el
Outdated
| (puthash "pending" t it) | ||
| (lsp-request-async "codeLens/resolve" it | ||
| (lambda (lens) | ||
| (when (equal tick (buffer-modified-tick)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=
lsp-mode.el
Outdated
| (lsp-request-async "textDocument/codeLens" | ||
| `(:textDocument (:uri ,(lsp--path-to-uri buffer-file-name))) | ||
| (lambda (lenses) | ||
| (when (equal tick (buffer-modified-tick)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=
lsp-mode.el
Outdated
| (-some-> lsp--lens-refresh-timer cancel-timer) | ||
|
|
||
| (setq-local lsp--lens-modified-tick (buffer-modified-tick)) | ||
| (setq-local lsp--lens-page (list (window-start) (window-end))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cons? And line 1013
lsp-mode.el
Outdated
| it | ||
| (lsp-request "codeLens/resolve" it))) | ||
| lsp--lens-display))) | ||
| (--each lsp--lens-overlays |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The (--each ...) is redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, copy/paste mistake, the only thing that is needed is the code in the let statement.
lsp-mode.el
Outdated
| (--each lsp--lens-overlays | ||
| (unless (-contains? overlays it) | ||
| (delete-overlay it))) | ||
| (setq-local lsp--lens-overlays overlays))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setq-local is also redundant
988ebf7 to
3447600
Compare
|
Addressed everything except "Set front-advance but unset rear-advance" which is not clear to me. |
lsp-mode.el
Outdated
| `buffer-modified-tick' at the time of receiving the updates the | ||
| updates must be discarted.. | ||
| CALLBACK - the callback for the lenses." | ||
| (--each (-filter 'lsp--lens-backend-not-loaded? lenses) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#'
lsp-mode.el
Outdated
| (when (= tick (buffer-modified-tick)) | ||
| (remhash "pending" it) | ||
| (puthash "command" (gethash "command" lens) it) | ||
| (when (-all? 'lsp--lens-backend-present? lenses) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#'
lsp-mode.el
Outdated
| (< pos (overlay-end ov)))) | ||
|
|
||
| (defun lsp--lens-idle-function (&optional buffer) | ||
| "Create iddle function for buffer BUFFER." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo. idle
Fixes emacs-lsp#361 The lenses support is similar to what VScode has: - Lenses are displayed above the line - Lenses on the same line are grouped and displayed above the first text item. - Extension could register custom lences provider and add custom lenses, e. g. JDT LS has extensions that display the tests hints. - The placement code was adapted from https://github.com/cpitclaudel/quick-peek Tested against CCLS and JDT LS. CCLS has to register the proper handler(similar to what ccls vscode extension does). Some other servers like rls do claim that they support lenses but I was unable to trigger them. Further improvements: * Provide different methods for redering methods (e. g. in the end of the line) * Keyboard support for the lenses * Test more servers
Fixes #361
The lenses support is similar to what VScode has:
Lenses are displayed above the line
Lenses on the same line are grouped and displayed above the first text item.
Extension could register custom lences provider and add custom lenses, e. g.
JDT LS has extensions that display the tests hints.
The placement code was adapter from https://github.com/cpitclaudel/quick-peek
Tested against CCLS and JDT LS. CCLS has to register the proper handler(similar
to what ccls vscode extension does). Some other servers like rls do clain that
they support lenses but I was unable to trigger them.
Further improvements: