Closed SyrakuShaikh closed 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)))
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.
I got the same problem in Spacemacs, if c-c++-lsp-enable-semantic-highlight 'rainbow
.
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 defun
s, 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 defun
s 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.
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.
additional feedback: when I delete all the .elc files in ccls
, all OK.
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.
Likely fixed by 32766da55299a5e0efcf8efe3bf223fa0b5a9ff5
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" []))).
@yssource Give my recent change a try.
@acowley Thanks, it works for me. The error message look disappeared.
I update my emacs packages today, now the version info:
emacs
26.3lsp-mode
20200622.1854lsp-ui
20200617.544ccls
20200621.2049However, when I open a C++ project which worked perfectly before, I get into this error message:
and the rainbow highlight for symbols are gone:(
Any ideas? Thanks!