From 65931370142be31163507bcde7b664fc783185ba Mon Sep 17 00:00:00 2001 From: Matt <85322+mattmassicotte@users.noreply.github.com> Date: Thu, 11 Jul 2024 12:02:46 -0400 Subject: [PATCH] Rust support #20 --- .gitmodules | 3 + Configurations/NonSwiftWorkaround.xcconfig | 1 + Dependencies/Package.swift | 2 + .../TreeSitterParsers/TreeSitterParsers.swift | 1 + Edit.xcodeproj/project.pbxproj | 114 ++++++++++++++++++ .../xcshareddata/swiftpm/Package.resolved | 11 +- .../xcshareddata/xcschemes/Rust.xcscheme | 97 +++++++++++++++ Edit/Modules/SyntaxService/RootLanguage.swift | 6 + Edit/Resources/Info.plist | 15 +++ EditIntents/HighlightIntent.swift | 1 + Extensions/Rust/RustStandaloneExtension.swift | 36 ++++++ Preview/Info.plist | 1 + submodules/chime-rust | 1 + 13 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 Edit.xcodeproj/xcshareddata/xcschemes/Rust.xcscheme create mode 100644 Extensions/Rust/RustStandaloneExtension.swift create mode 160000 submodules/chime-rust diff --git a/.gitmodules b/.gitmodules index 031e14e..bec5070 100644 --- a/.gitmodules +++ b/.gitmodules @@ -16,3 +16,6 @@ [submodule "submodules/chime-ruby"] path = submodules/chime-ruby url = git@github.com:ChimeHQ/chime-ruby.git +[submodule "submodules/chime-rust"] + path = submodules/chime-rust + url = git@github.com:ChimeHQ/chime-rust.git diff --git a/Configurations/NonSwiftWorkaround.xcconfig b/Configurations/NonSwiftWorkaround.xcconfig index ccd3eb5..4225975 100644 --- a/Configurations/NonSwiftWorkaround.xcconfig +++ b/Configurations/NonSwiftWorkaround.xcconfig @@ -18,4 +18,5 @@ OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DI 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)/TreeSitterRust.modulemap OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterSwift.modulemap diff --git a/Dependencies/Package.swift b/Dependencies/Package.swift index 6263510..648ea5c 100644 --- a/Dependencies/Package.swift +++ b/Dependencies/Package.swift @@ -22,6 +22,7 @@ let package = Package( .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/tree-sitter/tree-sitter-rust", branch: "master"), .package(url: "https://github.com/alex-pinkus/tree-sitter-swift", branch: "with-generated-files"), ], targets: [ @@ -38,6 +39,7 @@ let package = Package( .product(name: "TreeSitterOCaml", package: "tree-sitter-ocaml"), .product(name: "TreeSitterPython", package: "tree-sitter-python"), .product(name: "TreeSitterRuby", package: "tree-sitter-ruby"), + .product(name: "TreeSitterRust", package: "tree-sitter-rust"), .product(name: "TreeSitterSwift", package: "tree-sitter-swift"), ] ), diff --git a/Dependencies/Sources/TreeSitterParsers/TreeSitterParsers.swift b/Dependencies/Sources/TreeSitterParsers/TreeSitterParsers.swift index af9ee89..bf4f55e 100644 --- a/Dependencies/Sources/TreeSitterParsers/TreeSitterParsers.swift +++ b/Dependencies/Sources/TreeSitterParsers/TreeSitterParsers.swift @@ -9,4 +9,5 @@ @_exported import TreeSitterOCaml @_exported import TreeSitterPython @_exported import TreeSitterRuby +@_exported import TreeSitterRust @_exported import TreeSitterSwift diff --git a/Edit.xcodeproj/project.pbxproj b/Edit.xcodeproj/project.pbxproj index 36ee3b2..6fc364d 100644 --- a/Edit.xcodeproj/project.pbxproj +++ b/Edit.xcodeproj/project.pbxproj @@ -89,6 +89,10 @@ C973E0112B62BE0C000998F7 /* Highlighter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C973DFF62B62808D000998F7 /* Highlighter.swift */; }; C973E0132B62BE9F000998F7 /* TextViewSystemNeonInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = C99D76112B5EFA050028E3B0 /* TextViewSystemNeonInterface.swift */; }; C973E01F2B62C007000998F7 /* TokenServiceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C973E01E2B62C007000998F7 /* TokenServiceWrapper.swift */; }; + C97640EE2C40372C002C94BF /* RustExtension.appex in Copy Extensions */ = {isa = PBXBuildFile; fileRef = C97640E62C40372C002C94BF /* RustExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + C97640F42C403777002C94BF /* RustExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C97640F32C403777002C94BF /* RustExtension.swift */; }; + C97640F52C40377D002C94BF /* RustExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C97640F32C403777002C94BF /* RustExtension.swift */; }; + C97640F82C403791002C94BF /* ChimeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9FE52F42A7539B100CACA1A /* ChimeKit.framework */; }; C979187B2A9CC1110046EAF1 /* SearchItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C97918752A9CBEF20046EAF1 /* SearchItem.swift */; }; C979187C2A9CC1190046EAF1 /* RoundedCorners.swift in Sources */ = {isa = PBXBuildFile; fileRef = C97918792A9CBF8C0046EAF1 /* RoundedCorners.swift */; }; C979187D2A9CC1200046EAF1 /* ItemBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = C97918772A9CBF330046EAF1 /* ItemBackground.swift */; }; @@ -453,6 +457,20 @@ remoteGlobalIDString = C9B8AA492B37055800C79606; remoteInfo = SyntaxService; }; + C97640EC2C40372C002C94BF /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C9FE52912A7525D000CACA1A /* Project object */; + proxyType = 1; + remoteGlobalIDString = C97640E52C40372C002C94BF; + remoteInfo = Rust; + }; + C97640F62C40378C002C94BF /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C9FE52912A7525D000CACA1A /* Project object */; + proxyType = 1; + remoteGlobalIDString = C9FE52F32A7539B100CACA1A; + remoteInfo = ChimeKit; + }; C97918712A9CBD6B0046EAF1 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = C9FE52912A7525D000CACA1A /* Project object */; @@ -938,6 +956,7 @@ dstPath = "$(EXTENSIONS_FOLDER_PATH)"; dstSubfolderSpec = 16; files = ( + C97640EE2C40372C002C94BF /* RustExtension.appex in Copy Extensions */, C93F72582BF26E9C0021ACF3 /* EditIntents.appex in Copy Extensions */, C9E878092A9F53530018340C /* UIPlaceholderExtension.appex in Copy Extensions */, C9818ACA2C3F2C2F0032899D /* GoExtension.appex in Copy Extensions */, @@ -1037,6 +1056,9 @@ C973DFF62B62808D000998F7 /* Highlighter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Highlighter.swift; sourceTree = ""; }; C973E0002B62BDB3000998F7 /* libHighlighting.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libHighlighting.a; sourceTree = BUILT_PRODUCTS_DIR; }; C973E01E2B62C007000998F7 /* TokenServiceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenServiceWrapper.swift; sourceTree = ""; }; + C97640E62C40372C002C94BF /* RustExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.extensionkit-extension"; includeInIndex = 0; path = RustExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; + C97640F22C403744002C94BF /* RustStandaloneExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RustStandaloneExtension.swift; sourceTree = ""; }; + C97640F32C403777002C94BF /* RustExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RustExtension.swift; path = "submodules/chime-rust/Sources/ChimeRust/RustExtension.swift"; sourceTree = SOURCE_ROOT; }; C97918732A9CBEBA0046EAF1 /* StatusBarContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusBarContent.swift; sourceTree = ""; }; C97918752A9CBEF20046EAF1 /* SearchItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchItem.swift; sourceTree = ""; }; C97918772A9CBF330046EAF1 /* ItemBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemBackground.swift; sourceTree = ""; }; @@ -1292,6 +1314,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + C97640E32C40372C002C94BF /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + C97640F82C403791002C94BF /* ChimeKit.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; C979189C2A9D1D6D0046EAF1 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -1594,6 +1624,15 @@ path = Highlighting; sourceTree = ""; }; + C97640E72C40372C002C94BF /* Rust */ = { + isa = PBXGroup; + children = ( + C97640F32C403777002C94BF /* RustExtension.swift */, + C97640F22C403744002C94BF /* RustStandaloneExtension.swift */, + ); + path = Rust; + sourceTree = ""; + }; C979188F2A9CCC5E0046EAF1 /* Animations */ = { isa = PBXGroup; children = ( @@ -1794,6 +1833,7 @@ C9818AC32C3F2C2F0032899D /* Go */, C9BDB54C2B00FD89009225FB /* Info.plist */, C92631A62C40002F00C0AE07 /* Python */, + C97640E72C40372C002C94BF /* Rust */, C9BDB5492B00FD89009225FB /* Swift */, C9E878022A9F53530018340C /* UIPlaceholder */, C942E6772B67B78F00792DD4 /* UserScriptExtension */, @@ -1873,6 +1913,7 @@ C9818AAA2C3EF5ED0032899D /* ElixirExtension.appex */, C9818AC22C3F2C2F0032899D /* GoExtension.appex */, C92631A52C40002F00C0AE07 /* PythonExtension.appex */, + C97640E62C40372C002C94BF /* RustExtension.appex */, ); name = Products; sourceTree = ""; @@ -2452,6 +2493,24 @@ productReference = C973E0002B62BDB3000998F7 /* libHighlighting.a */; productType = "com.apple.product-type.library.static"; }; + C97640E52C40372C002C94BF /* Rust */ = { + isa = PBXNativeTarget; + buildConfigurationList = C97640F12C40372C002C94BF /* Build configuration list for PBXNativeTarget "Rust" */; + buildPhases = ( + C97640E22C40372C002C94BF /* Sources */, + C97640E32C40372C002C94BF /* Frameworks */, + C97640E42C40372C002C94BF /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + C97640F72C40378C002C94BF /* PBXTargetDependency */, + ); + name = Rust; + productName = Rust; + productReference = C97640E62C40372C002C94BF /* RustExtension.appex */; + productType = "com.apple.product-type.extensionkit-extension"; + }; C979189D2A9D1D6D0046EAF1 /* OpenQuickly */ = { isa = PBXNativeTarget; buildConfigurationList = C97918A42A9D1D6D0046EAF1 /* Build configuration list for PBXNativeTarget "OpenQuickly" */; @@ -2729,6 +2788,7 @@ C9818AB12C3EF5ED0032899D /* PBXTargetDependency */, C9818AC92C3F2C2F0032899D /* PBXTargetDependency */, C92631AC2C40002F00C0AE07 /* PBXTargetDependency */, + C97640ED2C40372C002C94BF /* PBXTargetDependency */, ); name = Edit; packageProductDependencies = ( @@ -3064,6 +3124,10 @@ C973DFFF2B62BDB3000998F7 = { CreatedOnToolsVersion = 15.2; }; + C97640E52C40372C002C94BF = { + CreatedOnToolsVersion = 15.4; + LastSwiftMigration = 1540; + }; C979189D2A9D1D6D0046EAF1 = { CreatedOnToolsVersion = 15.0; }; @@ -3223,6 +3287,7 @@ C9818AA92C3EF5ED0032899D /* Elixir */, C9818AC12C3F2C2F0032899D /* Go */, C92631A42C40002F00C0AE07 /* Python */, + C97640E52C40372C002C94BF /* Rust */, ); }; /* End PBXProject section */ @@ -3264,6 +3329,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + C97640E42C40372C002C94BF /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; C9818AA82C3EF5ED0032899D /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -3424,6 +3496,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + C97640E22C40372C002C94BF /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C97640F42C403777002C94BF /* RustExtension.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; C979189B2A9D1D6D0046EAF1 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -3735,6 +3815,7 @@ C9818AB92C3EF6E80032899D /* ElixirExtension.swift in Sources */, C97918F82A9E5E520046EAF1 /* ExtensionRouter.swift in Sources */, C97918FA2A9E5EAF0046EAF1 /* CompositeDocumentService.swift in Sources */, + C97640F52C40377D002C94BF /* RustExtension.swift in Sources */, C942E6AE2B69889F00792DD4 /* UserScriptExtension.swift in Sources */, C9FE54072A7A617000CACA1A /* ExtensionDocumentState.swift in Sources */, C941F0AD2B6E65110003B640 /* Process+Pipes.swift in Sources */, @@ -3958,6 +4039,16 @@ target = C9B8AA492B37055800C79606 /* SyntaxService */; targetProxy = C973E01C2B62BF4C000998F7 /* PBXContainerItemProxy */; }; + C97640ED2C40372C002C94BF /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = C97640E52C40372C002C94BF /* Rust */; + targetProxy = C97640EC2C40372C002C94BF /* PBXContainerItemProxy */; + }; + C97640F72C40378C002C94BF /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = C9FE52F32A7539B100CACA1A /* ChimeKit */; + targetProxy = C97640F62C40378C002C94BF /* PBXContainerItemProxy */; + }; C97918722A9CBD6B0046EAF1 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = C9FE539A2A76709D00CACA1A /* Status */; @@ -4517,6 +4608,20 @@ }; name = Release; }; + C97640EF2C40372C002C94BF /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = C9E878112A9F53BB0018340C /* Extension.xcconfig */; + buildSettings = { + }; + name = Debug; + }; + C97640F02C40372C002C94BF /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = C9E878112A9F53BB0018340C /* Extension.xcconfig */; + buildSettings = { + }; + name = Release; + }; C97918A52A9D1D6D0046EAF1 /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = C9FE531A2A759BC400CACA1A /* Module.xcconfig */; @@ -4961,6 +5066,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + C97640F12C40372C002C94BF /* Build configuration list for PBXNativeTarget "Rust" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C97640EF2C40372C002C94BF /* Debug */, + C97640F02C40372C002C94BF /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; C97918A42A9D1D6D0046EAF1 /* Build configuration list for PBXNativeTarget "OpenQuickly" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 0040ffa..692c41c 100644 --- a/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "547710c82c4ec23bd5902c9d500be3a3fc3c0a4a4837d5f28eda84b99ec91cc1", + "originHash" : "7ec6ccb9bc276a295422e18b1a495ba45c60ca70b5912320b7f399276466ef72", "pins" : [ { "identity" : "asyncxpcconnection", @@ -330,6 +330,15 @@ "revision" : "0ffe457fb6aabf064f173fd30ea356845cef2513" } }, + { + "identity" : "tree-sitter-rust", + "kind" : "remoteSourceControl", + "location" : "https://github.com/tree-sitter/tree-sitter-rust", + "state" : { + "branch" : "master", + "revision" : "9c84af007b0f144954adb26b3f336495cbb320a7" + } + }, { "identity" : "tree-sitter-swift", "kind" : "remoteSourceControl", diff --git a/Edit.xcodeproj/xcshareddata/xcschemes/Rust.xcscheme b/Edit.xcodeproj/xcshareddata/xcschemes/Rust.xcscheme new file mode 100644 index 0000000..2d6b3c0 --- /dev/null +++ b/Edit.xcodeproj/xcshareddata/xcschemes/Rust.xcscheme @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Edit/Modules/SyntaxService/RootLanguage.swift b/Edit/Modules/SyntaxService/RootLanguage.swift index 668adbd..0a378b1 100644 --- a/Edit/Modules/SyntaxService/RootLanguage.swift +++ b/Edit/Modules/SyntaxService/RootLanguage.swift @@ -18,6 +18,7 @@ public enum RootLanguage: Hashable, CaseIterable, Sendable { case ocamlInterface case python case ruby + case rust case swift var typeIdentifier: UTType { @@ -33,6 +34,7 @@ public enum RootLanguage: Hashable, CaseIterable, Sendable { case .ocamlInterface: .ocamlInterface case .python: .pythonScript case .ruby: .rubyScript + case .rust: .rustSource case .swift: .swiftSource } } @@ -67,6 +69,8 @@ extension RootLanguage: RawRepresentable { self = .python case "ruby": self = .ruby + case "rust": + self = .rust case "swift": self = .swift default: @@ -98,6 +102,8 @@ extension RootLanguage: RawRepresentable { "Python" case .ruby: "Ruby" + case .rust: + "Rust" case .swift: "Swift" } diff --git a/Edit/Resources/Info.plist b/Edit/Resources/Info.plist index da9d876..075c62b 100644 --- a/Edit/Resources/Info.plist +++ b/Edit/Resources/Info.plist @@ -277,6 +277,21 @@ + + UTTypeConformsTo + + public.source-code + + UTTypeIdentifier + org.rust-lang.rust-script + UTTypeTagSpecification + + public.filename-extension + + rs + + + diff --git a/EditIntents/HighlightIntent.swift b/EditIntents/HighlightIntent.swift index 98d17f0..1fe8884 100644 --- a/EditIntents/HighlightIntent.swift +++ b/EditIntents/HighlightIntent.swift @@ -21,6 +21,7 @@ extension RootLanguage: AppEnum { .ocamlInterface: "OCaml Interface", .python: "Python", .ruby: "Ruby", + .rust: "Rust", .swift: "Swift", ] } diff --git a/Extensions/Rust/RustStandaloneExtension.swift b/Extensions/Rust/RustStandaloneExtension.swift new file mode 100644 index 0000000..2ba6757 --- /dev/null +++ b/Extensions/Rust/RustStandaloneExtension.swift @@ -0,0 +1,36 @@ +import Foundation +import ExtensionFoundation + +import ChimeKit +import Extendable + +@main +final class RustStandaloneExtension: ChimeExtension { + @InitializerTransferred private var localExtension: StandaloneExtension + + nonisolated init() { + self._localExtension = InitializerTransferred(mainActorProvider: { + StandaloneExtension(extensionProvider: { host in + RustExtension(host: host) + }) + }) + } + + func acceptHostConnection(_ host: HostProtocol) throws { + try localExtension.acceptHostConnection(host) + } +} + +extension RustStandaloneExtension { + var configuration: ExtensionConfiguration { + get throws { + try localExtension.configuration + } + } + + var applicationService: some ApplicationService { + get throws { + try localExtension.applicationService + } + } +} diff --git a/Preview/Info.plist b/Preview/Info.plist index d2302c5..eca59ac 100644 --- a/Preview/Info.plist +++ b/Preview/Info.plist @@ -23,6 +23,7 @@ public.python-script public.ruby-script org.rubygems.specification + org.rust-lang.rust-script public.swift-source QLSupportsSearchableItems diff --git a/submodules/chime-rust b/submodules/chime-rust new file mode 160000 index 0000000..33172e6 --- /dev/null +++ b/submodules/chime-rust @@ -0,0 +1 @@ +Subproject commit 33172e635c5c752d2e86f88356d7d21ecfde04c8