Skip to content

Code.Fragment functions and whitespaces #11877

@lukaszsamson

Description

@lukaszsamson

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions