-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Labels
Milestone
Description
Environment
- Elixir & Erlang/OTP versions (elixir --version): 1.13, dev
Current behavior
Code.Fragment.surround_context/2
and cursor_context/1
do not handle newlines and other whitespaces very well (e.g. when the line ends with a comment).
iex(4)> Code.Fragment.cursor_context("DateTime.utc_no")
{:dot, {:alias, 'DateTime'}, 'utc_no'}
iex(5)> Code.Fragment.cursor_context("DateTime.\nutc_no")
{:local_or_var, 'utc_no'}
iex(5)> Code.Fragment.cursor_context("DateTime. # some comment\nutc_no")
{:local_or_var, 'utc_no'}
iex(6)> Code.Fragment.surround_context("DateTime.utc_no", {1, 11})
%{begin: {1, 1}, context: {:dot, {:alias, 'DateTime'}, 'utc_no'}, end: {1, 16}}
iex(7)> Code.Fragment.surround_context("DateTime.\nutc_no", {2, 2})
%{begin: {2, 1}, context: {:local_or_var, 'utc_no'}, end: {2, 7}}
Expected behavior
I don't know if this is an intended behavior to make those functions simpler but I would expect they are able to understand valid code.
whatyouhide