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
Integrate functionality from the atom-elixir alchemist-server version #6
Comments
@tonini I can start working on the integration in a couple of days. It would be great if we could eventually refactor the completion lookup or even reimplement it from scratch. During the whole process of creating atom-elixir, autocompletion was the hardest part to extend (and still is). I guess the reason is that it was originally designed only for |
Sounds good to me :) About the completion functionality. We used the autocompletion functionality served by elixir It would be great if you could write down some of the issues which you had, I'm really curious about these. |
@tonini I'm currently adding a couple of features to the parser and also refactoring some parts. I expect to finish this by the end of the week. As soon I get everything working, I'll merge into my alchemist-server fork and create a PR. Regarding the completion implementation, don't worry. As I wrote "we could eventually refactor the completion lookup". It's not a priority right now. I'll write down some of the issues I had when I have a chance ;) Cheers. |
@msaraiva These are great news :) Thanks a lot for all your effort. |
@tonini Quick update: There are two features I'm currently working on:
I'm resuming my work on these features today, so I hope I'll get something stable in the next few days. March was a really hard month for me to do any OSS work. Sorry about that. Cheers. |
Hey @msaraiva This sounds great! 👍 Don't worry, just take your time. Enjoy the weekend. 😄 |
@tonini Ok, let's get started ;) |
@msaraiva this is amazing :D ❤️ 💛 💙 Btw, currently the alchemist-server also uses the complete |
@tonini I just took a look at the new
The current implementation doesn't have any extension point where I can add what I need and, since I don't see Thoughts? |
Hi @msaraiva Sorry for my late response. I think you're right about this. What do you think of implementing your |
Hi @tonini Months ago I started to remove all logic from atom-elixir and moved to a new pure Elixir lib (temporally called ElixirSense) that could be used not only by alchemist and atom but also by vscode or any other editor/tool. The main goal was to create a unified way to introspect information from code/beans and provide that information through a well defined API. All functions available are editor agnostic and exchange not only strings but also compound data types like lists and maps. Any editor specific implementation, e.g. formatting, can be done by the plugin/package's author easily. Here's an example of how defmodule Alchemist.API.Comp do
@moduledoc false
@spec request(String.t) :: no_return
def request(args) do
{{hint, buffer_file, line}, _} = Code.eval_string(args)
buffer = File.read!(buffer_file)
ElixirSense.suggestions(hint, buffer, line)
|> Enum.map(&format_suggestion/1)
|> Enum.each(&IO.puts/1)
IO.puts "END-OF-COMP"
end
defp format_suggestion(%{type: :variable, name: name}) do
"#{name};var"
end
defp format_suggestion(%{type: :attribute, name: name}) do
"#{name};attribute"
end
defp format_suggestion(%{type: :hint, value: value}) do
"#{value};hint"
end
defp format_suggestion(%{type: :module, name: name, subtype: subtype, summary: summary}) do
"#{name};module;#{subtype};#{summary}"
end
defp format_suggestion(%{type: :callback, name: name, arity: arity, args: args, origin: mod_name, summary: desc, spec: spec}) do
"#{name}/#{arity};callback;#{args};#{mod_name};#{desc};#{spec}"
end
defp format_suggestion(%{type: :return, description: description, spec: spec, snippet: snippet}) do
"#{description};return;#{spec};#{snippet}"
end
defp format_suggestion(%{type: type, name: func, arity: arity, args: args, origin: mod_name, summary: summary, spec: spec}) do
"#{func}/#{arity};#{type};#{args};#{mod_name};#{summary};#{spec}"
end
end
The code above actually works and I was using it in atom-elixir for my tests. As you can see, there's no need to do any parsing in the client and you don't need to pass any use/alias/import/behaviour information since the library will handle all that using the new parser. Here's the implementation of @spec suggestions(String.t, String.t, non_neg_integer) :: [Suggestion.suggestion]
def suggestions(hint, code, line) do
buffer_file_metadata = Parser.parse_string(code, true, true, line)
%State.Env{
imports: imports,
aliases: aliases,
vars: vars,
attributes: attributes,
behaviours: behaviours,
module: module,
scope: scope
} = Metadata.get_env(buffer_file_metadata, line)
Suggestion.find(hint, [module|imports], aliases, vars, attributes, behaviours, scope)
end So, basically the only thing we have to do is formatting the result of the available functions. Currently they are: iex> code = ~S'''
...> defmodule MyModule do
...> alias List, as: MyList
...>
...> end
...> '''
iex> ElixirSense.signature("MyList.flatten(par0, ", code, 3)
%{active_param: 1,
signatures: [
%{name: "flatten", params: ["list"]},
%{name: "flatten", params: ["list", "tail"]}]}
Other existing functions in atom-elixir like There are also other things halfway done like function find/refactor using The bad news is that my last commit was about 3 months ago. Since then, I've had practically no time for OSS projects. The good news is that I will try to take a couple of days next week to finish the most important part so people can start using/testing and, depending on the feedback, we can finally release the first version. So, let's see how it goes ;) Cheers. |
you missed an |
Any news/progress on this ? |
Hi all. I've just pushed the first version of ElixirSense. As already mentioned, the final goal is provide a standard, easy to use API for retrieving context-aware information about Elixir code. The project is basically divided in two parts:
This first version has all the existing functionality of
Other information/notes:
The next release of I apologize in case this first release took much longer than expected. Unfortunately, I can only work on this project on my spare time. In case you have any questions, feel free to DM me. /cc @mat-mcloughlin, @fr1zle, @slashmili |
Just awesome! :) I try to get some free time to dive into ElixirSense! |
This looks awesome. |
This looks great! I would be amazing to add this to Emacs. :) I heavily depend upon |
@msaraiva it would be great if we could integrate the
code/parser
and thecode/metabuilder
(and the rest which is needed too) into thealchemist-server
. Then I could start to refactor a lot of the server itself and also simplify theAPI
a lot for example the definition and completion lookup for example. 🎉The text was updated successfully, but these errors were encountered: