Skip to content

Commit

Permalink
WIP demo download executable from internet, then run
Browse files Browse the repository at this point in the history
Signed-off-by: David Thompson <[email protected]>
  • Loading branch information
datho7561 committed Sep 1, 2020
1 parent d8478a5 commit 9c1cc6e
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 129 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@
"description": "Set a custom folder path for cached XML Schemas. An absolute path is expected, although the ~ prefix (for the user home directory) is supported.",
"scope": "window"
},
"xml.server.binary.enabled": {
"type": "boolean",
"default": "false",
"description": "Use an experimental binary build of the LemMinX XML language server instead of the Java version. Additions to LemMinX provided by other extensions won't work.",
"scope": "window"
},
"xml.validation.noGrammar": {
"type": "string",
"enum": [
Expand Down
202 changes: 102 additions & 100 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import { prepareExecutable } from './javaServerStarter';
import { LanguageClientOptions, RevealOutputChannelOn, LanguageClient, DidChangeConfigurationNotification, RequestType, TextDocumentPositionParams, ReferencesRequest, NotificationType, MessageType } from 'vscode-languageclient';
import { LanguageClientOptions, RevealOutputChannelOn, LanguageClient, DidChangeConfigurationNotification, RequestType, TextDocumentPositionParams, ReferencesRequest, NotificationType, MessageType, Executable } from 'vscode-languageclient';
import * as requirements from './requirements';
import { languages, IndentAction, workspace, window, commands, ExtensionContext, TextDocument, Position, LanguageConfiguration, Uri, extensions, Command } from "vscode";
import * as path from 'path';
Expand All @@ -30,7 +30,7 @@ export interface ScopeInfo {
* Interface for the FileAssociation shape.
* @param systemId - The path to a valid XSD.
* @param pattern - The file pattern associated with the XSD.
*
*
* @returns None
*/
export interface XMLFileAssociation {
Expand All @@ -40,7 +40,7 @@ export interface XMLFileAssociation {

/**
* Interface for APIs exposed from the extension.
*
*
* @remarks
* A sample code to use these APIs are as following:
* const ext = await vscode.extensions.getExtension('redhat.vscode-xml').activate();
Expand All @@ -52,61 +52,61 @@ export interface XMLFileAssociation {
export interface XMLExtensionApi {
/**
* Adds XML Catalogs in addition to the catalogs defined in the settings.json file.
*
*
* @remarks
* An example is to call this API:
* ```ts
* addXMLCatalogs(['path/to/catalog.xml', 'path/to/anotherCatalog.xml'])
* ```
* ```
* @param catalogs - A list of path to XML catalogs
* @returns None
*/
addXMLCatalogs(catalogs: string[]): void;
/**
* Removes XML Catalogs from the extension.
*
*
* @remarks
* An example is to call this API:
* ```ts
* removeXMLCatalogs(['path/to/catalog.xml', 'path/to/anotherCatalog.xml'])
* ```
* ```
* @param catalogs - A list of path to XML catalogs
* @returns None
*/
removeXMLCatalogs(catalogs: string[]): void;
/**
* Adds XML File Associations in addition to the catalogs defined in the settings.json file.
*
*
* @remarks
* An example is to call this API:
* ```ts
* addXMLFileAssociations([{
* "systemId": "path/to/file.xsd",
* "systemId": "path/to/file.xsd",
* "pattern": "file1.xml"
* },{
* "systemId": "http://www.w3.org/2001/XMLSchema.xsd",
* "pattern": "file2.xml"
* }])
* ```
* @param fileAssociations - A list of file association
* ```
* @param fileAssociations - A list of file association
* @returns None
*/
addXMLFileAssociations(fileAssociations: XMLFileAssociation[]): void;
/**
* Removes XML File Associations from the extension.
*
*
* @remarks
* An example is to call this API:
* ```ts
* removeXMLFileAssociations([{
* "systemId": "path/to/file.xsd",
* "systemId": "path/to/file.xsd",
* "pattern": "file1.xml"
* },{
* "systemId": "http://www.w3.org/2001/XMLSchema.xsd",
* "pattern": "file2.xml"
* }])
* ```
* @param fileAssociations - A list of file association
* ```
* @param fileAssociations - A list of file association
* @returns None
*/
removeXMLFileAssociations(fileAssociations: XMLFileAssociation[]): void;
Expand Down Expand Up @@ -195,101 +195,103 @@ export function activate(context: ExtensionContext) {
}
}

let serverOptions = prepareExecutable(requirements, collectXmlJavaExtensions(extensions.all), context);
languageClient = new LanguageClient('xml', 'XML Support', serverOptions, clientOptions);
let toDispose = context.subscriptions;
let disposable = languageClient.start();
toDispose.push(disposable);
prepareExecutable(requirements, collectXmlJavaExtensions(extensions.all), context).then((serverOptions: Executable) => {
languageClient = new LanguageClient('xml', 'XML Support', serverOptions, clientOptions);
let toDispose = context.subscriptions;
let disposable = languageClient.start();
toDispose.push(disposable);

languages.setLanguageConfiguration('xml', getIndentationRules());
languages.setLanguageConfiguration('xsl', getIndentationRules());

return languageClient.onReady().then(() => {
//Detect JDK configuration changes
disposable = subscribeJDKChangeConfiguration();
toDispose.push(disposable);
languages.setLanguageConfiguration('xml', getIndentationRules());
languages.setLanguageConfiguration('xsl', getIndentationRules());

// Code Lens actions
context.subscriptions.push(commands.registerCommand(Commands.SHOW_REFERENCES, (uriString: string, position: Position) => {
const uri = Uri.parse(uriString);
workspace.openTextDocument(uri).then(document => {
// Consume references service from the XML Language Server
let param = languageClient.code2ProtocolConverter.asTextDocumentPositionParams(document, position);
languageClient.sendRequest(ReferencesRequest.type, param).then(locations => {
commands.executeCommand(Commands.EDITOR_SHOW_REFERENCES, uri, languageClient.protocol2CodeConverter.asPosition(position), locations.map(languageClient.protocol2CodeConverter.asLocation));
return languageClient.onReady().then(() => {
//Detect JDK configuration changes
disposable = subscribeJDKChangeConfiguration();
toDispose.push(disposable);

// Code Lens actions
context.subscriptions.push(commands.registerCommand(Commands.SHOW_REFERENCES, (uriString: string, position: Position) => {
const uri = Uri.parse(uriString);
workspace.openTextDocument(uri).then(document => {
// Consume references service from the XML Language Server
let param = languageClient.code2ProtocolConverter.asTextDocumentPositionParams(document, position);
languageClient.sendRequest(ReferencesRequest.type, param).then(locations => {
commands.executeCommand(Commands.EDITOR_SHOW_REFERENCES, uri, languageClient.protocol2CodeConverter.asPosition(position), locations.map(languageClient.protocol2CodeConverter.asLocation));
})
})
})
}));
}));

setupActionableNotificationListener(languageClient);
setupActionableNotificationListener(languageClient);

context.subscriptions.push(commands.registerCommand(Commands.OPEN_SETTINGS, async (settingId?: string) => {
commands.executeCommand('workbench.action.openSettings', settingId);
}));
context.subscriptions.push(commands.registerCommand(Commands.OPEN_SETTINGS, async (settingId?: string) => {
commands.executeCommand('workbench.action.openSettings', settingId);
}));

// Setup autoCloseTags
const tagProvider = (document: TextDocument, position: Position) => {
let param = languageClient.code2ProtocolConverter.asTextDocumentPositionParams(document, position);
let text = languageClient.sendRequest(TagCloseRequest.type, param);
return text;
};
context.subscriptions.push(activateTagClosing(tagProvider, { xml: true, xsl: true }, Commands.AUTO_CLOSE_TAGS));
// Setup autoCloseTags
const tagProvider = (document: TextDocument, position: Position) => {
let param = languageClient.code2ProtocolConverter.asTextDocumentPositionParams(document, position);
let text = languageClient.sendRequest(TagCloseRequest.type, param);
return text;
};
context.subscriptions.push(activateTagClosing(tagProvider, { xml: true, xsl: true }, Commands.AUTO_CLOSE_TAGS));

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

const api: XMLExtensionApi = {
// add API set catalogs to internal memory
addXMLCatalogs: (catalogs: string[]) => {
const externalXmlCatalogs = externalXmlSettings.xmlCatalogs;
catalogs.forEach(element => {
if (!externalXmlCatalogs.includes(element)) {
externalXmlCatalogs.push(element);
}
});
languageClient.sendNotification(DidChangeConfigurationNotification.type, { settings: getXMLSettings(requirements.java_home) });
onConfigurationChange();
},
// remove API set catalogs to internal memory
removeXMLCatalogs: (catalogs: string[]) => {
catalogs.forEach(element => {
const api: XMLExtensionApi = {
// add API set catalogs to internal memory
addXMLCatalogs: (catalogs: string[]) => {
const externalXmlCatalogs = externalXmlSettings.xmlCatalogs;
if (externalXmlCatalogs.includes(element)) {
const itemIndex = externalXmlCatalogs.indexOf(element);
externalXmlCatalogs.splice(itemIndex, 1);
}
});
languageClient.sendNotification(DidChangeConfigurationNotification.type, { settings: getXMLSettings(requirements.java_home) });
onConfigurationChange();
},
// add API set fileAssociations to internal memory
addXMLFileAssociations: (fileAssociations: XMLFileAssociation[]) => {
const externalfileAssociations = externalXmlSettings.xmlFileAssociations;
fileAssociations.forEach(element => {
if (!externalfileAssociations.some(fileAssociation => fileAssociation.systemId === element.systemId)) {
externalfileAssociations.push(element);
}
});
languageClient.sendNotification(DidChangeConfigurationNotification.type, { settings: getXMLSettings(requirements.java_home) });
onConfigurationChange();
},
// remove API set fileAssociations to internal memory
removeXMLFileAssociations: (fileAssociations: XMLFileAssociation[]) => {
const externalfileAssociations = externalXmlSettings.xmlFileAssociations;
fileAssociations.forEach(element => {
const itemIndex = externalfileAssociations.findIndex(fileAssociation => fileAssociation.systemId === element.systemId) //returns -1 if item not found
if (itemIndex > -1) {
externalfileAssociations.splice(itemIndex, 1);
}
});
languageClient.sendNotification(DidChangeConfigurationNotification.type, { settings: getXMLSettings(requirements.java_home) });
onConfigurationChange();
}
};
return api;
catalogs.forEach(element => {
if (!externalXmlCatalogs.includes(element)) {
externalXmlCatalogs.push(element);
}
});
languageClient.sendNotification(DidChangeConfigurationNotification.type, { settings: getXMLSettings(requirements.java_home) });
onConfigurationChange();
},
// remove API set catalogs to internal memory
removeXMLCatalogs: (catalogs: string[]) => {
catalogs.forEach(element => {
const externalXmlCatalogs = externalXmlSettings.xmlCatalogs;
if (externalXmlCatalogs.includes(element)) {
const itemIndex = externalXmlCatalogs.indexOf(element);
externalXmlCatalogs.splice(itemIndex, 1);
}
});
languageClient.sendNotification(DidChangeConfigurationNotification.type, { settings: getXMLSettings(requirements.java_home) });
onConfigurationChange();
},
// add API set fileAssociations to internal memory
addXMLFileAssociations: (fileAssociations: XMLFileAssociation[]) => {
const externalfileAssociations = externalXmlSettings.xmlFileAssociations;
fileAssociations.forEach(element => {
if (!externalfileAssociations.some(fileAssociation => fileAssociation.systemId === element.systemId)) {
externalfileAssociations.push(element);
}
});
languageClient.sendNotification(DidChangeConfigurationNotification.type, { settings: getXMLSettings(requirements.java_home) });
onConfigurationChange();
},
// remove API set fileAssociations to internal memory
removeXMLFileAssociations: (fileAssociations: XMLFileAssociation[]) => {
const externalfileAssociations = externalXmlSettings.xmlFileAssociations;
fileAssociations.forEach(element => {
const itemIndex = externalfileAssociations.findIndex(fileAssociation => fileAssociation.systemId === element.systemId) //returns -1 if item not found
if (itemIndex > -1) {
externalfileAssociations.splice(itemIndex, 1);
}
});
languageClient.sendNotification(DidChangeConfigurationNotification.type, { settings: getXMLSettings(requirements.java_home) });
onConfigurationChange();
}
};
return api;
});
});
});

Expand Down
Loading

0 comments on commit 9c1cc6e

Please sign in to comment.