Skip to content
This repository was archived by the owner on Dec 17, 2018. It is now read-only.

Use International Components for Unicode (ICU) to parse line breaks #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RLovelett
Copy link
Owner

@RLovelett RLovelett commented May 30, 2018

I am trying to improve the robustness of the selection(startAt:,length:) and byteOffset(at:) which had a tendency to not be able to translate positions over time.

[Error - 1:51:10 PM] Request textDocument/completion failed.
  Message: Could not find the text in the source file.
  Code: -32098 
[Error - 1:51:21 PM] Request textDocument/completion failed.
  Message: Could not find the text in the source file.
  Code: -32098 
[Error - 1:51:23 PM] Request textDocument/completion failed.
  Message: Could not find the text in the source file.
  Code: -32098

These errors.

@RLovelett RLovelett self-assigned this May 30, 2018

}

struct Line {
Copy link
Owner Author

Choose a reason for hiding this comment

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

Add some documentation to Line to make sure we can remember what each of the fields is for.

let last: Bool

func contains(_ index: String.Index) -> Bool {
if last {
Copy link
Owner Author

Choose a reason for hiding this comment

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

Document why this condition is here. I know there is a failing test case for it.


private var lineNumber: Int

private var handleTrailingNewLine: Bool
Copy link
Owner Author

Choose a reason for hiding this comment

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

Document what handleTrailingNewLine is really trying to do. Probably needs a better name too.

}

mutating func next() -> Line? {
guard cursor < text.endIndex else {
Copy link
Owner Author

Choose a reason for hiding this comment

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

This next function is a mess.

/// - Parameter offset: The offset from the start of the TextDocument.
/// - Returns: A new and valid Position.
/// - Throws: WorkspaceError.positionNotFound if the offset is not within the bounds of the TextDocument.
func position(for offset: Int) throws -> Position {
Copy link
Owner Author

Choose a reason for hiding this comment

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

Does this make more sense as a function on TextDocument or as an initializer on Position that takes a TextDocument and offset? 🤔

return try! String(contentsOf: url)
}()

override func setUp() {
Copy link
Owner Author

Choose a reason for hiding this comment

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

Delete these since they are not used.

}

func testLastLine() {
for line in AnySequence({ LineIterator(self.simpleBar) }) {
Copy link
Owner Author

Choose a reason for hiding this comment

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

Do this for all of the documents and find a way to abstract it so that it is not so verbose.

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.

1 participant