label: string;
}
-const maxHintLength = 20;
-
const typeHintDecorationType = vscode.window.createTextEditorDecorationType({
after: {
color: new vscode.ThemeColor('ralsp.inlayHint')
const newHints = await this.queryHints(editor.document.uri.toString());
if (newHints !== null) {
const newDecorations = newHints.map(hint => {
- let label = hint.label.substring(0, maxHintLength);
- if (hint.label.length > maxHintLength) {
- label += '…';
- }
+ const [label, range] = this.truncateHint(
+ hint.label,
+ hint.range
+ );
return {
- range: this.truncateHint(hint.range),
+ range,
renderOptions: {
after: {
contentText: `: ${label}`
}
}
- private truncateHint(range: Range): Range {
- if (!range.isSingleLine) {
- return range;
+ private truncateHint(
+ label: string,
+ range: vscode.Range
+ ): [string, vscode.Range] {
+ if (!Server.config.maxInlayHintLength) {
+ return [label, range];
+ }
+
+ let newLabel = label.substring(0, Server.config.maxInlayHintLength);
+ if (label.length > Server.config.maxInlayHintLength) {
+ newLabel += '…';
}
- const maxEnd = new vscode.Position(
+
+ range = new vscode.Range(
range.start.line,
- range.start.character + maxHintLength
+ range.start.character,
+ range.end.line,
+ Math.min(
+ range.start.character + Server.config.maxInlayHintLength,
+ range.end.character
+ )
);
- const end = range.end.isAfter(maxEnd) ? maxEnd : range.end;
- return new Range(range.start, end);
+
+ return [newLabel, range];
}
private async queryHints(documentUri: string): Promise<InlayHint[] | null> {
public showWorkspaceLoadedNotification = true;
public lruCapacity: null | number = null;
public displayInlayHints = true;
+ public maxInlayHintLength: null | number = null;
public excludeGlobs = [];
public useClientWatching = false;
public featureFlags = {};
if (config.has('displayInlayHints')) {
this.displayInlayHints = config.get('displayInlayHints') as boolean;
}
+ if (config.has('maxInlayHintLength')) {
+ this.maxInlayHintLength = config.get(
+ 'maxInlayHintLength'
+ ) as number;
+ }
if (config.has('excludeGlobs')) {
this.excludeGlobs = config.get('excludeGlobs') || [];
}