vscode#DebugConfiguration TypeScript Examples
The following examples show how to use
vscode#DebugConfiguration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: codelens-provider.ts From plugin-vscode with Apache License 2.0 | 6 votes |
async function constructDebugConfig(testDebug: boolean, ballerinaCmd: string, ballerinaHome: string, args: any[])
: Promise<DebugConfiguration> {
const debugConfig: DebugConfiguration = {
type: LANGUAGE.BALLERINA,
name: testDebug ? DEBUG_CONFIG.TEST_DEBUG_NAME : DEBUG_CONFIG.SOURCE_DEBUG_NAME,
request: DEBUG_REQUEST.LAUNCH,
script: fileUriToPath(window.activeTextEditor!.document.uri.toString()),
networkLogs: false,
debugServer: '10001',
debuggeePort: '5010',
'ballerina.home': ballerinaHome,
'ballerina.command': ballerinaCmd,
debugTests: testDebug ? true : false,
tests: testDebug ? args : []
};
return debugConfig;
}
Example #2
Source File: extension.ts From vscode-riscv-venus with MIT License | 6 votes |
/**
* Massage a debug configuration just before a debug session is being launched,
* e.g. add all missing attributes to the debug configuration.
*/
resolveDebugConfiguration(folder: WorkspaceFolder | undefined, config: DebugConfiguration, token?: CancellationToken): ProviderResult<DebugConfiguration> {
// if launch.json is missing or empty
if (!config.type && !config.request && !config.name) {
const editor = vscode.window.activeTextEditor;
if (editor && editor.document.languageId === 'riscv') {
config.type = 'venus';
config.name = 'Launch';
config.request = 'launch';
config.program = '${file}';
config.stopOnEntry = true;
}
}
if (!config.program) {
return vscode.window.showInformationMessage("Cannot find a program to debug").then(_ => {
return undefined; // abort launch
});
}
return config;
}
Example #3
Source File: config-helper.ts From karma-test-explorer with MIT License | 6 votes |
getDefaultDebugPort = (
browser: string | undefined,
customLauncher: CustomLauncher,
debuggerConfigName: string | undefined,
debuggerConfig: DebugConfiguration,
config: ConfigStore<ConfigSetting>
): number | undefined => {
if (browser || debuggerConfigName) {
return;
}
const defaultCustomLauncher = config.inspect<CustomLauncher>(WorkspaceConfigSetting.CustomLauncher)?.defaultValue;
const defaultDebuggerConfig = config.inspect<DebugConfiguration>(WorkspaceConfigSetting.DebuggerConfig)?.defaultValue;
if (customLauncher.base !== defaultCustomLauncher?.base || debuggerConfig.type !== defaultDebuggerConfig?.type) {
return;
}
let configuredPort: number | undefined;
const browserDebugPortFlag = customLauncher.flags?.find(flag => flag.startsWith(CHROME_BROWSER_DEBUGGING_PORT_FLAG));
if (browserDebugPortFlag) {
const portPosition = browserDebugPortFlag.search(/[0-9]+$/g);
const portString = portPosition !== -1 ? browserDebugPortFlag.substring(portPosition) : undefined;
configuredPort = portString ? parseInt(portString, 10) : undefined;
}
return configuredPort ?? CHROME_DEFAULT_DEBUGGING_PORT;
}
Example #4
Source File: config-provider.ts From plugin-vscode with Apache License 2.0 | 5 votes |
async function getModifiedConfigs(config: DebugConfiguration) {
let debuggeePort = config.debuggeePort;
if (!debuggeePort) {
debuggeePort = await getPortPromise({ port: 5010, stopPort: 10000 });
}
const ballerinaHome = ballerinaExtInstance.getBallerinaHome();
config[BALLERINA_HOME] = ballerinaHome;
config[BALLERINA_COMMAND] = ballerinaExtInstance.getBallerinaCmd();
if (!config.type) {
config.type = LANGUAGE.BALLERINA;
}
if (!config.request) {
config.request = DEBUG_REQUEST.LAUNCH;
}
if (!window.activeTextEditor) {
ballerinaExtInstance.showMessageInvalidFile();
return Promise.reject();
}
const activeDoc = window.activeTextEditor.document;
if (ballerinaExtInstance.isSwanLake && ballerinaExtInstance.langClient) {
await ballerinaExtInstance.langClient.getBallerinaProject({
documentIdentifier: {
uri: activeDoc.uri.toString()
}
}).then((project) => {
if (!project.kind || (config.request === 'launch' && project.kind === 'BALA_PROJECT')) {
ballerinaExtInstance.showMessageInvalidProject();
return Promise.reject();
}
});
} else if (!activeDoc.fileName.endsWith('.bal')) {
ballerinaExtInstance.showMessageInvalidFile();
return Promise.reject();
}
config.script = activeDoc.uri.fsPath;
let langClient = <ExtendedLangClient>ballerinaExtInstance.langClient;
if (langClient.initializeResult) {
const { experimental } = langClient.initializeResult!.capabilities;
if (experimental && experimental.introspection && experimental.introspection.port > 0) {
config.networkLogsPort = experimental.introspection.port;
if (config.networkLogs === undefined) {
config.networkLogs = false;
}
}
}
// To make compatible with 1.2.x which supports scriptArguments
if (config.programArgs) {
config.scriptArguments = config.programArgs;
}
config.debuggeePort = debuggeePort.toString();
if (!config.debugServer) {
const debugServer = await getPortPromise({ port: 10001, stopPort: 20000 });
config.debugServer = debugServer.toString();
}
return config;
}
Example #5
Source File: config-provider.ts From plugin-vscode with Apache License 2.0 | 5 votes |
debugConfigProvider: DebugConfigurationProvider = {
resolveDebugConfiguration(folder: WorkspaceFolder, config: DebugConfiguration)
: Thenable<DebugConfiguration> {
return getModifiedConfigs(config);
}
}
Example #6
Source File: codelens-provider.ts From plugin-vscode with Apache License 2.0 | 5 votes |
async function startDebugging(uri: Uri, testDebug: boolean, ballerinaCmd: string, ballerinaHome: string, args: any[])
: Promise<boolean> {
const workspaceFolder: WorkspaceFolder | undefined = workspace.getWorkspaceFolder(uri);
const debugConfig: DebugConfiguration = await constructDebugConfig(testDebug, ballerinaCmd,
ballerinaHome, args);
return debug.startDebugging(workspaceFolder, debugConfig);
}
Example #7
Source File: config-helper.ts From karma-test-explorer with MIT License | 5 votes |
getMergedDebuggerConfig = (
workspacePath: string,
baseDebugConfig: DebugConfiguration,
webRootOverride?: string,
extraPathMappings?: Readonly<Record<string, string>>,
extraSourceMapPathOverrides?: Readonly<Record<string, string>>
): DebugConfiguration => {
const hasPathMapping = baseDebugConfig.pathMapping || extraPathMappings;
const hasSourceMapPathOverrides = baseDebugConfig.sourceMapPathOverrides || extraSourceMapPathOverrides;
const webRoot: string | undefined = (webRootOverride ?? baseDebugConfig.webRoot)?.replace(
/\${workspaceFolder}/g,
workspacePath
);
const replaceWorkspacePath = (value: string) =>
value.replace(/\${webRoot}/g, webRoot ?? workspacePath).replace(/\${workspaceFolder}/g, workspacePath);
const pathMapping = transformProperties(replaceWorkspacePath, {
...baseDebugConfig.pathMapping,
...extraPathMappings
});
const sourceMapPathOverrides = transformProperties(replaceWorkspacePath, {
...baseDebugConfig.sourceMapPathOverrides,
...extraSourceMapPathOverrides
});
const mergedDebuggerConfig: DebugConfiguration = { ...baseDebugConfig };
if (webRoot) {
mergedDebuggerConfig.webRoot = webRoot;
}
if (hasPathMapping) {
mergedDebuggerConfig.pathMapping = pathMapping;
}
if (hasSourceMapPathOverrides) {
mergedDebuggerConfig.sourceMapPathOverrides = sourceMapPathOverrides;
}
return mergedDebuggerConfig;
}
Example #8
Source File: extension-config.ts From karma-test-explorer with MIT License | 5 votes |
public readonly debuggerConfig: Readonly<DebugConfiguration>;
Example #9
Source File: debugger.ts From karma-test-explorer with MIT License | 5 votes |
public startDebugSession(
workspaceFolder: WorkspaceFolder,
debuggerNameOrConfig: string | DebugConfiguration,
sessionStartTimeout: number
): Execution<DebugSession> {
const deferredDebugSessionExecution: DeferredExecution<DebugSession> = new DeferredExecution();
const debugSessionExecution = deferredDebugSessionExecution.execution();
const debuggerNamespaceTag = this.options?.debuggerNamespace ? ` - ${this.options?.debuggerNamespace}` : '';
const actualDebuggerNameOrConfig =
typeof debuggerNameOrConfig === 'string'
? debuggerNameOrConfig
: { ...debuggerNameOrConfig, name: `${debuggerNameOrConfig.name}${debuggerNamespaceTag}` };
const debuggerConfigName =
typeof actualDebuggerNameOrConfig === 'string' ? actualDebuggerNameOrConfig : actualDebuggerNameOrConfig.name;
try {
const activeDebugSession = debug.activeDebugSession;
if (activeDebugSession && activeDebugSession.name === debuggerConfigName) {
this.logger.info(() => `Debug session '${activeDebugSession.name}' is alredy active`);
deferredDebugSessionExecution.start(activeDebugSession);
this.activeDebugSession = activeDebugSession;
} else {
const debugStartSubscription: Disposable = debug.onDidStartDebugSession(session => {
if (session.name === debuggerConfigName) {
this.logger.info(() => `Debug session '${session.name}' has started`);
deferredDebugSessionExecution.start(session);
this.activeDebugSession = session;
}
});
debugSessionExecution.started().finally(() => debugStartSubscription.dispose());
debug.startDebugging(workspaceFolder, actualDebuggerNameOrConfig).then(
isSessionStarted => {
if (!isSessionStarted) {
deferredDebugSessionExecution.fail(`Debug session '${debuggerConfigName}' failed to start`);
}
},
reason =>
deferredDebugSessionExecution.fail(
`Debug session '${debuggerConfigName}' failed to start: ${reason.message ?? reason}`
)
);
deferredDebugSessionExecution.failIfNotStarted(
sessionStartTimeout,
`Timeout after waiting ${sessionStartTimeout} ms for debug session '${debuggerConfigName}' to start`
);
}
debugSessionExecution.started().then(debugSession => {
const debugStopSubscription = debug.onDidTerminateDebugSession(session => {
if (session === debugSession) {
this.logger.info(() => `Debug session '${session.name}' has ended`);
deferredDebugSessionExecution.end();
this.activeDebugSession = undefined;
debugStopSubscription.dispose();
}
});
});
} catch (error) {
deferredDebugSessionExecution.fail(`Debug session '${debuggerConfigName}' failed to start: ${error}`);
}
return debugSessionExecution;
}
Example #10
Source File: extension-config.test.ts From karma-test-explorer with MIT License | 4 votes |
describe('ExtensionConfig', () => {
let mockLogger: MockProxy<Logger>;
let mockConfigValues: Map<string, any>;
let mockConfigDefaults: Map<string, any>;
let mockConfigStore: ConfigStore;
beforeEach(() => {
mockLogger = mock<Logger>();
mockConfigValues = new Map();
mockConfigDefaults = new Map();
mockConfigValues.set(WorkspaceConfigSetting.TestFiles, []);
mockConfigValues.set(WorkspaceConfigSetting.ExcludeFiles, []);
mockConfigValues.set(WorkspaceConfigSetting.ReloadOnChangedFiles, []);
mockConfigStore = {
has: mockConfigValues.has,
get: key => (mockConfigValues.has(key) ? mockConfigValues.get(key) : ''),
inspect: key => (mockConfigDefaults.has(key) ? { defaultValue: mockConfigDefaults.get(key) } : undefined)
};
});
describe('`karmaConfFilePath` setting', () => {
describe('when set to a relative path', () => {
const karmaConfFilePath = 'relative/fake/path/to/karma/conf';
beforeEach(() => {
mockConfigValues.set(WorkspaceConfigSetting.KarmaConfFilePath, karmaConfFilePath);
});
describe('when a non-blank project root path is set', () => {
const projectRootPath = 'fake/project/root/path';
beforeEach(() => {
mockConfigValues.set(WorkspaceConfigSetting.ProjectRootPath, projectRootPath);
});
it('is relative to the workspace path and configured project root path', () => {
const workspacePath = '/fake/workspace/path';
const extensionConfig = withUnixPaths(new ExtensionConfig(mockConfigStore, workspacePath, mockLogger));
expect(extensionConfig.userKarmaConfFilePath).toEqual(
`${workspacePath}/${projectRootPath}/${karmaConfFilePath}`
);
});
});
describe('when no project root path is set', () => {
const projectRootPath = '';
beforeEach(() => {
mockConfigValues.set(WorkspaceConfigSetting.ProjectRootPath, projectRootPath);
});
it('is located at the workspace path', () => {
const workspacePath = '/fake/workspace/path';
const extensionConfig = withUnixPaths(new ExtensionConfig(mockConfigStore, workspacePath, mockLogger));
expect(extensionConfig.userKarmaConfFilePath).toEqual(`${workspacePath}/${karmaConfFilePath}`);
});
});
});
describe('when set to an absolute path', () => {
const karmaConfFilePath = '/absolute/fake/path/to/karma/conf';
beforeEach(() => {
mockConfigValues.set(WorkspaceConfigSetting.KarmaConfFilePath, karmaConfFilePath);
});
it('is the configured absolute path regardless of workspace and project root path', () => {
const workspacePath = '/fake/workspace/path';
const projectRootPath = 'fake/project/root/path';
mockConfigValues.set(WorkspaceConfigSetting.ProjectRootPath, projectRootPath);
const extensionConfig = withUnixPaths(new ExtensionConfig(mockConfigStore, workspacePath, mockLogger));
expect(extensionConfig.userKarmaConfFilePath).toEqual(`${karmaConfFilePath}`);
});
});
});
describe('`customLauncher` setting', () => {
let customLauncherConfig: CustomLauncher;
let customLauncherConfigDefault: CustomLauncher;
beforeEach(() => {
customLauncherConfig = { base: '', flags: [] };
mockConfigValues.set(WorkspaceConfigSetting.CustomLauncher, customLauncherConfig);
customLauncherConfigDefault = { base: '', flags: [] };
mockConfigDefaults.set(WorkspaceConfigSetting.CustomLauncher, customLauncherConfigDefault);
});
describe('when has a `base` that is same as the default', () => {
beforeEach(() => {
customLauncherConfigDefault.base = 'randomDefaultBaseLauncherName';
customLauncherConfig.base = customLauncherConfigDefault.base;
});
describe('and the `debuggerConfig` setting', () => {
let debuggerConfig: DebugConfiguration;
let debuggerConfigDefault: DebugConfiguration;
beforeEach(() => {
debuggerConfig = { name: '', type: '', request: '' };
mockConfigValues.set(WorkspaceConfigSetting.DebuggerConfig, debuggerConfig);
debuggerConfigDefault = { name: '', type: '', request: '' };
mockConfigDefaults.set(WorkspaceConfigSetting.DebuggerConfig, debuggerConfigDefault);
});
describe('has a `type` that is same as the default', () => {
beforeEach(() => {
debuggerConfigDefault.type = 'fake-debugger-type';
debuggerConfig.type = debuggerConfigDefault.type;
});
it('uses the `remote-debugging-port` launcher flag value as the default debug port if present', () => {
customLauncherConfig.flags = ['--remote-debugging-port=1234'];
const extensionConfig = withUnixPaths(
new ExtensionConfig(mockConfigStore, '/fake/workspace/path', mockLogger)
);
expect(extensionConfig.defaultDebugPort).toEqual(1234);
});
it('uses port 9222 as the default debug port if `remote-debugging-port` launcher flag is not present', () => {
customLauncherConfig.flags = [];
const extensionConfig = withUnixPaths(
new ExtensionConfig(mockConfigStore, '/fake/workspace/path', mockLogger)
);
expect(extensionConfig.defaultDebugPort).toEqual(9222);
});
});
describe('has a `type` that is different from the default', () => {
beforeEach(() => {
debuggerConfigDefault.type = 'fake-debugger-type';
debuggerConfig.type = 'different-fake-debugger-type';
});
it('does not set a default debug port if the `remote-debugging-port` launcher flag is present', () => {
customLauncherConfig.flags = ['--remote-debugging-port=1234'];
const extensionConfig = withUnixPaths(
new ExtensionConfig(mockConfigStore, '/fake/workspace/path', mockLogger)
);
expect(extensionConfig.defaultDebugPort).not.toBeDefined();
});
it('does not default to port 9222 if the `remote-debugging-port` launcher flag is not present', () => {
customLauncherConfig.flags = [];
const extensionConfig = withUnixPaths(
new ExtensionConfig(mockConfigStore, '/fake/workspace/path', mockLogger)
);
expect(extensionConfig.defaultDebugPort).not.toBeDefined();
});
});
});
});
describe('when has a `base` that is different from the default', () => {
beforeEach(() => {
customLauncherConfigDefault.base = 'randomDefaultBaseLauncherName';
customLauncherConfig.base = 'differentDefaultBaseLauncherName';
});
it('does not set a default debug port if the `remote-debugging-port` launcher flag is present', () => {
customLauncherConfig.flags = ['--remote-debugging-port=1234'];
const extensionConfig = withUnixPaths(new ExtensionConfig(mockConfigStore, '/fake/workspace/path', mockLogger));
expect(extensionConfig.defaultDebugPort).not.toBeDefined();
});
it('does not default to port 9222 if the `remote-debugging-port` launcher flag is not present', () => {
customLauncherConfig.flags = [];
const extensionConfig = withUnixPaths(new ExtensionConfig(mockConfigStore, '/fake/workspace/path', mockLogger));
expect(extensionConfig.defaultDebugPort).not.toBeDefined();
});
});
});
describe('when the `containerMode` setting is `enabled`', () => {
beforeEach(() => {
mockConfigValues.set(WorkspaceConfigSetting.ContainerMode, 'enabled');
});
describe('and a custom launcher', () => {
let customLauncherConfig: CustomLauncher;
beforeEach(() => {
customLauncherConfig = { base: '', flags: [] };
mockConfigValues.set(WorkspaceConfigSetting.CustomLauncher, customLauncherConfig);
});
describe('is configured with a base launcher name that contains the string "chrome" in any casing', () => {
beforeEach(() => {
customLauncherConfig.base = 'randomChRoMeBasedBrowser';
});
it('adds a `--no-sandbox` flag to the launcher', () => {
customLauncherConfig.flags = ['some-random-flag'];
const extensionConfig = withUnixPaths(
new ExtensionConfig(mockConfigStore, '/fake/workspace/path', mockLogger)
);
expect(extensionConfig.customLauncher).toEqual(
expect.objectContaining({ flags: ['some-random-flag', '--no-sandbox'] })
);
});
it('does not add duplicate `--no-sandbox` flag when the configured launcher already has the flag', () => {
customLauncherConfig.flags = ['--no-sandbox', 'random-other-flag'];
const extensionConfig = withUnixPaths(
new ExtensionConfig(mockConfigStore, '/fake/workspace/path', mockLogger)
);
expect(extensionConfig.customLauncher).toEqual(
expect.objectContaining({ flags: ['--no-sandbox', 'random-other-flag'] })
);
});
});
describe('is configured with a base launcher name that does not contain the string "chrome"', () => {
beforeEach(() => {
customLauncherConfig.base = 'randomBaseLauncher';
});
it('does not add the `--no-sandbox` flag when', () => {
const extensionConfig = withUnixPaths(
new ExtensionConfig(mockConfigStore, '/fake/workspace/path', mockLogger)
);
expect(extensionConfig.customLauncher).toEqual(
expect.not.objectContaining({ flags: expect.arrayContaining(['--no-sandbox']) })
);
});
it('does not remove or alter any of the configured flags', () => {
customLauncherConfig.flags = ['--random-flag-one', 'randomFlagTwo', '-f3'];
const extensionConfig = withUnixPaths(
new ExtensionConfig(mockConfigStore, '/fake/workspace/path', mockLogger)
);
expect(extensionConfig.customLauncher).toEqual(
expect.objectContaining({ flags: ['--random-flag-one', 'randomFlagTwo', '-f3'] })
);
});
});
});
});
describe('when the `excludeFiles` setting is configured', () => {
let configuredExcludeFiles: string[];
beforeEach(() => {
configuredExcludeFiles = [];
mockConfigValues.set(WorkspaceConfigSetting.ExcludeFiles, configuredExcludeFiles);
});
it('includes the node_modules folder if it was not included in the configured exclusion list', () => {
configuredExcludeFiles = ['fake/exclusion/glob'];
const extensionConfig = withUnixPaths(new ExtensionConfig(mockConfigStore, '/fake/workspace/path', mockLogger));
expect(extensionConfig.excludeFiles).toEqual(expect.arrayContaining(['**/node_modules/**/*']));
});
it('retains the node_modules folder if it was included in the configured exclusion list', () => {
configuredExcludeFiles = ['fake/exclusion/glob/1', '**/node_modules/**/*', 'fake/exclusion/glob/2'];
const extensionConfig = withUnixPaths(new ExtensionConfig(mockConfigStore, '/fake/workspace/path', mockLogger));
expect(extensionConfig.excludeFiles).toEqual(expect.arrayContaining(['**/node_modules/**/*']));
});
});
});