emacs-lsp / emacs-ccls

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

.ccls-root ignored #84

Closed pmatos closed 3 years ago

pmatos commented 4 years ago

The file .ccls-root is being ignored. I am working on WebKit where the directory for source files is WebKit/Source. So I touched .ccls-root at WebKit/Source and yet lsp is still trying to index WebKit (which is where .git is), warning me that there are 337903 files in the folder and that it might slow down emacs watching the repo.

Relevant .emacs configuration looks like:

(use-package projectile
  :ensure helm-projectile
  :init (projectile-global-mode)
  :config
  (setq projectile-enable-caching t
    projectile-completion-system 'helm)
  (helm-projectile-on))

(use-package lsp-mode :commands lsp)
(use-package lsp-ui :commands lsp-ui-mode)
(use-package company-lsp :commands company-lsp)

(use-package ccls
  :hook ((c-mode c++-mode objc-mode cuda-mode) . 
     (lambda () (require 'ccls) (lsp)))
  :custom
  (ccls-executable "/usr/bin/ccls"))
pmatos commented 4 years ago

Here's the ccls stderr buffer:

11:09:40 ccls           initialize.cc:262 I initialize in directory /home/pmatos/dev/WebKit with uri file:///home/pmatos/dev/WebKit
11:09:40 ccls           initialize.cc:285 I initializationOptions: {"compilationDatabaseCommand":"","compilationDatabaseDirectory":"","cache":{"directory":".ccls-cache","format":"binary","hierarchicalPath":false,"retainInMemory":2},"capabilities":{"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"}","moreTriggerCharacter":[]},"foldingRangeProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":true}}},"clang":{"excludeArgs":[],"extraArgs":[],"pathMappings":[],"resourceDir":""},"client":{"diagnosticsRelatedInformation":true,"hierarchicalDocumentSymbolSupport":true,"linkSupport":true,"snippetSupport":true},"codeLens":{"localVariables":true},"completion":{"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,"initialNoLinkage":false,"initialBlacklist":[],"initialWhitelist":[],"maxInitializerLines":5,"multiVersion":0,"multiVersionBlacklist":[],"multiVersionWhitelist":[],"name":{"suppressUnwrittenScope":false},"onChange":false,"parametersInDeclarations":true,"threads":0,"trackDependency":2,"whitelist":[]},"request":{"timeout":5000},"session":{"maxNum":10},"workspaceSymbol":{"caseSensitivity":1,"maxNum":1000,"sort":true},"xref":{"maxNum":2000}}
11:09:40 ccls           initialize.cc:314 I use -resource-dir=/usr/lib/clang/10.0.0
11:09:40 ccls           initialize.cc:347 I workspace folder: /home/pmatos/dev/WebKit/
11:09:40 ccls           initialize.cc:372 I start 16 indexers
11:09:40 ccls           initialize.cc:380 I dispatch initial index requests
11:09:40 ccls             pipeline.cc:474 I loaded project. Refresh semantic highlight for all working file.
11:09:40 preamble     sema_manager.cc:734 I create session for /home/pmatos/dev/WebKit/Source/JavaScriptCore/jit/JITCall32_64.cpp
11:09:40 indexer1         pipeline.cc:290 I load cache for /home/pmatos/dev/WebKit/Source/JavaScriptCore/jit/JITCall32_64.cpp

and lsp:

Command "/usr/bin/ccls" is present on the path.
Command "clangd" is present on the path.
Command "/usr/bin/ccls" is present on the path.
Command "clangd" is present on the path.
Found the following clients for /home/pmatos/dev/WebKit/Source/JavaScriptCore/jit/JITCall32_64.cpp: (server-id ccls, priority 0), (server-id clangd, priority -1)
The following clients were selected based on priority: (server-id ccls, priority 0)
Creating watch for /home/pmatos/dev/WebKit
MaskRay commented 4 years ago

ccls.el sets an advice on lsp--suggest-project-root:

(defun ccls--suggest-project-root ()
  (and (memq major-mode '(c-mode c++-mode cuda-mode objc-mode))
       (when-let (dir (cl-some  #'(lambda (file) (locate-dominating-file default-directory file))
                                ccls-root-files))
         (expand-file-name dir))))

Can you add a (message ...) to ccls--suggest-project-root and check why the project root is wrong?

xiang578 commented 4 years ago

@MaskRay hello, i also meet same problem.

I make .ccls-root on xxx/src, when i open the xxx/src/xxx.cpp file:

LSP :: Guessed project root is ~/Documents/work/xxx

but when i run (ccls--suggest-project-root) (https://github.com/MaskRay/ccls/issues/232):

~/Documents/work/xxx/src
xiang578 commented 4 years ago

(ccls--suggest-project-root)

same as https://github.com/MaskRay/ccls/issues/679 ? I also use mac

MaskRay commented 3 years ago

@MaskRay hello, i also meet same problem.

I make .ccls-root on xxx/src, when i open the xxx/src/xxx.cpp file:

LSP :: Guessed project root is ~/Documents/work/xxx

but when i run (ccls--suggest-project-root) (MaskRay/ccls#232):

~/Documents/work/xxx/src

Perhaps you need to debug the function with edebug. ccls--suggest-project-root works perfectly fine. It may be that lsp--suggest-project-root is also hooked by other configurations.

https://github.com/MaskRay/ccls/issues/679 looks like another user configuration problem.

braoult commented 2 years ago

Probably too late for this issue, but as I had the same issue and found a workaround, this may help some others in the same situation.

My working tree is the following :

xxx/
     .git
     bash/
        a.sh
     c/
       .ccls-root
       .ccls
       .projectile
       compile_commands.json
       Makefile
       foo.c
       include/
           foo.h

I expected that the ccls root directory (when opening xxx/c/foo.c) would be xxx/c, but it was in fact xxx/, as shown in *ccls::stderr* :

18:51:41 ccls           initialize.cc:274 I initialize in directory /dir/tree/xxx with uri file:///dir/tree/xxx

I ended up adding a .dir-locals.el in xxx/c sub-directory with :

((c-mode . ((lsp-auto-guess-root . t))))

This solved the issue, and now the correct root is used :

18:01:22 ccls           initialize.cc:274 I initialize in directory /dir/tree/xxx/c with uri file:///dir/tree/xxx/c

In fact, I wonder if I should not set the lsp-auto-guess-root variable globally in my init.el. I believe it could be OK for me, despite the frightening lsp-mode warning, and the fact that I am surely not familiar with lsp-mode internals :

Automatically guess the project root using projectile/project. Do not use this setting unless you are familiar with lsp-mode internals and you are sure that all of your projects are following projectile/project.el conventions.

fredsco commented 1 year ago

I'm also having the same issue, no matter if I add .ccls-root or .ccls in /dir if i go to /dir/app a .ccls-cache is being created there and treated as root..

Did anyone find a fix for this?