Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import resultsDiff from './resultsDiff';
import { CompletedLocalQueryInfo } from '../query-results';
import { getErrorMessage } from '../pure/helpers-pure';
import { HistoryItemLabelProvider } from '../history-item-label-provider';
import { AbstractInterfaceManager, InterfacePanelConfig } from '../abstract-interface-manager';
import { WebviewBase, InterfacePanelConfig } from '../webview-base';

interface ComparePair {
from: CompletedLocalQueryInfo;
to: CompletedLocalQueryInfo;
}

export class CompareInterfaceManager extends AbstractInterfaceManager<ToCompareViewMessage, FromCompareViewMessage> {
export class CompareView extends WebviewBase<ToCompareViewMessage, FromCompareViewMessage> {
private comparePair: ComparePair | undefined;

constructor(
Expand Down
24 changes: 12 additions & 12 deletions extensions/ql-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import {
} from './helpers';
import { asError, assertNever, getErrorMessage } from './pure/helpers-pure';
import { spawnIdeServer } from './ide-server';
import { InterfaceManager } from './interface';
import { ResultsView } from './interface';
import { WebviewReveal } from './interface-utils';
import { ideServerLogger, logger, queryServerLogger } from './logging';
import { QueryHistoryManager } from './query-history';
Expand All @@ -78,7 +78,7 @@ import { displayQuickQuery } from './quick-query';
import { compileAndRunQueryAgainstDatabase, createInitialQueryInfo } from './run-queries';
import { QLTestAdapterFactory } from './test-adapter';
import { TestUIService } from './test-ui';
import { CompareInterfaceManager } from './compare/compare-interface';
import { CompareView } from './compare/compare-view';
import { gatherQlFiles } from './pure/files';
import { initializeTelemetry } from './telemetry';
import {
Expand All @@ -102,7 +102,7 @@ import { EvalLogViewer } from './eval-log-viewer';
import { SummaryLanguageSupport } from './log-insights/summary-language-support';
import { JoinOrderScannerProvider } from './log-insights/join-order';
import { LogScannerService } from './log-insights/log-scanner-service';
import { VariantAnalysisInterfaceManager } from './remote-queries/variant-analysis-interface';
import { VariantAnalysisView } from './remote-queries/variant-analysis-view';

/**
* extension.ts
Expand Down Expand Up @@ -461,8 +461,8 @@ async function activateWithInstalledDistribution(
const labelProvider = new HistoryItemLabelProvider(queryHistoryConfigurationListener);

void logger.log('Initializing results panel interface.');
const intm = new InterfaceManager(ctx, dbm, cliServer, queryServerLogger, labelProvider);
ctx.subscriptions.push(intm);
const localQueryResultsView = new ResultsView(ctx, dbm, cliServer, queryServerLogger, labelProvider);
ctx.subscriptions.push(localQueryResultsView);

void logger.log('Initializing variant analysis manager.');
const rqm = new RemoteQueriesManager(ctx, cliServer, queryStorageDir, logger);
Expand All @@ -472,7 +472,7 @@ async function activateWithInstalledDistribution(
const qhm = new QueryHistoryManager(
qs,
dbm,
intm,
localQueryResultsView,
rqm,
evalLogViewer,
queryStorageDir,
Expand All @@ -494,16 +494,16 @@ async function activateWithInstalledDistribution(
void logger.log('Reading query history');
await qhm.readQueryHistory();

void logger.log('Initializing compare panel interface.');
const cmpm = new CompareInterfaceManager(
void logger.log('Initializing compare view.');
const compareView = new CompareView(
ctx,
dbm,
cliServer,
queryServerLogger,
labelProvider,
showResults
);
ctx.subscriptions.push(cmpm);
ctx.subscriptions.push(compareView);

void logger.log('Initializing source archive filesystem provider.');
archiveFilesystemProvider.activate(ctx);
Expand All @@ -513,7 +513,7 @@ async function activateWithInstalledDistribution(
to: CompletedLocalQueryInfo
): Promise<void> {
try {
await cmpm.showResults(from, to);
await compareView.showResults(from, to);
} catch (e) {
void showAndLogErrorMessage(getErrorMessage(e));
}
Expand All @@ -523,7 +523,7 @@ async function activateWithInstalledDistribution(
query: CompletedLocalQueryInfo,
forceReveal: WebviewReveal
): Promise<void> {
await intm.showResults(query, forceReveal, false);
await localQueryResultsView.showResults(query, forceReveal, false);
}

async function compileAndRunQuery(
Expand Down Expand Up @@ -922,7 +922,7 @@ async function activateWithInstalledDistribution(

ctx.subscriptions.push(
commandRunner('codeQL.mockVariantAnalysisView', async () => {
const variantAnalysisView = new VariantAnalysisInterfaceManager(ctx);
const variantAnalysisView = new VariantAnalysisView(ctx);
variantAnalysisView.openView();
})
);
Expand Down
4 changes: 2 additions & 2 deletions extensions/ql-vscode/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
} from './interface-utils';
import { getDefaultResultSetName, ParsedResultSets } from './pure/interface-types';
import { RawResultSet, transformBqrsResultSet, ResultSetSchema } from './pure/bqrs-cli-types';
import { AbstractInterfaceManager, InterfacePanelConfig } from './abstract-interface-manager';
import { WebviewBase, InterfacePanelConfig } from './webview-base';
import { PAGE_SIZE } from './config';
import { CompletedLocalQueryInfo } from './query-results';
import { HistoryItemLabelProvider } from './history-item-label-provider';
Expand Down Expand Up @@ -120,7 +120,7 @@ function numInterpretedPages(interpretation: Interpretation | undefined): number
return Math.ceil(n / pageSize);
}

export class InterfaceManager extends AbstractInterfaceManager<IntoResultsViewMsg, FromResultsViewMsg> {
export class ResultsView extends WebviewBase<IntoResultsViewMsg, FromResultsViewMsg> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this file be called view.ts rather than interface.ts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was tempted to rename it but it has a bunch of other stuff in there so it didn't make sense to rename it.

private _displayedQuery?: CompletedLocalQueryInfo;
private _interpretation?: Interpretation;

Expand Down
6 changes: 3 additions & 3 deletions extensions/ql-vscode/src/query-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { Credentials } from './authentication';
import { cancelRemoteQuery } from './remote-queries/gh-actions-api-client';
import { RemoteQueriesManager } from './remote-queries/remote-queries-manager';
import { RemoteQueryHistoryItem } from './remote-queries/remote-query-history-item';
import { InterfaceManager } from './interface';
import { ResultsView } from './interface';
import { WebviewReveal } from './interface-utils';
import { EvalLogViewer } from './eval-log-viewer';
import EvalLogTreeBuilder from './eval-log-tree-builder';
Expand Down Expand Up @@ -331,7 +331,7 @@ export class QueryHistoryManager extends DisposableObject {
constructor(
private readonly qs: QueryServerClient,
private readonly dbm: DatabaseManager,
private readonly localQueriesInterfaceManager: InterfaceManager,
private readonly localQueriesResultsView: ResultsView,
private readonly remoteQueriesManager: RemoteQueriesManager,
private readonly evalLogViewer: EvalLogViewer,
private readonly queryStorageDir: string,
Expand Down Expand Up @@ -1360,7 +1360,7 @@ the file in the file explorer and dragging it into the workspace.`

private async openQueryResults(item: QueryHistoryInfo) {
if (item.t === 'local') {
await this.localQueriesInterfaceManager.showResults(item as CompletedLocalQueryInfo, WebviewReveal.Forced, false);
await this.localQueriesResultsView.showResults(item as CompletedLocalQueryInfo, WebviewReveal.Forced, false);
}
else if (item.t === 'remote') {
await this.remoteQueriesManager.openRemoteQueryResults(item.queryId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ProgressCallback } from '../commandRunner';
import { createTimestampFile, showAndLogErrorMessage, showAndLogInformationMessage, showInformationMessageWithAction } from '../helpers';
import { Logger } from '../logging';
import { runRemoteQuery } from './run-remote-query';
import { RemoteQueriesInterfaceManager } from './remote-queries-interface';
import { RemoteQueriesView } from './remote-queries-view';
import { RemoteQuery } from './remote-query';
import { RemoteQueriesMonitor } from './remote-queries-monitor';
import { getRemoteQueryIndex, getRepositoriesMetadata, RepositoriesMetadata } from './gh-actions-api-client';
Expand Down Expand Up @@ -56,7 +56,7 @@ export class RemoteQueriesManager extends DisposableObject {

private readonly remoteQueriesMonitor: RemoteQueriesMonitor;
private readonly analysesResultsManager: AnalysesResultsManager;
private readonly interfaceManager: RemoteQueriesInterfaceManager;
private readonly view: RemoteQueriesView;

constructor(
private readonly ctx: ExtensionContext,
Expand All @@ -66,7 +66,7 @@ export class RemoteQueriesManager extends DisposableObject {
) {
super();
this.analysesResultsManager = new AnalysesResultsManager(ctx, cliServer, storagePath, logger);
this.interfaceManager = new RemoteQueriesInterfaceManager(ctx, logger, this.analysesResultsManager);
this.view = new RemoteQueriesView(ctx, logger, this.analysesResultsManager);
this.remoteQueriesMonitor = new RemoteQueriesMonitor(ctx, logger);

this.remoteQueryAddedEventEmitter = this.push(new EventEmitter<NewQueryEvent>());
Expand All @@ -76,7 +76,7 @@ export class RemoteQueriesManager extends DisposableObject {
this.onRemoteQueryRemoved = this.remoteQueryRemovedEventEmitter.event;
this.onRemoteQueryStatusUpdate = this.remoteQueryStatusUpdateEventEmitter.event;

this.push(this.interfaceManager);
this.push(this.view);
}

public async rehydrateRemoteQuery(queryId: string, query: RemoteQuery, status: QueryStatus) {
Expand Down Expand Up @@ -192,7 +192,7 @@ export class RemoteQueriesManager extends DisposableObject {
await this.analysesResultsManager.loadAnalysesResults(
analysesToDownload,
token,
results => this.interfaceManager.setAnalysisResults(results, queryResult.queryId));
results => this.view.setAnalysisResults(results, queryResult.queryId));
}

public async copyRemoteQueryRepoListToClipboard(queryId: string) {
Expand Down Expand Up @@ -248,7 +248,7 @@ export class RemoteQueriesManager extends DisposableObject {
}

public async openResults(query: RemoteQuery, queryResult: RemoteQueryResult) {
await this.interfaceManager.showResults(query, queryResult);
await this.view.showResults(query, queryResult);
}

private async askToOpenResults(query: RemoteQuery, queryResult: RemoteQueryResult): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import { SHOW_QUERY_TEXT_MSG } from '../query-history';
import { AnalysesResultsManager } from './analyses-results-manager';
import { AnalysisResults } from './shared/analysis-result';
import { humanizeUnit } from '../pure/time';
import { AbstractInterfaceManager, InterfacePanelConfig } from '../abstract-interface-manager';
import { WebviewBase, InterfacePanelConfig } from '../webview-base';

export class RemoteQueriesInterfaceManager extends AbstractInterfaceManager<ToRemoteQueriesMessage, FromRemoteQueriesMessage> {
export class RemoteQueriesView extends WebviewBase<ToRemoteQueriesMessage, FromRemoteQueriesMessage> {
private currentQueryId: string | undefined;

constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ViewColumn } from 'vscode';
import { AbstractInterfaceManager, InterfacePanelConfig } from '../abstract-interface-manager';
import { WebviewBase, InterfacePanelConfig } from '../webview-base';
import { WebviewMessage } from '../interface-utils';
import { logger } from '../logging';

export class VariantAnalysisInterfaceManager extends AbstractInterfaceManager<WebviewMessage, WebviewMessage> {
export class VariantAnalysisView extends WebviewBase<WebviewMessage, WebviewMessage> {
public openView() {
this.getPanel().reveal(undefined, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { tmpDir } from '../../helpers';
import { getErrorMessage } from '../../pure/helpers-pure';
import { HistoryItemLabelProvider } from '../../history-item-label-provider';
import { RemoteQueriesManager } from '../../remote-queries/remote-queries-manager';
import { InterfaceManager } from '../../interface';
import { ResultsView } from '../../interface';
import { EvalLogViewer } from '../../eval-log-viewer';

describe('query-history', () => {
Expand All @@ -32,7 +32,7 @@ describe('query-history', () => {
let queryHistoryManager: QueryHistoryManager | undefined;
let doCompareCallback: sinon.SinonStub;

let localQueriesInterfaceManagerStub: InterfaceManager;
let localQueriesResultsViewStub: ResultsView;
let remoteQueriesManagerStub: RemoteQueriesManager;

let tryOpenExternalFile: Function;
Expand All @@ -55,9 +55,9 @@ describe('query-history', () => {
tryOpenExternalFile = (QueryHistoryManager.prototype as any).tryOpenExternalFile;
configListener = new QueryHistoryConfigListener();
doCompareCallback = sandbox.stub();
localQueriesInterfaceManagerStub = {
localQueriesResultsViewStub = {
showResults: sandbox.stub()
} as any as InterfaceManager;
} as any as ResultsView;
remoteQueriesManagerStub = {
onRemoteQueryAdded: sandbox.stub(),
onRemoteQueryRemoved: sandbox.stub(),
Expand Down Expand Up @@ -205,7 +205,7 @@ describe('query-history', () => {

await queryHistoryManager.handleItemClicked(allHistory[0], [allHistory[0]]);

expect(localQueriesInterfaceManagerStub.showResults).to.have.been.calledOnceWith(allHistory[0]);
expect(localQueriesResultsViewStub.showResults).to.have.been.calledOnceWith(allHistory[0]);
expect(queryHistoryManager.treeDataProvider.getCurrent()).to.eq(allHistory[0]);
});

Expand All @@ -214,7 +214,7 @@ describe('query-history', () => {

await queryHistoryManager.handleItemClicked(allHistory[0], [allHistory[0], allHistory[1]]);

expect(localQueriesInterfaceManagerStub.showResults).not.to.have.been.called;
expect(localQueriesResultsViewStub.showResults).not.to.have.been.called;
expect(queryHistoryManager.treeDataProvider.getCurrent()).to.be.undefined;
});

Expand All @@ -223,7 +223,7 @@ describe('query-history', () => {

await queryHistoryManager.handleItemClicked(undefined!, []);

expect(localQueriesInterfaceManagerStub.showResults).not.to.have.been.called;
expect(localQueriesResultsViewStub.showResults).not.to.have.been.called;
expect(queryHistoryManager.treeDataProvider.getCurrent()).to.be.undefined;
});
});
Expand Down Expand Up @@ -252,7 +252,7 @@ describe('query-history', () => {
expect(queryHistoryManager.treeDataProvider.allHistory).not.to.contain(toDelete);

// the same item should be selected
expect(localQueriesInterfaceManagerStub.showResults).to.have.been.calledOnceWith(selected);
expect(localQueriesResultsViewStub.showResults).to.have.been.calledOnceWith(selected);
});

it('should remove an item and select a new one', async () => {
Expand All @@ -272,7 +272,7 @@ describe('query-history', () => {
expect(queryHistoryManager.treeDataProvider.allHistory).not.to.contain(toDelete);

// the current item should have been selected
expect(localQueriesInterfaceManagerStub.showResults).to.have.been.calledOnceWith(newSelected);
expect(localQueriesResultsViewStub.showResults).to.have.been.calledOnceWith(newSelected);
});

describe('Compare callback', () => {
Expand Down Expand Up @@ -798,7 +798,7 @@ describe('query-history', () => {
const qhm = new QueryHistoryManager(
{} as QueryServerClient,
{} as DatabaseManager,
localQueriesInterfaceManagerStub,
localQueriesResultsViewStub,
remoteQueriesManagerStub,
{} as EvalLogViewer,
'xxx',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { walkDirectory } from '../../../helpers';
import { getErrorMessage } from '../../../pure/helpers-pure';
import { HistoryItemLabelProvider } from '../../../history-item-label-provider';
import { RemoteQueriesManager } from '../../../remote-queries/remote-queries-manager';
import { InterfaceManager } from '../../../interface';
import { ResultsView } from '../../../interface';
import { EvalLogViewer } from '../../../eval-log-viewer';

/**
Expand All @@ -33,7 +33,7 @@ describe('Remote queries and query history manager', function() {

let sandbox: sinon.SinonSandbox;
let qhm: QueryHistoryManager;
let localQueriesInterfaceManagerStub: InterfaceManager;
let localQueriesResutsViewStub: ResultsView;
let remoteQueriesManagerStub: RemoteQueriesManager;
let rawQueryHistory: any;
let remoteQueryResult0: RemoteQueryResult;
Expand All @@ -57,9 +57,9 @@ describe('Remote queries and query history manager', function() {

sandbox = sinon.createSandbox();

localQueriesInterfaceManagerStub = {
localQueriesResutsViewStub = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
localQueriesResutsViewStub = {
localQueriesResultsViewStub = {

showResults: sandbox.stub()
} as any as InterfaceManager;
} as any as ResultsView;

rehydrateRemoteQueryStub = sandbox.stub();
removeRemoteQueryStub = sandbox.stub();
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('Remote queries and query history manager', function() {
qhm = new QueryHistoryManager(
{} as QueryServerClient,
{} as DatabaseManager,
localQueriesInterfaceManagerStub,
localQueriesResutsViewStub,
remoteQueriesManagerStub,
{} as EvalLogViewer,
STORAGE_DIR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type InterfacePanelConfig = {
additionalOptions?: WebviewPanelOptions & WebviewOptions;
}

export abstract class AbstractInterfaceManager<ToMessage extends WebviewMessage, FromMessage extends WebviewMessage> extends DisposableObject {
export abstract class WebviewBase<ToMessage extends WebviewMessage, FromMessage extends WebviewMessage> extends DisposableObject {
protected panel: WebviewPanel | undefined;
protected panelLoaded = false;
protected panelLoadedCallBacks: (() => void)[] = [];
Expand Down