Sublime Forum

PHP 8.1 introduced Enums, is there a support for them in ST?

#1

Hi,

I’d like to kindly ask you about PHP syntaxt support. On November 25, 2021 PHP 8.1 was released, introducing Enums. It’s one year later and current build still does not support this feature. There is no working “jump to definition” nor the syntax highlight.

Also from another topic - namespaces in PHP are also highlighted weirdly. And so do the PHP constructor properties:

42

When in fact, it should look somehow like that:

57

Thanks for any answers

0 Likes

#2

Mind providing a copy-able text so people can copy for testing?

0 Likes

#3

Sure.

Example of an enum:

	<?php declare(strict_types = 1);

namespace App\Infrastructure\Http\Enum;

enum CookieName: string
{

	case SOME_COOKIE = 'SomeCookie';
	case ANOTHER_COOKIE = 'AnotherCookie';
}

Example of a normal namespaced PHP code:

	<?php declare(strict_types = 1);

namespace Awesome\Namespace\Foo;

use Psr\Http\Message\RequestInterface;

final class MyExample implements IExample
{

	private ?RequestInterface $request;


	public function __construct(
		public readonly string $username,
		private int $age,
		?RequestInterface $request = null
	) {
		$this->request = $request;
	}
}
0 Likes

#4

Both looks fine on my side.

The scope of namespace had been changed intentionally indeed. Fwiw, ST’s syntax works for PHP 8.2 grammar already.

0 Likes

#5

Maybe you can try to delete the cache directory. sublime.cache_path() should tells where the directory is.

0 Likes

#6

Actually, it looks broken on your side too.

Does “jump to definition” work with the Enum? That means, Writing somewhere “CookieName” and by hitting “jump to definition” ST will take you to the Enum file?

Also, both namespace and “use” statement looks weird in your screenshot. It seems white (plain-text) even though it is a namespace. In previous versions (ST 2), the whole “use” statement was blue. Why only the “RequestInterface” now?

0 Likes

#7

For weirdnes, that’s personal taste (color scheme). As long as scopes (syntax definition) are correct, I consider it works.

0 Likes

#8

yes, it bring me to the definition.

<?php declare(strict_types = 1);

namespace App\Infrastructure\Http\Enum;

enum CookieName: string
{

    case SOME_COOKIE = 'SomeCookie';
    case ANOTHER_COOKIE = 'AnotherCookie';
}

$status = CookieName::ANOTHER_COOKIE;
//        ^^^^^^^^^^ F12 works
0 Likes

#9

It does not work for me. :confused:

0 Likes

#10

Since you didn’t response to PHP 8.1 introduced Enums, is there a support for them in ST?, let me mention it again. Also, it would be good to clear ../Index too.

0 Likes

Text background
#11

Well, sure it is a personal preference. But since ST 2 showed it “correctly”, as do other IDEs, for example VS Code:

I would expect ST 3 not to introduce such BC breakes.

But alright, I understand it behaves correctly and I just need to adjust the theme color somehow? Could you plese guide me where can I change the color of it so it looks the same as it looked in ST 2 before or in other IDEs? Thanks a lot.

0 Likes

#12

I cleared the Index and the Cache. Nice, works now! Thx

0 Likes

#13

VC Code and many other IDEs still rely in ancient TextMate color schemes, which match paths and other terms/expressions as complete tokens and assign single scopes, mainly because it wasn’t possible to apply more detailed scopes.

ST started to scope each element of a path or qualified identifier independently, long ago and it is applied to all syntaxes step by step as single parts or whole syntaxes are improved.

This is what enables ST to support “Goto Definition” even for such namespace parts.

Also note, how VS Code scopes the use Hurricane\Method\ImethodDto very much the same way.

So the screenshot doesn’t actually provide any compelling arguments for the lagecy/plumping way of scoping things.

0 Likes

#14

Alright, I understand that. So my questino is:

I just need to adjust the theme color somehow - could you plese guide me where can I change the color of it so it looks the same as it looked in ST 2 before or in other IDEs?

Thanks a lot.

0 Likes

#15

Color schemes can be customized by creating user defined overrides via UI: Customize Color Scheme command.

You can use ctrl+alt+shift+p to display scope names at the caret’s positions. Those can be used to create color scheme rules.

To scope identifiers in namespace and use statements the resulting color scheme rules may look as follows:

{
	"rules":
	[
		{
			"scope": "meta.namespace meta.path variable.namespace, meta.namespace meta.path entity.name, meta.namespace meta.path punctuation.accessor",
			"foreground": "#b77fdb",
		},
		{
			"scope": "meta.use meta.path variable.namespace, meta.use meta.path support.class, meta.use meta.path punctuation.accessor",
			"foreground": "#b77fdb",
		},
	]
}
0 Likes

#16

Haha, thanks! I was looking for both those things.

Resolved, thank you.

0 Likes