Skip to content
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

Excluded source files in build directory #610

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions apps/remote_control/lib/lexical/remote_control/search/indexer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule Lexical.RemoteControl.Search.Indexer do

project_files =
project
|> indexable_files
|> indexable_files()
|> MapSet.new()

previously_indexed_paths = MapSet.new(path_to_ids, fn {path, _} -> path end)
Expand Down Expand Up @@ -176,10 +176,12 @@ defmodule Lexical.RemoteControl.Search.Indexer do

def indexable_files(%Project{} = project) do
root_dir = Project.root_path(project)
build_dir = build_dir()

[root_dir, "**", @indexable_extensions]
|> Path.join()
|> Path.wildcard()
|> Enum.reject(&contained_in?(&1, build_dir))
end

# stat(path) is here for testing so it can be mocked
Expand All @@ -188,9 +190,7 @@ defmodule Lexical.RemoteControl.Search.Indexer do
end

defp contained_in?(file_path, possible_parent) do
normalized_path = file_path

String.starts_with?(normalized_path, possible_parent)
String.starts_with?(file_path, possible_parent)
end

defp deps_dir do
Expand All @@ -199,4 +199,11 @@ defmodule Lexical.RemoteControl.Search.Indexer do
_ -> Mix.Project.deps_path()
end
end

defp build_dir do
case RemoteControl.Mix.in_project(&Mix.Project.build_path/0) do
{:ok, path} -> path
_ -> Mix.Project.build_path()
end
end
end
Loading