From 174e74364b1b5647394b5552f32c65a45f79601d Mon Sep 17 00:00:00 2001 From: Bruno Medeiros Date: Tue, 21 Jun 2016 18:07:14 +0100 Subject: [PATCH] Fix handling of godef result, use correct source truth. --- .../tooling/oracle/GoOperationContext.java | 4 +++ .../tools/GoFindDefinitionOperation.java | 4 +++ .../tooling/tools/GoFindDocOperation.java | 26 +++---------------- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/plugin_tooling/src/com/googlecode/goclipse/tooling/oracle/GoOperationContext.java b/plugin_tooling/src/com/googlecode/goclipse/tooling/oracle/GoOperationContext.java index 4bd9e5e6c..eab3da852 100644 --- a/plugin_tooling/src/com/googlecode/goclipse/tooling/oracle/GoOperationContext.java +++ b/plugin_tooling/src/com/googlecode/goclipse/tooling/oracle/GoOperationContext.java @@ -45,6 +45,10 @@ public ISourceBuffer getSourceBuffer() { return sourceBuffer; } + public SourceOpContext getOpContext() { + return opContext; + } + public IToolOperationService getToolOpService() { return toolOpService; } diff --git a/plugin_tooling/src/com/googlecode/goclipse/tooling/tools/GoFindDefinitionOperation.java b/plugin_tooling/src/com/googlecode/goclipse/tooling/tools/GoFindDefinitionOperation.java index 2726eb09f..b4da44b95 100644 --- a/plugin_tooling/src/com/googlecode/goclipse/tooling/tools/GoFindDefinitionOperation.java +++ b/plugin_tooling/src/com/googlecode/goclipse/tooling/tools/GoFindDefinitionOperation.java @@ -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 { diff --git a/plugin_tooling/src/com/googlecode/goclipse/tooling/tools/GoFindDocOperation.java b/plugin_tooling/src/com/googlecode/goclipse/tooling/tools/GoFindDocOperation.java index e919fbd10..abbeb631d 100644 --- a/plugin_tooling/src/com/googlecode/goclipse/tooling/tools/GoFindDocOperation.java +++ b/plugin_tooling/src/com/googlecode/goclipse/tooling/tools/GoFindDocOperation.java @@ -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 { @@ -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()); - } - } } \ No newline at end of file