loadwise 0.6.2 → 0.7.0
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/README.md +152 -100
- package/dist/bin/loadwise.js +126 -49
- package/dist/lib/accessibility/frontend-detect.js +6 -5
- package/dist/lib/accessibility/usage.js +10 -2
- package/dist/lib/editor/configured-setup.js +61 -0
- package/dist/lib/editor/editor-launcher.js +165 -0
- package/dist/lib/editor/fix-edits.js +19 -0
- package/dist/lib/editor/jetbrains-setup.js +53 -0
- package/dist/lib/editor/language-server.js +31 -14
- package/dist/lib/editor/managed-config.js +37 -0
- package/dist/lib/editor/native-setup.js +85 -0
- package/dist/lib/editor/release-vsix.js +61 -0
- package/dist/lib/editor/server-commands.js +2 -0
- package/dist/lib/editor/setup-server.js +87 -0
- package/dist/lib/editor/setup-vim.js +61 -0
- package/dist/lib/editor/setup.js +131 -0
- package/dist/lib/editor/stdio-setup.js +6 -0
- package/dist/lib/maintainability/cli/inputs.js +3 -2
- package/dist/lib/maintainability/cli.js +14 -5
- package/dist/lib/maintainability/examples.js +4 -0
- package/dist/lib/maintainability/rule-ids.js +3 -0
- package/dist/lib/maintainability/site-fixes/unused-bindings.js +138 -3
- package/dist/lib/maintainability/unused/unused-bindings.js +39 -4
- package/dist/lib/performance/cli/changed-lines.js +8 -1
- package/dist/lib/performance/cli/cli-arguments.js +19 -8
- package/dist/lib/performance/cli/cli-output.js +3 -0
- package/dist/lib/performance/cli.js +8 -4
- package/dist/lib/performance/datastores/pg-integrity.js +7 -0
- package/dist/lib/performance/datastores/pooling.js +6 -1
- package/dist/lib/performance/engine/native-syntax.js +3 -0
- package/dist/lib/performance/frontend/frontend-perf.js +80 -20
- package/dist/lib/performance/request/bulk-listener-registration.js +111 -0
- package/dist/lib/performance/request/fastify-receivers.js +93 -0
- package/dist/lib/performance/request/fresh-loop-socket.js +103 -0
- package/dist/lib/performance/request/mongoose-lean.js +140 -53
- package/dist/lib/performance/request/node-event-listener-leak.js +99 -5
- package/dist/lib/performance/request/phase5-ast.js +6 -7
- package/dist/lib/performance/request/phase5-rules.js +133 -13
- package/dist/lib/performance/request/request-handlers.js +120 -23
- package/dist/lib/performance/site-fixes/collection-existence.js +2 -1
- package/dist/lib/performance/site-fixes/collections.js +1 -2
- package/dist/lib/performance/site-fixes/frontend-fixes.js +10 -6
- package/dist/lib/performance/site-fixes/helpers.js +3 -4
- package/dist/lib/performance/site-fixes/integrity.js +2 -4
- package/dist/lib/reliability/react-bugs.js +11 -3
- package/dist/lib/reliability/usage.js +16 -5
- package/dist/lib/security/cli.js +15 -4
- package/dist/lib/shared/agent/agent-init.js +26 -4
- package/dist/lib/shared/agent/agent-prompt.js +74 -0
- package/dist/lib/shared/agent/agent-session.js +6 -1
- package/dist/lib/shared/agent/agent-verify.js +54 -10
- package/dist/lib/shared/agent/review-delivery.js +1 -1
- package/dist/lib/shared/analysis/scan-cache.js +3 -2
- package/dist/lib/shared/check.js +172 -20
- package/dist/lib/shared/fix/fix-convergence.js +15 -29
- package/dist/lib/shared/fix/fix-handoff.js +16 -11
- package/dist/lib/shared/fix/fix-imports.js +47 -38
- package/dist/lib/shared/fix/fix-presentation-prettier.js +1 -46
- package/dist/lib/shared/fix/fix-presentation-rows.js +45 -1
- package/dist/lib/shared/fix/fix-presentation.js +4 -3
- package/dist/lib/shared/fix/fix-safety.js +26 -1
- package/dist/lib/shared/fix/fix-scope.js +82 -0
- package/dist/lib/shared/fix/fix-terminal.js +28 -1
- package/dist/lib/shared/fix/project-file-access.js +17 -26
- package/dist/lib/shared/fix/read-fix-text.js +20 -0
- package/dist/lib/shared/fix.js +215 -102
- package/dist/lib/shared/report-fp.js +93 -0
- package/dist/lib/shared/reporting/automatic-fix-signal.js +10 -0
- package/dist/lib/shared/reporting/check-text.js +50 -0
- package/dist/lib/shared/reporting/pillars.js +45 -16
- package/dist/lib/shared/reporting/source-report.js +2 -0
- package/dist/lib/shared/system/atomic-write.js +5 -2
- package/dist/lib/shared/system/sentry.js +203 -0
- package/dist/lib/shared/system/shell-argument.js +5 -1
- package/dist/lib/shared/system/terminal-safe.js +3 -2
- package/dist/lib/shared/system/terminal-style.js +131 -0
- package/docs/assets/cli-workflow.gif +0 -0
- package/integrations/sublime/plugin.py +22 -0
- package/integrations/zed/Cargo.lock +845 -0
- package/integrations/zed/Cargo.toml +11 -0
- package/integrations/zed/extension.toml +11 -0
- package/integrations/zed/src/lib.rs +25 -0
- package/package.json +11 -3
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/commands/loadwise.md +11 -6
- package/schema/loadwise.config.schema.json +2 -0
|
@@ -90,6 +90,7 @@ function startServer(connection) {
|
|
|
90
90
|
const documents = new TextDocuments(TextDocument);
|
|
91
91
|
const openUris = new Map();
|
|
92
92
|
const savedVersions = new Map();
|
|
93
|
+
const pendingDiskChecks = new Map();
|
|
93
94
|
const folders = new Map();
|
|
94
95
|
// The latest workspace/configuration request per folder; an older answer arriving later is dropped.
|
|
95
96
|
const settingsRequests = new Map();
|
|
@@ -109,7 +110,15 @@ function startServer(connection) {
|
|
|
109
110
|
const open = uri === undefined ? undefined : documents.get(uri);
|
|
110
111
|
if (!open)
|
|
111
112
|
return readDiskDocument(filename);
|
|
112
|
-
|
|
113
|
+
const text = open.getText();
|
|
114
|
+
const initialVersion = pendingDiskChecks.get(key);
|
|
115
|
+
if (initialVersion !== undefined) {
|
|
116
|
+
pendingDiskChecks.delete(key);
|
|
117
|
+
if (initialVersion === open.version && readDiskDocument(filename)?.getText() === text) {
|
|
118
|
+
savedVersions.set(key, initialVersion);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return createEditorDocument(filename, text, {
|
|
113
122
|
languageId: open.languageId,
|
|
114
123
|
version: open.version,
|
|
115
124
|
isDirty: savedVersions.get(key) !== open.version,
|
|
@@ -320,25 +329,26 @@ function startServer(connection) {
|
|
|
320
329
|
return filename === undefined ? [] : [{ filename, type }];
|
|
321
330
|
});
|
|
322
331
|
}
|
|
323
|
-
//
|
|
324
|
-
//
|
|
332
|
+
// Editors can restore unsaved buffers. Check the unchanged initial version against disk when a
|
|
333
|
+
// finding needs it, so opening an unrelated document does not read it again.
|
|
325
334
|
function documentOpened(document) {
|
|
326
335
|
const filename = filenameOf(document.uri);
|
|
327
336
|
if (filename === undefined)
|
|
328
337
|
return;
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
savedVersions.delete(fileKey(filename));
|
|
338
|
+
const key = fileKey(filename);
|
|
339
|
+
openUris.set(key, document.uri);
|
|
340
|
+
pendingDiskChecks.set(key, document.version);
|
|
341
|
+
savedVersions.delete(key);
|
|
334
342
|
foldersFor(filename).forEach(republish);
|
|
335
343
|
}
|
|
336
344
|
function documentClosed(uri) {
|
|
337
345
|
const filename = filenameOf(uri);
|
|
338
346
|
if (filename === undefined)
|
|
339
347
|
return;
|
|
340
|
-
|
|
341
|
-
|
|
348
|
+
const key = fileKey(filename);
|
|
349
|
+
openUris.delete(key);
|
|
350
|
+
pendingDiskChecks.delete(key);
|
|
351
|
+
savedVersions.delete(key);
|
|
342
352
|
foldersFor(filename).forEach(republish);
|
|
343
353
|
}
|
|
344
354
|
const context = {
|
|
@@ -353,8 +363,10 @@ function startServer(connection) {
|
|
|
353
363
|
connection.onInitialize((params) => {
|
|
354
364
|
capabilities = params.capabilities;
|
|
355
365
|
initialSettings = settingsFrom(params.initializationOptions);
|
|
356
|
-
const
|
|
357
|
-
const
|
|
366
|
+
const legacyRoot = params.rootPath && path.isAbsolute(params.rootPath) ? params.rootPath : undefined;
|
|
367
|
+
const rootUri = params.rootUri ?? (legacyRoot && pathToFileURL(legacyRoot).href);
|
|
368
|
+
const rootFilename = rootUri ? filenameOf(rootUri) : undefined;
|
|
369
|
+
const rootFolder = rootUri && rootFilename ? [{ uri: rootUri, name: path.basename(rootFilename) }] : [];
|
|
358
370
|
const initialFolders = params.workspaceFolders ?? rootFolder;
|
|
359
371
|
connection.onInitialized(async () => {
|
|
360
372
|
// A client that advertises dynamic registration can still refuse it; the folders are scanned either way.
|
|
@@ -387,7 +399,9 @@ function startServer(connection) {
|
|
|
387
399
|
const filename = filenameOf(document.uri);
|
|
388
400
|
if (filename === undefined)
|
|
389
401
|
return;
|
|
390
|
-
|
|
402
|
+
const key = fileKey(filename);
|
|
403
|
+
pendingDiskChecks.delete(key);
|
|
404
|
+
savedVersions.set(key, document.version);
|
|
391
405
|
filesChanged([{ filename, type: FileChangeType.Changed }]);
|
|
392
406
|
});
|
|
393
407
|
connection.onDidChangeWatchedFiles(({ changes }) => filesChanged(watchedFileEvents(changes)));
|
|
@@ -406,11 +420,14 @@ function startServer(connection) {
|
|
|
406
420
|
}
|
|
407
421
|
});
|
|
408
422
|
connection.onHover(({ textDocument, position }) => {
|
|
423
|
+
const findings = entriesFor(textDocument.uri);
|
|
424
|
+
if (!findings.length)
|
|
425
|
+
return null;
|
|
409
426
|
const filename = filenameOf(textDocument.uri);
|
|
410
427
|
const document = filename === undefined ? undefined : documentFor(filename);
|
|
411
428
|
if (!document)
|
|
412
429
|
return null;
|
|
413
|
-
const hover = hoverFor(document,
|
|
430
|
+
const hover = hoverFor(document, findings, position);
|
|
414
431
|
return hover ? { contents: { kind: 'markdown', value: hover.markdown }, range: hover.range } : null;
|
|
415
432
|
});
|
|
416
433
|
connection.onCodeAction(({ textDocument, range, context: actionContext }) => codeActions(entriesFor(textDocument.uri), range, actionContext.only, textDocument.uri, fixWorkspace()));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { writeResolvedFileAtomic } from '../shared/system/atomic-write.js';
|
|
5
|
+
import { errorCode } from '../shared/system/error-code.js';
|
|
6
|
+
function digest(content) {
|
|
7
|
+
return createHash('sha256').update(content).digest('hex');
|
|
8
|
+
}
|
|
9
|
+
// The checksum lets setup upgrade its own configuration after the server moves, while
|
|
10
|
+
// preserving custom edits even when the user kept the original generated header.
|
|
11
|
+
export function writeManagedConfig(file, comment, content) {
|
|
12
|
+
const header = comment + ' Generated by Loadwise editor setup.';
|
|
13
|
+
const signature = header + ' sha256=';
|
|
14
|
+
const generated = signature + digest(content) + '\n' + content;
|
|
15
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
16
|
+
try {
|
|
17
|
+
fs.writeFileSync(file, generated, { flag: 'wx' });
|
|
18
|
+
return 'created';
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (errorCode(error) !== 'EEXIST')
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
const existing = fs.lstatSync(file);
|
|
25
|
+
if (!existing.isFile() || existing.nlink !== 1)
|
|
26
|
+
return 'conflict';
|
|
27
|
+
const previous = fs.readFileSync(file, 'utf8');
|
|
28
|
+
if (previous === generated)
|
|
29
|
+
return 'unchanged';
|
|
30
|
+
const newline = previous.indexOf('\n');
|
|
31
|
+
const verified = newline >= 0 && previous.slice(0, newline) === signature + digest(previous.slice(newline + 1));
|
|
32
|
+
// Early Vim setup wrote an unsigned header. Migrate only an exact copy of the generated plugin.
|
|
33
|
+
if (!verified && previous !== header + '\n' + content)
|
|
34
|
+
return 'conflict';
|
|
35
|
+
writeResolvedFileAtomic(file, generated);
|
|
36
|
+
return 'updated';
|
|
37
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { writeManagedConfig } from './managed-config.js';
|
|
4
|
+
function configDirectory(editor) {
|
|
5
|
+
const windows = process.platform === 'win32';
|
|
6
|
+
if (editor === 'nvim') {
|
|
7
|
+
const base = process.env.XDG_CONFIG_HOME || (windows ? process.env.LOCALAPPDATA : undefined);
|
|
8
|
+
return path.join(base || path.join(os.homedir(), windows ? 'AppData/Local' : '.config'), process.env.NVIM_APPNAME || 'nvim');
|
|
9
|
+
}
|
|
10
|
+
const base = windows ? process.env.APPDATA : process.env.XDG_CONFIG_HOME;
|
|
11
|
+
return path.join(base || path.join(os.homedir(), windows ? 'AppData/Roaming' : '.config'), editor === 'helix' ? 'helix' : 'loadwise');
|
|
12
|
+
}
|
|
13
|
+
function luaString(value) {
|
|
14
|
+
// Lua accepts three-digit decimal byte escapes on every supported runtime.
|
|
15
|
+
const escaped = value.replaceAll(/["\\\p{Cc}]/gu, (character) => Array.from(Buffer.from(character), (byte) => '\\' + String(byte).padStart(3, '0')).join(''));
|
|
16
|
+
return '"' + escaped + '"';
|
|
17
|
+
}
|
|
18
|
+
function nvimSetup(server) {
|
|
19
|
+
const content = `if vim.fn.has('nvim-0.11') == 0 then return end
|
|
20
|
+
if not vim.lsp.config.loadwise then
|
|
21
|
+
vim.lsp.config('loadwise', {
|
|
22
|
+
cmd = { ${[server.command, ...server.args].map(luaString).join(', ')} },
|
|
23
|
+
filetypes = { 'javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'html', 'vue', 'svelte', 'python', 'go', 'java', 'cs', 'rust' },
|
|
24
|
+
root_markers = { 'loadwise.config.json', 'tsconfig.json', 'jsconfig.json', 'package.json', '.git' },
|
|
25
|
+
})
|
|
26
|
+
end
|
|
27
|
+
vim.lsp.enable('loadwise')
|
|
28
|
+
`;
|
|
29
|
+
return {
|
|
30
|
+
file: path.join(configDirectory('nvim'), 'plugin', 'loadwise.lua'),
|
|
31
|
+
comment: '--',
|
|
32
|
+
content,
|
|
33
|
+
next: 'Restart Neovim 0.11+ in your project and open a source file. Check :checkhealth vim.lsp.',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function helixSetup(server) {
|
|
37
|
+
const serverTable = `[language-server.loadwise]
|
|
38
|
+
command = ${JSON.stringify(server.command)}
|
|
39
|
+
args = ${JSON.stringify(server.args)}`;
|
|
40
|
+
const languages = ['javascript', 'jsx', 'typescript', 'tsx'].map((name) => `[[language]]\nname = "${name}"\nlanguage-servers = ["typescript-language-server", "loadwise"]`);
|
|
41
|
+
return {
|
|
42
|
+
file: path.join(configDirectory('helix'), 'languages.toml'),
|
|
43
|
+
comment: '#',
|
|
44
|
+
content: [serverTable, ...languages, ''].join('\n\n'),
|
|
45
|
+
next: 'Restart Helix 23.10+ and open a JavaScript or TypeScript file. Check hx --health typescript.',
|
|
46
|
+
merge: 'Add the server table once and append "loadwise" to the enabled server lists for your languages. Keep each existing language table and its other servers.',
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function emacsSetup(server) {
|
|
50
|
+
const file = path.join(configDirectory('emacs'), 'loadwise-eglot.el');
|
|
51
|
+
const content = `(require 'eglot)
|
|
52
|
+
|
|
53
|
+
(defun loadwise-eglot ()
|
|
54
|
+
"Start Loadwise with Eglot in this buffer's project."
|
|
55
|
+
(interactive)
|
|
56
|
+
(when (eglot-current-server)
|
|
57
|
+
(user-error "This buffer already has an Eglot server. Use M-x eglot-shutdown to switch"))
|
|
58
|
+
(let ((eglot-server-programs
|
|
59
|
+
(cons (cons major-mode '(${[server.command, ...server.args].map((value) => JSON.stringify(value)).join(' ')}))
|
|
60
|
+
eglot-server-programs)))
|
|
61
|
+
(call-interactively #'eglot)))
|
|
62
|
+
|
|
63
|
+
(provide 'loadwise-eglot)
|
|
64
|
+
`;
|
|
65
|
+
return {
|
|
66
|
+
file,
|
|
67
|
+
comment: ';;',
|
|
68
|
+
content,
|
|
69
|
+
next: `Add (load ${JSON.stringify(file)}) to your Emacs init file. Open a project file and run M-x loadwise-eglot with Eglot (bundled in Emacs 29+). Eglot uses one server per buffer. To switch an active buffer, use M-x eglot-shutdown first.`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export function setupNativeEditor(editor, server) {
|
|
73
|
+
const setup = editor === 'nvim' ? nvimSetup(server) : editor === 'helix' ? helixSetup(server) : emacsSetup(server);
|
|
74
|
+
const { file, comment, content, next } = setup;
|
|
75
|
+
const status = writeManagedConfig(file, comment, content);
|
|
76
|
+
if (status === 'unchanged')
|
|
77
|
+
return `Already configured in ${file}.\n${next}`;
|
|
78
|
+
if (status === 'updated')
|
|
79
|
+
return `Updated ${file}.\n${next}`;
|
|
80
|
+
if (status === 'conflict') {
|
|
81
|
+
const merge = 'merge' in setup ? setup.merge : 'Merge the following configuration manually.';
|
|
82
|
+
return `Existing configuration at ${file} requires a manual merge. ${merge}\n\n${content}\n${next}`;
|
|
83
|
+
}
|
|
84
|
+
return `Configured ${file}.\n${next}`;
|
|
85
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { open } from 'node:fs/promises';
|
|
3
|
+
import { isRecord } from '../shared/system/is-record.js';
|
|
4
|
+
const repository = 'IbrahimHafez1/loadwise';
|
|
5
|
+
const metadataTimeoutMs = 30_000;
|
|
6
|
+
const downloadTimeoutMs = 300_000;
|
|
7
|
+
export function currentTarget(architecture = process.arch) {
|
|
8
|
+
if (!['win32', 'darwin', 'linux'].includes(process.platform) || !['x64', 'arm64'].includes(architecture))
|
|
9
|
+
throw new Error(`No official Loadwise editor package for ${process.platform}-${architecture}.`);
|
|
10
|
+
if (process.platform === 'linux') {
|
|
11
|
+
const report = process.report.getReport();
|
|
12
|
+
if (!(isRecord(report) && isRecord(report.header) && report.header.glibcVersionRuntime))
|
|
13
|
+
throw new Error('The official Linux editor package requires glibc.');
|
|
14
|
+
}
|
|
15
|
+
return `${process.platform}-${architecture}`;
|
|
16
|
+
}
|
|
17
|
+
export function vsixFilename(version, target = currentTarget()) {
|
|
18
|
+
return `loadwise-${version}-${target}.vsix`;
|
|
19
|
+
}
|
|
20
|
+
export async function downloadVsix(destination, version, target, request = fetch) {
|
|
21
|
+
const tag = 'v' + version;
|
|
22
|
+
const filename = vsixFilename(version, target);
|
|
23
|
+
const release = await request(`https://api.github.com/repos/${repository}/releases/tags/${encodeURIComponent(tag)}`, {
|
|
24
|
+
headers: { Accept: 'application/vnd.github+json' },
|
|
25
|
+
signal: AbortSignal.timeout(metadataTimeoutMs),
|
|
26
|
+
});
|
|
27
|
+
if (!release.ok)
|
|
28
|
+
throw new Error(`Cannot read Loadwise release ${tag} (GitHub HTTP ${release.status}). Use --vsix <file> with a local build or release asset.`);
|
|
29
|
+
const metadata = await release.json();
|
|
30
|
+
const asset = isRecord(metadata) && metadata.tag_name === tag && Array.isArray(metadata.assets)
|
|
31
|
+
? metadata.assets.find((item) => isRecord(item) && item.name === filename)
|
|
32
|
+
: undefined;
|
|
33
|
+
if (!isRecord(asset))
|
|
34
|
+
throw new Error(`Release ${tag} has no ${filename}. Use --vsix <file> with a matching local build.`);
|
|
35
|
+
if (typeof asset.digest !== 'string' ||
|
|
36
|
+
!/^sha256:[a-f0-9]{64}$/i.test(asset.digest) ||
|
|
37
|
+
typeof asset.size !== 'number' ||
|
|
38
|
+
!Number.isSafeInteger(asset.size) ||
|
|
39
|
+
asset.size <= 0)
|
|
40
|
+
throw new Error(`GitHub did not provide a valid SHA-256 digest and size for ${filename}.`);
|
|
41
|
+
const download = await request(`https://github.com/${repository}/releases/download/${encodeURIComponent(tag)}/${encodeURIComponent(filename)}`, { signal: AbortSignal.timeout(downloadTimeoutMs) });
|
|
42
|
+
if (!download.ok || !download.body)
|
|
43
|
+
throw new Error(`Cannot download ${filename} (GitHub HTTP ${download.status}).`);
|
|
44
|
+
const hash = createHash('sha256');
|
|
45
|
+
const file = await open(destination, 'wx', 0o600);
|
|
46
|
+
let size = 0;
|
|
47
|
+
try {
|
|
48
|
+
for await (const chunk of download.body) {
|
|
49
|
+
size += chunk.length;
|
|
50
|
+
if (size > asset.size)
|
|
51
|
+
throw new Error(`Downloaded size exceeds the release size for ${filename}.`);
|
|
52
|
+
hash.update(chunk);
|
|
53
|
+
await file.writeFile(chunk);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
await file.close();
|
|
58
|
+
}
|
|
59
|
+
if (size !== asset.size || 'sha256:' + hash.digest('hex') !== asset.digest.toLowerCase())
|
|
60
|
+
throw new Error(`Release integrity check failed for ${filename}.`);
|
|
61
|
+
}
|
|
@@ -137,6 +137,8 @@ async function applyAllFixes(context, value) {
|
|
|
137
137
|
if (!eligible.length && !reviewCount)
|
|
138
138
|
return window.showInformationMessage('Loadwise has no fixes for this file.');
|
|
139
139
|
const planned = fixAllEdit(eligible, context.fixWorkspace());
|
|
140
|
+
if (planned.error)
|
|
141
|
+
return window.showWarningMessage(planned.error);
|
|
140
142
|
const { applied, skipped } = planned;
|
|
141
143
|
if (applied && !(await applyEdit(context, planned, 'Loadwise could not apply the selected fixes.')))
|
|
142
144
|
return;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { access, mkdir, mkdtemp, rename, rm, stat } from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
import { packageManifest, packageRoot } from '../shared/package-root.js';
|
|
7
|
+
const execute = promisify(execFile);
|
|
8
|
+
export function editorDataDirectory() {
|
|
9
|
+
const home = os.homedir();
|
|
10
|
+
if (process.platform === 'win32')
|
|
11
|
+
return path.join(absoluteSetting(process.env.LOCALAPPDATA) ?? path.join(home, 'AppData', 'Local'), 'loadwise', 'editor');
|
|
12
|
+
if (process.platform === 'darwin')
|
|
13
|
+
return path.join(home, 'Library', 'Application Support', 'loadwise', 'editor');
|
|
14
|
+
return path.join(absoluteSetting(process.env.XDG_DATA_HOME) ?? path.join(home, '.local', 'share'), 'loadwise', 'editor');
|
|
15
|
+
}
|
|
16
|
+
function absoluteSetting(value) {
|
|
17
|
+
return value && path.isAbsolute(value) ? value : undefined;
|
|
18
|
+
}
|
|
19
|
+
async function npmCommand() {
|
|
20
|
+
const currentNpm = absoluteSetting(process.env.npm_execpath);
|
|
21
|
+
if (currentNpm && path.basename(currentNpm) === 'npm-cli.js' && (await isFile(currentNpm)))
|
|
22
|
+
return [process.execPath, currentNpm];
|
|
23
|
+
if (process.platform !== 'win32')
|
|
24
|
+
return ['npm'];
|
|
25
|
+
// Launch the npm JavaScript entry directly so paths never need cmd.exe quoting.
|
|
26
|
+
const directories = [
|
|
27
|
+
path.dirname(process.execPath),
|
|
28
|
+
...(process.env.PATH || '').split(path.delimiter).filter(path.isAbsolute),
|
|
29
|
+
];
|
|
30
|
+
const candidates = directories.map((directory) => path.join(directory, 'node_modules', 'npm', 'bin', 'npm-cli.js'));
|
|
31
|
+
for (const candidate of candidates) {
|
|
32
|
+
if (await isFile(candidate))
|
|
33
|
+
return [process.execPath, candidate];
|
|
34
|
+
}
|
|
35
|
+
throw new Error('Loadwise editor setup needs npm to prepare the language server. Install npm alongside Node.js and rerun setup.');
|
|
36
|
+
}
|
|
37
|
+
async function isFile(filename) {
|
|
38
|
+
return stat(filename).then((entry) => entry.isFile(), () => false);
|
|
39
|
+
}
|
|
40
|
+
export async function ensureEditorServer() {
|
|
41
|
+
const versions = path.join(editorDataDirectory(), 'servers');
|
|
42
|
+
const destination = path.join(versions, [packageManifest.version, process.platform, process.arch].join('-'));
|
|
43
|
+
const cli = path.join('node_modules', 'loadwise', 'dist', 'bin', 'loadwise.js');
|
|
44
|
+
const command = {
|
|
45
|
+
command: process.execPath,
|
|
46
|
+
args: [path.join(destination, cli), 'lsp', '--stdio'],
|
|
47
|
+
};
|
|
48
|
+
if (await isFile(command.args[0]))
|
|
49
|
+
return command;
|
|
50
|
+
await mkdir(versions, { recursive: true });
|
|
51
|
+
const stage = await mkdtemp(path.join(versions, '.install-'));
|
|
52
|
+
try {
|
|
53
|
+
const [executable, ...prefix] = await npmCommand();
|
|
54
|
+
// install-links packs the running distribution, including an unreleased checkout or npx install,
|
|
55
|
+
// into the destination instead of linking back to an evictable package cache.
|
|
56
|
+
await execute(executable, [
|
|
57
|
+
...prefix,
|
|
58
|
+
'install',
|
|
59
|
+
'--prefix',
|
|
60
|
+
stage,
|
|
61
|
+
'--install-links',
|
|
62
|
+
'--global=false',
|
|
63
|
+
'--prefer-offline',
|
|
64
|
+
'--omit=dev',
|
|
65
|
+
'--include=optional',
|
|
66
|
+
'--ignore-scripts',
|
|
67
|
+
'--no-bin-links',
|
|
68
|
+
'--no-audit',
|
|
69
|
+
'--no-fund',
|
|
70
|
+
'--no-save',
|
|
71
|
+
packageRoot,
|
|
72
|
+
], { cwd: stage, windowsHide: true });
|
|
73
|
+
await access(path.join(stage, cli));
|
|
74
|
+
try {
|
|
75
|
+
await rename(stage, destination);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
// Concurrent setups may finish the same immutable version while this one is preparing it.
|
|
79
|
+
if (!(await isFile(command.args[0])))
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
return command;
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
await rm(stage, { recursive: true, force: true });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { writeManagedConfig } from './managed-config.js';
|
|
6
|
+
import { ensureEditorServer } from './setup-server.js';
|
|
7
|
+
function unixVimOnWindows() {
|
|
8
|
+
const vim = (process.env.PATH ?? '')
|
|
9
|
+
.split(path.delimiter)
|
|
10
|
+
.filter((directory) => path.isAbsolute(directory))
|
|
11
|
+
.map((directory) => path.join(directory, 'vim.exe'))
|
|
12
|
+
.find((file) => fs.statSync(file, { throwIfNoEntry: false })?.isFile());
|
|
13
|
+
if (!vim)
|
|
14
|
+
return false;
|
|
15
|
+
// MSYS Vim uses ~/.vim just like Unix Vim. Native Windows Vim uses ~/vimfiles.
|
|
16
|
+
const version = spawnSync(vim, ['--version'], { encoding: 'utf8', windowsHide: true, timeout: 5_000 });
|
|
17
|
+
return version.status === 0 && version.stdout.includes('$HOME/.vimrc');
|
|
18
|
+
}
|
|
19
|
+
function vimDirectory() {
|
|
20
|
+
const home = process.env.HOME || os.homedir();
|
|
21
|
+
if (process.platform === 'win32' && !unixVimOnWindows())
|
|
22
|
+
return path.join(home, 'vimfiles');
|
|
23
|
+
const traditional = path.join(home, '.vim');
|
|
24
|
+
const xdg = path.join(process.env.XDG_CONFIG_HOME || path.join(home, '.config'), 'vim');
|
|
25
|
+
if (fs.existsSync(path.join(home, '.vimrc')) || fs.existsSync(path.join(traditional, 'vimrc')))
|
|
26
|
+
return traditional;
|
|
27
|
+
return fs.existsSync(path.join(xdg, 'vimrc')) ? xdg : traditional;
|
|
28
|
+
}
|
|
29
|
+
export function writeVimPlugin(directory, server) {
|
|
30
|
+
const filename = path.join(directory, 'plugin', 'loadwise.vim');
|
|
31
|
+
const command = JSON.stringify([server.command, ...server.args]).replaceAll("'", "''");
|
|
32
|
+
const contents = [
|
|
33
|
+
'function! s:project_root(server_info) abort',
|
|
34
|
+
" let root = lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), ['loadwise.config.json', 'tsconfig.json', 'jsconfig.json', 'package.json', '.git/'])",
|
|
35
|
+
" return lsp#utils#path_to_uri(empty(root) ? expand('%:p:h') : root)",
|
|
36
|
+
'endfunction',
|
|
37
|
+
'',
|
|
38
|
+
'function! s:register() abort',
|
|
39
|
+
" if index(lsp#get_server_names(), 'loadwise') >= 0 | return | endif",
|
|
40
|
+
' call lsp#register_server({',
|
|
41
|
+
" \\ 'name': 'loadwise',",
|
|
42
|
+
` \\ 'cmd': json_decode('${command}'),`,
|
|
43
|
+
" \\ 'root_uri': function('s:project_root'),",
|
|
44
|
+
" \\ 'allowlist': ['javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'html', 'vue', 'svelte', 'python', 'go', 'java', 'cs', 'rust', 'ruby', 'php', 'kotlin', 'c', 'cpp'],",
|
|
45
|
+
' \\ })',
|
|
46
|
+
'endfunction',
|
|
47
|
+
'',
|
|
48
|
+
'augroup loadwise_vim_lsp',
|
|
49
|
+
' autocmd!',
|
|
50
|
+
' autocmd User lsp_setup call s:register()',
|
|
51
|
+
'augroup END',
|
|
52
|
+
'',
|
|
53
|
+
].join('\n');
|
|
54
|
+
if (writeManagedConfig(filename, '"', contents) === 'conflict')
|
|
55
|
+
throw new Error('Existing Vim plugin is user-managed: ' + filename);
|
|
56
|
+
return filename;
|
|
57
|
+
}
|
|
58
|
+
export async function setupVim() {
|
|
59
|
+
const filename = writeVimPlugin(vimDirectory(), await ensureEditorServer());
|
|
60
|
+
return `Installed ${filename}\nVim uses prabirshrestha/vim-lsp. Install it with your Vim plugin manager if needed, then restart Vim and open a source file. Run :LspStatus to check Loadwise.`;
|
|
61
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { parseArgs } from 'node:util';
|
|
6
|
+
import { packageManifest } from '../shared/package-root.js';
|
|
7
|
+
import { setupNativeEditor } from './native-setup.js';
|
|
8
|
+
import { setupJetBrains } from './jetbrains-setup.js';
|
|
9
|
+
import { setupVim } from './setup-vim.js';
|
|
10
|
+
import { setupConfiguredEditor } from './configured-setup.js';
|
|
11
|
+
import { printStdioSetup } from './stdio-setup.js';
|
|
12
|
+
import { ensureEditorServer } from './setup-server.js';
|
|
13
|
+
import { currentTarget, downloadVsix } from './release-vsix.js';
|
|
14
|
+
import { detectEditor, editorLauncher, isProduct } from './editor-launcher.js';
|
|
15
|
+
const usage = `Usage: loadwise editor setup [--editor <name>] [--vsix <file>]
|
|
16
|
+
|
|
17
|
+
Choose the integration for your editor:
|
|
18
|
+
code, codium, cursor, windsurf Install the Loadwise VSIX
|
|
19
|
+
antigravity-ide Install the VSIX in Antigravity IDE
|
|
20
|
+
nvim, helix, emacs, vim Set up an editor language client
|
|
21
|
+
jetbrains Prepare the JetBrains LSP integration
|
|
22
|
+
zed Prepare a Zed development extension
|
|
23
|
+
sublime Install the Sublime Text LSP client package
|
|
24
|
+
stdio Get the command for another LSP client
|
|
25
|
+
|
|
26
|
+
Setup recognizes supported editor terminals and installed editor launchers.
|
|
27
|
+
If several editors are available, choose one in the terminal or pass --editor.
|
|
28
|
+
It verifies the matching release download against GitHub's SHA-256 digest.
|
|
29
|
+
Use --vsix with a trusted local package to install without downloading.`;
|
|
30
|
+
function editorEnvironment() {
|
|
31
|
+
const env = { ...process.env };
|
|
32
|
+
if (process.platform === 'win32') {
|
|
33
|
+
env.ELECTRON_RUN_AS_NODE = '1';
|
|
34
|
+
delete env.VSCODE_DEV;
|
|
35
|
+
}
|
|
36
|
+
return env;
|
|
37
|
+
}
|
|
38
|
+
export function editorReleaseTarget(launcher) {
|
|
39
|
+
const version = spawnSync(launcher.executable, [...launcher.args, '--version'], {
|
|
40
|
+
encoding: 'utf8',
|
|
41
|
+
env: editorEnvironment(),
|
|
42
|
+
windowsHide: true,
|
|
43
|
+
timeout: 15_000,
|
|
44
|
+
});
|
|
45
|
+
const arch = version.stdout?.trim().split(/\r?\n/).at(-1)?.trim();
|
|
46
|
+
if (version.status !== 0 || (arch !== 'x64' && arch !== 'arm64'))
|
|
47
|
+
throw new Error(`Cannot determine a supported architecture from "${launcher.product} --version". Use --vsix <file> with a package matching your editor.`);
|
|
48
|
+
return currentTarget(arch);
|
|
49
|
+
}
|
|
50
|
+
function install(launcher, vsix) {
|
|
51
|
+
const result = spawnSync(launcher.executable, [...launcher.args, '--install-extension', vsix], {
|
|
52
|
+
env: editorEnvironment(),
|
|
53
|
+
stdio: 'inherit',
|
|
54
|
+
windowsHide: true,
|
|
55
|
+
});
|
|
56
|
+
if (result.error)
|
|
57
|
+
throw result.error;
|
|
58
|
+
if (result.status !== 0)
|
|
59
|
+
throw new Error(`${launcher.product} extension installation failed (${result.signal ?? result.status}).`);
|
|
60
|
+
}
|
|
61
|
+
export async function runEditor(args) {
|
|
62
|
+
if (!args.length || (args.length === 1 && ['--help', '-h'].includes(args[0]))) {
|
|
63
|
+
console.log(usage);
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
if (args[0] !== 'setup')
|
|
67
|
+
throw new Error(usage);
|
|
68
|
+
const { values } = parseArgs({
|
|
69
|
+
args: args.slice(1),
|
|
70
|
+
options: {
|
|
71
|
+
editor: { type: 'string' },
|
|
72
|
+
vsix: { type: 'string' },
|
|
73
|
+
help: { type: 'boolean', short: 'h' },
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
if (values.help) {
|
|
77
|
+
console.log(usage);
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
const editor = values.editor ?? (await detectEditor(values.vsix !== undefined));
|
|
81
|
+
if (!isProduct(editor)) {
|
|
82
|
+
if (values.vsix !== undefined)
|
|
83
|
+
throw new Error('--vsix is available for code, codium, cursor, windsurf and antigravity-ide.');
|
|
84
|
+
await configureLanguageClient(editor);
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
const launcher = editorLauncher(editor);
|
|
88
|
+
if (values.vsix !== undefined) {
|
|
89
|
+
const local = path.resolve(values.vsix);
|
|
90
|
+
if (path.extname(local).toLowerCase() !== '.vsix' || !fs.statSync(local, { throwIfNoEntry: false })?.isFile())
|
|
91
|
+
throw new Error('--vsix must be an existing VSIX file.');
|
|
92
|
+
install(launcher, local);
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
const target = editorReleaseTarget(launcher);
|
|
96
|
+
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'loadwise-editor-'));
|
|
97
|
+
const vsix = path.join(directory, 'loadwise.vsix');
|
|
98
|
+
try {
|
|
99
|
+
await downloadVsix(vsix, packageManifest.version, target);
|
|
100
|
+
install(launcher, vsix);
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
fs.rmSync(vsix, { force: true });
|
|
104
|
+
fs.rmdirSync(directory);
|
|
105
|
+
}
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
async function configureLanguageClient(editor) {
|
|
109
|
+
switch (editor) {
|
|
110
|
+
case 'nvim':
|
|
111
|
+
case 'helix':
|
|
112
|
+
case 'emacs':
|
|
113
|
+
console.log(setupNativeEditor(editor, await ensureEditorServer()));
|
|
114
|
+
return;
|
|
115
|
+
case 'jetbrains':
|
|
116
|
+
console.log(await setupJetBrains());
|
|
117
|
+
return;
|
|
118
|
+
case 'vim':
|
|
119
|
+
console.log(await setupVim());
|
|
120
|
+
return;
|
|
121
|
+
case 'zed':
|
|
122
|
+
case 'sublime':
|
|
123
|
+
console.log(await setupConfiguredEditor(editor));
|
|
124
|
+
return;
|
|
125
|
+
case 'stdio':
|
|
126
|
+
await printStdioSetup();
|
|
127
|
+
return;
|
|
128
|
+
default:
|
|
129
|
+
throw new Error(`Invalid editor "${editor}". See loadwise editor --help.`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ensureEditorServer } from './setup-server.js';
|
|
2
|
+
/** Emit only the launch details so a client configuration tool can consume stdout. */
|
|
3
|
+
export async function printStdioSetup() {
|
|
4
|
+
const { command, args } = await ensureEditorServer();
|
|
5
|
+
console.log(JSON.stringify({ command, args }, null, 2));
|
|
6
|
+
}
|
|
@@ -174,10 +174,11 @@ function createResolver(root, fileSet, declarationFiles = []) {
|
|
|
174
174
|
allowJs: true,
|
|
175
175
|
};
|
|
176
176
|
if (config) {
|
|
177
|
-
const
|
|
177
|
+
const configFile = slash(config);
|
|
178
|
+
const loaded = ts.readConfigFile(configFile, configHost.readFile);
|
|
178
179
|
const parsed = loaded.error
|
|
179
180
|
? undefined
|
|
180
|
-
: ts.parseJsonConfigFileContent(loaded.config, configHost, path.dirname(config), undefined,
|
|
181
|
+
: ts.parseJsonConfigFileContent(loaded.config, configHost, slash(path.dirname(config)), undefined, configFile, undefined, undefined, extendedConfigs);
|
|
181
182
|
// A base config from a package is missing until dependencies are installed; its workspace
|
|
182
183
|
// imports would not resolve either, so scan with the local settings instead of failing.
|
|
183
184
|
const configErrors = parsed ? parsed.errors : loaded.error ? [loaded.error] : [];
|
|
@@ -8,6 +8,7 @@ import { fixLines } from './cli/fix-text.js';
|
|
|
8
8
|
import { loadSettings } from '../shared/config.js';
|
|
9
9
|
import { extractBaselineFlags } from '../shared/reporting/baseline-flags.js';
|
|
10
10
|
import { resolveFormat, renderReports } from '../shared/formats/index.js';
|
|
11
|
+
import { reportAutomaticFixes } from '../shared/reporting/automatic-fix-signal.js';
|
|
11
12
|
import { contractRules } from '../shared/formats/contract-rules.js';
|
|
12
13
|
import { quoteArgument } from '../shared/system/shell-argument.js';
|
|
13
14
|
import { exitCodeWithSkips } from '../performance/cli/scan-outcome.js';
|
|
@@ -18,11 +19,17 @@ import { findingReason, groupByReason } from '../shared/reporting/reason-groups.
|
|
|
18
19
|
import { notifyEditor } from '../shared/agent/notify-editor.js';
|
|
19
20
|
import { printTerminalLine } from '../shared/system/terminal-safe.js';
|
|
20
21
|
const help = `Usage:
|
|
21
|
-
loadwise maint [directory] [
|
|
22
|
-
loadwise maint [directory]
|
|
23
|
-
loadwise maint agent init [
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
loadwise maint [directory] [options]
|
|
23
|
+
loadwise maint [directory] --graph <modules.json> [options]
|
|
24
|
+
loadwise maint agent init [options]
|
|
25
|
+
|
|
26
|
+
Scan options
|
|
27
|
+
--workspace <name|path> --config <policy-file> --loadwise-config <file>
|
|
28
|
+
--staged | --changed-since <git-ref> --ignore <rule-id>
|
|
29
|
+
--json | --format <text|json|sarif|github> --include-contextual
|
|
30
|
+
--min-impact <low|medium|high|critical> --fail-on <all|contract>
|
|
31
|
+
--baseline [file] | --write-baseline [file]
|
|
32
|
+
--fix [--yes | --only <ids>] [--no-comments] [--no-format]
|
|
26
33
|
|
|
27
34
|
A loadwise.config.json in the directory also applies: its "maintainability" section holds the policy (--config names a policy file instead), and its ignore, rules and overrides filter the findings; --loadwise-config names another file. --ignore drops a rule's findings.
|
|
28
35
|
The default directory is the current folder. Source mode discovers supported files.
|
|
@@ -349,6 +356,8 @@ async function printScanReport(report, options) {
|
|
|
349
356
|
}
|
|
350
357
|
else
|
|
351
358
|
await printTextReport(report, options);
|
|
359
|
+
if (format === 'text')
|
|
360
|
+
reportAutomaticFixes(report.findings);
|
|
352
361
|
}
|
|
353
362
|
async function main(args) {
|
|
354
363
|
if (args[0] === 'agent')
|
|
@@ -123,6 +123,10 @@ const examples = {
|
|
|
123
123
|
before: ["import { readFile, writeFile } from 'node:fs/promises';", 'await writeFile(path, text);'],
|
|
124
124
|
after: ["import { writeFile } from 'node:fs/promises';", 'await writeFile(path, text);'],
|
|
125
125
|
},
|
|
126
|
+
'unused-local-function': {
|
|
127
|
+
before: ['function obsolete() { return 0; }', 'export function total() {', ' return 1;', '}'],
|
|
128
|
+
after: ['export function total() {', ' return 1;', '}'],
|
|
129
|
+
},
|
|
126
130
|
'unused-local-variable': {
|
|
127
131
|
before: [
|
|
128
132
|
'function total(items) {',
|