Skip to content

Commit 6e221ab

Browse files
autoClosingBrackets are forced off if autoCloseTags is enabled
Fixes #38 Signed-off-by: Nikolas Komonen <nikolaskomonen@gmail.com>
1 parent 022d05b commit 6e221ab

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@
150150
"scope": "window"
151151
}
152152
}
153+
},
154+
"configurationDefaults": {
155+
"[xml]": {
156+
"editor.autoClosingBrackets": "never"
157+
}
153158
}
154159
}
155160
}

src/extension.ts

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@
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, LanguageConfiguration } from "vscode";
16+
import { languages, IndentAction, workspace, window, commands, ExtensionContext, TextDocument, Position, LanguageConfiguration } from "vscode";
1717
import * as path from 'path';
1818
import * as os from 'os';
1919
import { activateTagClosing } from './tagClosing';
20+
import { WorkspaceFoldersFeature } from 'vscode-languageclient/lib/workspaceFolders';
21+
22+
export interface ScopeInfo {
23+
scope : "default" | "global" | "workspace" | "folder";
24+
configurationTarget: boolean;
25+
}
2026

2127
namespace TagCloseRequest {
2228
export const type: RequestType<TextDocumentPositionParams, string, any, any> = new RequestType('xml/closeTag');
2329
}
2430

31+
let ignoreAutoCloseTags = false;
32+
2533
export function activate(context: ExtensionContext) {
2634
let storagePath = context.storagePath;
2735
if (!storagePath) {
@@ -45,11 +53,16 @@ export function activate(context: ExtensionContext) {
4553
revealOutputChannelOn: RevealOutputChannelOn.Never,
4654
initializationOptions: { settings: getSettings() },
4755
synchronize: {
48-
configurationSection: ['xml']
56+
//preferences starting with these will trigger didChangeConfiguration
57+
configurationSection: ['xml', '[xml]']
4958
},
5059
middleware: {
5160
workspace: {
52-
didChangeConfiguration: () => languageClient.sendNotification(DidChangeConfigurationNotification.type, { settings: getSettings() })
61+
didChangeConfiguration: () => {
62+
languageClient.sendNotification(DidChangeConfigurationNotification.type, { settings: getSettings() });
63+
verifyAutoClosing();
64+
}
65+
5366
}
5467
}
5568
}
@@ -86,7 +99,7 @@ export function activate(context: ExtensionContext) {
8699
client: true
87100
},
88101
format: {
89-
enabled : true,
102+
enabled: true,
90103
splitAttributes: false
91104
},
92105
completion: {
@@ -102,11 +115,65 @@ export function activate(context: ExtensionContext) {
102115
settings['logs']['file'] = logfile;
103116
return settings;
104117
}
118+
}
105119

106120

121+
function verifyAutoClosing() {
122+
let configXML = workspace.getConfiguration();
123+
let autoCloseTags = configXML.get("xml.completion.autoCloseTags");
124+
getScopeLevel("xml.completion", "autoCloseTags");
125+
let autoClosingBrackets = configXML.get("[xml]");
126+
console.log(autoClosingBrackets);
127+
autoClosingBrackets = autoClosingBrackets["editor.autoClosingBrackets"];
128+
if (autoCloseTags && autoClosingBrackets != "never" && !ignoreAutoCloseTags) {
129+
window.showWarningMessage(
130+
"The [xml].editor.autoClosingBrackets setting conflicts with xml.completion.autoCloseTags. It's recommended to disable it.",
131+
"Disable",
132+
"Don't show again").then((selection) => {
133+
if (selection == "Disable") {
134+
let scopeInfo : ScopeInfo = getScopeLevel("", "[xml]");
135+
workspace.getConfiguration().update("[xml]", { "editor.autoClosingBrackets": "never" }, scopeInfo.configurationTarget).then(
136+
() => console.log('[xml].editor.autoClosingBrackets globally set to never'),
137+
(error) => console.log(error)
138+
);
139+
}
140+
else if(selection == "Don't show again") {
141+
ignoreAutoCloseTags = true;
142+
}
143+
});
144+
}
145+
}
107146

147+
function getScopeLevel(configurationKey : string, key : string) : ScopeInfo{
108148

149+
let configXML = workspace.getConfiguration(configurationKey);
150+
let result = configXML.inspect(key);
151+
let scope, configurationTarget;
152+
if(result.workspaceFolderValue == undefined) {
153+
if(result.workspaceValue == undefined) {
154+
if(result.globalValue == undefined) {
155+
scope = "default"
156+
configurationTarget = true;
157+
}
158+
else {
159+
scope = "global";
160+
configurationTarget = true;
161+
}
162+
}
163+
else {
164+
scope = "workspace";
165+
configurationTarget = false;
166+
}
167+
}
168+
else {
169+
scope = "folder";
170+
configurationTarget = undefined;
171+
}
172+
let scopeInfo : ScopeInfo = {"scope": scope, "configurationTarget": configurationTarget};
173+
return scopeInfo;
174+
109175
}
176+
110177
function getIndentationRules(): LanguageConfiguration {
111178
return {
112179
onEnterRules: [

0 commit comments

Comments
 (0)