Skip to content

feat: add an optional plugins module - #1222

Open
Niox1337 wants to merge 43 commits into
DEEIX-AI:devfrom
Niox1337:feat/1086-plugins
Open

Niox1337 wants to merge 43 commits into
DEEIX-AI:devfrom
Niox1337:feat/1086-plugins

Conversation

@Niox1337

@Niox1337 Niox1337 commented Dec 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #96
Fixes #1221

Part of #1086.

Builds on #933 (limn highlighting and runtime language definitions), so it should be merged after that PR. Until then the diff also shows the commits of #933.

Adds the first stage of #1086: declarative plugins. A plugin is a folder with a plugin.json manifest and the files it refers to. Its contributions go through the same lookups as the user's own settings, so no plugin code runs inside Winc. Code plugins are tracked in #1220. This also covers snippet completions from language servers (#1205).

Plugins are a new module under Settings > Modules, off by default. With the module off Winc never reads, lists or watches the plugin folder, and no contribution tables exist.

Documentation

What plugins can do and how they behave is described in the plugin documentation (Simplified Chinese), which follows this branch: https://niox1337.github.io/winc-plugin-docs/

Implementation notes

  • Manifests, highlighting rules, snippet files and button icons are read and watched off the UI thread. Each window with plugin rules owns one limn registry, and rules compile on a background worker the first time a document needs tokens.
  • The snippet engine lives in winc-editor and covers the LSP and VS Code snippet grammar. The LSP client now advertises snippetSupport, so snippet completions from language servers use the same engine.
  • Plugin programs are found with an exact lookup. On Windows a name without an extension means <name>.exe instead of the PATHEXT list, PowerShell runs the resolved path with &, and the remote server gained which-exact for Windows hosts. Values are quoted for the shell that runs the command, and a value that cannot be passed safely refuses to run.
  • Git installs reuse the clone dialog and runner with protocol.allow=never, https only, shallow and without submodules or LFS. The community list is fetched only when its page opens, limited to 2 MiB and 15 seconds.
  • Approvals and consent are stored in state.json per plugin version and permission list. Remembered input values are stored there per project. Global plugin settings stay in config.json.

Cost

With the module off nothing is read, listed, fetched or watched. Each contribution is one map lookup at the place where the built in feature already looks up its setting, with no per frame work. New language metadata is interned once per definition under a 1 MiB budget. Windows without plugin rules create no registry. Plugin snippets are a sorted prefix lookup that only runs when completion would run anyway. Visible buttons are cached and recomputed only when the active document, language, selection, project or contributions change, so opening a menu or drawing a frame reads no files. No new dependencies.

Change type

  • Bug fix
  • Feature
  • Performance
  • Refactor
  • Documentation
  • Build / tooling

Verification

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo xtask test --all
  • Tested by hand on: macOS (Apple silicon)

cargo xtask bench against #933 (15c6e8b) with the module off, run as base, branch, branch, base on the same machine:

base 1 branch 1 branch 2 base 2
Startup median, large.rs 155.6 ms 161.8 ms 158.1 ms 158.4 ms
Startup median, huge.txt 124.8 ms 129.1 ms 121.6 ms 119.6 ms
Startup median, huge.rs 134.5 ms 126.1 ms 128.2 ms 127.7 ms
Typing to frame p50 / p95, large.rs 0.52 / 0.8 ms 0.51 / 0.6 ms 0.51 / 0.7 ms 0.51 / 0.8 ms
Scroll p95, large.rs 0.7 ms 0.6 ms 0.6 ms 0.7 ms
Jump to end, large.rs 3.0 ms 2.9 ms 2.9 ms 3.8 ms
Idle memory, large.rs 28.0 MB 29.0 MB 29.0 MB 28.0 MB
Idle memory, huge.rs 26.0 MB 27.0 MB 27.0 MB 27.0 MB
Release binary 16,881,696 B 17,494,144 B (+612 KB)

The menus and buttons commit against the previous head (bf7cbe7), run the same way:

base 1 branch 1 branch 2 base 2
Startup median, large.rs 139.0 ms 137.5 ms 141.4 ms 173.6 ms
Startup median, huge.txt 101.7 ms 111.5 ms 107.6 ms 125.5 ms
Startup median, huge.rs 103.0 ms 119.1 ms 107.9 ms 121.9 ms
Typing to frame p50 / p95, large.rs 0.52 / 0.8 ms 0.45 / 1.1 ms 0.52 / 0.7 ms 0.41 / 0.6 ms
Scroll p95, large.rs 0.6 ms 0.6 ms 0.3 ms 0.4 ms
Jump to end, large.rs 3.0 ms 3.2 ms 3.1 ms 2.9 ms
Idle memory, large.rs 28.0 MB 29.0 MB 29.0 MB 29.0 MB
Idle memory, huge.rs 27.0 MB 27.0 MB 27.0 MB 27.0 MB
Release binary 17,494,144 B 17,543,872 B (+49 KB)

Screenshots

The Plugins page.

g9-plugins-page

A plugin language highlighted from its own rules.

g53-brew-highlighting

A snippet completion from a plugin.

g59-snippet-completion

Installing a plugin from a Git URL.

settings-plugins-install-menu settings-plugins-git-cloning

Community plugins and the consent dialog.

settings-plugins-community-list settings-plugins-consent-checked

Two demo plugins: a run button with an SVG icon in the tab bar for Python files, and a Maven button in the status bar because the project has a pom.xml.

m1-buttons

The editor menu with the plugin entry after a separator. Snapshot tests draw the menu inside the window, as on Linux and Windows.

m2-editor-menu

The file tree menu of pom.xml with an entry limited by fileNames.

m3-tree-menu

Checklist

  • The change is focused and does not include unrelated refactoring or formatting.
  • Tests cover the fixed bug or the new behavior.
  • New interface text is added in both English and Simplified Chinese.
  • Startup time, memory use, and large files are not made slower (run cargo xtask bench when in doubt).
  • I have read and agree to the Contributor License Agreement.

0.5.0 splits the grammars into nine features. Enable the eight that
contain the grammars Winc maps to limn. Contextual keywords such as
Java record and when, Groovy trait and Scala given are now keywords
only where the grammar allows them, so the tests check them in
declarations instead of as bare words.
limn gives JSX child text and plain identifiers the same kind, so the
capitalized type pass colored words such as Hello in element text.
Track tags, children and brace expressions from the punctuation limn
emits and skip the pass inside child text.
limn takes Nix escapes as more than one character, so "\u{" leaks a
string into the following lines. It also interpolates $${ and lets a
path swallow a following indented string. The DFA rules handle all of
these, so the tests assert every original expectation again.
limn treats %{ and %} on their own lines as line comments, so the
lines between them are colored as code. The DFA rules color the whole
block. They need the compiler's if-value action again.
Add an optional Plugins module, off by default, with a settings page that lists, installs and
removes plugins. Watch the plugins folder, apply global and project choices, and ask before
granting process permissions, which can be revoked one by one.
Apply plugin themes, file types and shortcuts for built-in actions. Use plugin formatters, fixers
and language servers after project and user settings, keeping the project before the user.
List approved plugin commands in the command palette and let shortcuts run them. Run commands in
the terminal or in the background, locally or on the connected host.
Show plugin settings on the Plugins page and store their values in the user config. Substitute
setting values and the active file and project in commands, quoted for the shell that runs them.
Register languages defined by plugins for detection, comments, indentation and the language
picker. They render as plain text and work with plugin file types, tools and language servers.
Register a local folder as a development plugin, used in place and watched for changes. It takes
the place of an installed plugin with the same id, and removing it only forgets the path.
Read plugin manifests and validate compatibility, contributions and process permissions.
Report invalid entries per item and expose the declaration types used by the plugins module.
Plugins can be installed from any https Git URL. The clone is shallow,
https only and never prompts, runs in a temporary folder inside the
plugins folder, and goes through the same checks and replace
confirmation as a folder install. The source is kept in state.json so
the plugin menu can offer an update from Git.
The manifest and each language server, formatter, fixer, command and
keybinding entry accept "platforms" with macos, linux and windows.
Tools and commands follow the system where the program runs (local,
WSL or the SSH host), keybindings follow the local system, and entries
for disjoint systems no longer conflict. A plugin that leaves out the
local system says so on its row.

On Windows a plugin program without an extension means <name>.exe.
PATH lookup, permission coverage and the shell line all use that exact
file instead of PATHEXT, so a .cmd or .bat must be named explicitly.
Programs from the user's own settings keep the PATHEXT lookup.
A plugin can declare dialogs in contributes.dialogs. A dialog shows some
of the plugin's settings and run-time inputs in separate groups, button
rows that run commands, and a footer with a fixed Close button, one
optional left button and the plugin's right buttons, the last one being
primary. Apply writes settings and project inputs and keeps the dialog
open. Command buttons apply, close the dialog and run the command.

Dialogs open from keybindings, menus and buttons through dialog:<plugin>.<id>
and from a command palette entry per dialog.
A plugin can ship locales/<tag>.json files with flat key to string maps.
Localizable manifest fields written as "%key%" resolve against the
interface language, then the same language, then en-US and en. Missing
keys keep the literal text and are reported once. Choice settings and
inputs accept optionLabels for translated option text while stored
values stay unchanged. Switching the interface language updates plugin
text right away from the loaded tables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Declarative plugins [Feature]: 请求增加不同格式文件的所属的keymap支持

1 participant