Skip to content

Improve Extension Authoring Experience with new Build Tasks and Launch Configs #4510

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

Merged
merged 13 commits into from
Apr 12, 2023
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
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ obj/
bin/
out/
sessions/
test/.vscode/

test-results.xml
*.vsix
*.DS_Store
4 changes: 0 additions & 4 deletions examples/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@
// Relative paths for this setting are always relative to the workspace root dir.
"powershell.scriptAnalysis.settingsPath": "./PSScriptAnalyzerSettings.psd1",
"files.defaultLanguage": "powershell",
// Suppresses some first-run messages
"git.openRepositoryInParentFolders": "never",
"csharp.suppressDotnetRestoreNotification": true,
"extensions.ignoreRecommendations": true
}
212 changes: 194 additions & 18 deletions extension-dev.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
]
},
"settings": {
"window.title": "PowerShell VS Code Extension Development",
"debug.onTaskErrors": "prompt",
"editor.tabSize": 4,
"editor.insertSpaces": true,
"files.trimTrailingWhitespace": true,
Expand All @@ -44,7 +46,17 @@
"powershell.codeFormatting.whitespaceBetweenParameters": true,
"powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline",
// Lock the TypeScript SDK path to the version we use
"typescript.tsdk": "Client/node_modules/typescript/lib"
"typescript.tsdk": "Client/node_modules/typescript/lib",
// Code actions like "organize imports" ignore ESLint, so we need this here
"typescript.format.semicolons": "insert",
// Enable ESLint as defaut formatter so quick fixes can be applied directly
"eslint.format.enable": true,
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "modificationsIfAvailable"
}
},
"tasks": {
"version": "2.0.0",
Expand Down Expand Up @@ -90,7 +102,7 @@
"options": {
"cwd": "${workspaceFolder:Client}"
},
"command": "Invoke-Build Build",
"command": "./build.ps1",
"problemMatcher": [
"$msCompile",
"$tsc"
Expand All @@ -106,7 +118,7 @@
"options": {
"cwd": "${workspaceFolder:Client}"
},
"command": "Invoke-Build Test",
"command": "./build.ps1 -Test",
"problemMatcher": [
"$msCompile",
"$tsc"
Expand Down Expand Up @@ -148,7 +160,39 @@
},
"command": "Invoke-Build ${input:serverBuildCommand}",
"group": "build"
}
},
// HACK: Can't use task type npm in workspace config: https://github.com/microsoft/vscode/issues/96086
{
"label": "test-watch",
"icon": {
"color": "terminal.ansiCyan",
"id": "sync"
},
"type": "shell",
"options": {
"cwd": "${workspaceFolder:Client}"
},
"command": "npm run-script build-test-watch",
"group": "test",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"dependsOn": "build-watch" // We need to also build main.js extension for testing or it leads to sourcemap errors
},
{
"label": "build-watch",
"icon": {
"color": "terminal.ansiCyan",
"id": "sync"
},
"type": "shell",
"options": {
"cwd": "${workspaceFolder:Client}"
},
"command": "npm run-script build-watch",
"group": "build",
"problemMatcher": "$esbuild-watch",
"isBackground": true,
},
],
"inputs": [
{
Expand Down Expand Up @@ -184,7 +228,52 @@
},
"launch": {
"version": "0.2.0",
"compounds": [
{
"name": "Test Extension",
"configurations": [
"ExtensionTests",
"ExtensionTestRunner",
],
"stopAll": true,
"presentation": {
"group": "test",
"order": 1
},
// This is here so instead of under TestRunner so that the attach doesn't start until the compile is complete
"preLaunchTask": "test-watch"
}
],
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder:Client}"
],
"env": {
"__TEST_WORKSPACE_PATH": "${workspaceFolder:Client}/examples",
},
"sourceMaps": true,
// This speeds up source map detection and makes smartStep work correctly
"outFiles": [
"${workspaceFolder:Client}/out/**/*.js",
"!**/node_modules/**",
"!**/.vscode-test/**"
],
"skipFiles": [
"<node_internals>/**",
"**/node_modules/**",
"**/.vscode-test/**"
],
"presentation": {
"hidden": false,
"group": "test",
"order": 2
}
},
{
// https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": "Attach to Editor Services",
Expand All @@ -197,42 +286,129 @@
"searchPaths": [],
"searchMicrosoftSymbolServer": true,
"searchNuGetOrgSymbolServer": true
},
"presentation": {
"hidden": false,
"group": "test",
"order": 3
}
},
{
"name": "Launch Extension",
// Runs the extension in an empty temp profile that is automatically cleaned up after use
// Undocumented: https://github.com/microsoft/vscode-docs/issues/6220
"name": "Launch Extension - Temp Profile",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder:Client}"
"--profile-temp",
"--extensionDevelopmentPath=${workspaceFolder:Client}",
"${workspaceFolder:Client}/examples"
],
"sourceMaps": true,
// This speeds up source map detection and makes smartStep work correctly
"outFiles": [
"${workspaceFolder:Client}/out/main.js"
"${workspaceFolder:Client}/out/**/*.js",
"!**/node_modules/**",
"!**/.vscode-test/**"
],
"skipFiles": [
"<node_internals>/**",
"**/node_modules/**",
"**/.vscode-test/**"
],
"preLaunchTask": "${defaultBuildTask}",
"presentation": {
"hidden": false,
"group": "test",
"order": 2
}
},
{
"name": "Launch Extension Tests",
// Runs the extension in an isolated but persistent profile separate from the user settings
// Undocumented: https://github.com/microsoft/vscode-docs/issues/6220
"name": "Launch Extension - Isolated Profile",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
// The tests require Code be opened with a workspace, which exists in
// `test`, but this has to be passed as a CLI argument, not just `cwd`.
"${workspaceFolder:Client}/test",
"--disableExtensions",
"--profile=debug",
"--extensionDevelopmentPath=${workspaceFolder:Client}",
"--extensionTestsPath=${workspaceFolder:Client}/out/test/index.js",
"${workspaceFolder:Client}/examples"
],
"sourceMaps": true,
// This speeds up source map detection and makes smartStep work correctly
"outFiles": [
"${workspaceFolder:Client}/out/test/**/*.js"
"${workspaceFolder:Client}/out/**/*.js",
"!**/node_modules/**",
"!**/.vscode-test/**"
],
"skipFiles": [
"<node_internals>/**",
"**/node_modules/**",
"**/.vscode-test/**"
],
"presentation": {
"hidden": false,
"group": "test",
"order": 2
}
},
{
"name": "ExtensionTestRunner",
"type": "node",
"request": "launch",
"program": "${workspaceFolder:Client}/out/test/runTests.js",
"cascadeTerminateToConfigurations": [
"ExtensionTests",
],
// This speeds up source map detection and makes smartStep work correctly
"outFiles": [
"${workspaceFolder:Client}/out/**/*.js",
"!**/node_modules/**",
"!**/.vscode-test/**"
],
"skipFiles": [
"<node_internals>/**",
"**/node_modules/**",
"**/.vscode-test/**"
],
"args": [
"59229" // Wait on this port for the separate debugger task to attach
],
"presentation": {
"hidden": true,
},
"internalConsoleOptions": "neverOpen",
"console": "integratedTerminal",
"autoAttachChildProcesses": false // Doesnt work with the extension host for whatever reason, hence the separate attach.
},
{
"name": "ExtensionTests",
"type": "node",
"request": "attach",
"port": 59229,
"autoAttachChildProcesses": true,
"outputCapture": "console",
"continueOnAttach": true,
// Sometimes we may need to install extensions or reload the window which requires reconnecting
"restart": {
"delay": 1000,
"maxAttempts": 3
},
"presentation": {
"hidden": true,
},
// This speeds up source map detection and makes smartStep work correctly
"outFiles": [
"${workspaceFolder:Client}/out/**/*.js",
"!**/node_modules/**",
"!**/.vscode-test/**"
],
"skipFiles": [
"<node_internals>/**",
"**/node_modules/**",
"**/.vscode-test/**"
],
"preLaunchTask": "${defaultBuildTask}",
"internalConsoleOptions": "openOnSessionStart"
}
]
}
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,11 @@
"main": "./out/main.js",
"scripts": {
"lint": "eslint . --ext .ts",
"build": "tsc --project tsconfig.json && esbuild ./src/main.ts --outdir=out --bundle --external:vscode --platform=node",
"test": "node ./out/test/runTests.js",
"build": "esbuild ./src/main.ts --outdir=out --bundle --external:vscode --platform=node",
"build-watch": "npm run build -- --watch",
"build-test": "tsc --incremental",
"build-test-watch": "npm run build-test -- --watch",
"test": "npm run build-test && node ./out/test/runTests.js",
"package": "vsce package --no-gitHubIssueLinking",
"publish": "vsce publish"
},
Expand Down
7 changes: 0 additions & 7 deletions test/.vscode/settings.json

This file was deleted.

13 changes: 13 additions & 0 deletions test/TestEnvironment.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// A simple test environment that suppresses some first start warnings we don't care about.
"folders": [
{
"path": "mocks"
}
],
"settings": {
"git.openRepositoryInParentFolders": "never",
"csharp.suppressDotnetRestoreNotification": true,
"extensions.ignoreRecommendations": true
}
}
26 changes: 12 additions & 14 deletions test/core/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,32 @@

import * as assert from "assert";
import * as vscode from "vscode";
import * as settings from "../../src/settings";
import { Settings, getSettings, getEffectiveConfigurationTarget, changeSetting, CommentType } from "../../src/settings";

describe("Settings module", function () {
describe("Settings E2E", function () {
this.slow(800);
it("Loads without error", function () {
assert.doesNotThrow(settings.getSettings);
assert.doesNotThrow(getSettings);
});

it("Loads the correct defaults", function () {
const testSettings = new settings.Settings();
testSettings.enableProfileLoading = false;
testSettings.powerShellAdditionalExePaths = { "Some PowerShell": "somePath" };
const actualSettings = settings.getSettings();
const testSettings = new Settings();
const actualSettings = getSettings();
assert.deepStrictEqual(actualSettings, testSettings);
});


it("Updates correctly", async function () {
await settings.changeSetting("helpCompletion", settings.CommentType.LineComment, false, undefined);
assert.strictEqual(settings.getSettings().helpCompletion, settings.CommentType.LineComment);
await changeSetting("helpCompletion", CommentType.LineComment, false, undefined);
assert.strictEqual(getSettings().helpCompletion, CommentType.LineComment);
});

it("Gets the effective configuration target", async function () {
await settings.changeSetting("helpCompletion", settings.CommentType.LineComment, false, undefined);
let target = settings.getEffectiveConfigurationTarget("helpCompletion");
await changeSetting("helpCompletion", CommentType.LineComment, false, undefined);
let target = getEffectiveConfigurationTarget("helpCompletion");
assert.strictEqual(target, vscode.ConfigurationTarget.Workspace);

await settings.changeSetting("helpCompletion", undefined, false, undefined);
target = settings.getEffectiveConfigurationTarget("helpCompletion");
await changeSetting("helpCompletion", undefined, false, undefined);
target = getEffectiveConfigurationTarget("helpCompletion");
assert.strictEqual(target, undefined);
});
});
Loading