@@ -73,115 +73,9 @@ export class ModelEditorModule extends DisposableObject {
7373
7474 public getCommands ( ) : ModelEditorCommands {
7575 return {
76- "codeQL.openModelEditor" : async ( ) => {
77- const db = this . databaseManager . currentDatabaseItem ;
78- if ( ! db ) {
79- void showAndLogErrorMessage ( this . app . logger , "No database selected" ) ;
80- return ;
81- }
82-
83- const language = db . language ;
84- if (
85- ! SUPPORTED_LANGUAGES . includes ( language ) ||
86- ! isQueryLanguage ( language )
87- ) {
88- void showAndLogErrorMessage (
89- this . app . logger ,
90- `The CodeQL Model Editor is not supported for ${ language } databases.` ,
91- ) ;
92- return ;
93- }
94-
95- return withProgress (
96- async ( progress ) => {
97- const maxStep = 4 ;
98-
99- if ( ! ( await this . cliServer . cliConstraints . supportsQlpacksKind ( ) ) ) {
100- void showAndLogErrorMessage (
101- this . app . logger ,
102- `This feature requires CodeQL CLI version ${ CliVersionConstraint . CLI_VERSION_WITH_QLPACKS_KIND . format ( ) } or later.` ,
103- ) ;
104- return ;
105- }
106-
107- if (
108- ! ( await this . cliServer . cliConstraints . supportsResolveExtensions ( ) )
109- ) {
110- void showAndLogErrorMessage (
111- this . app . logger ,
112- `This feature requires CodeQL CLI version ${ CliVersionConstraint . CLI_VERSION_WITH_RESOLVE_EXTENSIONS . format ( ) } or later.` ,
113- ) ;
114- return ;
115- }
116-
117- const modelFile = await pickExtensionPack (
118- this . cliServer ,
119- db ,
120- this . app . logger ,
121- progress ,
122- maxStep ,
123- ) ;
124- if ( ! modelFile ) {
125- return ;
126- }
127-
128- progress ( {
129- message : "Installing dependencies..." ,
130- step : 3 ,
131- maxStep,
132- } ) ;
133-
134- // Create new temporary directory for query files and pack dependencies
135- const { path : queryDir , cleanup : cleanupQueryDir } = await dir ( {
136- unsafeCleanup : true ,
137- } ) ;
138-
139- const success = await setUpPack ( this . cliServer , queryDir , language ) ;
140- if ( ! success ) {
141- await cleanupQueryDir ( ) ;
142- return ;
143- }
144-
145- progress ( {
146- message : "Opening editor..." ,
147- step : 4 ,
148- maxStep,
149- } ) ;
150-
151- const view = new ModelEditorView (
152- this . app ,
153- this . modelingStore ,
154- this . editorViewTracker ,
155- this . databaseManager ,
156- this . cliServer ,
157- this . queryRunner ,
158- this . queryStorageDir ,
159- queryDir ,
160- db ,
161- modelFile ,
162- Mode . Application ,
163- ) ;
164-
165- this . modelingStore . onDbClosed ( async ( dbUri ) => {
166- if ( dbUri === db . databaseUri . toString ( ) ) {
167- await cleanupQueryDir ( ) ;
168- }
169- } ) ;
170-
171- this . push ( view ) ;
172- this . push ( {
173- dispose ( ) : void {
174- void cleanupQueryDir ( ) ;
175- } ,
176- } ) ;
177-
178- await view . openView ( ) ;
179- } ,
180- {
181- title : "Opening CodeQL Model Editor" ,
182- } ,
183- ) ;
184- } ,
76+ "codeQL.openModelEditor" : this . openModelEditor . bind ( this ) ,
77+ "codeQL.openModelEditorFromModelingPanel" :
78+ this . openModelEditor . bind ( this ) ,
18579 "codeQLModelEditor.jumpToUsageLocation" : async (
18680 method : Method ,
18781 usage : Usage ,
@@ -213,4 +107,116 @@ export class ModelEditorModule extends DisposableObject {
213107 await this . methodModelingPanel . setMethod ( method ) ;
214108 await showResolvableLocation ( usage . url , databaseItem , this . app . logger ) ;
215109 }
110+
111+ private async openModelEditor ( ) : Promise < void > {
112+ {
113+ const db = this . databaseManager . currentDatabaseItem ;
114+ if ( ! db ) {
115+ void showAndLogErrorMessage ( this . app . logger , "No database selected" ) ;
116+ return ;
117+ }
118+
119+ const language = db . language ;
120+ if (
121+ ! SUPPORTED_LANGUAGES . includes ( language ) ||
122+ ! isQueryLanguage ( language )
123+ ) {
124+ void showAndLogErrorMessage (
125+ this . app . logger ,
126+ `The CodeQL Model Editor is not supported for ${ language } databases.` ,
127+ ) ;
128+ return ;
129+ }
130+
131+ return withProgress (
132+ async ( progress ) => {
133+ const maxStep = 4 ;
134+
135+ if ( ! ( await this . cliServer . cliConstraints . supportsQlpacksKind ( ) ) ) {
136+ void showAndLogErrorMessage (
137+ this . app . logger ,
138+ `This feature requires CodeQL CLI version ${ CliVersionConstraint . CLI_VERSION_WITH_QLPACKS_KIND . format ( ) } or later.` ,
139+ ) ;
140+ return ;
141+ }
142+
143+ if (
144+ ! ( await this . cliServer . cliConstraints . supportsResolveExtensions ( ) )
145+ ) {
146+ void showAndLogErrorMessage (
147+ this . app . logger ,
148+ `This feature requires CodeQL CLI version ${ CliVersionConstraint . CLI_VERSION_WITH_RESOLVE_EXTENSIONS . format ( ) } or later.` ,
149+ ) ;
150+ return ;
151+ }
152+
153+ const modelFile = await pickExtensionPack (
154+ this . cliServer ,
155+ db ,
156+ this . app . logger ,
157+ progress ,
158+ maxStep ,
159+ ) ;
160+ if ( ! modelFile ) {
161+ return ;
162+ }
163+
164+ progress ( {
165+ message : "Installing dependencies..." ,
166+ step : 3 ,
167+ maxStep,
168+ } ) ;
169+
170+ // Create new temporary directory for query files and pack dependencies
171+ const { path : queryDir , cleanup : cleanupQueryDir } = await dir ( {
172+ unsafeCleanup : true ,
173+ } ) ;
174+
175+ const success = await setUpPack ( this . cliServer , queryDir , language ) ;
176+ if ( ! success ) {
177+ await cleanupQueryDir ( ) ;
178+ return ;
179+ }
180+
181+ progress ( {
182+ message : "Opening editor..." ,
183+ step : 4 ,
184+ maxStep,
185+ } ) ;
186+
187+ const view = new ModelEditorView (
188+ this . app ,
189+ this . modelingStore ,
190+ this . editorViewTracker ,
191+ this . databaseManager ,
192+ this . cliServer ,
193+ this . queryRunner ,
194+ this . queryStorageDir ,
195+ queryDir ,
196+ db ,
197+ modelFile ,
198+ Mode . Application ,
199+ ) ;
200+
201+ this . modelingStore . onDbClosed ( async ( dbUri ) => {
202+ if ( dbUri === db . databaseUri . toString ( ) ) {
203+ await cleanupQueryDir ( ) ;
204+ }
205+ } ) ;
206+
207+ this . push ( view ) ;
208+ this . push ( {
209+ dispose ( ) : void {
210+ void cleanupQueryDir ( ) ;
211+ } ,
212+ } ) ;
213+
214+ await view . openView ( ) ;
215+ } ,
216+ {
217+ title : "Opening CodeQL Model Editor" ,
218+ } ,
219+ ) ;
220+ }
221+ }
216222}
0 commit comments