Skip to content

Commit ac54fc8

Browse files
committed
Split the classes into their own files.
Add folders where needed.
1 parent 2a8fa0a commit ac54fc8

19 files changed

Lines changed: 127 additions & 119 deletions

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
"activationEvents": [
2222
"onLanguage:markdown"
2323
],
24-
"main": "./out/src/extension",
24+
"main": "./out/src/extension/extension",
2525
"contributes": { },
2626
"capabilities": {
2727
"documentFormattingProvider" : "true"
2828
},
2929
"scripts": {
3030
"vscode:prepublish": "tsc -p ./",
31-
"compile": "tsc -watch -p ./",
31+
"compile": "tsc -p ./",
3232
"postinstall": "node ./node_modules/vscode/bin/install",
3333
"test": "node ./node_modules/vscode/bin/test"
3434
},

src/column.ts renamed to src/column/column.ts

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { RawColumn } from "./rawColumn";
2+
import { ColumnPositioning } from "./columnPositioning";
3+
14
export class Column {
25
private _normalizedColumnValues: string[] = [];
36

@@ -74,67 +77,3 @@ export class Column {
7477
return this._normalizedColumnValues.length == 1;
7578
}
7679
}
77-
78-
export enum ColumnPositioning {
79-
Unkown,
80-
First,
81-
Middle,
82-
Last
83-
}
84-
85-
export class ColumnFactory {
86-
public static *generateColumns(rawRows: string[][]): Iterable<Column> {
87-
const rowCount = rawRows.length;
88-
let colCount = rawRows[0].length;
89-
90-
let rawColumns: RawColumn[] = [];
91-
92-
// Create "raw" columns first to be able to specify the position (first/middle/last) of all columns later (based
93-
// on maxLength) taking into account that columns can still be added or removed from the begginning/end.
94-
for (let col = 0; col < colCount; col++) {
95-
rawColumns.push(new RawColumn(rawRows.map(r => r[col].trim())));
96-
}
97-
98-
if (colCount > 1 && !rawColumns[0].isEmpty() && rawColumns[colCount - 1].isEmpty()) {
99-
// if the first column is not empty, but the last one is, then remove the last one
100-
rawColumns.splice(colCount - 1, 1);
101-
colCount--;
102-
} else if (colCount > 1 && rawColumns[0].isEmpty() && !rawColumns[colCount - 1].isEmpty()) {
103-
// add an empty column at the end if the first one is an empty column but the last one isn't
104-
const emptyRawRows = new Array(rowCount).fill(0);
105-
rawColumns.push(new RawColumn(emptyRawRows));
106-
colCount++;
107-
}
108-
109-
// now that the types can be determined create the real columns
110-
for (let col = 0; col < colCount; col++) {
111-
const columnPositioning = col == 0
112-
? ColumnPositioning.First
113-
: col == colCount - 1
114-
? ColumnPositioning.Last
115-
: ColumnPositioning.Middle;
116-
yield new Column(rawColumns[col], columnPositioning);
117-
}
118-
}
119-
}
120-
121-
export class RawColumn {
122-
public cellLength: number = 0;
123-
constructor(public columnValues: string[]) {
124-
this._setCellLength();
125-
}
126-
127-
isEmpty(): boolean {
128-
return this.cellLength == 0;
129-
}
130-
131-
private _setCellLength(): void {
132-
// determine the expected maximum length of this column
133-
const rowCount = this.columnValues.length;
134-
for (let row = 0 ; row < rowCount; row++) {
135-
const currentLength = this.columnValues[row].length;
136-
if (currentLength > this.cellLength)
137-
this.cellLength = currentLength;
138-
}
139-
}
140-
}

src/column/columnFactory.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Column } from "./column";
2+
import { RawColumn } from "./rawColumn";
3+
import { ColumnPositioning } from "./columnPositioning";
4+
5+
export class ColumnFactory {
6+
public static *generateColumns(rawRows: string[][]): Iterable<Column> {
7+
const rowCount = rawRows.length;
8+
let colCount = rawRows[0].length;
9+
10+
let rawColumns: RawColumn[] = [];
11+
12+
// Create "raw" columns first to be able to specify the position (first/middle/last) of all columns later (based
13+
// on maxLength) taking into account that columns can still be added or removed from the begginning/end.
14+
for (let col = 0; col < colCount; col++) {
15+
rawColumns.push(new RawColumn(rawRows.map(r => r[col].trim())));
16+
}
17+
18+
if (colCount > 1 && !rawColumns[0].isEmpty() && rawColumns[colCount - 1].isEmpty()) {
19+
// if the first column is not empty, but the last one is, then remove the last one
20+
rawColumns.splice(colCount - 1, 1);
21+
colCount--;
22+
} else if (colCount > 1 && rawColumns[0].isEmpty() && !rawColumns[colCount - 1].isEmpty()) {
23+
// add an empty column at the end if the first one is an empty column but the last one isn't
24+
const emptyRawRows = new Array(rowCount).fill(0);
25+
rawColumns.push(new RawColumn(emptyRawRows));
26+
colCount++;
27+
}
28+
29+
// now that the types can be determined create the real columns
30+
for (let col = 0; col < colCount; col++) {
31+
const columnPositioning = col == 0
32+
? ColumnPositioning.First
33+
: col == colCount - 1
34+
? ColumnPositioning.Last
35+
: ColumnPositioning.Middle;
36+
yield new Column(rawColumns[col], columnPositioning);
37+
}
38+
}
39+
}

src/column/columnPositioning.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export enum ColumnPositioning {
2+
Unkown,
3+
First,
4+
Middle,
5+
Last
6+
}

src/column/rawColumn.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export class RawColumn {
2+
public cellLength: number = 0;
3+
constructor(public columnValues: string[]) {
4+
this._setCellLength();
5+
}
6+
7+
isEmpty(): boolean {
8+
return this.cellLength == 0;
9+
}
10+
11+
private _setCellLength(): void {
12+
// determine the expected maximum length of this column
13+
const rowCount = this.columnValues.length;
14+
for (let row = 0 ; row < rowCount; row++) {
15+
const currentLength = this.columnValues[row].length;
16+
if (currentLength > this.cellLength)
17+
this.cellLength = currentLength;
18+
}
19+
}
20+
}
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22
import * as vscode from 'vscode';
33
import { TableRangePrettyfier } from "./tableRangePrettyfier";
4-
import { TableFactory } from "./tableFactory";
5-
import { VsWindowLogger } from "./logger";
4+
import { TableFactory } from "../table/tableFactory";
5+
import { VsWindowLogger } from "../diagnostics/logger";
66

77
// This method is called when the extension is activated.
88
// The extension is activated the very first time the command is executed.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as vscode from 'vscode';
2-
import { ITable, Table } from "./table";
3-
import { ITableFactory } from "./tableFactory";
4-
import { ILogger } from "./logger";
1+
import * as vscode from "vscode";
2+
import { ITable } from "../table/table";
3+
import { ITableFactory } from "../table/tableFactory";
4+
import { ILogger } from "../diagnostics/logger";
55

66
export class TableRangePrettyfier implements vscode.DocumentRangeFormattingEditProvider {
77

src/table.ts renamed to src/table/table.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { Column, ColumnPositioning, ColumnFactory } from "./column";
1+
import { Column } from "../column/column";
2+
import { ColumnFactory } from "../column/columnFactory";
3+
import { ColumnPositioning } from "../column/columnPositioning";
24

35
export interface ITable {
46
prettyPrint(): string;

0 commit comments

Comments
 (0)