Intialize VSCode Java Debugger extension. (#1)

This commit is contained in:
Yaohai Zheng 2017-09-08 12:19:34 +08:00 committed by GitHub
parent 256243381e
commit 9eba74f492
15 changed files with 3941 additions and 59 deletions

62
.gitignore vendored
View File

@ -1,59 +1,3 @@
# Logs out
logs bin
*.log node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Typescript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env

28
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,28 @@
// A launch configuration that compiles the extension and then opens it inside a new window
{
"version": "0.1.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/src/**/*.js" ],
"preLaunchTask": "npm"
},
{
"name": "Launch Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/test/**/*.js" ],
"preLaunchTask": "npm"
}
]
}

9
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,9 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
}
}

30
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,30 @@
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
// A task runner that calls a custom npm script that compiles the extension.
{
"version": "0.1.0",
// we want to run npm
"command": "npm",
// the command is a shell script
"isShellCommand": true,
// show the output window only if unrecognized errors occur.
"showOutput": "silent",
// we run the custom script "compile" as defined in package.json
"args": ["run", "compile", "--loglevel", "silent"],
// The tsc compiler is started in watching mode
"isBackground": true,
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
"problemMatcher": "$tsc-watch"
}

8
.vscodeignore Normal file
View File

@ -0,0 +1,8 @@
.vscode/**
.vscode-test/**
out/test/**
test/**
src/**
**/*.map
.gitignore
tsconfig.json

7
CHANGELOG.md Normal file
View File

@ -0,0 +1,7 @@
# Change Log
All notable changes to the "vscode-java-debugger" extension will be documented in this file.
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
## [Unreleased]
- Initial release

8
gulpfile.js Normal file
View File

@ -0,0 +1,8 @@
const gulp = require("gulp");
const tslint = require("gulp-tslint");
gulp.task("tslint", () => {
return gulp.src(["**/*.ts", "!**/*.d.ts", "!node_modules/**", "!./src/views/node_modules/**"])
.pipe(tslint())
.pipe(tslint.report());
});

3542
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

152
package.json Normal file
View File

@ -0,0 +1,152 @@
{
"name": "vscode-java-debugger",
"displayName": "vscode-java-debugger",
"description": "",
"version": "0.0.1",
"publisher": "vscjava",
"engines": {
"vscode": "^1.14.0"
},
"categories": [
"Debuggers"
],
"activationEvents": [
"onLanguage:java"
],
"main": "./out/src/extension",
"contributes": {
"javaExtensions": [],
"commands": [],
"debuggers": [{
"type": "java",
"label": "Java",
"startSessionCommand": "java.debug.startSession",
"enableBreakpointsFor": {
"languageIds": [
"java"
]
},
"configurationAttributes": {
"launch": {
"required": [
"mainClass"
],
"properties": {
"projectName": {
"type": "string",
"description": "Name of the project that contains the main class (optional, only required when the main class resides in multiple projects).",
"default": ""
},
"mainClass": {
"type": "string",
"description": "The main class of the program (fully qualified name, e.g. com.xyz.MainClass).",
"default": ""
},
"args": {
"type": "string",
"description": "The command line arguments passed to the program.",
"default": ""
},
"vmArgs": {
"type": "string",
"description": "The java options and system properties passed to the JVM launcher (e.g. -Xms<size> -Xmx<size> -D<name>=<value>).",
"default": ""
},
"classPaths": {
"type": "array",
"items": {
"type": "string"
},
"description": "The classpaths passed to the JVM launcher (if not specified, debugger will resolve them automatically from the project configuration).",
"default": []
},
"sourcePaths": {
"type": "array",
"items": {
"type": "string"
},
"description": "The source directories of the program.",
"default": []
}
}
},
"attach": {
"required": [
"hostName",
"port"
],
"properties": {
"hostName": {
"type": "string",
"default": "localhost",
"description": "The host name or ip address of remote debuggee."
},
"port": {
"type": "number",
"description": "The debug port of remote debuggee."
},
"timeout": {
"type": "number",
"default": 30000,
"description": "Timeout value before reconnecting, in milliseconds (default to 30000ms)."
},
"sourcePaths": {
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "The source directories of the program."
},
"projectName": {
"type": "string",
"description": "Name of the project that contains the main class (optional, only required when the main class resides in multiple projects).",
"default": ""
}
}
}
},
"initialConfigurations": [{
"type": "java",
"name": "Debug (Launch)",
"request": "launch",
"mainClass": "",
"args": "",
"sourcePaths": [
"${workspaceRoot}"
]
},
{
"type": "java",
"name": "Debug (Attach)",
"request": "attach",
"hostName": "localhost",
"port": 0,
"timeout": 30000,
"sourcePaths": [
"${workspaceRoot}"
]
}
]
}]
},
"scripts": {
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "node ./node_modules/vscode/bin/test"
},
"extensionDependencies": [
"redhat.java"
],
"devDependencies": {
"@types/mocha": "^2.2.32",
"@types/node": "^6.0.40",
"gulp": "^3.9.1",
"gulp-tslint": "^8.1.2",
"mocha": "^2.3.3",
"tslint": "^5.7.0",
"typescript": "^2.0.3",
"vscode": "^1.1.5"
}
}

10
src/commands.ts Normal file
View File

@ -0,0 +1,10 @@
export const JAVA_DEBUG_STARTSESSION = "java.debug.startSession";
export const VSCODE_STARTDEBUG = "vsocde.startDebug";
export const GET_DEBUG_PORT = "vscode.java.getDebugPort";
export const RESOLVE_CLASSPATH = "vscode.java.resolveClasspath";
export const EXECUTE_WORKSPACE_COMMAND = "java.execute.workspaceCommand";

46
src/extension.ts Normal file
View File

@ -0,0 +1,46 @@
import * as path from "path";
import * as vscode from "vscode";
import * as commands from "./commands";
export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand(commands.JAVA_DEBUG_STARTSESSION, async (config) => {
if (config.request === "launch") {
if (!config.mainClass) {
vscode.window.showErrorMessage("Please specify the main class in launch.json.");
return;
} else if (!config.classPaths || !Array.isArray(config.classPaths) || !config.classPaths.length) {
config.classPaths = await resolveClasspath(config.mainClass, config.projectName);
}
if (!config.classPaths || !Array.isArray(config.classPaths) || !config.classPaths.length) {
vscode.window.showErrorMessage("Cannot resolve the classpaths automatically, please specify it in launch.json.");
return;
}
} else if (config.request === "attach") {
if (!config.hostName || !config.port) {
vscode.window.showErrorMessage("Please specify the host name and the port of the remote debuggee in launch.json.");
return;
}
}
const debugServerPort = await getDebugSessionPort();
if (debugServerPort) {
config.debugServer = debugServerPort;
vscode.commands.executeCommand(commands.VSCODE_STARTDEBUG, config);
}
});
}
// this method is called when your extension is deactivated
export function deactivate() {
}
function getDebugSessionPort() {
return executeJavaLanguageServerCommand(commands.GET_DEBUG_PORT);
}
function resolveClasspath(mainClass, projectName) {
return executeJavaLanguageServerCommand(commands.RESOLVE_CLASSPATH, mainClass, projectName);
}
function executeJavaLanguageServerCommand(...rest) {
return vscode.commands.executeCommand(commands.EXECUTE_WORKSPACE_COMMAND, ...rest);
}

22
test/extension.test.ts Normal file
View File

@ -0,0 +1,22 @@
//
// Note: This example test is leveraging the Mocha test framework.
// Please refer to their documentation on https://mochajs.org/ for help.
//
// The module 'assert' provides assertion methods from node
import * as assert from "assert";
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from "vscode";
import * as myExtension from "../src/extension";
// Defines a Mocha test suite to group tests of similar kind together
suite("Extension Tests", () => {
// Defines a Mocha unit test
test("Something 1", () => {
assert.equal(-1, [1, 2, 3].indexOf(5));
assert.equal(-1, [1, 2, 3].indexOf(0));
});
});

23
test/index.ts Normal file
View File

@ -0,0 +1,23 @@
//
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
//
// This file is providing the test runner to use when running extension tests.
// By default the test runner in use is Mocha based.
//
// You can provide your own test runner if you want to override it by exporting
// a function run(testRoot: string, clb: (error:Error) => void) that the extension
// host can call to run the tests. The test runner is expected to use console.log
// to report the results back to the caller. When the tests are finished, return
// a possible error to the callback or null if none.
// tslint:disable-next-line:no-submodule-imports
import testRunner = require("vscode/lib/testrunner");
// You can directly control Mocha options by uncommenting the following lines
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
testRunner.configure({
ui: "tdd", // the TDD UI is being used in extension.test.ts (suite, test, etc.)
useColors: true, // colored output from test results
});
module.exports = testRunner;

17
tsconfig.json Normal file
View File

@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"alwaysStrict": true,
"lib": [
"es6"
],
"sourceMap": true,
"rootDir": "."
},
"exclude": [
"node_modules",
".vscode-test"
]
}

36
tslint.json Normal file
View File

@ -0,0 +1,36 @@
{
"extends": "tslint:latest",
"rules": {
"variable-name": [
true,
"allow-leading-underscore"
],
"no-unused-expression": true,
"no-duplicate-variable": true,
"max-classes-per-file": [
false
],
"no-empty": false,
"object-literal-sort-keys": false,
"curly": true,
"class-name": true,
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-module",
"check-separator",
"check-type"
],
"semicolon": [
"always"
],
"triple-equals": true,
"max-line-length": [
true,
150
],
"no-angle-bracket-type-assertion": false
}
}