1+ import path = require( 'path' )
12import * as vscode from 'vscode'
23import * as lsp from 'vscode-languageclient'
34import { Extension } from './extension'
@@ -30,7 +31,7 @@ export function virtualMergedDocument(e: Extension): Command {
3031 command : 'virtualMerge' ,
3132 arguments : [ path ]
3233 } )
33- } catch ( e ) { }
34+ } catch ( e ) { }
3435
3536 return content
3637 }
@@ -40,17 +41,67 @@ export function virtualMergedDocument(e: Extension): Command {
4041 onDidChange = this . onDidChangeEmitter . event
4142
4243 provideTextDocumentContent ( uri : vscode . Uri , __ : vscode . CancellationToken ) : vscode . ProviderResult < string > {
43- return getVirtualDocument ( uri . path )
44+ return getVirtualDocument ( uri . path . replace ( '.flattened' + path . extname ( uri . path ) , path . extname ( uri . path ) ) )
4445 }
4546 }
4647
4748 e . context . subscriptions . push ( vscode . workspace . registerTextDocumentContentProvider ( 'mcglsl' , docProvider ) )
4849
4950 return async ( ) => {
51+ if ( vscode . window . activeTextEditor . document . languageId != 'glsl' ) return
52+
53+ const uri = vscode . window . activeTextEditor . document . uri . path
54+ . substring ( 0 , vscode . window . activeTextEditor . document . uri . path . lastIndexOf ( '.' ) )
55+ + '.flattened.'
56+ + vscode . window . activeTextEditor . document . uri . path
57+ . slice ( vscode . window . activeTextEditor . document . uri . path . lastIndexOf ( '.' ) + 1 )
58+ const path = vscode . Uri . parse ( `mcglsl:${ uri } ` )
59+
60+ const doc = await vscode . workspace . openTextDocument ( path )
61+ docProvider . onDidChangeEmitter . fire ( path )
62+ await vscode . window . showTextDocument ( doc , {
63+ viewColumn : vscode . ViewColumn . Two ,
64+ preview : true
65+ } )
66+ }
67+ }
68+
69+ export function parseTree ( e : Extension ) : Command {
70+ const getVirtualDocument = async ( path : string ) : Promise < string | null > => {
71+ let content : string = ''
72+ try {
73+ content = await e . lspClient . sendRequest < string > ( lsp . ExecuteCommandRequest . type . method , {
74+ command : 'parseTree' ,
75+ arguments : [ path ]
76+ } )
77+ } catch ( e ) { }
78+
79+ return content
80+ }
81+
82+ const docProvider = new class implements vscode . TextDocumentContentProvider {
83+ onDidChangeEmitter = new vscode . EventEmitter < vscode . Uri > ( )
84+ onDidChange = this . onDidChangeEmitter . event
85+
86+ provideTextDocumentContent ( uri : vscode . Uri , __ : vscode . CancellationToken ) : vscode . ProviderResult < string > {
87+ if ( uri . path . includes ( '.flattened.' ) ) return ''
88+ return getVirtualDocument ( uri . path . substring ( 0 , uri . path . lastIndexOf ( '.' ) ) )
89+ }
90+ }
91+
92+ e . context . subscriptions . push ( vscode . workspace . registerTextDocumentContentProvider ( 'mcglsl' , docProvider ) )
93+
94+ return async ( ) => {
95+ if ( vscode . window . activeTextEditor . document . languageId != 'glsl' ) return
96+
5097 const uri = vscode . window . activeTextEditor . document . uri
51- const path = vscode . Uri . parse ( 'mcglsl:' + uri . path )
98+ const path = vscode . Uri . parse ( `mcglsl:${ uri . path } .ast` )
99+
52100 const doc = await vscode . workspace . openTextDocument ( path )
53101 docProvider . onDidChangeEmitter . fire ( path )
54- await vscode . window . showTextDocument ( doc , { preview : true } )
102+ await vscode . window . showTextDocument ( doc , {
103+ viewColumn : vscode . ViewColumn . Two ,
104+ preview : true
105+ } )
55106 }
56107}
0 commit comments