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.
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:
textDocument/completion
returns no results if requested for the first occurrence ofthings.is
(uncommented, of course). It returnsisEmpty()
, however, for the second occurrence ofthing.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()" } ] } ```