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

Commit

Permalink
Fix handling of godef result, use correct source truth.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Jun 21, 2016
1 parent c287d50 commit 174e743
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public ISourceBuffer getSourceBuffer() {
return sourceBuffer;
}

public SourceOpContext getOpContext() {
return opContext;
}

public IToolOperationService getToolOpService() {
return toolOpService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public GoFindDefinitionOperation(GoOperationContext goOpContext) {
this.goOpContext = assertNotNull(goOpContext);
}

public GoOperationContext getGoOpContext() {
return goOpContext;
}

public SourceLocation getValidResult(IOperationMonitor om)
throws CommonException, OperationCancellation, OperationSoftFailure {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,15 @@

import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;

import java.io.IOException;

import com.googlecode.goclipse.tooling.oracle.GoDocParser;

import melnorme.lang.tooling.common.SourceLineColumnRange;
import melnorme.lang.tooling.common.ops.IOperationMonitor;
import melnorme.lang.tooling.parser.SourceLinesInfo;
import melnorme.lang.tooling.toolchain.ops.AbstractToolOperation;
import melnorme.lang.tooling.toolchain.ops.OperationSoftFailure;
import melnorme.lang.tooling.toolchain.ops.SourceLocation;
import melnorme.lang.tooling.toolchain.ops.SourceOpContext;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.FileUtil;
import melnorme.utilbox.misc.Location;
import melnorme.utilbox.misc.StringUtil;

public class GoFindDocOperation implements AbstractToolOperation<String> {

Expand All @@ -46,23 +40,11 @@ public String executeToolOperation(IOperationMonitor om) throws CommonException,
return null; // No documentation will be available
}

/* FIXME: review this code */
String fileContents = readFileContents(findDefResult.getFileLocation());
SourceLinesInfo linesInfo = new SourceLinesInfo(fileContents);

SourceLineColumnRange sourceLCRange = findDefResult.getSourceRange();
int offset = linesInfo.getOffsetForLine(sourceLCRange.getValidLineIndex()) + sourceLCRange.getValidColumnIndex();
SourceOpContext opContext = findDefOp.getGoOpContext().getOpContext();
String fileContents = opContext.getSourceFor(findDefResult.getFileLocation());
int offset = opContext.getOffsetFor(findDefResult);

return new GoDocParser().parseDocForDefinitionAt(fileContents, offset);
}

public static String readFileContents(Location location) throws CommonException {
try {
// TODO: we might need to do auto-detect of encoding.
return FileUtil.readStringFromFile(location.toPath(), StringUtil.UTF8);
} catch(IOException e) {
throw new CommonException(e.getMessage(), e.getCause());
}
}

}

0 comments on commit 174e743

Please sign in to comment.