Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inlay Hints Example #553

Open
RobertOstermann opened this issue Feb 4, 2022 · 4 comments
Open

Inlay Hints Example #553

RobertOstermann opened this issue Feb 4, 2022 · 4 comments
Assignees

Comments

@RobertOstermann
Copy link

Can we get an example extension using the proposed Inlay Hints API? Per the 1.64 release notes, this API is nearing completion and it would be helpful to have an extension sample available.

@jestarray
Copy link

@jrieken Can your test repo work as one? https://github.com/jrieken/test-inlayhints

@nclskfm

This comment was marked as spam.

@burner1024
Copy link

@jrieken Can your test repo work as one? https://github.com/jrieken/test-inlayhints

That's just client side, much more helpful would be proper LSP implementation.

@jardicc
Copy link

jardicc commented Sep 12, 2023

@burner1024 and if anyone else needs it. I spend about a hour to solve but I found it.

server side

		this.connection.languages.inlayHint.on((arg) => {
			const one = InlayHint.create(Position.create(1,1), [InlayHintLabelPart.create("type")], InlayHintKind.Type);
			one.data = "1";
			const two = InlayHint.create(Position.create(2,2), [InlayHintLabelPart.create("parameter")], InlayHintKind.Parameter);
			two.data = "2";
			return [one, two];
		});

		this.connection.languages.inlayHint.resolve((hint) => {
			(hint.label as InlayHintLabelPart[])[0].tooltip = "tooltip";
			hint.textEdits = [TextEdit.insert(Position.create(1, 1), "number")];
			return hint;
		});

Make sure to enable that in server capabilities

connection.onInitialize(() => {
	return {
		capabilities: {
// ...
			inlayHintProvider: {
				documentSelector: [{language: "json"}],
				resolveProvider: true
			},
			inlineValueProvider: {
				documentSelector: [{language: "json"}],
			},
// ...
		}
	};
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants