Skip to content

Commit

Permalink
OCaml language support #16
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed May 15, 2024
1 parent ce2f6a8 commit 913c69e
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Configurations/NonSwiftWorkaround.xcconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This is a workaround for a ridiculous problem related to non-Swift SPM dependencies. However, the linker will be unhappy if these modulemap files don't exist. So dependency management can get a little tricky.
// - "Internal" is for TextStory
// - "tree-sitter" is for SwiftTreeSitter
OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/Internal.modulemap -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/tree-sitter.modulemap -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterSwift.modulemap -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterMarkdown.modulemap -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterMarkdownInline.modulemap -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterGo.modulemap
OTHER_SWIFT_FLAGS = $(inherited) -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/Internal.modulemap -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/tree-sitter.modulemap -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterGo.modulemap -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterMarkdown.modulemap -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterMarkdownInline.modulemap -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterOCaml.modulemap -Xcc -fmodule-map-file=$(GENERATED_MODULEMAP_DIR)/TreeSitterSwift.modulemap


37 changes: 37 additions & 0 deletions Edit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
C9BFA1B72BC162EF00E86487 /* NSUI in Frameworks */ = {isa = PBXBuildFile; productRef = C9BFA1B62BC162EF00E86487 /* NSUI */; };
C9CDEB552B504485009E252A /* TextSystem+SwiftTreeSitterLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CDEB542B504485009E252A /* TextSystem+SwiftTreeSitterLayer.swift */; };
C9CDEB8F2B56ACA3009E252A /* MainOffender in Frameworks */ = {isa = PBXBuildFile; productRef = C9CDEB8E2B56ACA3009E252A /* MainOffender */; };
C9CFCF752BF4CBE80053C9A6 /* TreeSitterOCaml in Frameworks */ = {isa = PBXBuildFile; productRef = C9CFCF742BF4CBE80053C9A6 /* TreeSitterOCaml */; };
C9DCE1502BD7BFF30067D354 /* ThemeStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DCE14F2BD7BFF30067D354 /* ThemeStore.swift */; };
C9DCE1562BD8049F0067D354 /* ObservableState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DCE1552BD8049F0067D354 /* ObservableState.swift */; };
C9E0B9F72BD1A3CE007AF034 /* DiagnosticsStatusBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9E0B9F62BD1A3CE007AF034 /* DiagnosticsStatusBarItem.swift */; };
Expand Down Expand Up @@ -1129,6 +1130,7 @@
C96B61F32BDA70DA00561DE8 /* libEditor.a in Frameworks */,
C95B91302BD98C76006FDD00 /* libDocumentContent.a in Frameworks */,
C95B91232BD98B64006FDD00 /* libTextSystem.a in Frameworks */,
C9CFCF752BF4CBE80053C9A6 /* TreeSitterOCaml in Frameworks */,
C95B91222BD98B4D006FDD00 /* libSyntaxService.a in Frameworks */,
C96B61FD2BDA714700561DE8 /* ScrollViewPlus in Frameworks */,
C95B91342BD98CA1006FDD00 /* SwiftTreeSitter in Frameworks */,
Expand Down Expand Up @@ -2143,6 +2145,7 @@
buildRules = (
);
dependencies = (
C9CFCF772BF4CC1E0053C9A6 /* PBXTargetDependency */,
C96B62022BDA71FE00561DE8 /* PBXTargetDependency */,
C96B61FB2BDA714000561DE8 /* PBXTargetDependency */,
C96B61F92BDA711B00561DE8 /* PBXTargetDependency */,
Expand Down Expand Up @@ -2177,6 +2180,7 @@
C95B913D2BD98D01006FDD00 /* SwiftTreeSitterLayer */,
C96B61FC2BDA714700561DE8 /* ScrollViewPlus */,
C96B62052BDA721100561DE8 /* SourceView */,
C9CFCF742BF4CBE80053C9A6 /* TreeSitterOCaml */,
);
productName = EditKit;
productReference = C92931422B80CC6700C64DDE /* EditKit.framework */;
Expand Down Expand Up @@ -2364,6 +2368,7 @@
buildRules = (
);
dependencies = (
C9CFCF792BF4CC960053C9A6 /* PBXTargetDependency */,
C941F0B32B7102E80003B640 /* PBXTargetDependency */,
C9CDEB912B56ACBB009E252A /* PBXTargetDependency */,
C9CDEB632B51942E009E252A /* PBXTargetDependency */,
Expand Down Expand Up @@ -2930,6 +2935,7 @@
C9BFA1AE2BC0927A00E86487 /* XCRemoteSwiftPackageReference "Glyph" */,
C9E0BA3A2BD2EB05007AF034 /* XCRemoteSwiftPackageReference "ThemePark" */,
C93F72252BF0F9290021ACF3 /* XCRemoteSwiftPackageReference "Sparkle" */,
C9CFCF732BF4CBE80053C9A6 /* XCRemoteSwiftPackageReference "tree-sitter-ocaml" */,
);
productRefGroup = C9FE529A2A7525D000CACA1A /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -3871,6 +3877,14 @@
isa = PBXTargetDependency;
productRef = C9CDEB902B56ACBB009E252A /* MainOffender */;
};
C9CFCF772BF4CC1E0053C9A6 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
productRef = C9CFCF762BF4CC1E0053C9A6 /* TreeSitterOCaml */;
};
C9CFCF792BF4CC960053C9A6 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
productRef = C9CFCF782BF4CC960053C9A6 /* TreeSitterOCaml */;
};
C9DCE14E2BD7BC500067D354 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
productRef = C9DCE14D2BD7BC500067D354 /* ThemePark */;
Expand Down Expand Up @@ -4929,6 +4943,14 @@
minimumVersion = 0.1.0;
};
};
C9CFCF732BF4CBE80053C9A6 /* XCRemoteSwiftPackageReference "tree-sitter-ocaml" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/tree-sitter/tree-sitter-ocaml";
requirement = {
branch = master;
kind = branch;
};
};
C9E0BA3A2BD2EB05007AF034 /* XCRemoteSwiftPackageReference "ThemePark" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/ChimeHQ/ThemePark";
Expand Down Expand Up @@ -5261,6 +5283,21 @@
package = C9CDEB8D2B56ACA3009E252A /* XCRemoteSwiftPackageReference "MainOffender" */;
productName = MainOffender;
};
C9CFCF742BF4CBE80053C9A6 /* TreeSitterOCaml */ = {
isa = XCSwiftPackageProductDependency;
package = C9CFCF732BF4CBE80053C9A6 /* XCRemoteSwiftPackageReference "tree-sitter-ocaml" */;
productName = TreeSitterOCaml;
};
C9CFCF762BF4CC1E0053C9A6 /* TreeSitterOCaml */ = {
isa = XCSwiftPackageProductDependency;
package = C9CFCF732BF4CBE80053C9A6 /* XCRemoteSwiftPackageReference "tree-sitter-ocaml" */;
productName = TreeSitterOCaml;
};
C9CFCF782BF4CC960053C9A6 /* TreeSitterOCaml */ = {
isa = XCSwiftPackageProductDependency;
package = C9CFCF732BF4CBE80053C9A6 /* XCRemoteSwiftPackageReference "tree-sitter-ocaml" */;
productName = TreeSitterOCaml;
};
C9DCE14D2BD7BC500067D354 /* ThemePark */ = {
isa = XCSwiftPackageProductDependency;
package = C9E0BA3A2BD2EB05007AF034 /* XCRemoteSwiftPackageReference "ThemePark" */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "78a8897458ae353ab1f4fd14e2c55be0dba3fe7c46fb08bf337134a46b1e4ea1",
"originHash" : "5a57c719e79b0a39e32c853b3d8e18f925cbf132ebb27828399c403312eb262e",
"pins" : [
{
"identity" : "asyncxpcconnection",
Expand Down Expand Up @@ -258,6 +258,15 @@
"revision" : "f9820b2db958228f9be339b67d2de874d065866e"
}
},
{
"identity" : "tree-sitter-ocaml",
"kind" : "remoteSourceControl",
"location" : "https://github.com/tree-sitter/tree-sitter-ocaml",
"state" : {
"branch" : "master",
"revision" : "0b12614ded3ec7ed7ab7933a9ba4f695ba4c342e"
}
},
{
"identity" : "tree-sitter-swift",
"kind" : "remoteSourceControl",
Expand Down
15 changes: 15 additions & 0 deletions Edit/Modules/SyntaxService/LanguageProfile+Profiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SwiftTreeSitter
import UniformTypeIdentifiers

import TreeSitterGo
import TreeSitterOCaml
import TreeSitterMarkdown
import TreeSitterMarkdownInline
import TreeSitterSwift
Expand All @@ -18,6 +19,10 @@ extension LanguageProfile {
return LanguageProfile.markdownInlineProfile
}

if utType.conforms(to: .ocamlSource) {
return LanguageProfile.ocamlProfile
}

if utType.conforms(to: .swiftSource) {
return LanguageProfile.swiftProfile
}
Expand Down Expand Up @@ -47,6 +52,16 @@ extension LanguageProfile {
bundleName: "TreeSitterMarkdown_TreeSitterMarkdownInline"
)

static let ocamlProfile = LanguageProfile(
name: "OCaml",
language: Language(tree_sitter_ocaml())
)

static let ocamlInterfaceProfile = LanguageProfile(
name: "OCaml",
language: Language(tree_sitter_ocaml_interface())
)

static let swiftProfile = LanguageProfile(
name: "Swift",
language: Language(tree_sitter_swift())
Expand Down
17 changes: 17 additions & 0 deletions Edit/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@
<string>https://updates.chimehq.com/com.chimehq.Edit/appcast.xml</string>
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.source-code</string>
</array>
<key>UTTypeDescription</key>
<string>OCaml Source</string>
<key>UTTypeIdentifier</key>
<string>org.ocaml.ocaml</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>ml</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeConformsTo</key>
<array>
Expand Down
9 changes: 6 additions & 3 deletions EditIntents/HighlightIntent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ import UniformTypeIdentifiers
///
/// This must be defined within the same module as any AppIntent that uses it.
public enum RootLanguage: String, Hashable, CaseIterable, Sendable {
case swift = "Swift"
case go = "Go"
case markdown = "Markdown"
case ocaml = "OCaml"
case swift = "Swift"

var typeIdentifier: UTType {
switch self {
case .swift: .swiftSource
case .go: .goSource
case .markdown: .markdown
case .ocaml: .ocamlSource
case .swift: .swiftSource
}
}
}
Expand All @@ -27,9 +29,10 @@ extension RootLanguage: AppEnum {
public static var typeDisplayRepresentation: TypeDisplayRepresentation { "Language" }
public static var caseDisplayRepresentations: [RootLanguage: DisplayRepresentation] {
[
.swift: "Swift",
.go: "Go",
.markdown: "Markdown",
.ocaml: "OCaml",
.swift: "Swift",
]
}
}
Expand Down

0 comments on commit 913c69e

Please sign in to comment.