diff --git a/CHANGELOG.md b/CHANGELOG.md index 80c1102..d97ae2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ All notable changes to **Luix** will be documented in this file. Format follows [Keep a Changelog](https://keepachangelog.com/). +## [Unreleased] + +### Vide events are no longer flagged as unknown props ([#4](https://github.com/ericplane/Luix/issues/4)) + +Vide passes events as plain table keys — `Activated = function() … end`, +`MouseEnter = …`, `MouseButton1Down = …`. Completion already merged the +class's events into the prop list for frameworks with `eventsAsProps`, +but the unknown-prop diagnostic only consulted `flattenClassProps`, so +every Vide event handler on a host class was warned about as +`Unknown property`. The diagnostic now unions `flattenClassEvents` into +its known set when the call's alias belongs to an `eventsAsProps` +framework. React, Roact and Fusion spell events as computed keys and +are unaffected. ## [1.5.2] ### Fusion 0.3 and StyLua-formatted calls are recognised ([#3](https://github.com/ericplane/Luix/issues/3)) diff --git a/src/diagnostics.ts b/src/diagnostics.ts index 775bf57..6d4978e 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -3,6 +3,7 @@ import { getPropType, defaultPropsMap, flattenClassProps, + flattenClassEvents, isDeprecatedValidProp, cornerRadiusConflicts, } from "./data"; @@ -22,7 +23,7 @@ import { } from "./parser"; import { getAutoImportConfig } from "./config"; import { configChangeAffects, getConfig } from "./configCompat"; -import { getAliasPartition } from "./frameworks"; +import { findFrameworkForAlias, getAliasPartition } from "./frameworks"; import { WorkspaceIndex } from "./workspaceIndex"; import { planUICornerRefactor } from "./uiCorner"; @@ -549,6 +550,20 @@ function computePropValidationDiagnostics( // ---- Unknown / wrong-enum (Roblox host class only) ---- if (call.isStringLiteralName && defaultPropsMap[call.className]) { const known = new Set(flattenClassProps(call.className)); + // Frameworks that take events as plain table keys (Vide: + // `Activated = function() … end`) put event names in the same + // props table. Completion already merges them (see + // `completion.ts`); mirror that here so they aren't flagged + // "Unknown property" (issue #4). React/Roact/Fusion spell events + // as computed keys, which the entry scanner never yields. + const framework = call.alias + ? findFrameworkForAlias(call.alias) + : undefined; + if (framework?.eventsAsProps) { + for (const event of flattenClassEvents(call.className)) { + known.add(event); + } + } for (const entry of entries) { if (known.has(entry.key)) { // Check enum type, if we know one. Use class-aware lookup so