Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b691d6e0e3 | |||
| 6917c43c33 | |||
|
|
1a0596ca71 | ||
|
|
a9bbe834cc | ||
|
|
4fbf9133a5 | ||
|
|
972d9014ba | ||
|
|
4f4404d366 | ||
|
|
2dfbef6d7f | ||
|
|
7e6e968b0f | ||
|
|
dded453ba3 |
Binary file not shown.
3099
Clients/VisualStudioCode/package-lock.json
generated
3099
Clients/VisualStudioCode/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@
|
||||
"name": "java-tx-language-extension",
|
||||
"displayName": "Java-TX Language Extension",
|
||||
"description": "The Language Extension for Java-TX with Typehints and Syntax Checks",
|
||||
"version": "0.0.9",
|
||||
"version": "0.0.18",
|
||||
"engines": {
|
||||
"vscode": "^1.94.0"
|
||||
},
|
||||
@@ -20,6 +20,18 @@
|
||||
"command": "tx.restartLanguageServer",
|
||||
"title": "TX: Restart Language Server"
|
||||
}
|
||||
],
|
||||
"configuration": [
|
||||
{
|
||||
"title": "JavaTX Language Server Plugin",
|
||||
"properties": {
|
||||
"tx.compilerLocation": {
|
||||
"type": "string",
|
||||
"format": "file",
|
||||
"description": "JavaTX Compiler Location"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
@@ -42,6 +54,7 @@
|
||||
"typescript": "^5.6.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vscode/vsce": "^3.6.1",
|
||||
"vscode-languageclient": "^9.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,67 @@
|
||||
import path from 'path';
|
||||
import os from "os";
|
||||
import * as vscode from 'vscode';
|
||||
import {
|
||||
Executable,
|
||||
LanguageClient,
|
||||
LanguageClientOptions,
|
||||
ServerOptions
|
||||
} from 'vscode-languageclient/node';
|
||||
|
||||
let homeDirectory: string;
|
||||
let currentUser: string;
|
||||
|
||||
function untildify(pathWithTilde: string) {
|
||||
if (homeDirectory === undefined) {
|
||||
homeDirectory = os.homedir();
|
||||
}
|
||||
|
||||
// Handle regular ~ expansion (current user)
|
||||
if (homeDirectory && /^~(?=$|\/|\\)/.test(pathWithTilde)) {
|
||||
return pathWithTilde.replace(/^~/, homeDirectory);
|
||||
}
|
||||
|
||||
// Handle ~username expansion (only for current user)
|
||||
const userMatch = pathWithTilde.match(/^~([^/\\]+)(.*)/);
|
||||
if (userMatch) {
|
||||
if (currentUser === undefined) {
|
||||
currentUser = os.userInfo().username;
|
||||
}
|
||||
|
||||
if (currentUser) {
|
||||
const username = userMatch[1];
|
||||
const rest = userMatch[2];
|
||||
if (username === currentUser) {
|
||||
return homeDirectory + rest;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return unchanged if no expansion occurred
|
||||
return pathWithTilde;
|
||||
}
|
||||
|
||||
let client: LanguageClient | undefined; // <— global, damit wir neu starten können
|
||||
|
||||
function createClient(context: vscode.ExtensionContext): LanguageClient {
|
||||
function createClient(context: vscode.ExtensionContext): LanguageClient | null {
|
||||
const workspaceFolder = context.extensionPath;
|
||||
const config = vscode.workspace.getConfiguration("tx");
|
||||
|
||||
let compiler = config.get<string>("compilerLocation");
|
||||
if (!compiler || compiler.trim() === "") {
|
||||
vscode.window.showErrorMessage("Bitte konfiguriere den Pfad des Java-TX Compilers in den Einstellungen!");
|
||||
return null;
|
||||
}
|
||||
compiler = path.resolve(untildify(compiler));
|
||||
|
||||
const cmd: Executable = {
|
||||
command: 'java',
|
||||
args: ['-Xss10m', '-cp', `${compiler}:${workspaceFolder}/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar`, "de.dhbw.JavaTXLanguageServerLauncher"],
|
||||
};
|
||||
|
||||
const serverOptions: ServerOptions = {
|
||||
run: {
|
||||
command: 'java',
|
||||
args: ['-Xss10m', '-jar', workspaceFolder + "/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"],
|
||||
},
|
||||
debug: {
|
||||
command: 'java',
|
||||
args: [
|
||||
'-Xss10m',
|
||||
'-jar',
|
||||
workspaceFolder + '/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar',
|
||||
],
|
||||
}
|
||||
run: cmd,
|
||||
debug: cmd
|
||||
};
|
||||
|
||||
const clientOptions: LanguageClientOptions = {
|
||||
@@ -42,7 +81,9 @@ function createClient(context: vscode.ExtensionContext): LanguageClient {
|
||||
}
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext) {
|
||||
client = createClient(context);
|
||||
const c = createClient(context);
|
||||
if (!c) return;
|
||||
client = c;
|
||||
|
||||
client.start()
|
||||
.then(() => console.log("Language Client erfolgreich gestartet"))
|
||||
@@ -50,12 +91,6 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
console.log('Congratulations, your extension "tx" is now active!');
|
||||
|
||||
// Beispiel-Command aus deinem Code bleibt
|
||||
const hello = vscode.commands.registerCommand('lspclient.helloWorld', () => {
|
||||
vscode.window.showInformationMessage('Hello World from TX!');
|
||||
});
|
||||
context.subscriptions.push(hello);
|
||||
|
||||
// *** NEU: Restart-Command ***
|
||||
const restart = vscode.commands.registerCommand('tx.restartLanguageServer', async () => {
|
||||
if (!client) {
|
||||
@@ -68,7 +103,9 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
} catch (e) {
|
||||
console.error('Fehler beim Stoppen des Language Clients:', e);
|
||||
}
|
||||
client = createClient(context); // komplett neu erzeugen
|
||||
const c = createClient(context); // komplett neu erzeugen
|
||||
if (!c) return;
|
||||
client = c;
|
||||
try {
|
||||
await client.start();
|
||||
vscode.window.showInformationMessage('Java-TX Language Server neu gestartet.');
|
||||
|
||||
@@ -14,61 +14,17 @@
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.antlr/antlr4 -->
|
||||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4</artifactId>
|
||||
<version>4.11.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.java-diff-utils</groupId>
|
||||
<artifactId>java-diff-utils</artifactId>
|
||||
<version>4.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.20.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.20.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.10.0</version>
|
||||
<version>5.14.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.classgraph</groupId>
|
||||
<artifactId>classgraph</artifactId>
|
||||
<version>4.8.172</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>33.2.0-jre</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.ow2.asm/asm -->
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
<version>9.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.lsp4j</groupId>
|
||||
<artifactId>org.eclipse.lsp4j</artifactId>
|
||||
@@ -78,6 +34,7 @@
|
||||
<groupId>de.dhbwstuttgart</groupId>
|
||||
<artifactId>JavaTXcompiler</artifactId>
|
||||
<version>0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
|
||||
@@ -80,6 +80,8 @@ public class ChangeHandler {
|
||||
|
||||
if (!syntaxErrors.isEmpty()) {
|
||||
clientService.publishDiagnostics(params.getTextDocument().getUri(), syntaxErrors);
|
||||
}else {
|
||||
clientService.updateClient();
|
||||
}
|
||||
logService.log("Found [" + syntaxErrors.size() + "] Syntax Errors in Document.");
|
||||
|
||||
@@ -164,7 +166,7 @@ public class ChangeHandler {
|
||||
bw.close();
|
||||
|
||||
try {
|
||||
ArrayList<LSPVariable> variables = typeResolver.infereInput(tempFile2.toURI().toString(), input, true);
|
||||
ArrayList<LSPVariable> variables = typeResolver.infereInput(tempFile2.toURI().toString(), input);
|
||||
cacheService.setVariables(variables);
|
||||
|
||||
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehintsWithInput(variables, input);
|
||||
@@ -175,10 +177,9 @@ public class ChangeHandler {
|
||||
cacheService.updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
|
||||
|
||||
List<Diagnostic> allDiagnostics = new ArrayList<>(diagnostics);
|
||||
allDiagnostics.addAll(parserService.getDiagnosticsOfErrors(input, params.getTextDocument().getUri()));
|
||||
|
||||
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);
|
||||
} catch (Exception f) {
|
||||
} catch (Exception | VerifyError f) {
|
||||
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + f.getMessage(), MessageType.Error);
|
||||
|
||||
for (StackTraceElement elem : f.getStackTrace()) {
|
||||
@@ -190,10 +191,6 @@ public class ChangeHandler {
|
||||
tempFile2.delete();
|
||||
} catch (Exception e) {
|
||||
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
||||
|
||||
for (StackTraceElement elem : e.getStackTrace()) {
|
||||
logService.log(elem.toString());
|
||||
}
|
||||
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
||||
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
||||
|
||||
|
||||
@@ -105,43 +105,50 @@ public class CodeActionHandler {
|
||||
String documentUri = params.getTextDocument().getUri();
|
||||
Range rangeOfInsert = params.getRange();
|
||||
|
||||
//All Diagnostics that are in range of the hover -> All Diagnostics of the selected Variable and thus all Types of the Variable
|
||||
Map<String, List<PlaceholderVariable>> typeInsertsOverlapping = getOverlapping(typeResolver.getInserts(), rangeOfInsert.getStart().getLine() + 1, rangeOfInsert.getStart().getCharacter(), rangeOfInsert.getEnd().getCharacter());
|
||||
logService.log("Inserts are:");
|
||||
typeResolver.getInserts().forEach((key, value) -> logService.log(key));
|
||||
logService.log("Size is: " + typeInsertsOverlapping.size());
|
||||
logService.log("Range is: " + rangeOfInsert.getStart().getLine() + " -> " + rangeOfInsert.getStart().getCharacter() + " - " + rangeOfInsert.getEnd().getCharacter());
|
||||
List<Either<Command, CodeAction>> actions = new ArrayList<>();
|
||||
if (typeResolver.getInserts() != null) {
|
||||
//All Diagnostics that are in range of the hover -> All Diagnostics of the selected Variable and thus all Types of the Variable
|
||||
Map<String, List<PlaceholderVariable>> typeInsertsOverlapping = getOverlapping(typeResolver.getInserts(), rangeOfInsert.getStart().getLine() + 1, rangeOfInsert.getStart().getCharacter(), rangeOfInsert.getEnd().getCharacter());
|
||||
logService.log("Inserts are:");
|
||||
typeResolver.getInserts().forEach((key, value) -> logService.log(key));
|
||||
logService.log("Size is: " + typeInsertsOverlapping.size());
|
||||
logService.log("Range is: " + rangeOfInsert.getStart().getLine() + " -> " + rangeOfInsert.getStart().getCharacter() + " - " + rangeOfInsert.getEnd().getCharacter());
|
||||
List<Either<Command, CodeAction>> actions = new ArrayList<>();
|
||||
|
||||
for (var typeInsertList : typeInsertsOverlapping.values()) {
|
||||
for (var typeInsert : typeInsertList) {
|
||||
try {
|
||||
logService.log("NEW TEXT OF FILE BEFORE INSERT IS:");
|
||||
logService.log(textDocumentService.getFileOfUri(documentUri));
|
||||
String typeWithReplacedVariable = typeInsert.insert(textDocumentService.getFileOfUri(documentUri));
|
||||
for (var typeInsertList : typeInsertsOverlapping.values()) {
|
||||
for (var typeInsert : typeInsertList) {
|
||||
try {
|
||||
logService.log("NEW TEXT OF FILE BEFORE INSERT IS:");
|
||||
logService.log(textDocumentService.getFileOfUri(documentUri));
|
||||
String typeWithReplacedVariable = typeInsert.insert(textDocumentService.getFileOfUri(documentUri));
|
||||
|
||||
ArrayList<TextEdit> listOfChanges = new ArrayList<>();
|
||||
ArrayList<TextEdit> listOfChanges = new ArrayList<>();
|
||||
|
||||
listOfChanges.add(new TextEdit(wholeDocumentRange(textDocumentService.getFileOfUri(documentUri)), typeWithReplacedVariable));
|
||||
listOfChanges.add(new TextEdit(wholeDocumentRange(textDocumentService.getFileOfUri(documentUri)), typeWithReplacedVariable));
|
||||
|
||||
var isTypeImported = false;
|
||||
var isTypeImported = false;
|
||||
|
||||
Map<String, List<TextEdit>> changes = new HashMap<>();
|
||||
changes.put(documentUri, listOfChanges);
|
||||
Map<String, List<TextEdit>> changes = new HashMap<>();
|
||||
changes.put(documentUri, listOfChanges);
|
||||
|
||||
WorkspaceEdit edit = new WorkspaceEdit();
|
||||
edit.setChanges(changes);
|
||||
WorkspaceEdit edit = new WorkspaceEdit();
|
||||
edit.setChanges(changes);
|
||||
|
||||
CodeAction action = new CodeAction("Insert " + conversionHelper.cleanType(typeInsert.getInsertString()));
|
||||
action.setKind(CodeActionKind.QuickFix);
|
||||
action.setEdit(edit);
|
||||
actions.add(Either.forRight(action));
|
||||
} catch (Exception e) {
|
||||
logService.log("Error creating Actions, returning empty List. The Error was: " + e.getMessage(), MessageType.Error);
|
||||
CodeAction action = new CodeAction("Insert " + conversionHelper.cleanType(typeInsert.getInsertString()));
|
||||
action.setKind(CodeActionKind.QuickFix);
|
||||
action.setEdit(edit);
|
||||
|
||||
if(!actions.stream().map(el -> el.getRight().getTitle()).toList().contains(action.getTitle())){
|
||||
actions.add(Either.forRight(action));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logService.log("Error creating Actions, returning empty List. The Error was: " + e.getMessage(), MessageType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
return actions;
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<Either<Command, CodeAction>> handleCodeAction(CodeActionParams params) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.dhbw.handler;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.base.Verify;
|
||||
import de.dhbw.model.DiagnosticsAndTypehints;
|
||||
import de.dhbw.service.*;
|
||||
import de.dhbw.helper.ConversionHelper;
|
||||
@@ -51,19 +52,20 @@ public class SaveHandler {
|
||||
List<Diagnostic> syntaxErrors = parserService.getDiagnosticsOfErrors(fileInput, didSaveTextDocumentParams.getTextDocument().getUri());
|
||||
if (!syntaxErrors.isEmpty()) {
|
||||
clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), syntaxErrors);
|
||||
}else {
|
||||
clientService.updateClient();
|
||||
}
|
||||
logService.log("Found [" + syntaxErrors.size() + "] Syntax Errors in Document.");
|
||||
|
||||
if (syntaxErrors.isEmpty()) {
|
||||
|
||||
cacheService.getLastSavedFiles().put(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
||||
//typeResolver.getCompilerInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
||||
|
||||
if (fileInput == null) {
|
||||
logService.log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
||||
}
|
||||
|
||||
ArrayList<LSPVariable> variables = typeResolver.infereInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput, false);
|
||||
ArrayList<LSPVariable> variables = typeResolver.infereInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
||||
cacheService.setVariables(variables);
|
||||
|
||||
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(variables, didSaveTextDocumentParams.getTextDocument().getUri());
|
||||
@@ -79,16 +81,13 @@ public class SaveHandler {
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
} catch (Exception | VerifyError e) {
|
||||
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
||||
|
||||
for (StackTraceElement elem : e.getStackTrace()) {
|
||||
logService.log(elem.toString());
|
||||
}
|
||||
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
||||
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), didSaveTextDocumentParams.getTextDocument().getUri());
|
||||
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
sWatch.stop();
|
||||
logService.log("[didSave] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ public class TypeResolver {
|
||||
return variables;
|
||||
}
|
||||
|
||||
public ArrayList<LSPVariable> infereInput(String pathString, String input, boolean a) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||
public ArrayList<LSPVariable> infereInput(String pathString, String input) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
||||
|
||||
LanguageServerInterface languageServerInterface = new LanguageServerInterface();
|
||||
|
||||
@@ -63,7 +63,8 @@ The Language Server in itself can be used for any Client. The Clients task is to
|
||||
If you make changes in the Compiler Interface, you have to change the jar and therefore the Dependency in the Java TX Language Server
|
||||
You can follow this steps:
|
||||
1. package the JavaTX Compiler
|
||||
2. take the Jar-File and copy it into the /lib Folder
|
||||
2. create a lib Folder at ./LangaugeServer -> ./LanguageServer/lib
|
||||
2. take the Jar-File and copy it into the /lib Folder at
|
||||
3. execute this Maven command to add the Jar in your local Repository: ```mvn install:install-file -Dfile=lib/JavaTXcompiler-0.1-jar-with-dependencies.jar -DgroupId=de.dhbwstuttgart -DartifactId=JavaTXcompiler -Dversion=0.1 -Dpackaging=jar```
|
||||
4. run ```maven clean```, ```validate``` and ```install``` to load the new Dependency
|
||||
5. you can now package the Language Server or change the code accordingly.
|
||||
Reference in New Issue
Block a user