VS Code Setup: Difference between revisions
Jump to navigation
Jump to search
m fix formatting |
Windows-related schtuff, && Tasks |
||
Line 16: | Line 16: | ||
"mainClass": "net.sourceforge.kolmafia.KoLmafia", | "mainClass": "net.sourceforge.kolmafia.KoLmafia", | ||
"projectName": "kolmafia", | "projectName": "kolmafia", | ||
"windows": { | |||
"cwd": "${workspaceFolder}/dist", | |||
"sourcePaths": ["${workspaceFolder}"] | |||
}, | |||
"args": "--CLI" | "args": "--CLI" | ||
} | } | ||
Line 36: | Line 40: | ||
} | } | ||
Test by pressing F5 to run KoLmafia. | Test by pressing F5 to run KoLmafia. | ||
====== | === Optional Steps === | ||
* For easier coding, download the [[:File:KoLMafia Style.xml|KoLMafia Style Definitions]] and figure out how to install them in VS Code. | ===== Style definitions ===== | ||
*For easier coding, download the [[:File:KoLMafia Style.xml|KoLMafia Style Definitions]] and figure out how to install them in VS Code. | |||
===== Making Tasks ===== | |||
*Tasks are individual commands that can be used at will. There are two general situations in which they currently come in handy. | |||
*To use them, add the following file in .vscode: | |||
'''tasks.json:''' | |||
{ | |||
"version": "2.0.0", | |||
"problemMatcher": "$eslint-compact", | |||
"type": "shell", | |||
"tasks": [ | |||
{ | |||
"label": "build .jar", | |||
"command": "ant.bat daily<nul", | |||
"windows": { | |||
"command": "& ((get-command $env:ANT_HOME/bin/ant.bat).Source) daily<nul -lib ${workspaceFolder} -buildfile ${workspaceFolder}/build.xml" | |||
}, | |||
"group": { | |||
"kind": "build", | |||
"isDefault": true | |||
} | |||
}, | |||
{ | |||
"label": "reset constants for patchmaking", | |||
"command": "ant.bat unset.properties<nul", | |||
"windows": { | |||
"command": "& ((get-command $env:ANT_HOME/bin/ant.bat).Source) unset.properties<nul -lib ${workspaceFolder} -buildfile ${workspaceFolder}/build.xml" | |||
} | |||
}, | |||
{ | |||
"label": "ant.bat set.version", | |||
"command": "ant.bat set.version<nul", | |||
"windows": { | |||
"command": "& ((get-command $env:ANT_HOME/bin/ant.bat).Source) set.version<nul -lib ${workspaceFolder} -buildfile ${workspaceFolder}/build.xml" | |||
} | |||
}, | |||
{ | |||
"label": "ant.bat set.released.false", | |||
"command": "ant.bat set.released.false<nul", | |||
"windows": { | |||
"command": "& ((get-command $env:ANT_HOME/bin/ant.bat).Source) set.released.false<nul -lib ${workspaceFolder} -buildfile ${workspaceFolder}/build.xml" | |||
} | |||
}, | |||
{ | |||
"label": "set constants for code running", | |||
"dependsOrder": "sequence", | |||
"dependsOn": [ | |||
"reset constants for patchmaking", | |||
"ant.bat set.version", | |||
"ant.bat set.released.false" | |||
] | |||
} | |||
] | |||
} | |||
*Here are the two uses for them: | |||
====== Automate version-setting when debugging ====== | |||
*In its current state, if you were to start debugging, it would work. However, KoLmafia would think that your revision is 0. This would cause any script beginning with a ''since'' statement to abort immediately. | |||
*To counter this without having to manually change KoLConstants.java, add these two lines to <code>launch.json</code>: | |||
{ | |||
"version": "0.2.0", | |||
"configurations": [ | |||
{ | |||
"type": "java", | |||
"name": "Debug (Launch)-KoLmafia<kolmafia>", | |||
"request": "launch", | |||
"mainClass": "net.sourceforge.kolmafia.KoLmafia", | |||
"projectName": "kolmafia", | |||
"windows": { | |||
"cwd": "${workspaceFolder}/dist", | |||
"sourcePaths": ["${workspaceFolder}"] | |||
}, | |||
<u>'''"preLaunchTask": "set constants for code running",'''</u> | |||
<u>'''"postDebugTask": "reset constants for patchmaking",'''</u> | |||
"args": "--CLI" | |||
} | |||
] | |||
} | |||
====== Building the .jar ====== | |||
* If you are not on Windows and already made your own Wrapper file, this is most likely not that much of an improvement, but these tasks allow you to build the .jar file in only two clicks (if you ever need to). | |||
[[File:Build Task.png|alt=Terminal => Run Build Task...|left|frameless]] |
Latest revision as of 05:20, 22 December 2020
This guide assumes that you have a recent enough version of the Java JDK, ANT, and VS Code. Completing Compiling from Source is a requirement for this guide, although experienced developers can skip to whatever step is appropriate.
Build and Config Project Setup
- Open the KoLmafia directory in VS Code.
- Install the Java Extension Pack, Language Support for Java, Project Manager for Java, and Debugger for Java VS Code extensions.
- Install the following files in .vscode:
launch.json:
{ "version": "0.2.0", "configurations": [ { "type": "java", "name": "Debug (Launch)-KoLmafia<kolmafia>", "request": "launch", "mainClass": "net.sourceforge.kolmafia.KoLmafia", "projectName": "kolmafia", "windows": { "cwd": "${workspaceFolder}/dist", "sourcePaths": ["${workspaceFolder}"] }, "args": "--CLI" } ] }
settings.json:
{ "files.exclude": { "**/.classpath": true, "**/.factorypath": true, "**/.project": true, "**/.settings": true, "**/*.class": true }, "java.project.referencedLibraries": [ "lib/**/*.jar", "src/**/*.jar" ] }
Test by pressing F5 to run KoLmafia.
Optional Steps
Style definitions
- For easier coding, download the KoLMafia Style Definitions and figure out how to install them in VS Code.
Making Tasks
- Tasks are individual commands that can be used at will. There are two general situations in which they currently come in handy.
- To use them, add the following file in .vscode:
tasks.json:
{ "version": "2.0.0", "problemMatcher": "$eslint-compact", "type": "shell", "tasks": [ { "label": "build .jar", "command": "ant.bat daily<nul", "windows": { "command": "& ((get-command $env:ANT_HOME/bin/ant.bat).Source) daily<nul -lib ${workspaceFolder} -buildfile ${workspaceFolder}/build.xml" }, "group": { "kind": "build", "isDefault": true } }, { "label": "reset constants for patchmaking", "command": "ant.bat unset.properties<nul", "windows": { "command": "& ((get-command $env:ANT_HOME/bin/ant.bat).Source) unset.properties<nul -lib ${workspaceFolder} -buildfile ${workspaceFolder}/build.xml" } }, { "label": "ant.bat set.version", "command": "ant.bat set.version<nul", "windows": { "command": "& ((get-command $env:ANT_HOME/bin/ant.bat).Source) set.version<nul -lib ${workspaceFolder} -buildfile ${workspaceFolder}/build.xml" } }, { "label": "ant.bat set.released.false", "command": "ant.bat set.released.false<nul", "windows": { "command": "& ((get-command $env:ANT_HOME/bin/ant.bat).Source) set.released.false<nul -lib ${workspaceFolder} -buildfile ${workspaceFolder}/build.xml" } }, { "label": "set constants for code running", "dependsOrder": "sequence", "dependsOn": [ "reset constants for patchmaking", "ant.bat set.version", "ant.bat set.released.false" ] } ] }
- Here are the two uses for them:
Automate version-setting when debugging
- In its current state, if you were to start debugging, it would work. However, KoLmafia would think that your revision is 0. This would cause any script beginning with a since statement to abort immediately.
- To counter this without having to manually change KoLConstants.java, add these two lines to
launch.json
:
{ "version": "0.2.0", "configurations": [ { "type": "java", "name": "Debug (Launch)-KoLmafia<kolmafia>", "request": "launch", "mainClass": "net.sourceforge.kolmafia.KoLmafia", "projectName": "kolmafia", "windows": { "cwd": "${workspaceFolder}/dist", "sourcePaths": ["${workspaceFolder}"] }, "preLaunchTask": "set constants for code running", "postDebugTask": "reset constants for patchmaking", "args": "--CLI" } ] }
Building the .jar
- If you are not on Windows and already made your own Wrapper file, this is most likely not that much of an improvement, but these tasks allow you to build the .jar file in only two clicks (if you ever need to).