Skip to content

Get last mapping if line matches but column is way bigger#17

Merged
vmihailenco merged 1 commit intogo-sourcemap:masterfrom
mstoykov:getLastMappingEvenIfColumnIsBigger
Nov 19, 2021
Merged

Get last mapping if line matches but column is way bigger#17
vmihailenco merged 1 commit intogo-sourcemap:masterfrom
mstoykov:getLastMappingEvenIfColumnIsBigger

Conversation

@mstoykov
Copy link
Contributor

No description provided.

if int(match.genLine) > genLine || int(match.genColumn) > genColumn {
if i == 0 {
// lets see if the line is correct but the column is bigger
match = &m.mappings[i-1]
Copy link
Member

Choose a reason for hiding this comment

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

This does not look right. It looks like you want to change

sourcemap/consumer.go

Lines 187 to 193 in 73a0ee2

i := sort.Search(len(m.mappings), func(i int) bool {
m := &m.mappings[i]
if int(m.genLine) == genLine {
return int(m.genColumn) >= genColumn
}
return int(m.genLine) >= genLine
})
instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well, I guess we can move it there as well.

The thing is that sort.Search actually correctly search and finds that the place where this should be is at the end of the slice. In general sort.Search just finds where a thing is supposed to be not exactly if it's there, it's more answering the question where an element should be added in that regard.

This is a kin to the fuzzy search below where if what it was asked for isn't exactly there it will get the previous one if possible

Copy link
Member

Choose a reason for hiding this comment

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

You are right. Probably I should not have used sort.Search here, because there are too many corner cases.

@vmihailenco
Copy link
Member

Thanks for the PR 👍

@vmihailenco vmihailenco merged commit 180fcef into go-sourcemap:master Nov 19, 2021
@mstoykov mstoykov deleted the getLastMappingEvenIfColumnIsBigger branch January 19, 2024 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants