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

Commit

Permalink
Fixes #640 Use spawn to handle big data from gocode (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a authored Nov 29, 2016
1 parent c967ca4 commit 4b57011
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/goSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,25 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider {
// are used as the target operating system and architecture. `gocode` is unable to provide
// autocompletion when the Go environment is configured for cross compilation.
let env = Object.assign({}, process.env, { GOOS: '', GOARCH: '' });
let stdout = '';
let stderr = '';

// Spawn `gocode` process
let p = cp.execFile(gocode, ['-f=json', 'autocomplete', filename, 'c' + offset], { env }, (err, stdout, stderr) => {
let p = cp.spawn(gocode, ['-f=json', 'autocomplete', filename, 'c' + offset], { env });
p.stdout.on('data', data => stdout += data);
p.stderr.on('data', data => stderr += data);
p.on('error', err => {
if (err && (<any>err).code === 'ENOENT') {
promptForMissingTool('gocode');
return reject();
}
return reject(err);
});
p.on('close', code => {
try {
if (err && (<any>err).code === 'ENOENT') {
promptForMissingTool('gocode');
if (code !== 0) {
return reject(stderr);
}
if (err) {
console.log(err);
return reject(err);
};
let results = <[number, GoCodeSuggestion[]]>JSON.parse(stdout.toString());
let suggestions = [];
let suggestionSet = new Set<string>();
Expand Down

0 comments on commit 4b57011

Please sign in to comment.