Skip to content

Commit 95d5274

Browse files
committed
Avoid showing a link when the underlying path is empty
A common situation when a file is not relevant for a particular result is to return an empty file path location. Currently, we are displaying this situation as a hyperlink in the results, but when clicking on the link, there is an error. To mirror the behaviour of Eclipse, we should avoid showing a link here. This commit changes that behaviour.
1 parent 9595525 commit 95d5274

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,24 @@ const FILE_LOCATION_REGEX = /file:\/\/(.+):([0-9]+):([0-9]+):([0-9]+):([0-9]+)/;
1616
export function tryGetResolvableLocation(
1717
loc: LocationValue | undefined
1818
): ResolvableLocationValue | undefined {
19+
let resolvedLoc;
1920
if (loc === undefined) {
20-
return undefined;
21+
resolvedLoc = undefined;
2122
} else if (loc.t === LocationStyle.FivePart && loc.file) {
22-
return loc;
23+
resolvedLoc = loc;
2324
} else if (loc.t === LocationStyle.WholeFile && loc.file) {
24-
return loc;
25+
resolvedLoc = loc;
2526
} else if (loc.t === LocationStyle.String && loc.loc) {
26-
return tryGetLocationFromString(loc);
27+
resolvedLoc = tryGetLocationFromString(loc);
2728
} else {
28-
return undefined;
29+
resolvedLoc = undefined;
2930
}
31+
32+
if (resolvedLoc && isEmptyPath(resolvedLoc.file)) {
33+
resolvedLoc = undefined;
34+
}
35+
36+
return resolvedLoc;
3037
}
3138

3239
export function tryGetLocationFromString(
@@ -62,3 +69,14 @@ function isWholeFileMatch(matches: RegExpExecArray): boolean {
6269
matches[5] === '0'
6370
);
6471
}
72+
73+
/**
74+
* Checks whether the file path is empty. For now, just check whether
75+
* the file path is empty. If so, we do not want to render this location
76+
* as a link.
77+
*
78+
* @param path A file path
79+
*/
80+
function isEmptyPath(path: string) {
81+
return !path || path === '/';
82+
}

extensions/ql-vscode/src/vscode-tests/no-workspace/interface-utils.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,26 @@ describe('interface-utils', () => {
119119
);
120120
});
121121

122+
it('should resolve a five-part location with an empty path', () => {
123+
const mockDatabaseItem: DatabaseItem = ({
124+
resolveSourceFile: sinon.stub().returns(vscode.Uri.parse('abc')),
125+
} as unknown) as DatabaseItem;
126+
127+
expect(
128+
tryResolveLocation(
129+
{
130+
t: LocationStyle.FivePart,
131+
colStart: 1,
132+
colEnd: 3,
133+
lineStart: 4,
134+
lineEnd: 5,
135+
file: '',
136+
},
137+
mockDatabaseItem
138+
)
139+
).to.be.undefined;
140+
});
141+
122142
it('should resolve a string location for whole file', () => {
123143
const mockDatabaseItem: DatabaseItem = ({
124144
resolveSourceFile: sinon.stub().returns(vscode.Uri.parse('abc')),

0 commit comments

Comments
 (0)