From 313dd26b38d9f0cf0b89272fedf630839cb752ee Mon Sep 17 00:00:00 2001 From: Ilya Golovin Date: Fri, 2 Jun 2023 14:45:19 +0300 Subject: [PATCH 1/5] fix: handle case with no vue specific config --- typescript/src/volarConfig.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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]) => From b64a4f7d94d7c37bca4f4a3f801c339bfde057f4 Mon Sep 17 00:00:00 2001 From: Ilya Golovin <74474615+maIIady@users.noreply.github.com> Date: Sat, 10 Jun 2023 20:55:45 +0300 Subject: [PATCH 2/5] fix(vue support): restore broken definitions, use more precise way to filter out components definitions (#133) --- typescript/src/definitions.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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 From 4ab7111600c77093ce7ff25864c42a315c4e51b8 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Sat, 10 Jun 2023 20:56:52 +0300 Subject: [PATCH 3/5] fix: ban method snippets in the following location: `test/*|*/ = () => {}` --- .../src/completions/isGoodPositionMethodCompletion.ts | 8 ++++++++ typescript/test/completions.spec.ts | 3 +++ 2 files changed, 11 insertions(+) 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/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) From 7e27619a3a54e94a2a0febaf9da97d385a11d0fa Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Sat, 10 Jun 2023 21:03:03 +0300 Subject: [PATCH 4/5] fix: fix toString patching out of the box --- typescript/src/completionsAtPosition.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 } } From 55f4aac502495967091885679bca37fe48e23ef4 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Sat, 10 Jun 2023 21:27:23 +0300 Subject: [PATCH 5/5] fix: better type alias in navbar patching --- typescript/src/getPatchedNavTree.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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, },