Skip to content

Crash: protocol Jason.Encoder not implemented for ElixirLS.LanguageServer.Protocol.DocumentSymbol #253

@thetamind

Description

@thetamind

(Protocol.UndefinedError) protocol Jason.Encoder not implemented for %ElixirLS.LanguageServer.Protocol.DocumentSymbol

Environment

  • Elixir & Erlang versions (elixir --version):
Erlang/OTP 23 [erts-11.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [dtrace]

Elixir 1.11.0-dev (b028ac8) (compiled with Erlang/OTP 23)
  • Operating system: macOS High Sierra 10.13.6
  • Editor or IDE name (e.g. Emacs/VSCode): VSCode 1.44.2
  • LSP Client name:
    • If using VSCode, are you using "ElixirLS: Elixir support and debugger"? Yes, jakebecker.elixir-ls v0.4.0

Troubleshooting

  • Restart your editor (which will restart ElixirLS) sometimes fixes issues
  • Stop your editor, remove the entire .elixir_ls directory, then restart your editor
    • NOTE: This will cause you to have to re-run the dialyzer build for your project

Reproduction steps

I could not trigger the error with a simple file in a empty mix project, but I could in a new Phoenix project.

  1. mix phx.new hello # Phoenix 1.5.1
  2. cd hello
  3. code .
  4. In VSCode open lib/hello/repo.ex
  5. Wait for ElixirLS to finish working (to show not a race condition...)
  6. At the end of defmodule Hello.Repo do press enter to insert new line
  7. ElixirLS has crashed. See Output panel.
defmodule Hello.Repo do

  use Ecto.Repo,
    otp_app: :hello,
    adapter: Ecto.Adapters.Postgres
end

Logs

Full log.

[Trace - 5:06:14 p.m.] Sending request 'textDocument/documentSymbol - (4)'.
[Trace - 5:06:14 p.m.] Received notification 'window/logMessage'.

17:06:14.940 [error] GenServer ElixirLS.LanguageServer.Server terminating
** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for %ElixirLS.LanguageServer.Protocol.DocumentSymbol{children: [], kind: 2, name: "Hello.Repo", range: %{end: %{character: 0, line: 0}, start: %{character: 0, line: 0}}, selectionRange: %{end: %{character: 0, line: 0}, start: %{character: 0, line: 0}}} of type ElixirLS.LanguageServer.Protocol.DocumentSymbol (a struct), Jason.Encoder protocol must always be explicitly implemented.
[...]
This protocol is implemented for the following type(s): Ecto.Association.NotLoaded, Ecto.Schema.Metadata, Date, BitString, Jason.Fragment, Any, Map, NaiveDateTime, List, Integer, Time, DateTime, Decimal, Atom, Float
    lib/jason.ex:150: Jason.encode!/2
    (elixir_ls_utils 0.4.0) lib/wire_protocol.ex:9: ElixirLS.Utils.WireProtocol.send/1
    (language_server 0.4.0) lib/language_server/server.ex:94: ElixirLS.LanguageServer.Server.handle_call/3
    (stdlib 3.13) gen_server.erl:706: :gen_server.try_handle_call/4
    (stdlib 3.13) gen_server.erl:735: :gen_server.handle_msg/6
    (stdlib 3.13) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.366.0>): {:request_finished, 4, {:ok, [%ElixirLS.LanguageServer.Protocol.DocumentSymbol{children: [], kind: 2, name: "Hello.Repo", range: %{end: %{character: 0, line: 0}, start: %{character: 0, line: 0}}, selectionRange: %{end: %{character: 0, line: 0}, start: %{character: 0, line: 0}}}]}}
State: %ElixirLS.LanguageServer.Server{analysis_ready?: true, awaiting_contracts: [{{#PID<0.325.0>, #Reference<0.3225323319.1372323841.96827>}, "file:///Users/thetamind/Projects/tmp/phoenix_hello/lib/hello/repo.ex"}], build_diagnostics: [], build_ref: #Reference<0.3225323319.1372323842.93752>, build_running?: false, client_capabilities: %{"textDocument" => %{"codeAction" => %{"codeActionLiteralSupport" => %{"codeActionKind" => %{"valueSet" => ["", "quickfix", "refactor", "refactor.extract", "refactor.inline", "refactor.rewrite", "source", "source.organizeImports"]}}, "dynamicRegistration" => true, "isPreferredSupport" => true}, "codeLens" => %{"dynamicRegistration" => true}, "colorProvider" => %{"dynamicRegistration" => true}, "completion" => %{"completionItem" => %{"commitCharactersSupport" => true, "deprecatedSupport" => true, "documentationFormat" => ["markdown", "plaintext"], "preselectSupport" => true, "snippetSupport" => true, "tagSupport" => %{"valueSet" => [1]}}, "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}, "declaration" => %{"dynamicRegistration" => true, "linkSupport" => true}, "definition" => %{"dynamicRegistration" => true, "linkSupport" => true}, "documentHighlight" => %{"dynamicRegistration" => true}, "documentLink" => %{"dynamicRegistration" => true, "tooltipSupport" => 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, "linkSupport" => true}, "onTypeFormatting" => %{"dynamicRegistration" => true}, "publishDiagnostics" => %{"relatedInformation" => true, "tagSupport" => %{"valueSet" => [1, 2]}, "versionSupport" => false}, "rangeFormatting" => %{"dynamicRegistration" => true}, "references" => %{"dynamicRegistration" => true}, "rename" => %{"dynamicRegistration" => true, "prepareSupport" => true}, "selectionRange" => %{"dynamicRegistration" => true}, "signatureHelp" => %{"contextSupport" => true, "dynamicRegistration" => true, "signatureInformation" => %{"documentationFormat" => ["markdown", "plaintext"], "parameterInformation" => %{"labelOffsetSupport" => true}}}, "synchronization" => %{"didSave" => true, "dynamicRegistration" => true, "willSave" => true, "willSaveWaitUntil" => true}, "typeDefinition" => %{"dynamicRegistration" => true, "linkSupport" => true}}, "window" => %{"workDoneProgress" => 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, "failureHandling" => "textOnlyTransactional", "resourceOperations" => ["create", "rename", "delete"]}, "workspaceFolders" => true}}, dialyzer_diagnostics: [%Mix.Task.Compiler.Diagnostic{compiler_name: "ElixirLS Dialyzer", details: {:warn_failing_call, {'lib/hello_web/gettext.ex', 23, {HelloWeb.Gettext, :handle_missing_bindings, 2}}, {:call, [Logger, :__do_log__, '(_@3::any(),binary(),\#{\'application\':=\'hello\', \'file\':=[46 | 47 | 95 | 98 | 101 | 103 | 104 | 105 | 108 | 111 | 116 | 119 | 120,...], \'line\':=23, \'mfa\':={\'Elixir.HelloWeb.Gettext\',\'handle_missing_bindings\',2}})', [2], :only_sig, '(any(),fun(() -> any()),map())', 'no_return()', {false, :none}]}}, file: "/Users/thetamind/Projects/tmp/phoenix_hello/lib/hello_web/gettext.ex", message: "The call 'Elixir.Logger':'__do_log__'\n         (_@3 :: any(),\n          binary(),\n          \#{'application' := 'hello',\n            'file' :=\n                [46 | 47 | 95 | 98 | 101 | 103 | 104 | 105 | 108 | 111 |\n                 116 | 119 | 120,\n                 ...],\n            'line' := 23,\n            'mfa' :=\n                {'Elixir.HelloWeb.Gettext', 'handle_missing_bindings',\n                 2}}) will never return since it differs in the 2nd argument from the success typing arguments: \n         (any(),\n          fun(() -> any()),\n          map())", position: 23, severity: :warning}], dialyzer_sup: #PID<0.118.0>, load_all_modules?: false, needs_build?: false, project_dir: "/Users/thetamind/Projects/tmp/phoenix_hello", received_shutdown?: false, requests: %{3 => #PID<0.325.0>, 4 => #PID<0.366.0>}, root_uri: "file:///Users/thetamind/Projects/tmp/phoenix_hello", settings: %{"dialyzerEnabled" => true, "dialyzerFormat" => "dialyzer", "dialyzerWarnOpts" => [], "fetchDeps" => true, "mixEnv" => "test", "projectDir" => "", "suggestSpecs" => true, "trace" => %{"server" => "messages"}}, source_files: %{"file:///Users/thetamind/Projects/tmp/phoenix_hello/lib/hello/repo.ex" => %ElixirLS.LanguageServer.SourceFile{dirty?: true, text: "defmodule Hello.Repo do\n  \n  use Ecto.Repo,\n    otp_app: :hello,\n    adapter: Ecto.Adapters.Postgres\nend\n", version: 3}}}
Client #PID<0.366.0> is alive

    (stdlib 3.13) gen.erl:208: :gen.do_call/4
    (elixir 1.11.0-dev) lib/gen_server.ex:1020: GenServer.call/3
[Trace - 5:06:14 p.m.] Received notification 'window/showMessage'.
[Info  - 5:06:19 p.m.] Connection to server got closed. Server will restart.
[Error - 5:06:19 p.m.] Request textDocument/codeLens failed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions