Add TM_FULLNAME and TM_EMAIL snippet variables#315156
Conversation
Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/0295e588-92b2-4cca-be2c-beca6ec13536 Co-authored-by: dmitrivMS <9581278+dmitrivMS@users.noreply.github.com>
dmitrivMS
left a comment
There was a problem hiding this comment.
See comments.
What happens on MacOS?
Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/c29703c3-6f3a-4d9e-936f-5acb88f5b0aa Co-authored-by: dmitrivMS <9581278+dmitrivMS@users.noreply.github.com>
On macOS this resolves via the same fallback chain: |
|
@copilot There are other places variables need to be registered - find and update them all. |
There was a problem hiding this comment.
Pull request overview
This PR adds two new built-in snippet variables (CURRENT_USER, CURRENT_USER_EMAIL) that resolve from environment variables, and wires the new resolver into snippet insertion so snippets can stamp per-user identity information.
Changes:
- Added
UserBasedVariableResolverand registeredCURRENT_USER/CURRENT_USER_EMAILas known built-in snippet variables. - Integrated the new resolver into
SnippetSessionvariable resolution so the variables expand during snippet insertion. - Updated snippet documentation and added unit tests for precedence, casing, and empty/whitespace handling.
Show a summary per file
| File | Description |
|---|---|
| src/vs/editor/contrib/snippet/test/browser/snippetVariables.test.ts | Adds tests validating resolution behavior for the new user-based snippet variables. |
| src/vs/editor/contrib/snippet/browser/snippetVariables.ts | Introduces UserBasedVariableResolver and registers the new built-in variable names. |
| src/vs/editor/contrib/snippet/browser/snippetSession.ts | Wires UserBasedVariableResolver into the composite resolver used by snippet insertion paths. |
| src/vs/editor/contrib/snippet/browser/snippet.md | Documents the new snippet variables and their environment-variable fallbacks. |
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 2
| private _resolveFromEnv(...keys: string[]): string | undefined { | ||
| for (const key of keys) { | ||
| const value = this._env[key] ?? this._env[key.toLowerCase()] ?? this._env[key.toUpperCase()]; | ||
| if (!isFalsyOrWhitespace(value)) { | ||
| return value; | ||
| } |
Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/01dab724-095e-4685-bee4-11787a1d2b27 Co-authored-by: dmitrivMS <9581278+dmitrivMS@users.noreply.github.com>
Fixed in 7f4852d — I audited the registrations and updated all hard-coded snippet variable regex lists in |
|
|
@copilot Remove the redundant toUpperCase() in the env lookup. |
Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/7fe10c09-c687-4745-9d8c-be53d974033d Co-authored-by: dmitrivMS <9581278+dmitrivMS@users.noreply.github.com>
Done in e448a9b — renamed to For |
Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/783657f3-89e8-4bfb-9d30-b25de02ef995 Co-authored-by: dmitrivMS <9581278+dmitrivMS@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/783657f3-89e8-4bfb-9d30-b25de02ef995 Co-authored-by: dmitrivMS <9581278+dmitrivMS@users.noreply.github.com>
| return this._email; | ||
| } | ||
|
|
||
| return undefined; |
|
|
||
| private static readonly _userNameEnvVariables = ['GIT_AUTHOR_NAME', 'GIT_COMMITTER_NAME', 'USER', 'USERNAME', 'LOGNAME']; | ||
| private static readonly _userEmailEnvVariables = ['GIT_AUTHOR_EMAIL', 'GIT_COMMITTER_EMAIL', 'EMAIL']; | ||
| private static _cachedFullName: string | undefined; |
There was a problem hiding this comment.
@copilot remove these _cached variables - one level of caching is enough
There was a problem hiding this comment.
Done in aef7942 — removed the static _cached variables and kept only the resolver-level computed values. No UI changes in this PR, so no screenshot applies.
|
@copilot revert changes to extensions/json/syntaxes/snippets.tmLanguage.json file |
Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/28dcb2a4-5a1e-4c4f-9a25-c2c03b8c25d8 Co-authored-by: dmitrivMS <9581278+dmitrivMS@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/5548b474-3130-4b4c-99f0-453eb17214fb Co-authored-by: dmitrivMS <9581278+dmitrivMS@users.noreply.github.com>
Description
This adds first-class snippet variables for per-user identity so shared snippets can stamp author info without hardcoding names. It introduces user name/email expansion with cross-platform env fallbacks and keeps behavior deterministic with resolver ordering.
What’s added
TM_FULLNAMETM_EMAILResolution behavior
TM_FULLNAMEresolves in priority order:GIT_AUTHOR_NAMEGIT_COMMITTER_NAMEUSERUSERNAMELOGNAMETM_EMAILresolves in priority order:GIT_AUTHOR_EMAILGIT_COMMITTER_EMAILEMAILEditor integration
UserBasedVariableResolverinto snippet expansion paths used by snippet session insertion.Docs and coverage
Follow-up from review feedback
UserBasedVariableResolver.resolveto useswitchwithdefault._resolveFromEnv.CURRENT_USER/CURRENT_USER_EMAILtoTM_FULLNAME/TM_EMAILfor TextMate naming consistency.toUpperCase()env lookup._cachedresolver fields so only one caching level remains.extensions/json/syntaxes/snippets.tmLanguage.jsonper review feedback.{ "Comment todo": { "prefix": "//", "body": [ "// TODO (${TM_FULLNAME}) [${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}]: $1", "// Contact: ${TM_EMAIL}" ] } }Testing
npm run compile-check-ts-nativenpm run transpile-clientnode test/unit/browser/index.js --run src/vs/editor/contrib/snippet/test/browser/snippetVariables.test.ts --browser chromiumnpm run test-node -- --grep "Snippet Variables Resolver"