@@ -870,6 +870,30 @@ function resolveSettings(document: TextDocument): Promise<TextDocumentSettings>
870
870
connection . sendRequest ( ProbeFailedRequest . type , params ) ;
871
871
}
872
872
}
873
+ if ( settings . format && settings . validate === Validate . on && TextDocumentSettings . hasLibrary ( settings ) ) {
874
+ const Uri = URI . parse ( uri ) ;
875
+ const isFile = Uri . scheme === 'file' ;
876
+ let pattern : string = isFile
877
+ ? Uri . path . replace ( / \\ / g, '/' )
878
+ : Uri . path ;
879
+ pattern = pattern . replace ( '[' , '\\[' ) ;
880
+ pattern = pattern . replace ( ']' , '\\]' ) ;
881
+ pattern = pattern . replace ( '{' , '\\{' ) ;
882
+ pattern = pattern . replace ( '}' , '\\}' ) ;
883
+
884
+ const filter : DocumentFilter = { scheme : Uri . scheme , pattern : pattern } ;
885
+ const options : DocumentFormattingRegistrationOptions = { documentSelector : [ filter ] } ;
886
+ if ( ! isFile ) {
887
+ formatterRegistrations . set ( uri , connection . client . register ( DocumentFormattingRequest . type , options ) ) ;
888
+ } else {
889
+ const filePath = getFilePath ( uri ) ! ;
890
+ withCLIEngine ( ( cli ) => {
891
+ if ( ! cli . isPathIgnored ( filePath ) ) {
892
+ formatterRegistrations . set ( uri , connection . client . register ( DocumentFormattingRequest . type , options ) ) ;
893
+ }
894
+ } , settings ) ;
895
+ }
896
+ }
873
897
return settings ;
874
898
} ) ;
875
899
} , ( ) => {
@@ -1050,30 +1074,6 @@ function setupDocumentsListeners() {
1050
1074
if ( settings . validate !== Validate . on || ! TextDocumentSettings . hasLibrary ( settings ) ) {
1051
1075
return ;
1052
1076
}
1053
- if ( settings . format ) {
1054
- const uri = URI . parse ( event . document . uri ) ;
1055
- const isFile = uri . scheme === 'file' ;
1056
- let pattern : string = isFile
1057
- ? uri . path . replace ( / \\ / g, '/' )
1058
- : uri . path ;
1059
- pattern = pattern . replace ( '[' , '\\[' ) ;
1060
- pattern = pattern . replace ( ']' , '\\]' ) ;
1061
- pattern = pattern . replace ( '{' , '\\{' ) ;
1062
- pattern = pattern . replace ( '}' , '\\}' ) ;
1063
-
1064
- const filter : DocumentFilter = { scheme : uri . scheme , pattern : pattern } ;
1065
- const options : DocumentFormattingRegistrationOptions = { documentSelector : [ filter ] } ;
1066
- if ( ! isFile ) {
1067
- formatterRegistrations . set ( event . document . uri , connection . client . register ( DocumentFormattingRequest . type , options ) ) ;
1068
- } else {
1069
- const filePath = getFilePath ( uri ) ! ;
1070
- withCLIEngine ( ( cli ) => {
1071
- if ( ! cli . isPathIgnored ( filePath ) ) {
1072
- formatterRegistrations . set ( event . document . uri , connection . client . register ( DocumentFormattingRequest . type , options ) ) ;
1073
- }
1074
- } , settings ) ;
1075
- }
1076
- }
1077
1077
if ( settings . run === 'onSave' ) {
1078
1078
messageQueue . addNotificationMessage ( ValidateNotification . type , event . document , event . document . version ) ;
1079
1079
}
@@ -1125,6 +1125,10 @@ function environmentChanged() {
1125
1125
for ( let document of documents . all ( ) ) {
1126
1126
messageQueue . addNotificationMessage ( ValidateNotification . type , document , document . version ) ;
1127
1127
}
1128
+ for ( const unregistration of formatterRegistrations . values ( ) ) {
1129
+ unregistration . then ( disposable => disposable . dispose ( ) ) ;
1130
+ }
1131
+ formatterRegistrations . clear ( ) ;
1128
1132
}
1129
1133
1130
1134
function trace ( message : string , verbose ?: string ) : void {
0 commit comments