From 0b9813f25d5b78cfd30f2a2b3ee784ee973dc937 Mon Sep 17 00:00:00 2001 From: anotherzxx <30956192+anotherzxx@users.noreply.github.com> Date: Wed, 23 Aug 2023 08:34:37 +0800 Subject: [PATCH 1/2] get third dep name from definition --- .../lib/language_server/providers/hover.ex | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/language_server/lib/language_server/providers/hover.ex b/apps/language_server/lib/language_server/providers/hover.ex index c837aee34..aff82b01e 100644 --- a/apps/language_server/lib/language_server/providers/hover.ex +++ b/apps/language_server/lib/language_server/providers/hover.ex @@ -73,7 +73,7 @@ defmodule ElixirLS.LanguageServer.Providers.Hover do "" true -> - dep = subject |> root_module_name() |> dep_name(project_dir) |> URI.encode() + dep = subject |> dep_name(project_dir) |> URI.encode() cond do func?(title) -> @@ -114,16 +114,24 @@ defmodule ElixirLS.LanguageServer.Providers.Hover do end end - defp dep_name(root_mod_name, project_dir) do + defp dep_name(subject, project_dir) do + root_mod_name = root_module_name(subject) + if not elixir_mod_exported?(root_mod_name) do "" else s = root_mod_name |> source() cond do - third_dep?(s, project_dir) -> third_dep_name(s, project_dir) - builtin?(s) -> builtin_dep_name(s) - true -> "" + third_dep?(s, project_dir) -> + %ElixirSense.Location{file: source} = ElixirSense.definition(subject, 1, 1) + third_dep_name(source, project_dir) + + builtin?(s) -> + builtin_dep_name(s) + + true -> + "" end end end From 28452fafccf5841345c7da09d7ebd01736522f3e Mon Sep 17 00:00:00 2001 From: anotherzxx <30956192+anotherzxx@users.noreply.github.com> Date: Wed, 23 Aug 2023 15:17:47 +0800 Subject: [PATCH 2/2] handle definition return nil file --- .../lib/language_server/providers/hover.ex | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/language_server/lib/language_server/providers/hover.ex b/apps/language_server/lib/language_server/providers/hover.ex index aff82b01e..bd9adb778 100644 --- a/apps/language_server/lib/language_server/providers/hover.ex +++ b/apps/language_server/lib/language_server/providers/hover.ex @@ -124,8 +124,13 @@ defmodule ElixirLS.LanguageServer.Providers.Hover do cond do third_dep?(s, project_dir) -> - %ElixirSense.Location{file: source} = ElixirSense.definition(subject, 1, 1) - third_dep_name(source, project_dir) + case ElixirSense.definition(subject, 1, 1) do + %ElixirSense.Location{file: source} when not is_nil(source) -> + third_dep_name(source, project_dir) + + _ -> + third_dep_name(s, project_dir) + end builtin?(s) -> builtin_dep_name(s)