ChimeHQ / Neon

A Swift library for efficient, flexible content-based text styling
BSD 3-Clause "New" or "Revised" License
319 stars 17 forks source link

Repo example code returns nil for highlight method #38

Closed Wouter01 closed 7 months ago

Wouter01 commented 7 months ago

I'm trying to use the example code provided in the repo. For some reason that is not clear to me, the following line will return nil (and in the example case, crash because it's force unwrapped)

let highlights = try client.highlights(in: NSRange(0..<24), provider: provider, mode: .required)!

I had a look at the code but couldn't find an immediate cause for it. I'm using the main branch to test this, as it's the one used in the example code.

I also tried using the sample project. There, the TextViewHighlighter example seems to work as expected. The other method provided (setUpTreeSitter) has the same issue though.

Am I doing anything wrong here? Or should I stick with 0.6.0 for now?

mattmassicotte commented 7 months ago

Thank you for reporting this. Probably a bug - investigating now.

mattmassicotte commented 7 months ago

Ok so this is a bug. Even though synchronous access with the .required fill mode is specified, BackgroundingLanguageLayerTree.accessTreeSynchronously is returning false, disallowing the synchronous access.

So far, this is a valid situation. You've asked for synchronous access, and that access is impossible. But, it should not be in this situation. I think this is because the pendingWork calculation is too simplistic.

Wouter01 commented 7 months ago

Thank you for looking into it! I can confirm that it does work if I use the asynchronous methods. Does this mean I should hold off of using the synchronous methods for now? Or is there a case where they work as expected?

mattmassicotte commented 7 months ago

With the code currently on main, any synchronous work that requires parsing will fail. I'm working on a fix, but I also want to make a test and getting that working has been a chain reaction of problems...

mattmassicotte commented 7 months ago

Ok, I think this is fixed now. It took a long time because I added a test, but that test didn't work because a whole bunch of stuff went wrong with accessing Swift tree-sitter highlights. https://github.com/alex-pinkus/tree-sitter-swift/issues/289

Wouter01 commented 7 months ago

Yep, all working now. Thank you for the quick fix!