From 45a18c3db5bef7f9dba54bd3ff879207549cba21 Mon Sep 17 00:00:00 2001 From: gotpl <631707329@qq.com> Date: Mon, 12 Aug 2024 00:50:51 +0800 Subject: [PATCH 1/2] fix lsp-bridge-epc-manager-manager nil caused by auto-insert-mode. --- lsp-bridge.el | 109 +++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/lsp-bridge.el b/lsp-bridge.el index ac73932a5c..9771d1e610 100644 --- a/lsp-bridge.el +++ b/lsp-bridge.el @@ -1621,61 +1621,62 @@ So we build this macro to restore postion after code format." (defun lsp-bridge-monitor-after-change (begin end length) ;; Nothing change actual if `begin' and `end' equal `lsp-bridge--before-change-begin-point' and `lsp-bridge--before-change-end-point' ;; Then we should not send any request to search backend. - (unless (and (equal begin lsp-bridge--before-change-begin-point) + (when lsp-bridge-epc-process + (unless (and (equal begin lsp-bridge--before-change-begin-point) (equal end lsp-bridge--before-change-end-point)) - ;; Use `save-match-data' protect match data, avoid conflict with command call `search-regexp'. - (save-match-data - (unless lsp-bridge-revert-buffer-flag - (let ((change-text (buffer-substring-no-properties begin end))) - ;; Record last command to `lsp-bridge-last-change-command'. - (setq lsp-bridge-last-change-command (format "%s" this-command)) - - ;; Record last change position to avoid popup outdate completions. - (lsp-bridge-record-last-change-position) - - ;; Set `lsp-bridge-last-change-is-delete-command-p' - (setq lsp-bridge-last-change-is-delete-command-p (> length 0)) - - ;; Sync change for org babel if we enable it - (lsp-bridge-org-babel-monitor-after-change begin end length) - - ;; Send LSP requests. - (when (or (lsp-bridge-call-file-api-p) - (lsp-bridge-is-remote-file)) - - ;; Uncomment below code to debug `change_file' protocol. - ;; (message (format "change_file: '%s' '%s' '%s' '%s' '%s' '%s'" - ;; length - ;; lsp-bridge--before-change-begin-pos - ;; lsp-bridge--before-change-end-pos - ;; (lsp-bridge--position) - ;; change-text - ;; (buffer-substring-no-properties (line-beginning-position) (point)) - ;; )) - - ;; Send change_file request to trigger LSP completion. - (lsp-bridge-call-file-api "change_file" - lsp-bridge--before-change-begin-pos - lsp-bridge--before-change-end-pos - length - change-text - (lsp-bridge--position) - (acm-char-before) - (buffer-name) - (acm-get-input-prefix)) - - ;; Send inlay hint request. - (lsp-bridge-try-send-inlay-hint-request)) - - ;; Complete other non-LSP backends. - (lsp-bridge-complete-other-backends) - - ;; Update search words backend. - (lsp-bridge-search-words-update - lsp-bridge--before-change-begin-pos - lsp-bridge--before-change-end-pos - change-text) - ))))) + ;; Use `save-match-data' protect match data, avoid conflict with command call `search-regexp'. + (save-match-data + (unless lsp-bridge-revert-buffer-flag + (let ((change-text (buffer-substring-no-properties begin end))) + ;; Record last command to `lsp-bridge-last-change-command'. + (setq lsp-bridge-last-change-command (format "%s" this-command)) + + ;; Record last change position to avoid popup outdate completions. + (lsp-bridge-record-last-change-position) + + ;; Set `lsp-bridge-last-change-is-delete-command-p' + (setq lsp-bridge-last-change-is-delete-command-p (> length 0)) + + ;; Sync change for org babel if we enable it + (lsp-bridge-org-babel-monitor-after-change begin end length) + + ;; Send LSP requests. + (when (or (lsp-bridge-call-file-api-p) + (lsp-bridge-is-remote-file)) + + ;; Uncomment below code to debug `change_file' protocol. + ;; (message (format "change_file: '%s' '%s' '%s' '%s' '%s' '%s'" + ;; length + ;; lsp-bridge--before-change-begin-pos + ;; lsp-bridge--before-change-end-pos + ;; (lsp-bridge--position) + ;; change-text + ;; (buffer-substring-no-properties (line-beginning-position) (point)) + ;; )) + + ;; Send change_file request to trigger LSP completion. + (lsp-bridge-call-file-api "change_file" + lsp-bridge--before-change-begin-pos + lsp-bridge--before-change-end-pos + length + change-text + (lsp-bridge--position) + (acm-char-before) + (buffer-name) + (acm-get-input-prefix)) + + ;; Send inlay hint request. + (lsp-bridge-try-send-inlay-hint-request)) + + ;; Complete other non-LSP backends. + (lsp-bridge-complete-other-backends) + + ;; Update search words backend. + (lsp-bridge-search-words-update + lsp-bridge--before-change-begin-pos + lsp-bridge--before-change-end-pos + change-text) + )))))) (defun lsp-bridge-try-send-inlay-hint-request () (when lsp-bridge-enable-inlay-hint From 928c17a6bebfa82603fe4ac2a090e0b08212ffd0 Mon Sep 17 00:00:00 2001 From: gotpl <631707329@qq.com> Date: Thu, 15 Aug 2024 23:51:09 +0800 Subject: [PATCH 2/2] fix clangd inlay hints. --- core/lspserver.py | 6 +++++- core/utils.py | 26 +++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/core/lspserver.py b/core/lspserver.py index b01973b02b..8055a7686a 100755 --- a/core/lspserver.py +++ b/core/lspserver.py @@ -690,7 +690,11 @@ def save_attribute_from_message(self, message): ("range_format_provider", ["result", "capabilities", "documentRangeFormattingProvider"]), ("signature_help_provider", ["result", "capabilities", "signatureHelpProvider"]), ("workspace_symbol_provider", ["result", "capabilities", "workspaceSymbolProvider"]), - ("inlay_hint_provider", ["result", "capabilities", "inlayHintProvider", "resolveProvider"]), + # ("inlay_hint_provider", ["result", "capabilities", "inlayHintProvider", "resolveProvider"]), + ("inlay_hint_provider", [ + ["result", "capabilities", "inlayHintProvider", "resolveProvider"], + ["result", "capabilities", "clangdInlayHintsProvider"] # 兼容clangd + ]), ("save_include_text", ["result", "capabilities", "textDocumentSync", "save", "includeText"]), ("text_document_sync", ["result", "capabilities", "textDocumentSync"]), ("semantic_tokens_provider", ["result", "capabilities", "semanticTokensProvider"])] diff --git a/core/utils.py b/core/utils.py index bdc3256cc4..17c146059d 100755 --- a/core/utils.py +++ b/core/utils.py @@ -519,13 +519,33 @@ def remove_duplicate_references(data): result.append(item) return result +# def get_nested_value(dct, keys): +# for key in keys: +# try: +# dct = dct[key] +# except (KeyError, TypeError): +# return None +# return dct + def get_nested_value(dct, keys): + ''' + keys: ["k1", "k2", ...]匹配一组, [["k1", "k2", ...], [], ...]匹配多组情况 + ''' + value = None for key in keys: try: - dct = dct[key] + if isinstance(key, list): + value = get_nested_value(dct, key) + if value: + break + else: + dct = dct[key] except (KeyError, TypeError): - return None - return dct + dct = None + break + + return value if value else dct + class MessageSender(Thread):