This PR significantly improves the performance of auto-completion by optimizing individual requests by a factor of ~2 and by giving language clients like VS Code the opportunity to reuse the state of previous completion requests, thus greatly reducing the latency for the auto-completion list to update when adding more characters to an identifier. In my testing: - The latency of completing `C` in a file with `import Mathlib` was reduced from ~1650ms to ~800ms - The latency of completing `Cat` in a file with `import Mathlib` was reduced from ~800ms to ~430ms - The latency of completing dot notation was mostly unaffected - Successive completions are now practically instant, e.g. if we were to complete `C` and then type it out to `Cat`, before it would take roughly ~1650ms + ~800ms, whereas now there is only a significant latency for completing `C` (~800ms) and the completion list is updated practically instantly when typing out `Cat`. <details> <summary>(Video) Auto-completion latency before this PR</summary>  </details> <details> <summary>(Video) Auto-completion latency after this PR</summary>  </details> In detail, this PR makes the following changes: - Set `isIncomplete` to `false` in non-synthetic completion responses so that the client can re-use these completion states. - Replace the server side fuzzy matching with a simple and fast check that all characters in the identifier thus far are present in the same order in the declaration to match against. There are some examples where the simple and fast check yields a completion item that the fuzzy matching would filter, but since VS Code filters the completion items with its own fuzzy matching after that anyways, these extra completion items are never actually displayed to the user. - Remove all notions of scoring and sorting completion items from the language server. We now rely entirely on the client to sort the completion items as it sees fit. In my testing, the only significant change as a result of this is that while the language server would sometimes penalize namespaces with lots of components, VS Code instead uses a strictly alphabetic order. Even before this change, we never actually really prioritized local variables over global variables, so the penalty wasn't very helpful in practice. We might add some small form of local variable prioritization in the future, though. - Remove the empty completion list hack that was introduced in #1885. It does not appear to be necessary anymore.
80 lines
2.4 KiB
Text
80 lines
2.4 KiB
Text
{"textDocument": {"uri": "file:///completionFallback.lean"},
|
|
"position": {"line": 14, "character": 14}}
|
|
{"items":
|
|
[{"label": "noConfusionType",
|
|
"kind": 3,
|
|
"data":
|
|
{"params":
|
|
{"textDocument": {"uri": "file:///completionFallback.lean"},
|
|
"position": {"line": 14, "character": 14}},
|
|
"id": {"const": {"declName": "Direction.noConfusionType"}},
|
|
"cPos": 0}},
|
|
{"label": "left",
|
|
"kind": 4,
|
|
"data":
|
|
{"params":
|
|
{"textDocument": {"uri": "file:///completionFallback.lean"},
|
|
"position": {"line": 14, "character": 14}},
|
|
"id": {"const": {"declName": "Direction.left"}},
|
|
"cPos": 0}},
|
|
{"label": "toCtorIdx",
|
|
"kind": 3,
|
|
"data":
|
|
{"params":
|
|
{"textDocument": {"uri": "file:///completionFallback.lean"},
|
|
"position": {"line": 14, "character": 14}},
|
|
"id": {"const": {"declName": "Direction.toCtorIdx"}},
|
|
"cPos": 0}},
|
|
{"label": "right",
|
|
"kind": 4,
|
|
"data":
|
|
{"params":
|
|
{"textDocument": {"uri": "file:///completionFallback.lean"},
|
|
"position": {"line": 14, "character": 14}},
|
|
"id": {"const": {"declName": "Direction.right"}},
|
|
"cPos": 0}},
|
|
{"label": "up",
|
|
"kind": 4,
|
|
"data":
|
|
{"params":
|
|
{"textDocument": {"uri": "file:///completionFallback.lean"},
|
|
"position": {"line": 14, "character": 14}},
|
|
"id": {"const": {"declName": "Direction.up"}},
|
|
"cPos": 0}},
|
|
{"label": "down",
|
|
"kind": 4,
|
|
"data":
|
|
{"params":
|
|
{"textDocument": {"uri": "file:///completionFallback.lean"},
|
|
"position": {"line": 14, "character": 14}},
|
|
"id": {"const": {"declName": "Direction.down"}},
|
|
"cPos": 0}}],
|
|
"isIncomplete": true}
|
|
{"textDocument": {"uri": "file:///completionFallback.lean"},
|
|
"position": {"line": 28, "character": 30}}
|
|
{"items":
|
|
[{"label": "mk",
|
|
"kind": 4,
|
|
"data":
|
|
{"params":
|
|
{"textDocument": {"uri": "file:///completionFallback.lean"},
|
|
"position": {"line": 28, "character": 30}},
|
|
"id": {"const": {"declName": "CustomAnd.mk"}},
|
|
"cPos": 0}},
|
|
{"label": "hb",
|
|
"kind": 23,
|
|
"data":
|
|
{"params":
|
|
{"textDocument": {"uri": "file:///completionFallback.lean"},
|
|
"position": {"line": 28, "character": 30}},
|
|
"id": {"const": {"declName": "CustomAnd.hb"}},
|
|
"cPos": 0}},
|
|
{"label": "ha",
|
|
"kind": 23,
|
|
"data":
|
|
{"params":
|
|
{"textDocument": {"uri": "file:///completionFallback.lean"},
|
|
"position": {"line": 28, "character": 30}},
|
|
"id": {"const": {"declName": "CustomAnd.ha"}},
|
|
"cPos": 0}}],
|
|
"isIncomplete": false}
|