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

completion returns no results with pattern matching. #3068

Open
lbrayner opened this issue Feb 21, 2024 · 1 comment
Open

completion returns no results with pattern matching. #3068

lbrayner opened this issue Feb 21, 2024 · 1 comment

Comments

@lbrayner
Copy link
Contributor

lbrayner commented Feb 21, 2024

These are the completion capabilities:

Completion capabilities
{
  "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
{
  "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
{
  "isIncomplete": false,
  "itemDefaults": {
    "data": {
      "completionKinds": [ 9 ]
    }
  },
  "items": []
}
Request for the second occurrence
{
  "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
{
  "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
Copy link
Contributor

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.

@rgrunber rgrunber changed the title "textDocument/completion" returns no results before variable declaration completion returns no results with pattern matching. Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants