Skip to content

Commit

Permalink
feat: class documenting (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimlimjustin committed Aug 22, 2021
1 parent 82082b1 commit 3fa8848
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ const generateJSDoc = () => {
// Get texts of the selection or current line content if no selection
const selectionText = editor.document.getText(selection) || text;
const getParamReg = /\(([^)]*)\)/;

const isClass = /class/i.test(selectionText);

if (isClass) {
editor.edit(editBuilder => {
// Insert text above current line
const selectionLine = editor.document.lineAt(selection.start.line);
const insertPosition = selectionLine.range.start;
const whitespace = selectionLine.firstNonWhitespaceCharacterIndex;
let text = '/** Your class description */\r';
const padSpaceStr = ' '.repeat(whitespace);
text = text.replace(/\r/g, `\r${padSpaceStr} `);
text = `${padSpaceStr}${text}`;
text = text.slice(0, text.length - whitespace - 1);
editBuilder.insert(insertPosition, text);
});
return;
}
// Check if the line matches function params;
const m = selectionText.match(getParamReg);
if (!m) {
Expand Down

0 comments on commit 3fa8848

Please sign in to comment.