Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ subprojects {

dependencies {
implementation 'org.slf4j:slf4j-api:2.0.9'
implementation 'org.slf4j:slf4j-simple:2.0.9'
implementation 'ch.qos.logback:logback-classic:1.4.11'

testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'
Expand All @@ -37,7 +37,8 @@ subprojects {
group 'distribution'
from (configurations.runtimeClasspath) {
include 'slf4j-api-*.jar'
include 'slf4j-simple-*.jar'
include 'logback-classic-*.jar'
include 'logback-core-*.jar'
}
into '../vscode-extension/server'
}
Expand Down
50 changes: 50 additions & 0 deletions vscode-extension/client/src/debug-adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

import { join } from "node:path";
import { ExtensionContext, window, workspace, debug, DebugAdapterExecutable } from "vscode";
import { SimpleLogger } from "./simple-logger";

/**
* @param {string} javaBin
* @param {ExtensionContext} context
*/
export async function activateDebugAdapter(javaBin, context) {
const logChannel = window.createOutputChannel('ZenScript Debug Adapter', "log");
const logger = new SimpleLogger(logChannel);
logger.info('Initializing Debug Adapter');
const config = workspace.getConfiguration();
// start debug adapter protocol
const classpath = join(__dirname, '..', '..', 'server', '*');
let dapDebug = '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5006,quiet=y';
const dapMain = 'raylras.zen.dap.debugserver.StandardIOLauncher';
const dapArgs = ['-cp', classpath];
if (config.get('zenscript.debugAdapter.debug')) {
logger.info(`Language server is running in debug mode.`);
if (config.get('zenscript.debugAdapter.suspend')) {
dapDebug = dapDebug.replace(/suspend=n/, "suspend=y");
}
logger.info(`DAP Debug arguments: ${dapDebug}`);
dapArgs.push(dapDebug);
}
const isSuspendDAP = dapDebug.indexOf("suspend=y") > -1;
dapArgs.push('-Dfile.encoding=UTF-8');
dapArgs.push(dapMain);
const dapOptions = {
env: process.env
};
context.subscriptions.push(debug.registerDebugAdapterDescriptorFactory('zenscript', {
createDebugAdapterDescriptor(session, executable) {
logger.info('Starting ZensScript Debug Adapter server');
if (isSuspendDAP) {
logger.info('Waiting for debugger attachment for DAP...');
}
return new DebugAdapterExecutable(javaBin, dapArgs, dapOptions);
}
}));


debug.onDidReceiveDebugSessionCustomEvent((e) => {
if(e.event === "outputLog") {
logChannel.appendLine(e.body);
}
});
}
8 changes: 7 additions & 1 deletion vscode-extension/client/src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ExtensionContext, window } from "vscode";
import { LanguageClient } from "vscode-languageclient/node";
import LocateJavaHome from "@viperproject/locate-java-home";
import { activateLanguageServer } from "./language-server"
import { activateDebugAdapter } from "./debug-adapter"

/** @type {LanguageClient} */
let languageClient = undefined;
Expand All @@ -15,7 +16,12 @@ export async function activate(context) {
window.showErrorMessage("No valid Java environment found, please install Java 17 or later");
} else {
const javaBin = javaHomes[0].executables.java;
languageClient = await activateLanguageServer(javaBin);

activateDebugAdapter(javaBin, context);
activateLanguageServer(javaBin)
.then(client => {
languageClient = client;
});
}
});
}
Expand Down
17 changes: 17 additions & 0 deletions vscode-extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 109 additions & 4 deletions vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"vscode": "^1.81.0"
},
"activationEvents": [
"onLanguage:zenscript"
"onLanguage:zenscript",
"onDebugResolve:zenscript"
],
"icon": "./icon/zs.webp",
"main": "./client/out/extension.js",
Expand All @@ -45,6 +46,11 @@
"path": "./language/ZenScript.tmLanguage.json"
}
],
"breakpoints": [
{
"language": "zenscript"
}
],
"configuration": {
"title": "ZenScript Language Server",
"properties": {
Expand All @@ -58,16 +64,114 @@
"order": 1,
"type": "boolean",
"default": false,
"description": "Suspend to wait for the debugger to attach"
"description": "Suspend to wait for the debugger to attach for language server"
},
"zenscript.languageServer.javaHome": {
"zenscript.debugAdapter.debug": {
"order": 2,
"type": "boolean",
"default": false,
"description": "Enable/disable debug mode for debug adapter"
},
"zenscript.debugAdapter.suspend": {
"order": 3,
"type": "boolean",
"default": false,
"description": "Suspend to wait for the debugger to attach for debug adapter"
},
"zenscript.languageServer.javaHome": {
"order": 4,
"type": "string",
"default": null,
"description": "Path of java home"
}
}
}
},
"debuggers": [
{
"type": "zenscript",
"label": "ZenScript",
"configurationAttributes": {
"attach": {
"required": [
"scriptRoot",
"hostName",
"port"
],
"properties": {
"scriptRoot": {
"type": "string",
"description": "The path of 'scripts' folder",
"default": "${workspaceFolder}/scripts"
},
"hostName": {
"type": "string",
"description": "The host name of your running JVM.",
"default": "localhost"
},
"port": {
"type": "number",
"description": "The port number of your running JVM.",
"default": 8000
}
}
},
"launch": {
"required": [
"scriptRoot"
],
"properties": {
"scriptRoot": {
"type": "string",
"description": "The path of 'scripts' folder",
"default": "${workspaceFolder}/scripts"
},
"javaExecutable": {
"type": "string",
"description": "The java to launch minecraft, if not specified, try to resolve from probezs environment"
},
"launchInTerminal": {
"type": "boolean",
"description": "Is process launch in vscode integrated terminal, false to launch it as subprocess",
"default": true
}
}
}
},
"configurationSnippets": [

{
"label": "ZenScript: Launch Minecraft",
"description": "Launch a new minecraft instance and start debug",
"body": {
"type": "zenscript",
"request": "launch",
"name": "ZenScript Launch",
"scriptRoot": "^\"\\${workspaceFolder}/scripts\""
}
},
{
"label": "ZenScript: Attach VM",
"description": "Attaches a debugger to a running JVM",
"body": {
"type": "zenscript",
"request": "attach",
"name": "ZenScript Attach",
"scriptRoot": "^\"\\${workspaceFolder}/scripts\"",
"hostName": "localhost",
"port": 8000
}
}
],
"initialConfigurations": [
{
"type": "zenscript",
"request": "launch",
"name": "ZenScript Launch",
"scriptRoot": "${workspaceFolder}/scripts"
}
]
}
]
},
"scripts": {
"package": "vsce package",
Expand All @@ -78,6 +182,7 @@
},
"dependencies": {
"@viperproject/locate-java-home": "^1.1.13",
"@vscode/debugadapter": "^1.63.0",
"dayjs": "^1.11.9",
"vscode-languageclient": "^9.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import raylras.zen.model.type.Types;
import raylras.zen.util.PathUtil;

import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -22,7 +21,6 @@
public class CompilationEnvironment {

public static final String DEFAULT_ROOT_DIRECTORY = "scripts";
public static final String DEFAULT_GENERATED_DIRECTORY = "generated";

private final Path root;
private final Path generatedRoot;
Expand Down Expand Up @@ -136,11 +134,7 @@ public String toString() {
}

private static Path resolveGeneratedRoot(CompilationEnvironment env) {
return FileSystems.getDefault()
.getPath(System.getProperty("user.home"))
.resolve(".probezs")
.resolve(PathUtil.toHash(env.getRoot()))
.resolve(DEFAULT_GENERATED_DIRECTORY);
return PathUtil.resolveGeneratedRoot(env.getRoot());
}

}
11 changes: 11 additions & 0 deletions zenscript-code-model/src/main/java/raylras/zen/util/PathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.math.BigInteger;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -12,6 +13,7 @@

public final class PathUtil {

public static final String DEFAULT_GENERATED_DIRECTORY = "generated";
private PathUtil() {}

public static Path toPath(String uri) {
Expand Down Expand Up @@ -75,4 +77,13 @@ public static String toHash(Path path) {
}
}


public static Path resolveGeneratedRoot(Path envRoot) {
return FileSystems.getDefault()
.getPath(System.getProperty("user.home"))
.resolve(".probezs")
.resolve(PathUtil.toHash(envRoot))
.resolve(DEFAULT_GENERATED_DIRECTORY);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ public String toString() {
return "(" + line + ":" + column + ')';
}


}
38 changes: 0 additions & 38 deletions zenscript-code-model/src/main/resources/simplelogger.properties

This file was deleted.

11 changes: 10 additions & 1 deletion zenscript-debug-adapter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ group 'raylras.zen.dap'

dependencies {
implementation project(':zenscript-code-model')
implementation 'org.eclipse.lsp4j:org.eclipse.lsp4j.debug:0.21.1'
implementation 'io.reactivex.rxjava3:rxjava:3.1.7'
}

test {
useJUnitPlatform()
}

distDeps {
from (configurations.runtimeClasspath) {
include 'org.eclipse.lsp4j-*.jar'
include 'org.eclipse.lsp4j.debug-*.jar'
include 'org.eclipse.lsp4j.jsonrpc.debug-*.jar'
include 'reactive-streams-*.jar'
include 'rxjava-*.jar'
}
into '../vscode-extension/server'
}
Loading