Skip to content

Commit 79edf29

Browse files
authored
Add TSV support (#45)
* feat: add TSV support * move text
1 parent 20fdd80 commit 79edf29

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to the "CSV" extension will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.1.3] - 2025-06-11
8+
- Added: TSV file support with automatic tab delimiter.
9+
710
## [1.1.2] - 2025-06-11
811
- Fixed: fontFamily
912

README.md

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

4445
---
4546

@@ -56,10 +57,10 @@ Cursor (built on VS Code 1.99) and the latest VS Code releases (1.102).
5657
- Go to the Extensions view (`Ctrl+Shift+X` or `Cmd+Shift+X` on macOS).
5758
- Search for **CSV** and click **Install**.
5859

59-
### 2. Open a CSV File
60+
### 2. Open a CSV or TSV File
6061

61-
- Open any `.csv` file in VS Code.
62-
- The CSV will automatically load, presenting your file in an interactive grid view.
62+
- Open any `.csv` or `.tsv` file in VS Code.
63+
- The file will automatically load, presenting your data in an interactive grid view.
6364

6465
### 3. Edit and Navigate
6566

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"categories": ["Data Science", "Programming Languages", "Other"],
1717
"activationEvents": [
1818
"onLanguage:csv",
19+
"onLanguage:tsv",
1920
"onCommand:csv.toggleExtension",
2021
"onCommand:csv.toggleHeader",
2122
"onCommand:csv.toggleSerialIndex",
@@ -30,6 +31,12 @@
3031
"extensions": [".csv"],
3132
"aliases": ["CSV", "csv"],
3233
"configuration": "./language-configuration.json"
34+
},
35+
{
36+
"id": "tsv",
37+
"extensions": [".tsv"],
38+
"aliases": ["TSV", "tsv"],
39+
"configuration": "./language-configuration.json"
3340
}
3441
],
3542
"commands": [
@@ -80,7 +87,10 @@
8087
{
8188
"viewType": "csv.editor",
8289
"displayName": "CSV",
83-
"selector": [{ "filenamePattern": "*.csv" }]
90+
"selector": [
91+
{ "filenamePattern": "*.csv" },
92+
{ "filenamePattern": "*.tsv" }
93+
]
8494
}
8595
]
8696
},

src/extension.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ class CsvEditorProvider implements vscode.CustomTextEditorProvider {
199199
*/
200200
private async updateDocument(row: number, col: number, value: string) {
201201
this.isUpdatingDocument = true;
202-
const config = vscode.workspace.getConfiguration('csv');
203-
const separator = config.get<string>('separator', ',');
202+
const separator = this.getSeparator();
204203
const oldText = this.document.getText();
205204
const lines = oldText.split(/\r?\n/);
206205
let editSucceeded = false;
@@ -261,8 +260,7 @@ class CsvEditorProvider implements vscode.CustomTextEditorProvider {
261260
*/
262261
private async insertColumn(index: number) {
263262
this.isUpdatingDocument = true;
264-
const config = vscode.workspace.getConfiguration('csv');
265-
const separator = config.get<string>('separator', ',');
263+
const separator = this.getSeparator();
266264
const text = this.document.getText();
267265
const result = Papa.parse(text, { dynamicTyping: false, delimiter: separator });
268266
const data = result.data as string[][];
@@ -286,8 +284,7 @@ class CsvEditorProvider implements vscode.CustomTextEditorProvider {
286284
*/
287285
private async deleteColumn(index: number) {
288286
this.isUpdatingDocument = true;
289-
const config = vscode.workspace.getConfiguration('csv');
290-
const separator = config.get<string>('separator', ',');
287+
const separator = this.getSeparator();
291288
const text = this.document.getText();
292289
const result = Papa.parse(text, { dynamicTyping: false, delimiter: separator });
293290
const data = result.data as string[][];
@@ -313,7 +310,7 @@ class CsvEditorProvider implements vscode.CustomTextEditorProvider {
313310
this.isUpdatingDocument = true;
314311

315312
const config = vscode.workspace.getConfiguration('csv');
316-
const separator = config.get<string>('separator', ',');
313+
const separator = this.getSeparator();
317314
const treatHeader = config.get<boolean>('treatFirstRowAsHeader', true);
318315

319316
const text = this.document.getText();
@@ -364,8 +361,7 @@ class CsvEditorProvider implements vscode.CustomTextEditorProvider {
364361
*/
365362
private async insertRow(index: number) {
366363
this.isUpdatingDocument = true;
367-
const config = vscode.workspace.getConfiguration('csv');
368-
const separator = config.get<string>('separator', ',');
364+
const separator = this.getSeparator();
369365
const text = this.document.getText();
370366
const result = Papa.parse(text, { dynamicTyping: false, delimiter: separator });
371367
const data = result.data as string[][];
@@ -389,8 +385,7 @@ class CsvEditorProvider implements vscode.CustomTextEditorProvider {
389385
*/
390386
private async deleteRow(index: number) {
391387
this.isUpdatingDocument = true;
392-
const config = vscode.workspace.getConfiguration('csv');
393-
const separator = config.get<string>('separator', ',');
388+
const separator = this.getSeparator();
394389
const text = this.document.getText();
395390
const result = Papa.parse(text, { dynamicTyping: false, delimiter: separator });
396391
const data = result.data as string[][];
@@ -415,7 +410,7 @@ class CsvEditorProvider implements vscode.CustomTextEditorProvider {
415410
const config = vscode.workspace.getConfiguration('csv');
416411
const treatHeader = config.get<boolean>('treatFirstRowAsHeader', true);
417412
const addSerialIndex = config.get<boolean>('addSerialIndex', false);
418-
const separator = config.get<string>('separator', ',');
413+
const separator = this.getSeparator();
419414
const text = this.document.getText();
420415
let result;
421416
try {
@@ -1043,6 +1038,19 @@ class CsvEditorProvider implements vscode.CustomTextEditorProvider {
10431038
return widths;
10441039
}
10451040

1041+
/**
1042+
* Determines the delimiter to use based on configuration and file extension.
1043+
* `.tsv` files default to a tab separator when the setting is untouched.
1044+
*/
1045+
private getSeparator(): string {
1046+
const config = vscode.workspace.getConfiguration('csv');
1047+
let sep = config.get<string>('separator', ',');
1048+
if (sep === ',' && this.document?.uri.fsPath.toLowerCase().endsWith('.tsv')) {
1049+
sep = '\t';
1050+
}
1051+
return sep;
1052+
}
1053+
10461054
/**
10471055
* Escapes HTML special characters in a string to prevent injection.
10481056
*/

0 commit comments

Comments
 (0)