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

Indentation is off for multi-line snippets with InsertTextMode.AsIs #598

Open
mfussenegger opened this issue Jan 26, 2025 · 0 comments
Open

Comments

@mfussenegger
Copy link
Contributor

In editors like neovim the indentation for dependency completion is off

For example in:

  <dependencies>
    |
    <dependency>
      <groupId>org.eclipse.lsp4j</groupId>
      <artifactId>org.eclipse.lsp4j</artifactId>
      <version>0.23.1</version>
    </dependency>

With the cursor indicated as |, completing something like jackson-core leads to:

  <dependencies>
    <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-core</artifactId>
          <version>2.18.2</version>
        </dependency>

Instead of:

  <dependencies>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>2.18.2</version>
    </dependency>

The reason is that the subsequent lines in the textEdit are pre-indented. But asIs is defined in the specification as:

/**
  * The insertion or replace strings is taken as it is. If the
  * value is multi line the lines below the cursor will be
  * inserted using the indentation defined in the string value.
  * The client will not apply any kind of adjustments to the
  * string.
  */

Meaning the subsequent indentation should be relative to the cursor, not more.

Changing the isInsertTextModeAdjustIndentationSupport condition like the following would fix the problem, but it seems like this was intentional?

diff --git a/lemminx-maven/src/main/java/org/eclipse/lemminx/extensions/maven/participants/completion/MavenCompletionParticipant.java b/lemminx-maven/src/main/java/org/eclipse/lemminx/extensions/maven/participants/completion/MavenCompletionParticipant.java
index 85eda71..4ed20c5 100644
--- a/lemminx-maven/src/main/java/org/eclipse/lemminx/extensions/maven/participants/completion/MavenCompletionParticipant.java
+++ b/lemminx-maven/src/main/java/org/eclipse/lemminx/extensions/maven/participants/completion/MavenCompletionParticipant.java
@@ -777,11 +777,11 @@ private CompletionItem toGAVCompletionItem(ArtifactWithDescription artifactInfo,
 				if (insertGroupId) {
 					Position insertionPosition;
 					try {
 						insertionPosition = request.getXMLDocument()
 								.positionAt(request.getParentElement().getParentElement().getStartTagCloseOffset() + 1);
-						String indent = !isInsertTextModeAdjustIndentationSupport(request)
+						String indent = isInsertTextModeAdjustIndentationSupport(request)
 								? request.getLineIndentInfo().getWhitespacesIndent()
 								: "";
 						additionalEdits.add(new TextEdit(new Range(insertionPosition, insertionPosition),
 								request.getLineIndentInfo().getLineDelimiter()
 										+ indent + "<groupId>"
@@ -795,11 +795,11 @@ private CompletionItem toGAVCompletionItem(ArtifactWithDescription artifactInfo,
 				if (insertVersion) {
 					Position insertionPosition;
 					try {
 						insertionPosition = insertArtifactIsEnd ? replaceRange.getEnd() :
 								request.getXMLDocument().positionAt(request.getParentElement().getEndTagCloseOffset() + 1);
-						String indent = !isInsertTextModeAdjustIndentationSupport(request)
+						String indent = isInsertTextModeAdjustIndentationSupport(request)
 								? request.getLineIndentInfo().getWhitespacesIndent()
 								: "";
 						additionalEdits.add(new TextEdit(new Range(insertionPosition, insertionPosition),
 								request.getLineIndentInfo().getLineDelimiter()
 										+ indent + "<version>"
@@ -834,11 +834,11 @@ private CompletionItem toGAVCompletionItem(ArtifactWithDescription artifactInfo,
 			item.setKind(CompletionItemKind.Struct);
 			item.setFilterText(artifactInfo.artifact.getArtifactId());
 			try {
 				String newText = "";
 				String suffix = "";
-				String gavElementsIndent = !isInsertTextModeAdjustIndentationSupport(request)
+				String gavElementsIndent = isInsertTextModeAdjustIndentationSupport(request)
 						? request.getLineIndentInfo().getWhitespacesIndent()
 						: "";
 				String oneLevelIndent = DOMUtils.getOneLevelIndent(request);
 				String lineDelimiter = request.getLineIndentInfo().getLineDelimiter();
 				cancelChecker.checkCanceled();
@@ -1422,6 +1422,6 @@ private static boolean isInsertTextModeAdjustIndentationSupport(ICompletionReque
 				&& request.getSharedSettings().getCompletionSettings() != null
 				&& request.getSharedSettings().getCompletionSettings().getCompletionCapabilities() != null
 				&& InsertTextMode.AdjustIndentation.equals(request.getSharedSettings().getCompletionSettings()
 						.getCompletionCapabilities().getInsertTextMode());
 	}
-}
\ No newline at end of file
+}
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

1 participant