@@ -12,6 +12,7 @@ import { DebugManager, debugTests } from './debug'
1212import { ExtensionDiagnostic } from './diagnostic'
1313import { log } from './log'
1414import { TestRunner } from './runner'
15+ import { SchemaProvider } from './schemaProvider'
1516import { TagsManager } from './tagsManager'
1617import { TestTree } from './testTree'
1718import { getTestData , TestFile } from './testTreeData'
@@ -41,6 +42,7 @@ class VitestExtension {
4142 private disposables : vscode . Disposable [ ] = [ ]
4243 private diagnostic : ExtensionDiagnostic | undefined
4344 private debugManager : DebugManager
45+ private schemaProvider : SchemaProvider
4446
4547 /** @internal */
4648 _debugDisposable : vscode . Disposable | undefined
@@ -58,6 +60,12 @@ class VitestExtension {
5860 this . testTree = new TestTree ( this . testController , this . loadingTestItem )
5961 this . tagsManager = new TagsManager ( this . testTree )
6062 this . debugManager = new DebugManager ( )
63+ this . schemaProvider = new SchemaProvider (
64+ async ( apiId , project , environment , file ) => {
65+ const api = this . api ?. folderAPIs . find ( a => a . id === apiId )
66+ return api ?. getTransformedModule ( project , environment , file ) ?? null
67+ } ,
68+ )
6169 }
6270
6371 private _defineTestProfilePromise : Promise < void > | undefined
@@ -344,6 +352,51 @@ class VitestExtension {
344352 const tokenSource = new vscode . CancellationTokenSource ( )
345353 await profile . runHandler ( request , tokenSource . token )
346354 } ) ,
355+ vscode . commands . registerCommand ( 'vitest.openTransformedModule' , async ( uri : vscode . Uri | undefined ) => {
356+ const currentUri = uri || vscode . window . activeTextEditor ?. document . uri
357+ if ( ! this . api || ! currentUri || currentUri . scheme === 'vitest-transform' ) {
358+ return
359+ }
360+ const environments = await this . api . getModuleEnvironments ( currentUri . fsPath )
361+ const options = environments . map ( ( { api, projects } ) => {
362+ return projects . map ( ( project ) => {
363+ return project . environments . map ( ( environment ) => {
364+ let label = ''
365+ if ( environments . length > 1 ) {
366+ label += `${ api . prefix } : `
367+ }
368+ if ( project . name ) {
369+ label += `[${ project . name } ] `
370+ }
371+ label += environment
372+ return {
373+ label,
374+ uriParts : [ api . id , project . name , environment ] ,
375+ }
376+ } )
377+ } )
378+ } ) . flat ( 2 )
379+ if ( options . length === 0 ) {
380+ vscode . window . showWarningMessage ( 'All module graphs are empty, nothing to show.' )
381+ return
382+ }
383+ const pick = options . length === 1 ? options [ 0 ] : await vscode . window . showQuickPick ( options )
384+ if ( ! pick ) {
385+ return
386+ }
387+ try {
388+ const [ apiId , projectName , environment ] = pick . uriParts
389+ const uri = vscode . Uri . parse (
390+ `vitest-transform://${ currentUri . fsPath } .js?apiId=${ apiId } &project=${ projectName } &environment=${ environment } ` ,
391+ )
392+ const doc = await vscode . workspace . openTextDocument ( uri )
393+ await vscode . window . showTextDocument ( doc , { preview : false } )
394+ }
395+ catch ( err ) {
396+ log . error ( err )
397+ vscode . window . showErrorMessage ( `Vitest: The file was not processed by Vite yet. Try running the tests first${ options . length > 1 ? ' or select a different environment' : '' } .` )
398+ }
399+ } ) ,
347400 ]
348401
349402 // if the config changes, re-define all test profiles
@@ -429,6 +482,7 @@ class VitestExtension {
429482 this . testTree . dispose ( )
430483 this . tagsManager . dispose ( )
431484 this . testController . dispose ( )
485+ this . schemaProvider . dispose ( )
432486 this . runProfiles . forEach ( profile => profile . dispose ( ) )
433487 this . runProfiles . clear ( )
434488 this . disposables . forEach ( d => d . dispose ( ) )
0 commit comments