Skip to content

Commit

Permalink
Use the newly added receiver output from godef to get the correct doc…
Browse files Browse the repository at this point in the history
…umentation

See rogpeppe/godef#105

Part of microsoft#2107
  • Loading branch information
segevfiner committed Dec 31, 2018
1 parent 744bd83 commit a1f0200
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/goDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import vscode = require('vscode');
import cp = require('child_process');
import path = require('path');
import { byteOffsetAt, getBinPath, runGodoc, getWorkspaceFolderPath } from './util';
import { promptForMissingTool } from './goInstallTools';
import { promptForMissingTool, promptForUpdatingTool } from './goInstallTools';
import { getGoVersion, SemVersion, goKeywords, isPositionInString, getToolsEnvVars, getFileArchive, killProcess } from './util';
import { isModSupported, promptToUpdateToolForModules } from './goModules';

Expand Down Expand Up @@ -95,12 +95,15 @@ function definitionLocation_godef(input: GoDefinitionInput, token: vscode.Cancel

return new Promise<GoDefinitionInformation>((resolve, reject) => {
// Spawn `godef` process
p = cp.execFile(godefPath, ['-t', '-i', '-f', input.document.fileName, '-o', offset.toString()], { env, cwd }, (err, stdout, stderr) => {
p = cp.execFile(godefPath, ['-t', '-r', '-i', '-f', input.document.fileName, '-o', offset.toString()], { env, cwd }, (err, stdout, stderr) => {
try {
if (err && (<any>err).code === 'ENOENT') {
return reject(missingToolMsg + godefTool);
}
if (err) {
if (stderr.indexOf('flag provided but not defined: -r') !== -1) {
promptForUpdatingTool('godef');
}
return reject(err.message || stderr);
}
let result = stdout.toString();
Expand All @@ -117,17 +120,16 @@ function definitionLocation_godef(input: GoDefinitionInput, token: vscode.Cancel
file: file,
line: +line - 1,
column: + col - 1,
declarationlines: lines.splice(1),
declarationlines: lines.slice(1),
toolUsed: 'godef',
doc: null,
name: null
};
if (!input.includeDocs || godefImportDefinitionRegex.test(definitionInformation.declarationlines[0])) {
return resolve(definitionInformation);
}
// TODO #2107 Once godef supports printing method receivers we should pass
// the receiver to runGodoc
runGodoc(pkgPath, '', input.word, token).then(doc => {
match = /^\w+ \(\*?(\w+)\)/.exec(lines[1]);
runGodoc(pkgPath, match ? match[1] : '', input.word, token).then(doc => {
if (doc) {
definitionInformation.doc = doc;
}
Expand Down

0 comments on commit a1f0200

Please sign in to comment.