Skip to content

Commit 0004f19

Browse files
fbriconNikolasKomonen
authored andcommitted
Add XSL support (#56)
Signed-off-by: Fred Bricon <fbricon@gmail.com>
1 parent 73c50ef commit 0004f19

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
"bugs": "https://github.com/redhat-developer/vscode-xml/issues",
1111
"preview": true,
1212
"keywords": [
13-
"xml"
13+
"xml", "xsl", "xsd"
1414
],
1515
"engines": {
1616
"vscode": "^1.27.0"
1717
},
1818
"activationEvents": [
19-
"onLanguage:xml"
19+
"onLanguage:xml",
20+
"onLanguage:xsl"
2021
],
2122
"main": "./out/src/extension",
2223
"scripts": {

src/extension.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import { prepareExecutable } from './javaServerStarter';
1414
import { LanguageClientOptions, RevealOutputChannelOn, LanguageClient, DidChangeConfigurationNotification, RequestType, TextDocumentPositionParams } from 'vscode-languageclient';
1515
import * as requirements from './requirements';
16-
import { languages, IndentAction, workspace, window, commands, ExtensionContext, TextDocument, Position, WorkspaceConfiguration } from "vscode";
16+
import { languages, IndentAction, workspace, window, commands, ExtensionContext, TextDocument, Position, WorkspaceConfiguration, LanguageConfiguration } from "vscode";
1717
import * as path from 'path';
1818
import * as os from 'os';
1919
import { activateTagClosing } from './tagClosing';
@@ -40,8 +40,8 @@ export function activate(context: ExtensionContext) {
4040
throw error;
4141
}).then(requirements => {
4242
let clientOptions: LanguageClientOptions = {
43-
// Register the server for java
44-
documentSelector: ['xml'],
43+
// Register the server for xml and xsl
44+
documentSelector: ['xml', 'xsl'],
4545
revealOutputChannelOn: RevealOutputChannelOn.Never,
4646
initializationOptions: { settings: getSettings() },
4747
synchronize: {
@@ -66,24 +66,11 @@ export function activate(context: ExtensionContext) {
6666
return languageClient.sendRequest(TagCloseRequest.type, param);
6767
};
6868

69-
disposable = activateTagClosing(tagRequestor, { xml: true }, 'xml.completion.autoCloseTags');
69+
disposable = activateTagClosing(tagRequestor, { xml: true, xsl: true }, 'xml.completion.autoCloseTags');
7070
toDispose.push(disposable);
7171
});
72-
languages.setLanguageConfiguration('xml', {
73-
onEnterRules: [
74-
{
75-
beforeText: new RegExp(`<([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
76-
afterText: /^<\/([_:\w][_:\w-.\d]*)\s*>/i,
77-
action: { indentAction: IndentAction.IndentOutdent }
78-
},
79-
{
80-
beforeText: new RegExp(`<(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
81-
action: { indentAction: IndentAction.Indent }
82-
}
83-
],
84-
});
85-
86-
72+
languages.setLanguageConfiguration('xml', getIndentationRules());
73+
languages.setLanguageConfiguration('xsl', getIndentationRules());
8774
});
8875

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

10188

10289
}
90+
function getIndentationRules(): LanguageConfiguration {
91+
return {
92+
onEnterRules: [
93+
{
94+
beforeText: new RegExp(`<([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
95+
afterText: /^<\/([_:\w][_:\w-.\d]*)\s*>/i,
96+
action: { indentAction: IndentAction.IndentOutdent }
97+
},
98+
{
99+
beforeText: new RegExp(`<(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
100+
action: { indentAction: IndentAction.Indent }
101+
}
102+
],
103+
};
104+
}
105+

src/tagClosing.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ export function activateTagClosing(tagProvider: (document: TextDocument, positio
3939
if (!isEnabled) {
4040
return;
4141
}
42-
let activeDocument = window.activeTextEditor && window.activeTextEditor.document;
43-
let a = document !== activeDocument;
44-
let b = changes.length === 0;
42+
let activeDocument = window.activeTextEditor && window.activeTextEditor.document;
43+
let a = document !== activeDocument;
44+
let b = changes.length === 0;
4545
if (document !== activeDocument || changes.length === 0) {
4646
return;
4747
}
4848
if (typeof timeout !== 'undefined') {
4949
clearTimeout(timeout);
5050
}
5151
let lastChange = changes[changes.length - 1];
52-
let lastCharacter = lastChange.text[lastChange.text.length - 1];
52+
let lastCharacter = lastChange.text[lastChange.text.length - 1];
5353
if (lastChange.rangeLength > 0 || lastCharacter !== '>' && lastCharacter !== '/') {
5454
return;
5555
}

0 commit comments

Comments
 (0)