LSPのcompletionのメモ その2

この前のLSPのcompletionに関するメモのつづき。

masahino123.hatenablog.com

別のサーバだと、そもそも挙動が異なるという話。

なにか正解があるのか、実装依存なのか、手元の環境の問題なのか、設定によるものなのか、 分らないけど。

typescript-language-server

github.com

3.3.1というバージョン。

1エントリ分を以下に。新規ファイルにpとだけ入力したときの最初の項目。

{
    "label": "__dirname",
    "kind": 6,
    "sortText": "15",
    "data": {
        "file": "/Users/masahino/Program/mrbmacs/mruby/test.js",
        "line": 1,
        "offset": 2,
        "entryNames": [
            "__dirname"
        ]
    },
    "textEdit": {
        "newText": "__dirname",
        "insert": {
            "start": {
                "line": 0,
                "character": 0
            },
            "end": {
                "line": 0,
                "character": 1
            }
        },
        "replace": {
            "start": {
                "line": 0,
                "character": 0
            },
            "end": {
                "line": 0,
                "character": 1
            }
        }
    }
}

入力したpとは関係なさそうな候補が入っていた。 回答内容の形式は、textEditによる編集で、detailとかは無い。

全部で915個の補完候補が返ってきた。多すぎ。

続けて、prと入力を進めても同じ候補が返ってきたので、どうやらそういう挙動らしい。 前回試したいくつかのサーバだと、そこまでに入力した文字に関係する候補が返ってきたのだが・・・

なにか、設定やオプションで挙動を変えられるのかと、いろいろ試してみたものの、変わらず。

これは、クライアント側で絞れということなのだろうか。

rust-analyer

rust-analyzer 0.0.0 (b99d5eb97 2023-03-26)

{
    "label": "self::",
    "kind": 14,
    "deprecated": false,
    "preselect": true,
    "sortText": "ffffffef",
    "filterText": "self::",
    "textEdit": {
        "newText": "self::",
        "insert": {
            "start": {
                "line": 6,
                "character": 0
            },
            "end": {
                "line": 6,
                "character": 1
            }
        },
        "replace": {
            "start": {
                "line": 6,
                "character": 0
            },
            "end": {
                "line": 6,
                "character": 1
            }
        }
    },
    "additionalTextEdits": []
}

deprecatedとかpreselectとかfilterTextとか情報が多い。 textEditの中身が、rangeではなくinsertreplaceが使われている。 と思ったら、ClientCapabilitiesinsertReplaceSupporttrueとしていたからだった。falseにしてみると、rangeで指定されてきた。

別の項目にはdocumentationもあった。

{
    "label": "Ordering",
    "kind": 13,
    "documentation": {
        "kind": "markdown",
        "value": "An `Ordering` is the result of a comparison between two values.\n\n# Examples\n\n```rust\nuse std::cmp::Ordering;\n\nlet result = 1.cmp(&2);\nassert_eq!(Ordering::Less, result);\n\nlet result = 1.cmp(&1);\nassert_eq!(Ordering::Equal, result);\n\nlet result = 2.cmp(&1);\nassert_eq!(Ordering::Greater, result);\n```"
    },
    "deprecated": false,
    "preselect": true,
    "sortText": "ffffffef",
    "filterText": "Ordering",
    "textEdit": {
        "newText": "Ordering",
        "insert": {
            "start": {
                "line": 6,
                "character": 0
            },
            "end": {
                "line": 6,
                "character": 1
            }
        },
        "replace": {
            "start": {
                "line": 6,
                "character": 0
            },
            "end": {
                "line": 6,
                "character": 1
            }
        }
    },
    "additionalTextEdits": []
}

設定やオプションはまだ見ていないが、こちらもクライアント側で候補を絞り込んで表示しないと駄目なのかな。