Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat]: Add language support for Elixir / Update docs for Zig #73

Merged
merged 6 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/mattmassicotte/tree-sitter-html.git", branch: "feature/spm"),
Expand All @@ -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"),
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 TreeSitterHTML
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -152,6 +155,7 @@ public extension CodeLanguage {
.cpp,
.cSharp,
.css,
.elixir,
.go,
.goMod,
.html,
Expand Down Expand Up @@ -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"])

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 html
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 @@ -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)
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
- HTML
Expand All @@ -37,6 +38,7 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL)
- Rust
- Swift
- YAML
- Zig

## Topics

Expand Down Expand Up @@ -64,6 +66,7 @@ let language = CodeLanguage.detectLanguageFrom(url: fileURL)
- ``cpp``
- ``cSharp``
- ``css``
- ``elixir``
- ``go``
- ``goMod``
- ``html``
Expand All @@ -77,6 +80,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``
- ``htmlQuery``
Expand All @@ -50,3 +51,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 @@ -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 {
Expand Down