From 9fc098c5d762f59bb716f1b3b09606ed92c8c8e0 Mon Sep 17 00:00:00 2001 From: Marcin Krzyzanowski Date: Sat, 26 Aug 2023 22:21:03 +0200 Subject: [PATCH] Change TreeSitter provider to tree-sitter-xcframework --- Package.swift | 4 ++-- Sources/NeonPlugin/Coordinator.swift | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Package.swift b/Package.swift index 956dca0..1fa1832 100644 --- a/Package.swift +++ b/Package.swift @@ -14,7 +14,7 @@ let package = Package( dependencies: [ .package(url: "https://github.com/krzyzanowskim/STTextView", from: "0.8.10"), .package(url: "https://github.com/ChimeHQ/Neon.git", from: "0.5.1"), - .package(url: "https://github.com/alex-pinkus/tree-sitter-swift.git", commit: "eda05af7ac41adb4eb19c346883c0fa32fe3bdd8") // with-generated-files + .package(url: "https://github.com/krzyzanowskim/tree-sitter-xcframework", from: "0.208.3") ], targets: [ .target( @@ -22,7 +22,7 @@ let package = Package( dependencies: [ .product(name: "STTextView", package: "STTextView"), "Neon", - .product(name: "TreeSitterSwift", package: "tree-sitter-swift") + .product(name: "TreeSitter", package: "tree-sitter-xcframework") ] ) ] diff --git a/Sources/NeonPlugin/Coordinator.swift b/Sources/NeonPlugin/Coordinator.swift index 56482f9..9baabe6 100644 --- a/Sources/NeonPlugin/Coordinator.swift +++ b/Sources/NeonPlugin/Coordinator.swift @@ -5,8 +5,9 @@ import Neon import TreeSitterClient import SwiftTreeSitter -// Swift -import TreeSitterSwift +// tree-sitter-xcframework +import TreeSitter +import TreeSitterResource public class Coordinator { private(set) var highlighter: Neon.Highlighter? @@ -15,7 +16,7 @@ public class Coordinator { private var prevViewportRange: NSTextRange? init(textView: STTextView, theme: Theme) { - tsLanguage = Language(language: tree_sitter_swift()) + tsLanguage = Language(language: TreeSitterLanguage.swift.parser) tsClient = try! TreeSitterClient(language: tsLanguage) { codePointIndex in guard let location = textView.textContentManager.location(at: codePointIndex), @@ -65,9 +66,7 @@ public class Coordinator { private func tokenProvider(textContentManager: NSTextContentManager) -> Neon.TokenProvider? { - let url = Bundle.main.resourceURL!.appendingPathComponent("TreeSitterSwift_TreeSitterSwift.bundle").appendingPathComponent("Contents/Resources/queries/highlights.scm") - - guard let highlightsQuery = try? tsLanguage.query(contentsOf: url) else { + guard let highlightsQuery = try? tsLanguage.query(contentsOf: TreeSitterLanguage.swift.highlightQueryURL!) else { return nil }