Add configuration-based variable expansion for snippets#124
Merged
Conversation
…sion (closes #83) Agent-Logs-Url: https://github.com/neptuo/Productivity.SnippetManager/sessions/2c520484-66d7-4527-8bf6-0796b2109012 Co-authored-by: maraf <10020471+maraf@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add variables for snippets configuration
Add configuration-based variable expansion for snippets
Apr 17, 2026
This comment was marked as resolved.
This comment was marked as resolved.
…ySnippetCommand tests Agent-Logs-Url: https://github.com/neptuo/Productivity.SnippetManager/sessions/9d0e6b49-1143-4b85-9926-fed59d0a0154 Co-authored-by: maraf <10020471+maraf@users.noreply.github.com>
There was a problem hiding this comment.
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
Variablesconfiguration section plus aSnippetExpansionPipeline(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
Neptuopackage 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.
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>
There was a problem hiding this comment.
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
src/Neptuo.Productivity.SnippetManager.UI/Navigator.cs— addVariablesusing, addVariablesConfiguration?param, createSnippetExpansionPipelinefield, pass to command constructorssrc/Neptuo.Productivity.SnippetManager.UI/App.xaml.cs— forwardconfiguration.Variablesto Navigator and addVariablesto example configsrc/Neptuo.Productivity.SnippetManager.UI/Views/DesignData/ViewModelLocator.cs— add empty pipeline, pass to commandsREADME.md— rephrase{{literal}}escape semanticsApplySnippetCommandTests.csfor test parity (4 tests: CanExecute null/shadow/filled + Execute expands variables)