Skip to content

Inline completion feature#1784

Merged
angelozerr merged 8 commits into
eclipse-lemminx:mainfrom
venmanyarun:inline_completion_feature
Jun 10, 2026
Merged

Inline completion feature#1784
angelozerr merged 8 commits into
eclipse-lemminx:mainfrom
venmanyarun:inline_completion_feature

Conversation

@venmanyarun

@venmanyarun venmanyarun commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #1780

This PR provides InlineCompletion participant API and it provides a basic inline completion to close the tag name. This inline support works only when you have this usecase <name>|

Tested in vscode-xml with redhat-developer/vscode-xml#1151

image

@angelozerr

Copy link
Copy Markdown
Contributor

It looks promising!

Please create the vscode-xml PR and reference it in this PR.

/**
* Helper method to extract string from Either<String, StringValue>
*/
private String getInsertTextAsString(Either<String, org.eclipse.lsp4j.StringValue> insertText) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have this method in an utility class?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* @return the inline completion list
* @throws BadLocationException if the position is invalid
*/
private InlineCompletionList testInlineCompletionFor(String xml) throws BadLocationException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use XMLAssert

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@angelozerr angelozerr Jun 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having this test:

String xml = "<root><child>|</child></root>";
		InlineCompletionList result = testInlineCompletionFor(xml);
		assertNotNull(result);
		assertEquals(1, result.getItems().size());
		assertEquals("nested", getInsertTextAsString(result.getItems().get(0).getInsertText()));

You should have this test

String xml = "<root><child>|</child></root>";
testInlineCompletionFor(xml, "nested");

by using XMLAssert#testInlineCompletionFor

@Test
public void testCloseRootElement() throws BadLocationException {
String xml = "<root>|";
XMLAssert.testInlineCompletionFor(new XMLLanguageService(), xml, null, "</root>");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test must be easy to read, instead of

XMLAssert.testInlineCompletionFor(new XMLLanguageService(), xml, null, "</root>");

it should be testInlineCompletionFor(xml, "</root>");

PLease:

  • use import static
  • define a new testInlineCompletionFor(String, String) which call your existing testInlineCompletionFor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


@Test
public void testCloseRootElement() throws BadLocationException {
String xml = "<root>|";

@angelozerr angelozerr Jun 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about <root| ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about <ro|ot ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XMLCloseTagInlineCompletion only works after closing tags

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@venmanyarun I have noticed that, see my comment #1784 (comment)

import org.junit.jupiter.api.Test;

/**
* XML inline completion service tests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XML inline completion service tests with custom participants.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* @return the inline completion list
* @throws BadLocationException if the position is invalid
*/
private InlineCompletionList testInlineCompletionFor(String xml) throws BadLocationException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't redefine testInlineCompletionFor but use your XMLAssert.testInlineCompletionFor

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated all calls to use XMLAssert.testInlineCompletionFor implementations

* @param insertText the insert text as Either
* @return the string value or null
*/
public static String getInsertTextAsString(Either<String, StringValue> insertText) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I though this utility class could be used in the core (not in the test).

Please remove this method and define it as private in XMLAssert.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@venmanyarun venmanyarun requested a review from angelozerr June 10, 2026 10:52
@angelozerr

Copy link
Copy Markdown
Contributor

@datho7561 @fbricon this PR provides inline completion with participant API and one impementation exists to show close tag:

If you have <name>|, inline completion display </name>, but with auto close tag we cannot seen this usecase.

So I wonder if we should provide inline completion with also this usecase <name| to show ></name> as inline completion.

What do you think about that?

@fbricon

fbricon commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

@datho7561 @fbricon this PR provides inline completion with participant API and one impementation exists to show close tag:

If you have <name>|, inline completion display </name>, but with auto close tag we cannot seen this usecase.

So I wonder if we should provide inline completion with also this usecase <name| to show ></name> as inline completion.

What do you think about that?

keeping tag autoclose should be fine
if autoclose is disabled then inline completion displaying </name> should work.

Both features should have the ability to be toggled

@angelozerr

angelozerr commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

this usecase <name| to show ></name>

Thanks for your feedback @fbricon and do you think we should also cover this usecase <name| to show ></name>

@fbricon

fbricon commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

this usecase <name| to show ></name>

Thanks for your feedback @fbricon and do you think we should also cover this usecase <name| to show ></name>

it depends. Adding ></name> is useless, but >${0}</name> makes sense if inline completion supports cursor position (I don't know)

@angelozerr

Copy link
Copy Markdown
Contributor

The PR is very good and we can improve inline completion features with another PR.

Let's merge it.

it depends. Adding ></name> is useless, but >${0}</name> makes sense if inline completion supports cursor position (I don't know)

I agree! I am not sure that inline completion can support snippet syntax.

@angelozerr angelozerr merged commit 85de214 into eclipse-lemminx:main Jun 10, 2026
6 checks passed
@angelozerr

Copy link
Copy Markdown
Contributor

Great job @venmanyarun !

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

Successfully merging this pull request may close these issues.

Add support for textDocument/inlineCompletion

3 participants