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 Ruby Language Support #597

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 = [
wsxiaoys marked this conversation as resolved.
Show resolved Hide resolved
"__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
CrCs2O4 marked this conversation as resolved.
Show resolved Hide resolved

; 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_ruby::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/)
CrCs2O4 marked this conversation as resolved.
Show resolved Hide resolved

## 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 | 🚫 | 🚫 |