Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option for 'sealed' class #48

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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_DECLERATION' | 'LINE_BREAK' | 'TAB';
export type Replaces = Record<ReplaceType, string>;

export const TEMPLATES = ['classes', 'methods', 'calls', 'attributes', 'experimentalAttributes'] as const;
Expand Down
11 changes: 10 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,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"';
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_DECLERATION% ${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_DECLERATION% ${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_DECLERATION% ${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_DECLERATION% ${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_DECLERATION% ${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_DECLERATION% ${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_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}>();",
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_DECLERATION% ${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_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}\");",
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_DECLERATION% ${TM_FILENAME_BASE}%LINE_BREAK%{", "\t$0", "}"]
},

"General interface": {
Expand Down