diff --git a/packages/language-core/lib/codegen/script/scriptSetup.ts b/packages/language-core/lib/codegen/script/scriptSetup.ts index 28730198a7..c53b74be21 100644 --- a/packages/language-core/lib/codegen/script/scriptSetup.ts +++ b/packages/language-core/lib/codegen/script/scriptSetup.ts @@ -5,7 +5,7 @@ import { combineLastMapping, endOfLine, generateSfcBlockSection, newLine } from import { generateComponent, generateEmitsOption } from './component'; import { generateComponentSelf } from './componentSelf'; import type { ScriptCodegenContext } from './context'; -import { ScriptCodegenOptions, generateScriptSectionPartiallyEnding } from './index'; +import { type ScriptCodegenOptions, generateScriptSectionPartiallyEnding } from './index'; import { generateTemplate } from './template'; export function* generateScriptSetupImports( diff --git a/packages/language-core/lib/codegen/template/context.ts b/packages/language-core/lib/codegen/template/context.ts index 4255d6cab3..e9e7ac3c84 100644 --- a/packages/language-core/lib/codegen/template/context.ts +++ b/packages/language-core/lib/codegen/template/context.ts @@ -35,7 +35,7 @@ export function createTemplateCodegenContext(options: Pick { token.errors++; return false; - } + }, }, }; } diff --git a/packages/language-core/lib/codegen/template/elementDirectives.ts b/packages/language-core/lib/codegen/template/elementDirectives.ts index 1eccb0147f..e861c8220c 100644 --- a/packages/language-core/lib/codegen/template/elementDirectives.ts +++ b/packages/language-core/lib/codegen/template/elementDirectives.ts @@ -2,6 +2,7 @@ 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, wrapWith } from '../utils'; import { generateCamelized } from '../utils/camelized'; import { generateStringLiteralKey } from '../utils/stringLiteralKey'; @@ -10,6 +11,15 @@ import type { TemplateCodegenOptions } from './index'; import { generateInterpolation } from './interpolation'; import { generateObjectProperty } from './objectProperty'; +const builtInDirectives = new Set([ + 'cloak', + 'html', + 'memo', + 'once', + 'show', + 'text', +]); + export function* generateElementDirectives( options: TemplateCodegenOptions, ctx: TemplateCodegenContext, @@ -34,7 +44,7 @@ export function* generateElementDirectives( prop.loc.end.offset, ctx.codeFeatures.verification, `__VLS_asFunctionalDirective(`, - ...generateIdentifier(ctx, prop), + ...generateIdentifier(options, ctx, prop), `)(null!, { ...__VLS_directiveBindingRestFields, `, ...generateArg(options, ctx, prop), ...generateModifiers(options, ctx, prop), @@ -46,6 +56,7 @@ export function* generateElementDirectives( } function* generateIdentifier( + options: TemplateCodegenOptions, ctx: TemplateCodegenContext, prop: CompilerDOM.DirectiveNode ): Generator { @@ -58,16 +69,16 @@ function* generateIdentifier( ...generateCamelized( rawName, prop.loc.start.offset, - { - ...ctx.codeFeatures.withoutHighlight, + ctx.resolveCodeFeatures({ + ...codeFeatures.withoutHighlight, // fix https://github.com/vuejs/language-tools/issues/1905 - ...ctx.codeFeatures.additionalCompletion, - verification: false, + ...codeFeatures.additionalCompletion, + verification: options.vueCompilerOptions.checkUnknownDirectives && !builtInDirectives.has(prop.name), navigation: { resolveRenameNewName: camelize, resolveRenameEditText: getPropRenameApply(prop.name), }, - } + }) ) ); } diff --git a/packages/language-core/lib/types.ts b/packages/language-core/lib/types.ts index 0a9ea03d88..523eda9fb2 100644 --- a/packages/language-core/lib/types.ts +++ b/packages/language-core/lib/types.ts @@ -31,6 +31,7 @@ export interface VueCompilerOptions { jsxSlots: boolean; checkUnknownProps: boolean; checkUnknownEvents: boolean; + checkUnknownDirectives: boolean; checkUnknownComponents: boolean; skipTemplateCodegen: boolean; fallthroughAttributes: boolean; diff --git a/packages/language-core/lib/utils/ts.ts b/packages/language-core/lib/utils/ts.ts index d8605b0f75..d9d4877167 100644 --- a/packages/language-core/lib/utils/ts.ts +++ b/packages/language-core/lib/utils/ts.ts @@ -264,6 +264,7 @@ export function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTempla jsxSlots: false, checkUnknownProps: strictTemplates, checkUnknownEvents: strictTemplates, + checkUnknownDirectives: strictTemplates, checkUnknownComponents: strictTemplates, skipTemplateCodegen: false, fallthroughAttributes: false, diff --git a/packages/language-core/schemas/vue-tsconfig.schema.json b/packages/language-core/schemas/vue-tsconfig.schema.json index d2f8613a01..ed60b2c699 100644 --- a/packages/language-core/schemas/vue-tsconfig.schema.json +++ b/packages/language-core/schemas/vue-tsconfig.schema.json @@ -55,6 +55,11 @@ "default": false, "markdownDescription": "Check unknown events. If not set, uses the 'strictTemplates' value." }, + "checkUnknownDirectives": { + "type": "boolean", + "default": false, + "markdownDescription": "Check unknown directives. If not set, uses the 'strictTemplates' value." + }, "checkUnknownComponents": { "type": "boolean", "default": false,