Skip to content
Merged
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
4 changes: 2 additions & 2 deletions Wurstpack/wurstscript/grill.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ rem Resolve script dir
set "DIR=%~dp0"

set "JAVA=%DIR%wurst-runtime\bin\java.exe"
set "GRILL_JAR=%DIR%grill\grill.jar"
set "GRILL_JAR=%DIR%grill-cli\grill.jar"

if not exist "%GRILL_JAR%" (
echo [grill] ERROR: Missing jar. Searched:
echo %GRILL_JAR%
rem fallback to ../grill if you want:
set "GRILL_JAR=%DIR%..\grill\grill.jar"
set "GRILL_JAR=%DIR%..\grill-cli\grill.jar"
if not exist "%GRILL_JAR%" (
echo %GRILL_JAR%
goto :restore
Expand Down
1 change: 1 addition & 0 deletions de.peeeq.wurstscript/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ dependencies {
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'commons-lang:commons-lang:2.6'
implementation 'com.github.albfernandez:juniversalchardet:2.4.0'
implementation 'org.xerial:sqlite-jdbc:3.46.1.3'
implementation 'com.github.inwc3:jmpq3:29b55f2c32'
implementation 'com.github.inwc3:wc3libs:cc49c8e63c'
implementation('com.github.wurstscript:wurstsetup:393cf5ea39') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
Expand Down Expand Up @@ -41,7 +40,6 @@

import java.io.*;
import java.lang.ref.WeakReference;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.Function;
Expand Down Expand Up @@ -148,49 +146,12 @@ public void loadWurstFilesInDir(File dir) {
loadWurstFilesInDir(f);
} else if (Utils.isWurstFile(f)) {
loadFile(f);
} else if (f.getName().equals("wurst.dependencies")) {
dependencies.addAll(checkDependencyFile(f, gui));
} else if ((!mapFile.isPresent() || runArgs.isNoExtractMapScript()) && f.getName().equals("war3map.j")) {
loadFile(f);
}
}
}

public static ImmutableList<File> checkDependencyFile(File depFile, WurstGui gui) {
List<String> lines;
try {
lines = Files.readLines(depFile, StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
throw new Error(e);
}
LineOffsets offsets = new LineOffsets();
int lineNr = 0;
int offset = 0;
for (String line : lines) {
offsets.set(lineNr, offset);
lineNr++;
offset += line.length() + 1;
}
offsets.set(lineNr, offset);
lineNr = 0;
ImmutableList.Builder<File> dependencies = ImmutableList.builder();
for (String line : lines) {
int lineOffset = offsets.get(lineNr);
WPos pos = new WPos(depFile.getAbsolutePath(), offsets, lineOffset + 1, lineOffset + line.length() + 1);
File folder = new File(line);
if (!folder.exists()) {
gui.sendError(new CompileError(pos, "Folder " + line + " not found."));
} else if (!folder.isDirectory()) {
gui.sendError(new CompileError(pos, line + " is not a folder."));
} else {
dependencies.add(folder);
}
lineNr++;
}
return dependencies.build();
}

@Override
public @Nullable WurstModel parseFiles() {

Expand Down Expand Up @@ -220,10 +181,6 @@ public static ImmutableList<File> checkDependencyFile(File depFile, WurstGui gui
} else {
WLogger.info("No wurst folder found in " + relativeWurstDir);
}
File dependencyFile = new File(projectFolder, "wurst.dependencies");
if (dependencyFile.exists()) {
dependencies.addAll(checkDependencyFile(dependencyFile, gui));
}
addDependenciesFromFolder(projectFolder, dependencies);
}

Expand Down Expand Up @@ -373,7 +330,7 @@ private void resolveImport(Function<File, CompilationUnit> addCompilationUnit, S
private CompilationUnit loadLibPackage(Function<File, CompilationUnit> addCompilationUnit, String imp) {
File file = getLibs().get(imp);
if (file == null) {
gui.sendError(new CompileError(new WPos("", null, 0, 0), "Could not find lib-package " + imp + ". Are you missing your wurst.dependencies file?"));
gui.sendError(new CompileError(new WPos("", null, 0, 0), "Could not find lib-package " + imp + ". Is your dependency present in _build/dependencies?"));
return Ast.CompilationUnit(new CompilationUnitInfo(errorHandler), Ast.JassToplevelDeclarations(), Ast.WPackages());
} else {
return addCompilationUnit.apply(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ synchronized void handleFileChange(FileEvent fileEvent) {
switch (fileEvent.getType()) {
case Created:
case Changed:
readFileFromDisk(uri);
readFileFromDisk(uri);
break;
case Deleted:
currentBuffer.remove(uri);
latestVersion.remove(uri);
break;
}
}

Expand All @@ -69,7 +72,8 @@ private String readFileFromDisk(WFile uri) {

synchronized void handleChange(DidChangeTextDocumentParams params) {
WFile uri = WFile.create(params.getTextDocument().getUri());
int version = params.getTextDocument().getVersion();
Integer versionObj = params.getTextDocument().getVersion();
int version = versionObj != null ? versionObj : getTextDocumentVersion(uri) + 1;
if (version < getTextDocumentVersion(uri)) {
// ignore old versions
return;
Expand All @@ -84,26 +88,45 @@ synchronized void handleChange(DidChangeTextDocumentParams params) {
} else {
int start = getOffset(sb, contentChange.getRange().getStart());
int end = getOffset(sb, contentChange.getRange().getEnd());
sb.replace(start, end - start, contentChange.getText());
if (end < start) {
int tmp = start;
start = end;
end = tmp;
}
sb.replace(start, end, contentChange.getText());
}
}
}

synchronized void handleOpen(DidOpenTextDocumentParams params) {
TextDocumentItem item = params.getTextDocument();
WFile uri = WFile.create(item.getUri());
latestVersion.put(uri, item.getVersion());
StringBuilder sb = buffer(uri);
sb.replace(0, sb.length(), item.getText());
}

synchronized void handleClose(DidCloseTextDocumentParams params) {
WFile uri = WFile.create(params.getTextDocument().getUri());
currentBuffer.remove(uri);
latestVersion.remove(uri);
}

public synchronized int getTextDocumentVersion(WFile uri) {
return latestVersion.getOrDefault(uri, -1);
}

private int getOffset(StringBuilder sb, Position position) {
int pos = 0;
int line = 1;
int line = 0;
while (pos < sb.length() && line < position.getLine()) {
if (sb.charAt(pos) == '\n') {
line++;
}
pos++;
}
pos += position.getCharacter();
return Math.min(pos, sb.length() - 1);
pos += Math.max(0, position.getCharacter());
return Math.min(Math.max(0, pos), sb.length());
}

synchronized public void updateFile(WFile wFile, String contents) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.eclipse.lsp4j.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand Down Expand Up @@ -76,7 +77,13 @@ public static PublishDiagnosticsParams createDiagnostics(String extra, WFile fil
break;

}
diagnostics.add(new Diagnostic(range, message, severity, "Wurst"));
Diagnostic diagnostic = new Diagnostic(range, message, severity, "Wurst");
diagnostic.setCode("WURST_" + err.getErrorType().name());
String messageLower = message.toLowerCase();
if (messageLower.contains("deprecated")) {
diagnostic.setTags(Collections.singletonList(DiagnosticTag.Deprecated));
}
diagnostics.add(diagnostic);
}
return new PublishDiagnosticsParams(filename.getUriString(), diagnostics);
}
Expand Down
Loading
Loading