Skip to content
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

WIP: Test discovery file watching #3226

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
18 changes: 17 additions & 1 deletion lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def process_message(message)
when "rubyLsp/diagnoseState"
diagnose_state(message)
when "rubyLsp/discoverTests"
send_log_message("got rubyLsp/discoverTests")
discover_tests(message)
when "$/cancelRequest"
@global_state.synchronize { @cancelled_requests << message[:params][:id] }
Expand Down Expand Up @@ -1057,13 +1058,21 @@ def handle_ruby_file_change(index, file_path, change_type)
# If we receive a late created notification for a file that has already been claimed by the client, we want to
# handle change for that URI so that the require path tree is updated
@store.key?(uri) ? index.handle_change(uri, content) : index.index_single(uri, content)
if file_path.include?("test/") # TODO: improve check
send_log_message("new test: #{uri}")
discover_tests(params: { textDocument: { uri: uri } })
end
when Constant::FileChangeType::CHANGED
content = File.read(file_path)
# We only handle changes on file watched notifications if the client is not the one managing this URI.
# Otherwise, these changes are handled when running the combined requests
index.handle_change(uri, content) unless @store.key?(uri)
when Constant::FileChangeType::DELETED
index.delete(uri)
if file_path.include?("test/") # TODO: improve check
send_log_message("test deleted: #{uri}")
discover_tests(params: { textDocument: { uri: uri } })
end
end
rescue Errno::ENOENT
# If a file is created and then delete immediately afterwards, we will process the created notification before we
Expand Down Expand Up @@ -1396,7 +1405,14 @@ def diagnose_state(message)
# all add-ons
sig { params(message: T::Hash[Symbol, T.untyped]).void }
def discover_tests(message)
document = @store.get(message.dig(:params, :textDocument, :uri))
send_log_message("*** discover_tests: #{message}")

begin
document = @store.get(message.dig(:params, :textDocument, :uri))
rescue RubyLsp::Store::NonExistingDocumentError
send_log_message("deosn't exist")
return
end

unless document.is_a?(RubyDocument)
send_empty_response(message[:id])
Expand Down