# mchakravarty/codeeditorview architecture

> Architecture diagram of the GitHub repository mchakravarty/codeeditorview, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mchakravarty/codeeditorview
- Repository: https://github.com/mchakravarty/codeeditorview

## Overview

CodeEditorView is a cross-platform SwiftUI code editor built on TextKit 2. A user supplies editable text, selection/position, messages, and a language configuration; the editor hosts the native text view, applies token highlighting and editing behavior, and presents gutter, minimap, and inline diagnostics. Language configurations provide lexical rules, while an optional language service can add semantic tokens, diagnostics, identifier information, and completions. The README documents these capabilities; sampled excerpts show core editing, highlighting, and service interactions, but not every feature’s implementation.

Main entry points: [`Sources/CodeEditorView/CodeView.swift`](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/CodeView.swift) (Native text view), [`Sources/CodeEditorView/CodeStorageDelegate.swift`](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/CodeStorageDelegate.swift) (Storage delegate), [`Sources/CodeEditorView/CodeStorage.swift`](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/CodeStorage.swift) (Text storage), [`Sources/CodeEditorView/TextView.swift`](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/TextView.swift) (Text interaction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_editor["Editor interface"]
  node_swiftui["CodeEditor<br/>[CodeEditor.swift]"]
  node_native["Native text view<br/>[CodeView.swift]"]
end

subgraph group_editing["Editing and text"]
  node_textview["Text interaction<br/>[TextView.swift]"]
  node_editingops["Editing operations<br/>[CodeEditing.swift]"]
  node_actions["Code actions<br/>[CodeActions.swift]"]
  node_storage["Text storage<br/>[CodeStorage.swift]"]
  node_delegate["Storage delegate"]
  node_linemap["Line map<br/>[LineMap.swift]"]
end

subgraph group_language["Language intelligence"]
  node_languageconfig["Language rules"]
  node_tokeniser["Tokeniser<br/>[Tokeniser.swift]"]
  node_languageimpl["Language configurations"]
  node_service["Language service API"]
  node_messages["Diagnostic messages<br/>[Message.swift]"]
end

subgraph group_presentation["Editor presentation"]
  node_gutter["Gutter<br/>[GutterView.swift]"]
  node_messageviews["Message views<br/>[MessageViews.swift]"]
  node_minimap["Minimap<br/>[MinimapView.swift]"]
  node_theme["Editor theme<br/>[Theme.swift]"]
end

node_user(("Editor user"))
node_externalservice(("Language service"))

node_user -->|"provides text"| node_swiftui
node_swiftui -->|"hosts view"| node_native
node_native -->|"configures"| node_delegate
node_native -->|"embeds"| node_minimap
node_native -->|"presents"| node_messageviews
node_native -->|"embeds"| node_gutter
node_native -->|"uses"| node_storage
node_native -->|"uses"| node_textview
node_textview -->|"queries"| node_service
node_textview -->|"uses"| node_linemap
node_textview -->|"uses"| node_storage
node_textview -->|"uses"| node_delegate
node_editingops -->|"operates on"| node_native
node_editingops -->|"uses"| node_delegate
node_actions -->|"operates on"| node_native
node_actions -->|"uses"| node_delegate
node_delegate -->|"updates"| node_storage
node_delegate -->|"updates"| node_linemap
node_delegate -->|"requests tokens"| node_service
node_delegate -->|"uses"| node_languageconfig
node_storage -->|"uses"| node_languageconfig
node_storage -->|"enumerates tokens"| node_tokeniser
node_languageconfig -->|"defines tokens"| node_tokeniser
node_languageconfig -->|"configures"| node_service
node_languageimpl -->|"provides rules"| node_languageconfig
node_service -->|"publishes diagnostics"| node_messages
node_externalservice -.->|"implements"| node_service
node_delegate -->|"collects diagnostics"| node_messages
node_messageviews -->|"renders"| node_messages
node_native -->|"uses"| node_theme
node_storage -->|"uses"| node_theme
node_gutter -->|"uses"| node_linemap
node_gutter -->|"renders"| node_messages
node_minimap -->|"tracks"| node_native

click node_swiftui "https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/CodeEditor.swift"
click node_native "https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/CodeView.swift"
click node_textview "https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/TextView.swift"
click node_editingops "https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/CodeEditing.swift"
click node_actions "https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/CodeActions.swift"
click node_storage "https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/CodeStorage.swift"
click node_delegate "https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/CodeStorageDelegate.swift"
click node_linemap "https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/LineMap.swift"
click node_languageconfig "https://github.com/mchakravarty/codeeditorview/blob/main/Sources/LanguageSupport/LanguageConfiguration.swift"
click node_tokeniser "https://github.com/mchakravarty/codeeditorview/blob/main/Sources/LanguageSupport/Tokeniser.swift"
click node_languageimpl "https://github.com/mchakravarty/codeeditorview/tree/main/Sources/LanguageSupport"
click node_service "https://github.com/mchakravarty/codeeditorview/blob/main/Sources/LanguageSupport/LanguageService.swift"
click node_messages "https://github.com/mchakravarty/codeeditorview/blob/main/Sources/LanguageSupport/Message.swift"
click node_gutter "https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/GutterView.swift"
click node_messageviews "https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/MessageViews.swift"
click node_minimap "https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/MinimapView.swift"
click node_theme "https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/Theme.swift"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_swiftui,node_native,node_user toneBlue
class node_textview,node_editingops,node_actions,node_storage,node_delegate,node_linemap toneAmber
class node_languageconfig,node_tokeniser,node_languageimpl,node_service,node_messages toneMint
class node_gutter,node_messageviews,node_minimap,node_theme toneRose
class node_externalservice toneIndigo
```

## Components

### Editor interface

- [CodeEditor](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/CodeEditor.swift): `Sources/CodeEditorView/CodeEditor.swift`
- [Native text view](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/CodeView.swift): `Sources/CodeEditorView/CodeView.swift`

### Editing and text

- [Text interaction](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/TextView.swift): `Sources/CodeEditorView/TextView.swift`
- [Editing operations](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/CodeEditing.swift): `Sources/CodeEditorView/CodeEditing.swift`
- [Code actions](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/CodeActions.swift): `Sources/CodeEditorView/CodeActions.swift`
- [Text storage](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/CodeStorage.swift): `Sources/CodeEditorView/CodeStorage.swift`
- [Storage delegate](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/CodeStorageDelegate.swift): `Sources/CodeEditorView/CodeStorageDelegate.swift`
- [Line map](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/LineMap.swift): `Sources/CodeEditorView/LineMap.swift`

### Language intelligence

- [Language rules](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/LanguageSupport/LanguageConfiguration.swift): `Sources/LanguageSupport/LanguageConfiguration.swift`
- [Tokeniser](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/LanguageSupport/Tokeniser.swift): `Sources/LanguageSupport/Tokeniser.swift`
- [Language configurations](https://github.com/mchakravarty/codeeditorview/tree/main/Sources/LanguageSupport): `Sources/LanguageSupport`
- [Language service API](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/LanguageSupport/LanguageService.swift): `Sources/LanguageSupport/LanguageService.swift`
- [Diagnostic messages](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/LanguageSupport/Message.swift): `Sources/LanguageSupport/Message.swift`

### Editor presentation

- [Gutter](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/GutterView.swift): `Sources/CodeEditorView/GutterView.swift`
- [Message views](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/MessageViews.swift): `Sources/CodeEditorView/MessageViews.swift`
- [Minimap](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/MinimapView.swift): `Sources/CodeEditorView/MinimapView.swift`
- [Editor theme](https://github.com/mchakravarty/codeeditorview/blob/main/Sources/CodeEditorView/Theme.swift): `Sources/CodeEditorView/Theme.swift`

### Other components

- **Editor user**
- **Language service**

## Connections

- Editor user → CodeEditor: provides text (evidence: `README.md`)
- CodeEditor → Native text view: hosts view (evidence: `Sources/CodeEditorView/CodeEditor.swift`)
- Native text view → Storage delegate: configures (evidence: `Sources/CodeEditorView/CodeView.swift`)
- Native text view → Minimap: embeds (evidence: `Sources/CodeEditorView/CodeView.swift`)
- Native text view → Message views: presents (evidence: `Sources/CodeEditorView/CodeView.swift`)
- Native text view → Gutter: embeds (evidence: `Sources/CodeEditorView/CodeView.swift`)
- Native text view → Text storage: uses (evidence: `Sources/CodeEditorView/CodeView.swift`)
- Native text view → Text interaction: uses (evidence: `Sources/CodeEditorView/CodeView.swift`)
- Text interaction → Language service API: queries (evidence: `Sources/CodeEditorView/TextView.swift`)
- Text interaction → Line map: uses (evidence: `Sources/CodeEditorView/TextView.swift`)
- Text interaction → Text storage: uses (evidence: `Sources/CodeEditorView/TextView.swift`)
- Text interaction → Storage delegate: uses (evidence: `Sources/CodeEditorView/TextView.swift`)
- Editing operations → Native text view: operates on (evidence: `Sources/CodeEditorView/CodeEditing.swift`)
- Editing operations → Storage delegate: uses (evidence: `Sources/CodeEditorView/CodeEditing.swift`)
- Code actions → Native text view: operates on (evidence: `Sources/CodeEditorView/CodeActions.swift`)
- Code actions → Storage delegate: uses (evidence: `Sources/CodeEditorView/CodeActions.swift`)
- Storage delegate → Text storage: updates (evidence: `Sources/CodeEditorView/CodeStorageDelegate.swift`)
- Storage delegate → Line map: updates (evidence: `Sources/CodeEditorView/CodeStorageDelegate.swift`)
- Storage delegate → Language service API: requests tokens (evidence: `Sources/CodeEditorView/CodeStorageDelegate.swift`)
- Storage delegate → Language rules: uses (evidence: `Sources/CodeEditorView/CodeStorageDelegate.swift`)
- Text storage → Language rules: uses (evidence: `Sources/CodeEditorView/CodeStorage.swift`)
- Text storage → Tokeniser: enumerates tokens (evidence: `Sources/CodeEditorView/CodeStorage.swift`)
- Language rules → Tokeniser: defines tokens (evidence: `Sources/LanguageSupport/LanguageConfiguration.swift`)
- Language rules → Language service API: configures (evidence: `Sources/LanguageSupport/LanguageConfiguration.swift`)
- Language configurations → Language rules: provides rules (evidence: `Sources/LanguageSupport/SwiftConfiguration.swift`)
- Language service API → Diagnostic messages: publishes diagnostics (evidence: `Sources/LanguageSupport/LanguageService.swift`)
- Language service → Language service API: implements
- Storage delegate → Diagnostic messages: collects diagnostics (evidence: `Sources/CodeEditorView/CodeStorageDelegate.swift`)
- Message views → Diagnostic messages: renders (evidence: `Sources/CodeEditorView/MessageViews.swift`)
- Native text view → Editor theme: uses (evidence: `Sources/CodeEditorView/CodeView.swift`)
- Text storage → Editor theme: uses (evidence: `Sources/CodeEditorView/CodeStorage.swift`)
- Gutter → Line map: uses (evidence: `Sources/CodeEditorView/GutterView.swift`)
- Gutter → Diagnostic messages: renders (evidence: `Sources/CodeEditorView/GutterView.swift`)
- Minimap → Native text view: tracks (evidence: `Sources/CodeEditorView/MinimapView.swift`)
