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

Guard against new positions with line or char less than 1 #800

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 apps/common/lib/lexical/ast.ex
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ defmodule Lexical.Ast do

defp one_line_range(%Document{} = document, line_number) do
start_pos = Position.new(document, line_number, 1)
end_pos = Position.new(document, line_number + 1, 0)
end_pos = Position.new(document, line_number + 1, 1)
Range.new(start_pos, end_pos)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule Lexical.RemoteControl.CodeAction.Handlers.ReplaceRemoteFunction do
defp apply_transform(%Document{} = doc, line_number, module, function, suggestion) do
{:ok, doc, analysis} = Document.Store.fetch(doc.uri, :analysis)
function_atom = String.to_atom(function)
position = Document.Position.new(doc, line_number, 0)
position = Document.Position.new(doc, line_number, 1)

doc
|> Ast.traverse_line(line_number, [], fn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule Lexical.RemoteControl.Search.Indexer.Source.Reducer do
blocks: [Block.root()],
entries: [],
extractors: extractors || @extractors,
position: {0, 0}
position: {1, 1}
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ defmodule Lexical.RemoteControl.CodeAction.Handlers.ReplaceRemoteFunctionTest do

range =
Document.Range.new(
Document.Position.new(document, line_number, 0),
Document.Position.new(document, line_number + 1, 0)
Document.Position.new(document, line_number, 1),
Document.Position.new(document, line_number + 1, 1)
)

diagnostic = Diagnostic.new(range, message, nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ defmodule Lexical.RemoteControl.CodeAction.Handlers.ReplaceWithUnderscoreTest do

range =
Document.Range.new(
Document.Position.new(document, line_number, 0),
Document.Position.new(document, line_number + 1, 0)
Document.Position.new(document, line_number, 1),
Document.Position.new(document, line_number + 1, 1)
)

diagnostic = Diagnostic.new(range, message, nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Callback do
start_char =
case String.split(line, "def", parts: 2) do
[i, _] -> String.length(i) + 1
[_] -> 0
[_] -> 1
end

end_char = String.length(line) + 1
Expand Down
4 changes: 2 additions & 2 deletions projects/lexical_shared/lib/lexical/document/position.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ defmodule Lexical.Document.Position do

@spec new(line_container(), line(), character()) :: t
def new(%Document{} = document, line, character)
when is_number(line) and is_number(character) do
when is_number(line) and is_number(character) and line >= 1 and character >= 1 do
new(document.lines, line, character)
end

def new(%Document.Lines{} = lines, line, character)
when is_number(line) and is_number(character) do
when is_number(line) and is_number(character) and line >= 1 and character >= 1 do
line_count = Document.Lines.size(lines)
starting_index = lines.starting_index

Expand Down
Loading