Skip to content

Commit

Permalink
refactor(language-core): remove invalid rename hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Mar 7, 2025
1 parent 34538b9 commit a2027e9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 59 deletions.
21 changes: 1 addition & 20 deletions packages/language-core/lib/codegen/script/src.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,7 @@ export function* generateSrc(src: SfcBlockAttr): Generator<Code> {
yield `export * from `;
yield* generateSfcBlockAttrValue(src, text, {
...codeFeatures.all,
navigation: text === src.text
? true
: {
shouldRename: () => false,
resolveRenameEditText(newName) {
if (newName.endsWith('.jsx') || newName.endsWith('.js')) {
newName = newName.split('.').slice(0, -1).join('.');
}
if (src?.text.endsWith('.d.ts')) {
newName = newName + '.d.ts';
}
else if (src?.text.endsWith('.ts')) {
newName = newName + '.ts';
}
else if (src?.text.endsWith('.tsx')) {
newName = newName + '.tsx';
}
return newName;
},
},
...text === src.text ? codeFeatures.navigation : codeFeatures.navigationWithoutRename,
});
yield endOfLine;
yield `export { default } from '${text}'${endOfLine}`;
Expand Down
25 changes: 3 additions & 22 deletions packages/language-core/lib/codegen/template/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as CompilerDOM from '@vue/compiler-dom';
import { camelize, capitalize } from '@vue/shared';
import type { Code, VueCodeInformation } from '../../types';
import { getSlotsPropertyName, hyphenateTag } from '../../utils/shared';
import { codeFeatures } from '../codeFeatures';
import { createVBindShorthandInlayHintInfo } from '../inlayHints';
import { endOfLine, identifierRegex, newLine, normalizeAttributeValue } from '../utils';
import { generateCamelized } from '../utils/camelized';
Expand Down Expand Up @@ -102,13 +103,7 @@ export function* generateComponent(
shouldCapitalize ? capitalize(node.tag) : node.tag,
'template',
tagOffset,
{
...ctx.codeFeatures.withoutHighlightAndCompletion,
navigation: {
resolveRenameNewName: camelizeComponentName,
resolveRenameEditText: getTagRenameApply(node.tag),
},
}
ctx.codeFeatures.withoutHighlightAndCompletion
);
}
yield `, `;
Expand Down Expand Up @@ -171,18 +166,12 @@ export function* generateComponent(
yield `/** @type {[`;
for (const tagOffset of tagOffsets) {
for (const shouldCapitalize of (node.tag[0] === node.tag[0].toUpperCase() ? [false] : [true, false])) {
const expectName = shouldCapitalize ? capitalize(camelizedTag) : camelizedTag;
yield `typeof __VLS_components.`;
yield* generateCamelized(
shouldCapitalize ? capitalize(node.tag) : node.tag,
'template',
tagOffset,
{
navigation: {
resolveRenameNewName: node.tag !== expectName ? camelizeComponentName : undefined,
resolveRenameEditText: getTagRenameApply(node.tag),
},
}
codeFeatures.navigation
);
yield `, `;
}
Expand Down Expand Up @@ -510,11 +499,3 @@ function hasVBindAttrs(
)
);
}

function camelizeComponentName(newName: string) {
return camelize('-' + newName);
}

function getTagRenameApply(oldName: string) {
return oldName === hyphenateTag(oldName) ? hyphenateTag : undefined;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as CompilerDOM from '@vue/compiler-dom';
import { camelize } from '@vue/shared';
import type { Code } from '../../types';
import { hyphenateAttr } from '../../utils/shared';
import { codeFeatures } from '../codeFeatures';
import { endOfLine } from '../utils';
import { generateCamelized } from '../utils/camelized';
Expand Down Expand Up @@ -77,10 +76,6 @@ function* generateIdentifier(
// fix https://github.com/vuejs/language-tools/issues/1905
...codeFeatures.additionalCompletion,
verification: options.vueCompilerOptions.checkUnknownDirectives && !builtInDirectives.has(prop.name),
navigation: {
resolveRenameNewName: camelize,
resolveRenameEditText: getPropRenameApply(prop.name),
},
})
)
);
Expand Down Expand Up @@ -187,7 +182,3 @@ function* generateValue(
ctx.codeFeatures.all
);
}

function getPropRenameApply(oldName: string) {
return oldName === hyphenateAttr(oldName) ? hyphenateAttr : undefined;
}
11 changes: 3 additions & 8 deletions packages/language-core/lib/codegen/template/elementProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function* generateElementProps(

const shouldSpread = propName === 'style' || propName === 'class';
const shouldCamelize = isComponent && getShouldCamelize(options, prop, propName);
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck, shouldCamelize);
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck);

if (shouldSpread) {
yield `...{ `;
Expand Down Expand Up @@ -197,7 +197,7 @@ export function* generateElementProps(

const shouldSpread = prop.name === 'style' || prop.name === 'class';
const shouldCamelize = isComponent && getShouldCamelize(options, prop, prop.name);
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck, true);
const codeInfo = getPropsCodeInfo(ctx, strictPropsCheck);

if (shouldSpread) {
yield `...{ `;
Expand Down Expand Up @@ -378,15 +378,10 @@ function getShouldCamelize(

function getPropsCodeInfo(
ctx: TemplateCodegenContext,
strictPropsCheck: boolean,
shouldCamelize: boolean
strictPropsCheck: boolean
): VueCodeInformation {
return ctx.resolveCodeFeatures({
...codeFeatures.withoutHighlightAndCompletion,
navigation: {
resolveRenameNewName: camelize,
resolveRenameEditText: shouldCamelize ? hyphenateAttr : undefined,
},
verification: strictPropsCheck || {
shouldReport(_source, code) {
// https://typescript.tv/errors/#ts2353
Expand Down

0 comments on commit a2027e9

Please sign in to comment.