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

Completions that are effectively code-generated overrides aren't inserted properly #685

Open
SCWells72 opened this issue Dec 11, 2024 · 3 comments

Comments

@SCWells72
Copy link
Contributor

Some LSP-provided completions are intended to behave as code generation, e.g., implementing/overriding a method from an interface/base class. When I accepted such a completion, it resulted in invalid code, e.g., HTMLElement.click() in JavaScript/TypeScript which results in:

click(): void {
    $0
\}()

Here's a demonstration of the issue:

Image

It looks like it's just a current limited handling of templatized completion results.

@angelozerr
Copy link
Contributor

Are you sure this completion comes from language server and not from IJ himself?

Could you check in lsp completion returns this click snippet.

@angelozerr
Copy link
Contributor

If it comes from language server, could yiu copy paste the lsp response in the issue please.

@SCWells72
Copy link
Contributor Author

Yes, it's coming from the TypeScript language server. Here's the response to textDocument/completion (retaining only the relevant completion):

{
  "isIncomplete": false,
  "items": [
    {
      "label": "click",
      "kind": 2,
      "sortText": "11",
      "filterText": "click(): void {\n    $0\n}",
      "insertText": "click(): void {\n    $0\n}",
      "insertTextFormat": 2,
      "data": {
        "cacheId": 87
      }
    }
  ]
}

and here's the request/response for completionItem/resolve for that completion:

Request

{
  "label": "click",
  "kind": 2,
  "sortText": "11",
  "filterText": "click(): void {\n    $0\n}",
  "insertText": "click(): void {\n    $0\n}",
  "insertTextFormat": 2,
  "data": {
    "cacheId": 87
  }
}

Response

{
  "label": "click",
  "kind": 2,
  "detail": "(method) HTMLElement.click(): void",
  "documentation": {
    "kind": "markdown",
    "value": "Called when the element is inserted in a document"
  },
  "sortText": "11",
  "filterText": "click(): void {\n    $0\n}",
  "insertText": "click(): void {\n    \\$0\n\\}()$0",
  "insertTextFormat": 2,
  "data": {
    "file": "/path/to/sourceFile.ts",
    "line": 41,
    "offset": 9,
    "entryNames": [
      "click"
    ]
  }
}

To be honest, the insertText from the detailed response looks suspicious to me since it would have parentheses after the method body close brace. I'm not sure what "insertTextFormat": 2 implies either, but presumably some type of guidance on how to process the "template" from the insert text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants