Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashing String.slice after editing file/module endings #1002

Closed
florianb opened this issue Oct 13, 2023 · 4 comments
Closed

Crashing String.slice after editing file/module endings #1002

florianb opened this issue Oct 13, 2023 · 4 comments

Comments

@florianb
Copy link
Contributor

florianb commented Oct 13, 2023

Environment

  • Erlang/OTP 26 [erts-14.0.2] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]
  • Elixir 1.15.4 (compiled with Erlang/OTP 26)
  • Elixir Language Server version: 0.17.0
  • Operating system: Alpine Linux v3.18; Linux 4d993fe017da 6.4.16-linuxkit # 1 SMP PREEMPT_DYNAMIC Sat Sep 23 13:39:52 UTC 2023 x86_64 Linux
  • VSCode: 1.83.0
  • ElixirLS: 0.17.0

Current behavior

The LS seems to crash when adding/removing the last end in this module:

Change

defmodule T do
  defdelegate, to:
  def t(), do: :smth e
  defp u do

  end
end

to

defmodule T do
  defdelegate, to:
  def t(), do: :smth e
  defp u do

  end

It might be, that the appearance/disappearance of the last line/last "newline" plays a role here. I noticed my Editor currently seems to strip the last line and this happens a lot when quickly edditing in the last section of the file.

Log

[Error - 7:42:30 AM] GenServer ElixirLS.LanguageServer.Server terminating
** (FunctionClauseError) no function clause matching in String.slice/2
    (elixir 1.15.4) lib/string.ex:2241: String.slice(nil, 0..0)
    (language_server 0.17.0) lib/language_server/source_file.ex:316: ElixirLS.LanguageServer.SourceFile.elixir_character_to_lsp/2
    (language_server 0.17.0) lib/language_server/diagnostics.ex:324: ElixirLS.LanguageServer.Diagnostics.range/2
    (language_server 0.17.0) lib/language_server/diagnostics.ex:210: anonymous fn/2 in ElixirLS.LanguageServer.Diagnostics.publish_file_diagnostics/3
    (elixir 1.15.4) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
    (elixir 1.15.4) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
    (language_server 0.17.0) lib/language_server/diagnostics.ex:192: ElixirLS.LanguageServer.Diagnostics.publish_file_diagnostics/3
    (language_server 0.17.0) lib/language_server/server.ex:1187: anonymous fn/4 in ElixirLS.LanguageServer.Server.publish_diagnostics/3
@lukaszsamson
Copy link
Collaborator

That's most likely race conditions between publishing diagnostics and source file changes. This line assumes the source file has the line with error

start_line = Enum.at(lines, line_start - 1)

@florianb
Copy link
Contributor Author

Shouldn't the file already being read at this point, how can this differ?

@lukaszsamson
Copy link
Collaborator

Async parsing and async text document synchronisation. When the diagnostic is being published the line is not there anymore and we need the line to convert UTF8 code points to UTF16. I know what needs fixing here :)

@florianb
Copy link
Contributor Author

Thank you very much for your work! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants