Skip to content

Commit

Permalink
fix: better error message in devtools console when TS misbehaves (you…
Browse files Browse the repository at this point in the history
… will see no completions in this case)
  • Loading branch information
zardoy committed Aug 9, 2023
1 parent e144fe6 commit cffd4bc
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions typescript/src/completionsAtPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export const getCompletionsAtPosition = (
const sourceFile = program?.getSourceFile(fileName)
if (!program || !sourceFile) return
if (!scriptSnapshot || isInBannedPosition(position, scriptSnapshot, sourceFile)) return
// just pick up random setting to check if we they are here
if (c('correctSorting.enable') === undefined) {
throw new Error(
"Plugin didn't get required user settings (config). Most probably there is a problem with TypeScript. Either restart TS server, use stable TS version or disable typescript-essentials-plugin if you need to test this TS version",
)
}
const exactNode = findChildContainingExactPosition(sourceFile, position)
const isCheckedFile =
!tsFull.isSourceFileJS(sourceFile as any) || !!tsFull.isCheckJsEnabledForFile(sourceFile as any, additionalData.compilerOptions as any)
Expand Down Expand Up @@ -226,11 +232,6 @@ export const getCompletionsAtPosition = (
// if (c('completionHelpers') && node) prior.entries = objectLiteralHelpers(node, prior.entries) ?? prior.entries

if (c('patchToString.enable')) {
// const indexToPatch = arrayMoveItemToFrom(
// prior.entries,
// ({ name }) => name === 'toExponential',
// ({ name }) => name === 'toString',
// )
const indexToPatch = prior.entries.findIndex(({ name, kind }) => name === 'toString' && kind !== ts.ScriptElementKind.warning)
if (indexToPatch !== -1) {
const entryToPatch = prior.entries[indexToPatch]!
Expand Down

0 comments on commit cffd4bc

Please sign in to comment.