Skip to content
Merged
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
2 changes: 1 addition & 1 deletion lib/ruby_lsp/global_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def apply_options(options)
Encoding::UTF_16LE
else
@graph.encoding = "utf32"
Encoding::UTF_32
Encoding::UTF_32LE
end
@index.configuration.encoding = @encoding

Expand Down
16 changes: 16 additions & 0 deletions test/global_state_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,22 @@ def test_delegates_supports_watching_files_to_client_capabilities
global_state.supports_watching_files
end

def test_utf32_negotiation_yields_encoding_compatible_with_prism_code_units_cache
state = GlobalState.new
state.apply_options(capabilities: { general: { positionEncodings: ["utf-32"] } })

source = "class Foo; end\n\"🙂\"; Foo\n"
result = Prism.parse(source)
cache = result.code_units_cache(state.encoding)
foo_ref = result.value.statements.body.last #: as !nil

# `Foo` on line 1 starts at byte 23 (`class Foo; end\n` = 15 bytes + `"🙂"; ` = 8 bytes).
# In UTF-32 code units that same position is codepoint 20 (15 + 5). If `state.encoding`
# returns the dummy `Encoding::UTF_32`, the cache cannot translate past `🙂` and this
# assertion fails with a non-20 value.
assert_equal(20, foo_ref.location.cached_start_code_units_offset(cache))
end

def test_feature_flags_are_processed_by_apply_options
state = GlobalState.new

Expand Down
Loading