Skip to content

Add custom request for macro expansion #1

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

Merged
merged 4 commits into from
May 14, 2018
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
12 changes: 12 additions & 0 deletions apps/language_server/lib/language_server/protocol.ex
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ defmodule ElixirLS.LanguageServer.Protocol do
end
end

defmacro macro_expansion(id, whole_buffer, selected_macro, macro_line) do
quote do
request(unquote(id), "elixirDocument/macroExpansion", %{
"context" => %{"selection" => unquote(selected_macro)},
"textDocument" => %{
"text" => unquote(whole_buffer)},
"position" => %{ "line" => unquote(macro_line) }
})
end
end


# Other utilities

defmacro range(start_line, start_character, end_line, end_character) do
Expand Down
7 changes: 7 additions & 0 deletions apps/language_server/lib/language_server/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ defmodule ElixirLS.LanguageServer.Server do
{:async, fun, state}
end

defp handle_request(macro_expansion(_id, whole_buffer, selected_macro, macro_line), state) do
x = ElixirSense.expand_full(whole_buffer, selected_macro, macro_line)
{:ok, x, state}
end

defp handle_request(request(_, _, _) = req, state) do
IO.inspect(req, label: "Unmatched request")
{:error, :invalid_request, nil, state}
Expand Down Expand Up @@ -434,6 +439,7 @@ defmodule ElixirLS.LanguageServer.Server do

defp server_capabilities do
%{
"macroExpansion" => true,
"textDocumentSync" => 2,
"hoverProvider" => true,
"completionProvider" => %{"triggerCharacters" => Completion.trigger_characters()},
Expand Down Expand Up @@ -644,4 +650,5 @@ defmodule ElixirLS.LanguageServer.Server do
defp set_project_dir(state, _) do
state
end

end