|
| 1 | +import * as monaco from 'monaco-editor'; |
| 2 | + |
| 3 | +/* eslint-disable no-template-curly-in-string */ |
| 4 | + |
| 5 | +// Import aliases |
| 6 | +type CompletionList = monaco.languages.CompletionList; |
| 7 | +type CompletionContext = monaco.languages.CompletionContext; |
| 8 | +type ITextModel = monaco.editor.ITextModel; |
| 9 | +type Position = monaco.Position; |
| 10 | + |
| 11 | +/** |
| 12 | + * List of snippets for editor |
| 13 | + */ |
| 14 | +const snippets = [ |
| 15 | + { |
| 16 | + label: 'iferr', |
| 17 | + insertText: [ |
| 18 | + 'if err != nil {', |
| 19 | + '\treturn ${1:nil, err}', |
| 20 | + '}' |
| 21 | + ].join('\n'), |
| 22 | + documentation: 'Return error if err != nil' |
| 23 | + }, |
| 24 | + { |
| 25 | + label: 'switch', |
| 26 | + insertText: [ |
| 27 | + "switch ${1:expression} {", |
| 28 | + "\tcase ${2:match}:", |
| 29 | + "\t\t$0", |
| 30 | + "\tdefault:", |
| 31 | + "\t\t// TODO: implement", |
| 32 | + "}", |
| 33 | + ].join('\n'), |
| 34 | + documentation: 'Insert switch statement' |
| 35 | + }, |
| 36 | + { |
| 37 | + label: 'go', |
| 38 | + insertText: [ |
| 39 | + "go func(){", |
| 40 | + "\t$0", |
| 41 | + "}()" |
| 42 | + ].join('\n'), |
| 43 | + documentation: 'Call goroutine' |
| 44 | + }, |
| 45 | + { |
| 46 | + label: 'append', |
| 47 | + insertText: "$1 = append($1, $0)", |
| 48 | + documentation: 'Append to slice' |
| 49 | + }, |
| 50 | + { |
| 51 | + label: 'typestruct', |
| 52 | + insertText: [ |
| 53 | + "type ${1:name} struct {", |
| 54 | + "\t$0", |
| 55 | + "}" |
| 56 | + ].join('\n'), |
| 57 | + documentation: 'Declare a struct' |
| 58 | + }, |
| 59 | + { |
| 60 | + label: 'typeinterface', |
| 61 | + insertText: [ |
| 62 | + "type ${1:name} interface {", |
| 63 | + "\t$0", |
| 64 | + "}" |
| 65 | + ].join('\n'), |
| 66 | + documentation: 'Declare a struct' |
| 67 | + }, |
| 68 | + { |
| 69 | + label: 'fmtprintf', |
| 70 | + insertText: 'fmt.Printf("${1:format}\n", $0)', |
| 71 | + documentation: 'fmt.Printf() shorthand' |
| 72 | + }, |
| 73 | + { |
| 74 | + label: 'fmtprintln', |
| 75 | + insertText: 'fmt.Println(${0:message})', |
| 76 | + documentation: 'fmt.Println() shorthand' |
| 77 | + }, |
| 78 | + { |
| 79 | + label: 'returnnil', |
| 80 | + insertText: 'return nil', |
| 81 | + documentation: 'return nil' |
| 82 | + }, |
| 83 | + { |
| 84 | + label: 'timenow', |
| 85 | + insertText: '${0:t} := time.Now()', |
| 86 | + documentation: 'time.Now() shorthand' |
| 87 | + }, |
| 88 | + { |
| 89 | + label: 'makeslice', |
| 90 | + insertText: '${0:items} := make([]${1:string}, ${2:0}, ${3:0})', |
| 91 | + documentation: 'Make a new slice' |
| 92 | + }, |
| 93 | + { |
| 94 | + label: 'slice', |
| 95 | + insertText: '${1:items} := []${2:string}{${0}}', |
| 96 | + documentation: 'Declare slice' |
| 97 | + }, |
| 98 | + { |
| 99 | + label: 'map', |
| 100 | + insertText: 'map[${1:string}]${0:value}', |
| 101 | + documentation: 'Insert map type' |
| 102 | + }, |
| 103 | + { |
| 104 | + label: 'func', |
| 105 | + insertText: [ |
| 106 | + "func ${1:functionName}(${3:param}) $4 {", |
| 107 | + " $0", |
| 108 | + "}" |
| 109 | + ].join('\n'), |
| 110 | + documentation: 'Insert a function' |
| 111 | + }, |
| 112 | + { |
| 113 | + label: 'for', |
| 114 | + insertText: [ |
| 115 | + "for _, ${1:v} := range ${2:value} {", |
| 116 | + " $0", |
| 117 | + "}" |
| 118 | + ].join('\n'), |
| 119 | + documentation: 'Insert a for range statement' |
| 120 | + }, |
| 121 | + |
| 122 | +].map(s => ({ |
| 123 | + kind: monaco.languages.CompletionItemKind.Snippet, |
| 124 | + insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet, |
| 125 | + ...s, |
| 126 | +})); |
| 127 | + |
| 128 | +export default snippets as monaco.languages.CompletionItem[]; |
0 commit comments