Skip to content

More accurate autolink warnings line #1807

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

Merged
merged 4 commits into from
Nov 13, 2023
Merged

More accurate autolink warnings line #1807

merged 4 commits into from
Nov 13, 2023

Conversation

wojtekmach
Copy link
Member

Demo:

image

mix.exs Outdated
Comment on lines 37 to 39
# TODO
{:earmark_parser, "~> 1.4.31",
github: "wojtekmach/earmark_parser", branch: "wm-codespan-line"},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garazdawi
Copy link
Contributor

When I saw your other PRs regarding warnings I was hoping the change in this PR was coming soon :) looks great! Now we just need the various LSPs to warn for this as well :)

Copy link
Member

@josevalim josevalim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely beautiful.

@wojtekmach wojtekmach merged commit 3a7999c into main Nov 13, 2023
@wojtekmach wojtekmach deleted the wm-warn-line branch November 13, 2023 10:54
@garazdawi
Copy link
Contributor

Do you know of any way to fix this for Erlang as well? :elixir_error.emit_diagnostic/5 seems to get

[{elixir_compiler,'__FILE__',1,
                  [{file,"/home/eluklar/git/otp3/lib/stdlib/src/gen_statem.erl"},
                   {line,1180}]}]

as the stacktrace, instead of something that it can convert to a nice warning message.

@josevalim
Copy link
Member

Elixir allows you to compile code outside of modules, but it does so by compiling the code inside a fake module with a fake __FILE__ function. So for a warning like that to appear, you need to be compiling code somewhere. Do you know where that could be?

Before printing stacktraces, Elixir explicitly matches on the :elixir_compiler.__FILE__/1 and knows it should show only the file info.

@garazdawi
Copy link
Contributor

I managed to get a bit further by setting :module and :function in IO.warn. Now the warning I get looks like this:

warning: documentation references function "erlang:foo/1" but it is undefined or private
  (stdlib 5.1.1) .../lib/stdlib/src/gen_statem.erl:1181: :gen_statem.callback_mode/0

Still need to figure out how to get the code snippet printed, or is that something that mix does?

@wojtekmach
Copy link
Member Author

printing snippet is an Elixir 1.16 feature!

@garazdawi
Copy link
Contributor

Aha!

@garazdawi
Copy link
Contributor

      warning: documentation references function "erlang:throws/1" but it is undefined or private
      │
 1181 │ `erlang:throws/1`
      │ ~~~~~~~~~~~~~~~~~
      │
      └─ /home/eluklar/git/otp3/lib/stdlib/src/gen_statem.erl:1181: :gen_statem (module)

      warning: documentation references type "t:callback_mode/0" but it is undefined or private
      │
 1338 │ -doc """
      │ ~~~~~~~~
      │
      └─ /home/eluklar/git/otp3/lib/stdlib/src/gen_statem.erl:1338: :gen_statem (module)

with an upgraded Elixir it works great for regular links. Custom links don't have the line number info though so they look a bit odd :) Looking forward to the same info being added about <a href>! :D

I'll submit a PR with the changes I had to do to make Erlang work.

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

Successfully merging this pull request may close these issues.

3 participants