From 3108b32d67dc5e010f8e4738126d845af5faac5f Mon Sep 17 00:00:00 2001 From: Rahul Kadyan Date: Tue, 8 Nov 2022 12:22:22 -0800 Subject: [PATCH] Detect correct bound span for definition (#313) --- .../src/features/DefinitionService.ts | 6 ++---- .../src/services/TemplateContextService.ts | 10 +++++----- .../typescript-plugin-vue/types/shared/components.d.ts | 10 ---------- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/packages/typescript-plugin-vue/src/features/DefinitionService.ts b/packages/typescript-plugin-vue/src/features/DefinitionService.ts index b7a801d8..99de073d 100644 --- a/packages/typescript-plugin-vue/src/features/DefinitionService.ts +++ b/packages/typescript-plugin-vue/src/features/DefinitionService.ts @@ -111,11 +111,9 @@ export class DefinitionService return { textSpan: { start: - context.template.loc.start.offset + - context.element.tagLoc.start.offset, - length: - context.element.tagLoc.end.offset - + context.block.loc.start.offset + context.element.tagLoc.start.offset, + length: context.element.tagLoc.source.length, }, definitions: definition.flatMap((definition) => this.processDefinitionInfo(definition), diff --git a/packages/typescript-plugin-vue/src/services/TemplateContextService.ts b/packages/typescript-plugin-vue/src/services/TemplateContextService.ts index 52ec9a8b..0de81b76 100644 --- a/packages/typescript-plugin-vue/src/services/TemplateContextService.ts +++ b/packages/typescript-plugin-vue/src/services/TemplateContextService.ts @@ -37,7 +37,7 @@ interface BaseTemplateContext extends SearchResult { kind: TemplateContextKind document: VueSFCDocument block: Exclude - template: RootNode + root: RootNode offsetInDocument: number offsetInTemplate: number offsetInGenerated: number @@ -117,17 +117,17 @@ export class TemplateContextService { ): TemplateContext | null { const block = document.descriptor.template if (block == null) return null - const template = document.templateAST - if (template == null) return null + const root = document.templateAST + if (root == null) return null const offsetInGenerated = document.generatedOffsetAt(offsetInDocument) if (offsetInGenerated == null) return null const offsetInTemplate = offsetInDocument - block.loc.start.offset - const { node, ancestors } = findTemplateNodeAt(template, offsetInTemplate) + const { node, ancestors } = findTemplateNodeAt(root, offsetInTemplate) if (node == null) return null const shared = { document, block, - template, + root, offsetInDocument, offsetInTemplate, offsetInGenerated, diff --git a/packages/typescript-plugin-vue/types/shared/components.d.ts b/packages/typescript-plugin-vue/types/shared/components.d.ts index bf9ca6ff..1d3105a5 100644 --- a/packages/typescript-plugin-vue/types/shared/components.d.ts +++ b/packages/typescript-plugin-vue/types/shared/components.d.ts @@ -5,16 +5,6 @@ declare module '@vue/runtime-core' { export interface GlobalComponents {} } -declare module '@vue/runtime-dom' { - export interface GlobalComponents {} -} - -// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error -// @ts-ignore -declare module 'vue' { - export interface GlobalComponents {} -} - export function resolveComponent< GlobalComponents, IntrinsicElements,