Skip to content

Commit

Permalink
Extract execute_in_project_path
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Jan 28, 2025
1 parent 1dfeacf commit 014d49b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/ruby_lsp/tapioca/run_gem_rbi_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def lockfile_changed?
sig { returns(String) }
def fetch_lockfile_diff
@lockfile_diff =
File.exist?("#{project_path}/Gemfile.lock") ? %x(cd #{project_path} && git diff Gemfile.lock).strip : ""
File.exist?("#{project_path}/Gemfile.lock") ? execute_in_project_path("git diff Gemfile.lock").strip : ""
end

sig { void }
Expand Down Expand Up @@ -91,30 +91,33 @@ def remove_rbis(gems)

sig { void }
def cleanup_orphaned_rbis
untracked_files =
%x(cd #{project_path} && git ls-files --others --exclude-standard sorbet/rbi/gems/).lines.map(&:strip)
deleted_files = %x(cd #{project_path} && git ls-files --deleted sorbet/rbi/gems/).lines.map(&:strip)
untracked_files = execute_in_project_path("git ls-files --others --exclude-standard sorbet/rbi/gems/").lines.map(&:strip)
deleted_files = execute_in_project_path("git ls-files --deleted sorbet/rbi/gems/").lines.map(&:strip)

delete_files(untracked_files, "Deleted untracked RBIs")
restore_files(deleted_files, "Restored deleted RBIs")
end

sig { params(files: T::Array[String], message: String).void }
def delete_files(files, message)
files.each { |file| File.delete("#{project_path}/#{file}") }
files.each { |file| execute_in_project_path("rm #{file}") }
log_message("#{message}: #{files.join(", ")}") unless files.empty?
end

sig { params(files: T::Array[String], message: String).void }
def restore_files(files, message)
files.each { |file| %x(cd #{project_path} && git checkout -- #{file}) }
files.each { |file| execute_in_project_path("git checkout -- #{file}") }
log_message("#{message}: #{files.join(", ")}") unless files.empty?
end

sig { params(message: String).void }
def log_message(message)
@stdout += "#{message}\n"
end

def execute_in_project_path(command)
%x(cd #{project_path} && #{command})
end
end
end
end

0 comments on commit 014d49b

Please sign in to comment.