Skip to content

Commit 7131bca

Browse files
committed
Pick up changes from .rubocop-todo.yml
1 parent 0318a74 commit 7131bca

File tree

2 files changed

+67
-49
lines changed

2 files changed

+67
-49
lines changed

lib/ruby_lsp/server.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def run_initialize(message)
310310
@current_request_id,
311311
Interface::RelativePattern.new(
312312
base_uri: @global_state.workspace_uri.to_s,
313-
pattern: "{.rubocop.yml,.rubocop}",
313+
pattern: "{.rubocop.yml,.rubocop,.rubocop_todo.yml}",
314314
),
315315
registration_id: "rubocop-watcher",
316316
))
@@ -1058,7 +1058,7 @@ def workspace_did_change_watched_files(message)
10581058

10591059
file_name = File.basename(file_path)
10601060

1061-
if file_name == ".rubocop.yml" || file_name == ".rubocop"
1061+
if file_name == ".rubocop.yml" || file_name == ".rubocop" || file_name == ".rubocop_todo.yml"
10621062
handle_rubocop_config_change(uri)
10631063
end
10641064
end

test/server_test.rb

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,10 @@ def test_changed_file_only_indexes_ruby
502502
uri: URI("file:///.rubocop.yml"),
503503
type: RubyLsp::Constant::FileChangeType::CREATED,
504504
},
505+
{
506+
uri: URI("file:///.rubocop_todo.yml"),
507+
type: RubyLsp::Constant::FileChangeType::CREATED,
508+
},
505509
],
506510
},
507511
})
@@ -619,23 +623,11 @@ def version
619623
end
620624

621625
def test_did_change_watched_files_processes_unique_change_entries
622-
@server.global_state.index.index_all(uris: [])
623-
@server.expects(:handle_rubocop_config_change).once
624-
@server.process_message({
625-
method: "workspace/didChangeWatchedFiles",
626-
params: {
627-
changes: [
628-
{
629-
uri: URI::Generic.from_path(path: File.join(Dir.pwd, ".rubocop.yml")).to_s,
630-
type: RubyLsp::Constant::FileChangeType::CHANGED,
631-
},
632-
{
633-
uri: URI::Generic.from_path(path: File.join(Dir.pwd, ".rubocop.yml")).to_s,
634-
type: RubyLsp::Constant::FileChangeType::CHANGED,
635-
},
636-
],
637-
},
638-
})
626+
assert_rubocop_config_handles_unique_change_entries(".rubocop.yml")
627+
end
628+
629+
def test_did_change_watched_files_processes_unique_change_entries_for_rubocop_todo
630+
assert_rubocop_config_handles_unique_change_entries(".rubocop_todo.yml")
639631
end
640632

641633
def test_workspace_addons
@@ -1123,37 +1115,11 @@ def test_edits_outside_of_declarations_do_not_trigger_indexing
11231115
end
11241116

11251117
def test_rubocop_config_changes_trigger_workspace_diagnostic_refresh
1126-
uri = URI::Generic.from_path(path: File.join(Dir.pwd, ".rubocop.yml"))
1127-
1128-
@server.process_message({
1129-
id: 1,
1130-
method: "initialize",
1131-
params: {
1132-
initializationOptions: {},
1133-
capabilities: {
1134-
general: {
1135-
positionEncodings: ["utf-8"],
1136-
},
1137-
workspace: { diagnostics: { refreshSupport: true } },
1138-
},
1139-
},
1140-
})
1141-
1142-
@server.global_state.index.index_all(uris: [])
1143-
@server.process_message({
1144-
method: "workspace/didChangeWatchedFiles",
1145-
params: {
1146-
changes: [
1147-
{
1148-
uri: uri,
1149-
type: RubyLsp::Constant::FileChangeType::CHANGED,
1150-
},
1151-
],
1152-
},
1153-
})
1118+
assert_rubocop_config_triggers_diagnostic_refresh(".rubocop.yml")
1119+
end
11541120

1155-
request = find_message(RubyLsp::Request)
1156-
assert_equal("workspace/diagnostic/refresh", request.method)
1121+
def test_rubocop_todo_config_changes_trigger_workspace_diagnostic_refresh
1122+
assert_rubocop_config_triggers_diagnostic_refresh(".rubocop_todo.yml")
11571123
end
11581124

11591125
def test_compose_bundle_creates_file_to_skip_next_compose
@@ -1712,6 +1678,58 @@ def deactivate; end
17121678
end
17131679
end
17141680

1681+
def assert_rubocop_config_handles_unique_change_entries(config_file)
1682+
@server.global_state.index.index_all(uris: [])
1683+
@server.expects(:handle_rubocop_config_change).once
1684+
@server.process_message({
1685+
method: "workspace/didChangeWatchedFiles",
1686+
params: {
1687+
changes: [
1688+
{
1689+
uri: URI::Generic.from_path(path: File.join(Dir.pwd, config_file)).to_s,
1690+
type: RubyLsp::Constant::FileChangeType::CHANGED,
1691+
},
1692+
{
1693+
uri: URI::Generic.from_path(path: File.join(Dir.pwd, config_file)).to_s,
1694+
type: RubyLsp::Constant::FileChangeType::CHANGED,
1695+
},
1696+
],
1697+
},
1698+
})
1699+
end
1700+
1701+
def assert_rubocop_config_triggers_diagnostic_refresh(config_file)
1702+
@server.process_message({
1703+
id: 1,
1704+
method: "initialize",
1705+
params: {
1706+
initializationOptions: {},
1707+
capabilities: {
1708+
general: {
1709+
positionEncodings: ["utf-8"],
1710+
},
1711+
workspace: { diagnostics: { refreshSupport: true } },
1712+
},
1713+
},
1714+
})
1715+
1716+
@server.global_state.index.index_all(uris: [])
1717+
@server.process_message({
1718+
method: "workspace/didChangeWatchedFiles",
1719+
params: {
1720+
changes: [
1721+
{
1722+
uri: URI::Generic.from_path(path: File.join(Dir.pwd, config_file)).to_s,
1723+
type: RubyLsp::Constant::FileChangeType::CHANGED,
1724+
},
1725+
],
1726+
},
1727+
})
1728+
1729+
request = find_message(RubyLsp::Request)
1730+
assert_equal("workspace/diagnostic/refresh", request.method)
1731+
end
1732+
17151733
#: (Class desired_class, ?String? desired_method, ?id: Integer?) -> untyped
17161734
def find_message(desired_class, desired_method = nil, id: nil)
17171735
message = @server.pop_response

0 commit comments

Comments
 (0)