diff --git a/app/DataStore.php b/app/DataStore.php index 9f75cc9..b6cd4cb 100644 --- a/app/DataStore.php +++ b/app/DataStore.php @@ -70,6 +70,19 @@ public function findComponentForFile(TextDocumentItem $file): ?BladeComponentDat return $matchingComponent; } + public function findComponentForClass(string $className): ?BladeComponentData + { + $matchingComponent = null; + + foreach ($this->availableComponents as $component) { + if ($component->matchesClass($className)) { + $matchingComponent = $component; + break; + } + } + return $matchingComponent; + } + public function refreshAvailableComponents(bool $force = false): Collection { if (self::$inprogress === false && ($this->availableComponents->isEmpty() || $force)) { diff --git a/app/Dto/BladeComponentData.php b/app/Dto/BladeComponentData.php index 1e31915..5389889 100644 --- a/app/Dto/BladeComponentData.php +++ b/app/Dto/BladeComponentData.php @@ -31,6 +31,12 @@ public function matchesView(string $viewFilePath): bool return false; } + // Check if the view file is from this component. + public function matchesClass(string $className): bool + { + return $this->class === $className; + } + public function getHoverData(): string { return $this->doc ?? $this->getFile() ?? $this->class ?? ''; diff --git a/app/Lsp/LspValidators/LivewireLspValidate.php b/app/Lsp/LspValidators/LivewireLspValidate.php index cb5256c..e668c08 100644 --- a/app/Lsp/LspValidators/LivewireLspValidate.php +++ b/app/Lsp/LspValidators/LivewireLspValidate.php @@ -31,6 +31,17 @@ public function getErrors(TextDocumentItem $document): array ]); } + $nestedProps = []; + foreach ($component->wireProps as $prop => $className) { + $nestedComponent = $this->store->findComponentForClass('\\' . $className); + if (!$nestedComponent) { + continue; + } + foreach (array_keys($nestedComponent->wireProps) as $nestedProp) { + $nestedProps[] = $prop . '.' . $nestedProp; + } + } + $wireModels = $workableArray ->filter(function ($item) { // Only get models. @@ -39,8 +50,13 @@ public function getErrors(TextDocumentItem $document): array ->filter(function ($item) use ($component) { // Check if they are in the list. return !array_key_exists($item['name'], $component->wireProps); + }) + ->filter(function ($item) use ($nestedProps) { + // Check if they are nested. + return !in_array($item['name'], $nestedProps); }); + foreach ($wireModels as $missingWireable) { $errors[] = new DiagnosticError( error: 'Wireable not found: ' . $missingWireable['name'],