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

Repo example code returns nil for highlight method #38

Closed
Wouter01 opened this issue Jan 30, 2024 · 6 comments
Closed

Repo example code returns nil for highlight method #38

Wouter01 opened this issue Jan 30, 2024 · 6 comments

Comments

@Wouter01
Copy link
Contributor

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
Copy link
Contributor

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

@mattmassicotte
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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. alex-pinkus/tree-sitter-swift#289

@Wouter01
Copy link
Contributor Author

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

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