@@ -105,9 +105,13 @@ export default function ecTwoSlash(options: PluginTwoslashOptions = {}): Express
105105 ...twoslashEslintOptions ,
106106 } ) ;
107107
108- const snippetTsconfigPath = resolveTsconfigPath ( cwd , tsConfigPath ) ;
109- const { options : baseCompilerOptions } = parseSnippetTsconfig ( snippetTsconfigPath ) ;
108+ // Get the TSConfig path for getting the default library files for Twoslash
109+ const _TsConfigPath = resolveTsconfigPath ( cwd , tsConfigPath ) ;
110110
111+ // Get the default compiler options from the parsed TSConfig, which includes the default library files for Twoslash
112+ const { options : baseCompilerOptions } = parseSnippetTsconfig ( _TsConfigPath ) ;
113+
114+ // Get the directory of the default library files for Twoslash, which is needed for proper module resolution in Twoslash
111115 const tsLibDirectory = path . dirname ( ts . getDefaultLibFilePath ( baseCompilerOptions ) ) ;
112116
113117 return definePlugin ( {
@@ -138,8 +142,10 @@ export default function ecTwoSlash(options: PluginTwoslashOptions = {}): Express
138142 // Add the include to the includes map if it exists
139143 if ( include ) includes . add ( include , codeWithIncludes ) ;
140144
145+ // If the trigger is "eslint", we want to set a full filename with extension instead of just the language identifier,
146+ // because ESLint's Twoslasher needs the full filename to properly parse the code block and provide accurate completions.
141147 const extension =
142- trigger === "twoslash " ? codeBlock . language : `index.${ codeBlock . language } ` ;
148+ trigger === "eslint " ? `index.${ codeBlock . language } ` : codeBlock . language ;
143149
144150 // Twoslash the code block
145151 const twoslash = twoslasher ( codeWithIncludes , extension , {
@@ -153,7 +159,9 @@ export default function ecTwoSlash(options: PluginTwoslashOptions = {}): Express
153159 } ,
154160 } ) ;
155161
156- // Update EC code block with the twoslash information
162+ // Update EC code block with the twoslash information this is important to ensure that if the end user
163+ // is using the @showEmit functionality, the emitted code is properly displayed in the code block.
164+ // Twoslash output code, could be TypeScript, but could also be a JS/JSON/d.ts representation of the code.
157165 if ( twoslash . extension ) {
158166 codeBlock . language = twoslash . extension ;
159167 }
0 commit comments