Skip to content

Commit

Permalink
Merge pull request #74 from lukepistrol/feat/add-language-haskell
Browse files Browse the repository at this point in the history
[Feat]: Add language support for `Haskell`
  • Loading branch information
lukepistrol authored Oct 3, 2022
2 parents f2b8764 + ad60569 commit 2e7f406
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down
7 changes: 7 additions & 0 deletions Sources/CodeEditTextView/CodeLanguage/CodeLanguage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import TreeSitterCSharp
import TreeSitterCSS
import TreeSitterGo
import TreeSitterGoMod
import TreeSitterHaskell
import TreeSitterHTML
import TreeSitterJava
import TreeSitterJS
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -154,6 +157,7 @@ public extension CodeLanguage {
.css,
.go,
.goMod,
.haskell,
.html,
.java,
.javascript,
Expand Down Expand Up @@ -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"])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum TreeSitterLanguage: String {
case css
case go
case goMod
case haskell
case html
case java
case javascript
Expand Down
7 changes: 7 additions & 0 deletions Sources/CodeEditTextView/CodeLanguage/TreeSitterModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class TreeSitterModel {
return goQuery
case .goMod:
return goModQuery
case .haskell:
return haskellQuery
case .html:
return htmlQuery
case .java:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Sources/CodeEditTextView/Documentation.docc/CodeLanguage.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL)
- CSS
- Go
- Go Mod
- Haskell
- HTML
- Java
- JavaScript
Expand Down Expand Up @@ -66,6 +67,7 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL)
- ``css``
- ``go``
- ``goMod``
- ``haskell``
- ``html``
- ``java``
- ``javascript``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ let query = TreeSitterModel.shared.swiftQuery
- ``cssQuery``
- ``goQuery``
- ``goModQuery``
- ``haskellQuery``
- ``htmlQuery``
- ``javaQuery``
- ``javascriptQuery``
Expand Down
9 changes: 9 additions & 0 deletions Tests/CodeEditTextViewTests/CodeEditTextViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2e7f406

Please sign in to comment.