Skip to content

Add configuration-based variable expansion for snippets#124

Merged
maraf merged 9 commits intomainfrom
copilot/add-snapshot-variables-support
Apr 19, 2026
Merged

Add configuration-based variable expansion for snippets#124
maraf merged 9 commits intomainfrom
copilot/add-snapshot-variables-support

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

  • Update src/Neptuo.Productivity.SnippetManager.UI/Navigator.cs — add Variables using, add VariablesConfiguration? param, create SnippetExpansionPipeline field, pass to command constructors
  • Update src/Neptuo.Productivity.SnippetManager.UI/App.xaml.cs — forward configuration.Variables to Navigator and add Variables to example config
  • Update src/Neptuo.Productivity.SnippetManager.UI/Views/DesignData/ViewModelLocator.cs — add empty pipeline, pass to commands
  • Update README.md — rephrase {{literal}} escape semantics
  • Add ApplySnippetCommandTests.cs for test parity (4 tests: CanExecute null/shadow/filled + Execute expands variables)

Copilot AI changed the title [WIP] Add variables for snippets configuration Add configuration-based variable expansion for snippets Apr 17, 2026
Copilot AI requested a review from maraf April 17, 2026 17:51
@maraf

This comment was marked as resolved.

@maraf maraf marked this pull request as ready for review April 17, 2026 18:29
@maraf maraf requested a review from Copilot April 17, 2026 18:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds configuration-driven variable expansion for snippet text at apply/copy time, integrating the feature into both WPF and Avalonia front-ends while keeping snippet search based on raw templates.

Changes:

  • Introduces a Variables configuration section plus a SnippetExpansionPipeline (scanner → resolver → expander) for {Name} placeholder expansion.
  • Updates Apply/Copy commands and both UI navigators/design-time locators to apply the expansion pipeline when sending/copying snippet text.
  • Adds/updates tests for variable scanning/expansion/resolution and Apply command behavior; updates README and adds the required Neptuo package reference.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/Neptuo.Productivity.SnippetManager.Tests/SnippetVariablesTests.cs Adds unit tests for scanner/expander/resolvers and end-to-end pipeline behavior.
test/Neptuo.Productivity.SnippetManager.Tests/CopySnippetCommandTests.cs Updates command construction to pass an expansion pipeline.
test/Neptuo.Productivity.SnippetManager.Tests/ApplySnippetCommandTests.cs Adds Apply command tests including variable expansion before send.
src/Neptuo.Productivity.SnippetManager/ViewModels/Commands/CopySnippetCommand.cs Applies the expansion pipeline before copying text to clipboard.
src/Neptuo.Productivity.SnippetManager/ViewModels/Commands/ApplySnippetCommand.cs Applies the expansion pipeline before sending text.
src/Neptuo.Productivity.SnippetManager/Variables/VariablesConfiguration.cs Adds VariablesConfiguration (dictionary-backed) with an example payload.
src/Neptuo.Productivity.SnippetManager/Variables/VariableReference.cs Adds a simple reference type for discovered variables.
src/Neptuo.Productivity.SnippetManager/Variables/TokenSnippetVariableScanner.cs Implements token scanning via Neptuo.Text.Tokens.
src/Neptuo.Productivity.SnippetManager/Variables/TokenSnippetTextExpander.cs Implements token expansion (replace known tokens, preserve unknown/escaped).
src/Neptuo.Productivity.SnippetManager/Variables/SnippetExpansionPipeline.cs Orchestrates scan → resolve → expand for snippet text.
src/Neptuo.Productivity.SnippetManager/Variables/IVariableValueResolver.cs Introduces resolver abstraction for variable values.
src/Neptuo.Productivity.SnippetManager/Variables/ISnippetVariableScanner.cs Introduces scanner abstraction for variable discovery.
src/Neptuo.Productivity.SnippetManager/Variables/ISnippetTextExpander.cs Introduces expander abstraction for applying substitutions.
src/Neptuo.Productivity.SnippetManager/Variables/ConfigurationVariableValueResolver.cs Resolves variables from VariablesConfiguration.
src/Neptuo.Productivity.SnippetManager/Variables/CompositeVariableValueResolver.cs Adds resolver composition (first match wins).
src/Neptuo.Productivity.SnippetManager/Neptuo.Productivity.SnippetManager.csproj Adds Neptuo package reference needed for token parsing.
src/Directory.Packages.props Defines central package version for Neptuo.
src/Neptuo.Productivity.SnippetManager/Configuration.cs Adds VariablesConfiguration? Variables to the app configuration model.
src/Neptuo.Productivity.SnippetManager.UI/Navigator.cs Creates and wires the expansion pipeline into WPF commands.
src/Neptuo.Productivity.SnippetManager.UI/App.xaml.cs Forwards configuration.Variables into Navigator and includes variables in example config.
src/Neptuo.Productivity.SnippetManager.UI/Views/DesignData/ViewModelLocator.cs Uses an “empty” pipeline for design-time view models and updated command constructors.
src/Neptuo.Productivity.SnippetManager.Avalonia/Navigator.cs Creates and wires the expansion pipeline into Avalonia commands.
src/Neptuo.Productivity.SnippetManager.Avalonia/App.axaml.cs Forwards configuration.Variables into Navigator and includes variables in example config.
src/Neptuo.Productivity.SnippetManager.Avalonia/Views/DesignData/ViewModelLocator.cs Uses an “empty” pipeline for design-time view models and updated command constructors.
README.md Documents variables syntax, escaping, and behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Neptuo.Productivity.SnippetManager/Variables/VariablesConfiguration.cs Outdated
Comment thread src/Neptuo.Productivity.SnippetManager/Variables/TokenSnippetVariableScanner.cs Outdated
maraf and others added 5 commits April 17, 2026 20:37
Replaces the scanner + expander pair with a single compile step that
returns an ISnippetTemplate capturing the parsed token positions and
the list of variable references. SnippetExpansionPipeline now calls
Compile once, resolves values for Template.Variables, and renders
using the already-captured positions — no second parse pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The tray icon and hotkey handlers capture a specific Navigator instance
by reference. Previously the WPF reload path only rebound the hotkey
when GeneralConfiguration.HotKey changed, and never recreated the tray
icon, so any edit limited to Variables (or Providers) left the old
Navigator wired up. Mirror the Avalonia host: unconditionally dispose
and recreate the tray icon, and unconditionally unbind and rebind the
hotkey to the new Navigator.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- CopySnippetCommand.Execute: expansion parity with ApplySnippetCommand
- Template: repeated same token, adjacent tokens, token-only string,
  empty-string value, brace-like value never re-expanded,
  multiline text with tokens

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 24 out of 24 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@maraf maraf merged commit 7ecdff8 into main Apr 19, 2026
1 check passed
@maraf maraf deleted the copilot/add-snapshot-variables-support branch April 19, 2026 18:26
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.

3 participants