Skip to content

Commit

Permalink
feat: add Ruby Support
Browse files Browse the repository at this point in the history
  • Loading branch information
CrCs2O4 committed Oct 19, 2023
1 parent 257dba6 commit 395d579
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 49 additions & 1 deletion crates/tabby-common/assets/languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,52 @@ top_level_keywords = [
"import",
"var",
"const",
]
]

[[config]]
languages = ["ruby"]
line_comment = "#"
# from https://docs.ruby-lang.org/en/3.2/keywords_rdoc.html
top_level_keywords = [
"__ENCODING__",
"__LINE__",
"__FILE__",
"BEGIN",
"END",
"alias",
"and",
"begin",
"break",
"case",
"class",
"def",
"defined?",
"do",
"else",
"elsif",
"end",
"ensure",
"false",
"for",
"if",
"in",
"module",
"next",
"nil",
"not",
"or",
"redo",
"rescue",
"retry",
"return",
"self",
"super",
"then",
"true",
"undef",
"unless",
"until",
"when",
"while",
"yield",
]
1 change: 1 addition & 0 deletions crates/tabby-scheduler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tree-sitter-python = "0.20.2"
tree-sitter-rust = "0.20.3"
tree-sitter-typescript = "0.20.3"
tree-sitter-go = "0.20.0"
tree-sitter-ruby= "0.20.0"

[dev-dependencies]
temp_testdir = "0.2"
Expand Down
66 changes: 66 additions & 0 deletions crates/tabby-scheduler/queries/ruby.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
; https://github.com/tree-sitter/tree-sitter-ruby/blob/master/queries/tags.scm

; Method definitions

(
(comment)* @doc
.
[
(method
name: (_) @name) @definition.method
(singleton_method
name: (_) @name) @definition.method
]
(#strip! @doc "^#\\s*")
(#select-adjacent! @doc @definition.method)
)

(alias
name: (_) @name) @definition.method

(setter
(identifier) @ignore)

; Class definitions

(
(comment)* @doc
.
[
(class
name: [
(constant) @name
(scope_resolution
name: (_) @name)
]) @definition.class
(singleton_class
value: [
(constant) @name
(scope_resolution
name: (_) @name)
]) @definition.class
]
(#strip! @doc "^#\\s*")
(#select-adjacent! @doc @definition.class)
)

; Module definitions

(
(module
name: [
(constant) @name
(scope_resolution
name: (_) @name)
]) @definition.module
)

; Calls

(call method: (identifier) @name) @reference.call

(
[(identifier) (constant)] @name @reference.call
(#is-not? local)
(#not-match? @name "^(lambda|load|require|require_relative|__FILE__|__LINE__)$")
)
12 changes: 12 additions & 0 deletions crates/tabby-scheduler/src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,18 @@ lazy_static! {
.unwrap(),
),
),
(
"ruby",
TagsConfigurationSync(
TagsConfiguration::new(
tree_sitter_go::language(),
include_str!("../queries/ruby.scm"),
"",
)
.unwrap(),
),
),

])
};
}
2 changes: 1 addition & 1 deletion website/docs/programming-languages.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ For an actual example of an issue or pull request adding the above support, plea
* [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript)
* [TypeScript](https://www.typescriptlang.org/)
* [Golang](https://go.dev/): Since v0.4.0
* [Ruby](https://www.ruby-lang.org/)

## Languages Missing Certain Support

Expand All @@ -40,5 +41,4 @@ For an actual example of an issue or pull request adding the above support, plea
| Lua | 🚫 | 🚫 |
| PHP | 🚫 | 🚫 |
| Perl | 🚫 | 🚫 |
| Ruby | 🚫 | 🚫 |
| Scala | 🚫 | 🚫 |

0 comments on commit 395d579

Please sign in to comment.