Skip to content

Commit

Permalink
Don't log errors for NonExistingDocumentError
Browse files Browse the repository at this point in the history
These are expected to happen.
VSCode extensions can registers additional uri schemes
for which they provide content for.
These do not exist on disk which means the server will not find  them in the index.

Happens since Shopify#2334

Also adds a test that virtual documents raise the same error
https://code.visualstudio.com/api/extension-guides/virtual-documents
https://code.visualstudio.com/api/references/document-selector#document-scheme

Closes Shopify#2384
  • Loading branch information
Earlopain committed Aug 3, 2024
1 parent 37814d7 commit a688331
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,9 @@ def process_message(message)
backtrace: e.backtrace&.join("\n"),
},
))
$stderr.puts("Error processing #{message[:method]}: #{e.full_message}")
end
end

$stderr.puts("Error processing #{message[:method]}: #{e.full_message}")
end

sig { void }
Expand Down
5 changes: 3 additions & 2 deletions lib/ruby_lsp/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def get(uri)
document = @state[uri.to_s]
return document unless document.nil?

# For unsaved files (`untitled:Untitled-1` uris), there's no path to read from. If we don't have the untitled file
# already present in the store, then we have to raise non existing document error
# For unsaved files (`untitled:Untitled-1` uris) or virtual documents (extension-contributed schemes), there's no
# path to read from. If we don't have the untitled file already present in the store, then we have to raise
# non existing document error
path = uri.to_standardized_path
raise NonExistingDocumentError, uri.to_s unless path

Expand Down
8 changes: 8 additions & 0 deletions test/store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,12 @@ def test_raises_non_existing_document_error_on_unknown_unsaved_files
@store.get(URI("untitled:Untitled-1"))
end
end

def test_raises_non_existing_document_error_for_virtual_documents
uri =
"sorbet:https%3A//github.com/sorbet/sorbet/tree/090ed6096a83dd7a5fe52bd3f9338c1eca5178eb/rbi/core/constants.rbi"
assert_raises(RubyLsp::Store::NonExistingDocumentError) do
@store.get(URI(uri))
end
end
end

0 comments on commit a688331

Please sign in to comment.