Skip to content

Commit 36225de

Browse files
committed
Support for textDocument/InlayHint
See redhat-developer/quarkus-ls#595 Signed-off-by: azerr <azerr@redhat.com>
1 parent 7d70d6b commit 36225de

File tree

5 files changed

+130
-6
lines changed

5 files changed

+130
-6
lines changed

docs/qute/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@
1010
## Settings
1111

1212
* `qute.trace.server`: Trace the communication between VS Code and the Qute language server in the Output view. Default is `off`.
13+
* `qute.codeLens.enabled`: Enable/disable Qute CodeLens. Default is `true`.
14+
* `qute.inlayHint.enabled`: Enable/disable Inlay Hint. Default is `true`.
15+
* `qute.inlayHint.showSectionParameterType`: Show section parameter type. Default is `true`.
16+
* `qute.inlayHint.showMethodParameterType`: Show method parameter type. Default is `true`.
1317
* `qute.validation.enabled`: Enable/disable all Qute validation. Default is `false`.
1418
* `qute.validation.excluded`: Disable Qute validation for the given file name patterns.\n\nExample:\n```\n[\n \"**/*items.qute.*\"\n]```.

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"license": "Apache-2.0",
1111
"bugs": "https://github.com/redhat-developer/vscode-quarkus/issues",
1212
"engines": {
13-
"vscode": "^1.37.0"
13+
"vscode": "^1.65.0"
1414
},
1515
"galleryBanner": {
1616
"color": "#d8ebff",
@@ -245,6 +245,26 @@
245245
"markdownDescription": "Traces the communication between VS Code and the Qute language server in the Output view. Default is `off`.",
246246
"scope": "window"
247247
},
248+
"qute.codeLens.enabled": {
249+
"type": "boolean",
250+
"default": true,
251+
"markdownDescription": "Enable/disable Qute CodeLens. Default is `true`."
252+
},
253+
"qute.inlayHint.enabled": {
254+
"type": "boolean",
255+
"default": true,
256+
"markdownDescription": "Enable/disable Qute Inlay Hint. Default is `true`."
257+
},
258+
"qute.inlayHint.showSectionParameterType": {
259+
"type": "boolean",
260+
"default": true,
261+
"markdownDescription": "Show section parameter type. Default is `true`."
262+
},
263+
"qute.inlayHint.showMethodParameterType": {
264+
"type": "boolean",
265+
"default": true,
266+
"markdownDescription": "Show method parameter type. Default is `true`."
267+
},
248268
"qute.validation.enabled": {
249269
"type": "boolean",
250270
"default": false,
@@ -393,7 +413,7 @@
393413
"@types/request": "^2.48.3",
394414
"@types/request-promise": "^4.1.44",
395415
"@types/semver": "^6.2.0",
396-
"@types/vscode": "^1.37.0",
416+
"@types/vscode": "^1.65.0",
397417
"@types/which": "^2.0.1",
398418
"@types/yauzl": "^2.9.1",
399419
"chai": "^4.2.0",

src/qute/languageServer/client.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import * as requirements from './requirements';
22

33
import { DidChangeConfigurationNotification, LanguageClientOptions } from 'vscode-languageclient';
44
import { LanguageClient } from 'vscode-languageclient/node';
5-
import { ExtensionContext, commands, workspace, window, ConfigurationTarget, WorkspaceConfiguration } from 'vscode';
5+
import { ExtensionContext, commands, workspace, window, ConfigurationTarget, WorkspaceConfiguration, InlayHintsProvider, CancellationToken, Event, InlayHint, ProviderResult, Range, TextDocument, languages } from 'vscode';
66
import { prepareExecutable } from './javaServerStarter';
77
import { registerQuteExecuteWorkspaceCommand, registerVSCodeQuteCommands, synchronizeQuteValidationButton } from '../commands/registerCommands';
88
import { QuteClientCommandConstants } from '../commands/commandConstants';
99
import { QuteSettings } from './settings';
1010
import { JavaExtensionAPI } from '../../extension';
11+
import { QuteInlayHintsProvider } from './inlayHintsProvider';
1112

1213
export function connectToQuteLS(context: ExtensionContext, api: JavaExtensionAPI) {
1314
registerVSCodeQuteCommands(context);
@@ -107,6 +108,9 @@ export function connectToQuteLS(context: ExtensionContext, api: JavaExtensionAPI
107108
if (!hasShownQuteValidationPopUp(context)) {
108109
await showQuteValidationPopUp(context);
109110
}
111+
if (languages.registerInlayHintsProvider) {
112+
context.subscriptions.push(languages.registerInlayHintsProvider(clientOptions.documentSelector, new QuteInlayHintsProvider(quteLanguageClient)));
113+
}
110114
});
111115
});
112116
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { LanguageClient, RequestType, TextDocumentPositionParams } from "vscode-languageclient/node";
2+
3+
import * as code from 'vscode';
4+
import * as ls from 'vscode-languageserver-protocol';
5+
6+
/**
7+
* A parameter literal used in inlay hints requests.
8+
*
9+
* @since 3.17.0 - proposed state
10+
*/
11+
export type InlayHintParams = /*WorkDoneProgressParams &*/ {
12+
/**
13+
* The text document.
14+
*/
15+
textDocument: ls.TextDocumentIdentifier;
16+
17+
/**
18+
* The document range for which inlay hints should be computed.
19+
*/
20+
range: ls.Range;
21+
};
22+
23+
/**
24+
* Inlay hint information.
25+
*
26+
* @since 3.17.0 - proposed state
27+
*/
28+
export type LSInlayHint = {
29+
30+
/**
31+
* The position of this hint.
32+
*/
33+
position: ls.Position;
34+
35+
/**
36+
* The label of this hint. A human readable string or an array of
37+
* InlayHintLabelPart label parts.
38+
*
39+
* *Note* that neither the string nor the label part can be empty.
40+
*/
41+
label: string; // label: string | InlayHintLabelPart[];
42+
};
43+
44+
namespace InlayHintRequest {
45+
export const type: RequestType<InlayHintParams, LSInlayHint[], any> = new RequestType('textDocument/inlayHint');
46+
}
47+
48+
/**
49+
* @since 3.17.0 - proposed state
50+
*/
51+
namespace InlayHintRefreshRequest {
52+
export const type: RequestType<void, void, void> = new RequestType('workspace/inlayHint/refresh');
53+
}
54+
55+
export class QuteInlayHintsProvider implements code.InlayHintsProvider {
56+
private readonly _onDidChangeInlayHints = new code.EventEmitter<void>();
57+
public readonly onDidChangeInlayHints = this._onDidChangeInlayHints.event;
58+
59+
constructor(private client: LanguageClient) {
60+
this.client.onRequest(InlayHintRefreshRequest.type, async () => {
61+
this._onDidChangeInlayHints.fire();
62+
});
63+
}
64+
async provideInlayHints(document: code.TextDocument, range: code.Range, token: code.CancellationToken): Promise<code.InlayHint[]> {
65+
const requestParams: InlayHintParams = {
66+
textDocument: this.client.code2ProtocolConverter.asTextDocumentIdentifier(document),
67+
range: this.client.code2ProtocolConverter.asRange(range)
68+
};
69+
70+
try {
71+
const values = await this.client.sendRequest(InlayHintRequest.type, requestParams, token);
72+
if (token.isCancellationRequested) {
73+
return null;
74+
}
75+
return asInlayHints(values, this.client, token);
76+
} catch (error) {
77+
return this.client.handleFailedRequest(InlayHintRequest.type, token, error);
78+
}
79+
}
80+
async resolveInlayHint?(hint: code.InlayHint, token: code.CancellationToken): Promise<code.InlayHint> {
81+
throw new Error("Method not implemented.");
82+
}
83+
}
84+
85+
async function asInlayHints(values: LSInlayHint[] | undefined | null, client: LanguageClient, token?: code.CancellationToken): Promise<code.InlayHint[] | undefined> {
86+
if (!Array.isArray(values)) {
87+
return undefined;
88+
}
89+
return values.map(lsHint => asInlayHint(lsHint, client, token));
90+
}
91+
92+
function asInlayHint(value: LSInlayHint, client: LanguageClient, token?: code.CancellationToken): code.InlayHint {
93+
const label = value.label;
94+
const result = new code.InlayHint(client.protocol2CodeConverter.asPosition(value.position), label);
95+
return result;
96+
}

0 commit comments

Comments
 (0)