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
4 changes: 4 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export default defineConfig(
rules: {
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/no-empty-object-type": "off",
// VS Code's .get<T>(key, default) needs explicit type params to
// widen literal defaults (e.g. true -> boolean), otherwise
// no-unnecessary-condition fires on the result.
"@typescript-eslint/no-unnecessary-type-arguments": "off",
"@typescript-eslint/no-floating-promises": [
"error",
{
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.

6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -864,12 +864,6 @@
"default": false,
"markdownDescription": "Removes redundant whitespace between parameters."
},
"powershell.codeFormatting.whitespaceAroundPipe": {
"type": "boolean",
"default": true,
"markdownDescription": "**Deprecated:** Please use the `#powershell.codeFormatting.addWhitespaceAroundPipe#` setting instead. If you've used this setting before, we have moved it for you automatically.",
"markdownDeprecationMessage": "**Deprecated:** Please use the `#powershell.codeFormatting.addWhitespaceAroundPipe#` setting instead. If you've used this setting before, we have moved it for you automatically."
},
"powershell.codeFormatting.addWhitespaceAroundPipe": {
"type": "boolean",
"default": true,
Expand Down
16 changes: 6 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import { ShowHelpFeature } from "./features/ShowHelp";
import { LanguageClientConsumer } from "./languageClientConsumer";
import { Logger } from "./logging";
import { SessionManager } from "./session";
import { getSettings } from "./settings";
import { PowerShellLanguageId, sleep } from "./utils";
import { sleep } from "./utils";
// The 1DS telemetry key, which is just shared among all Microsoft extensions
// (and isn't sensitive).
const TELEMETRY_KEY =
Expand Down Expand Up @@ -56,13 +55,8 @@ export async function activate(

telemetryReporter = new TelemetryReporter(TELEMETRY_KEY);

const settings = getSettings();
logger.writeDebug(
`Loaded settings:\n${JSON.stringify(settings, undefined, 2)}`,
);

languageConfigurationDisposable = vscode.languages.setLanguageConfiguration(
PowerShellLanguageId,
"powershell",
{
// TODO: Remove the useless escapes
wordPattern:
Expand Down Expand Up @@ -148,7 +142,6 @@ export async function activate(

sessionManager = new SessionManager(
context,
settings,
logger,
documentSelector,
packageInfo.name,
Expand Down Expand Up @@ -204,7 +197,10 @@ export async function activate(

sessionManager.setLanguageClientConsumers(languageClientConsumers);

if (settings.startAutomatically) {
const startAutomatically = vscode.workspace
.getConfiguration("powershell")
.get<boolean>("startAutomatically", true);
if (startAutomatically) {
await sessionManager.start();
}

Expand Down
7 changes: 4 additions & 3 deletions src/features/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from "../controls/checkboxQuickPick";
import { LanguageClientConsumer } from "../languageClientConsumer";
import type { ILogger } from "../logging";
import { getSettings } from "../settings";

export const EvaluateRequestType = new RequestType<
IEvaluateRequestArguments,
Expand Down Expand Up @@ -215,9 +214,11 @@ export class ConsoleFeature extends LanguageClientConsumer {
// We need to honor the focusConsoleOnExecute setting here too. However, the boolean that `show`
// takes is called `preserveFocus` which when `true` the terminal will not take focus.
// This is the inverse of focusConsoleOnExecute so we have to inverse the boolean.
const focusConsoleOnExecute = vscode.workspace
.getConfiguration("powershell.integratedConsole")
.get<boolean>("focusConsoleOnExecute", true);
vscode.window.activeTerminal.show(
!getSettings().integratedConsole
.focusConsoleOnExecute,
!focusConsoleOnExecute,
);
await vscode.commands.executeCommand(
"workbench.action.terminal.scrollToBottom",
Expand Down
31 changes: 13 additions & 18 deletions src/features/DebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import type { ILogger } from "../logging";
import { OperatingSystem, getPlatformDetails } from "../platform";
import { PowerShellProcess } from "../process";
import { SessionManager, type IEditorServicesSessionDetails } from "../session";
import { getSettings } from "../settings";
import { checkIfFileExists } from "../utils";

export const StartDebuggerNotificationType = new NotificationType<void>(
Expand Down Expand Up @@ -358,10 +357,12 @@ export class DebugSessionFeature
// Prevent the Debug Console from opening
config.internalConsoleOptions = "neverOpen";

const settings = getSettings();
config.createTemporaryIntegratedConsole ??=
settings.debugging.createTemporaryIntegratedConsole;
config.executeMode ??= settings.debugging.executeMode;
config.createTemporaryIntegratedConsole ??= workspace
.getConfiguration("powershell.debugging")
.get<boolean>("createTemporaryIntegratedConsole");
config.executeMode ??= workspace
.getConfiguration("powershell.debugging")
.get("executeMode", "DotSource");
if (config.request === "attach") {
resolvedConfig = await this.resolveAttachDebugConfiguration(config);
} else if (config.request === "launch") {
Expand Down Expand Up @@ -499,12 +500,10 @@ export class DebugSessionFeature
private async createTemporaryIntegratedConsole(
session: DebugSession,
): Promise<IEditorServicesSessionDetails | undefined> {
const settings = getSettings();
const previousActiveTerminal = window.activeTerminal;

this.tempDebugProcess =
await this.sessionManager.createDebugSessionProcess(
settings,
session.configuration.sessionName,
);
// TODO: Maybe set a timeout on the cancellation token?
Expand Down Expand Up @@ -665,11 +664,9 @@ export class DebugSessionFeature

/** Fetches all available vscode launch configurations. This is abstracted out for easier testing. */
private getLaunchConfigurations(): DebugConfiguration[] {
return (
workspace
.getConfiguration("launch")
.get<DebugConfiguration[]>("configurations") ?? []
);
return workspace
.getConfiguration("launch")
.get<DebugConfiguration[]>("configurations", []);
}

private async resolveAttachDebugConfiguration(
Expand Down Expand Up @@ -823,12 +820,10 @@ class PowerShellDebugAdapterTrackerFactory
* user re-enables, then logging resumes.
*/
get log(): LogOutputChannel | undefined {
if (
workspace
.getConfiguration("powershell.developer")
.get<boolean>("traceDap") &&
this._log === undefined
) {
const traceDap = workspace
.getConfiguration("powershell.developer")
.get<boolean>("traceDap");
if (traceDap && this._log === undefined) {
this._log = window.createOutputChannel(
`${this.adapterName}: Trace DAP`,
{ log: true },
Expand Down
9 changes: 5 additions & 4 deletions src/features/ExtensionCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { LanguageClient } from "vscode-languageclient/node";
import { LanguageClientConsumer } from "../languageClientConsumer";
import type { ILogger } from "../logging";
import { getSettings, validateCwdSetting } from "../settings";
import { validateCwdSetting } from "../settings";
import { DebugConfig, DebugConfigurations } from "./DebugSession";

export interface IExtensionCommand {
Expand Down Expand Up @@ -311,9 +311,10 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
languageClient.onNotification(ClearTerminalNotificationType, () => {
// We check to see if they have TrueClear on. If not, no-op because the
// overriden Clear-Host already calls [System.Console]::Clear()
if (
getSettings().integratedConsole.forceClearScrollbackBuffer
) {
const forceClearScrollbackBuffer = vscode.workspace
.getConfiguration("powershell.integratedConsole")
.get<boolean>("forceClearScrollbackBuffer");
if (forceClearScrollbackBuffer) {
void vscode.commands.executeCommand(
"workbench.action.terminal.clear",
);
Expand Down
5 changes: 3 additions & 2 deletions src/features/GetCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as vscode from "vscode";
import { RequestType0 } from "vscode-languageclient";
import { LanguageClient } from "vscode-languageclient/node";
import { LanguageClientConsumer } from "../languageClientConsumer";
import { getSettings } from "../settings";

interface ICommand {
name: string;
Expand Down Expand Up @@ -79,7 +78,9 @@ export class GetCommandsFeature extends LanguageClientConsumer {
private async CommandExplorerRefresh(): Promise<void> {
const client = await LanguageClientConsumer.getLanguageClient();
const result = await client.sendRequest(GetCommandRequestType);
const exclusions = getSettings().sideBar.CommandExplorerExcludeFilter;
const exclusions = vscode.workspace
.getConfiguration("powershell.sideBar")
.get<string[]>("CommandExplorerExcludeFilter", []);
const excludeFilter = exclusions.map((filter: string) =>
filter.toLowerCase(),
);
Expand Down
22 changes: 14 additions & 8 deletions src/features/HelpCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {
import { RequestType } from "vscode-languageclient";
import { LanguageClient } from "vscode-languageclient/node";
import { LanguageClientConsumer } from "../languageClientConsumer";
import { CommentType, getSettings, Settings } from "../settings";

enum CommentType {
Disabled = "Disabled",
BlockComment = "BlockComment",
LineComment = "LineComment",
}

interface ICommentHelpRequestArguments {}

Expand All @@ -37,13 +42,14 @@ enum SearchState {
export class HelpCompletionFeature extends LanguageClientConsumer {
private helpCompletionProvider: HelpCompletionProvider | undefined;
private disposable: Disposable | undefined;
private settings: Settings;

constructor() {
super();
this.settings = getSettings();

if (this.settings.helpCompletion !== CommentType.Disabled) {
const helpCompletion = workspace
.getConfiguration("powershell")
.get<CommentType>("helpCompletion", CommentType.BlockComment);
if (helpCompletion !== CommentType.Disabled) {
this.helpCompletionProvider = new HelpCompletionProvider();
this.disposable = workspace.onDidChangeTextDocument(async (e) => {
await this.onEvent(e);
Expand Down Expand Up @@ -144,12 +150,10 @@ class HelpCompletionProvider extends LanguageClientConsumer {
private triggerFinderHelpComment: TriggerFinder;
private lastChangeRange: Range | undefined;
private lastDocument: TextDocument | undefined;
private settings: Settings;

constructor() {
super();
this.triggerFinderHelpComment = new TriggerFinder("##");
this.settings = getSettings();
}

public get triggerFound(): boolean {
Expand Down Expand Up @@ -187,11 +191,13 @@ class HelpCompletionProvider extends LanguageClientConsumer {
const doc = this.lastDocument;

const client = await LanguageClientConsumer.getLanguageClient();
const helpCompletion = workspace
.getConfiguration("powershell")
.get<CommentType>("helpCompletion", CommentType.BlockComment);
const result = await client.sendRequest(CommentHelpRequestType, {
documentUri: doc.uri.toString(),
triggerPosition: triggerStartPos,
blockComment:
this.settings.helpCompletion === CommentType.BlockComment,
blockComment: helpCompletion === CommentType.BlockComment,
});

if (result.content.length === 0) {
Expand Down
23 changes: 16 additions & 7 deletions src/features/PesterTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as path from "path";
import type { ILogger } from "../logging";
import { SessionManager } from "../session";
import { getChosenWorkspace, getSettings } from "../settings";
import { getChosenWorkspace } from "../settings";
import vscode = require("vscode");
import utils = require("../utils");

Expand Down Expand Up @@ -115,7 +115,11 @@ export class PesterTestsFeature implements vscode.Disposable {
lineNum?: number,
outputPath?: string,
): vscode.DebugConfiguration {
const settings = getSettings();
const debuggingConfig = vscode.workspace.getConfiguration(
"powershell.debugging",
);
const pesterConfig =
vscode.workspace.getConfiguration("powershell.pester");
const launchConfig = {
request: "launch",
type: "PowerShell",
Expand All @@ -127,8 +131,9 @@ export class PesterTestsFeature implements vscode.Disposable {
],
internalConsoleOptions: "neverOpen",
noDebug: launchType === LaunchType.Run,
createTemporaryIntegratedConsole:
settings.debugging.createTemporaryIntegratedConsole,
createTemporaryIntegratedConsole: debuggingConfig.get<boolean>(
"createTemporaryIntegratedConsole",
),
};

if (lineNum) {
Expand All @@ -142,19 +147,23 @@ export class PesterTestsFeature implements vscode.Disposable {
launchConfig.args.push("-All");
}

if (!settings.pester.useLegacyCodeLens) {
const useLegacyCodeLens = pesterConfig.get<boolean>(
"useLegacyCodeLens",
true,
);
if (!useLegacyCodeLens) {
launchConfig.args.push("-MinimumVersion5");
}

if (launchType === LaunchType.Debug) {
launchConfig.args.push(
"-Output",
`'${settings.pester.debugOutputVerbosity}'`,
`'${pesterConfig.get("debugOutputVerbosity", "Diagnostic")}'`,
);
} else {
launchConfig.args.push(
"-Output",
`'${settings.pester.outputVerbosity}'`,
`'${pesterConfig.get("outputVerbosity", "FromPreference")}'`,
);
}

Expand Down
8 changes: 5 additions & 3 deletions src/features/UpdatePowerShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import vscode = require("vscode");

import type { ILogger } from "../logging";
import type { IPowerShellVersionDetails } from "../session";
import { changeSetting, Settings } from "../settings";
import { changeSetting } from "../settings";

interface IUpdateMessageItem extends vscode.MessageItem {
id: number;
Expand Down Expand Up @@ -39,7 +39,6 @@ export class UpdatePowerShell {
private localVersion: SemVer;

constructor(
private sessionSettings: Settings,
private logger: ILogger,
versionDetails: IPowerShellVersionDetails,
) {
Expand All @@ -52,7 +51,10 @@ export class UpdatePowerShell {

private shouldCheckForUpdate(): boolean {
// Respect user setting.
if (!this.sessionSettings.promptToUpdatePowerShell) {
const promptToUpdatePowerShell = vscode.workspace
.getConfiguration("powershell")
.get<boolean>("promptToUpdatePowerShell", true);
if (!promptToUpdatePowerShell) {
this.logger.writeDebug(
"Setting 'promptToUpdatePowerShell' was false.",
);
Expand Down
Loading
Loading