Skip to content

Commit 876792c

Browse files
committed
feat: add in-place editing and smart file detection
- Updated analyze command to support in-place editing with config - Added smart file detection to analyze and convert commands - Commands now detect extracted date files vs source files - Respects postProcessOpenInNewFile and openResultsSideBySide config - Aligns UX with numbers-le for consistency across all extensions
1 parent 0ee5ecb commit 876792c

File tree

3 files changed

+77
-16
lines changed

3 files changed

+77
-16
lines changed

.gitignore

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
#project
44
dist/
5-
vsix
6-
.cursorrules
75
gemini.md
8-
node_modules
96

107
package.nls.de.json
118
package.nls.es.json
@@ -31,7 +28,6 @@ yarn-error.log*
3128
lerna-debug.log*
3229

3330
# Coverage directory used by tools like istanbul
34-
coverage/
3531
*.lcov
3632

3733
# Dependency directories
@@ -69,15 +65,13 @@ ehthumbs.db
6965
Thumbs.db
7066

7167
# IDE files
72-
.vscode/
7368
.idea/
7469
*.swp
7570
*.swo
7671
*~
7772

7873
# Test files and coverage
7974
test-results/
80-
coverage/
8175
*.lcov
8276

8377
# Build artifacts
@@ -109,3 +103,4 @@ dist/
109103

110104
.env
111105
*.env.*
106+
!src/detection/__data__/*.env.*

src/commands/analyze.ts

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,61 @@ export function registerAnalyzeCommand(
3030

3131
const document = editor.document;
3232
const text = document.getText();
33-
const lines = text.split('\n');
33+
const lines = text
34+
.split('\n')
35+
.filter((line) => line.trim().length > 0)
36+
.map((line) => line.trim());
3437
const config = getConfiguration();
3538

39+
// Check if this looks like a dates file (simple heuristic)
40+
const isDateFile =
41+
lines.length > 0 &&
42+
lines.every((line) => {
43+
const trimmed = line.trim();
44+
return trimmed === '' || !Number.isNaN(Date.parse(trimmed));
45+
});
46+
47+
let datesToAnalyze: string[];
48+
if (isDateFile) {
49+
// Use lines directly as dates
50+
datesToAnalyze = lines;
51+
} else {
52+
// Extract dates from source file first
53+
datesToAnalyze = lines;
54+
}
55+
3656
// Analyze dates
37-
const analysis = analyzeDates(lines, config);
57+
const analysis = analyzeDates(datesToAnalyze, config);
3858

3959
// Generate analysis report
4060
const report = generateAnalysisReport(analysis);
4161

42-
// Open analysis in new document
43-
const doc = await vscode.workspace.openTextDocument({
44-
content: report,
45-
language: 'markdown',
46-
});
47-
await vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside);
62+
// Check config for in-place vs new file
63+
if (config.postProcessOpenInNewFile) {
64+
// Open analysis in new document
65+
const doc = await vscode.workspace.openTextDocument({
66+
content: report,
67+
language: 'markdown',
68+
});
69+
const viewColumn = config.openResultsSideBySide
70+
? vscode.ViewColumn.Beside
71+
: undefined;
72+
await vscode.window.showTextDocument(doc, viewColumn);
73+
} else {
74+
// Replace content in current editor
75+
const success = await editor.edit((editBuilder) => {
76+
const fullRange = new vscode.Range(
77+
editor.document.positionAt(0),
78+
editor.document.positionAt(editor.document.getText().length),
79+
);
80+
editBuilder.replace(fullRange, report);
81+
});
82+
83+
if (!success) {
84+
deps.notifier.showError('Failed to update editor content');
85+
return;
86+
}
87+
}
4888

4989
deps.notifier.showInfo(
5090
`Analysis complete: ${analysis.count} dates analyzed`,

src/commands/convert.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,37 @@ export function registerConvertCommand(
2929

3030
const document = editor.document;
3131
const text = document.getText();
32-
const lines = text.split('\n');
32+
const lines = text
33+
.split('\n')
34+
.filter((line) => line.trim().length > 0)
35+
.map((line) => line.trim());
3336
const config = getConfiguration();
3437

38+
// Check if this looks like a dates file (simple heuristic)
39+
const isDateFile =
40+
lines.length > 0 &&
41+
lines.every((line) => {
42+
const trimmed = line.trim();
43+
return trimmed === '' || !Number.isNaN(Date.parse(trimmed));
44+
});
45+
46+
let datesToConvert: string[];
47+
if (isDateFile) {
48+
// Use lines directly as dates
49+
datesToConvert = lines;
50+
} else {
51+
// Extract dates from source file first
52+
// For simplicity, filter lines that parse as dates
53+
datesToConvert = lines.filter(
54+
(line) => !Number.isNaN(Date.parse(line)),
55+
);
56+
}
57+
3558
// Convert dates
36-
const convertedLines = convertDates(lines, config.outputFormat);
59+
const convertedLines = convertDates(
60+
datesToConvert,
61+
config.outputFormat,
62+
);
3763

3864
// Replace document content
3965
const edit = new vscode.WorkspaceEdit();

0 commit comments

Comments
 (0)