@@ -11,13 +11,12 @@ import {
1111 Uri ,
1212 version as vscodeVersion ,
1313 window as Window ,
14- window ,
1514 workspace ,
1615} from "vscode" ;
1716import { LanguageClient } from "vscode-languageclient/node" ;
1817import { arch , platform } from "os" ;
1918import { ensureDir } from "fs-extra" ;
20- import { basename , join } from "path" ;
19+ import { join } from "path" ;
2120import { dirSync } from "tmp-promise" ;
2221import { testExplorerExtensionId , TestHub } from "vscode-test-adapter-api" ;
2322import { lt , parse } from "semver" ;
@@ -111,7 +110,6 @@ import { ExtensionApp } from "./common/vscode/vscode-app";
111110import { DbModule } from "./databases/db-module" ;
112111import { redactableError } from "./pure/errors" ;
113112import { QueryHistoryDirs } from "./query-history/query-history-dirs" ;
114- import { DirResult } from "tmp" ;
115113import {
116114 AllCommands ,
117115 BaseCommands ,
@@ -123,6 +121,7 @@ import {
123121 showResultsForCompletedQuery ,
124122} from "./local-queries" ;
125123import { getAstCfgCommands } from "./ast-cfg-commands" ;
124+ import { getQueryEditorCommands } from "./query-editor" ;
126125
127126/**
128127 * extension.ts
@@ -834,6 +833,11 @@ async function activateWithInstalledDistribution(
834833
835834 const allCommands : AllCommands = {
836835 ...getCommands ( cliServer , qs ) ,
836+ ...getQueryEditorCommands ( {
837+ queryRunner : qs ,
838+ cliServer,
839+ qhelpTmpDir : qhelpTmpDir . name ,
840+ } ) ,
837841 ...localQueryResultsView . getCommands ( ) ,
838842 ...qhm . getCommands ( ) ,
839843 ...variantAnalysisManager . getCommands ( ) ,
@@ -883,38 +887,6 @@ async function activateWithInstalledDistribution(
883887 ) ;
884888 }
885889
886- ctx . subscriptions . push (
887- commandRunner ( "codeQL.openReferencedFile" , async ( selectedQuery : Uri ) => {
888- await openReferencedFile ( qs , cliServer , selectedQuery ) ;
889- } ) ,
890- ) ;
891-
892- // Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
893- ctx . subscriptions . push (
894- commandRunner (
895- "codeQL.openReferencedFileContextEditor" ,
896- async ( selectedQuery : Uri ) => {
897- await openReferencedFile ( qs , cliServer , selectedQuery ) ;
898- } ,
899- ) ,
900- ) ;
901-
902- // Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
903- ctx . subscriptions . push (
904- commandRunner (
905- "codeQL.openReferencedFileContextExplorer" ,
906- async ( selectedQuery : Uri ) => {
907- await openReferencedFile ( qs , cliServer , selectedQuery ) ;
908- } ,
909- ) ,
910- ) ;
911-
912- ctx . subscriptions . push (
913- commandRunner ( "codeQL.previewQueryHelp" , async ( selectedQuery : Uri ) => {
914- await previewQueryHelp ( cliServer , qhelpTmpDir , selectedQuery ) ;
915- } ) ,
916- ) ;
917-
918890 ctx . subscriptions . push (
919891 commandRunner ( "codeQL.copyVersion" , async ( ) => {
920892 const text = `CodeQL extension version: ${
@@ -1020,51 +992,6 @@ async function showResultsForComparison(
1020992 }
1021993}
1022994
1023- async function previewQueryHelp (
1024- cliServer : CodeQLCliServer ,
1025- qhelpTmpDir : DirResult ,
1026- selectedQuery : Uri ,
1027- ) : Promise < void > {
1028- // selectedQuery is unpopulated when executing through the command palette
1029- const pathToQhelp = selectedQuery
1030- ? selectedQuery . fsPath
1031- : window . activeTextEditor ?. document . uri . fsPath ;
1032- if ( pathToQhelp ) {
1033- // Create temporary directory
1034- const relativePathToMd = `${ basename ( pathToQhelp , ".qhelp" ) } .md` ;
1035- const absolutePathToMd = join ( qhelpTmpDir . name , relativePathToMd ) ;
1036- const uri = Uri . file ( absolutePathToMd ) ;
1037- try {
1038- await cliServer . generateQueryHelp ( pathToQhelp , absolutePathToMd ) ;
1039- await commands . executeCommand ( "markdown.showPreviewToSide" , uri ) ;
1040- } catch ( e ) {
1041- const errorMessage = getErrorMessage ( e ) . includes (
1042- "Generating qhelp in markdown" ,
1043- )
1044- ? redactableError `Could not generate markdown from ${ pathToQhelp } : Bad formatting in .qhelp file.`
1045- : redactableError `Could not open a preview of the generated file (${ absolutePathToMd } ).` ;
1046- void showAndLogExceptionWithTelemetry ( errorMessage , {
1047- fullMessage : `${ errorMessage } \n${ getErrorMessage ( e ) } ` ,
1048- } ) ;
1049- }
1050- }
1051- }
1052-
1053- async function openReferencedFile (
1054- qs : QueryRunner ,
1055- cliServer : CodeQLCliServer ,
1056- selectedQuery : Uri ,
1057- ) : Promise < void > {
1058- // If no file is selected, the path of the file in the editor is selected
1059- const path =
1060- selectedQuery ?. fsPath || window . activeTextEditor ?. document . uri . fsPath ;
1061- if ( qs !== undefined && path ) {
1062- const resolved = await cliServer . resolveQlref ( path ) ;
1063- const uri = Uri . file ( resolved . resolvedPath ) ;
1064- await window . showTextDocument ( uri , { preview : false } ) ;
1065- }
1066- }
1067-
1068995function addUnhandledRejectionListener ( ) {
1069996 const handler = ( error : unknown ) => {
1070997 // This listener will be triggered for errors from other extensions as
0 commit comments