sublimelsp / LSP-clangd

C/C++ support for Sublime's LSP plugin provided through clangd.
MIT License
42 stars 1 forks source link

Set compile_commands.json path on a per project basis #12

Closed LDAP closed 1 year ago

LDAP commented 1 year ago

Hey @LDAP, thanks so much for looking into it! I can confirm that I can properly configure the system binary to use clangd-12. However I still have another issue that might be relevant to this PR.

My compile_commands.json file is not at the root of the project, so I have to pass --compile-commands-dir arg to clangd-12. Since this path changes for each project, I have to have this setting in the .sublime-project file. I saw you mentioned initializationOptions can now be overwritten per project, so I tried multiple things without success:

It seems like the plugin doesn't read any settings from the project file for initializationOptions. The JSON auto-completion also doesn't bring any options for any of the keys in initializationOptions (but works when used in the LSP-clangd setting file).

Originally posted by @berteauxjb in https://github.com/sublimelsp/LSP-clangd/pull/11#issuecomment-1473525245

LDAP commented 1 year ago

@berteauxjb lets make a new issue for this.

Can you post your sublime-project file please?

Btw, you can also always run the LSP: Troubleshoot Server command to see which options are passed to the language server.

berteauxjb commented 1 year ago

Here's the relevant parts in my project file:

{
  "tab_size": 2,
  "folders":
  [
    {
      "path": "/home/jb/github/project",
      "folder_exclude_patterns":
      [
        "build*",
      ],
    }
  ],

  "settings":
  {
    "LSP": {
      "LSP-clangd": {
        "initializationOptions": {
          "clangd.compile-commands-dir": "/home/jb/github/project/build/project-relwithdebinfo/"
        },
        "enabled": true,
      },
    },
  },
}

Thanks for the tip, I never realized that this was an option, much easier than reading the log panel :) BTW I noticed that I have two clangd servers showing up in the troubleshoot panel: LSP-clangd and clangd. One has the compile command arg but nothing else (not even a valid command), the other has everything else but not the compile command arg. Here's the server configuration I get for both of them:

Troubleshooting: clangd

Version

==================================================================================================

Troubleshooting: LSP-clangd

Version

 - selector
 - priority_selector
 - init_options
```json
{
  "clangd": {
    "compile-commands-dir": "/home/jb/github/project/build/project-relwithdebinfo/"
  }
}
LDAP commented 1 year ago

There is your issue: They key in the sublime-project should be clangd not LSP-clangd :)

(This is to keep this package backward compatible for users that used the default configuration that shipped with the LSP plugin a while back.)

The intended way to set the compilation database path is via clangd.compile-commands-dir, you just need to change the key.

berteauxjb commented 1 year ago

Haha, yes now it works. Sorry about that! I got confused with LSP-pyright that uses the same key as its name. Thanks a lot for your help :)

LDAP commented 1 year ago

I added a section to the README