Truncate hints longer than 20 characters
This commit is contained in:
@@ -13,6 +13,8 @@ interface InlayHint {
|
|||||||
label: string;
|
label: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const maxHintLength = 20;
|
||||||
|
|
||||||
const typeHintDecorationType = vscode.window.createTextEditorDecorationType({
|
const typeHintDecorationType = vscode.window.createTextEditorDecorationType({
|
||||||
after: {
|
after: {
|
||||||
color: new vscode.ThemeColor('ralsp.inlayHint')
|
color: new vscode.ThemeColor('ralsp.inlayHint')
|
||||||
@@ -83,10 +85,20 @@ export class HintsUpdater {
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const newHints = await this.queryHints(editor.document.uri.toString());
|
const newHints = await this.queryHints(editor.document.uri.toString());
|
||||||
if (newHints !== null) {
|
if (newHints !== null) {
|
||||||
const newDecorations = newHints.map(hint => ({
|
const newDecorations = newHints.map(hint => {
|
||||||
range: hint.range,
|
let label = hint.label.substring(0, maxHintLength);
|
||||||
renderOptions: { after: { contentText: `: ${hint.label}` } }
|
if (hint.label.length > maxHintLength) {
|
||||||
}));
|
label += '…';
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
range: this.truncateHint(hint.range),
|
||||||
|
renderOptions: {
|
||||||
|
after: {
|
||||||
|
contentText: `: ${label}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
return editor.setDecorations(
|
return editor.setDecorations(
|
||||||
typeHintDecorationType,
|
typeHintDecorationType,
|
||||||
newDecorations
|
newDecorations
|
||||||
@@ -94,6 +106,18 @@ export class HintsUpdater {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private truncateHint(range: Range): Range {
|
||||||
|
if (!range.isSingleLine) {
|
||||||
|
return range;
|
||||||
|
}
|
||||||
|
const maxEnd = new vscode.Position(
|
||||||
|
range.start.line,
|
||||||
|
range.start.character + maxHintLength
|
||||||
|
);
|
||||||
|
const end = range.end.isAfter(maxEnd) ? maxEnd : range.end;
|
||||||
|
return new Range(range.start, end);
|
||||||
|
}
|
||||||
|
|
||||||
private async queryHints(documentUri: string): Promise<InlayHint[] | null> {
|
private async queryHints(documentUri: string): Promise<InlayHint[] | null> {
|
||||||
const request: InlayHintsParams = {
|
const request: InlayHintsParams = {
|
||||||
textDocument: { uri: documentUri }
|
textDocument: { uri: documentUri }
|
||||||
|
|||||||
Reference in New Issue
Block a user