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

Fixes #640 Use spawn to handle big data from gocode #661

Merged
merged 1 commit into from
Nov 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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