Unverified Commit cade2588 authored by Neil C Smith's avatar Neil C Smith Committed by GitHub
Browse files

Merge pull request #2330 from apache/master

Sync master to release121 for 12.1-beta4
parents 26e6ce80 35c43570
......@@ -127,17 +127,16 @@ public class SearchComboBoxEditor implements ComboBoxEditor {
// selection is not removed when text is input via IME
// so, just remove it when the caret is changed
if ("caret".equals(evt.getPropertyName())) { // NOI18N
if (evt.getOldValue() instanceof Caret) {
if (evt.getOldValue() instanceof Caret
&& evt.getNewValue() instanceof Caret) { // NETBEANS-4620 check new value is not null but Caret
Caret oldCaret = (Caret) evt.getOldValue();
if (oldCaret != null) {
int dotPosition = oldCaret.getDot();
int markPosition = oldCaret.getMark();
if (dotPosition != markPosition) {
try {
editorPane.getDocument().remove(Math.min(markPosition, dotPosition), Math.abs(markPosition - dotPosition));
} catch (BadLocationException ex) {
LOG.log(Level.WARNING, "Invalid removal offset: {0}", ex.offsetRequested()); // NOI18N
}
int dotPosition = oldCaret.getDot();
int markPosition = oldCaret.getMark();
if (dotPosition != markPosition) {
try {
editorPane.getDocument().remove(Math.min(markPosition, dotPosition), Math.abs(markPosition - dotPosition));
} catch (BadLocationException ex) {
LOG.log(Level.WARNING, "Invalid removal offset: {0}", ex.offsetRequested()); // NOI18N
}
}
}
......@@ -412,4 +411,4 @@ public class SearchComboBoxEditor implements ComboBoxEditor {
return originalActionName;
}
};
}
\ No newline at end of file
}
......@@ -20,6 +20,8 @@ package org.netbeans.modules.debugger.ui;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
......@@ -313,6 +315,9 @@ public class DebuggerManagerListener extends DebuggerManagerAdapter {
}
private void setupToolbar(final DebuggerEngine engine) {
if (GraphicsEnvironment.isHeadless()) {
return;
}
final List<Component> buttonsToClose = new ArrayList<Component>();
buttonsToClose.add(new java.awt.Label("EMPTY"));
final boolean isFirst;
......
......@@ -7,4 +7,5 @@ OpenIDE-Module-Specification-Version: 1.6
OpenIDE-Module-Provides: org.netbeans.modules.debugger.jpda.truffle
OpenIDE-Module-Requires: org.netbeans.api.debugger.jpda.JPDADebuggerEngineImpl,
org.netbeans.spi.debugger.ui
OpenIDE-Module-Recommends: cnb.org.netbeans.modules.java.kit
OpenIDE-Module-Package-Dependencies: com.sun.jdi[VirtualMachineManager]
......@@ -79,12 +79,6 @@
<specification-version>1.4</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.java.kit</code-name-base>
<run-dependency>
<specification-version>1.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.java.platform</code-name-base>
<build-prerequisite/>
......
......@@ -41,6 +41,7 @@
<copy todir="${lsp.build.dir}/etc" file="script/etc/nb-java-lsp-server.conf" />
<copy todir="${lsp.build.dir}/etc" file="script/etc/nb-java-lsp-server.clusters" />
<chmod file="${lsp.build.dir}/bin/nb-java-lsp-server" perm="u+x" />
<chmod file="${lsp.build.dir}/java/maven/bin/mvn" perm="u+x" />
<delete file="${lsp.build.dir}/lib/nb-javac-9-api.jar" />
<delete file="${lsp.build.dir}/lib/nb-javac-9-impl.jar" />
<delete file="${lsp.build.dir}/lib/org-netbeans-modules-java-source-nbjavac.jar" />
......
......@@ -27,6 +27,15 @@
<file>vscode/src/extension.ts</file>
<license ref="MIT-vscode-ext" />
</fileset>
<fileset>
<file>vscode/.vscodeignore</file>
<file>vscode/.eslintrc.json</file>
<file>vscode/.vscode/extensions.json</file>
<file>vscode/.vscode/launch.json</file>
<file>vscode/.vscode/tasks.json</file>
<file>vscode/.vscode/settings.json</file>
<license ref="Apache-2.0" />
</fileset>
<fileset>
<file>script/etc/nb-java-lsp-server.clusters</file>
<license ref="Apache-2.0-ASF" />
......
......@@ -58,7 +58,7 @@ default_cachedir="${DEFAULT_CACHEDIR_ROOT}/dev"
# options used by the launcher by default, can be overridden by explicit
# command line switches
default_options="--nogui --nosplash -J-Djava.awt.headless=true --start-java-language-server -J--add-opens=java.base/java.net=ALL-UNNAMED -J--add-opens=java.base/java.lang.ref=ALL-UNNAMED -J--add-opens=java.base/java.lang=ALL-UNNAMED -J--add-opens=java.base/java.security=ALL-UNNAMED -J--add-opens=java.base/java.util=ALL-UNNAMED -J--add-opens=java.desktop/javax.swing.plaf.basic=ALL-UNNAMED -J--add-opens=java.desktop/javax.swing.text=ALL-UNNAMED -J--add-opens=java.desktop/javax.swing=ALL-UNNAMED -J--add-opens=java.desktop/java.awt=ALL-UNNAMED -J--add-opens=java.desktop/java.awt.event=ALL-UNNAMED -J--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED -J--add-opens=jdk.jshell/jdk.jshell=ALL-UNNAMED -J--add-modules=jdk.jshell -J--add-exports=java.desktop/sun.awt=ALL-UNNAMED -J--add-exports=java.desktop/java.awt.peer=ALL-UNNAMED -J--add-exports=java.desktop/com.sun.beans.editors=ALL-UNNAMED -J--add-exports=java.desktop/sun.swing=ALL-UNNAMED -J--add-exports=java.desktop/sun.awt.im=ALL-UNNAMED -J--add-exports=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED -J--add-exports=java.management/sun.management=ALL-UNNAMED -J--add-exports=java.base/sun.reflect.annotation=ALL-UNNAMED -J-XX:+IgnoreUnrecognizedVMOptions"
default_options="--nogui --nosplash -J-Dnetbeans.logger.console=true -J-Djava.awt.headless=true -J--add-opens=java.base/java.net=ALL-UNNAMED -J--add-opens=java.base/java.lang.ref=ALL-UNNAMED -J--add-opens=java.base/java.lang=ALL-UNNAMED -J--add-opens=java.base/java.security=ALL-UNNAMED -J--add-opens=java.base/java.util=ALL-UNNAMED -J--add-opens=java.desktop/javax.swing.plaf.basic=ALL-UNNAMED -J--add-opens=java.desktop/javax.swing.text=ALL-UNNAMED -J--add-opens=java.desktop/javax.swing=ALL-UNNAMED -J--add-opens=java.desktop/java.awt=ALL-UNNAMED -J--add-opens=java.desktop/java.awt.event=ALL-UNNAMED -J--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED -J--add-opens=jdk.jshell/jdk.jshell=ALL-UNNAMED -J--add-modules=jdk.jshell -J--add-exports=java.desktop/sun.awt=ALL-UNNAMED -J--add-exports=java.desktop/java.awt.peer=ALL-UNNAMED -J--add-exports=java.desktop/com.sun.beans.editors=ALL-UNNAMED -J--add-exports=java.desktop/sun.swing=ALL-UNNAMED -J--add-exports=java.desktop/sun.awt.im=ALL-UNNAMED -J--add-exports=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED -J--add-exports=java.management/sun.management=ALL-UNNAMED -J--add-exports=java.base/sun.reflect.annotation=ALL-UNNAMED -J-XX:+IgnoreUnrecognizedVMOptions"
# for development purposes you may wish to append: -J-Dnetbeans.logger.console=true -J-ea
# default location of JDK/JRE, can be overridden by using --jdkhome <dir> switch
......
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/class-name-casing": "warn",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
}
}
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint"
]
}
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
// 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
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
}
\ No newline at end of file
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
.vscode/**
.vscode-test/**
out/test/**
src/**
.gitignore
vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.ts
......@@ -25,16 +25,48 @@ https://github.com/microsoft/vscode-extension-samples
# Building
To build the VS Code extension do:
* cd java/java.lsp.server
* ant build-vscode-ext
The resulting extension is then in the build directory, with the vsix extension.
```bash
netbeans$ cd java/java.lsp.server
java.lsp.server$ ant build-vscode-ext
```
#Building for Development
The resulting extension is then in the `build` directory, with the `.vsix` extension.
# Building for Development
If you want to develop the extension, use these steps for building instead:
* cd java/java.lsp.server
* ant build-lsp-server
* cd vscode
* npm install
* npm run compile
```bash
netbeans$ cd java/java.lsp.server
java.lsp.server$ ant build-lsp-server
java.lsp.server$ cd vscode
vscode$ npm install
vscode$ npm run compile
```
# Running and Debugging
To use the extension created for developement you can run VSCode with
following parameter:
```bash
vscode$ code --extensionDevelopmentPath=`pwd` name_of_folder_to_open
```
Or you can open the `vscode` folder in `code` directly and use **F5** to
debug the extension's typescript code.
The idea when debugging Java code is to launch the NetBeans part of the LSP
system first, provide suitable debug arguments:
```bash
vscode$ ./nb-java-lsp-server/bin/nb-java-lsp-server -J-agentlib:jdwp=transport=dt_socket,server=y,address=8000
```
and then connect to with debugger setup all breakpoints and then also connect
from the VSCode extension:
```bash
vscode$ code --extensionDevelopmentPath=`pwd` name_of_folder_to_open
```
{
"name": "apache-netbeans-java",
"displayName": "Apache Netbeans Java for VSCode",
"description": "An Apache NetBeans Java plugin for Visual Studio Code",
"author": "Apache NetBeans",
"license": "Apache 2.0",
......@@ -14,38 +15,47 @@
"multi-root ready"
],
"engines": {
"vscode": "^1.26.0"
"vscode": "^1.47.0"
},
"activationEvents": [
"onLanguage:java"
],
"main": "./out/extension",
"main": "./out/extension.js",
"contributes": {
"configuration": {
"title": "Java",
"properties": {
"netbeans.jdkhome": {
"type": [
"string",
"null"
],
"default": null,
"description": "Specifies the JDK on which the Java language server should be run"
}
}
}
},
"scripts": {
"vscode:prepublish": "npm run update-vscode && npm run compile",
"compile": "tsc -p ./tsconfig.json",
"watch": "tsc -w -p ./tsconfig.json",
"postinstall": "vscode-install",
"update-vscode": "vscode-install"
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"lint": "eslint src --ext ts",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/mocha": "5.2.7",
"@types/node": "13.1.7",
"typescript": "3.7.4",
"vscode": "1.1.36"
"@types/vscode": "^1.47.0",
"@types/glob": "^7.1.1",
"@types/mocha": "^7.0.2",
"@types/node": "^13.11.0",
"glob": "^7.1.6",
"mocha": "^7.1.2",
"typescript": "^3.8.3",
"vscode-test": "^1.3.0"
},
"dependencies": {
"vscode-languageclient": "4.4.2"
},
"contributes": {
"configuration": {
"title": "Java",
"properties": {
"netbeans.jdkhome": {
"type": ["string", "null"],
"default": null,
"description": "Specifies the JDK on which the Java language server should be run"
}
}
}
}
"vscode-languageclient": "4.4.2",
"vscode-debugadapter": "1.33.0"
}
}
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
/*Heavily influenced by the extension for Kotlin Language Server which is:
* Copyright (c) 2016 George Fraser
* Copyright (c) 2018 fwcd
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
'use strict';
......@@ -17,13 +27,17 @@ import {
} from 'vscode-languageclient';
import * as path from 'path';
import { execSync } from 'child_process';
import { execSync, spawn, ChildProcess } from 'child_process';
import { resolve } from 'path';
import { rejects } from 'assert';
import * as vscode from 'vscode';
let client: LanguageClient;
let nbProcess : ChildProcess | null = null;
export function activate(context: ExtensionContext) {
//verify acceptable JDK is available/set:
let specifiedJDK: string = workspace.getConfiguration('netbeans').get('jdkhome');
let specifiedJDK = workspace.getConfiguration('netbeans').get('jdkhome');
try {
let targetJava = specifiedJDK != null ? specifiedJDK + '/bin/java' : 'java';
......@@ -35,45 +49,105 @@ export function activate(context: ExtensionContext) {
let serverPath = path.resolve(context.extensionPath, "nb-java-lsp-server", "bin", "nb-java-lsp-server");
let serverOptions: ServerOptions;
let args: string[] = [];
if (specifiedJDK != null) {
args = ['--jdkhome', specifiedJDK];
let ideArgs: string[] = [];
if (specifiedJDK) {
ideArgs = ['--jdkhome', specifiedJDK as string];
}
let serverArgs: string[] = new Array<string>(...ideArgs);
serverArgs.push("--start-java-language-server");
serverOptions = {
command: serverPath,
args: args,
options: { cwd: workspace.rootPath }
}
args: serverArgs,
options: { cwd: workspace.rootPath },
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for java documents
documentSelector: ['java'],
synchronize: {
configurationSection: 'java',
fileEvents: [
workspace.createFileSystemWatcher('**/*.java')
]
},
outputChannelName: 'Java',
revealOutputChannelOn: 4 // never
}
// Create the language client and start the client.
client = new LanguageClient(
'java',
'NetBeans Java',
serverOptions,
clientOptions
);
// give the process some reasonable command
ideArgs.push("--modules");
ideArgs.push("--list");
let log = vscode.window.createOutputChannel("Java Language Server");
log.show(true);
log.appendLine("Launching Java Language Server");
vscode.window.showInformationMessage("Launching Java Language Server");
let ideRunning = new Promise((resolve, reject) => {
let collectedText : string | null = '';
function logAndWaitForEnabled(text: string) {
log.append(text);
if (collectedText == null) {
return;
}
collectedText += text;
if (collectedText.match(/org.netbeans.modules.java.lsp.server.*Enabled/)) {
resolve(text);
collectedText = null;
}
}
let p = spawn(serverPath, ideArgs, {
stdio : ["ignore", "pipe", "pipe"]
});
p.stdout.on('data', function(d: any) {
logAndWaitForEnabled(d.toString());
});
p.stderr.on('data', function(d: any) {
logAndWaitForEnabled(d.toString());
});
nbProcess = p;
nbProcess.on('close', function(code: number) {
if (code != 0) {
vscode.window.showWarningMessage("Java Language Server exited with " + code);
}
log.appendLine("");
if (collectedText != null) {
reject("Exit code " + code);
} else {
log.appendLine("Exit code " + code);
}
nbProcess = null;
});
});
ideRunning.then((value) => {
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for java documents
documentSelector: ['java'],
synchronize: {
configurationSection: 'java',
fileEvents: [
workspace.createFileSystemWatcher('**/*.java')
]
},
outputChannelName: 'Java',
revealOutputChannelOn: 4 // never
}
// Create the language client and start the client.
client = new LanguageClient(
'java',
'NetBeans Java',
serverOptions,
clientOptions
);
// Start the client. This will also launch the server
client.start();
}).catch((reason) => {
log.append(reason);
window.showErrorMessage('Error initializing ' + reason);
});
// Start the client. This will also launch the server
client.start();
}
export function deactivate(): Thenable<void> {
if (nbProcess != null) {
nbProcess.kill();
}
if (!client) {
return undefined;
return Promise.resolve();
}
return client.stop();
}
import * as path from 'path';
import { runTests } from 'vscode-test';
async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');
// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}
main();
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 '../../extension';
suite('Extension Test Suite', () => {
vscode.window.showInformationMessage('Start all tests.');
test('Sample test', () => {
assert.equal(-1, [1, 2, 3].indexOf(5));
assert.equal(-1, [1, 2, 3].indexOf(0));
});
});
import * as path from 'path';
import * as Mocha from 'mocha';