From cc46f8798a6222390221c35b8c51e4bf1ce43584 Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Sat, 24 Jun 2023 10:41:56 +0200 Subject: [PATCH] Fix crash when handling workspace/didChangeWatchedFiles when project_dir not yet set Fixes https://github.com/elixir-lsp/elixir-ls/issues/920 --- apps/language_server/lib/language_server/server.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/language_server/lib/language_server/server.ex b/apps/language_server/lib/language_server/server.ex index 0ad4aea0e..8a7223a80 100644 --- a/apps/language_server/lib/language_server/server.ex +++ b/apps/language_server/lib/language_server/server.ex @@ -418,7 +418,8 @@ defmodule ElixirLS.LanguageServer.Server do end end - defp handle_notification(did_change_watched_files(changes), state = %__MODULE__{}) do + defp handle_notification(did_change_watched_files(changes), state = %__MODULE__{}) + when is_binary(state.project_dir) do changes = Enum.filter(changes, &match?(%{"uri" => "file:" <> _}, &1)) # `settings` may not always be available here, like during testing @@ -486,6 +487,11 @@ defmodule ElixirLS.LanguageServer.Server do if needs_build, do: trigger_build(state), else: state end + defp handle_notification(did_change_watched_files(_changes), state = %__MODULE__{}) do + # swallow notification if project_dir is not yet set + state + end + defp handle_notification(%{"method" => "$/" <> _}, state = %__MODULE__{}) do # not supported "$/" notifications may be safely ignored state