Skip to content

Commit 2ab5f60

Browse files
dot hovers
1 parent 5b2951a commit 2ab5f60

3 files changed

Lines changed: 72 additions & 14 deletions

File tree

client/src/CashscriptHoverProvider.ts

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ class CashscriptHoverProvider implements vscode.HoverProvider{
2222

2323
// check special words
2424

25+
const dotHovers = this.getTxDotHovers(document, position);
26+
if(dotHovers) return new vscode.Hover(dotHovers, range)
27+
2528
const varTypes = this.getVariableTypes(document, word); // fix this
26-
return new vscode.Hover(varTypes, range);
29+
if(varTypes) return new vscode.Hover(varTypes, range);
30+
31+
return null;
2732
}
2833

2934

@@ -65,6 +70,58 @@ class CashscriptHoverProvider implements vscode.HoverProvider{
6570
]
6671
}
6772

73+
getTxDotHovers(document:vscode.TextDocument, position:vscode.Position):vscode.MarkdownString[]{
74+
const reg = /tx.[a-zA-Z0-9]+/;
75+
let range = document.getWordRangeAtPosition(position, reg);
76+
let word = document.getText(range).substring(3);
77+
78+
// /### tx.(\w+)\n+```solidity\n(.+)\n```/
79+
const TX_HOVERS = {
80+
time:{
81+
code:'require(tx.time >= <expression>);'
82+
},
83+
age:{
84+
code:'require(tx.age >= <expression>);'
85+
},
86+
version:{
87+
code:'bytes4 tx.version'
88+
},
89+
hashPrevouts:{
90+
code:'bytes32 tx.hashPrevouts'
91+
},
92+
hashSequence:{
93+
code:'bytes32 tx.hashSequence'
94+
},
95+
outpoint:{
96+
code:'bytes36 tx.outpoint'
97+
},
98+
bytecode:{
99+
code:'bytes tx.bytecode'
100+
},
101+
value:{
102+
code:'bytes8 value'
103+
},
104+
sequence:{
105+
code:'bytes4 tx.sequence'
106+
},
107+
hashOutputs:{
108+
code:'bytes32 tx.hashOutputs'
109+
},
110+
locktime:{
111+
code:'bytes4 tx.locktime'
112+
},
113+
hashtype:{
114+
code:'bytes4 tx.hashtype'
115+
},
116+
}
117+
118+
119+
this.channel.appendLine("dot: "+word);
120+
return [
121+
new vscode.MarkdownString().appendCodeblock(TX_HOVERS[word].code)
122+
];
123+
}
124+
68125
}
69126

70127
export default CashscriptHoverProvider;

client/testFixture/time.cash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ 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("");
9+
//int m = date("");
1010
int initial = int(initialBlock);
1111
require(tx.time >= initial);
1212

13+
1314
// Pledge amount calculation is done in client, verified in contract
1415
// When OP_MUL is enabled this can be done in contract
1516
// Double require to account for integer division

server/src/completionService.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,51 +50,51 @@ export default class CompletionService {
5050
tx:[
5151
{
5252
label:"time",
53-
kind:CompletionItemKind.Variable
53+
kind:CompletionItemKind.Field,
5454
},
5555
{
5656
label:"age",
57-
kind:CompletionItemKind.Variable
57+
kind:CompletionItemKind.Field
5858
},
5959
{
6060
label:"version",
61-
kind:CompletionItemKind.Variable
61+
kind:CompletionItemKind.Field
6262
},
6363
{
6464
label:"hashPrevouts",
65-
kind:CompletionItemKind.Variable
65+
kind:CompletionItemKind.Field
6666
},
6767
{
6868
label:"hashSequence",
69-
kind:CompletionItemKind.Variable
69+
kind:CompletionItemKind.Field
7070
},
7171
{
7272
label:"outpoint",
73-
kind:CompletionItemKind.Variable
73+
kind:CompletionItemKind.Field
7474
},
7575
{
7676
label:"bytecode",
77-
kind:CompletionItemKind.Variable
77+
kind:CompletionItemKind.Field
7878
},
7979
{
8080
label:"value",
81-
kind:CompletionItemKind.Variable
81+
kind:CompletionItemKind.Field
8282
},
8383
{
8484
label:"sequence",
85-
kind:CompletionItemKind.Variable
85+
kind:CompletionItemKind.Field
8686
},
8787
{
8888
label:"hashOutputs",
89-
kind:CompletionItemKind.Variable
89+
kind:CompletionItemKind.Field
9090
},
9191
{
9292
label:"locktime",
93-
kind:CompletionItemKind.Variable
93+
kind:CompletionItemKind.Field
9494
},
9595
{
9696
label:"hashtype",
97-
kind:CompletionItemKind.Variable
97+
kind:CompletionItemKind.Field
9898
},
9999
]
100100
}

0 commit comments

Comments
 (0)