Skip to content

Commit

Permalink
Fix for comments in function argument lists
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Aug 27, 2024
1 parent 4c90828 commit 1b4fc5c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Fix for blade echo highlighting within comments (#113)
- Fix for static property types (#129)
- Fix for attribute in promoted property (#133)
- Fix for comments in function argument lists (#134)

## 2.8.2

Expand Down
8 changes: 8 additions & 0 deletions src/Languages/Php/PhpTypeLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
use Tempest\Highlight\Languages\Base\BaseLanguage;
use Tempest\Highlight\Languages\Php\Injections\PhpAttributeInstanceInjection;
use Tempest\Highlight\Languages\Php\Injections\PhpAttributePlainInjection;
use Tempest\Highlight\Languages\Php\Injections\PhpDocCommentInjection;
use Tempest\Highlight\Languages\Php\Patterns\ClassPropertyPattern;
use Tempest\Highlight\Languages\Php\Patterns\KeywordPattern;
use Tempest\Highlight\Languages\Php\Patterns\MultilineSingleDocCommentPattern;
use Tempest\Highlight\Languages\Php\Patterns\NewObjectPattern;
use Tempest\Highlight\Languages\Php\Patterns\SinglelineCommentPattern;
use Tempest\Highlight\Languages\Php\Patterns\TypeForVariablePattern;

final class PhpTypeLanguage extends BaseLanguage
Expand All @@ -25,6 +28,7 @@ public function getInjections(): array
...parent::getInjections(),
new PhpAttributePlainInjection(),
new PhpAttributeInstanceInjection(),
new PhpDocCommentInjection(),
];
}

Expand All @@ -33,6 +37,10 @@ public function getPatterns(): array
return [
...parent::getPatterns(),

// COMMENTS
new MultilineSingleDocCommentPattern(),
new SinglelineCommentPattern(),

new KeywordPattern('public'),
new KeywordPattern('private'),
new KeywordPattern('protected'),
Expand Down
21 changes: 20 additions & 1 deletion tests/Languages/Php/PhpLanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,26 @@ public function info(
#[Lazy] public Author $author,
) {}', '<span class="hl-keyword">public</span> <span class="hl-keyword">function</span> <span class="hl-property">__construct</span>(<span class="hl-injection">
<span class="hl-attribute">#[<span class="hl-type">Lazy</span>]</span> <span class="hl-keyword">public</span> <span class="hl-type">Author</span> <span class="hl-property">$author</span>,
</span>) {}']
</span>) {}'],
[' public function __construct(
// Allow a union on a special "missing relation" type:
public Relation|Author $author,
// Making the relation nullable would be an option as well:
/** @var Chapter[] $chapters */
/**
* hello */
public ?array $chapters,
) {}', ' <span class="hl-keyword">public</span> <span class="hl-keyword">function</span> <span class="hl-property">__construct</span>(<span class="hl-injection">
<span class="hl-comment">// Allow a union on a special &quot;missing relation&quot; type:</span>
<span class="hl-keyword">public</span> <span class="hl-type">Relation|Author</span> <span class="hl-property">$author</span>,
<span class="hl-comment">// Making the relation nullable would be an option as well:</span>
<span class="hl-comment">/** <span class="hl-value"><span class="hl-value">@var</span></span> <span class="hl-type">Chapter[]</span> <span class="hl-variable"><span class="hl-variable">$chapters</span></span> */</span>
<span class="hl-comment">/**
* hello */</span>
<span class="hl-keyword">public</span> <span class="hl-type">?array</span> <span class="hl-property">$chapters</span>,
</span>) {}'],
];
}
}
13 changes: 10 additions & 3 deletions tests/targets/test.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
```php
public function __construct(
#[Lazy] public Author $author,
) {}
public function __construct(
// Allow a union on a special "missing relation" type:
public Relation|Author $author,

// Making the relation nullable would be an option as well:
/** @var Chapter[] $chapters */
/**
* hello */
public ?array $chapters,
) {}
```

0 comments on commit 1b4fc5c

Please sign in to comment.