Code Monkey home page Code Monkey logo

Comments (7)

mattmassicotte avatar mattmassicotte commented on August 25, 2024 1

I'm so glad you reached out - I would be very happy to help!

I hope the read me was clear, but Neon isn't a drop-in view. It is a collection of components you can use for efficient text style application and invalidation. So, how you integrate it it very dependent on your text system and what you are trying to do.

(I'm actually working right now on further generalizing the system and adopting Swift concurrency!)

Are you wrapping up an NSTextView for use in SwiftUI? And are you interested in using tree-sitter for token information, or some other source? You may want to have a look at TextViewHighlighter. It is easiest (but least-flexible) option for directly connecting tree-sitter to an NSTextView.

from neon.

mattmassicotte avatar mattmassicotte commented on August 25, 2024

(I also just put a link to a Discord in case you are looking for some more live help and that's your kind of thing)

I do, also, want to confirm that a SwiftUI example is a great idea and something that should definitely be added.

from neon.

keyle avatar keyle commented on August 25, 2024

Thanks, I've seen and corrected a mistake of mine.

I had added neon to my project via the add package... Only did it add 0.5.1 by default and that was missing some classes, as it's 7 months old. So that got me confused for a while.

I understand Swift well, but as a polyglot, I'm not really across XCode. Changing that to "branch" "main" fixed the missing class issues.

The other problem I'm having is with the bundle business

let url = Bundle.main
	  .resourceURL?
	  .appendingPathComponent("TreeSitterSwift_TreeSitterSwift.bundle")
	  .appendingPathComponent("queries/highlights.scm")
let query = try! language.query(contentsOf: url!)

Would it be possible to see a full example with tree_sitter_c or other language that has a clear cut away from Swift without this bundle business?

For the sake of not tip toeing around and this thread carrying on, which is due to my lack of understanding, I've included the code I'm haplessly trying to adapt for a code editor: https://gist.github.com/keyle/228ffd4a5622c1c328299f3ff9dd7c25

I've highlighted the issue at problem here.

Thanks for your time! 🙏🏻

from neon.

mattmassicotte avatar mattmassicotte commented on August 25, 2024

What wasn't working with 0.5.1? That's definitely supposed to be functional.

The bundle handling is completely independent of parser language. The issue is you must provide the tree-sitter integration with a minimum of two things: the parser and the highlighting query patterns. Many tree-sitter parsers have been packaged up with SPM to ease integration into Swift code.

Your code isn't working because you have added "TreeSitterC", but you are telling the system to look for a bundle called "TreeSitterSwift". Try this:

let url = Bundle.main
            .resourceURL?
            .appendingPathComponent("TreeSitterC_TreeSitterC.bundle")
            .appendingPathComponent("Contents/Resources/queries/highlights.scm")
        let query = try! language.query(contentsOf: url!)

Another alternative is to make use of the bundle searching facilities in SwiftTreeSitter (this is the runtime system, not to be confused with the Swift language parser called TreeSitterSwift).

(writing this off the top of my head, could be wrong)

let language = Language(language: tree_sitter_c(), name: "C")
let query = try! language.query(contentsOf: language.highlightsFileURL!)

from neon.

mattmassicotte avatar mattmassicotte commented on August 25, 2024

Any progress?

from neon.

keyle avatar keyle commented on August 25, 2024

Sorry for the lack of updates, life got in the way... What you've written makes sense and clearly I wasn't groking the relationship with the bundle and tree sitter.

from neon.

mattmassicotte avatar mattmassicotte commented on August 25, 2024

Absolutely no need to apologize. If anything else comes up, please don't be shy to ask again!

from neon.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.