drupal-smart-snippets icon indicating copy to clipboard operation
drupal-smart-snippets copied to clipboard

FR: insert namespace

Open tyler36 opened this issue 1 year ago • 2 comments

I would like to request a new feature that can automate namespace insertions.

Given I'm in web/module/custom/example/src/Controller/ExampleController.php -> generates namespace Drupal\example\Controller;

Given I'm in web/module/custom/theme/src/Plugin/Block/ExampleBlock.php -> generates namespace Drupal\example\Plugin\Block;

The logic seems consistent enough, although Test namespaces are a little different.

Thank you for your consideration.

tyler36 avatar Jan 24 '24 01:01 tyler36

Thanks for this request! Do you have a link to documentation around how namespaces should be created? While i can definitely see value in this, I'm not sure the snippet-based nature of this project currently supports the right functionality to be able to parse all that out.

andy-blum avatar Jan 24 '24 17:01 andy-blum

The best I could find was https://www.drupal.org/docs/develop/standards/php/psr-4-namespaces-and-autoloading-in-drupal-8#s-namespace-resolution .

VSCode does support some file-based variables in snippets such as:

TM_FILENAME The filename of the current document TM_DIRECTORY The directory of the current document TM_FILEPATH The full file path of the current document RELATIVE_FILEPATH The relative (to the opened workspace or folder) file path of the current document

I'm not sure how well these can be parsed/manipulated.

tyler36 avatar Jan 25 '24 01:01 tyler36