Skip to content

Commit

Permalink
added class accessibility level enum option
Browse files Browse the repository at this point in the history
  • Loading branch information
somedeveloper00 committed May 19, 2024
1 parent 6afcabd commit a5e0430
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@
"markdownDescription": "Auto complete classes like `MonoBehaviour` and `Editor`.",
"default": true
},
"unity-code-snippets.classAccessibilityLevel": {
"type": "string",
"markdownDescription": "Select the class accessibility levels.",
"order": 105,
"default": "public",
"enum": [
"public",
"internal",
"none"
],
"enumItemLabels": [
"public",
"internal",
"empty (internal)"
],
"markdownEnumDescriptions": [
"[Access is not restricted.](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/public)",
"[Access is limited to the current assembly.](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/internal)",
"Uses nothing which lets C# use the default [(internal)](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/class) option."
]
},
"unity-code-snippets.autoComplete.methods": {
"type": "boolean",
"order": 110,
Expand Down
3 changes: 2 additions & 1 deletion src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ export const DEST_PATH = 'snippets/snippets.json';
export const ISSUES_URL = 'https://github.com/kleber-swf/vscode-unity-code-snippets/issues';

export type IndentationStyle = 'kr' | 'allman';
export type ClassAccessibilityLevel = 'public' |'internal' | 'none';

export type ReplaceType = 'PRIVATE' | 'LINE_BREAK' | 'TAB';
export type ReplaceType = 'PRIVATE' | 'CLASS_ACCESSIBILITY_LEVEL' | 'LINE_BREAK' | 'TAB';
export type Replaces = Record<ReplaceType, string>;

export const TEMPLATES = ['classes', 'methods', 'calls', 'attributes', 'experimentalAttributes'] as const;
Expand Down
6 changes: 5 additions & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from 'vscode';
import { AutoCompletes, IndentationStyle, Options, Replaces, TEMPLATES } from './model';
import { AutoCompletes, ClassAccessibilityLevel, IndentationStyle, Options, Replaces, TEMPLATES } from './model';

export function parseOptions(conf: vscode.WorkspaceConfiguration): Options {
return {
Expand All @@ -18,12 +18,16 @@ function parseAutoCompletes(conf: vscode.WorkspaceConfiguration): AutoCompletes
function parseReplaces(conf: vscode.WorkspaceConfiguration): Replaces {
const style = conf.get('style') as IndentationStyle;
const usePrivateKeyword = conf.get('usePrivateKeyword') as boolean;
const classAccessibilityLevelKeyword = conf.get('classAccessibilityLevel') as ClassAccessibilityLevel;

const replaces: Replaces = {} as any;

// private keyword
replaces.PRIVATE = usePrivateKeyword ? 'private ' : '';

// class accessibility level
replaces.CLASS_ACCESSIBILITY_LEVEL = classAccessibilityLevelKeyword === 'none' ? '' : `${classAccessibilityLevelKeyword} `;

// indentation style
if (style === 'allman') {
replaces.LINE_BREAK = '",\n\t\t\t"';
Expand Down
20 changes: 10 additions & 10 deletions templates/classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"body": [
"using UnityEngine;",
"",
"public class ${TM_FILENAME_BASE} : MonoBehaviour%LINE_BREAK%{",
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE} : MonoBehaviour%LINE_BREAK%{",
"\t$0",
"}"
]
Expand All @@ -17,7 +17,7 @@
"body": [
"using UnityEngine;",
"",
"public class ${TM_FILENAME_BASE} : StateMachineBehaviour%LINE_BREAK%{",
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE} : StateMachineBehaviour%LINE_BREAK%{",
"\tpublic override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)%LINE_BREAK%%TAB%{",
"\t\t$0",
"\t}",
Expand All @@ -32,7 +32,7 @@
"using UnityEngine;",
"using UnityEngine.Networking;",
"",
"public class ${TM_FILENAME_BASE} : NetworkBehaviour%LINE_BREAK%{",
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE} : NetworkBehaviour%LINE_BREAK%{",
"\t$0",
"}"
]
Expand All @@ -45,7 +45,7 @@
"using UnityEngine;",
"",
"[CreateAssetMenu(fileName = \"${1:${TM_FILENAME_BASE}}\", menuName = \"${2:${TM_FILENAME_BASE}}\", order = ${3:0})]",
"public class ${TM_FILENAME_BASE} : ScriptableObject%LINE_BREAK%{",
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE} : ScriptableObject%LINE_BREAK%{",
"\t$0",
"}"
]
Expand All @@ -59,7 +59,7 @@
"using UnityEditor;",
"",
"[CustomEditor(typeof(${1:${TM_FILENAME_BASE/(.*)Editor/${1}/}}))]",
"public class ${TM_FILENAME_BASE} : Editor%LINE_BREAK%{",
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE} : Editor%LINE_BREAK%{",
"\tpublic override void OnInspectorGUI()%LINE_BREAK%%TAB%{",
"\t\tbase.OnInspectorGUI();",
"\t\t$0",
Expand All @@ -77,7 +77,7 @@
"using UnityEditorInternal;",
"",
"[CustomEditor(typeof(${1:${TM_FILENAME_BASE/(.*)Editor/${1}/}}))]",
"public class ${TM_FILENAME_BASE} : Editor%LINE_BREAK%{",
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE} : Editor%LINE_BREAK%{",
"\t%PRIVATE%SerializedProperty _property;",
"\t%PRIVATE%ReorderableList _list;",
"",
Expand Down Expand Up @@ -115,7 +115,7 @@
"using UnityEngine;",
"using UnityEditor;",
"",
"public class ${TM_FILENAME_BASE} : EditorWindow%LINE_BREAK%{",
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE} : EditorWindow%LINE_BREAK%{",
"\t[MenuItem(\"${1:${TM_FILEPATH/.*\\\\(.*)\\\\Assets\\\\.*/${1}/}/${TM_FILENAME_BASE/(.*)Editor/${1}/}}\")]",
"\t%PRIVATE%static void ShowWindow()%LINE_BREAK%%TAB%{",
"\t\tvar window = GetWindow<${TM_FILENAME_BASE}>();",
Expand All @@ -138,7 +138,7 @@
"using UnityEditor;",
"",
"[CustomPropertyDrawer(typeof(${1:${TM_FILENAME_BASE/(.*)Drawer/${1}/}}))]",
"public class ${TM_FILENAME_BASE}: PropertyDrawer%LINE_BREAK%{",
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE}: PropertyDrawer%LINE_BREAK%{",
"\tpublic override void OnGUI(Rect position, SerializedProperty property, GUIContent label)%LINE_BREAK%%TAB%{",
"\t\t$0",
"\t}",
Expand All @@ -153,7 +153,7 @@
"using UnityEngine;",
"using UnityEditor;",
"",
"public class ${TM_FILENAME_BASE}: ScriptableWizard%LINE_BREAK%{",
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE}: ScriptableWizard%LINE_BREAK%{",
"\t[MenuItem(\"${1:${TM_FILEPATH/.*\\\\(.*)\\\\Assets\\\\.*/${1}/}/${TM_FILENAME_BASE/(.*)Wizard/${1}/}}\")]",
"\t%PRIVATE%static void MenuEntryCall()%LINE_BREAK%%TAB%{",
"\t\tDisplayWizard<${TM_FILENAME_BASE}>(\"${2:Title}\");",
Expand All @@ -169,7 +169,7 @@
"General class": {
"prefix": "class",
"description": "Creates a standard class.",
"body": ["public class ${TM_FILENAME_BASE}%LINE_BREAK%{", "\t$0", "}"]
"body": ["%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE}%LINE_BREAK%{", "\t$0", "}"]
},

"General interface": {
Expand Down

0 comments on commit a5e0430

Please sign in to comment.