1
1
import * as vscode from "vscode" ;
2
2
import { AtelierAPI } from "../api" ;
3
3
import { config , FILESYSTEM_SCHEMA } from "../extension" ;
4
- import { outputChannel } from "../utils" ;
4
+ import { outputChannel , outputConsole } from "../utils" ;
5
5
import { DocumentContentProvider } from "../providers/DocumentContentProvider" ;
6
6
import { ClassNode } from "../explorer/models/classesNode" ;
7
7
import { PackageNode } from "../explorer/models/packageNode" ;
8
8
import { RoutineNode } from "../explorer/models/routineNode" ;
9
9
import { NodeBase } from "../explorer/models/nodeBase" ;
10
+ import { importAndCompile } from "./compile" ;
11
+
12
+ export let documentBeingProcessed : vscode . TextDocument = null ;
10
13
11
14
interface StudioAction extends vscode . QuickPickItem {
12
15
name : string ;
@@ -18,18 +21,20 @@ class StudioActions {
18
21
private api : AtelierAPI ;
19
22
private name : string ;
20
23
21
- public constructor ( uriOrNode : vscode . Uri | PackageNode | ClassNode | RoutineNode ) {
24
+ public constructor ( uriOrNode ? : vscode . Uri | PackageNode | ClassNode | RoutineNode ) {
22
25
if ( uriOrNode instanceof vscode . Uri ) {
23
26
const uri : vscode . Uri = uriOrNode ;
24
27
this . uri = uri ;
25
28
this . name = this . uri . path . slice ( 1 ) . replace ( / \/ / g, "." ) ;
26
29
this . api = new AtelierAPI ( uri . authority ) ;
27
- } else {
30
+ } else if ( uriOrNode ) {
28
31
const node : NodeBase = uriOrNode ;
29
32
this . api = new AtelierAPI ( ) ;
30
33
this . name = ( node instanceof PackageNode )
31
34
? node . fullName + ".PKG"
32
35
: node . fullName ;
36
+ } else {
37
+ this . api = new AtelierAPI ( ) ;
33
38
}
34
39
}
35
40
@@ -40,7 +45,7 @@ class StudioActions {
40
45
outputChannel . appendLine ( errorText ) ;
41
46
outputChannel . show ( ) ;
42
47
}
43
- outputChannel . appendLine ( JSON . stringify ( userAction ) ) ;
48
+ // outputChannel.appendLine(JSON.stringify(userAction));
44
49
switch ( serverAction ) {
45
50
case 0 :
46
51
/// do nothing
@@ -179,11 +184,10 @@ class StudioActions {
179
184
const query = `select * from %Atelier_v1_Utils.Extension_${ func } ` ;
180
185
let selectedText = "" ;
181
186
const editor = vscode . window . activeTextEditor ;
182
- if ( ! editor ) {
183
- selectedText = "" ;
187
+ if ( editor ) {
188
+ const selection = editor . selection ;
189
+ selectedText = editor . document . getText ( selection ) ;
184
190
}
185
- const selection = editor . selection ;
186
- selectedText = editor . document . getText ( selection ) ;
187
191
188
192
const parameters = afterUserAction
189
193
? [ type . toString ( ) , action . id , this . name , answer , msg ]
@@ -198,12 +202,13 @@ class StudioActions {
198
202
( ) =>
199
203
this . api
200
204
. actionQuery ( query , parameters )
201
- . then ( data => {
202
- const actionInfo = data . result . content . pop ( ) ;
203
- actionInfo . save = action . save ;
204
- return actionInfo ;
205
+ . then ( async data => {
206
+ if ( action . save ) {
207
+ await this . processSaveFlag ( action . save ) ;
208
+ }
209
+ outputConsole ( data . console ) ;
210
+ return data . result . content . pop ( ) ;
205
211
} )
206
- . then ( this . processSaveFlag )
207
212
. then ( this . processUserAction )
208
213
. then ( answer => {
209
214
if ( answer ) {
@@ -286,19 +291,38 @@ class StudioActions {
286
291
} ) ;
287
292
}
288
293
289
- private async processSaveFlag ( userAction ) {
290
- if ( userAction . save ) {
291
- const bitString = userAction . save . toString ( ) . padStart ( 3 , "0" ) ;
292
- // Save the current document
293
- if ( bitString . charAt ( 0 ) === "1" ) {
294
- await vscode . window . activeTextEditor . document . save ( ) ;
294
+ public changedNamespace ( ) {
295
+ const changedNamespaceAction = {
296
+ id : "5" ,
297
+ label : "Changed Namespace"
298
+ } ;
299
+ this . userAction ( changedNamespaceAction , false , "" , "" , 1 ) ;
300
+ }
301
+
302
+ private async processSaveFlag ( saveFlag : number ) {
303
+ const bitString = saveFlag . toString ( ) . padStart ( 3 , "0" ) ;
304
+ const saveAndCompile = async ( document : vscode . TextDocument ) => {
305
+ if ( document . isDirty ) {
306
+ // Prevent onDidSave from compiling the file
307
+ // in order to await the importAndCompile function
308
+ documentBeingProcessed = document ;
309
+ await document . save ( ) ;
310
+ await importAndCompile ( false , document ) ;
311
+ documentBeingProcessed = null ;
295
312
}
296
- // Save all documents
297
- if ( bitString . charAt ( 2 ) === "1" ) {
298
- await vscode . workspace . saveAll ( ) ;
313
+ } ;
314
+
315
+ // Save the current document
316
+ if ( bitString . charAt ( 0 ) === "1" ) {
317
+ await saveAndCompile ( vscode . window . activeTextEditor . document ) ;
318
+ }
319
+
320
+ // Save all documents
321
+ if ( bitString . charAt ( 2 ) === "1" ) {
322
+ for ( const document of vscode . workspace . textDocuments ) {
323
+ await saveAndCompile ( document )
299
324
}
300
325
}
301
- return userAction ;
302
326
}
303
327
}
304
328
@@ -330,4 +354,9 @@ export async function contextMenu(node: PackageNode | ClassNode | RoutineNode):
330
354
}
331
355
const studioActions = new StudioActions ( nodeOrUri ) ;
332
356
return studioActions && studioActions . getMenu ( "" , true ) ;
357
+ }
358
+
359
+ export async function fireChangedNamespace ( ) {
360
+ const studioActions = new StudioActions ( ) ;
361
+ return studioActions && studioActions . changedNamespace ( ) ;
333
362
}
0 commit comments