@@ -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" ;
126125import { App } from "./common/app" ;
127126
128127/**
@@ -865,6 +864,11 @@ async function activateWithInstalledDistribution(
865864
866865 const allCommands : AllCommands = {
867866 ...getCommands ( app , cliServer , qs ) ,
867+ ...getQueryEditorCommands ( {
868+ queryRunner : qs ,
869+ cliServer,
870+ qhelpTmpDir : qhelpTmpDir . name ,
871+ } ) ,
868872 ...localQueryResultsView . getCommands ( ) ,
869873 ...qhm . getCommands ( ) ,
870874 ...variantAnalysisManager . getCommands ( ) ,
@@ -914,38 +918,6 @@ async function activateWithInstalledDistribution(
914918 ) ;
915919 }
916920
917- ctx . subscriptions . push (
918- commandRunner ( "codeQL.openReferencedFile" , async ( selectedQuery : Uri ) => {
919- await openReferencedFile ( qs , cliServer , selectedQuery ) ;
920- } ) ,
921- ) ;
922-
923- // Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
924- ctx . subscriptions . push (
925- commandRunner (
926- "codeQL.openReferencedFileContextEditor" ,
927- async ( selectedQuery : Uri ) => {
928- await openReferencedFile ( qs , cliServer , selectedQuery ) ;
929- } ,
930- ) ,
931- ) ;
932-
933- // Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
934- ctx . subscriptions . push (
935- commandRunner (
936- "codeQL.openReferencedFileContextExplorer" ,
937- async ( selectedQuery : Uri ) => {
938- await openReferencedFile ( qs , cliServer , selectedQuery ) ;
939- } ,
940- ) ,
941- ) ;
942-
943- ctx . subscriptions . push (
944- commandRunner ( "codeQL.previewQueryHelp" , async ( selectedQuery : Uri ) => {
945- await previewQueryHelp ( cliServer , qhelpTmpDir , selectedQuery ) ;
946- } ) ,
947- ) ;
948-
949921 void extLogger . log ( "Starting language server." ) ;
950922 await client . start ( ) ;
951923 ctx . subscriptions . push ( {
@@ -1013,51 +985,6 @@ async function showResultsForComparison(
1013985 }
1014986}
1015987
1016- async function previewQueryHelp (
1017- cliServer : CodeQLCliServer ,
1018- qhelpTmpDir : DirResult ,
1019- selectedQuery : Uri ,
1020- ) : Promise < void > {
1021- // selectedQuery is unpopulated when executing through the command palette
1022- const pathToQhelp = selectedQuery
1023- ? selectedQuery . fsPath
1024- : window . activeTextEditor ?. document . uri . fsPath ;
1025- if ( pathToQhelp ) {
1026- // Create temporary directory
1027- const relativePathToMd = `${ basename ( pathToQhelp , ".qhelp" ) } .md` ;
1028- const absolutePathToMd = join ( qhelpTmpDir . name , relativePathToMd ) ;
1029- const uri = Uri . file ( absolutePathToMd ) ;
1030- try {
1031- await cliServer . generateQueryHelp ( pathToQhelp , absolutePathToMd ) ;
1032- await commands . executeCommand ( "markdown.showPreviewToSide" , uri ) ;
1033- } catch ( e ) {
1034- const errorMessage = getErrorMessage ( e ) . includes (
1035- "Generating qhelp in markdown" ,
1036- )
1037- ? redactableError `Could not generate markdown from ${ pathToQhelp } : Bad formatting in .qhelp file.`
1038- : redactableError `Could not open a preview of the generated file (${ absolutePathToMd } ).` ;
1039- void showAndLogExceptionWithTelemetry ( errorMessage , {
1040- fullMessage : `${ errorMessage } \n${ getErrorMessage ( e ) } ` ,
1041- } ) ;
1042- }
1043- }
1044- }
1045-
1046- async function openReferencedFile (
1047- qs : QueryRunner ,
1048- cliServer : CodeQLCliServer ,
1049- selectedQuery : Uri ,
1050- ) : Promise < void > {
1051- // If no file is selected, the path of the file in the editor is selected
1052- const path =
1053- selectedQuery ?. fsPath || window . activeTextEditor ?. document . uri . fsPath ;
1054- if ( qs !== undefined && path ) {
1055- const resolved = await cliServer . resolveQlref ( path ) ;
1056- const uri = Uri . file ( resolved . resolvedPath ) ;
1057- await window . showTextDocument ( uri , { preview : false } ) ;
1058- }
1059- }
1060-
1061988function addUnhandledRejectionListener ( ) {
1062989 const handler = ( error : unknown ) => {
1063990 // This listener will be triggered for errors from other extensions as
0 commit comments