-
Notifications
You must be signed in to change notification settings - Fork 93
Migrate VFS to Data.Text.Utf16.Rope.Mixed #436
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
module VspSpec where | ||
|
||
import Data.String | ||
import qualified Data.Text.Utf16.Rope as Rope | ||
import qualified Data.Text.Utf16.Rope.Mixed as Rope | ||
import Language.LSP.VFS | ||
import qualified Language.LSP.Types as J | ||
import qualified Data.Text as T | ||
|
@@ -313,12 +313,12 @@ vspSpec = do | |
positionToCodePointPosition vfile (J.Position 1 2) `shouldBe` Nothing | ||
positionToCodePointPosition vfile (J.Position 1 3) `shouldBe` Just (CodePointPosition 1 2) | ||
positionToCodePointPosition vfile (J.Position 1 4) `shouldBe` Just (CodePointPosition 1 3) | ||
positionToCodePointPosition vfile (J.Position 1 5) `shouldBe` Just (CodePointPosition 1 4) | ||
positionToCodePointPosition vfile (J.Position 1 5) `shouldBe` Just (CodePointPosition 2 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one looks like an actual logic change 🤔 What happened here? Was the old implementation wrong? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tend to think that the previous implementation was not quite correct.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, there's an interesting question here, namely: if you have a position There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Imagine that you pressed → key There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the more realistic example in our case where we can end up with positions out of range is the following:
It would be more wrong in general I believe to just start wrapping onto the next line. Keeping things strictly line-based is better here. That's why I initially was returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your point, but IMHO once VFS is out of sync all bets are off anyways. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, the VFS being slightly out of sync is actually the normal state when the user is editing the file! I wish I had some clear design to point you to (the LSP spec sadly provides no guidance)... I think the clamping part is fine, but I do think we should try and keep things to the same line and use the position "just past" the end of the line when we go off the end. |
||
-- Greater column than max column | ||
positionToCodePointPosition vfile (J.Position 1 6) `shouldBe` Nothing | ||
positionToCodePointPosition vfile (J.Position 2 1) `shouldBe` Nothing | ||
positionToCodePointPosition vfile (J.Position 1 6) `shouldBe` Just (CodePointPosition 2 0) | ||
positionToCodePointPosition vfile (J.Position 2 1) `shouldBe` Just (CodePointPosition 2 0) | ||
-- Greater line than max line | ||
positionToCodePointPosition vfile (J.Position 3 0) `shouldBe` Nothing | ||
positionToCodePointPosition vfile (J.Position 3 0) `shouldBe` Just (CodePointPosition 2 0) | ||
|
||
it "converts code points to code units" $ do | ||
let | ||
|
@@ -328,16 +328,16 @@ vspSpec = do | |
] | ||
vfile = VirtualFile 0 0 (fromString orig) | ||
|
||
codePointPositionToPosition vfile (CodePointPosition 1 0) `shouldBe` Just (J.Position 1 0) | ||
codePointPositionToPosition vfile (CodePointPosition 1 1) `shouldBe` Just (J.Position 1 1) | ||
codePointPositionToPosition vfile (CodePointPosition 1 2) `shouldBe` Just (J.Position 1 3) | ||
codePointPositionToPosition vfile (CodePointPosition 1 3) `shouldBe` Just (J.Position 1 4) | ||
codePointPositionToPosition vfile (CodePointPosition 1 4) `shouldBe` Just (J.Position 1 5) | ||
codePointPositionToPosition vfile (CodePointPosition 1 0) `shouldBe` J.Position 1 0 | ||
codePointPositionToPosition vfile (CodePointPosition 1 1) `shouldBe` J.Position 1 1 | ||
codePointPositionToPosition vfile (CodePointPosition 1 2) `shouldBe` J.Position 1 3 | ||
codePointPositionToPosition vfile (CodePointPosition 1 3) `shouldBe` J.Position 1 4 | ||
codePointPositionToPosition vfile (CodePointPosition 1 4) `shouldBe` J.Position 2 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
-- Greater column than max column | ||
codePointPositionToPosition vfile (CodePointPosition 1 5) `shouldBe` Nothing | ||
codePointPositionToPosition vfile (CodePointPosition 2 1) `shouldBe` Nothing | ||
codePointPositionToPosition vfile (CodePointPosition 1 5) `shouldBe` J.Position 2 0 | ||
codePointPositionToPosition vfile (CodePointPosition 2 1) `shouldBe` J.Position 2 0 | ||
-- Greater line than max line | ||
codePointPositionToPosition vfile (CodePointPosition 3 0) `shouldBe` Nothing | ||
codePointPositionToPosition vfile (CodePointPosition 3 0) `shouldBe` J.Position 2 0 | ||
|
||
-- --------------------------------- | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,5 @@ extra-package-dbs: [] | |
nix: | ||
packages: [icu] | ||
extra-deps: | ||
- text-rope-0.1 | ||
- text-rope-0.2 | ||
- co-log-core-0.3.1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens now? I'm guessing we get the "clamped" result. I think both behaviours are reasonable but I'd like it to be documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's clamped.