在 Visual Studio 中编写 Java 代码片段 json 中的代码
Writing Java code snippets in Visual Studio Code in json
我想为 Visual Studio 代码添加一些 Java 代码片段,以加速我常用的东西,例如System.out.println()
但是片段是用 json 写的,我没有经验。谁能帮助我了解如何构造这些 Java 片段,以及您在编程时如何实际使用它们?
这是我自己的尝试:
"Print to console":
{
"prefix": "System",
"body" : ["System.out.println("],
"description": "Print to the console"
}
虽然我不知道是我写错了还是没有正确访问代码段。
来自https://code.visualstudio.com/docs/editor/userdefinedsnippets
You can define your own snippets for specific languages. To open up a snippet file for editing, open User Snippets under File > Preferences (Code > Preferences on Mac) and select the language for which the snippets should appear.
使用上述步骤打开 java.json 后,您应该会看到一个注释示例。
要修复您的代码段,它应该是:
"Print to Console": {
"prefix": "System",
"body": [
"System.out.println(\"\");"
],
"description": "Print to the console"
}
当您在 vscode 上键入 System 时,您会看到 IntelliSense 为您提供建议。
我想为 Visual Studio 代码添加一些 Java 代码片段,以加速我常用的东西,例如System.out.println()
但是片段是用 json 写的,我没有经验。谁能帮助我了解如何构造这些 Java 片段,以及您在编程时如何实际使用它们?
这是我自己的尝试:
"Print to console":
{
"prefix": "System",
"body" : ["System.out.println("],
"description": "Print to the console"
}
虽然我不知道是我写错了还是没有正确访问代码段。
来自https://code.visualstudio.com/docs/editor/userdefinedsnippets
You can define your own snippets for specific languages. To open up a snippet file for editing, open User Snippets under File > Preferences (Code > Preferences on Mac) and select the language for which the snippets should appear.
使用上述步骤打开 java.json 后,您应该会看到一个注释示例。
要修复您的代码段,它应该是:
"Print to Console": {
"prefix": "System",
"body": [
"System.out.println(\"\");"
],
"description": "Print to the console"
}
当您在 vscode 上键入 System 时,您会看到 IntelliSense 为您提供建议。