Skip to content

Commit 77ee782

Browse files
prep for deployment
1 parent 60538a8 commit 77ee782

6 files changed

Lines changed: 308 additions & 475 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ Would like to implement tests and other sustainability features before bumping v
1313

1414
## 0.1.1
1515
- Fixed language grammar to have comprehensive highlighting
16-
-
16+
- Added janky HoverProvider for variable types
17+
- Added split/reverse to hover provider

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ None available yet.
5050

5151
Check the [changelog](/CHANGELOG.md) for past releases. Latest stable version:
5252

53-
### 0.1.0
54-
55-
Initial release of vscode-cashscript. Features:
56-
- Syntax Highlighting
57-
- Auto-Completion
58-
- Snippets
59-
- Linting
60-
- Contract Compilation (press F5 or click "Compile Contract")
53+
### 0.1.1
54+
- Fixed language grammar to have comprehensive highlighting
55+
- Added janky HoverProvider for variable types
56+
- Added split/reverse to hover provider

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
{
6464
"language": "cashscript",
6565
"scopeName": "source.cash",
66-
"path": "./syntaxes/cashscript.json"
66+
"path": "./syntaxes/cashscript.tmLanguage.json"
6767
}
6868
],
6969
"snippets": [

src/CashscriptHoverProvider.ts

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as vscode from 'vscode';
2-
import { MarkedString } from 'vscode-languageclient';
32
import { LANGUAGE } from './LanguageDesc';
43

54
class CashscriptHoverProvider implements vscode.HoverProvider{
@@ -13,20 +12,22 @@ class CashscriptHoverProvider implements vscode.HoverProvider{
1312
let range = document.getWordRangeAtPosition(position, this.re);
1413
let word = document.getText(range);
1514

16-
//this.channel.appendLine("hoverword: "+word)
15+
16+
const varTypes = this.getVariableTypes(document, word); // fix this
17+
if(varTypes) return new vscode.Hover(varTypes, range);
18+
1719
const annotation = this.getHoverAnnotation(word);
1820
if(annotation) return new vscode.Hover(annotation, range);
1921

22+
const memberHovers = this.getMemberHovers(document, word);
23+
if(memberHovers) return new vscode.Hover(memberHovers, range);
24+
2025
const miscel = this.getMiscellaneousHovers(document, position);
2126
if(miscel) return new vscode.Hover(miscel, range)
2227

23-
// check special words
24-
2528
const dotHovers = this.getTxDotHovers(document, position);
2629
if(dotHovers) return new vscode.Hover(dotHovers, range)
2730

28-
const varTypes = this.getVariableTypes(document, word); // fix this
29-
if(varTypes) return new vscode.Hover(varTypes, range);
3031

3132
return null;
3233
}
@@ -60,16 +61,28 @@ class CashscriptHoverProvider implements vscode.HoverProvider{
6061
* Very bad way to get type annotations, better option: custom Tree Builder
6162
*/
6263
getVariableTypes(document:vscode.TextDocument, targetWord:string):vscode.MarkdownString[]{
63-
const reg = /([a-zA-Z0-9]+)\s+(pk)[^a-zA-Z0-9]/;
64-
const text = document.getText();
65-
const matches = text.match(new RegExp(`([a-zA-Z0-9]+)\\s+(${targetWord})[^a-zA-Z0-9]`)); //regex still incomplete
66-
if(!matches) return null;
6764

65+
const type = this.getVariableType(targetWord, document);
66+
if(!type) return null;
6867
return [
69-
new vscode.MarkdownString().appendCodeblock(`${matches[1]} ${matches[2]}`),
68+
new vscode.MarkdownString().appendCodeblock(`${type} ${targetWord}`),
7069
]
7170
}
7271

72+
/**
73+
* Gets the data type of a variable
74+
*
75+
* @param variable the variable to be seached for
76+
* @param document the entire text document
77+
* @returns a string of the data type
78+
*/
79+
getVariableType(variable:string, document:vscode.TextDocument){
80+
const text = document.getText();
81+
const matches = text.match(new RegExp(`\\b(int|bool|string|pubkey|sig|datasig|bytes\\d*)\\s+${variable}\\b`)); //regex still incomplete
82+
if(!matches) return null;
83+
return matches[1];
84+
}
85+
7386
getTxDotHovers(document:vscode.TextDocument, position:vscode.Position):vscode.MarkdownString[]{
7487
const reg = /tx.[a-zA-Z0-9]+/;
7588
let range = document.getWordRangeAtPosition(position, reg);
@@ -116,9 +129,29 @@ class CashscriptHoverProvider implements vscode.HoverProvider{
116129
}
117130

118131

119-
return [
120-
new vscode.MarkdownString().appendCodeblock(TX_HOVERS[word].code)
121-
];
132+
if(TX_HOVERS[word].code){
133+
return [
134+
new vscode.MarkdownString().appendCodeblock(TX_HOVERS[word].code)
135+
];
136+
}
137+
138+
return null
139+
}
140+
141+
getMemberHovers(document:vscode.TextDocument, word:string){
142+
if(word === "split"){
143+
return [
144+
new vscode.MarkdownString().appendCodeblock('[s1, s2] sequence.split(int i)'),
145+
new vscode.MarkdownString('Splits the sequence at the specified index and returns a tuple with the two resulting sequences.')
146+
]
147+
}else if(word === "reverse"){
148+
return [
149+
new vscode.MarkdownString().appendCodeblock('any sequence.reverse()'),
150+
new vscode.MarkdownString('Reverses the sequence.')
151+
]
152+
}
153+
154+
return null;
122155
}
123156

124157
}

0 commit comments

Comments
 (0)