diff --git a/Package.swift b/Package.swift index 999e41c10..d12a9f33a 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/mattmassicotte/tree-sitter-html.git", branch: "feature/spm"), @@ -45,6 +46,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: "TreeSitterHTML", package: "tree-sitter-html"), diff --git a/Sources/CodeEditTextView/CodeLanguage/CodeLanguage.swift b/Sources/CodeEditTextView/CodeLanguage/CodeLanguage.swift index 1538f425a..482bae744 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 TreeSitterHTML @@ -92,6 +93,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: @@ -152,6 +155,7 @@ public extension CodeLanguage { .cpp, .cSharp, .css, + .elixir, .go, .goMod, .html, @@ -186,6 +190,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 c06990ebe..beccbda9d 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 html diff --git a/Sources/CodeEditTextView/CodeLanguage/TreeSitterModel.swift b/Sources/CodeEditTextView/CodeLanguage/TreeSitterModel.swift index 0787077a5..ee261273d 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: @@ -88,6 +90,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 eb80899c5..957621b1a 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 - HTML @@ -37,6 +38,7 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL) - Rust - Swift - YAML +- Zig ## Topics @@ -64,6 +66,7 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL) - ``cpp`` - ``cSharp`` - ``css`` +- ``elixir`` - ``go`` - ``goMod`` - ``html`` @@ -77,6 +80,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 f4e105cb3..dd8ae7e95 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`` - ``htmlQuery`` @@ -50,3 +51,4 @@ let query = TreeSitterModel.shared.swiftQuery - ``rustQuery`` - ``swiftQuery`` - ``yamlQuery`` +- ``zigQuery`` diff --git a/Tests/CodeEditTextViewTests/CodeEditTextViewTests.swift b/Tests/CodeEditTextViewTests/CodeEditTextViewTests.swift index 5d9a912ce..20b4d1bf8 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 { @@ -238,6 +254,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 {