From 003cc1afb0bb7db45f3b92f466289934c7e4e6a9 Mon Sep 17 00:00:00 2001 From: Bruno Medeiros Date: Tue, 17 May 2016 19:30:55 +0100 Subject: [PATCH] gometalinter support, fixes #163 --- documentation/ChangeLog.md | 3 +- .../core/operations/GoBuildManager.java | 6 +-- .../lang/tooling/ops/BuildOutputParser.java | 2 +- .../tooling/GoBuildOutputProcessorTest.java | 39 ++++++++++++++----- .../tooling/GoBuildOutputProcessor.java | 28 ++++++++++--- 5 files changed, 56 insertions(+), 22 deletions(-) diff --git a/documentation/ChangeLog.md b/documentation/ChangeLog.md index 3bf2e3be2..fdd4c6ef2 100644 --- a/documentation/ChangeLog.md +++ b/documentation/ChangeLog.md @@ -8,7 +8,8 @@ It's now possible to specify a command other than the default one (the `go` tool * The default is `` for $$IDE * Added [Building](documentation/UserGuide.md#building) section to documentation. * The goal for the future is to enable invoking this command on-the-fly (as the user types), although for this to be useful in practice it will likely require the compiler to support incremental compilation (or be super fast otherwise). - * Added support for modifying the environment variables of a Build Target's build command. (fixes #191) + * Added support for modifying the environment variables of a Build Target's build command. (#191) + * Added support for lint build target, using `gometalinter`. (#163) * Fixed "IllegalStateException: The service has been unregistered" on Mars.2 when Eclipse is closed. * Fixed: Don't call editor save actions (such as `gofmt`) when Open Definition is requested. diff --git a/plugin_ide.core/src/com/googlecode/goclipse/core/operations/GoBuildManager.java b/plugin_ide.core/src/com/googlecode/goclipse/core/operations/GoBuildManager.java index 8b021882f..c12fe70a9 100644 --- a/plugin_ide.core/src/com/googlecode/goclipse/core/operations/GoBuildManager.java +++ b/plugin_ide.core/src/com/googlecode/goclipse/core/operations/GoBuildManager.java @@ -218,7 +218,7 @@ public String getDefaultCommandLine(BuildTarget bt) throws CommonException { @Override protected ArrayList2 getDefaultCommandArguments_list(BuildTarget bt) throws CommonException { - ArrayList2 commandLine = new ArrayList2<>("gometalinter"); + ArrayList2 commandLine = new ArrayList2<>("gometalinter", "-t"); addPackageSpecCommand(bt, commandLine); return commandLine; } @@ -346,10 +346,6 @@ public void execute(IOperationMonitor om) throws CommonException, OperationCance String goPackageToBuild = StringUtil.trimEnd(argumentsTemplate.get(lastArgIx), "..."); GoWorkspaceLocation goWorkspace = goEnv.getGoPath().findGoPathEntry(getProjectLocation()); -// GoPackageName baseGoPackage = goEnv.getGoPath().findGoPackageForLocation(getProjectLocation()); -// if(baseGoPackage != null) { -// goPackageToBuild = createResolvedPath(baseGoPackage.toString(), goPackageToBuild).toString(); -// } Collection2 sourcePackages = goWorkspace.findSubPackages(goPackageToBuild); for (GoPackageName goPackage : sourcePackages) { diff --git a/plugin_tooling/src-lang/melnorme/lang/tooling/ops/BuildOutputParser.java b/plugin_tooling/src-lang/melnorme/lang/tooling/ops/BuildOutputParser.java index ec94845e7..546e39814 100644 --- a/plugin_tooling/src-lang/melnorme/lang/tooling/ops/BuildOutputParser.java +++ b/plugin_tooling/src-lang/melnorme/lang/tooling/ops/BuildOutputParser.java @@ -124,7 +124,7 @@ protected ToolSourceMessage createMessage(ToolMessageData msgdata) throws Common Path filePath = parsePath(msgdata.pathString).normalize(); int lineNo = parsePositiveInt(msgdata.lineString); - int column = parseOptionalPositiveInt(msgdata.columnString); + int column = parseOptionalPositiveInt(StringUtil.emptyAsNull(msgdata.columnString)); int endline = parseOptionalPositiveInt(msgdata.endLineString); int endColumn = parseOptionalPositiveInt(msgdata.endColumnString); diff --git a/plugin_tooling/src-tests/com/googlecode/goclipse/tooling/GoBuildOutputProcessorTest.java b/plugin_tooling/src-tests/com/googlecode/goclipse/tooling/GoBuildOutputProcessorTest.java index 7c65f400b..0d0f55cfc 100644 --- a/plugin_tooling/src-tests/com/googlecode/goclipse/tooling/GoBuildOutputProcessorTest.java +++ b/plugin_tooling/src-tests/com/googlecode/goclipse/tooling/GoBuildOutputProcessorTest.java @@ -31,6 +31,10 @@ public class GoBuildOutputProcessorTest extends CommonGoToolingTest { protected static final Path BUILD_OUTPUT_TestResources = getTestResourcePath("buildOutput"); + protected static ToolSourceMessage warning(Path path, int line, int column, String errorMessage) { + return new ToolSourceMessage(path, new SourceLineColumnRange(line, column), Severity.WARNING, errorMessage); + } + protected static ToolSourceMessage error(Path path, int line, int column, String errorMessage) { return new ToolSourceMessage(path, new SourceLineColumnRange(line, column), Severity.ERROR, errorMessage); } @@ -57,18 +61,18 @@ protected void handleParseError(CommonException ce) { testParseError(buildProcessor, "asdfsdaf/asdfsd", listFrom()); - List OUTPUTA_Errors = listFrom( - error(path("MyGoLibFoo/libfoo/blah.go"), 7, -1, "undefined: asdfsd"), - error(path("MyGoLibFoo/libfoo/blah.go"), 10, -1, "not enough arguments in call to fmt.Printf"), - error(path("MyGoLibFoo/foo.go"), 3, -1, "undefined: ziggy"), - error(TR_SAMPLE_GOPATH_ENTRY.resolve_valid("src/samplePackage/foo.go").path, 5, -1, "undefined: ziggy2") - ); testParseError(buildProcessor, - readTemplatedFiled(BUILD_OUTPUT_TestResources.resolve("outputA.txt")), - OUTPUTA_Errors); + readTemplatedFile(BUILD_OUTPUT_TestResources.resolve("outputA.txt")), + + listFrom( + error(path("MyGoLibFoo/libfoo/blah.go"), 7, -1, "undefined: asdfsd"), + error(path("MyGoLibFoo/libfoo/blah.go"), 10, -1, "not enough arguments in call to fmt.Printf"), + error(path("MyGoLibFoo/foo.go"), 3, -1, "undefined: ziggy"), + error(TR_SAMPLE_GOPATH_ENTRY.resolve_valid("src/samplePackage/foo.go").path, 5, -1, "undefined: ziggy2") + )); - String OUTPUT_B = readTemplatedFiled(BUILD_OUTPUT_TestResources.resolve("outputB.txt")); + String OUTPUT_B = readTemplatedFile(BUILD_OUTPUT_TestResources.resolve("outputB.txt")); String errorMessage1 = findMatch(OUTPUT_B, "cannot find package \"xxx.*\\n.*\\n.*", 0).replace("\r", ""); String errorMessage2 = findMatch(OUTPUT_B, "cannot find package \"yyy.*\\n.*\\n.*", 0).replace("\r", ""); @@ -83,6 +87,21 @@ protected void handleParseError(CommonException ce) { testParseError(buildProcessor, OUTPUT_B, OUTPUTB_Errors); + + // Test gometalinter format + testParseError(buildProcessor, + "path/file:3:: ()"+"\n"+ + "path/file:3:10: ()"+"\n"+ + "path/file:4:11:warning: This is a warning!" + + , + listFrom( + error(path("path/file"), 3, -1, " ()"), + error(path("path/file"), 3, 10, " ()"), + warning(path("path/file"), 4, 11, "This is a warning!") + ) + ); + } protected void testParseError(GoBuildOutputProcessor buildProcessor, String stderr, List expected) @@ -91,7 +110,7 @@ protected void testParseError(GoBuildOutputProcessor buildProcessor, String stde assertEquals(buildProcessor.getBuildErrors(), expected); } - protected String readTemplatedFiled(Path filePath) { + protected String readTemplatedFile(Path filePath) { String fileContents = readStringFromFile(filePath); return fileContents.replaceAll( Pattern.quote("$$TESTRESOURCE_SAMPLE_GOPATH_ENTRY$$"), diff --git a/plugin_tooling/src/com/googlecode/goclipse/tooling/GoBuildOutputProcessor.java b/plugin_tooling/src/com/googlecode/goclipse/tooling/GoBuildOutputProcessor.java index ee0da797b..3bb4cbaa0 100644 --- a/plugin_tooling/src/com/googlecode/goclipse/tooling/GoBuildOutputProcessor.java +++ b/plugin_tooling/src/com/googlecode/goclipse/tooling/GoBuildOutputProcessor.java @@ -10,6 +10,7 @@ *******************************************************************************/ package com.googlecode.goclipse.tooling; +import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -20,6 +21,8 @@ import melnorme.lang.utils.parse.StringParseSource; import melnorme.utilbox.collections.ArrayList2; import melnorme.utilbox.core.CommonException; +import melnorme.utilbox.misc.StringUtil; +import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult; public abstract class GoBuildOutputProcessor extends BuildOutputParser { @@ -31,6 +34,13 @@ protected String getToolProcessName() { return "go build"; } + @Override + protected ArrayList doHandleProcessResult(ExternalProcessResult result) throws CommonException { + ArrayList msgs = parse(result.getStdErrBytes().toString(StringUtil.UTF8)); + msgs.addAll(parse(result.getStdOutBytes().toString(StringUtil.UTF8))); + return msgs; + } + public ArrayList2 getBuildErrors() { return buildMessages; } @@ -38,7 +48,8 @@ public ArrayList2 getBuildErrors() { protected static final Pattern ERROR_LINE_Regex = Pattern.compile( "^([^:\\n]*):" + // file "(\\d*):" + // line - "((\\d*):)?" + // column + "(\\d*)?(:)?" + // column + "((warning|error|info):)?" + // type "\\s(.*)$" // error message ); @@ -74,8 +85,9 @@ protected ToolMessageData parseMessageData(StringParseSource output) throws Comm msgData.pathString = pathDevicePrefix + matcher.group(1); msgData.lineString = matcher.group(2); - msgData.columnString = matcher.group(4); - msgData.messageText = matcher.group(5); + msgData.columnString = matcher.group(3); + msgData.messageTypeString = matcher.group(6); + msgData.messageText = matcher.group(7); while(true) { int readChar = output.lookahead(); @@ -87,9 +99,15 @@ protected ToolMessageData parseMessageData(StringParseSource output) throws Comm } } - msgData.messageTypeString = StatusLevel.ERROR.toString(); - return msgData; } + @Override + protected ToolSourceMessage createMessage(ToolMessageData msgdata) throws CommonException { + if(msgdata.messageTypeString == null) { + msgdata.messageTypeString = StatusLevel.ERROR.toString(); + } + return super.createMessage(msgdata); + } + } \ No newline at end of file