diff --git a/package.json b/package.json index 5993a24..f8612a9 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,33 @@ "markdownDescription": "Use `private` accessor keyword for private members", "default": true }, + "unity-code-snippets.classAccessibilityLevel": { + "type": "string", + "markdownDescription": "Select the class accessibility levels.", + "order": 20, + "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.useSealedClasses": { + "type": "boolean", + "order": 30, + "markdownDescription": "[When applied to a class, the sealed modifier prevents other classes from inheriting from it.](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/sealed)", + "default": false + }, "unity-code-snippets.autoComplete.classes": { "type": "boolean", "order": 100, diff --git a/src/model.ts b/src/model.ts index 8eeedff..c4fa1e8 100644 --- a/src/model.ts +++ b/src/model.ts @@ -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_DECLERATION' | 'LINE_BREAK' | 'TAB'; export type Replaces = Record; export const TEMPLATES = ['classes', 'methods', 'calls', 'attributes', 'experimentalAttributes'] as const; diff --git a/src/options.ts b/src/options.ts index 2f59781..807ce83 100644 --- a/src/options.ts +++ b/src/options.ts @@ -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 { @@ -18,12 +18,21 @@ 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 useSealedClassesKeyword = conf.get('useSealedClasses') as boolean; const replaces: Replaces = {} as any; // private keyword replaces.PRIVATE = usePrivateKeyword ? 'private ' : ''; + replaces.CLASS_DECLERATION = + // class accessibility level + (classAccessibilityLevelKeyword === 'none' ? '' : `${classAccessibilityLevelKeyword} `) + + // sealed keyword + (useSealedClassesKeyword ? 'sealed ' : '') + + 'class'; + // indentation style if (style === 'allman') { replaces.LINE_BREAK = '",\n\t\t\t"'; diff --git a/templates/classes.json b/templates/classes.json index 8e223ef..e2eae5a 100644 --- a/templates/classes.json +++ b/templates/classes.json @@ -5,7 +5,7 @@ "body": [ "using UnityEngine;", "", - "public class ${TM_FILENAME_BASE} : MonoBehaviour%LINE_BREAK%{", + "%CLASS_DECLERATION% ${TM_FILENAME_BASE} : MonoBehaviour%LINE_BREAK%{", "\t$0", "}" ] @@ -17,7 +17,7 @@ "body": [ "using UnityEngine;", "", - "public class ${TM_FILENAME_BASE} : StateMachineBehaviour%LINE_BREAK%{", + "%CLASS_DECLERATION% ${TM_FILENAME_BASE} : StateMachineBehaviour%LINE_BREAK%{", "\tpublic override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)%LINE_BREAK%%TAB%{", "\t\t$0", "\t}", @@ -32,7 +32,7 @@ "using UnityEngine;", "using UnityEngine.Networking;", "", - "public class ${TM_FILENAME_BASE} : NetworkBehaviour%LINE_BREAK%{", + "%CLASS_DECLERATION% ${TM_FILENAME_BASE} : NetworkBehaviour%LINE_BREAK%{", "\t$0", "}" ] @@ -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_DECLERATION% ${TM_FILENAME_BASE} : ScriptableObject%LINE_BREAK%{", "\t$0", "}" ] @@ -59,7 +59,7 @@ "using UnityEditor;", "", "[CustomEditor(typeof(${1:${TM_FILENAME_BASE/(.*)Editor/${1}/}}))]", - "public class ${TM_FILENAME_BASE} : Editor%LINE_BREAK%{", + "%CLASS_DECLERATION% ${TM_FILENAME_BASE} : Editor%LINE_BREAK%{", "\tpublic override void OnInspectorGUI()%LINE_BREAK%%TAB%{", "\t\tbase.OnInspectorGUI();", "\t\t$0", @@ -77,7 +77,7 @@ "using UnityEditorInternal;", "", "[CustomEditor(typeof(${1:${TM_FILENAME_BASE/(.*)Editor/${1}/}}))]", - "public class ${TM_FILENAME_BASE} : Editor%LINE_BREAK%{", + "%CLASS_DECLERATION% ${TM_FILENAME_BASE} : Editor%LINE_BREAK%{", "\t%PRIVATE%SerializedProperty _property;", "\t%PRIVATE%ReorderableList _list;", "", @@ -115,7 +115,7 @@ "using UnityEngine;", "using UnityEditor;", "", - "public class ${TM_FILENAME_BASE} : EditorWindow%LINE_BREAK%{", + "%CLASS_DECLERATION% ${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}>();", @@ -138,7 +138,7 @@ "using UnityEditor;", "", "[CustomPropertyDrawer(typeof(${1:${TM_FILENAME_BASE/(.*)Drawer/${1}/}}))]", - "public class ${TM_FILENAME_BASE}: PropertyDrawer%LINE_BREAK%{", + "%CLASS_DECLERATION% ${TM_FILENAME_BASE}: PropertyDrawer%LINE_BREAK%{", "\tpublic override void OnGUI(Rect position, SerializedProperty property, GUIContent label)%LINE_BREAK%%TAB%{", "\t\t$0", "\t}", @@ -153,7 +153,7 @@ "using UnityEngine;", "using UnityEditor;", "", - "public class ${TM_FILENAME_BASE}: ScriptableWizard%LINE_BREAK%{", + "%CLASS_DECLERATION% ${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}\");", @@ -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_DECLERATION% ${TM_FILENAME_BASE}%LINE_BREAK%{", "\t$0", "}"] }, "General interface": {