emacs-lsp/emacs-ccls

Wrong project root when more than one ccls server running

eullerborges opened this issue · 3 comments

I'm using ccls on a big project. It indexes everything perfectly despite the thousands of files (kudos for the fantastic work).

Everything works properly on spacemacs, but whenever I open another perspective with a different copy of the same project (and its own properly generated compilation database), a new ccls server is spawned at a different port, but the path to the project root is incorrect. Spacemacs then hangs. The ccls::stderr buffer shows:

13:49:29 ccls           initialize.cc:272 I initialize in directory /home/euller with uri file:///home/euller/
13:49:29 ccls           initialize.cc:295 I initializationOptions: {"compilationDatabaseCommand":"","compilationDatabaseDirectory":"","cache":{"directory":"/tmp/euller-c++-lsp-cache","format":"binary","hierarchicalPath":false,"retainInM\
emory":2},"capabilities":{"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"}","moreTriggerCharacter":[]},"foldingRangeProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":true}}},"clang":{"e\
xcludeArgs":[],"extraArgs":[],"pathMappings":[],"resourceDir":""},"client":{"diagnosticsRelatedInformation":true,"hierarchicalDocumentSymbolSupport":true,"linkSupport":true,"snippetSupport":true},"codeLens":{"localVariables":true},"comp\
letion":{"caseSensitivity":2,"detailedLabel":true,"dropOldRequests":true,"duplicateOptional":true,"filterAndSort":true,"include":{"blacklist":[],"maxPathSize":30,"suffixWhitelist":[".h",".hpp",".hh",".inc"],"whitelist":[]},"maxNum":100}\
,"diagnostics":{"blacklist":[],"onChange":1000,"onOpen":0,"onSave":0,"spellChecking":true,"whitelist":[]},"highlight":{"largeFileSize":2097152,"lsRanges":false,"blacklist":[],"whitelist":[]},"index":{"blacklist":[],"comments":2,"initial\
NoLinkage":false,"initialBlacklist":[],"initialWhitelist":[],"maxInitializerLines":5,"multiVersion":0,"multiVersionBlacklist":[],"multiVersionWhitelist":[],"name":{"suppressUnwrittenScope":false},"onChange":false,"parametersInDeclaratio\
ns":true,"threads":0,"trackDependency":2,"whitelist":[]},"request":{"timeout":5000},"session":{"maxNum":10},"workspaceSymbol":{"caseSensitivity":1,"maxNum":1000,"sort":true},"xref":{"maxNum":2000}}
13:49:29 ccls           initialize.cc:324 I use -resource-dir=/home/euller/apps/install/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/8.0.0
13:49:29 ccls           initialize.cc:357 I workspace folder: /home/euller/
13:49:29 ccls           initialize.cc:382 I start 56 indexers
13:49:29 ccls           initialize.cc:390 I dispatch initial index requests
13:49:29 ccls             pipeline.cc:483 I loaded project. Refresh semantic highlight for all working file.

Note how it initialized on my home directory instead of the proper project path. This happens both on the first startup and on subsequent calls to lsp-workspace-restart.

Thanks.

I think this is likely a spacemacs or configuration problem. lsp-mode or emacs-ccls does not have such behavior. A newly opened buffer in the same project should share the same server.

but whenever I open another perspective with a different copy of the same project

If you have different source directories, then you should expect different servers to be spawned. You may not set up compile_commands.json correctly.

I couldn't figure out whether it was really a spacemacs issue. I'm sure that compile_commands.json is setup properly, and the new server is spawned, it just starts with the wrong directory.

I managed to work around this issue by setting the project directory with lsp-workspace-folders-add. After doing that and removing the previous wrongly-detected root everything worked properly.

I still think this is still an issue, nonetheless, if there's some way to determine who's the culprit behind setting the wrong directory, please let me know and I'll be glad to help.

I also had this problem until I tried your solution. I am using doom emacs.