@@ -6,7 +6,7 @@ import * as path from "node:path"
66import * as vscode from "vscode"
77
88import { Acton } from "../Acton"
9- import { ScriptCommand } from "../ActonCommand"
9+ import { BuildCommand , ScriptCommand , WrapperCommand } from "../ActonCommand"
1010
1111import { startActonScriptDebugging } from "./ActonScriptDebug"
1212
@@ -28,6 +28,8 @@ const SCRIPT_BROADCAST_NETWORKS = [
2828 } ,
2929] as const
3030
31+ const CONTRACT_DECLARATION_PATTERN = / ^ \s * c o n t r a c t \s + ( [ $ A - Z _ a - z ] [ \w $ ] * ) \b /
32+
3133export class ActonTolkCodeLensProvider implements vscode . CodeLensProvider {
3234 public provideCodeLenses (
3335 document : vscode . TextDocument ,
@@ -42,8 +44,32 @@ export class ActonTolkCodeLensProvider implements vscode.CodeLensProvider {
4244 for ( let i = 0 ; i < document . lineCount ; i ++ ) {
4345 const line = document . lineAt ( i )
4446 const text = line . text
47+ const code = text . split ( "//" , 1 ) [ 0 ]
4548
46- if ( / f u n \s + m a i n \s * \( / i. test ( text ) ) {
49+ const contractMatch = CONTRACT_DECLARATION_PATTERN . exec ( code )
50+ if ( contractMatch ) {
51+ const contractId = contractMatch [ 1 ]
52+ const range = new vscode . Range ( i , 0 , i , text . length )
53+ lenses . push (
54+ new vscode . CodeLens ( range , {
55+ title : "Build contract" ,
56+ command : "ton.acton.buildContractFromTolk" ,
57+ arguments : [ document . uri , contractId ] ,
58+ } ) ,
59+ new vscode . CodeLens ( range , {
60+ title : "Generate Tolk wrapper" ,
61+ command : "ton.acton.generateTolkWrapper" ,
62+ arguments : [ document . uri , contractId ] ,
63+ } ) ,
64+ new vscode . CodeLens ( range , {
65+ title : "Generate TypeScript wrapper" ,
66+ command : "ton.acton.generateTypescriptWrapper" ,
67+ arguments : [ document . uri , contractId ] ,
68+ } ) ,
69+ )
70+ }
71+
72+ if ( / f u n \s + m a i n \s * \( / i. test ( code ) ) {
4773 const range = new vscode . Range ( i , 0 , i , text . length )
4874 lenses . push (
4975 new vscode . CodeLens ( range , {
@@ -73,6 +99,33 @@ export class ActonTolkCodeLensProvider implements vscode.CodeLensProvider {
7399 vscode . commands . registerCommand ( "ton.acton.run" , async ( fileUri : vscode . Uri ) => {
74100 await ActonTolkCodeLensProvider . runScript ( fileUri , "" )
75101 } ) ,
102+ vscode . commands . registerCommand (
103+ "ton.acton.buildContractFromTolk" ,
104+ async ( fileUri : vscode . Uri , contractId : string ) => {
105+ await ActonTolkCodeLensProvider . runContractCommand (
106+ fileUri ,
107+ new BuildCommand ( contractId ) ,
108+ )
109+ } ,
110+ ) ,
111+ vscode . commands . registerCommand (
112+ "ton.acton.generateTolkWrapper" ,
113+ async ( fileUri : vscode . Uri , contractId : string ) => {
114+ await ActonTolkCodeLensProvider . runContractCommand (
115+ fileUri ,
116+ new WrapperCommand ( contractId ) ,
117+ )
118+ } ,
119+ ) ,
120+ vscode . commands . registerCommand (
121+ "ton.acton.generateTypescriptWrapper" ,
122+ async ( fileUri : vscode . Uri , contractId : string ) => {
123+ await ActonTolkCodeLensProvider . runContractCommand (
124+ fileUri ,
125+ new WrapperCommand ( contractId , true ) ,
126+ )
127+ } ,
128+ ) ,
76129 vscode . commands . registerCommand (
77130 "ton.acton.debugScript" ,
78131 async ( fileUri : vscode . Uri ) => {
@@ -114,4 +167,14 @@ export class ActonTolkCodeLensProvider implements vscode.CodeLensProvider {
114167
115168 await Acton . getInstance ( ) . execute ( command , workingDir )
116169 }
170+
171+ private static async runContractCommand (
172+ fileUri : vscode . Uri ,
173+ command : BuildCommand | WrapperCommand ,
174+ ) : Promise < void > {
175+ const tomlUri = await Acton . getInstance ( ) . findActonToml ( fileUri )
176+ const workingDir = tomlUri ? path . dirname ( tomlUri . fsPath ) : path . dirname ( fileUri . fsPath )
177+
178+ await Acton . getInstance ( ) . execute ( command , workingDir )
179+ }
117180}
0 commit comments