From 48c674a51eed5a5f1fdb08901b43185875bef746 Mon Sep 17 00:00:00 2001 From: Iain King Date: Sun, 1 Dec 2019 12:13:41 +0000 Subject: [PATCH 1/4] Changed indentation rules to only apply when enter is pressed, to fix copy+paste & move line being broken. --- src/nimMain.ts | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/src/nimMain.ts b/src/nimMain.ts index d77821a..a75989f 100644 --- a/src/nimMain.ts +++ b/src/nimMain.ts @@ -48,15 +48,45 @@ export function activate(ctx: vscode.ExtensionContext): void { ctx.subscriptions.push(diagnosticCollection); vscode.languages.setLanguageConfiguration(NIM_MODE.language as string, { - indentationRules: { - increaseIndentPattern: /^\s*((((proc|macro|iterator|template|converter|func)\b.*\=)|(import|export|var|const|type)\s)|(import|export|let|var|const|type)|([^:]+:))$/, - decreaseIndentPattern: /^\s*(((return|break|continue|raise)\n)|((elif|else|except|finally)\b.*:))\s*$/ - }, + // @Note Literal whitespace in below regexps is removed + onEnterRules: [ + { + beforeText: new RegExp(String.raw` + ^\s* + ( + ( + (proc|macro|iterator|template|converter|func) \b .*= + )|( + (import|export|let|var|const|type) \b + )|( + [^:]+: + ) + ) + \s*$ + `.replace(/\s+?/g, '')), + action: { + indentAction: vscode.IndentAction.Indent + } + }, + { + beforeText: new RegExp(String.raw` + ^\s* + ( + ( + (return|raise|break|continue) \b .* + )|( + (discard) \b + ) + ) + \s* + `.replace(/\s+?/g, '')), + action: { + indentAction: vscode.IndentAction.Outdent + } + } + ], + wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g, - onEnterRules: [{ - beforeText: /^\s*$/, - action: { indentAction: vscode.IndentAction.None } - }] }); vscode.window.onDidChangeActiveTextEditor(showHideStatus, null, ctx.subscriptions); From 28f8d55289479e3f1097b98358bcf621566280fd Mon Sep 17 00:00:00 2001 From: Iain King Date: Sun, 1 Dec 2019 14:51:53 +0000 Subject: [PATCH 2/4] No indent after `case` --- src/nimMain.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/nimMain.ts b/src/nimMain.ts index a75989f..73b17c3 100644 --- a/src/nimMain.ts +++ b/src/nimMain.ts @@ -50,6 +50,18 @@ export function activate(ctx: vscode.ExtensionContext): void { vscode.languages.setLanguageConfiguration(NIM_MODE.language as string, { // @Note Literal whitespace in below regexps is removed onEnterRules: [ + { + beforeText: new RegExp(String.raw` + ^\s* + ( + (case) \b .* : + ) + \s*$ + `.replace(/\s+?/g, '')), + action: { + indentAction: vscode.IndentAction.None + } + }, { beforeText: new RegExp(String.raw` ^\s* From 74154cb62a3bb7216596c204d1b18ee55ff7998e Mon Sep 17 00:00:00 2001 From: Iain King Date: Tue, 3 Dec 2019 10:31:32 +0000 Subject: [PATCH 3/4] Added ability to set runtime command-line arguments in comments, for testing --- src/nimMain.ts | 72 ++++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 52 deletions(-) diff --git a/src/nimMain.ts b/src/nimMain.ts index 73b17c3..7d852c3 100644 --- a/src/nimMain.ts +++ b/src/nimMain.ts @@ -48,57 +48,15 @@ export function activate(ctx: vscode.ExtensionContext): void { ctx.subscriptions.push(diagnosticCollection); vscode.languages.setLanguageConfiguration(NIM_MODE.language as string, { - // @Note Literal whitespace in below regexps is removed - onEnterRules: [ - { - beforeText: new RegExp(String.raw` - ^\s* - ( - (case) \b .* : - ) - \s*$ - `.replace(/\s+?/g, '')), - action: { - indentAction: vscode.IndentAction.None - } - }, - { - beforeText: new RegExp(String.raw` - ^\s* - ( - ( - (proc|macro|iterator|template|converter|func) \b .*= - )|( - (import|export|let|var|const|type) \b - )|( - [^:]+: - ) - ) - \s*$ - `.replace(/\s+?/g, '')), - action: { - indentAction: vscode.IndentAction.Indent - } - }, - { - beforeText: new RegExp(String.raw` - ^\s* - ( - ( - (return|raise|break|continue) \b .* - )|( - (discard) \b - ) - ) - \s* - `.replace(/\s+?/g, '')), - action: { - indentAction: vscode.IndentAction.Outdent - } - } - ], - + indentationRules: { + increaseIndentPattern: /^\s*((((proc|macro|iterator|template|converter|func)\b.*\=)|(import|export|var|const|type)\s)|(import|export|let|var|const|type)|([^:]+:))$/, + decreaseIndentPattern: /^\s*(((return|break|continue|raise)\n)|((elif|else|except|finally)\b.*:))\s*$/ + }, wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g, + onEnterRules: [{ + beforeText: /^\s*$/, + action: { indentAction: vscode.IndentAction.None } + }] }); vscode.window.onDidChangeActiveTextEditor(showHideStatus, null, ctx.subscriptions); @@ -232,13 +190,23 @@ function startBuildOnSaveWatcher(subscriptions: vscode.Disposable[]) { function runFile() { let editor = vscode.window.activeTextEditor; if (editor) { + var additionalArguments = ""; + for (var i = 0; i < editor.document.lineCount; i++) { + var line = editor.document.lineAt(i); + var match = /#\s*vscode-nim\s+arguments:\s+(.*)/i.exec(line.text); + if (match) { + additionalArguments = match[1]; + break; + } + } + if (!terminal) { terminal = vscode.window.createTerminal('Nim'); } terminal.show(true); if (editor.document.isUntitled) { terminal.sendText('nim ' + vscode.workspace.getConfiguration('nim')['buildCommand'] + - ' -r "' + getDirtyFile(editor.document) + '"', true); + ' -r "' + getDirtyFile(editor.document) + '" ' + additionalArguments, true); } else { let outputDirConfig = vscode.workspace.getConfiguration('nim')['runOutputDirectory']; var outputParams = ''; @@ -268,7 +236,7 @@ function runFile() { }); } else { terminal.sendText('nim ' + vscode.workspace.getConfiguration('nim')['buildCommand'] + - outputParams + ' -r "' + editor.document.fileName + '"', true); + outputParams + ' -r "' + editor.document.fileName + '" ' + additionalArguments, true); } } } From 289506045d1518a0c6fc82ef97353addd0c07dec Mon Sep 17 00:00:00 2001 From: Iain King Date: Tue, 3 Dec 2019 10:41:05 +0000 Subject: [PATCH 4/4] Fix quotes --- src/nimMain.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nimMain.ts b/src/nimMain.ts index 7d852c3..947cefd 100644 --- a/src/nimMain.ts +++ b/src/nimMain.ts @@ -190,7 +190,7 @@ function startBuildOnSaveWatcher(subscriptions: vscode.Disposable[]) { function runFile() { let editor = vscode.window.activeTextEditor; if (editor) { - var additionalArguments = ""; + var additionalArguments = ''; for (var i = 0; i < editor.document.lineCount; i++) { var line = editor.document.lineAt(i); var match = /#\s*vscode-nim\s+arguments:\s+(.*)/i.exec(line.text);