autozimu / LanguageClient-neovim

Language Server Protocol (LSP) support for vim and neovim.
MIT License
3.55k stars 273 forks source link

Go to definition doesn't work (Vim8, Rust) on stdlib #328

Closed vimpunk closed 6 years ago

vimpunk commented 6 years ago

Hey, great idea generalizing the language server protocol. I'd love to migrate from ALE to this but unfortunately I'm having some problems.

Plug 'autozimu/LanguageClient-neovim', { \ 'branch': 'next', \ 'do': 'bash install.sh', \ }

call plug#end()

augroup filetype_rust autocmd! autocmd BufReadPost *.rs setlocal filetype=rust augroup END

let g:LanguageClient_serverCommands = { \ 'rust': ['rustup', 'run', 'stable', 'rls'], \ } let g:LanguageClient_loggingLevel = 'DEBUG'

I tried to issue :call LanguageClient_textDocument_definition() on std::collections::HashMap. e.g.:
```rust
use std::collections::HashMap;

fn main() {
    let map: HashMap<i32, i32> = HashMap::new();
    println!("{}", map.is_empty());
}

The expected result was to see the source file but instead I got an empty buffer with the path /checkout/src/libstd/collections/hash/map.rs, which of course doesn't exist. The logs confirm that this is the returned path for locating the target of the GoTo command. This is pretty strange as rls has been working fine under ALE, and otherwise with this plugin as well, as diagnostics and hover (the only ones I've tried so far) seem to be working fine.

The LanguageServer.log file was empty, so here's the LanguageClient.log file:


2018-03-09T01:36:12.499449320+01:00 DEBUG languageclient::vim - state.id: 4 ==> 5
2018-03-09T01:36:12.499650157+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"eval","params":["[!!get(g:, 'LanguageClient_diagnosticsEnable', v:true), get(g:, 'LanguageClient_diagnosticsList', 'Quickfix'), get(g:, 'LanguageClient_diagnosticsDisplay', {}), get(g:, 'LanguageClient_windowLogMessageLevel', 'Warning')]"],"id":5}
2018-03-09T01:36:12.500207764+01:00 INFO languageclient::vim - <= {"id":5,"jsonrpc":"2.0","result":[1,"Quickfix",{},"Warning"]}
2018-03-09T01:36:12.500667290+01:00 DEBUG languageclient::vim - state.selectionUI: "LocationList" ==> "FZF"
2018-03-09T01:36:12.500685066+01:00 DEBUG languageclient::vim - state.loadSettings: false ==> true
2018-03-09T01:36:12.500694017+01:00 DEBUG languageclient::vim - state.serverCommands.rust: null ==> ["rustup","run","stable","rls"]
2018-03-09T01:36:12.501438605+01:00 DEBUG languageclient::vim - state.child_ids.rust: null ==> 7571
2018-03-09T01:36:12.501515253+01:00 INFO languageclient::languageclient - End languageClient/startServer
2018-03-09T01:36:12.501530989+01:00 INFO languageclient::languageclient - Define signs
2018-03-09T01:36:12.501558674+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"execute","params":["echo | execute 'sign define LanguageClientWarning text=⚠ texthl=ALEWarningSign' | execute 'sign define LanguageClientHint text=➤ texthl=ALEInfoSign' | execute 'sign define LanguageClientInformation text=ℹ texthl=ALEInfoSign' | execute 'sign define LanguageClientError text=✖ texthl=ALEErrorSign'"]}
2018-03-09T01:36:12.501586152+01:00 INFO languageclient::languageclient - Define signs
2018-03-09T01:36:12.501604953+01:00 INFO languageclient::languageclient - Begin initialize
2018-03-09T01:36:12.501621723+01:00 INFO languageclient::languageclient - gather_args: [LanguageId, Filename] = [String("rust"), String("/home/mandreyel/code/scratchpad/rust-playground/src/main.rs")]
2018-03-09T01:36:12.501639749+01:00 INFO languageclient::languageclient - Some arguments are not available. Requesting from vim. Keys: ["rootPath", "hasSnippetSupport"]. Exps: ["v:null", "s:hasSnippetSupport()"]
2018-03-09T01:36:12.501748847+01:00 DEBUG languageclient::vim - state.id: 5 ==> 6
2018-03-09T01:36:12.501843424+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"eval","params":["[v:null, s:hasSnippetSupport()]"],"id":6}
2018-03-09T01:36:12.503481188+01:00 INFO languageclient::vim - <= {"id":6,"jsonrpc":"2.0","result":[null,0]}
2018-03-09T01:36:12.503772879+01:00 INFO languageclient::languageclient - gather_args: [("rootPath", "v:null"), ("hasSnippetSupport", "s:hasSnippetSupport()")] = [Null, Number(0)]
2018-03-09T01:36:12.503836472+01:00 INFO languageclient::languageclient - Project root: /home/mandreyel/code/scratchpad/rust-playground
2018-03-09T01:36:12.504000044+01:00 DEBUG languageclient::vim - state.roots.rust: null ==> "/home/mandreyel/code/scratchpad/rust-playground"
2018-03-09T01:36:12.504032006+01:00 DEBUG languageclient::languageclient - Project settings: {}
2018-03-09T01:36:12.504040887+01:00 DEBUG languageclient::languageclient - Project settings.initializationOptions: null
2018-03-09T01:36:12.504212357+01:00 DEBUG languageclient::vim - state.id: 6 ==> 7
2018-03-09T01:36:12.504389566+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"completion":{"completionItem":{"commitCharactersSupport":null,"documentationFormat":null,"snippetSupport":false},"dynamicRegistration":null}}},"initializationOptions":null,"processId":7562,"rootPath":"/home/mandreyel/code/scratchpad/rust-playground","rootUri":"file:///home/mandreyel/code/scratchpad/rust-playground","trace":"off"},"id":7}
2018-03-09T01:36:12.607772137+01:00 INFO languageclient::vim - <= {"jsonrpc":"2.0","id":7,"result":{"capabilities":{"textDocumentSync":2,"hoverProvider":true,"completionProvider":{"resolveProvider":true,"triggerCharacters":[".",":"]},"definitionProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"workspaceSymbolProvider":true,"codeActionProvider":true,"documentFormattingProvider":true,"documentRangeFormattingProvider":false,"renameProvider":true,"executeCommandProvider":{"commands":["rls.applySuggestion","rls.deglobImports"]}}}}
2018-03-09T01:36:12.607877533+01:00 INFO languageclient::vim - <= {"jsonrpc":"2.0","method":"rustDocument/beginBuild","params":null}
2018-03-09T01:36:12.608131051+01:00 INFO languageclient::languageclient - Begin rustDocument/beginBuild
2018-03-09T01:36:12.608219418+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"execute","params":["let g:LanguageClient_serverStatus=1 | let g:LanguageClient_serverStatusMessage='Rust: build begin'"]}
2018-03-09T01:36:12.608257538+01:00 INFO languageclient::languageclient - End rustDocument/beginBuild
2018-03-09T01:36:12.608690958+01:00 DEBUG languageclient::vim - state.capabilities.rust: null ==> {"capabilities":{"codeActionProvider":true,"completionProvider":{"resolveProvider":true,"triggerCharacters":[".",":"]},"definitionProvider":true,"documentFormattingProvider":true,"documentHighlightProvider":true,"documentRangeFormattingProvider":false,"documentSymbolProvider":true,"executeCommandProvider":{"commands":["rls.applySuggestion","rls.deglobImports"]},"hoverProvider":true,"referencesProvider":true,"renameProvider":true,"textDocumentSync":2,"workspaceSymbolProvider":true}}
2018-03-09T01:36:12.608757030+01:00 INFO languageclient::languageclient - End initialize
2018-03-09T01:36:12.608772330+01:00 INFO languageclient::languageclient - Begin register NCM source
2018-03-09T01:36:12.609098310+01:00 DEBUG languageclient::vim - state.id: 7 ==> 8
2018-03-09T01:36:12.609507036+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"eval","params":["exists('g:cm_matcher')"],"id":8}
2018-03-09T01:36:12.610425911+01:00 INFO languageclient::vim - <= {"id":8,"jsonrpc":"2.0","result":0}
2018-03-09T01:36:12.611119431+01:00 INFO languageclient::languageclient - Begin textDocument/didOpen
2018-03-09T01:36:12.611174698+01:00 INFO languageclient::languageclient - Some arguments are not available. Requesting from vim. Keys: ["text"]. Exps: ["getbufline(\'\', 1, \'$\')"]
2018-03-09T01:36:12.611530879+01:00 DEBUG languageclient::vim - state.id: 8 ==> 9
2018-03-09T01:36:12.611906681+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"eval","params":["[getbufline('', 1, '$')]"],"id":9}
2018-03-09T01:36:12.612601889+01:00 INFO languageclient::vim - <= {"id":9,"jsonrpc":"2.0","result":[["use std::collections::HashMap;","","fn main() {","    let map: HashMap<i32, i32> = HashMap::new();","    println!(\"{}\", map.is_empty());","}"]]}
2018-03-09T01:36:12.613133099+01:00 INFO languageclient::languageclient - gather_args: [Buftype, LanguageId, Filename, Text] = [String(""), String("rust"), String("/home/mandreyel/code/scratchpad/rust-playground/src/main.rs"), Array([String("use std::collections::HashMap;"), String(""), String("fn main() {"), String("    let map: HashMap<i32, i32> = HashMap::new();"), String("    println!(\"{}\", map.is_empty());"), String("}")])]
2018-03-09T01:36:12.613617147+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"rust","text":"use std::collections::HashMap;\n\nfn main() {\n    let map: HashMap<i32, i32> = HashMap::new();\n    println!(\"{}\", map.is_empty());\n}","uri":"file:///home/mandreyel/code/scratchpad/rust-playground/src/main.rs","version":0}}}
2018-03-09T01:36:12.613950708+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"execute","params":["setlocal omnifunc=LanguageClient#complete"]}
2018-03-09T01:36:12.613985428+01:00 INFO languageclient::languageclient - End textDocument/didOpen
2018-03-09T01:36:12.614003465+01:00 INFO languageclient::languageclient - Begin textDocument/didChange
2018-03-09T01:36:12.614023100+01:00 INFO languageclient::languageclient - gather_args: [Buftype, LanguageId, Filename] = [String(""), String("rust"), String("/home/mandreyel/code/scratchpad/rust-playground/src/main.rs")]
2018-03-09T01:36:12.614058816+01:00 INFO languageclient::languageclient - Some arguments are not available. Requesting from vim. Keys: ["text"]. Exps: ["getbufline(\'\', 1, \'$\')"]
2018-03-09T01:36:12.614321109+01:00 DEBUG languageclient::vim - state.id: 9 ==> 10
2018-03-09T01:36:12.614582437+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"eval","params":["[getbufline('', 1, '$')]"],"id":10}
2018-03-09T01:36:12.615287865+01:00 INFO languageclient::vim - <= {"id":10,"jsonrpc":"2.0","result":[["use std::collections::HashMap;","","fn main() {","    let map: HashMap<i32, i32> = HashMap::new();","    println!(\"{}\", map.is_empty());","}"]]}
2018-03-09T01:36:12.615803329+01:00 INFO languageclient::languageclient - gather_args: [Text] = [Array([String("use std::collections::HashMap;"), String(""), String("fn main() {"), String("    let map: HashMap<i32, i32> = HashMap::new();"), String("    println!(\"{}\", map.is_empty());"), String("}")])]
2018-03-09T01:36:12.615862242+01:00 INFO languageclient::languageclient - Texts equal. Skipping didChange.
2018-03-09T01:36:12.616225096+01:00 DEBUG languageclient::vim - state.id: 10 ==> 11
2018-03-09T01:36:12.616575838+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"eval","params":["exists('#User#LanguageClientStarted')"],"id":11}
2018-03-09T01:36:12.617245546+01:00 INFO languageclient::vim - <= {"id":11,"jsonrpc":"2.0","result":0}
2018-03-09T01:36:12.617717163+01:00 INFO languageclient::languageclient - End languageClient/handleBufReadPost
2018-03-09T01:36:12.937198288+01:00 INFO languageclient::vim - <= {"jsonrpc":"2.0","method":"rustDocument/diagnosticsBegin","params":null}
2018-03-09T01:36:12.937413199+01:00 INFO languageclient::languageclient - Begin rustDocument/diagnosticsBegin
2018-03-09T01:36:12.937436896+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"execute","params":["let g:LanguageClient_serverStatus=1 | let g:LanguageClient_serverStatusMessage='Rust: diagnostics begin'"]}
2018-03-09T01:36:12.937456487+01:00 INFO languageclient::languageclient - End rustDocument/diagnosticsBegin
2018-03-09T01:36:13.214328825+01:00 INFO languageclient::vim - <= {"jsonrpc":"2.0","method":"rustDocument/diagnosticsEnd","params":null}
2018-03-09T01:36:13.214461955+01:00 INFO languageclient::languageclient - Begin rustDocument/diagnosticsEnd
2018-03-09T01:36:13.214495223+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"execute","params":["let g:LanguageClient_serverStatus=0 | let g:LanguageClient_serverStatusMessage='Rust: diagnostics end'"]}
2018-03-09T01:36:13.214521626+01:00 INFO languageclient::languageclient - End rustDocument/diagnosticsEnd
2018-03-09T01:36:13.303188183+01:00 INFO languageclient::vim - <= {"method":"languageClient/handleCursorMoved","jsonrpc":"2.0","params":{"filename":"/home/mandreyel/code/scratchpad/rust-playground/src/main.rs","line":1,"buftype":""}}
2018-03-09T01:36:13.303563737+01:00 INFO languageclient::languageclient - Begin languageClient/handleCursorMoved
2018-03-09T01:36:13.303603064+01:00 INFO languageclient::languageclient - gather_args: [Buftype, Filename, Line] = [String(""), String("/home/mandreyel/code/scratchpad/rust-playground/src/main.rs"), Number(1)]
2018-03-09T01:36:13.304263031+01:00 DEBUG languageclient::vim - state.last_cursor_line: 0 ==> 1
2018-03-09T01:36:13.304751085+01:00 DEBUG languageclient::vim - state.last_line_diagnostic: " " ==> ""
2018-03-09T01:36:13.305216329+01:00 DEBUG languageclient::vim - state.id: 11 ==> 12
2018-03-09T01:36:13.305680957+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"eval","params":["&columns"],"id":12}
2018-03-09T01:36:13.307454111+01:00 INFO languageclient::vim - <= {"id":12,"jsonrpc":"2.0","result":149}
2018-03-09T01:36:13.308402253+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"execute","params":["echo ''"]}
2018-03-09T01:36:13.308491457+01:00 INFO languageclient::languageclient - End languageClient/handleCursorMoved
2018-03-09T01:36:13.501233429+01:00 INFO languageclient::vim - <= {"method":"languageClient/handleCursorMoved","jsonrpc":"2.0","params":{"filename":"/home/mandreyel/code/scratchpad/rust-playground/src/main.rs","line":2,"buftype":""}}
2018-03-09T01:36:13.501716246+01:00 INFO languageclient::languageclient - Begin languageClient/handleCursorMoved
2018-03-09T01:36:13.501766595+01:00 INFO languageclient::languageclient - gather_args: [Buftype, Filename, Line] = [String(""), String("/home/mandreyel/code/scratchpad/rust-playground/src/main.rs"), Number(2)]
2018-03-09T01:36:13.502424564+01:00 DEBUG languageclient::vim - state.last_cursor_line: 1 ==> 2
2018-03-09T01:36:13.667208671+01:00 INFO languageclient::vim - <= {"method":"languageClient/handleCursorMoved","jsonrpc":"2.0","params":{"filename":"/home/mandreyel/code/scratchpad/rust-playground/src/main.rs","line":3,"buftype":""}}
2018-03-09T01:36:13.667575401+01:00 INFO languageclient::languageclient - Begin languageClient/handleCursorMoved
2018-03-09T01:36:13.667612867+01:00 INFO languageclient::languageclient - gather_args: [Buftype, Filename, Line] = [String(""), String("/home/mandreyel/code/scratchpad/rust-playground/src/main.rs"), Number(3)]
2018-03-09T01:36:13.668249282+01:00 DEBUG languageclient::vim - state.last_cursor_line: 2 ==> 3
2018-03-09T01:36:16.660855225+01:00 INFO languageclient::vim - <= {"id":1,"jsonrpc":"2.0","method":"textDocument/definition","params":{"gotoCmd":null,"character":13,"handle":true,"languageId":"rust","line":3,"buftype":"","filename":"/home/mandreyel/code/scratchpad/rust-playground/src/main.rs"}}
2018-03-09T01:36:16.661310853+01:00 INFO languageclient::languageclient - Begin textDocument/definition
2018-03-09T01:36:16.661382456+01:00 INFO languageclient::languageclient - gather_args: [Buftype, LanguageId, Filename, Line, Character, GotoCmd, Handle] = [String(""), String("rust"), String("/home/mandreyel/code/scratchpad/rust-playground/src/main.rs"), Number(3), Number(13), Null, Bool(true)]
2018-03-09T01:36:16.661982267+01:00 DEBUG languageclient::vim - state.id: 12 ==> 13
2018-03-09T01:36:16.662514083+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"textDocument/definition","params":{"position":{"character":13,"line":3},"textDocument":{"uri":"file:///home/mandreyel/code/scratchpad/rust-playground/src/main.rs"}},"id":13}
2018-03-09T01:36:16.664061454+01:00 INFO languageclient::vim - <= {"jsonrpc":"2.0","id":13,"result":[{"uri":"file:///checkout/src/libstd/collections/hash/map.rs","range":{"start":{"line":390,"character":11},"end":{"line":390,"character":18}}}]}
2018-03-09T01:36:16.665705398+01:00 DEBUG languageclient::vim - state.id: 13 ==> 14
2018-03-09T01:36:16.666222612+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"eval","params":["bufnr('/checkout/src/libstd/collections/hash/map.rs')"],"id":14}
2018-03-09T01:36:16.668366754+01:00 INFO languageclient::vim - <= {"id":14,"jsonrpc":"2.0","result":-1}
2018-03-09T01:36:16.669276897+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","method":"execute","params":["echo | execute 'edit +:call\\ cursor(391,12) ' . fnameescape('/checkout/src/libstd/collections/hash/map.rs')"]}
2018-03-09T01:36:16.669353501+01:00 INFO languageclient::languageclient - End textDocument/definition
2018-03-09T01:36:16.669396892+01:00 INFO languageclient::vim - => {"jsonrpc":"2.0","result":[{"range":{"end":{"character":18,"line":390},"start":{"character":11,"line":390}},"uri":"file:///checkout/src/libstd/collections/hash/map.rs"}],"id":1}
autozimu commented 6 years ago

This is a somewhat language server issue.

The path is probably the best result rls can come up with in this case. There is a similar issue created on rls side, but without obvious solution. https://github.com/rust-lang-nursery/rls/issues/227

vimpunk commented 6 years ago

Hmm, I see, thanks for your response and for pointing me to the rls issue, I should have looked there too.