diff --git a/.gitmodules b/.gitmodules index 55ff8b9..69662b2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "submodules/chime-go"] path = submodules/chime-go url = git@github.com:ChimeHQ/chime-go.git +[submodule "submodules/chime-python"] + path = submodules/chime-python + url = git@github.com:ChimeHQ/chime-python.git diff --git a/Configurations/NonSwiftWorkaround.xcconfig b/Configurations/NonSwiftWorkaround.xcconfig index 43b1f0a..17f0a22 100644 --- a/Configurations/NonSwiftWorkaround.xcconfig +++ b/Configurations/NonSwiftWorkaround.xcconfig @@ -16,4 +16,5 @@ OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DI OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterMarkdown.modulemap 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)/TreeSitterSwift.modulemap diff --git a/Dependencies/Package.swift b/Dependencies/Package.swift index 9011ca8..34b5e2a 100644 --- a/Dependencies/Package.swift +++ b/Dependencies/Package.swift @@ -20,6 +20,7 @@ let package = Package( .package(url: "https://github.com/mattmassicotte/tree-sitter-go-work", branch: "feature/spm"), .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/alex-pinkus/tree-sitter-swift", branch: "with-generated-files"), ], targets: [ @@ -34,6 +35,7 @@ let package = Package( .product(name: "TreeSitterGoWork", package: "tree-sitter-go-work"), .product(name: "TreeSitterMarkdown", package: "tree-sitter-markdown"), .product(name: "TreeSitterOCaml", package: "tree-sitter-ocaml"), + .product(name: "TreeSitterPython", package: "tree-sitter-python"), .product(name: "TreeSitterSwift", package: "tree-sitter-swift"), ] ), diff --git a/Dependencies/Sources/TreeSitterParsers/TreeSitterParsers.swift b/Dependencies/Sources/TreeSitterParsers/TreeSitterParsers.swift index 6c4ea92..40842ca 100644 --- a/Dependencies/Sources/TreeSitterParsers/TreeSitterParsers.swift +++ b/Dependencies/Sources/TreeSitterParsers/TreeSitterParsers.swift @@ -7,4 +7,5 @@ @_exported import TreeSitterMarkdown @_exported import TreeSitterMarkdownInline @_exported import TreeSitterOCaml +@_exported import TreeSitterPython @_exported import TreeSitterSwift diff --git a/Edit.xcodeproj/project.pbxproj b/Edit.xcodeproj/project.pbxproj index 01a582a..362a092 100644 --- a/Edit.xcodeproj/project.pbxproj +++ b/Edit.xcodeproj/project.pbxproj @@ -10,6 +10,8 @@ C900A7C82A9E94AE000556A6 /* libPreferencesWindow.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C900A7BA2A9E93FC000556A6 /* libPreferencesWindow.a */; }; C900A7CA2A9E94B4000556A6 /* ExtendableHost in Frameworks */ = {isa = PBXBuildFile; productRef = C900A7C92A9E94B4000556A6 /* ExtendableHost */; }; C900A7D12A9F472E000556A6 /* Chime.appextensionpoint in Copy Extensions */ = {isa = PBXBuildFile; fileRef = C900A7CF2A9F46EF000556A6 /* Chime.appextensionpoint */; }; + C92631AD2C40002F00C0AE07 /* PythonExtension.appex in Copy Extensions */ = {isa = PBXBuildFile; fileRef = C92631A52C40002F00C0AE07 /* PythonExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + C92631B22C40005800C0AE07 /* PythonStandaloneExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C92631B12C40005200C0AE07 /* PythonStandaloneExtension.swift */; }; C92672F82B0399D800B3CE2F /* SwiftExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C92672F72B0399D800B3CE2F /* SwiftExtension.swift */; }; C92672FA2B039AA300B3CE2F /* SwiftExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C92672F72B0399D800B3CE2F /* SwiftExtension.swift */; }; C92673452B05500500B3CE2F /* RegionLabellingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C92673442B05500500B3CE2F /* RegionLabellingView.swift */; }; @@ -150,6 +152,9 @@ C99491C52B153051002DC2AC /* TextMetrics.swift in Sources */ = {isa = PBXBuildFile; fileRef = C99491C42B153051002DC2AC /* TextMetrics.swift */; }; C995EA6A2C3EC7A900D3ED4C /* ChimeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9FE52F42A7539B100CACA1A /* ChimeKit.framework */; }; C995EA752C3ED52900D3ED4C /* ClojureStandaloneExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C995EA742C3ED52900D3ED4C /* ClojureStandaloneExtension.swift */; }; + C99A8DF92C40011100D8F599 /* PythonExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C99A8DF82C40011100D8F599 /* PythonExtension.swift */; }; + C99A8DFA2C40011100D8F599 /* PythonExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C99A8DF82C40011100D8F599 /* PythonExtension.swift */; }; + C99A8DFD2C40017200D8F599 /* ChimeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9FE52F42A7539B100CACA1A /* ChimeKit.framework */; }; C99D75F42B5DB42E0028E3B0 /* TextMetrics+ChimeKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = C99D75F32B5DB42E0028E3B0 /* TextMetrics+ChimeKit.swift */; }; C9B8A9812B1B836C00C79606 /* TextMetricsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9B8A9802B1B836C00C79606 /* TextMetricsTests.swift */; }; C9B8A9D62B30613300C79606 /* DocumentCursorsMonitorModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9B8A9D52B30613300C79606 /* DocumentCursorsMonitorModifier.swift */; }; @@ -259,6 +264,13 @@ remoteGlobalIDString = C900A7B92A9E93FC000556A6; remoteInfo = PreferencesWindow; }; + C92631AB2C40002F00C0AE07 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C9FE52912A7525D000CACA1A /* Project object */; + proxyType = 1; + remoteGlobalIDString = C92631A42C40002F00C0AE07; + remoteInfo = Python; + }; C92673482B055DD700B3CE2F /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = C9FE52912A7525D000CACA1A /* Project object */; @@ -623,6 +635,13 @@ remoteGlobalIDString = C9FE52F32A7539B100CACA1A; remoteInfo = ChimeKit; }; + C99A8DFB2C40016E00D8F599 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C9FE52912A7525D000CACA1A /* Project object */; + proxyType = 1; + remoteGlobalIDString = C9FE52F32A7539B100CACA1A; + remoteInfo = ChimeKit; + }; C99D76162B5FE1530028E3B0 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = C9FE52912A7525D000CACA1A /* Project object */; @@ -918,6 +937,7 @@ C9BDB5502B00FD89009225FB /* SwiftExtension.appex in Copy Extensions */, C9818AB22C3EF5ED0032899D /* ElixirExtension.appex in Copy Extensions */, C9439A812C3EC4220020DDF5 /* ClojureExtension.appex in Copy Extensions */, + C92631AD2C40002F00C0AE07 /* PythonExtension.appex in Copy Extensions */, C942E67E2B67B78F00792DD4 /* UserScriptExtension.appex in Copy Extensions */, C900A7D12A9F472E000556A6 /* Chime.appextensionpoint in Copy Extensions */, ); @@ -952,6 +972,8 @@ /* Begin PBXFileReference section */ C900A7BA2A9E93FC000556A6 /* libPreferencesWindow.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPreferencesWindow.a; sourceTree = BUILT_PRODUCTS_DIR; }; C900A7CF2A9F46EF000556A6 /* Chime.appextensionpoint */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Chime.appextensionpoint; sourceTree = ""; }; + C92631A52C40002F00C0AE07 /* PythonExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.extensionkit-extension"; includeInIndex = 0; path = PythonExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; + C92631B12C40005200C0AE07 /* PythonStandaloneExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PythonStandaloneExtension.swift; sourceTree = ""; }; C92672F72B0399D800B3CE2F /* SwiftExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftExtension.swift; path = "submodules/chime-swift/Sources/ChimeSwift/SwiftExtension.swift"; sourceTree = SOURCE_ROOT; }; C92673282B04046700B3CE2F /* Edit-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Edit-Debug.xcconfig"; sourceTree = ""; }; C92673432B05244600B3CE2F /* EditUITests.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = EditUITests.xcconfig; sourceTree = ""; }; @@ -1067,6 +1089,7 @@ C99491C12B0D1660002DC2AC /* TextStorageDispatcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextStorageDispatcher.swift; sourceTree = ""; }; C99491C42B153051002DC2AC /* TextMetrics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextMetrics.swift; sourceTree = ""; }; C995EA742C3ED52900D3ED4C /* ClojureStandaloneExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClojureStandaloneExtension.swift; sourceTree = ""; }; + C99A8DF82C40011100D8F599 /* PythonExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PythonExtension.swift; path = "submodules/chime-python/Sources/ChimePython/PythonExtension.swift"; sourceTree = SOURCE_ROOT; }; C99D75F32B5DB42E0028E3B0 /* TextMetrics+ChimeKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TextMetrics+ChimeKit.swift"; sourceTree = ""; }; C99D76112B5EFA050028E3B0 /* TextViewSystemNeonInterface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextViewSystemNeonInterface.swift; sourceTree = ""; }; C9B8A9802B1B836C00C79606 /* TextMetricsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextMetricsTests.swift; sourceTree = ""; }; @@ -1189,6 +1212,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + C92631A22C40002F00C0AE07 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + C99A8DFD2C40017200D8F599 /* ChimeKit.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; C929313F2B80CC6700C64DDE /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -1477,6 +1508,15 @@ path = PreferencesWindow; sourceTree = ""; }; + C92631A62C40002F00C0AE07 /* Python */ = { + isa = PBXGroup; + children = ( + C99A8DF82C40011100D8F599 /* PythonExtension.swift */, + C92631B12C40005200C0AE07 /* PythonStandaloneExtension.swift */, + ); + path = Python; + sourceTree = ""; + }; C93F72492BF26BDC0021ACF3 /* EditIntents */ = { isa = PBXGroup; children = ( @@ -1746,6 +1786,7 @@ C9E878062A9F53530018340C /* Extension.entitlements */, C9818AC32C3F2C2F0032899D /* Go */, C9BDB54C2B00FD89009225FB /* Info.plist */, + C92631A62C40002F00C0AE07 /* Python */, C9BDB5492B00FD89009225FB /* Swift */, C9E878022A9F53530018340C /* UIPlaceholder */, C942E6772B67B78F00792DD4 /* UserScriptExtension */, @@ -1824,6 +1865,7 @@ C9439A792C3EC4220020DDF5 /* ClojureExtension.appex */, C9818AAA2C3EF5ED0032899D /* ElixirExtension.appex */, C9818AC22C3F2C2F0032899D /* GoExtension.appex */, + C92631A52C40002F00C0AE07 /* PythonExtension.appex */, ); name = Products; sourceTree = ""; @@ -2259,6 +2301,24 @@ productReference = C900A7BA2A9E93FC000556A6 /* libPreferencesWindow.a */; productType = "com.apple.product-type.library.static"; }; + C92631A42C40002F00C0AE07 /* Python */ = { + isa = PBXNativeTarget; + buildConfigurationList = C92631B02C40002F00C0AE07 /* Build configuration list for PBXNativeTarget "Python" */; + buildPhases = ( + C92631A12C40002F00C0AE07 /* Sources */, + C92631A22C40002F00C0AE07 /* Frameworks */, + C92631A32C40002F00C0AE07 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + C99A8DFC2C40016E00D8F599 /* PBXTargetDependency */, + ); + name = Python; + productName = Python; + productReference = C92631A52C40002F00C0AE07 /* PythonExtension.appex */; + productType = "com.apple.product-type.extensionkit-extension"; + }; C92931412B80CC6700C64DDE /* EditKit */ = { isa = PBXNativeTarget; buildConfigurationList = C929314A2B80CC6700C64DDE /* Build configuration list for PBXNativeTarget "EditKit" */; @@ -2660,6 +2720,7 @@ C9439A802C3EC4220020DDF5 /* PBXTargetDependency */, C9818AB12C3EF5ED0032899D /* PBXTargetDependency */, C9818AC92C3F2C2F0032899D /* PBXTargetDependency */, + C92631AC2C40002F00C0AE07 /* PBXTargetDependency */, ); name = Edit; packageProductDependencies = ( @@ -2976,6 +3037,9 @@ CreatedOnToolsVersion = 15.0; LastSwiftMigration = 1500; }; + C92631A42C40002F00C0AE07 = { + CreatedOnToolsVersion = 15.4; + }; C92931412B80CC6700C64DDE = { CreatedOnToolsVersion = 15.3; }; @@ -3150,11 +3214,19 @@ C9439A782C3EC4220020DDF5 /* Clojure */, C9818AA92C3EF5ED0032899D /* Elixir */, C9818AC12C3F2C2F0032899D /* Go */, + C92631A42C40002F00C0AE07 /* Python */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + C92631A32C40002F00C0AE07 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; C92931402B80CC6700C64DDE /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -3286,6 +3358,15 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + C92631A12C40002F00C0AE07 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C92631B22C40005800C0AE07 /* PythonStandaloneExtension.swift in Sources */, + C99A8DFA2C40011100D8F599 /* PythonExtension.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; C929313E2B80CC6700C64DDE /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -3651,6 +3732,7 @@ C941F0AD2B6E65110003B640 /* Process+Pipes.swift in Sources */, C97919042A9E74620046EAF1 /* AppExtensionIdentity+UI.swift in Sources */, C9818AD22C3F2CA70032899D /* GoExtension.swift in Sources */, + C99A8DF92C40011100D8F599 /* PythonExtension.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3678,6 +3760,11 @@ target = C900A7B92A9E93FC000556A6 /* PreferencesWindow */; targetProxy = C900A7CD2A9E9600000556A6 /* PBXContainerItemProxy */; }; + C92631AC2C40002F00C0AE07 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = C92631A42C40002F00C0AE07 /* Python */; + targetProxy = C92631AB2C40002F00C0AE07 /* PBXContainerItemProxy */; + }; C92673492B055DD700B3CE2F /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = C9FE53222A75A17700CACA1A /* UIUtility */; @@ -4021,6 +4108,11 @@ target = C9FE52F32A7539B100CACA1A /* ChimeKit */; targetProxy = C999C7852ABDA97500D49939 /* PBXContainerItemProxy */; }; + C99A8DFC2C40016E00D8F599 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = C9FE52F32A7539B100CACA1A /* ChimeKit */; + targetProxy = C99A8DFB2C40016E00D8F599 /* PBXContainerItemProxy */; + }; C99D76172B5FE1530028E3B0 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = C9FE53DC2A7A5A2A00CACA1A /* ExtensionHost */; @@ -4328,6 +4420,20 @@ }; name = Release; }; + C92631AE2C40002F00C0AE07 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = C9E878112A9F53BB0018340C /* Extension.xcconfig */; + buildSettings = { + }; + name = Debug; + }; + C92631AF2C40002F00C0AE07 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = C9E878112A9F53BB0018340C /* Extension.xcconfig */; + buildSettings = { + }; + name = Release; + }; C929314B2B80CC6700C64DDE /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = C92931722B822BFF00C64DDE /* EditKit.xcconfig */; @@ -4788,6 +4894,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + C92631B02C40002F00C0AE07 /* Build configuration list for PBXNativeTarget "Python" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C92631AE2C40002F00C0AE07 /* Debug */, + C92631AF2C40002F00C0AE07 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; C929314A2B80CC6700C64DDE /* Build configuration list for PBXNativeTarget "EditKit" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index decbc66..8c7296c 100644 --- a/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "64557960cc5ec5b4a9453f704db74eda7fe05f7d4409970dff0b26d5861a97ae", + "originHash" : "a40fd49a16700338aabad67421f82fb686bfcd06da9dc2ea24be06be89094a14", "pins" : [ { "identity" : "asyncxpcconnection", @@ -312,6 +312,15 @@ "revision" : "0b12614ded3ec7ed7ab7933a9ba4f695ba4c342e" } }, + { + "identity" : "tree-sitter-python", + "kind" : "remoteSourceControl", + "location" : "https://github.com/tree-sitter/tree-sitter-python", + "state" : { + "branch" : "master", + "revision" : "ccc2408e558029ad82b0dea63ff55ada495965da" + } + }, { "identity" : "tree-sitter-swift", "kind" : "remoteSourceControl", diff --git a/Edit/Modules/SyntaxService/LanguageProfile+Profiles.swift b/Edit/Modules/SyntaxService/LanguageProfile+Profiles.swift index 03156eb..9da363e 100644 --- a/Edit/Modules/SyntaxService/LanguageProfile+Profiles.swift +++ b/Edit/Modules/SyntaxService/LanguageProfile+Profiles.swift @@ -16,6 +16,14 @@ extension LanguageProfile { return LanguageProfile.elixirProfile } + if utType.conforms(to: .goSource) { + return LanguageProfile.goProfile + } + + if utType.conforms(to: .goSumFile) { + return LanguageProfile.goSumProfile + } + if utType.conforms(to: .markdown) { return LanguageProfile.markdownProfile } @@ -32,16 +40,12 @@ extension LanguageProfile { return LanguageProfile.ocamlInterfaceProfile } - if utType.conforms(to: .swiftSource) { - return LanguageProfile.swiftProfile + if utType.conforms(to: .pythonScript) { + return LanguageProfile.pythonProfile } - if utType.conforms(to: .goSource) { - return LanguageProfile.goProfile - } - - if utType.conforms(to: .goSumFile) { - return LanguageProfile.goSumProfile + if utType.conforms(to: .swiftSource) { + return LanguageProfile.swiftProfile } return LanguageProfile.genericProfile @@ -99,7 +103,11 @@ extension LanguageProfile { name: "OCaml Interface", language: Language(tree_sitter_ocaml_interface()), bundleName: "TreeSitterOCaml_TreeSitterOCaml" + ) + static let pythonProfile = LanguageProfile( + RootLanguage.python, + language: Language(tree_sitter_python()) ) static let swiftProfile = LanguageProfile( diff --git a/Edit/Modules/SyntaxService/RootLanguage.swift b/Edit/Modules/SyntaxService/RootLanguage.swift index 638e0e4..b4e178c 100644 --- a/Edit/Modules/SyntaxService/RootLanguage.swift +++ b/Edit/Modules/SyntaxService/RootLanguage.swift @@ -16,6 +16,7 @@ public enum RootLanguage: Hashable, CaseIterable, Sendable { case markdown case ocaml case ocamlInterface + case python case swift var typeIdentifier: UTType { @@ -29,6 +30,7 @@ public enum RootLanguage: Hashable, CaseIterable, Sendable { case .markdown: .markdown case .ocaml: .ocamlSource case .ocamlInterface: .ocamlInterface + case .python: .pythonScript case .swift: .swiftSource } } @@ -59,6 +61,8 @@ extension RootLanguage: RawRepresentable { self = .ocaml case "ocaml-interface": self = .ocamlInterface + case "python": + self = .python case "swift": self = .swift default: @@ -86,6 +90,8 @@ extension RootLanguage: RawRepresentable { "OCaml" case .ocamlInterface: "OCaml Interface" + case .python: + "Python" case .swift: "Swift" } diff --git a/Edit/Resources/LanguageData/Python/queries/highlights.scm b/Edit/Resources/LanguageData/Python/queries/highlights.scm new file mode 100644 index 0000000..4b821e4 --- /dev/null +++ b/Edit/Resources/LanguageData/Python/queries/highlights.scm @@ -0,0 +1,133 @@ +; Identifier naming conventions + +(identifier) @variable + +((identifier) @constructor + (#match? @constructor "^[A-Z]")) + +((identifier) @constant + (#match? @constant "^[A-Z][A-Z_]*$")) + +; Function calls + +(decorator) @function + +(call + function: (attribute attribute: (identifier) @function.method)) +(call + function: (identifier) @function) + +; Builtin functions + +((call + function: (identifier) @function.builtin) + (#match? + @function.builtin + "^(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dict|dir|divmod|enumerate|eval|exec|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|isinstance|issubclass|iter|len|list|locals|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|vars|zip|__import__)$")) + +; Function definitions + +(function_definition + name: (identifier) @function) + +(attribute attribute: (identifier) @property) +(type (identifier) @type) + +; Literals + +[ + (none) + (true) + (false) +] @constant.builtin + +[ + (integer) + (float) +] @number + +(comment) @comment +(string) @string +(escape_sequence) @escape + +(interpolation + "{" @punctuation.special + "}" @punctuation.special) @embedded + +[ + "-" + "-=" + "!=" + "*" + "**" + "**=" + "*=" + "/" + "//" + "//=" + "/=" + "&" + "&=" + "%" + "%=" + "^" + "^=" + "+" + "->" + "+=" + "<" + "<<" + "<<=" + "<=" + "<>" + "=" + ":=" + "==" + ">" + ">=" + ">>" + ">>=" + "|" + "|=" + "~" + "@=" + "and" + "in" + "is" + "not" + "or" +] @operator + +[ + "as" + "assert" + "async" + "await" + "break" + "class" + "continue" + "def" + "del" + "elif" + "else" + "except" + "exec" + "finally" + "for" + "from" + "global" + "if" + "import" + "lambda" + "nonlocal" + "pass" + "print" + "raise" + "return" + "try" + "while" + "with" + "yield" + "match" + "case" +] @keyword diff --git a/Edit/Resources/LanguageData/Python/queries/tags.scm b/Edit/Resources/LanguageData/Python/queries/tags.scm new file mode 100644 index 0000000..4fe3655 --- /dev/null +++ b/Edit/Resources/LanguageData/Python/queries/tags.scm @@ -0,0 +1,14 @@ +(module (expression_statement (assignment left: (identifier) @name) @definition.constant)) + +(class_definition + name: (identifier) @name) @definition.class + +(function_definition + name: (identifier) @name) @definition.function + +(call + function: [ + (identifier) @name + (attribute + attribute: (identifier) @name) + ]) @reference.call diff --git a/EditIntents/HighlightIntent.swift b/EditIntents/HighlightIntent.swift index db407b1..29c2c65 100644 --- a/EditIntents/HighlightIntent.swift +++ b/EditIntents/HighlightIntent.swift @@ -19,6 +19,7 @@ extension RootLanguage: AppEnum { .markdown: "Markdown", .ocaml: "OCaml", .ocamlInterface: "OCaml Interface", + .python: "Python", .swift: "Swift", ] } diff --git a/Extensions/Python/PythonStandaloneExtension.swift b/Extensions/Python/PythonStandaloneExtension.swift new file mode 100644 index 0000000..3baa561 --- /dev/null +++ b/Extensions/Python/PythonStandaloneExtension.swift @@ -0,0 +1,36 @@ +import Foundation +import ExtensionFoundation + +import ChimeKit +import Extendable + +@main +final class PythonStandaloneExtension: ChimeExtension { + @InitializerTransferred private var localExtension: StandaloneExtension + + nonisolated init() { + self._localExtension = InitializerTransferred(mainActorProvider: { + StandaloneExtension(extensionProvider: { host in + PythonExtension(host: host) + }) + }) + } + + func acceptHostConnection(_ host: HostProtocol) throws { + try localExtension.acceptHostConnection(host) + } +} + +extension PythonStandaloneExtension { + 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 38bad78..9519d90 100644 --- a/Preview/Info.plist +++ b/Preview/Info.plist @@ -13,6 +13,7 @@ public.swift-source dev.go.go-source org.golang.go-script + public.python-script QLSupportsSearchableItems diff --git a/submodules/chime-python b/submodules/chime-python new file mode 160000 index 0000000..422b33f --- /dev/null +++ b/submodules/chime-python @@ -0,0 +1 @@ +Subproject commit 422b33f09404c6ba3126dc0a1049d1c9eead981e