Permalink
Browse files

Worksheet remade

  • Loading branch information...
1 parent 1a7ef03 commit 4aafb9b7284bd831f108afb91ebdfbe315902f85 @Lugzan Lugzan committed Feb 14, 2014
Showing with 1,775 additions and 691 deletions.
  1. +3 −0 META-INF/scala-plugin-common.xml
  2. +14 −0 NailgunRunners/NailgunRunners.iml
  3. 0 {Runners → NailgunRunners}/src/org/jetbrains/plugins/scala/nailgun/NailgunRunner.java
  4. +79 −0 Runners/src/org/jetbrains/plugins/scala/worksheet/MyWorksheetRunner.java
  5. +0 −47 Runners/src/org/jetbrains/plugins/scala/worksheet/WorksheetInterpreter.java
  6. +0 −26 Runners/src/org/jetbrains/plugins/scala/worksheet/WorksheetReporter.java
  7. +0 −68 Runners/src/org/jetbrains/plugins/scala/worksheet/WorksheetRunner.java
  8. BIN SDK/nailgun/nailgun.jar
  9. +1 −0 ScalaCommunity.iml
  10. +34 −0 ScalaRunner/src/org/jetbrains/plugins/scala/worksheet/MacroPrinter.scala
  11. +11 −0 compiler-settings/compiler-settings.iml
  12. +42 −0 compiler-settings/src/org/jetbrains/jps/incremental/scala/Client.scala
  13. +12 −11 {jps-plugin → compiler-settings}/src/org/jetbrains/jps/incremental/scala/data/SbtData.scala
  14. +1 −1 {jps-plugin → compiler-settings}/src/org/jetbrains/jps/incremental/scala/package.scala
  15. +6 −0 ...in → compiler-settings}/src/org/jetbrains/jps/incremental/scala/remote/ClientEventProcessor.scala
  16. +5 −1 {jps-plugin → compiler-settings}/src/org/jetbrains/jps/incremental/scala/remote/Event.scala
  17. +105 −0 compiler-settings/src/org/jetbrains/jps/incremental/scala/remote/RemoteResourceOwner.scala
  18. +1 −33 jps-plugin/src/org/jetbrains/jps/incremental/scala/Server.scala
  19. +1 −0 jps-plugin/src/org/jetbrains/jps/incremental/scala/local/LocalServer.scala
  20. +6 −4 jps-plugin/src/org/jetbrains/jps/incremental/scala/remote/Arguments.scala
  21. +8 −0 jps-plugin/src/org/jetbrains/jps/incremental/scala/remote/EventGeneratingClient.scala
  22. +154 −10 jps-plugin/src/org/jetbrains/jps/incremental/scala/remote/Main.scala
  23. +5 −92 jps-plugin/src/org/jetbrains/jps/incremental/scala/remote/RemoteServer.scala
  24. +49 −29 src/org/jetbrains/plugins/scala/compiler/CompileServerLauncher.scala
  25. +1 −1 src/org/jetbrains/plugins/scala/compiler/CompileServerManager.scala
  26. +1 −1 src/org/jetbrains/plugins/scala/compiler/ServerMediator.scala
  27. +1 −1 src/org/jetbrains/plugins/scala/runner/BaseRunConfiguration.scala
  28. +16 −6 src/org/jetbrains/plugins/scala/settings/ScalaProjectSettings.java
  29. +11 −2 src/org/jetbrains/plugins/scala/settings/ScalaProjectSettingsPanel.form
  30. +5 −0 src/org/jetbrains/plugins/scala/settings/ScalaProjectSettingsPanel.java
  31. +50 −13 src/org/jetbrains/plugins/scala/worksheet/actions/CleanWorksheetAction.scala
  32. +30 −4 src/org/jetbrains/plugins/scala/worksheet/actions/RunWorksheetAction.scala
  33. +67 −0 src/org/jetbrains/plugins/scala/worksheet/actions/WorksheetFileHook.scala
  34. +31 −0 src/org/jetbrains/plugins/scala/worksheet/processor/WorksheetBoundCompilationInfo.scala
  35. +77 −0 src/org/jetbrains/plugins/scala/worksheet/processor/WorksheetCompiler.scala
  36. +171 −0 src/org/jetbrains/plugins/scala/worksheet/processor/WorksheetSourceProcessor.scala
  37. +57 −341 src/org/jetbrains/plugins/scala/worksheet/runconfiguration/WorksheetRunConfiguration.scala
  38. +11 −0 src/org/jetbrains/plugins/scala/worksheet/runconfiguration/WorksheetViewerInfo.scala
  39. +290 −0 src/org/jetbrains/plugins/scala/worksheet/server/RemoteServerConnector.scala
  40. +13 −0 src/org/jetbrains/plugins/scala/worksheet/server/WorksheetMakeType.scala
  41. +124 −0 src/org/jetbrains/plugins/scala/worksheet/server/WorksheetNonServerRunner.scala
  42. +282 −0 src/org/jetbrains/plugins/scala/worksheet/ui/WorksheetEditorPrinter.scala
@@ -914,6 +914,9 @@
<component>
<implementation-class>org.jetbrains.plugins.scala.components.WorksheetProjectComponent</implementation-class>
</component>
+ <component>
+ <implementation-class>org.jetbrains.plugins.scala.worksheet.actions.WorksheetFileHook</implementation-class>
+ </component>
</project-components>
<actions>
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="nailgun" level="project" />
+ <orderEntry type="module" module-name="ScalaRunner" />
+ </component>
+</module>
+
@@ -0,0 +1,79 @@
+package org.jetbrains.plugins.scala.worksheet;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * User: Dmitry Naydanov
+ * Date: 1/17/14
+ */
+public class MyWorksheetRunner {
+ private static final int TRACE_PREFIX = 13;
+
+ public static void main(String[] args) throws IOException {
+ String className = args[0];
+ String fileName = args.length > 1? args[1] : null;
+
+ try {
+ Class cl = ClassLoader.getSystemClassLoader().loadClass(className); //It's in default package, so name == fqn
+ Object methodArgs = new String[] {};
+ for (Method method : cl.getDeclaredMethods()) {
+ if ("main".equals(method.getName())) method.invoke(null, methodArgs);
+ }
+
+ } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException e) {
+ e.printStackTrace(System.out);
+ } catch (InvocationTargetException e) {
+ Throwable newThrowable =
+ new StackTraceClean(e.getCause() == null? e : e.getCause(), fileName, className + "$" + className).clean();
+ newThrowable.printStackTrace(System.out);
+ }
+ }
+
+ private static class StackTraceClean {
+ private final static String WORKSHEET = "#worksheet#";
+
+ Throwable e;
+ String fileName;
+ String className;
+
+ private StackTraceClean(Throwable e, String fileName, String className) {
+ this.e = e;
+ this.fileName = fileName;
+ this.className = className;
+ }
+
+ private Throwable clean() {
+ StackTraceElement[] els = e.getStackTrace();
+ final int length = els.length;
+
+ if (length < TRACE_PREFIX) return e;
+ StackTraceElement[] newTrace = new StackTraceElement[length - TRACE_PREFIX + 1];
+ StackTraceElement referenceElement = els[length - TRACE_PREFIX];
+
+ newTrace[newTrace.length - 1] = new StackTraceElement(WORKSHEET, WORKSHEET,
+ fileName == null? referenceElement.getFileName() : fileName,
+ referenceElement.getLineNumber() - 4
+ );
+
+ for (int i = 0; i < newTrace.length - 1; ++i) {
+ newTrace[i] = transformElement(els[i]);
+ }
+
+ e.setStackTrace(newTrace);
+
+ return e;
+ }
+
+ private StackTraceElement transformElement(StackTraceElement original) {
+ final String originalClassName = original.getClassName();
+ final String declaringClassName = originalClassName.equals(className) ? WORKSHEET :
+ (originalClassName.startsWith(className + "$")? WORKSHEET + "." + originalClassName.substring(className.length() + 1) : originalClassName);
+ final String originalFileName = fileName == null ? original.getFileName() : fileName;
+
+ return new StackTraceElement(declaringClassName, original.getMethodName(),
+ originalFileName, original.getLineNumber() - 4);
+ }
+ }
+}
@@ -1,47 +0,0 @@
-package org.jetbrains.plugins.scala.worksheet;
-
-import scala.Some;
-import scala.tools.nsc.interpreter.ILoop;
-
-import java.io.BufferedReader;
-import java.io.PrintWriter;
-
-/**
- * @author Ksenia.Sautina
- * @since 10/30/12
- */
-public class WorksheetInterpreter extends ILoop {
- private BufferedReader _in0;
- private PrintWriter _out;
- private WorksheetReporter intp;
-// private WorksheetReporter reporter = new WorksheetReporter(this);
-
- public WorksheetInterpreter(BufferedReader in0, PrintWriter out) {
- super(new Some(in0), out);
- _in0 = in0;
- _out = out;
- }
-
- /** Print a welcome message */
- @Override
- public void printWelcome() {
- }
-
- @Override
- public void createInterpreter() {
- super.createInterpreter();
- intp = new WorksheetReporter(this);
- }
-
-
- @Override
- public void echo(String msg) {
- _out.println("[worksheet]" + msg);
- _out.flush();
- }
-
- @Override
- public void echoCommandMessage(String msg) {
- super.echoCommandMessage("[worksheetCommand]" + msg);
- }
-}
@@ -1,26 +0,0 @@
-package org.jetbrains.plugins.scala.worksheet;
-
-import scala.tools.nsc.Settings;
-import scala.tools.nsc.interpreter.ILoop;
-import scala.tools.nsc.interpreter.IMain;
-import scala.tools.nsc.reporters.ConsoleReporter;
-
-import java.io.BufferedReader;
-import java.io.PrintWriter;
-
-/**
- * @author Ksenia.Sautina
- * @since 10/30/12
- */
-public class WorksheetReporter extends ConsoleReporter {
- public WorksheetReporter(ILoop intr) {
- super(intr.settings());
- }
- @Override
- public void printMessage(String msg) {
- // Avoiding deadlock if the compiler starts logging before
- // the lazy val is complete.
- super.printMessage("[worksheetReporter]" + msg);
- }
-
-}
@@ -1,68 +0,0 @@
-package org.jetbrains.plugins.scala.worksheet;
-
-import scala.Some;
-import scala.collection.mutable.ListBuffer;
-import scala.collection.mutable.ListBuffer$;
-import scala.runtime.AbstractFunction1;
-import scala.runtime.BoxedUnit;
-import scala.tools.nsc.GenericRunnerSettings;
-import scala.tools.nsc.InterpreterLoop;
-import scala.tools.nsc.interpreter.ILoop;
-
-import java.io.*;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-/**
- * @author Ksenia.Sautina
- * @since 10/15/12
- */
-public class WorksheetRunner {
-
- public static void main(String[] args) throws IOException, InvocationTargetException, IllegalAccessException {
- String[] newArgs;
- if (args.length == 1 && args[0].startsWith("@")) {
- String arg = args[0];
- File file = new File(arg.substring(1));
- if (!file.exists())
- throw new java.io.FileNotFoundException(String.format("argument file %s could not be found", file.getName()));
- FileReader fileReader = new FileReader(file);
- StringBuilder buffer = new StringBuilder();
- while (true) {
- int i = fileReader.read();
- if (i == -1) break;
- char c = (char) i;
- if (c == '\r') continue;
- buffer.append(c);
- }
- newArgs = buffer.toString().split("[\n]");
- } else {
- newArgs = args;
- }
- WorksheetInterpreter interpreterLoop = new WorksheetInterpreter(new BufferedReader(new InputStreamReader(System.in)),
- new PrintWriter(System.out));
- Method[] methods = interpreterLoop.getClass().getMethods();
- for (Method method : methods) {
- if (method.getName().equals("name") && method.getParameterTypes().length == 1 &&
- method.getParameterTypes()[0].isArray()) {
- method.invoke(interpreterLoop, newArgs);
- return;
- }
- }
- GenericRunnerSettings settings = new GenericRunnerSettings(new AbstractFunction1<String, BoxedUnit>() {
- /** Apply the body of this function to the argument.
- * @return the result of function application.
- */
- @Override
- public BoxedUnit apply(String v1) {
- return BoxedUnit.UNIT;
- }
- });
- ListBuffer<String> buffer = ListBuffer$.MODULE$.<String>empty();
- for (String newArg : newArgs) {
- buffer.$plus$eq(newArg);
- }
- settings.processArguments(buffer.toList(), true);
- interpreterLoop.process(settings);
- }
-}
Binary file not shown.
View
@@ -36,6 +36,7 @@
<orderEntry type="library" name="idea-full" level="project" />
<orderEntry type="library" name="community-plugins" level="project" />
<orderEntry type="library" name="nailgun" level="project" />
+ <orderEntry type="module" module-name="ScalaRunner" />
</component>
</module>
@@ -0,0 +1,34 @@
+package org.jetbrains.plugins.scala.worksheet
+
+import scala.reflect.macros.Context
+import scala.language.experimental.macros
+
+/**
+ * User: Dmitry Naydanov
+ * Date: 1/21/14
+ */
+object MacroPrinter {
+ def printDefInfo[T](toPrint: T) = macro printDefImpl[T]
+
+ def printTypeInfo[T] = macro printTypeInfoImpl[T]
+
+ /**
+ * Usage
+ * {{{
+ * printImportInfo({import java.io.File;})
+ * }}}
+ */
+ def printImportInfo[T](toPrint: T) = macro printImportInfoImpl[T]
+
+ def printDefImpl[T: c.WeakTypeTag](c: Context)(toPrint: c.Expr[T]) = c literal toPrint.tree.tpe.toString
+
+ def printTypeInfoImpl[T](c: Context)(implicit ev: c.WeakTypeTag[T]) = c literal ev.tpe.toString
+
+ def printImportInfoImpl[T: c.WeakTypeTag](c: Context)(toPrint: c.Expr[T]) = {
+ toPrint.tree match {
+ case c.universe.Block(imp, _) => c literal imp.head.toString()
+ }
+ }
+}
+
+class MacroPrinter {}
@@ -1,12 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
+ <component name="FacetManager">
+ <facet type="scala" name="Scala">
+ <configuration>
+ <option name="compilerLibraryLevel" value="Project" />
+ <option name="compilerLibraryName" value="main-scala-compiler" />
+ </configuration>
+ </facet>
+ </component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" scope="PROVIDED" name="main-scala-library" level="project" />
+ <orderEntry type="library" name="nailgun" level="project" />
+ <orderEntry type="library" scope="PROVIDED" name="idea-full" level="project" />
</component>
</module>
@@ -0,0 +1,42 @@
+package org.jetbrains.jps.incremental.scala
+
+import org.jetbrains.jps.incremental.messages.BuildMessage.Kind
+import java.io.File
+
+/**
+ * @author Pavel Fatin
+ */
+trait Client {
+ def message(kind: Kind, text: String, source: Option[File] = None, line: Option[Long] = None, column: Option[Long] = None)
+
+ def error(text: String, source: Option[File] = None, line: Option[Long] = None, column: Option[Long] = None) {
+ message(Kind.ERROR, text, source, line, column)
+ }
+
+ def warning(text: String, source: Option[File] = None, line: Option[Long] = None, column: Option[Long] = None) {
+ message(Kind.WARNING, text, source, line, column)
+ }
+
+ def info(text: String, source: Option[File] = None, line: Option[Long] = None, column: Option[Long] = None) {
+ message(Kind.INFO, text, source, line, column)
+ }
+
+ def trace(exception: Throwable)
+
+ def progress(text: String, done: Option[Float] = None)
+
+ def debug(text: String)
+
+ def generated(source: File, module: File, name: String)
+
+ def processed(source: File)
+
+ def deleted(module: File)
+
+ def isCanceled: Boolean
+
+ def worksheetOutput(text: String) {}
+
+ def compilationEnd() {}
+}
+
Oops, something went wrong.

0 comments on commit 4aafb9b

Please sign in to comment.