Skip to content

Commit c047d4e

Browse files
authored
Activate extension when compile_flags.txt or buildServer.json is present (#1240)
SourceKit-LSP can handle projects configured with the paired down clang `compile_flags.txt` configuration file, as well as projects configured with the Build Server Protocol's `buildServer.json`. Activate the extension if the folder added to the workspace contains either of these files in the root. Issue: #1087
1 parent 4fc8f88 commit c047d4e

File tree

6 files changed

+54
-3
lines changed

6 files changed

+54
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cmake_minimum_required(VERSION 2.4)
2+
3+
project(hello_world)
4+
5+
add_executable(app main.cpp)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
2+
-isysroot
3+
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk
4+
-mmacosx-version-min=13.0
5+
-o
6+
CMakeFiles/app.dir/main.o
7+
-c
8+
main.cpp
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <iostream>
2+
3+
int main()
4+
{
5+
std::cout << "Hello World!\n";
6+
return 0;
7+
}

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"onLanguage:swift",
2727
"workspaceContains:Package.swift",
2828
"workspaceContains:compile_commands.json",
29+
"workspaceContains:compile_flags.txt",
30+
"workspaceContains:buildServer.json",
2931
"onDebugResolve:swift-lldb"
3032
],
3133
"main": "./dist/src/extension.js",

src/WorkspaceContext.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ export class WorkspaceContext implements vscode.Disposable {
349349
}
350350

351351
async searchForPackages(folder: vscode.Uri, workspaceFolder: vscode.WorkspaceFolder) {
352-
// add folder if Package.swift/compile_commands.json exists
352+
// add folder if Package.swift/compile_commands.json/compile_flags.txt/buildServer.json exists
353353
if (await this.isValidWorkspaceFolder(folder.fsPath)) {
354354
await this.addPackageFolder(folder, workspaceFolder);
355355
return;
@@ -614,13 +614,15 @@ export class WorkspaceContext implements vscode.Disposable {
614614

615615
/**
616616
* Return if folder is considered a valid root folder ie does it contain a SwiftPM
617-
* Package.swift or a CMake compile_commands.json
617+
* Package.swift or a CMake compile_commands.json, compile_flags.txt, or a BSP buildServer.json.
618618
*/
619619
async isValidWorkspaceFolder(folder: string): Promise<boolean> {
620620
return (
621621
((await pathExists(folder, "Package.swift")) &&
622622
!configuration.disableSwiftPMIntegration) ||
623-
(await pathExists(folder, "compile_commands.json"))
623+
(await pathExists(folder, "compile_commands.json")) ||
624+
(await pathExists(folder, "compile_flags.txt")) ||
625+
(await pathExists(folder, "buildServer.json"))
624626
);
625627
}
626628

test/integration-tests/ExtensionActivation.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import {
2222
deactivateExtension,
2323
} from "./utilities/testutilities";
2424
import { WorkspaceContext } from "../../src/WorkspaceContext";
25+
import { testAssetUri } from "../fixtures";
26+
import { assertContains } from "./testexplorer/utilities";
2527

2628
suite("Extension Activation/Deactivation Tests", () => {
2729
suite("Extension Activation", () => {
@@ -97,4 +99,29 @@ suite("Extension Activation/Deactivation Tests", () => {
9799
assert.notStrictEqual(workspaceContext, capturedWorkspaceContext);
98100
});
99101
});
102+
103+
suite("Activates for cmake projects", () => {
104+
let workspaceContext: WorkspaceContext;
105+
106+
activateExtensionForTest({
107+
async setup(ctx) {
108+
workspaceContext = ctx;
109+
},
110+
testAssets: ["cmake", "cmake-compile-flags"],
111+
});
112+
113+
test("compile_commands.json", async () => {
114+
const lspWorkspaces = workspaceContext.languageClientManager.subFolderWorkspaces.map(
115+
({ fsPath }) => fsPath
116+
);
117+
assertContains(lspWorkspaces, testAssetUri("cmake").fsPath);
118+
});
119+
120+
test("compile_flags.txt", async () => {
121+
const lspWorkspaces = workspaceContext.languageClientManager.subFolderWorkspaces.map(
122+
({ fsPath }) => fsPath
123+
);
124+
assertContains(lspWorkspaces, testAssetUri("cmake-compile-flags").fsPath);
125+
});
126+
});
100127
});

0 commit comments

Comments
 (0)