Switch AST viewer to use new result types

This commit is contained in:
Koen Vlaswinkel
2023-11-27 13:25:26 +01:00
parent 63d6793795
commit 76529572f5
2 changed files with 21 additions and 17 deletions

View File

@@ -9,6 +9,7 @@ import { ChildAstItem, AstItem } from "./ast-viewer";
import { Uri } from "vscode";
import { QueryOutputDir } from "../../run-queries-shared";
import { fileRangeFromURI } from "../contextual/file-range-from-uri";
import { mapUrlValue } from "../../common/bqrs-result";
/**
* A class that wraps a tree of QL results from a query that
@@ -106,7 +107,7 @@ export class AstBuilder {
const item = {
id,
label,
location: entity.url,
location: entity.url ? mapUrlValue(entity.url) : undefined,
fileLocation: fileRangeFromURI(entity.url, this.db),
children: [] as ChildAstItem[],
order: Number.MAX_SAFE_INTEGER,

View File

@@ -16,20 +16,20 @@ import {
import { basename } from "path";
import { DatabaseItem } from "../../databases/local-databases";
import { UrlValue, BqrsId } from "../../common/bqrs-cli-types";
import { BqrsId } from "../../common/bqrs-cli-types";
import { showLocation } from "../../databases/local-databases/locations";
import {
isStringLoc,
isWholeFileLoc,
isLineColumnLoc,
} from "../../common/bqrs-utils";
import { DisposableObject } from "../../common/disposable-object";
import { asError, getErrorMessage } from "../../common/helpers-pure";
import {
asError,
assertNever,
getErrorMessage,
} from "../../common/helpers-pure";
import { redactableError } from "../../common/errors";
import { AstViewerCommands } from "../../common/commands";
import { extLogger } from "../../common/logging/vscode";
import { showAndLogExceptionWithTelemetry } from "../../common/logging";
import { telemetryListener } from "../../common/vscode/telemetry";
import { UrlValue } from "../../common/raw-result-types";
export interface AstItem {
id: BqrsId;
@@ -90,15 +90,18 @@ class AstViewerDataProvider
private extractLineInfo(loc?: UrlValue) {
if (!loc) {
return "";
} else if (isStringLoc(loc)) {
return loc;
} else if (isWholeFileLoc(loc)) {
return;
}
switch (loc.type) {
case "string":
return loc.value;
case "wholeFileLocation":
return loc.uri;
} else if (isLineColumnLoc(loc)) {
case "lineColumnLocation":
return loc.startLine;
} else {
return "";
default:
assertNever(loc);
}
}
}