Skip to content

Commit ca53b93

Browse files
authored
Merge pull request #32 from daimor/autocompile
autocompile on save with status notification
2 parents 8350648 + faa4077 commit ca53b93

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

extension.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const activate = context => {
2323
return {
2424

2525
init,
26+
get: ( option ) => options.get( option ),
2627
conn: () => {
2728
const _conn = options.get( 'conn' )
2829
_conn.toString = () => JSON.stringify( Object.assign( {}, _conn, { password: '***' } ), null, 4 )
@@ -57,12 +58,21 @@ const activate = context => {
5758

5859
} , null, context.subscriptions ) //reload config on event
5960

61+
workspace.onDidSaveTextDocument( ( file ) => {
62+
if ( !config.get( 'autoCompile' )) {
63+
return
64+
}
65+
if (languages.includes(file.languageId)) {
66+
importCompileExport();
67+
}
68+
})
69+
6070
const currentDoc = CurrentDoc({ window, languages, log })
6171

6272
const Save = ({ name, log, fileName }) => ( err, data ) => {
6373

6474
// IsApiError, ExportDoc - global
65-
const isGetDocError = IsApiError( name, 'getDoc', log )
75+
const isGetDocError = IsApiError( name, 'getDoc', log, window )
6676
if ( isGetDocError({ err, data }) ) return
6777

6878
const completed = () => log( 'Completed.' )
@@ -73,7 +83,7 @@ const activate = context => {
7383

7484
const Export = ( { api, name, log, fileName } ) => ( err, data ) => {
7585
// IsApiError, Save - from upper scope
76-
const isCompileError = IsApiError( name, 'compile', log )
86+
const isCompileError = IsApiError( name, 'compile', log, window )
7787
if ( isCompileError({ err, data }) ) return;
7888
// after compilation API returns updated storage definition
7989
// but, currently, we don`t have any AST implementation
@@ -87,13 +97,13 @@ const activate = context => {
8797
const Compile = ( { api, name, log, fileName } ) => ( err, data ) => {
8898

8999
// IsApiError, Export
90-
const isImportError = IsApiError( name, 'import', log )
100+
const isImportError = IsApiError( name, 'import', log, window )
91101
if ( isImportError({ err, data }) ) return;
92102

93103
const exportCurrent = Export( { api, name, log, fileName } )
94104
//log( `Compile ${ name }` )
95105
api.compile( name, exportCurrent )
96-
106+
window.showInformationMessage( `${name}: Compile successed` )
97107
}
98108

99109
// import -> compile -> export

is-api-error.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
module.exports = ( name, action, log ) => ({ err, data = {} }) => {
1+
module.exports = ( name, action, log, window ) => ({ err, data = {} }) => {
22

33
const { result, status, console } = data
44

55
if ( err ){
66
const errtext = err.code ? err.code + ' ' + err.message : err
7-
log( `${ name } ${ action }: ${ errtext }` )
7+
const errMsg = `${ name } ${ action }: ${ errtext }`
8+
log( errMsg )
9+
window.showErrorMessage( errMsg )
810
return true
911
}
1012

1113
if ( !data || !status || !( status.errors instanceof Array ) ){
12-
log( `Unknown response from ${ name } ${ action }: ${ JSON.stringify( res ) }` )
14+
const errMsg = `Unknown response from ${ name } ${ action }: ${ JSON.stringify( res ) }`
15+
log( errMsg )
16+
window.showErrorMessage( errMsg )
1317
return true
1418
}
1519

1620
if ( result && result.status ){
1721
log( result.status )
18-
return true
22+
window.showErrorMessage( result.status )
23+
return true
1924
}
2025

2126
if ( status.errors.length !== 0 ){
22-
log( `${ name } ${ action }:` )
27+
errMsg = `${ name } ${ action }:`
28+
log( errMsg )
29+
window.showErrorMessage( errMsg )
2330
console.forEach( line => log( line ) )
2431
return true
2532
}

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@
163163
"description": "Specifies a category: CLS = classes; RTN = routines; CSP = csp files; OTH = other. Default is *",
164164
"type": "string",
165165
"default": "*"
166+
},
167+
"cos.autoCompile": {
168+
"description": "Autocompile on save file",
169+
"type": "boolean",
170+
"default": false
166171
}
167172
}
168173
}

0 commit comments

Comments
 (0)