11import * as vscode from "vscode" ;
2- import { Converter } from "aws-sdk/clients/dynamodb" ;
3- import { render as renderVelocity } from "velocityjs " ;
2+ import { Converter } from "aws-sdk/clients/dynamodb" ;
3+ import Parser from "appsync-template-tester " ;
44
55function isVelocityFile ( document ?: vscode . TextDocument ) : boolean {
6- return document ?. languageId === "velocity" ;
7- }
6+ return document ?. languageId === "velocity" ;
7+ }
88
99export class VelocityPreviewProvider
1010 implements vscode . TextDocumentContentProvider {
@@ -14,48 +14,34 @@ export class VelocityPreviewProvider
1414 private contentProviderRegistration : vscode . Disposable ;
1515
1616 static SCHEME = `appsyncvtl` ;
17- static URI = vscode . Uri . parse ( `${ VelocityPreviewProvider . SCHEME } :preview.json` , true ) ;
17+ static URI = vscode . Uri . parse (
18+ `${ VelocityPreviewProvider . SCHEME } :preview.json` ,
19+ true
20+ ) ;
1821
1922 constructor ( ) {
20- this . contentProviderRegistration = vscode . workspace . registerTextDocumentContentProvider ( VelocityPreviewProvider . SCHEME , this ) ;
23+ this . contentProviderRegistration = vscode . workspace . registerTextDocumentContentProvider (
24+ VelocityPreviewProvider . SCHEME ,
25+ this
26+ ) ;
2127 }
2228
2329 provideTextDocumentContent (
2430 uri : vscode . Uri ,
2531 token : vscode . CancellationToken
2632 ) : vscode . ProviderResult < string > {
27- const editor = vscode . window . activeTextEditor ;
33+ const editor = vscode . window . activeTextEditor ;
2834
29- if ( ! isVelocityFile ( editor ?. document ) ) {
30- console . error ( `Wrong document type` ) ;
31- return `Unknown document type "${ editor ?. document ?. languageId } "` ;
35+ if ( ! isVelocityFile ( editor ?. document ) ) {
36+ console . error ( `Wrong document type` ) ;
37+ return `Unknown document type "${ editor ?. document ?. languageId } "` ;
3238 }
3339
3440 const content = editor ?. document ?. getText ( ) ?? `` ;
3541
36- const renderContext = {
37- util : {
38- toJson ( vmString : any , context : any ) : string {
39- return JSON . stringify ( vmString ) ;
40- } ,
41- dynamodb : {
42- toMap ( vmString : any , context : any ) : object {
43- return Converter . input ( vmString ) ;
44- } ,
45- toMapValues ( vmString : any , context : any ) : object {
46- return Converter . marshall ( vmString ) ;
47- } ,
48- toMapJson ( vmString : any , context : any ) : string {
49- return JSON . stringify ( Converter . input ( vmString ) ) ;
50- } ,
51- toMapValuesJson ( vmString : any , context : any ) : string {
52- return JSON . stringify ( Converter . marshall ( vmString ) ) ;
53- }
54- }
55- }
56- } ;
57-
58- return renderVelocity ( content , renderContext ) ;
42+ const parser = new Parser ( content ) ;
43+
44+ return parser . resolve ( { } ) ;
5945 }
6046
6147 async updatePreview ( ) { }
@@ -76,15 +62,23 @@ export class VelocityPreviewProvider
7662 const provider = new VelocityPreviewProvider ( ) ;
7763
7864 context . subscriptions . push (
79- vscode . workspace . onDidChangeTextDocument ( provider . onContentUpdated . bind ( provider ) )
65+ vscode . workspace . onDidChangeTextDocument (
66+ provider . onContentUpdated . bind ( provider )
67+ )
8068 ) ;
8169 context . subscriptions . push (
82- vscode . window . onDidChangeActiveTextEditor ( provider . onContentUpdated . bind ( provider ) )
70+ vscode . window . onDidChangeActiveTextEditor (
71+ provider . onContentUpdated . bind ( provider )
72+ )
8373 ) ;
8474
85- vscode . commands . registerCommand ( 'appsyncVtl.showPreview' , async ( ) => {
86- let doc = await vscode . workspace . openTextDocument ( this . URI ) ;
87- await vscode . window . showTextDocument ( doc , { preview : false , viewColumn : vscode . ViewColumn . Beside , preserveFocus : true } ) ;
75+ vscode . commands . registerCommand ( "appsyncVtl.showPreview" , async ( ) => {
76+ let doc = await vscode . workspace . openTextDocument ( this . URI ) ;
77+ await vscode . window . showTextDocument ( doc , {
78+ preview : false ,
79+ viewColumn : vscode . ViewColumn . Beside ,
80+ preserveFocus : true ,
81+ } ) ;
8882 } ) ;
8983
9084 return provider ;
0 commit comments