Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add XSL support #56

Merged
merged 1 commit into from
Oct 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -10,13 +10,14 @@
"bugs": "https://github.com/redhat-developer/vscode-xml/issues",
"preview": true,
"keywords": [
"xml"
"xml", "xsl", "xsd"
],
"engines": {
"vscode": "^1.27.0"
},
"activationEvents": [
"onLanguage:xml"
"onLanguage:xml",
"onLanguage:xsl"
],
"main": "./out/src/extension",
"scripts": {
41 changes: 22 additions & 19 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
import { prepareExecutable } from './javaServerStarter';
import { LanguageClientOptions, RevealOutputChannelOn, LanguageClient, DidChangeConfigurationNotification, RequestType, TextDocumentPositionParams } from 'vscode-languageclient';
import * as requirements from './requirements';
import { languages, IndentAction, workspace, window, commands, ExtensionContext, TextDocument, Position, WorkspaceConfiguration } from "vscode";
import { languages, IndentAction, workspace, window, commands, ExtensionContext, TextDocument, Position, WorkspaceConfiguration, LanguageConfiguration } from "vscode";
import * as path from 'path';
import * as os from 'os';
import { activateTagClosing } from './tagClosing';
@@ -40,8 +40,8 @@ export function activate(context: ExtensionContext) {
throw error;
}).then(requirements => {
let clientOptions: LanguageClientOptions = {
// Register the server for java
documentSelector: ['xml'],
// Register the server for xml and xsl
documentSelector: ['xml', 'xsl'],
revealOutputChannelOn: RevealOutputChannelOn.Never,
initializationOptions: { settings: getSettings() },
synchronize: {
@@ -66,24 +66,11 @@ export function activate(context: ExtensionContext) {
return languageClient.sendRequest(TagCloseRequest.type, param);
};

disposable = activateTagClosing(tagRequestor, { xml: true }, 'xml.completion.autoCloseTags');
disposable = activateTagClosing(tagRequestor, { xml: true, xsl: true }, 'xml.completion.autoCloseTags');
toDispose.push(disposable);
});
languages.setLanguageConfiguration('xml', {
onEnterRules: [
{
beforeText: new RegExp(`<([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
afterText: /^<\/([_:\w][_:\w-.\d]*)\s*>/i,
action: { indentAction: IndentAction.IndentOutdent }
},
{
beforeText: new RegExp(`<(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
action: { indentAction: IndentAction.Indent }
}
],
});


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

function getSettings(): JSON {
@@ -100,3 +87,19 @@ export function activate(context: ExtensionContext) {


}
function getIndentationRules(): LanguageConfiguration {
return {
onEnterRules: [
{
beforeText: new RegExp(`<([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
afterText: /^<\/([_:\w][_:\w-.\d]*)\s*>/i,
action: { indentAction: IndentAction.IndentOutdent }
},
{
beforeText: new RegExp(`<(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
action: { indentAction: IndentAction.Indent }
}
],
};
}

8 changes: 4 additions & 4 deletions src/tagClosing.ts
Original file line number Diff line number Diff line change
@@ -39,17 +39,17 @@ export function activateTagClosing(tagProvider: (document: TextDocument, positio
if (!isEnabled) {
return;
}
let activeDocument = window.activeTextEditor && window.activeTextEditor.document;
let a = document !== activeDocument;
let b = changes.length === 0;
let activeDocument = window.activeTextEditor && window.activeTextEditor.document;
let a = document !== activeDocument;
let b = changes.length === 0;
if (document !== activeDocument || changes.length === 0) {
return;
}
if (typeof timeout !== 'undefined') {
clearTimeout(timeout);
}
let lastChange = changes[changes.length - 1];
let lastCharacter = lastChange.text[lastChange.text.length - 1];
let lastCharacter = lastChange.text[lastChange.text.length - 1];
if (lastChange.rangeLength > 0 || lastCharacter !== '>' && lastCharacter !== '/') {
return;
}