{"record":{"id":"32361fca84e2e04d","repo":"Hmbown/CodeWhale","slug":"lsp-server-must-use-utf-16-positions","errorCode":null,"errorMessage":"LSP server must use UTF-16 positions","messagePattern":"LSP server must use UTF-16 positions","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/lsp/client.rs","lineNumber":296,"sourceCode":"            \"rootUri\": uri_from_path(&workspace),\n            \"capabilities\": {\n                \"general\": { \"positionEncodings\": [\"utf-16\"] },\n                \"textDocument\": {\n                    \"publishDiagnostics\": { \"relatedInformation\": false, \"versionSupport\": true }\n                }\n            },\n            \"workspaceFolders\": [{\"uri\": uri_from_path(&workspace), \"name\": \"workspace\"}]\n        }), initialize_wait).await.context(\"LSP initialization failed\")?;\n        if !result.get(\"capabilities\").is_some_and(Value::is_object) {\n            return Err(anyhow!(\n                \"LSP initialize response is missing server capabilities\"\n            ));\n        }\n        if result\n            .pointer(\"/capabilities/positionEncoding\")\n            .is_some_and(|encoding| encoding.as_str() != Some(\"utf-16\"))\n        {\n            return Err(anyhow!(\"LSP server must use UTF-16 positions\"));\n        }\n        timeout(\n            initialize_wait,\n            send_message(\n                &transport.tx_outbound,\n                &json!({\n                    \"jsonrpc\": \"2.0\", \"method\": \"initialized\", \"params\": {}\n                }),\n            ),\n        )\n        .await\n        .map_err(|_| anyhow!(\"LSP initialized notification timed out\"))??;\n        Ok(transport)\n    }\n}\n\nimpl Drop for StdioLspTransport {\n    fn drop(&mut self) {","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/lsp/client.rs#L278-L314","documentation":"The client requires UTF-16 (LSP default) position encoding. If the server advertises a `capabilities.positionEncoding` other than \"utf-16\", offsets computed by the client would disagree with the server's, so spawn fails rather than corrupt positions.","triggerScenarios":"Server negotiates `positionEncoding` to \"utf-8\" or \"utf-32\" in its initialize response while the client only speaks utf-16.","commonSituations":"Newer servers (LSP 3.17+) supporting utf-8 encodings; misconfigured client capabilities requesting a non-utf-16 encoding; custom/specialty servers.","solutions":["Request only utf-16 in client capabilities during initialize","Reject or restart with a server that keeps default utf-16 encoding","Implement utf-8/utf-32 offset conversion if you must support such servers"],"exampleFix":"// before\n\"capabilities\": {\"general\": {\"positionEncodings\": [\"utf-8\", \"utf-16\"]}}\n// after\n\"capabilities\": {\"general\": {\"positionEncodings\": [\"utf-16\"]}}","handlingStrategy":"validation","validationCode":"const enc = caps?.general?.positionEncodings ?? ['utf-16'];\nif (!enc.includes('utf-16')) throw new Error('server does not support utf-16 positions');","typeGuard":"fn supports_utf16(v: &Value) -> bool {\n    match v.pointer(\"/capabilities/positionEncoding\") {\n        None => true,\n        Some(e) => e.as_str() == Some(\"utf-16\"),\n    }\n}","tryCatchPattern":"match spawn_with_timeout(...).await {\n    Err(e) if e.to_string().contains(\"UTF-16\") => {\n        eprintln!(\"configure server for utf-16 or pick a compatible server\");\n    }\n    other => other,\n}","preventionTips":["Advertise only utf-16 in client capabilities","Check server docs for positionEncoding support before adopting it","Add an offset-conversion layer only if non-utf-16 servers must be supported"],"tags":["lsp","utf-16","position-encoding"],"backgroundTag":"incompatible-source-type","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}