Skip to content

Commit 61d18c9

Browse files
committed
feat: implemented provideInlayHints
1 parent b89b4c5 commit 61d18c9

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/monaco/code2monaco.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,49 @@ export function asSelectionRange(item: vscode.SelectionRange): monaco.languages.
442442
range: asRange(item.range),
443443
};
444444
}
445+
446+
export function asInlayHint(item: vscode.InlayHint): monaco.languages.InlayHint {
447+
return {
448+
label: asInlayHintLabel(item.label),
449+
tooltip: item.tooltip,
450+
command: undefined,
451+
position: asPosition(item.position),
452+
kind: item.kind ? asInlayHintKind(item.kind) : undefined,
453+
paddingLeft: item.paddingLeft,
454+
paddingRight: item.paddingRight,
455+
};
456+
}
457+
458+
export function asInlayHintKind(kind: vscode.InlayHintKind): monaco.languages.InlayHintKind {
459+
switch (kind) {
460+
case vscode.InlayHintKind.Parameter:
461+
return monaco.languages.InlayHintKind.Parameter;
462+
case vscode.InlayHintKind.Type:
463+
return monaco.languages.InlayHintKind.Type;
464+
}
465+
}
466+
467+
export function asInlayHintLabel(label: vscode.InlayHint['label']): monaco.languages.InlayHint['label'] {
468+
if (typeof label === 'string') {
469+
return label;
470+
}
471+
else {
472+
return label.map(asInlayHintLabelPart);
473+
}
474+
}
475+
476+
export function asInlayHintLabelPart(part: vscode.InlayHintLabelPart): monaco.languages.InlayHintLabelPart {
477+
return {
478+
label: part.value,
479+
tooltip: part.tooltip,
480+
command: part.command ? asCommand(part.command) : undefined,
481+
location: part.location ? asLocation(part.location) : undefined,
482+
};
483+
}
484+
485+
export function asPosition(position: vscode.Position): monaco.Position {
486+
return {
487+
lineNumber: position.line + 1,
488+
column: position.character + 1,
489+
} as unknown as monaco.Position;
490+
}

src/monaco/ls.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,23 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
544544
}
545545
},
546546
}),
547+
// TODO: registerDocumentSemanticTokensProvider
548+
// TODO: registerDocumentRangeSemanticTokensProvider
549+
// TODO: registerInlineCompletionsProvider
550+
monaco.languages.registerInlayHintsProvider(lang, {
551+
provideInlayHints: async (model, range) => {
552+
const codeResult = await ls.getInlayHints(
553+
model.uri.toString(),
554+
monaco2code.asRange(range),
555+
);
556+
if (codeResult) {
557+
return {
558+
hints: codeResult.map(code2monaco.asInlayHint),
559+
dispose: () => { },
560+
};
561+
}
562+
},
563+
}),
547564
);
548565

549566
return ls;

0 commit comments

Comments
 (0)