Skip to content
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
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ src/client/formatters/baseFormatter.ts
src/client/testing/serviceRegistry.ts
src/client/testing/main.ts
src/client/testing/configurationFactory.ts
src/client/testing/common/debugLauncher.ts
src/client/testing/common/constants.ts
src/client/testing/common/testUtils.ts
src/client/testing/common/socketServer.ts
Expand Down
6 changes: 6 additions & 0 deletions src/client/common/vscodeApis/windowApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ProgressOptions,
QuickPickItem,
QuickPickOptions,
TextEditor,
window,
} from 'vscode';

Expand Down Expand Up @@ -61,3 +62,8 @@ export function withProgress<R>(
): Thenable<R> {
return window.withProgress(options, task);
}

export function getActiveTextEditor(): TextEditor | undefined {
const { activeTextEditor } = window;
return activeTextEditor;
}
6 changes: 5 additions & 1 deletion src/client/common/vscodeApis/workspaceApis.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { ConfigurationScope, workspace, WorkspaceConfiguration, WorkspaceFolder } from 'vscode';
import { ConfigurationScope, workspace, WorkspaceConfiguration, WorkspaceEdit, WorkspaceFolder } from 'vscode';
import { Resource } from '../types';

export function getWorkspaceFolders(): readonly WorkspaceFolder[] | undefined {
Expand All @@ -19,3 +19,7 @@ export function getWorkspaceFolderPaths(): string[] {
export function getConfiguration(section?: string, scope?: ConfigurationScope | null): WorkspaceConfiguration {
return workspace.getConfiguration(section, scope);
}

export function applyEdit(edit: WorkspaceEdit): Thenable<boolean> {
return workspace.applyEdit(edit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,23 @@
import { inject, injectable } from 'inversify';
import { Uri } from 'vscode';
import { IExtensionSingleActivationService } from '../../../../activation/types';
import { ICommandManager } from '../../../../common/application/types';
import { Commands } from '../../../../common/constants';
import { IDisposable, IDisposableRegistry } from '../../../../common/types';
import { registerCommand } from '../../../../common/vscodeApis/commandApis';
import { IInterpreterService } from '../../../../interpreter/contracts';

@injectable()
export class InterpreterPathCommand implements IExtensionSingleActivationService {
public readonly supportedWorkspaceTypes = { untrustedWorkspace: false, virtualWorkspace: false };

constructor(
@inject(ICommandManager) private readonly commandManager: ICommandManager,
@inject(IInterpreterService) private readonly interpreterService: IInterpreterService,
@inject(IDisposableRegistry) private readonly disposables: IDisposable[],
) {}

public async activate(): Promise<void> {
this.disposables.push(
this.commandManager.registerCommand(Commands.GetSelectedInterpreterPath, (args) =>
this._getSelectedInterpreterPath(args),
),
registerCommand(Commands.GetSelectedInterpreterPath, (args) => this._getSelectedInterpreterPath(args)),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as path from 'path';
import * as fs from 'fs-extra';
import { parse } from 'jsonc-parser';
import { DebugConfiguration, Uri, WorkspaceFolder } from 'vscode';
import { getWorkspaceFolder } from '../utils/workspaceFolder';
import { getWorkspaceFolder } from '../../../../common/vscodeApis/workspaceApis';

export async function getConfigurationsForWorkspace(workspace: WorkspaceFolder): Promise<DebugConfiguration[]> {
const filename = path.join(workspace.uri.fsPath, '.vscode', 'launch.json');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import { inject, injectable } from 'inversify';
import { IExtensionSingleActivationService } from '../../../../activation/types';
import { ICommandManager } from '../../../../common/application/types';
import { IDisposableRegistry } from '../../../../common/types';
import { registerCommand } from '../../../../common/vscodeApis/commandApis';
import { IDebugConfigurationService } from '../../types';
import { LaunchJsonUpdaterServiceHelper } from './updaterServiceHelper';

Expand All @@ -15,19 +15,14 @@ export class LaunchJsonUpdaterService implements IExtensionSingleActivationServi
public readonly supportedWorkspaceTypes = { untrustedWorkspace: false, virtualWorkspace: false };

constructor(
@inject(ICommandManager) private readonly commandManager: ICommandManager,
@inject(IDisposableRegistry) private readonly disposableRegistry: IDisposableRegistry,
@inject(IDebugConfigurationService) private readonly configurationProvider: IDebugConfigurationService,
) {}

public async activate(): Promise<void> {
const handler = new LaunchJsonUpdaterServiceHelper(this.commandManager, this.configurationProvider);
const handler = new LaunchJsonUpdaterServiceHelper(this.configurationProvider);
this.disposableRegistry.push(
this.commandManager.registerCommand(
'python.SelectAndInsertDebugConfiguration',
handler.selectAndInsertDebugConfig,
handler,
),
registerCommand('python.SelectAndInsertDebugConfiguration', handler.selectAndInsertDebugConfig, handler),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,19 @@

import { createScanner, parse, SyntaxKind } from 'jsonc-parser';
import { CancellationToken, DebugConfiguration, Position, Range, TextDocument, WorkspaceEdit } from 'vscode';
import { ICommandManager } from '../../../../common/application/types';
import { noop } from '../../../../common/utils/misc';
import { executeCommand } from '../../../../common/vscodeApis/commandApis';
import { getActiveTextEditor } from '../../../../common/vscodeApis/windowApis';
import { applyEdit, getWorkspaceFolder } from '../../../../common/vscodeApis/workspaceApis';
import { captureTelemetry } from '../../../../telemetry';
import { EventName } from '../../../../telemetry/constants';
import { IDebugConfigurationService } from '../../types';
import { applyEdit, getActiveTextEditor } from '../utils/common';
import { getWorkspaceFolder } from '../utils/workspaceFolder';

type PositionOfCursor = 'InsideEmptyArray' | 'BeforeItem' | 'AfterItem';
type PositionOfComma = 'BeforeCursor';

export class LaunchJsonUpdaterServiceHelper {
constructor(
private readonly commandManager: ICommandManager,
private readonly configurationProvider: IDebugConfigurationService,
) {}
constructor(private readonly configurationProvider: IDebugConfigurationService) {}

@captureTelemetry(EventName.DEBUGGER_CONFIGURATION_PROMPTS_IN_LAUNCH_JSON)
public async selectAndInsertDebugConfig(
Expand All @@ -35,7 +32,7 @@ export class LaunchJsonUpdaterServiceHelper {

if (!token.isCancellationRequested && Array.isArray(configs) && configs.length > 0) {
// Always use the first available debug configuration.
await this.insertDebugConfiguration(document, position, configs[0]);
await LaunchJsonUpdaterServiceHelper.insertDebugConfiguration(document, position, configs[0]);
}
}
}
Expand All @@ -49,7 +46,7 @@ export class LaunchJsonUpdaterServiceHelper {
* @returns {Promise<void>}
* @memberof LaunchJsonCompletionItemProvider
*/
public async insertDebugConfiguration(
public static async insertDebugConfiguration(
document: TextDocument,
position: Position,
config: DebugConfiguration,
Expand All @@ -68,7 +65,7 @@ export class LaunchJsonUpdaterServiceHelper {
const workspaceEdit = new WorkspaceEdit();
workspaceEdit.insert(document.uri, position, formattedJson);
await applyEdit(workspaceEdit);
this.commandManager.executeCommand('editor.action.formatDocument').then(noop, noop);
executeCommand('editor.action.formatDocument').then(noop, noop);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import * as path from 'path';
import { CancellationToken, DebugConfiguration, Uri, WorkspaceFolder } from 'vscode';
import { IConfigurationService } from '../../../../common/types';
import { getOSType, OSType } from '../../../../common/utils/platform';
import {
getWorkspaceFolder as getVSCodeWorkspaceFolder,
getWorkspaceFolders,
} from '../../../../common/vscodeApis/workspaceApis';
import { IInterpreterService } from '../../../../interpreter/contracts';
import { sendTelemetryEvent } from '../../../../telemetry';
import { EventName } from '../../../../telemetry/constants';
Expand All @@ -16,7 +20,6 @@ import { AttachRequestArguments, DebugOptions, LaunchRequestArguments, PathMappi
import { PythonPathSource } from '../../types';
import { IDebugConfigurationResolver } from '../types';
import { resolveVariables } from '../utils/common';
import { getWorkspaceFolder as getVSCodeWorkspaceFolder, getWorkspaceFolders } from '../utils/workspaceFolder';
import { getProgram } from './helper';

@injectable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
'use strict';

import { inject, injectable } from 'inversify';
import { ICurrentProcess, IPathUtils } from '../../../../common/types';
import { ICurrentProcess } from '../../../../common/types';
import { EnvironmentVariables, IEnvironmentVariablesService } from '../../../../common/variables/types';
import { LaunchRequestArguments } from '../../../types';
import { getActiveTextEditor } from '../utils/common';
import { PYTHON_LANGUAGE } from '../../../../common/constants';
import { getActiveTextEditor } from '../../../../common/vscodeApis/windowApis';
import { getSearchPathEnvVarNames } from '../../../../common/utils/exec';

export const IDebugEnvironmentVariablesService = Symbol('IDebugEnvironmentVariablesService');
export interface IDebugEnvironmentVariablesService {
Expand All @@ -19,12 +20,11 @@ export interface IDebugEnvironmentVariablesService {
export class DebugEnvironmentVariablesHelper implements IDebugEnvironmentVariablesService {
constructor(
@inject(IEnvironmentVariablesService) private envParser: IEnvironmentVariablesService,
@inject(IPathUtils) private pathUtils: IPathUtils,
@inject(ICurrentProcess) private process: ICurrentProcess,
) {}

public async getEnvironmentVariables(args: LaunchRequestArguments): Promise<EnvironmentVariables> {
const pathVariableName = this.pathUtils.getPathVariableName();
const pathVariableName = getSearchPathEnvVarNames()[0];

// Merge variables from both .env file and env json variables.
const debugLaunchEnvVars: Record<string, string> =
Expand Down
13 changes: 2 additions & 11 deletions src/client/debugger/extension/configuration/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

'use strict';

import { WorkspaceFolder, window, TextEditor, WorkspaceEdit, workspace } from 'vscode';
import { getWorkspaceFolder } from './workspaceFolder';
import { WorkspaceFolder } from 'vscode';
import { getWorkspaceFolder } from '../../../../common/vscodeApis/workspaceApis';

/**
* @returns whether the provided parameter is a JavaScript String or not.
Expand Down Expand Up @@ -41,12 +41,3 @@ export function resolveVariables(
}
return value;
}

export function getActiveTextEditor(): TextEditor | undefined {
const { activeTextEditor } = window;
return activeTextEditor;
}

export function applyEdit(edit: WorkspaceEdit): Thenable<boolean> {
return workspace.applyEdit(edit);
}

This file was deleted.

Loading