Stream: t-compiler/rust-analyzer

Topic: issue 2799 - missing struct field diagnostics span

Pascal (Feb 03 2020 at 10:42, on Zulip):

Morning! If someone can point out to me how to write a test for I'd love to dig into it :)

matklad (Feb 03 2020 at 10:44, on Zulip):

See as an example of a diagnostics test

Florian Diebold (Feb 03 2020 at 10:44, on Zulip):

for the struct field diagnostic, there's an existing test here

matklad (Feb 03 2020 at 10:45, on Zulip):

Yeah, actually, Florian Diebold test is better, because it is more targeted

Florian Diebold (Feb 03 2020 at 10:45, on Zulip):

keep in mind that you have to define everything you use, you don't get vec! from the standard library

Pascal (Feb 03 2020 at 10:47, on Zulip):

thanks! i'll have a look now (instead of a lunch break :D)

matklad (Feb 03 2020 at 10:52, on Zulip):

Hm, accutaly, I think mine proposal is a better one :D

Internally, the diagnostics are expressed in terms of the macro file, and it looks like what breaks here is the transition from macro-file to the original file. Ie, we show, int he original file, ranges from macro pseudo file.

matklad (Feb 03 2020 at 10:53, on Zulip):

I think the way to fix this would be to change

trait Diagnostic {
  fn highlight_range(&self) -> TextRange


trait Diagnostic {
  fn highlight_range(&self) -> InFile<TextRange>

and make sure that the call-site correctly unwraps potential maro file

Pascal (Feb 03 2020 at 10:57, on Zulip):

that was my first guess as well. not sure how to change that but i'll try to understand it at least :)

matklad (Feb 03 2020 at 10:58, on Zulip):

Yeah, unforutantely our internal APIs are not... polished.

matklad (Feb 03 2020 at 10:59, on Zulip):

But the core thing to understand is that we have real files (FileId) and pseudo files generated by macros HirFileId. InFile<T> is something withing a real or pseudo file. When you render something to the user, you need to make sure that you are talking in terms of ranges in the real file.

Pascal (Feb 03 2020 at 12:24, on Zulip):

alright, how do i resolve an InFile<TextRange> to a TextRange in a given file_id? maybe i'm looking for the wrong thing, but i hoped there was a map somewhere to translate virtual file_id ranges to spans in real files (i ask because in ra_ide::Diagnostic i need to set a real TextRange)

matklad (Feb 03 2020 at 12:56, on Zulip):

See HirFIleId::expansion_info

matklad (Feb 03 2020 at 12:56, on Zulip):

It doesn't have API for ranges though, but it might make sense to add it.

Last update: Jul 28 2021 at 03:45UTC