diff --git a/Package.swift b/Package.swift index 999e41c10..73ee5ef3e 100644 --- a/Package.swift +++ b/Package.swift @@ -22,6 +22,7 @@ let package = Package( .package(url: "https://github.com/lukepistrol/tree-sitter-css.git", branch: "feature/spm"), .package(url: "https://github.com/tree-sitter/tree-sitter-go.git", branch: "master"), .package(url: "https://github.com/camdencheek/tree-sitter-go-mod.git", branch: "main"), + .package(url: "https://github.com/tree-sitter/tree-sitter-haskell.git", branch: "master"), .package(url: "https://github.com/mattmassicotte/tree-sitter-html.git", branch: "feature/spm"), .package(url: "https://github.com/tree-sitter/tree-sitter-java.git", branch: "master"), .package(url: "https://github.com/tree-sitter/tree-sitter-javascript.git", branch: "master"), @@ -47,6 +48,7 @@ let package = Package( .product(name: "TreeSitterCSS", package: "tree-sitter-css"), .product(name: "TreeSitterGo", package: "tree-sitter-go"), .product(name: "TreeSitterGoMod", package: "tree-sitter-go-mod"), + .product(name: "TreeSitterHaskell", package: "tree-sitter-haskell"), .product(name: "TreeSitterHTML", package: "tree-sitter-html"), .product(name: "TreeSitterJava", package: "tree-sitter-java"), .product(name: "TreeSitterJS", package: "tree-sitter-javascript"), diff --git a/Sources/CodeEditTextView/CodeLanguage/CodeLanguage.swift b/Sources/CodeEditTextView/CodeLanguage/CodeLanguage.swift index 1538f425a..5e7bcd7f3 100644 --- a/Sources/CodeEditTextView/CodeLanguage/CodeLanguage.swift +++ b/Sources/CodeEditTextView/CodeLanguage/CodeLanguage.swift @@ -16,6 +16,7 @@ import TreeSitterCSharp import TreeSitterCSS import TreeSitterGo import TreeSitterGoMod +import TreeSitterHaskell import TreeSitterHTML import TreeSitterJava import TreeSitterJS @@ -96,6 +97,8 @@ public struct CodeLanguage { return tree_sitter_go() case .goMod: return tree_sitter_gomod() + case .haskell: + return tree_sitter_haskell() case .html: return tree_sitter_html() case .java: @@ -154,6 +157,7 @@ public extension CodeLanguage { .css, .go, .goMod, + .haskell, .html, .java, .javascript, @@ -192,6 +196,9 @@ public extension CodeLanguage { /// A language structure for `GoMod` static let goMod: CodeLanguage = .init(id: .goMod, tsName: "GoMod", extensions: ["mod"]) + /// A language structure for `Haskell` + static let haskell: CodeLanguage = .init(id: .haskell, tsName: "Haskell", extensions: ["hs"]) + /// A language structure for `HTML` static let html: CodeLanguage = .init(id: .html, tsName: "HTML", extensions: ["html", "htm"]) diff --git a/Sources/CodeEditTextView/CodeLanguage/TreeSitterLanguage.swift b/Sources/CodeEditTextView/CodeLanguage/TreeSitterLanguage.swift index c06990ebe..0cb998d80 100644 --- a/Sources/CodeEditTextView/CodeLanguage/TreeSitterLanguage.swift +++ b/Sources/CodeEditTextView/CodeLanguage/TreeSitterLanguage.swift @@ -16,6 +16,7 @@ public enum TreeSitterLanguage: String { case css case go case goMod + case haskell case html case java case javascript diff --git a/Sources/CodeEditTextView/CodeLanguage/TreeSitterModel.swift b/Sources/CodeEditTextView/CodeLanguage/TreeSitterModel.swift index 0787077a5..3aea409ef 100644 --- a/Sources/CodeEditTextView/CodeLanguage/TreeSitterModel.swift +++ b/Sources/CodeEditTextView/CodeLanguage/TreeSitterModel.swift @@ -34,6 +34,8 @@ public class TreeSitterModel { return goQuery case .goMod: return goModQuery + case .haskell: + return haskellQuery case .html: return htmlQuery case .java: @@ -98,6 +100,11 @@ public class TreeSitterModel { return queryFor(.goMod) }() + /// Query for `Haskell` files. + public private(set) lazy var haskellQuery: Query? = { + return queryFor(.haskell) + }() + /// Query for `HTML` files. public private(set) lazy var htmlQuery: Query? = { return queryFor(.html) diff --git a/Sources/CodeEditTextView/Documentation.docc/CodeLanguage.md b/Sources/CodeEditTextView/Documentation.docc/CodeLanguage.md index eb80899c5..32fc0efd9 100644 --- a/Sources/CodeEditTextView/Documentation.docc/CodeLanguage.md +++ b/Sources/CodeEditTextView/Documentation.docc/CodeLanguage.md @@ -26,6 +26,7 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL) - CSS - Go - Go Mod +- Haskell - HTML - Java - JavaScript @@ -66,6 +67,7 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL) - ``css`` - ``go`` - ``goMod`` +- ``haskell`` - ``html`` - ``java`` - ``javascript`` diff --git a/Sources/CodeEditTextView/Documentation.docc/TreeSitterModel.md b/Sources/CodeEditTextView/Documentation.docc/TreeSitterModel.md index f4e105cb3..e8430f495 100644 --- a/Sources/CodeEditTextView/Documentation.docc/TreeSitterModel.md +++ b/Sources/CodeEditTextView/Documentation.docc/TreeSitterModel.md @@ -39,6 +39,7 @@ let query = TreeSitterModel.shared.swiftQuery - ``cssQuery`` - ``goQuery`` - ``goModQuery`` +- ``haskellQuery`` - ``htmlQuery`` - ``javaQuery`` - ``javascriptQuery`` diff --git a/Tests/CodeEditTextViewTests/CodeEditTextViewTests.swift b/Tests/CodeEditTextViewTests/CodeEditTextViewTests.swift index 5d9a912ce..4b4a550da 100644 --- a/Tests/CodeEditTextViewTests/CodeEditTextViewTests.swift +++ b/Tests/CodeEditTextViewTests/CodeEditTextViewTests.swift @@ -125,6 +125,15 @@ final class CodeEditTextViewTests: XCTestCase { XCTAssertEqual(language.id, .goMod) } + // MARK: Haskell + + func test_CodeLanguageHaskell() throws { + let url = URL(fileURLWithPath: "~/path/to/file.hs") + let language = CodeLanguage.detectLanguageFrom(url: url) + + XCTAssertEqual(language.id, .haskell) + } + // MARK: HTML func test_CodeLanguageHTML() throws {