Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable substitution #9

Closed
24 tasks done
usernamehw opened this issue Jul 6, 2021 · 6 comments
Closed
24 tasks done

Variable substitution #9

usernamehw opened this issue Jul 6, 2021 · 6 comments
Labels
feature-request New feature or request

Comments

@usernamehw
Copy link
Owner

usernamehw commented Jul 6, 2021

Make it possible to use inside "args" https://code.visualstudio.com/docs/editor/variables-reference

  • ${userHome}
  • ${file}
  • ${fileBasename}
  • ${fileBasenameNoExtension}
  • ${fileExtname}
  • ${fileDirname}
  • ${fileWorkspaceFolder}
  • ${workspaceFolder}
  • ${workspaceFolderBasename}
  • ${execPath}
  • ${pathSeparator}
  • ${lineNumber}
  • ${selectedText}
  • ${currentYear}
  • ${currentYearShort}
  • ${currentMonth}
  • ${currentMonthName}
  • ${currentMonthNameShort}
  • ${currentDate}
  • ${currentDayName}
  • ${currentDayNameShort}
  • ${currentHour}
  • ${currentMinute}
  • ${currentSecond}
  • ${currentSecondsUnix}
  • ${currentTimezoneOffset}
  • ${config:VSCODE_SETTING_ID}
  • ${input:Name}
  • ${command:Name}
  • ${env:ENV_VAR}
"commands.variableSubstitutionEnabled": true,
"Input file name from selection": {
	"command": "workbench.action.quickOpen",
	"args": "${selectedText}",
},
  • Predefined variables ${file},${fileBasename},...
  • Environment variables ${env:MY_SYSTEM_VAR}
  • Configuration variables ${config:CONFIG_VAR}
  • Command variables ${command:vscodeCommandId}
  • Substitute inside arrays/objects
  • Input variables
  • Quick Pick list variables
  • Other
    • ${clipboard} current clipboard value
    • ${random} 6 random Base-10 digits
    • ${randomHex} 6 random Base-16 digits
    • ${selectedLineCount} Number of selected lines in active file
    • ${currentYear}
    • ${currentYearShort}
    • ${currentMonth}
    • ${currentMonthName}
    • ${currentMonthNameShort}
    • ${currentDate}
    • ${currentDayName}
    • ${currentDayNameShort}
    • ${currentHour}
    • ${currentMinute}
    • ${currentSecond}
    • ${currentSecondsUnix}
    • ${currentTimezoneOffset}
@usernamehw usernamehw added the feature-request New feature or request label Jul 6, 2021
usernamehw added a commit that referenced this issue Jul 6, 2021
@depascalis
Copy link

May I add a request for ${env:MY_SYSTEM_VAR} also.

https://code.visualstudio.com/docs/editor/variables-reference#_environment-variables

@marblewraith
Copy link

marblewraith commented Nov 13, 2021

Hi 🙋‍♂️

Not sure if this is fully implemented yet, but i may have found a bug?

I came across this when trying to replicate a feature of vim, specifically zz, zt, zb, because i don't want to have to install a whole vim extension just for this.

The following is for the example of zt.

It is supposed to eval the cursor line number, and scroll it to the top of the viewport, without moving the cursor.

"commands.variableSubstitutionEnabled": true,
"commands.commands": {
  "Viewport scroll Top": {
    "command": "revealLine",
    "args": {
      "lineNumber": "${lineNumber}",
      "at": "top",
    },
    "statusBar": {
      "alignment": "left",
      "color": "#FFCC00",
      "text": "scroll Top"
    }
  }
},

The problem is it doesn't work?

But if i hard code a value instead like "lineNumber": "20", or "lineNumber": 20, it does work.

Any thoughts? Solutions?

@usernamehw
Copy link
Owner Author

usernamehw commented Nov 13, 2021

Variable substitution only works if the "args" is of type - string.

It needs to be implemented as a recursive walking through arrays/objects and then when the item is string - substitute.

Actually, I don't feel like writing a recursive walking function. Just going to use JSON.stringify() & JSON.parse() - that will replace variables even inside object keys, but that's really unlikely to be a problem.

@marblewraith
Copy link

Awesome! Working beautifully now.

Thank you!

@GitMensch
Copy link
Contributor

GitMensch commented Jan 25, 2022

The one I miss the most in the list above are the configuration variables ${config:CONFIG_VAR}. Can you add that, please?

moved to separate issue for better tracking

@0vik7

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants