[Tools] Add editor snippets to help new developers. (#12479)

* [Toold] Add editor snippets to help new developers.

We do have a few tings that we have to do manually yet it is repetitive,
I am adding the vscode (soon to come vim) configuration files to provide
useful snippets when working with the bindings.

The syntax of the snippets present is very simple, there are just two
things to understand in these new ones:

1 Tab complitions: $1, $2 etc.. are the tab complitions that the user
  can provide. This allows the user to navigate and the snippets engine
  will replace all the complitions with the provided text.
2 Options: We can provide options for tab complitions, for example for
  the PlatformName, which is a known value. The syntax to do so is
  {$1|one,two,three|} where:

  * `$1`: is the tab completion.
  * `|one,two,three|`: are the options.


Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
This commit is contained in:
Manuel de la Pena 2021-08-19 19:03:14 -04:00 коммит произвёл GitHub
Родитель c00e3a9878
Коммит dfb903e8b0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 137 добавлений и 0 удалений

28
tools/editors/README.md Normal file
Просмотреть файл

@ -0,0 +1,28 @@
# Editors
This directory contains a list of useful settings and snippets to make your life easier. There is a directory per editor that contains recommendations
and snippets to be used.
## VS Code
You can find the snippets for csharp in the VSCode directory. There are two possible scenarios:
1. You do no have snippets setup in your system.
2. You do alrady use snippets.
### New to snippets
In order to be able to use snippets you need to enable tab completion on vscode, you do so by following the instructions
you can find in the [vscode documentation](https://code.visualstudio.com/docs/editor/userdefinedsnippets).
Copy the snippets file
```bash
mkdir -p "~/Library/Application Support/Code/User/snippets"
cp VSCode/* "~/Library/Application Support/Code/User/snippets"
```
### Already have snippets
You are all setup, you just need to merge the contents of the file VSCode/csharp.json with the file in "~/Library/Application Support/Code/User/snippets"

Просмотреть файл

@ -0,0 +1,109 @@
{
// Useful snippets for xamarin.ios bindings
"Write all the deprecation attributes for a manual binding.": {
"prefix": "manual_deprecation",
"body": [
"#if !NET",
"\t\t[Deprecated (PlatformName.iOS, $1, $2, message: \"$11\")]",
"\t\t[Deprecated (PlatformName.TvOS, $3, $4, message: \"$11\")] ",
"\t\t[Deprecated (PlatformName.MacCatalyst, $5, $6, message: \"$11\")]",
"\t\t[Deprecated (PlatformName.MacOSX, $7, $8, message: \"$11\")]",
"\t\t[Deprecated (PlatformName.WatchOS, $9, $10, message: \"$11\")]",
"#else",
"\t\t[UnsupportedOSPlatform (\"ios$1.$2\")]",
"\t\t[UnsupportedOSPlatform (\"tvos$3.$4\")]",
"\t\t[UnsupportedOSPlatform (\"maccatalyst$5.$6\")]",
"\t\t[UnsupportedOSPlatform (\"macos$7.$8\")]",
"#if __MACCATALYST__",
"\t\t[Obsolete (\"Starting with maccatalyst$5.$6 $11\", DiagnosticId = \"BI1234\", UrlFormat = \"https://github.com/xamarin/xamarin-macios/wiki/Obsolete\")]",
"#elif IOS",
"\t\t[Obsolete (\"Starting with ios$1.$2 $11\", DiagnosticId = \"BI1234\", UrlFormat = \"https://github.com/xamarin/xamarin-macios/wiki/Obsolete\")]",
"#elif TVOS",
"\t\t[Obsolete (\"Starting with tvos$3.$4 $11' instead.\", DiagnosticId = \"BI1234\", UrlFormat = \"https://github.com/xamarin/xamarin-macios/wiki/Obsolete\")]",
"#elif MONOMAC",
"\t\t[Obsolete (\"Starting with macos$7.$8 $11\", DiagnosticId = \"BI1234\", UrlFormat = \"https://github.com/xamarin/xamarin-macios/wiki/Obsolete\")]",
"#endif",
"#endif"
],
"description": "Write all the deprecation attributes for a manual binding."
},
"Write all the availability attributes for a manual binding.": {
"prefix": "manual_avaliability",
"body": [
"#if !NET",
"\t\t[iOS ($1,$2), TV ($3,$4), MacCatalyst ($5,$6), Mac ($7,$8), Watch ($9,$10)]",
"#else",
"\t\t[SupportedOSPlatform (\"ios$1.$2\")]",
"\t\t[SupportedOSPlatform (\"tvos$3.$4\")]",
"\t\t[SupportedOSPlatform (\"maccatalyst$5.$6\")]",
"\t\t[SupportedOSPlatform (\"macos$7.$8\")]",
"#endif"
],
"description": "Write all the availability attributes for a manual binding."
},
"Add a native ref type declaration": {
"prefix": "native_reference",
"body": [
"using $1Ref = System.IntPtr;"
],
"description": "Add a native ref type declaration"
},
"Import needed dlls for versioning.": {
"prefix": "netcore_versioning",
"body": [
"using System.Runtime.Versioning;"
],
"description": "Import needed dlls for versioning."
},
"Availability attribute for bindings.": {
"prefix": "availability_attr",
"body": [
"${1|Mac,iOS,TV,Watch,MacCatalyst|} ($2,$3)"
],
"description": "Availability attribute for manual bindings."
},
"All availability attributes.": {
"prefix": "all_attr",
"body": [
"[iOS ($1,$2), TV ($3,$4), MacCatalyst ($5,$6), Mac ($7,$8), Watch ($9,$10)"
],
"description": "All availability attributes."
},
"All mobile availability attributes.": {
"prefix": "mobile_attr",
"body": [
"[iOS ($1,$2), TV ($3,$4), MacCatalyst ($5,$6), Watch ($9,$10)]"
],
"description": "All mobile availability attributes."
},
"Write BindAs attr.": {
"prefix": "bindas_attr",
"body": [
"[BindAs (typeof ($1))]"
],
"description": "Write BindAs attr."
},
"Write a deprecated attribute with NO message.": {
"prefix": "deprecated_attr",
"body": [
"[Deprecated (PlatformName.${1|MacOSX,iOS,TvOS,WatchOS,MacCatalyst|}, $2, $3)]"
],
"description": "Write a deprecated attribute with NO message."
},
"Write a deprecated attribute with a message.": {
"prefix": "deprecated_attr_msg",
"body": [
"[Deprecated (PlatformName.${1|MacOSX,iOS,TvOS,WatchOS,MacCatalyst|}, $2, $3, message: \"$4\")]"
],
"description": "Write a deprecated attribute with a message."
}
}