@@ -21,6 +21,7 @@ export default class CompletionService {
2121 return this . getDotCompletions ( ) ;
2222 }
2323
24+ completions = completions . concat ( this . getConditionalCompletions ( ) ) ;
2425 completions = completions . concat ( this . getControlCompletions ( ) ) ;
2526 completions = completions . concat ( this . getGlobalFunctionCompletions ( ) ) ;
2627 completions = completions . concat ( this . getOutputCompletions ( ) ) ;
@@ -114,6 +115,20 @@ export default class CompletionService {
114115
115116 return [ ]
116117 }
118+
119+ protected getConditionalCompletions ( ) :CompletionItem [ ] {
120+ const completions :CompletionItem [ ] = [ ] ;
121+ if ( ! this . text . includes ( "contract" ) ) {
122+ completions . push ( {
123+ label :"contract" ,
124+ detail :"Instantiate a new Contract" ,
125+ insertText :"contract ${1:ContractName}($2) {\n\n}" ,
126+ insertTextFormat :2
127+ } ) ;
128+ }
129+
130+ return completions ;
131+ }
117132
118133 protected getControlCompletions ( ) :CompletionItem [ ] {
119134 const words = [ "pragma" , "cashscript" , "if" , "else" , "require" ]
@@ -132,6 +147,7 @@ export default class CompletionService {
132147 "ripemd160" , "sha1" , "sha256" , "hash160" , "hash256" ,
133148 "checkSig" , "checkMultiSig" , "checkDataSig" ]
134149
150+ /*
135151 const comps: CompletionItem[] = [
136152 {
137153 label:"abs",
@@ -193,6 +209,69 @@ export default class CompletionService {
193209 insertText:"checkDataSig(${1:signature}, ${2:message}, ${3:pubkey})",
194210 insertTextFormat:2
195211 }
212+ ]*/
213+
214+ const comps : CompletionItem [ ] = [
215+ {
216+ label :"abs" ,
217+ detail : 'int abs(int a): Returns the absolute value of argument a.' ,
218+ insertText : 'abs' ,
219+ insertTextFormat : 2 ,
220+ } ,
221+ {
222+ label :"min" ,
223+ detail :"int min(int a, int b): Returns the minimum value of arguments `a` and `b`." ,
224+ insertText :"min" ,
225+ insertTextFormat :2
226+ } ,
227+ {
228+ label :"max" ,
229+ detail :"int max(int a, int b): Returns the maximum value of arguments `a` and `b`." ,
230+ insertText :"max" ,
231+ insertTextFormat :2
232+ } ,
233+ {
234+ label :"within" ,
235+ detail :"bool within(int x, int lower, int upper): Returns `true` if and only if `x >= lower && x < upper`." ,
236+ insertText :"within" ,
237+ insertTextFormat :2
238+ } ,
239+ {
240+ label :"ripemd160" ,
241+ detail :"bytes20 ripemd160(any x): Returns the SHA-1 hash of argument `x`." ,
242+ insertText :"ripemd160" ,
243+ insertTextFormat :2
244+ } ,
245+ {
246+ label :"sha256" ,
247+ detail :"bytes32 sha256(any x): Returns the SHA-256 hash of argument `x`." ,
248+ insertText :"sha256" ,
249+ insertTextFormat :2
250+ } ,
251+ {
252+ label :"hash160" ,
253+ detail :"bytes20 hash160(any x): Returns the RIPEMD-160 hash of the SHA-256 hash of argument `x`." ,
254+ insertText :"hash160" ,
255+ insertTextFormat :2
256+ } ,
257+ {
258+ label :"hash256" ,
259+ detail :"bytes32 hash256(any x): bytes32 hash256(any x)" ,
260+ insertText :"hash256" ,
261+ insertTextFormat :2
262+ } ,
263+ {
264+ label :"checkMultiSig" ,
265+ detail :"bool checkMultiSig(sig[] sigs, pubkey[] pks): Performs a multi-signature check using a list of transaction signatures and public keys." ,
266+ insertText :"checkMultiSig" ,
267+ insertTextFormat :2
268+ } ,
269+ {
270+ label :"checkDataSig" ,
271+ detail :"bool checkDataSig(datasig s, bytes msg, pubkey pk): Checks that sig `s` is a valid signature for message `msg` and matches with public key `pk`." ,
272+ insertText :"checkDataSig" ,
273+ insertTextFormat :2
274+ }
196275 ]
197276
198277 return comps ;
0 commit comments