Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions apps/language_server/lib/language_server/source_file/path.ex
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ defmodule ElixirLS.LanguageServer.SourceFile.Path do

# This function expects absolute paths with universal separators
def path_in_dir?(file, dir) do
dir = if dir == "/", do: "/", else: String.trim_trailing(dir, "/")

case String.starts_with?(file, dir) do
true ->
# Get the grapheme after the directory in the file path
Expand Down
14 changes: 14 additions & 0 deletions apps/language_server/test/source_file/path_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,18 @@ defmodule ElixirLS.LanguageServer.SourceFile.PathTest do
end
end
end

describe "path_in_dir?/2" do
test "matches regardless of trailing slash" do
assert path_in_dir?("/foo/bar.ex", "/foo")
assert path_in_dir?("/foo/bar.ex", "/foo/")
assert path_in_dir?("c:/foo/bar.ex", "c:/foo")
assert path_in_dir?("c:/foo/bar.ex", "c:/foo/")
end

test "non-matching paths" do
refute path_in_dir?("/foobar/baz.ex", "/foo")
refute path_in_dir?("/foobar/baz.ex", "/foo/")
end
end
end
Loading