How to find the parameters for a VSCode command in executeCommands() - visual-studio-code

I want to write a vscode extension and use vscode.commands.executeCommands(), but I don't know what parameters the command I want to use takes.
For example, when I want to use the "actions.find" command, how do I find out what parameters this specific API accepts?

I don't think there's any comprehensive documentation on commands and their arguments at this time. This page does list some of the most important ones though.
For some commands, there's also args auto-completion in keybindings.json:
Note that a lot of the built-in commands aren't much of an "API" at all. Looking at its implementation, "actions.find" in particular does not seem to support any arguments that would be useful to extensions. Compare this to the implementation of "workbench.action.findInFiles", which supports a well-defined set of arguments such as search query etc.

Related

Making all PowerShell script variables explicitly Typed

I'm new to PowerShell scripting and am looking to create ps1 scripts that I can used as cmdlets. My background is in using strongly typed variables, but I'm struggling to find how (or if) it is possible to ensure that all user variables in a script are explicitly typed. Some languages only allow explicitly typed variables. VBA allows the directive "Option Explicit" and I was hoping to find some way to achieve the same in any PSH scripts I create.
I've done a lot of searching (google, stackoverflow etc.) but not found anything. If there is no way to force all variable definitions to be explicitly typed, I'll have to write a cmdlet to parse my scripts to find any implicitly typed variables ... but hoping for a better solution.
I don't think you can do that in PowerShell. Closest you can get is to use Set-StrictMode which will, among other things, prohibit use of uninitialized variables.
But if you want to parse the scripts, maybe don't write your own solution. Use PSScriptAnalyzer module. It has a lot of built-in rules, unfortunately none for checking explicit types. But you can define your own rules, and maybe someone already created the one you're looking for and posted it somewhere.

How to create custom commands in VSCode?

In Emacs, I can create functions in Lisp language and place them in .emacs file. Those function will become commands that can be called from the editor or bound to keys just like any other built-in command.
Is there a way to do that in VSCode?
Note: The custom commands need to be able to call other commands. Simply using a batch file and running it as a task will not work.
A few marketplace extensions may be of interest:
Script Commands by Marcel J. Kloubert
multi-command by ryuta46
However in general, you'll need to write an extension to do anything complex.
There's also a VS Code issue tracking support for built-in macros
There's Power Tools by e.GO:digital. It has support for custom commands and event triggers (ie. on file changed), among other things.

Is it possible to configure tab completion with PowerTab for aliased functions?

I have written a set of PowerShell helper functions for the Micrsosoft TFS and Micrsosoft TFPT command line tools (some which in turn use the Posh cmdlets included with TFPT). To shorten the commands from their standard naming conventions, like Get-TfsStatus and Invoke-TfsCommit, I created aliases as well (e.g. tf-status and tf-commit). I use PowerTab as well for tab completion, but v0.99.6 does not support tab completion with aliases by default.
How do you configure tab completion so that my aliases, which all start with tf- can show me the list of available commands?
I see that PowerTab includes an editor for modifying tab expansion behavior, but it is not clear to me exactly what I would need to configure. I also know with PowerTab turned off, the default posh tab completion works with aliases.
Example function and alias:
function Get-TfsStatus([switch]$all) {
# Do something
}
Set-Alias tf-status Get-TfsStatus
Set-Alias tf-st Get-TfsStatus
Note: Originally, I had the actual function names as tf-status, tf-commit, etc., but when you Import-Module, PowerShell complains that I was not following the naming standards for PowerShell functions.
This is not a use case I had anticipated, so it is not well supported. However, there is an easy way to hack this in so long as your aliases continue to have a "-" in their name.
Edit line 957 of TabExpansionCore.ps1 to add "Alias" to the list of command types.
Get-Command -CommandType Alias,Function,ExternalScript,Filter,Cmdlet -Name "$($Matches[1])*" |
First off, you can use non-standard names for your functions without getting warnings.
Import-Module <<path_to_your_module>> -DisableNameChecking
Although, from experience, it is a good habit to follow (in most cases) the naming convention.
By default, autocomplete does not work on aliases. What does work, even for aliases, is parameter completion. So whether you type tf-status -a or Get-TfsStatus -a, if you press Tab, it will autocomplete to -All.
Neither the Powershell console nor the ISE editor have an option to enable alias completion.
For your case, I would suggest to use the "wrong" name (no alias), import with -DisableNameChecking and the autocomplete will then work for tf-status.
Concerning PowerTab -- this is not fully supported in all hosts. Check this page to see which functionality is supported where. I don't know it well - I'm sure it's possible to add aliases, but it might be a tedious task and would need to be done for each user. If someone doesn't have powertab, they won't be able to use autocompletion for the aliases you define in your module.

How can I jump only to the exact function name with etags?

I wanted to find the following function with etags:
dt()
but as I go through the tag table, I keep hitting functions with dt in their names, like
widthThing1()
widthThing2()
...
making the definition of dt() extremely difficult to find.
Is there some way to search only for the exact function that I'm searching for with etags?
Open up your TAGS file and see what it is actually indexing (which will vary by language, of course).
For instance, if the relevant entry looked like this:
function ds(^?6140,232332
Then you could use function ds( (or potentially just ds( ) as your search term, to ensure that you weren't matching other functions.
You could omit the "function" part of that, except that typing SPC at the find-tag prompt will invoke TAG completion. You could avoid that by typing C-qSPC instead, or alternatively utilise find-tag-regexp bound to C-M-. which does not have the completion binding.
So C-M-.SPC ds( RET might be convenient.
You may also want to look at the etags-select library and binding M-. to etags-select-find-tag, which I find provides a much better interface.
You can get that from the EmacsWiki, or Marmalade:
http://www.emacswiki.org/emacs/EtagsSelect
http://marmalade-repo.org/packages/etags-select
Packages like Icicles and Helm also provide alternative interfaces. You can start reading at http://emacswiki.org/emacs/EmacsTags

how to "copy" existing completions to other commands in zsh

I have a custom script that takes hostnames as parameters. I know that I can easily copy the existing completion of ssh like this:
compdef myscript=ssh
But that only enables completion of the 1st parameter. Is there an easy way to enable the same completion for all parameters?
I'm not aware of an easy method to enable completion for a custom command. Assuming you've got a command foo with a bunch of allowable arguments bar, bas or baz, then the completion is easy: you can either have foo bar, foo bas, or foo baz. If they're not or'd, though, you could have any combination of the three.
It gets somewhat worse when you've got a 'depth' of more than 1 (bar can take arguments car, cas and caz, for example).
In zsh, my general understanding is that completion for commands is detailed in completion functions. These functions are application specific, because the arguments for each application are specific to those applications. As an example, the tmux (a terminal multiplexer, similar to screen, in case you're not familiar) has a completion function that's fairly complex: here's a link.
If you want to write your own completion functions, the documentation is available and accessible. Here are a bunch of links that I'm (slowly) working my way through - they'll definitely tell you how to get completion working, but there's a lot of reading. The Z-Shell is a complex beast.
Z-Shell completion introduction
Z-Shell functions: Writing and loading your own
ZSH Users Guide, Ch. 6: "Completion, old and new"
You're specifically interested in enabling completion for hostname-like arguments, and you've singled out ssh as the idea. The zsh completion function for ssh is defined in Completion/Unix/Command/_ssh, if you've got the ZSH source. If not, here's a link.
Of course, this SO question is rather similar. compdef alone may do what you want, if myscript and ssh parameters are identical enough.