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

Commit

Permalink
Show error in references codelens instead of 0 Fixes #1336
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Nov 15, 2017
1 parent 6650260 commit 68a8d1f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
19 changes: 11 additions & 8 deletions src/goReferences.ts
Expand Up @@ -19,30 +19,33 @@ export class GoReferenceProvider implements vscode.ReferenceProvider {

private doFindReferences(document: vscode.TextDocument, position: vscode.Position, options: { includeDeclaration: boolean }, token: vscode.CancellationToken): Thenable<vscode.Location[]> {
return new Promise<vscode.Location[]>((resolve, reject) => {
let filename = canonicalizeGOPATHPrefix(document.fileName);
let cwd = path.dirname(filename);

// get current word
let wordRange = document.getWordRangeAtPosition(position);
if (!wordRange) {
return resolve([]);
}

let goGuru = getBinPath('guru');
if (!path.isAbsolute(goGuru)) {
promptForMissingTool('guru');
return reject('Cannot find tool "guru" to find references.');
}

let filename = canonicalizeGOPATHPrefix(document.fileName);
let cwd = path.dirname(filename);
let offset = byteOffsetAt(document, position);
let env = getToolsEnvVars();
let goGuru = getBinPath('guru');
let buildTags = '"' + vscode.workspace.getConfiguration('go', document.uri)['buildTags'] + '"';

let process = cp.execFile(goGuru, ['-modified', '-tags', buildTags, 'referrers', `${filename}:#${offset.toString()}`], {env}, (err, stdout, stderr) => {
let process = cp.execFile(goGuru, ['-modified', '-tags', buildTags, 'referrers', `${filename}:#${offset.toString()}`], { env }, (err, stdout, stderr) => {
try {
if (err && (<any>err).code === 'ENOENT') {
promptForMissingTool('guru');
return resolve([]);
return reject('Cannot find tool "guru" to find references.')
}

if (err && (<any>err).killed !== true) {
console.log(err);
return resolve([]);
return reject(`Error running guru: ${err.message || stderr}`);
}

let lines = stdout.toString().split('\n');
Expand Down
28 changes: 14 additions & 14 deletions src/goReferencesCodelens.ts
Expand Up @@ -56,20 +56,20 @@ export class GoReferencesCodeLensProvider extends GoBaseCodeLensProvider {
};
let referenceProvider = new GoReferenceProvider();
return referenceProvider.provideReferences(codeLens.document, codeLens.range.start, options, token).then(references => {
if (references) {
codeLens.command = {
title: references.length === 1
? '1 reference'
: references.length + ' references',
command: 'editor.action.showReferences',
arguments: [codeLens.document.uri, codeLens.range.start, references]
};
} else {
codeLens.command = {
title: 'No references found',
command: ''
};
}
codeLens.command = {
title: references.length === 1
? '1 reference'
: references.length + ' references',
command: 'editor.action.showReferences',
arguments: [codeLens.document.uri, codeLens.range.start, references]
};
return codeLens;
}, err => {
console.log(err);
codeLens.command = {
title: 'Error finding references',
command: ''
};
return codeLens;
});
}
Expand Down

0 comments on commit 68a8d1f

Please sign in to comment.