@@ -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 ,
@@ -122,6 +120,7 @@ import {
122120 showResultsForCompletedQuery ,
123121} from "./local-queries" ;
124122import { getAstCfgCommands } from "./ast-cfg-commands" ;
123+ import { registerQueryEditorCommands } from "./query-editor" ;
125124
126125/**
127126 * extension.ts
@@ -878,37 +877,11 @@ async function activateWithInstalledDistribution(
878877 ) ;
879878 }
880879
881- ctx . subscriptions . push (
882- commandRunner ( "codeQL.openReferencedFile" , async ( selectedQuery : Uri ) => {
883- await openReferencedFile ( qs , cliServer , selectedQuery ) ;
884- } ) ,
885- ) ;
886-
887- // Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
888- ctx . subscriptions . push (
889- commandRunner (
890- "codeQL.openReferencedFileContextEditor" ,
891- async ( selectedQuery : Uri ) => {
892- await openReferencedFile ( qs , cliServer , selectedQuery ) ;
893- } ,
894- ) ,
895- ) ;
896-
897- // Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
898- ctx . subscriptions . push (
899- commandRunner (
900- "codeQL.openReferencedFileContextExplorer" ,
901- async ( selectedQuery : Uri ) => {
902- await openReferencedFile ( qs , cliServer , selectedQuery ) ;
903- } ,
904- ) ,
905- ) ;
906-
907- ctx . subscriptions . push (
908- commandRunner ( "codeQL.previewQueryHelp" , async ( selectedQuery : Uri ) => {
909- await previewQueryHelp ( cliServer , qhelpTmpDir , selectedQuery ) ;
910- } ) ,
911- ) ;
880+ registerQueryEditorCommands ( ctx , {
881+ queryRunner : qs ,
882+ cliServer,
883+ qhelpTmpDir : qhelpTmpDir . name ,
884+ } ) ;
912885
913886 ctx . subscriptions . push (
914887 commandRunner ( "codeQL.copyVersion" , async ( ) => {
@@ -1015,51 +988,6 @@ async function showResultsForComparison(
1015988 }
1016989}
1017990
1018- async function previewQueryHelp (
1019- cliServer : CodeQLCliServer ,
1020- qhelpTmpDir : DirResult ,
1021- selectedQuery : Uri ,
1022- ) : Promise < void > {
1023- // selectedQuery is unpopulated when executing through the command palette
1024- const pathToQhelp = selectedQuery
1025- ? selectedQuery . fsPath
1026- : window . activeTextEditor ?. document . uri . fsPath ;
1027- if ( pathToQhelp ) {
1028- // Create temporary directory
1029- const relativePathToMd = `${ basename ( pathToQhelp , ".qhelp" ) } .md` ;
1030- const absolutePathToMd = join ( qhelpTmpDir . name , relativePathToMd ) ;
1031- const uri = Uri . file ( absolutePathToMd ) ;
1032- try {
1033- await cliServer . generateQueryHelp ( pathToQhelp , absolutePathToMd ) ;
1034- await commands . executeCommand ( "markdown.showPreviewToSide" , uri ) ;
1035- } catch ( e ) {
1036- const errorMessage = getErrorMessage ( e ) . includes (
1037- "Generating qhelp in markdown" ,
1038- )
1039- ? redactableError `Could not generate markdown from ${ pathToQhelp } : Bad formatting in .qhelp file.`
1040- : redactableError `Could not open a preview of the generated file (${ absolutePathToMd } ).` ;
1041- void showAndLogExceptionWithTelemetry ( errorMessage , {
1042- fullMessage : `${ errorMessage } \n${ getErrorMessage ( e ) } ` ,
1043- } ) ;
1044- }
1045- }
1046- }
1047-
1048- async function openReferencedFile (
1049- qs : QueryRunner ,
1050- cliServer : CodeQLCliServer ,
1051- selectedQuery : Uri ,
1052- ) : Promise < void > {
1053- // If no file is selected, the path of the file in the editor is selected
1054- const path =
1055- selectedQuery ?. fsPath || window . activeTextEditor ?. document . uri . fsPath ;
1056- if ( qs !== undefined && path ) {
1057- const resolved = await cliServer . resolveQlref ( path ) ;
1058- const uri = Uri . file ( resolved . resolvedPath ) ;
1059- await window . showTextDocument ( uri , { preview : false } ) ;
1060- }
1061- }
1062-
1063991function addUnhandledRejectionListener ( ) {
1064992 const handler = ( error : unknown ) => {
1065993 // This listener will be triggered for errors from other extensions as
0 commit comments