vscode_erlang icon indicating copy to clipboard operation
vscode_erlang copied to clipboard

LSP handler error error:badarg while executing lsp_handlers:initialize

Open cliesens27 opened this issue 5 years ago • 2 comments

output

erlang extension is active starting : escript.exe c:\Users\clies.vscode\extensions\pgourlain.erlang-0.6.5\rebar3 compile ===> Verifying dependencies... ===> Compiling vscode_lsp escript.exe exit code:0 starting : erl -noshell -pa src -pa ebin -s int -vscode_port 50546 -s vscode_lsp_entry start 50546 Old inliner: threshold=0 functions=[{hex,1}] Old inliner: threshold=0 functions=[{object_key,2}] =ERROR REPORT==== 3-Sep-2020::18:53:51.272000 === LSP handler error error:badarg while executing lsp_handlers:initialize(_, #{capabilities => #{textDocument => #{codeAction => #{codeActionLiteralSupport => #{codeActionKind => #{valueSet => [<<>>, <<"quickfix">>, <<"refactor">>, <<"refactor.extract">>, <<"refactor.inline">>, <<"refactor.rewrite">>, <<"source">>, <<"source.organizeImports">>]}}, dynamicRegistration => true}, codeLens => #{dynamicRegistration => true}, colorProvider => #{dynamicRegistration => true}, completion => #{completionItem => #{commitCharactersSupport => true, deprecatedSupport => true, documentationFormat => [<<"markdown">>, <<"plaintext">>], preselectSupport => true, snippetSupport => true}, completionItemKind => #{valueSet => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]}, contextSupport => true, dynamicRegistration => true}, definition => #{dynamicRegistration => true}, documentHighlight => #{dynamicRegistration => true}, documentLink => #{dynamicRegistration => true}, documentSymbol => #{dynamicRegistration => true, hierarchicalDocumentSymbolSupport => true, symbolKind => #{valueSet => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]}}, foldingRange => #{dynamicRegistration => true, lineFoldingOnly => true, rangeLimit => 5000}, formatting => #{dynamicRegistration => true}, hover => #{contentFormat => [<<"markdown">>, <<"plaintext">>], dynamicRegistration => true}, implementation => #{dynamicRegistration => true}, onTypeFormatting => #{dynamicRegistration => true}, publishDiagnostics => #{relatedInformation => true}, rangeFormatting => #{dynamicRegistration => true}, references => #{dynamicRegistration => true}, rename => #{dynamicRegistration => true}, signatureHelp => #{dynamicRegistration => true, signatureInformation => #{documentationFormat => [<<"markdown">>, <<"plaintext">>]}}, synchronization => #{didSave => true, dynamicRegistration => true, willSave => true, willSaveWaitUntil => true}, typeDefinition => #{dynamicRegistration => true}}, workspace => #{applyEdit => true, configuration => true, didChangeConfiguration => #{dynamicRegistration => true}, didChangeWatchedFiles => #{dynamicRegistration => true}, executeCommand => #{dynamicRegistration => true}, symbol => #{dynamicRegistration => true, symbolKind => #{valueSet => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]}}, workspaceEdit => #{documentChanges => true}, workspaceFolders => true}}, processId => 9720, rootPath => null, rootUri => null, trace => <<"off">>, workspaceFolders => null}), stacktrace:[{erlang, binary_to_list, [null], []}, {lsp_handlers, initialize, 2, [{file, "src/lsp_handlers.erl"}, {line, 10}]}, {gen_lsp_server, safeApply, 3, [{file, "src/gen_lsp_server.erl"}, {line, 26}]}, {gen_lsp_server, do_contents, 2, [{file, "src/gen_lsp_server.erl"}, {line, 104}]}]


I'm on Windows 10, I haven't changed any of the settings, and have erl.exe and escript.exe in my path. This happens whenever I open an .erl file in VS Code.

I've tried a few fixes, but nothing has worked so far (uninstalled/reinstalled multiple times, restarted... also from https://github.com/pgourlain/vscode_erlang/issues/97 since the error seemed somewhat similar).

Thanks for making this extension, and thanks for any help you might be able to provide.

cliesens27 avatar Sep 03 '20 16:09 cliesens27

Hello,

The error is coming from lsp_handlers.erl at line 10. This is only happening when opening a file (and not a folder) because the value of rootPath is null. As it is not a valid binary, the call to binary_to_list fails. Here is a quick fix:

initialize(_Socket, Params) ->
    RootPath = case maps:get(rootPath, Params) of
        null -> <<"">>;
        Other -> Other
    end,
    gen_lsp_config_server:update_config(root, binary_to_list(RootPath)),

I am not certain that "" is ok for the rootPath when there is none though. I took it from gen_lsp_config_server:root. What do you think ?

sebkm avatar Oct 03 '20 10:10 sebkm

@sebkm This works great! Thank you for a quick fix. Hopefully, this will find its way into release sometime...

altishchenko avatar May 18 '21 21:05 altishchenko