rust-lang / rls

Repository for the Rust Language Server (aka RLS)
Other
3.51k stars 257 forks source link

Message: invalid type: map, expected a string #1430

Open akosyakov opened 5 years ago

akosyakov commented 5 years ago

Hey 👋 I'm trying to integrate vscode rust extension in Theia and hitting the issue that completionItem/resolve is failing for the following message:

{
    "jsonrpc": "2.0",
    "id": 4,
    "method": "completionItem/resolve",
    "params": [
        {
            "label": "cgroups_fs",
            "detail": "/home/gitpod/.cargo/registry/src/github.com-1ecc6299db9ec823/cgroups-fs-1.0.1/src/lib.rs",
            "documentation": {
                "kind": "markdown",
                "value": "Cgroup-fs is a minimal wrapper around Linux Control Groups (cgroups) filesystem (usually\nmounted as `/sys/fs/cgroup`).\n\n# Examples\n\n## Get memory usage from root cgroup\n\n```rust\nlet root_cgroup = cgroups_fs::CgroupName::new(\"\");\nlet root_memory_cgroup = cgroups_fs::Cgroup::new(&root_cgroup, \"memory\");\nprintln!(\n    \"Current memory usage is {} bytes\",\n    root_memory_cgroup.get_value::<u64>(\"memory.usage_in_bytes\").unwrap()\n);\n```\n\n## Measure memory usage of a child process\n\nRead [the `CgroupsCommandExt` documentation].\n\n[the `CgroupsCommandExt` documentation]: trait.CgroupsCommandExt.html#impl-CgroupsCommandExt"
            },
            "insertTextFormat": 2,
            "insertText": "cgroups_fs",
            "kind": 9
        },
        null
    ]
}

Could someone get a hint what is wrong with a message?

alexheretic commented 5 years ago

Check the LSP spec https://github.com/Microsoft/language-server-protocol/blob/gh-pages/specification.md#completionItem_resolve, does your message look valid?

Construct a test case to figure it out, serde spits out line/column numbers this way:

// lsp-types = "0.57"
// serde_json = "1"
// serde = { version = "1", features = ["derive"] }

const MSG: &str = r#"{
  "jsonrpc": "2.0",
  "id": 4,
  "method": "completionItem/resolve",
  "params": [{
    "label": "cgroups_fs",
    "detail": "/home/gitpod/.cargo/registry/src/github.com-1ecc6299db9ec823/cgroups-fs-1.0.1/src/lib.rs",
    "documentation": {
      "kind": "markdown",
      "value": "Cgroup-fs is a minimal wrapper around Linux Control Groups (cgroups) filesystem (usually\nmounted as `/sys/fs/cgroup`).\n\n# Examples\n\n## Get memory usage from root cgroup\n\n```rust\nlet root_cgroup = cgroups_fs::CgroupName::new(\"\");\nlet root_memory_cgroup = cgroups_fs::Cgroup::new(&root_cgroup, \"memory\");\nprintln!(\n    \"Current memory usage is {} bytes\",\n    root_memory_cgroup.get_value::<u64>(\"memory.usage_in_bytes\").unwrap()\n);\n```\n\n## Measure memory usage of a child process\n\nRead [the `CgroupsCommandExt` documentation].\n\n[the `CgroupsCommandExt` documentation]: trait.CgroupsCommandExt.html#impl-CgroupsCommandExt"
    },
    "insertTextFormat": 2,
    "insertText": "cgroups_fs",
    "kind": 9
}, null]
}"#;

fn main() -> Result<(), Box<serde_json::Error>> {
    let request: Request<lsp_types::CompletionItem> = serde_json::from_str(MSG)?;
    assert_eq!(request.params.label, "cgroups_fs");
    Ok(())
}

#[derive(serde::Deserialize)]
struct Request<P> {
    params: P,
}

Perhaps a params array with the 2nd item null isn't what's needed here.