Truncate hints longer than 20 characters
This commit is contained in:
parent
523d7d2c82
commit
ce4fb06dec
1 changed files with 28 additions and 4 deletions
|
@ -13,6 +13,8 @@ interface InlayHint {
|
|||
label: string;
|
||||
}
|
||||
|
||||
const maxHintLength = 20;
|
||||
|
||||
const typeHintDecorationType = vscode.window.createTextEditorDecorationType({
|
||||
after: {
|
||||
color: new vscode.ThemeColor('ralsp.inlayHint')
|
||||
|
@ -83,10 +85,20 @@ export class HintsUpdater {
|
|||
): Promise<void> {
|
||||
const newHints = await this.queryHints(editor.document.uri.toString());
|
||||
if (newHints !== null) {
|
||||
const newDecorations = newHints.map(hint => ({
|
||||
range: hint.range,
|
||||
renderOptions: { after: { contentText: `: ${hint.label}` } }
|
||||
}));
|
||||
const newDecorations = newHints.map(hint => {
|
||||
let label = hint.label.substring(0, maxHintLength);
|
||||
if (hint.label.length > maxHintLength) {
|
||||
label += '…';
|
||||
}
|
||||
return {
|
||||
range: this.truncateHint(hint.range),
|
||||
renderOptions: {
|
||||
after: {
|
||||
contentText: `: ${label}`
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
return editor.setDecorations(
|
||||
typeHintDecorationType,
|
||||
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> {
|
||||
const request: InlayHintsParams = {
|
||||
textDocument: { uri: documentUri }
|
||||
|
|
Loading…
Add table
Reference in a new issue