Skip to content

Commit f356bf7

Browse files
committed
[FIX] line bug introduced (per accident) in version 1.0.17
1 parent 6faaf27 commit f356bf7

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

vscode/asperheader/src/modules/commentGenerator.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,8 @@ export class CommentGenerator {
776776
if (commentCloser.length > 0) {
777777
buildHeader.push(`${commentCloser}${this.determineNewLine(eol)}`);
778778
}
779-
779+
// Check wether there are elements required to be added after the header
780780
buildHeader = this.appendIfPresent(buildHeader, eol, languageId);
781-
782781
return buildHeader;
783782
}
784783

@@ -899,6 +898,18 @@ export class CommentGenerator {
899898
return false;
900899
}
901900

901+
private skipFirstLineInDocument(document: vscode.TextDocument): number {
902+
let insertLine = 0;
903+
904+
if (document.lineCount > 0) {
905+
const firstLine = document.lineAt(0).text;
906+
if (firstLine.startsWith("#!")) {
907+
insertLine = 1;
908+
}
909+
}
910+
return insertLine;
911+
}
912+
902913
/**
903914
* @brief Writes a new header to the beginning of the file
904915
* @param editor VS Code text editor instance
@@ -910,26 +921,21 @@ export class CommentGenerator {
910921
*/
911922
private async writeHeaderToFile(document: vscode.TextDocument, comments: string[], languageId?: string): Promise<number> {
912923
logger.debug(getMessage("inFunction", "writeHeaderToFile", "CommentGenerator"));
913-
const headerLines: string[] = await this.buildTheHeader(comments, languageId);
914-
const headerText: string = headerLines.join(this.determineNewLine(document.eol));
915-
let insertPosition = 0;
916-
if (document.lineCount > 0) {
917-
const firstLine = document.lineAt(0).text;
918-
if (firstLine.startsWith('#!')) {
919-
insertPosition = 1;
920-
if (document.lineCount > 1 && document.lineAt(1).text !== '') {
921-
const edit = new vscode.WorkspaceEdit();
922-
edit.insert(document.uri, new vscode.Position(1, 0), this.determineNewLine(document.eol));
923-
await vscode.workspace.applyEdit(edit);
924-
insertPosition = 2;
925-
}
926-
}
927-
}
924+
925+
const headerLines = await this.buildTheHeader(comments, languageId);
926+
const headerText = headerLines.join("");
928927
const edit = new vscode.WorkspaceEdit();
929-
edit.insert(document.uri, new vscode.Position(insertPosition, 0), headerText + this.determineNewLine(document.eol));
928+
const insertLine: number = this.skipFirstLineInDocument(document);
929+
edit.insert(
930+
document.uri,
931+
new vscode.Position(insertLine, 0),
932+
headerText
933+
);
934+
930935
await vscode.workspace.applyEdit(edit);
931936
return this.Config.get("statusSuccess");
932937
}
938+
933939
/**
934940
* @brief Main method to inject or update header in active editor
935941
*

0 commit comments

Comments
 (0)