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,64 @@ 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 autoCloseTags = configXML . get ( "xml.completion.autoCloseTags" ) ;
126+ let autoClosingBrackets = configXML . get ( "[xml]" ) ;
127+ console . log ( autoClosingBrackets ) ;
128+ autoClosingBrackets = autoClosingBrackets [ "editor.autoClosingBrackets" ] ;
129+ if ( autoCloseTags && autoClosingBrackets != "never" ) {
130+ window . showWarningMessage (
131+ "The [xml].editor.autoClosingBrackets setting conflicts with xml.completion.autoCloseTags. It's recommended to disable it." ,
132+ "Disable" ,
133+ "Don't show again" ) . then ( ( selection ) => {
134+ if ( selection == "Disable" ) {
135+ let scopeInfo : ScopeInfo = getScopeLevel ( "" , "[xml]" ) ;
136+ workspace . getConfiguration ( ) . update ( "[xml]" , { "editor.autoClosingBrackets" : "never" } , scopeInfo . configurationTarget ) . then (
137+ ( ) => console . log ( '[xml].editor.autoClosingBrackets globally set to never' ) ,
138+ ( error ) => console . log ( error )
139+ ) ;
140+ }
141+ else if ( selection == "Don't show again" ) {
142+ ignoreAutoCloseTags = true ;
143+ }
144+ } ) ;
145+ }
146+ }
107147
148+ function getScopeLevel ( configurationKey : string , key : string ) : ScopeInfo {
108149
150+ let configXML = workspace . getConfiguration ( configurationKey ) ;
151+ let result = configXML . inspect ( key ) ;
152+ let scope , configurationTarget ;
153+ if ( result . workspaceFolderValue == undefined ) {
154+ if ( result . workspaceValue == undefined ) {
155+ if ( result . globalValue == undefined ) {
156+ scope = "default"
157+ configurationTarget = true ;
158+ }
159+ else {
160+ scope = "global" ;
161+ configurationTarget = true ;
162+ }
163+ }
164+ else {
165+ scope = "workspace" ;
166+ configurationTarget = false ;
167+ }
168+ }
169+ else {
170+ scope = "folder" ;
171+ configurationTarget = undefined ;
172+ }
173+ let scopeInfo : ScopeInfo = { "scope" : scope , "configurationTarget" : configurationTarget } ;
174+ return scopeInfo ;
175+
109176}
177+
110178function getIndentationRules ( ) : LanguageConfiguration {
111179 return {
112180 onEnterRules : [
0 commit comments