forked from redhat-developer/vscode-quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See redhat-developer/quarkus-ls#595 Signed-off-by: azerr <azerr@redhat.com>
- Loading branch information
1 parent
4235b37
commit 4e91fa9
Showing
5 changed files
with
131 additions
and
12 deletions.
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,96 @@ | ||
import { LanguageClient, RequestType, TextDocumentPositionParams } from "vscode-languageclient/node"; | ||
|
||
import * as code from 'vscode'; | ||
import * as ls from 'vscode-languageserver-protocol'; | ||
|
||
/** | ||
* 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'); | ||
} | ||
|
||
export class QuteInlayHintsProvider implements code.InlayHintsProvider { | ||
private readonly _onDidChangeInlayHints = new code.EventEmitter<void>(); | ||
public readonly onDidChangeInlayHints = this._onDidChangeInlayHints.event; | ||
|
||
constructor(private client: LanguageClient) { | ||
this.client.onRequest(InlayHintRefreshRequest.type, async () => { | ||
this._onDidChangeInlayHints.fire(); | ||
}); | ||
} | ||
async provideInlayHints(document: code.TextDocument, range: code.Range, token: code.CancellationToken): Promise<code.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 null; | ||
} | ||
return asInlayHints(values, this.client, token); | ||
} catch (error) { | ||
return this.client.handleFailedRequest(InlayHintRequest.type, token, error); | ||
} | ||
} | ||
async resolveInlayHint?(hint: code.InlayHint, token: code.CancellationToken): Promise<code.InlayHint> { | ||
throw new Error("Method not implemented."); | ||
} | ||
} | ||
|
||
async function asInlayHints(values: LSInlayHint[] | undefined | null, client: LanguageClient, token?: code.CancellationToken): Promise<code.InlayHint[] | undefined> { | ||
if (!Array.isArray(values)) { | ||
return undefined; | ||
} | ||
return values.map(lsHint => asInlayHint(lsHint, client, token)); | ||
} | ||
|
||
function asInlayHint(value: LSInlayHint, client: LanguageClient, token?: code.CancellationToken): code.InlayHint { | ||
const label = value.label; | ||
const result = new code.InlayHint(client.protocol2CodeConverter.asPosition(value.position), label); | ||
return result; | ||
} |