Add import within a snippet - VS Code
Asked Answered
H

0

7

I am writing a code snippet in Visual Studio Code, and I need that the snippet will import libraries if they are not already imported.

A simple example: I want to create a snippet in Java that will create a new Scanner and close it:

    "Scanner": {
    "prefix": "scanner",
    "body": [
        "Scanner scanner = new Scanner(System.in);",
        "scanner.close();"]
    }

I need that if the code doesn't contain an import for java.util.Scanner it will be imported (as part of the snippet).

How can I do it?

Hurryscurry answered 7/9, 2019 at 9:18 Comment(1)
Does this answer your question? visual studio code add corresponding import statements for snippetsFasces

© 2022 - 2024 — McMap. All rights reserved.