Skip to content

Commit 24fb67a

Browse files
author
Ilya Golovin
committed
feat: skip identifiers in vue template for addDestructure code action
1 parent 273cfe5 commit 24fb67a

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

typescript/src/completionsAtPosition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import _ from 'lodash'
22
import { compact } from '@zardoy/utils'
33
import escapeStringRegexp from 'escape-string-regexp'
4+
import isVueFileName from './utils/vue/isVueFileName'
45
import inKeywordCompletions from './completions/inKeywordCompletions'
56
import isInBannedPosition from './completions/isInBannedPosition'
67
import { GetConfig } from './types'
@@ -266,7 +267,6 @@ export const getCompletionsAtPosition = (
266267
prior.entries = arrayMethods(prior.entries, position, sourceFile, c) ?? prior.entries
267268
prior.entries = jsdocDefault(prior.entries, position, sourceFile, languageService) ?? prior.entries
268269

269-
const isVueFileName = (fileName: string | undefined) => fileName && (fileName.endsWith('.vue.ts') || fileName.endsWith('.vue.js'))
270270
// #region Vue (Volar) specific
271271
const isVueFile = isVueFileName(fileName)
272272
if (isVueFile && exactNode) {

typescript/src/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { Except, SetOptional } from 'type-fest'
33
import * as semver from 'semver'
44
import type { MatchParentsType } from './utilTypes'
5+
import isVueFileName from './utils/vue/isVueFileName'
56

67
export function findChildContainingPosition(typescript: typeof ts, sourceFile: ts.SourceFile, position: number): ts.Node | undefined {
78
function find(node: ts.Node): ts.Node | undefined {
@@ -354,7 +355,7 @@ export const isValidInitializerForDestructure = (match: ts.Expression) => {
354355

355356
return true
356357
}
357-
export const isNameUniqueAtLocation = (name: string, location: ts.Node | undefined, typeChecker: ts.TypeChecker) => {
358+
export const isNameUniqueAtLocation = (name: string, location: ts.Node, typeChecker: ts.TypeChecker) => {
358359
const checker = getFullTypeChecker(typeChecker)
359360
let hasCollision: boolean | undefined
360361

@@ -366,7 +367,6 @@ export const isNameUniqueAtLocation = (name: string, location: ts.Node | undefin
366367
childNode.forEachChild(checkCollision)
367368
}
368369
}
369-
if (!location) return
370370

371371
if (ts.isSourceFile(location)) {
372372
hasCollision = createUniqueName(name, location as any) !== name
@@ -385,6 +385,8 @@ const getClosestParentScope = (node: ts.Node) => {
385385
}
386386
export const isNameUniqueAtNodeClosestScope = (name: string, node: ts.Node, typeChecker: ts.TypeChecker) => {
387387
const closestScope = getClosestParentScope(node)
388+
if (!closestScope) return
389+
388390
return isNameUniqueAtLocation(name, closestScope, typeChecker)
389391
}
390392

@@ -423,6 +425,9 @@ const createUniqueName = (name: string, sourceFile: ts.SourceFile) => {
423425
return (parent as ts.ImportSpecifier).propertyName !== node
424426
case ts.SyntaxKind.PropertyAssignment:
425427
return (parent as ts.PropertyAssignment).name !== node
428+
// Skip identifiers in vue template
429+
case ts.SyntaxKind.ArrayLiteralExpression:
430+
return !isVueFileName(sourceFile.fileName)
426431
default:
427432
return true
428433
}
@@ -437,6 +442,7 @@ const createUniqueName = (name: string, sourceFile: ts.SourceFile) => {
437442
while (identifiers.includes(name)) {
438443
name = `_${name}`
439444
}
445+
440446
return name
441447
}
442448

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default (fileName: string) => fileName.endsWith('.vue.ts') || fileName.endsWith('.vue.js')

0 commit comments

Comments
 (0)