@@ -42,55 +42,49 @@ const extMatch = n => ({
4242 pattern : n . startsWith ( "**/" ) ? n : ( "**/" + n )
4343} ) ;
4444
45- const getBeautifyType = function ( doc ) {
45+ const getBeautifyType = function ( doc , dontAsk ) {
4646 if ( doc . languageId === 'javascript' ) return 'js' ;
4747 if ( doc . languageId === 'json' ) return 'js' ;
4848 if ( doc . languageId === 'html' ) return 'html' ;
4949 if ( doc . languageId === 'css' ) return 'css' ;
5050
51+ const type = doc . isUntitled ? "" : path . extname ( doc . fileName )
52+ . toLowerCase ( ) ;
53+ const cfg = vscode . workspace . getConfiguration ( 'beautify' ) ;
54+ //if a type is set on the window, use that
55+ //check if the file is in the users json schema set
56+ const jsSchema = vscode . workspace . getConfiguration ( 'json' )
57+ . schemas ;
58+ if ( jsSchema . length ) {
59+ let matcher = [ ] ;
60+ jsSchema . forEach ( schema => {
61+ if ( typeof schema . fileMatch === 'string' ) matcher . push ( extMatch ( schema . fileMatch ) ) ;
62+ else matcher = matcher . concat ( schema . fileMatch . map ( extMatch ) ) ;
63+ } ) ;
64+ if ( vscode . languages . match ( matcher , doc ) ) return "js" ;
65+ }
66+ if ( cfg . HTMLfiles . indexOf ( type ) + 1 || cfg . HTMLfiles . indexOf ( type . slice ( 1 ) ) + 1 ) return 'html' ;
67+ else if ( cfg . CSSfiles . indexOf ( type ) + 1 || cfg . CSSfiles . indexOf ( type . slice ( 1 ) ) + 1 ) return 'css' ;
68+ else if ( cfg . JSfiles . indexOf ( type ) + 1 || cfg . JSfiles . indexOf ( type . slice ( 1 ) ) + 1 ) return 'js' ;
69+ if ( dontAsk ) return ;
70+
5171 return new Promise ( ( resolve , reject ) => {
52- const type = doc . isUntitled ? "" : path . extname ( doc . fileName )
53- . toLowerCase ( ) ;
54- const cfg = vscode . workspace . getConfiguration ( 'beautify' ) ;
55- //if a type is set on the window, use that
56- //check if the file is in the users json schema set
57- const jsSchema = vscode . workspace . getConfiguration ( 'json' )
58- . schemas ;
59- if ( jsSchema . length ) {
60- let matcher = [ ] ;
61- jsSchema . forEach ( schema => {
62- if ( typeof schema . fileMatch === 'string' ) matcher . push ( extMatch ( schema . fileMatch ) ) ;
63- else matcher = matcher . concat ( schema . fileMatch . map ( extMatch ) ) ;
64- } ) ;
65- if ( vscode . languages . match ( matcher , doc ) ) return resolve ( "js" ) ;
66- }
67- if ( cfg . HTMLfiles . indexOf ( type ) + 1 ) {
68- //showDepWarning();
69- return resolve ( "html" ) ;
70- } else if ( cfg . CSSfiles . indexOf ( type ) + 1 ) {
71- //showDepWarning();
72- return resolve ( "css" ) ;
73- } else if ( cfg . JSfiles . indexOf ( type ) + 1 ) {
74- //showDepWarning();
75- return resolve ( "js" ) ;
76- } else {
77- //Ask what they want to do:
78- return vscode . window . showQuickPick ( [ {
79- label : "JS" ,
80- description : "Does JavaScript and JSON"
72+ //Ask what they want to do:
73+ return vscode . window . showQuickPick ( [ {
74+ label : "JS" ,
75+ description : "Does JavaScript and JSON"
8176 } , {
82- label : "CSS"
77+ label : "CSS"
8378 } , {
84- label : "HTML"
79+ label : "HTML"
8580 } ] , {
86- matchOnDescription : true ,
87- placeHolder : "Couldn't determine type to beautify, please choose."
88- } )
89- . then ( function ( choice ) {
90- if ( ! choice || ! choice . label ) return reject ( 'no beautify type selected' ) ;
91- return resolve ( choice . label . toLowerCase ( ) ) ;
92- } ) ;
93- }
81+ matchOnDescription : true ,
82+ placeHolder : "Couldn't determine type to beautify, please choose."
83+ } )
84+ . then ( function ( choice ) {
85+ if ( ! choice || ! choice . label ) return reject ( 'no beautify type selected' ) ;
86+ return resolve ( choice . label . toLowerCase ( ) ) ;
87+ } ) ;
9488 } ) ;
9589} ;
9690
@@ -173,8 +167,10 @@ function beautifyOnSave(doc) {
173167 let refType = doc . languageId ;
174168
175169 if ( refType === 'javascript' ) refType = 'js' ;
176- if ( [ 'json' , 'js' , 'html' , 'css' ] . indexOf ( refType ) === - 1 ) return ;
177-
170+ if ( [ 'json' , 'js' , 'html' , 'css' ] . indexOf ( refType ) === - 1 ) {
171+ refType = getBeautifyType ( doc , true ) ;
172+ if ( ! refType ) return ;
173+ }
178174 if ( cfg . onSave === true || (
179175 Array . isArray ( cfg . onSave ) && cfg . onSave . indexOf ( refType ) >= 0
180176 ) ) {
0 commit comments