Skip to content

Commit

Permalink
Ruby language support #20
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Jul 11, 2024
1 parent fd9ed77 commit 44eecf1
Show file tree
Hide file tree
Showing 15 changed files with 346 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "submodules/chime-python"]
path = submodules/chime-python
url = [email protected]:ChimeHQ/chime-python.git
[submodule "submodules/chime-ruby"]
path = submodules/chime-ruby
url = [email protected]:ChimeHQ/chime-ruby.git
1 change: 1 addition & 0 deletions Configurations/NonSwiftWorkaround.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DI
OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterMarkdownInline.modulemap
OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterOCaml.modulemap
OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterPython.modulemap
OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterRuby.modulemap
OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterSwift.modulemap
2 changes: 2 additions & 0 deletions Dependencies/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let package = Package(
.package(url: "https://github.com/tree-sitter-grammars/tree-sitter-markdown", branch: "split_parser"),
.package(url: "https://github.com/tree-sitter/tree-sitter-ocaml", branch: "master"),
.package(url: "https://github.com/tree-sitter/tree-sitter-python", branch: "master"),
.package(url: "https://github.com/tree-sitter/tree-sitter-ruby", branch: "master"),
.package(url: "https://github.com/alex-pinkus/tree-sitter-swift", branch: "with-generated-files"),
],
targets: [
Expand All @@ -36,6 +37,7 @@ let package = Package(
.product(name: "TreeSitterMarkdown", package: "tree-sitter-markdown"),
.product(name: "TreeSitterOCaml", package: "tree-sitter-ocaml"),
.product(name: "TreeSitterPython", package: "tree-sitter-python"),
.product(name: "TreeSitterRuby", package: "tree-sitter-ruby"),
.product(name: "TreeSitterSwift", package: "tree-sitter-swift"),
]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
@_exported import TreeSitterMarkdownInline
@_exported import TreeSitterOCaml
@_exported import TreeSitterPython
@_exported import TreeSitterRuby
@_exported import TreeSitterSwift
13 changes: 13 additions & 0 deletions Edit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,13 @@
remoteGlobalIDString = C9FE52F32A7539B100CACA1A;
remoteInfo = ChimeKit;
};
C99A8DFE2C4013BC00D8F599 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = C9FE52912A7525D000CACA1A /* Project object */;
proxyType = 1;
remoteGlobalIDString = C9B8AA492B37055800C79606;
remoteInfo = SyntaxService;
};
C99D76162B5FE1530028E3B0 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = C9FE52912A7525D000CACA1A /* Project object */;
Expand Down Expand Up @@ -2375,6 +2382,7 @@
buildRules = (
);
dependencies = (
C99A8DFF2C4013BC00D8F599 /* PBXTargetDependency */,
C9439A6F2C3EB41F0020DDF5 /* PBXTargetDependency */,
C9439A6D2C3EB3F00020DDF5 /* PBXTargetDependency */,
);
Expand Down Expand Up @@ -4113,6 +4121,11 @@
target = C9FE52F32A7539B100CACA1A /* ChimeKit */;
targetProxy = C99A8DFB2C40016E00D8F599 /* PBXContainerItemProxy */;
};
C99A8DFF2C4013BC00D8F599 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = C9B8AA492B37055800C79606 /* SyntaxService */;
targetProxy = C99A8DFE2C4013BC00D8F599 /* PBXContainerItemProxy */;
};
C99D76172B5FE1530028E3B0 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = C9FE53DC2A7A5A2A00CACA1A /* ExtensionHost */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "a40fd49a16700338aabad67421f82fb686bfcd06da9dc2ea24be06be89094a14",
"originHash" : "547710c82c4ec23bd5902c9d500be3a3fc3c0a4a4837d5f28eda84b99ec91cc1",
"pins" : [
{
"identity" : "asyncxpcconnection",
Expand Down Expand Up @@ -321,6 +321,15 @@
"revision" : "ccc2408e558029ad82b0dea63ff55ada495965da"
}
},
{
"identity" : "tree-sitter-ruby",
"kind" : "remoteSourceControl",
"location" : "https://github.com/tree-sitter/tree-sitter-ruby",
"state" : {
"branch" : "master",
"revision" : "0ffe457fb6aabf064f173fd30ea356845cef2513"
}
},
{
"identity" : "tree-sitter-swift",
"kind" : "remoteSourceControl",
Expand Down
9 changes: 9 additions & 0 deletions Edit/Modules/SyntaxService/LanguageProfile+Profiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ extension LanguageProfile {
return LanguageProfile.pythonProfile
}

if utType.conforms(to: .rubyScript) {
return LanguageProfile.rubyProfile
}

if utType.conforms(to: .swiftSource) {
return LanguageProfile.swiftProfile
}
Expand Down Expand Up @@ -110,6 +114,11 @@ extension LanguageProfile {
language: Language(tree_sitter_python())
)

static let rubyProfile = LanguageProfile(
RootLanguage.ruby,
language: Language(tree_sitter_ruby())
)

static let swiftProfile = LanguageProfile(
RootLanguage.swift,
language: Language(tree_sitter_swift())
Expand Down
6 changes: 6 additions & 0 deletions Edit/Modules/SyntaxService/RootLanguage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum RootLanguage: Hashable, CaseIterable, Sendable {
case ocaml
case ocamlInterface
case python
case ruby
case swift

var typeIdentifier: UTType {
Expand All @@ -31,6 +32,7 @@ public enum RootLanguage: Hashable, CaseIterable, Sendable {
case .ocaml: .ocamlSource
case .ocamlInterface: .ocamlInterface
case .python: .pythonScript
case .ruby: .rubyScript
case .swift: .swiftSource
}
}
Expand Down Expand Up @@ -63,6 +65,8 @@ extension RootLanguage: RawRepresentable {
self = .ocamlInterface
case "python":
self = .python
case "ruby":
self = .ruby
case "swift":
self = .swift
default:
Expand Down Expand Up @@ -92,6 +96,8 @@ extension RootLanguage: RawRepresentable {
"OCaml Interface"
case .python:
"Python"
case .ruby:
"Ruby"
case .swift:
"Swift"
}
Expand Down
51 changes: 51 additions & 0 deletions Edit/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@
</array>
</dict>
</dict>
<dict>
<key>UTTypeReferenceURL</key>
<string>https://cocoapods.org</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.ruby-script</string>
</array>
<key>UTTypeIdentifier</key>
<string>org.cocoapods.specification</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>podspec</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeConformsTo</key>
<array>
Expand Down Expand Up @@ -226,6 +243,40 @@
</array>
</dict>
</dict>
<dict>
<key>UTTypeReferenceURL</key>
<string>https://rubygems.org</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.ruby-script</string>
</array>
<key>UTTypeIdentifier</key>
<string>org.rubygems.specification</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>gemspec</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeReferenceURL</key>
<string>https://github.com/ruby/rake</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.ruby-script</string>
</array>
<key>UTTypeIdentifier</key>
<string>org.ruby-lang.rake</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>rake</string>
</array>
</dict>
</dict>
</array>
</dict>
</plist>
154 changes: 154 additions & 0 deletions Edit/Resources/LanguageData/Ruby/queries/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
(identifier) @variable

((identifier) @function.method
(#is-not? local))

[
"alias"
"and"
"begin"
"break"
"case"
"class"
"def"
"do"
"else"
"elsif"
"end"
"ensure"
"for"
"if"
"in"
"module"
"next"
"or"
"rescue"
"retry"
"return"
"then"
"unless"
"until"
"when"
"while"
"yield"
] @keyword

((identifier) @keyword
(#match? @keyword "^(private|protected|public)$"))

(constant) @constructor

; Function calls

"defined?" @function.method.builtin

(call
method: [(identifier) (constant)] @function.method)

((identifier) @function.method.builtin
(#eq? @function.method.builtin "require"))

; Function definitions

(alias (identifier) @function.method)
(setter (identifier) @function.method)
(method name: [(identifier) (constant)] @function.method)
(singleton_method name: [(identifier) (constant)] @function.method)

; Identifiers

[
(class_variable)
(instance_variable)
] @property

((identifier) @constant.builtin
(#match? @constant.builtin "^__(FILE|LINE|ENCODING)__$"))

(file) @constant.builtin
(line) @constant.builtin
(encoding) @constant.builtin

(hash_splat_nil
"**" @operator) @constant.builtin

((constant) @constant
(#match? @constant "^[A-Z\\d_]+$"))

[
(self)
(super)
] @variable.builtin

(block_parameter (identifier) @variable.parameter)
(block_parameters (identifier) @variable.parameter)
(destructured_parameter (identifier) @variable.parameter)
(hash_splat_parameter (identifier) @variable.parameter)
(lambda_parameters (identifier) @variable.parameter)
(method_parameters (identifier) @variable.parameter)
(splat_parameter (identifier) @variable.parameter)

(keyword_parameter name: (identifier) @variable.parameter)
(optional_parameter name: (identifier) @variable.parameter)

; Literals

[
(string)
(bare_string)
(subshell)
(heredoc_body)
(heredoc_beginning)
] @string

[
(simple_symbol)
(delimited_symbol)
(hash_key_symbol)
(bare_symbol)
] @string.special.symbol

(regex) @string.special.regex
(escape_sequence) @escape

[
(integer)
(float)
] @number

[
(nil)
(true)
(false)
] @constant.builtin

(interpolation
"#{" @punctuation.special
"}" @punctuation.special) @embedded

(comment) @comment

; Operators

[
"="
"=>"
"->"
] @operator

[
","
";"
"."
] @punctuation.delimiter

[
"("
")"
"["
"]"
"{"
"}"
"%w("
"%i("
] @punctuation.bracket
27 changes: 27 additions & 0 deletions Edit/Resources/LanguageData/Ruby/queries/locals.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
((method) @local.scope
(#set! local.scope-inherits false))

[
(lambda)
(block)
(do_block)
] @local.scope

(block_parameter (identifier) @local.definition)
(block_parameters (identifier) @local.definition)
(destructured_parameter (identifier) @local.definition)
(hash_splat_parameter (identifier) @local.definition)
(lambda_parameters (identifier) @local.definition)
(method_parameters (identifier) @local.definition)
(splat_parameter (identifier) @local.definition)

(keyword_parameter name: (identifier) @local.definition)
(optional_parameter name: (identifier) @local.definition)

(identifier) @local.reference

(assignment left: (identifier) @local.definition)
(operator_assignment left: (identifier) @local.definition)
(left_assignment_list (identifier) @local.definition)
(rest_assignment (identifier) @local.definition)
(destructured_left_assignment (identifier) @local.definition)
Loading

0 comments on commit 44eecf1

Please sign in to comment.