Difference between revisions of "VS Code Setup"

From Kolmafia
Jump to navigation Jump to search
(Created page with "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 exp...")
 
(Windows-related schtuff, && Tasks)
 
(One intermediate revision by one other user not shown)
Line 6: Line 6:
 
# Install the following files in .vscode:
 
# Install the following files in .vscode:
  
launch.json:
+
===== launch.json: =====
<nowiki>
+
{
{
+
    "version": "0.2.0",
    "version": "0.2.0",
+
    "configurations": [
    "configurations": [
+
        {
        {
+
            "type": "java",
            "type": "java",
+
            "name": "Debug (Launch)-KoLmafia<kolmafia>",
            "name": "Debug (Launch)-KoLmafia<kolmafia>",
+
            "request": "launch",
            "request": "launch",
+
            "mainClass": "net.sourceforge.kolmafia.KoLmafia",
            "mainClass": "net.sourceforge.kolmafia.KoLmafia",
+
            "projectName": "kolmafia",
            "projectName": "kolmafia",
+
            "windows": {
            "args": "--CLI"
+
                "cwd": "${workspaceFolder}/dist",
        }
+
                "sourcePaths": ["${workspaceFolder}"]
    ]
+
            },
}
+
            "args": "--CLI"
</nowiki>
+
        }
 +
    ]
 +
}
  
settings.json:
+
===== settings.json: =====
<nowiki>
+
{
{
+
    "files.exclude": {
    "files.exclude": {
+
        "**/.classpath": true,
        "**/.classpath": true,
+
        "**/.factorypath": true,
        "**/.factorypath": true,
+
        "**/.project": true,
        "**/.project": true,
+
        "**/.settings": true,
        "**/.settings": true,
+
        "**/*.class": true
        "**/*.class": true
+
    },
    },
+
    "java.project.referencedLibraries": [
    "java.project.referencedLibraries": [
+
        "lib/**/*.jar",
        "lib/**/*.jar",
+
        "src/**/*.jar"
        "src/**/*.jar"
+
    ]
    ]
+
}
}
+
Test by pressing F5 to run KoLmafia.
</nowiki>
+
=== Optional Steps ===
 +
===== Style definitions =====
 +
*For easier coding, download the [[:File:KoLMafia Style.xml|KoLMafia Style Definitions]] and figure out how to install them in VS Code.
  
Test by pressing F5 to run KoLmafia.
+
===== Making Tasks =====
====== Optional Steps ======
+
*Tasks are individual commands that can be used at will. There are two general situations in which they currently come in handy.
* For easier coding, download the [[:File:KoLMafia Style.xml|KoLMafia Style Definitions]] and figure out how to install them in VS Code.
+
*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

  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...