neoclide / coc.nvim

Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
Other
24.41k stars 953 forks source link

Server ccls failed to start: invalid params of initialize: array #247

Closed quebin31 closed 5 years ago

quebin31 commented 5 years ago

Result from CocInfo

## versions

vim version: NVIM v0.3.1
node version: v8.9.0
coc.nvim version: 0.0.38
term: xterm-256color
platform: linux

## Error messages

## Output channel: languageserver.ccls

## Output channel: languageserver.ccls-359ca090-fb76-11e8-aac2-83f76a79a3f3
[Trace - 00:49:35] Sending request 'shutdown - (1)'.
[Trace - 00:49:35] Received response 'shutdown - (1)' in 1ms.
No result returned.

[Trace - 00:49:35] Sending notification 'exit'.
No parameters provided.

Describe the bug Opening a C++ file located in $HOME with the configured server with ccls results in initialization fail, opening a C++ file located somewhere else doesn't result in fail. Note: An empty vertical split is opened when the error ocurs, and :CocInfo shows no error messages

To Reproduce

cd $HOME
nvim test.cpp

Screenshot screenshot

chemzqm commented 5 years ago

You can't use ccls in home directory, there could be too many files to index.

quebin31 commented 5 years ago

You can't use ccls in home directory, there could be too many files to index.

That's interesting. I thought that for a moment, but I remember that I used to open files inside home directory with cquery + LanguageClient-neovim. If I combine cquery + coc.nvim, will it fail too?

chemzqm commented 5 years ago

You can't use ccls in home directory, there could be too many files to index.

That's interesting. I thought that for a moment, but I remember that I used to open files inside home directory with cquery + LanguageClient-neovim. If I combine cquery + coc.nvim, will it fail too?

I don't know, ccls could work for me in home directory, consider paste full output from ccls by add "trace.server": "verbose" to your configuration https://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel

MaskRay commented 5 years ago

It seems for some initialization option, the server expects an array but you passed it something different. ccls HEAD will report a better error message if you have a type error, e.g. "initializationOptions": { "cacheDirectory": 3 }

{"jsonrpc":"2.0","id":0,"error":{"code":-32602,"message":"invalid params of initialize: /initializationOptions/cacheDirectory is expected to be string"}}

Don't start ccls/cquery in the home directory, they will recursively list files and index all of them, you may get unwanted ~/.ccls-cache/**

quebin31 commented 5 years ago

This is coc-settings.json:

{
    "languageserver": {
        "ccls": {
            "command": "ccls",
            "trace.server": "verbose",
            "initializationOptions": {
                "cacheDirectory": "/tmp/ccls"
            },
            "filetypes": ["c", "cpp", "objc", "objcpp"]
        }
    }
}

As @MaskRay, the expected type should be string for cacheDirectory, with this config I can't still open ccls in home directory (aside from having an unwanted ~/.ccls-cache/**)

oblitum commented 5 years ago

You should set rootPatterns for ccls.

oblitum commented 5 years ago

I think wiki should be updated with that :)

oblitum commented 5 years ago

@lans98 I've updated the wiki https://github.com/neoclide/coc.nvim/wiki/Language-servers#ccobjective-c, you need at least one of those in the tree for root resolve.

oblitum commented 5 years ago

Documentation for project setup with ccls: https://github.com/MaskRay/ccls/wiki/Getting-started#project-setup.

If I recall correctly, in the past, I also got problems when a file/directory for root resolve wasn't present, one of the side-effects being the creation of <cwd>/.ccls-cache/**, but ccls states to give support even without any root file/dir. I simply use them all the time now.

MaskRay commented 5 years ago

FWIW, in Emacs lsp-mode + emacs-ccls, the approach I use is: there should be an explicit project root indicator (e.g. .git .ccls-root). Unless you did git init in your HOME, the language client will not start ccls at ~. Since .git is scanned bottom-up, (projectile-project-root) may think files in the subproject belong to the child workspace, which is not desired. In that case I touch .ccls-root. The reason I don't use .ccls is because .ccls can be hierarchical and is not a reliable bottom-up scanner.

chemzqm commented 5 years ago

Now "ignoredRootPaths": ["~"] can be used to ignore home as rootPath for specified language server, this could help to prevent server start in specified roots.

AhmadFudl commented 3 years ago

I'm getting the same problem even though I'm using the default setups provided in the docs

{
"languageserver": {
  "ccls": {
    "command": "ccls",
    "filetypes": ["c", "cc", "cpp", "c++", "objc", "objcpp"],
    "rootPatterns": [".ccls", "compile_commands.json", ".git/", ".hg/"],
    "initializationOptions": {
        "cache": {
          "directory": "/tmp/ccls"
        }
      }
  }
}
}
oblitum commented 3 years ago

@AhmadFudl clangd, or coc-clangd is recommended.

vvhitedog commented 1 month ago

This seems like a bug that might be related, but you see the error

Error: invalid params of initialize: expected array for /workspaceFolders

If the root directory is a name like "3DGs.cpp" which is the name of the project in my case.

It's an absurd corner-case (I've never known many projects to call themselves something like A.cpp, and hence result in directory files such as A.cpp as the root dir.)

Not sure if its worth fixing, but if anyone comes across this issue in the future, its a simple fix: rename the root dir.

Given that ccls is sensitive to the name of the root directory, I imagine there are other cases possible that result in similar errors, so the fix would be:

Rename your root dir to something reasonable (not dots, no file extensions in the name of the root dir.)