Skip to content

positionInRange function in PluginUtils doesn't work as its name suggests #2618

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

Closed
kokobd opened this issue Jan 21, 2022 · 2 comments · Fixed by #2625
Closed

positionInRange function in PluginUtils doesn't work as its name suggests #2618

kokobd opened this issue Jan 21, 2022 · 2 comments · Fixed by #2625
Labels
status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@kokobd
Copy link
Collaborator

kokobd commented Jan 21, 2022

Look closely at this function:

positionInRange :: Position -> Range -> Bool
positionInRange (Position pl po) (Range (Position sl so) (Position el eo)) =
pl > sl && pl < el
|| pl == sl && pl == el && po >= so && po <= eo
|| pl == sl && po >= so
|| pl == el && po <= eo

If this range has only 1 line, and the position lies in the same line as the range, but after the end of the range, then,
the second branch will fail, but the third branch will succeed, which is not expected, I think.

Your environment

Which OS do you use:

Ubuntu 20.04

Steps to reproduce

I wrote a testcase for that

tests :: TestTree
tests = testGroup "PluginUtils"
    [ testCase "positionInRange" $
        positionInRange (Position 1 10) (Range (Position 1 1) (Position 1 3)) @?= False
    ]

Expected behaviour

Position 1 10 is not in the range of Position 1 1 and Position 1 3. The above testcase should pass.

Actual behaviour

The testcase fails
image

@kokobd kokobd added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Jan 21, 2022
@michaelpj
Copy link
Collaborator

Yikes. A fix would be great. (separately, I should raid PluginUtils for stuff to upstream into lsp 🤔 )

@kokobd
Copy link
Collaborator Author

kokobd commented Jan 21, 2022

I will submit a PR later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants