diff --git a/Package.resolved b/Package.resolved index c8552035..d4b41d51 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "c15e8aa8884e5c43573b4c6821e6a2d2a6f33b031aae46b8d3f500da1ae16ba1", + "originHash" : "86ca3573181d97fb51f834cb8c76d8139ea4570c71591717fff34d96048696a1", "pins" : [ { "identity" : "aexml", @@ -10,15 +10,6 @@ "version" : "4.6.1" } }, - { - "identity" : "asyncextensions", - "kind" : "remoteSourceControl", - "location" : "https://github.com/lhoward/AsyncExtensions", - "state" : { - "branch" : "linux", - "revision" : "2218eaa30dbdb39b063e92644fc28ed22e2cb942" - } - }, { "identity" : "graphviz", "kind" : "remoteSourceControl", @@ -37,14 +28,6 @@ "version" : "4.2.0" } }, - { - "identity" : "lvglswift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/PADL/LVGLSwift", - "state" : { - "revision" : "19c19a942153b50d61486faf1d0d45daf79e7be5" - } - }, { "identity" : "mainoffender", "kind" : "remoteSourceControl", @@ -81,15 +64,6 @@ "version" : "1.26.2" } }, - { - "identity" : "opencombine", - "kind" : "remoteSourceControl", - "location" : "https://github.com/OpenCombine/OpenCombine.git", - "state" : { - "revision" : "8576f0d579b27020beccbccc3ea6844f3ddfc2c2", - "version" : "0.14.0" - } - }, { "identity" : "pathkit", "kind" : "remoteSourceControl", @@ -108,14 +82,6 @@ "version" : "0.4.2" } }, - { - "identity" : "qlift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Longhanks/qlift", - "state" : { - "revision" : "ddab1f1ecc113ad4f8e05d2999c2734cdf706210" - } - }, { "identity" : "rainbow", "kind" : "remoteSourceControl", @@ -197,24 +163,6 @@ "version" : "1.1.0" } }, - { - "identity" : "swift-cross-ui", - "kind" : "remoteSourceControl", - "location" : "https://github.com/stackotter/swift-cross-ui", - "state" : { - "branch" : "f57f7ab", - "revision" : "f57f7abc22c7aee3ba642ef714742776e2b767ed" - } - }, - { - "identity" : "swift-cwinrt", - "kind" : "remoteSourceControl", - "location" : "https://github.com/thebrowsercompany/swift-cwinrt", - "state" : { - "branch" : "main", - "revision" : "ad451d31fc7c1c60041c146d177cdaf5aaf1cf47" - } - }, { "identity" : "swift-format", "kind" : "remoteSourceControl", @@ -269,42 +217,6 @@ "version" : "509.1.1" } }, - { - "identity" : "swift-uwp", - "kind" : "remoteSourceControl", - "location" : "https://github.com/thebrowsercompany/swift-uwp", - "state" : { - "branch" : "main", - "revision" : "cfad0a43469211bf7eb58ed23af3d4a176faec07" - } - }, - { - "identity" : "swift-windowsappsdk", - "kind" : "remoteSourceControl", - "location" : "https://github.com/thebrowsercompany/swift-windowsappsdk", - "state" : { - "branch" : "main", - "revision" : "8d094d4478d0eabcf584fef133b8ce45287ecd72" - } - }, - { - "identity" : "swift-windowsfoundation", - "kind" : "remoteSourceControl", - "location" : "https://github.com/thebrowsercompany/swift-windowsfoundation", - "state" : { - "branch" : "main", - "revision" : "ba7a8b5000ed3f9f077000d1a31f2a0b19907657" - } - }, - { - "identity" : "swift-winui", - "kind" : "remoteSourceControl", - "location" : "https://github.com/thebrowsercompany/swift-winui", - "state" : { - "branch" : "main", - "revision" : "4c246a1352accfa5e12f7103bd2725b271730cce" - } - }, { "identity" : "swiftcli", "kind" : "remoteSourceControl", @@ -314,15 +226,6 @@ "version" : "6.0.3" } }, - { - "identity" : "swiftterm", - "kind" : "remoteSourceControl", - "location" : "https://github.com/migueldeicaza/SwiftTerm.git", - "state" : { - "revision" : "e2b431dbf73f775fb4807a33e4572ffd3dc6933a", - "version" : "1.2.5" - } - }, { "identity" : "swifttreesitter", "kind" : "remoteSourceControl", @@ -350,23 +253,6 @@ "version" : "8.10.1" } }, - { - "identity" : "termkit", - "kind" : "remoteSourceControl", - "location" : "https://github.com/migueldeicaza/TermKit", - "state" : { - "revision" : "3bce85d1bafbbb0336b3b7b7e905c35754cb9adf" - } - }, - { - "identity" : "textbufferkit", - "kind" : "remoteSourceControl", - "location" : "https://github.com/migueldeicaza/TextBufferKit.git", - "state" : { - "revision" : "7f3ed5b1d7288de34ad853544d802647be11cfcf", - "version" : "0.3.0" - } - }, { "identity" : "textformation", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index 434d8d55..c41f1396 100644 --- a/Package.swift +++ b/Package.swift @@ -1,11 +1,11 @@ // swift-tools-version: 5.10 import PackageDescription -#if os(macOS) - let crazyToolChainBug: [String: String]? = nil -#else /* os(macOS) */ - let crazyToolChainBug: [String: String]? = ["SwiftCrossUI": "SwiftUI"] -#endif /* !os(macOS) */ +// #if os(macOS) +// let crazyToolChainBug: [String: String]? = nil +// #else /* os(macOS) */ +// let crazyToolChainBug: [String: String]? = ["SwiftCrossUI": "SwiftUI"] +// #endif /* !os(macOS) */ let package = Package( name: "Kraken", @@ -21,11 +21,11 @@ let package = Package( // --- 🎨 Editors --- .library( name: "CosmoEditor", - targets: ["CosmoTextView", "CosmoEditor"] + targets: ["CodeView", "CosmoEditor"] ), .library( - name: "CosmoLanguages", - targets: ["CosmoLanguagesContainer", "CosmoLanguages"] + name: "CodeLanguages", + targets: ["LanguagesBundle", "CodeLanguages"] ), // --- 🦑 Kraken --- .library( @@ -36,10 +36,6 @@ let package = Package( name: "KrakenLib", targets: ["KrakenLib"] ), - .library( - name: "KrakenUI", - targets: ["KrakenUI"] - ), .executable( name: "Kraken", targets: ["Kraken"] @@ -54,15 +50,15 @@ let package = Package( .package(url: "https://github.com/ChimeHQ/TextStory.git", from: "0.8.0"), .package(url: "https://github.com/apple/swift-collections", from: "1.1.0"), .package(url: "https://github.com/furby-tm/swift-bundler", from: "2.0.9"), - .package(url: "https://github.com/stackotter/swift-cross-ui", revision: "f57f7ab") + //.package(url: "https://github.com/stackotter/swift-cross-ui", revision: "f57f7ab") ], // --- 🎯 Package Targets. --- targets: [ // --- 🎨 Editors --- .target( - name: "CosmoLanguagesContainer", - path: "Sources/Editors/Code/CosmoLanguagesContainer", + name: "LanguagesBundle", + path: "Sources/Editors/Code/LanguagesBundle", publicHeadersPath: "include", cSettings: [ .headerSearchPath("TreeSitterC/include"), @@ -76,39 +72,39 @@ let package = Package( ] ), .target( - name: "CosmoLanguages", + name: "CodeLanguages", dependencies: [ - .target(name: "CosmoLanguagesContainer"), + .target(name: "LanguagesBundle"), .product(name: "SwiftTreeSitter", package: "SwiftTreeSitter"), ], - path: "Sources/Editors/Code/CosmoLanguages", + path: "Sources/Editors/Code/Languages", resources: [ .copy("Resources"), ] ), .testTarget( - name: "CosmoLanguagesTests", + name: "CodeEditorTests", dependencies: [ - .target(name: "CosmoLanguages") + .target(name: "CodeLanguages") ], - path: "Tests/Editors/Code/CosmoLanguagesTests" + path: "Tests/Editors/Code" ), .target( - name: "CosmoTextView", + name: "CodeView", dependencies: [ .product(name: "TextStory", package: "TextStory"), .product(name: "Collections", package: "swift-collections"), ], - path: "Sources/Editors/Code/CosmoTextView" + path: "Sources/Editors/Code/CodeView" ), .target( name: "CosmoEditor", dependencies: [ - .target(name: "CosmoLanguages"), - .target(name: "CosmoTextView"), + .target(name: "CodeLanguages"), + .target(name: "CodeView"), .product(name: "TextFormation", package: "TextFormation"), ], - path: "Sources/Editors/Code/CosmoEditor" + path: "Sources/Editors/Code/Cosmo" ), // --- 🦑 Kraken --- .target( @@ -129,34 +125,13 @@ let package = Package( .interoperabilityMode(.Cxx) ] ), - .target( - name: "KrakenUI", - dependencies: [ - .target(name: "KrakenKit"), - .target(name: "CosmoEditor"), - .product( - name: "SwiftCrossUI", - package: "swift-cross-ui", - moduleAliases: crazyToolChainBug, - condition: .when(platforms: [.linux, .windows]) - ), - .product( - name: "GtkBackend", - package: "swift-cross-ui", - condition: .when(platforms: [.linux, .windows]) - ), - ], - swiftSettings: [ - .interoperabilityMode(.Cxx) - ] - ), .executableTarget( name: "Kraken", dependencies: [ .product(name: "PixarUSD", package: "SwiftUSD"), .target(name: "KrakenKit"), .target(name: "KrakenLib"), - .target(name: "KrakenUI"), + .target(name: "CosmoEditor"), ], resources: [ .process("Resources") diff --git a/Sources/Editors/Code/CodeView/CodeView.docc/CodeView.md b/Sources/Editors/Code/CodeView/CodeView.docc/CodeView.md new file mode 100644 index 00000000..178f9d60 --- /dev/null +++ b/Sources/Editors/Code/CodeView/CodeView.docc/CodeView.md @@ -0,0 +1,37 @@ +# ``CodeView`` + +A text editor designed to edit code documents. + +## Overview + +A text editor specialized for displaying and editing code documents. Features include basic text editing, extremely fast initial layout, support for handling large documents, customization options for code documents. + +> This package contains a text view suitable for replacing `NSTextView` in some, **_specific_** cases. + +The `TextView` class is an `NSView` subclass that can be embedded in a scroll view or used standalone. It parses and renders lines of a document and handles mouse and keyboard events for text editing. It also renders styled strings for use cases like syntax highlighting. + +## Topics + +### Text View + +- `TextView` +- `CEUndoManager` + +### Text Layout + +- `TextLayoutManager` +- `TextLine` +- `LineFragment` + +### Text Selection + +- `TextSelectionManager` +- `TextSelectionManager/TextSelection` +- `CursorView` + +### Supporting Types + +- `TextLineStorage` +- `HorizontalEdgeInsets` +- `LineEnding` +- `LineBreakStrategy` diff --git a/Sources/Editors/Code/CosmoTextView/Cursors/CursorTimer.swift b/Sources/Editors/Code/CodeView/Cursors/CursorTimer.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/Cursors/CursorTimer.swift rename to Sources/Editors/Code/CodeView/Cursors/CursorTimer.swift diff --git a/Sources/Editors/Code/CosmoTextView/Cursors/CursorView.swift b/Sources/Editors/Code/CodeView/Cursors/CursorView.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/Cursors/CursorView.swift rename to Sources/Editors/Code/CodeView/Cursors/CursorView.swift diff --git a/Sources/Editors/Code/CosmoTextView/Extensions/GC+ApproximateEqual.swift b/Sources/Editors/Code/CodeView/Extensions/GC+ApproximateEqual.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/Extensions/GC+ApproximateEqual.swift rename to Sources/Editors/Code/CodeView/Extensions/GC+ApproximateEqual.swift diff --git a/Sources/Editors/Code/CosmoTextView/Extensions/NSColor+Greyscale.swift b/Sources/Editors/Code/CodeView/Extensions/NSColor+Greyscale.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/Extensions/NSColor+Greyscale.swift rename to Sources/Editors/Code/CodeView/Extensions/NSColor+Greyscale.swift diff --git a/Sources/Editors/Code/CosmoTextView/Extensions/NSRange+isEmpty.swift b/Sources/Editors/Code/CodeView/Extensions/NSRange+isEmpty.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/Extensions/NSRange+isEmpty.swift rename to Sources/Editors/Code/CodeView/Extensions/NSRange+isEmpty.swift diff --git a/Sources/Editors/Code/CosmoTextView/Extensions/NSTextStorage+getLine.swift b/Sources/Editors/Code/CodeView/Extensions/NSTextStorage+getLine.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/Extensions/NSTextStorage+getLine.swift rename to Sources/Editors/Code/CodeView/Extensions/NSTextStorage+getLine.swift diff --git a/Sources/Editors/Code/CosmoTextView/Extensions/PixelAligned.swift b/Sources/Editors/Code/CodeView/Extensions/PixelAligned.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/Extensions/PixelAligned.swift rename to Sources/Editors/Code/CodeView/Extensions/PixelAligned.swift diff --git a/Sources/Editors/Code/CosmoTextView/MarkedTextManager/MarkedTextManager.swift b/Sources/Editors/Code/CodeView/MarkedTextManager/MarkedTextManager.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/MarkedTextManager/MarkedTextManager.swift rename to Sources/Editors/Code/CodeView/MarkedTextManager/MarkedTextManager.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextLayoutManager/TextLayoutManager+Edits.swift b/Sources/Editors/Code/CodeView/TextLayoutManager/TextLayoutManager+Edits.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextLayoutManager/TextLayoutManager+Edits.swift rename to Sources/Editors/Code/CodeView/TextLayoutManager/TextLayoutManager+Edits.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextLayoutManager/TextLayoutManager+Invalidation.swift b/Sources/Editors/Code/CodeView/TextLayoutManager/TextLayoutManager+Invalidation.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextLayoutManager/TextLayoutManager+Invalidation.swift rename to Sources/Editors/Code/CodeView/TextLayoutManager/TextLayoutManager+Invalidation.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextLayoutManager/TextLayoutManager+Iterator.swift b/Sources/Editors/Code/CodeView/TextLayoutManager/TextLayoutManager+Iterator.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextLayoutManager/TextLayoutManager+Iterator.swift rename to Sources/Editors/Code/CodeView/TextLayoutManager/TextLayoutManager+Iterator.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextLayoutManager/TextLayoutManager+Public.swift b/Sources/Editors/Code/CodeView/TextLayoutManager/TextLayoutManager+Public.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextLayoutManager/TextLayoutManager+Public.swift rename to Sources/Editors/Code/CodeView/TextLayoutManager/TextLayoutManager+Public.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextLayoutManager/TextLayoutManager+Transaction.swift b/Sources/Editors/Code/CodeView/TextLayoutManager/TextLayoutManager+Transaction.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextLayoutManager/TextLayoutManager+Transaction.swift rename to Sources/Editors/Code/CodeView/TextLayoutManager/TextLayoutManager+Transaction.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextLayoutManager/TextLayoutManager.swift b/Sources/Editors/Code/CodeView/TextLayoutManager/TextLayoutManager.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextLayoutManager/TextLayoutManager.swift rename to Sources/Editors/Code/CodeView/TextLayoutManager/TextLayoutManager.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextLine/LineBreakStrategy.swift b/Sources/Editors/Code/CodeView/TextLine/LineBreakStrategy.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextLine/LineBreakStrategy.swift rename to Sources/Editors/Code/CodeView/TextLine/LineBreakStrategy.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextLine/LineFragment.swift b/Sources/Editors/Code/CodeView/TextLine/LineFragment.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextLine/LineFragment.swift rename to Sources/Editors/Code/CodeView/TextLine/LineFragment.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextLine/LineFragmentView.swift b/Sources/Editors/Code/CodeView/TextLine/LineFragmentView.swift similarity index 99% rename from Sources/Editors/Code/CosmoTextView/TextLine/LineFragmentView.swift rename to Sources/Editors/Code/CodeView/TextLine/LineFragmentView.swift index d1573a2a..bf8e9165 100644 --- a/Sources/Editors/Code/CosmoTextView/TextLine/LineFragmentView.swift +++ b/Sources/Editors/Code/CodeView/TextLine/LineFragmentView.swift @@ -25,7 +25,8 @@ * -------------------------------------------------------------- */ import AppKit -// import CosmoTextViewObjC + +// import CodeViewObjC /// Displays a line fragment. final class LineFragmentView: NSView diff --git a/Sources/Editors/Code/CosmoTextView/TextLine/TextLine.swift b/Sources/Editors/Code/CodeView/TextLine/TextLine.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextLine/TextLine.swift rename to Sources/Editors/Code/CodeView/TextLine/TextLine.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextLine/Typesetter.swift b/Sources/Editors/Code/CodeView/TextLine/Typesetter.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextLine/Typesetter.swift rename to Sources/Editors/Code/CodeView/TextLine/Typesetter.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextLineStorage/TextLineStorage+Iterator.swift b/Sources/Editors/Code/CodeView/TextLineStorage/TextLineStorage+Iterator.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextLineStorage/TextLineStorage+Iterator.swift rename to Sources/Editors/Code/CodeView/TextLineStorage/TextLineStorage+Iterator.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextLineStorage/TextLineStorage+NSTextStorage.swift b/Sources/Editors/Code/CodeView/TextLineStorage/TextLineStorage+NSTextStorage.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextLineStorage/TextLineStorage+NSTextStorage.swift rename to Sources/Editors/Code/CodeView/TextLineStorage/TextLineStorage+NSTextStorage.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextLineStorage/TextLineStorage+Node.swift b/Sources/Editors/Code/CodeView/TextLineStorage/TextLineStorage+Node.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextLineStorage/TextLineStorage+Node.swift rename to Sources/Editors/Code/CodeView/TextLineStorage/TextLineStorage+Node.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextLineStorage/TextLineStorage+Structs.swift b/Sources/Editors/Code/CodeView/TextLineStorage/TextLineStorage+Structs.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextLineStorage/TextLineStorage+Structs.swift rename to Sources/Editors/Code/CodeView/TextLineStorage/TextLineStorage+Structs.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextLineStorage/TextLineStorage.swift b/Sources/Editors/Code/CodeView/TextLineStorage/TextLineStorage.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextLineStorage/TextLineStorage.swift rename to Sources/Editors/Code/CodeView/TextLineStorage/TextLineStorage.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextSelectionManager/TextSelectionManager+FillRects.swift b/Sources/Editors/Code/CodeView/TextSelectionManager/TextSelectionManager+FillRects.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextSelectionManager/TextSelectionManager+FillRects.swift rename to Sources/Editors/Code/CodeView/TextSelectionManager/TextSelectionManager+FillRects.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextSelectionManager/TextSelectionManager+Move.swift b/Sources/Editors/Code/CodeView/TextSelectionManager/TextSelectionManager+Move.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextSelectionManager/TextSelectionManager+Move.swift rename to Sources/Editors/Code/CodeView/TextSelectionManager/TextSelectionManager+Move.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextSelectionManager/TextSelectionManager+SelectionManipulation.swift b/Sources/Editors/Code/CodeView/TextSelectionManager/TextSelectionManager+SelectionManipulation.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextSelectionManager/TextSelectionManager+SelectionManipulation.swift rename to Sources/Editors/Code/CodeView/TextSelectionManager/TextSelectionManager+SelectionManipulation.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextSelectionManager/TextSelectionManager+Update.swift b/Sources/Editors/Code/CodeView/TextSelectionManager/TextSelectionManager+Update.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextSelectionManager/TextSelectionManager+Update.swift rename to Sources/Editors/Code/CodeView/TextSelectionManager/TextSelectionManager+Update.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextSelectionManager/TextSelectionManager.swift b/Sources/Editors/Code/CodeView/TextSelectionManager/TextSelectionManager.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextSelectionManager/TextSelectionManager.swift rename to Sources/Editors/Code/CodeView/TextSelectionManager/TextSelectionManager.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextView+Accessibility.swift b/Sources/Editors/Code/CodeView/TextView/TextView+Accessibility.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextView+Accessibility.swift rename to Sources/Editors/Code/CodeView/TextView/TextView+Accessibility.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextView+CopyPaste.swift b/Sources/Editors/Code/CodeView/TextView/TextView+CopyPaste.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextView+CopyPaste.swift rename to Sources/Editors/Code/CodeView/TextView/TextView+CopyPaste.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextView+Delete.swift b/Sources/Editors/Code/CodeView/TextView/TextView+Delete.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextView+Delete.swift rename to Sources/Editors/Code/CodeView/TextView/TextView+Delete.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextView+Drag.swift b/Sources/Editors/Code/CodeView/TextView/TextView+Drag.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextView+Drag.swift rename to Sources/Editors/Code/CodeView/TextView/TextView+Drag.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextView+Insert.swift b/Sources/Editors/Code/CodeView/TextView/TextView+Insert.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextView+Insert.swift rename to Sources/Editors/Code/CodeView/TextView/TextView+Insert.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextView+Menu.swift b/Sources/Editors/Code/CodeView/TextView/TextView+Menu.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextView+Menu.swift rename to Sources/Editors/Code/CodeView/TextView/TextView+Menu.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextView+Mouse.swift b/Sources/Editors/Code/CodeView/TextView/TextView+Mouse.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextView+Mouse.swift rename to Sources/Editors/Code/CodeView/TextView/TextView+Mouse.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextView+Move.swift b/Sources/Editors/Code/CodeView/TextView/TextView+Move.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextView+Move.swift rename to Sources/Editors/Code/CodeView/TextView/TextView+Move.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextView+NSTextInput.swift b/Sources/Editors/Code/CodeView/TextView/TextView+NSTextInput.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextView+NSTextInput.swift rename to Sources/Editors/Code/CodeView/TextView/TextView+NSTextInput.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextView+ReplaceCharacters.swift b/Sources/Editors/Code/CodeView/TextView/TextView+ReplaceCharacters.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextView+ReplaceCharacters.swift rename to Sources/Editors/Code/CodeView/TextView/TextView+ReplaceCharacters.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextView+Select.swift b/Sources/Editors/Code/CodeView/TextView/TextView+Select.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextView+Select.swift rename to Sources/Editors/Code/CodeView/TextView/TextView+Select.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextView+Setup.swift b/Sources/Editors/Code/CodeView/TextView/TextView+Setup.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextView+Setup.swift rename to Sources/Editors/Code/CodeView/TextView/TextView+Setup.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextView+StorageDelegate.swift b/Sources/Editors/Code/CodeView/TextView/TextView+StorageDelegate.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextView+StorageDelegate.swift rename to Sources/Editors/Code/CodeView/TextView/TextView+StorageDelegate.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextView+TextLayoutManagerDelegate.swift b/Sources/Editors/Code/CodeView/TextView/TextView+TextLayoutManagerDelegate.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextView+TextLayoutManagerDelegate.swift rename to Sources/Editors/Code/CodeView/TextView/TextView+TextLayoutManagerDelegate.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextView+UndoRedo.swift b/Sources/Editors/Code/CodeView/TextView/TextView+UndoRedo.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextView+UndoRedo.swift rename to Sources/Editors/Code/CodeView/TextView/TextView+UndoRedo.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextView.swift b/Sources/Editors/Code/CodeView/TextView/TextView.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextView.swift rename to Sources/Editors/Code/CodeView/TextView/TextView.swift diff --git a/Sources/Editors/Code/CosmoTextView/TextView/TextViewDelegate.swift b/Sources/Editors/Code/CodeView/TextView/TextViewDelegate.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/TextView/TextViewDelegate.swift rename to Sources/Editors/Code/CodeView/TextView/TextViewDelegate.swift diff --git a/Sources/Editors/Code/CosmoTextView/Utils/CEUndoManager.swift b/Sources/Editors/Code/CodeView/Utils/CEUndoManager.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/Utils/CEUndoManager.swift rename to Sources/Editors/Code/CodeView/Utils/CEUndoManager.swift diff --git a/Sources/Editors/Code/CosmoTextView/Utils/HorizontalEdgeInsets.swift b/Sources/Editors/Code/CodeView/Utils/HorizontalEdgeInsets.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/Utils/HorizontalEdgeInsets.swift rename to Sources/Editors/Code/CodeView/Utils/HorizontalEdgeInsets.swift diff --git a/Sources/Editors/Code/CosmoTextView/Utils/LineEnding.swift b/Sources/Editors/Code/CodeView/Utils/LineEnding.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/Utils/LineEnding.swift rename to Sources/Editors/Code/CodeView/Utils/LineEnding.swift diff --git a/Sources/Editors/Code/CosmoTextView/Utils/Logger.swift b/Sources/Editors/Code/CodeView/Utils/Logger.swift similarity index 94% rename from Sources/Editors/Code/CosmoTextView/Utils/Logger.swift rename to Sources/Editors/Code/CodeView/Utils/Logger.swift index 57f67a8f..46d24858 100644 --- a/Sources/Editors/Code/CosmoTextView/Utils/Logger.swift +++ b/Sources/Editors/Code/CodeView/Utils/Logger.swift @@ -26,4 +26,4 @@ import os -let logger = Logger(subsystem: "com.CodeEdit.CosmoTextView", category: "TextView") +let logger = Logger(subsystem: "foundation.wabi.textview", category: "TextView") diff --git a/Sources/Editors/Code/CosmoTextView/Utils/MultiStorageDelegate.swift b/Sources/Editors/Code/CodeView/Utils/MultiStorageDelegate.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/Utils/MultiStorageDelegate.swift rename to Sources/Editors/Code/CodeView/Utils/MultiStorageDelegate.swift diff --git a/Sources/Editors/Code/CosmoTextView/Utils/ViewReuseQueue.swift b/Sources/Editors/Code/CodeView/Utils/ViewReuseQueue.swift similarity index 100% rename from Sources/Editors/Code/CosmoTextView/Utils/ViewReuseQueue.swift rename to Sources/Editors/Code/CodeView/Utils/ViewReuseQueue.swift diff --git a/Sources/Editors/Code/CosmoEditor/Controller/CursorPosition.swift b/Sources/Editors/Code/Cosmo/Controller/CursorPosition.swift similarity index 93% rename from Sources/Editors/Code/CosmoEditor/Controller/CursorPosition.swift rename to Sources/Editors/Code/Cosmo/Controller/CursorPosition.swift index be1b650a..e850d68f 100644 --- a/Sources/Editors/Code/CosmoEditor/Controller/CursorPosition.swift +++ b/Sources/Editors/Code/Cosmo/Controller/CursorPosition.swift @@ -40,7 +40,7 @@ public struct CursorPosition: Sendable, Codable, Equatable /// Initialize a cursor position. /// /// When this initializer is used, ``CursorPosition/range`` will be initialized to `NSNotFound`. - /// The range value, however, be filled when updated by ``CosmoEditor`` via a `Binding`, or when it appears + /// The range value, however, be filled when updated by ``Editor/Code/Cosmo`` via a `Binding`, or when it appears /// in the``TextViewController/cursorPositions`` array. /// /// - Parameters: @@ -56,7 +56,7 @@ public struct CursorPosition: Sendable, Codable, Equatable /// Initialize a cursor position. /// /// When this initializer is used, both ``CursorPosition/line`` and ``CursorPosition/column`` will be initialized - /// to `-1`. They will, however, be filled when updated by ``CosmoEditor`` via a `Binding`, or when it + /// to `-1`. They will, however, be filled when updated by ``Editor/Code/Cosmo`` via a `Binding`, or when it /// appears in the ``TextViewController/cursorPositions`` array. /// /// - Parameter range: The range of the cursor position. diff --git a/Sources/Editors/Code/CosmoEditor/Controller/TextViewController+Cursor.swift b/Sources/Editors/Code/Cosmo/Controller/TextViewController+Cursor.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Controller/TextViewController+Cursor.swift rename to Sources/Editors/Code/Cosmo/Controller/TextViewController+Cursor.swift diff --git a/Sources/Editors/Code/CosmoEditor/Controller/TextViewController+HighlightBracket.swift b/Sources/Editors/Code/Cosmo/Controller/TextViewController+HighlightBracket.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Controller/TextViewController+HighlightBracket.swift rename to Sources/Editors/Code/Cosmo/Controller/TextViewController+HighlightBracket.swift diff --git a/Sources/Editors/Code/CosmoEditor/Controller/TextViewController+Highlighter.swift b/Sources/Editors/Code/Cosmo/Controller/TextViewController+Highlighter.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Controller/TextViewController+Highlighter.swift rename to Sources/Editors/Code/Cosmo/Controller/TextViewController+Highlighter.swift diff --git a/Sources/Editors/Code/CosmoEditor/Controller/TextViewController+LoadView.swift b/Sources/Editors/Code/Cosmo/Controller/TextViewController+LoadView.swift similarity index 99% rename from Sources/Editors/Code/CosmoEditor/Controller/TextViewController+LoadView.swift rename to Sources/Editors/Code/Cosmo/Controller/TextViewController+LoadView.swift index 04120d08..0c03f3ca 100644 --- a/Sources/Editors/Code/CosmoEditor/Controller/TextViewController+LoadView.swift +++ b/Sources/Editors/Code/Cosmo/Controller/TextViewController+LoadView.swift @@ -25,7 +25,7 @@ * -------------------------------------------------------------- */ import AppKit -import CosmoTextView +import CodeView public extension TextViewController { diff --git a/Sources/Editors/Code/CosmoEditor/Controller/TextViewController+TextFormation.swift b/Sources/Editors/Code/Cosmo/Controller/TextViewController+TextFormation.swift similarity index 99% rename from Sources/Editors/Code/CosmoEditor/Controller/TextViewController+TextFormation.swift rename to Sources/Editors/Code/Cosmo/Controller/TextViewController+TextFormation.swift index 36fd95cf..f4f2cde2 100644 --- a/Sources/Editors/Code/CosmoEditor/Controller/TextViewController+TextFormation.swift +++ b/Sources/Editors/Code/Cosmo/Controller/TextViewController+TextFormation.swift @@ -25,7 +25,7 @@ * -------------------------------------------------------------- */ import AppKit -import CosmoTextView +import CodeView import TextFormation import TextStory diff --git a/Sources/Editors/Code/CosmoEditor/Controller/TextViewController+TextViewDelegate.swift b/Sources/Editors/Code/Cosmo/Controller/TextViewController+TextViewDelegate.swift similarity index 98% rename from Sources/Editors/Code/CosmoEditor/Controller/TextViewController+TextViewDelegate.swift rename to Sources/Editors/Code/Cosmo/Controller/TextViewController+TextViewDelegate.swift index 6041475b..ac3aa38c 100644 --- a/Sources/Editors/Code/CosmoEditor/Controller/TextViewController+TextViewDelegate.swift +++ b/Sources/Editors/Code/Cosmo/Controller/TextViewController+TextViewDelegate.swift @@ -24,7 +24,7 @@ * . x x x . o o o . x x x . : : : . o x o . : : : . * -------------------------------------------------------------- */ -import CosmoTextView +import CodeView import Foundation import TextStory diff --git a/Sources/Editors/Code/CosmoEditor/Controller/TextViewController.swift b/Sources/Editors/Code/Cosmo/Controller/TextViewController.swift similarity index 97% rename from Sources/Editors/Code/CosmoEditor/Controller/TextViewController.swift rename to Sources/Editors/Code/Cosmo/Controller/TextViewController.swift index 872baeef..1d47005e 100644 --- a/Sources/Editors/Code/CosmoEditor/Controller/TextViewController.swift +++ b/Sources/Editors/Code/Cosmo/Controller/TextViewController.swift @@ -25,15 +25,15 @@ * -------------------------------------------------------------- */ import AppKit +import CodeLanguages +import CodeView import Combine -import CosmoLanguages -import CosmoTextView import SwiftUI import TextFormation /// # TextViewController /// -/// A view controller class for managing a source editor. Uses ``CosmoTextView/TextView`` for input and rendering, +/// A view controller class for managing a source editor. Uses ``CodeView/TextView`` for input and rendering, /// tree-sitter for syntax highlighting, and TextFormation for live editing completions. /// public class TextViewController: NSViewController @@ -57,8 +57,8 @@ public class TextViewController: NSViewController textView.string } - /// The associated `CodeLanguage` - public var language: CodeLanguage + /// The associated ``Editor/Code/Language`` + public var language: Editor.Code.Language { didSet { @@ -77,7 +77,7 @@ public class TextViewController: NSViewController } /// The associated `Theme` used for highlighting. - public var theme: EditorTheme + public var theme: Editor.Code.Theme { didSet { @@ -230,9 +230,9 @@ public class TextViewController: NSViewController init( string: String, - language: CodeLanguage, + language: Editor.Code.Language, font: NSFont, - theme: EditorTheme, + theme: Editor.Code.Theme, tabWidth: Int, indentOption: IndentOption, lineHeight: CGFloat, diff --git a/Sources/Editors/Code/CosmoEditor/CosmoEditor.docc/CosmoEditor.md b/Sources/Editors/Code/Cosmo/CosmoEditor.docc/CosmoEditor.md similarity index 79% rename from Sources/Editors/Code/CosmoEditor/CosmoEditor.docc/CosmoEditor.md rename to Sources/Editors/Code/Cosmo/CosmoEditor.docc/CosmoEditor.md index eed59c63..c20997f2 100644 --- a/Sources/Editors/Code/CosmoEditor/CosmoEditor.docc/CosmoEditor.md +++ b/Sources/Editors/Code/Cosmo/CosmoEditor.docc/CosmoEditor.md @@ -8,11 +8,11 @@ An code editor view written in Swift powered by tree-sitter. Features include sy ## Topics -### Text View +### Code Editor -- ``CosmoEditor/CosmoEditor`` -- ``CosmoEditor/TextViewController`` +- ``Editor/Code/Cosmo`` +- ``Editor/Code/Cosmo/TextViewController`` ### Theme -- ``EditorTheme`` +- ``Code/Editor/Theme`` diff --git a/Sources/Editors/Code/CosmoEditor/CosmoEditor.docc/CosmoTextView.md b/Sources/Editors/Code/Cosmo/CosmoEditor.docc/CosmoTextView.md similarity index 89% rename from Sources/Editors/Code/CosmoEditor/CosmoEditor.docc/CosmoTextView.md rename to Sources/Editors/Code/Cosmo/CosmoEditor.docc/CosmoTextView.md index 5dc60e14..66a26ea9 100644 --- a/Sources/Editors/Code/CosmoEditor/CosmoEditor.docc/CosmoTextView.md +++ b/Sources/Editors/Code/Cosmo/CosmoEditor.docc/CosmoTextView.md @@ -1,4 +1,4 @@ -# ``CosmoEditor/CosmoEditor`` +# ``CosmoEditor/Editor/Code/Cosmo`` ## Usage @@ -12,7 +12,7 @@ public struct CodeEditor: View public var body: some View { - CosmoEditor( + Editor.Code.Cosmo( $text, language: .default, theme: .standard, diff --git a/Sources/Editors/Code/Cosmo/CosmoEditor.swift b/Sources/Editors/Code/Cosmo/CosmoEditor.swift new file mode 100644 index 00000000..203a35ee --- /dev/null +++ b/Sources/Editors/Code/Cosmo/CosmoEditor.swift @@ -0,0 +1,333 @@ +/* -------------------------------------------------------------- + * :: : K R A K E N : :: + * -------------------------------------------------------------- + * @wabistudios :: metaverse :: kraken + * + * This program is free software; you can redistribute it, and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out + * the GNU General Public License for more details. + * + * You should have received a copy for this software license, the + * GNU General Public License along with this program; or, if not + * write to the Free Software Foundation, Inc., to the address of + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright (C) 2023 Wabi Foundation. + * All Rights Reserved. + * -------------------------------------------------------------- + * . x x x . o o o . x x x . : : : . o x o . : : : . + * -------------------------------------------------------------- */ + +import CodeLanguages +import CodeView +import SwiftUI + +public extension Editor.Code +{ + struct Cosmo: NSViewControllerRepresentable + { + /// Initializes a Text Editor + /// - Parameters: + /// - text: The text content + /// - language: The language for syntax highlighting + /// - theme: The theme for syntax highlighting + /// - font: The default font + /// - tabWidth: The visual tab width in number of spaces + /// - indentOption: The behavior to use when the tab key is pressed. Defaults to 4 spaces. + /// - lineHeight: The line height multiplier (e.g. `1.2`) + /// - wrapLines: Whether lines wrap to the width of the editor + /// - editorOverscroll: The distance to overscroll the editor by. + /// - cursorPosition: The cursor's position in the editor, measured in `(lineNum, columnNum)` + /// - useThemeBackground: Determines whether the editor uses the theme's background color, or a transparent + /// background color + /// - highlightProvider: A class you provide to perform syntax highlighting. Leave this as `nil` to use the + /// built-in `TreeSitterClient` highlighter. + /// - contentInsets: Insets to use to offset the content in the enclosing scroll view. Leave as `nil` to let the + /// scroll view automatically adjust content insets. + /// - isEditable: A Boolean value that controls whether the text view allows the user to edit text. + /// - isSelectable: A Boolean value that controls whether the text view allows the user to select text. If this + /// value is true, and `isEditable` is false, the editor is selectable but not editable. + /// - letterSpacing: The amount of space to use between letters, as a percent. Eg: `1.0` = no space, `1.5` = 1/2 a + /// character's width between characters, etc. Defaults to `1.0` + /// - bracketPairHighlight: The type of highlight to use to highlight bracket pairs. + /// See `BracketPairHighlight` for more information. Defaults to `nil` + /// - undoManager: The undo manager for the text view. Defaults to `nil`, which will create a new CEUndoManager + public init( + _ text: Binding, + language: Editor.Code.Language, + theme: Editor.Code.Theme, + font: NSFont, + tabWidth: Int, + indentOption: IndentOption = .spaces(count: 4), + lineHeight: Double, + wrapLines: Bool, + editorOverscroll: CGFloat = 0, + cursorPositions: Binding<[CursorPosition]>, + useThemeBackground: Bool = true, + highlightProvider: HighlightProviding? = nil, + contentInsets: NSEdgeInsets? = nil, + isEditable: Bool = true, + isSelectable: Bool = true, + letterSpacing: Double = 1.0, + bracketPairHighlight: BracketPairHighlight? = nil, + undoManager: CEUndoManager? = nil, + coordinators: [any TextViewCoordinator] = [] + ) + { + _text = text + _cursorPositions = cursorPositions + self.language = language + self.theme = theme + self.useThemeBackground = useThemeBackground + self.font = font + self.tabWidth = tabWidth + self.indentOption = indentOption + self.lineHeight = lineHeight + self.wrapLines = wrapLines + self.editorOverscroll = editorOverscroll + self.highlightProvider = highlightProvider + self.contentInsets = contentInsets + self.isEditable = isEditable + self.isSelectable = isSelectable + self.letterSpacing = letterSpacing + self.bracketPairHighlight = bracketPairHighlight + self.undoManager = undoManager + self.coordinators = coordinators + } + + @Binding private var text: String + @Binding private var cursorPositions: [CursorPosition] + private var language: Editor.Code.Language + private var theme: Editor.Code.Theme + private var font: NSFont + private var tabWidth: Int + private var indentOption: IndentOption + private var lineHeight: Double + private var wrapLines: Bool + private var editorOverscroll: CGFloat + private var useThemeBackground: Bool + private var highlightProvider: HighlightProviding? + private var contentInsets: NSEdgeInsets? + private var isEditable: Bool + private var isSelectable: Bool + private var letterSpacing: Double + private var bracketPairHighlight: BracketPairHighlight? + private var undoManager: CEUndoManager? + private var coordinators: [any TextViewCoordinator] + + public typealias NSViewControllerType = TextViewController + + public func makeNSViewController(context: Context) -> TextViewController + { + let controller = TextViewController( + string: text, + language: language, + font: font, + theme: theme, + tabWidth: tabWidth, + indentOption: indentOption, + lineHeight: lineHeight, + wrapLines: wrapLines, + cursorPositions: cursorPositions, + editorOverscroll: editorOverscroll, + useThemeBackground: useThemeBackground, + highlightProvider: highlightProvider, + contentInsets: contentInsets, + isEditable: isEditable, + isSelectable: isSelectable, + letterSpacing: letterSpacing, + bracketPairHighlight: bracketPairHighlight, + undoManager: undoManager + ) + if controller.textView == nil + { + controller.loadView() + } + if !cursorPositions.isEmpty + { + controller.setCursorPositions(cursorPositions) + } + + context.coordinator.controller = controller + coordinators.forEach + { + $0.prepareCoordinator(controller: controller) + } + return controller + } + + public func makeCoordinator() -> Coordinator + { + Coordinator(parent: self) + } + + public func updateNSViewController(_ controller: TextViewController, context: Context) + { + if !context.coordinator.isUpdateFromTextView + { + // Prevent infinite loop of update notifications + context.coordinator.isUpdatingFromRepresentable = true + controller.setCursorPositions(cursorPositions) + context.coordinator.isUpdatingFromRepresentable = false + } + else + { + context.coordinator.isUpdateFromTextView = false + } + + // Do manual diffing to reduce the amount of reloads. + // This helps a lot in view performance, as it otherwise gets triggered on each environment change. + guard !paramsAreEqual(controller: controller) + else + { + return + } + + if controller.font != font + { + controller.font = font + } + + controller.wrapLines = wrapLines + controller.useThemeBackground = useThemeBackground + controller.lineHeightMultiple = lineHeight + controller.editorOverscroll = editorOverscroll + controller.contentInsets = contentInsets + + if controller.isEditable != isEditable + { + controller.isEditable = isEditable + } + + if controller.isSelectable != isSelectable + { + controller.isSelectable = isSelectable + } + + if controller.language.id != language.id + { + controller.language = language + } + + if controller.theme != theme + { + controller.theme = theme + } + + if controller.indentOption != indentOption + { + controller.indentOption = indentOption + } + + if controller.tabWidth != tabWidth + { + controller.tabWidth = tabWidth + } + + if controller.letterSpacing != letterSpacing + { + controller.letterSpacing = letterSpacing + } + + controller.bracketPairHighlight = bracketPairHighlight + + controller.reloadUI() + } + + func paramsAreEqual(controller: NSViewControllerType) -> Bool + { + controller.font == font && + controller.isEditable == isEditable && + controller.isSelectable == isSelectable && + controller.wrapLines == wrapLines && + controller.useThemeBackground == useThemeBackground && + controller.lineHeightMultiple == lineHeight && + controller.editorOverscroll == editorOverscroll && + controller.contentInsets == contentInsets && + controller.language.id == language.id && + controller.theme == theme && + controller.indentOption == indentOption && + controller.tabWidth == tabWidth && + controller.letterSpacing == letterSpacing && + controller.bracketPairHighlight == bracketPairHighlight + } + + @MainActor + public class Coordinator: NSObject + { + var parent: Editor.Code.Cosmo + weak var controller: TextViewController? + var isUpdatingFromRepresentable: Bool = false + var isUpdateFromTextView: Bool = false + + init(parent: Editor.Code.Cosmo) + { + self.parent = parent + super.init() + + NotificationCenter.default.addObserver( + self, + selector: #selector(textViewDidChangeText(_:)), + name: TextView.textDidChangeNotification, + object: nil + ) + + NotificationCenter.default.addObserver( + self, + selector: #selector(textControllerCursorsDidUpdate(_:)), + name: TextViewController.cursorPositionUpdatedNotification, + object: nil + ) + } + + @objc func textViewDidChangeText(_ notification: Notification) + { + guard let textView = notification.object as? TextView, + let controller, + controller.textView === textView + else + { + return + } + parent.text = textView.string + parent.coordinators.forEach + { + $0.textViewDidChangeText(controller: controller) + } + } + + @objc func textControllerCursorsDidUpdate(_: Notification) + { + guard !isUpdatingFromRepresentable else { return } + isUpdateFromTextView = true + parent._cursorPositions.wrappedValue = controller?.cursorPositions ?? [] + if controller != nil + { + parent.coordinators.forEach + { + $0.textViewDidChangeSelection( + controller: self.controller!, + newPositions: self.controller!.cursorPositions + ) + } + } + } + + deinit + { + parent.coordinators.forEach + { + $0.destroy() + } + parent.coordinators.removeAll() + NotificationCenter.default.removeObserver(self) + } + } + } +} diff --git a/Sources/Editors/Code/CosmoEditor/Enums/BracketPairHighlight.swift b/Sources/Editors/Code/Cosmo/Enums/BracketPairHighlight.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Enums/BracketPairHighlight.swift rename to Sources/Editors/Code/Cosmo/Enums/BracketPairHighlight.swift diff --git a/Sources/Editors/Code/CosmoEditor/Enums/CaptureName.swift b/Sources/Editors/Code/Cosmo/Enums/CaptureName.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Enums/CaptureName.swift rename to Sources/Editors/Code/Cosmo/Enums/CaptureName.swift diff --git a/Sources/Editors/Code/CosmoEditor/Enums/IndentOption.swift b/Sources/Editors/Code/Cosmo/Enums/IndentOption.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Enums/IndentOption.swift rename to Sources/Editors/Code/Cosmo/Enums/IndentOption.swift diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/Color+Hex.swift b/Sources/Editors/Code/Cosmo/Extensions/Color+Hex.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Extensions/Color+Hex.swift rename to Sources/Editors/Code/Cosmo/Extensions/Color+Hex.swift diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/IndexSet+NSRange.swift b/Sources/Editors/Code/Cosmo/Extensions/IndexSet+NSRange.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Extensions/IndexSet+NSRange.swift rename to Sources/Editors/Code/Cosmo/Extensions/IndexSet+NSRange.swift diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/NSEdgeInsets+Equatable.swift b/Sources/Editors/Code/Cosmo/Extensions/NSEdgeInsets+Equatable.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Extensions/NSEdgeInsets+Equatable.swift rename to Sources/Editors/Code/Cosmo/Extensions/NSEdgeInsets+Equatable.swift diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/NSFont+LineHeight.swift b/Sources/Editors/Code/Cosmo/Extensions/NSFont+LineHeight.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Extensions/NSFont+LineHeight.swift rename to Sources/Editors/Code/Cosmo/Extensions/NSFont+LineHeight.swift diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/NSFont+RulerFont.swift b/Sources/Editors/Code/Cosmo/Extensions/NSFont+RulerFont.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Extensions/NSFont+RulerFont.swift rename to Sources/Editors/Code/Cosmo/Extensions/NSFont+RulerFont.swift diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/NSRange+/NSRange+Comparable.swift b/Sources/Editors/Code/Cosmo/Extensions/NSRange+/NSRange+Comparable.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Extensions/NSRange+/NSRange+Comparable.swift rename to Sources/Editors/Code/Cosmo/Extensions/NSRange+/NSRange+Comparable.swift diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/NSRange+/NSRange+InputEdit.swift b/Sources/Editors/Code/Cosmo/Extensions/NSRange+/NSRange+InputEdit.swift similarity index 99% rename from Sources/Editors/Code/CosmoEditor/Extensions/NSRange+/NSRange+InputEdit.swift rename to Sources/Editors/Code/Cosmo/Extensions/NSRange+/NSRange+InputEdit.swift index b9d1036e..b22ec222 100644 --- a/Sources/Editors/Code/CosmoEditor/Extensions/NSRange+/NSRange+InputEdit.swift +++ b/Sources/Editors/Code/Cosmo/Extensions/NSRange+/NSRange+InputEdit.swift @@ -24,7 +24,7 @@ * . x x x . o o o . x x x . : : : . o x o . : : : . * -------------------------------------------------------------- */ -import CosmoTextView +import CodeView import Foundation import SwiftTreeSitter diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/NSRange+/NSRange+NSTextRange.swift b/Sources/Editors/Code/Cosmo/Extensions/NSRange+/NSRange+NSTextRange.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Extensions/NSRange+/NSRange+NSTextRange.swift rename to Sources/Editors/Code/Cosmo/Extensions/NSRange+/NSRange+NSTextRange.swift diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/NSRange+/NSRange+String.swift b/Sources/Editors/Code/Cosmo/Extensions/NSRange+/NSRange+String.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Extensions/NSRange+/NSRange+String.swift rename to Sources/Editors/Code/Cosmo/Extensions/NSRange+/NSRange+String.swift diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/NSRange+/NSRange+TSRange.swift b/Sources/Editors/Code/Cosmo/Extensions/NSRange+/NSRange+TSRange.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Extensions/NSRange+/NSRange+TSRange.swift rename to Sources/Editors/Code/Cosmo/Extensions/NSRange+/NSRange+TSRange.swift diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/NSRange+/NSRange+isEmpty.swift b/Sources/Editors/Code/Cosmo/Extensions/NSRange+/NSRange+isEmpty.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Extensions/NSRange+/NSRange+isEmpty.swift rename to Sources/Editors/Code/Cosmo/Extensions/NSRange+/NSRange+isEmpty.swift diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/String+encoding.swift b/Sources/Editors/Code/Cosmo/Extensions/String+encoding.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Extensions/String+encoding.swift rename to Sources/Editors/Code/Cosmo/Extensions/String+encoding.swift diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/TextMutation+isEmpty.swift b/Sources/Editors/Code/Cosmo/Extensions/TextMutation+isEmpty.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Extensions/TextMutation+isEmpty.swift rename to Sources/Editors/Code/Cosmo/Extensions/TextMutation+isEmpty.swift diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/TextView+/TextView+Menu.swift b/Sources/Editors/Code/Cosmo/Extensions/TextView+/TextView+Menu.swift similarity index 99% rename from Sources/Editors/Code/CosmoEditor/Extensions/TextView+/TextView+Menu.swift rename to Sources/Editors/Code/Cosmo/Extensions/TextView+/TextView+Menu.swift index 8b25c2ea..2cd1c043 100644 --- a/Sources/Editors/Code/CosmoEditor/Extensions/TextView+/TextView+Menu.swift +++ b/Sources/Editors/Code/Cosmo/Extensions/TextView+/TextView+Menu.swift @@ -25,7 +25,7 @@ * -------------------------------------------------------------- */ import AppKit -import CosmoTextView +import CodeView extension TextView { diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/TextView+/TextView+Point.swift b/Sources/Editors/Code/Cosmo/Extensions/TextView+/TextView+Point.swift similarity index 98% rename from Sources/Editors/Code/CosmoEditor/Extensions/TextView+/TextView+Point.swift rename to Sources/Editors/Code/Cosmo/Extensions/TextView+/TextView+Point.swift index c19697b0..f9ee8695 100644 --- a/Sources/Editors/Code/CosmoEditor/Extensions/TextView+/TextView+Point.swift +++ b/Sources/Editors/Code/Cosmo/Extensions/TextView+/TextView+Point.swift @@ -24,7 +24,7 @@ * . x x x . o o o . x x x . : : : . o x o . : : : . * -------------------------------------------------------------- */ -import CosmoTextView +import CodeView import Foundation import SwiftTreeSitter diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/TextView+/TextView+TextFormation.swift b/Sources/Editors/Code/Cosmo/Extensions/TextView+/TextView+TextFormation.swift similarity index 99% rename from Sources/Editors/Code/CosmoEditor/Extensions/TextView+/TextView+TextFormation.swift rename to Sources/Editors/Code/Cosmo/Extensions/TextView+/TextView+TextFormation.swift index 81118e9c..8c772314 100644 --- a/Sources/Editors/Code/CosmoEditor/Extensions/TextView+/TextView+TextFormation.swift +++ b/Sources/Editors/Code/Cosmo/Extensions/TextView+/TextView+TextFormation.swift @@ -24,7 +24,7 @@ * . x x x . o o o . x x x . : : : . o x o . : : : . * -------------------------------------------------------------- */ -import CosmoTextView +import CodeView import Foundation import TextFormation import TextStory diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/TextView+/TextView+createReadBlock.swift b/Sources/Editors/Code/Cosmo/Extensions/TextView+/TextView+createReadBlock.swift similarity index 99% rename from Sources/Editors/Code/CosmoEditor/Extensions/TextView+/TextView+createReadBlock.swift rename to Sources/Editors/Code/Cosmo/Extensions/TextView+/TextView+createReadBlock.swift index b8b235f2..cd1d9cb6 100644 --- a/Sources/Editors/Code/CosmoEditor/Extensions/TextView+/TextView+createReadBlock.swift +++ b/Sources/Editors/Code/Cosmo/Extensions/TextView+/TextView+createReadBlock.swift @@ -24,7 +24,7 @@ * . x x x . o o o . x x x . : : : . o x o . : : : . * -------------------------------------------------------------- */ -import CosmoTextView +import CodeView import Foundation import SwiftTreeSitter diff --git a/Sources/Editors/Code/CosmoEditor/Extensions/Tree+prettyPrint.swift b/Sources/Editors/Code/Cosmo/Extensions/Tree+prettyPrint.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Extensions/Tree+prettyPrint.swift rename to Sources/Editors/Code/Cosmo/Extensions/Tree+prettyPrint.swift diff --git a/Sources/Editors/Code/CosmoEditor/Filters/DeleteWhitespaceFilter.swift b/Sources/Editors/Code/Cosmo/Filters/DeleteWhitespaceFilter.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Filters/DeleteWhitespaceFilter.swift rename to Sources/Editors/Code/Cosmo/Filters/DeleteWhitespaceFilter.swift diff --git a/Sources/Editors/Code/CosmoEditor/Filters/TabReplacementFilter.swift b/Sources/Editors/Code/Cosmo/Filters/TabReplacementFilter.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Filters/TabReplacementFilter.swift rename to Sources/Editors/Code/Cosmo/Filters/TabReplacementFilter.swift diff --git a/Sources/Editors/Code/CosmoEditor/Gutter/GutterView.swift b/Sources/Editors/Code/Cosmo/Gutter/GutterView.swift similarity index 99% rename from Sources/Editors/Code/CosmoEditor/Gutter/GutterView.swift rename to Sources/Editors/Code/Cosmo/Gutter/GutterView.swift index 76655f1e..b819954a 100644 --- a/Sources/Editors/Code/CosmoEditor/Gutter/GutterView.swift +++ b/Sources/Editors/Code/Cosmo/Gutter/GutterView.swift @@ -25,7 +25,7 @@ * -------------------------------------------------------------- */ import AppKit -import CosmoTextView +import CodeView public protocol GutterViewDelegate: AnyObject { diff --git a/Sources/Editors/Code/CosmoEditor/Highlighting/HighlightProviding.swift b/Sources/Editors/Code/Cosmo/Highlighting/HighlightProviding.swift similarity index 96% rename from Sources/Editors/Code/CosmoEditor/Highlighting/HighlightProviding.swift rename to Sources/Editors/Code/Cosmo/Highlighting/HighlightProviding.swift index 53b37c58..2af45211 100644 --- a/Sources/Editors/Code/CosmoEditor/Highlighting/HighlightProviding.swift +++ b/Sources/Editors/Code/Cosmo/Highlighting/HighlightProviding.swift @@ -25,8 +25,8 @@ * -------------------------------------------------------------- */ import AppKit -import CosmoLanguages -import CosmoTextView +import CodeLanguages +import CodeView import Foundation /// The protocol a class must conform to to be used for highlighting. @@ -36,7 +36,7 @@ public protocol HighlightProviding: AnyObject /// - Parameters: /// - textView: The text view to use as a text source. /// - codeLanguage: The language that should be used by the highlighter. - func setUp(textView: TextView, codeLanguage: CodeLanguage) + func setUp(textView: TextView, codeLanguage: Editor.Code.Language) /// Notifies the highlighter that an edit is going to happen in the given range. /// - Parameters: diff --git a/Sources/Editors/Code/CosmoEditor/Highlighting/HighlightRange.swift b/Sources/Editors/Code/Cosmo/Highlighting/HighlightRange.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Highlighting/HighlightRange.swift rename to Sources/Editors/Code/Cosmo/Highlighting/HighlightRange.swift diff --git a/Sources/Editors/Code/CosmoEditor/Highlighting/Highlighter+NSTextStorageDelegate.swift b/Sources/Editors/Code/Cosmo/Highlighting/Highlighter+NSTextStorageDelegate.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Highlighting/Highlighter+NSTextStorageDelegate.swift rename to Sources/Editors/Code/Cosmo/Highlighting/Highlighter+NSTextStorageDelegate.swift diff --git a/Sources/Editors/Code/CosmoEditor/Highlighting/Highlighter.swift b/Sources/Editors/Code/Cosmo/Highlighting/Highlighter.swift similarity index 97% rename from Sources/Editors/Code/CosmoEditor/Highlighting/Highlighter.swift rename to Sources/Editors/Code/Cosmo/Highlighting/Highlighter.swift index 2295b274..23a097fb 100644 --- a/Sources/Editors/Code/CosmoEditor/Highlighting/Highlighter.swift +++ b/Sources/Editors/Code/Cosmo/Highlighting/Highlighter.swift @@ -25,8 +25,8 @@ * -------------------------------------------------------------- */ import AppKit -import CosmoLanguages -import CosmoTextView +import CodeLanguages +import CodeView import Foundation import SwiftTreeSitter @@ -59,13 +59,13 @@ class Highlighter: NSObject private weak var textView: TextView? /// The editor theme - private var theme: EditorTheme + private var theme: Editor.Code.Theme /// The object providing attributes for captures. private weak var attributeProvider: ThemeAttributesProviding! /// The current language of the editor. - private var language: CodeLanguage + private var language: Editor.Code.Language /// Calculates invalidated ranges given an edit. private(set) weak var highlightProvider: HighlightProviding? @@ -83,9 +83,9 @@ class Highlighter: NSObject init( textView: TextView, highlightProvider: HighlightProviding?, - theme: EditorTheme, + theme: Editor.Code.Theme, attributeProvider: ThemeAttributesProviding, - language: CodeLanguage + language: Editor.Code.Language ) { self.textView = textView @@ -128,7 +128,7 @@ class Highlighter: NSObject /// Sets the language and causes a re-highlight of the entire text. /// - Parameter language: The language to update to. - public func setLanguage(language: CodeLanguage) + public func setLanguage(language: Editor.Code.Language) { guard let textView else { return } // Remove all current highlights. Makes the language setting feel snappier and tells the user we're doing diff --git a/Sources/Editors/Code/CosmoEditor/Highlighting/HighlighterTextView.swift b/Sources/Editors/Code/Cosmo/Highlighting/HighlighterTextView.swift similarity index 98% rename from Sources/Editors/Code/CosmoEditor/Highlighting/HighlighterTextView.swift rename to Sources/Editors/Code/Cosmo/Highlighting/HighlighterTextView.swift index 9a4b4d7a..66e3ec2f 100644 --- a/Sources/Editors/Code/CosmoEditor/Highlighting/HighlighterTextView.swift +++ b/Sources/Editors/Code/Cosmo/Highlighting/HighlighterTextView.swift @@ -25,7 +25,7 @@ * -------------------------------------------------------------- */ import AppKit -import CosmoTextView +import CodeView import Foundation public extension TextView diff --git a/Sources/Editors/Code/CosmoEditor/TextViewCoordinator.swift b/Sources/Editors/Code/Cosmo/TextViewCoordinator.swift similarity index 98% rename from Sources/Editors/Code/CosmoEditor/TextViewCoordinator.swift rename to Sources/Editors/Code/Cosmo/TextViewCoordinator.swift index 0b1c5f5e..42404434 100644 --- a/Sources/Editors/Code/CosmoEditor/TextViewCoordinator.swift +++ b/Sources/Editors/Code/Cosmo/TextViewCoordinator.swift @@ -28,7 +28,7 @@ import AppKit /// # TextViewCoordinator /// -/// A protocol that can be used to provide extra functionality to ``CosmoEditor/CosmoEditor`` while +/// A protocol that can be used to provide extra functionality to ``Editor/Code/Cosmo`` while /// avoiding some of the inefficiencies of SwiftUI. /// public protocol TextViewCoordinator: AnyObject diff --git a/Sources/Editors/Code/Cosmo/Theme/EditorTheme.swift b/Sources/Editors/Code/Cosmo/Theme/EditorTheme.swift new file mode 100644 index 00000000..ec31b966 --- /dev/null +++ b/Sources/Editors/Code/Cosmo/Theme/EditorTheme.swift @@ -0,0 +1,134 @@ +/* -------------------------------------------------------------- + * :: : K R A K E N : :: + * -------------------------------------------------------------- + * @wabistudios :: metaverse :: kraken + * + * This program is free software; you can redistribute it, and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out + * the GNU General Public License for more details. + * + * You should have received a copy for this software license, the + * GNU General Public License along with this program; or, if not + * write to the Free Software Foundation, Inc., to the address of + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright (C) 2023 Wabi Foundation. + * All Rights Reserved. + * -------------------------------------------------------------- + * . x x x . o o o . x x x . : : : . o x o . : : : . + * -------------------------------------------------------------- */ + +import SwiftUI +import CodeLanguages + +public extension Editor.Code +{ + /// A collection of `NSColor` used for syntax higlighting + struct Theme + { + public var text: NSColor + public var insertionPoint: NSColor + public var invisibles: NSColor + public var background: NSColor + public var lineHighlight: NSColor + public var selection: NSColor + public var keywords: NSColor + public var commands: NSColor + public var types: NSColor + public var attributes: NSColor + public var variables: NSColor + public var values: NSColor + public var numbers: NSColor + public var strings: NSColor + public var characters: NSColor + public var comments: NSColor + + public init( + text: NSColor, + insertionPoint: NSColor, + invisibles: NSColor, + background: NSColor, + lineHighlight: NSColor, + selection: NSColor, + keywords: NSColor, + commands: NSColor, + types: NSColor, + attributes: NSColor, + variables: NSColor, + values: NSColor, + numbers: NSColor, + strings: NSColor, + characters: NSColor, + comments: NSColor + ) + { + self.text = text + self.insertionPoint = insertionPoint + self.invisibles = invisibles + self.background = background + self.lineHighlight = lineHighlight + self.selection = selection + self.keywords = keywords + self.commands = commands + self.types = types + self.attributes = attributes + self.variables = variables + self.values = values + self.numbers = numbers + self.strings = strings + self.characters = characters + self.comments = comments + } + + /// Get the color from ``theme`` for the specified capture name. + /// - Parameter capture: The capture name + /// - Returns: A `NSColor` + func colorFor(_ capture: CaptureName?) -> NSColor + { + switch capture + { + case .include, .constructor, .keyword, .boolean, .variableBuiltin, + .keywordReturn, .keywordFunction, .repeat, .conditional, .tag: + keywords + case .comment: comments + case .variable, .property: variables + case .function, .method: variables + case .number, .float: numbers + case .string: strings + case .type: types + case .parameter: variables + case .typeAlternate: attributes + default: text + } + } + } +} + +extension Editor.Code.Theme: Equatable +{ + public static func == (lhs: Self, rhs: Self) -> Bool + { + lhs.text == rhs.text && + lhs.insertionPoint == rhs.insertionPoint && + lhs.invisibles == rhs.invisibles && + lhs.background == rhs.background && + lhs.lineHighlight == rhs.lineHighlight && + lhs.selection == rhs.selection && + lhs.keywords == rhs.keywords && + lhs.commands == rhs.commands && + lhs.types == rhs.types && + lhs.attributes == rhs.attributes && + lhs.variables == rhs.variables && + lhs.values == rhs.values && + lhs.numbers == rhs.numbers && + lhs.strings == rhs.strings && + lhs.characters == rhs.characters && + lhs.comments == rhs.comments + } +} diff --git a/Sources/Editors/Code/CosmoEditor/Theme/ThemeAttributesProviding.swift b/Sources/Editors/Code/Cosmo/Theme/ThemeAttributesProviding.swift similarity index 100% rename from Sources/Editors/Code/CosmoEditor/Theme/ThemeAttributesProviding.swift rename to Sources/Editors/Code/Cosmo/Theme/ThemeAttributesProviding.swift diff --git a/Sources/Editors/Code/CosmoEditor/TreeSitter/LanguageLayer.swift b/Sources/Editors/Code/Cosmo/TreeSitter/LanguageLayer.swift similarity index 99% rename from Sources/Editors/Code/CosmoEditor/TreeSitter/LanguageLayer.swift rename to Sources/Editors/Code/Cosmo/TreeSitter/LanguageLayer.swift index 0164ebf8..48295afe 100644 --- a/Sources/Editors/Code/CosmoEditor/TreeSitter/LanguageLayer.swift +++ b/Sources/Editors/Code/Cosmo/TreeSitter/LanguageLayer.swift @@ -24,7 +24,7 @@ * . x x x . o o o . x x x . : : : . o x o . : : : . * -------------------------------------------------------------- */ -import CosmoLanguages +import CodeLanguages import Foundation import SwiftTreeSitter diff --git a/Sources/Editors/Code/CosmoEditor/TreeSitter/TreeSitterClient+Edit.swift b/Sources/Editors/Code/Cosmo/TreeSitter/TreeSitterClient+Edit.swift similarity index 99% rename from Sources/Editors/Code/CosmoEditor/TreeSitter/TreeSitterClient+Edit.swift rename to Sources/Editors/Code/Cosmo/TreeSitter/TreeSitterClient+Edit.swift index 06e206ad..1cf15f20 100644 --- a/Sources/Editors/Code/CosmoEditor/TreeSitter/TreeSitterClient+Edit.swift +++ b/Sources/Editors/Code/Cosmo/TreeSitter/TreeSitterClient+Edit.swift @@ -24,7 +24,7 @@ * . x x x . o o o . x x x . : : : . o x o . : : : . * -------------------------------------------------------------- */ -import CosmoLanguages +import CodeLanguages import Foundation import SwiftTreeSitter diff --git a/Sources/Editors/Code/CosmoEditor/TreeSitter/TreeSitterClient+Highlight.swift b/Sources/Editors/Code/Cosmo/TreeSitter/TreeSitterClient+Highlight.swift similarity index 99% rename from Sources/Editors/Code/CosmoEditor/TreeSitter/TreeSitterClient+Highlight.swift rename to Sources/Editors/Code/Cosmo/TreeSitter/TreeSitterClient+Highlight.swift index a19e2336..cae2b43b 100644 --- a/Sources/Editors/Code/CosmoEditor/TreeSitter/TreeSitterClient+Highlight.swift +++ b/Sources/Editors/Code/Cosmo/TreeSitter/TreeSitterClient+Highlight.swift @@ -24,7 +24,7 @@ * . x x x . o o o . x x x . : : : . o x o . : : : . * -------------------------------------------------------------- */ -import CosmoLanguages +import CodeLanguages import Foundation import SwiftTreeSitter diff --git a/Sources/Editors/Code/CosmoEditor/TreeSitter/TreeSitterClient.swift b/Sources/Editors/Code/Cosmo/TreeSitter/TreeSitterClient.swift similarity index 98% rename from Sources/Editors/Code/CosmoEditor/TreeSitter/TreeSitterClient.swift rename to Sources/Editors/Code/Cosmo/TreeSitter/TreeSitterClient.swift index 96aeae5c..310759ab 100644 --- a/Sources/Editors/Code/CosmoEditor/TreeSitter/TreeSitterClient.swift +++ b/Sources/Editors/Code/Cosmo/TreeSitter/TreeSitterClient.swift @@ -24,8 +24,8 @@ * . x x x . o o o . x x x . : : : . o x o . : : : . * -------------------------------------------------------------- */ -import CosmoLanguages -import CosmoTextView +import CodeLanguages +import CodeView import Foundation import OSLog import SwiftTreeSitter @@ -46,7 +46,7 @@ import SwiftTreeSitter /// length, edit length, highlight length and if the object is available for a synchronous call. public final class TreeSitterClient: HighlightProviding { - static let logger: Logger = .init(subsystem: "foundation.wabi.CosmoEditor", category: "TreeSitterClient") + static let logger: Logger = .init(subsystem: "foundation.wabi.cosmo", category: "TreeSitterClient") /// The number of operations running or enqueued to run on the dispatch queue. This variable **must** only be /// changed from the main thread or race conditions are very likely. @@ -114,7 +114,7 @@ public final class TreeSitterClient: HighlightProviding /// - textView: The text view to use as a data source. /// A weak reference will be kept for the lifetime of this object. /// - codeLanguage: The language to use for parsing. - public func setUp(textView: TextView, codeLanguage: CodeLanguage) + public func setUp(textView: TextView, codeLanguage: Editor.Code.Language) { Self.logger.debug("TreeSitterClient setting up with language: \(codeLanguage.id.rawValue, privacy: .public)") @@ -134,7 +134,7 @@ public final class TreeSitterClient: HighlightProviding /// - readCallback: The callback to use to read text from the document. /// - readBlock: The callback to use to read blocks of text from the document. private func setState( - language: CodeLanguage, + language: Editor.Code.Language, readCallback: @escaping SwiftTreeSitter.Predicate.TextProvider, readBlock: @escaping Parser.ReadBlock ) diff --git a/Sources/Editors/Code/CosmoEditor/TreeSitter/TreeSitterState.swift b/Sources/Editors/Code/Cosmo/TreeSitter/TreeSitterState.swift similarity index 96% rename from Sources/Editors/Code/CosmoEditor/TreeSitter/TreeSitterState.swift rename to Sources/Editors/Code/Cosmo/TreeSitter/TreeSitterState.swift index bab90af2..2ed3fdb1 100644 --- a/Sources/Editors/Code/CosmoEditor/TreeSitter/TreeSitterState.swift +++ b/Sources/Editors/Code/Cosmo/TreeSitter/TreeSitterState.swift @@ -24,14 +24,14 @@ * . x x x . o o o . x x x . : : : . o x o . : : : . * -------------------------------------------------------------- */ -import CosmoLanguages +import CodeLanguages import Foundation import SwiftTreeSitter /// TreeSitterState contains the tree of language layers that make up the tree-sitter document. public class TreeSitterState { - private(set) var primaryLayer: CodeLanguage + private(set) var primaryLayer: Editor.Code.Language private(set) var layers: [LanguageLayer] = [] // MARK: - Init @@ -42,7 +42,7 @@ public class TreeSitterState /// - readCallback: Callback used to read text for a specific range. /// - readBlock: Callback used to read blocks of text. init( - codeLanguage: CodeLanguage, + codeLanguage: Editor.Code.Language, readCallback: @escaping SwiftTreeSitter.Predicate.TextProvider, readBlock: @escaping Parser.ReadBlock ) @@ -53,7 +53,7 @@ public class TreeSitterState } /// Private initializer used by `copy` - private init(codeLanguage: CodeLanguage, layers: [LanguageLayer]) + private init(codeLanguage: Editor.Code.Language, layers: [LanguageLayer]) { primaryLayer = codeLanguage self.layers = layers @@ -61,7 +61,7 @@ public class TreeSitterState /// Sets the language for the state. Removing all existing layers. /// - Parameter codeLanguage: The language to use. - private func setLanguage(_ codeLanguage: CodeLanguage) + private func setLanguage(_ codeLanguage: Editor.Code.Language) { layers.removeAll() @@ -137,7 +137,7 @@ public class TreeSitterState readBlock _: @escaping Parser.ReadBlock ) -> LanguageLayer? { - guard let language = CodeLanguage.allLanguages.first(where: { $0.id == layerId }), + guard let language = Editor.Code.Language.allLanguages.first(where: { $0.id == layerId }), let parserLanguage = language.language else { diff --git a/Sources/Editors/Code/CosmoEditor/CosmoEditor.swift b/Sources/Editors/Code/CosmoEditor/CosmoEditor.swift deleted file mode 100644 index d7dfefca..00000000 --- a/Sources/Editors/Code/CosmoEditor/CosmoEditor.swift +++ /dev/null @@ -1,363 +0,0 @@ -/* -------------------------------------------------------------- - * :: : K R A K E N : :: - * -------------------------------------------------------------- - * @wabistudios :: metaverse :: kraken - * - * This program is free software; you can redistribute it, and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out - * the GNU General Public License for more details. - * - * You should have received a copy for this software license, the - * GNU General Public License along with this program; or, if not - * write to the Free Software Foundation, Inc., to the address of - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright (C) 2023 Wabi Foundation. - * All Rights Reserved. - * -------------------------------------------------------------- - * . x x x . o o o . x x x . : : : . o x o . : : : . - * -------------------------------------------------------------- */ - -import CosmoLanguages -import CosmoTextView -import SwiftUI - -public struct CosmoEditor: NSViewControllerRepresentable -{ - /// Initializes a Text Editor - /// - Parameters: - /// - text: The text content - /// - language: The language for syntax highlighting - /// - theme: The theme for syntax highlighting - /// - font: The default font - /// - tabWidth: The visual tab width in number of spaces - /// - indentOption: The behavior to use when the tab key is pressed. Defaults to 4 spaces. - /// - lineHeight: The line height multiplier (e.g. `1.2`) - /// - wrapLines: Whether lines wrap to the width of the editor - /// - editorOverscroll: The distance to overscroll the editor by. - /// - cursorPosition: The cursor's position in the editor, measured in `(lineNum, columnNum)` - /// - useThemeBackground: Determines whether the editor uses the theme's background color, or a transparent - /// background color - /// - highlightProvider: A class you provide to perform syntax highlighting. Leave this as `nil` to use the - /// built-in `TreeSitterClient` highlighter. - /// - contentInsets: Insets to use to offset the content in the enclosing scroll view. Leave as `nil` to let the - /// scroll view automatically adjust content insets. - /// - isEditable: A Boolean value that controls whether the text view allows the user to edit text. - /// - isSelectable: A Boolean value that controls whether the text view allows the user to select text. If this - /// value is true, and `isEditable` is false, the editor is selectable but not editable. - /// - letterSpacing: The amount of space to use between letters, as a percent. Eg: `1.0` = no space, `1.5` = 1/2 a - /// character's width between characters, etc. Defaults to `1.0` - /// - bracketPairHighlight: The type of highlight to use to highlight bracket pairs. - /// See `BracketPairHighlight` for more information. Defaults to `nil` - /// - undoManager: The undo manager for the text view. Defaults to `nil`, which will create a new CEUndoManager - public init( - _ text: Binding, - language: CodeLanguage, - theme: EditorTheme, - font: NSFont, - tabWidth: Int, - indentOption: IndentOption = .spaces(count: 4), - lineHeight: Double, - wrapLines: Bool, - editorOverscroll: CGFloat = 0, - cursorPositions: Binding<[CursorPosition]>, - useThemeBackground: Bool = true, - highlightProvider: HighlightProviding? = nil, - contentInsets: NSEdgeInsets? = nil, - isEditable: Bool = true, - isSelectable: Bool = true, - letterSpacing: Double = 1.0, - bracketPairHighlight: BracketPairHighlight? = nil, - undoManager: CEUndoManager? = nil, - coordinators: [any TextViewCoordinator] = [] - ) - { - _text = text - _cursorPositions = cursorPositions - self.language = language - self.theme = theme - self.useThemeBackground = useThemeBackground - self.font = font - self.tabWidth = tabWidth - self.indentOption = indentOption - self.lineHeight = lineHeight - self.wrapLines = wrapLines - self.editorOverscroll = editorOverscroll - self.highlightProvider = highlightProvider - self.contentInsets = contentInsets - self.isEditable = isEditable - self.isSelectable = isSelectable - self.letterSpacing = letterSpacing - self.bracketPairHighlight = bracketPairHighlight - self.undoManager = undoManager - self.coordinators = coordinators - } - - @Binding private var text: String - @Binding private var cursorPositions: [CursorPosition] - private var language: CodeLanguage - private var theme: EditorTheme - private var font: NSFont - private var tabWidth: Int - private var indentOption: IndentOption - private var lineHeight: Double - private var wrapLines: Bool - private var editorOverscroll: CGFloat - private var useThemeBackground: Bool - private var highlightProvider: HighlightProviding? - private var contentInsets: NSEdgeInsets? - private var isEditable: Bool - private var isSelectable: Bool - private var letterSpacing: Double - private var bracketPairHighlight: BracketPairHighlight? - private var undoManager: CEUndoManager? - private var coordinators: [any TextViewCoordinator] - - public typealias NSViewControllerType = TextViewController - - public func makeNSViewController(context: Context) -> TextViewController - { - let controller = TextViewController( - string: text, - language: language, - font: font, - theme: theme, - tabWidth: tabWidth, - indentOption: indentOption, - lineHeight: lineHeight, - wrapLines: wrapLines, - cursorPositions: cursorPositions, - editorOverscroll: editorOverscroll, - useThemeBackground: useThemeBackground, - highlightProvider: highlightProvider, - contentInsets: contentInsets, - isEditable: isEditable, - isSelectable: isSelectable, - letterSpacing: letterSpacing, - bracketPairHighlight: bracketPairHighlight, - undoManager: undoManager - ) - if controller.textView == nil - { - controller.loadView() - } - if !cursorPositions.isEmpty - { - controller.setCursorPositions(cursorPositions) - } - - context.coordinator.controller = controller - coordinators.forEach - { - $0.prepareCoordinator(controller: controller) - } - return controller - } - - public func makeCoordinator() -> Coordinator - { - Coordinator(parent: self) - } - - public func updateNSViewController(_ controller: TextViewController, context: Context) - { - if !context.coordinator.isUpdateFromTextView - { - // Prevent infinite loop of update notifications - context.coordinator.isUpdatingFromRepresentable = true - controller.setCursorPositions(cursorPositions) - context.coordinator.isUpdatingFromRepresentable = false - } - else - { - context.coordinator.isUpdateFromTextView = false - } - - // Do manual diffing to reduce the amount of reloads. - // This helps a lot in view performance, as it otherwise gets triggered on each environment change. - guard !paramsAreEqual(controller: controller) - else - { - return - } - - if controller.font != font - { - controller.font = font - } - - controller.wrapLines = wrapLines - controller.useThemeBackground = useThemeBackground - controller.lineHeightMultiple = lineHeight - controller.editorOverscroll = editorOverscroll - controller.contentInsets = contentInsets - - if controller.isEditable != isEditable - { - controller.isEditable = isEditable - } - - if controller.isSelectable != isSelectable - { - controller.isSelectable = isSelectable - } - - if controller.language.id != language.id - { - controller.language = language - } - - if controller.theme != theme - { - controller.theme = theme - } - - if controller.indentOption != indentOption - { - controller.indentOption = indentOption - } - - if controller.tabWidth != tabWidth - { - controller.tabWidth = tabWidth - } - - if controller.letterSpacing != letterSpacing - { - controller.letterSpacing = letterSpacing - } - - controller.bracketPairHighlight = bracketPairHighlight - - controller.reloadUI() - } - - func paramsAreEqual(controller: NSViewControllerType) -> Bool - { - controller.font == font && - controller.isEditable == isEditable && - controller.isSelectable == isSelectable && - controller.wrapLines == wrapLines && - controller.useThemeBackground == useThemeBackground && - controller.lineHeightMultiple == lineHeight && - controller.editorOverscroll == editorOverscroll && - controller.contentInsets == contentInsets && - controller.language.id == language.id && - controller.theme == theme && - controller.indentOption == indentOption && - controller.tabWidth == tabWidth && - controller.letterSpacing == letterSpacing && - controller.bracketPairHighlight == bracketPairHighlight - } - - @MainActor - public class Coordinator: NSObject - { - var parent: CosmoEditor - weak var controller: TextViewController? - var isUpdatingFromRepresentable: Bool = false - var isUpdateFromTextView: Bool = false - - init(parent: CosmoEditor) - { - self.parent = parent - super.init() - - NotificationCenter.default.addObserver( - self, - selector: #selector(textViewDidChangeText(_:)), - name: TextView.textDidChangeNotification, - object: nil - ) - - NotificationCenter.default.addObserver( - self, - selector: #selector(textControllerCursorsDidUpdate(_:)), - name: TextViewController.cursorPositionUpdatedNotification, - object: nil - ) - } - - @objc func textViewDidChangeText(_ notification: Notification) - { - guard let textView = notification.object as? TextView, - let controller, - controller.textView === textView - else - { - return - } - parent.text = textView.string - parent.coordinators.forEach - { - $0.textViewDidChangeText(controller: controller) - } - } - - @objc func textControllerCursorsDidUpdate(_: Notification) - { - guard !isUpdatingFromRepresentable else { return } - isUpdateFromTextView = true - parent._cursorPositions.wrappedValue = controller?.cursorPositions ?? [] - if controller != nil - { - parent.coordinators.forEach - { - $0.textViewDidChangeSelection( - controller: self.controller!, - newPositions: self.controller!.cursorPositions - ) - } - } - } - - deinit - { - parent.coordinators.forEach - { - $0.destroy() - } - parent.coordinators.removeAll() - NotificationCenter.default.removeObserver(self) - } - } -} - -// swiftlint:disable:next line_length -@available(*, unavailable, renamed: "CosmoEditor", message: "CosmoTextView has been renamed to CosmoEditor.") -public struct CosmoTextView: View -{ - public init( - _: Binding, - language _: CodeLanguage, - theme _: EditorTheme, - font _: NSFont, - tabWidth _: Int, - indentOption _: IndentOption = .spaces(count: 4), - lineHeight _: Double, - wrapLines _: Bool, - editorOverscroll _: CGFloat = 0, - cursorPositions _: Binding<[CursorPosition]>, - useThemeBackground _: Bool = true, - highlightProvider _: HighlightProviding? = nil, - contentInsets _: NSEdgeInsets? = nil, - isEditable _: Bool = true, - isSelectable _: Bool = true, - letterSpacing _: Double = 1.0, - bracketPairHighlight _: BracketPairHighlight? = nil, - undoManager _: CEUndoManager? = nil, - coordinators _: [any TextViewCoordinator] = [] - ) - {} - - public var body: some View - { - EmptyView() - } -} diff --git a/Sources/Editors/Code/CosmoEditor/Theme/EditorTheme.swift b/Sources/Editors/Code/CosmoEditor/Theme/EditorTheme.swift deleted file mode 100644 index c8ca869d..00000000 --- a/Sources/Editors/Code/CosmoEditor/Theme/EditorTheme.swift +++ /dev/null @@ -1,130 +0,0 @@ -/* -------------------------------------------------------------- - * :: : K R A K E N : :: - * -------------------------------------------------------------- - * @wabistudios :: metaverse :: kraken - * - * This program is free software; you can redistribute it, and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out - * the GNU General Public License for more details. - * - * You should have received a copy for this software license, the - * GNU General Public License along with this program; or, if not - * write to the Free Software Foundation, Inc., to the address of - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright (C) 2023 Wabi Foundation. - * All Rights Reserved. - * -------------------------------------------------------------- - * . x x x . o o o . x x x . : : : . o x o . : : : . - * -------------------------------------------------------------- */ - -import SwiftUI - -/// A collection of `NSColor` used for syntax higlighting -public struct EditorTheme -{ - public var text: NSColor - public var insertionPoint: NSColor - public var invisibles: NSColor - public var background: NSColor - public var lineHighlight: NSColor - public var selection: NSColor - public var keywords: NSColor - public var commands: NSColor - public var types: NSColor - public var attributes: NSColor - public var variables: NSColor - public var values: NSColor - public var numbers: NSColor - public var strings: NSColor - public var characters: NSColor - public var comments: NSColor - - public init( - text: NSColor, - insertionPoint: NSColor, - invisibles: NSColor, - background: NSColor, - lineHighlight: NSColor, - selection: NSColor, - keywords: NSColor, - commands: NSColor, - types: NSColor, - attributes: NSColor, - variables: NSColor, - values: NSColor, - numbers: NSColor, - strings: NSColor, - characters: NSColor, - comments: NSColor - ) - { - self.text = text - self.insertionPoint = insertionPoint - self.invisibles = invisibles - self.background = background - self.lineHighlight = lineHighlight - self.selection = selection - self.keywords = keywords - self.commands = commands - self.types = types - self.attributes = attributes - self.variables = variables - self.values = values - self.numbers = numbers - self.strings = strings - self.characters = characters - self.comments = comments - } - - /// Get the color from ``theme`` for the specified capture name. - /// - Parameter capture: The capture name - /// - Returns: A `NSColor` - func colorFor(_ capture: CaptureName?) -> NSColor - { - switch capture - { - case .include, .constructor, .keyword, .boolean, .variableBuiltin, - .keywordReturn, .keywordFunction, .repeat, .conditional, .tag: - keywords - case .comment: comments - case .variable, .property: variables - case .function, .method: variables - case .number, .float: numbers - case .string: strings - case .type: types - case .parameter: variables - case .typeAlternate: attributes - default: text - } - } -} - -extension EditorTheme: Equatable -{ - public static func == (lhs: EditorTheme, rhs: EditorTheme) -> Bool - { - lhs.text == rhs.text && - lhs.insertionPoint == rhs.insertionPoint && - lhs.invisibles == rhs.invisibles && - lhs.background == rhs.background && - lhs.lineHighlight == rhs.lineHighlight && - lhs.selection == rhs.selection && - lhs.keywords == rhs.keywords && - lhs.commands == rhs.commands && - lhs.types == rhs.types && - lhs.attributes == rhs.attributes && - lhs.variables == rhs.variables && - lhs.values == rhs.values && - lhs.numbers == rhs.numbers && - lhs.strings == rhs.strings && - lhs.characters == rhs.characters && - lhs.comments == rhs.comments - } -} diff --git a/Sources/Editors/Code/CosmoLanguages/CodeLanguage.swift b/Sources/Editors/Code/CosmoLanguages/CodeLanguage.swift deleted file mode 100644 index 288b7d44..00000000 --- a/Sources/Editors/Code/CosmoLanguages/CodeLanguage.swift +++ /dev/null @@ -1,190 +0,0 @@ -/* -------------------------------------------------------------- - * :: : K R A K E N : :: - * -------------------------------------------------------------- - * @wabistudios :: metaverse :: kraken - * - * This program is free software; you can redistribute it, and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out - * the GNU General Public License for more details. - * - * You should have received a copy for this software license, the - * GNU General Public License along with this program; or, if not - * write to the Free Software Foundation, Inc., to the address of - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright (C) 2023 Wabi Foundation. - * All Rights Reserved. - * -------------------------------------------------------------- - * . x x x . o o o . x x x . : : : . o x o . : : : . - * -------------------------------------------------------------- */ - -import CosmoLanguagesContainer -import Foundation -import RegexBuilder -import SwiftTreeSitter -import tree_sitter - -/// A structure holding metadata for code languages -public struct CodeLanguage -{ - init( - id: TreeSitterLanguage, - tsName: String, - extensions: Set, - lineCommentString: String, - rangeCommentStrings: (String, String), - documentationCommentStrings: Set = [], - parentURL: URL? = nil, - highlights: Set? = nil, - additionalIdentifiers: Set = [] - ) - { - self.id = id - self.tsName = tsName - self.extensions = extensions - self.lineCommentString = lineCommentString - self.rangeCommentStrings = rangeCommentStrings - self.documentationCommentStrings = documentationCommentStrings - parentQueryURL = parentURL - additionalHighlights = highlights - self.additionalIdentifiers = additionalIdentifiers - } - - /// The ID of the language - public let id: TreeSitterLanguage - - /// The display name of the language - public let tsName: String - - /// A set of file extensions for the language - /// - /// In special cases this can also be a file name - /// (e.g `Dockerfile`, `Makefile`) - public let extensions: Set - - /// The leading string of a comment line - public let lineCommentString: String - - /// The leading and trailing string of a multi-line comment - public let rangeCommentStrings: (String, String) - - /// The leading (and trailing, if there is one) string of a documentation comment - public let documentationCommentStrings: Set - - /// The query URL of a language this language inherits from. (e.g.: C for C++) - public let parentQueryURL: URL? - - /// Additional highlight file names (e.g.: JSX for JavaScript) - public let additionalHighlights: Set? - - /// The query URL for the language if available - public var queryURL: URL? - { - queryURL() - } - - /// The bundle's resource URL - var resourceURL: URL? = Bundle.module.resourceURL - - /// A set of aditional identifiers to use for things like shebang matching. - public let additionalIdentifiers: Set - - /// The tree-sitter language for the language if available - public var language: Language? - { - guard let tsLanguage else { return nil } - return Language(language: tsLanguage) - } - - func queryURL(for highlights: String = "highlights") -> URL? - { - resourceURL? - .appendingPathComponent("tree-sitter-\(tsName)/\(highlights).scm") - } - - /// Gets the TSLanguage from `tree-sitter` - private var tsLanguage: UnsafeMutablePointer? - { - switch id - { - case .c: - tree_sitter_c() - case .cpp: - tree_sitter_cpp() - case .json: - tree_sitter_json() - case .python: - tree_sitter_python() - case .rust: - tree_sitter_rust() - case .swift: - tree_sitter_swift() - case .toml: - tree_sitter_toml() - case .usd: - tree_sitter_usd() - case .plainText: - nil - } - } -} - -extension CodeLanguage: Hashable -{ - public static func == (lhs: CodeLanguage, rhs: CodeLanguage) -> Bool - { - lhs.id == rhs.id - } - - public func hash(into hasher: inout Hasher) - { - hasher.combine(id) - } -} - -public enum DocumentationComments: Hashable -{ - public static func == (lhs: DocumentationComments, rhs: DocumentationComments) -> Bool - { - switch lhs - { - case let .single(lhsString): - switch rhs - { - case let .single(rhsString): - lhsString == rhsString - case .pair: - false - } - case let .pair(lhsPair): - switch rhs - { - case .single: - false - case let .pair(rhsPair): - lhsPair.0 == rhsPair.0 && lhsPair.1 == rhsPair.1 - } - } - } - - public func hash(into hasher: inout Hasher) - { - switch self - { - case let .single(string): - hasher.combine(string) - case let .pair(pair): - hasher.combine(pair.0) - hasher.combine(pair.1) - } - } - - case single(String) - case pair((String, String)) -} diff --git a/Sources/Editors/Code/CosmoTextView/CosmoTextView.docc/CosmoTextView.md b/Sources/Editors/Code/CosmoTextView/CosmoTextView.docc/CosmoTextView.md deleted file mode 100644 index 8cf02fdc..00000000 --- a/Sources/Editors/Code/CosmoTextView/CosmoTextView.docc/CosmoTextView.md +++ /dev/null @@ -1,37 +0,0 @@ -# ``CosmoTextView`` - -A text editor designed to edit code documents. - -## Overview - -A text editor specialized for displaying and editing code documents. Features include basic text editing, extremely fast initial layout, support for handling large documents, customization options for code documents. - -> This package contains a text view suitable for replacing ``NSTextView`` in some, **_specific_** cases. - -The ``TextView`` class is an ``NSView`` subclass that can be embedded in a scroll view or used standalone. It parses and renders lines of a document and handles mouse and keyboard events for text editing. It also renders styled strings for use cases like syntax highlighting. - -## Topics - -### Text View - -- ``TextView`` -- ``CEUndoManager`` - -### Text Layout - -- ``TextLayoutManager`` -- ``TextLine`` -- ``LineFragment`` - -### Text Selection - -- ``TextSelectionManager`` -- ``TextSelectionManager/TextSelection`` -- ``CursorView`` - -### Supporting Types - -- ``TextLineStorage`` -- ``HorizontalEdgeInsets`` -- ``LineEnding`` -- ``LineBreakStrategy`` diff --git a/Sources/Editors/Code/CosmoTextView/CosmoTextView.swift b/Sources/Editors/Code/CosmoTextView/CosmoTextView.swift deleted file mode 100644 index b0d573f5..00000000 --- a/Sources/Editors/Code/CosmoTextView/CosmoTextView.swift +++ /dev/null @@ -1,14 +0,0 @@ -// This file is purely for helping in the transition from `CosmoTextView` to `CodeEditSourceEditor` -// The struct here is an empty view, and will be removed in a future release. - -import SwiftUI - -// swiftlint:disable:next line_length -@available(*, unavailable, renamed: "CodeEditSourceEditor", message: "CosmoTextView has moved to https://github.com/CodeEditApp/CodeEditSourceEditor, please update any dependencies to use this new repository URL.") -struct CosmoTextView: View -{ - var body: some View - { - EmptyView() - } -} diff --git a/Sources/Editors/Code/CosmoLanguages/CodeLanguage+Definitions.swift b/Sources/Editors/Code/Languages/CodeLanguage+Definitions.swift similarity index 81% rename from Sources/Editors/Code/CosmoLanguages/CodeLanguage+Definitions.swift rename to Sources/Editors/Code/Languages/CodeLanguage+Definitions.swift index f4050de2..92bb57a8 100644 --- a/Sources/Editors/Code/CosmoLanguages/CodeLanguage+Definitions.swift +++ b/Sources/Editors/Code/Languages/CodeLanguage+Definitions.swift @@ -27,7 +27,7 @@ // swiftlint:disable file_length // -// CodeLanguage+Definitions.swift +// Editor.Code.Language+Definitions.swift // // // Created by Lukas Pistrol on 15.01.23. @@ -35,10 +35,10 @@ import Foundation -public extension CodeLanguage +public extension Editor.Code.Language { /// An array of all language structures. - static let allLanguages: [CodeLanguage] = [ + static let allLanguages: [Editor.Code.Language] = [ .c, .cpp, .json, @@ -50,7 +50,7 @@ public extension CodeLanguage ] /// A language structure for `C` - static let c: CodeLanguage = .init( + static let c: Editor.Code.Language = .init( id: .c, tsName: "c", extensions: ["c", "h"], @@ -59,19 +59,19 @@ public extension CodeLanguage ) /// A language structure for `C++` - static let cpp: CodeLanguage = .init( + static let cpp: Editor.Code.Language = .init( id: .cpp, tsName: "cpp", extensions: ["cc", "cpp", "c++", "hpp", "h"], - lineCommentString: CodeLanguage.c.lineCommentString, - rangeCommentStrings: CodeLanguage.c.rangeCommentStrings, + lineCommentString: Editor.Code.Language.c.lineCommentString, + rangeCommentStrings: Editor.Code.Language.c.rangeCommentStrings, documentationCommentStrings: [.pair(("/**", "*/"))], - parentURL: CodeLanguage.c.queryURL, + parentURL: Editor.Code.Language.c.queryURL, highlights: ["injections"] ) /// A language structure for `JSON` - static let json: CodeLanguage = .init( + static let json: Editor.Code.Language = .init( id: .json, tsName: "json", extensions: ["json"], @@ -80,7 +80,7 @@ public extension CodeLanguage ) /// A language structure for `Python` - static let python: CodeLanguage = .init( + static let python: Editor.Code.Language = .init( id: .python, tsName: "python", extensions: ["py"], @@ -91,7 +91,7 @@ public extension CodeLanguage ) /// A language structure for `Rust` - static let rust: CodeLanguage = .init( + static let rust: Editor.Code.Language = .init( id: .rust, tsName: "rust", extensions: ["rs"], @@ -107,7 +107,7 @@ public extension CodeLanguage ) /// A language structure for `Swift` - static let swift: CodeLanguage = .init( + static let swift: Editor.Code.Language = .init( id: .swift, tsName: "swift", extensions: ["swift"], @@ -117,7 +117,7 @@ public extension CodeLanguage ) /// A language structure for `TOML` - static let toml: CodeLanguage = .init( + static let toml: Editor.Code.Language = .init( id: .toml, tsName: "toml", extensions: ["toml"], @@ -126,17 +126,17 @@ public extension CodeLanguage ) /// A language structure for `USD` - static let usd: CodeLanguage = .init( + static let usd: Editor.Code.Language = .init( id: .usd, tsName: "usd", extensions: ["usda"], lineCommentString: "#", rangeCommentStrings: ("", ""), - documentationCommentStrings: [.pair(("(", ")"))] + documentationCommentStrings: [.pair(("\"", "\""))] ) /// The default language (plain text) - static let `default`: CodeLanguage = .init( + static let `default`: Editor.Code.Language = .init( id: .plainText, tsName: "PlainText", extensions: ["txt"], diff --git a/Sources/Editors/Code/CosmoLanguages/CodeLanguage+DetectLanguage.swift b/Sources/Editors/Code/Languages/CodeLanguage+DetectLanguage.swift similarity index 95% rename from Sources/Editors/Code/CosmoLanguages/CodeLanguage+DetectLanguage.swift rename to Sources/Editors/Code/Languages/CodeLanguage+DetectLanguage.swift index 0f255407..77dfa203 100644 --- a/Sources/Editors/Code/CosmoLanguages/CodeLanguage+DetectLanguage.swift +++ b/Sources/Editors/Code/Languages/CodeLanguage+DetectLanguage.swift @@ -27,7 +27,7 @@ import Foundation import RegexBuilder -public extension CodeLanguage +public extension Editor.Code.Language { /// Gets the corresponding language for the given file URL /// @@ -37,7 +37,7 @@ public extension CodeLanguage /// - url: The URL to get the language for. /// - prefixBuffer: The first few lines of the document. /// - suffixBuffer: The last few lines of the document. - static func detectLanguageFrom(url: URL, prefixBuffer: String? = nil, suffixBuffer: String? = nil) -> CodeLanguage + static func detectLanguageFrom(url: URL, prefixBuffer: String? = nil, suffixBuffer: String? = nil) -> Editor.Code.Language { if let urlLanguage = detectLanguageUsingURL(url: url) { @@ -65,7 +65,7 @@ public extension CodeLanguage /// Detects a file's language using the file url. /// - Parameter url: The URL of the file. /// - Returns: The detected code language, if any. - private static func detectLanguageUsingURL(url: URL) -> CodeLanguage? + private static func detectLanguageUsingURL(url: URL) -> Editor.Code.Language? { let fileExtension = url.pathExtension.lowercased() let fileName = url.pathComponents.last // should not be lowercase since it has to match e.g. `Dockerfile` @@ -86,7 +86,7 @@ public extension CodeLanguage /// Or, `#! /usr/bin/env perl` will detect the `perl` code language. /// - Parameter contents: The contents of the first few lines of the file. /// - Returns: The detected code language, if any. - private static func detectLanguageUsingShebang(contents: String) -> CodeLanguage? + private static func detectLanguageUsingShebang(contents: String) -> Editor.Code.Language? { var contents = String(contents.split(separator: "\n").first ?? "") // Make sure: @@ -182,9 +182,9 @@ public extension CodeLanguage /// - prefixBuffer: The first few lines of a document. /// - suffixBuffer: The last few lines of a document. /// - Returns: The detected code language, if any. - private static func detecLanguageUsingModeline(prefixBuffer: String, suffixBuffer: String?) -> CodeLanguage? + private static func detecLanguageUsingModeline(prefixBuffer: String, suffixBuffer: String?) -> Editor.Code.Language? { - func detectModeline(in string: String) -> CodeLanguage? + func detectModeline(in string: String) -> Editor.Code.Language? { guard !string.isEmpty else { return nil } @@ -255,7 +255,7 @@ public extension CodeLanguage /// Finds a language to match a parsed identifier. /// - Parameter identifier: The identifier to use. /// - Returns: The found code language, if any. - private static func languageFromIdentifier(_ identifier: String) -> CodeLanguage? + private static func languageFromIdentifier(_ identifier: String) -> Editor.Code.Language? { allLanguages.first { diff --git a/Sources/Editors/Code/Languages/CodeLanguage.swift b/Sources/Editors/Code/Languages/CodeLanguage.swift new file mode 100644 index 00000000..926eafd0 --- /dev/null +++ b/Sources/Editors/Code/Languages/CodeLanguage.swift @@ -0,0 +1,193 @@ +/* -------------------------------------------------------------- + * :: : K R A K E N : :: + * -------------------------------------------------------------- + * @wabistudios :: metaverse :: kraken + * + * This program is free software; you can redistribute it, and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out + * the GNU General Public License for more details. + * + * You should have received a copy for this software license, the + * GNU General Public License along with this program; or, if not + * write to the Free Software Foundation, Inc., to the address of + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright (C) 2023 Wabi Foundation. + * All Rights Reserved. + * -------------------------------------------------------------- + * . x x x . o o o . x x x . : : : . o x o . : : : . + * -------------------------------------------------------------- */ + +import Foundation +import LanguagesBundle +import RegexBuilder +import SwiftTreeSitter +import tree_sitter + +public extension Editor.Code +{ + /// A structure holding metadata for code languages + struct Language + { + init( + id: TreeSitterLanguage, + tsName: String, + extensions: Set, + lineCommentString: String, + rangeCommentStrings: (String, String), + documentationCommentStrings: Set = [], + parentURL: URL? = nil, + highlights: Set? = nil, + additionalIdentifiers: Set = [] + ) + { + self.id = id + self.tsName = tsName + self.extensions = extensions + self.lineCommentString = lineCommentString + self.rangeCommentStrings = rangeCommentStrings + self.documentationCommentStrings = documentationCommentStrings + parentQueryURL = parentURL + additionalHighlights = highlights + self.additionalIdentifiers = additionalIdentifiers + } + + /// The ID of the language + public let id: TreeSitterLanguage + + /// The display name of the language + public let tsName: String + + /// A set of file extensions for the language + /// + /// In special cases this can also be a file name + /// (e.g `Dockerfile`, `Makefile`) + public let extensions: Set + + /// The leading string of a comment line + public let lineCommentString: String + + /// The leading and trailing string of a multi-line comment + public let rangeCommentStrings: (String, String) + + /// The leading (and trailing, if there is one) string of a documentation comment + public let documentationCommentStrings: Set + + /// The query URL of a language this language inherits from. (e.g.: C for C++) + public let parentQueryURL: URL? + + /// Additional highlight file names (e.g.: JSX for JavaScript) + public let additionalHighlights: Set? + + /// The query URL for the language if available + public var queryURL: URL? + { + queryURL() + } + + /// The bundle's resource URL + var resourceURL: URL? = Bundle.module.resourceURL + + /// A set of aditional identifiers to use for things like shebang matching. + public let additionalIdentifiers: Set + + /// The tree-sitter language for the language if available + public var language: SwiftTreeSitter.Language? + { + guard let tsLanguage else { return nil } + return SwiftTreeSitter.Language(language: tsLanguage) + } + + func queryURL(for highlights: String = "highlights") -> URL? + { + resourceURL? + .appendingPathComponent("tree-sitter-\(tsName)/\(highlights).scm") + } + + /// Gets the TSLanguage from `tree-sitter` + private var tsLanguage: UnsafeMutablePointer? + { + switch id + { + case .c: + tree_sitter_c() + case .cpp: + tree_sitter_cpp() + case .json: + tree_sitter_json() + case .python: + tree_sitter_python() + case .rust: + tree_sitter_rust() + case .swift: + tree_sitter_swift() + case .toml: + tree_sitter_toml() + case .usd: + tree_sitter_usd() + case .plainText: + nil + } + } + } +} + +extension Editor.Code.Language: Hashable +{ + public static func == (lhs: Self, rhs: Self) -> Bool + { + lhs.id == rhs.id + } + + public func hash(into hasher: inout Hasher) + { + hasher.combine(id) + } +} + +public enum DocumentationComments: Hashable +{ + public static func == (lhs: Self, rhs: Self) -> Bool + { + switch lhs + { + case let .single(lhsString): + switch rhs + { + case let .single(rhsString): + lhsString == rhsString + case .pair: + false + } + case let .pair(lhsPair): + switch rhs + { + case .single: + false + case let .pair(rhsPair): + lhsPair.0 == rhsPair.0 && lhsPair.1 == rhsPair.1 + } + } + } + + public func hash(into hasher: inout Hasher) + { + switch self + { + case let .single(string): + hasher.combine(string) + case let .pair(pair): + hasher.combine(pair.0) + hasher.combine(pair.1) + } + } + + case single(String) + case pair((String, String)) +} diff --git a/Sources/KrakenUI/Code/CodeEditor.swift b/Sources/Editors/Code/Languages/ED.Code.swift similarity index 66% rename from Sources/KrakenUI/Code/CodeEditor.swift rename to Sources/Editors/Code/Languages/ED.Code.swift index eaf88143..2ef1721b 100644 --- a/Sources/KrakenUI/Code/CodeEditor.swift +++ b/Sources/Editors/Code/Languages/ED.Code.swift @@ -24,36 +24,8 @@ * . x x x . o o o . x x x . : : : . o x o . : : : . * -------------------------------------------------------------- */ -import CosmoEditor -import Foundation -import SwiftUI - -public struct CodeEditor: View +public enum Editor { - @Binding var text: String - - @State private var cursorPositions: [CursorPosition] - - public init(text: Binding) - { - _text = text - _cursorPositions = State(initialValue: []) - } - - public var body: some View - { - CosmoEditor( - $text, - language: .default, - theme: .standard, - font: .monospacedSystemFont(ofSize: 11, weight: .bold), - tabWidth: 2, - indentOption: .spaces(count: 2), - lineHeight: 1.2, - wrapLines: true, - editorOverscroll: 0.3, - cursorPositions: $cursorPositions, - useThemeBackground: false - ) - } + public enum Code + {} } diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-c/highlights.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-c/highlights.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-c/highlights.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-c/highlights.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-c/tags.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-c/tags.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-c/tags.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-c/tags.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-cpp/highlights.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-cpp/highlights.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-cpp/highlights.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-cpp/highlights.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-cpp/injections.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-cpp/injections.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-cpp/injections.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-cpp/injections.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-cpp/tags.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-cpp/tags.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-cpp/tags.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-cpp/tags.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-json/highlights.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-json/highlights.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-json/highlights.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-json/highlights.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-python/highlights.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-python/highlights.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-python/highlights.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-python/highlights.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-python/tags.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-python/tags.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-python/tags.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-python/tags.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-rust/highlights.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-rust/highlights.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-rust/highlights.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-rust/highlights.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-rust/injections.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-rust/injections.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-rust/injections.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-rust/injections.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-rust/tags.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-rust/tags.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-rust/tags.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-rust/tags.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-swift/highlights.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-swift/highlights.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-swift/highlights.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-swift/highlights.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-swift/indents.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-swift/indents.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-swift/indents.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-swift/indents.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-swift/injections.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-swift/injections.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-swift/injections.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-swift/injections.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-swift/locals.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-swift/locals.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-swift/locals.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-swift/locals.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-swift/tags.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-swift/tags.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-swift/tags.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-swift/tags.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-swift/textobjects.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-swift/textobjects.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-swift/textobjects.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-swift/textobjects.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-toml/highlights.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-toml/highlights.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-toml/highlights.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-toml/highlights.scm diff --git a/Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-usd/highlights.scm b/Sources/Editors/Code/Languages/Resources/tree-sitter-usd/highlights.scm similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/Resources/tree-sitter-usd/highlights.scm rename to Sources/Editors/Code/Languages/Resources/tree-sitter-usd/highlights.scm diff --git a/Sources/Editors/Code/CosmoLanguages/TreeSitterLanguage.swift b/Sources/Editors/Code/Languages/TreeSitterLanguage.swift similarity index 100% rename from Sources/Editors/Code/CosmoLanguages/TreeSitterLanguage.swift rename to Sources/Editors/Code/Languages/TreeSitterLanguage.swift diff --git a/Sources/Editors/Code/CosmoLanguages/TreeSitterModel.swift b/Sources/Editors/Code/Languages/TreeSitterModel.swift similarity index 98% rename from Sources/Editors/Code/CosmoLanguages/TreeSitterModel.swift rename to Sources/Editors/Code/Languages/TreeSitterModel.swift index 5523d329..c3943a60 100644 --- a/Sources/Editors/Code/CosmoLanguages/TreeSitterModel.swift +++ b/Sources/Editors/Code/Languages/TreeSitterModel.swift @@ -86,7 +86,7 @@ public class TreeSitterModel /// Query for `USD` files. public private(set) lazy var usdQuery: Query? = queryFor(.usd) - private func queryFor(_ codeLanguage: CodeLanguage) -> Query? + private func queryFor(_ codeLanguage: Editor.Code.Language) -> Query? { // get the tree-sitter language and query url if available guard let language = codeLanguage.language, diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterC/grammar.json b/Sources/Editors/Code/LanguagesBundle/TreeSitterC/grammar.json similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterC/grammar.json rename to Sources/Editors/Code/LanguagesBundle/TreeSitterC/grammar.json diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterC/include/TreeSitterC/Alloc.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterC/include/TreeSitterC/Alloc.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterC/include/TreeSitterC/Alloc.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterC/include/TreeSitterC/Alloc.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterC/include/TreeSitterC/Array.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterC/include/TreeSitterC/Array.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterC/include/TreeSitterC/Array.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterC/include/TreeSitterC/Array.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterC/include/TreeSitterC/TreeSitterC.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterC/include/TreeSitterC/TreeSitterC.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterC/include/TreeSitterC/TreeSitterC.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterC/include/TreeSitterC/TreeSitterC.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterC/node-types.json b/Sources/Editors/Code/LanguagesBundle/TreeSitterC/node-types.json similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterC/node-types.json rename to Sources/Editors/Code/LanguagesBundle/TreeSitterC/node-types.json diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterC/parser.c b/Sources/Editors/Code/LanguagesBundle/TreeSitterC/parser.c similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterC/parser.c rename to Sources/Editors/Code/LanguagesBundle/TreeSitterC/parser.c diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterCPP/grammar.json b/Sources/Editors/Code/LanguagesBundle/TreeSitterCPP/grammar.json similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterCPP/grammar.json rename to Sources/Editors/Code/LanguagesBundle/TreeSitterCPP/grammar.json diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterCPP/include/TreeSitterCPP/Alloc.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterCPP/include/TreeSitterCPP/Alloc.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterCPP/include/TreeSitterCPP/Alloc.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterCPP/include/TreeSitterCPP/Alloc.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterCPP/include/TreeSitterCPP/Array.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterCPP/include/TreeSitterCPP/Array.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterCPP/include/TreeSitterCPP/Array.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterCPP/include/TreeSitterCPP/Array.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterCPP/include/TreeSitterCPP/TreeSitterCPP.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterCPP/include/TreeSitterCPP/TreeSitterCPP.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterCPP/include/TreeSitterCPP/TreeSitterCPP.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterCPP/include/TreeSitterCPP/TreeSitterCPP.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterCPP/node-types.json b/Sources/Editors/Code/LanguagesBundle/TreeSitterCPP/node-types.json similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterCPP/node-types.json rename to Sources/Editors/Code/LanguagesBundle/TreeSitterCPP/node-types.json diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterCPP/parser.c b/Sources/Editors/Code/LanguagesBundle/TreeSitterCPP/parser.c similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterCPP/parser.c rename to Sources/Editors/Code/LanguagesBundle/TreeSitterCPP/parser.c diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterCPP/scanner.c b/Sources/Editors/Code/LanguagesBundle/TreeSitterCPP/scanner.c similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterCPP/scanner.c rename to Sources/Editors/Code/LanguagesBundle/TreeSitterCPP/scanner.c diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterJSON/grammar.json b/Sources/Editors/Code/LanguagesBundle/TreeSitterJSON/grammar.json similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterJSON/grammar.json rename to Sources/Editors/Code/LanguagesBundle/TreeSitterJSON/grammar.json diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterJSON/include/TreeSitterJSON/Alloc.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterJSON/include/TreeSitterJSON/Alloc.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterJSON/include/TreeSitterJSON/Alloc.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterJSON/include/TreeSitterJSON/Alloc.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterJSON/include/TreeSitterJSON/Array.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterJSON/include/TreeSitterJSON/Array.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterJSON/include/TreeSitterJSON/Array.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterJSON/include/TreeSitterJSON/Array.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterJSON/include/TreeSitterJSON/TreeSitterJSON.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterJSON/include/TreeSitterJSON/TreeSitterJSON.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterJSON/include/TreeSitterJSON/TreeSitterJSON.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterJSON/include/TreeSitterJSON/TreeSitterJSON.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterJSON/node-types.json b/Sources/Editors/Code/LanguagesBundle/TreeSitterJSON/node-types.json similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterJSON/node-types.json rename to Sources/Editors/Code/LanguagesBundle/TreeSitterJSON/node-types.json diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterJSON/parser.c b/Sources/Editors/Code/LanguagesBundle/TreeSitterJSON/parser.c similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterJSON/parser.c rename to Sources/Editors/Code/LanguagesBundle/TreeSitterJSON/parser.c diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterPython/grammar.json b/Sources/Editors/Code/LanguagesBundle/TreeSitterPython/grammar.json similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterPython/grammar.json rename to Sources/Editors/Code/LanguagesBundle/TreeSitterPython/grammar.json diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterPython/include/TreeSitterPython/Alloc.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterPython/include/TreeSitterPython/Alloc.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterPython/include/TreeSitterPython/Alloc.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterPython/include/TreeSitterPython/Alloc.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterPython/include/TreeSitterPython/Array.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterPython/include/TreeSitterPython/Array.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterPython/include/TreeSitterPython/Array.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterPython/include/TreeSitterPython/Array.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterPython/include/TreeSitterPython/TreeSitterPython.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterPython/include/TreeSitterPython/TreeSitterPython.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterPython/include/TreeSitterPython/TreeSitterPython.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterPython/include/TreeSitterPython/TreeSitterPython.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterPython/node-types.json b/Sources/Editors/Code/LanguagesBundle/TreeSitterPython/node-types.json similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterPython/node-types.json rename to Sources/Editors/Code/LanguagesBundle/TreeSitterPython/node-types.json diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterPython/parser.c b/Sources/Editors/Code/LanguagesBundle/TreeSitterPython/parser.c similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterPython/parser.c rename to Sources/Editors/Code/LanguagesBundle/TreeSitterPython/parser.c diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterPython/scanner.c b/Sources/Editors/Code/LanguagesBundle/TreeSitterPython/scanner.c similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterPython/scanner.c rename to Sources/Editors/Code/LanguagesBundle/TreeSitterPython/scanner.c diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterRust/grammar.json b/Sources/Editors/Code/LanguagesBundle/TreeSitterRust/grammar.json similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterRust/grammar.json rename to Sources/Editors/Code/LanguagesBundle/TreeSitterRust/grammar.json diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterRust/include/TreeSitterRust/Alloc.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterRust/include/TreeSitterRust/Alloc.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterRust/include/TreeSitterRust/Alloc.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterRust/include/TreeSitterRust/Alloc.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterRust/include/TreeSitterRust/Array.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterRust/include/TreeSitterRust/Array.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterRust/include/TreeSitterRust/Array.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterRust/include/TreeSitterRust/Array.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterRust/include/TreeSitterRust/TreeSitterRust.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterRust/include/TreeSitterRust/TreeSitterRust.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterRust/include/TreeSitterRust/TreeSitterRust.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterRust/include/TreeSitterRust/TreeSitterRust.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterRust/node-types.json b/Sources/Editors/Code/LanguagesBundle/TreeSitterRust/node-types.json similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterRust/node-types.json rename to Sources/Editors/Code/LanguagesBundle/TreeSitterRust/node-types.json diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterRust/parser.c b/Sources/Editors/Code/LanguagesBundle/TreeSitterRust/parser.c similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterRust/parser.c rename to Sources/Editors/Code/LanguagesBundle/TreeSitterRust/parser.c diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterRust/scanner.c b/Sources/Editors/Code/LanguagesBundle/TreeSitterRust/scanner.c similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterRust/scanner.c rename to Sources/Editors/Code/LanguagesBundle/TreeSitterRust/scanner.c diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterSwift/grammar.json b/Sources/Editors/Code/LanguagesBundle/TreeSitterSwift/grammar.json similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterSwift/grammar.json rename to Sources/Editors/Code/LanguagesBundle/TreeSitterSwift/grammar.json diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterSwift/include/TreeSitterSwift/TreeSitterSwift.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterSwift/include/TreeSitterSwift/TreeSitterSwift.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterSwift/include/TreeSitterSwift/TreeSitterSwift.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterSwift/include/TreeSitterSwift/TreeSitterSwift.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterSwift/node-types.json b/Sources/Editors/Code/LanguagesBundle/TreeSitterSwift/node-types.json similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterSwift/node-types.json rename to Sources/Editors/Code/LanguagesBundle/TreeSitterSwift/node-types.json diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterSwift/parser.c b/Sources/Editors/Code/LanguagesBundle/TreeSitterSwift/parser.c similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterSwift/parser.c rename to Sources/Editors/Code/LanguagesBundle/TreeSitterSwift/parser.c diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterSwift/scanner.c b/Sources/Editors/Code/LanguagesBundle/TreeSitterSwift/scanner.c similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterSwift/scanner.c rename to Sources/Editors/Code/LanguagesBundle/TreeSitterSwift/scanner.c diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterTOML/grammar.json b/Sources/Editors/Code/LanguagesBundle/TreeSitterTOML/grammar.json similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterTOML/grammar.json rename to Sources/Editors/Code/LanguagesBundle/TreeSitterTOML/grammar.json diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterTOML/include/TreeSitterTOML/TreeSitterTOML.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterTOML/include/TreeSitterTOML/TreeSitterTOML.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterTOML/include/TreeSitterTOML/TreeSitterTOML.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterTOML/include/TreeSitterTOML/TreeSitterTOML.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterTOML/node-types.json b/Sources/Editors/Code/LanguagesBundle/TreeSitterTOML/node-types.json similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterTOML/node-types.json rename to Sources/Editors/Code/LanguagesBundle/TreeSitterTOML/node-types.json diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterTOML/parser.c b/Sources/Editors/Code/LanguagesBundle/TreeSitterTOML/parser.c similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterTOML/parser.c rename to Sources/Editors/Code/LanguagesBundle/TreeSitterTOML/parser.c diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterTOML/scanner.c b/Sources/Editors/Code/LanguagesBundle/TreeSitterTOML/scanner.c similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterTOML/scanner.c rename to Sources/Editors/Code/LanguagesBundle/TreeSitterTOML/scanner.c diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterUSD/grammar.json b/Sources/Editors/Code/LanguagesBundle/TreeSitterUSD/grammar.json similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterUSD/grammar.json rename to Sources/Editors/Code/LanguagesBundle/TreeSitterUSD/grammar.json diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterUSD/include/TreeSitterUSD/TreeSitterUSD.h b/Sources/Editors/Code/LanguagesBundle/TreeSitterUSD/include/TreeSitterUSD/TreeSitterUSD.h similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterUSD/include/TreeSitterUSD/TreeSitterUSD.h rename to Sources/Editors/Code/LanguagesBundle/TreeSitterUSD/include/TreeSitterUSD/TreeSitterUSD.h diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterUSD/node-types.json b/Sources/Editors/Code/LanguagesBundle/TreeSitterUSD/node-types.json similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterUSD/node-types.json rename to Sources/Editors/Code/LanguagesBundle/TreeSitterUSD/node-types.json diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterUSD/parser.c b/Sources/Editors/Code/LanguagesBundle/TreeSitterUSD/parser.c similarity index 100% rename from Sources/Editors/Code/CosmoLanguagesContainer/TreeSitterUSD/parser.c rename to Sources/Editors/Code/LanguagesBundle/TreeSitterUSD/parser.c diff --git a/Sources/Editors/Code/CosmoLanguagesContainer/include/CosmoLanguagesContainer/CosmoLanguagesContainer.h b/Sources/Editors/Code/LanguagesBundle/include/LanguagesBundle/LanguagesBundle.h similarity index 81% rename from Sources/Editors/Code/CosmoLanguagesContainer/include/CosmoLanguagesContainer/CosmoLanguagesContainer.h rename to Sources/Editors/Code/LanguagesBundle/include/LanguagesBundle/LanguagesBundle.h index 6f33e33a..4eb7ea81 100644 --- a/Sources/Editors/Code/CosmoLanguagesContainer/include/CosmoLanguagesContainer/CosmoLanguagesContainer.h +++ b/Sources/Editors/Code/LanguagesBundle/include/LanguagesBundle/LanguagesBundle.h @@ -1,5 +1,5 @@ -#ifndef __CODE_LANGUAGES_CONTAINER_H__ -#define __CODE_LANGUAGES_CONTAINER_H__ +#ifndef __CODE_LANGUAGES_BUNDLE_H__ +#define __CODE_LANGUAGES_BUNDLE_H__ typedef struct TSLanguage TSLanguage; @@ -23,4 +23,4 @@ extern TSLanguage *tree_sitter_usd(); } #endif -#endif // __CODE_LANGUAGES_CONTAINER_H__ +#endif // __CODE_LANGUAGES_BUNDLE_H__ diff --git a/Sources/Kraken/IO/Hydra/KIO.StageManager.swift b/Sources/Kraken/IO/Hydra/KIO.StageManager.swift new file mode 100644 index 00000000..4b737ac0 --- /dev/null +++ b/Sources/Kraken/IO/Hydra/KIO.StageManager.swift @@ -0,0 +1,127 @@ +/* -------------------------------------------------------------- + * :: : K R A K E N : :: + * -------------------------------------------------------------- + * @wabistudios :: metaverse :: kraken + * + * This program is free software; you can redistribute it, and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out + * the GNU General Public License for more details. + * + * You should have received a copy for this software license, the + * GNU General Public License along with this program; or, if not + * write to the Free Software Foundation, Inc., to the address of + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright (C) 2023 Wabi Foundation. + * All Rights Reserved. + * -------------------------------------------------------------- + * . x x x . o o o . x x x . : : : . o x o . : : : . + * -------------------------------------------------------------- */ + +import CxxStdlib +import Foundation +import PixarUSD + +public extension Kraken.IO +{ + /** + * A manager for validating and managing the + * stage files used by Kraken for USD operations. */ + struct Stage + { + /** The shared instance of the stage manager singleton. */ + public static let manager = Stage() + + private init() + {} + + /** The underlying file manager for file ops. */ + private let fileManager = FileManager.default + + /** + * Validates the usd file at the given path. + * + * Creates a new file if it does not exist. + * If the file is not readable or writable, + * it will be removed and recreated with the + * correct file permissions. + * + * - Parameter file: The usd filepath to validate. */ + @discardableResult + public func validate(url fileURL: URL?) -> String + { + let filePath = fileURL?.absoluteString + ?? "\(Bundle.main.resourcePath ?? ".")/Untitled.usda" + + guard + fileManager.fileExists(atPath: filePath), + fileManager.isReadableFile(atPath: filePath), + fileManager.isWritableFile(atPath: filePath) + else + { + try? fileManager.removeItem(atPath: filePath) + + fileManager.createFile( + atPath: filePath, + contents: (try? String( + contentsOfFile: filePath + ).data(using: .utf8)) ?? "".data(using: .utf8), + attributes: [.posixPermissions: 0o777] + ) + + return filePath + } + + return filePath + } + + /** + * Saves (.usda) file contents and syncs modifications + * to the stage in real time. + * + * When this method is called, it will validate + * the file at the given path, write the stage data + * to the file, and then reload the stage in real + * time to ensure the changes are reflected. + * + * - Parameters: + * - stageData: The stage data to save to the file. + * - file: The usd filepath to save the data to. + * - stage: The stage to save and reload. */ + public func save(contentsOfFile stageData: String, atPath file: String, stage: inout UsdStageRefPtr) + { + let path = URL(fileURLWithPath: file) + validate(url: path) + + do + { + try stageData.write(to: path, atomically: true, encoding: .utf8) + } + catch + { + print("Error writing to file: \(path.absoluteString)") + } + + stage.pointee.Reload() + + stage.save() + } + + func save(_ stage: inout UsdStageRefPtr) + { + let formatter = DateFormatter() + formatter.dateFormat = "MM-dd-yyyy HH:mm:ss" + let date = formatter.string(from: Date()) + + /* set the timestamp metadata & save. */ + stage.getPseudoRoot().set(doc: "\(date) | Kraken v\(Kraken.version)") + stage.save() + } + } +} diff --git a/Sources/Kraken/IO/KIO.swift b/Sources/Kraken/IO/KIO.swift new file mode 100644 index 00000000..2bddff73 --- /dev/null +++ b/Sources/Kraken/IO/KIO.swift @@ -0,0 +1,31 @@ +/* -------------------------------------------------------------- + * :: : K R A K E N : :: + * -------------------------------------------------------------- + * @wabistudios :: metaverse :: kraken + * + * This program is free software; you can redistribute it, and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out + * the GNU General Public License for more details. + * + * You should have received a copy for this software license, the + * GNU General Public License along with this program; or, if not + * write to the Free Software Foundation, Inc., to the address of + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright (C) 2023 Wabi Foundation. + * All Rights Reserved. + * -------------------------------------------------------------- + * . x x x . o o o . x x x . : : : . o x o . : : : . + * -------------------------------------------------------------- */ + +public extension Kraken +{ + enum IO + {} +} diff --git a/Sources/Kraken/IO/Universal/KIO.USD.swift b/Sources/Kraken/IO/Universal/KIO.USD.swift new file mode 100644 index 00000000..b9514daa --- /dev/null +++ b/Sources/Kraken/IO/Universal/KIO.USD.swift @@ -0,0 +1,71 @@ +/* -------------------------------------------------------------- + * :: : K R A K E N : :: + * -------------------------------------------------------------- + * @wabistudios :: metaverse :: kraken + * + * This program is free software; you can redistribute it, and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out + * the GNU General Public License for more details. + * + * You should have received a copy for this software license, the + * GNU General Public License along with this program; or, if not + * write to the Free Software Foundation, Inc., to the address of + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright (C) 2023 Wabi Foundation. + * All Rights Reserved. + * -------------------------------------------------------------- + * . x x x . o o o . x x x . : : : . o x o . : : : . + * -------------------------------------------------------------- */ + +import SwiftUI +import UniformTypeIdentifiers + +public extension Kraken.IO +{ + struct USD: FileDocument + { + var text: String + + public init(text: String = "") + { + self.text = text + } + + public static var readableContentTypes: [UTType] + { + [ + .sourceCode, + .plainText, + .usd, + .usdz, + .delimitedText, + .script + ] + } + + public init(configuration: ReadConfiguration) throws + { + guard let data = configuration.file.regularFileContents, + let string = String(data: data, encoding: .utf8) + else + { + text = "" + return + } + text = string + } + + public func fileWrapper(configuration _: WriteConfiguration) throws -> FileWrapper + { + let data = text.data(using: .utf8) ?? "".data(using: .utf8)! + return .init(regularFileWithContents: data) + } + } +} diff --git a/Sources/Kraken/Creator.swift b/Sources/Kraken/KR/KR.Creator.swift similarity index 52% rename from Sources/Kraken/Creator.swift rename to Sources/Kraken/KR/KR.Creator.swift index 13bd706f..4f25e06e 100644 --- a/Sources/Kraken/Creator.swift +++ b/Sources/Kraken/KR/KR.Creator.swift @@ -28,8 +28,8 @@ import CxxStdlib import Foundation import KrakenKit import KrakenLib -import KrakenUI import PixarUSD +import SceneKit #if canImport(PyBundle) import PyBundle import Python @@ -40,7 +40,7 @@ import SwiftUI #endif /* canImport(GtkBackend) */ @main -struct Kraken: App +public struct Kraken: SwiftUI.App { #if canImport(GtkBackend) typealias Backend = GtkBackend @@ -52,15 +52,10 @@ struct Kraken: App /** The current version of Kraken. */ public static let version = ".".join(array: Pixar.GfVec3i(1, 0, 7)) - /** The current usd filepath. */ - public static let filePath = "\(Bundle.main.resourcePath ?? ".")/KrakenExampleScene.usda" + /** Whether to show the splash screen. */ + @State public var showSplash = true - /** The current stage for Kraken. */ - @State private var stage: UsdStageRefPtr - @State private var showSplash = true - @State private var usdFile: String = "" - - init() + public init() { /* setup usd plugins & resources. */ Pixar.Bundler.shared.setup(.resources) @@ -69,82 +64,37 @@ struct Kraken: App PyBundler.shared.pyInit() PyBundler.shared.pyInfo() - /* -------------------------------------------------------- */ - - /* validate usd filepath. */ - StageManager.shared.validate(atPath: Kraken.filePath) - - /* -------------------------------------------------------- */ - - /* create a new stage. */ - _stage = State(initialValue: Usd.Stage.createNew(Kraken.filePath)) - - /* add basic scene data. */ - UsdGeom.Xform.define(stage, path: "/Hello") - UsdGeom.Sphere.define(stage, path: "/Hello/World") - - /* set the stage metadata & save. */ - stage.getPseudoRoot().set(doc: "Example Scene | Kraken v\(Kraken.version)") - stage.save() - - /* -------------------------------------------------------- */ - - /* bind the usd file contents. */ - _usdFile = State(initialValue: (try? String(contentsOfFile: Kraken.filePath)) ?? "") - - /* -------------------------------------------------------- */ - - /* hello metaverse. */ - UsdStage("Kraken", ext: .usda) - { - // 👋. - UsdPrim("Hello", type: .xform) - { - // 🌌. - UsdPrim("Metaverse", type: .xform) - { - // 🦑. - UsdPrim("Kraken", type: .cylinder) - } - } - } - .set(doc: "Kraken v\(Kraken.version) | PixarUSD v\(Pixar.version)") - .save() - Msg.logger.log(level: .info, "\("Kraken".magenta) \("v".yellow)\(Kraken.version.yellow) | \("PixarUSD".magenta) \("v".yellow)\(Pixar.version.yellow)") Msg.logger.log(level: .info, "Kraken launched.") } /* --- xxx --- */ - var body: some Scene + public var body: some SwiftUI.Scene { - MicaWindow(title: "Kraken", id: "kraken") - { - if showSplash + DocumentGroup(newDocument: Kraken.IO.USD()) + { stage in + HStack { - SplashScreen( - image: "Splash", - logo: "wabi.hexagon.fill", - title: "The Metaversal Creation Suite", - showSplash: $showSplash + Kraken.UI.CodeEditor( + document: stage.$document, + fileURL: stage.fileURL ) - } - else - { - CodeEditor(text: $usdFile) - .onChange(of: usdFile) - { - /* on usd file changes, update the stage in real time. */ - StageManager.shared.save( - contentsOfFile: usdFile, - atPath: Kraken.filePath, - stage: &stage - ) - } + + if let scene = stage.fileURL + { + SceneView( + scene: try? SCNScene(url: scene), + options: [.allowsCameraControl, .autoenablesDefaultLighting] + ) + } + else + { + Text("Create or open a USD file.") + } } } } -} -/* --- xxx --- */ + /* --- xxx --- */ +} diff --git a/Sources/Kraken/UI/Editors/KUI.CodeEditor.swift b/Sources/Kraken/UI/Editors/KUI.CodeEditor.swift new file mode 100644 index 00000000..5e0fbe37 --- /dev/null +++ b/Sources/Kraken/UI/Editors/KUI.CodeEditor.swift @@ -0,0 +1,105 @@ +/* -------------------------------------------------------------- + * :: : K R A K E N : :: + * -------------------------------------------------------------- + * @wabistudios :: metaverse :: kraken + * + * This program is free software; you can redistribute it, and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out + * the GNU General Public License for more details. + * + * You should have received a copy for this software license, the + * GNU General Public License along with this program; or, if not + * write to the Free Software Foundation, Inc., to the address of + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright (C) 2023 Wabi Foundation. + * All Rights Reserved. + * -------------------------------------------------------------- + * . x x x . o o o . x x x . : : : . o x o . : : : . + * -------------------------------------------------------------- */ + +import CodeLanguages +import CosmoEditor +import Foundation +import PixarUSD +import SwiftUI + +public extension Kraken.UI +{ + struct CodeEditor: View + { + /** The document contents to edit. */ + @Binding var document: Kraken.IO.USD + + /** The usd file path. */ + var filePath: String + + /** The stage identified by this file. */ + @State private var stage: UsdStageRefPtr + + /** Whether the document is in binary format. */ + @State private var isBinary: Bool + + /** + * Creates a new code editor and stage for the provided document, + * if the file URL is nil or invalid, a new stage will be created. + * - Parameters: + * - document: The document to edit. + * - fileURL: The file URL to edit. */ + public init(document: Binding, fileURL: URL?) + { + /* set the document. */ + _document = document + + /* validate usd filepath. */ + filePath = Kraken.IO.Stage.manager.validate(url: fileURL) + + /* open an existing usd stage. */ + _stage = State(initialValue: Usd.Stage.open(filePath)) + + /* check if the file is binary. */ + isBinary = fileURL?.pathExtension != "usda" + } + + /* -------------------------------------------------------- */ + + @State private var language: Editor.Code.Language = .default + @State private var theme: Editor.Code.Theme = .standard + @State private var font: NSFont = .monospacedSystemFont(ofSize: 12, weight: .regular) + @AppStorage("wrapLines") private var wrapLines: Bool = true + @State private var cursorPositions: [CursorPosition] = [] + + public var body: some View + { + if !isBinary + { + Editor.Code.Cosmo( + $document.text, + language: language, + theme: theme, + font: font, + tabWidth: 2, + indentOption: .spaces(count: 2), + lineHeight: 1.2, + wrapLines: wrapLines, + cursorPositions: $cursorPositions + ) + .onChange(of: document.text) + { + /* live visual reloading of stage changes. */ + // Kraken.IO.Stage.manager.save( + // contentsOfFile: document.text, + // atPath: filePath, + // stage: &stage + // ) + } + } + } + } +} diff --git a/Sources/Kraken/UI/KUI.swift b/Sources/Kraken/UI/KUI.swift new file mode 100644 index 00000000..65da92b8 --- /dev/null +++ b/Sources/Kraken/UI/KUI.swift @@ -0,0 +1,31 @@ +/* -------------------------------------------------------------- + * :: : K R A K E N : :: + * -------------------------------------------------------------- + * @wabistudios :: metaverse :: kraken + * + * This program is free software; you can redistribute it, and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out + * the GNU General Public License for more details. + * + * You should have received a copy for this software license, the + * GNU General Public License along with this program; or, if not + * write to the Free Software Foundation, Inc., to the address of + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright (C) 2023 Wabi Foundation. + * All Rights Reserved. + * -------------------------------------------------------------- + * . x x x . o o o . x x x . : : : . o x o . : : : . + * -------------------------------------------------------------- */ + +public extension Kraken +{ + enum UI + {} +} diff --git a/Sources/Kraken/UI/Materials/KUI.MicaMaterial.swift b/Sources/Kraken/UI/Materials/KUI.MicaMaterial.swift new file mode 100644 index 00000000..6fa269c3 --- /dev/null +++ b/Sources/Kraken/UI/Materials/KUI.MicaMaterial.swift @@ -0,0 +1,58 @@ +/* -------------------------------------------------------------- + * :: : K R A K E N : :: + * -------------------------------------------------------------- + * @wabistudios :: metaverse :: kraken + * + * This program is free software; you can redistribute it, and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out + * the GNU General Public License for more details. + * + * You should have received a copy for this software license, the + * GNU General Public License along with this program; or, if not + * write to the Free Software Foundation, Inc., to the address of + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright (C) 2023 Wabi Foundation. + * All Rights Reserved. + * -------------------------------------------------------------- + * . x x x . o o o . x x x . : : : . o x o . : : : . + * -------------------------------------------------------------- */ + +import SwiftUI + +public extension Kraken.UI +{ + /** + * # Mica Material + * + * Mica material is a subtle tinted + * background, depending on the backdrop. + * + * Mica adds a subtle blur effect, to + * make the window appear to be floating + * above the backdrop. + */ + struct MicaMaterial: NSViewRepresentable + { + public let material: NSVisualEffectView.Material + + public func makeNSView(context _: Context) -> NSVisualEffectView + { + let visualEffectView = NSVisualEffectView() + visualEffectView.material = material + visualEffectView.state = NSVisualEffectView.State.active + return visualEffectView + } + + public func updateNSView(_ visualEffectView: NSVisualEffectView, context _: Context) + { + visualEffectView.material = material + } + } +} diff --git a/Sources/Kraken/UI/Menus/KUI.IntroMenu.swift b/Sources/Kraken/UI/Menus/KUI.IntroMenu.swift new file mode 100644 index 00000000..0c61cc56 --- /dev/null +++ b/Sources/Kraken/UI/Menus/KUI.IntroMenu.swift @@ -0,0 +1,112 @@ +/* -------------------------------------------------------------- + * :: : K R A K E N : :: + * -------------------------------------------------------------- + * @wabistudios :: metaverse :: kraken + * + * This program is free software; you can redistribute it, and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out + * the GNU General Public License for more details. + * + * You should have received a copy for this software license, the + * GNU General Public License along with this program; or, if not + * write to the Free Software Foundation, Inc., to the address of + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright (C) 2023 Wabi Foundation. + * All Rights Reserved. + * -------------------------------------------------------------- + * . x x x . o o o . x x x . : : : . o x o . : : : . + * -------------------------------------------------------------- */ + +import SwiftUI + +public extension Kraken.UI +{ + struct IntroMenu: View + { + @Binding public var showSplash: Bool + + public var body: some View + { + VStack + { + Button + { + showSplash = false + } + label: + { + HStack + { + Image(systemName: "globe.americas.fill") + #if !os(Linux) + .aspectRatio(contentMode: .fill) + .foregroundStyle(.green.opacity(0.8)) + .font(.system(size: 16)) + #endif /* !os(Linux) */ + .padding(2) + .background(RoundedRectangle(cornerRadius: 8, style: .continuous).fill(.blue.opacity(0.2))) + .frame(width: 85, alignment: .trailing) + + Spacer() + + Text("New Project") + #if !os(Linux) + .fontWeight(.bold) + #endif /* !os(Linux) */ + .foregroundStyle(.secondary) + .frame(width: 165, alignment: .leading) + } + .frame(width: 250, alignment: .center) + .padding() + .background(RoundedRectangle(cornerRadius: 12, style: .continuous).fill(.quaternary)) + } + #if !os(Linux) + .buttonStyle(PlainButtonStyle()) + #endif + + Button + {} + label: + { + HStack + { + Image(systemName: "network") + #if !os(Linux) + .aspectRatio(contentMode: .fill) + #endif /* !os(Linux) */ + .foregroundStyle(.purple.opacity(0.8)) + .font(.system(size: 16)) + .padding(2) + .background(RoundedRectangle(cornerRadius: 8, style: .continuous).fill(.purple.opacity(0.2))) + .frame(width: 85, alignment: .trailing) + + Spacer() + + Text("Metaverse Portal") + #if !os(Linux) + .fontWeight(.bold) + #endif /* !os(Linux) */ + .foregroundStyle(.secondary) + .frame(width: 165, alignment: .leading) + } + .frame(width: 250, alignment: .center) + .padding() + .background(RoundedRectangle(cornerRadius: 12, style: .continuous).fill(.quaternary)) + } + #if !os(Linux) + .buttonStyle(PlainButtonStyle()) + #endif /* !os(Linux) */ + .padding(.bottom, 4) + + Spacer() + } + } + } +} diff --git a/Sources/KrakenUI/Splash/SplashBadge.swift b/Sources/Kraken/UI/Splash/KUI.SplashBadge.swift similarity index 72% rename from Sources/KrakenUI/Splash/SplashBadge.swift rename to Sources/Kraken/UI/Splash/KUI.SplashBadge.swift index 20a669c7..f08b2768 100644 --- a/Sources/KrakenUI/Splash/SplashBadge.swift +++ b/Sources/Kraken/UI/Splash/KUI.SplashBadge.swift @@ -27,40 +27,38 @@ import KrakenKit import SwiftUI -/** - * A view that displays a logo badge. - */ -public struct SplashBadge: View +public extension Kraken.UI { - public init(logo: String) + /** + * A view that displays a logo badge. + */ + struct SplashBadge: View { - self.logo = logo - } - - public let logo: String + public let logo: String - public var body: some View - { - HStack + public var body: some View { - VStack + HStack { - Image(logo, bundle: .kraken) + VStack + { + Image(logo, bundle: .kraken) + #if !os(Linux) + .aspectRatio(contentMode: .fit) + .foregroundStyle(.secondary, .ultraThinMaterial) + .font(.system(size: 42)) + .padding(.top, 17) + #endif /* !os(Linux) */ + + Spacer() + } #if !os(Linux) - .aspectRatio(contentMode: .fit) - .foregroundStyle(.secondary, .ultraThinMaterial) - .font(.system(size: 42)) - .padding(.top, 17) + .frame(alignment: .leading) #endif /* !os(Linux) */ + .padding(2) Spacer() } - #if !os(Linux) - .frame(alignment: .leading) - #endif /* !os(Linux) */ - .padding(2) - - Spacer() } } } diff --git a/Sources/KrakenUI/Splash/SplashFeature.swift b/Sources/Kraken/UI/Splash/KUI.SplashFeature.swift similarity index 72% rename from Sources/KrakenUI/Splash/SplashFeature.swift rename to Sources/Kraken/UI/Splash/KUI.SplashFeature.swift index b546ecd5..6f6cc90e 100644 --- a/Sources/KrakenUI/Splash/SplashFeature.swift +++ b/Sources/Kraken/UI/Splash/KUI.SplashFeature.swift @@ -26,32 +26,29 @@ import SwiftUI -/** - * A view that displays a splash screen, - * consisting of a featured image and a - * logo badge overlay. - */ -public struct SplashFeature: View +public extension Kraken.UI { - public init(image: String, logo: String) + /** + * A view that displays a splash screen, + * consisting of a featured image and a + * logo badge overlay. + */ + struct SplashFeature: View { - self.image = image - self.logo = logo - } - - public let image: String - public let logo: String + public let image: String + public let logo: String - public var body: some View - { - SplashImage(image: image) - #if !os(Linux) - .overlay(content: - { - SplashBadge(logo: logo) - .frame(alignment: .leading) + public var body: some View + { + Kraken.UI.SplashImage(image: image) + #if !os(Linux) + .overlay(content: + { + SplashBadge(logo: logo) + .frame(alignment: .leading) - }) - #endif /* !os(Linux) */ + }) + #endif /* !os(Linux) */ + } } } diff --git a/Sources/KrakenUI/Splash/SplashImage.swift b/Sources/Kraken/UI/Splash/KUI.SplashImage.swift similarity index 79% rename from Sources/KrakenUI/Splash/SplashImage.swift rename to Sources/Kraken/UI/Splash/KUI.SplashImage.swift index d3682b66..73be327c 100644 --- a/Sources/KrakenUI/Splash/SplashImage.swift +++ b/Sources/Kraken/UI/Splash/KUI.SplashImage.swift @@ -27,25 +27,23 @@ import KrakenKit import SwiftUI -/** - * A view that displays a image - * that fills it's parent view. - */ -public struct SplashImage: View +public extension Kraken.UI { - public init(image: String) + /** + * A view that displays a image + * that fills it's parent view. + */ + struct SplashImage: View { - self.image = image - } - - public let image: String + public let image: String - public var body: some View - { - Image(image, bundle: .kraken) - #if !os(Linux) - .resizable() - .aspectRatio(contentMode: .fill) - #endif /* !os(Linux) */ + public var body: some View + { + Image(image, bundle: .kraken) + #if !os(Linux) + .resizable() + .aspectRatio(contentMode: .fill) + #endif /* !os(Linux) */ + } } } diff --git a/Sources/Kraken/UI/Splash/KUI.SplashScreen.swift b/Sources/Kraken/UI/Splash/KUI.SplashScreen.swift new file mode 100644 index 00000000..ce06d8dc --- /dev/null +++ b/Sources/Kraken/UI/Splash/KUI.SplashScreen.swift @@ -0,0 +1,65 @@ +/* -------------------------------------------------------------- + * :: : K R A K E N : :: + * -------------------------------------------------------------- + * @wabistudios :: metaverse :: kraken + * + * This program is free software; you can redistribute it, and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out + * the GNU General Public License for more details. + * + * You should have received a copy for this software license, the + * GNU General Public License along with this program; or, if not + * write to the Free Software Foundation, Inc., to the address of + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright (C) 2023 Wabi Foundation. + * All Rights Reserved. + * -------------------------------------------------------------- + * . x x x . o o o . x x x . : : : . o x o . : : : . + * -------------------------------------------------------------- */ + +import SwiftUI + +public extension Kraken.UI +{ + /** + * A view that displays a splash screen, + * consisting of a featured image, a logo + * badge overlay, a welcome title, and a + * menu stack of introductory options. + */ + struct SplashScreen: View + { + public let image: String + public let logo: String + public let title: String + + @Binding public var showSplash: Bool + + public var body: some View + { + VStack + { + Kraken.UI.SplashFeature(image: image, logo: logo) + + Kraken.UI.SplashTitle(title: title) + .padding(.top, 7) + + Kraken.UI.IntroMenu(showSplash: $showSplash) + .padding() + + Spacer() + } + .frame(width: 400, height: 400) + .background(.quaternary) + .clipShape(RoundedRectangle(cornerRadius: 12, style: .continuous)) + .padding() + } + } +} diff --git a/Sources/KrakenUI/Splash/SplashTitle.swift b/Sources/Kraken/UI/Splash/KUI.SplashTitle.swift similarity index 81% rename from Sources/KrakenUI/Splash/SplashTitle.swift rename to Sources/Kraken/UI/Splash/KUI.SplashTitle.swift index a6cf921e..586df7b5 100644 --- a/Sources/KrakenUI/Splash/SplashTitle.swift +++ b/Sources/Kraken/UI/Splash/KUI.SplashTitle.swift @@ -26,24 +26,22 @@ import SwiftUI -/** - * A view that displays a title. - */ -public struct SplashTitle: View +public extension Kraken.UI { - public init(title: String) + /** + * A view that displays a title. + */ + struct SplashTitle: View { - self.title = title - } - - public let title: String + public let title: String - public var body: some View - { - Text(title) - #if !os(Linux) - .fontWeight(.black) - .foregroundStyle(.primary) - #endif /* !os(Linux) */ + public var body: some View + { + Text(title) + #if !os(Linux) + .fontWeight(.black) + .foregroundStyle(.primary) + #endif /* !os(Linux) */ + } } } diff --git a/Sources/KrakenUI/Code/EditorTheme.swift b/Sources/Kraken/UI/Themes/KUI.CodeTheme.swift similarity index 94% rename from Sources/KrakenUI/Code/EditorTheme.swift rename to Sources/Kraken/UI/Themes/KUI.CodeTheme.swift index 9f94a225..60117718 100644 --- a/Sources/KrakenUI/Code/EditorTheme.swift +++ b/Sources/Kraken/UI/Themes/KUI.CodeTheme.swift @@ -24,14 +24,15 @@ * . x x x . o o o . x x x . : : : . o x o . : : : . * -------------------------------------------------------------- */ +import CodeLanguages import CosmoEditor import Foundation -extension EditorTheme +extension Editor.Code.Theme { - static var standard: EditorTheme + static var standard: Editor.Code.Theme { - EditorTheme( + Editor.Code.Theme( text: .init(hex: "D9D9D9"), insertionPoint: .init(hex: "D9D9D9"), invisibles: .init(hex: "424D5B"), diff --git a/Sources/KrakenUI/Splash/SplashScreen.swift b/Sources/Kraken/UI/Windows/KUI.MicaWindow.swift similarity index 58% rename from Sources/KrakenUI/Splash/SplashScreen.swift rename to Sources/Kraken/UI/Windows/KUI.MicaWindow.swift index 9d2cfabf..1e58bf68 100644 --- a/Sources/KrakenUI/Splash/SplashScreen.swift +++ b/Sources/Kraken/UI/Windows/KUI.MicaWindow.swift @@ -26,45 +26,51 @@ import SwiftUI -/** - * A view that displays a splash screen, - * consisting of a featured image, a logo - * badge overlay, a welcome title, and a - * menu stack of introductory options. - */ -public struct SplashScreen: View +public extension Kraken.UI { - public let image: String - public let logo: String - public let title: String - - @Binding public var showSplash: Bool - - public init(image: String, logo: String, title: String, showSplash: Binding) - { - self.image = image - self.logo = logo - self.title = title - _showSplash = showSplash - } - - public var body: some View + /** + * Mica windows are subtly tinted with + * the user's desktop background color, + * and have a subtle blur effect. + */ + struct MicaWindow: Scene { - VStack + public init(title: String, + id: String, + @ViewBuilder view: () -> ContentItems) { - SplashFeature(image: image, logo: logo) + self.title = title + self.id = id + self.view = view() + } - SplashTitle(title: title) - .padding(.top, 7) + public let title: String + public let id: String - IntroStack(showSplash: $showSplash) - .padding() + public var view: ContentItems + + public var body: some Scene + { + WindowGroup(title, id: id) + { + #if !os(Linux) + ZStack + { + Color.clear.ignoresSafeArea() - Spacer() + view + } + .background(Kraken.UI.MicaMaterial(material: .sidebar).ignoresSafeArea()) + #else /* os(Linux) */ + HStack + { + view + } + #endif /* !os(Linux) */ + } + #if os(macOS) + .windowStyle(.hiddenTitleBar) + #endif /* os(macOS) */ } - .frame(width: 400, height: 400) - .background(.quaternary) - .clipShape(RoundedRectangle(cornerRadius: 12, style: .continuous)) - .padding() } } diff --git a/Sources/KrakenKit/Bundle.swift b/Sources/KrakenKit/KITBundle.swift similarity index 100% rename from Sources/KrakenKit/Bundle.swift rename to Sources/KrakenKit/KITBundle.swift diff --git a/Sources/KrakenLib/StrContainer.swift b/Sources/KrakenLib/KIBStringify.swift similarity index 100% rename from Sources/KrakenLib/StrContainer.swift rename to Sources/KrakenLib/KIBStringify.swift diff --git a/Sources/KrakenLib/StageManager.swift b/Sources/KrakenLib/StageManager.swift deleted file mode 100644 index 81b9f93b..00000000 --- a/Sources/KrakenLib/StageManager.swift +++ /dev/null @@ -1,107 +0,0 @@ -/* -------------------------------------------------------------- - * :: : K R A K E N : :: - * -------------------------------------------------------------- - * @wabistudios :: metaverse :: kraken - * - * This program is free software; you can redistribute it, and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out - * the GNU General Public License for more details. - * - * You should have received a copy for this software license, the - * GNU General Public License along with this program; or, if not - * write to the Free Software Foundation, Inc., to the address of - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright (C) 2023 Wabi Foundation. - * All Rights Reserved. - * -------------------------------------------------------------- - * . x x x . o o o . x x x . : : : . o x o . : : : . - * -------------------------------------------------------------- */ - -import CxxStdlib -import Foundation -import PixarUSD - -/** - * A manager for validating and managing the - * stage files used by Kraken for USD operations. */ -public struct StageManager -{ - /** The shared instance of the stage manager singleton. */ - public static let shared = StageManager() - - private init() - {} - - /** The underlying file manager for file ops. */ - private let fileManager = FileManager.default - - /** - * Validates the usd file at the given path. - * - * Creates a new file if it does not exist. - * If the file is not readable or writable, - * it will be removed and recreated with the - * correct file permissions. - * - * - Parameter file: The usd filepath to validate. */ - public func validate(atPath file: String) - { - guard fileManager.fileExists(atPath: file), - fileManager.isReadableFile(atPath: file), - fileManager.isWritableFile(atPath: file) - else - { - try? fileManager.removeItem(atPath: file) - - fileManager.createFile( - atPath: file, - contents: (try? String( - contentsOfFile: file - ).data(using: .utf8)) ?? "".data(using: .utf8), - attributes: [.posixPermissions: 0o777] - ) - - return - } - } - - /** - * Saves (.usda) file contents and syncs modifications - * to the stage in real time. - * - * When this method is called, it will validate - * the file at the given path, write the stage data - * to the file, and then reload the stage in real - * time to ensure the changes are reflected. - * - * - Parameters: - * - stageData: The stage data to save to the file. - * - file: The usd filepath to save the data to. - * - stage: The stage to save and reload. */ - public func save(contentsOfFile stageData: String, atPath file: String, stage: inout UsdStageRefPtr) - { - validate(atPath: file) - - let path = URL(fileURLWithPath: file) - - do - { - try stageData.write(to: path, atomically: true, encoding: .utf8) - } - catch - { - print("Error writing to file: \(path.absoluteString)") - } - - stage.pointee.Reload() - - stage.save() - } -} diff --git a/Sources/KrakenUI/Materials/Mica.swift b/Sources/KrakenUI/Materials/Mica.swift deleted file mode 100644 index b895da2e..00000000 --- a/Sources/KrakenUI/Materials/Mica.swift +++ /dev/null @@ -1,129 +0,0 @@ -/* -------------------------------------------------------------- - * :: : K R A K E N : :: - * -------------------------------------------------------------- - * @wabistudios :: metaverse :: kraken - * - * This program is free software; you can redistribute it, and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out - * the GNU General Public License for more details. - * - * You should have received a copy for this software license, the - * GNU General Public License along with this program; or, if not - * write to the Free Software Foundation, Inc., to the address of - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright (C) 2023 Wabi Foundation. - * All Rights Reserved. - * -------------------------------------------------------------- - * . x x x . o o o . x x x . : : : . o x o . : : : . - * -------------------------------------------------------------- */ - -import SwiftUI - -#if os(macOS) - /** - * # Mica Material - * - * Mica material is a subtle tinted - * background, depending on the backdrop. - * - * Mica adds a subtle blur effect, to - * make the window appear to be floating - * above the backdrop. - */ - public struct MicaMaterial: NSViewRepresentable - { - public let material: NSVisualEffectView.Material - - public func makeNSView(context _: Context) -> NSVisualEffectView - { - let visualEffectView = NSVisualEffectView() - visualEffectView.material = material - visualEffectView.state = NSVisualEffectView.State.active - return visualEffectView - } - - public func updateNSView(_ visualEffectView: NSVisualEffectView, context _: Context) - { - visualEffectView.material = material - } - } -#else /* !os(macOS) */ - /** - * # Background Style - * - * Does nothing on platforms that do not - * import SwiftUI, and is provided to be - * compatible with platforms that use SwiftUI */ - public struct BackgroundStyle - { - public init() - {} - } - - /** - * # Rounded Rectangle - * - * Does nothing on platforms that do not - * import SwiftUI, and is provided to be - * compatible with platforms that use SwiftUI */ - public struct RoundedRectangle: Shape - { - public func path(in _: CGRect) -> Path - { - Path() - } - - public enum Style - { - case continuous - } - - public init(cornerRadius _: CGFloat, style _: Style) - {} - - public var body: some View - { - EmptyView() - } - } - - public extension Image - { - init(_ name: String, bundle: Bundle?) - { - guard let bundle - else { self.init(name) } - - self.init("\(bundle.resourcePath)/Assets/\(name)") - } - } - - /** - * # Mica Material - * - * Does nothing on platforms that are not macOS, - * and is provided to be compatible with the macOS - * material API without having to use the if #available - * syntax to workaround it. */ - public struct MicaMaterial - { - public enum MaterialTypes - { - case sidebar - } - - public let material: MaterialTypes - - public func ignoresSafeArea() -> BackgroundStyle - { - BackgroundStyle() - } - } -#endif /* os(macOS) */ diff --git a/Sources/KrakenUI/Menus/IntroStack.swift b/Sources/KrakenUI/Menus/IntroStack.swift deleted file mode 100644 index a469ed82..00000000 --- a/Sources/KrakenUI/Menus/IntroStack.swift +++ /dev/null @@ -1,114 +0,0 @@ -/* -------------------------------------------------------------- - * :: : K R A K E N : :: - * -------------------------------------------------------------- - * @wabistudios :: metaverse :: kraken - * - * This program is free software; you can redistribute it, and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out - * the GNU General Public License for more details. - * - * You should have received a copy for this software license, the - * GNU General Public License along with this program; or, if not - * write to the Free Software Foundation, Inc., to the address of - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright (C) 2023 Wabi Foundation. - * All Rights Reserved. - * -------------------------------------------------------------- - * . x x x . o o o . x x x . : : : . o x o . : : : . - * -------------------------------------------------------------- */ - -import SwiftUI - -public struct IntroStack: View -{ - @Binding public var showSplash: Bool - - public init(showSplash: Binding) - { - _showSplash = showSplash - } - - public var body: some View - { - VStack - { - Button - { - showSplash.toggle() - } - label: - { - HStack - { - Image(systemName: "globe.americas.fill") - #if !os(Linux) - .aspectRatio(contentMode: .fill) - .foregroundStyle(.green.opacity(0.8)) - .font(.system(size: 16)) - #endif /* !os(Linux) */ - .padding(2) - .background(RoundedRectangle(cornerRadius: 8, style: .continuous).fill(.blue.opacity(0.2))) - .frame(width: 85, alignment: .trailing) - - Spacer() - - Text("New Project") - #if !os(Linux) - .fontWeight(.bold) - #endif /* !os(Linux) */ - .foregroundStyle(.secondary) - .frame(width: 165, alignment: .leading) - } - .frame(width: 250, alignment: .center) - .padding() - .background(RoundedRectangle(cornerRadius: 12, style: .continuous).fill(.quaternary)) - } - #if !os(Linux) - .buttonStyle(PlainButtonStyle()) - #endif - - Button - {} - label: - { - HStack - { - Image(systemName: "network") - #if !os(Linux) - .aspectRatio(contentMode: .fill) - #endif /* !os(Linux) */ - .foregroundStyle(.purple.opacity(0.8)) - .font(.system(size: 16)) - .padding(2) - .background(RoundedRectangle(cornerRadius: 8, style: .continuous).fill(.purple.opacity(0.2))) - .frame(width: 85, alignment: .trailing) - - Spacer() - - Text("Metaverse Portal") - #if !os(Linux) - .fontWeight(.bold) - #endif /* !os(Linux) */ - .foregroundStyle(.secondary) - .frame(width: 165, alignment: .leading) - } - .frame(width: 250, alignment: .center) - .padding() - .background(RoundedRectangle(cornerRadius: 12, style: .continuous).fill(.quaternary)) - } - #if !os(Linux) - .buttonStyle(PlainButtonStyle()) - #endif /* !os(Linux) */ - .padding(.bottom, 4) - - Spacer() - } - } -} diff --git a/Sources/KrakenUI/Windows/MicaWindow.swift b/Sources/KrakenUI/Windows/MicaWindow.swift deleted file mode 100644 index eb683048..00000000 --- a/Sources/KrakenUI/Windows/MicaWindow.swift +++ /dev/null @@ -1,73 +0,0 @@ -/* -------------------------------------------------------------- - * :: : K R A K E N : :: - * -------------------------------------------------------------- - * @wabistudios :: metaverse :: kraken - * - * This program is free software; you can redistribute it, and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out - * the GNU General Public License for more details. - * - * You should have received a copy for this software license, the - * GNU General Public License along with this program; or, if not - * write to the Free Software Foundation, Inc., to the address of - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright (C) 2023 Wabi Foundation. - * All Rights Reserved. - * -------------------------------------------------------------- - * . x x x . o o o . x x x . : : : . o x o . : : : . - * -------------------------------------------------------------- */ - -import SwiftUI - -/** - * Mica windows are subtly tinted with - * the user's desktop background color, - * and have a subtle blur effect. - */ -public struct MicaWindow: Scene -{ - public init(title: String, - id: String, - @ViewBuilder view: () -> ContentItems) - { - self.title = title - self.id = id - self.view = view() - } - - public let title: String - public let id: String - - public var view: ContentItems - - public var body: some Scene - { - WindowGroup(title, id: id) - { - #if !os(Linux) - ZStack - { - Color.clear.ignoresSafeArea() - - view - } - .background(MicaMaterial(material: .sidebar).ignoresSafeArea()) - #else /* os(Linux) */ - HStack - { - view - } - #endif /* !os(Linux) */ - } - #if os(macOS) - .windowStyle(.hiddenTitleBar) - #endif /* os(macOS) */ - } -} diff --git a/Tests/Editors/Code/CosmoLanguagesTests/CosmoLanguagesTests.swift b/Tests/Editors/Code/CodeLanguagesTests.swift similarity index 81% rename from Tests/Editors/Code/CosmoLanguagesTests/CosmoLanguagesTests.swift rename to Tests/Editors/Code/CodeLanguagesTests.swift index 25d51d65..f09ab9db 100644 --- a/Tests/Editors/Code/CosmoLanguagesTests/CosmoLanguagesTests.swift +++ b/Tests/Editors/Code/CodeLanguagesTests.swift @@ -26,9 +26,9 @@ import SwiftTreeSitter import XCTest -@testable import CosmoLanguages +@testable import CodeLanguages -final class CosmoLanguagesTests: XCTestCase +final class CodeLanguagesTests: XCTestCase { let bundleURL = Bundle.module.resourceURL @@ -37,7 +37,7 @@ final class CosmoLanguagesTests: XCTestCase func test_CodeLanguageC() throws { let url = URL(fileURLWithPath: "~/path/to/file.c") - let language = CodeLanguage.detectLanguageFrom(url: url) + let language = Editor.Code.Language.detectLanguageFrom(url: url) XCTAssertEqual(language.id, .c) } @@ -45,14 +45,14 @@ final class CosmoLanguagesTests: XCTestCase func test_CodeLanguageC2() throws { let url = URL(fileURLWithPath: "~/path/to/file.h") - let language = CodeLanguage.detectLanguageFrom(url: url) + let language = Editor.Code.Language.detectLanguageFrom(url: url) XCTAssertEqual(language.id, .c) } func test_FetchQueryC() throws { - var language = CodeLanguage.c + var language = Editor.Code.Language.c language.resourceURL = bundleURL let data = try Data(contentsOf: language.queryURL!) @@ -66,7 +66,7 @@ final class CosmoLanguagesTests: XCTestCase func test_CodeLanguageCPP() throws { let url = URL(fileURLWithPath: "~/path/to/file.cc") - let language = CodeLanguage.detectLanguageFrom(url: url) + let language = Editor.Code.Language.detectLanguageFrom(url: url) XCTAssertEqual(language.id, .cpp) } @@ -74,7 +74,7 @@ final class CosmoLanguagesTests: XCTestCase func test_CodeLanguageCPP2() throws { let url = URL(fileURLWithPath: "~/path/to/file.cpp") - let language = CodeLanguage.detectLanguageFrom(url: url) + let language = Editor.Code.Language.detectLanguageFrom(url: url) XCTAssertEqual(language.id, .cpp) } @@ -82,14 +82,14 @@ final class CosmoLanguagesTests: XCTestCase func test_CodeLanguageCPP3() throws { let url = URL(fileURLWithPath: "~/path/to/file.hpp") - let language = CodeLanguage.detectLanguageFrom(url: url) + let language = Editor.Code.Language.detectLanguageFrom(url: url) XCTAssertEqual(language.id, .cpp) } func test_FetchQueryCPP() throws { - var language = CodeLanguage.cpp + var language = Editor.Code.Language.cpp language.resourceURL = bundleURL let data = try Data(contentsOf: language.queryURL!) @@ -103,14 +103,14 @@ final class CosmoLanguagesTests: XCTestCase func test_CodeLanguageJSON() throws { let url = URL(fileURLWithPath: "~/path/to/file.json") - let language = CodeLanguage.detectLanguageFrom(url: url) + let language = Editor.Code.Language.detectLanguageFrom(url: url) XCTAssertEqual(language.id, .json) } func test_FetchQueryJSON() throws { - var language = CodeLanguage.json + var language = Editor.Code.Language.json language.resourceURL = bundleURL let data = try Data(contentsOf: language.queryURL!) @@ -124,14 +124,14 @@ final class CosmoLanguagesTests: XCTestCase func test_CodeLanguagePython() throws { let url = URL(fileURLWithPath: "~/path/to/file.py") - let language = CodeLanguage.detectLanguageFrom(url: url) + let language = Editor.Code.Language.detectLanguageFrom(url: url) XCTAssertEqual(language.id, .python) } func test_FetchQueryPython() throws { - var language = CodeLanguage.python + var language = Editor.Code.Language.python language.resourceURL = bundleURL let data = try Data(contentsOf: language.queryURL!) @@ -145,14 +145,14 @@ final class CosmoLanguagesTests: XCTestCase func test_CodeLanguageRust() throws { let url = URL(fileURLWithPath: "~/path/to/file.rs") - let language = CodeLanguage.detectLanguageFrom(url: url) + let language = Editor.Code.Language.detectLanguageFrom(url: url) XCTAssertEqual(language.id, .rust) } func test_FetchQueryRust() throws { - var language = CodeLanguage.rust + var language = Editor.Code.Language.rust language.resourceURL = bundleURL let data = try Data(contentsOf: language.queryURL!) @@ -166,14 +166,14 @@ final class CosmoLanguagesTests: XCTestCase func test_CodeLanguageSwift() throws { let url = URL(fileURLWithPath: "~/path/to/file.swift") - let language = CodeLanguage.detectLanguageFrom(url: url) + let language = Editor.Code.Language.detectLanguageFrom(url: url) XCTAssertEqual(language.id, .swift) } func test_FetchQuerySwift() throws { - var language = CodeLanguage.swift + var language = Editor.Code.Language.swift language.resourceURL = bundleURL let data = try Data(contentsOf: language.queryURL!) @@ -187,14 +187,14 @@ final class CosmoLanguagesTests: XCTestCase func test_CodeLanguageTOML() throws { let url = URL(fileURLWithPath: "~/path/to/file.toml") - let language = CodeLanguage.detectLanguageFrom(url: url) + let language = Editor.Code.Language.detectLanguageFrom(url: url) XCTAssertEqual(language.id, .toml) } func test_FetchQueryTOML() throws { - var language = CodeLanguage.toml + var language = Editor.Code.Language.toml language.resourceURL = bundleURL let data = try Data(contentsOf: language.queryURL!) @@ -208,14 +208,14 @@ final class CosmoLanguagesTests: XCTestCase func test_CodeLanguageUSD() throws { let url = URL(fileURLWithPath: "~/path/to/file.usda") - let language = CodeLanguage.detectLanguageFrom(url: url) + let language = Editor.Code.Language.detectLanguageFrom(url: url) XCTAssertEqual(language.id, .usd) } func test_FetchQueryUSD() throws { - var language = CodeLanguage.usd + var language = Editor.Code.Language.usd language.resourceURL = bundleURL let data = try Data(contentsOf: language.queryURL!) @@ -229,7 +229,7 @@ final class CosmoLanguagesTests: XCTestCase func test_CodeLanguageUnsupported() throws { let url = URL(fileURLWithPath: "~/path/to/file.abc") - let language = CodeLanguage.detectLanguageFrom(url: url) + let language = Editor.Code.Language.detectLanguageFrom(url: url) XCTAssertEqual(language.id, .plainText) } @@ -237,7 +237,7 @@ final class CosmoLanguagesTests: XCTestCase func test_CodeLanguageUnsupportedNoExtension() throws { let url = URL(fileURLWithPath: "~/path/to/file") - let language = CodeLanguage.detectLanguageFrom(url: url) + let language = Editor.Code.Language.detectLanguageFrom(url: url) XCTAssertEqual(language.id, .plainText) } diff --git a/Tests/Editors/Code/CosmoLanguagesTests/LanguageDetectionTests.swift b/Tests/Editors/Code/LanguageDetectionTests.swift similarity index 82% rename from Tests/Editors/Code/CosmoLanguagesTests/LanguageDetectionTests.swift rename to Tests/Editors/Code/LanguageDetectionTests.swift index 4c960996..d7245bf7 100644 --- a/Tests/Editors/Code/CosmoLanguagesTests/LanguageDetectionTests.swift +++ b/Tests/Editors/Code/LanguageDetectionTests.swift @@ -26,7 +26,7 @@ import RegexBuilder import XCTest -@testable import CosmoLanguages +@testable import CodeLanguages // swiftlint:disable all final class LanguageDetectionTests: XCTestCase @@ -44,7 +44,7 @@ final class LanguageDetectionTests: XCTestCase let invalidCases = [ "1234", - "import CosmoLanguages", + "import CodeLanguages", "", "\n", "# This is a regular comment", @@ -55,7 +55,7 @@ final class LanguageDetectionTests: XCTestCase for validCase in validCases { - let detectedLanguage = CodeLanguage.detectLanguageFrom(url: URL(filePath: ""), prefixBuffer: validCase) + let detectedLanguage = Editor.Code.Language.detectLanguageFrom(url: URL(filePath: ""), prefixBuffer: validCase) XCTAssert( detectedLanguage == .swift, "Parser failed to find valid shebang language. Given \"\(validCase)\", found \(detectedLanguage), expected swift." @@ -64,7 +64,7 @@ final class LanguageDetectionTests: XCTestCase for invalidCase in invalidCases { - let detectedLanguage = CodeLanguage.detectLanguageFrom(url: URL(filePath: ""), prefixBuffer: invalidCase) + let detectedLanguage = Editor.Code.Language.detectLanguageFrom(url: URL(filePath: ""), prefixBuffer: invalidCase) XCTAssert( detectedLanguage == .default, "Parser unexpectedly found valid shebang language. Given \"\(invalidCase)\", found \(detectedLanguage), expected default." @@ -89,14 +89,14 @@ final class LanguageDetectionTests: XCTestCase "/* vim", "/* this is also a normal comment */", "1234", - "import CosmoLanguages", + "import CodeLanguages", "", "\n", ] for validCase in validCases { - let detectedLanguage = CodeLanguage.detectLanguageFrom(url: URL(filePath: ""), prefixBuffer: validCase) + let detectedLanguage = Editor.Code.Language.detectLanguageFrom(url: URL(filePath: ""), prefixBuffer: validCase) XCTAssert( detectedLanguage == .swift, "Parser failed to find valid shebang language. Given \"\(validCase)\", found \(detectedLanguage), expected swift." @@ -105,7 +105,7 @@ final class LanguageDetectionTests: XCTestCase for invalidCase in invalidCases { - let detectedLanguage = CodeLanguage.detectLanguageFrom(url: URL(filePath: ""), prefixBuffer: invalidCase) + let detectedLanguage = Editor.Code.Language.detectLanguageFrom(url: URL(filePath: ""), prefixBuffer: invalidCase) XCTAssert( detectedLanguage == .default, "Parser unexpectedly found valid shebang language. Given \"\(invalidCase)\", found \(detectedLanguage), expected default." @@ -123,7 +123,7 @@ final class LanguageDetectionTests: XCTestCase let invalidCases = [ "1234", - "import CosmoLanguages", + "import CodeLanguages", "", "\n", "-*-", @@ -134,7 +134,7 @@ final class LanguageDetectionTests: XCTestCase for validCase in validCases { - let detectedLanguage = CodeLanguage.detectLanguageFrom(url: URL(filePath: ""), prefixBuffer: validCase) + let detectedLanguage = Editor.Code.Language.detectLanguageFrom(url: URL(filePath: ""), prefixBuffer: validCase) XCTAssert( detectedLanguage == .swift, "Parser failed to find valid shebang language. Given \"\(validCase)\", found \(detectedLanguage), expected swift." @@ -143,7 +143,7 @@ final class LanguageDetectionTests: XCTestCase for invalidCase in invalidCases { - let detectedLanguage = CodeLanguage.detectLanguageFrom(url: URL(filePath: ""), prefixBuffer: invalidCase) + let detectedLanguage = Editor.Code.Language.detectLanguageFrom(url: URL(filePath: ""), prefixBuffer: invalidCase) XCTAssert( detectedLanguage == .default, "Parser unexpectedly found valid shebang language. Given \"\(invalidCase)\", found \(detectedLanguage), expected default."