diff --git a/package.json b/package.json index dc0f576..d0dce26 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,10 @@ { "command": "extension.badSwitch", "title": "badSwitch" + }, + { + "command": "extension.lazyClass", + "title": "lazyClass" } ], "menus": { diff --git a/src/extension.ts b/src/extension.ts index aace195..2f841bf 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -14,20 +14,20 @@ import { findConstantCap} from './findConstantCap'; import { longMethod } from './longMethod'; import { longParameters } from './longParameters'; import { badSwitch } from './badSwitch'; +import { lazyClass } from './lazyClass'; const myMap: Map = new Map(); -const filePath = 'C:\\Users\\Will\\Desktop\\cw\\gradeFast-1.0\\output\\data.json'; +const filePath = 'C:\\Users\\senla\\OneDrive\\Documents\\capstone\\gradeFast-1.0\\output\\data.json'; export function activate(context: vscode.ExtensionContext) { const disposable = vscode.commands.registerCommand('extension.findCapitalizedPrimitiveTypes', () => { findCapitalizedPrimitiveTypes(myMap); - }); + } ); const create = vscode.commands.registerCommand('extension.createJSON', ()=> { convertMapToJson(myMap, filePath); - } - ) + } ); const disposable2 = vscode.commands.registerCommand('extension.findCapitalizedMethodName', () => { findCapitalizedMethodName(myMap); @@ -63,6 +63,10 @@ export function activate(context: vscode.ExtensionContext) { badSwitch(myMap); } ); + const disposable10 = vscode.commands.registerCommand('extension.lazyClass', () => { + lazyClass(myMap); + } ); + const commentController = vscode.comments.createCommentController('comment-sample', 'Comment API Sample'); context.subscriptions.push(commentController); diff --git a/src/lazyClass.ts b/src/lazyClass.ts new file mode 100644 index 0000000..977f268 --- /dev/null +++ b/src/lazyClass.ts @@ -0,0 +1,54 @@ +import * as vscode from 'vscode'; + +export function lazyClass(myMap: Map): Map { + // 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(?:class|interface)\s+([a-z][a-zA-Z]*)\b/g; + let match; + + while ((match = pattern.exec(text)) !== null) { + // Get the matched variable name + const lineNumber = document.positionAt(match.index).line + 1; // Get the line number + 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 lastLetterIndex = match.index + match[0].indexOf(match[-1]); // Index of the last letter after class + const firstLetterRange = new vscode.Range(document.positionAt(firstLetterIndex), document.positionAt(lastLetterIndex)); + + // 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]); + + if(match.length == 1) { + if (!myMap.has(lineNumber)) { + myMap.set(lineNumber, []); + } + const errorMessage = "Lazy Class"; + const currentErrors = myMap.get(lineNumber) || []; + currentErrors.push(errorMessage); + myMap.set(lineNumber, currentErrors); + } + } + + } else { + vscode.window.showErrorMessage('No active text editor.'); + } + return myMap; +} \ No newline at end of file