Skip to content
Merged
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
poncho_dirs = forge expert_credo proto protocol engine expert
poncho_dirs = forge expert_credo engine expert

compile.all: compile.poncho

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,23 @@ compile_project(:other)
# the other project is compiled
iex(2)> complete :other, "defmo|"
[
#Protocol.Types.Completion.Item<[
#GenLSP.Structures.CompletionItem<[
detail: "",
insert_text: "defmacro ${1:name}($2) do\n $0\nend\n",
insert_text_format: :snippet,
kind: :class,
label: "defmacro (Define a macro)",
sort_text: "093_defmacro (Define a macro)"
]>,
#Protocol.Types.Completion.Item<[
#GenLSP.Structures.CompletionItem<[
detail: "",
insert_text: "defmacrop ${1:name}($2) do\n $0\nend\n",
insert_text_format: :snippet,
kind: :class,
label: "defmacrop (Define a private macro)",
sort_text: "094_defmacrop (Define a private macro)"
]>,
#Protocol.Types.Completion.Item<[
#GenLSP.Structures.CompletionItem<[
detail: "",
insert_text: "defmodule ${1:module name} do\n $0\nend\n",
insert_text_format: :snippet,
Expand Down
15 changes: 4 additions & 11 deletions apps/engine/lib/engine/engine/code_action.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@ defmodule Engine.CodeAction do
alias Forge.Document.Changes
alias Forge.Document.Range

require Logger

defstruct [:title, :kind, :changes, :uri]

@type code_action_kind ::
:empty
| :quick_fix
| :refactor
| :refactor_extract
| :refactor_inline
| :refactor_rewrite
| :source
| :source_organize_imports
| :source_fix_all
@type code_action_kind :: GenLSP.Enumerations.CodeActionKind.t()

@type trigger_kind :: :invoked | :automatic
@type trigger_kind :: GenLSP.Enumerations.CodeActionTriggerKind.t()

@type t :: %__MODULE__{
title: String.t(),
Expand Down
20 changes: 10 additions & 10 deletions apps/engine/lib/engine/engine/code_action/handlers/add_alias.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
defmodule Engine.CodeAction.Handlers.AddAlias do
alias Engine.Analyzer
alias Engine.CodeAction
alias Engine.CodeIntelligence.Entity
alias Engine.CodeMod
alias Engine.Modules
alias Engine.Search.Fuzzy
alias Engine.Search.Indexer.Entry
alias Forge.Ast
alias Forge.Ast.Analysis
alias Forge.Ast.Analysis.Alias
Expand All @@ -7,14 +14,7 @@ defmodule Engine.CodeAction.Handlers.AddAlias do
alias Forge.Document.Position
alias Forge.Document.Range
alias Forge.Formats

alias Engine.Analyzer
alias Engine.CodeAction
alias Engine.CodeIntelligence.Entity
alias Engine.CodeMod
alias Engine.Modules
alias Engine.Search.Fuzzy
alias Engine.Search.Indexer.Entry
alias GenLSP.Enumerations.CodeActionKind
alias Mix.Tasks.Namespace
alias Sourceror.Zipper

Expand All @@ -41,7 +41,7 @@ defmodule Engine.CodeAction.Handlers.AddAlias do

@impl CodeAction.Handler
def kinds do
[:quick_fix]
[CodeActionKind.quick_fix()]
end

@impl CodeAction.Handler
Expand Down Expand Up @@ -69,7 +69,7 @@ defmodule Engine.CodeAction.Handlers.AddAlias do
CodeAction.new(
analysis.document.uri,
"alias #{Formats.module(potential_alias_module)}",
:quick_fix,
CodeActionKind.quick_fix(),
changes
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Engine.CodeAction.Handlers.OrganizeAliases do
alias Forge.Document
alias Forge.Document.Changes
alias Forge.Document.Range
alias GenLSP.Enumerations.CodeActionKind

require Logger

Expand All @@ -23,7 +24,15 @@ defmodule Engine.CodeAction.Handlers.OrganizeAliases do
[]
else
changes = Changes.new(doc, edits)
[CodeAction.new(doc.uri, "Organize aliases", :source_organize_imports, changes)]

[
CodeAction.new(
doc.uri,
"Organize aliases",
CodeActionKind.source_organize_imports(),
changes
)
]
end
else
_ ->
Expand All @@ -33,7 +42,7 @@ defmodule Engine.CodeAction.Handlers.OrganizeAliases do

@impl CodeAction.Handler
def kinds do
[:source, :source_organize_imports]
[CodeActionKind.source(), CodeActionKind.source_organize_imports()]
end

@impl CodeAction.Handler
Expand Down
16 changes: 6 additions & 10 deletions apps/engine/lib/engine/engine/code_action/handlers/refactorex.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
defmodule Engine.CodeAction.Handlers.Refactorex do
alias Engine.CodeAction
alias Engine.CodeMod
alias Forge.Document
alias Forge.Document.Changes
alias Forge.Document.Range

alias Engine.CodeAction
alias Engine.CodeMod

alias GenLSP.Enumerations
alias Refactorex.Refactor

@behaviour CodeAction.Handler
Expand All @@ -21,7 +20,7 @@ defmodule Engine.CodeAction.Handlers.Refactorex do
CodeAction.new(
doc.uri,
refactoring.title,
map_kind(refactoring.kind),
refactoring.kind,
ast_to_changes(doc, refactoring.refactored)
)
end)
Expand All @@ -31,10 +30,10 @@ defmodule Engine.CodeAction.Handlers.Refactorex do
end

@impl CodeAction.Handler
def kinds, do: [:refactor]
def kinds, do: [Enumerations.CodeActionKind.refactor()]

@impl CodeAction.Handler
def trigger_kind, do: :invoked
def trigger_kind, do: Enumerations.CodeActionTriggerKind.invoked()

defp line_or_selection(_, %{start: start, end: start}), do: {:ok, start.line}

Expand All @@ -44,9 +43,6 @@ defmodule Engine.CodeAction.Handlers.Refactorex do
|> Sourceror.parse_string(line: start.line, column: start.character)
end

defp map_kind("quickfix"), do: :quick_fix
defp map_kind(kind), do: :"#{String.replace(kind, ".", "_")}"

defp ast_to_changes(doc, ast) do
{formatter, opts} = CodeMod.Format.formatter_for_file(Engine.get_project(), doc.uri)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ defmodule Engine.CodeAction.Handlers.RemoveUnusedAlias do
alias Forge.Document.Edit
alias Forge.Document.Position
alias Forge.Document.Range
alias GenLSP.Enumerations
alias Sourceror.Zipper

import Record
Expand All @@ -51,7 +52,14 @@ defmodule Engine.CodeAction.Handlers.RemoveUnusedAlias do
case to_edit(document, range.start, diagnostic) do
{:ok, module_name, edit} ->
changes = Changes.new(document, [edit])
action = CodeAction.new(document.uri, "Remove alias #{module_name}", :source, changes)

action =
CodeAction.new(
document.uri,
"Remove alias #{module_name}",
Enumerations.CodeActionKind.source(),
changes
)

[action | acc]

Expand All @@ -63,7 +71,7 @@ defmodule Engine.CodeAction.Handlers.RemoveUnusedAlias do

@impl CodeAction.Handler
def kinds do
[:source]
[Enumerations.CodeActionKind.source()]
end

@impl CodeAction.Handler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
defmodule Engine.CodeAction.Handlers.ReplaceRemoteFunction do
alias Engine.CodeAction
alias Engine.CodeAction.Diagnostic
alias Engine.Modules
alias Forge.Ast
alias Forge.Document
alias Forge.Document.Changes
alias Forge.Document.Edit
alias Forge.Document.Range

alias Engine.CodeAction
alias Engine.CodeAction.Diagnostic
alias Engine.Modules
alias GenLSP.Enumerations.CodeActionKind
alias Sourceror.Zipper

@behaviour CodeAction.Handler
Expand All @@ -27,7 +27,7 @@ defmodule Engine.CodeAction.Handlers.ReplaceRemoteFunction do

@impl CodeAction.Handler
def kinds do
[:quick_fix]
[CodeActionKind.quick_fix()]
end

@impl CodeAction.Handler
Expand All @@ -41,7 +41,14 @@ defmodule Engine.CodeAction.Handlers.ReplaceRemoteFunction do
case apply_transform(doc, line_number, module, function, suggestion) do
{:ok, edits} ->
changes = Changes.new(doc, edits)
code_action = CodeAction.new(doc.uri, "Rename to #{suggestion}", :quick_fix, changes)

code_action =
CodeAction.new(
doc.uri,
"Rename to #{suggestion}",
CodeActionKind.quick_fix(),
changes
)

[code_action | acc]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Engine.CodeAction.Handlers.ReplaceWithUnderscore do
alias Forge.Document
alias Forge.Document.Changes
alias Forge.Document.Range
alias GenLSP.Enumerations.CodeActionKind
alias Sourceror.Zipper

@behaviour CodeAction.Handler
Expand All @@ -14,7 +15,13 @@ defmodule Engine.CodeAction.Handlers.ReplaceWithUnderscore do
Enum.reduce(diagnostics, [], fn %Diagnostic{} = diagnostic, acc ->
with {:ok, variable_name, line_number} <- extract_variable_and_line(diagnostic),
{:ok, changes} <- to_changes(doc, line_number, variable_name) do
action = CodeAction.new(doc.uri, "Rename to _#{variable_name}", :quick_fix, changes)
action =
CodeAction.new(
doc.uri,
"Rename to _#{variable_name}",
CodeActionKind.quick_fix(),
changes
)

[action | acc]
else
Expand All @@ -26,7 +33,7 @@ defmodule Engine.CodeAction.Handlers.ReplaceWithUnderscore do

@impl CodeAction.Handler
def kinds do
[:quick_fix]
[CodeActionKind.quick_fix()]
end

@impl CodeAction.Handler
Expand Down
1 change: 1 addition & 0 deletions apps/engine/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ defmodule Engine.MixProject do
Mix.Dialyzer.dependency(),
{:elixir_sense,
github: "elixir-lsp/elixir_sense", ref: "73ce7e0d239342fb9527d7ba567203e77dbb9b25"},
{:gen_lsp, "~> 0.10"},
{:patch, "~> 0.15", only: [:dev, :test], optional: true, runtime: false},
{:path_glob, "~> 0.2", optional: true},
{:phoenix_live_view, "~> 1.0", only: [:test], optional: true, runtime: false},
Expand Down
4 changes: 4 additions & 0 deletions apps/engine/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "73ce7e0d239342fb9527d7ba567203e77dbb9b25", [ref: "73ce7e0d239342fb9527d7ba567203e77dbb9b25"]},
"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.10.0", "f6da076b5ccedf937d17aa9743635a2c3d0f31265c853e58b02ab84d71852270", [: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", "768f8f7b5c5e218fb36dcebd30dcd6275b61ca77052c98c3c4c0375158392c4a"},
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
"mime": {:hex, :mime, "2.0.6", "8f18486773d9b15f95f4f4f1e39b710045fa1de891fada4516559967276e4dc2", [:mix], [], "hexpm", "c9945363a6b26d747389aac3643f8e0e09d30499a138ad64fe8fd1d13d9b153e"},
"nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
"patch": {:hex, :patch, "0.15.0", "947dd6a8b24a2d2d1137721f20bb96a8feb4f83248e7b4ad88b4871d52807af5", [:mix], [], "hexpm", "e8dadf9b57b30e92f6b2b1ce2f7f57700d14c66d4ed56ee27777eb73fb77e58d"},
"path_glob": {:hex, :path_glob, "0.2.0", "b9e34b5045cac5ecb76ef1aa55281a52bf603bf7009002085de40958064ca312", [:mix], [{:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "be2594cb4553169a1a189f95193d910115f64f15f0d689454bb4e8cfae2e7ebc"},
Expand All @@ -21,11 +23,13 @@
"plug": {:hex, :plug, "1.17.0", "a0832e7af4ae0f4819e0c08dd2e7482364937aea6a8a997a679f2cbb7e026b2e", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f6692046652a69a00a5a21d0b7e11fcf401064839d59d6b8787f23af55b1e6bc"},
"plug_crypto": {:hex, :plug_crypto, "2.1.0", "f44309c2b06d249c27c8d3f65cfe08158ade08418cf540fd4f72d4d6863abb7b", [:mix], [], "hexpm", "131216a4b030b8f8ce0f26038bc4421ae60e4bb95c5cf5395e1421437824c4fa"},
"refactorex": {:hex, :refactorex, "0.1.51", "74fc4603b31b600d78539ffea9fe170038aa8d471eec5aed261354c9734b4b27", [:mix], [{:sourceror, "~> 1.7", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "aefa150ab2c0d62aa8c01c4d04b932806118790f09c4106e20883281932fba03"},
"schematic": {:hex, :schematic, "0.2.1", "0b091df94146fd15a0a343d1bd179a6c5a58562527746dadd09477311698dbb1", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "0b255d65921e38006138201cd4263fd8bb807d9dfc511074615cd264a571b3b1"},
"snowflake": {:hex, :snowflake, "1.0.4", "8433b4e04fbed19272c55e1b7de0f7a1ee1230b3ae31a813b616fd6ef279e87a", [:mix], [], "hexpm", "badb07ebb089a5cff737738297513db3962760b10fe2b158ae3bebf0b4d5be13"},
"sourceror": {:hex, :sourceror, "1.9.0", "3bf5fe2d017aaabe3866d8a6da097dd7c331e0d2d54e59e21c2b066d47f1e08e", [:mix], [], "hexpm", "d20a9dd5efe162f0d75a307146faa2e17b823ea4f134f662358d70f0332fed82"},
"statistex": {:hex, :statistex, "1.0.0", "f3dc93f3c0c6c92e5f291704cf62b99b553253d7969e9a5fa713e5481cd858a5", [:mix], [], "hexpm", "ff9d8bee7035028ab4742ff52fc80a2aa35cece833cf5319009b52f1b5a86c27"},
"stream_data": {:hex, :stream_data, "1.2.0", "58dd3f9e88afe27dc38bef26fce0c84a9e7a96772b2925c7b32cd2435697a52b", [:mix], [], "hexpm", "eb5c546ee3466920314643edf68943a5b14b32d1da9fe01698dc92b73f89a9ed"},
"telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"},
"typed_struct": {:hex, :typed_struct, "0.3.0", "939789e3c1dca39d7170c87f729127469d1315dcf99fee8e152bb774b17e7ff7", [:mix], [], "hexpm", "c50bd5c3a61fe4e198a8504f939be3d3c85903b382bde4865579bc23111d1b6d"},
"websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"},
"websock_adapter": {:hex, :websock_adapter, "0.5.8", "3b97dc94e407e2d1fc666b2fb9acf6be81a1798a2602294aac000260a7c4a47d", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "315b9a1865552212b5f35140ad194e67ce31af45bcee443d4ecb96b5fd3f3782"},
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defimpl Forge.Convertible, for: Forge.Plugin.V1.Diagnostic.Result do
alias Expert.Protocol.Conversions
alias Expert.Protocol.Types
defimpl Forge.Protocol.Convertible, for: Forge.Plugin.V1.Diagnostic.Result do
alias GenLSP.Structures
alias GenLSP.Enumerations.DiagnosticSeverity
alias Forge.Protocol.Conversions
alias Forge.Document
alias Forge.Document.Position
alias Forge.Document.Range
Expand All @@ -10,28 +11,33 @@ defimpl Forge.Convertible, for: Forge.Plugin.V1.Diagnostic.Result do

def to_lsp(%Diagnostic.Result{} = diagnostic) do
with {:ok, lsp_range} <- lsp_range(diagnostic) do
proto_diagnostic = %Types.Diagnostic{
proto_diagnostic = %Structures.Diagnostic{
message: diagnostic.message,
range: lsp_range,
severity: diagnostic.severity,
severity: map_severity(diagnostic.severity),
source: diagnostic.source
}

{:ok, proto_diagnostic}
end
end

defp map_severity(:error), do: DiagnosticSeverity.error()
defp map_severity(:warning), do: DiagnosticSeverity.warning()
defp map_severity(:information), do: DiagnosticSeverity.information()
defp map_severity(:hint), do: DiagnosticSeverity.hint()

def to_native(%Diagnostic.Result{} = diagnostic, _) do
{:ok, diagnostic}
end

defp lsp_range(%Diagnostic.Result{position: %Position{} = position}) do
with {:ok, lsp_start_pos} <- Conversions.to_lsp(position) do
range =
Types.Range.new(
%Structures.Range{
start: lsp_start_pos,
end: Types.Position.new(line: lsp_start_pos.line + 1, character: 0)
)
end: %Structures.Position{line: lsp_start_pos.line + 1, character: 0}
}

{:ok, range}
end
Expand Down
Loading
Loading