Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code snippet that inserts the method/function name?

I am not looking for a snippet that creates a method or function, I want a snippet that inserts the name of the method/function automatically.

Precisely, I would like something like this:

console.log('${TM_METHODNAME}: ${1}')

Unfortunately, TM_METHODNAME is not part of the default set of variables.

There doesn't seem to be an extension available for that either.

Maybe a compromise would be to use TM_SELECTED_TEXT, although I don't understand how it works, as when typing the snippet prefix, the selected text is obviously erased.

like image 905
Maxime Dupré Avatar asked Feb 20 '18 21:02

Maxime Dupré


People also ask

What is function snippet?

In programming practice, "snippet" refers narrowly to a portion of source code that is literally included by an editor program into a file, and is a form of copy and paste programming. This concrete inclusion is in contrast to abstraction methods, such as functions or macros, which are abstraction within the language.

How do you write a code snippet in VS Code?

Create your own snippets# To create or edit your own snippets, select User Snippets under File > Preferences (Code > Preferences on macOS), and then select the language (by language identifier) for which the snippets should appear, or the New Global Snippets file option if they should appear for all languages.

What is a snippet Visual Studio?

Applies to: Visual Studio Visual Studio for Mac Visual Studio Code. Code snippets are small blocks of reusable code that can be inserted in a code file using a right-click menu (context menu) command or a combination of hotkeys.

What does the code snippet show?

A code Snippet is a programming term that refers to a small portion of re-usable source code, machine code, or text. Snippets help programmers reduce the time it takes to type in repetitive information while coding. Code Snippets are a feature on most text editors, code editors, and IDEs.


1 Answers

As of v1.20 you can use CLIPBOARD as a variable, see v1.20 release notes so you could copy the method name first and have it ready to use in the snippet. I think at this point that is your only option.

like image 199
Mark Avatar answered Oct 09 '22 17:10

Mark