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

Commit

Permalink
Skip scope on guru when folder is not under GOPATH #1545 #1554
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Mar 4, 2018
1 parent 7304f71 commit 6a97c1b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/goImplementations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import vscode = require('vscode');
import cp = require('child_process');
import path = require('path');
import { byteOffsetAt, getBinPath, canonicalizeGOPATHPrefix } from './util';
import { byteOffsetAt, getBinPath, canonicalizeGOPATHPrefix, getWorkspaceFolderPath } from './util';
import { promptForMissingTool } from './goInstallTools';
import { getToolsEnvVars } from './util';
import { getGoRuntimePath } from './goPath';

interface GoListOutput {
Dir: string;
ImportPath: string;
Root: string;
}

interface GuruImplementsRef {
Expand All @@ -31,15 +32,12 @@ export class GoImplementationProvider implements vscode.ImplementationProvider {
public provideImplementation(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Thenable<vscode.Definition> {
// To keep `guru implements` fast we want to restrict the scope of the search to current workpsace
// If no workpsace is open, then no-op
let root = vscode.workspace.rootPath;
if (vscode.workspace.getWorkspaceFolder(document.uri)) {
root = vscode.workspace.getWorkspaceFolder(document.uri).uri.fsPath;
}
const root = getWorkspaceFolderPath(document.uri);
if (!root) {
vscode.window.showInformationMessage('Cannot find implementations when there is no workspace open.');
return;
}

return new Promise<vscode.Definition>((resolve, reject) => {
if (token.isCancellationRequested) {
return resolve(null);
Expand All @@ -50,14 +48,16 @@ export class GoImplementationProvider implements vscode.ImplementationProvider {
return reject(err);
}
let listOutput = <GoListOutput>JSON.parse(stdout.toString());
let scope = listOutput.ImportPath;
let filename = canonicalizeGOPATHPrefix(document.fileName);
let cwd = path.dirname(filename);
let offset = byteOffsetAt(document, position);
let goGuru = getBinPath('guru');
const buildTags = vscode.workspace.getConfiguration('go', document.uri)['buildTags'];
let args = buildTags ? ['-tags', buildTags] : [];
args.push('-scope', `${scope}/...`, '-json', 'implements', `${filename}:#${offset.toString()}`);
if (listOutput.Root && listOutput.ImportPath) {
args.push('-scope', `${listOutput.ImportPath}/...`);
}
args.push('-json', 'implements', `${filename}:#${offset.toString()}`);

let guruProcess = cp.execFile(goGuru, args, { env }, (err, stdout, stderr) => {
if (err && (<any>err).code === 'ENOENT') {
Expand Down

0 comments on commit 6a97c1b

Please sign in to comment.