1

I want to add user code snippet and I want to have the function name in it, something like this:

{
    "Print to console": {
        "prefix": "clog",
        "body": [
            "console.log('CONSOLE', '$FUNC_NAME$', $1);"
        ],
        "description": "Log to console"
     }
}

I can't find how to get the function name in VSCode snippets.

Any help?

2
  • Would this be printed anywhere n the function or predictably right after the function declaration? If the later there might be a way to do it. What language are you using? There is no built-in way to do this. Perhaps an extension could do the function lookup. Commented Aug 6, 2020 at 16:53
  • exactly what I wanted to ask , unfortunately no good answer so far ... Commented Nov 26, 2020 at 12:35

1 Answer 1

2

You'll need to write an extension to do this. VS Code's user snippets cannot access program structure information, such as class or function names.

Check out the completions extension sample to get started.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.