Skip to content

Commit

Permalink
feat: update jsdoc insteaed of creating new if it already exists (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimlimjustin committed Aug 18, 2021
1 parent 6729723 commit 82082b1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ const generateJSDoc = () => {
}
const paramList = m[1].replace(/[\t\s\r]/g, '').split(',').filter(s => s !== '');

let jsdocExist = editor.document.lineAt(editor.selection.active.line - 1).text.indexOf(' */') !== -1;
let _line = editor.selection.active.line - 2;
if(jsdocExist){
while(editor.document.lineAt(_line).text.indexOf("/**") === -1){
if(editor.document.lineAt(_line).text.indexOf("*") === -1){
jsdocExist = false;
break;
}
_line -= 1;
}
}


editor.edit(editBuilder => {
// Insert text above current line
const selectionLine = editor.document.lineAt(selection.start.line);
Expand Down Expand Up @@ -49,6 +62,9 @@ const generateJSDoc = () => {
text = `${padSpaceStr}${text}`;
text = text.slice(0, text.length - whitespace - 1);

if(jsdocExist){
editBuilder.delete(new vscode.Range(new vscode.Position(_line, 0), new vscode.Position(editor.selection.active.line, 0)));
}
// Insert the text :)
editBuilder.insert(insertPosition, text);
});
Expand Down

0 comments on commit 82082b1

Please sign in to comment.