Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Conversation

@amitzur
Copy link
Contributor

@amitzur amitzur commented Oct 18, 2017

Associated Issue: #4369

Summary of Changes

Thanks @liorpr for working on this together!

The reason for the bug was that it was ignoring column data. If the token is at the same line where an out of scope range begins, but earlier, then the token was considered out of scope. We added consideration of the column position.

  • Add outOfScopeLocations to props of preview
  • Use column data to accurately compute out of scope

NOTE: the code is dirty, maybe a bit of refactoring is in place. We did it in #goodnessSquad and wanted to create a PR. It works, but it's complicated and can probably be simplified.

Test Plan

updatePreview probably needs testing, but we didn't add it.

@jasonLaster
Copy link
Contributor

Hey @amitzur + @liorpr!

I think this was worked on here too: #4381. Could you see how the implementations are similar / different and help land one of them. The other is missing unit tests. I think this one is too :)

Copy link
Contributor

@codehag codehag left a comment

Choose a reason for hiding this comment

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

looks pretty good thanks! added a few comments and a question

const inScope = linesInScope && linesInScope.includes(location.line);
let inScope;
const isLineInScope = linesInScope && linesInScope.includes(location.line);
if (isLineInScope) {
Copy link
Contributor

Choose a reason for hiding this comment

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

lets move this into its own function which returns a value that can be assigned to inScope

here is how it would looks like:

function isInScope(linesInScope, location) {
  const isLineInScope = linesInScope && linesInScope.includes(location.line);
  if (isLineInScope) {
    return true;
  }

  const startLineLocation = outOfScopeLocations.find(
    loc => loc.start.line === location.line
  );
  if (startLineLocation) {
    return startLineLocation.start.column > location.column;
  }
  
  const endLineLocation = outOfScopeLocations.find(
    loc => loc.end.line === location.line
  );
  if (endLineLocation) {
    return endLineLocation.end.column < location.column;
  }    

  // if none of these conditions are true, return false
  return false;
}

// use
const inScope = isInScope(linesInScope, location)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

love it

const startLineLocation = outOfScopeLocations.find(
loc => loc.start.line === location.line
);
if (startLineLocation) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we seem to be using the out of scope locations to determine if the lien is in scope, but we have a linesInScope array -- why was this not working as intended? perhaps the bug is steming from linesInScope not representing the correct information?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, actually linesInScope is not really mandatory here, since we need the column information.
you could write a function which works only with outOfScopeLocations and calculates if a location is out of scope.
I kept linesInScope since it was easier to calculate only in for cases where the line isn't in that array.

hope that makes sense o_O

@Fischer-L
Copy link
Contributor

I was working on the issue #4369 from 5 days ago but forgot to leave the message (sorry for causing the double effort). I will suggest another approach for the issue #4369 . Please see the detailed explanation: #4381 (comment)

@jasonLaster
Copy link
Contributor

I think @Fischer-L's solution w/ containsLocation is sufficient here. Happy to re-open if there is still ongoing work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants