Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
gometalinter support, fixes #163
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed May 17, 2016
1 parent 4fe88e1 commit 003cc1a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 22 deletions.
3 changes: 2 additions & 1 deletion documentation/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public String getDefaultCommandLine(BuildTarget bt) throws CommonException {

@Override
protected ArrayList2<String> getDefaultCommandArguments_list(BuildTarget bt) throws CommonException {
ArrayList2<String> commandLine = new ArrayList2<>("gometalinter");
ArrayList2<String> commandLine = new ArrayList2<>("gometalinter", "-t");
addPackageSpecCommand(bt, commandLine);
return commandLine;
}
Expand Down Expand Up @@ -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<GoPackageName> sourcePackages = goWorkspace.findSubPackages(goPackageToBuild);

for (GoPackageName goPackage : sourcePackages) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -57,18 +61,18 @@ protected void handleParseError(CommonException ce) {
testParseError(buildProcessor, "asdfsdaf/asdfsd", listFrom());


List<ToolSourceMessage> 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", "");
Expand All @@ -83,6 +87,21 @@ protected void handleParseError(CommonException ce) {
testParseError(buildProcessor,
OUTPUT_B,
OUTPUTB_Errors);

// Test gometalinter format
testParseError(buildProcessor,
"path/file:3:: <message> (<linter>)"+"\n"+
"path/file:3:10: <message> (<linter>)"+"\n"+
"path/file:4:11:warning: This is a warning!"

,
listFrom(
error(path("path/file"), 3, -1, "<message> (<linter>)"),
error(path("path/file"), 3, 10, "<message> (<linter>)"),
warning(path("path/file"), 4, 11, "This is a warning!")
)
);

}

protected void testParseError(GoBuildOutputProcessor buildProcessor, String stderr, List<?> expected)
Expand All @@ -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$$"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*******************************************************************************/
package com.googlecode.goclipse.tooling;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -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 {

Expand All @@ -31,14 +34,22 @@ protected String getToolProcessName() {
return "go build";
}

@Override
protected ArrayList<ToolSourceMessage> doHandleProcessResult(ExternalProcessResult result) throws CommonException {
ArrayList<ToolSourceMessage> msgs = parse(result.getStdErrBytes().toString(StringUtil.UTF8));
msgs.addAll(parse(result.getStdOutBytes().toString(StringUtil.UTF8)));
return msgs;
}

public ArrayList2<ToolSourceMessage> getBuildErrors() {
return buildMessages;
}

protected static final Pattern ERROR_LINE_Regex = Pattern.compile(
"^([^:\\n]*):" + // file
"(\\d*):" + // line
"((\\d*):)?" + // column
"(\\d*)?(:)?" + // column
"((warning|error|info):)?" + // type
"\\s(.*)$" // error message
);

Expand Down Expand Up @@ -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();
Expand All @@ -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);
}

}

0 comments on commit 003cc1a

Please sign in to comment.