Skip to content

Commit 415d384

Browse files
Revert "Fail requests that are searching for a non existing position (#2938)"
This reverts commit 0d421a6. Co-authored-by: Vinicius Stock <vinistock@users.noreply.github.com>
1 parent bad03fb commit 415d384

File tree

4 files changed

+2
-77
lines changed

4 files changed

+2
-77
lines changed

lib/ruby_lsp/document.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ module RubyLsp
77
class Document
88
extend T::Generic
99

10-
class LocationNotFoundError < StandardError; end
11-
1210
# This maximum number of characters for providing expensive features, like semantic highlighting and diagnostics.
1311
# This is the same number used by the TypeScript extension in VS Code
1412
MAXIMUM_CHARACTERS_FOR_EXPENSIVE_FEATURES = 100_000
@@ -186,15 +184,7 @@ def initialize(source, encoding)
186184
def find_char_position(position)
187185
# Find the character index for the beginning of the requested line
188186
until @current_line == position[:line]
189-
until LINE_BREAK == @source[@pos]
190-
@pos += 1
191-
192-
if @pos >= @source.length
193-
# Pack the code points back into the original string to provide context in the error message
194-
raise LocationNotFoundError, "Requested position: #{position}\nSource:\n\n#{@source.pack("U*")}"
195-
end
196-
end
197-
187+
@pos += 1 until LINE_BREAK == @source[@pos]
198188
@pos += 1
199189
@current_line += 1
200190
end

lib/ruby_lsp/server.rb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,12 @@ def process_message(message)
121121
# If a document is deleted before we are able to process all of its enqueued requests, we will try to read it
122122
# from disk and it raise this error. This is expected, so we don't include the `data` attribute to avoid
123123
# reporting these to our telemetry
124-
case e
125-
when Store::NonExistingDocumentError
124+
if e.is_a?(Store::NonExistingDocumentError)
126125
send_message(Error.new(
127126
id: message[:id],
128127
code: Constant::ErrorCodes::INVALID_PARAMS,
129128
message: e.full_message,
130129
))
131-
when Document::LocationNotFoundError
132-
send_message(Error.new(
133-
id: message[:id],
134-
code: Constant::ErrorCodes::REQUEST_FAILED,
135-
message: <<~MESSAGE,
136-
Request #{message[:method]} failed to find the target position.
137-
The file might have been modified while the server was in the middle of searching for the target.
138-
If you experience this regularly, please report any findings and extra information on
139-
https://github.com/Shopify/ruby-lsp/issues/2446
140-
MESSAGE
141-
))
142130
else
143131
send_message(Error.new(
144132
id: message[:id],

test/ruby_document_test.rb

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -774,29 +774,6 @@ class Foo
774774
assert_nil(document.cache_get("textDocument/codeLens"))
775775
end
776776

777-
def test_locating_a_non_existing_location_raises
778-
document = RubyLsp::RubyDocument.new(source: <<~RUBY.chomp, version: 1, uri: @uri, global_state: @global_state)
779-
class Foo
780-
end
781-
RUBY
782-
783-
# Exactly at the last character doesn't raise
784-
document.locate_node({ line: 1, character: 2 })
785-
786-
# Anything beyond does
787-
error = assert_raises(RubyLsp::Document::LocationNotFoundError) do
788-
document.locate_node({ line: 3, character: 2 })
789-
end
790-
791-
assert_match(/Requested position: {(:)?line[\s:=>]+3, (:)?character[\s:=>]+2}/, error.message)
792-
assert_match(<<~MESSAGE.chomp, error.message)
793-
Source:
794-
795-
class Foo
796-
end
797-
MESSAGE
798-
end
799-
800777
def test_document_tracks_latest_edit_context
801778
document = RubyLsp::RubyDocument.new(source: +<<~RUBY, version: 1, uri: @uri, global_state: @global_state)
802779
class Foo

test/server_test.rb

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -893,36 +893,6 @@ def handle_window_show_message_response(title)
893893
end
894894
end
895895

896-
def test_requests_to_a_non_existing_position_return_error
897-
uri = URI("file:///foo.rb")
898-
899-
@server.process_message({
900-
method: "textDocument/didOpen",
901-
params: {
902-
textDocument: {
903-
uri: uri,
904-
text: "class Foo\nend",
905-
version: 1,
906-
languageId: "ruby",
907-
},
908-
},
909-
})
910-
911-
@server.process_message({
912-
id: 1,
913-
method: "textDocument/completion",
914-
params: {
915-
textDocument: {
916-
uri: uri,
917-
},
918-
position: { line: 10, character: 0 },
919-
},
920-
})
921-
922-
error = find_message(RubyLsp::Error)
923-
assert_match("Request textDocument/completion failed to find the target position.", error.message)
924-
end
925-
926896
def test_cancelling_requests_returns_nil
927897
uri = URI("file:///foo.rb")
928898

0 commit comments

Comments
 (0)