Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 53ddc26

Browse files
committedMay 21, 2024
added sealed class option
1 parent a5e0430 commit 53ddc26

File tree

4 files changed

+38
-21
lines changed

4 files changed

+38
-21
lines changed
 

‎package.json

+13-7
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,10 @@
7676
"markdownDescription": "Use `private` accessor keyword for private members",
7777
"default": true
7878
},
79-
"unity-code-snippets.autoComplete.classes": {
80-
"type": "boolean",
81-
"order": 100,
82-
"markdownDescription": "Auto complete classes like `MonoBehaviour` and `Editor`.",
83-
"default": true
84-
},
8579
"unity-code-snippets.classAccessibilityLevel": {
8680
"type": "string",
8781
"markdownDescription": "Select the class accessibility levels.",
88-
"order": 105,
82+
"order": 20,
8983
"default": "public",
9084
"enum": [
9185
"public",
@@ -103,6 +97,18 @@
10397
"Uses nothing which lets C# use the default [(internal)](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/class) option."
10498
]
10599
},
100+
"unity-code-snippets.useSealedClasses": {
101+
"type": "boolean",
102+
"order": 30,
103+
"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)",
104+
"default": false
105+
},
106+
"unity-code-snippets.autoComplete.classes": {
107+
"type": "boolean",
108+
"order": 100,
109+
"markdownDescription": "Auto complete classes like `MonoBehaviour` and `Editor`.",
110+
"default": true
111+
},
106112
"unity-code-snippets.autoComplete.methods": {
107113
"type": "boolean",
108114
"order": 110,

‎src/model.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ export const DEST_PATH = 'snippets/snippets.json';
44
export const ISSUES_URL = 'https://github.com/kleber-swf/vscode-unity-code-snippets/issues';
55

66
export type IndentationStyle = 'kr' | 'allman';
7-
export type ClassAccessibilityLevel = 'public' |'internal' | 'none';
7+
export type ClassAccessibilityLevel = 'public' | 'internal' | 'none';
88

9-
export type ReplaceType = 'PRIVATE' | 'CLASS_ACCESSIBILITY_LEVEL' | 'LINE_BREAK' | 'TAB';
9+
export type ReplaceType = 'PRIVATE' | 'CLASS_DECLERATION' | 'LINE_BREAK' | 'TAB';
1010
export type Replaces = Record<ReplaceType, string>;
1111

1212
export const TEMPLATES = ['classes', 'methods', 'calls', 'attributes', 'experimentalAttributes'] as const;

‎src/options.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,25 @@ function parseReplaces(conf: vscode.WorkspaceConfiguration): Replaces {
1919
const style = conf.get('style') as IndentationStyle;
2020
const usePrivateKeyword = conf.get('usePrivateKeyword') as boolean;
2121
const classAccessibilityLevelKeyword = conf.get('classAccessibilityLevel') as ClassAccessibilityLevel;
22+
const useSealedClassesKeyword = conf.get('useSealedClasses') as boolean;
2223

2324
const replaces: Replaces = {} as any;
2425

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

28-
// class accessibility level
29-
replaces.CLASS_ACCESSIBILITY_LEVEL = classAccessibilityLevelKeyword === 'none' ? '' : `${classAccessibilityLevelKeyword} `;
29+
try {
30+
replaces.CLASS_DECLERATION =
31+
// class accessibility level
32+
(classAccessibilityLevelKeyword === 'none' ? '' : `${classAccessibilityLevelKeyword} `) +
33+
// sealed keyword
34+
(useSealedClassesKeyword ? 'sealed ' : '') +
35+
'class';
36+
} catch (error) {
37+
replaces.CLASS_DECLERATION = 'error!!';
38+
}
39+
console.log('hshshs' + replaces.CLASS_DECLERATION);
40+
3041

3142
// indentation style
3243
if (style === 'allman') {

‎templates/classes.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"body": [
66
"using UnityEngine;",
77
"",
8-
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE} : MonoBehaviour%LINE_BREAK%{",
8+
"%CLASS_DECLERATION% ${TM_FILENAME_BASE} : MonoBehaviour%LINE_BREAK%{",
99
"\t$0",
1010
"}"
1111
]
@@ -17,7 +17,7 @@
1717
"body": [
1818
"using UnityEngine;",
1919
"",
20-
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE} : StateMachineBehaviour%LINE_BREAK%{",
20+
"%CLASS_DECLERATION% ${TM_FILENAME_BASE} : StateMachineBehaviour%LINE_BREAK%{",
2121
"\tpublic override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)%LINE_BREAK%%TAB%{",
2222
"\t\t$0",
2323
"\t}",
@@ -32,7 +32,7 @@
3232
"using UnityEngine;",
3333
"using UnityEngine.Networking;",
3434
"",
35-
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE} : NetworkBehaviour%LINE_BREAK%{",
35+
"%CLASS_DECLERATION% ${TM_FILENAME_BASE} : NetworkBehaviour%LINE_BREAK%{",
3636
"\t$0",
3737
"}"
3838
]
@@ -45,7 +45,7 @@
4545
"using UnityEngine;",
4646
"",
4747
"[CreateAssetMenu(fileName = \"${1:${TM_FILENAME_BASE}}\", menuName = \"${2:${TM_FILENAME_BASE}}\", order = ${3:0})]",
48-
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE} : ScriptableObject%LINE_BREAK%{",
48+
"%CLASS_DECLERATION% ${TM_FILENAME_BASE} : ScriptableObject%LINE_BREAK%{",
4949
"\t$0",
5050
"}"
5151
]
@@ -59,7 +59,7 @@
5959
"using UnityEditor;",
6060
"",
6161
"[CustomEditor(typeof(${1:${TM_FILENAME_BASE/(.*)Editor/${1}/}}))]",
62-
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE} : Editor%LINE_BREAK%{",
62+
"%CLASS_DECLERATION% ${TM_FILENAME_BASE} : Editor%LINE_BREAK%{",
6363
"\tpublic override void OnInspectorGUI()%LINE_BREAK%%TAB%{",
6464
"\t\tbase.OnInspectorGUI();",
6565
"\t\t$0",
@@ -77,7 +77,7 @@
7777
"using UnityEditorInternal;",
7878
"",
7979
"[CustomEditor(typeof(${1:${TM_FILENAME_BASE/(.*)Editor/${1}/}}))]",
80-
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE} : Editor%LINE_BREAK%{",
80+
"%CLASS_DECLERATION% ${TM_FILENAME_BASE} : Editor%LINE_BREAK%{",
8181
"\t%PRIVATE%SerializedProperty _property;",
8282
"\t%PRIVATE%ReorderableList _list;",
8383
"",
@@ -115,7 +115,7 @@
115115
"using UnityEngine;",
116116
"using UnityEditor;",
117117
"",
118-
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE} : EditorWindow%LINE_BREAK%{",
118+
"%CLASS_DECLERATION% ${TM_FILENAME_BASE} : EditorWindow%LINE_BREAK%{",
119119
"\t[MenuItem(\"${1:${TM_FILEPATH/.*\\\\(.*)\\\\Assets\\\\.*/${1}/}/${TM_FILENAME_BASE/(.*)Editor/${1}/}}\")]",
120120
"\t%PRIVATE%static void ShowWindow()%LINE_BREAK%%TAB%{",
121121
"\t\tvar window = GetWindow<${TM_FILENAME_BASE}>();",
@@ -138,7 +138,7 @@
138138
"using UnityEditor;",
139139
"",
140140
"[CustomPropertyDrawer(typeof(${1:${TM_FILENAME_BASE/(.*)Drawer/${1}/}}))]",
141-
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE}: PropertyDrawer%LINE_BREAK%{",
141+
"%CLASS_DECLERATION% ${TM_FILENAME_BASE}: PropertyDrawer%LINE_BREAK%{",
142142
"\tpublic override void OnGUI(Rect position, SerializedProperty property, GUIContent label)%LINE_BREAK%%TAB%{",
143143
"\t\t$0",
144144
"\t}",
@@ -153,7 +153,7 @@
153153
"using UnityEngine;",
154154
"using UnityEditor;",
155155
"",
156-
"%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE}: ScriptableWizard%LINE_BREAK%{",
156+
"%CLASS_DECLERATION% ${TM_FILENAME_BASE}: ScriptableWizard%LINE_BREAK%{",
157157
"\t[MenuItem(\"${1:${TM_FILEPATH/.*\\\\(.*)\\\\Assets\\\\.*/${1}/}/${TM_FILENAME_BASE/(.*)Wizard/${1}/}}\")]",
158158
"\t%PRIVATE%static void MenuEntryCall()%LINE_BREAK%%TAB%{",
159159
"\t\tDisplayWizard<${TM_FILENAME_BASE}>(\"${2:Title}\");",
@@ -169,7 +169,7 @@
169169
"General class": {
170170
"prefix": "class",
171171
"description": "Creates a standard class.",
172-
"body": ["%CLASS_ACCESSIBILITY_LEVEL%class ${TM_FILENAME_BASE}%LINE_BREAK%{", "\t$0", "}"]
172+
"body": ["%CLASS_DECLERATION% ${TM_FILENAME_BASE}%LINE_BREAK%{", "\t$0", "}"]
173173
},
174174

175175
"General interface": {

0 commit comments

Comments
 (0)
Please sign in to comment.