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

Commit

Permalink
Allow changing package-lookup-mode in gocode #547
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Nov 10, 2017
1 parent a0a8a9d commit 0eb7308
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,16 @@
"description": "Enable gocode's autobuild feature",
"scope": "resource"
},
"go.gocodePackageLookupMode": {
"type": "string",
"enum": [
"go",
"gb"
],
"default": "go",
"description": "If go, use standard Go package lookup rules for completions. If gb, use gb-specific lookup rules for completions",
"scope": "resource"
},
"go.useCodeSnippetsOnFunctionSuggest": {
"type": "boolean",
"default": false,
Expand Down
40 changes: 32 additions & 8 deletions src/goSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider {
param = param.replace('${', '\\${').replace('}', '\\}');
if (conf.get('useCodeSnippetsOnFunctionSuggestWithoutType')) {
if (param.includes(' ')) {
// Separate the variable name from the type
param = param.substr(0, param.indexOf(' '));
// Separate the variable name from the type
param = param.substr(0, param.indexOf(' '));
}
}
paramSnippets.push('${' + (i + 1) + ':' + param + '}');
Expand Down Expand Up @@ -219,19 +219,43 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider {
// TODO: Shouldn't lib-path also be set?
private ensureGoCodeConfigured(): Thenable<void> {
let setPkgsList = getImportablePackages(vscode.window.activeTextEditor.document.fileName, true).then(pkgMap => this.pkgsList = pkgMap);
// let setPkgsList = Promise.race([timeout(1000).then(() => this.pkgsList), importablePkgsPromise]);

let setGocodeProps = new Promise<void>((resolve, reject) => {
let gocode = getBinPath('gocode');
let autobuild = vscode.workspace.getConfiguration('go', vscode.window.activeTextEditor ? vscode.window.activeTextEditor.document.uri : null)['gocodeAutoBuild'];
let goConfig = vscode.workspace.getConfiguration('go', vscode.window.activeTextEditor ? vscode.window.activeTextEditor.document.uri : null);
let env = getToolsEnvVars();
cp.execFile(gocode, ['set', 'propose-builtins', 'true'], { env }, (err, stdout, stderr) => {
cp.execFile(gocode, ['set', 'autobuild', autobuild], {}, (err, stdout, stderr) => {

cp.execFile(gocode, ['set'], { env }, (err, stdout, stderr) => {
const existingOptions = stdout.split(/\r\n|\n/);
const optionsToSet: string[][] = [];
const setOption = () => {
const [name, value] = optionsToSet.pop();
cp.execFile(gocode, ['set', name, value], { env }, (err, stdout, stderr) => {
if (optionsToSet.length) {
setOption();
} else {
resolve();
}
});
};

if (existingOptions.indexOf('propose-builtins true') === -1) {
optionsToSet.push(['propose-builtins', 'true']);
}
if (existingOptions.indexOf(`autobuild ${goConfig['gocodeAutoBuild']}`) === -1) {
optionsToSet.push(['autobuild', goConfig['gocodeAutoBuild']]);
}
if (existingOptions.indexOf(`package-lookup-mode ${goConfig['gocodePackageLookupMode']}`) === -1) {
optionsToSet.push(['package-lookup-mode', goConfig['gocodePackageLookupMode']]);
}
if (!optionsToSet.length) {
return resolve();
});
}

setOption();
});
});
// return setGocodeProps;

return Promise.all([setPkgsList, setGocodeProps]).then(() => {
return;
});
Expand Down

0 comments on commit 0eb7308

Please sign in to comment.