-
Notifications
You must be signed in to change notification settings - Fork 28
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.