A moderately dirty solution with the current variable and the vscode regex system looks like this:
Assuming you have all your projects in / your / projects / directory /
So, project number 1 is located in / your / projects / directory / Project1 /
And project number 2 is in / your / projects / directory / Project2 /
etc.
The following snippet will create a namespace implementation for all subdirectories:
Linux / MacOS
"Namespace declaration": { "prefix": "name", "description": "Creates a new namespace declaration.", "body": [ "namespace ${TM_DIRECTORY/^\\/your\\/projects\\/directory(\\/([^\\/]+))(\\/([^\\/]+))?(\\/([^\\/]+))?(\\/([^\\/]+))?(\\/([^\\/]+))?(\\/([^\\/]+))?(\\/([^\\/]+))?(\\/([^\\/]+))?(\\/([^\\/]+))?(\\/([^\\/]+))?/$2${3:+.}$4${5:+.}$6${7:+.}$8${9:+.}$10${11:+.}$12${13:+.}$14${15:+.}$16${17:+.}$18${19:+.}$20/gi}", "{", "}" ] }
Windows
"Namespace declaration": { "prefix": "name", "description": "Creates a new namespace declaration.", "body": [ "namespace ${TM_DIRECTORY/^c:\\\\your\\\\projects\\\\directory(\\\\([^\\\\]+))(\\\\([^\\\\]+))?(\\\\([^\\\\]+))?(\\\\([^\\\\]+))?(\\\\([^\\\\]+))?(\\\\([^\\\\]+))?(\\\\([^\\\\]+))?(\\\\([^\\\\]+))?(\\\\([^\\\\]+))?(\\\\([^\\\\]+))?/$2${3:+.}$4${5:+.}$6${7:+.}$8${9:+.}$10${11:+.}$12${13:+.}$14${15:+.}$16${17:+.}$18${19:+.}$20/gi}", "{", "}" ] }
explanation
- The snippet matches your base directory and up to ten subdirectories (the first directory is required
(\\/([^\\/]+)) , while all the other nine are optional (\\/([^\\/]+))? ) - Then a namespace directive is created with the first matching directory
- For each successful match of the additional subdirectory, a period is set
. inserted ( ${3:+.} ) with a sub-match of this group ( $4 ); for unsuccessful groups, a dot is not inserted, and the sub-item is empty
Enjoy :)
Simon mattes
source share