@@ -32,17 +32,15 @@ class StudioActions {
3232 private name : string ;
3333
3434 public constructor ( uriOrNode ?: vscode . Uri | PackageNode | ClassNode | RoutineNode ) {
35- if ( uriOrNode instanceof vscode . Uri ) {
35+ if ( uriOrNode instanceof vscode . Uri ) {
3636 const uri : vscode . Uri = uriOrNode ;
3737 this . uri = uri ;
3838 this . name = this . uri . path . slice ( 1 ) . replace ( / \/ / g, "." ) ;
3939 this . api = new AtelierAPI ( uri . authority ) ;
40- } else if ( uriOrNode ) {
40+ } else if ( uriOrNode ) {
4141 const node : NodeBase = uriOrNode ;
4242 this . api = new AtelierAPI ( ) ;
43- this . name = ( node instanceof PackageNode )
44- ? node . fullName + ".PKG"
45- : node . fullName ;
43+ this . name = node instanceof PackageNode ? node . fullName + ".PKG" : node . fullName ;
4644 } else {
4745 this . api = new AtelierAPI ( ) ;
4846 }
@@ -55,11 +53,11 @@ class StudioActions {
5553 outputChannel . appendLine ( errorText ) ;
5654 outputChannel . show ( ) ;
5755 }
58- if ( userAction . reload ) {
56+ if ( userAction . reload ) {
5957 const document = vscode . window . activeTextEditor . document ;
6058 loadChanges ( [ currentFile ( document ) ] ) ;
6159 }
62- if ( config ( ) . studioActionDebugOutput ) {
60+ if ( config ( ) . studioActionDebugOutput ) {
6361 outputChannel . appendLine ( JSON . stringify ( userAction ) ) ;
6462 }
6563 switch ( serverAction ) {
@@ -71,12 +69,10 @@ class StudioActions {
7169 . showWarningMessage ( target , { modal : true } , "Yes" , "No" )
7270 . then ( answer => ( answer === "Yes" ? "1" : answer === "No" ? "0" : "2" ) ) ;
7371 case 2 : // Run a CSP page/Template. The Target is the full url to the CSP page/Template
74- return new Promise ( ( resolve ) => {
72+ return new Promise ( resolve => {
7573 let answer = "2" ;
7674 const conn = config ( ) . conn ;
77- const column = vscode . window . activeTextEditor
78- ? vscode . window . activeTextEditor . viewColumn
79- : undefined ;
75+ const column = vscode . window . activeTextEditor ? vscode . window . activeTextEditor . viewColumn : undefined ;
8076 const panel = vscode . window . createWebviewPanel (
8177 "studioactionwebview" ,
8278 "Studio Extension Page" ,
@@ -86,7 +82,7 @@ class StudioActions {
8682 }
8783 ) ;
8884 panel . webview . onDidReceiveMessage ( message => {
89- if ( message . result && message . result === "done" ) {
85+ if ( message . result && message . result === "done" ) {
9086 answer = "1" ;
9187 panel . dispose ( ) ;
9288 }
@@ -97,8 +93,8 @@ class StudioActions {
9793 const api = new AtelierAPI ( ) ;
9894 api . actionQuery ( "select %Atelier_v1_Utils.General_GetCSPToken(?) token" , [ url . toString ( ) ] ) . then ( tokenObj => {
9995 const csptoken = tokenObj . result . content [ 0 ] . token ;
100- url . searchParams . set ( ' CSPCHD' , csptoken ) ;
101- url . searchParams . set ( ' Namespace' , conn . ns ) ;
96+ url . searchParams . set ( " CSPCHD" , csptoken ) ;
97+ url . searchParams . set ( " Namespace" , conn . ns ) ;
10298 panel . webview . html = `
10399 <!DOCTYPE html>
104100 <html lang="en">
@@ -133,7 +129,7 @@ class StudioActions {
133129 throw new Error ( "Not suppoorted" ) ;
134130 case 4 : // Insert the text in Target in the current document at the current selection point
135131 const editor = vscode . window . activeTextEditor ;
136- if ( editor ) {
132+ if ( editor ) {
137133 editor . edit ( editBuilder => {
138134 editBuilder . replace ( editor . selection , target ) ;
139135 } ) ;
@@ -144,28 +140,27 @@ class StudioActions {
144140 let classname = element ;
145141 let method : string ;
146142 let offset = 0 ;
147- if ( element . includes ( ":" ) ) {
143+ if ( element . includes ( ":" ) ) {
148144 [ classname , method ] = element . split ( ":" ) ;
149- if ( method . includes ( "+" ) ) {
145+ if ( method . includes ( "+" ) ) {
150146 offset = + method . split ( "+" ) [ 1 ] ;
151147 method = method . split ( "+" ) [ 0 ] ;
152148 }
153149 }
154150
155151 const splitClassname = classname . split ( "." ) ;
156152 const filetype = splitClassname [ splitClassname . length - 1 ] ;
157- const isCorrectMethod = ( text : string ) => ( filetype === "cls" )
158- ? text . match ( "Method " + method )
159- : text . startsWith ( method ) ;
153+ const isCorrectMethod = ( text : string ) =>
154+ filetype === "cls" ? text . match ( "Method " + method ) : text . startsWith ( method ) ;
160155
161156 const uri = DocumentContentProvider . getUri ( classname ) ;
162- vscode . window . showTextDocument ( uri , { " preview" : false } ) . then ( newEditor => {
163- if ( method ) {
157+ vscode . window . showTextDocument ( uri , { preview : false } ) . then ( newEditor => {
158+ if ( method ) {
164159 const document = newEditor . document ;
165- for ( let i = 0 ; i < document . lineCount ; i ++ ) {
160+ for ( let i = 0 ; i < document . lineCount ; i ++ ) {
166161 const line = document . lineAt ( i ) ;
167- if ( isCorrectMethod ( line . text ) ) {
168- if ( ! line . text . endsWith ( "{" ) ) offset ++ ;
162+ if ( isCorrectMethod ( line . text ) ) {
163+ if ( ! line . text . endsWith ( "{" ) ) offset ++ ;
169164 const cursor = newEditor . selection . active ;
170165 const newPosition = cursor . with ( i + offset , 0 ) ;
171166 newEditor . selection = new vscode . Selection ( newPosition , newPosition ) ;
@@ -179,14 +174,16 @@ class StudioActions {
179174 case 6 : // Display an alert dialog in Studio with the text from the Target variable.
180175 return vscode . window . showWarningMessage ( target , { modal : true } ) ;
181176 case 7 : // Display a dialog with a textbox and Yes/No/Cancel buttons.
182- return vscode . window . showInputBox ( {
183- prompt : target ,
184- } ) . then ( msg => {
185- return {
186- "msg" : ( msg ? msg : "" ) ,
187- "answer" : ( msg ? 1 : 2 )
188- }
189- } ) ;
177+ return vscode . window
178+ . showInputBox ( {
179+ prompt : target ,
180+ } )
181+ . then ( msg => {
182+ return {
183+ msg : msg ? msg : "" ,
184+ answer : msg ? 1 : 2 ,
185+ } ;
186+ } ) ;
190187 default :
191188 throw new Error ( "Not suppoorted" ) ;
192189 }
@@ -219,7 +216,7 @@ class StudioActions {
219216 this . api
220217 . actionQuery ( query , parameters )
221218 . then ( async data => {
222- if ( action . save ) {
219+ if ( action . save ) {
223220 await this . processSaveFlag ( action . save ) ;
224221 }
225222 outputConsole ( data . console ) ;
@@ -228,7 +225,7 @@ class StudioActions {
228225 . then ( this . processUserAction )
229226 . then ( answer => {
230227 if ( answer ) {
231- return ( answer . msg || answer . msg === "" )
228+ return answer . msg || answer . msg === ""
232229 ? this . userAction ( action , true , answer . answer , answer . msg , type )
233230 : this . userAction ( action , true , answer , "" , type ) ;
234231 }
@@ -241,9 +238,9 @@ class StudioActions {
241238 ) ;
242239 }
243240
244- private constructMenu ( menu , contextOnly = false ) : any [ ] {
241+ private constructMenu ( menu , contextMenu = false ) : any [ ] {
245242 return menu
246- . filter ( menuGroup => ! ( contextOnly && menuGroup . type === "main" ) )
243+ . filter ( menuGroup => ! ( contextMenu == ( menuGroup . type === "main" ) ) )
247244 . reduce (
248245 ( list , sub ) =>
249246 list . concat (
@@ -260,20 +257,13 @@ class StudioActions {
260257 } ) )
261258 ) ,
262259 [ ]
263- )
264- . sort ( ( el1 , el2 ) => ( el1 . type === "main" && el2 . type !== el1 . type ? - 1 : 1 ) )
265- . filter ( ( item : any , index : number , self : any ) => {
266- if ( item && item . type === "main" ) {
267- return true ;
268- }
269- return self . findIndex ( ( el ) : boolean => el . itemId === item . itemId ) === index ;
270- } ) ;
260+ ) ;
271261 }
272262
273263 public getMenu ( menuType : string , contextOnly = false ) : Thenable < any > {
274264 let selectedText = "" ;
275265 const editor = vscode . window . activeTextEditor ;
276- if ( this . uri && editor ) {
266+ if ( this . uri && editor ) {
277267 const selection = editor . selection ;
278268 selectedText = editor . document . getText ( selection ) ;
279269 }
@@ -286,22 +276,25 @@ class StudioActions {
286276 . then ( data => data . result . content )
287277 . then ( menu => this . constructMenu ( menu , contextOnly ) )
288278 . then ( menuItems => {
289- return vscode . window . showQuickPick < StudioAction > ( menuItems , { canPickMany : false } ) ;
279+ return vscode . window . showQuickPick < StudioAction > ( menuItems , {
280+ canPickMany : false ,
281+ placeHolder : `Pick server-side action to perform${ this . name ? " on " + this . name : "" } ` ,
282+ } ) ;
290283 } )
291284 . then ( action => this . userAction ( action ) ) ;
292285 }
293286
294287 public fireOtherStudioAction ( action : OtherStudioAction ) {
295288 const actionObject = {
296289 id : action . toString ( ) ,
297- label : getOtherStudioActionLabel ( action )
290+ label : getOtherStudioActionLabel ( action ) ,
298291 } ;
299- if ( action === OtherStudioAction . AttemptedEdit ) {
292+ if ( action === OtherStudioAction . AttemptedEdit ) {
300293 const query = "select * from %Atelier_v1_Utils.Extension_GetStatus(?)" ;
301294 this . api . actionQuery ( query , [ this . name ] ) . then ( statusObj => {
302295 const docStatus = statusObj . result . content . pop ( ) ;
303- if ( ! docStatus . editable ) {
304- vscode . commands . executeCommand ( ' undo' ) ;
296+ if ( ! docStatus . editable ) {
297+ vscode . commands . executeCommand ( " undo" ) ;
305298 this . userAction ( actionObject , false , "" , "" , 1 ) ;
306299 }
307300 } ) ;
@@ -313,7 +306,7 @@ class StudioActions {
313306 private async processSaveFlag ( saveFlag : number ) {
314307 const bitString = saveFlag . toString ( ) . padStart ( 3 , "0" ) ;
315308 const saveAndCompile = async ( document : vscode . TextDocument ) => {
316- if ( document . isDirty ) {
309+ if ( document . isDirty ) {
317310 // Prevent onDidSave from compiling the file
318311 // in order to await the importAndCompile function
319312 documentBeingProcessed = document ;
@@ -324,22 +317,22 @@ class StudioActions {
324317 } ;
325318
326319 // Save the current document
327- if ( bitString . charAt ( 0 ) === "1" ) {
320+ if ( bitString . charAt ( 0 ) === "1" ) {
328321 await saveAndCompile ( vscode . window . activeTextEditor . document ) ;
329322 }
330323
331324 // Save all documents
332- if ( bitString . charAt ( 2 ) === "1" ) {
333- for ( const document of vscode . workspace . textDocuments ) {
325+ if ( bitString . charAt ( 2 ) === "1" ) {
326+ for ( const document of vscode . workspace . textDocuments ) {
334327 await saveAndCompile ( document ) ;
335328 }
336329 }
337330 }
338331}
339332
340- export async function mainMenu ( uri : vscode . Uri ) {
333+ export async function mainMenu ( uri ? : vscode . Uri ) {
341334 uri = uri || vscode . window . activeTextEditor ?. document . uri ;
342- if ( ! uri || uri . scheme !== FILESYSTEM_SCHEMA ) {
335+ if ( uri && uri . scheme !== FILESYSTEM_SCHEMA ) {
343336 return ;
344337 }
345338 const studioActions = new StudioActions ( uri ) ;
@@ -362,19 +355,25 @@ export async function fireOtherStudioAction(action: OtherStudioAction, uri?: vsc
362355
363356function getOtherStudioActionLabel ( action : OtherStudioAction ) : string {
364357 let label = "" ;
365- switch ( action ) {
358+ switch ( action ) {
366359 case OtherStudioAction . AttemptedEdit :
367360 label = "Attempted Edit" ;
361+ break ;
368362 case OtherStudioAction . CreatedNewDocument :
369363 label = "Created New Document" ;
364+ break ;
370365 case OtherStudioAction . DeletedDocument :
371366 label = "Deleted Document" ;
367+ break ;
372368 case OtherStudioAction . OpenedDocument :
373369 label = "Opened Document" ;
370+ break ;
374371 case OtherStudioAction . ClosedDocument :
375372 label = "Closed Document" ;
373+ break ;
376374 case OtherStudioAction . ConnectedToNewNamespace :
377375 label = "Changed Namespace" ;
376+ break ;
378377 case OtherStudioAction . FirstTimeDocumentSave :
379378 label = "Saved Document to Server for the First Time" ;
380379 }
0 commit comments