1
1
import { ensureArray } from '@zardoy/utils'
2
- import { getCancellationToken , isTs5 , nodeModules } from './utils'
2
+ import { getCancellationToken , isTs5 , isTs5And5 , nodeModules } from './utils'
3
3
import { createLanguageService } from './dummyLanguageService'
4
4
import { getCannotFindCodes } from './utils/cannotFindCodes'
5
5
@@ -11,8 +11,9 @@ type AdditionalFeatures = Record<'arraysTuplesNumberedItems', boolean>
11
11
const getPatchedNavModule = ( additionalFeatures : AdditionalFeatures ) : { getNavigationTree ( ...args ) } => {
12
12
// what is happening here: grabbing & patching NavigationBar module contents from actual running JS
13
13
const tsServerPath = typeof __TS_SEVER_PATH__ === 'undefined' ? require . main ! . filename : __TS_SEVER_PATH__
14
+ const typescriptFilePath = `${ nodeModules ! . path . dirname ( tsServerPath ) } /typescript.js`
14
15
// current lib/tsserver.js
15
- const mainScript = nodeModules ! . fs . readFileSync ( tsServerPath , 'utf8' )
16
+ const mainScript = nodeModules ! . fs . readFileSync ( isTs5And5 ( ) ? typescriptFilePath : tsServerPath , 'utf8' )
16
17
type PatchData = {
17
18
markerModuleStart : string
18
19
skipStartMarker ?: boolean
@@ -173,7 +174,7 @@ export const getNavTreeItems = (
173
174
fileName : string ,
174
175
additionalFeatures : AdditionalFeatures ,
175
176
) => {
176
- if ( ! navModule ) navModule = getPatchedNavModule ( additionalFeatures )
177
+ navModule = getPatchedNavModule ( additionalFeatures )
177
178
const sourceFile =
178
179
( languageService as unknown as import ( 'typescript-full' ) . LanguageService ) . getNonBoundSourceFile ?.( fileName ) ??
179
180
languageService . getProgram ( ) ! . getSourceFile ( fileName )
0 commit comments