From 467aa455740bcffe16f8cd660f4f8683356e1bf8 Mon Sep 17 00:00:00 2001 From: Alexandra Dima Date: Wed, 10 Jul 2019 17:18:03 +0200 Subject: Fixed compilation error, removed print statements and unnecessary code. --- .../src/mill/contrib/bsp/BspLoggedReporter.scala | 4 - .../bsp/src/mill/contrib/bsp/MillBuildServer.scala | 109 +-------------------- main/core/src/eval/Evaluator.scala | 2 - 3 files changed, 1 insertion(+), 114 deletions(-) diff --git a/contrib/bsp/src/mill/contrib/bsp/BspLoggedReporter.scala b/contrib/bsp/src/mill/contrib/bsp/BspLoggedReporter.scala index 31900211..4bc94b41 100644 --- a/contrib/bsp/src/mill/contrib/bsp/BspLoggedReporter.scala +++ b/contrib/bsp/src/mill/contrib/bsp/BspLoggedReporter.scala @@ -20,9 +20,7 @@ class BspLoggedReporter(client: bsp.BuildClient, override def logError(problem: Problem): Unit = { client.onBuildPublishDiagnostics(getDiagnostics(problem, targetId, compilationOriginId)) - println("Sent diagnostics to the client") super.logError(problem) - println("Logged the error") } override def logInfo(problem: Problem): Unit = { @@ -37,7 +35,6 @@ class BspLoggedReporter(client: bsp.BuildClient, def getDiagnostics(problem: Problem, targetId: bsp.BuildTargetIdentifier, originId: Option[String]): bsp.PublishDiagnosticsParams = { - println("Problem: " + problem) val sourceFile = problem.position().sourceFile().asScala val start = new bsp.Position( problem.position.startLine.asScala.getOrElse(0), @@ -60,7 +57,6 @@ class BspLoggedReporter(client: bsp.BuildClient, targetId, List(diagnostic).asJava, true) if (originId.nonEmpty) { params.setOriginId(originId.get) } - println("Diagnostics: " + params) params } diff --git a/contrib/bsp/src/mill/contrib/bsp/MillBuildServer.scala b/contrib/bsp/src/mill/contrib/bsp/MillBuildServer.scala index 5d79ee76..add5da5a 100644 --- a/contrib/bsp/src/mill/contrib/bsp/MillBuildServer.scala +++ b/contrib/bsp/src/mill/contrib/bsp/MillBuildServer.scala @@ -223,107 +223,7 @@ class MillBuildServer(evaluator: Evaluator, future.complete(getResources) future } - - private[this] def getErrorCode(file: File, start: bsp.Position, end: bsp.Position): String = { - - val source = Source.fromFile(file) - source.close() - val lines = source.getLines.toSeq - val code = lines(start.getLine).substring(start.getCharacter) + - lines.take(start.getLine - 1).takeRight(lines.length - end.getLine - 1).mkString("\n") + - lines(end.getLine).substring(0, end.getCharacter + 1) - code - } - - def getDiagnosticsFromFile(analysisFile: os.Path, targetId: BuildTargetIdentifier, originId: Option[String]): - Seq[PublishDiagnosticsParams] = { - val analysisStore: AnalysisStore = FileAnalysisStore.getDefault(analysisFile.toIO) - analysisStore.get.asScala match { - case contents: AnalysisContents => - val sourceInfoMap: Map[File, SourceInfo] = contents.getAnalysis.readSourceInfos.getAllSourceInfos.asScala - var diagnosticsParams = Seq.empty[PublishDiagnosticsParams] - for ( (file, sourceInfo) <- sourceInfoMap) { - var diagnostics = List.empty[Diagnostic] - for (problem <- sourceInfo.getReportedProblems) { - val start = new bsp.Position( - problem.position.startLine.asScala.getOrElse(0), - problem.position.startOffset.asScala.getOrElse(0)) - val end = new bsp.Position( - problem.position.endLine.asScala.getOrElse(0), - problem.position.endOffset.asScala.getOrElse(0)) - val diagnostic = new Diagnostic(new Range(start, end), problem.message) - diagnostic.setCode(getErrorCode(file, start, end)) - diagnostic.setSource("compiler from mill") - - diagnostic.setSeverity( problem.severity match { - case Severity.Info => DiagnosticSeverity.INFORMATION - case Severity.Error => DiagnosticSeverity.ERROR - case Severity.Warn => DiagnosticSeverity.WARNING - } - ) - diagnostics ++= List(diagnostic) - } - val params = new PublishDiagnosticsParams(new TextDocumentIdentifier(file.toURI.toString), - targetId, diagnostics.asJava, true) - if (originId.nonEmpty) { params.setOriginId(originId.get) } - diagnosticsParams ++= Seq(params) - } - diagnosticsParams - case None => Seq.empty[PublishDiagnosticsParams] - } - } - - def getSourceFileCompileErrors(problems: Seq[Problem]): Map[File, Array[Problem]] = { - val problemsMap = Map.empty[File, Array[Problem]] - - for (problem <- problems) { - try { - val sourceFile = problem.position.sourceFile.get - if (problemsMap.contains(sourceFile)) { - problemsMap(sourceFile) = problemsMap(sourceFile) ++ Array(problem) - } else { - problemsMap(sourceFile) = Array(problem) - } - - } catch { - case e: Exception => - } - } - problemsMap - } - - def getDiagnostics(problems: Array[Problem], targetId: BuildTargetIdentifier, originId: Option[String]): - Seq[PublishDiagnosticsParams] = { - var diagnosticsParams = Seq.empty[PublishDiagnosticsParams] - for (( sourceFile, problems ) <- getSourceFileCompileErrors(problems)) { - var diagnostics = Seq.empty[Diagnostic] - for (problem <- problems) { - val start = new bsp.Position( - problem.position.startLine.asScala.getOrElse(0), - problem.position.startOffset.asScala.getOrElse(0)) - val end = new bsp.Position( - problem.position.endLine.asScala.getOrElse(0), - problem.position.endOffset.asScala.getOrElse(0)) - val diagnostic = new Diagnostic(new Range(start, end), problem.message) - diagnostic.setCode(getErrorCode(sourceFile, start, end)) - diagnostic.setSource("compiler from mill") - diagnostic.setSeverity( problem.severity match { - case Severity.Info => DiagnosticSeverity.INFORMATION - case Severity.Error => DiagnosticSeverity.ERROR - case Severity.Warn => DiagnosticSeverity.WARNING - } - ) - diagnostics ++= List(diagnostic) - } - val params = new PublishDiagnosticsParams(new TextDocumentIdentifier(sourceFile.toPath.toAbsolutePath.toUri.toString), - targetId, diagnostics.asJava, true) - - if (originId.nonEmpty) { params.setOriginId(originId.get) } - diagnosticsParams ++= Seq(params) - } - diagnosticsParams - } - + def getOriginId(params: CompileParams): Option[String] = { try { Option(params.getOriginId) @@ -332,13 +232,6 @@ class MillBuildServer(evaluator: Evaluator, } } - def sendCompilationDiagnostics(problems: Array[Problem], targetId: BuildTargetIdentifier, compileParams: CompileParams) = { - for (publishDiagnosticsParams <- - getDiagnostics(problems, targetId, getOriginId(compileParams))) { - client.onBuildPublishDiagnostics(publishDiagnosticsParams) - } - } - def getCompilationLogger: ManagedLogger = { val consoleAppender = MainAppender.defaultScreen(ConsoleOut.printStreamOut( mill.util.DummyLogger.outputStream diff --git a/main/core/src/eval/Evaluator.scala b/main/core/src/eval/Evaluator.scala index 22132a8f..99befd0d 100644 --- a/main/core/src/eval/Evaluator.scala +++ b/main/core/src/eval/Evaluator.scala @@ -20,7 +20,6 @@ case class Labelled[T](task: NamedTask[T], segments: Segments){ def format = task match{ case t: Target[T] => Some(t.readWrite.asInstanceOf[upickle.default.ReadWriter[T]]) - case t: PersistentArgs[T] => Some(t.readWrite.asInstanceOf[upickle.default.ReadWriter[T]]) case _ => None } def writer = task match{ @@ -330,7 +329,6 @@ case class Evaluator(home: os.Path, env, reporter //new ManagedLoggedReporter(10, logger) ) - println("Reporter: " + reporter) val out = System.out val in = System.in val err = System.err -- cgit v1.2.3