emacs-lsp / emacs-ccls

Emacs client for ccls, a C/C++ language server
200 stars 29 forks source link

(void-function lsp:ccls-semantic-highlight-symbol-ranges). #91

Closed SyrakuShaikh closed 4 years ago

SyrakuShaikh commented 4 years ago

I update my emacs packages today, now the version info:

However, when I open a C++ project which worked perfectly before, I get into this error message:

(void-function lsp:ccls-semantic-highlight-symbol-ranges).

and the rainbow highlight for symbols are gone:(

Any ideas? Thanks!

MaskRay commented 4 years ago

lsp-mode.el requires lsp-protocol. ccls-common.el requires lsp-mode.

This block of code should define lsp:ccls-semantic-highlight-symbol-ranges for you:

(eval-when-compile
  (lsp-interface
   (CclsLR (:L :R) nil)
   (CclsSemanticHighlightSymbol (:id :parentKind :kind :storage :ranges) nil)
   (CclsSemanticHighlight (:uri :symbols) nil)
   (CclsSkippedRanges (:uri :skippedRanges) nil)))
SyrakuShaikh commented 4 years ago

I noticed the block of codes you posted, it's in the ccls-semantic-highlight.el. The strange thing is that the only way I can do to make all the highlights work is copy-and-paste the block of codes to my config file under use-package function, like the following:

(defun myusername/post-init-ccls ()
  "blabla"
  (use-package ccls
    :defer t
    :config
    (progn
      (eval-when-compile
        (lsp-interface
         (CclsLR (:L :R) nil)
         (CclsSemanticHighlightSymbol (:id :parentKind :kind :storage :ranges) nil)
         (CclsSemanticHighlight (:uri :symbols) nil)
         (CclsSkippedRanges (:uri :skippedRanges) nil)))
      (... other configs)
    )))

Maybe it's due to Spacemacs? I'm not sure. Anyway, all things work now! Thanks.

yssource commented 4 years ago

I got the same problem in Spacemacs, if c-c++-lsp-enable-semantic-highlight 'rainbow.

OceanS2000 commented 4 years ago

Same problem here with Emacs 28.0.50.

@MaskRay After some debugging, it looks like eval-when-compile is causing the problem.

The macro lsp-interface expands to server defuns, most of them are used only by macros provided by dash.el. However in the ccls-semantic-highlight.el file there is an exception: lsp:ccls-semantic-highlight-symbol-ranges called directly in ccls--publish-semantic-highlight.

As lsp-interface is eval-when-compile, the defuns generated will not be seen when the byte-compiled package is loaded. As nearly all the function it generated is only used by macro expanding, everything will work fine except ccls--publish-semantic-highlight because it ended up with calling a function never defined in load time.

The following minimal config can reproduce the problem on Emacs 28.0.50:

;; All the packages are byte-compiled
(require 'lsp-mode)
(require 'ccls)
(setq ccls-executable "/Users/sao/.local/bin/ccls")
(setq ccls-sem-highlight-method 'font-lock)
;; seems required on macOS
(setq ccls-initialization-options
    '(:clang (:extraArgs
["-isysroot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/"
 "-I/usr/local/include"
 "-isystem/opt/local/libexec/llvm-9.0/include/c++/v1"
 "-isystem/opt/local/libexec/llvm-9.0/lib/clang/9.0.1/include"]
              :resourceDir "/opt/local/libexec/llvm-9.0/lib/clang/9.0.1")))

(with-current-buffer (find-file "~/Code/Ctest/cpptest.cpp")
  (lsp))

As for fixing the issue, I suggest move this particular lsp-interface out of eval-when-compile.

diff --git a/ccls-semantic-highlight.el b/ccls-semantic-highlight.el
index 18655cb..4abef9b 100644
--- a/ccls-semantic-highlight.el
+++ b/ccls-semantic-highlight.el
@@ -177,9 +177,10 @@ If nil, disable semantic highlight."
 (eval-when-compile
   (lsp-interface
    (CclsLR (:L :R) nil)
-   (CclsSemanticHighlightSymbol (:id :parentKind :kind :storage :ranges) nil)
    (CclsSemanticHighlight (:uri :symbols) nil)
    (CclsSkippedRanges (:uri :skippedRanges) nil)))
+(lsp-interface
+ (CclsSemanticHighlightSymbol (:id :parentKind :kind :storage :ranges) nil))

 (defun ccls--clear-sem-highlights ()
   "."

Note: Byte-compiling the package is important for reproducing the issue. If the elisp file is directly loaded instead of compiled, eval-when-compile will behave as progn and every defun can be seen normally.

SyrakuShaikh commented 4 years ago

After updating ccls today, I encountered a new error,

Error processing message 
(wrong-type-argument listp 
  #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data 
      ("id" 123 "parentKind" 1 "kind" 5 "storage" 0 "ranges" 
         [#s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data
            ("L" 3070 "R" 3077))] "lsRanges" []))).

the numbers 123, 3070, 3077 varies.

I think it's still relevant to this issue, so I comment here.

SyrakuShaikh commented 4 years ago

additional feedback: when I delete all the .elc files in ccls, all OK.

acowley commented 4 years ago

I am seeing the same Error processing message (wrong-type-argument listp #s(hash-table ... error with the dec9224 revision with no stale .elc files.

MaskRay commented 4 years ago

Likely fixed by 32766da55299a5e0efcf8efe3bf223fa0b5a9ff5

yssource commented 4 years ago

Error processing message (wrong-type-argument listp #s(hash-table size 6 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("id" 14647 "parentKind" 5 "kind" 6 "storage" 0 "ranges" [#s(hash-table size 2 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("L" 2602 "R" 2611))] "lsRanges" []))).

acowley commented 4 years ago

@yssource Give my recent change a try.

yssource commented 4 years ago

@acowley Thanks, it works for me. The error message look disappeared.