Skip to content

Commit

Permalink
Replace TreeSitter parsers provider. Add bunch of languages.
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyzanowskim committed Aug 6, 2024
1 parent dc37eb2 commit 6afdecf
Show file tree
Hide file tree
Showing 279 changed files with 7,374,639 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DemoApp/EditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EditorViewController: NSViewController {
super.viewDidLoad()
view.frame.size = CGSize(width: 500, height: 500)


textView.backgroundColor = .controlBackgroundColor
textView.addPlugin(
NeonPlugin(theme: .default, language: .swift)
)
Expand Down
54 changes: 50 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,66 @@ let package = Package(
targets: ["NeonPlugin"]),
],
dependencies: [
.package(url: "https://github.com/krzyzanowskim/STTextView", from: "0.9.4"),
.package(url: "https://github.com/krzyzanowskim/STTextView", from: "0.9.6"),
.package(url: "https://github.com/ChimeHQ/Neon.git", from: "0.6.0"),
.package(url: "https://github.com/krzyzanowskim/tree-sitter-xcframework", from: "0.208.5")
.package(url: "https://github.com/ChimeHQ/SwiftTreeSitter", from: "0.8.0"),
.package(path: "TreeSitterLanguages")
],
targets: [
.target(
name: "NeonPlugin",
dependencies: [
.product(name: "STTextView", package: "STTextView"),
"Neon",
.product(name: "TreeSitter", package: "tree-sitter-xcframework")
"TreeSitterResource",
],
path: "Sources/NeonPlugin",
resources: [.process("Themes.xcassets")]
),
.target(
name: "TreeSitterResource",
dependencies: [
.product(name: "SwiftTreeSitter", package: "SwiftTreeSitter"),
.product(name: "TreeSitterBash", package: "TreeSitterLanguages"),
.product(name: "TreeSitterBashQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterC", package: "TreeSitterLanguages"),
.product(name: "TreeSitterCQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterCPP", package: "TreeSitterLanguages"),
.product(name: "TreeSitterCPPQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterCSharp", package: "TreeSitterLanguages"),
.product(name: "TreeSitterCSharpQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterCSS", package: "TreeSitterLanguages"),
.product(name: "TreeSitterCSSQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterGo", package: "TreeSitterLanguages"),
.product(name: "TreeSitterGoQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterHTML", package: "TreeSitterLanguages"),
.product(name: "TreeSitterHTMLQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterJava", package: "TreeSitterLanguages"),
.product(name: "TreeSitterJavaQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterJavaScript", package: "TreeSitterLanguages"),
.product(name: "TreeSitterJavaScriptQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterJSON", package: "TreeSitterLanguages"),
.product(name: "TreeSitterJSONQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterMarkdown", package: "TreeSitterLanguages"),
.product(name: "TreeSitterMarkdownQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterPHP", package: "TreeSitterLanguages"),
.product(name: "TreeSitterPHPQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterPython", package: "TreeSitterLanguages"),
.product(name: "TreeSitterPythonQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterRuby", package: "TreeSitterLanguages"),
.product(name: "TreeSitterRubyQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterRust", package: "TreeSitterLanguages"),
.product(name: "TreeSitterRustQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterSwift", package: "TreeSitterLanguages"),
.product(name: "TreeSitterSwiftQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterSQL", package: "TreeSitterLanguages"),
.product(name: "TreeSitterSQLQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterTOML", package: "TreeSitterLanguages"),
.product(name: "TreeSitterTOMLQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterTypeScript", package: "TreeSitterLanguages"),
.product(name: "TreeSitterTypeScriptQueries", package: "TreeSitterLanguages"),
.product(name: "TreeSitterYAML", package: "TreeSitterLanguages"),
.product(name: "TreeSitterYAMLQueries", package: "TreeSitterLanguages")
]
)
]
)
2 changes: 1 addition & 1 deletion Sources/NeonPlugin/Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import TreeSitterClient
import SwiftTreeSitter

// tree-sitter-xcframework
import TreeSitter
//import TreeSitter
import TreeSitterResource

@MainActor
Expand Down
2 changes: 1 addition & 1 deletion Sources/NeonPlugin/NeonPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Cocoa
import STTextView

// tree-sitter-xcframework
import TreeSitter
//import TreeSitter
import TreeSitterResource

public struct NeonPlugin: STPlugin {
Expand Down
202 changes: 202 additions & 0 deletions Sources/TreeSitterResource/TreeSitterLanguage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import Foundation

import tree_sitter

import TreeSitterBash
import TreeSitterBashQueries
import TreeSitterC
import TreeSitterCQueries
import TreeSitterCPP
import TreeSitterCPPQueries
import TreeSitterCSharp
import TreeSitterCSharpQueries
import TreeSitterCSS
import TreeSitterCSSQueries
import TreeSitterGo
import TreeSitterGoQueries
import TreeSitterHTML
import TreeSitterHTMLQueries
import TreeSitterJava
import TreeSitterJavaQueries
import TreeSitterJavaScript
import TreeSitterJavaScriptQueries
import TreeSitterJSON
import TreeSitterJSONQueries
import TreeSitterMarkdown
import TreeSitterMarkdownQueries
import TreeSitterPHP
import TreeSitterPHPQueries
import TreeSitterPython
import TreeSitterPythonQueries
import TreeSitterRuby
import TreeSitterRubyQueries
import TreeSitterRust
import TreeSitterRustQueries
import TreeSitterSwift
import TreeSitterSwiftQueries
import TreeSitterSQL
import TreeSitterSQLQueries
import TreeSitterTOML
import TreeSitterTOMLQueries
import TreeSitterTypeScript
import TreeSitterTypeScriptQueries
import TreeSitterYAML
import TreeSitterYAMLQueries

public enum TreeSitterLanguage: CaseIterable, Hashable {
case bash
case c
case cpp
case csharp
case css
case go
case html
case java
case javascript
case json
case markdown
case php
case python
case ruby
case rust
case swift
case sql
case toml
case typescript
case yaml

public var parser: UnsafePointer<TSLanguage> {
switch self {
case .bash:
tree_sitter_bash()
case .c:
tree_sitter_c()
case .cpp:
tree_sitter_cpp()
case .csharp:
tree_sitter_c_sharp()
case .css:
tree_sitter_css()
case .go:
tree_sitter_go()
case .html:
tree_sitter_html()
case .java:
tree_sitter_java()
case .javascript:
tree_sitter_javascript()
case .json:
tree_sitter_json()
case .markdown:
tree_sitter_markdown()
case .php:
tree_sitter_php()
case .python:
tree_sitter_python()
case .ruby:
tree_sitter_ruby()
case .rust:
tree_sitter_rust()
case .swift:
tree_sitter_swift()
case .sql:
tree_sitter_sql()
case .toml:
tree_sitter_toml()
case .typescript:
tree_sitter_typescript()
case .yaml:
tree_sitter_yaml()
}
}

public var highlightQueryURL: URL? {
switch self {
case .bash:
TreeSitterBashQueries.Query.highlightsFileURL
case .c:
TreeSitterCQueries.Query.highlightsFileURL
case .cpp:
TreeSitterCPPQueries.Query.highlightsFileURL
case .csharp:
TreeSitterCSharpQueries.Query.highlightsFileURL
case .css:
TreeSitterCSSQueries.Query.highlightsFileURL
case .go:
TreeSitterGoQueries.Query.highlightsFileURL
case .html:
TreeSitterHTMLQueries.Query.highlightsFileURL
case .java:
TreeSitterJavaQueries.Query.highlightsFileURL
case .javascript:
TreeSitterJavaScriptQueries.Query.highlightsFileURL
case .json:
TreeSitterJSONQueries.Query.highlightsFileURL
case .markdown:
TreeSitterMarkdownQueries.Query.highlightsFileURL
case .php:
TreeSitterPHPQueries.Query.highlightsFileURL
case .python:
TreeSitterPythonQueries.Query.highlightsFileURL
case .ruby:
TreeSitterRubyQueries.Query.highlightsFileURL
case .rust:
TreeSitterRustQueries.Query.highlightsFileURL
case .swift:
TreeSitterSwiftQueries.Query.highlightsFileURL
case .sql:
TreeSitterSQLQueries.Query.highlightsFileURL
case .toml:
TreeSitterTOMLQueries.Query.highlightsFileURL
case .typescript:
TreeSitterTypeScriptQueries.Query.highlightsFileURL
case .yaml:
TreeSitterYAMLQueries.Query.highlightsFileURL
}
}

public var localsQueryURL: URL? {
switch self {
case .bash:
nil
case .c:
nil
case .cpp:
nil
case .csharp:
nil
case .css:
nil
case .go:
nil
case .html:
nil
case .java:
nil
case .javascript:
TreeSitterJavaScriptQueries.Query.localsFileURL
case .json:
nil
case .markdown:
nil
case .php:
nil
case .python:
nil
case .ruby:
TreeSitterRubyQueries.Query.localsFileURL
case .rust:
nil
case .swift:
TreeSitterSwiftQueries.Query.localsFileURL
case .sql:
nil
case .toml:
nil
case .typescript:
TreeSitterTypeScriptQueries.Query.localsFileURL
case .yaml:
nil
}
}
}
21 changes: 21 additions & 0 deletions TreeSitterLanguages/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Simon Støvring

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 6afdecf

Please sign in to comment.