Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1,364 changes: 384 additions & 980 deletions package-lock.json

Large diffs are not rendered by default.

147 changes: 114 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
{
"name" : "codealignment-vscode",
"displayName" : "Code alignment",
"description" : "Code Alignment for Visual Studio Code. Based on the Extension for Visual Studio.",
"version" : "0.0.1",
"publisher" : "cpmcgrath",
"engines" : { "vscode": "^1.19.0" },
"categories" : [ "Formatters" ],
"keywords" : [ "align", "alignment", "formatting" ],
"repository": { "type": "git", "url": "https://github.com/cpmcgrath/codealignment-vscode" },
"icon" : "images/CodeAlignment.png",
"name": "codealignment-vscode",
"displayName": "Code alignment",
"description": "Code Alignment for Visual Studio Code. Based on the Extension for Visual Studio.",
"version": "0.0.1",
"publisher": "cpmcgrath",
"engines": {
"vscode": "^1.19.0"
},
"categories": [
"Formatters"
],
"keywords": [
"align",
"alignment",
"formatting"
],
"repository": {
"type": "git",
"url": "https://github.com/cpmcgrath/codealignment-vscode"
},
"icon": "images/CodeAlignment.png",
"activationEvents": [
"onCommand:codealignment.alignbystring",
"onCommand:codealignment.alignbyequals",
Expand All @@ -19,35 +30,105 @@
],
"main": "./out/extension",
"contributes": {
"configuration":[
{
"title": "codealignment",
"properties": {
"codealignment.stopregexes": {
"type": "array",
"items": {
"type": "string"
},
"default": []
}
}

}
],
"commands": [
{ "command": "codealignment.alignbystring", "title" : "Align by string (Code Alignment)" },
{ "command": "codealignment.alignbyequals", "title" : "Align by equals (Code Alignment)" },
{ "command": "codealignment.alignbyperiod", "title" : "Align by period (Code Alignment)" },
{ "command": "codealignment.alignbyquote", "title" : "Align by quote (Code Alignment)" },
{ "command": "codealignment.alignbyregex", "title" : "Align by regex (Code Alignment)" },
{ "command": "codealignment.alignbyspace", "title" : "Align by space (Code Alignment)" }
{
"command": "codealignment.alignbystring",
"title": "Align by string (Code Alignment)"
},
{
"command": "codealignment.alignbyequals",
"title": "Align by equals (Code Alignment)"
},
{
"command": "codealignment.alignbyperiod",
"title": "Align by period (Code Alignment)"
},
{
"command": "codealignment.alignbyquote",
"title": "Align by quote (Code Alignment)"
},
{
"command": "codealignment.alignbyregex",
"title": "Align by regex (Code Alignment)"
},
{
"command": "codealignment.alignbyspace",
"title": "Align by space (Code Alignment)"
}
],
"keybindings" : [
{ "command": "codealignment.alignbystring", "key": "ctrl+shift+=", "mac": "cmd+shift+=", "when": "editorTextFocus"},
{ "command": "codealignment.alignbyequals", "key": "ctrl+= ctrl+=", "mac": "cmd+= cmd+=", "when": "editorTextFocus"},
{ "command": "codealignment.alignbyequalsfromcaret", "key": "ctrl+= ctrl+shift+=", "mac": "cmd+= cmd+shift+=", "when": "editorTextFocus"},
{ "command": "codealignment.alignbyperiod", "key": "ctrl+= ctrl+.", "mac": "cmd+= cmd+.", "when": "editorTextFocus"},
{ "command": "codealignment.alignbyquote", "key": "ctrl+= ctrl+'", "mac": "cmd+= cmd+'", "when": "editorTextFocus"},
{ "command": "codealignment.alignbyquotefromcaret", "key": "ctrl+= ctrl+shift+'", "mac": "cmd+= cmd+shift+'", "when": "editorTextFocus"},
{ "command": "codealignment.alignbyspace", "key": "ctrl+= ctrl+space", "mac": "cmd+= cmd+space", "when": "editorTextFocus"}
"keybindings": [
{
"command": "codealignment.alignbystring",
"key": "ctrl+shift+=",
"mac": "cmd+shift+=",
"when": "editorTextFocus"
},
{
"command": "codealignment.alignbyequals",
"key": "ctrl+= ctrl+=",
"mac": "cmd+= cmd+=",
"when": "editorTextFocus"
},
{
"command": "codealignment.alignbyequalsfromcaret",
"key": "ctrl+= ctrl+shift+=",
"mac": "cmd+= cmd+shift+=",
"when": "editorTextFocus"
},
{
"command": "codealignment.alignbyperiod",
"key": "ctrl+= ctrl+.",
"mac": "cmd+= cmd+.",
"when": "editorTextFocus"
},
{
"command": "codealignment.alignbyquote",
"key": "ctrl+= ctrl+'",
"mac": "cmd+= cmd+'",
"when": "editorTextFocus"
},
{
"command": "codealignment.alignbyquotefromcaret",
"key": "ctrl+= ctrl+shift+'",
"mac": "cmd+= cmd+shift+'",
"when": "editorTextFocus"
},
{
"command": "codealignment.alignbyspace",
"key": "ctrl+= ctrl+space",
"mac": "cmd+= cmd+space",
"when": "editorTextFocus"
}
]
},
"scripts": {
"vscode:prepublish" : "npm run compile",
"compile" : "tsc -p ./",
"watch" : "tsc -watch -p ./",
"postinstall" : "node ./node_modules/vscode/bin/install",
"test" : "npm run compile && node ./node_modules/vscode/bin/test"
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "npm run compile && node ./node_modules/vscode/bin/test"
},
"devDependencies": {
"typescript" : "^3.1.6",
"vscode" : "^1.1.21",
"@types/node" : "^10.12.10",
"@types/mocha" : "^5.2.5"
"typescript": "^3.1.6",
"vscode": "^1.1.22"
},
"dependencies": {
"@types/mocha": "^5.2.5",
"@types/node": "^11.9.3"
}
}
19 changes: 19 additions & 0 deletions src/common/Config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as vscode from "vscode"

export interface ICodeAlignmentConfig
{
stopregexes: string[]
}

export class Config implements ICodeAlignmentConfig
{
stopregexes: string[];

public static GetConfig(): ICodeAlignmentConfig
{
let config = vscode.workspace.getConfiguration("codealignment");
return {
stopregexes: config.get<string[]>("stopregexes")
}
}
}
2 changes: 1 addition & 1 deletion src/common/business/Alignment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NormalDelimiterFinder } from "./delimiterFinders/NormalDelimiterFinder";
import { LineDetails } from "./lineDetails";
import { LineDetails } from "./LineDetails";
import { StringFunctions } from "./tools/StringFunctions";
import { IDelimiterFinder } from "./interfaces/IDelimiterFinder";
import { ArrayFunctions } from "./tools/ArrayFunctions";
Expand Down
28 changes: 25 additions & 3 deletions src/common/business/selectors/GeneralScopeSelector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export class GeneralScopeSelector implements IScopeSelector
import { Config } from '../../Config';
import * as vscode from 'vscode';

export class GeneralScopeSelector implements IScopeSelector
{
ScopeSelectorRegex : string;
Start : number; //nullable
Expand All @@ -25,7 +28,7 @@
private GetStart(view: IDocument, start: number) : number
{
for (var i = start; i >= 0; i--)
if (this.IsLineBlank(view, i))
if (this.IsLineBlank(view, i) || this.StopRexexMatches(view, i))
return i + 1;

return 0;
Expand All @@ -34,12 +37,31 @@
private GetEnd(view: IDocument, end: number) : number
{
for (var i = end; i < view.LineCount; i++)
if (this.IsLineBlank(view, i))
if (this.IsLineBlank(view, i) || this.StopRexexMatches(view, i))
return i - 1;

return view.LineCount - 1;
}

private StopRexexMatches(view: IDocument, lineNo: number): boolean
{
let line = view.GetLineFromLineNumber(lineNo);
let config = Config.GetConfig();
for(let pattern of config.stopregexes)
{
try
{
let regex = new RegExp(pattern);
if(regex.test(line.Text) == true)
return true;
}
catch(error)
{
vscode.window.showErrorMessage(`Could not test regex with pattern ${pattern}, maybe it is invalid (you have to double escape \\)? Exception: ${error}`)
}
}
}

private IsLineBlank(view: IDocument, lineNo: number) : boolean
{
//return Regex.IsMatch(view.GetLineFromLineNumber(lineNo).Text, this.ScopeSelectorRegex);
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

import * as vscode from 'vscode';
import { Line } from './implementation/line'
import { Document } from './implementation/document'
import { Line } from './implementation/Line'
import { Document } from './implementation/Document'
import { Alignment } from './common/business/Alignment'
import { GeneralScopeSelector } from './common/business/selectors/GeneralScopeSelector';
import { RegexDelimiterFinder } from './common/business/delimiterFinders/RegexDelimiterFinder';
Expand Down
4 changes: 2 additions & 2 deletions src/implementation/Document.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import { Line } from './line'
import { Edit } from './edit'
import { Line } from './Line'
import { Edit } from './Edit'

export class Document implements IDocument
{
Expand Down
2 changes: 1 addition & 1 deletion src/implementation/Edit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from 'vscode';
import { Line } from './line'
import { Line } from './Line'

type ChangeData = { position: vscode.Position; text: string }

Expand Down