Skip to content

Commit

Permalink
Merge branch 'Shopify:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannism20 authored Sep 20, 2023
2 parents fa10565 + f3c601e commit bdd9079
Show file tree
Hide file tree
Showing 21 changed files with 1,214 additions and 154 deletions.
15 changes: 12 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ updates:
groups:
minor-and-patch:
update-types:
- 'minor'
- 'patch'
- "minor"
- "patch"
exclude-patterns:
- 'yarp'
- "yarp"
- package-ecosystem: "gitsubmodule"
directory: "/"
schedule:
interval: "weekly"
reviewers:
- "Shopify/ruby-dev-exp"
labels:
- "dependencies"
- "fixtures"
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
name: Ruby ${{ matrix.ruby }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
submodules: "recursive"

- name: Set up Ruby
uses: ruby/setup-ruby@v1
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "test/fixtures/yarp"]
path = test/fixtures/yarp
url = https://github.com/ruby/yarp.git
18 changes: 9 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ GEM
rubocop (>= 0.90.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sorbet (0.5.11026)
sorbet-static (= 0.5.11026)
sorbet-runtime (0.5.11026)
sorbet-static (0.5.11026-universal-darwin)
sorbet-static (0.5.11026-x86_64-linux)
sorbet-static-and-runtime (0.5.11026)
sorbet (= 0.5.11026)
sorbet-runtime (= 0.5.11026)
sorbet (0.5.11032)
sorbet-static (= 0.5.11032)
sorbet-runtime (0.5.11032)
sorbet-static (0.5.11032-universal-darwin)
sorbet-static (0.5.11032-x86_64-linux)
sorbet-static-and-runtime (0.5.11032)
sorbet (= 0.5.11032)
sorbet-runtime (= 0.5.11032)
spoom (1.2.4)
erubi (>= 1.10.0)
sorbet-static-and-runtime (>= 0.5.10187)
syntax_tree (>= 6.1.1)
thor (>= 0.19.2)
stringio (3.0.7)
syntax_tree (6.1.1)
syntax_tree (6.2.0)
prettier_print (>= 1.2.0)
tapioca (0.11.9)
bundler (>= 2.2.25)
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require "ruby_lsp/check_docs"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb", "lib/ruby_indexer/test/**/*_test.rb"]
t.test_files = FileList["test/**/*_test.rb", "lib/ruby_indexer/test/**/*_test.rb"].exclude("test/fixtures/yarp/**/*")
end

RDoc::Task.new do |rdoc|
Expand Down
8 changes: 8 additions & 0 deletions bin/test
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/usr/bin/env bash

YARP_FIXTURES_DIR=test/fixtures/yarp/test/yarp/fixtures

if [ ! -d "$YARP_FIXTURES_DIR" ]; then
echo "$YARP_FIXTURES_DIR does not exist."
echo "Please run 'git submodule update --init' to pull submodule fixtures."
exit 1
fi

if [[ 2 -eq $# ]]; then
bundle exec rake TEST="$1" TESTOPTS="-n='/$2/'"
elif [[ 1 -eq $# ]]; then
Expand Down
4 changes: 3 additions & 1 deletion lib/ruby_lsp/requests/code_action_resolve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def initialize(document, code_action)

sig { override.returns(T.any(Interface::CodeAction, Error)) }
def run
return Error::EmptySelection if @document.source.empty?

source_range = @code_action.dig(:data, :range)
return Error::EmptySelection if source_range[:start] == source_range[:end]

Expand All @@ -55,7 +57,7 @@ def run
closest_statements, parent_statements = @document
.locate(@document.tree, start_index, node_types: [YARP::StatementsNode, YARP::BlockNode])

return Error::InvalidTargetRange if closest_statements.nil?
return Error::InvalidTargetRange if closest_statements.nil? || closest_statements.child_nodes.compact.empty?

# Find the node with the end line closest to the requested position, so that we can place the refactor
# immediately after that closest node
Expand Down
5 changes: 5 additions & 0 deletions lib/ruby_lsp/requests/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def on_constant_path(node)

candidates = @index.prefix_search(name, top_level_reference ? [] : @nesting)
candidates.each do |entries|
# The only time we may have a private constant reference from outside of the namespace is if we're dealing
# with ConstantPath and the entry name doesn't start with the current nesting
first_entry = T.must(entries.first)
next if first_entry.visibility == :private && !first_entry.name.start_with?("#{@nesting}::")

@_response << build_entry_completion(
name,
node,
Expand Down
5 changes: 5 additions & 0 deletions lib/ruby_lsp/requests/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ def find_in_index(value)
entries = @index.resolve(value, @nesting)
return unless entries

# We should only allow jumping to the definition of private constants if the constant is defined in the same
# namespace as the reference
first_entry = T.must(entries.first)
return if first_entry.visibility == :private && first_entry.name != "#{@nesting.join("::")}::#{value}"

bundle_path = begin
Bundler.bundle_path.to_s
rescue Bundler::GemfileNotFound
Expand Down
5 changes: 5 additions & 0 deletions lib/ruby_lsp/requests/hover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def generate_hover(name, location)
entries = @index.resolve(name, @nesting)
return unless entries

# We should only show hover for private constants if the constant is defined in the same namespace as the
# reference
first_entry = T.must(entries.first)
return if first_entry.visibility == :private && first_entry.name != "#{@nesting.join("::")}::#{name}"

@_response = Interface::Hover.new(
range: range_from_location(location),
contents: markdown_from_index_entries(name, entries),
Expand Down
13 changes: 9 additions & 4 deletions lib/ruby_lsp/requests/support/rubocop_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ class InternalRuboCopError < StandardError
extend T::Sig

MESSAGE = <<~EOS
An internal error occurred for the %s cop.
An internal error occurred %s.
Updating to a newer version of RuboCop may solve this.
For more details, run RuboCop on the command line.
EOS

sig { params(rubocop_error: RuboCop::ErrorWithAnalyzedFileLocation).void }
sig { params(rubocop_error: T.any(RuboCop::ErrorWithAnalyzedFileLocation, StandardError)).void }
def initialize(rubocop_error)
message = format(MESSAGE, rubocop_error.cop.name)
message = case rubocop_error
when RuboCop::ErrorWithAnalyzedFileLocation
format(MESSAGE, "for the #{rubocop_error.cop.name} cop")
when StandardError
format(MESSAGE, rubocop_error.message)
end
super(message)
end
end
Expand Down Expand Up @@ -87,7 +92,7 @@ def run(path, contents)
raise Formatting::Error, error.message
rescue RuboCop::ValidationError => error
raise ConfigurationError, error.message
rescue RuboCop::ErrorWithAnalyzedFileLocation => error
rescue StandardError => error
raise InternalRuboCopError, error
end

Expand Down
3 changes: 3 additions & 0 deletions lib/ruby_lsp/requests/workspace_symbol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def run
next
end

# We should never show private symbols when searching the entire workspace
next if entry.visibility == :private

kind = kind_for_entry(entry)
loc = entry.location

Expand Down
Loading

0 comments on commit bdd9079

Please sign in to comment.