Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Use the newly added receiver output from gocode to get the correct do…
Browse files Browse the repository at this point in the history
…cumentation (#2215)

See mdempsky/gocode@be056ad

Part of #2107
  • Loading branch information
segevfiner authored and ramya-rao-a committed Jan 8, 2019
1 parent 9943ca1 commit d9f1335
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/goDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -307,4 +309,4 @@ interface GoGetDocOuput {
interface GuruDefinitionOuput {
objpos: string;
desc: string;
}
}
5 changes: 4 additions & 1 deletion src/goSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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') {
Expand Down
7 changes: 6 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand All @@ -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<string>((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) => {
Expand Down

0 comments on commit d9f1335

Please sign in to comment.