Last active
January 17, 2019 16:44
-
-
Save atomkirk/1008a622b73c39014ad3fbe8cea32556 to your computer and use it in GitHub Desktop.
Create Sublime completions file from elixir project
This file contains hidden or 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
defmodule Mix.Tasks.CreateSublimeCompletions do | |
use Mix.Task | |
@moduledoc """ | |
Add this mix file to your project, update `@sublime_dir` and run it periodically to | |
create a Sublime completions file to get fast code completion in Sublime for your Elixir project. | |
""" | |
def run(_args) do | |
create_completions_file() | |
end | |
@sublime_dir "/Users/adamkirk/Dropbox/symlinked/Sublime Text 3/Packages/User" | |
def create_completions_file() do | |
modules = | |
Path.wildcard("lib/**/*.ex") | |
|> Enum.filter(fn | |
"lib/mix/tasks" <> _ -> false | |
_ -> true | |
end) | |
|> Enum.map(& &1 |> File.read!()) | |
|> Enum.flat_map(fn contents -> | |
Regex.scan(~r/defmodule (.*?) do/, contents) | |
|> Enum.flat_map(fn [_, module] -> | |
Regex.scan(~r/def (.*?)\(/, contents) | |
|> Enum.map(fn [_, function] -> | |
"#{module}.#{function}" | |
end) | |
end) | |
end) | |
|> Enum.uniq() | |
File.write!( | |
Path.join(@sublime_dir, "project-modules.sublime-completions"), | |
%{ | |
scope: "source.elixir", | |
completions: modules | |
} |> Jason.encode!() | |
) | |
end | |
end |
Author
atomkirk
commented
Jan 17, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment