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

Replace git submodule with package dependency for tree-sitter integration #23

Merged
merged 3 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "tree-sitter"]
path = tree-sitter
url = https://github.com/tree-sitter/tree-sitter.git
[submodule "tree-sitter-swift"]
path = tree-sitter-swift
url = https://github.com/alex-pinkus/tree-sitter-swift
Expand Down
21 changes: 6 additions & 15 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,14 @@ let settings: [SwiftSetting] = [

let package = Package(
name: "SwiftTreeSitter",
platforms: [
.macOS(.v10_13),
.iOS(.v12),
.tvOS(.v12),
.macCatalyst(.v13),
.watchOS(.v4)
],
products: [
.library(name: "SwiftTreeSitter", targets: ["SwiftTreeSitter"]),
.library(name: "SwiftTreeSitterLayer", targets: ["SwiftTreeSitterLayer"]),
],
dependencies: [
.package(url: "https://github.com/tree-sitter/tree-sitter", .upToNextMinor(from: "0.20.9")),
],
targets: [
.target(
name: "tree-sitter",
path: "tree-sitter/lib",
sources: ["src/lib.c"],
publicHeadersPath: "include",
cSettings: [.headerSearchPath("src/")]
),
.target(
name: "TestTreeSitterSwift",
path: "tree-sitter-swift",
Expand All @@ -36,7 +25,9 @@ let package = Package(
),
.target(
name: "SwiftTreeSitter",
dependencies: ["tree-sitter"],
dependencies: [
.product(name: "TreeSitter", package: "tree-sitter"),
],
swiftSettings: settings
),
.testTarget(
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Encoding+Helpers.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import tree_sitter
import TreeSitter

extension String.Encoding {
var internalEncoding: TSInputEncoding? {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Input.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import tree_sitter
import TreeSitter

final class Input {
typealias Buffer = UnsafeMutableBufferPointer<Int8>
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/InputEdit.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import tree_sitter
import TreeSitter

/// Structure that describes a change to the text content.
///
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Language.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import tree_sitter
import TreeSitter

public struct Language: Sendable {
private let tsLanguagePointer: SendableUnsafePointer<TSLanguage>
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/LanguageConfiguration.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

import tree_sitter
import TreeSitter

/// A structure that holds a language name and its assoicated queries.
public struct LanguageData: Sendable {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import tree_sitter
import TreeSitter

public struct Node {
let internalNode: TSNode
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftTreeSitter/Parser.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import tree_sitter
import TreeSitter

enum ParserError: Error {
case languageIncompatible
Expand Down Expand Up @@ -54,7 +54,7 @@ extension Parser {
var count: UInt32 = 0
let tsRangePointer = ts_parser_included_ranges(internalParser, &count)

let tsRangeBuffer = UnsafeBufferPointer<tree_sitter.TSRange>(start: tsRangePointer, count: Int(count))
let tsRangeBuffer = UnsafeBufferPointer<TreeSitter.TSRange>(start: tsRangePointer, count: Int(count))

return tsRangeBuffer.map({ TSRange(internalRange: $0) })
}
Expand All @@ -64,7 +64,7 @@ extension Parser {
ranges.withUnsafeBytes { bufferPtr in
let count = newValue.count

guard let ptr = bufferPtr.baseAddress?.bindMemory(to: tree_sitter.TSRange.self, capacity: count) else {
guard let ptr = bufferPtr.baseAddress?.bindMemory(to: TreeSitter.TSRange.self, capacity: count) else {
preconditionFailure("unable to convert pointer")
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Point.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import tree_sitter
import TreeSitter

public struct Point: Codable, Sendable {
public let row: UInt32
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Predicate.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import tree_sitter
import TreeSitter

public enum QueryPredicateStep: Hashable, Sendable {
case done
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Query.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import tree_sitter
import TreeSitter

public enum QueryError: Error {
case none
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftTreeSitter/TSRange.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import tree_sitter
import TreeSitter

public struct TSRange: Codable, Hashable, Sendable {
public let points: Range<Point>
Expand All @@ -10,12 +10,12 @@ public struct TSRange: Codable, Hashable, Sendable {
self.bytes = bytes
}

init(internalRange range: tree_sitter.TSRange) {
init(internalRange range: TreeSitter.TSRange) {
self.bytes = range.start_byte..<range.end_byte
self.points = Point(internalPoint: range.start_point)..<Point(internalPoint: range.end_point)
}

init(potentiallyInvalidRange range: tree_sitter.TSRange) {
init(potentiallyInvalidRange range: TreeSitter.TSRange) {
self.bytes = range.start_byte..<range.end_byte

let start = Point(internalPoint: range.start_point)
Expand All @@ -25,7 +25,7 @@ public struct TSRange: Codable, Hashable, Sendable {
self.points = start..<safeEnd
}

var internalRange: tree_sitter.TSRange {
var internalRange: TreeSitter.TSRange {
return .init(start_point: points.lowerBound.internalPoint,
end_point: points.upperBound.internalPoint,
start_byte: bytes.lowerBound,
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/Tree.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tree_sitter
import TreeSitter

/// An immutable tree-sitter tree structure.
public final class Tree: Sendable {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTreeSitter/TreeCursor.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import tree_sitter
import TreeSitter

public class TreeCursor {
private var internalCursor: TSTreeCursor
Expand Down
1 change: 0 additions & 1 deletion tree-sitter
Submodule tree-sitter deleted from 98be22
Loading