Skip to content

Commit ef69a51

Browse files
committed
Avoid creating a multitoken when finding definitions
This will avoid showing a query-server popup on hovers. When someone does CTRL+hover on source code in a database archive, the definitions provider is triggered. The first time this is run, there will be a query that is invoked in order to find definitions. This can be a long process. Previously, this query brought up a popup window that could be cancelled. However, this is confusing users since the query is automatically cancelled when the mouse hovers away from the element. The downside of this PR is that even when find definitions is explicitly invoked, (using F12), there will still be no hover. I think this is an improvement, but I am happy to discuss if others disagree.
1 parent 9594a5e commit ef69a51

2 files changed

Lines changed: 31 additions & 33 deletions

File tree

extensions/ql-vscode/src/extension.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,23 +1086,27 @@ async function activateWithInstalledDistribution(
10861086
// Jump-to-definition and find-references
10871087
void extLogger.log("Registering jump-to-definition handlers.");
10881088

1089-
languages.registerDefinitionProvider(
1090-
{ scheme: zipArchiveScheme },
1091-
new TemplateQueryDefinitionProvider(
1092-
cliServer,
1093-
qs,
1094-
dbm,
1095-
contextualQueryStorageDir,
1089+
ctx.subscriptions.push(
1090+
languages.registerDefinitionProvider(
1091+
{ scheme: zipArchiveScheme },
1092+
new TemplateQueryDefinitionProvider(
1093+
cliServer,
1094+
qs,
1095+
dbm,
1096+
contextualQueryStorageDir,
1097+
),
10961098
),
10971099
);
10981100

1099-
languages.registerReferenceProvider(
1100-
{ scheme: zipArchiveScheme },
1101-
new TemplateQueryReferenceProvider(
1102-
cliServer,
1103-
qs,
1104-
dbm,
1105-
contextualQueryStorageDir,
1101+
ctx.subscriptions.push(
1102+
languages.registerReferenceProvider(
1103+
{ scheme: zipArchiveScheme },
1104+
new TemplateQueryReferenceProvider(
1105+
cliServer,
1106+
qs,
1107+
dbm,
1108+
contextualQueryStorageDir,
1109+
),
11061110
),
11071111
);
11081112

extensions/ql-vscode/src/language-support/contextual/template-provider.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,18 @@ export class TemplateQueryDefinitionProvider implements DefinitionProvider {
8888
uriString: string,
8989
token: CancellationToken,
9090
): Promise<LocationLink[]> {
91-
return withProgress(
92-
async (progress, tokenInner) => {
93-
const multiToken = new MultiCancellationToken(token, tokenInner);
94-
return getLocationsForUriString(
95-
this.cli,
96-
this.qs,
97-
this.dbm,
98-
uriString,
99-
KeyType.DefinitionQuery,
100-
this.queryStorageDir,
101-
progress,
102-
multiToken,
103-
(src, _dest) => src === uriString,
104-
);
105-
},
106-
{
107-
cancellable: true,
108-
title: "Finding definitions",
109-
},
91+
// Do not create a multitoken here. There will be no popup and users cannot click on anything to cancel this operation.
92+
// This is because finding definitions can be triggered by a hover, which should not have a popup.
93+
return getLocationsForUriString(
94+
this.cli,
95+
this.qs,
96+
this.dbm,
97+
uriString,
98+
KeyType.DefinitionQuery,
99+
this.queryStorageDir,
100+
() => {}, // noop
101+
token,
102+
(src, _dest) => src === uriString,
110103
);
111104
}
112105
}
@@ -161,6 +154,7 @@ export class TemplateQueryReferenceProvider implements ReferenceProvider {
161154
uriString: string,
162155
token: CancellationToken,
163156
): Promise<FullLocationLink[]> {
157+
// Create a multitoken here. There will be a popup and users can click on it to cancel this operation.
164158
return withProgress(
165159
async (progress, tokenInner) => {
166160
const multiToken = new MultiCancellationToken(token, tokenInner);

0 commit comments

Comments
 (0)