clangd / clangd

clangd language server
https://clangd.llvm.org
Apache License 2.0
1.49k stars 60 forks source link

Missing arguments of the member function implementation in `textDocument/completion` #2086

Closed ddovod closed 1 month ago

ddovod commented 2 months ago

Consider this piece of code from the header file:

class SomeClass
{
public:
    void fooMethod(int arg);
};

void fooFunction(int arg);

I'm trying to complete the implementation in the cpp file by writing the part of the member function or the free function. I'm getting different responses in textDocument/completion request in clangd-15 and clangd-16+ versions (logs and versions are provided below). The only thing I change is a symlink to clangd, everything else (editor, plugins etc) are not changed between runs. Note the insertText field, only clangd-15 gives the parameters in it, while clangd-16..18 gives only function name. And it looks fine in free function completion, while the member function completion differs and feels broken in clangd-16+.

Logs

clangd-15

{
  "isIncomplete": null,
  "items": [
    {
      "detail": "void",
      "filterText": "fooMethod",
      "insertText": "fooMethod(${1:int arg})",
      "insertTextFormat": 2,
      "kind": 2,
      "label": "fooMethod(int arg)",
      "score": 0.4090021550655365,
      "sortText": "412e9745fooMethod",
      "textEdit": {
        "newText": "fooMethod(${1:int arg})",
        "range": {
          "end": {
            "character": 16,
            "line": 21
          },
          "start": {
            "character": 16,
            "line": 21
          }
        }
      }
    }
  ]
}

{
  "isIncomplete": null,
  "items": [
    {
      "detail": "void",
      "filterText": "fooFunction",
      "insertText": "fooFunction(${1:int arg})",
      "insertTextFormat": 2,
      "kind": 3,
      "label": "fooFunction(int arg)",
      "score": 0.4580559730529785,
      "sortText": "411579b0fooFunction",
      "textEdit": {
        "newText": "fooFunction(${1:int arg})",
        "range": {
          "end": {
            "character": 8,
            "line": 21
          },
          "start": {
            "character": 5,
            "line": 21
          }
        }
      }
    }
  ]
}

clang-16..18

{
  "isIncomplete": null,
  "items": [
    {
      "detail": "void",
      "filterText": "fooMethod",
      "insertText": "fooMethod",
      "insertTextFormat": 1,
      "kind": 2,
      "label": "fooMethod(int arg)",
      "score": 0.4090021550655365,
      "sortText": "412e9745fooMethod",
      "textEdit": {
        "newText": "fooMethod",
        "range": {
          "end": {
            "character": 16,
            "line": 23
          },
          "start": {
            "character": 16,
            "line": 23
          }
        }
      }
    }
  ]
}

{
  "isIncomplete": null,
  "items": [
    {
      "detail": "void",
      "filterText": "fooFunction",
      "insertText": "fooFunction(${1:int arg})",
      "insertTextFormat": 2,
      "kind": 3,
      "label": "fooFunction(int arg)",
      "score": 0.5678196549415588,
      "sortText": "40eea35ffooFunction",
      "textEdit": {
        "newText": "fooFunction(${1:int arg})",
        "range": {
          "end": {
            "character": 8,
            "line": 21
          },
          "start": {
            "character": 5,
            "line": 21
          }
        }
      }
    }
  ]
}

System information

Output of clangd --version: Ubuntu clangd version 15.0.7 Features: linux+grpc Platform: x86_64-pc-linux-gnu

Ubuntu clangd version 16.0.6 (23ubuntu4) Features: linux+grpc Platform: x86_64-pc-linux-gnu

Ubuntu clangd version 17.0.6 (9ubuntu1) Features: linux+grpc Platform: x86_64-pc-linux-gnu

Ubuntu clangd version 18.1.8 (++20240701074744+3b5b5c1ec4a3-1~exp1~20240701194905.84) Features: linux+grpc Platform: x86_64-pc-linux-gnu

Editor/LSP plugin: emacs + emacs-lsp

Operating system: xubuntu 24.04

HighCommander4 commented 1 month ago

Duplicate of https://github.com/clangd/clangd/issues/1752