redhat-developer / redhat-developer/lsp4ij

Completion collapses with previous line when triggered on a new empty line

Open
#945 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug completion
Dominant language
Java
Stars
344
Forks
113
Avg merge
5h 22m
Merged PRs (30d)
15

Description

Issue: Completion collapses with previous line when triggered on a new empty line

Description

When triggering completion with Ctrl+Space on a new empty line to get attribute suggestions, LSP4IJ correctly displays the completion suggestions. However, when selecting one of these suggestions, it removes the newline character and places the inserted text on the previous line, causing it to collapse with the last non-whitespace character.

This issue only occurs when triggering completion on a completely empty line. If at least one character is typed before triggering completion, the feature works as expected.

Steps to Reproduce

  1. Open a file supported by an LSP server
  2. Place the cursor on a new empty line
  3. Press Ctrl+Space to trigger completion
  4. Select one of the suggestions from the popup

Current Behavior

The selected completion item is inserted at the end of the previous line, removing the newline character.

Expected Behavior

The selected completion item should be inserted at the cursor position on the new line, preserving the line break.

Root Cause Analysis

When no TextEdit is provided by the language server, LSP4IJ tries to compute the prefix start offset using the insert text. The method getPrefixStartOffsetWhichMatchesLeftContent looks back for content that matches the beginning of the insert text but doesn't respect line boundaries.

When on a new empty line, this method looks back across the newline character and may find matching content on the previous line. It then sets the prefix start offset to that position, causing the completion to overwrite the newline character and collapse with the previous line.

Affected Components

  • LSPCompletionProposal.java - Specifically the methods:
    • getPrefixStartOffset
    • computePrefixStartFromInsertText
    • getPrefixStartOffsetWhichMatchesLeftContent

The issue is present in the latest version of the LSP4IJ plugin.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in LSPCompletionProposal.java, focusing on getPrefixStartOffset, computePrefixStartFromInsertText, and getPrefixStartOffsetWhichMatchesLeftContent. Reproduce completion with Ctrl+Space on a completely empty line and inspect how the prefix start offset is computed when no TextEdit is provided. Done means the selected completion preserves the newline and is inserted on the new line while existing non-empty-line behavior still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.