Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.0.7 release #106

Merged
merged 21 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,14 @@
- Fixed bug that introduced spaces to blank lines
- Introduced webpack to bundle the extension
- Removed docs from the bundled extension (they can still be accessed online at the repo)
- Improvements to RestFS API
- Improvements to RestFS API

## 2.0.7

- Fixed a bug with the "customWordPath" option (#24)
- Fixed auto-formatting bug (#45)
- Added documentation for the RestFS API (#89)
- Fixed bug with space-prefixed labels (#96)
- Improved linting (#98)
- Improved label detection with GOTO/GOSUB (#99)
- Fixed bug with FOR/NEXT linting with labels (#104)
4 changes: 2 additions & 2 deletions Syntaxes/QM.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"name": "QM# BASIC",
"patterns": [
{
"match": "(\"([^\"]|\"\")*\")|('([^']|'')*')|(\\\\([^\\\\]|\\\\\\\\)*\\\\)",
"match": "'.*?'|\".*?\"|\\\\.*?\\\\",
"name": "string.other.quoted-or-unquoted.mvon"
},
{
"match": "(^[0-9]+\\s)|(^[0-9]+:\\s)|(^[\\w]+:(?!=))|(^[\\w\\.\\w]+:(?!=))",
"match": "^\\s*([\\w.]+:(?!=)|[0-9.]+)",
"name": "string.other.quoted-or-unquoted.mvon"
},
{
Expand Down
4 changes: 2 additions & 2 deletions Syntaxes/UniVerse.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"name": "MVON# BASIC",
"patterns": [
{
"match": "(\"([^\"]|\"\")*\")|('([^']|'')*')|(\\\\([^\\\\]|\\\\\\\\)*\\\\)",
"match": "'.*?'|\".*?\"|\\\\.*?\\\\",
"name": "string.other.quoted-or-unquoted.mvon"
},
{
"match": "(^[0-9]+\\s)|(^[0-9]+:\\s)|(^[\\w]+:(?!=))|(^[\\w\\.\\w]+:(?!=))",
"match": "^\\s*([\\w.]+:(?!=)|[0-9.]+)",
"name": "string.other.quoted-or-unquoted.mvon"
},
{
Expand Down
4 changes: 2 additions & 2 deletions Syntaxes/jBASE.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"name": "jBASE PickBASIC",
"patterns": [
{
"match": "(\"([^\"]|\"\")*\")|('([^']|'')*')|(\\\\([^\\\\]|\\\\\\\\)*\\\\)",
"match": "'.*?'|\".*?\"|\\\\.*?\\\\",
"name": "string.other.quoted-or-unquoted.jbase"
},
{
"match": "(^[0-9]+\\s)|(^[0-9]+:\\s)|(^[\\w]+:(?!=))|(^[\\w\\.\\w]+:(?!=))",
"match": "^\\s*([\\w.]+:(?!=)|[0-9.]+)",
"name": "string.other.quoted-or-unquoted.jbase"
},
{
Expand Down
4 changes: 2 additions & 2 deletions Syntaxes/mvon.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"name": "MVON# BASIC",
"patterns": [
{
"match": "(\"([^\"]|\"\")*\")|('([^']|'')*')|(\\\\([^\\\\]|\\\\\\\\)*\\\\)",
"match": "'.*?'|\".*?\"|\\\\.*?\\\\",
"name": "string.other.quoted-or-unquoted.mvon"
},
{
"match": "(^[0-9]+)|(^[0-9]+:\\s)|(^[\\w]+:(?!=))|(^[\\w\\.\\w]+:(?!=))",
"match": "^\\s*([\\w.]+:(?!=)|[0-9.]+)",
"name": "string.other.quoted-or-unquoted.mvon"
},
{
Expand Down
4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mvbasic",
"displayName": "MV Basic",
"description": "MV Basic",
"version": "2.0.6",
"version": "2.0.7",
"publisher": "mvextensions",
"license": "MIT",
"icon": "../images/mvbasic-logo.png",
Expand Down Expand Up @@ -38,4 +38,4 @@
"@types/node": "^13.13.4",
"@types/vscode": "^1.44.0"
}
}
}
128 changes: 74 additions & 54 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,13 @@ export function activate(context: vscode.ExtensionContext) {
var lines = contents.replace('\r', '').split('\n');
for (let i = 0; i < lines.length; i++) {
let parts = lines[i].split(':')
customWordDict.set(parts[0].replace("\"", "").replace("\"", ""), parts[1].replace("\"", "").replace("\"", ""))
customWordlist += parts[0].replace('"', '').replace("\"", "") + "|";
if (parts.length >= 2) {
customWordDict.set(parts[0].replace("\"", "").replace("\"", ""), parts[1].replace("\"", "").replace("\"", ""))
customWordlist += parts[0].replace("\"", '').replace("\"", "") + "|";
}
}
customWordlist = customWordlist.substr(0, customWordlist.length - 1) + ")";
if (customWordlist.length > 1)
customWordlist = customWordlist.substr(0, customWordlist.length - 1) + ")";

}

Expand Down Expand Up @@ -270,84 +273,96 @@ export function activate(context: vscode.ExtensionContext) {
var edits: vscode.TextEdit[] = []

if (formattingEnabled) {
let rBlockStart = new RegExp("^(lock |key\\(|if |commit |rollback |readnext |open |write |writeu |writev |writevu |read |readv |readu |readt |readvu |matreadu |locate |locate\\(|openseq |matread |create |readlist |openpath |find |findstr |bscan)", "i")
let rBlockCase = new RegExp("(^begin case)", "i")
let rBlockTransaction = new RegExp("(^begin transaction|^begin work)", "i")
let rBlockEndCase = new RegExp("(^end case)", "i")
let rBlockEndTransaction = new RegExp("(^end transaction|^end work)", "i")
let rBlockAlways = new RegExp("^(for |loop$|loop\\s+)", "i")
let rBlockContinue = new RegExp("(then$|else$|case$|on error$|locked$)", "i")
let rBlockEnd = new RegExp("^(end|repeat|next\\s.+)$", "i")
let rElseEnd = new RegExp("^(end else\\s.+)", "i")
let rLabel = new RegExp("(^[0-9]+\\s)|(^[0-9]+:\\s)|(^[\\w]+:)");
let rBlockStart = new RegExp("^(begin case$|lock |key\\(|if |commit |rollback |readnext |open |write |writeu |writev |writevu |read |readv |readu |readt |readvu |matreadu |locate |locate\\(|openseq |matread |create |readlist |openpath |find |findstr |bscan)", "i")
let rBlockAlways = new RegExp("^(for |loop( |$))", "i")
let rBlockContinue = new RegExp(" (then|else|case|on error|locked)$", "i")
let rBlockEnd = new RegExp("^(end|end case|next|next\\s+.+|repeat)$| repeat$", "i")
let rBlockCase = new RegExp("^begin case$", "i")
let rBlockEndCase = new RegExp("^end case$", "i")
let rBlockTransaction = new RegExp("^(begin transaction|begin work)", "i")
let rBlockEndTransaction = new RegExp("^(end transaction|end work)", "i")
let rElseEnd = new RegExp("^end else\\s+?.+?", "i")
let rLabel = new RegExp("^([\\w\\.]+:(?!=)|[0-9\\.]+)");
let rComment = new RegExp("^\\s*(\\*|!|REM\\s+?).*", "i")
let tComment = new RegExp(";\\s*(\\*|!|REM\\s+?).*", "i");
let lComment = new RegExp("(^[0-9]+\\s+\\*)|(^[0-9]+\\s+;)|(^[0-9]+\\*)|(^[0-9]+;)") // number label with comments after
let trailingComment = new RegExp("(\\*.+)|(;+)")
let spaces = " "
let lComment = new RegExp("^\\s*([\\w\\.]+:(?!=)|[0-9\\.]+)(\\s*(\\*|!|REM\\s+?).*)", "i") // a label with comments after
let qStrings = new RegExp("'.*?'|\".*?\"|\\\\.*?\\\\", "g");
let rParenthesis = new RegExp("\\(.*\\)", "g");
if (indent === undefined) { indent = 3 }
if (margin === undefined) { margin = 5 }


// first build a list of labels in the program and indentation levels
let Level = 0
var RowLevel: number[] = []
for (var i = 0; i < document.lineCount; i++) {

let curLine = document.lineAt(i);
let line = curLine.text;
if (rComment.test(line.trim()) == true) { continue }
// TODO ignore comment lines and
if (line.trim().startsWith("$")) { continue }
// remove trailing comments

if (tComment.test(line.trim()) == true) {
let comment = tComment.exec(line.trim());
line = line.trim().replace(comment[0], "");
// replace comment line with blank line
line = line.replace(rComment, "");

// remove comments after label (no semi-colon)
if (lComment.test(line)) {
let comment = lComment.exec(line);
line = comment![1];
}
lComment.lastIndex = 0;
if (lComment.test(line.trim()) === true) {
let comment = trailingComment.exec(line.trim());
if (comment != null) {
line = line.trim().replace(comment[0], "");
}

// remove trailing comments with a semi-colon
line = line.replace(tComment, "");

// replace contents of parenthesis with spaces, maintaining original
// character positions for intellisense error highlighting.
let v = rParenthesis.exec(line);
if (v !== null) {
let value = "(" + " ".repeat(v[0].length - 2) + ")";
line = line.replace(rParenthesis, value);
}

// replace contents of quoted strings with spaces, maintaining original
// character positions for intellisense error highlighting.
v = qStrings.exec(line);
if (v !== null) {
let value = "'" + " ".repeat(v[0].length - 2) + "'";
line = line.replace(qStrings, value);
}

// Trim() leading & trailing spaces
line = line.trim();

// check opening and closing block for types
// check block statements
var position = i
RowLevel[i] = Level

if (rBlockStart.test(line.trim()) == true) {
if (rBlockStart.test(line)) {
Level++
if (rBlockContinue.test(line.trim()) == false) {
if (!rBlockContinue.test(line)) {
// single line statement
Level--
}
position = i + 1
}
if (rBlockCase.test(line.trim()) == true) {
// increment 2 to cater for case statement
Level++
if (rBlockCase.test(line)) {
// increment to cater for case statement
Level++
position = i + 1
}
if (rBlockEndCase.test(line.trim()) == true) {
// decrement 2 to cater for case statement
Level--
if (rBlockEndCase.test(line)) {
// decrement to cater for case statement
Level--
}
if (rElseEnd.test(line.trim()) == true) {
if (rElseEnd.test(line)) {
// decrement 1 to cater for end else stements
Level--
}
if (rBlockTransaction.test(line.trim()) == true) {
// increment 2 to cater for case statement
if (rBlockTransaction.test(line)) {
// increment for transaction statement
Level++
position = i + 1
}
if (rBlockEndTransaction.test(line.trim()) == true) {
// decrement 2 to cater for case statement
if (rBlockEndTransaction.test(line)) {
// decrement for transaction statement
Level--
}
if (rBlockAlways.test(line.trim())) {
Expand All @@ -360,40 +375,45 @@ export function activate(context: vscode.ExtensionContext) {
}
RowLevel[position] = Level
}

// Output formatted lines
for (var i = 0; i < document.lineCount; i++) {

const line = document.lineAt(i);
let lineText = line.text.trim();

// ignore labels
if (rLabel.test(line.text.trim()) == true) { continue }
if (rLabel.test(lineText)) { continue }

var indentation = 0

if (RowLevel[i] === undefined) { continue; }

indentation = (RowLevel[i] * indent) + margin
if (new RegExp("(^case\\s)", "i").test(line.text.trim()) == true) {
if (new RegExp("(^case\\s)", "i").test(lineText)) {
indentation -= indent
}
if (new RegExp("(^while\\s|^until\\s)", "i").test(line.text.trim()) == true) {
if (new RegExp("(^while\\s|^until\\s)", "i").test(lineText)) {
indentation -= indent
}
if (new RegExp("(^end else$)", "i").test(line.text.trim()) == true) {

// remove trailing comments with a semi-colon
let tempLine = lineText.replace(tComment, "").trim();
if (new RegExp("(^end else$)", "i").test(tempLine)) {
indentation -= indent
}

var blankLine = line.text.replace(/\s/g, "")
var blankLine = lineText.replace(/\s/g, "")
if (indentation < 1 || blankLine.length == 0) {
edits.push(vscode.TextEdit.replace(line.range, line.text.trim()))
edits.push(vscode.TextEdit.replace(line.range, lineText))
}
else {
var regEx = "\\s{" + indentation + "}"
var formattedLine = new RegExp(regEx).exec(spaces)[0] + line.text.trim()
var formattedLine = " ".repeat(indentation) + lineText
var formatted = vscode.TextEdit.replace(line.range, formattedLine)
edits.push(formatted)
}
}
}

return edits
}
});
Expand Down Expand Up @@ -451,11 +471,11 @@ export function activate(context: vscode.ExtensionContext) {
}
activeEditor.setDecorations(customDecoration, customWords);
}

let api = {
getRestFS(): RestFS {
return RESTFS;
}
}
};
return api;
}
Expand Down
2 changes: 1 addition & 1 deletion doc/DeveloperIntro.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ An introduction to how syntax highlights work in VSCode: https://code.visualstud

A description of the various "scopes" typically used: https://macromates.com/manual/en/language_grammars#naming_conventions

Using "Developer: Inspect TM Scopes" to see how a particular token is interpreted. This will show both the source as well as the scope for any language elements selected.
Using "Developer: Inspect Editor Token and Scopes" to see how a particular token is interpreted. This will show both the source as well as the scope for any language elements selected.

![Dev Inspect Scopes](screenshots/devguide/dev_inspect_scopes.gif)

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mvbasic",
"displayName": "MV Basic",
"description": "MV Basic",
"version": "2.0.6",
"version": "2.0.7",
"publisher": "mvextensions",
"license": "MIT",
"icon": "images/mvbasic-logo.png",
Expand Down Expand Up @@ -341,4 +341,4 @@
"webpack-cli": "^3.3.11"
},
"dependencies": {}
}
}
4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mvbasic",
"displayName": "MV Basic",
"description": "MV Basic",
"version": "2.0.6",
"version": "2.0.7",
"publisher": "mvextensions",
"license": "MIT",
"icon": "../images/mvbasic-logo.png",
Expand Down Expand Up @@ -36,4 +36,4 @@
"devDependencies": {
"@types/node": "^13.13.4"
}
}
}
Loading