redhat-developer / redhat-developer/lsp4ij
Completion collapses with previous line when triggered on a new empty line
Nobody has claimed this yet.
- 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
- Open a file supported by an LSP server
- Place the cursor on a new empty line
- Press Ctrl+Space to trigger completion
- 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:getPrefixStartOffsetcomputePrefixStartFromInsertTextgetPrefixStartOffsetWhichMatchesLeftContent
The issue is present in the latest version of the LSP4IJ plugin.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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