diff --git a/typescript/src/completions/isGoodPositionMethodCompletion.ts b/typescript/src/completions/isGoodPositionMethodCompletion.ts index f13aec06..7dded45e 100644 --- a/typescript/src/completions/isGoodPositionMethodCompletion.ts +++ b/typescript/src/completions/isGoodPositionMethodCompletion.ts @@ -11,6 +11,14 @@ export const isGoodPositionMethodCompletion = (sourceFile: ts.SourceFile, positi // type A = typeof obj["|"] if (ts.isStringLiteralLike(currentNode)) return false if (ts.isNamedExports(currentNode)) return false + if ( + ts.isIdentifier(currentNode) && + ts.isBinaryExpression(currentNode.parent) && + currentNode.parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && + currentNode === currentNode.parent.left + ) { + return false + } if (ts.isIdentifier(currentNode)) currentNode = currentNode.parent if (ts.isExportSpecifier(currentNode)) return false if (ts.isJsxSelfClosingElement(currentNode) || ts.isJsxOpeningElement(currentNode)) return false diff --git a/typescript/src/completionsAtPosition.ts b/typescript/src/completionsAtPosition.ts index 0b453771..18c8b7d0 100644 --- a/typescript/src/completionsAtPosition.ts +++ b/typescript/src/completionsAtPosition.ts @@ -223,9 +223,10 @@ export const getCompletionsAtPosition = ( // ) const indexToPatch = prior.entries.findIndex(({ name, kind }) => name === 'toString' && kind !== ts.ScriptElementKind.warning) if (indexToPatch !== -1) { - prior.entries[indexToPatch]!.insertText = `${prior.entries[indexToPatch]!.insertText ?? prior.entries[indexToPatch]!.name}()` - prior.entries[indexToPatch]!.kind = ts.ScriptElementKind.constElement - // prior.entries[indexToPatch]!.isSnippet = true + const entryToPatch = prior.entries[indexToPatch]! + entryToPatch.insertText = `${entryToPatch.insertText ?? entryToPatch.name}()` + entryToPatch.isSnippet = true + entryToPatch.kind = ts.ScriptElementKind.constElement } } diff --git a/typescript/src/definitions.ts b/typescript/src/definitions.ts index d9378713..efd8c934 100644 --- a/typescript/src/definitions.ts +++ b/typescript/src/definitions.ts @@ -164,14 +164,20 @@ export default (proxy: ts.LanguageService, languageService: ts.LanguageService, const lines = sourceFile.getFullText().split('\n') const { line: curLine } = ts.getLineAndCharacterOfPosition(sourceFile, position) - const VLS_COMPONENT_STRING = `__VLS_templateComponents` - const isTemplateComponent = lines[curLine]?.startsWith(VLS_COMPONENT_STRING) - if (!isTemplateComponent) return + const VLS_COMPONENT_STRINGS = ['__VLS_templateComponents', '__VLS_components'] + const isVLSComponent = VLS_COMPONENT_STRINGS.some(VLS_COMPONENT_STRING => lines[curLine]?.startsWith(VLS_COMPONENT_STRING)) const componentName = lines[curLine]?.match(/\.(\w+);?/)?.[1] - if (!componentName) return - prior.definitions = prior.definitions.filter(({ name }) => !(componentName === name && lines[curLine - 2] === '// @ts-ignore')) + prior.definitions = + !isVLSComponent || !componentName + ? prior.definitions + : prior.definitions.filter(({ name, containerName }) => { + const isDefinitionInComponentsProperty = componentName === name && lines[curLine - 2] === '// @ts-ignore' + const isGlobalComponent = containerName === 'GlobalComponents' + + return !isDefinitionInComponentsProperty || isGlobalComponent + }) } return prior diff --git a/typescript/src/getPatchedNavTree.ts b/typescript/src/getPatchedNavTree.ts index 1affa14d..1aa87c19 100644 --- a/typescript/src/getPatchedNavTree.ts +++ b/typescript/src/getPatchedNavTree.ts @@ -28,6 +28,7 @@ const getPatchedNavModule = (additionalFeatures: AdditionalFeatures): { getNavig // transform?: (found: string, content: string, position: number) => [string?, string?] } const addChildrenRecursivelySwitchFirstCase = ['function addChildrenRecursively(node)', 'switch (node.kind)'] + const typeAliasCaseNeedle = [...addChildrenRecursivelySwitchFirstCase, 'TypeAliasDeclaration */'] const patchLocations: PatchLocation[] = [ { @@ -44,7 +45,7 @@ const getPatchedNavModule = (additionalFeatures: AdditionalFeatures): { getNavig break;`, }, { - searchString: 'case 262 /* SyntaxKind.TypeAliasDeclaration */', + searchString: typeAliasCaseNeedle, linesOffset: 3, // https://github.com/microsoft/TypeScript/pull/52558/ addString: /* js */ ` @@ -54,7 +55,7 @@ const getPatchedNavModule = (additionalFeatures: AdditionalFeatures): { getNavig `, }, { - searchString: 'case 262 /* SyntaxKind.TypeAliasDeclaration */', + searchString: typeAliasCaseNeedle, linesOffset: 0, removeLines: 1, }, diff --git a/typescript/src/volarConfig.ts b/typescript/src/volarConfig.ts index e163198a..7687c315 100644 --- a/typescript/src/volarConfig.ts +++ b/typescript/src/volarConfig.ts @@ -50,7 +50,8 @@ const plugin = ((context, { typescript: tsModule } = {}) => { const getResolvedUserConfig = async () => { const regularConfig = await configurationHost.getConfiguration!('tsEssentialPlugins') - const _vueSpecificConfig = await configurationHost.getConfiguration!('[vue]') + const _vueSpecificConfig = (await configurationHost.getConfiguration!('[vue]')) || {} + const vueSpecificConfig = Object.fromEntries( compact( Object.entries(_vueSpecificConfig).map(([key, value]) => diff --git a/typescript/test/completions.spec.ts b/typescript/test/completions.spec.ts index 8eadd62b..bd11f941 100644 --- a/typescript/test/completions.spec.ts +++ b/typescript/test/completions.spec.ts @@ -56,6 +56,7 @@ test('Banned positions for all method snippets', () => { test({ /*|*/ }) + test/*|*/ = test ; ; ; @@ -83,6 +84,8 @@ test('Not banned positions for method snippets', () => { method: setTimeout/*|*/ }) test2/*|*/ + test = test/*|*/ + test/*|*/ >= test/*|*/ `) for (const [i, pos] of cursorPositions.entries()) { const result = isGoodPositionMethodCompletion(getSourceFile(), pos - 1, defaultConfigFunc)