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

Formatter expand/collapse/ignore empty XML tags #241

Closed
Closed
Show file tree
Hide file tree
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
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ The following settings are supported:
* `xml.catalogs` : Register XML catalog files.
* `xml.logs.client` : Enable/disable logging to the Output view.
* `xml.fileAssociations` : Associate XML Schemas to XML file patterns.
* `xml.format.emptyElements` : Expand/collapse empty elements during formatting. Defaults to `ignore`.
* `xml.format.splitAttributes` : Set to `true` to split node attributes onto multiple lines during formatting. Defaults to `false`.
* `xml.format.joinCDATALines` : Set to `true` to join lines in CDATA content during formatting. Defaults to `false`.
* `xml.format.joinContentLines` : Set to `true` to join lines in node content during formatting. Defaults to `false`.
Expand All @@ -75,10 +76,7 @@ The following settings are supported:
* `xml.server.workDir`: Set an absolute path for all cached schemas to be stored. Defaults to `~/.lemminx`.
* `xml.codeLens.enabled`: Enable/disable XML CodeLens. Default is `false`.
* `xml.symbols.excluded`: Disable document symbols (Outline) for the given file name patterns. Updating file name patterns does not automatically reload the Outline view for the relevant file(s). Each file must either be reopened or changed, in order to trigger an Outline view reload.

Since 0.12.0:
* `xml.symbols.maxItemsComputed`: The maximum number of outline symbols and folding regions computed (limited for performance reasons). Default is `5000`.


## Custom XML Extensions

The [LemMinX - XML Language Server](https://github.com/eclipse/lemminx) can be extended to support custom completion, hover, validation, rename, etc by using the [Java Service Provider Interface (SPI)](https://www.baeldung.com/java-spi) mechanism. vscode-xml provides the ability use your custom XML support provider, by adding external jars to the XML language server's classpath.
Expand Down
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@
"default": true,
"description": "Should the server log to client output"
},
"xml.format.emptyElements": {
"type": "string",
"enum": [
"ignore",
"collapse",
"expand"
],
"default": "ignore",
"description": "Expand/collapse empty elements.",
"scope": "window"
},
"xml.format.splitAttributes": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -281,11 +292,6 @@
},
"description": "Disable document symbols (Outline) for the given file name patterns. Updating file name patterns does not automatically reload the Outline view for the relevant file(s). Each file must either be reopened or changed, in order to trigger an Outline view reload.\n\nExample:\n[\n \"**/*LargeFile.xml\"\n]",
"scope": "window"
},
"xml.symbols.maxItemsComputed": {
"type": "integer",
"default": 5000,
"description": "The maximum number of outline symbols and folding regions computed (limited for performance reasons)."
}
}
},
Expand Down
7 changes: 0 additions & 7 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,4 @@ export namespace Commands {
*/
export const RELOAD_WINDOW = 'workbench.action.reloadWindow';

/**
* Open settings command
*
* A `settingId: string` parameter can be optionally provided
*/
export const OPEN_SETTINGS = 'xml.open.settings';

}
74 changes: 12 additions & 62 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
*/

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 } from 'vscode-languageclient';
import * as requirements from './requirements';
import { languages, IndentAction, workspace, window, commands, ExtensionContext, TextDocument, Position, LanguageConfiguration, Uri, extensions, Disposable, Command } 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';
Expand All @@ -22,7 +22,7 @@ import { onConfigurationChange, subscribeJDKChangeConfiguration } from './settin
import { collectXmlJavaExtensions, onExtensionChange } from './plugin';

export interface ScopeInfo {
scope: "default" | "global" | "workspace" | "folder";
scope : "default" | "global" | "workspace" | "folder";
configurationTarget: boolean;
}

Expand All @@ -31,20 +31,6 @@ namespace TagCloseRequest {
}


namespace SymbolsLimitExceededNotification {
export const type: NotificationType<{commandId: string, message: string}, any> = new NotificationType('xml/symbolsLimitExceeded');
}

interface ActionableMessage {
severity: MessageType;
message: string;
data?: any;
commands?: Command[];
}

namespace ActionableNotification {
export const type = new NotificationType<ActionableMessage, void>('xml/actionableNotification');
}

export function activate(context: ExtensionContext) {
let storagePath = context.storagePath;
Expand Down Expand Up @@ -82,11 +68,9 @@ export function activate(context: ExtensionContext) {
'references'
]
}
},
actionableNotificationSupport: true,
openSettingsCommandSupport: true
}
}
},
},
synchronize: {
//preferences starting with these will trigger didChangeConfiguration
configurationSection: ['xml', '[xml]']
Expand Down Expand Up @@ -123,26 +107,21 @@ export function activate(context: ExtensionContext) {
})
}));

setupActionableNotificationListener(languageClient);

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) => {
//Setup autoCloseTags
let 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
extensions.onDidChange(() => {
onExtensionChange(extensions.all);
});
}

disposable = activateTagClosing(tagProvider, { xml: true, xsl: true }, Commands.AUTO_CLOSE_TAGS);
toDispose.push(disposable);
});
languages.setLanguageConfiguration('xml', getIndentationRules());
languages.setLanguageConfiguration('xsl', getIndentationRules());
Expand All @@ -160,7 +139,7 @@ export function activate(context: ExtensionContext) {
let configXML = workspace.getConfiguration().get('xml');
let xml;
if (!configXML) { //Set default preferences if not provided
const defaultValue =
const defaultValue =
{
xml: {
trace: {
Expand All @@ -181,7 +160,7 @@ export function activate(context: ExtensionContext) {
xml = defaultValue;
} else {
let x = JSON.stringify(configXML); //configXML is not a JSON type
xml = { "xml": JSON.parse(x) };
xml = { "xml" : JSON.parse(x)};
}
xml['xml']['logs']['file'] = logfile;
xml['xml']['useCache'] = true;
Expand All @@ -192,7 +171,7 @@ export function activate(context: ExtensionContext) {

function getIndentationRules(): LanguageConfiguration {
return {

// indentationRules referenced from:
// https://github.com/microsoft/vscode/blob/d00558037359acceea329e718036c19625f91a1a/extensions/html-language-features/client/src/htmlMain.ts#L114-L115
indentationRules: {
Expand All @@ -213,32 +192,3 @@ function getIndentationRules(): LanguageConfiguration {
};
}

function setupActionableNotificationListener(languageClient: LanguageClient): void {
languageClient.onNotification(ActionableNotification.type, (notification: ActionableMessage) => {
let show = null;
switch (notification.severity) {
case MessageType.Info:
show = window.showInformationMessage;
break;
case MessageType.Warning:
show = window.showWarningMessage;
break;
case MessageType.Error:
show = window.showErrorMessage;
break;
}
if (!show) {
return;
}
const titles: string[] = notification.commands.map(a => a.title);
show(notification.message, ...titles).then((selection) => {
for (const action of notification.commands) {
if (action.title === selection) {
const args: any[] = (action.arguments) ? action.arguments : [];
commands.executeCommand(action.command, ...args);
break;
}
}
});
});
}