Skip to content

Commit

Permalink
Lazy Class Implementation added.
Browse files Browse the repository at this point in the history
  • Loading branch information
aravindrsripada committed Jun 5, 2024
1 parent f798a59 commit d3c5e1c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@
{
"command": "extension.badSwitch",
"title": "badSwitch"
},
{
"command": "extension.lazyClass",
"title": "lazyClass"
}
],
"menus": {
Expand Down
12 changes: 8 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number, string[]> = 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);
Expand Down Expand Up @@ -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);

Expand Down
54 changes: 54 additions & 0 deletions src/lazyClass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as vscode from 'vscode';

export function lazyClass(myMap: Map<number, string[]>): Map<number, string[]> {
// 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;
}

0 comments on commit d3c5e1c

Please sign in to comment.