diff --git a/Package.swift b/Package.swift index 73ee5ef3e..a77e45ae8 100644 --- a/Package.swift +++ b/Package.swift @@ -13,13 +13,14 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), - .package(url: "https://github.com/krzyzanowskim/STTextView", branch: "main"), - .package(url: "https://github.com/ChimeHQ/SwiftTreeSitter", from: "0.6.0"), + .package(url: "https://github.com/krzyzanowskim/STTextView", exact: "0.0.20"), + .package(url: "https://github.com/ChimeHQ/SwiftTreeSitter", exact: "0.6.1"), .package(url: "https://github.com/lukepistrol/tree-sitter-bash.git", branch: "feature/spm"), .package(url: "https://github.com/tree-sitter/tree-sitter-c.git", branch: "master"), .package(url: "https://github.com/tree-sitter/tree-sitter-cpp.git", branch: "master"), .package(url: "https://github.com/tree-sitter/tree-sitter-c-sharp.git", branch: "master"), .package(url: "https://github.com/lukepistrol/tree-sitter-css.git", branch: "feature/spm"), + .package(url: "https://github.com/elixir-lang/tree-sitter-elixir.git", branch: "main"), .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"), @@ -46,6 +47,7 @@ let package = Package( .product(name: "TreeSitterCPP", package: "tree-sitter-cpp"), .product(name: "TreeSitterCSharp", package: "tree-sitter-c-sharp"), .product(name: "TreeSitterCSS", package: "tree-sitter-css"), + .product(name: "TreeSitterElixir", package: "tree-sitter-elixir"), .product(name: "TreeSitterGo", package: "tree-sitter-go"), .product(name: "TreeSitterGoMod", package: "tree-sitter-go-mod"), .product(name: "TreeSitterHaskell", package: "tree-sitter-haskell"), diff --git a/Sources/CodeEditTextView/CodeLanguage/CodeLanguage.swift b/Sources/CodeEditTextView/CodeLanguage/CodeLanguage.swift index 5e7bcd7f3..bd2833a5e 100644 --- a/Sources/CodeEditTextView/CodeLanguage/CodeLanguage.swift +++ b/Sources/CodeEditTextView/CodeLanguage/CodeLanguage.swift @@ -14,6 +14,7 @@ import TreeSitterC import TreeSitterCPP import TreeSitterCSharp import TreeSitterCSS +import TreeSitterElixir import TreeSitterGo import TreeSitterGoMod import TreeSitterHaskell @@ -93,6 +94,8 @@ public struct CodeLanguage { return tree_sitter_c_sharp() case .css: return tree_sitter_css() + case .elixir: + return tree_sitter_elixir() case .go: return tree_sitter_go() case .goMod: @@ -155,6 +158,7 @@ public extension CodeLanguage { .cpp, .cSharp, .css, + .elixir, .go, .goMod, .haskell, @@ -190,6 +194,9 @@ public extension CodeLanguage { /// A language structure for `CSS` static let css: CodeLanguage = .init(id: .css, tsName: "CSS", extensions: ["css"]) + /// A language structure for `Elixir` + static let elixir: CodeLanguage = .init(id: .elixir, tsName: "Elixir", extensions: ["ex", "exs"]) + /// A language structure for `Go` static let go: CodeLanguage = .init(id: .go, tsName: "Go", extensions: ["go"]) diff --git a/Sources/CodeEditTextView/CodeLanguage/TreeSitterLanguage.swift b/Sources/CodeEditTextView/CodeLanguage/TreeSitterLanguage.swift index 0cb998d80..cc3673043 100644 --- a/Sources/CodeEditTextView/CodeLanguage/TreeSitterLanguage.swift +++ b/Sources/CodeEditTextView/CodeLanguage/TreeSitterLanguage.swift @@ -14,6 +14,7 @@ public enum TreeSitterLanguage: String { case cpp case cSharp case css + case elixir case go case goMod case haskell diff --git a/Sources/CodeEditTextView/CodeLanguage/TreeSitterModel.swift b/Sources/CodeEditTextView/CodeLanguage/TreeSitterModel.swift index 3aea409ef..75c81db5e 100644 --- a/Sources/CodeEditTextView/CodeLanguage/TreeSitterModel.swift +++ b/Sources/CodeEditTextView/CodeLanguage/TreeSitterModel.swift @@ -30,6 +30,8 @@ public class TreeSitterModel { return cSharpQuery case .css: return cssQuery + case .elixir: + return elixirQuery case .go: return goQuery case .goMod: @@ -90,6 +92,11 @@ public class TreeSitterModel { return queryFor(.css) }() + /// Query for `Elixir` files. + public private(set) lazy var elixirQuery: Query? = { + return queryFor(.elixir) + }() + /// Query for `Go` files. public private(set) lazy var goQuery: Query? = { return queryFor(.go) diff --git a/Sources/CodeEditTextView/Documentation.docc/Add-Languages.md b/Sources/CodeEditTextView/Documentation.docc/Add-Languages.md index 3b1dc62dd..35627eb37 100644 --- a/Sources/CodeEditTextView/Documentation.docc/Add-Languages.md +++ b/Sources/CodeEditTextView/Documentation.docc/Add-Languages.md @@ -204,3 +204,7 @@ When everything is working correctly push your `tree-sitter-{lang}` changes to ` > Take [this PR description](https://github.com/tree-sitter/tree-sitter-javascript/pull/223) as a template and cross-reference it with your Pull Request. Now you can remove the local dependencies and replace it with the actual package URLs and submit a Pull Request for ``CodeEditTextView``. + +## Documentation + +Please make sure to add the newly created properties to the documentation `*.md` files. diff --git a/Sources/CodeEditTextView/Documentation.docc/CodeLanguage.md b/Sources/CodeEditTextView/Documentation.docc/CodeLanguage.md index 32fc0efd9..bcc6b3fb5 100644 --- a/Sources/CodeEditTextView/Documentation.docc/CodeLanguage.md +++ b/Sources/CodeEditTextView/Documentation.docc/CodeLanguage.md @@ -24,6 +24,7 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL) - C++ - C# - CSS +- Elixir - Go - Go Mod - Haskell @@ -38,6 +39,7 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL) - Rust - Swift - YAML +- Zig ## Topics @@ -65,6 +67,7 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL) - ``cpp`` - ``cSharp`` - ``css`` +- ``elixir`` - ``go`` - ``goMod`` - ``haskell`` @@ -79,6 +82,7 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL) - ``rust`` - ``swift`` - ``yaml`` +- ``zig`` ### Type Methods diff --git a/Sources/CodeEditTextView/Documentation.docc/TreeSitterModel.md b/Sources/CodeEditTextView/Documentation.docc/TreeSitterModel.md index e8430f495..4c2036c06 100644 --- a/Sources/CodeEditTextView/Documentation.docc/TreeSitterModel.md +++ b/Sources/CodeEditTextView/Documentation.docc/TreeSitterModel.md @@ -37,6 +37,7 @@ let query = TreeSitterModel.shared.swiftQuery - ``cppQuery`` - ``cSharpQuery`` - ``cssQuery`` +- ``elixirQuery`` - ``goQuery`` - ``goModQuery`` - ``haskellQuery`` @@ -51,3 +52,4 @@ let query = TreeSitterModel.shared.swiftQuery - ``rustQuery`` - ``swiftQuery`` - ``yamlQuery`` +- ``zigQuery`` diff --git a/Tests/CodeEditTextViewTests/CodeEditTextViewTests.swift b/Tests/CodeEditTextViewTests/CodeEditTextViewTests.swift index 4b4a550da..31bf5f708 100644 --- a/Tests/CodeEditTextViewTests/CodeEditTextViewTests.swift +++ b/Tests/CodeEditTextViewTests/CodeEditTextViewTests.swift @@ -107,6 +107,22 @@ final class CodeEditTextViewTests: XCTestCase { XCTAssertEqual(language.id, .css) } + // MARK: Elixir + + func test_CodeLanguageElixir() throws { + let url = URL(fileURLWithPath: "~/path/to/file.ex") + let language = CodeLanguage.detectLanguageFrom(url: url) + + XCTAssertEqual(language.id, .elixir) + } + + func test_CodeLanguageElixir2() throws { + let url = URL(fileURLWithPath: "~/path/to/file.exs") + let language = CodeLanguage.detectLanguageFrom(url: url) + + XCTAssertEqual(language.id, .elixir) + } + // MARK: Go func test_CodeLanguageGo() throws { @@ -247,6 +263,15 @@ final class CodeEditTextViewTests: XCTestCase { XCTAssertEqual(language.id, .yaml) } + // MARK: Zig + + func test_CodeLanguageZig() throws { + let url = URL(fileURLWithPath: "~/path/to/file.zig") + let language = CodeLanguage.detectLanguageFrom(url: url) + + XCTAssertEqual(language.id, .zig) + } + // MARK: Unsupported func test_CodeLanguageUnsupported() throws {