mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 15:29:22 +00:00
transpile tsserver cleaning and error reporting
This commit is contained in:
parent
56a89a77d1
commit
4803f9ec6f
@ -21,7 +21,6 @@ package org.jsweet.transpiler;
|
|||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
import static org.jsweet.transpiler.util.Util.toJavaFileObjects;
|
import static org.jsweet.transpiler.util.Util.toJavaFileObjects;
|
||||||
import static ts.client.TypeScriptServiceClient.TypeScriptServiceLogConfiguration;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@ -43,12 +42,7 @@ import java.util.HashSet;
|
|||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import ts.internal.client.protocol.OpenExternalProjectRequestArgs.ExternalFile;
|
|
||||||
import ts.nodejs.TraceNodejsProcess;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -103,16 +97,16 @@ import com.sun.tools.javac.util.Options;
|
|||||||
|
|
||||||
import ts.TypeScriptException;
|
import ts.TypeScriptException;
|
||||||
import ts.client.ITypeScriptServiceClient;
|
import ts.client.ITypeScriptServiceClient;
|
||||||
import ts.client.LoggingInterceptor;
|
|
||||||
import ts.client.ScriptKindName;
|
import ts.client.ScriptKindName;
|
||||||
import ts.client.TypeScriptServiceClient;
|
import ts.client.TypeScriptServiceClient;
|
||||||
|
import ts.client.TypeScriptServiceClient.TypeScriptServiceLogConfiguration;
|
||||||
import ts.client.TypeScriptServiceClient.TypeScriptServiceLogLevel;
|
import ts.client.TypeScriptServiceClient.TypeScriptServiceLogLevel;
|
||||||
import ts.client.completions.CompletionEntry;
|
|
||||||
import ts.client.diagnostics.Diagnostic;
|
|
||||||
import ts.client.diagnostics.DiagnosticEvent;
|
import ts.client.diagnostics.DiagnosticEvent;
|
||||||
import ts.client.diagnostics.IDiagnostic;
|
import ts.client.diagnostics.IDiagnostic;
|
||||||
import ts.client.projectinfo.ProjectInfo;
|
import ts.client.projectinfo.ProjectInfo;
|
||||||
import ts.cmd.tsc.CompilerOptions;
|
import ts.cmd.tsc.CompilerOptions;
|
||||||
|
import ts.internal.client.protocol.OpenExternalProjectRequestArgs.ExternalFile;
|
||||||
|
import ts.nodejs.TraceNodejsProcess;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The actual JSweet transpiler.
|
* The actual JSweet transpiler.
|
||||||
@ -1500,44 +1494,42 @@ public class JSweetTranspiler implements JSweetOptions {
|
|||||||
|
|
||||||
for (String fileName : sourceFilePaths) {
|
for (String fileName : sourceFilePaths) {
|
||||||
Boolean result = client.compileOnSaveEmitFile(fileName, true).get(5000, TimeUnit.MILLISECONDS);
|
Boolean result = client.compileOnSaveEmitFile(fileName, true).get(5000, TimeUnit.MILLISECONDS);
|
||||||
logger.info(fileName + " >>>> " + result);
|
logger.info("COMPILE >>> " + fileName + " >>>> " + result);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("tsserver project compiled ");
|
logger.info("tsserver project compiled ");
|
||||||
|
|
||||||
ProjectInfo projectInfo = client.projectInfo(referenceFileName, projectFileName, true).get(5000,
|
ProjectInfo projectInfo = client.projectInfo(referenceFileName, projectFileName, true).get(5000,
|
||||||
TimeUnit.MILLISECONDS);
|
TimeUnit.MILLISECONDS);
|
||||||
CompletableFuture<java.util.List<DiagnosticEvent>> errors = client.geterrForProject(referenceFileName, 0,
|
Collection<DiagnosticEvent> compilationErrors = client.geterrForProject(referenceFileName, 0, projectInfo)
|
||||||
projectInfo);
|
.get();
|
||||||
displayDiagnostics(errors.get());
|
printTsserverDiagnostics(compilationErrors);
|
||||||
|
|
||||||
// if (isIgnoreTypeScriptErrors()) {
|
if (!isIgnoreTypeScriptErrors()) {
|
||||||
// return;
|
for (DiagnosticEvent errorEvent : compilationErrors) {
|
||||||
// }
|
File fileInError = new File(errorEvent.getBody().getFile());
|
||||||
// SourcePosition position = SourceFile.findOriginPosition(output.position,
|
for (IDiagnostic error : errorEvent.getBody().getDiagnostics()) {
|
||||||
// Arrays.asList(files));
|
SourcePosition position = new SourcePosition(fileInError, null,
|
||||||
// if (position == null) {
|
new Position(error.getStartLocation().getLine(), error.getStartLocation().getOffset()));
|
||||||
// transpilationHandler.report(JSweetProblem.INTERNAL_TSC_ERROR,
|
transpilationHandler.report(JSweetProblem.MAPPED_TSC_ERROR, position, error.getFullText());
|
||||||
// output.position, output.message);
|
}
|
||||||
// } else {
|
}
|
||||||
// transpilationHandler.report(JSweetProblem.MAPPED_TSC_ERROR, position,
|
}
|
||||||
// output.message);
|
|
||||||
// }
|
|
||||||
// if (!ignoreTypeScriptErrors && transpilationHandler.getProblemCount() == 0) {
|
|
||||||
// transpilationHandler.report(JSweetProblem.INTERNAL_TSC_ERROR, null, "Unknown
|
|
||||||
// tsc error");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// onTsTranspilationCompleted(false, transpilationHandler, files);
|
onTsTranspilationCompleted(false, transpilationHandler, files);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("ts2js transpilation failed", e);
|
logger.error("ts2js transpilation failed", e);
|
||||||
|
|
||||||
|
if (!ignoreTypeScriptErrors && transpilationHandler.getProblemCount() == 0) {
|
||||||
|
transpilationHandler.report(JSweetProblem.INTERNAL_TSC_ERROR, null, "Unknown tsc error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String lastTsserverProjectOpened;
|
private String lastTsserverProjectOpened;
|
||||||
|
|
||||||
private static void displayDiagnostics(java.util.List<DiagnosticEvent> events) {
|
private static void printTsserverDiagnostics(Collection<DiagnosticEvent> events) {
|
||||||
System.out.println("========== DISPLAY DIAGNOSTICS ============");
|
System.out.println("========== DISPLAY DIAGNOSTICS ============");
|
||||||
for (DiagnosticEvent event : events) {
|
for (DiagnosticEvent event : events) {
|
||||||
System.out.println(event.getBody().getFile() + ":: " + event.getEvent());
|
System.out.println(event.getBody().getFile() + ":: " + event.getEvent());
|
||||||
|
|||||||
@ -60,12 +60,18 @@ import source.syntax.ValidIndexedAccesses;
|
|||||||
public class SyntaxTests extends AbstractTest {
|
public class SyntaxTests extends AbstractTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
// @Ignore
|
||||||
public void mamene() throws Exception {
|
public void mamene() throws Exception {
|
||||||
try (Scanner s = new Scanner(System.in)) {
|
try (Scanner s = new Scanner(System.in)) {
|
||||||
while (s.hasNextLine()) {
|
while (s.hasNextLine()) {
|
||||||
s.nextLine();
|
s.nextLine();
|
||||||
transpiler.transpile(new ConsoleTranspilationHandler(),
|
TestTranspilationHandler handler = new TestTranspilationHandler();
|
||||||
new SourceFile[] { getSourceFile(References.class) });
|
transpiler.transpile(handler, new SourceFile[] { getSourceFile(References.class) });
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(handler.getReportedProblems());
|
||||||
|
// handler.assertReportedProblems(JSweetProblem.);
|
||||||
|
|
||||||
System.out.println("ok");
|
System.out.println("ok");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,8 @@ public class References {
|
|||||||
$export("i", i);
|
$export("i", i);
|
||||||
$export("m", m(MyObject::new));
|
$export("m", m(MyObject::new));
|
||||||
$export("m2", m2(MyObject[]::new));
|
$export("m2", m2(MyObject[]::new));
|
||||||
|
|
||||||
|
References.this.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void m1(BiConsumer<String, Integer> c) {
|
void m1(BiConsumer<String, Integer> c) {
|
||||||
@ -38,12 +40,6 @@ public class References {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
References r = new References();
|
References r = new References();
|
||||||
r.m1(r::m);
|
r.m1(r::m);
|
||||||
|
|
||||||
int y = 0;
|
|
||||||
y++;
|
|
||||||
y++;
|
|
||||||
|
|
||||||
float aaaa;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> Object m(Supplier<T> supplier) {
|
public static <T> Object m(Supplier<T> supplier) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user