Skip to content
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

fixed out of bounds in line mapping #1707

Merged
merged 8 commits into from
Feb 13, 2020
Merged

Conversation

filipw
Copy link
Member

@filipw filipw commented Feb 10, 2020

Fixes dotnet/vscode-csharp#3485
Also added more comprehensive tests.

Here is the summary of the logic:

  • correct mapping within a file - then we return the mapped line and mapped text
  • incorrect mapping within a file - then we return the mapped line (even though it's incorrect) and the original (unmapped) text since there is no way to fetch the mapped text as it's out of bounds
  • correct mapping into a file that exists in a workspace - then we return the mapped line and mapped text from that file
  • incorrect mapping into a file that exists in a workspace - then we return the mapped line and the original (unmapped) text since there is no way to fetch the mapped text as it's out of bounds
  • mapping into a file that does not exist in a workspace - then we return the mapped line and the original (unmapped) text since there is no way to fetch the mapped text as we don't have access to it (Razor case). The editor still ignores it anyway and shows the correct file in this case.

cc @NTaylorMullen as this bug affected Razor 🙈

Copy link
Contributor

@NTaylorMullen NTaylorMullen left a comment

Choose a reason for hiding this comment

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

♥️

@filipw
Copy link
Member Author

filipw commented Feb 12, 2020

@JoeRobich @david-driscoll any objections? can this be merged?

Copy link
Member

@JoeRobich JoeRobich left a comment

Choose a reason for hiding this comment

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

I am fine with this change. Just not an area I know much about. =)

if (hasMappedPath)
{
SourceText source = null;
if (documents != null && documents.Any() && documents.FirstOrDefault(d => d.TryGetText(out source)) != null)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not as familiar with line mappings. Would it be more correct to loop through the documents where you can get text and see if the mapping applies?

Copy link
Member

Choose a reason for hiding this comment

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

documents.Any() isn't necessary now that you are using FirstOrDefault

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this can only ever return more than 1 in case of multi targeting so the document text would be identical

@david-driscoll
Copy link
Member

:shipit:

@filipw filipw merged commit d443479 into master Feb 13, 2020
@filipw filipw deleted the bugfix/locationextensions branch February 13, 2020 09:22
filipw added a commit that referenced this pull request Feb 14, 2020
bjorkstromm added a commit that referenced this pull request Feb 15, 2020
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.

Omnisharp stops a few minutes after loading project
5 participants