@@ -52,15 +52,16 @@ export function activate(context: ExtensionContext) {
5252 // Register the server for xml and xsl
5353 documentSelector : [ 'xml' , 'xsl' ] ,
5454 revealOutputChannelOn : RevealOutputChannelOn . Never ,
55- initializationOptions : { settings : getSettings ( ) } ,
55+ //wrap with key 'settings' so it can be handled same a DidChangeConfiguration
56+ initializationOptions : { "settings" : getXMLSettings ( ) } ,
5657 synchronize : {
5758 //preferences starting with these will trigger didChangeConfiguration
5859 configurationSection : [ 'xml' , '[xml]' ]
5960 } ,
6061 middleware : {
6162 workspace : {
6263 didChangeConfiguration : ( ) => {
63- languageClient . sendNotification ( DidChangeConfigurationNotification . type , { settings : getSettings ( ) } ) ;
64+ languageClient . sendNotification ( DidChangeConfigurationNotification . type , { settings : getXMLSettings ( ) } ) ;
6465 if ( ! ignoreAutoCloseTags ) {
6566 verifyAutoClosing ( ) ;
6667 }
@@ -90,35 +91,45 @@ export function activate(context: ExtensionContext) {
9091 languages . setLanguageConfiguration ( 'xsl' , getIndentationRules ( ) ) ;
9192 } ) ;
9293
93- function getSettings ( ) : JSON {
94- let configXML = workspace . getConfiguration ( ) ;
95- configXML = configXML . get ( 'xml' ) ;
96- let settings : JSON ;
97- if ( ! configXML ) {
98- const defaultValue = {
99- trace : {
100- server : 'verbose'
101- } ,
102- logs : {
103- client : true
104- } ,
105- format : {
106- enabled : true ,
107- splitAttributes : false
108- } ,
109- completion : {
110- autoCloseTags : false
94+ /**
95+ * Returns a json object with key 'xml' and a json object value that
96+ * holds all xml. settings.
97+ *
98+ * Returns: {
99+ * 'xml': {...}
100+ * }
101+ */
102+ function getXMLSettings ( ) : JSON {
103+ let configXML = workspace . getConfiguration ( ) . get ( 'xml' ) ;
104+ configXML = null ;
105+ let xml ;
106+ if ( ! configXML ) { //Set default preferences if not provided
107+ const defaultValue =
108+ {
109+ xml : {
110+ trace : {
111+ server : 'verbose'
112+ } ,
113+ logs : {
114+ client : true
115+ } ,
116+ format : {
117+ enabled : true ,
118+ splitAttributes : false
119+ } ,
120+ completion : {
121+ autoCloseTags : false
122+ }
111123 }
112124 }
113- const x = JSON . stringify ( defaultValue ) ;
114- settings = JSON . parse ( x ) ;
125+ xml = defaultValue ;
115126 } else {
116- const x = JSON . stringify ( configXML ) ;
117- settings = JSON . parse ( x ) ;
127+ let x = JSON . stringify ( configXML ) ; //configXML is not a JSON type
128+ xml = { "xml" : JSON . parse ( x ) } ;
118129 }
119- settings [ 'logs' ] [ 'file' ] = logfile ;
120- settings [ 'useCache' ] = true ;
121- return settings ;
130+ xml [ 'xml' ] [ 'logs' ] [ 'file' ] = logfile ;
131+ xml [ 'xml' ] [ 'useCache' ] = true ;
132+ return xml ;
122133 }
123134}
124135
0 commit comments