diff --git a/examples/browser/package.json b/examples/browser/package.json index 2fa43a2721bf0..ecf63fe98d82d 100644 --- a/examples/browser/package.json +++ b/examples/browser/package.json @@ -19,7 +19,6 @@ "@theia/core": "^0.10.0", "@theia/cpp": "^0.10.0", "@theia/debug": "^0.10.0", - "@theia/debug-nodejs": "^0.10.0", "@theia/editor": "^0.10.0", "@theia/editor-preview": "^0.10.0", "@theia/editorconfig": "^0.10.0", @@ -28,7 +27,6 @@ "@theia/getting-started": "^0.10.0", "@theia/git": "^0.10.0", "@theia/java": "^0.10.0", - "@theia/java-debug": "^0.10.0", "@theia/json": "^0.10.0", "@theia/keymaps": "^0.10.0", "@theia/languages": "^0.10.0", diff --git a/examples/electron/package.json b/examples/electron/package.json index 86017ecf93e51..28d78800cc86f 100644 --- a/examples/electron/package.json +++ b/examples/electron/package.json @@ -17,7 +17,6 @@ "@theia/core": "^0.10.0", "@theia/cpp": "^0.10.0", "@theia/debug": "^0.10.0", - "@theia/debug-nodejs": "^0.10.0", "@theia/editor": "^0.10.0", "@theia/editor-preview": "^0.10.0", "@theia/editorconfig": "^0.10.0", @@ -26,7 +25,6 @@ "@theia/getting-started": "^0.10.0", "@theia/git": "^0.10.0", "@theia/java": "^0.10.0", - "@theia/java-debug": "^0.10.0", "@theia/json": "^0.10.0", "@theia/keymaps": "^0.10.0", "@theia/languages": "^0.10.0", diff --git a/packages/debug-nodejs/.gitignore b/packages/debug-nodejs/.gitignore deleted file mode 100644 index d3a4c58190359..0000000000000 --- a/packages/debug-nodejs/.gitignore +++ /dev/null @@ -1 +0,0 @@ -download diff --git a/packages/debug-nodejs/README.md b/packages/debug-nodejs/README.md deleted file mode 100644 index 42afb55dfb345..0000000000000 --- a/packages/debug-nodejs/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Theia - NodeJS Debug Extension - -See [here](https://www.theia-ide.org/doc/index.html) for a detailed documentation. - -## License -- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/) -- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp) diff --git a/packages/debug-nodejs/compile.tsconfig.json b/packages/debug-nodejs/compile.tsconfig.json deleted file mode 100644 index a23513b5e6b13..0000000000000 --- a/packages/debug-nodejs/compile.tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../configs/base.tsconfig", - "compilerOptions": { - "rootDir": "src", - "outDir": "lib" - }, - "include": [ - "src" - ] -} diff --git a/packages/debug-nodejs/package.json b/packages/debug-nodejs/package.json deleted file mode 100644 index efab37e4ffd3d..0000000000000 --- a/packages/debug-nodejs/package.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "name": "@theia/debug-nodejs", - "version": "0.10.0", - "description": "Theia - NodeJS Debug Extension", - "dependencies": { - "@theia/debug": "^0.10.0", - "ps-list": "5.0.1", - "vscode-debugprotocol": "^1.32.0" - }, - "publishConfig": { - "access": "public" - }, - "theiaExtensions": [ - { - "backend": "lib/node/debug-nodejs-backend-module" - } - ], - "keywords": [ - "theia-extension", - "debug", - "nodejs" - ], - "license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0", - "repository": { - "type": "git", - "url": "https://github.com/theia-ide/theia.git" - }, - "bugs": { - "url": "https://github.com/theia-ide/theia/issues" - }, - "homepage": "https://github.com/theia-ide/theia", - "files": [ - "lib", - "src", - "scripts" - ], - "scripts": { - "postinstall": "download-debug-adapters", - "prepare": "yarn run clean && yarn run build", - "clean": "theiaext clean", - "build": "theiaext build", - "watch": "theiaext watch", - "test": "theiaext test" - }, - "devDependencies": { - "@theia/ext-scripts": "^0.10.0" - }, - "nyc": { - "extends": "../../configs/nyc.json" - }, - "adapters": { - "node-debug": "https://ms-vscode.gallery.vsassets.io/_apis/public/gallery/publisher/ms-vscode/extension/node-debug/1.35.3/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage", - "node-debug2": "https://ms-vscode.gallery.vsassets.io/_apis/public/gallery/publisher/ms-vscode/extension/node-debug2/1.33.0/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage" - } -} diff --git a/packages/debug-nodejs/src/node/debug-nodejs-backend-module.ts b/packages/debug-nodejs/src/node/debug-nodejs-backend-module.ts deleted file mode 100644 index 80713b2912fab..0000000000000 --- a/packages/debug-nodejs/src/node/debug-nodejs-backend-module.ts +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************** - * Copyright (C) 2018 Red Hat, Inc. and others. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the Eclipse - * Public License v. 2.0 are satisfied: GNU General Public License, version 2 - * with the GNU Classpath Exception which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - ********************************************************************************/ - -import { ContainerModule } from 'inversify'; -import { DebugAdapterContribution } from '@theia/debug/lib/common/debug-model'; -import { NodeDebugAdapterContribution, Node2DebugAdapterContribution } from './node-debug-adapter-contribution'; - -export default new ContainerModule(bind => { - bind(DebugAdapterContribution).to(NodeDebugAdapterContribution).inSingletonScope(); - bind(DebugAdapterContribution).to(Node2DebugAdapterContribution).inSingletonScope(); -}); diff --git a/packages/debug-nodejs/src/node/debug-nodejs.spec.ts b/packages/debug-nodejs/src/node/debug-nodejs.spec.ts deleted file mode 100644 index 81c1a4618d237..0000000000000 --- a/packages/debug-nodejs/src/node/debug-nodejs.spec.ts +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************** - * Copyright (C) 2018 Red Hat, Inc. and others. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the Eclipse - * Public License v. 2.0 are satisfied: GNU General Public License, version 2 - * with the GNU Classpath Exception which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - ********************************************************************************/ - -describe('node-debug package', () => { - - it('support code coverage statistics', () => true); -}); diff --git a/packages/debug-nodejs/src/node/node-debug-adapter-contribution.ts b/packages/debug-nodejs/src/node/node-debug-adapter-contribution.ts deleted file mode 100644 index 756f070bf23ee..0000000000000 --- a/packages/debug-nodejs/src/node/node-debug-adapter-contribution.ts +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************** - * Copyright (C) 2018 TypeFox and others. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the Eclipse - * Public License v. 2.0 are satisfied: GNU General Public License, version 2 - * with the GNU Classpath Exception which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - ********************************************************************************/ - -import * as path from 'path'; -const psList: () => Promise<[{ pid: number, cmd: string }]> = require('ps-list'); // FIXME use import, provide proper d.ts file -import { injectable } from 'inversify'; -// tslint:disable-next-line:no-implicit-dependencies -import { FileUri } from '@theia/core/lib/node'; -import { DebugConfiguration } from '@theia/debug/lib/common/debug-configuration'; -import { AbstractVSCodeDebugAdapterContribution } from '@theia/debug/lib/node/vscode/vscode-debug-adapter-contribution'; - -export const INSPECTOR_PORT_DEFAULT = 9229; -export const LEGACY_PORT_DEFAULT = 5858; - -@injectable() -export class NodeDebugAdapterContribution extends AbstractVSCodeDebugAdapterContribution { - constructor() { - super( - 'node', - path.join(__dirname, '../../download/node-debug/extension') - ); - } - - // TODO: construct based on package.json of the given workspace - provideDebugConfigurations(workspaceFolderUri?: string): DebugConfiguration[] { - return [{ - type: this.type, - request: 'attach', - name: 'Debug (Attach)', - processId: '' - }]; - } - - // TODO: align with vscode-node-debug - async resolveDebugConfiguration(config: DebugConfiguration, workspaceFolderUri?: string): Promise { - if (!config.cwd && !!workspaceFolderUri) { - config.cwd = FileUri.fsPath(workspaceFolderUri); - } - if (!config.cwd) { - config.cwd = '${workspaceFolder}'; - } - if (config.request === 'attach' && typeof config.processId === 'string') { - await this.resolveAttachConfiguration(config); - } - config.type = await this.resolveDebugType(config); - return config; - } - - protected async resolveDebugType(config: DebugConfiguration): Promise { - if (config.protocol === 'legacy') { - return 'node'; - } - if (config.protocol === 'inspector') { - return 'node2'; - } - // TODO: auto detect - return 'node2'; - } - - // TODO: align with vscode-node-debug - protected async resolveAttachConfiguration(config: DebugConfiguration): Promise { - config.protocol = 'inspector'; - config.port = 9229; - - const pidToDebug = Number.parseInt(config.processId); - - const tasks = await psList(); - const taskToDebug = tasks.find(task => task.pid === pidToDebug); - if (taskToDebug) { - const matches = /--(inspect|debug)-port=(\d+)/.exec(taskToDebug.cmd); - if (matches && matches.length === 3) { - config.port = parseInt(matches[2]); - config.protocol = matches[1] === 'debug' ? 'legacy' : 'inspector'; - } - } - - delete config.processId; - } -} - -@injectable() -export class Node2DebugAdapterContribution extends AbstractVSCodeDebugAdapterContribution { - constructor() { - super( - 'node2', - path.join(__dirname, '../../download/node-debug2/extension') - ); - } -} diff --git a/packages/debug/README.md b/packages/debug/README.md index 9395201412bf0..79fbc381aad9c 100644 --- a/packages/debug/README.md +++ b/packages/debug/README.md @@ -16,13 +16,11 @@ In most cases the default behavior of the `DebugSession` is enough. But it is po ### Server side At the back-end we start a debug adapter using `DebugAdapterFactory` and then a `DebugAdapterSession` is instantiated which works as a proxy between client and debug adapter. If a default implementation of the debug adapter session does not fit needs, it is possible to provide its own implementation using `DebugAdapterSessionFactory`. If so, it is recommended to extend the default implementation of the `DebugAdapterSession`. Documented model objects are located [here](https://github.com/theia-ide/theia/tree/master/packages/debug/src/node/debug-model.ts) -`DebugSessionState` accumulates debug adapter events and is used to restore debug session on the client side when page is refreshed. +`DebugSessionState` accumulates debug adapter events and is used to restore debug session on the client side when page is refreshed. ## How to contribute a new debugger `DebugAdapterContribution` is a contribution point for all debug adapters to provide and resolve debug configuration. -Here is an example of [debug adapter contribution for node](https://github.com/theia-ide/theia/tree/master/packages/debug-nodejs/src/node/debug-nodejs.ts) - ## References * [Debug Adapter Protocol](https://github.com/Microsoft/vscode-debugadapter-node/blob/master/protocol/src/debugProtocol.ts) * [VS Code debug API](https://code.visualstudio.com/docs/extensionAPI/api-debugging) diff --git a/packages/java-debug/.gitignore b/packages/java-debug/.gitignore deleted file mode 100644 index d3a4c58190359..0000000000000 --- a/packages/java-debug/.gitignore +++ /dev/null @@ -1 +0,0 @@ -download diff --git a/packages/java-debug/README.md b/packages/java-debug/README.md deleted file mode 100644 index 24cb4e80f8a1a..0000000000000 --- a/packages/java-debug/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Theia - Java Debug Extension - -See [here](https://www.theia-ide.org/doc/index.html) for a detailed documentation. - -## License -- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/) -- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp) diff --git a/packages/java-debug/compile.tsconfig.json b/packages/java-debug/compile.tsconfig.json deleted file mode 100644 index a23513b5e6b13..0000000000000 --- a/packages/java-debug/compile.tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../configs/base.tsconfig", - "compilerOptions": { - "rootDir": "src", - "outDir": "lib" - }, - "include": [ - "src" - ] -} diff --git a/packages/java-debug/package.json b/packages/java-debug/package.json deleted file mode 100644 index 9655df4025006..0000000000000 --- a/packages/java-debug/package.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "name": "@theia/java-debug", - "version": "0.10.0", - "description": "Theia - Java Debug Extension", - "dependencies": { - "@theia/debug": "^0.10.0", - "@theia/java": "^0.10.0", - "lodash": "^4.17.10" - }, - "publishConfig": { - "access": "public" - }, - "theiaExtensions": [ - { - "frontend": "lib/browser/java-debug-frontend-module", - "backend": "lib/node/java-debug-backend-module" - } - ], - "keywords": [ - "theia-extension", - "debug", - "java" - ], - "license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0", - "repository": { - "type": "git", - "url": "https://github.com/theia-ide/theia.git" - }, - "bugs": { - "url": "https://github.com/theia-ide/theia/issues" - }, - "homepage": "https://github.com/theia-ide/theia", - "files": [ - "lib", - "src", - "scripts" - ], - "scripts": { - "postinstall": "download-debug-adapters", - "prepare": "yarn run clean && yarn run build", - "clean": "theiaext clean", - "build": "theiaext build", - "watch": "theiaext watch", - "test": "theiaext test" - }, - "devDependencies": { - "@theia/ext-scripts": "^0.10.0" - }, - "nyc": { - "extends": "../../configs/nyc.json" - }, - "adapters": { - "java-debug": "https://ms-vscode.gallery.vsassets.io/_apis/public/gallery/publisher/vscjava/extension/vscode-java-debug/0.15.0/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage" - } -} diff --git a/packages/java-debug/src/browser/java-debug-frontend-contribution.ts b/packages/java-debug/src/browser/java-debug-frontend-contribution.ts deleted file mode 100644 index 1fec3f790a2e9..0000000000000 --- a/packages/java-debug/src/browser/java-debug-frontend-contribution.ts +++ /dev/null @@ -1,296 +0,0 @@ -/******************************************************************************** - * Copyright (C) 2018 TypeFox and others. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the Eclipse - * Public License v. 2.0 are satisfied: GNU General Public License, version 2 - * with the GNU Classpath Exception which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - ********************************************************************************/ - -import * as _ from 'lodash'; -import { injectable, inject } from 'inversify'; -// tslint:disable:no-implicit-dependencies -import { Range, CodeLens } from 'vscode-languageserver-types'; -import URI from '@theia/core/lib/common/uri'; -import { MessageService, CommandContribution, CommandRegistry, Command, DisposableCollection } from '@theia/core/lib/common'; -import { FrontendApplicationContribution, } from '@theia/core/lib/browser'; -import { Workspace, Languages } from '@theia/languages/lib/browser'; -import { WorkspaceService } from '@theia/workspace/lib/browser'; -// tslint:enable:no-implicit-dependencies -import { DebugConfiguration } from '@theia/debug/lib/common/debug-common'; -import { DebugSession } from '@theia/debug/lib/browser/debug-session'; -import { DebugSessionManager } from '@theia/debug/lib/browser/debug-session-manager'; -import { DebugConfigurationManager } from '@theia/debug/lib/browser/debug-configuration-manager'; -import { JavaDebugPreferences } from './java-debug-preferences'; - -enum HcrChangeType { - ERROR = 'ERROR', - WARNING = 'WARNING', - STARTING = 'STARTING', - END = 'END', - BUILD_COMPLETE = 'BUILD_COMPLETE', -} - -enum LogLevel { - FINE = 'FINE', - INFO = 'INFO', - SEVERE = 'SEVERE', - WARNING = 'WARNING' -} - -export namespace JavaDebugCommands { - export const RUN: Command = { - id: 'java.debug.run' - }; - export const DEBUG: Command = { - id: 'java.debug.debug' - }; - export const RESOLVE_MAIN_METHOD = 'vscode.java.resolveMainMethod'; -} - -export namespace JavaDebugSession { - export function is(session: DebugSession): boolean { - return session.configuration.type === 'java'; - } -} - -interface JavaMainMethod { - range: Range; - mainClass: string; - projectName: string; -} - -@injectable() -export class JavaDebugFrontendContribution implements FrontendApplicationContribution, CommandContribution { - - @inject(Workspace) - protected readonly workspace: Workspace; - - @inject(Languages) - protected readonly languages: Languages; - - @inject(CommandRegistry) - protected readonly commands: CommandRegistry; - - @inject(MessageService) - protected readonly messages: MessageService; - - @inject(DebugSessionManager) - protected readonly sessions: DebugSessionManager; - - @inject(JavaDebugPreferences) - protected readonly preferences: JavaDebugPreferences; - - @inject(WorkspaceService) - protected readonly workspaceService: WorkspaceService; - - @inject(DebugConfigurationManager) - protected readonly configurations: DebugConfigurationManager; - - protected readonly suppressedReasons = new Set(); - - initialize(): void { - this.updateRunDebugCodeLens(); - this.preferences.onPreferenceChanged(({ preferenceName }) => { - if (preferenceName === 'java.debug.settings.enableRunDebugCodeLens') { - this.updateRunDebugCodeLens(); - } - }); - this.sessions.onDidCreateDebugSession(session => { - if (JavaDebugSession.is(session) && this.sessions.sessions.filter(JavaDebugSession.is).length === 1) { - this.updateDebugSettings(); - } - }); - this.sessions.onDidReceiveDebugSessionCustomEvent(({ session, event, body }) => { - if (session.configuration.type !== 'java') { - return; - } - if (event === 'hotcodereplace' && body) { - return this.applyCodeChanges(session, body); - } - if (event === 'usernotification' && body) { - return this.handleUserNotification(body); - } - }); - this.sessions.onDidDestroyDebugSession(session => { - if (session.configuration.type === 'java') { - this.suppressedReasons.clear(); - } - }); - const { configurations } = this.workspace; - if (configurations) { - configurations.onDidChangeConfiguration(e => { - if (e.affectsConfiguration('java.debug')) { - this.dirtyDebugSettings = true; - if (this.sessions.sessions.some(JavaDebugSession.is)) { - this.updateDebugSettings(); - } - } - }); - } - } - - registerCommands(commands: CommandRegistry): void { - commands.registerCommand(JavaDebugCommands.RUN, { - execute: (mainClass, projectName, uri) => this.runProgram(mainClass, projectName, uri) - }); - commands.registerCommand(JavaDebugCommands.DEBUG, { - execute: (mainClass, projectName, uri) => this.runProgram(mainClass, projectName, uri, false) - }); - } - - protected readonly toDisposeRunDebugCodeLens = new DisposableCollection(); - protected updateRunDebugCodeLens(): void { - if (this.preferences['java.debug.settings.enableRunDebugCodeLens'] && this.toDisposeRunDebugCodeLens.disposed) { - if (this.languages.registerCodeLensProvider) { - this.toDisposeRunDebugCodeLens.push(this.languages.registerCodeLensProvider([{ language: 'java' }], { - provideCodeLenses: async params => { - if (!this.commands.isEnabled(JavaDebugCommands.RESOLVE_MAIN_METHOD)) { - return []; - } - try { - const uri = params.textDocument.uri; - const mainMethods = await this.commands.executeCommand(JavaDebugCommands.RESOLVE_MAIN_METHOD, uri) || []; - return _.flatten(mainMethods.map(method => [ - { - range: method.range, - command: { - title: '▶ Run', - command: JavaDebugCommands.RUN.id, - arguments: [method.mainClass, method.projectName, uri] - } - }, - { - range: method.range, - command: { - title: '🐞 Debug', - command: JavaDebugCommands.DEBUG.id, - arguments: [method.mainClass, method.projectName, uri] - } - } - ])); - } catch (e) { - console.error(e); - return []; - } - - } - })); - } - } else { - this.toDisposeRunDebugCodeLens.dispose(); - } - } - - protected async runProgram(mainClass: string, projectName: string, uri: string, noDebug: boolean = true): Promise { - const workspaceFolder = this.workspaceService.getWorkspaceRootUri(new URI(uri)); - const workspaceFolderUri = workspaceFolder && workspaceFolder.toString(); - const configuration = this.constructDebugConfig(mainClass, projectName, workspaceFolderUri); - configuration.projectName = projectName; - configuration.noDebug = noDebug; - await this.sessions.start({ - configuration, - workspaceFolderUri - }); - } - protected constructDebugConfig(mainClass: string, projectName: string, workspaceFolderUri?: string): DebugConfiguration { - return _.cloneDeep(this.findConfiguration(mainClass, projectName).next().value || { - type: 'java', - name: `CodeLens (Launch) - ${mainClass.substr(mainClass.lastIndexOf('.') + 1)}`, - request: 'launch', - cwd: workspaceFolderUri ? '${workspaceFolder}' : undefined, - console: 'internalConsole', - stopOnEntry: false, - mainClass, - args: '', - projectName, - }); - } - protected * findConfiguration(mainClass: string, projectName: string): IterableIterator { - for (const option of this.configurations.all) { - const { configuration } = option; - if (configuration.mainClass === mainClass && _.toString(configuration.projectName) === _.toString(projectName)) { - yield configuration; - } - } - for (const option of this.configurations.all) { - const { configuration } = option; - if (configuration.mainClass === mainClass && !configuration.projectName) { - yield configuration; - } - } - } - - protected dirtyDebugSettings = true; - protected async updateDebugSettings(): Promise { - if (!this.dirtyDebugSettings) { - return; - } - this.dirtyDebugSettings = false; - const { configurations } = this.workspace; - if (configurations) { - const configuration = configurations.getConfiguration('java.debug'); - const logLevel = this.convertLogLevel(configuration.logLevel || ''); - if (configuration.settings && Object.keys(configuration.settings).length) { - await this.commands.executeCommand('vscode.java.updateDebugSettings', JSON.stringify({ - ...configuration.settings, logLevel - })); - } - } - } - protected convertLogLevel(commonLogLevel: string): LogLevel { - // convert common log level to java log level - switch (commonLogLevel.toLowerCase()) { - case 'verbose': - return LogLevel.FINE; - case 'warn': - return LogLevel.WARNING; - case 'error': - return LogLevel.SEVERE; - case 'info': - return LogLevel.INFO; - default: - return LogLevel.FINE; - } - } - - protected async applyCodeChanges(session: DebugSession, { changeType, message }: { changeType?: HcrChangeType, message: string }): Promise { - if (changeType === HcrChangeType.BUILD_COMPLETE) { - this.messages.info('Applying code changes...'); - session.sendCustomRequest('redefineClasses'); - return; - } - if (changeType === HcrChangeType.ERROR || changeType === HcrChangeType.WARNING) { - if (this.suppressedReasons.has(message)) { - return; - } - const response = await this.messages.error( - `Hot code replace failed - ${message}. Would you like to restart the debug session?`, - 'Yes', 'No', 'Not show again' - ); - if (response === 'Not show again') { - this.suppressedReasons.add(message); - } else if (response === 'Yes') { - this.sessions.restart(session); - } - } - } - - protected async handleUserNotification({ notificationType, message }: { notificationType?: string, message: string }): Promise { - if (notificationType === 'ERROR') { - await this.messages.error(message); - } else if (notificationType === 'WARNING') { - await this.messages.warn(message); - } else { - await this.messages.info(message); - } - } - -} diff --git a/packages/java-debug/src/browser/java-debug-frontend-module.ts b/packages/java-debug/src/browser/java-debug-frontend-module.ts deleted file mode 100644 index 83ac17166e7ed..0000000000000 --- a/packages/java-debug/src/browser/java-debug-frontend-module.ts +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************** - * Copyright (C) 2018 TypeFox and others. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the Eclipse - * Public License v. 2.0 are satisfied: GNU General Public License, version 2 - * with the GNU Classpath Exception which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - ********************************************************************************/ - -import { ContainerModule } from 'inversify'; -// tslint:disable:no-implicit-dependencies -import { CommandContribution } from '@theia/core/lib/common'; -import { FrontendApplicationContribution } from '@theia/core/lib/browser'; -// tslint:enable:no-implicit-dependencies -import { bindJavaDebugPreferences } from './java-debug-preferences'; -import { JavaDebugFrontendContribution } from './java-debug-frontend-contribution'; - -export default new ContainerModule(bind => { - bindJavaDebugPreferences(bind); - bind(JavaDebugFrontendContribution).toSelf().inSingletonScope(); - bind(CommandContribution).toService(JavaDebugFrontendContribution); - bind(FrontendApplicationContribution).toService(JavaDebugFrontendContribution); -}); diff --git a/packages/java-debug/src/browser/java-debug-preferences.ts b/packages/java-debug/src/browser/java-debug-preferences.ts deleted file mode 100644 index a8ce2f5af272c..0000000000000 --- a/packages/java-debug/src/browser/java-debug-preferences.ts +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************** - * Copyright (C) 2018 TypeFox and others. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the Eclipse - * Public License v. 2.0 are satisfied: GNU General Public License, version 2 - * with the GNU Classpath Exception which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - ********************************************************************************/ - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -// https://github.com/Microsoft/vscode-java-debug/blob/bcd69b52e4d941323cae662a154afd2a7852f43d/package.json#L353-L405 adjusted to Theia APIs - -import { interfaces } from 'inversify'; -import { - createPreferenceProxy, - PreferenceProxy, - PreferenceService, - PreferenceContribution, - PreferenceSchema, - PreferenceChangeEvent - // tslint:disable-next-line:no-implicit-dependencies -} from '@theia/core/lib/browser/preferences'; - -export const javaDebugPreferenceSchema: PreferenceSchema = { - 'type': 'object', - 'properties': { - 'java.debug.logLevel': { - 'type': 'string', - 'default': 'warn', - 'description': 'Minimum level of debugger logs.', - 'enum': [ - 'error', - 'warn', - 'info', - 'verbose' - ] - }, - 'java.debug.settings.showHex': { - 'type': 'boolean', - 'description': 'Show numbers in hex format in \"Variables\" viewlet.', - 'default': false - }, - 'java.debug.settings.showStaticVariables': { - 'type': 'boolean', - 'description': 'Show static variables in \"Variables\" viewlet.', - 'default': true - }, - 'java.debug.settings.showQualifiedNames': { - 'type': 'boolean', - 'description': 'Show fully qualified class names in \"Variables\" viewlet.', - 'default': false - }, - 'java.debug.settings.maxStringLength': { - 'type': 'number', - // tslint:disable-next-line:max-line-length - 'description': 'The maximum length of strings displayed in \"Variables\" or \"Debug Console\" viewlet, strings longer than this length will be trimmed, if 0 no trim is performed.', - 'default': 0 - }, - 'java.debug.settings.enableHotCodeReplace': { - 'type': 'boolean', - 'description': 'Enable hot code replace for Java code.', - 'default': true - }, - 'java.debug.settings.enableRunDebugCodeLens': { - 'type': 'boolean', - 'description': 'Enable the run and debug code lens providers over main methods.', - 'default': true - } - } -}; - -export interface JavaDebugConfiguration { - 'java.debug.logLevel'?: 'error' | 'warn' | 'info' | 'verbose' - 'java.debug.settings.showHex': boolean - 'java.debug.settings.showStaticVariables': boolean - 'java.debug.settings.showQualifiedNames': boolean - 'java.debug.settings.maxStringLength': number - 'java.debug.settings.enableHotCodeReplace': boolean - 'java.debug.settings.enableRunDebugCodeLens': boolean -} -export type JavaDebugPreferenceChange = PreferenceChangeEvent; - -export const JavaDebugPreferences = Symbol('JavaDebugPreferences'); -export type JavaDebugPreferences = PreferenceProxy; - -export function createJavaDebugPreferences(preferences: PreferenceService): JavaDebugPreferences { - return createPreferenceProxy(preferences, javaDebugPreferenceSchema); -} - -export function bindJavaDebugPreferences(bind: interfaces.Bind): void { - bind(JavaDebugPreferences).toDynamicValue(ctx => { - const preferences = ctx.container.get(PreferenceService); - return createJavaDebugPreferences(preferences); - }).inSingletonScope(); - - bind(PreferenceContribution).toConstantValue({ schema: javaDebugPreferenceSchema }); -} diff --git a/packages/java-debug/src/node/java-debug-adapter-contribution.ts b/packages/java-debug/src/node/java-debug-adapter-contribution.ts deleted file mode 100644 index c25c4740744d4..0000000000000 --- a/packages/java-debug/src/node/java-debug-adapter-contribution.ts +++ /dev/null @@ -1,299 +0,0 @@ -/******************************************************************************** - * Copyright (C) 2018 TypeFox and others. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the Eclipse - * Public License v. 2.0 are satisfied: GNU General Public License, version 2 - * with the GNU Classpath Exception which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - ********************************************************************************/ - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -// https://github.com/Microsoft/vscode-java-debug/blob/master/src/configurationProvider.ts adjusted to Theia APIs - -// tslint:disable:no-any - -import * as path from 'path'; -import * as _ from 'lodash'; -import { injectable, inject } from 'inversify'; -import { DebugConfiguration } from '@theia/debug/lib/common/debug-configuration'; -import { JavaExtensionContribution } from '@theia/java/lib/node'; -// tslint:disable-next-line:no-implicit-dependencies -import { MessageService, CommandService } from '@theia/core/lib/common'; -// tslint:disable-next-line:no-implicit-dependencies -import { QuickPickService, QuickPickItem } from '@theia/core/lib/common/quick-pick-service'; -import { AbstractVSCodeDebugAdapterContribution } from '@theia/debug/lib/node/vscode/vscode-debug-adapter-contribution'; - -export namespace VSCodeJavaDebugCommands { - export const COMPILE_WORKSPACE = 'java.workspace.compile'; - export const RESOLVE_MAINCLASS = 'vscode.java.resolveMainClass'; - export const VALIDATE_LAUNCH_CONFIG = 'vscode.java.validateLaunchConfig'; - export const RESOLVE_CLASSPATH = 'vscode.java.resolveClasspath'; - export const START_DEBUG_SESSION = 'vscode.java.startDebugSession'; -} - -export interface MainClassOption { - readonly mainClass: string; - readonly projectName?: string; - readonly filePath?: string; -} - -interface ValidationResult { - readonly isValid: boolean; - readonly message?: string; -} - -interface LaunchValidationResponse { - readonly mainClass: ValidationResult; - readonly projectName: ValidationResult; - readonly proposals?: MainClassOption[]; -} - -@injectable() -export class JavaDebugExtensionContribution extends AbstractVSCodeDebugAdapterContribution implements JavaExtensionContribution { - - constructor() { - super( - 'java', - path.join(__dirname, '../../download/java-debug/extension') - ); - } - - async getExtensionBundles(): Promise { - const debuggerContribution: { - contributes: { javaExtensions: string[] } - // tslint:disable-next-line:no-any - } = (await this.pck); - return debuggerContribution.contributes.javaExtensions.map(javaExtPath => - path.resolve(this.extensionPath, javaExtPath) - ); - } -} - -@injectable() -export class JavaDebugAdapterContribution extends JavaDebugExtensionContribution { - - @inject(CommandService) - protected readonly commands: CommandService; - - @inject(MessageService) - protected readonly messages: MessageService; - - @inject(QuickPickService) - protected readonly quickPickService: QuickPickService; - - async provideDebugConfigurations(workspaceFolderUri?: string): Promise { - const items = await this.resolveMainClass(workspaceFolderUri); - const defaultLaunchConfig = { - type: 'java', - name: 'Debug (Launch)', - request: 'launch', - cwd: '${workspaceFolder}', - console: 'internalConsole', - stopOnEntry: false, - mainClass: '', - args: '', - }; - const cache = {}; - const launchConfigs = items.map(item => ({ - ...defaultLaunchConfig, - name: this.constructLaunchConfigName(item.mainClass, item.projectName, cache), - mainClass: item.mainClass, - projectName: item.projectName, - })); - const defaultAttachConfig = { - type: 'java', - name: 'Debug (Attach)', - request: 'attach', - hostName: 'localhost', - port: '', - }; - return [defaultLaunchConfig, ...launchConfigs, defaultAttachConfig]; - } - protected constructLaunchConfigName(mainClass: string, projectName: string | undefined, cache: { - [name: string]: number - }): string { - const prefix = 'Debug (Launch)-'; - let name = prefix + mainClass.substr(mainClass.lastIndexOf('.') + 1); - if (projectName !== undefined) { - name += `<${projectName}>`; - } - if (cache[name] === undefined) { - cache[name] = 0; - return name; - } - cache[name] += 1; - return `${name}(${cache[name]})`; - } - - async resolveDebugConfiguration(config: DebugConfiguration, workspaceFolderUri?: string): Promise { - try { - if (config.request === 'launch') { - try { - await this.compileWorkspace(); - } catch (err) { - const answer = await this.messages.error('Build failed, do you want to continue?', 'Proceed', 'Abort'); - if (answer !== 'Proceed') { - return undefined; - } - } - - const mainClassOption = await this.resolveLaunchConfig(config, workspaceFolderUri); - if (!mainClassOption || !mainClassOption.mainClass) { // Exit silently if the user cancels the prompt fix by ESC. - // Exit the debug session. - return; - } - - config.mainClass = mainClassOption.mainClass; - config.projectName = mainClassOption.projectName; - - if (_.isEmpty(config.classPaths) && _.isEmpty(config.modulePaths)) { - const result = await this.resolveClasspath(config.mainClass, config.projectName); - config.modulePaths = result && result[0]; - config.classPaths = result && result[1]; - } - if (_.isEmpty(config.classPaths) && _.isEmpty(config.modulePaths)) { - throw new Error('Cannot resolve the modulepaths/classpaths automatically, please specify the value in the launch.json.'); - } - } else if (config.request === 'attach') { - if (!config.hostName || !config.port) { - throw new Error('Please specify the host name and the port of the remote debuggee in the launch.json.'); - } - } else { - throw new Error(`Request type "${config.request}" is not supported. Only "launch" and "attach" are supported.`); - } - - if (Array.isArray(config.args)) { - config.args = this.concatArgs(config.args); - } - - if (Array.isArray(config.vmArgs)) { - config.vmArgs = this.concatArgs(config.vmArgs); - } - - const debugServerPort = await this.startDebugSession(); - if (debugServerPort) { - config.debugServer = debugServerPort; - return config; - } else { - throw new Error('Failed to start debug server.'); - } - } catch (ex) { - const errorMessage = (ex && ex.message) || ex; - this.messages.error(String(errorMessage)); - return undefined; - } - } - - protected async resolveLaunchConfig(config: DebugConfiguration, workspaceFolderUri?: string): Promise { - if (!config.mainClass) { - return this.promptMainClass(workspaceFolderUri); - } - - const containsExternalClasspaths = !_.isEmpty(config.classPaths) || !_.isEmpty(config.modulePaths); - const validationResponse = await this.validateLaunchConfig(config.mainClass, config.projectName, containsExternalClasspaths, workspaceFolderUri); - if (validationResponse && (!validationResponse.mainClass.isValid || !validationResponse.projectName.isValid)) { - return this.fixMainClass(config, validationResponse, workspaceFolderUri); - } - - return { - mainClass: config.mainClass, - projectName: config.projectName, - }; - } - - protected async promptMainClass(workspaceFolderUri?: string): Promise { - const options = await this.resolveMainClass(workspaceFolderUri); - if (options.length) { - return this.selectMainClass(options); - } - throw new Error('Cannot find a class with the main method.'); - } - - protected async fixMainClass(config: DebugConfiguration, validationResponse: LaunchValidationResponse, workspaceFolderUri?: string): Promise { - const errors: string[] = []; - if (!validationResponse.mainClass.isValid) { - errors.push(String(validationResponse.mainClass.message)); - } - if (!validationResponse.projectName.isValid) { - errors.push(String(validationResponse.projectName.message)); - } - - const message = errors.join('\n'); - const proposals = validationResponse.proposals || []; - if (validationResponse.proposals && validationResponse.proposals.length) { - const answer = await this.messages.error(message, 'Fix'); - return answer === 'Fix' ? this.selectMainClass(proposals) : undefined; - } - throw new Error(message); - } - - protected async selectMainClass(options: MainClassOption[]): Promise { - return this.quickPickService.show(this.formatMainClassOptions(options), { placeholder: 'Select main class' }); - } - protected formatMainClassOptions(options: MainClassOption[]): QuickPickItem[] { - return options.map(option => { - let label = option.mainClass; - let description = `main class: ${option.mainClass}`; - if (option.projectName) { - label += `<${option.projectName}>`; - description += ` | project name: ${option.projectName}`; - } - return { - label, - description, - value: option - }; - }); - } - - protected async resolveMainClass(workspaceFolderUri?: string): Promise { - const items = await this.commands.executeCommand(VSCodeJavaDebugCommands.RESOLVE_MAINCLASS, workspaceFolderUri); - return items || []; - } - - protected compileWorkspace(): Promise { - return this.commands.executeCommand(VSCodeJavaDebugCommands.COMPILE_WORKSPACE, false); - } - - protected validateLaunchConfig( - mainClass: string, projectName: string, containsExternalClasspaths: boolean, workspaceFolderUri?: string - ): Promise { - return this.commands.executeCommand( - VSCodeJavaDebugCommands.VALIDATE_LAUNCH_CONFIG, workspaceFolderUri, mainClass, projectName, containsExternalClasspaths - ); - } - - protected resolveClasspath(mainClass: string | undefined, projectName: string | undefined): Promise<[string, string] | undefined> { - return this.commands.executeCommand<[string, string]>(VSCodeJavaDebugCommands.RESOLVE_CLASSPATH, mainClass, projectName); - } - - protected startDebugSession(): Promise { - return this.commands.executeCommand(VSCodeJavaDebugCommands.START_DEBUG_SESSION); - } - - /** - * Converts an array of arguments to a string as the args and vmArgs. - */ - protected concatArgs(args: any[]): string { - return _.join(_.map(args, (arg: any): string => { - const str = String(arg); - // if it has quotes or spaces, use double quotes to wrap it - if (/['"\s]/.test(str)) { - return '"' + str.replace(/(['"\\])/g, '\\$1') + '"'; - } - return str; - - // if it has only single quotes - }), ' '); - } - -} diff --git a/packages/java-debug/src/node/java-debug-backend-module.ts b/packages/java-debug/src/node/java-debug-backend-module.ts deleted file mode 100644 index ebec3e36d42a8..0000000000000 --- a/packages/java-debug/src/node/java-debug-backend-module.ts +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************** - * Copyright (C) 2018 TypeFox and others. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the Eclipse - * Public License v. 2.0 are satisfied: GNU General Public License, version 2 - * with the GNU Classpath Exception which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - ********************************************************************************/ - -import { ContainerModule } from 'inversify'; -import { JavaExtensionContribution } from '@theia/java/lib/node'; -import { JavaDebugAdapterContribution, JavaDebugExtensionContribution } from './java-debug-adapter-contribution'; -import { DebugAdapterContribution } from '@theia/debug/lib/common/debug-model'; - -export default new ContainerModule(bind => { - /* explicit inTransientScope because it is very important, that - each web socket connection gets its own instance, - since it is using frontend services via this connection */ - bind(DebugAdapterContribution).to(JavaDebugAdapterContribution).inTransientScope(); - bind(JavaExtensionContribution).to(JavaDebugExtensionContribution).inSingletonScope(); -}); diff --git a/packages/java-debug/src/node/java-debug.spec.ts b/packages/java-debug/src/node/java-debug.spec.ts deleted file mode 100644 index bf9e865f96a7f..0000000000000 --- a/packages/java-debug/src/node/java-debug.spec.ts +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************** - * Copyright (C) 2018 TypeFox and others. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the Eclipse - * Public License v. 2.0 are satisfied: GNU General Public License, version 2 - * with the GNU Classpath Exception which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - ********************************************************************************/ - -describe('java-debug package', () => { - - it('support code coverage statistics', () => true); -}); diff --git a/tsconfig.json b/tsconfig.json index fe54e5e4da180..0d23b713dd506 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -55,15 +55,9 @@ "@theia/java/lib/*": [ "packages/java/src/*" ], - "@theia/java-debug/lib/*": [ - "packages/java-debug/src/*" - ], "@theia/debug/lib/*": [ "packages/debug/src/*" ], - "@theia/debug-nodejs/lib/*": [ - "packages/debug-nodejs/src/*" - ], "@theia/python/lib/*": [ "packages/python/src/*" ],