Skip to content

Commit 626e483

Browse files
committed
fix ts5 completion crash with out of the box settings
1 parent 698926b commit 626e483

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

typescript/src/completionsAtPosition.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import inKeywordCompletions from './inKeywordCompletions'
33
// import * as emmet from '@vscode/emmet-helper'
44
import isInBannedPosition from './completions/isInBannedPosition'
55
import { GetConfig } from './types'
6-
import { findChildContainingExactPosition, findChildContainingPosition } from './utils'
6+
import { findChildContainingExactPosition, findChildContainingPosition, isTs5 } from './utils'
77
import indexSignatureAccessCompletions from './completions/indexSignatureAccess'
88
import fixPropertiesSorting from './completions/fixPropertiesSorting'
99
import { isGoodPositionBuiltinMethodCompletion } from './completions/isGoodPositionMethodCompletion'
@@ -60,7 +60,7 @@ export const getCompletionsAtPosition = (
6060
try {
6161
return languageService.getCompletionsAtPosition(fileName, position, options, formatOptions)
6262
} finally {
63-
unpatch()
63+
unpatch?.()
6464
}
6565
}
6666
let prior = getPrior()
@@ -341,6 +341,8 @@ const arrayMoveItemToFrom = <T>(array: T[], originalItem: ArrayPredicate<T>, ite
341341
}
342342

343343
const patchBuiltinMethods = (c: GetConfig, languageService: ts.LanguageService, isCheckedFile: boolean) => {
344+
if (isTs5 && (isCheckedFile || !c('additionalIncludeExtensions').length)) return
345+
344346
let addFileExtensions: string[] | undefined
345347
const getAddFileExtensions = () => {
346348
const typeChecker = languageService.getProgram()!.getTypeChecker()!

typescript/src/getPatchedNavTree.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { nodeModules } from './utils'
2-
import * as semver from 'semver'
1+
import { isTs5, nodeModules } from './utils'
32
import { createLanguageService } from './dummyLanguageService'
43
import { getCannotFindCodes } from './utils/cannotFindCodes'
5-
import { Configuration } from './types'
64

75
// used at testing only
86
declare const __TS_SEVER_PATH__: string | undefined
@@ -83,8 +81,6 @@ const getPatchedNavModule = (additionalFeatures: AdditionalFeatures): { getNavig
8381
},
8482
]
8583

86-
// semver: can't use compare as it incorrectly works with build postfix
87-
const isTs5 = semver.major(ts.version) >= 5
8884
const {
8985
markerModuleStart,
9086
markerModuleEnd,

typescript/src/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { SetOptional } from 'type-fest'
2+
import * as semver from 'semver'
23

34
export function findChildContainingPosition(typescript: typeof ts, sourceFile: ts.SourceFile, position: number): ts.Node | undefined {
45
function find(node: ts.Node): ts.Node | undefined {
@@ -116,6 +117,9 @@ export const boostExistingSuggestions = (entries: ts.CompletionEntry[], predicat
116117
})
117118
}
118119

120+
// semver: can't use compare as it incorrectly works with build postfix
121+
export const isTs5 = semver.major(ts.version) >= 5
122+
119123
// Workaround esbuild bundle modules
120124
export const nodeModules = __WEB__
121125
? null

0 commit comments

Comments
 (0)