Skip to content

Commit

Permalink
Merge pull request #73 from lukepistrol/feat/add-language-elixir
Browse files Browse the repository at this point in the history
[Feat]: Add language support for `Elixir` / Update docs for `Zig`
  • Loading branch information
lukepistrol authored Oct 3, 2022
2 parents 2e7f406 + 6b7c195 commit 8398367
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
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 @@ -14,6 +14,7 @@ import TreeSitterC
import TreeSitterCPP
import TreeSitterCSharp
import TreeSitterCSS
import TreeSitterElixir
import TreeSitterGo
import TreeSitterGoMod
import TreeSitterHaskell
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -155,6 +158,7 @@ public extension CodeLanguage {
.cpp,
.cSharp,
.css,
.elixir,
.go,
.goMod,
.haskell,
Expand Down Expand Up @@ -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"])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum TreeSitterLanguage: String {
case cpp
case cSharp
case css
case elixir
case go
case goMod
case haskell
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 @@ -30,6 +30,8 @@ public class TreeSitterModel {
return cSharpQuery
case .css:
return cssQuery
case .elixir:
return elixirQuery
case .go:
return goQuery
case .goMod:
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions Sources/CodeEditTextView/Documentation.docc/Add-Languages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 4 additions & 0 deletions Sources/CodeEditTextView/Documentation.docc/CodeLanguage.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL)
- C++
- C#
- CSS
- Elixir
- Go
- Go Mod
- Haskell
Expand All @@ -38,6 +39,7 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL)
- Rust
- Swift
- YAML
- Zig

## Topics

Expand Down Expand Up @@ -65,6 +67,7 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL)
- ``cpp``
- ``cSharp``
- ``css``
- ``elixir``
- ``go``
- ``goMod``
- ``haskell``
Expand All @@ -79,6 +82,7 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL)
- ``rust``
- ``swift``
- ``yaml``
- ``zig``

### Type Methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ let query = TreeSitterModel.shared.swiftQuery
- ``cppQuery``
- ``cSharpQuery``
- ``cssQuery``
- ``elixirQuery``
- ``goQuery``
- ``goModQuery``
- ``haskellQuery``
Expand All @@ -51,3 +52,4 @@ let query = TreeSitterModel.shared.swiftQuery
- ``rustQuery``
- ``swiftQuery``
- ``yamlQuery``
- ``zigQuery``
25 changes: 25 additions & 0 deletions Tests/CodeEditTextViewTests/CodeEditTextViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8398367

Please sign in to comment.