Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for textDocument/InlayHint #474

Merged
merged 1 commit into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/qute/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

## Settings

* `qute.codeLens.enabled`: Enable/disable Qute CodeLens. Default is `true`.
* `qute.trace.server`: Trace the communication between VS Code and the Qute language server in the Output view. Default is `off`.
* `qute.codeLens.enabled`: Enable/disable Qute CodeLens. Default is `true`.
* `qute.inlayHint.enabled`: Enable/disable Inlay Hint. Default is `true`.
* `qute.inlayHint.showSectionParameterType`: Show section parameter type. Default is `true`.
* `qute.inlayHint.showMethodParameterType`: Show method parameter type. Default is `true`.
* `qute.validation.enabled`: Enable/disable all Qute validation. Default is `false`.
* `qute.validation.excluded`: Disable Qute validation for the given file name patterns.\n\nExample:\n```\n[\n \"**/*items.qute.*\"\n]```.
* `qute.validation.undefinedObject.severity`: Validation severity for undefined object in Qute template files. Default is `warning`.
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 17 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "Apache-2.0",
"bugs": "https://github.com/redhat-developer/vscode-quarkus/issues",
"engines": {
"vscode": "^1.37.0"
"vscode": "^1.65.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most likely will be incompatible with theia

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benoitf what's the max vscode engine version compatible with theia?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most likely will be incompatible with theia

please note vscode-java have a PR to support Inlay Hint too, and they did that too https://github.com/redhat-developer/vscode-java/pull/2354/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R26

Copy link
Member

@rgrunber rgrunber Mar 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's not supported currently. https://eclipse-theia.github.io/vscode-theia-comparator/status.html .

Also, from redhat-developer/vscode-java#2183 (review), looks like updating the engine itself should not be harmful to Theia. Just have to ensure you don't call API that doesn't exist.

Update : According to https://github.com/eclipse-theia/theia/blob/master/dev-packages/application-package/src/api.ts#L21, should be 1.53.2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also see https://github.com/redhat-developer/vscode-java/pull/1975/files for how to adopt new API while still being compatible with older engines.

},
"galleryBanner": {
"color": "#d8ebff",
Expand Down Expand Up @@ -218,11 +218,6 @@
"description": "Action performed when detected Quarkus properties have an incorrect language.",
"scope": "window"
},
"qute.codeLens.enabled": {
"type": "boolean",
"default": true,
"markdownDescription": "Enable/disable Qute CodeLens. Default is `true`."
},
"qute.templates.languageMismatch": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -250,6 +245,21 @@
"markdownDescription": "Traces the communication between VS Code and the Qute language server in the Output view. Default is `off`.",
"scope": "window"
},
"qute.codeLens.enabled": {
"type": "boolean",
"default": true,
"markdownDescription": "Enable/disable Qute CodeLens. Default is `true`."
},
"qute.inlayHint.enabled": {
"type": "boolean",
"default": true,
"markdownDescription": "Enable/disable Qute Inlay Hint. Default is `true`."
},
"qute.inlayHint.showSectionParameterType": {
"type": "boolean",
"default": true,
"markdownDescription": "Show section parameter type. Default is `true`."
},
"qute.validation.enabled": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -409,7 +419,7 @@
"@types/request": "^2.48.3",
"@types/request-promise": "^4.1.44",
"@types/semver": "^6.2.0",
"@types/vscode": "^1.37.0",
"@types/vscode": "^1.65.0",
"@types/which": "^2.0.1",
"@types/yauzl": "^2.9.1",
"chai": "^4.2.0",
Expand Down
7 changes: 6 additions & 1 deletion src/qute/languageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import * as requirements from './requirements';

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

export function connectToQuteLS(context: ExtensionContext, api: JavaExtensionAPI) {
registerVSCodeQuteCommands(context);
Expand Down Expand Up @@ -107,6 +108,10 @@ export function connectToQuteLS(context: ExtensionContext, api: JavaExtensionAPI
if (!hasShownQuteValidationPopUp(context)) {
showQuteValidationPopUp(context);
}
const supportRegisterInlayHintsProvider = (languages as any).registerInlayHintsProvider;
if (supportRegisterInlayHintsProvider) {
context.subscriptions.push(languages.registerInlayHintsProvider(clientOptions.documentSelector, new QuteInlayHintsProvider(quteLanguageClient)));
}
});
});
}
Expand Down
95 changes: 95 additions & 0 deletions src/qute/languageServer/inlayHintsProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { CancellationToken, EventEmitter, InlayHint, InlayHintKind, InlayHintsProvider, Range, TextDocument } from "vscode";
import * as ls from 'vscode-languageserver-protocol';
import { LanguageClient, RequestType } from "vscode-languageclient/node";

export class QuteInlayHintsProvider implements InlayHintsProvider {

private onDidChange = new EventEmitter<void>();
public onDidChangeInlayHints = this.onDidChange.event;

constructor(private client: LanguageClient) {
this.client.onRequest(InlayHintRefreshRequest.type, async () => {
this.onDidChange.fire();
});
}

public async provideInlayHints(document: TextDocument, range: Range, token: CancellationToken): Promise<InlayHint[]> {
const requestParams: InlayHintParams = {
textDocument: this.client.code2ProtocolConverter.asTextDocumentIdentifier(document),
range: this.client.code2ProtocolConverter.asRange(range)
};
try {
const values = await this.client.sendRequest(InlayHintRequest.type, requestParams, token);
if (token.isCancellationRequested) {
return [];
}
return asInlayHints(values, this.client);
} catch (error) {
return this.client.handleFailedRequest(InlayHintRequest.type, token, error);
}
}
}

/**
* A parameter literal used in inlay hints requests.
*
* @since 3.17.0 - proposed state
*/
export type InlayHintParams = /*WorkDoneProgressParams &*/ {
/**
* The text document.
*/
textDocument: ls.TextDocumentIdentifier;

/**
* The document range for which inlay hints should be computed.
*/
range: ls.Range;
};

/**
* Inlay hint information.
*
* @since 3.17.0 - proposed state
*/
export type LSInlayHint = {

/**
* The position of this hint.
*/
position: ls.Position;

/**
* The label of this hint. A human readable string or an array of
* InlayHintLabelPart label parts.
*
* *Note* that neither the string nor the label part can be empty.
*/
label: string; // label: string | InlayHintLabelPart[];
};

namespace InlayHintRequest {
export const type: RequestType<InlayHintParams, LSInlayHint[], any> = new RequestType('textDocument/inlayHint');
}

/**
* @since 3.17.0 - proposed state
*/
namespace InlayHintRefreshRequest {
export const type: RequestType<void, void, void> = new RequestType('workspace/inlayHint/refresh');
}

async function asInlayHints(values: LSInlayHint[] | undefined | null, client: LanguageClient, ): Promise<InlayHint[] | undefined> {
if (!Array.isArray(values)) {
return undefined;
}
return values.map(lsHint => asInlayHint(lsHint, client));
}

function asInlayHint(value: LSInlayHint, client: LanguageClient): InlayHint {
const label = value.label;
const result = new InlayHint(client.protocol2CodeConverter.asPosition(value.position), label);
result.paddingRight = true;
result.kind = InlayHintKind.Parameter;
return result;
}