11import * as vscode from 'vscode' ;
22import { Range , CompletionItem , CompletionItemKind } from 'vscode' ;
3+ import { DOT_COMPLETIONS } from './LanguageDesc' ;
34
45export default class CashscriptCompletionProvider implements vscode . CompletionItemProvider {
56
@@ -50,75 +51,17 @@ export default class CashscriptCompletionProvider implements vscode.CompletionIt
5051 return false ;
5152 }
5253
53-
54- DOT_COMPLETIONS :{ [ key :string ] :CompletionItem [ ] } = {
55- tx :[
56- {
57- label :"time" ,
58- kind :CompletionItemKind . Field ,
59- } ,
60- {
61- label :"age" ,
62- kind :CompletionItemKind . Field
63- } ,
64- {
65- label :"version" ,
66- kind :CompletionItemKind . Field
67- } ,
68- {
69- label :"hashPrevouts" ,
70- kind :CompletionItemKind . Field
71- } ,
72- {
73- label :"hashSequence" ,
74- kind :CompletionItemKind . Field
75- } ,
76- {
77- label :"outpoint" ,
78- kind :CompletionItemKind . Field
79- } ,
80- {
81- label :"bytecode" ,
82- kind :CompletionItemKind . Field
83- } ,
84- {
85- label :"value" ,
86- kind :CompletionItemKind . Field
87- } ,
88- {
89- label :"sequence" ,
90- kind :CompletionItemKind . Field
91- } ,
92- {
93- label :"hashOutputs" ,
94- kind :CompletionItemKind . Field
95- } ,
96- {
97- label :"locktime" ,
98- kind :CompletionItemKind . Field
99- } ,
100- {
101- label :"hashtype" ,
102- kind :CompletionItemKind . Field
103- } ,
104- ]
105- }
106-
10754 protected getDotCompletions ( ) :CompletionItem [ ] {
10855
10956 const re = / ( \w + ) .$ / // EX: "tx."
11057 const range :Range = new Range ( new vscode . Position ( this . pos . line , 0 ) , this . pos )
111- // {
112- // start:{character:0, line:this.pos.line},
113- // end:this.pos
114- // }
11558 const text = this . doc . getText ( range ) ;
11659 var arr , keyword ;
11760 if ( ( arr = text ?. match ( re ) ) ) {
11861 keyword = arr [ 1 ] ;
11962 console . log ( "keyword: " , keyword ) ;
12063
121- return this . DOT_COMPLETIONS [ keyword ] ;
64+ return DOT_COMPLETIONS [ keyword ] ;
12265 }
12366
12467 return [ ]
@@ -138,19 +81,20 @@ export default class CashscriptCompletionProvider implements vscode.CompletionIt
13881 return completions ;
13982 }
14083
141- protected getConditionalCompletions ( ) :CompletionItem [ ] {
142- const completions :CompletionItem [ ] = [ ] ;
143- if ( ! this . text . includes ( "contract" ) ) {
144- completions . push ( {
145- label :"contract" ,
146- detail :"Instantiate a new Contract" ,
147- insertText :"contract ${1:ContractName}($2) {\n\n}" ,
148- } ) ;
149- }
84+ // protected getConditionalCompletions():CompletionItem[]{
85+ // const completions:CompletionItem[] = [];
86+ // if(!this.text.includes("contract")){
87+ // completions.push({
88+ // label:"contract",
89+ // detail:"Instantiate a new Contract",
90+ // insertText:"contract ${1:ContractName}($2) {\n\n}",
91+ // });
92+ // }
15093
151- return completions ;
152- }
94+ // return completions;
95+ // }
15396
97+
15498 protected getControlCompletions ( ) :CompletionItem [ ] {
15599 const words = [ "pragma" , "cashscript" , "if" , "else" , "require" ]
156100 const completions = [ ] ;
@@ -271,7 +215,7 @@ export default class CashscriptCompletionProvider implements vscode.CompletionIt
271215 }
272216
273217 protected getGlobalConstantsCompletions ( ) :CompletionItem [ ] {
274- const words = [ "sats" , "satoshis" , "finney" , "bit" , "bitcoin" , "seconds" , "minutes" , "hours" , "days" , "weeks" ] ;
218+ const words = [ "sats" , "satoshis" , "finney" , "bit" , "bitcoin" , "seconds" , "minutes" , "hours" , "days" , "weeks" , "tx" ] ;
275219 const completions = [ ] ;
276220 for ( let i = 0 ; i < words . length ; i ++ ) {
277221 this . currentIndex += 1 ;
0 commit comments