1
1
import * 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 " ;
4
4
5
5
function isVelocityFile ( document ?: vscode . TextDocument ) : boolean {
6
- return document ?. languageId === "velocity" ;
7
- }
6
+ return document ?. languageId === "velocity" ;
7
+ }
8
8
9
9
export class VelocityPreviewProvider
10
10
implements vscode . TextDocumentContentProvider {
@@ -14,48 +14,34 @@ export class VelocityPreviewProvider
14
14
private contentProviderRegistration : vscode . Disposable ;
15
15
16
16
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
+ ) ;
18
21
19
22
constructor ( ) {
20
- this . contentProviderRegistration = vscode . workspace . registerTextDocumentContentProvider ( VelocityPreviewProvider . SCHEME , this ) ;
23
+ this . contentProviderRegistration = vscode . workspace . registerTextDocumentContentProvider (
24
+ VelocityPreviewProvider . SCHEME ,
25
+ this
26
+ ) ;
21
27
}
22
28
23
29
provideTextDocumentContent (
24
30
uri : vscode . Uri ,
25
31
token : vscode . CancellationToken
26
32
) : vscode . ProviderResult < string > {
27
- const editor = vscode . window . activeTextEditor ;
33
+ const editor = vscode . window . activeTextEditor ;
28
34
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 } "` ;
32
38
}
33
39
34
40
const content = editor ?. document ?. getText ( ) ?? `` ;
35
41
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 ( { } ) ;
59
45
}
60
46
61
47
async updatePreview ( ) { }
@@ -76,15 +62,23 @@ export class VelocityPreviewProvider
76
62
const provider = new VelocityPreviewProvider ( ) ;
77
63
78
64
context . subscriptions . push (
79
- vscode . workspace . onDidChangeTextDocument ( provider . onContentUpdated . bind ( provider ) )
65
+ vscode . workspace . onDidChangeTextDocument (
66
+ provider . onContentUpdated . bind ( provider )
67
+ )
80
68
) ;
81
69
context . subscriptions . push (
82
- vscode . window . onDidChangeActiveTextEditor ( provider . onContentUpdated . bind ( provider ) )
70
+ vscode . window . onDidChangeActiveTextEditor (
71
+ provider . onContentUpdated . bind ( provider )
72
+ )
83
73
) ;
84
74
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
+ } ) ;
88
82
} ) ;
89
83
90
84
return provider ;
0 commit comments