neoclide/coc-json

Add schema for `compile_commands.json`

xulongwu4 opened this issue · 4 comments

clang-based tools rely on a compilation database to work correctly. Such a file is named compile_commands.json. When a valid compile_commands.json is opened in vim, coc-json reports a "fake" warning message

[json] [W] Incorrect type. Expected "object".

and highlights the whole compilation database. This can be quite annoying as a compilation database can be quite large, and this lint highlight causes vim to freeze up a bit when closing the file.

This issue is brought up in #9 but closed without actually being fixed. One can see that the current catalog.json file still does not contain the schema for compilation database, which was added in the schemastore in SchemaStore/schemastore#934.

EDIT:
I added the following schema to my coc-settings.json to add support for compile_commands.json:

"json.schemas": [
     {
       "fileMatch": ["compile_commands.json"],
       "url": "http://json.schemastore.org/compile-commands"
    }
],

However, I still get the same warning message. After some debugging, I found that this is because compile_commands.json matches two schemas simultaneously. One is http://json.schemastore.org/compile-commands (which matches to compile_commands.json), and the other one is http://json.schemastore.org/commands (which matches to commands.json). commands.json is supposed to contain json objects rather than arrays, hence the message [json] [W] Incorrect type. Expected "object".

I don't know if this is only an issue for coc-json, or it also applies to other editor plugins such as vscode-json-languageservice. However, this does seem like a bug for me.

Thanks for reporting, will update json language server.

Fixed.

I just upgraded to latest coc-json and I saw that compile_commands.json schema was added. However, the problem still exists, meaning the error message Incorrect type. Expected "object". still pops up. This is because any file with name compile_commands.json will match both compile_commands.json and commands.json schemas. One of them requires a top-level array while the other requires a top-level object, so it is impossible to make both of them happy.

This is fixed in 1.3.1. Thanks a lot.