Skip to content

Commit

Permalink
Issue #111: Added user setting to control indentation of comment lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Powick committed Jun 12, 2020
1 parent 491bb80 commit f60304e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
31 changes: 28 additions & 3 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var UseGateway: boolean;
var UsingRest: boolean;
var margin: number;
var indent: number;
var indentComment: string;
var formattingEnabled: boolean;
var editFiles: any;
var customWordColor: any;
Expand Down Expand Up @@ -85,6 +86,7 @@ export function activate(context: vscode.ExtensionContext) {
UsingRest = vscode.workspace.getConfiguration("MVBasic").get("UseRestFS");
margin = vscode.workspace.getConfiguration("MVBasic").get("margin");
indent = vscode.workspace.getConfiguration("MVBasic").get("indent");
indentComment = vscode.workspace.getConfiguration("MVBasic").get("indentComment");
formattingEnabled = vscode.workspace.getConfiguration("MVBasic").get("formattingEnabled");
editFiles = vscode.workspace.getConfiguration("MVBasic").get("EditFiles");
customWordColor = vscode.workspace.getConfiguration("MVBasic").get("customWordColor");
Expand Down Expand Up @@ -382,9 +384,6 @@ export function activate(context: vscode.ExtensionContext) {
const line = document.lineAt(i);
let lineText = line.text.trim();

// ignore comment lines
if (rComment.test(lineText)) { continue }

// ignore labels
if (rLabel.test(lineText)) { continue }

Expand All @@ -393,6 +392,32 @@ export function activate(context: vscode.ExtensionContext) {
if (RowLevel[i] === undefined) { continue; }

indentation = (RowLevel[i] * indent) + margin

// Comment indent rules
if (rComment.test(lineText)) {
switch (indentComment) {
case "left": {
// Indent comment to margin position 0
indentation = 0;
break;
}
case "margin": {
// Indent comment to margin position
indentation = margin;
break;
}
case "code": {
// Indent comment with code
break;
}
default: {
// No change to indent if indentComment = "ignore",
// is missing, or has an invalid value.
continue;
}
}
}

if (new RegExp("(^case\\s)", "i").test(lineText)) {
indentation -= indent
}
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@
"default": 3,
"description": "The number of characters to use when indenting code blocks."
},
"MVBasic.indentComment": {
"scope": "resource",
"type": "string",
"default": "ignore",
"description": "Indentation of comment lines. Set to: left, margin, code, or ignore."
},
"MVBasic.maxNumberOfProblems": {
"scope": "resource",
"type": "number",
Expand Down

0 comments on commit f60304e

Please sign in to comment.