-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a simple remote debugging shell which supplants the debug app we were using previously. This one allows us to connect observer as well. I had to update project node to handle this, as it assumed that _any_ nodedown message was coming from the project node.
- Loading branch information
Showing
13 changed files
with
211 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,156 +1 @@ | ||
alias Lexical.RemoteControl | ||
alias Lexical.Document | ||
alias Lexical.Document.Position | ||
|
||
defmodule Helpers do | ||
alias Lexical.Document.Position | ||
alias Lexical.Project | ||
alias Lexical.Protocol.Types.Completion | ||
alias Lexical.Server.CodeIntelligence | ||
|
||
def observer do | ||
:observer.start() | ||
end | ||
|
||
def observer(project) do | ||
project | ||
|> ensure_project() | ||
|> RemoteControl.call(:observer, :start) | ||
end | ||
|
||
def doc(text) do | ||
doc(:lexical, text) | ||
end | ||
|
||
def doc(project, text) do | ||
root_path = | ||
project | ||
|> project() | ||
|> Project.root_path() | ||
|
||
[root_path, "lib", "file.ex"] | ||
|> Path.join() | ||
|> Document.Path.to_uri() | ||
|> Document.new(text, 0) | ||
end | ||
|
||
def pos(line, character) do | ||
Position.new(line, character) | ||
end | ||
|
||
def compile_project(project) do | ||
project | ||
|> ensure_project() | ||
|> RemoteControl.Api.schedule_compile(true) | ||
end | ||
|
||
def compile_file(project, source) when is_binary(source) do | ||
project | ||
|> ensure_project() | ||
|> compile_file(doc(source)) | ||
end | ||
|
||
def compile_file(project, %Document{} = document) do | ||
project | ||
|> ensure_project() | ||
|> RemoteControl.Api.compile_document(document) | ||
end | ||
|
||
def complete(project, source, context \\ nil) | ||
|
||
def complete(project, source, context) when is_binary(source) do | ||
case completion_position(source) do | ||
{:found, line, character} -> | ||
complete(project, doc(source), line, character, context) | ||
|
||
other -> | ||
other | ||
end | ||
end | ||
|
||
def complete(project, %Document{} = source, line, character, context) do | ||
context = | ||
if is_nil(context) do | ||
Completion.Context.new(trigger_kind: nil) | ||
else | ||
context | ||
end | ||
|
||
position = pos(line, character) | ||
|
||
project | ||
|> ensure_project() | ||
|> CodeIntelligence.Completion.complete(source, position, context) | ||
end | ||
|
||
def connect do | ||
manager_name = manager_name() | ||
Node.start(:"[email protected]") | ||
Node.set_cookie(:lexical) | ||
Node.connect(:"#{manager_name}@127.0.0.1") | ||
end | ||
|
||
def project(project) when is_atom(project) do | ||
project_path = | ||
[File.cwd!(), "..", to_string(project)] | ||
|> Path.join() | ||
|> Path.expand() | ||
|
||
project_uri = "file://#{project_path}" | ||
Lexical.Project.new(project_uri) | ||
end | ||
|
||
def stop_project(project) do | ||
project | ||
|> ensure_project() | ||
|> Lexical.Server.Project.Supervisor.stop() | ||
end | ||
|
||
def start_project(project) do | ||
project | ||
|> ensure_project() | ||
|> Lexical.Server.Project.Supervisor.start() | ||
end | ||
|
||
defp manager_name do | ||
{:ok, names} = :erl_epmd.names() | ||
|
||
names | ||
|> Enum.map(fn {name, _port} -> List.to_string(name) end) | ||
|> Enum.find(&String.starts_with?(&1, "manager")) | ||
end | ||
|
||
defp completion_position(source_string) do | ||
source_string | ||
|> String.split(["\r\n", "\r", "\n"]) | ||
|> Enum.with_index() | ||
|> Enum.reduce_while(:not_found, fn {line, line_number}, _ -> | ||
if String.contains?(line, "|") do | ||
index = | ||
line | ||
|> String.graphemes() | ||
|> Enum.find_index(&(&1 == "|")) | ||
|
||
{:halt, {:found, line_number + 1, index + 1}} | ||
else | ||
{:cont, :not_found} | ||
end | ||
end) | ||
end | ||
|
||
defp ensure_project(%Project{} = project) do | ||
project | ||
end | ||
|
||
defp ensure_project(project) when is_binary(project) do | ||
project | ||
|> String.to_atom() | ||
|> project() | ||
end | ||
|
||
defp ensure_project(project) when is_atom(project) do | ||
project(project) | ||
end | ||
end | ||
|
||
import Helpers | ||
use Lexical.Server.IEx.Helpers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use LXical.Server.IEx.Helpers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.