Skip to content

Commit

Permalink
Detect correct bound span for definition (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
znck authored Nov 8, 2022
1 parent 000a6e6 commit 3108b32
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface BaseTemplateContext extends SearchResult {
kind: TemplateContextKind
document: VueSFCDocument
block: Exclude<VueSFCDocument['descriptor']['template'], null>
template: RootNode
root: RootNode
offsetInDocument: number
offsetInTemplate: number
offsetInGenerated: number
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions packages/typescript-plugin-vue/types/shared/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3108b32

Please sign in to comment.