@@ -10,13 +10,12 @@ import {
1010 Uri ,
1111 version as vscodeVersion ,
1212 window as Window ,
13- window ,
1413 workspace ,
1514} from "vscode" ;
1615import { LanguageClient } from "vscode-languageclient/node" ;
1716import { arch , platform } from "os" ;
1817import { ensureDir } from "fs-extra" ;
19- import { basename , join } from "path" ;
18+ import { join } from "path" ;
2019import { dirSync } from "tmp-promise" ;
2120import { testExplorerExtensionId , TestHub } from "vscode-test-adapter-api" ;
2221import { lt , parse } from "semver" ;
@@ -110,17 +109,18 @@ import { ExtensionApp } from "./common/vscode/vscode-app";
110109import { DbModule } from "./databases/db-module" ;
111110import { redactableError } from "./pure/errors" ;
112111import { QueryHistoryDirs } from "./query-history/query-history-dirs" ;
113- import { DirResult } from "tmp" ;
114112import {
115113 AllExtensionCommands ,
116114 BaseCommands ,
117115 QueryServerCommands ,
116+ TestUICommands ,
118117} from "./common/commands" ;
119118import {
120119 getLocalQueryCommands ,
121120 showResultsForCompletedQuery ,
122121} from "./local-queries" ;
123122import { getAstCfgCommands } from "./ast-cfg-commands" ;
123+ import { getQueryEditorCommands } from "./query-editor" ;
124124
125125/**
126126 * extension.ts
@@ -805,6 +805,7 @@ async function activateWithInstalledDistribution(
805805 const testExplorerExtension = extensions . getExtension < TestHub > (
806806 testExplorerExtensionId ,
807807 ) ;
808+ let testUiCommands : Partial < TestUICommands > = { } ;
808809 if ( testExplorerExtension ) {
809810 const testHub = testExplorerExtension . exports ;
810811 const testAdapterFactory = new QLTestAdapterFactory (
@@ -816,6 +817,8 @@ async function activateWithInstalledDistribution(
816817
817818 const testUIService = new TestUIService ( testHub ) ;
818819 ctx . subscriptions . push ( testUIService ) ;
820+
821+ testUiCommands = testUIService . getCommands ( ) ;
819822 }
820823
821824 const astViewer = new AstViewer ( ) ;
@@ -839,6 +842,11 @@ async function activateWithInstalledDistribution(
839842
840843 const allCommands : AllExtensionCommands = {
841844 ...getCommands ( cliServer , qs ) ,
845+ ...getQueryEditorCommands ( {
846+ queryRunner : qs ,
847+ cliServer,
848+ qhelpTmpDir : qhelpTmpDir . name ,
849+ } ) ,
842850 ...localQueryResultsView . getCommands ( ) ,
843851 ...qhm . getCommands ( ) ,
844852 ...variantAnalysisManager . getCommands ( ) ,
@@ -860,6 +868,7 @@ async function activateWithInstalledDistribution(
860868 } ) ,
861869 ...evalLogViewer . getCommands ( ) ,
862870 ...summaryLanguageSupport . getCommands ( ) ,
871+ ...testUiCommands ,
863872 ...mockServer . getCommands ( ) ,
864873 } ;
865874
@@ -887,38 +896,6 @@ async function activateWithInstalledDistribution(
887896 ) ;
888897 }
889898
890- ctx . subscriptions . push (
891- commandRunner ( "codeQL.openReferencedFile" , async ( selectedQuery : Uri ) => {
892- await openReferencedFile ( qs , cliServer , selectedQuery ) ;
893- } ) ,
894- ) ;
895-
896- // Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
897- ctx . subscriptions . push (
898- commandRunner (
899- "codeQL.openReferencedFileContextEditor" ,
900- async ( selectedQuery : Uri ) => {
901- await openReferencedFile ( qs , cliServer , selectedQuery ) ;
902- } ,
903- ) ,
904- ) ;
905-
906- // Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
907- ctx . subscriptions . push (
908- commandRunner (
909- "codeQL.openReferencedFileContextExplorer" ,
910- async ( selectedQuery : Uri ) => {
911- await openReferencedFile ( qs , cliServer , selectedQuery ) ;
912- } ,
913- ) ,
914- ) ;
915-
916- ctx . subscriptions . push (
917- commandRunner ( "codeQL.previewQueryHelp" , async ( selectedQuery : Uri ) => {
918- await previewQueryHelp ( app , cliServer , qhelpTmpDir , selectedQuery ) ;
919- } ) ,
920- ) ;
921-
922899 ctx . subscriptions . push (
923900 commandRunner ( "codeQL.copyVersion" , async ( ) => {
924901 const text = `CodeQL extension version: ${
@@ -1024,52 +1001,6 @@ async function showResultsForComparison(
10241001 }
10251002}
10261003
1027- async function previewQueryHelp (
1028- app : ExtensionApp ,
1029- cliServer : CodeQLCliServer ,
1030- qhelpTmpDir : DirResult ,
1031- selectedQuery : Uri ,
1032- ) : Promise < void > {
1033- // selectedQuery is unpopulated when executing through the command palette
1034- const pathToQhelp = selectedQuery
1035- ? selectedQuery . fsPath
1036- : window . activeTextEditor ?. document . uri . fsPath ;
1037- if ( pathToQhelp ) {
1038- // Create temporary directory
1039- const relativePathToMd = `${ basename ( pathToQhelp , ".qhelp" ) } .md` ;
1040- const absolutePathToMd = join ( qhelpTmpDir . name , relativePathToMd ) ;
1041- const uri = Uri . file ( absolutePathToMd ) ;
1042- try {
1043- await cliServer . generateQueryHelp ( pathToQhelp , absolutePathToMd ) ;
1044- await app . commands . execute ( "markdown.showPreviewToSide" , uri ) ;
1045- } catch ( e ) {
1046- const errorMessage = getErrorMessage ( e ) . includes (
1047- "Generating qhelp in markdown" ,
1048- )
1049- ? redactableError `Could not generate markdown from ${ pathToQhelp } : Bad formatting in .qhelp file.`
1050- : redactableError `Could not open a preview of the generated file (${ absolutePathToMd } ).` ;
1051- void showAndLogExceptionWithTelemetry ( errorMessage , {
1052- fullMessage : `${ errorMessage } \n${ getErrorMessage ( e ) } ` ,
1053- } ) ;
1054- }
1055- }
1056- }
1057-
1058- async function openReferencedFile (
1059- qs : QueryRunner ,
1060- cliServer : CodeQLCliServer ,
1061- selectedQuery : Uri ,
1062- ) : Promise < void > {
1063- // If no file is selected, the path of the file in the editor is selected
1064- const path =
1065- selectedQuery ?. fsPath || window . activeTextEditor ?. document . uri . fsPath ;
1066- if ( qs !== undefined && path ) {
1067- const resolved = await cliServer . resolveQlref ( path ) ;
1068- const uri = Uri . file ( resolved . resolvedPath ) ;
1069- await window . showTextDocument ( uri , { preview : false } ) ;
1070- }
1071- }
1072-
10731004function addUnhandledRejectionListener ( ) {
10741005 const handler = ( error : unknown ) => {
10751006 // This listener will be triggered for errors from other extensions as
0 commit comments