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

Fix Formatting.format returns character float number #250

Merged
merged 1 commit into from
May 20, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ defmodule ElixirLS.LanguageServer.Providers.Formatting do
else
# LSP contentChanges positions are based on UTF-16 string representation
# https://microsoft.github.io/language-server-protocol/specification#textDocuments
{line, col + byte_size(:unicode.characters_to_binary(char, :utf8, :utf16)) / 2}
{line, col + div(byte_size(:unicode.characters_to_binary(char, :utf8, :utf16)), 2)}
end
end)
end
Expand Down
8 changes: 8 additions & 0 deletions apps/language_server/test/providers/formatting_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,16 @@ defmodule ElixirLS.LanguageServer.Providers.FormattingTest do
}
}
]

assert Enum.all?(changes, fn change ->
assert_position_type(change["range"]["end"]) and
assert_position_type(change["range"]["start"])
end)
end

defp assert_position_type(%{"character" => ch, "line" => line}),
do: is_integer(ch) and is_integer(line)

test "returns an error when formatting a file with a syntax error" do
uri = "file://project/file.ex"

Expand Down