Skip to content

Instantly share code, notes, and snippets.

@atomkirk
Last active January 17, 2019 16:44
Show Gist options
  • Save atomkirk/1008a622b73c39014ad3fbe8cea32556 to your computer and use it in GitHub Desktop.
Save atomkirk/1008a622b73c39014ad3fbe8cea32556 to your computer and use it in GitHub Desktop.
Create Sublime completions file from elixir project
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
@atomkirk
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment