Skip to content

Commit 469dca8

Browse files
polish
1 parent ac92d19 commit 469dca8

6 files changed

Lines changed: 80 additions & 74 deletions

File tree

examples/anyhedge.cash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ contract AnyHedge_v0_10(
5050
// Verify that both Hedge and Long agree to the details of this transaction.
5151
require(checkSig(hedgeMutualRedeemSig, hedgeMutualRedeemPubk));
5252
require(checkSig(longMutualRedeemSig, longMutualRedeemPubk));
53+
54+
5355
}
5456

5557
// Payout in Liquidation or Maturity conditions

examples/locktime.cash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ contract Mecenas(bytes4 initialBlock, int pledgePerBlock, bytes20 recipient, byt
3636
}
3737
}
3838

39+
3940
function reclaim(pubkey pk, sig s) {
4041
require(hash160(pk) == funder);
4142
require(checkSig(s, pk));

src/CashscriptCompletionProvider.ts

Lines changed: 15 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from 'vscode';
22
import { Range, CompletionItem, CompletionItemKind } from 'vscode';
3+
import { DOT_COMPLETIONS } from './LanguageDesc';
34

45
export 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;

src/CashscriptSignatureCompleter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class CashscriptSignatureCompleter implements vscode.SignatureHelpProvider{
1111
let range = document.getWordRangeAtPosition(position, this.re);
1212
let word = document.getText(range).slice(0, -1); // removes the '('
1313

14-
//this.channel.appendLine("signature " + word);
1514
const sh = new vscode.SignatureHelp();
1615
const data = LANGUAGE[word] || TYPECASTS[word];
1716
sh.signatures = [new vscode.SignatureInformation(data.codeDesc, new vscode.MarkdownString().appendCodeblock(data.code))];

src/LanguageDesc.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CompletionItem, CompletionItemKind } from "vscode";
12

23
interface Data {
34
[key:string]:{
@@ -108,4 +109,59 @@ let TYPECASTS:Data = {
108109

109110
let LANGUAGE:Data = {...GLOBAL_FUNCTIONS, ...OUTPUT_INSTANTIATION, ...STATEMENTS};
110111

111-
export { GLOBAL_FUNCTIONS, OUTPUT_INSTANTIATION, TYPECASTS, LANGUAGE };
112+
113+
let DOT_COMPLETIONS:{[key:string]:CompletionItem[]} = {
114+
tx:[
115+
{
116+
label:"time",
117+
kind:CompletionItemKind.Field,
118+
},
119+
{
120+
label:"age",
121+
kind:CompletionItemKind.Field
122+
},
123+
{
124+
label:"version",
125+
kind:CompletionItemKind.Field
126+
},
127+
{
128+
label:"hashPrevouts",
129+
kind:CompletionItemKind.Field
130+
},
131+
{
132+
label:"hashSequence",
133+
kind:CompletionItemKind.Field
134+
},
135+
{
136+
label:"outpoint",
137+
kind:CompletionItemKind.Field
138+
},
139+
{
140+
label:"bytecode",
141+
kind:CompletionItemKind.Field
142+
},
143+
{
144+
label:"value",
145+
kind:CompletionItemKind.Field
146+
},
147+
{
148+
label:"sequence",
149+
kind:CompletionItemKind.Field
150+
},
151+
{
152+
label:"hashOutputs",
153+
kind:CompletionItemKind.Field
154+
},
155+
{
156+
label:"locktime",
157+
kind:CompletionItemKind.Field
158+
},
159+
{
160+
label:"hashtype",
161+
kind:CompletionItemKind.Field
162+
},
163+
]
164+
}
165+
166+
167+
export { GLOBAL_FUNCTIONS, OUTPUT_INSTANTIATION, TYPECASTS, LANGUAGE, DOT_COMPLETIONS };

syntaxes/cashscript.tmLanguage.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
"global-variables": {
177177
"patterns": [
178178
{
179-
"match": "\\b(tx)(?:.(time|age|version|hashPrevouts|hashSequence|outpoint|bytecode|value|sequence|hashOutputs|locktime|hashtype|preimage))\\b",
179+
"match": "\\b(tx)(?:.(time|age|version|hashPrevouts|hashSequence|outpoint|bytecode|value|sequence|hashOutputs|locktime|hashtype|preimage))?\\b",
180180
"captures":{
181181
"1":{
182182
"name":"variable.language.transaction.cashscript"
@@ -209,6 +209,10 @@
209209
"match": "\\b(checkSig|checkMultiSig|checkDataSig)\\b",
210210
"name": "entity.name.function.checking.cashscript"
211211
},
212+
{
213+
"match": "\\b(date)\\b",
214+
"name": "entity.name.function.utility.cashscript"
215+
},
212216
{
213217
"match": "\\b(OutputP2PKH|OutputP2SH|OutputNullData)\\b",
214218
"name":"entity.name.function.declaration.cashscript"

0 commit comments

Comments
 (0)