Upgrades in Latte plugin for PHPStorm

3 months ago

mesour
Member | 218
+
+26
-

Introducing

I'm working on upgrade for Latte plugin for PHPStorm. Now is in the beta version only, you can download and test it by download link. It can be installed from disk (help for install). I will be happy if as many people as possible try it out before we release the official version. There were a lot of changes, so let’s test it out.

Before stable will be released, new beta versions will be pushed to Github and in this forum will be posted information about new update. Download link will be same.

Links

  • DOWNLOAD
  • Custom template class… – More informations about new templateType macro. Macro varType is equivalent for /** @var string|null $foo */ and have this syntax: {vatType string|null $foo}.
  • I also created small update for Neon plugin

Issues

If you find some bug, please reply to this topic and I will add it to issues list.

Important notes

  • Refactoring for class names is now supported only from PHP to Latte

Changelist

  • Increased minimum compatibility with PhpStorm version to 2017.3 from PhpStorm 8 (pre-2016.2 IDE version)
  • added support for PHP content
  • added variable types
  • added highlighting and go to source support for latte variables
  • added support for define custom default variables per project
  • added completions for latte variables, PHP functions, methods, constants and properties
  • added varType macro
  • added templateType macro
  • added support for define type in {var Bar\FooClass $class = …}
  • added support for mime types and completion it in contentType macro
  • added reference search for usages from PHP to Latte (for classes, methods, properties and constants)
  • added brace matcher for highlight braces
  • added go to source for class names, methods, constants and properties
  • added support for highlighting macro name and pair macro
  • added support for refactoring rename (methods, properties, constants and class names)
  • added code-completion for latte filters
  • added support for adding custom latte filters
  • added UI for setting custom variables, filters and macros
  • added inspections for:
    • class usages (Undefined class)
    • checking not defined variables, more definitions with same variable name etc.
    • checking constant, property and methods visibility (if is not public it make warning)
    • checking not existing constants, properties and methods
    • checking static methods and properties used non statically and vice versa
    • checking valid content for templateType, varType and var macro
    • checking existing latte filters

Donate

More of you wrote that they would like to contribute to development. I appreciate it, thanks. So I'm adding a link to PayPal and a bank account number. Donors will be posted here on the forum and in the future somewhere on the web with information about the Latte plugin (if you want, then write a payment note with your name for the recipient).

  • Patreon – more tiers
  • PayPal
  • CZ bank account: 2600850198/2010
Donor list

Last edited by mesour (2020-03-03 21:28)

3 months ago

mesour
Member | 218
+
+7
-

Update 01

I added this to latest update (can be donwloaded by download link in main post):

  • Support for refactoring rename
  • Support for classes not starting with \ and completion without \
  • Added support for PHP functions (completions, reference…)
  • Added completion type hints like string, int… in varType macro
  • Added better support for strings and support for variable used in double quoted string like: "foo-string $bar"

This is new compared to the version that has been on the Slack.

3 months ago

mesour
Member | 218
+
+10
-

Update 02

I added this to latest update (can be donwloaded by download link in main post):

  • Fixed bug with refactoring rename
  • Fixed bug in completion and reference class members if class name is without \ and if is |null in type
  • Added support for define type in {var Bar\FooClass $class = ...}
  • Added support for define variable in macro {capture $definition}
  • Added completion for content types to {contentType application/json} macro

I think this can be first release candidate. Because all important features are implemented. Only minor changes are in need fix section in issues list.

  • Please if someone have PHPStorm with Java version 8, test it. I change settings for project and try it compile it for Java 8, but it is hard to test for me with Java 11.

Last edited by mesour (2020-01-07 22:06)

3 months ago

mesour
Member | 218
+
+12
-

Update 03

I added this to latest update (can be donwloaded by download link in main post):

  • Added some performance improvements
  • Added code-completion for latte filters
  • Added support for adding custom latte filters
  • Added UI for setting custom variables, filters and macros
  • Added inspection for checking existing latte filters

Now Im waiting for review and some things to solve around the merge to the main repository. After this it can be released. But I think it's good to wait a week or two for finding bugs in this version. Only adding templatePrint macro is planed to this version. Next features really in future versions.

If you want donate, I added a section to main post.

Last edited by mesour (2020-01-08 19:16)

3 months ago

mesour
Member | 218
+
+9
-

Update 04

I added this to the latest update (can be downloaded by a download link in the main post):

  • Added support for templatePrint macro
  • Added tests for LattePhpLexer
  • Added completion for macro end tag
  • Improved n: attributes completion
  • Improved pages with settings for (macros, variables, and custom functions)
  • Fixed bug in completion for the end tag macro
  • Fixed annotator messages and annotating for some cases
  • Nette macros moved to custom configurations and can be disabled for the project with Latte only
  • Fixed bugs with unclosed block macro and translate macro
  • Fixed macro completion at the end of the file

I have created a pull request. Now it is mergeable without conflicts. Now I'm working only on testing and bug fixing.

Last edited by mesour (2020-01-13 21:10)

2 months ago

mesour
Member | 218
+
+9
-

Update 05

I added this to the latest update (can be downloaded by a download link in the main post):

  • Fixed bug in filters completion and settings

You have not reported any bugs for ~2 weeks and this update is minor. Now I will merge it to master and I will initiate for the plugin to be published.

Last edited by mesour (2020-01-25 08:49)

2 months ago

mesour
Member | 218
+
+7
-

Update 06

I added this to the latest update (can be downloaded by a download link in the main post):

  • Changed functionality for reset buttons in settings (now working only with Nette macros, variables…)
  • Renamed macro to tag
  • Fixed bugs in macro settings UI
  • Fixed completion for magic methods prefixed with __ (complete only if __ is typed)
  • Fixed bug in completion for custom-defined filters

This is the latest update before release.

2 months ago

Tomáš Jacík
Member | 144
+
+1
-

@mesour Can you post your account number here? Are you able to make an invoice if my company donate too?

Thanks

2 months ago

mesour
Member | 218
+
0
-

@TomášJacík I added the bank account to Donate information in the main post. I can make an invoice. If you want, email me by the contact form here: https://mesour.com/cs#… or message me on Slack

Last edited by mesour (2020-02-10 19:32)

2 months ago

mesour
Member | 218
+
+9
-

Version 1.0.0

I merged it to master and asked competent people to publish a new version of the plugin.

This is planed in the next version (v1.0.2)

  • Fix and add more if completing code (for faster code writing in latte templates)
    • Complete variables without typing $
    • and more…
  • Try to implement some performance improvements
  • Fix resolving methods if a type is more classes FooClass|BarClass (sometimes bugging)
  • And more bug fixes if someone reports a new bug

Important planed features (v1.1.0)

  • Add support for optional chaining
    • {$order->item?->name}, {if $blogPost?->count(‘*’)}
    • Add intention for add optional chaining
  • Added resolving in foreach and ArrayAccess ($arr['foo']) for types defined with []. Example: FooClass[]
  • Inspections
    • For checking nullable types (eg. calling method on nullable variable)
    • For checking foreach value, must be array or iterable
    • For used @deprecated and @internal PHP elements

Last edited by mesour (2020-02-18 02:23)

2 months ago

mesour
Member | 218
+
+1
-

The plugin is not yet published to JetBrains repository. I updated the download link in main post to download the current version.

2 months ago

mesour
Member | 218
+
+7
-

A new version of the plugin has been submitted for moderation. Now we are waiting for a security check from JetBrains. The request will be processed within two business days. After this, the plugin will be visible and downloadable for all, normally from IDEA Preferences -> Plugins.

Last edited by mesour (2020-02-10 19:18)

2 months ago

Milo
Nette Core | 1148
+
+2
-

Hi. This is awesome and thanks for your work!

I'm excited about {varType} macro and Latte autocompletion. Unfortunatelly, I'm running Latte v2.6. So, I published small LatteBackportMacros class as a workaround before upgrade to 2.7.

2 months ago

mesour
Member | 218
+
+10
-

Thank you all for your positive feedback and donating. In the future, I plan to update the plugin to make work with it even easier :)


Version 1.0.2

Version 1.0.1 was released and here is a new planed update.

If you want, you can test it by direct download from GitHub: DOWNLOAD and install it manually from a disc.

I added this to the latest update:

  • added code style settings (settings for use tabs or spaces) (issue #46, #30)
  • added support for define variable in tag {default $foo = 123}
  • added class namespaces completion
  • added support for define variables by {php [$foo, $bar] = $arr}
  • implemented some performance improvements
  • fixed resolving methods if a type is more classes FooClass|BarClass
  • fixed completion for unpaired macro after if missing end }
  • fixed filters on variables (issue #47)
  • fixed wrong indent for elseifset (issue #42)
  • fixed multiple variable definitions in for/foreach cycles
  • fixed auto-complete (disabled in strings, more improvements)
  • increased minimum compatibility to 2018.3

I'll wait a week for the bugs report and after this, I'll release this version.

Last edited by mesour (2020-02-18 18:31)

about a month ago

MajklNajt
Member | 320
+
0
-

hi @mesour, first I want to thank you for this plugin, nice work!

I have one surprising behavior, I have template:

{varType Student $student}
{$student->getCourse()->getName()}

Above is analysed fine getName is known method, but if I assign variable:

{varType Student $student}
{var $course = $student->getCourse()} <-- whithout type definition
{$course->getName()}

…method getName is highlighted as unknown.

For completion – interfaces of PHP classes:

interface Student {
	public function getCourse(): Course;
}

interface Course {
	public function getName(): string;
}

Is this expected behavior?

about a month ago

Milo
Nette Core | 1148
+
0
-

Issue: Support stdClass type

If I typehint variable as {varType stdClass $data} I get an error First value in {varType} tag must be typehint. When I use typehint \stdClass the error disappears but I still see higlighted properties like Property 'xyz' not found on $data->xyz.

Would be great to accept any property with stdClass.

about a month ago

dkorpar
Backer | 87
+
0
-

Milo wrote:

Issue: Support stdClass type

If I typehint variable as {varType stdClass $data} I get an error First value in {varType} tag must be typehint. When I use typehint \stdClass the error disappears but I still see higlighted properties like Property 'xyz' not found on $data->xyz.

Would be great to accept any property with stdClass.

what's the point of even using varType if you set it as stdClass?

about a month ago

David Grudl
Nette Core | 6985
+
+2
-

dkorpar wrote:

what's the point of even using varType if you set it as stdClass?

The editor and static analysis will know that it is stdClass, not a string or a number, …

about a month ago

mesour
Member | 218
+
0
-

MajklNajt wrote:

hi @mesour, first I want to thank you for this plugin, nice work!

I have one surprising behavior, I have template:

{varType Student $student}
{$student->getCourse()->getName()}

Is this expected behavior?

@MajklNajt: Hi, I think, it is because there is not support to use classes without \ if class have not namespace. Try use:

{varType \Student $student}

Last edited by mesour (2020-03-05 10:27)

about a month ago

mesour
Member | 218
+
+1
-

Milo wrote:

Issue: Support stdClass type

If I typehint variable as {varType stdClass $data} I get an error First value in {varType} tag must be typehint. When I use typehint \stdClass the error disappears but I still see higlighted properties like Property 'xyz' not found on $data->xyz.

Would be great to accept any property with stdClass.

@Milo: Support for \stdClass will be added.

about a month ago

MajklNajt
Member | 320
+
0
-

Hi @messour, namespace is not problem, your cited code snippet work fine, problem is only with this:

{varType \Student $student}
{var $course = $student->getCourse()} <-- getCourse() is known, it returns \Course
{$course->getName()} <-- getName() is unknown for latte plugin

In runtime it work properly, only static analysis in PhpStorm screams

Last edited by MajklNajt (2020-03-05 13:33)