pi-lens 3.6.2 → 3.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -2
- package/package.json +4 -4
- package/tsconfig.json +1 -1
- package/clients/__tests__/file-time.test.js +0 -216
- package/clients/__tests__/file-time.test.ts +0 -276
- package/clients/__tests__/format-service.test.js +0 -245
- package/clients/__tests__/format-service.test.ts +0 -339
- package/clients/__tests__/formatters.test.js +0 -271
- package/clients/__tests__/formatters.test.ts +0 -401
- package/clients/agent-behavior-client.js +0 -110
- package/clients/agent-behavior-client.test.js +0 -94
- package/clients/agent-behavior-client.test.ts +0 -116
- package/clients/amain-types.js +0 -164
- package/clients/architect-client.js +0 -291
- package/clients/ast-grep-client.js +0 -253
- package/clients/ast-grep-parser.js +0 -84
- package/clients/ast-grep-rule-manager.js +0 -89
- package/clients/ast-grep-types.js +0 -9
- package/clients/auto-loop.js +0 -131
- package/clients/biome-client.js +0 -420
- package/clients/biome-client.test.js +0 -144
- package/clients/biome-client.test.ts +0 -163
- package/clients/cache/rule-cache.js +0 -72
- package/clients/cache-manager.js +0 -245
- package/clients/cache-manager.test.js +0 -197
- package/clients/cache-manager.test.ts +0 -299
- package/clients/complexity-client.js +0 -675
- package/clients/complexity-client.test.js +0 -234
- package/clients/complexity-client.test.ts +0 -255
- package/clients/config-validator.js +0 -465
- package/clients/dependency-checker.js +0 -325
- package/clients/dependency-checker.test.js +0 -60
- package/clients/dependency-checker.test.ts +0 -71
- package/clients/dispatch/__tests__/autofix-integration.test.js +0 -245
- package/clients/dispatch/__tests__/autofix-integration.test.ts +0 -300
- package/clients/dispatch/__tests__/runner-registration.test.js +0 -234
- package/clients/dispatch/__tests__/runner-registration.test.ts +0 -286
- package/clients/dispatch/debug.log +0 -1
- package/clients/dispatch/dispatcher.edge.test.js +0 -82
- package/clients/dispatch/dispatcher.edge.test.ts +0 -100
- package/clients/dispatch/dispatcher.format.test.js +0 -46
- package/clients/dispatch/dispatcher.format.test.ts +0 -58
- package/clients/dispatch/dispatcher.inline.test.js +0 -74
- package/clients/dispatch/dispatcher.inline.test.ts +0 -93
- package/clients/dispatch/dispatcher.js +0 -381
- package/clients/dispatch/dispatcher.test.js +0 -116
- package/clients/dispatch/dispatcher.test.ts +0 -149
- package/clients/dispatch/integration.js +0 -108
- package/clients/dispatch/plan.js +0 -183
- package/clients/dispatch/runners/architect.js +0 -83
- package/clients/dispatch/runners/architect.test.js +0 -138
- package/clients/dispatch/runners/architect.test.ts +0 -162
- package/clients/dispatch/runners/ast-grep-napi.js +0 -405
- package/clients/dispatch/runners/ast-grep-napi.test.js +0 -107
- package/clients/dispatch/runners/ast-grep-napi.test.ts +0 -129
- package/clients/dispatch/runners/ast-grep.js +0 -157
- package/clients/dispatch/runners/biome.js +0 -55
- package/clients/dispatch/runners/config-validation.js +0 -67
- package/clients/dispatch/runners/go-vet.js +0 -48
- package/clients/dispatch/runners/index.js +0 -47
- package/clients/dispatch/runners/lsp.js +0 -102
- package/clients/dispatch/runners/oxlint.js +0 -67
- package/clients/dispatch/runners/oxlint.test.js +0 -230
- package/clients/dispatch/runners/oxlint.test.ts +0 -303
- package/clients/dispatch/runners/pyright.js +0 -100
- package/clients/dispatch/runners/pyright.test.js +0 -98
- package/clients/dispatch/runners/pyright.test.ts +0 -121
- package/clients/dispatch/runners/python-slop.js +0 -97
- package/clients/dispatch/runners/python-slop.test.js +0 -203
- package/clients/dispatch/runners/python-slop.test.ts +0 -298
- package/clients/dispatch/runners/ruff.js +0 -48
- package/clients/dispatch/runners/rust-clippy.js +0 -102
- package/clients/dispatch/runners/scan_codebase.test.js +0 -89
- package/clients/dispatch/runners/scan_codebase.test.ts +0 -105
- package/clients/dispatch/runners/shellcheck.js +0 -147
- package/clients/dispatch/runners/shellcheck.test.js +0 -98
- package/clients/dispatch/runners/shellcheck.test.ts +0 -129
- package/clients/dispatch/runners/similarity.js +0 -230
- package/clients/dispatch/runners/spellcheck.js +0 -106
- package/clients/dispatch/runners/spellcheck.test.js +0 -158
- package/clients/dispatch/runners/spellcheck.test.ts +0 -214
- package/clients/dispatch/runners/tree-sitter.js +0 -246
- package/clients/dispatch/runners/ts-lsp.js +0 -125
- package/clients/dispatch/runners/ts-slop.js +0 -113
- package/clients/dispatch/runners/type-safety.js +0 -142
- package/clients/dispatch/runners/utils/diagnostic-parsers.js +0 -134
- package/clients/dispatch/runners/utils/runner-helpers.js +0 -115
- package/clients/dispatch/runners/utils.js +0 -51
- package/clients/dispatch/runners/yaml-rule-parser.js +0 -360
- package/clients/dispatch/types.js +0 -16
- package/clients/dispatch/utils/format-utils.js +0 -44
- package/clients/dogfood.test.js +0 -201
- package/clients/dogfood.test.ts +0 -269
- package/clients/file-kinds.js +0 -177
- package/clients/file-kinds.test.js +0 -169
- package/clients/file-kinds.test.ts +0 -210
- package/clients/file-time.js +0 -152
- package/clients/file-utils.js +0 -40
- package/clients/fix-scanners.js +0 -204
- package/clients/format-service.js +0 -184
- package/clients/formatters.js +0 -488
- package/clients/go-client.js +0 -203
- package/clients/go-client.test.js +0 -127
- package/clients/go-client.test.ts +0 -143
- package/clients/installer/index.js +0 -403
- package/clients/interviewer-templates.js +0 -75
- package/clients/interviewer.js +0 -173
- package/clients/jscpd-client.js +0 -196
- package/clients/jscpd-client.test.js +0 -127
- package/clients/jscpd-client.test.ts +0 -145
- package/clients/knip-client.js +0 -239
- package/clients/knip-client.test.js +0 -112
- package/clients/knip-client.test.ts +0 -128
- package/clients/latency-logger.js +0 -40
- package/clients/lsp/__tests__/client.test.js +0 -310
- package/clients/lsp/__tests__/client.test.ts +0 -412
- package/clients/lsp/__tests__/config.test.js +0 -167
- package/clients/lsp/__tests__/config.test.ts +0 -217
- package/clients/lsp/__tests__/error-recovery.test.js +0 -213
- package/clients/lsp/__tests__/error-recovery.test.ts +0 -279
- package/clients/lsp/__tests__/integration.test.js +0 -127
- package/clients/lsp/__tests__/integration.test.ts +0 -160
- package/clients/lsp/__tests__/launch.test.js +0 -313
- package/clients/lsp/__tests__/launch.test.ts +0 -394
- package/clients/lsp/__tests__/server.test.js +0 -259
- package/clients/lsp/__tests__/server.test.ts +0 -332
- package/clients/lsp/__tests__/service.test.js +0 -438
- package/clients/lsp/__tests__/service.test.ts +0 -530
- package/clients/lsp/client.js +0 -350
- package/clients/lsp/config.js +0 -112
- package/clients/lsp/index.js +0 -318
- package/clients/lsp/installer/index.js +0 -391
- package/clients/lsp/interactive-install.js +0 -221
- package/clients/lsp/language.js +0 -170
- package/clients/lsp/launch.js +0 -329
- package/clients/lsp/lsp/launch.js +0 -116
- package/clients/lsp/lsp/server.js +0 -532
- package/clients/lsp/lsp-index.js +0 -10
- package/clients/lsp/path-utils.js +0 -5
- package/clients/lsp/server.js +0 -725
- package/clients/lsp/test-py-spawn/requirements.txt +0 -1
- package/clients/lsp/test-py-spawn/test.py +0 -3
- package/clients/lsp/test-py-svc/requirements.txt +0 -1
- package/clients/lsp/test-py-svc/test.py +0 -3
- package/clients/lsp/test-python-project/requirements.txt +0 -1
- package/clients/lsp/test-python-project/test.py +0 -5
- package/clients/metrics-client.js +0 -107
- package/clients/metrics-client.test.js +0 -128
- package/clients/metrics-client.test.ts +0 -163
- package/clients/metrics-history.js +0 -367
- package/clients/path-utils.js +0 -142
- package/clients/pipeline.js +0 -272
- package/clients/production-readiness.js +0 -522
- package/clients/project-index.js +0 -255
- package/clients/project-metadata.js +0 -531
- package/clients/ruff-client.js +0 -325
- package/clients/ruff-client.test.js +0 -132
- package/clients/ruff-client.test.ts +0 -153
- package/clients/rules-scanner.js +0 -97
- package/clients/runner-tracker.js +0 -152
- package/clients/rust-client.js +0 -205
- package/clients/rust-client.test.js +0 -108
- package/clients/rust-client.test.ts +0 -130
- package/clients/safe-spawn-async.js +0 -163
- package/clients/safe-spawn.js +0 -241
- package/clients/sanitize.js +0 -291
- package/clients/sanitize.test.js +0 -177
- package/clients/sanitize.test.ts +0 -223
- package/clients/scan-architectural-debt.js +0 -167
- package/clients/scan-utils.js +0 -83
- package/clients/secrets-scanner.js +0 -119
- package/clients/secrets-scanner.test.js +0 -100
- package/clients/secrets-scanner.test.ts +0 -113
- package/clients/sg-runner.js +0 -292
- package/clients/state-matrix.js +0 -160
- package/clients/subprocess-client.js +0 -65
- package/clients/symbol-types.js +0 -5
- package/clients/test-runner-client.js +0 -523
- package/clients/test-runner-client.test.js +0 -192
- package/clients/test-runner-client.test.ts +0 -253
- package/clients/test-utils.js +0 -27
- package/clients/test-utils.ts +0 -36
- package/clients/todo-scanner.js +0 -200
- package/clients/todo-scanner.test.js +0 -301
- package/clients/todo-scanner.test.ts +0 -352
- package/clients/tool-availability.js +0 -207
- package/clients/tree-sitter-client.js +0 -601
- package/clients/tree-sitter-query-loader.js +0 -355
- package/clients/tree-sitter-symbol-extractor.js +0 -289
- package/clients/ts-service.js +0 -129
- package/clients/type-coverage-client.js +0 -127
- package/clients/type-coverage-client.test.js +0 -105
- package/clients/type-coverage-client.test.ts +0 -125
- package/clients/type-safety-client.js +0 -138
- package/clients/types.js +0 -11
- package/clients/typescript-client.codefix.test.js +0 -157
- package/clients/typescript-client.codefix.test.ts +0 -186
- package/clients/typescript-client.js +0 -509
- package/clients/typescript-client.test.js +0 -105
- package/clients/typescript-client.test.ts +0 -126
- package/commands/booboo.js +0 -1007
- package/commands/fix-from-booboo.js +0 -398
- package/commands/fix-simplified.js +0 -618
- package/commands/rate.js +0 -281
- package/commands/rate.test.js +0 -119
- package/commands/rate.test.ts +0 -131
- package/commands/refactor.js +0 -130
package/clients/formatters.js
DELETED
|
@@ -1,488 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Formatter Definitions for pi-lens
|
|
3
|
-
*
|
|
4
|
-
* Auto-detects formatters based on:
|
|
5
|
-
* - Config files (biome.json, .prettierrc, etc.)
|
|
6
|
-
* - Dependencies (package.json, requirements.txt, etc.)
|
|
7
|
-
* - Binary availability (which/where)
|
|
8
|
-
*
|
|
9
|
-
* Inspired by OpenCode's formatter.ts pattern
|
|
10
|
-
*/
|
|
11
|
-
import * as fs from "node:fs/promises";
|
|
12
|
-
import * as path from "node:path";
|
|
13
|
-
import { safeSpawn } from "./safe-spawn.js";
|
|
14
|
-
// --- Utility Functions ---
|
|
15
|
-
async function fileExists(filePath) {
|
|
16
|
-
try {
|
|
17
|
-
await fs.access(filePath);
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
async function findUp(targets, startDir, stopDir = path.parse(startDir).root) {
|
|
25
|
-
const found = [];
|
|
26
|
-
let currentDir = startDir;
|
|
27
|
-
while (currentDir !== stopDir) {
|
|
28
|
-
for (const target of targets) {
|
|
29
|
-
const checkPath = path.join(currentDir, target);
|
|
30
|
-
if (await fileExists(checkPath)) {
|
|
31
|
-
found.push(checkPath);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
const parent = path.dirname(currentDir);
|
|
35
|
-
if (parent === currentDir)
|
|
36
|
-
break;
|
|
37
|
-
currentDir = parent;
|
|
38
|
-
}
|
|
39
|
-
return found;
|
|
40
|
-
}
|
|
41
|
-
async function readJson(filePath) {
|
|
42
|
-
try {
|
|
43
|
-
const content = await fs.readFile(filePath, "utf-8");
|
|
44
|
-
return JSON.parse(content);
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return {};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async function which(command) {
|
|
51
|
-
const result = safeSpawn(process.platform === "win32" ? "where" : "which", [command], { timeout: 5000 });
|
|
52
|
-
if (result.error || result.status !== 0)
|
|
53
|
-
return null;
|
|
54
|
-
return result.stdout?.trim().split("\n")[0] ?? null;
|
|
55
|
-
}
|
|
56
|
-
// --- Formatter Definitions ---
|
|
57
|
-
export const biomeFormatter = {
|
|
58
|
-
name: "biome",
|
|
59
|
-
command: ["npx", "@biomejs/biome", "format", "--write", "$FILE"],
|
|
60
|
-
extensions: [
|
|
61
|
-
".js",
|
|
62
|
-
".jsx",
|
|
63
|
-
".mjs",
|
|
64
|
-
".cjs",
|
|
65
|
-
".ts",
|
|
66
|
-
".tsx",
|
|
67
|
-
".mts",
|
|
68
|
-
".cts",
|
|
69
|
-
".json",
|
|
70
|
-
".jsonc",
|
|
71
|
-
".css",
|
|
72
|
-
".scss",
|
|
73
|
-
".sass",
|
|
74
|
-
".vue",
|
|
75
|
-
".svelte",
|
|
76
|
-
".html",
|
|
77
|
-
".htm",
|
|
78
|
-
],
|
|
79
|
-
async detect(cwd) {
|
|
80
|
-
const configs = ["biome.json", "biome.jsonc"];
|
|
81
|
-
const found = await findUp(configs, cwd);
|
|
82
|
-
if (found.length > 0)
|
|
83
|
-
return true;
|
|
84
|
-
// Check if biome is in package.json devDependencies
|
|
85
|
-
const pkgPath = path.join(cwd, "package.json");
|
|
86
|
-
if (await fileExists(pkgPath)) {
|
|
87
|
-
const pkg = (await readJson(pkgPath));
|
|
88
|
-
if (pkg.devDependencies?.["@biomejs/biome"])
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
return false;
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
export const prettierFormatter = {
|
|
95
|
-
name: "prettier",
|
|
96
|
-
command: ["npx", "prettier", "--write", "$FILE"],
|
|
97
|
-
extensions: [
|
|
98
|
-
".js",
|
|
99
|
-
".jsx",
|
|
100
|
-
".mjs",
|
|
101
|
-
".cjs",
|
|
102
|
-
".ts",
|
|
103
|
-
".tsx",
|
|
104
|
-
".mts",
|
|
105
|
-
".cts",
|
|
106
|
-
".json",
|
|
107
|
-
".jsonc",
|
|
108
|
-
".css",
|
|
109
|
-
".scss",
|
|
110
|
-
".sass",
|
|
111
|
-
".less",
|
|
112
|
-
".vue",
|
|
113
|
-
".svelte",
|
|
114
|
-
".html",
|
|
115
|
-
".htm",
|
|
116
|
-
".md",
|
|
117
|
-
".mdx",
|
|
118
|
-
".yaml",
|
|
119
|
-
".yml",
|
|
120
|
-
".graphql",
|
|
121
|
-
".gql",
|
|
122
|
-
],
|
|
123
|
-
async detect(cwd) {
|
|
124
|
-
// Check for prettier config files
|
|
125
|
-
const configs = [
|
|
126
|
-
".prettierrc",
|
|
127
|
-
".prettierrc.json",
|
|
128
|
-
".prettierrc.yml",
|
|
129
|
-
".prettierrc.yaml",
|
|
130
|
-
".prettierrc.js",
|
|
131
|
-
".prettierrc.cjs",
|
|
132
|
-
"prettier.config.js",
|
|
133
|
-
"prettier.config.cjs",
|
|
134
|
-
];
|
|
135
|
-
const found = await findUp(configs, cwd);
|
|
136
|
-
if (found.length > 0)
|
|
137
|
-
return true;
|
|
138
|
-
// Check package.json
|
|
139
|
-
const pkgPath = path.join(cwd, "package.json");
|
|
140
|
-
if (await fileExists(pkgPath)) {
|
|
141
|
-
const pkg = (await readJson(pkgPath));
|
|
142
|
-
if (pkg.devDependencies?.prettier || pkg.dependencies?.prettier) {
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
// Also check if "prettier" field exists in package.json
|
|
146
|
-
if (pkg.prettier !== undefined)
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
return false;
|
|
150
|
-
},
|
|
151
|
-
};
|
|
152
|
-
export const ruffFormatter = {
|
|
153
|
-
name: "ruff",
|
|
154
|
-
command: ["ruff", "format", "$FILE"],
|
|
155
|
-
extensions: [".py", ".pyi"],
|
|
156
|
-
async detect(cwd) {
|
|
157
|
-
// Check for ruff config
|
|
158
|
-
const configs = ["pyproject.toml", "ruff.toml", ".ruff.toml"];
|
|
159
|
-
const found = await findUp(configs, cwd);
|
|
160
|
-
for (const configPath of found) {
|
|
161
|
-
if (configPath.endsWith("pyproject.toml")) {
|
|
162
|
-
const content = await fs.readFile(configPath, "utf-8");
|
|
163
|
-
if (content.includes("[tool.ruff]"))
|
|
164
|
-
return true;
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
return true; // ruff.toml or .ruff.toml found
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
// Check if ruff in requirements
|
|
171
|
-
const deps = ["requirements.txt", "pyproject.toml", "Pipfile"];
|
|
172
|
-
for (const dep of deps) {
|
|
173
|
-
const depPath = path.join(cwd, dep);
|
|
174
|
-
if (await fileExists(depPath)) {
|
|
175
|
-
const content = await fs.readFile(depPath, "utf-8");
|
|
176
|
-
if (content.includes("ruff"))
|
|
177
|
-
return true;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
// Only enable if the project explicitly uses ruff (config or deps).
|
|
181
|
-
// Do NOT fall back to "ruff binary is installed" — that would format
|
|
182
|
-
// projects that never asked for ruff.
|
|
183
|
-
return false;
|
|
184
|
-
},
|
|
185
|
-
};
|
|
186
|
-
export const blackFormatter = {
|
|
187
|
-
name: "black",
|
|
188
|
-
command: ["black", "$FILE"],
|
|
189
|
-
extensions: [".py", ".pyi"],
|
|
190
|
-
async detect(cwd) {
|
|
191
|
-
// Check for black config in pyproject.toml
|
|
192
|
-
const configs = ["pyproject.toml"];
|
|
193
|
-
const found = await findUp(configs, cwd);
|
|
194
|
-
for (const configPath of found) {
|
|
195
|
-
const content = await fs.readFile(configPath, "utf-8");
|
|
196
|
-
if (content.includes("[tool.black]"))
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
// Check if black in requirements
|
|
200
|
-
const deps = ["requirements.txt", "pyproject.toml", "Pipfile"];
|
|
201
|
-
for (const dep of deps) {
|
|
202
|
-
const depPath = path.join(cwd, dep);
|
|
203
|
-
if (await fileExists(depPath)) {
|
|
204
|
-
const content = await fs.readFile(depPath, "utf-8");
|
|
205
|
-
if (content.toLowerCase().includes("black"))
|
|
206
|
-
return true;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return false;
|
|
210
|
-
},
|
|
211
|
-
};
|
|
212
|
-
export const gofmtFormatter = {
|
|
213
|
-
name: "gofmt",
|
|
214
|
-
command: ["gofmt", "-w", "$FILE"],
|
|
215
|
-
extensions: [".go"],
|
|
216
|
-
async detect(_cwd) {
|
|
217
|
-
return (await which("gofmt")) !== null;
|
|
218
|
-
},
|
|
219
|
-
};
|
|
220
|
-
export const rustfmtFormatter = {
|
|
221
|
-
name: "rustfmt",
|
|
222
|
-
command: ["rustfmt", "$FILE"],
|
|
223
|
-
extensions: [".rs"],
|
|
224
|
-
async detect(_cwd) {
|
|
225
|
-
return (await which("rustfmt")) !== null;
|
|
226
|
-
},
|
|
227
|
-
};
|
|
228
|
-
export const zigFormatter = {
|
|
229
|
-
name: "zig",
|
|
230
|
-
command: ["zig", "fmt", "$FILE"],
|
|
231
|
-
extensions: [".zig", ".zon"],
|
|
232
|
-
async detect(_cwd) {
|
|
233
|
-
return (await which("zig")) !== null;
|
|
234
|
-
},
|
|
235
|
-
};
|
|
236
|
-
export const dartFormatter = {
|
|
237
|
-
name: "dart",
|
|
238
|
-
command: ["dart", "format", "$FILE"],
|
|
239
|
-
extensions: [".dart"],
|
|
240
|
-
async detect(_cwd) {
|
|
241
|
-
return (await which("dart")) !== null;
|
|
242
|
-
},
|
|
243
|
-
};
|
|
244
|
-
export const shfmtFormatter = {
|
|
245
|
-
name: "shfmt",
|
|
246
|
-
command: ["shfmt", "-w", "$FILE"],
|
|
247
|
-
extensions: [".sh", ".bash"],
|
|
248
|
-
async detect(_cwd) {
|
|
249
|
-
return (await which("shfmt")) !== null;
|
|
250
|
-
},
|
|
251
|
-
};
|
|
252
|
-
export const nixfmtFormatter = {
|
|
253
|
-
name: "nixfmt",
|
|
254
|
-
command: ["nixfmt", "$FILE"],
|
|
255
|
-
extensions: [".nix"],
|
|
256
|
-
async detect(_cwd) {
|
|
257
|
-
return (await which("nixfmt")) !== null;
|
|
258
|
-
},
|
|
259
|
-
};
|
|
260
|
-
export const mixFormatter = {
|
|
261
|
-
name: "mix",
|
|
262
|
-
command: ["mix", "format", "$FILE"],
|
|
263
|
-
extensions: [".ex", ".exs", ".eex", ".heex", ".leex"],
|
|
264
|
-
async detect(_cwd) {
|
|
265
|
-
return (await which("mix")) !== null;
|
|
266
|
-
},
|
|
267
|
-
};
|
|
268
|
-
export const ocamlformatFormatter = {
|
|
269
|
-
name: "ocamlformat",
|
|
270
|
-
command: ["ocamlformat", "-i", "$FILE"],
|
|
271
|
-
extensions: [".ml", ".mli"],
|
|
272
|
-
async detect(cwd) {
|
|
273
|
-
const hasBinary = (await which("ocamlformat")) !== null;
|
|
274
|
-
if (!hasBinary)
|
|
275
|
-
return false;
|
|
276
|
-
const configs = [".ocamlformat"];
|
|
277
|
-
const found = await findUp(configs, cwd);
|
|
278
|
-
return found.length > 0;
|
|
279
|
-
},
|
|
280
|
-
};
|
|
281
|
-
export const clangFormatFormatter = {
|
|
282
|
-
name: "clang-format",
|
|
283
|
-
command: ["clang-format", "-i", "$FILE"],
|
|
284
|
-
extensions: [".c", ".cc", ".cpp", ".cxx", ".h", ".hpp", ".ino"],
|
|
285
|
-
async detect(cwd) {
|
|
286
|
-
const hasBinary = (await which("clang-format")) !== null;
|
|
287
|
-
if (!hasBinary)
|
|
288
|
-
return false;
|
|
289
|
-
const configs = [".clang-format", "_clang-format"];
|
|
290
|
-
const found = await findUp(configs, cwd);
|
|
291
|
-
return found.length > 0;
|
|
292
|
-
},
|
|
293
|
-
};
|
|
294
|
-
export const ktlintFormatter = {
|
|
295
|
-
name: "ktlint",
|
|
296
|
-
command: ["ktlint", "-F", "$FILE"],
|
|
297
|
-
extensions: [".kt", ".kts"],
|
|
298
|
-
async detect(_cwd) {
|
|
299
|
-
return (await which("ktlint")) !== null;
|
|
300
|
-
},
|
|
301
|
-
};
|
|
302
|
-
export const rubocopFormatter = {
|
|
303
|
-
name: "rubocop",
|
|
304
|
-
command: ["rubocop", "-a", "--no-color", "$FILE"],
|
|
305
|
-
extensions: [".rb", ".rake", ".gemspec", ".ru"],
|
|
306
|
-
async detect(cwd) {
|
|
307
|
-
// Only run if project has explicit RuboCop config
|
|
308
|
-
const configs = [".rubocop.yml", ".rubocop.yaml"];
|
|
309
|
-
const found = await findUp(configs, cwd);
|
|
310
|
-
if (found.length > 0)
|
|
311
|
-
return (await which("rubocop")) !== null;
|
|
312
|
-
// Or rubocop in Gemfile
|
|
313
|
-
const gemfile = path.join(cwd, "Gemfile");
|
|
314
|
-
if (await fileExists(gemfile)) {
|
|
315
|
-
const content = await fs.readFile(gemfile, "utf-8");
|
|
316
|
-
if (content.includes("rubocop"))
|
|
317
|
-
return (await which("rubocop")) !== null;
|
|
318
|
-
}
|
|
319
|
-
return false;
|
|
320
|
-
},
|
|
321
|
-
};
|
|
322
|
-
export const standardrbFormatter = {
|
|
323
|
-
name: "standardrb",
|
|
324
|
-
command: ["standardrb", "--fix", "$FILE"],
|
|
325
|
-
extensions: [".rb", ".rake"],
|
|
326
|
-
async detect(cwd) {
|
|
327
|
-
// standardrb is only used if explicitly in Gemfile (no config file — it is the config)
|
|
328
|
-
const gemfile = path.join(cwd, "Gemfile");
|
|
329
|
-
if (await fileExists(gemfile)) {
|
|
330
|
-
const content = await fs.readFile(gemfile, "utf-8");
|
|
331
|
-
if (content.includes("standard"))
|
|
332
|
-
return (await which("standardrb")) !== null;
|
|
333
|
-
}
|
|
334
|
-
return false;
|
|
335
|
-
},
|
|
336
|
-
};
|
|
337
|
-
export const gleamFormatter = {
|
|
338
|
-
name: "gleam",
|
|
339
|
-
command: ["gleam", "format", "$FILE"],
|
|
340
|
-
extensions: [".gleam"],
|
|
341
|
-
async detect(cwd) {
|
|
342
|
-
// Present if gleam.toml exists (any Gleam project)
|
|
343
|
-
const found = await findUp(["gleam.toml"], cwd);
|
|
344
|
-
if (found.length > 0)
|
|
345
|
-
return (await which("gleam")) !== null;
|
|
346
|
-
return false;
|
|
347
|
-
},
|
|
348
|
-
};
|
|
349
|
-
export const terraformFormatter = {
|
|
350
|
-
name: "terraform",
|
|
351
|
-
command: ["terraform", "fmt", "$FILE"],
|
|
352
|
-
extensions: [".tf", ".tfvars"],
|
|
353
|
-
async detect(_cwd) {
|
|
354
|
-
return (await which("terraform")) !== null;
|
|
355
|
-
},
|
|
356
|
-
};
|
|
357
|
-
// --- Registry ---
|
|
358
|
-
const ALL_FORMATTERS = [
|
|
359
|
-
biomeFormatter,
|
|
360
|
-
prettierFormatter,
|
|
361
|
-
ruffFormatter,
|
|
362
|
-
blackFormatter,
|
|
363
|
-
gofmtFormatter,
|
|
364
|
-
rustfmtFormatter,
|
|
365
|
-
zigFormatter,
|
|
366
|
-
dartFormatter,
|
|
367
|
-
shfmtFormatter,
|
|
368
|
-
nixfmtFormatter,
|
|
369
|
-
mixFormatter,
|
|
370
|
-
ocamlformatFormatter,
|
|
371
|
-
clangFormatFormatter,
|
|
372
|
-
ktlintFormatter,
|
|
373
|
-
terraformFormatter,
|
|
374
|
-
rubocopFormatter,
|
|
375
|
-
standardrbFormatter,
|
|
376
|
-
gleamFormatter,
|
|
377
|
-
];
|
|
378
|
-
// Cache for detection results - stores array of enabled formatter names per cwd+ext
|
|
379
|
-
const detectionCache = new Map();
|
|
380
|
-
// --- Public API ---
|
|
381
|
-
export async function getFormattersForFile(filePath, cwd) {
|
|
382
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
383
|
-
const cacheKey = `${cwd}:${ext}`;
|
|
384
|
-
// Check cache
|
|
385
|
-
let cached = detectionCache.get(cwd);
|
|
386
|
-
if (!cached) {
|
|
387
|
-
cached = new Map();
|
|
388
|
-
detectionCache.set(cwd, cached);
|
|
389
|
-
}
|
|
390
|
-
if (cached.has(cacheKey)) {
|
|
391
|
-
const enabledNames = cached.get(cacheKey);
|
|
392
|
-
if (!enabledNames || enabledNames.length === 0)
|
|
393
|
-
return [];
|
|
394
|
-
// Return cached formatters by name (preserves priority order)
|
|
395
|
-
return ALL_FORMATTERS.filter((f) => enabledNames.includes(f.name));
|
|
396
|
-
}
|
|
397
|
-
// Detect formatters for this extension
|
|
398
|
-
const matching = ALL_FORMATTERS.filter((f) => f.extensions.includes(ext));
|
|
399
|
-
const enabled = [];
|
|
400
|
-
// Check for Biome first (preferred default)
|
|
401
|
-
const biomeFormatter = matching.find((f) => f.name === "biome");
|
|
402
|
-
let biomeEnabled = false;
|
|
403
|
-
if (biomeFormatter) {
|
|
404
|
-
try {
|
|
405
|
-
biomeEnabled = await biomeFormatter.detect(cwd);
|
|
406
|
-
if (biomeEnabled) {
|
|
407
|
-
enabled.push(biomeFormatter);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
catch (err) {
|
|
411
|
-
console.error(`[format] Detection failed for ${biomeFormatter.name}:`, err);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
// If Biome is enabled, skip Prettier for overlapping extensions
|
|
415
|
-
// (Biome is the preferred default, Prettier is fallback)
|
|
416
|
-
const skipPrettier = biomeEnabled;
|
|
417
|
-
for (const formatter of matching) {
|
|
418
|
-
// Skip Biome (already checked above)
|
|
419
|
-
if (formatter.name === "biome")
|
|
420
|
-
continue;
|
|
421
|
-
// Skip Prettier if Biome is enabled (prevents race condition)
|
|
422
|
-
if (skipPrettier && formatter.name === "prettier")
|
|
423
|
-
continue;
|
|
424
|
-
try {
|
|
425
|
-
const isEnabled = await formatter.detect(cwd);
|
|
426
|
-
if (isEnabled) {
|
|
427
|
-
enabled.push(formatter);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
catch (err) {
|
|
431
|
-
// Detection failed, skip this formatter
|
|
432
|
-
console.error(`[format] Detection failed for ${formatter.name}:`, err);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
// Store the list of enabled formatter names in cache
|
|
436
|
-
const enabledNames = enabled.map((f) => f.name);
|
|
437
|
-
cached.set(cacheKey, enabledNames);
|
|
438
|
-
return enabled;
|
|
439
|
-
}
|
|
440
|
-
export function clearFormatterCache() {
|
|
441
|
-
detectionCache.clear();
|
|
442
|
-
}
|
|
443
|
-
export async function formatFile(filePath, formatter) {
|
|
444
|
-
try {
|
|
445
|
-
const absolutePath = path.resolve(filePath);
|
|
446
|
-
const cwd = path.dirname(absolutePath);
|
|
447
|
-
const contentBefore = await fs.readFile(absolutePath, "utf-8");
|
|
448
|
-
// Replace $FILE placeholder
|
|
449
|
-
let cmd = formatter.command.map((c) => c.replace("$FILE", absolutePath));
|
|
450
|
-
// OPTIMIZATION: Use local biome binary instead of npx if available
|
|
451
|
-
if (formatter.name === "biome" && cmd[0] === "npx") {
|
|
452
|
-
const localBiome = path.join(cwd, "node_modules", ".bin", "biome");
|
|
453
|
-
const localBiomeWin = path.join(cwd, "node_modules", ".bin", "biome.cmd");
|
|
454
|
-
if (await fileExists(localBiome)) {
|
|
455
|
-
cmd = [localBiome, ...cmd.slice(2)]; // Replace "npx" "@biomejs/biome" with local path
|
|
456
|
-
}
|
|
457
|
-
else if (await fileExists(localBiomeWin)) {
|
|
458
|
-
cmd = [localBiomeWin, ...cmd.slice(2)];
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
// Run formatter
|
|
462
|
-
const result = safeSpawn(cmd[0], cmd.slice(1), { timeout: 15000, cwd });
|
|
463
|
-
if (result.error) {
|
|
464
|
-
return {
|
|
465
|
-
success: false,
|
|
466
|
-
changed: false,
|
|
467
|
-
error: result.error.message,
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
// Check if content changed
|
|
471
|
-
const contentAfter = await fs.readFile(absolutePath, "utf-8");
|
|
472
|
-
const changed = contentBefore !== contentAfter;
|
|
473
|
-
return {
|
|
474
|
-
success: true,
|
|
475
|
-
changed,
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
catch (err) {
|
|
479
|
-
return {
|
|
480
|
-
success: false,
|
|
481
|
-
changed: false,
|
|
482
|
-
error: err instanceof Error ? err.message : String(err),
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
export function listAllFormatters() {
|
|
487
|
-
return ALL_FORMATTERS.map((f) => f.name);
|
|
488
|
-
}
|
package/clients/go-client.js
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Go Client for pi-lens
|
|
3
|
-
*
|
|
4
|
-
* Provides Go type checking and linting via gopls and go vet.
|
|
5
|
-
*
|
|
6
|
-
* Requires: gopls (go install golang.org/x/tools/gopls@latest)
|
|
7
|
-
* Docs: https://pkg.go.dev/golang.org/x/tools/gopls
|
|
8
|
-
*/
|
|
9
|
-
import * as fs from "node:fs";
|
|
10
|
-
import * as path from "node:path";
|
|
11
|
-
import { safeSpawn } from "./safe-spawn.js";
|
|
12
|
-
// --- Common install paths ---
|
|
13
|
-
const GO_WINDOWS_PATHS = [
|
|
14
|
-
"C:\\Program Files\\Go\\bin\\go.exe",
|
|
15
|
-
"C:\\Go\\bin\\go.exe",
|
|
16
|
-
"go.exe", // PATH
|
|
17
|
-
];
|
|
18
|
-
const GO_UNIX_PATHS = [
|
|
19
|
-
"/usr/local/go/bin/go",
|
|
20
|
-
"/usr/bin/go",
|
|
21
|
-
"go", // PATH
|
|
22
|
-
];
|
|
23
|
-
// --- Client ---
|
|
24
|
-
export class GoClient {
|
|
25
|
-
constructor(verbose = false) {
|
|
26
|
-
this.goplsAvailable = null;
|
|
27
|
-
this.goAvailable = null;
|
|
28
|
-
this.goPath = null;
|
|
29
|
-
this.log = verbose
|
|
30
|
-
? (msg) => console.error(`[go] ${msg}`)
|
|
31
|
-
: () => { };
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Find go executable path
|
|
35
|
-
*/
|
|
36
|
-
findGoPath() {
|
|
37
|
-
if (this.goPath)
|
|
38
|
-
return this.goPath;
|
|
39
|
-
const paths = process.platform === "win32" ? GO_WINDOWS_PATHS : GO_UNIX_PATHS;
|
|
40
|
-
for (const p of paths) {
|
|
41
|
-
try {
|
|
42
|
-
if (p.includes("\\") || p.includes("/")) {
|
|
43
|
-
// Absolute path - check if exists
|
|
44
|
-
if (fs.existsSync(p)) {
|
|
45
|
-
this.goPath = p;
|
|
46
|
-
return p;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
// Relative (PATH) - try running it
|
|
51
|
-
const result = safeSpawn(p, ["version"], {
|
|
52
|
-
timeout: 3000,
|
|
53
|
-
});
|
|
54
|
-
if (!result.error && result.status === 0) {
|
|
55
|
-
this.goPath = p;
|
|
56
|
-
return p;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
catch (err) {
|
|
61
|
-
void err;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Check if Go is installed
|
|
68
|
-
*/
|
|
69
|
-
isGoAvailable() {
|
|
70
|
-
if (this.goAvailable !== null)
|
|
71
|
-
return this.goAvailable;
|
|
72
|
-
this.goAvailable = this.findGoPath() !== null;
|
|
73
|
-
if (this.goAvailable) {
|
|
74
|
-
this.log(`Go found: ${this.goPath}`);
|
|
75
|
-
}
|
|
76
|
-
return this.goAvailable;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Check if gopls is installed
|
|
80
|
-
*/
|
|
81
|
-
isGoplsAvailable() {
|
|
82
|
-
if (this.goplsAvailable !== null)
|
|
83
|
-
return this.goplsAvailable;
|
|
84
|
-
const result = safeSpawn("gopls", ["version"], {
|
|
85
|
-
timeout: 5000,
|
|
86
|
-
});
|
|
87
|
-
this.goplsAvailable = !result.error && result.status === 0;
|
|
88
|
-
if (this.goplsAvailable) {
|
|
89
|
-
this.log(`gopls found: ${result.stdout?.trim()}`);
|
|
90
|
-
}
|
|
91
|
-
return this.goplsAvailable;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Check if a file is a Go file
|
|
95
|
-
*/
|
|
96
|
-
isGoFile(filePath) {
|
|
97
|
-
return path.extname(filePath).toLowerCase() === ".go";
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Run go vet on a file and return diagnostics
|
|
101
|
-
*/
|
|
102
|
-
checkFile(filePath) {
|
|
103
|
-
const goExe = this.findGoPath();
|
|
104
|
-
if (!goExe)
|
|
105
|
-
return [];
|
|
106
|
-
const absolutePath = path.resolve(filePath);
|
|
107
|
-
if (!fs.existsSync(absolutePath))
|
|
108
|
-
return [];
|
|
109
|
-
const dir = path.dirname(absolutePath);
|
|
110
|
-
const fileName = path.basename(absolutePath);
|
|
111
|
-
try {
|
|
112
|
-
// Run go vet on the specific file
|
|
113
|
-
const result = safeSpawn(goExe, ["vet", fileName], {
|
|
114
|
-
timeout: 15000,
|
|
115
|
-
cwd: dir,
|
|
116
|
-
});
|
|
117
|
-
const output = (result.stderr || "") + (result.stdout || "");
|
|
118
|
-
return this.parseOutput(output, absolutePath);
|
|
119
|
-
}
|
|
120
|
-
catch (err) {
|
|
121
|
-
this.log(`Check error: ${err.message}`);
|
|
122
|
-
return [];
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Run go build to check for compilation errors
|
|
127
|
-
*/
|
|
128
|
-
buildCheck(cwd) {
|
|
129
|
-
if (!this.isGoAvailable())
|
|
130
|
-
return [];
|
|
131
|
-
try {
|
|
132
|
-
const result = safeSpawn("go", ["build", "./..."], {
|
|
133
|
-
timeout: 30000,
|
|
134
|
-
cwd,
|
|
135
|
-
});
|
|
136
|
-
const output = (result.stderr || "") + (result.stdout || "");
|
|
137
|
-
return this.parseOutput(output, cwd);
|
|
138
|
-
}
|
|
139
|
-
catch (err) {
|
|
140
|
-
this.log(`Build check error: ${err.message}`);
|
|
141
|
-
return [];
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Format diagnostics for LLM consumption
|
|
146
|
-
*/
|
|
147
|
-
formatDiagnostics(diags, maxItems = 10) {
|
|
148
|
-
if (diags.length === 0)
|
|
149
|
-
return "";
|
|
150
|
-
const errors = diags.filter((d) => d.severity === "error");
|
|
151
|
-
const warnings = diags.filter((d) => d.severity === "warning");
|
|
152
|
-
let output = `[Go] ${diags.length} issue(s)`;
|
|
153
|
-
if (errors.length)
|
|
154
|
-
output += ` — ${errors.length} error(s)`;
|
|
155
|
-
if (warnings.length)
|
|
156
|
-
output += ` — ${warnings.length} warning(s)`;
|
|
157
|
-
output += ":\n";
|
|
158
|
-
for (const d of diags.slice(0, maxItems)) {
|
|
159
|
-
const loc = `L${d.line}:${d.column}`;
|
|
160
|
-
const rule = d.rule ? ` [${d.rule}]` : "";
|
|
161
|
-
output += ` [${d.severity}] ${loc} ${d.message}${rule}\n`;
|
|
162
|
-
}
|
|
163
|
-
if (diags.length > maxItems) {
|
|
164
|
-
output += ` ... and ${diags.length - maxItems} more\n`;
|
|
165
|
-
}
|
|
166
|
-
return output;
|
|
167
|
-
}
|
|
168
|
-
// --- Internal ---
|
|
169
|
-
parseOutput(output, fileOrDir) {
|
|
170
|
-
if (!output.trim())
|
|
171
|
-
return [];
|
|
172
|
-
const diags = [];
|
|
173
|
-
// Go vet/build output format: "file.go:line:col: message"
|
|
174
|
-
const pattern = /^(.+?):(\d+):(?:(\d+):)?\s*(?:([^:]+):\s*)?(.+)$/gm;
|
|
175
|
-
let match;
|
|
176
|
-
while ((match = pattern.exec(output)) !== null) {
|
|
177
|
-
const [, file, line, col, rule, message] = match;
|
|
178
|
-
const lineNum = parseInt(line, 10);
|
|
179
|
-
const colNum = col ? parseInt(col, 10) : 1;
|
|
180
|
-
// Filter to the specific file if a file path was provided
|
|
181
|
-
const absFile = path.isAbsolute(file)
|
|
182
|
-
? file
|
|
183
|
-
: path.resolve(path.dirname(fileOrDir), file);
|
|
184
|
-
if (path.extname(absFile) !== ".go")
|
|
185
|
-
continue;
|
|
186
|
-
const isError = message.includes("undefined") ||
|
|
187
|
-
message.includes("cannot") ||
|
|
188
|
-
message.includes("syntax error") ||
|
|
189
|
-
rule === "compile";
|
|
190
|
-
diags.push({
|
|
191
|
-
line: lineNum,
|
|
192
|
-
column: colNum - 1,
|
|
193
|
-
endLine: lineNum,
|
|
194
|
-
endColumn: colNum,
|
|
195
|
-
severity: isError ? "error" : "warning",
|
|
196
|
-
message: message.trim().slice(0, 300),
|
|
197
|
-
rule: rule?.trim(),
|
|
198
|
-
file: absFile,
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
return diags;
|
|
202
|
-
}
|
|
203
|
-
}
|