eclipse-jdtls / eclipse.jdt.ls

Java language server
1.75k stars 387 forks source link

completion returns no results with pattern matching. #3068

Open lbrayner opened 6 months ago

lbrayner commented 6 months ago

These are the completion capabilities:

Completion capabilities ```json { "textDocument": { "completion": { "completionItem": { "commitCharactersSupport": true, "deprecatedSupport": true, "insertReplaceSupport": true, "insertTextModeSupport": { "valueSet": [ 1, 2 ] }, "labelDetailsSupport": true, "preselectSupport": true, "snippetSupport": true, "tagSupport": { "valueSet": [ 1 ] } }, "completionList": { "itemDefaults": [ "commitCharacters", "data", "editRange", "insertTextFormat", "insertTextMode" ] }, "contextSupport": true, "dynamicRegistration": false, "insertTextMode": 1 } } } ```

Consider the following code:

import java.util.ArrayList;
import java.util.List;

public class SimpleJavaClass {
  public static void main(String[] args) {
    Object unknown = new ArrayList<>();

    if (unknown instanceof List things) {
      // things.is
      Object nothing = null;
      // things.is
    }
  }
}

textDocument/completion returns no results if requested for the first occurrence of things.is (uncommented, of course). It returns isEmpty(), however, for the second occurrence of thing.is.

Request for the first occurrence ```json { "method": "textDocument/completion", "params": { "position": { "character": 15, "line": 8 }, "textDocument": { "uri": "file:///var/tmp/jdtls-complete-fails/src/main/java/SimpleJavaClass.java" } } } ```
Result for the first occurrence ```json { "isIncomplete": false, "itemDefaults": { "data": { "completionKinds": [ 9 ] } }, "items": [] } ```
Request for the second occurrence ```json { "method": "textDocument/completion", "params": { "position": { "character": 15, "line": 10 }, "textDocument": { "uri": "file:///var/tmp/jdtls-complete-fails/src/main/java/SimpleJavaClass.java" } } } ```
Result for the second occurrence ```json { "isIncomplete": false, "itemDefaults": { "data": { "completionKinds": [ 2, 6 ] }, "editRange": { "insert": { "end": { "character": 15, "line": 10 }, "start": { "character": 13, "line": 10 } }, "replace": { "end": { "character": 15, "line": 10 }, "start": { "character": 13, "line": 10 } } }, "insertTextFormat": 2, "insertTextMode": 2 }, "items": [ { "command": { "arguments": [ "2", "0" ], "command": "java.completion.onDidSelect", "title": "" }, "data": { "pid": "0", "rid": "2" }, "detail": "List.isEmpty() : boolean", "filterText": "isEmpty() : boolean", "insertText": "isEmpty", "kind": 2, "label": "isEmpty", "labelDetails": { "description": "boolean", "detail": "()" }, "sortText": "999999035", "textEditText": "isEmpty()" } ] } ```
rgrunber commented 6 months ago

Definitely an upstream bug as well. It's interesting because it seemed to slightly work in earlier versions but regressed to the point of no support.