Skip to content

Commit b1447fa

Browse files
committed
feat: add .tab file support and default tab delimiter handling
1 parent ced8dd2 commit b1447fa

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Working with CSV files shouldn’t be a chore. With CSV, you get:
4242
- **Preserved CSV Integrity:** All modifications respect CSV formatting—no unwanted extra characters or formatting issues.
4343
- **Optimized for Performance:** Designed for medium-sized datasets, ensuring a smooth editing experience without compromising on functionality.
4444
- **Large File Support:** Loads big CSVs in chunks so even large datasets open quickly.
45-
- **TSV Support:** `.tsv` files are recognized automatically and use tabs as the default separator.
45+
- **TSV/TAB Support:** `.tsv` and `.tab` files are recognized automatically and use tabs as the default separator.
4646

4747
---
4848

@@ -59,9 +59,9 @@ Cursor (built on VS Code 1.99) and the latest VS Code releases (1.102).
5959
- Go to the Extensions view (`Ctrl+Shift+X` or `Cmd+Shift+X` on macOS).
6060
- Search for **CSV** and click **Install**.
6161

62-
### 2. Open a CSV or TSV File
62+
### 2. Open a CSV, TSV, or TAB File
6363

64-
- Open any `.csv` or `.tsv` file in VS Code.
64+
- Open any `.csv`, `.tsv`, or `.tab` file in VS Code.
6565
- The file will automatically load, presenting your data in an interactive grid view.
6666

6767
### 3. Edit and Navigate
@@ -104,7 +104,7 @@ Per-file (stored by the extension; set via commands):
104104

105105
- First row as header (default `true`) — `CSV: Toggle First Row as Header`
106106
- Serial index column (default `true`) — `CSV: Toggle Serial Index Column`
107-
- CSV separator (default inherit: `.tsv` → tab, otherwise comma) — `CSV: Change CSV Separator`
107+
- CSV separator (default inherit: `.tsv`/`.tab` → tab, otherwise comma) — `CSV: Change CSV Separator`
108108
- Hide first N rows (default `0`) — `CSV: Hide First N Rows`
109109

110110
---

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@
4747
{
4848
"id": "tsv",
4949
"extensions": [
50-
".tsv"
50+
".tsv",
51+
".tab"
5152
],
5253
"aliases": [
5354
"TSV",
54-
"tsv"
55+
"tsv",
56+
"TAB",
57+
"tab"
5558
],
5659
"configuration": "./language-configuration.json"
5760
}
@@ -133,6 +136,9 @@
133136
},
134137
{
135138
"filenamePattern": "*.tsv"
139+
},
140+
{
141+
"filenamePattern": "*.tab"
136142
}
137143
]
138144
}

src/CsvEditorProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,8 @@ class CsvEditorController {
10871087
const stored = CsvEditorProvider.getSeparatorForUri(this.context, this.document.uri);
10881088
if (stored && stored.length) return stored;
10891089
// Default inherited from file
1090-
return this.document?.uri.fsPath.toLowerCase().endsWith('.tsv') ? '\t' : ',';
1090+
const fsPath = this.document?.uri.fsPath.toLowerCase() || '';
1091+
return (fsPath.endsWith('.tsv') || fsPath.endsWith('.tab')) ? '\t' : ',';
10911092
}
10921093

10931094
private getHiddenRows(): number {

src/commands.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ export function registerCsvCommands(context: vscode.ExtensionContext) {
4141
const active = CsvEditorProvider.getActiveProvider();
4242
if (!active) { vscode.window.showInformationMessage('Open a CSV/TSV file in the CSV editor.'); return; }
4343
const uri = active.getDocumentUri();
44-
const currentSep = CsvEditorProvider.getSeparatorForUri(context, uri) ?? (uri.fsPath.toLowerCase().endsWith('.tsv') ? '\\t' : ',');
44+
const uriPath = uri.fsPath.toLowerCase();
45+
const defaultSep = (uriPath.endsWith('.tsv') || uriPath.endsWith('.tab')) ? '\\t' : ',';
46+
const currentSep = CsvEditorProvider.getSeparatorForUri(context, uri) ?? defaultSep;
4547
const input = await vscode.window.showInputBox({ prompt: 'Enter new CSV separator (empty to inherit from file)', value: currentSep });
4648
if (input !== undefined) {
4749
const sep = input;

src/extension.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export function activate(context: vscode.ExtensionContext) {
3232
if (viewType === CsvEditorProvider.viewType) return; // already our editor
3333
if (!uri) return;
3434
const fsPath = uri.fsPath?.toLowerCase?.() || '';
35-
const isCsv = fsPath.endsWith('.csv') || fsPath.endsWith('.tsv');
36-
console.log(`[CSV(enable)]: -> eligible=${isCsv}`);
37-
if (!isCsv) return;
35+
const isCsvLike = fsPath.endsWith('.csv') || fsPath.endsWith('.tsv') || fsPath.endsWith('.tab');
36+
console.log(`[CSV(enable)]: -> eligible=${isCsvLike}`);
37+
if (!isCsvLike) return;
3838
candidates.push({ group, groupIndex: gi, tab, tabIndex: ti, uri, wasActive: tab.isActive, wasPreview: tab.isPreview, viewColumn: group.viewColumn });
3939
});
4040
});

src/test/separators-and-dates.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ describe('Separators and date edge cases', () => {
2323
assert.strictEqual(eff('/tmp/sample.csv', undefined), ',');
2424
// Default TSV -> '\t'
2525
assert.strictEqual(eff('/tmp/sample.tsv', undefined), '\t');
26+
// Default TAB -> '\t'
27+
assert.strictEqual(eff('/tmp/sample.tab', undefined), '\t');
2628
// Override wins regardless of extension
2729
assert.strictEqual(eff('/tmp/sample.csv', ';'), ';');
2830
assert.strictEqual(eff('/tmp/sample.tsv', ';'), ';');
31+
assert.strictEqual(eff('/tmp/sample.tab', ';'), ';');
2932
});
3033

3134
it('isDate handles offsets, time components, and rejects bogus values', () => {
@@ -43,4 +46,3 @@ describe('Separators and date edge cases', () => {
4346
assert.strictEqual(isDate('42'), false);
4447
});
4548
});
46-

0 commit comments

Comments
 (0)