Skip to content

Support for multi-root .code-workspace workspaces #1566

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

Open
wants to merge 5 commits into
base: main
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
33 changes: 33 additions & 0 deletions .vscode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,39 @@ module.exports = defineConfig({
reuseMachineInstall: !isCIBuild,
installExtensions,
},
{
label: "codeWorkspaceTests",
files: [
"dist/test/common.js",
"dist/test/integration-tests/extension.test.js",
"dist/test/integration-tests/WorkspaceContext.test.js",
"dist/test/integration-tests/tasks/**/*.test.js",
"dist/test/integration-tests/commands/build.test.js",
],
version: process.env["VSCODE_VERSION"] ?? "stable",
workspaceFolder: "./assets/test.code-workspace",
launchArgs,
extensionDevelopmentPath: vsixPath
? [`${__dirname}/.vscode-test/extensions/${publisher}.${name}-${version}`]
: undefined,
mocha: {
ui: "tdd",
color: true,
timeout,
forbidOnly: isCIBuild,
grep: isFastTestRun ? "@slow" : undefined,
invert: isFastTestRun,
slow: 10000,
reporter: path.join(__dirname, ".mocha-reporter.js"),
reporterOptions: {
jsonReporterOptions: {
output: path.join(__dirname, "test-results", "code-workspace-tests.json"),
},
},
},
reuseMachineInstall: !isCIBuild,
installExtensions,
},
{
label: "unitTests",
files: ["dist/test/common.js", "dist/test/unit-tests/**/*.test.js"],
Expand Down
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
},
"preLaunchTask": "compile-tests"
},
{
"name": "Code Workspace Tests",
"type": "extensionHost",
"request": "launch",
"testConfiguration": "${workspaceFolder}/.vscode-test.js",
"testConfigurationLabel": "codeWorkspaceTests",
"args": ["--profile=testing-debug"],
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"env": {
"VSCODE_DEBUG": "1"
},
"preLaunchTask": "compile-tests"
},
{
"name": "Unit Tests",
"type": "extensionHost",
Expand Down
106 changes: 106 additions & 0 deletions assets/test.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"folders": [
{
"name": "test",
"path": "./test"
},
{
"name": "defaultPackage",
"path": "./test/defaultPackage"
},
{
"name": "diagnostics",
"path": "./test/diagnostics"
},
{
"name": "command-plugin",
"path": "./test/command-plugin"
}
],
"settings": {
"swift.disableAutoResolve": true,
"swift.autoGenerateLaunchConfigurations": false,
"swift.debugger.debugAdapter": "lldb-dap",
"swift.debugger.setupCodeLLDB": "alwaysUpdateGlobal",
"swift.additionalTestArguments": [
"-Xswiftc",
"-DTEST_ARGUMENT_SET_VIA_TEST_BUILD_ARGUMENTS_SETTING"
],
"lldb.verboseLogging": true,
"swift.sourcekit-lsp.backgroundIndexing": "off"
},
"tasks": {
"version": "2.0.0",
"tasks": [
{
"type": "swift",
"args": [
"build",
"--build-tests",
"--verbose"
],
"cwd": "${workspaceFolder:defaultPackage}",
"group": {
"kind": "build",
"isDefault": true
},
"label": "swift: Build All (defaultPackage)",
"detail": "swift build --build-tests --verbose"
},
{
"type": "swift",
"args": [
"build",
"--show-bin-path"
],
"cwd": "${workspaceFolder:defaultPackage}",
"group": "build",
"label": "swift: Build All from tasks.json",
"detail": "swift build --show-bin-path"
},
{
"type": "swift-plugin",
"command": "command_plugin",
"args": [
"--foo"
],
"cwd": "${workspaceFolder:command-plugin}",
"disableSandbox": true,
"label": "swift: command-plugin from tasks.json",
"detail": "swift package command_plugin --foo"
}
]
},
"launch": {
"version": "0.2.0",
"configurations": [
{
"type": "swift",
"request": "launch",
"name": "Debug PackageExe (defaultPackage)",
"program": "${workspaceFolder:defaultPackage}/.build/debug/PackageExe",
"args": [],
"cwd": "${workspaceFolder:defaultPackage}",
"preLaunchTask": "swift: Build Debug PackageExe (defaultPackage)",
"disableASLR": false,
"initCommands": [
"settings set target.disable-aslr false"
]
},
{
"type": "swift",
"request": "launch",
"name": "Release PackageExe (defaultPackage)",
"program": "${workspaceFolder:defaultPackage}/.build/release/PackageExe",
"args": [],
"cwd": "${workspaceFolder:defaultPackage}",
"preLaunchTask": "swift: Build Release PackageExe (defaultPackage)",
"disableASLR": false,
"initCommands": [
"settings set target.disable-aslr false"
]
}
],
"compounds": []
}
}
19 changes: 19 additions & 0 deletions scripts/test_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
function Update-SwiftBuildAndPackageArguments {
param (
[string]$jsonFilePath = "./assets/test/.vscode/settings.json",
[string]$codeWorkspaceFilePath = "./assets/test.code-workspace",
[string]$windowsSdkVersion = "10.0.22000.0",
[string]$vcToolsVersion = "14.43.34808"
)
Expand All @@ -28,9 +29,17 @@ function Update-SwiftBuildAndPackageArguments {
exit 1
}

try {
$codeWorkspaceContent = Get-Content -Raw -Path $codeWorkspaceFilePath | ConvertFrom-Json
} catch {
Write-Host "Invalid JSON content in $codeWorkspaceFilePath"
exit 1
}

if ($jsonContent.PSObject.Properties['swift.buildArguments']) {
$jsonContent.PSObject.Properties.Remove('swift.buildArguments')
}


$jsonContent | Add-Member -MemberType NoteProperty -Name "swift.buildArguments" -Value @(
"-Xbuild-tools-swiftc", "-windows-sdk-root", "-Xbuild-tools-swiftc", $windowsSdkRoot,
Expand All @@ -54,10 +63,20 @@ function Update-SwiftBuildAndPackageArguments {
"-Xswiftc", "-visualc-tools-version", "-Xswiftc", $vcToolsVersion
)


$codeWorkspaceContent.PSObject.Properties.Remove('settings')
$codeWorkspaceContent | Add-Member -MemberType NoteProperty -Name "settings" -Value $jsonContent

$jsonContent | ConvertTo-Json -Depth 32 | Set-Content -Path $jsonFilePath


$codeWorkspaceContent | ConvertTo-Json -Depth 32 | Set-Content -Path $codeWorkspaceFilePath

Write-Host "Contents of ${jsonFilePath}:"
Get-Content -Path $jsonFilePath

Write-Host "Contents of ${codeWorkspaceFilePath}:"
Get-Content -Path $codeWorkspaceFilePath
}

$swiftVersionOutput = & swift --version
Expand Down
3 changes: 2 additions & 1 deletion src/TestExplorer/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { reduceTestItemChildren } from "./TestUtils";
import { CompositeCancellationToken } from "../utilities/cancellation";
// eslint-disable-next-line @typescript-eslint/no-require-imports
import stripAnsi = require("strip-ansi");
import { packageName } from "../utilities/tasks";

export enum TestLibrary {
xctest = "XCTest",
Expand Down Expand Up @@ -771,7 +772,7 @@ export class TestRunner {
{
cwd: this.folderContext.folder,
scope: this.folderContext.workspaceFolder,
prefix: this.folderContext.name,
packageName: packageName(this.folderContext),
presentationOptions: { reveal: vscode.TaskRevealKind.Never },
},
this.folderContext.toolchain,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { debugLaunchConfig, getLaunchConfiguration } from "../debugger/launch";
import { executeTaskWithUI } from "./utilities";
import { FolderContext } from "../FolderContext";
import { Target } from "../SwiftPackage";
import { packageName } from "../utilities/tasks";

/**
* Executes a {@link vscode.Task task} to run swift target.
Expand Down Expand Up @@ -56,7 +57,7 @@ export async function folderCleanBuild(folderContext: FolderContext) {
{
cwd: folderContext.folder,
scope: folderContext.workspaceFolder,
prefix: folderContext.name,
packageName: packageName(folderContext),
presentationOptions: { reveal: vscode.TaskRevealKind.Silent },
group: vscode.TaskGroup.Clean,
},
Expand Down
3 changes: 2 additions & 1 deletion src/commands/dependencies/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as vscode from "vscode";
import { createSwiftTask } from "../../tasks/SwiftTaskProvider";
import { FolderOperation, WorkspaceContext } from "../../WorkspaceContext";
import { executeTaskWithUI } from "../utilities";
import { packageName } from "../../utilities/tasks";

/**
* Setup package dependency to be edited
Expand All @@ -34,7 +35,7 @@ export async function editDependency(identifier: string, ctx: WorkspaceContext)
{
scope: currentFolder.workspaceFolder,
cwd: currentFolder.folder,
prefix: currentFolder.name,
packageName: packageName(currentFolder),
},
currentFolder.toolchain
);
Expand Down
3 changes: 2 additions & 1 deletion src/commands/dependencies/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { FolderContext } from "../../FolderContext";
import { createSwiftTask, SwiftTaskProvider } from "../../tasks/SwiftTaskProvider";
import { WorkspaceContext } from "../../WorkspaceContext";
import { executeTaskWithUI, updateAfterError } from "../utilities";
import { packageName } from "../../utilities/tasks";

/**
* Executes a {@link vscode.Task task} to resolve this package's dependencies.
Expand All @@ -43,7 +44,7 @@ export async function resolveFolderDependencies(
{
cwd: folderContext.folder,
scope: folderContext.workspaceFolder,
prefix: folderContext.name,
packageName: packageName(folderContext),
presentationOptions: { reveal: vscode.TaskRevealKind.Silent },
},
folderContext.toolchain
Expand Down
3 changes: 2 additions & 1 deletion src/commands/dependencies/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { FolderContext } from "../../FolderContext";
import { WorkspaceContext } from "../../WorkspaceContext";
import { createSwiftTask, SwiftTaskProvider } from "../../tasks/SwiftTaskProvider";
import { executeTaskWithUI, updateAfterError } from "./../utilities";
import { packageName } from "../../utilities/tasks";

/**
* Executes a {@link vscode.Task task} to update this package's dependencies.
Expand All @@ -41,7 +42,7 @@ export async function updateFolderDependencies(folderContext: FolderContext) {
{
cwd: folderContext.folder,
scope: folderContext.workspaceFolder,
prefix: folderContext.name,
packageName: packageName(folderContext),
presentationOptions: { reveal: vscode.TaskRevealKind.Silent },
},
folderContext.toolchain
Expand Down
3 changes: 2 additions & 1 deletion src/commands/dependencies/useLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as vscode from "vscode";
import { FolderOperation, WorkspaceContext } from "../../WorkspaceContext";
import { createSwiftTask } from "../../tasks/SwiftTaskProvider";
import { executeTaskWithUI } from "../utilities";
import { packageName } from "../../utilities/tasks";

/**
* Use local version of package dependency
Expand Down Expand Up @@ -61,7 +62,7 @@ export async function useLocalDependency(
{
scope: currentFolder.workspaceFolder,
cwd: currentFolder.folder,
prefix: currentFolder.name,
packageName: packageName(currentFolder),
},
currentFolder.toolchain
);
Expand Down
5 changes: 3 additions & 2 deletions src/commands/resetPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { FolderContext } from "../FolderContext";
import { createSwiftTask, SwiftTaskProvider } from "../tasks/SwiftTaskProvider";
import { WorkspaceContext } from "../WorkspaceContext";
import { executeTaskWithUI } from "./utilities";
import { packageName } from "../utilities/tasks";

/**
* Executes a {@link vscode.Task task} to reset the complete cache/build directory.
Expand All @@ -40,7 +41,7 @@ export async function folderResetPackage(folderContext: FolderContext) {
{
cwd: folderContext.folder,
scope: folderContext.workspaceFolder,
prefix: folderContext.name,
packageName: packageName(folderContext),
presentationOptions: { reveal: vscode.TaskRevealKind.Silent },
group: vscode.TaskGroup.Clean,
},
Expand All @@ -58,7 +59,7 @@ export async function folderResetPackage(folderContext: FolderContext) {
{
cwd: folderContext.folder,
scope: folderContext.workspaceFolder,
prefix: folderContext.name,
packageName: packageName(folderContext),
presentationOptions: { reveal: vscode.TaskRevealKind.Silent },
},
folderContext.toolchain
Expand Down
7 changes: 7 additions & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,13 @@ function computeVscodeVar(varName: string): string | null {

const file = () => vscode.window.activeTextEditor?.document?.uri?.fsPath || "";

const regex = /workspaceFolder:(.*)/gm;
const match = regex.exec(varName);
if (match) {
const name = match[1];
return vscode.workspace.workspaceFolders?.find(f => f.name === name)?.uri.fsPath ?? null;
}

// https://code.visualstudio.com/docs/editor/variables-reference
// Variables to be substituted should be added here.
const supportedVariables: { [k: string]: () => string } = {
Expand Down
35 changes: 22 additions & 13 deletions src/debugger/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,28 @@ export function getLaunchConfiguration(
target: string,
folderCtx: FolderContext
): vscode.DebugConfiguration | undefined {
const wsLaunchSection = vscode.workspace.getConfiguration("launch", folderCtx.workspaceFolder);
const launchConfigs = wsLaunchSection.get<vscode.DebugConfiguration[]>("configurations") || [];
const { folder } = getFolderAndNameSuffix(folderCtx);
const targetPath = path.join(
BuildFlags.buildDirectoryFromWorkspacePath(folder, true),
"debug",
target
);
// Users could be on different platforms with different path annotations,
// so normalize before we compare.
return launchConfigs.find(
config => path.normalize(config.program) === path.normalize(targetPath)
);
for (const wsLaunchSection of [
vscode.workspace.getConfiguration("launch", folderCtx.workspaceFolder),
vscode.workspace.getConfiguration("launch"), // Needed for .code-workspace files
]) {
const launchConfigs =
wsLaunchSection.get<vscode.DebugConfiguration[]>("configurations") || [];
const { folder } = getFolderAndNameSuffix(folderCtx);
const targetPath = path.join(
BuildFlags.buildDirectoryFromWorkspacePath(folder, true),
"debug",
target
);
// Users could be on different platforms with different path annotations,
// so normalize before we compare.
const launchConfig = launchConfigs.find(
config => path.normalize(config.program) === path.normalize(targetPath)
);
if (!launchConfig) {
continue;
}
return launchConfig;
}
}

// Return array of DebugConfigurations for executables based on what is in Package.swift
Expand Down
Loading