Skip to content

Pick up changes from .rubocop-todo.yml #3625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions lib/ruby_lsp/requests/support/rubocop_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class ConfigurationError < StandardError; end
"RuboCop::Formatter::BaseFormatter", # Suppress any output by using the base formatter
] #: Array[String]

CONFIG_FILES = [
".rubocop.yml",
".rubocop",
".rubocop_todo.yml",
] #: Array[String]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's freeze it because then Sorbet will automatically know that this is a 3 element Tuple of strings instead of an array of arbitrary size.

Suggested change
] #: Array[String]
].freeze


#: Array[::RuboCop::Cop::Offense]
attr_reader :offenses

Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def run_initialize(message)
@current_request_id,
Interface::RelativePattern.new(
base_uri: @global_state.workspace_uri.to_s,
pattern: "{.rubocop.yml,.rubocop}",
pattern: "{#{Requests::Support::RuboCopRunner::CONFIG_FILES.join(",")}}",
),
registration_id: "rubocop-watcher",
))
Expand Down Expand Up @@ -1058,7 +1058,7 @@ def workspace_did_change_watched_files(message)

file_name = File.basename(file_path)

if file_name == ".rubocop.yml" || file_name == ".rubocop"
if defined?(Requests::Support::RuboCopRunner) && Requests::Support::RuboCopRunner::CONFIG_FILES.include?(file_name)
handle_rubocop_config_change(uri)
end
end
Expand Down
58 changes: 43 additions & 15 deletions test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1123,8 +1123,6 @@ def test_edits_outside_of_declarations_do_not_trigger_indexing
end

def test_rubocop_config_changes_trigger_workspace_diagnostic_refresh
uri = URI::Generic.from_path(path: File.join(Dir.pwd, ".rubocop.yml"))

@server.process_message({
id: 1,
method: "initialize",
Expand All @@ -1140,20 +1138,10 @@ def test_rubocop_config_changes_trigger_workspace_diagnostic_refresh
})

@server.global_state.index.index_all(uris: [])
@server.process_message({
method: "workspace/didChangeWatchedFiles",
params: {
changes: [
{
uri: uri,
type: RubyLsp::Constant::FileChangeType::CHANGED,
},
],
},
})

request = find_message(RubyLsp::Request)
assert_equal("workspace/diagnostic/refresh", request.method)
RubyLsp::Requests::Support::RuboCopRunner::CONFIG_FILES.each do |config_file|
assert_rubocop_config_triggers_diagnostic_refresh_without_setup(config_file)
end
end

def test_compose_bundle_creates_file_to_skip_next_compose
Expand Down Expand Up @@ -1712,6 +1700,46 @@ def deactivate; end
end
end

def assert_rubocop_config_triggers_diagnostic_refresh(config_file)
uri = URI::Generic.from_path(path: File.join(Dir.pwd, config_file))

@server.process_message({
id: 1,
method: "initialize",
params: {
initializationOptions: {},
capabilities: {
general: {
positionEncodings: ["utf-8"],
},
workspace: { diagnostics: { refreshSupport: true } },
},
},
})

@server.global_state.index.index_all(uris: [])
assert_rubocop_config_triggers_diagnostic_refresh_without_setup(config_file)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert_rubocop_config_triggers_diagnostic_refresh_without_setup(config_file)
assert_rubocop_config_triggers_diagnostic_refresh_without_setup(uri)

end

def assert_rubocop_config_triggers_diagnostic_refresh_without_setup(config_file)
uri = URI::Generic.from_path(path: File.join(Dir.pwd, config_file))

Comment on lines +1724 to +1726
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def assert_rubocop_config_triggers_diagnostic_refresh_without_setup(config_file)
uri = URI::Generic.from_path(path: File.join(Dir.pwd, config_file))
def assert_rubocop_config_triggers_diagnostic_refresh_without_setup(uri)

@server.process_message({
method: "workspace/didChangeWatchedFiles",
params: {
changes: [
{
uri: uri,
type: RubyLsp::Constant::FileChangeType::CHANGED,
},
],
},
})

request = find_message(RubyLsp::Request)
assert_equal("workspace/diagnostic/refresh", request.method)
end

#: (Class desired_class, ?String? desired_method, ?id: Integer?) -> untyped
def find_message(desired_class, desired_method = nil, id: nil)
message = @server.pop_response
Expand Down
Loading