Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**/*.ts
**/eslint.config.mjs
**/tsconfig.json
diagrams/**
esbuild.mjs
media/**
node_modules/**
Expand Down
29 changes: 29 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Contributing

If you'd like to contribute, the best way right now is to open a bug report, suggestion, or question on [Dim GitHub Discussions](https://github.com/ufukty/dim/discussions). PRs and issues aren't being accepted from users at this stage.

## Internals

Dim's code may not be straightforward to follow, as it employs several optimization techniques that scatter and intertwine logic across files.

### Overview

The extension starts with the lifecycle controller. It is responsible for routing user events received from VS Code to the correct units. Units include the compiled user-config cache and individual editor decorators. Events include changes in the config, active and visible editors, and selections.

<picture>
<source srcset="./diagrams/structure@2x.png 2x">
<img srcset="./diagrams/structure@2x.png 2x">
</picture>
Comment on lines +13 to +16
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for future,

This "hack" works at the moment. But will cause duplicate placements once GitHub or VS Code enhance their srcset support.

This combination seems redundant but each attachment works in either VS Code Markdown Preview or GitHub Markdown Preview.

GitHub seems to allow srcset attribute only on the source tags contained inside picture elements, and VS Code only allows the attribute on the img tags.

Hardcoding the Markdown file for the diagram widths is worse, as they are very dynamic.

Both mediums ignore the other's solution.


An editor decorator instance is responsible for a single `TextEditor` instance. It holds the UI state, including the per-document toggle and the ranges decorated at the previous iteration.

### Compiled user-config cache

A Dim user-config may contain many RegExes, so compiled results are cached. The compiled config is sensitive to the scope of `TextEditor`. That's a shallow handle VS Code uses to represent a tab's session. Cache invalidation is triggered by the Extensions API event `onDidChangeConfiguration`.

<picture>
<source srcset="./diagrams/config-cache@2x.png 2x">
<img srcset="./diagrams/config-cache@2x.png 2x">
</picture>
Comment on lines +24 to +27
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.


Cache keys may shift as VS Code returns different `TextEditor` instances for the same "tab" when the user switches between them.
12 changes: 12 additions & 0 deletions diagrams/config-cache.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ishikawa-beta
Recompile user-configuration
Raw user-configuration
File
Editor
Workspace
Scope
Top-level
Language-specific
Editor scope
Document URI
Language mode
Binary file added diagrams/config-cache@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions diagrams/structure.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
block

columns 3

space:2 ConfigReader
space:3
space:2 ConfigCompiler
space:3
EditorDecorator space ConfigCache
space:3
LifecycleCtrl:3
space:3
ExtensionHost:3

ConfigCompiler--"Scope"-->ConfigReader
ConfigCache--"Scope"-->ConfigCompiler
LifecycleCtrl--"Invalidate"-->ConfigCache
LifecycleCtrl--"Event, Command"-->EditorDecorator
ExtensionHost--"Events, Commands"-->LifecycleCtrl
EditorDecorator--"Scope"-->ConfigCache
Binary file added diagrams/structure@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions diagrams/watch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

fswatch diagrams/*.mmd | while read -r FILE; do
mmdc -i "$FILE" -o "${FILE/.mmd/@2x.png}" -s 2 -t neutral;
done