-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Anatoliy Bazko <abazko@redhat.com>
- Loading branch information
Showing
41 changed files
with
4,890 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Theia - NodeJS Debug Extension | ||
|
||
See [here](https://github.com/theia-ide/theia) 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../configs/base.tsconfig", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "lib" | ||
}, | ||
"include": [ | ||
"src" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "@theia/debug-nodejs", | ||
"version": "0.3.13", | ||
"description": "Theia - NodeJS Debug Extension", | ||
"dependencies": { | ||
"@theia/debug": "^0.3.13", | ||
"vscode-debugprotocol": "^1.26.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"theiaExtensions": [ | ||
{ | ||
"backend": "lib/node/debug-nodejs-backend-module" | ||
} | ||
], | ||
"keywords": [ | ||
"theia-extension, debug, nodejs" | ||
], | ||
"license": "Apache-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": { | ||
"prepare": "yarn run clean && yarn run build", | ||
"clean": "theiaext clean", | ||
"build": "concurrently -n download,build -c red,blue \"node ./scripts/download-vscode-node-debug.js\" \"theiaext build\"", | ||
"watch": "theiaext watch", | ||
"test": "theiaext test", | ||
"docs": "theiaext docs" | ||
}, | ||
"devDependencies": { | ||
"@theia/ext-scripts": "^0.3.13" | ||
}, | ||
"nyc": { | ||
"extends": "../../configs/nyc.json" | ||
}, | ||
"debugAdapter": { | ||
"downloadUrl": "https://github.com/tolusha/node-debug/releases/download/v1.23.5/vscode-node-debug.tar.gz", | ||
"dir": "lib/adapter" | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
packages/debug-nodejs/scripts/download-vscode-node-debug.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/******************************************************************************** | ||
* 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 | ||
********************************************************************************/ | ||
|
||
const fs = require('fs'); | ||
const https = require('https'); | ||
const http = require('http'); | ||
const path = require('path'); | ||
const zlib = require('zlib'); | ||
const tar = require('tar'); | ||
const mkdirp = require('mkdirp'); | ||
const packageJson = require('../package.json'); | ||
const downloadUrl = packageJson['debugAdapter']['downloadUrl']; | ||
const downloadPath = path.join(__dirname, '../node_modules/download'); | ||
const archivePath = path.join(downloadPath, path.basename(downloadUrl)); | ||
const targetPath = packageJson['debugAdapter']['dir']; | ||
|
||
function downloadDap() { | ||
return new Promise((resolve, reject) => { | ||
if (fs.existsSync(archivePath)) { | ||
resolve(); | ||
return; | ||
} | ||
|
||
if (!fs.existsSync(downloadPath)) { | ||
fs.mkdirSync(downloadPath); | ||
} | ||
|
||
const file = fs.createWriteStream(archivePath); | ||
const downloadWithRedirect = url => { | ||
const h = url.toString().startsWith('https') ? https : http; | ||
h.get(url, response => { | ||
const statusCode = response.statusCode; | ||
const redirectLocation = response.headers.location; | ||
if (statusCode >= 300 && statusCode < 400 && redirectLocation) { | ||
console.log('Redirect location: ' + redirectLocation); | ||
downloadWithRedirect(redirectLocation); | ||
} else if (statusCode === 200) { | ||
response.on('end', () => resolve()); | ||
response.on('error', e => { | ||
file.destroy(); | ||
reject(e); | ||
}); | ||
response.pipe(file); | ||
} else { | ||
file.destroy(); | ||
reject(new Error(`Failed to download 'VSCode Node Debug' with error code: ${statusCode}`)); | ||
} | ||
}) | ||
}; | ||
|
||
downloadWithRedirect(downloadUrl); | ||
}); | ||
} | ||
|
||
decompressArchive = function () { | ||
return new Promise((resolve, reject) => { | ||
if (!fs.existsSync(archivePath)) { | ||
reject(new Error(`The archive was not found at ${archivePath}.`)); | ||
return; | ||
} | ||
|
||
if (!fs.existsSync(targetPath)) { | ||
mkdirp.sync(targetPath); | ||
} | ||
|
||
const gunzip = zlib.createGunzip({ finishFlush: zlib.Z_SYNC_FLUSH, flush: zlib.Z_SYNC_FLUSH }); | ||
const untar = tar.x({ cwd: targetPath }); | ||
fs.createReadStream(archivePath).pipe(gunzip).pipe(untar) | ||
.on('error', e => reject(e)) | ||
.on('end', () => resolve()); | ||
}); | ||
} | ||
|
||
downloadDap().then(() => { | ||
decompressArchive(); | ||
}).catch(error => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
23 changes: 23 additions & 0 deletions
23
packages/debug-nodejs/src/node/debug-nodejs-backend-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/******************************************************************************** | ||
* 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 { NodeJsDebugAdapterContribution } from './debug-nodejs'; | ||
import { DebugAdapterContribution } from '@theia/debug/lib/node/debug-model'; | ||
|
||
export default new ContainerModule(bind => { | ||
bind(DebugAdapterContribution).to(NodeJsDebugAdapterContribution).inSingletonScope(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/******************************************************************************** | ||
* 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 | ||
********************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/******************************************************************************** | ||
* 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 | ||
********************************************************************************/ | ||
|
||
const path = require('path'); | ||
const packageJson = require('../../package.json'); | ||
const debugAdapterDir = packageJson['debugAdapter']['dir']; | ||
|
||
import { injectable } from 'inversify'; | ||
import { DebugConfiguration } from '@theia/debug/lib/common/debug-common'; | ||
import { DebugAdapterContribution, DebugAdapterExecutable } from '@theia/debug/lib/node/debug-model'; | ||
|
||
@injectable() | ||
export class NodeJsDebugAdapterContribution implements DebugAdapterContribution { | ||
readonly debugType = 'node'; | ||
|
||
provideDebugConfigurations = [{ | ||
type: this.debugType, | ||
breakpoints: { filePatterns: ['[.]js$', '[.]ts$'] }, | ||
request: 'attach', | ||
name: 'Attach by PID', | ||
processId: '' | ||
}]; | ||
|
||
resolveDebugConfiguration(config: DebugConfiguration): DebugConfiguration { | ||
config.breakpoints = { filePatterns: ['[.]js$', '[.]ts$'] }; | ||
|
||
if (!config.request) { | ||
throw new Error('Debug request type is not provided.'); | ||
} | ||
|
||
switch (config.request) { | ||
case 'attach': this.validateAttachConfig(config); | ||
} | ||
|
||
return config; | ||
} | ||
|
||
provideDebugAdapterExecutable(config: DebugConfiguration): DebugAdapterExecutable { | ||
const program = path.join(__dirname, `../../${debugAdapterDir}/out/src/nodeDebug.js`); | ||
return { | ||
program, | ||
runtime: 'node' | ||
}; | ||
} | ||
|
||
private validateAttachConfig(config: DebugConfiguration) { | ||
if (!config.processId) { | ||
throw new Error('PID is not provided.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## Architecture | ||
`DebugService` is used to initialize a new `DebugSession`. This service provides functionality to configure and to start a new debug session. The workflow is the following. If user wants to debug an application and there is no debug configuration associated with the application then the list of available debuggers is requested to create a suitable debug configuration. When configuration is chosen it is possible to alter the configuration by filling in missing values or by adding/changing/removing attributes. | ||
|
||
In most cases the default behavior of the `DebugSession` is enough. But it is possible to provide its own implementation. The `DebugSessionFactory` is used for this purpose via `DebugSessionContribution`. Documented model objects are located [here](https://github.com/theia-ide/theia/tree/master/packages/debug/src/browser/debug-model.ts) | ||
|
||
### Debug Session life-cycle API | ||
`DebugSession` life-cycle is controlled and can be tracked as follows: | ||
* An `onDidPreCreateDebugSession` event indicates that a debug session is going to be created. | ||
* An `onDidCreateDebugSession` event indicates that a debug session has been created. | ||
* An `onDidDestroyDebugSession` event indicates that a debug session has terminated. | ||
* An `onDidChangeActiveDebugSession` event indicates that an active debug session has been changed | ||
|
||
### Breakpoints API | ||
`ExtDebugProtocol.AggregatedBreakpoint` is used to handle breakpoints on the client side. It covers all three breakpoint types: `DebugProtocol.SourceBreakpoint`, `DebugProtocol.FunctionBreakpoint` and `ExtDebugProtocol.ExceptionBreakpoint`. It is possible to identify a breakpoint type with help of `DebugUtils`. Notification about added, removed, or changed breakpoints is received via `onDidChangeBreakpoints`. | ||
|
||
### 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. | ||
|
||
## 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) | ||
* [Debug adapter example for VS Code](https://code.visualstudio.com/docs/extensions/example-debuggers) | ||
|
||
## Debug adapter implementations for VS Code | ||
* [Node debugger](https://github.com/Microsoft/vscode-node-debug) | ||
* [Java debugger](https://github.com/Microsoft/vscode-java-debug) | ||
|
||
## 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../configs/base.tsconfig", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "lib" | ||
}, | ||
"include": [ | ||
"src" | ||
] | ||
} |
Oops, something went wrong.