Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Snippets Quality of Life and Continuity #174889

Merged
merged 18 commits into from
May 18, 2023
Merged

Conversation

soulshined
Copy link
Contributor

@soulshined soulshined commented Feb 21, 2023

Qualify of Life

  • Updated all snippets to be consistent with documentation snippets
    • No snippets have docs in them unless they are prefixed with doc_
  • Updated the class snippet to default to the current file's base name instead of 'ClassName'
  • Add an additional tab stop to functions for chaining args/params
  • Remove kvps from array since arrays can be associative or just values
    • Instead, users can chain snippet after snippet by way of the keyval snippet if it's an associative array
  • Changed verbiage of doc_param to more accurately describe it's intent
New Snippets
  • try_finally
    tryfinally

  • param
    Used to chain params for any function

    param

  • functions

    • fun
      Users should use param to chain parameters
      fun

    • fun_anonymous
      fun2

    • fun_arrow
      fun3

  • constructor_promotion
    Users can use property_promoted to chain promotion properties in a constructor
    promoted

    promoted2

  • spaceship
    spaceship

  • property
    property

  • goto

  • const
    const

  • namespace

    • use_as
    • use_group
    • use_fun
    • use_const
  • match ref
    match

  • Attributes ref

    • attr
      attr2
    • attr_with_target
      attr3
    • attr_target
      attr
  • Enum ref

    • enum
      enum
    • enum_backed
      backed
    • foreach_enum
      foreachenum
  • Dynamic Properties Class
    dynamic

- Sorted snippets by snippet title for discoverability
- Removed all doc comments from non 'doc_' prefixed snippets
- Added doc_trait for continuity with other patterns
- Updated snippet prefixes
	- Add kvp to keyval
	- Prefixed fun with class_
	- Changed doc_param to doc_var
	- Qualified 'con' to 'constructor' to not be confused with const
- Updated class snippet to default the 'class' placeholder to the file's base name
- Add snippet choices for private, public, protected where appropriate
- Add an additional tab stop to end of functions for additional args/params
- Remove array kvps since arrays can be associative or just values
- Add fun for a general function out of scope of class
- Add fun_anonymous for anonymous functions
- Add fun_arrow for arrow functions
- Add match expression
- Add Attribute snippets
  - Add sensitive parameter
  - Add attribute target
  - Add attribute with target
- Rename class_const to const
- Add Dynamic Property Class snippet
- Add enum snippets
  - Basic Enum
  - Backed Enum
  - foreach enum
@soulshined
Copy link
Contributor Author

@microsoft-github-policy-service agree

@microsoft-github-policy-service agree

@soulshined soulshined reopened this Feb 21, 2023
@soulshined
Copy link
Contributor Author

My fork was out of sync. I have synced the fork and merged vscode/main into my branch

@roblourens
Copy link
Member

This seems like a lot of work. In the future, you might want to open an issue so that we can have a discussion about what you want to add before you do a lot of work to write the code. I'm not sure I want to merge this. Some of these snippets are really detailed and specific. I think it's nice for us to offer basic snippets for the most common scenarios out of the box, but I think that most of these would be better suited for a php snippet extension. Have you considered that?

@soulshined
Copy link
Contributor Author

soulshined commented Mar 11, 2023

This seems like a lot of work. In the future, you might want to open an issue so that we can have a discussion about what you want to add before you do a lot of work to write the code. I'm not sure I want to merge this. Some of these snippets are really detailed and specific. I think it's nice for us to offer basic snippets for the most common scenarios out of the box, but I think that most of these would be better suited for a php snippet extension. Have you considered that?

Unfortunately, when I rebased I lost the commit messages, but in short, there is nothing really specific to 'me' or my needs here. I'm all for taking whatever offenders you think out, but the goal with this PR is to align PHP snippets with PHP 8 features. < PHP 8 is reaching end of life and there are no snippets to bridge the gap out-of-box. This also makes the PHP doc strategy consistent, some snippets had a prefix some others didn't. I'm willing to filter and adjust if you can point to some ones that may not be suitable for the community at large, I'm not married to these by any means so if you have feedback, I'd consider this discussion just as valuable. But at minimum, there should be some PHP 8 support out-of-box imo.

I think for starters, the heredoc and nowdoc and super global snippets aren't necessary. I'm okay with removing those personally. Everything else was updated for the purposes to be used across all versions of PHP agnostically. For example, the parameter snippets are way out of date, because we have type hints now and we have promoted parameters. Classes also need to be updated because not every class needs a constructor signature and so forth. I think if anything I'm removing a lot of the 'explicit' use cases of these snippets,

If by extension, you mean me create one, sure I could, but I don't see the difference in creating one and adding it here; at a high level anyways. Again, open to suggestions, I know you have a lot of users to think about and that's fair

@roblourens
Copy link
Member

Sorry for the slow response. I think that for our builtin snippets, we want to stick to snippets that just cover the most common usages of general language constructs. We don't want to try to be exhaustive for every possible for- eg we'll take a try/catch snippet but I don't think we also need a try/catch/finally snippet built-in. And we don't want snippets that cover sort of opinionated workflows- I think the echo $this->… snippet feels that way to me. The snippets for global variables like $_COOKIE or the array initializers also feel that way to me- they are probably helpful for a php snippet poweruser but I don't think they need to be built in.

If you can do a pass to remove snippets that might fit that description then I will take another look. The other snippets can go in a user's snippets files or a snippets extension.

@roblourens
Copy link
Member

Do you plan to work on this more @soulshined?

@soulshined
Copy link
Contributor Author

soulshined commented May 16, 2023

Oops. sorry I missed the last email notification about it. I will adjust based on your feedback! I should have time tomorrow or wednesday evening

  • Please review @roblourens the latest 'Remove php snippets as candidates' commit for verbose commit message. Effectively removed things that didn't focus on continuity or PHP 8 specific concepts (match, enums, dynamic classes etc)

soulshined and others added 3 commits May 17, 2023 18:23
- Remove heredoc
- Remove nowdoc
- Remove php super global snippets
- Remove namespace_path
- Remove ethis (echo $this->)
- Remove try/catch finally
Copy link
Member

@roblourens roblourens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I trimmed the snippets a bit more, just removing ones that I feel don't add much or are a variation of another snippet.

@roblourens roblourens merged commit 89636b9 into microsoft:main May 18, 2023
@soulshined
Copy link
Contributor Author

@roblourens no issues here; just a fair warning you removed a majority of existing ones prior to my changes (ultimately like you said, people will have to add to their personal snippets as they see fit anyways) but I think at minimum we need to add back the throws exception snippet and the 2 constructors. Here's the file prior to my changes: https://github.com/soulshined/vscode/blob/d5e12a12ddcdbffa565ea36aec17d94df7c9f3d9/extensions/php/snippets/php.code-snippets

Additionally, some 'variations' come at a cost. the class snippet that existed prior to mine never accounted for promotion style constructors or chaining parameters etc. I'll leave that up to you to decide. I'm not married to anything just adding color that the old php syntax is far from php 8 snytax (yet the new 'variants' are backwards compatible, err i tried my best to be)

@roblourens
Copy link
Member

Oops, I meant to check for that, I will at least add back the ones that were previously existing. Thanks. I will put back one constructor snippet. I think having both is just a level of detail that we don't need built in but would make sense in an extension for snippet power users.

roblourens added a commit that referenced this pull request May 19, 2023
That shouldn't have been deleted in #174889
And also bring back one constructor snippet
roblourens added a commit that referenced this pull request May 19, 2023
That shouldn't have been deleted in #174889
And also bring back one constructor snippet
@roblourens roblourens added this to the May 2023 milestone May 19, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jul 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants