rubylens 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,19 +22,25 @@ module RubyLens
22
22
  end
23
23
 
24
24
  def selected_files
25
- output, status = capture("ls-files", "-z", "--cached", "--others", "--exclude-standard")
25
+ arguments = ["ls-files", "-z", "--cached", "--others", "--exclude-standard"]
26
+ unless @target_root == @git_root
27
+ relative_target = @target_root.relative_path_from(@git_root)
28
+ arguments.concat(["--", ":(literal)#{relative_target}"])
29
+ end
30
+ output, status = capture(*arguments)
26
31
  raise GitError, "failed to enumerate tracked and unignored files" unless status.success?
27
32
 
33
+ git_root = @git_root.to_s
34
+ target_root = @target_root.to_s
28
35
  output.split("\0").filter_map do |relative_to_git|
29
36
  next unless INDEXABLE_EXTENSIONS.include?(File.extname(relative_to_git))
30
37
 
31
- absolute = @git_root.join(relative_to_git).cleanpath
32
- next unless Paths.inside?(absolute, @target_root)
33
- next unless absolute.file?
34
- resolved = absolute.realpath
35
- next unless Paths.inside?(resolved, @target_root.realpath)
38
+ absolute = File.join(git_root, relative_to_git)
39
+ next unless File.file?(absolute)
40
+ resolved = File.realpath(absolute)
41
+ next unless Paths.inside?(resolved, target_root)
36
42
 
37
- resolved.to_s
43
+ resolved
38
44
  rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP
39
45
  nil
40
46
  end.sort
@@ -70,10 +70,11 @@ module RubyLens
70
70
 
71
71
  def package_index_for(path)
72
72
  path = path.to_s
73
- return @package_index_by_file[path] if @package_index_by_file.key?(path)
74
- return @package_index_cache[path] if @package_index_cache.key?(path)
75
-
76
- @package_index_cache[path] = uncached_package_index_for(path)
73
+ @package_index_by_file.fetch(path) do
74
+ @package_index_cache.fetch(path) do
75
+ @package_index_cache[path] = uncached_package_index_for(path)
76
+ end
77
+ end
77
78
  rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP
78
79
  nil
79
80
  end
@@ -84,9 +85,9 @@ module RubyLens
84
85
 
85
86
  def relative_workspace_path(path)
86
87
  path = path.to_s
87
- return @relative_workspace_path_cache[path] if @relative_workspace_path_cache.key?(path)
88
-
89
- @relative_workspace_path_cache[path] = uncached_relative_workspace_path(path)
88
+ @relative_workspace_path_cache.fetch(path) do
89
+ @relative_workspace_path_cache[path] = uncached_relative_workspace_path(path)
90
+ end
90
91
  end
91
92
 
92
93
  private
@@ -11,28 +11,24 @@ module RubyLens
11
11
  SPEC_SEGMENTS = Set.new(%w[spec specs]).freeze
12
12
  PROXY_NAME_PREFIX = "RSpec example group #"
13
13
 
14
- Group = Data.define(:name, :component)
15
14
  Result = Data.define(:groups, :method_count)
16
15
 
17
- def initialize(graph:, manifest:, package_document_paths: Set.new)
16
+ def initialize(graph:, manifest:, package_document_paths: Set.new, documents_with_paths: nil)
18
17
  @graph = graph
19
18
  @manifest = manifest
20
19
  @package_document_paths = package_document_paths
20
+ @documents_with_paths = documents_with_paths
21
21
  end
22
22
 
23
23
  def call
24
24
  groups = []
25
25
  method_count = 0
26
26
 
27
- spec_documents.each do |document, relative|
27
+ spec_documents.each do |document, _relative|
28
28
  group_count, example_count = reference_counts(document.method_references)
29
29
  method_count += example_count
30
- component = SourcePath.component_for(relative)
31
30
  group_count.times do
32
- groups << Group.new(
33
- format("%s%06d", PROXY_NAME_PREFIX, groups.length + 1),
34
- component,
35
- )
31
+ groups << format("%s%06d", PROXY_NAME_PREFIX, groups.length + 1)
36
32
  end
37
33
  end
38
34
 
@@ -41,10 +37,16 @@ module RubyLens
41
37
 
42
38
  private
43
39
 
40
+ # The adapter passes its already-resolved [document, path] pairs so the
41
+ # documents are not re-enumerated and their URIs not re-parsed here;
42
+ # standalone construction still resolves them from the graph.
44
43
  def spec_documents
45
- @graph.documents.filter_map do |document|
44
+ pairs = @documents_with_paths || @graph.documents.filter_map do |document|
46
45
  path = SourcePath.from_file_uri(document.uri)
47
- next unless path && @manifest.workspace_path?(path)
46
+ [document, path] if path
47
+ end
48
+ pairs.filter_map do |document, path|
49
+ next unless @manifest.workspace_path?(path)
48
50
  next if @package_document_paths.include?(path)
49
51
 
50
52
  relative = @manifest.relative_workspace_path(path)