Skip to content

Commit

Permalink
Contribute to completion, hover .. with external JAR
Browse files Browse the repository at this point in the history
Fixes #190

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Oct 22, 2019
1 parent cf8674b commit c04c50b
Show file tree
Hide file tree
Showing 8 changed files with 939 additions and 1,187 deletions.
1,973 changes: 809 additions & 1,164 deletions package-lock.json

Large diffs are not rendered by default.

46 changes: 30 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dtd"
],
"engines": {
"vscode": "^1.27.0"
"vscode": "^1.37.0"
},
"activationEvents": [
"onLanguage:xml",
Expand All @@ -28,10 +28,12 @@
"compile": "webpack --mode none",
"watch": "webpack --mode development --watch --info-verbosity verbose",
"test-compile": "tsc -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "node ./node_modules/vscode/bin/test",
"build-server": "./node_modules/.bin/gulp build_server",
"tslint": "./node_modules/.bin/gulp tslint"
"pretest": "npm run test-compile",
"test": "node ./out/test/runTest.js",
"tslint": "./node_modules/.bin/tslint -p .",
"build": "./node_modules/.bin/gulp build",
"build-server": "./node_modules/.bin/gulp buildServer",
"build-ext": "./node_modules/.bin/gulp buildExtension"
},
"repository": {
"type": "git",
Expand All @@ -44,25 +46,31 @@
"Snippets"
],
"devDependencies": {
"@types/mocha": "^5.2.5",
"@types/node": "^6.0.40",
"gulp": "^4.0.0",
"@types/fs-extra": "^7.0.0",
"@types/md5": "^2.1.33",
"@types/mocha": "^5.2.6",
"@types/node": "^10.14.16",
"@types/vscode": "^1.37.0",
"@types/which": "^1.3.1",
"@types/xml2js": "^0.4.4",
"gulp": "^4.0.2",
"gulp-tslint": "^8.1.3",
"mocha": "^5.2.0",
"tar": ">=4.4.2",
"gulp-rename": "^1.4.0",
"mocha": "^6.2.1",
"ts-loader": "^6.0.1",
"tslint": "^5.11.0",
"typescript": "^3.0.3",
"vscode": "^1.1.21",
"tslint": "^5.12.1",
"typescript": "^3.4.1",
"typescript-tslint-plugin": "^0.3.1",
"vscode-test": "^1.2.0",
"webpack": "^4.32.2",
"webpack-cli": "^3.3.2"
},
"dependencies": {
"expand-home-dir": "^0.0.3",
"find-java-home": "0.2.0",
"glob": "^7.1.1",
"path-exists": "^3.0.0",
"vscode-languageclient": "~5.1.0"
"glob": "^7.1.4",
"path-exists": "^4.0.0",
"vscode-languageclient": "^5.2.1"
},
"contributes": {
"configuration": {
Expand Down Expand Up @@ -285,6 +293,12 @@
".mod"
]
}
],
"jsonValidation": [
{
"fileMatch": "package.json",
"url": "./schemas/package.schema.json"
}
]
}
}
20 changes: 20 additions & 0 deletions schemas/package.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "XML Language server contributions to package.json",
"type": "object",
"properties": {
"contributes": {
"type": "object",
"properties": {
"xml.javaExtensions": {
"type": "array",
"markdownDescription": "XML language server extensions",
"items": {
"type": "string",
"description": "Relative path to a XML language server extension JAR file"
}
}
}
}
}
}
5 changes: 5 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ export namespace Commands {
*/
export const EDITOR_SHOW_REFERENCES = 'editor.action.showReferences';

/**
* Reload VS Code window
*/
export const RELOAD_WINDOW = 'workbench.action.reloadWindow';

}
11 changes: 9 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
import { prepareExecutable } from './javaServerStarter';
import { LanguageClientOptions, RevealOutputChannelOn, LanguageClient, DidChangeConfigurationNotification, RequestType, TextDocumentPositionParams, ReferencesRequest } from 'vscode-languageclient';
import * as requirements from './requirements';
import { languages, IndentAction, workspace, window, commands, ExtensionContext, TextDocument, Position, LanguageConfiguration, Uri } from "vscode";
import { languages, IndentAction, workspace, window, commands, ExtensionContext, TextDocument, Position, LanguageConfiguration, Uri, extensions } from "vscode";
import * as path from 'path';
import * as os from 'os';
import { activateTagClosing, AutoCloseResult } from './tagClosing';
import { Commands } from './commands';
import { onConfigurationChange, subscribeJDKChangeConfiguration } from './settings';
import { collectXmlJavaExtensions, onExtensionChange } from './plugin';

export interface ScopeInfo {
scope : "default" | "global" | "workspace" | "folder";
Expand Down Expand Up @@ -84,7 +85,7 @@ export function activate(context: ExtensionContext) {
}
}

let serverOptions = prepareExecutable(requirements);
let serverOptions = prepareExecutable(requirements, collectXmlJavaExtensions(extensions.all));
let languageClient = new LanguageClient('xml', 'XML Support', serverOptions, clientOptions);
let toDispose = context.subscriptions;
let disposable = languageClient.start();
Expand Down Expand Up @@ -113,6 +114,12 @@ export function activate(context: ExtensionContext) {
return text;
};

/*if (extensions.onDidChange) {// Theia doesn't support this API yet
extensions.onDidChange(() => {
onExtensionChange(extensions.all);
});
}*/

disposable = activateTagClosing(tagProvider, { xml: true, xsl: true }, Commands.AUTO_CLOSE_TAGS);
toDispose.push(disposable);
});
Expand Down
14 changes: 10 additions & 4 deletions src/javaServerStarter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ declare var v8debug;

const DEBUG = (typeof v8debug === 'object') || startedInDebugMode();

export function prepareExecutable(requirements: RequirementsData): Executable {
export function prepareExecutable(requirements: RequirementsData, xmlJavaExtensions: string[]): Executable {
let executable: Executable = Object.create(null);
let options: ExecutableOptions = Object.create(null);
options.env = process.env;
options.stdio = 'pipe';
executable.options = options;
executable.command = path.resolve(requirements.java_home + '/bin/java');
executable.args = prepareParams(requirements);
executable.args = prepareParams(requirements, xmlJavaExtensions);
return executable;
}

function prepareParams(requirements: RequirementsData): string[] {
function prepareParams(requirements: RequirementsData, xmlJavaExtensions: string[]): string[] {
let params: string[] = [];
if (DEBUG) {
params.push('-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1054,quiet=y');
Expand All @@ -38,7 +38,13 @@ function prepareParams(requirements: RequirementsData): string[] {
let server_home: string = path.resolve(__dirname, '../server');
let launchersFound: Array<string> = glob.sync('**/org.eclipse.lsp4xml-uber.jar', { cwd: server_home });
if (launchersFound.length) {
params.push('-jar'); params.push(path.resolve(server_home, launchersFound[0]));
let xmlJavaExtensionsClasspath = '';
if (xmlJavaExtensions.length > 0) {
const pathSeparator = os.platform() == 'win32' ? ';' : ':';
xmlJavaExtensionsClasspath = pathSeparator + xmlJavaExtensions.join(pathSeparator);
}
params.push('-cp'); params.push(path.resolve(server_home, launchersFound[0]) + xmlJavaExtensionsClasspath);
params.push('org.eclipse.lsp4xml.XMLServerLauncher');
} else {
return null;
}
Expand Down
55 changes: 55 additions & 0 deletions src/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict';

import * as vscode from 'vscode';
import * as path from 'path';
import { Commands } from './commands';

let existingExtensions: Array<string>;

export function collectXmlJavaExtensions(extensions: readonly vscode.Extension<any>[]): string[] {
const result = [];
if (extensions && extensions.length) {
for (const extension of extensions) {
const contributesSection = extension.packageJSON['contributes'];
if (contributesSection) {
const xmlJavaExtensions = contributesSection['xml.javaExtensions'];
if (Array.isArray(xmlJavaExtensions) && xmlJavaExtensions.length) {
for (const xmLJavaExtensionPath of xmlJavaExtensions) {
result.push(path.resolve(extension.extensionPath, xmLJavaExtensionPath));
}
}
}
}
}
// Make a copy of extensions:
existingExtensions = result.slice();
return result;
}

export function onExtensionChange(extensions: readonly vscode.Extension<any>[]) {
if (!existingExtensions) {
return;
}
const oldExtensions = new Set(existingExtensions.slice());
const newExtensions = collectXmlJavaExtensions(extensions);
let hasChanged = ( oldExtensions.size !== newExtensions.length);
if (!hasChanged) {
for (const newExtension of newExtensions) {
if (!oldExtensions.has(newExtension)) {
hasChanged = true;
break;
}
}
}

if (hasChanged) {
const msg = `Extensions to the XML Language Server changed, reloading ${vscode.env.appName} is required for the changes to take effect.`;
const action = 'Reload';
const restartId = Commands.RELOAD_WINDOW;
vscode.window.showWarningMessage(msg, action).then((selection) => {
if (action === selection) {
vscode.commands.executeCommand(restartId);
}
});
}
}
2 changes: 1 addition & 1 deletion src/tagClosing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function activateTagClosing(tagProvider: (document: TextDocument, positio
isEnabled = true;
}

function onDidChangeTextDocument(document: TextDocument, changes: TextDocumentContentChangeEvent[]) {
function onDidChangeTextDocument(document: TextDocument, changes: ReadonlyArray<TextDocumentContentChangeEvent>) {
if (!isEnabled) {
return;
}
Expand Down

0 comments on commit c04c50b

Please sign in to comment.