Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Fix for livewire form properties not being found. #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/DataStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
6 changes: 6 additions & 0 deletions app/Dto/BladeComponentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '';
Expand Down
16 changes: 16 additions & 0 deletions app/Lsp/LspValidators/LivewireLspValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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'],
Expand Down