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

'staleContent' error in highlighter #23

Closed
kaunteya opened this issue Aug 13, 2023 · 2 comments
Closed

'staleContent' error in highlighter #23

kaunteya opened this issue Aug 13, 2023 · 2 comments

Comments

@kaunteya
Copy link
Contributor

kaunteya commented Aug 13, 2023

I am getting an error while updating the font size of textview

self.textView.font = .systemFont(ofSize: size, weight: .regular)

The error says failed to get tokens: staleContent


Tried debugging and noticed that the issue does not occur in the Example project. While comparing the stack side by side by putting breakpoints on the line which prints error, it seems like the guard comparison fails on the following line

guard startedVersion == self.version else {

In debugger startedVersion = 2 and self.version = 3. What could be the probable reason?
The code works fine despite the error

@kaunteya kaunteya reopened this Aug 14, 2023
@kaunteya
Copy link
Contributor Author

kaunteya commented Aug 14, 2023

Will it make sense to call treeSitterClient.willChangeContent and treeSitterClient.didChangeContent only when edited mask contains editedCharacters?

func textStorage(_ textStorage: NSTextStorage, willProcessEditing editedMask: NSTextStorageEditActions, range editedRange: NSRange, changeInLength delta: Int) {
    if editedMask.contains(.editedCharacters) {
        treeSitterClient.willChangeContent(in: editedRange)
    }
}

func textStorage(_ textStorage: NSTextStorage, didProcessEditing editedMask: NSTextStorageEditActions, range editedRange: NSRange, changeInLength delta: Int) {
    guard editedMask.contains(.editedCharacters) else { return }
    let adjustedRange = NSRange(location: editedRange.location, length: editedRange.length - delta)
    let string = textStorage.string

    highlighter.didChangeContent(in: adjustedRange, delta: delta)
    treeSitterClient.didChangeContent(to: string, in: adjustedRange, delta: delta, limit: string.utf16.count)
}

@mattmassicotte
Copy link
Contributor

I think it is safe to ignore edits if they only contain attribute changes. But, I have experimented with this in the past and have run into issues - I just cannot remember why...

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

No branches or pull requests

2 participants