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

WIP: Suggestion to expand func types to func snippets (#1553) #1560

Merged
merged 1 commit into from
May 13, 2018
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
17 changes: 17 additions & 0 deletions src/goSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,23 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider {
}
item.insertText = new vscode.SnippetString(suggest.name + '(' + paramSnippets.join(', ') + ')');
}
if (conf.get('useCodeSnippetsOnFunctionSuggest') && suggest.class === 'type' && suggest.type.startsWith('func(')) {
let params = parameters(suggest.type.substring(4));
let paramSnippets = [];
for (let i = 0; i < params.length; i++) {
let param = params[i].trim();
if (param) {
param = param.replace('${', '\\${').replace('}', '\\}');
if (!param.includes(' ')) {
// If we don't have an argument name, we need to create one
param = 'arg' + (i + 1) + ' ' + param;
}
let arg = param.substr(0, param.indexOf(' '));
paramSnippets.push('${' + (i + 1) + ':' + arg + '}' + param.substr(param.indexOf(' '), param.length));
}
}
item.insertText = new vscode.SnippetString(suggest.name + '(func(' + paramSnippets.join(', ') + ') {\n $' + (params.length + 1) + '\n})');
}

if (wordAtPosition && wordAtPosition.start.character === 0 &&
suggest.class === 'type' && !goBuiltinTypes.has(suggest.name)) {
Expand Down