mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 15:29:22 +00:00
transpile tsserver works fast / many times
This commit is contained in:
parent
b0c09e28a1
commit
56a89a77d1
@ -21,6 +21,7 @@ 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;
|
||||||
@ -105,6 +106,7 @@ import ts.client.ITypeScriptServiceClient;
|
|||||||
import ts.client.LoggingInterceptor;
|
import ts.client.LoggingInterceptor;
|
||||||
import ts.client.ScriptKindName;
|
import ts.client.ScriptKindName;
|
||||||
import ts.client.TypeScriptServiceClient;
|
import ts.client.TypeScriptServiceClient;
|
||||||
|
import ts.client.TypeScriptServiceClient.TypeScriptServiceLogLevel;
|
||||||
import ts.client.completions.CompletionEntry;
|
import ts.client.completions.CompletionEntry;
|
||||||
import ts.client.diagnostics.Diagnostic;
|
import ts.client.diagnostics.Diagnostic;
|
||||||
import ts.client.diagnostics.DiagnosticEvent;
|
import ts.client.diagnostics.DiagnosticEvent;
|
||||||
@ -1466,72 +1468,64 @@ public class JSweetTranspiler implements JSweetOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Collection<String> sourceFilePaths = sourceFiles.stream().map(ts.utils.FileUtils::getPath).collect(toList());
|
Collection<String> sourceFilePaths = sourceFiles.stream().map(ts.utils.FileUtils::getPath)
|
||||||
|
.collect(toList());
|
||||||
if (sourceFilePaths.isEmpty()) {
|
if (sourceFilePaths.isEmpty()) {
|
||||||
throw new RuntimeException("no files to transpile");
|
throw new RuntimeException("no files to transpile");
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("launching tsserver compilation : \ncompilerOptions=" + compilerOptions + " \nsourcesFilePaths=" + sourceFilePaths);
|
logger.info("launching tsserver compilation : \ncompilerOptions=" + compilerOptions + " \nsourcesFilePaths="
|
||||||
|
+ sourceFilePaths);
|
||||||
ITypeScriptServiceClient client = getTypeScriptServiceClient();
|
ITypeScriptServiceClient client = getTypeScriptServiceClient();
|
||||||
|
|
||||||
|
logger.info("tsserver client built");
|
||||||
|
|
||||||
String projectFileName = ts.utils.FileUtils.getPath(getTsOutputDir());
|
String projectFileName = ts.utils.FileUtils.getPath(getTsOutputDir());
|
||||||
String referenceFileName = sourceFilePaths.iterator().next();
|
String referenceFileName = sourceFilePaths.iterator().next();
|
||||||
// ProjectInfo projectInfo = client.projectInfo(projectFileName, projectFileName, false).get();
|
|
||||||
//if (projectInfo == null) {
|
|
||||||
|
|
||||||
client.openExternalProject(projectFileName, new ArrayList<>(), compilerOptions);
|
if (lastTsserverProjectOpened == null || lastTsserverProjectOpened.equals(projectFileName)) {
|
||||||
//}
|
logger.info("open external project");
|
||||||
// Open "sample.ts" in an editor
|
client.openExternalProject(projectFileName,
|
||||||
// String fileName = ts.utils.FileUtils.getPath(new File("./ts2/test.ts"));
|
sourceFilePaths.stream().map(path -> new ExternalFile(path, ScriptKindName.TS, false, null))
|
||||||
// String fileName2 = ts.utils.FileUtils.getPath(new File("./ts2/test2.ts"));
|
.collect(toList()), //
|
||||||
// String fileName3 = ts.utils.FileUtils.getPath(new File("./ts2/lib/lib.ts"));
|
compilerOptions);
|
||||||
//
|
lastTsserverProjectOpened = projectFileName;
|
||||||
// compilerOptions.setOutDir("ts2/OUT");
|
|
||||||
// client.openExternalProject("./ts2", asList( //
|
|
||||||
// new ExternalFile(fileName, ScriptKindName.TS, false, null), //
|
|
||||||
// new ExternalFile(fileName2, ScriptKindName.TS, false, null)), compilerOptions);
|
|
||||||
|
|
||||||
for (String fileName : sourceFilePaths) {
|
|
||||||
logger.info("!OPEN " + fileName);
|
|
||||||
client.openFile(fileName, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// client.openFile(fileName3, null);
|
logger.info("tsserver project opened ");
|
||||||
|
|
||||||
|
for (String fileName : sourceFilePaths) {
|
||||||
|
client.updateFile(fileName, null);
|
||||||
|
}
|
||||||
|
|
||||||
// try (Scanner scanner = new Scanner(System.in)) {
|
|
||||||
// while (scanner.hasNextLine()) {
|
|
||||||
// System.out.println("NEXT >> " + scanner.nextLine());
|
|
||||||
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(fileName + " >>>> " + result);
|
||||||
}
|
}
|
||||||
// Boolean result = client.compileOnSaveEmitFile(fileName, true).get(5000, TimeUnit.MILLISECONDS);
|
|
||||||
// Boolean result2 = client.compileOnSaveEmitFile(fileName2, true).get(5000, TimeUnit.MILLISECONDS);
|
logger.info("tsserver project compiled ");
|
||||||
// Boolean result3 = client.compileOnSaveEmitFile(fileName3, true).get(5000, TimeUnit.MILLISECONDS);
|
|
||||||
//
|
ProjectInfo projectInfo = client.projectInfo(referenceFileName, projectFileName, true).get(5000,
|
||||||
ProjectInfo projectInfo = client.projectInfo(null, projectFileName, true).get(5000, TimeUnit.MILLISECONDS);
|
TimeUnit.MILLISECONDS);
|
||||||
CompletableFuture<java.util.List<DiagnosticEvent>> errors = client.geterrForProject(referenceFileName, 0,
|
CompletableFuture<java.util.List<DiagnosticEvent>> errors = client.geterrForProject(referenceFileName, 0,
|
||||||
projectInfo);
|
projectInfo);
|
||||||
displayDiagnostics(errors.get());
|
displayDiagnostics(errors.get());
|
||||||
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// client.closeFile(fileName);
|
|
||||||
// client.closeFile(fileName2);
|
|
||||||
// client.dispose();
|
|
||||||
|
|
||||||
// if (isIgnoreTypeScriptErrors()) {
|
// if (isIgnoreTypeScriptErrors()) {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
// SourcePosition position = SourceFile.findOriginPosition(output.position, Arrays.asList(files));
|
// SourcePosition position = SourceFile.findOriginPosition(output.position,
|
||||||
|
// Arrays.asList(files));
|
||||||
// if (position == null) {
|
// if (position == null) {
|
||||||
// transpilationHandler.report(JSweetProblem.INTERNAL_TSC_ERROR, output.position, output.message);
|
// transpilationHandler.report(JSweetProblem.INTERNAL_TSC_ERROR,
|
||||||
|
// output.position, output.message);
|
||||||
// } else {
|
// } else {
|
||||||
// transpilationHandler.report(JSweetProblem.MAPPED_TSC_ERROR, position, output.message);
|
// transpilationHandler.report(JSweetProblem.MAPPED_TSC_ERROR, position,
|
||||||
|
// output.message);
|
||||||
// }
|
// }
|
||||||
// if (!ignoreTypeScriptErrors && transpilationHandler.getProblemCount() == 0) {
|
// if (!ignoreTypeScriptErrors && transpilationHandler.getProblemCount() == 0) {
|
||||||
// transpilationHandler.report(JSweetProblem.INTERNAL_TSC_ERROR, null, "Unknown tsc error");
|
// transpilationHandler.report(JSweetProblem.INTERNAL_TSC_ERROR, null, "Unknown
|
||||||
|
// tsc error");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// onTsTranspilationCompleted(false, transpilationHandler, files);
|
// onTsTranspilationCompleted(false, transpilationHandler, files);
|
||||||
@ -1541,6 +1535,8 @@ ITypeScriptServiceClient client = getTypeScriptServiceClient();
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String lastTsserverProjectOpened;
|
||||||
|
|
||||||
private static void displayDiagnostics(java.util.List<DiagnosticEvent> events) {
|
private static void displayDiagnostics(java.util.List<DiagnosticEvent> events) {
|
||||||
System.out.println("========== DISPLAY DIAGNOSTICS ============");
|
System.out.println("========== DISPLAY DIAGNOSTICS ============");
|
||||||
for (DiagnosticEvent event : events) {
|
for (DiagnosticEvent event : events) {
|
||||||
@ -1553,22 +1549,20 @@ ITypeScriptServiceClient client = getTypeScriptServiceClient();
|
|||||||
System.out.println("========== END ===========");
|
System.out.println("========== END ===========");
|
||||||
}
|
}
|
||||||
|
|
||||||
// private ProjectInfo typeScriptProjectInfo;
|
|
||||||
//
|
|
||||||
// private ProjectInfo getOrInitTypeScriptProject(ITypeScriptServiceClient client, String name) {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
private ITypeScriptServiceClient typeScriptServiceClient;
|
private ITypeScriptServiceClient typeScriptServiceClient;
|
||||||
|
|
||||||
private ITypeScriptServiceClient getTypeScriptServiceClient() {
|
private ITypeScriptServiceClient getTypeScriptServiceClient() {
|
||||||
try {
|
try {
|
||||||
if (this.typeScriptServiceClient == null) {
|
if (this.typeScriptServiceClient == null) {
|
||||||
TypeScriptServiceClient typeScriptServiceClient = new TypeScriptServiceClient(new File("."),
|
TypeScriptServiceClient typeScriptServiceClient = new TypeScriptServiceClient(new File("."), //
|
||||||
new File("../../typescript.java/typescript-2.1.6/node_modules/typescript/bin/tsserver"), null);
|
new File("../../typescript.java/typescript-2.1.6/node_modules/typescript/bin/tsserver"), //
|
||||||
typeScriptServiceClient.addInterceptor(LoggingInterceptor.getInstance());
|
null, false, false, null, null, //
|
||||||
|
new TypeScriptServiceLogConfiguration("/tmp/tss.log", TypeScriptServiceLogLevel.verbose));
|
||||||
|
// typeScriptServiceClient.addInterceptor(LoggingInterceptor.getInstance());
|
||||||
typeScriptServiceClient.addProcessListener(TraceNodejsProcess.INSTANCE);
|
typeScriptServiceClient.addProcessListener(TraceNodejsProcess.INSTANCE);
|
||||||
this.typeScriptServiceClient = typeScriptServiceClient;
|
this.typeScriptServiceClient = typeScriptServiceClient;
|
||||||
|
|
||||||
|
logger.info("creating TypeScriptServiceClient");
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.typeScriptServiceClient;
|
return this.typeScriptServiceClient;
|
||||||
|
|||||||
@ -22,17 +22,20 @@ import static org.junit.Assert.assertNull;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.jsweet.transpiler.JSweetProblem;
|
import org.jsweet.transpiler.JSweetProblem;
|
||||||
import org.jsweet.transpiler.ModuleKind;
|
import org.jsweet.transpiler.ModuleKind;
|
||||||
import org.jsweet.transpiler.SourceFile;
|
import org.jsweet.transpiler.SourceFile;
|
||||||
|
import org.jsweet.transpiler.util.ConsoleTranspilationHandler;
|
||||||
import org.jsweet.transpiler.util.EvaluationResult;
|
import org.jsweet.transpiler.util.EvaluationResult;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import source.ambient.three.Globals;
|
||||||
import source.syntax.AnnotationQualifiedNames;
|
import source.syntax.AnnotationQualifiedNames;
|
||||||
import source.syntax.Casts;
|
import source.syntax.Casts;
|
||||||
import source.syntax.DocComments;
|
import source.syntax.DocComments;
|
||||||
@ -56,6 +59,18 @@ import source.syntax.ValidIndexedAccesses;
|
|||||||
|
|
||||||
public class SyntaxTests extends AbstractTest {
|
public class SyntaxTests extends AbstractTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mamene() throws Exception {
|
||||||
|
try (Scanner s = new Scanner(System.in)) {
|
||||||
|
while (s.hasNextLine()) {
|
||||||
|
s.nextLine();
|
||||||
|
transpiler.transpile(new ConsoleTranspilationHandler(),
|
||||||
|
new SourceFile[] { getSourceFile(References.class) });
|
||||||
|
System.out.println("ok");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReferences() {
|
public void testReferences() {
|
||||||
eval((logHandler, r) -> {
|
eval((logHandler, r) -> {
|
||||||
|
|||||||
@ -38,6 +38,12 @@ 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