Skip to content

Commit

Permalink
Merge commit 'f27b91f1f13678a486f95f7a88b450512617df3f' into 18-creat…
Browse files Browse the repository at this point in the history
…e-readme
  • Loading branch information
PauliusKu committed Sep 16, 2024
2 parents f983c8c + f27b91f commit 14be8d4
Show file tree
Hide file tree
Showing 19 changed files with 84 additions and 121 deletions.
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ vsc-extension-quickstart.md
node_modules/**
resources/functionalTests/**
resources/samples/**
resources/treeSitterErrorTests/**
18 changes: 7 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "AblFormatter",
"displayName": "AblFormatter",
"description": "TODO",
"name": "abl-formatter",
"displayName": "Abl Formatter",
"description": "Progress OpenEdge (ABL) code formatter",
"version": "0.0.1",
"icon": "resources/Formatter_LOGO.png",
"repository": {},
"repository": {
"url": "https://github.com/BalticAmadeus/AblFormatter"
},
"engines": {
"vscode": "^1.84.0"
},
Expand Down Expand Up @@ -226,13 +228,7 @@
"description": "Enable table view with tree info on hover"
}
}
},
"commands": [
{
"command": "AblFormatter.helloWorld",
"title": "Hello World"
}
]
}
},
"scripts": {
"copy-wasm": "copyfiles -u 2 ./node_modules/web-tree-sitter/*.wasm out",
Expand Down
7 changes: 7 additions & 0 deletions resources/functionalTests/block/6-do-do-end1/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true}*/

do transaction:
do transaction:
a /= 3.
end. end.
8 changes: 8 additions & 0 deletions resources/functionalTests/block/6-do-do-end1/target.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true}*/

do transaction:
do transaction:
a /= 3.
end.
end.
5 changes: 5 additions & 0 deletions resources/functionalTests/block/6do-start/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true}*/

do while true: a = 3.
end.
6 changes: 6 additions & 0 deletions resources/functionalTests/block/6do-start/target.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true}*/

do while true:
a = 3.
end.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ PROCEDURE testCase:
i = 2.

CASE i:
WHEN 1 THEN DO: MESSAGE "Case 1".
WHEN 1 THEN DO:
MESSAGE "Case 1".
END.
OTHERWISE MESSAGE "No match found".
END CASE.
Expand Down
10 changes: 0 additions & 10 deletions resources/functionalTests/temptable/4-like/input.p

This file was deleted.

8 changes: 0 additions & 8 deletions resources/functionalTests/temptable/4-like/target.p

This file was deleted.

2 changes: 1 addition & 1 deletion resources/functionalTests/temptable/5-serializable/input.p
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
/* { "AblFormatter.temptableFormatting": true,
"abl.completion.upperCase": true}*/

DEFINE SERIALIZABLE TEMP-TABLE ttCustomer NO-UNDO REFERENCE-ONLY LIKE Customer INX CustNum I PRIMARY UNIQUE ustNum
DEFINE SERIALIZABLE TEMP-TABLE ttCustomer NO-UNDO REFERENCE-ONLY LIKE Customer INDEX CustNum I PRIMARY UNIQUE ustNum
INDEX CustNum IS PRIMARY UNIQUE CustNum.
4 changes: 2 additions & 2 deletions resources/functionalTests/temptable/5-serializable/target.p
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
/* { "AblFormatter.temptableFormatting": true,
"abl.completion.upperCase": true}*/

DEFINE SERIALIZABLE TEMP-TABLE ttCustomer NO-UNDO REFERENCE-ONLY
LIKE Customer. INX CustNum I PRIMARY UNIQUE ustNum
DEFINE SERIALIZABLE TEMP-TABLE ttCustomer NO-UNDO REFERENCE-ONLY LIKE Customer
INDEX CustNum I PRIMARY UNIQUE ustNum
INDEX CustNum IS PRIMARY UNIQUE CustNum.
Binary file modified resources/tree-sitter-abl.wasm
Binary file not shown.
24 changes: 3 additions & 21 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from "vscode";
import Parser from "web-tree-sitter";
import { AblFormatterProvider } from "./providers/AblFormatterProvider";
Expand All @@ -10,8 +8,6 @@ import { ConfigurationManager2 } from "./utils/ConfigurationManager";
import { enableFormatterDecorators } from "./v2/formatterFramework/enableFormatterDecorators";
import { DebugManager } from "./providers/DebugManager";

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
export async function activate(context: vscode.ExtensionContext) {
const debugManager = DebugManager.getInstance(context);

Expand All @@ -38,23 +34,9 @@ export async function activate(context: vscode.ExtensionContext) {

const hoverProvider = new AblDebugHoverProvider(parserHelper);
vscode.languages.registerHoverProvider(Constants.ablId, hoverProvider);

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
let disposable = vscode.commands.registerCommand(
"AblFormatter.helloWorld",
() => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
vscode.window.showInformationMessage(
"Hello World from AblFormatter!"
);
}
);

context.subscriptions.push(disposable);
}

// This method is called when your extension is deactivated
export function deactivate() {}
export function deactivate() {
//do nothing
}
10 changes: 0 additions & 10 deletions src/v2/formatterFramework/FormatterFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export class FormatterFactory {
public static getFormatterInstances(
configurationManager: IConfigurationManager
): IFormatter[] {
console.log("Getting formatters ... ");
const instances: IFormatter[] = [];
for (const formatterClass in formatterRegistry) {
if (
Expand All @@ -15,18 +14,9 @@ export class FormatterFactory {
configurationManager
)
) {
console.log(
"Formatter activated:",
formatterRegistry[formatterClass].formatterLabel
);
instances.push(
new formatterRegistry[formatterClass](configurationManager)
);
} else {
console.log(
"Formatter disabled:",
formatterRegistry[formatterClass].formatterLabel
);
}
}
return instances;
Expand Down
1 change: 0 additions & 1 deletion src/v2/formatterFramework/FormattingEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ export class FormattingEngine {
this.configurationManager.setOverridingSettings(
JSON.parse(settingsString)
);
console.log("Settings override");
}
}

Expand Down
56 changes: 42 additions & 14 deletions src/v2/formatters/block/BlockFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ export class BlockFormater extends AFormatter implements IFormatter {
);

const indentationStep = this.settings.tabSize();
const blockStatementsStartRows = node.children
let indexOfColon = -1;
let blockStatementsStartRows = node.children
.filter((child) => {
if (child.type === ":") {
if (child.type === SyntaxNodeType.ColonKeyword) {
indexOfColon = child.startPosition.column;
return false;
}
return true;
Expand All @@ -85,31 +87,59 @@ export class BlockFormater extends AFormatter implements IFormatter {
);

// Do not do any changes for one-liner blocks
if (codeLines.length === 1) {
if (codeLines.length <= 1) {
const text = FormatterHelper.getCurrentText(node, fullText);
return this.getCodeEdit(node, text, text, fullText);
}
const firstLine = codeLines[0];
const lastLine = codeLines[codeLines.length - 1];

const lastLineMatchesTypicalStructure = this.matchEndPattern(lastLine);
if (lastLineMatchesTypicalStructure) {
codeLines.pop();
}

if (indexOfColon !== -1) {
// indexOfColon += parentIndentation;
indexOfColon -= parent.startPosition.column;
const partAfterColon = firstLine
.slice(indexOfColon + 1)
.trimStart();
// If the part after the colon is not only whitespace, put it on the next line
if (partAfterColon.trim().length !== 0) {
const firstPart = firstLine.slice(0, indexOfColon + 1);
codeLines.shift(); // pop from the start of the list
codeLines.unshift(firstPart, partAfterColon);
const firstBlockStatementRow = blockStatementsStartRows[0];
blockStatementsStartRows.shift();
blockStatementsStartRows.unshift(
firstBlockStatementRow - 1,
firstBlockStatementRow
);
blockStatementsStartRows = blockStatementsStartRows.map(
(currentRow) => currentRow + 1
);
}
}

let n = 0;
let lineChangeDelta = 0;
codeLines.forEach((codeLine, index) => {
const lineNumber = parent.startPosition.row + index;

// adjust delta
if (blockStatementsStartRows[n] === lineNumber) {
lineChangeDelta =
parentIndentation +
indentationStep -
FormatterHelper.getActualTextIndentation(
codeLine,
fullText
);
if (index === 0) {
lineChangeDelta = 0;
} else {
lineChangeDelta =
parentIndentation +
indentationStep -
FormatterHelper.getActualTextIndentation(
codeLine,
fullText
);
}

n++;
}
Expand All @@ -123,6 +153,7 @@ export class BlockFormater extends AFormatter implements IFormatter {
});

if (lastLineMatchesTypicalStructure) {
codeLines.push(lastLine);
const parentOfEndNode = formattingOnStatement
? node.parent
: parent;
Expand All @@ -141,15 +172,12 @@ export class BlockFormater extends AFormatter implements IFormatter {

if (endRowDelta !== 0) {
indentationEdits.push({
line:
parent.endPosition.row -
parent.startPosition.row,
line: codeLines.length - 1,
lineChangeDelta: endRowDelta,
});
}
}
}
codeLines.push(lastLine);
} else {
const parentOfEndNode = formattingOnStatement
? node.parent
Expand Down
42 changes: 0 additions & 42 deletions vsc-extension-quickstart.md

This file was deleted.

0 comments on commit 14be8d4

Please sign in to comment.