Skip to content

Code.Fragment.surround_context returns :none within sigils #14243

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

Open
rudiejd opened this issue Jan 30, 2025 · 1 comment
Open

Code.Fragment.surround_context returns :none within sigils #14243

rudiejd opened this issue Jan 30, 2025 · 1 comment

Comments

@rudiejd
Copy link

rudiejd commented Jan 30, 2025

Elixir and Erlang/OTP versions

❯ elixir --version
Erlang/OTP 27 [erts-15.1.2] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]

Elixir 1.17.3 (compiled with Erlang/OTP 27)

Operating system

Arch Linux x86_64 6.12.1-arch1-1

Current behavior

%{context: {:sigil, ~c"D"}, begin: {1, 1}, end: {1, 3}}
iex [ :: 24] > Code.Fragment.surround_context("~D[2025-01-01]", {1, 2})
%{context: {:sigil, ~c"D"}, begin: {1, 1}, end: {1, 3}}
iex [ :: 25] > Code.Fragment.surround_context("~D[2025-01-01]", {1, 3})
:none
iex [ :: 26] > Code.Fragment.surround_context("~D[2025-01-01]", {1, 4})
:none

Expected behavior

%{context: {:sigil, ~c"D"}, begin: {1, 1}, end: {1, 12}}
iex [ :: 24] > Code.Fragment.surround_context("~D[2025-01-01]", {1, 2})
%{context: {:sigil, ~c"D"}, begin: {1, 1}, end: {1, 12}}
iex [ :: 25] > Code.Fragment.surround_context("~D[2025-01-01]", {1, 3})
%{context: {:sigil, ~c"D"}, begin: {1, 1}, end: {1, 12}}
iex [ :: 26] > Code.Fragment.surround_context("~D[2025-01-01]", {1, 4})
%{context: {:sigil, ~c"D"}, begin: {1, 1}, end: {1, 12}}

I would expect the surround_context for a sigil to span the entire body of the sigil. My use case is that I'd like to be able to determine when I'm in a ~H sigil in elixir-ls. Should surround_context return information about the "container" that I am in (this was my take from the docs), or am I mistaking this for another API?

@josevalim
Copy link
Member

I don't think there is an API to return this today, one would need to be added. The reason why surround_context is not a good candidate for this are two:

  1. Sometimes you want the surround context inside a sigil itself, think autocompletion inside HEEx
  2. surround_context only looks at the current line, so it wouldn't work for a multiline sigil

The best candidate would be to change Code.Fragment.container_cursor_to_quoted("~D[2025-01-01") to return we are inside a sigil if an option is given. We could probably do it somewhat cleanly by returning something like sigil_D(<<"2025-01-01", __cursor__>>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants