From 744bd83e7e856b9df2281bbe89ce07d57fcd977b Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Wed, 26 Dec 2018 21:10:48 +0200 Subject: [PATCH] Use the newly added receiver output from gocode to get the correct documentation See https://github.com/mdempsky/gocode/commit/be056ad32a5e9e6b0f640e650319100c464e19a7 Part of #2107 --- src/goDeclaration.ts | 6 ++++-- src/goSuggest.ts | 5 ++++- src/util.ts | 7 ++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/goDeclaration.ts b/src/goDeclaration.ts index 4c95a68d5..43dd0e254 100644 --- a/src/goDeclaration.ts +++ b/src/goDeclaration.ts @@ -125,7 +125,9 @@ function definitionLocation_godef(input: GoDefinitionInput, token: vscode.Cancel if (!input.includeDocs || godefImportDefinitionRegex.test(definitionInformation.declarationlines[0])) { return resolve(definitionInformation); } - runGodoc(pkgPath, input.word, token).then(doc => { + // TODO #2107 Once godef supports printing method receivers we should pass + // the receiver to runGodoc + runGodoc(pkgPath, '', input.word, token).then(doc => { if (doc) { definitionInformation.doc = doc; } @@ -305,4 +307,4 @@ interface GoGetDocOuput { interface GuruDefinitionOuput { objpos: string; desc: string; -} \ No newline at end of file +} diff --git a/src/goSuggest.ts b/src/goSuggest.ts index e19a63bb0..824e9cbcc 100644 --- a/src/goSuggest.ts +++ b/src/goSuggest.ts @@ -44,10 +44,12 @@ interface GoCodeSuggestion { package?: string; name: string; type: string; + receiver?: string; } class ExtendedCompletionItem extends vscode.CompletionItem { package?: string; + receiver?: string; fileName: string; } @@ -94,7 +96,7 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider, return; } - return runGodoc(item.package || path.dirname(item.fileName), item.label, token).then(doc => { + return runGodoc(item.package || path.dirname(item.fileName), item.receiver, item.label, token).then(doc => { item.documentation = new vscode.MarkdownString(doc); return item; }).catch(err => { @@ -283,6 +285,7 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider, let item = new ExtendedCompletionItem(suggest.name); item.kind = vscodeKindFromGoCodeClass(suggest.class, suggest.type); item.package = suggest.package; + item.receiver = suggest.receiver; item.fileName = document.fileName; item.detail = suggest.type; if (suggest.class === 'package') { diff --git a/src/util.ts b/src/util.ts index 6d0171cfd..c8de20829 100644 --- a/src/util.ts +++ b/src/util.ts @@ -892,7 +892,7 @@ export function cleanupTempDir() { * @param symbol Symbol for which docs need to be found * @param token Cancellation token */ -export function runGodoc(packagePath: string, symbol: string, token: vscode.CancellationToken) { +export function runGodoc(packagePath: string, receiver: string, symbol: string, token: vscode.CancellationToken) { if (!packagePath) { return Promise.reject(new Error('Package Path not provided')); } @@ -908,6 +908,11 @@ export function runGodoc(packagePath: string, symbol: string, token: vscode.Canc const getCurrentPackagePromise = path.isAbsolute(packagePath) ? getCurrentPackage(packagePath) : Promise.resolve(packagePath); return getCurrentPackagePromise.then(packageImportPath => { return new Promise((resolve, reject) => { + if (receiver) { + receiver = receiver.replace(/^\*/, ''); + symbol = receiver + '.' + symbol; + } + const env = getToolsEnvVars(); const args = ['doc', '-c', '-cmd', '-u', packageImportPath, symbol]; const p = cp.execFile(goRuntimePath, args, { env }, (err, stdout, stderr) => {