Skip to content

Commit

Permalink
Move erb? to Support::Common module and address RuboCop warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoroth committed Nov 13, 2023
1 parent 9b0cfc4 commit 4db50dd
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 18 deletions.
5 changes: 2 additions & 3 deletions lib/ruby_lsp/requests/definition.rb
Expand Up @@ -150,9 +150,8 @@ def find_in_index(value)
# additional behavior on top of jumping to RBIs. Sorbet can already handle go to definition for all constants
# in the project, even if the files are typed false
file_path = entry.file_path
if DependencyDetector.instance.typechecker_for_uri?(@uri) && bundle_path && !file_path.start_with?(bundle_path) &&
!file_path.start_with?(RbConfig::CONFIG["rubylibdir"])

if DependencyDetector.instance.typechecker_for_uri?(@uri) && bundle_path &&
!file_path.start_with?(bundle_path) && !file_path.start_with?(RbConfig::CONFIG["rubylibdir"])
next
end

Expand Down
5 changes: 5 additions & 0 deletions lib/ruby_lsp/requests/support/common.rb
Expand Up @@ -98,6 +98,11 @@ def markdown_from_index_entries(title, entries)
MARKDOWN
)
end

sig { params(uri: URI::Generic).returns(T::Boolean) }
def erb?(uri)
uri.to_s.match?(/\.(?:erb|rhtml|rhtm)$/)
end
end
end
end
Expand Down
8 changes: 1 addition & 7 deletions lib/ruby_lsp/requests/support/dependency_detector.rb
Expand Up @@ -6,6 +6,7 @@
module RubyLsp
class DependencyDetector
include Singleton
include Support::Common
extend T::Sig

sig { returns(String) }
Expand Down Expand Up @@ -89,12 +90,5 @@ def gemspec_dependencies
.grep(Bundler::Source::Gemspec)
.flat_map { _1.gemspec&.dependencies&.map(&:name) }
end

private

sig { params(uri: URI::Generic).returns(T::Boolean) }
def erb?(uri)
uri.to_s.match?(/\.(?:erb|rhtml|rhtm)$/)
end
end
end
5 changes: 2 additions & 3 deletions lib/ruby_lsp/requests/workspace_symbol.rb
Expand Up @@ -40,9 +40,8 @@ def run
# If the project is using Sorbet, we let Sorbet handle symbols defined inside the project itself and RBIs, but
# we still return entries defined in gems to allow developers to jump directly to the source
file_path = entry.file_path
if DependencyDetector.instance.typechecker_for_uri?(@uri) && bundle_path && !file_path.start_with?(bundle_path) &&
!file_path.start_with?(RbConfig::CONFIG["rubylibdir"])

if DependencyDetector.instance.typechecker_for_uri?(@uri) && bundle_path &&
!file_path.start_with?(bundle_path) && !file_path.start_with?(RbConfig::CONFIG["rubylibdir"])
next
end

Expand Down
6 changes: 1 addition & 5 deletions lib/ruby_lsp/store.rb
Expand Up @@ -4,6 +4,7 @@
module RubyLsp
class Store
extend T::Sig
include Support::Common

sig { returns(String) }
attr_accessor :encoding
Expand Down Expand Up @@ -77,10 +78,5 @@ def delete(uri)
def cache_fetch(uri, request_name, &block)
get(uri).cache_fetch(request_name, &block)
end

sig { params(uri: URI::Generic).returns(T::Boolean) }
def erb?(uri)
uri.to_s.match?(/\.(?:erb|rhtml|rhtm)$/)
end
end
end

0 comments on commit 4db50dd

Please sign in to comment.