Stream: t-compiler/wg-diagnostics

Topic: removing a line in a suggestion


davidtwco (Jan 28 2019 at 17:03, on Zulip):

Am I right in thinking that there's no way to remove a line in a suggestion?
cc @Esteban Küber

Esteban Küber (Jan 28 2019 at 17:06, on Zulip):

You need a span that goes from the beginning on the line to be removed to the beginning of the next one, replacing with empty string

davidtwco (Jan 28 2019 at 17:06, on Zulip):

I thought that might work, but I was struggling at a glance to figure out how to get that with the APIs on SourceMap?

Esteban Küber (Jan 28 2019 at 17:06, on Zulip):

That will do what you want but might get you in tricky span offset calculation waters

Esteban Küber (Jan 28 2019 at 17:07, on Zulip):

What span do you available?

Esteban Küber (Jan 28 2019 at 17:07, on Zulip):

*have

davidtwco (Jan 28 2019 at 17:07, on Zulip):

I'm looking at #52891. I've got the span for issue_52891::a in use issue_52891::a;.

davidtwco (Jan 28 2019 at 17:08, on Zulip):

I noticed that if I got a SourceFile for the Span then I could call line_begin_pos.

davidtwco (Jan 28 2019 at 17:09, on Zulip):

And I could get one of those from lookup_byte_offset using either of .hi() or .lo().

Esteban Küber (Jan 28 2019 at 17:09, on Zulip):

Yep that's what I'd do

Esteban Küber (Jan 28 2019 at 17:09, on Zulip):

There's a method to consume backwards until a certain condition is true

Esteban Küber (Jan 28 2019 at 17:10, on Zulip):

Passed in as q closure

Esteban Küber (Jan 28 2019 at 17:10, on Zulip):

I think it's used to get the pub span somewhere

Esteban Küber (Jan 28 2019 at 17:10, on Zulip):

It's a hack

Esteban Küber (Jan 28 2019 at 17:10, on Zulip):

But it works :grimacing:

davidtwco (Jan 28 2019 at 17:10, on Zulip):

I figured I'd be able to do something like that if it went forwards by looking for \n.

davidtwco (Jan 28 2019 at 17:10, on Zulip):

or EOF I guess.

davidtwco (Jan 28 2019 at 17:12, on Zulip):

Or maybe I could take one BytePos away from the line_begin_pos of the next line. Might be a straight forward variation on the line_begin_pos function but that may not work for reasons I'm not aware of.

Esteban Küber (Jan 28 2019 at 17:24, on Zulip):

If you try to remove from here to next \n, the things to account for are multiline strings (they are evil) and Eof

Esteban Küber (Jan 28 2019 at 17:24, on Zulip):

also one could write

use
foo::bar:Baz
as
Qux
;

and you should be able to account for that :-/

Esteban Küber (Jan 28 2019 at 17:25, on Zulip):

@davidtwco ^

davidtwco (Jan 28 2019 at 17:26, on Zulip):

I expected that would be the Span of the Item that represents the use statement - but I've not been able to find a way to get at that from where this error is reported.

Esteban Küber (Jan 28 2019 at 17:27, on Zulip):

I think that the Qux in the example above is a Spanned Ident, so if present you should use that for the tentative end of it

Esteban Küber (Jan 28 2019 at 17:27, on Zulip):

Also, I know there were prior PRs dealing with this were the ; was sometimes included and sometimes not

davidtwco (Jan 28 2019 at 17:27, on Zulip):

I think that (having an Item) would be necessary as well to distinguish between use foo:{a, b}; and use foo::a;

Esteban Küber (Jan 28 2019 at 17:28, on Zulip):

yep

davidtwco (Jan 28 2019 at 17:28, on Zulip):

So I know what Span to suggest - the line (or multiple lines) or just the binding_span I have.

Esteban Küber (Jan 28 2019 at 17:28, on Zulip):

Makes sense

davidtwco (Jan 28 2019 at 17:29, on Zulip):

I've not been able to find an example in that file of getting an Item from a NodeId - the Resolver doesn't really need to do that.

Last update: Nov 15 2019 at 09:40UTC