Skip to content

Commit 5b2951a

Browse files
variable completions
1 parent 73d701d commit 5b2951a

5 files changed

Lines changed: 37 additions & 7 deletions

File tree

client/src/CashscriptSignatureCompleter.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ class CashscriptSignatureCompleter implements vscode.SignatureHelpProvider{
1515
const sh = new vscode.SignatureHelp();
1616
const data = LANGUAGE[word] || TYPECASTS[word];
1717
sh.signatures = [new vscode.SignatureInformation(data.codeDesc, new vscode.MarkdownString().appendCodeblock(data.code))];
18-
//sh.signatures = this.SIG_DATA[word]; data
19-
//sh.signatures = [new vscode.SignatureInformation("param here", "documentation here")]
2018
return sh;
2119
}
2220

client/src/LanguageDesc.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,24 @@ let TYPECASTS:Data = {
8686
int:{
8787
code:"int int( v )",
8888
codeDesc:"Converts to int"
89+
},
90+
string:{
91+
code:"string string( v )",
92+
codeDesc:"Converts to string"
93+
},
94+
bytes:{
95+
code:"bytes bytes( v )",
96+
codeDesc:"Converts to bytes"
97+
},
98+
bool:{
99+
code:"bool bool( v )",
100+
codeDesc:"Converts to bool"
101+
},
102+
date:{
103+
code:"int date(\" YYYY-MM-DDThh:mm:ss \")",
104+
codeDesc:"Converts implicit date to timestamp"
89105
}
106+
90107
}
91108

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

client/testFixture/time.cash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ contract Mecenas(bytes4 initialBlock, int pledgePerBlock, bytes20 recipient, byt
66
function receive(pubkey pk, sig s, int pledge) {
77
require(checkSig(s, pk));
88

9+
int m = date("");
910
int initial = int(initialBlock);
1011
require(tx.time >= initial);
11-
12+
1213
// Pledge amount calculation is done in client, verified in contract
1314
// When OP_MUL is enabled this can be done in contract
1415
// Double require to account for integer division

server/src/completionService.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default class CompletionService {
2323
return this.getDotCompletions();
2424
}
2525

26+
completions = completions.concat(this.getVarCompletions());
2627
completions = completions.concat(this.getConditionalCompletions());
2728
completions = completions.concat(this.getControlCompletions());
2829
completions = completions.concat(this.getGlobalFunctionCompletions());
@@ -114,10 +115,23 @@ export default class CompletionService {
114115
return this.DOT_COMPLETIONS[keyword];
115116
}
116117

117-
118118
return []
119119
}
120-
120+
121+
protected getVarCompletions():CompletionItem[]{
122+
123+
const re = /(int|bool|string|pubkey|sig|datasig|bytes)\s+(\w+)/g;
124+
const completions:CompletionItem[] = [];
125+
for(const m of this.text.matchAll(re)){
126+
completions.push({
127+
label:m[2],
128+
kind:CompletionItemKind.Variable
129+
});
130+
}
131+
132+
return completions;
133+
}
134+
121135
protected getConditionalCompletions():CompletionItem[]{
122136
const completions:CompletionItem[] = [];
123137
if(!this.text.includes("contract")){
@@ -296,7 +310,7 @@ export default class CompletionService {
296310
}
297311

298312
protected getTypesCompletions():CompletionItem[]{
299-
const words = ["int", "bool", "string", "bytes", "pubkey", "sig", "datasig", "true", "false"]
313+
const words = ["int", "bool", "string", "bytes", "pubkey", "sig", "datasig", "true", "false", "date"]
300314
const completions = [];
301315
for (let i = 0; i < words.length; i++) {
302316
this.currentIndex += 1;

server/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "es2019",
4-
"lib": ["ES2019",
4+
"lib": ["ES2020",
55
"es2017",
66
"esnext.bigint",
77
"dom",

0 commit comments

Comments
 (0)