Skip to content

Commit 7652957

Browse files
committed
Switch AST viewer to use new result types
1 parent 63d6793 commit 7652957

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

extensions/ql-vscode/src/language-support/ast-viewer/ast-builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ChildAstItem, AstItem } from "./ast-viewer";
99
import { Uri } from "vscode";
1010
import { QueryOutputDir } from "../../run-queries-shared";
1111
import { fileRangeFromURI } from "../contextual/file-range-from-uri";
12+
import { mapUrlValue } from "../../common/bqrs-result";
1213

1314
/**
1415
* A class that wraps a tree of QL results from a query that
@@ -106,7 +107,7 @@ export class AstBuilder {
106107
const item = {
107108
id,
108109
label,
109-
location: entity.url,
110+
location: entity.url ? mapUrlValue(entity.url) : undefined,
110111
fileLocation: fileRangeFromURI(entity.url, this.db),
111112
children: [] as ChildAstItem[],
112113
order: Number.MAX_SAFE_INTEGER,

extensions/ql-vscode/src/language-support/ast-viewer/ast-viewer.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ import {
1616
import { basename } from "path";
1717

1818
import { DatabaseItem } from "../../databases/local-databases";
19-
import { UrlValue, BqrsId } from "../../common/bqrs-cli-types";
19+
import { BqrsId } from "../../common/bqrs-cli-types";
2020
import { showLocation } from "../../databases/local-databases/locations";
21-
import {
22-
isStringLoc,
23-
isWholeFileLoc,
24-
isLineColumnLoc,
25-
} from "../../common/bqrs-utils";
2621
import { DisposableObject } from "../../common/disposable-object";
27-
import { asError, getErrorMessage } from "../../common/helpers-pure";
22+
import {
23+
asError,
24+
assertNever,
25+
getErrorMessage,
26+
} from "../../common/helpers-pure";
2827
import { redactableError } from "../../common/errors";
2928
import { AstViewerCommands } from "../../common/commands";
3029
import { extLogger } from "../../common/logging/vscode";
3130
import { showAndLogExceptionWithTelemetry } from "../../common/logging";
3231
import { telemetryListener } from "../../common/vscode/telemetry";
32+
import { UrlValue } from "../../common/raw-result-types";
3333

3434
export interface AstItem {
3535
id: BqrsId;
@@ -90,15 +90,18 @@ class AstViewerDataProvider
9090

9191
private extractLineInfo(loc?: UrlValue) {
9292
if (!loc) {
93-
return "";
94-
} else if (isStringLoc(loc)) {
95-
return loc;
96-
} else if (isWholeFileLoc(loc)) {
97-
return loc.uri;
98-
} else if (isLineColumnLoc(loc)) {
99-
return loc.startLine;
100-
} else {
101-
return "";
93+
return;
94+
}
95+
96+
switch (loc.type) {
97+
case "string":
98+
return loc.value;
99+
case "wholeFileLocation":
100+
return loc.uri;
101+
case "lineColumnLocation":
102+
return loc.startLine;
103+
default:
104+
assertNever(loc);
102105
}
103106
}
104107
}

0 commit comments

Comments
 (0)