metals icon indicating copy to clipboard operation
metals copied to clipboard

Integral goes before Int in completion

Open kurnevsky opened this issue 2 years ago • 4 comments

Describe the bug

It seems vscode applies its own ordering in completion but it might affect other editors (i.e. emacs). When you write def f(x: Int) you get the following completion response for Int:

[Trace - 05:28:07 PM] Received response 'textDocument/completion - (1503)' in 72ms.
Result: {
  "isIncomplete": true,
  "items": [
    {
      "label": "Integral scala.math",
      "kind": 9,
      "detail": " scala.math",
      "preselect": true,
      "sortText": "00000",
      "filterText": "Integral",
      "insertTextFormat": 2,
      "textEdit": {
        "range": {
          "start": {
            "line": 11,
            "character": 69
          },
          "end": {
            "line": 11,
            "character": 72
          }
        },
        "newText": "Integral"
      },
      "data": {
        "symbol": "scala/package.Integral.",
        "target": "file:..."
      }
    },
    {
      "label": "BigInt scala.math",
      "kind": 9,
      "detail": " scala.math",
      "sortText": "00001",
      "filterText": "BigInt",
      "insertTextFormat": 2,
      "textEdit": {
        "range": {
          "start": {
            "line": 11,
            "character": 69
          },
          "end": {
            "line": 11,
            "character": 72
          }
        },
        "newText": "BigInt"
      },
      "data": {
        "symbol": "scala/package.BigInt.",
        "target": "file:..."
      }
    },
    {
      "label": "Int scala",
      "kind": 9,
      "detail": " scala",
      "sortText": "00002",
      "filterText": "Int",
      "insertTextFormat": 2,
      "textEdit": {
        "range": {
          "start": {
            "line": 11,
            "character": 69
          },
          "end": {
            "line": 11,
            "character": 72
          }
        },
        "newText": "Int"
      },
      "data": {
        "symbol": "scala/Int.",
        "target": "file:..."
      }
    },

Integral has sortText 00000 and Int 00002.

Expected behavior

Int is prioritized over Integer.

Operating system

Linux

Editor/Extension

Emacs (lsp-metals)

Version of Metals

0.11.6

Extra context or search terms

emacs completion ordering

kurnevsky avatar Jun 22 '22 14:06 kurnevsky

Thanks for reporting! That's a definitely an ordering bug

dos65 avatar Jun 22 '22 15:06 dos65

I dug into it a bit and it seems that Int is showing up later because the symbol that we get is actually an Int object and BigInt is a field. We prioritize fields which is causing this issue. I tried to fix it in:

https://github.com/scalameta/metals/compare/main...tgodzik:fix-int?expand=1

but I am not sure about this fix :/

tgodzik avatar Jun 23 '22 18:06 tgodzik

If sorting in vscode is good enough, then probably we can just replicate it on metals side? :)

kurnevsky avatar Jun 24 '22 08:06 kurnevsky

@tgodzik oh, I got what are you about. Maybe we can try to fix by it keeping a symbol in filterInteresting that has a less relevance?

dos65 avatar Jun 24 '22 09:06 dos65