Skip to content

Commit 8402843

Browse files
committed
Refactor: Remove duplicated BQRS types
This refactoring combines the types in `bqrs-types.ts` and `bqrs-cli-types.ts`. Historically, the former was used for BQRS files parsed by the extension and the latter for BQRS files parsed by the cli. They describe the same file types, but using different property and type names. We have moved to parsing all BQRS files by the cli. This refactoring removes the `bqrs-types.ts` file and replaces all BQRS references to use types in `bqrs-cli-types.ts`. Additionally, the `adapt.ts` file has been deleted since its purpose was to convert between extension and cli BQRS types. Some one type and one function from `adapt.ts` has been moved from `adapt.ts` to `bqrs-types.ts`. It's possible that we want to do a further refactoring to simply remove them both.
1 parent b917a20 commit 8402843

24 files changed

Lines changed: 261 additions & 464 deletions

extensions/ql-vscode/src/adapt.ts

Lines changed: 0 additions & 113 deletions
This file was deleted.

extensions/ql-vscode/src/astViewer.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { DatabaseItem } from './databases';
44
import { UrlValue, BqrsId } from './bqrs-cli-types';
55
import fileRangeFromURI from './contextual/fileRangeFromURI';
66
import { showLocation } from './interface-utils';
7+
import { isStringLoc, isWholeFileLoc, isLineColumnLoc } from './bqrs-utils';
78

89
export interface AstItem {
910
id: BqrsId;
@@ -33,7 +34,7 @@ class AstViewerDataProvider implements vscode.TreeDataProvider<AstItem | RootAst
3334
await showLocation(fileRangeFromURI(location, db));
3435
}
3536
});
36-
}
37+
}
3738

3839
refresh(): void {
3940
this._onDidChangeTreeData.fire();
@@ -48,9 +49,7 @@ class AstViewerDataProvider implements vscode.TreeDataProvider<AstItem | RootAst
4849
}
4950

5051
getTreeItem(item: AstItem): vscode.TreeItem {
51-
const line = typeof item.location === 'string'
52-
? item.location
53-
: item.location?.startLine;
52+
const line = this.extractLineInfo(item?.location);
5453

5554
const state = item.children.length
5655
? vscode.TreeItemCollapsibleState.Collapsed
@@ -67,6 +66,20 @@ class AstViewerDataProvider implements vscode.TreeDataProvider<AstItem | RootAst
6766
};
6867
return treeItem;
6968
}
69+
70+
private extractLineInfo(loc?: UrlValue) {
71+
if (!loc) {
72+
return '';
73+
} else if (isStringLoc(loc)) {
74+
return loc;
75+
} else if (isWholeFileLoc(loc)) {
76+
return loc.uri;
77+
} else if (isLineColumnLoc(loc)) {
78+
return loc.startLine;
79+
} else {
80+
return '';
81+
}
82+
}
7083
}
7184

7285
export class AstViewer {

extensions/ql-vscode/src/bqrs-cli-types.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,6 @@ export interface LineColumnLocation {
6767
startColumn: number;
6868
endLine: number;
6969
endColumn: number;
70-
charOffset: never;
71-
charLength: never;
72-
}
73-
74-
export interface OffsetLengthLocation {
75-
uri: string;
76-
startLine: never;
77-
startColumn: never;
78-
endLine: never;
79-
endColumn: never;
80-
charOffset: number;
81-
charLength: number;
8270
}
8371

8472
export interface WholeFileLocation {
@@ -87,15 +75,28 @@ export interface WholeFileLocation {
8775
startColumn: never;
8876
endLine: never;
8977
endColumn: never;
90-
charOffset: never;
91-
charLength: never;
9278
}
9379

94-
export type UrlValue = LineColumnLocation | OffsetLengthLocation | WholeFileLocation | string;
80+
export type UrlValue = LineColumnLocation | WholeFileLocation | string;
9581

82+
export type ResolvableLocationValue = WholeFileLocation | LineColumnLocation;
9683

9784
export type ColumnValue = EntityValue | number | string | boolean;
9885

86+
export type ResultRow = ColumnValue[];
87+
88+
export interface RawResultSet {
89+
readonly schema: ResultSetSchema;
90+
readonly rows: readonly ResultRow[];
91+
}
92+
93+
export function adaptBqrs(schema: ResultSetSchema, page: DecodedBqrsChunk): RawResultSet {
94+
return {
95+
schema,
96+
rows: Array.from(page.tuples),
97+
};
98+
}
99+
99100
export interface DecodedBqrsChunk {
100101
tuples: ColumnValue[][];
101102
next?: number;

extensions/ql-vscode/src/bqrs-types.ts

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)