Remove WebviewParsed branch from ParsedResultSets
Also remove dead code downstream from it.
This commit is contained in:
@@ -110,7 +110,7 @@ export function adaptBqrs(schema: AdaptedSchema, page: DecodedBqrsChunk): RawRes
|
|||||||
* for this transition is to make pagination possible in such a way
|
* for this transition is to make pagination possible in such a way
|
||||||
* that only one page needs to be sent from the extension to the webview.
|
* that only one page needs to be sent from the extension to the webview.
|
||||||
*/
|
*/
|
||||||
export type ParsedResultSets = ExtensionParsedResultSets | WebviewParsedResultSets;
|
export type ParsedResultSets = ExtensionParsedResultSets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The old method doesn't require any nontrivial information to be included here,
|
* The old method doesn't require any nontrivial information to be included here,
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ import {
|
|||||||
ParsedResultSets,
|
ParsedResultSets,
|
||||||
RawResultSet,
|
RawResultSet,
|
||||||
} from './adapt';
|
} from './adapt';
|
||||||
import { EXPERIMENTAL_BQRS_SETTING } from './config';
|
|
||||||
import {
|
import {
|
||||||
WebviewReveal,
|
WebviewReveal,
|
||||||
fileUriToWebviewUri,
|
fileUriToWebviewUri,
|
||||||
@@ -335,40 +334,34 @@ export class InterfaceManager extends DisposableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getParsedResultSets = async (): Promise<ParsedResultSets> => {
|
const getParsedResultSets = async (): Promise<ParsedResultSets> => {
|
||||||
if (EXPERIMENTAL_BQRS_SETTING.getValue()) {
|
|
||||||
const resultSetSchemas = await this.getResultSetSchemas(results);
|
|
||||||
const resultSetNames = resultSetSchemas.map(schema => schema.name);
|
|
||||||
|
|
||||||
// This may not wind up being the page we actually show, if there are interpreted results,
|
const resultSetSchemas = await this.getResultSetSchemas(results);
|
||||||
// but speculatively send it anyway.
|
const resultSetNames = resultSetSchemas.map(schema => schema.name);
|
||||||
const selectedTable = getDefaultResultSetName(resultSetNames);
|
|
||||||
const schema = resultSetSchemas.find(
|
|
||||||
(resultSet) => resultSet.name == selectedTable
|
|
||||||
)!;
|
|
||||||
if (schema === undefined) {
|
|
||||||
return { t: 'WebviewParsed' };
|
|
||||||
}
|
|
||||||
|
|
||||||
const chunk = await this.cliServer.bqrsDecode(
|
// This may not wind up being the page we actually show, if there are interpreted results,
|
||||||
results.query.resultsPaths.resultsPath,
|
// but speculatively send it anyway.
|
||||||
schema.name,
|
const selectedTable = getDefaultResultSetName(resultSetNames);
|
||||||
RAW_RESULTS_PAGE_SIZE,
|
const schema = resultSetSchemas.find(
|
||||||
schema.pagination?.offsets[0]
|
(resultSet) => resultSet.name == selectedTable
|
||||||
);
|
)!;
|
||||||
const adaptedSchema = adaptSchema(schema);
|
|
||||||
const resultSet = adaptBqrs(adaptedSchema, chunk);
|
const chunk = await this.cliServer.bqrsDecode(
|
||||||
return {
|
results.query.resultsPaths.resultsPath,
|
||||||
t: 'ExtensionParsed',
|
schema.name,
|
||||||
pageNumber: 0,
|
RAW_RESULTS_PAGE_SIZE,
|
||||||
numPages: numPagesOfResultSet(resultSet),
|
schema.pagination?.offsets[0]
|
||||||
numInterpretedPages: numInterpretedPages(this._interpretation),
|
);
|
||||||
resultSet: { t: 'RawResultSet', ...resultSet },
|
const adaptedSchema = adaptSchema(schema);
|
||||||
selectedTable: undefined,
|
const resultSet = adaptBqrs(adaptedSchema, chunk);
|
||||||
resultSetNames,
|
return {
|
||||||
};
|
t: 'ExtensionParsed',
|
||||||
} else {
|
pageNumber: 0,
|
||||||
return { t: 'WebviewParsed' };
|
numPages: numPagesOfResultSet(resultSet),
|
||||||
}
|
numInterpretedPages: numInterpretedPages(this._interpretation),
|
||||||
|
resultSet: { t: 'RawResultSet', ...resultSet },
|
||||||
|
selectedTable: undefined,
|
||||||
|
resultSetNames,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
await this.postMessage({
|
await this.postMessage({
|
||||||
|
|||||||
@@ -117,9 +117,6 @@ export class ResultTables
|
|||||||
case 'ExtensionParsed':
|
case 'ExtensionParsed':
|
||||||
selectedPage = (props.parsedResultSets.pageNumber + 1) + '';
|
selectedPage = (props.parsedResultSets.pageNumber + 1) + '';
|
||||||
break;
|
break;
|
||||||
case 'WebviewParsed':
|
|
||||||
selectedPage = '';
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
this.state = { selectedTable, selectedPage };
|
this.state = { selectedTable, selectedPage };
|
||||||
}
|
}
|
||||||
@@ -167,8 +164,6 @@ export class ResultTables
|
|||||||
switch (parsedResultSets.t) {
|
switch (parsedResultSets.t) {
|
||||||
case 'ExtensionParsed':
|
case 'ExtensionParsed':
|
||||||
return parsedResultSets.pageNumber * RAW_RESULTS_PAGE_SIZE;
|
return parsedResultSets.pageNumber * RAW_RESULTS_PAGE_SIZE;
|
||||||
case 'WebviewParsed':
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import * as Rdom from 'react-dom';
|
import * as Rdom from 'react-dom';
|
||||||
import * as bqrs from 'semmle-bqrs';
|
|
||||||
import {
|
|
||||||
ElementBase,
|
|
||||||
PrimitiveColumnValue,
|
|
||||||
PrimitiveTypeKind,
|
|
||||||
tryGetResolvableLocation,
|
|
||||||
} from 'semmle-bqrs';
|
|
||||||
import { assertNever } from '../helpers-pure';
|
import { assertNever } from '../helpers-pure';
|
||||||
import {
|
import {
|
||||||
DatabaseInfo,
|
DatabaseInfo,
|
||||||
@@ -22,8 +15,6 @@ import {
|
|||||||
import { EventHandlers as EventHandlerList } from './event-handler-list';
|
import { EventHandlers as EventHandlerList } from './event-handler-list';
|
||||||
import { ResultTables } from './result-tables';
|
import { ResultTables } from './result-tables';
|
||||||
import {
|
import {
|
||||||
ResultValue,
|
|
||||||
ResultRow,
|
|
||||||
ParsedResultSets,
|
ParsedResultSets,
|
||||||
} from '../adapt';
|
} from '../adapt';
|
||||||
import { ResultSet } from '../interface-types';
|
import { ResultSet } from '../interface-types';
|
||||||
@@ -36,91 +27,6 @@ import { vscode } from './vscode-api';
|
|||||||
* Displaying query results.
|
* Displaying query results.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async function* getChunkIterator(
|
|
||||||
response: Response
|
|
||||||
): AsyncIterableIterator<Uint8Array> {
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(
|
|
||||||
`Failed to load results: (${response.status}) ${response.statusText}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const reader = response.body!.getReader();
|
|
||||||
while (true) {
|
|
||||||
const { value, done } = await reader.read();
|
|
||||||
if (done) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
yield value!;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function translatePrimitiveValue(
|
|
||||||
value: PrimitiveColumnValue,
|
|
||||||
type: PrimitiveTypeKind
|
|
||||||
): ResultValue {
|
|
||||||
switch (type) {
|
|
||||||
case 'i':
|
|
||||||
case 'f':
|
|
||||||
case 's':
|
|
||||||
case 'd':
|
|
||||||
case 'b':
|
|
||||||
return value.toString();
|
|
||||||
|
|
||||||
case 'u':
|
|
||||||
return {
|
|
||||||
uri: value as string,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function parseResultSets(
|
|
||||||
response: Response
|
|
||||||
): Promise<readonly ResultSet[]> {
|
|
||||||
const chunks = getChunkIterator(response);
|
|
||||||
|
|
||||||
const resultSets: ResultSet[] = [];
|
|
||||||
|
|
||||||
await bqrs.parse(chunks, (resultSetSchema) => {
|
|
||||||
const columnTypes = resultSetSchema.columns.map((column) => column.type);
|
|
||||||
const rows: ResultRow[] = [];
|
|
||||||
resultSets.push({
|
|
||||||
t: 'RawResultSet',
|
|
||||||
schema: resultSetSchema,
|
|
||||||
rows: rows,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (tuple) => {
|
|
||||||
const row: ResultValue[] = [];
|
|
||||||
tuple.forEach((value, index) => {
|
|
||||||
const type = columnTypes[index];
|
|
||||||
if (type.type === 'e') {
|
|
||||||
const element: ElementBase = value as ElementBase;
|
|
||||||
const label =
|
|
||||||
element.label !== undefined ? element.label : element.id.toString(); //REVIEW: URLs?
|
|
||||||
const resolvableLocation = tryGetResolvableLocation(element.location);
|
|
||||||
if (resolvableLocation !== undefined) {
|
|
||||||
row.push({
|
|
||||||
label: label,
|
|
||||||
location: resolvableLocation,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// No location link.
|
|
||||||
row.push(label);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
row.push(
|
|
||||||
translatePrimitiveValue(value as PrimitiveColumnValue, type.type)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
rows.push(row);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return resultSets;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ResultsInfo {
|
interface ResultsInfo {
|
||||||
parsedResultSets: ParsedResultSets;
|
parsedResultSets: ParsedResultSets;
|
||||||
resultsPath: string;
|
resultsPath: string;
|
||||||
@@ -270,8 +176,6 @@ class App extends React.Component<{}, ResultsViewState> {
|
|||||||
): Promise<readonly ResultSet[]> {
|
): Promise<readonly ResultSet[]> {
|
||||||
const parsedResultSets = resultsInfo.parsedResultSets;
|
const parsedResultSets = resultsInfo.parsedResultSets;
|
||||||
switch (parsedResultSets.t) {
|
switch (parsedResultSets.t) {
|
||||||
case 'WebviewParsed':
|
|
||||||
return await this.fetchResultSets(resultsInfo);
|
|
||||||
case 'ExtensionParsed': {
|
case 'ExtensionParsed': {
|
||||||
return [{ t: 'RawResultSet', ...parsedResultSets.resultSet }];
|
return [{ t: 'RawResultSet', ...parsedResultSets.resultSet }];
|
||||||
}
|
}
|
||||||
@@ -321,35 +225,6 @@ class App extends React.Component<{}, ResultsViewState> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This is deprecated, because it calls `fetch`. We are moving
|
|
||||||
* towards doing all bqrs parsing in the extension.
|
|
||||||
*/
|
|
||||||
private async fetchResultSets(
|
|
||||||
resultsInfo: ResultsInfo
|
|
||||||
): Promise<readonly ResultSet[]> {
|
|
||||||
const unsortedResponse = await fetch(resultsInfo.resultsPath);
|
|
||||||
const unsortedResultSets = await parseResultSets(unsortedResponse);
|
|
||||||
return Promise.all(
|
|
||||||
unsortedResultSets.map(async (unsortedResultSet) => {
|
|
||||||
const sortedResultSetInfo = resultsInfo.sortedResultsMap.get(
|
|
||||||
unsortedResultSet.schema.name
|
|
||||||
);
|
|
||||||
if (sortedResultSetInfo === undefined) {
|
|
||||||
return unsortedResultSet;
|
|
||||||
}
|
|
||||||
const response = await fetch(sortedResultSetInfo.resultsPath);
|
|
||||||
const resultSets = await parseResultSets(response);
|
|
||||||
if (resultSets.length != 1) {
|
|
||||||
throw new Error(
|
|
||||||
`Expected sorted BQRS to contain a single result set, encountered ${resultSets.length} result sets.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return resultSets[0];
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private getSortStates(
|
private getSortStates(
|
||||||
resultsInfo: ResultsInfo
|
resultsInfo: ResultsInfo
|
||||||
): Map<string, RawResultsSortState> {
|
): Map<string, RawResultsSortState> {
|
||||||
|
|||||||
Reference in New Issue
Block a user