-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support inlay hint protocol, but emacs' overlay is buggy, realtime re…
…nder inlay hint, overlay will infect buffer's content.
- Loading branch information
1 parent
a3d67c8
commit 0ad8afb
Showing
16 changed files
with
215 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from core.handler import Handler | ||
from core.utils import * | ||
|
||
|
||
class InlayHint(Handler): | ||
name = "inlay_hint" | ||
method = "textDocument/inlayHint" | ||
cancel_on_change = True | ||
provider = "inlay_hint_provider" | ||
|
||
def process_request(self, range_start, range_end) -> dict: | ||
self.range_start = range_start | ||
self.range_end = range_end | ||
|
||
range = { | ||
"start": range_start, | ||
"end": range_end | ||
} | ||
return dict(range=range) | ||
|
||
def process_response(self, response: dict) -> None: | ||
if response is not None: | ||
self.file_action.push_inlay_hints(response, self.range_start, self.range_end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
;;; lsp-bridge-inlay-hint.el --- Inlay hint protocol -*- lexical-binding: t; -*- | ||
|
||
;; Filename: lsp-bridge-inlay-hint.el | ||
;; Description: Inlay hint protocol | ||
;; Author: Andy Stewart <[email protected]> | ||
;; Maintainer: Andy Stewart <[email protected]> | ||
;; Copyright (C) 2023, Andy Stewart, all rights reserved. | ||
;; Created: 2023-10-03 21:35:08 | ||
;; Version: 0.1 | ||
;; Last-Updated: 2023-10-03 21:35:08 | ||
;; By: Andy Stewart | ||
;; URL: https://www.github.org/manateelazycat/lsp-bridge-inlay-hint | ||
;; Keywords: | ||
;; Compatibility: GNU Emacs 30.0.50 | ||
;; | ||
;; Features that might be required by this library: | ||
;; | ||
;; | ||
;; | ||
|
||
;;; This file is NOT part of GNU Emacs | ||
|
||
;;; License | ||
;; | ||
;; This program is free software; you can redistribute it and/or modify | ||
;; it under the terms of the GNU General Public License as published by | ||
;; the Free Software Foundation; either version 3, or (at your option) | ||
;; any later version. | ||
|
||
;; This program is distributed in the hope that it will be useful, | ||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
;; GNU General Public License for more details. | ||
|
||
;; You should have received a copy of the GNU General Public License | ||
;; along with this program; see the file COPYING. If not, write to | ||
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth | ||
;; Floor, Boston, MA 02110-1301, USA. | ||
|
||
;;; Commentary: | ||
;; | ||
;; Inlay hint protocol | ||
;; | ||
|
||
;;; Installation: | ||
;; | ||
;; Put lsp-bridge-inlay-hint.el to your load-path. | ||
;; The load-path is usually ~/elisp/. | ||
;; It's set in your ~/.emacs like this: | ||
;; (add-to-list 'load-path (expand-file-name "~/elisp")) | ||
;; | ||
;; And the following to your ~/.emacs startup file. | ||
;; | ||
;; (require 'lsp-bridge-inlay-hint) | ||
;; | ||
;; No need more. | ||
|
||
;;; Customize: | ||
;; | ||
;; | ||
;; | ||
;; All of the above can customize by: | ||
;; M-x customize-group RET lsp-bridge-inlay-hint RET | ||
;; | ||
|
||
;;; Change log: | ||
;; | ||
;; 2023/10/03 | ||
;; * First released. | ||
;; | ||
|
||
;;; Acknowledgements: | ||
;; | ||
;; | ||
;; | ||
|
||
;;; TODO | ||
;; | ||
;; | ||
;; | ||
|
||
;;; Require | ||
|
||
|
||
;;; Code: | ||
|
||
(defun lsp-bridge-inlay-hint () | ||
(lsp-bridge-call-file-api "inlay_hint" | ||
(lsp-bridge--point-position (window-start)) | ||
(lsp-bridge--point-position (window-end)))) | ||
|
||
(defvar-local lsp-bridge-inlay-hint-overlays '()) | ||
|
||
(defun lsp-bridge-inlay-hint-hide-overlays () | ||
(when lsp-bridge-inlay-hint-overlays | ||
(dolist (inlay-hint-overlay lsp-bridge-inlay-hint-overlays) | ||
(delete-overlay inlay-hint-overlay))) | ||
|
||
(setq-local lsp-bridge-inlay-hint-overlays nil)) | ||
|
||
(defun lsp-bridge-inlay-hint--render (filepath filehost inlay-hints) | ||
(lsp-bridge--with-file-buffer filepath filehost | ||
(lsp-bridge-inlay-hint-hide-overlays) | ||
|
||
(dolist (hint inlay-hints) | ||
(let* ((hint-start-pos (acm-backend-lsp-position-to-point (plist-get hint :position))) | ||
(hint-at-end-of-line-p (save-excursion | ||
(goto-char hint-start-pos) | ||
(eolp))) | ||
(hint-text (format "%s" | ||
(cond ((listp (plist-get hint :label)) | ||
(apply 'concat | ||
(mapcar (lambda (label) | ||
(concat (plist-get label :value) " ")) | ||
(plist-get hint :label) | ||
))) | ||
(t (plist-get hint :label))))) | ||
(hint-insert-text (if hint-at-end-of-line-p | ||
(format "%s\n" hint-text) | ||
hint-text)) | ||
(overlay (make-overlay | ||
hint-start-pos | ||
(1+ hint-start-pos) | ||
nil t t))) | ||
(overlay-put overlay 'display hint-insert-text) | ||
(overlay-put overlay 'face `(:foreground "#aaaaaa")) | ||
(overlay-put overlay 'read-only t) | ||
(push overlay lsp-bridge-inlay-hint-overlays) | ||
)))) | ||
|
||
(provide 'lsp-bridge-inlay-hint) | ||
|
||
;;; lsp-bridge-inlay-hint.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters