in src/language/legacy/goDeclaration.ts [220:292]
function definitionLocation_gogetdoc(
input: GoDefinitionInput,
token: vscode.CancellationToken,
useTags: boolean
): Promise<GoDefinitionInformation | null> {
const gogetdoc = getBinPath('gogetdoc');
if (!path.isAbsolute(gogetdoc)) {
return Promise.reject(missingToolMsg + 'gogetdoc');
}
const offset = byteOffsetAt(input.document, input.position);
const env = toolExecutionEnvironment();
let p: cp.ChildProcess | null | undefined;
if (token) {
token.onCancellationRequested(() => p && killProcessTree(p));
}
return new Promise((resolve, reject) => {
const gogetdocFlagsWithoutTags = [
'-u',
'-json',
'-modified',
'-pos',
input.document.fileName + ':#' + offset.toString()
];
const buildTags = getGoConfig(input.document.uri)['buildTags'];
const gogetdocFlags =
buildTags && useTags ? [...gogetdocFlagsWithoutTags, '-tags', buildTags] : gogetdocFlagsWithoutTags;
p = cp.execFile(gogetdoc, gogetdocFlags, { env, cwd: input.cwd }, (err, stdout, stderr) => {
try {
if (err && (<any>err).code === 'ENOENT') {
return reject(missingToolMsg + 'gogetdoc');
}
if (stderr && stderr.startsWith('flag provided but not defined: -tags')) {
p = null;
return definitionLocation_gogetdoc(input, token, false).then(resolve, reject);
}
if (err) {
if (input.isMod && !input.includeDocs && stdout.startsWith("gogetdoc: couldn't get package for")) {
promptToUpdateToolForModules(
'gogetdoc',
'To get the Go to Definition feature when using Go modules, please update your version of the "gogetdoc" tool.'
);
return resolve(null);
}
return reject(err.message || stderr);
}
const goGetDocOutput = <GoGetDocOuput>JSON.parse(stdout.toString());
const match = /(.*):(\d+):(\d+)/.exec(goGetDocOutput.pos);
const definitionInfo: GoDefinitionInformation = {
file: undefined,
line: 0,
column: 0,
toolUsed: 'gogetdoc',
declarationlines: goGetDocOutput.decl.split('\n'),
doc: goGetDocOutput.doc,
name: goGetDocOutput.name
};
if (!match) {
return resolve(definitionInfo);
}
definitionInfo.file = match[1];
definitionInfo.line = +match[2] - 1;
definitionInfo.column = +match[3] - 1;
return resolve(definitionInfo);
} catch (e) {
reject(e);
}
});
if (p.pid) {
p.stdin?.end(getFileArchive(input.document));
}
});
}