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

Wrong completion text for AnonymousDeclarationType #1168

Closed
Eskibear opened this issue Sep 9, 2019 · 1 comment
Closed

Wrong completion text for AnonymousDeclarationType #1168

Eskibear opened this issue Sep 9, 2019 · 1 comment

Comments

@Eskibear
Copy link
Contributor

Eskibear commented Sep 9, 2019

Originally reported in microsoft/vscode-java-pack#203 , the snippet string for the completion item is wrong.

Before

public class A {
  void foo() {
    new IA<-------- Trigger completion here
  }
}

interface IA {
  void bar();
}

After

public class A {
  void foo() {
    new IA(){
      @Override
      public void bar() {
        ${0// TODO Auto-generated method stub
        }
      }
    };
  }
}

interface IA {
  void bar();
}

LSP request/response

[Trace - 上午10:29:32] Sending request 'completionItem/resolve - (2786)'.
Params: {
    "label": "IA()  Anonymous Inner Type",
    "detail": "com.example.demo",
    "insertTextFormat": 1,
    "insertText": "IA",
    "kind": 4,
    "sortText": "999999100",
    "data": {
        "decl_signature": "Lcom.example.demo.IA;",
        "pid": "0",
        "rid": "43",
        "uri": "file:///C:/Users/yanzh/Desktop/play/demo/src/main/java/com/example/demo/A.java"
    }
}


[Trace - 上午10:29:32] Received response 'completionItem/resolve - (2786)' in 16ms.
Result: {
    "label": "IA()  Anonymous Inner Type",
    "kind": 4,
    "detail": "com.example.demo",
    "sortText": "999999100",
    "insertText": "IA",
    "insertTextFormat": 2,
    "textEdit": {
        "range": {
            "start": {
                "line": 7,
                "character": 8
            },
            "end": {
                "line": 7,
                "character": 10
            }
        },
        "newText": "IA(){\r\n\r\n\t@Override\r\n\tpublic void bar() {\r\n\t\t${0// TODO Auto-generated method stub\r\n\t\t}\r\n\t}\n};"
    }
}
@Eskibear
Copy link
Contributor Author

Eskibear commented Sep 9, 2019

Root cause

Missing semicolon in snippet string. In jdt.core.manipulation, a corner case is not coverred (possibly due to upstream refactoring):

  • bodyStatement is empty but bodyContent is not, because of additional auto-generated comments

See: https://github.com/eclipse/eclipse.jdt.ui/blob/c554aedb07125de381956149030d24ff23e7e4ce/org.eclipse.jdt.core.manipulation/core%20extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2Core.java#L398-L414

Solution

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