1313import { prepareExecutable } from './javaServerStarter' ;
1414import { LanguageClientOptions , RevealOutputChannelOn , LanguageClient , DidChangeConfigurationNotification , RequestType , TextDocumentPositionParams } from 'vscode-languageclient' ;
1515import * 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" ;
1717import * as path from 'path' ;
1818import * as os from 'os' ;
1919import { 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
2127namespace TagCloseRequest {
2228 export const type : RequestType < TextDocumentPositionParams , string , any , any > = new RequestType ( 'xml/closeTag' ) ;
2329}
2430
31+ let ignoreAutoCloseTags = false ;
32+
2533export function activate ( context : ExtensionContext ) {
2634 let storagePath = context . storagePath ;
2735 if ( ! storagePath ) {
@@ -45,11 +53,18 @@ 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+ if ( ! ignoreAutoCloseTags ) {
64+ verifyAutoClosing ( ) ;
65+ }
66+ }
67+
5368 }
5469 }
5570 }
@@ -86,7 +101,7 @@ export function activate(context: ExtensionContext) {
86101 client : true
87102 } ,
88103 format : {
89- enabled : true ,
104+ enabled : true ,
90105 splitAttributes : false
91106 } ,
92107 completion : {
@@ -102,11 +117,62 @@ export function activate(context: ExtensionContext) {
102117 settings [ 'logs' ] [ 'file' ] = logfile ;
103118 return settings ;
104119 }
120+ }
105121
106122
123+ function verifyAutoClosing ( ) {
124+ let configXML = workspace . getConfiguration ( ) ;
125+ let closeTags = configXML . get ( "xml.completion.autoCloseTags" ) ;
126+ let closeBrackets = configXML . get ( "[xml]" ) [ "editor.autoClosingBrackets" ] ;
127+ if ( closeTags && closeBrackets != "never" ) {
128+ window . showWarningMessage (
129+ "The [xml].editor.autoClosingBrackets setting conflicts with xml.completion.autoCloseTags. It's recommended to disable it." ,
130+ "Disable" ,
131+ "Ignore" ) . then ( ( selection ) => {
132+ if ( selection == "Disable" ) {
133+ let scopeInfo : ScopeInfo = getScopeLevel ( "" , "[xml]" ) ;
134+ workspace . getConfiguration ( ) . update ( "[xml]" , { "editor.autoClosingBrackets" : "never" } , scopeInfo . configurationTarget ) . then (
135+ ( ) => console . log ( '[xml].editor.autoClosingBrackets globally set to never' ) ,
136+ ( error ) => console . log ( error )
137+ ) ;
138+ }
139+ else if ( selection == "Ignore" ) {
140+ ignoreAutoCloseTags = true ;
141+ }
142+ } ) ;
143+ }
144+ }
107145
146+ function getScopeLevel ( configurationKey : string , key : string ) : ScopeInfo {
108147
148+ let configXML = workspace . getConfiguration ( configurationKey ) ;
149+ let result = configXML . inspect ( key ) ;
150+ let scope , configurationTarget ;
151+ if ( result . workspaceFolderValue == undefined ) {
152+ if ( result . workspaceValue == undefined ) {
153+ if ( result . globalValue == undefined ) {
154+ scope = "default"
155+ configurationTarget = true ;
156+ }
157+ else {
158+ scope = "global" ;
159+ configurationTarget = true ;
160+ }
161+ }
162+ else {
163+ scope = "workspace" ;
164+ configurationTarget = false ;
165+ }
166+ }
167+ else {
168+ scope = "folder" ;
169+ configurationTarget = undefined ;
170+ }
171+ let scopeInfo : ScopeInfo = { "scope" : scope , "configurationTarget" : configurationTarget } ;
172+ return scopeInfo ;
173+
109174}
175+
110176function getIndentationRules ( ) : LanguageConfiguration {
111177 return {
112178 onEnterRules : [
0 commit comments