atom/language-php

Function name after newline not classified correctly

Opened this issue · 1 comments

<?php

	$x = new class {
		public function
		test(string $hi): string {
			return $hi;
		}
	};
?>

<div class="xyz"></div>
  • Check scopes at test, see that it's a function call meta.function-call.php. This newline is allowed
<?php

	$x = new class {
		public function test(string $hi): string {
			return $hi;
		}
	};
?>

<div class="xyz"></div>
  • Now it's a function in a class body
entity.name.function.php
meta.function.php
meta.class.body.php

Not a problem normally but I think it is the root cause behind an issue like microsoft/vscode#124381 where unexpected syntax in the first context causes more problems

This is very strange formatting, and I'm not sure if we should even fix this. We are supporting PSR format and this should be used. We're unable to make TM based syntax 100% accurate and we need to draw a line somewhere.

For the records code responsible for this:

'begin': '''(?x)
((?:(?:final|abstract|public|private|protected|static)\\s+)*)
(function)\\s+
(?i:
(__(?:call|construct|debugInfo|destruct|get|set|isset|unset|toString|
clone|set_state|sleep|wakeup|autoload|invoke|callStatic|serialize|unserialize))
|(?:(&)?\\s*([a-zA-Z_\\x{7f}-\\x{7fffffff}][a-zA-Z0-9_\\x{7f}-\\x{7fffffff}]*))
)
\\s*(\\()
'''