VS Code Setup

From Kolmafia
Revision as of 05:20, 22 December 2020 by Fredg1 (talk | contribs) (Windows-related schtuff, && Tasks)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

  1. Open the KoLmafia directory in VS Code.
  2. Install the Java Extension Pack, Language Support for Java, Project Manager for Java, and Debugger for Java VS Code extensions.
  3. 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
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).
Terminal => Run Build Task...