diff --git a/package.json b/package.json index bfa83c4..f5e78bf 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,10 @@ { "command": "extension.findConstantCap", "title": "findConstantCap" + }, + { + "command": "extension.findLowercaseEnums", + "title": "findLowercaseEnums" } ], "menus": { diff --git a/src/extension.ts b/src/extension.ts index 85e9923..ef577e5 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -8,6 +8,7 @@ import { findCapitalizedMethodName } from './findCapitalizedMethodName'; import { singleStatementPerLineChecker } from './singleStatementPerLineChecker'; import { findAllErrors } from './findAllErrors'; import { findConstantCap} from './findConstantCap'; +import { findLowercaseEnums } from './findLowercaseEnums'; export function activate(context: vscode.ExtensionContext) { console.log('Congratulations, your extension "Java convention commands" is now active!'); diff --git a/src/findLowercaseEnums.ts b/src/findLowercaseEnums.ts new file mode 100644 index 0000000..85c870d --- /dev/null +++ b/src/findLowercaseEnums.ts @@ -0,0 +1,44 @@ +import * as vscode from 'vscode'; + +export function findLowercaseEnums() { + // activeTextEditor allows access to text inside opened document. + vscode.window.showInformationMessage('Naming Convention Mistake!! Highlighted in RED='); + const editor = vscode.window.activeTextEditor; + + if (editor) { + const document = editor.document; + const text = document.getText(); + + const pattern = /\b(?:enum)\s+([a-z][a-zA-Z]*)\b/g; + + let match; + while ((match = pattern.exec(text)) !== null) { + // Get the matched variable name + + const variableName = match[0]; // Entire matched variable name + const firstLetterIndex = match.index + match[0].indexOf(match[1]); // Index of the first letter after class + const firstLetterRange = new vscode.Range(document.positionAt(firstLetterIndex), document.positionAt(firstLetterIndex + 1)); + + // Highlight the first letter after the class name + editor.setDecorations(vscode.window.createTextEditorDecorationType({ + isWholeLine: false, + borderWidth: '1px', + borderStyle: 'solid', + overviewRulerColor: 'red', + overviewRulerLane: vscode.OverviewRulerLane.Right, + light: { + borderColor: 'darkred', + backgroundColor: 'rgba(255, 0, 0, 0.1)' + }, + dark: { + borderColor: 'lightred', + backgroundColor: 'rgba(255, 0, 0, 0.4)' + } + }), [firstLetterRange]); + + } + + } else { + vscode.window.showErrorMessage('No active text editor.'); + } +} \ No newline at end of file