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

Activate extension when compile_flags.txt or buildServer.json is present #1240

Merged
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
5 changes: 5 additions & 0 deletions assets/test/cmake-compile-flags/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 2.4)

project(hello_world)

add_executable(app main.cpp)
8 changes: 8 additions & 0 deletions assets/test/cmake-compile-flags/compile_flags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk
-mmacosx-version-min=13.0
-o
CMakeFiles/app.dir/main.o
-c
main.cpp
7 changes: 7 additions & 0 deletions assets/test/cmake-compile-flags/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <iostream>

int main()
{
std::cout << "Hello World!\n";
return 0;
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"onLanguage:swift",
"workspaceContains:Package.swift",
"workspaceContains:compile_commands.json",
"workspaceContains:compile_flags.txt",
"workspaceContains:buildServer.json",
"onDebugResolve:swift-lldb"
],
"main": "./dist/src/extension.js",
Expand Down
8 changes: 5 additions & 3 deletions src/WorkspaceContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export class WorkspaceContext implements vscode.Disposable {
}

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

/**
* Return if folder is considered a valid root folder ie does it contain a SwiftPM
* Package.swift or a CMake compile_commands.json
* Package.swift or a CMake compile_commands.json, compile_flags.txt, or a BSP buildServer.json.
*/
async isValidWorkspaceFolder(folder: string): Promise<boolean> {
return (
((await pathExists(folder, "Package.swift")) &&
!configuration.disableSwiftPMIntegration) ||
(await pathExists(folder, "compile_commands.json"))
(await pathExists(folder, "compile_commands.json")) ||
(await pathExists(folder, "compile_flags.txt")) ||
(await pathExists(folder, "buildServer.json"))
);
}

Expand Down
27 changes: 27 additions & 0 deletions test/integration-tests/ExtensionActivation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
deactivateExtension,
} from "./utilities/testutilities";
import { WorkspaceContext } from "../../src/WorkspaceContext";
import { testAssetUri } from "../fixtures";
import { assertContains } from "./testexplorer/utilities";

suite("Extension Activation/Deactivation Tests", () => {
suite("Extension Activation", () => {
Expand Down Expand Up @@ -97,4 +99,29 @@ suite("Extension Activation/Deactivation Tests", () => {
assert.notStrictEqual(workspaceContext, capturedWorkspaceContext);
});
});

suite("Activates for cmake projects", () => {
let workspaceContext: WorkspaceContext;

activateExtensionForTest({
async setup(ctx) {
workspaceContext = ctx;
},
testAssets: ["cmake", "cmake-compile-flags"],
});

test("compile_commands.json", async () => {
const lspWorkspaces = workspaceContext.languageClientManager.subFolderWorkspaces.map(
({ fsPath }) => fsPath
);
assertContains(lspWorkspaces, testAssetUri("cmake").fsPath);
});

test("compile_flags.txt", async () => {
const lspWorkspaces = workspaceContext.languageClientManager.subFolderWorkspaces.map(
({ fsPath }) => fsPath
);
assertContains(lspWorkspaces, testAssetUri("cmake-compile-flags").fsPath);
});
});
});
Loading