Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set path to compileCommands automatically. #247

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,6 @@ Please see [xmake-github](https://github.com/xmake-io/xmake) and [website](http:

## IntelliSense

xmake-vscode will generate `.vscode/compile_commands.json` file, so you need only add it to `.vscode/c_cpp_properties.json` to enable IntelliSense.

for example (`.vscode/c_cpp_properties.json`):

```json
{
"configurations": [
{
"compileCommands": ".vscode/compile_commands.json"
}
],
"version": 4
}
```

### How can I generate c_cpp_properties.json?

These configuration settings are stored in your project's c_cpp_properties.json file. To edit this file, in VS Code, select C/C++: Edit Configurations (UI) from the Command Palette (⇧⌘P):

Please see [IntelliSense for cross-compiling](https://code.visualstudio.com/docs/cpp/configure-intellisense-crosscompilation)

![](https://code.visualstudio.com/assets/docs/cpp/cpp/command-palette.png)

## Debugging
Expand Down
13 changes: 13 additions & 0 deletions src/xmake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,19 @@ export class XMake implements vscode.Disposable {
this._projectFileSystemWatcher.onDidCreate(this.onProjectFileUpdated.bind(this));
this._projectFileSystemWatcher.onDidChange(this.onProjectFileUpdated.bind(this));

const compileCommandsFile = path.join(config.compileCommandsDirectory, "compile_commands.json");
const compileCommandsWatcher = vscode.workspace.createFileSystemWatcher(compileCommandsFile);
compileCommandsWatcher.onDidCreate(() => {
const config = vscode.workspace.getConfiguration('C_Cpp');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user does not have cpptools installed, do we always get a valid config instead of undefined?

config.update("default.compileCommands", compileCommandsFile, vscode.ConfigurationTarget.Workspace);
});
this._context.subscriptions.push(compileCommandsWatcher);

if (fs.existsSync(compileCommandsFile)) {
const config = vscode.workspace.getConfiguration('C_Cpp');
config.update("default.compileCommands", compileCommandsFile, vscode.ConfigurationTarget.Workspace);
}

this._context.subscriptions.push(
vscode.workspace.onDidCreateFiles((e: vscode.FileCreateEvent) => {
this._xmakeExplorer.refresh();
Expand Down