Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/c-cpp-pro-native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "c-cpp-pro-native"
version = "0.4.2"
version = "0.4.4"
edition = "2021"

[lib]
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 72 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "c-cpp-pro",
"displayName": "C/C++ Pro",
"description": "High-performance C/C++ language support, debugging, and tooling for Visual Studio Code",
"version": "0.4.2",
"version": "0.4.4",
"publisher": "FunToHard",
"icon": "media/icon.png",
"engines": {
Expand All @@ -26,6 +26,7 @@
"onLanguage:c",
"onLanguage:cpp",
"onLanguage:cuda-cpp",
"onLanguage:cmake",
"onCommand:c-cpp-pro.openSettings",
"onCommand:c-cpp-pro.restartServer",
"onCommand:c-cpp-pro.switchSourceHeader",
Expand Down Expand Up @@ -297,6 +298,24 @@
"command": "c-cpp-pro.flushTelemetry",
"title": "C/C++ Pro: Flush Telemetry Batch",
"category": "C/C++"
},
{
"command": "c-cpp-pro.buildProject",
"title": "C/C++ Pro: Build Project",
"icon": "$(tools)",
"category": "C/C++"
},
{
"command": "c-cpp-pro.buildAndRunProject",
"title": "C/C++ Pro: Build & Run Project",
"icon": "$(play)",
"category": "C/C++"
},
{
"command": "c-cpp-pro.buildAndDebugProject",
"title": "C/C++ Pro: Build & Debug Project",
"icon": "$(debug-alt)",
"category": "C/C++"
}
],
"menus": {
Expand All @@ -310,6 +329,21 @@
"command": "c-cpp-pro.debugFile",
"when": "editorLangId == cpp || editorLangId == c",
"group": "navigation@2"
},
{
"command": "c-cpp-pro.buildAndRunProject",
"when": "editorLangId == cmake || resourceFilename =~ /CMakeLists\\.txt$/ || resourceExtname == .cmake || resourceExtname == .sln || resourceExtname == .slnx || resourceExtname == .vcxproj",
"group": "navigation@1"
},
{
"command": "c-cpp-pro.buildProject",
"when": "editorLangId == cmake || resourceFilename =~ /CMakeLists\\.txt$/ || resourceExtname == .cmake || resourceExtname == .sln || resourceExtname == .slnx || resourceExtname == .vcxproj",
"group": "navigation@2"
},
{
"command": "c-cpp-pro.buildAndDebugProject",
"when": "editorLangId == cmake || resourceFilename =~ /CMakeLists\\.txt$/ || resourceExtname == .cmake || resourceExtname == .sln || resourceExtname == .slnx || resourceExtname == .vcxproj",
"group": "navigation@3"
}
],
"editor/context": [
Expand Down Expand Up @@ -670,6 +704,43 @@
}
}
],
"languages": [
{
"id": "cmake",
"extensions": [
".cmake"
],
"filenames": [
"CMakeLists.txt",
"CMakelists.txt"
],
"aliases": [
"CMake"
],
"configuration": "./syntaxes/cmake-language-configuration.json"
},
{
"id": "cmake-cache",
"filenames": [
"CMakeCache.txt"
],
"aliases": [
"CMake Cache"
]
}
],
"grammars": [
{
"language": "cmake",
"scopeName": "source.cmake",
"path": "./syntaxes/CMake.tmLanguage.json"
},
{
"language": "cmake-cache",
"scopeName": "source.cmakecache",
"path": "./syntaxes/CMakeCache.tmLanguage.json"
}
],
"languageModelTools": [
{
"name": "c-cpp-pro",
Expand Down
41 changes: 35 additions & 6 deletions src/bridge/cmake-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ export async function writeCompilationDatabase(filePath: string, content: string
return filePath;
}

function isCompilationDatabase(filePath: string): boolean {
const norm = filePath.replace(/\\/g, '/').toLowerCase();
return (
norm.endsWith('/compile_commands.json') ||
norm.endsWith('/compile_flags.txt') ||
norm.endsWith('/.clangd')
);
}

function isCmakeConfiguration(filePath: string): boolean {
const norm = filePath.replace(/\\/g, '/').toLowerCase();
return (
norm.endsWith('/cmakelists.txt') ||
norm.endsWith('.cmake') ||
norm.endsWith('/cmakepresets.json') ||
norm.endsWith('/cmakeuserpresets.json') ||
norm.includes('/.cmake/api/v1/reply/')
);
}

export class CMakeWatcher implements vscode.Disposable {
private watcher: vscode.FileSystemWatcher | null = null;
private disposables: vscode.Disposable[] = [];
Expand Down Expand Up @@ -42,16 +62,25 @@ export class CMakeWatcher implements vscode.Disposable {

this.disposables.push(
this.watcher.onDidChange(async (uri) => {
if (this.onCmakeUpdate) await this.onCmakeUpdate(uri);
this.debouncedReload(uri);
if (isCmakeConfiguration(uri.fsPath)) {
if (this.onCmakeUpdate) await this.onCmakeUpdate(uri);
} else if (isCompilationDatabase(uri.fsPath)) {
this.debouncedReload(uri);
}
}),
this.watcher.onDidCreate(async (uri) => {
if (this.onCmakeUpdate) await this.onCmakeUpdate(uri);
this.debouncedReload(uri);
if (isCmakeConfiguration(uri.fsPath)) {
if (this.onCmakeUpdate) await this.onCmakeUpdate(uri);
} else if (isCompilationDatabase(uri.fsPath)) {
this.debouncedReload(uri);
}
}),
this.watcher.onDidDelete(async (uri) => {
if (this.onCmakeUpdate) await this.onCmakeUpdate(uri);
this.debouncedReload({ fsPath: '' } as any);
if (isCmakeConfiguration(uri.fsPath)) {
if (this.onCmakeUpdate) await this.onCmakeUpdate(uri);
} else if (isCompilationDatabase(uri.fsPath)) {
this.debouncedReload({ fsPath: '' } as any);
}
})
);
}
Expand Down
Loading
Loading