Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/engine/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule Engine.MixProject do
Mix.Credo.dependency(),
Mix.Dialyzer.dependency(),
{:elixir_sense,
github: "elixir-lsp/elixir_sense", ref: "73ce7e0d239342fb9527d7ba567203e77dbb9b25"},
github: "elixir-lsp/elixir_sense", ref: "e3ddc403554050221a2fd19a10a896fa7525bc02"},
{:forge, path: "../forge", env: Mix.env()},
{:gen_lsp, "~> 0.11"},
{:patch, "~> 0.15", only: [:dev, :test], optional: true, runtime: false},
Expand Down
2 changes: 1 addition & 1 deletion apps/engine/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"credo": {:hex, :credo, "1.7.12", "9e3c20463de4b5f3f23721527fcaf16722ec815e70ff6c60b86412c695d426c1", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8493d45c656c5427d9c729235b99d498bd133421f3e0a683e5c1b561471291e5"},
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"},
"dialyxir": {:hex, :dialyxir, "1.4.5", "ca1571ac18e0f88d4ab245f0b60fa31ff1b12cbae2b11bd25d207f865e8ae78a", [:mix], [{:erlex, ">= 0.2.7", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "b0fb08bb8107c750db5c0b324fa2df5ceaa0f9307690ee3c1f6ba5b9eb5d35c3"},
"elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "73ce7e0d239342fb9527d7ba567203e77dbb9b25", [ref: "73ce7e0d239342fb9527d7ba567203e77dbb9b25"]},
"elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "e3ddc403554050221a2fd19a10a896fa7525bc02", [ref: "e3ddc403554050221a2fd19a10a896fa7525bc02"]},
"erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"},
"file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"},
"gen_lsp": {:hex, :gen_lsp, "0.11.0", "9eda4d2fcaff94d9b3062e322fcf524c176db1502f584a3cff6135088b46084b", [:mix], [{:jason, "~> 1.3", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.5 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:schematic, "~> 0.2.1", [hex: :schematic, repo: "hexpm", optional: false]}, {:typed_struct, "~> 0.3.0", [hex: :typed_struct, repo: "hexpm", optional: false]}], "hexpm", "d67c20650a5290a02f7bac53083ac4487d3c6b461f35a8b14c5d2d7638c20d26"},
Expand Down
65 changes: 43 additions & 22 deletions apps/expert/lib/expert.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,39 @@ defmodule Expert do
def handle_request(request, lsp) do
state = assigns(lsp).state

with {:ok, handler} <- fetch_handler(request),
{:ok, request} <- Convert.to_native(request),
{:ok, response} <- handler.handle(request, state.configuration),
{:ok, response} <- Expert.Protocol.Convert.to_lsp(response) do
{:reply, response, lsp}
if state.engine_initialized? do
with {:ok, handler} <- fetch_handler(request),
{:ok, request} <- Convert.to_native(request),
{:ok, response} <- handler.handle(request, state.configuration),
{:ok, response} <- Expert.Protocol.Convert.to_lsp(response) do
{:reply, response, lsp}
else
{:error, {:unhandled, _}} ->
Logger.info("Unhandled request: #{request.method}")

{:reply,
%GenLSP.ErrorResponse{
code: GenLSP.Enumerations.ErrorCodes.method_not_found(),
message: "Method not found"
}, lsp}

error ->
message = "Failed to handle #{request.method}, #{inspect(error)}"
Logger.error(message)

{:reply,
%GenLSP.ErrorResponse{
code: GenLSP.Enumerations.ErrorCodes.internal_error(),
message: message
}, lsp}
end
else
{:error, {:unhandled, _}} ->
Logger.info("Unhandled request: #{request.method}")

{:reply,
%GenLSP.ErrorResponse{
code: GenLSP.Enumerations.ErrorCodes.method_not_found(),
message: "Method not found"
}, lsp}

error ->
message = "Failed to handle #{request.method}, #{inspect(error)}"
Logger.error(message)
GenLSP.warning(
lsp,
"Received request #{request.method} before engine was initialized. Ignoring."
)

{:reply,
%GenLSP.ErrorResponse{
code: GenLSP.Enumerations.ErrorCodes.internal_error(),
message: message
}, lsp}
{:noreply, lsp}
end
end

Expand Down Expand Up @@ -155,6 +164,18 @@ defmodule Expert do
end
end

def handle_info(:engine_initialized, lsp) do
state = assigns(lsp).state

new_state = %State{state | engine_initialized?: true}

lsp = assign(lsp, state: new_state)

Logger.info("Engine initialized")

{:noreply, lsp}
end

def handle_info(:default_config, lsp) do
state = assigns(lsp).state

Expand Down
1 change: 1 addition & 0 deletions apps/expert/lib/expert/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule Expert.Application do
{Task.Supervisor, name: :expert_task_queue},
{GenLSP.Buffer, name: Expert.Buffer},
{Expert,
name: Expert,
buffer: Expert.Buffer,
task_supervisor: :expert_task_queue,
dynamic_supervisor: Expert.DynamicSupervisor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule Expert.CodeIntelligence.Completion.Translations.Callable do

tags =
if Map.get(callable.metadata, :deprecated) do
[:deprecated]
[GenLSP.Enumerations.CompletionItemTag.deprecated()]
end

kind =
Expand Down
5 changes: 5 additions & 0 deletions apps/expert/lib/expert/protocol/convert.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ defmodule Expert.Protocol.Convert do
{:ok, %{original_request | params: updated_request}}
end
end

def to_native(%GenLSP.Requests.Shutdown{} = request) do
# Special case for shutdown requests, which don't have a params field
{:ok, request}
end
end
6 changes: 5 additions & 1 deletion apps/expert/lib/expert/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule Expert.State do

defstruct configuration: nil,
initialized?: false,
engine_initialized?: false,
shutdown_received?: false,
in_flight_requests: %{}

Expand Down Expand Up @@ -54,7 +55,10 @@ defmodule Expert.State do

response = initialize_result()

Task.start_link(fn -> Project.Supervisor.start(config.project) end)
Task.Supervisor.start_child(:expert_task_queue, fn ->
Project.Supervisor.start(config.project)
send(Expert, :engine_initialized)
end)

{:ok, response, new_state}
end
Expand Down
2 changes: 1 addition & 1 deletion apps/expert/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"credo": {:hex, :credo, "1.7.12", "9e3c20463de4b5f3f23721527fcaf16722ec815e70ff6c60b86412c695d426c1", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8493d45c656c5427d9c729235b99d498bd133421f3e0a683e5c1b561471291e5"},
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"},
"dialyxir": {:hex, :dialyxir, "1.4.5", "ca1571ac18e0f88d4ab245f0b60fa31ff1b12cbae2b11bd25d207f865e8ae78a", [:mix], [{:erlex, ">= 0.2.7", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "b0fb08bb8107c750db5c0b324fa2df5ceaa0f9307690ee3c1f6ba5b9eb5d35c3"},
"elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "73ce7e0d239342fb9527d7ba567203e77dbb9b25", [ref: "73ce7e0d239342fb9527d7ba567203e77dbb9b25"]},
"elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "e3ddc403554050221a2fd19a10a896fa7525bc02", [ref: "e3ddc403554050221a2fd19a10a896fa7525bc02"]},
"erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"},
"file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"},
"gen_lsp": {:hex, :gen_lsp, "0.11.0", "9eda4d2fcaff94d9b3062e322fcf524c176db1502f584a3cff6135088b46084b", [:mix], [{:jason, "~> 1.3", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.5 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:schematic, "~> 0.2.1", [hex: :schematic, repo: "hexpm", optional: false]}, {:typed_struct, "~> 0.3.0", [hex: :typed_struct, repo: "hexpm", optional: false]}], "hexpm", "d67c20650a5290a02f7bac53083ac4487d3c6b461f35a8b14c5d2d7638c20d26"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ defmodule Expert.CodeIntelligence.Completion.Translations.FunctionTest do
|> fetch_completion("filter_map")

assert completion.label
assert [:deprecated] = completion.tags
expected_tag = GenLSP.Enumerations.CompletionItemTag.deprecated()
assert [^expected_tag] = completion.tags
end

test "bang functions are sorted after non-bang functions", %{project: project} do
Expand Down
Loading