@@ -27,7 +27,7 @@ type ForgeFmtResult = {
2727
2828function isFmtInstalled ( ) : boolean {
2929 try {
30- exec ( " forge fmt --version" , ( error , _stdout , _stderr ) => {
30+ exec ( ' forge fmt --version' , ( error , _stdout , _stderr ) => {
3131 if ( error ) {
3232 throw error ;
3333 }
@@ -38,35 +38,30 @@ function isFmtInstalled(): boolean {
3838 }
3939}
4040
41- function forgeFmt (
42- args : ForgeFmtArgs ,
43- debug ?: boolean ,
44- ) : Promise < ForgeFmtResult > {
41+ function forgeFmt ( args : ForgeFmtArgs , debug ?: boolean ) : Promise < ForgeFmtResult > {
4542 const { options, files } = args ;
4643 const { root, check, raw } = options ;
4744
48- const commandArgs = [ " fmt" ] ;
45+ const commandArgs = [ ' fmt' ] ;
4946
5047 if ( root ) {
51- commandArgs . push ( " --root" , `"${ root } "` ) ;
48+ commandArgs . push ( ' --root' , `"${ root } "` ) ;
5249 }
5350
5451 if ( check ) {
55- commandArgs . push ( " --check" ) ;
52+ commandArgs . push ( ' --check' ) ;
5653 }
5754
5855 if ( raw ) {
59- commandArgs . push ( " --raw" ) ;
56+ commandArgs . push ( ' --raw' ) ;
6057 }
6158
62- commandArgs . push (
63- ...files . map ( ( file ) => ( file . includes ( " " ) ? `"${ file } "` : file ) ) ,
64- ) ;
59+ commandArgs . push ( ...files . map ( ( file ) => ( file . includes ( ' ' ) ? `"${ file } "` : file ) ) ) ;
6560
66- const command = `forge ${ commandArgs . join ( " " ) } ` ;
61+ const command = `forge ${ commandArgs . join ( ' ' ) } ` ;
6762
6863 if ( debug ) {
69- console . debug ( " command =>" , command ) ;
64+ console . debug ( ' command =>' , command ) ;
7065 }
7166
7267 return new Promise ( ( resolve , reject ) => {
@@ -159,13 +154,6 @@ function registerForgeFmtLinter(context: vscode.ExtensionContext): {fileDisposab
159154 return ;
160155 }
161156
162- if ( ! vscode . workspace . workspaceFolders ?. [ 0 ] ) {
163- vscode . window . showErrorMessage (
164- "Unable to find workspace root. Please open a folder and try again." ,
165- ) ;
166- return ;
167- }
168-
169157 const options : ForgeFmtOptions = {
170158 root : vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath ,
171159 check : false ,
@@ -174,68 +162,97 @@ function registerForgeFmtLinter(context: vscode.ExtensionContext): {fileDisposab
174162
175163 const args : ForgeFmtArgs = {
176164 options,
177- files : [ vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath ] ,
165+ files : [ document . fileName ] ,
178166 } ;
179167
180168 forgeFmt ( args )
181169 . then ( ( result ) => {
182170 if ( result . exitCode === 0 ) {
183- vscode . window . showInformationMessage ( " Forge fmt ran successfully." ) ;
171+ vscode . window . showInformationMessage ( ' Forge fmt ran successfully.' ) ;
184172 } else {
185- vscode . window . showErrorMessage (
186- "Forge fmt failed. Please check the output for details." ,
187- ) ;
173+ vscode . window . showErrorMessage ( 'Forge fmt failed. Please check the output for details.' ) ;
188174
189175 console . log ( result . output ) ;
190176 }
191177 } )
192178 . catch ( ( error ) => {
193- vscode . window . showErrorMessage (
194- "Forge fmt failed. Please check the output for details." ,
195- ) ;
179+ vscode . window . showErrorMessage ( 'Forge fmt failed. Please check the output for details.' ) ;
196180 console . error ( error ) ;
197181 } ) ;
198- } ,
199- ) ;
182+ } else {
183+ vscode . window . showErrorMessage ( 'Forge fmt is only available for solidity files.' ) ;
184+ }
185+ } ) ;
200186
201- const formatter = vscode . languages . registerDocumentFormattingEditProvider (
202- "solidity" ,
203- {
204- provideDocumentFormattingEdits : ( document ) => {
205- if ( ! isFmtInstalled ( ) ) {
206- vscode . window . showErrorMessage (
207- "Forge fmt is not installed. Please install it and try again." ,
208- ) ;
209- return ;
187+ const lintSolWorkspace = vscode . commands . registerCommand ( 'osmium.format-sol-workspace' , function ( ) {
188+ if ( ! isFmtInstalled ( ) ) {
189+ vscode . window . showErrorMessage ( 'Forge fmt is not installed. Please install it and try again.' ) ;
190+ return ;
191+ }
192+
193+ if ( ! vscode . workspace . workspaceFolders ?. [ 0 ] ) {
194+ vscode . window . showErrorMessage ( 'Unable to find workspace root. Please open a folder and try again.' ) ;
195+ return ;
196+ }
197+
198+ const options : ForgeFmtOptions = {
199+ root : vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath ,
200+ check : false ,
201+ raw : false ,
202+ } ;
203+
204+ const args : ForgeFmtArgs = {
205+ options,
206+ files : [ vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath ] ,
207+ } ;
208+
209+ forgeFmt ( args )
210+ . then ( ( result ) => {
211+ if ( result . exitCode === 0 ) {
212+ vscode . window . showInformationMessage ( 'Forge fmt ran successfully.' ) ;
213+ } else {
214+ vscode . window . showErrorMessage ( 'Forge fmt failed. Please check the output for details.' ) ;
215+
216+ console . log ( result . output ) ;
210217 }
218+ } )
219+ . catch ( ( error ) => {
220+ vscode . window . showErrorMessage ( 'Forge fmt failed. Please check the output for details.' ) ;
221+ console . error ( error ) ;
222+ } ) ;
223+ } ) ;
211224
212- const options : ForgeFmtOptions = {
213- root : vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath ,
214- check : false ,
215- raw : false ,
216- } ;
225+ const formatter = vscode . languages . registerDocumentFormattingEditProvider ( 'solidity' , {
226+ provideDocumentFormattingEdits : ( document ) => {
227+ if ( ! isFmtInstalled ( ) ) {
228+ vscode . window . showErrorMessage ( 'Forge fmt is not installed. Please install it and try again.' ) ;
229+ return ;
230+ }
217231
218- const args : ForgeFmtArgs = {
219- options,
220- files : [ document . fileName ] ,
221- } ;
232+ const options : ForgeFmtOptions = {
233+ root : vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath ,
234+ check : false ,
235+ raw : false ,
236+ } ;
222237
223- return forgeFmt ( args ) . then ( ( result ) => {
224- if ( result . exitCode === 0 ) {
225- vscode . window . showInformationMessage ( "Forge fmt ran successfully." ) ;
226- } else {
227- vscode . window . showErrorMessage (
228- "Forge fmt failed. Please check the output for details." ,
229- ) ;
238+ const args : ForgeFmtArgs = {
239+ options,
240+ files : [ document . fileName ] ,
241+ } ;
230242
231- console . log ( result . output ) ;
232- }
243+ return forgeFmt ( args ) . then ( ( result ) => {
244+ if ( result . exitCode === 0 ) {
245+ vscode . window . showInformationMessage ( 'Forge fmt ran successfully.' ) ;
246+ } else {
247+ vscode . window . showErrorMessage ( 'Forge fmt failed. Please check the output for details.' ) ;
233248
234- return [ ] ;
235- } ) ;
236- } ,
249+ console . log ( result . output ) ;
250+ }
251+
252+ return [ ] ;
253+ } ) ;
237254 } ,
238- ) ;
255+ } ) ;
239256
240257 context . subscriptions . push ( lintSolFile ) ;
241258 context . subscriptions . push ( lintSolWorkspace ) ;
0 commit comments