loadwise 0.6.2 → 0.8.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 +175 -115
- package/dist/bin/loadwise.js +132 -67
- package/dist/lib/accessibility/analyze.js +5 -3
- package/dist/lib/accessibility/angular-inline.js +9 -11
- package/dist/lib/accessibility/angular-literal.js +39 -0
- package/dist/lib/accessibility/form-context.js +36 -0
- package/dist/lib/accessibility/frame-head.js +92 -0
- package/dist/lib/accessibility/frame-viewport.js +149 -0
- package/dist/lib/accessibility/frontend-detect.js +6 -5
- package/dist/lib/accessibility/jsx-elements.js +13 -3
- package/dist/lib/accessibility/markup-files.js +7 -2
- package/dist/lib/accessibility/rule-ids.js +3 -0
- package/dist/lib/accessibility/rules.js +128 -41
- package/dist/lib/accessibility/site-fixes/buttons.js +5 -1
- package/dist/lib/accessibility/template-attributes.js +5 -3
- package/dist/lib/accessibility/template-elements.js +25 -6
- package/dist/lib/accessibility/template-file.js +40 -25
- package/dist/lib/accessibility/usage.js +10 -2
- package/dist/lib/editor/accessibility-examples.js +6 -1
- package/dist/lib/editor/actions.js +46 -7
- package/dist/lib/editor/apply-fix.js +69 -4
- package/dist/lib/editor/configured-setup.js +63 -0
- package/dist/lib/editor/diagnostics.js +206 -17
- package/dist/lib/editor/dismissals.js +85 -26
- package/dist/lib/editor/editor-document.js +5 -2
- package/dist/lib/editor/editor-launcher.js +170 -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 +80 -24
- package/dist/lib/editor/managed-config.js +37 -0
- package/dist/lib/editor/native-setup.js +86 -0
- package/dist/lib/editor/perf-watch.js +8 -6
- package/dist/lib/editor/release-vsix.js +61 -0
- package/dist/lib/editor/reliability-examples.js +15 -0
- package/dist/lib/editor/scan-session.js +29 -8
- package/dist/lib/editor/server-commands.js +38 -9
- package/dist/lib/editor/setup-server.js +87 -0
- package/dist/lib/editor/setup-vim.js +63 -0
- package/dist/lib/editor/setup.js +131 -0
- package/dist/lib/editor/stdio-setup.js +6 -0
- package/dist/lib/editor/workspace-files.js +61 -7
- package/dist/lib/editor/workspace-paths.js +41 -1
- package/dist/lib/maintainability/analysis/analyze-source.js +1 -1
- package/dist/lib/maintainability/architecture/architecture.js +4 -4
- package/dist/lib/maintainability/cli/changed-lines.js +20 -2
- package/dist/lib/maintainability/cli/inputs.js +12 -3
- package/dist/lib/maintainability/cli.js +18 -5
- package/dist/lib/maintainability/entry-points/entry-points.js +44 -15
- package/dist/lib/maintainability/entry-points/html-entry-points.js +5 -1
- package/dist/lib/maintainability/examples.js +4 -0
- package/dist/lib/maintainability/quality/functions.js +9 -6
- package/dist/lib/maintainability/quality/limits.js +19 -0
- package/dist/lib/maintainability/quality/size-limits.js +8 -2
- package/dist/lib/maintainability/quality/stray-console.js +62 -1
- package/dist/lib/maintainability/quality/tsconfig-strict.js +2 -0
- package/dist/lib/maintainability/rule-ids.js +3 -0
- package/dist/lib/maintainability/scan-changed.js +4 -1
- package/dist/lib/maintainability/scan-worker.js +6 -2
- package/dist/lib/maintainability/scan.js +21 -8
- package/dist/lib/maintainability/site-fixes/unused-bindings.js +138 -3
- package/dist/lib/maintainability/unused/module-usage.js +43 -21
- package/dist/lib/maintainability/unused/unused-bindings.js +39 -4
- package/dist/lib/maintainability/unused/unused-modules.js +5 -10
- package/dist/lib/performance/analysis/source-inputs.js +7 -2
- package/dist/lib/performance/analysis/source-options.js +7 -6
- package/dist/lib/performance/analyze.js +16 -3
- 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 +4 -0
- package/dist/lib/performance/cli/cli-scan.js +21 -2
- package/dist/lib/performance/cli.js +16 -7
- package/dist/lib/performance/collections/memory-growth.js +55 -12
- package/dist/lib/performance/contracts/openapi.js +13 -4
- package/dist/lib/performance/datastores/pg-integrity.js +68 -22
- package/dist/lib/performance/datastores/pg-session-release.js +114 -0
- package/dist/lib/performance/datastores/pg-session-sql.js +144 -0
- package/dist/lib/performance/datastores/pooling.js +62 -3
- package/dist/lib/performance/datastores/redis.js +94 -18
- package/dist/lib/performance/datastores/session-store.js +2 -1
- package/dist/lib/performance/db/checks.js +19 -8
- package/dist/lib/performance/db/gateway.js +3 -1
- package/dist/lib/performance/db/plan-estimates.js +4 -4
- package/dist/lib/performance/engine/native-syntax.js +3 -0
- package/dist/lib/performance/engine/native.js +11 -7
- package/dist/lib/performance/evidence/plans.js +7 -5
- package/dist/lib/performance/evidence/traces.js +21 -1
- package/dist/lib/performance/frontend/angular-teardown.js +96 -0
- package/dist/lib/performance/frontend/effect-cleanup.js +148 -0
- package/dist/lib/performance/frontend/frontend-dom-perf.js +14 -2
- package/dist/lib/performance/frontend/frontend-helpers.js +1 -9
- package/dist/lib/performance/frontend/frontend-perf.js +149 -74
- package/dist/lib/performance/migrations/extract-code-sql.js +16 -4
- package/dist/lib/performance/migrations/extract-code.js +13 -5
- package/dist/lib/performance/migrations/extract-sql.js +82 -38
- package/dist/lib/performance/migrations/operations.js +56 -13
- package/dist/lib/performance/migrations/postgres-lock-timeout.js +52 -0
- package/dist/lib/performance/migrations/postgres-registry.js +127 -26
- package/dist/lib/performance/migrations/postgres-settings.js +78 -0
- package/dist/lib/performance/migrations/rules-postgres-add-column.js +3 -3
- package/dist/lib/performance/migrations/rules-postgres-shared.js +9 -0
- package/dist/lib/performance/migrations/rules-postgres.js +88 -39
- package/dist/lib/performance/orm/offset-pagination.js +6 -4
- package/dist/lib/performance/orm/prisma-aggregates.js +69 -18
- package/dist/lib/performance/orm/unbounded-list-chain.js +29 -0
- package/dist/lib/performance/orm/unbounded-list-queries.js +18 -13
- package/dist/lib/performance/polyglot.js +111 -14
- package/dist/lib/performance/projects.js +3 -3
- package/dist/lib/performance/query-loops/sequential-loops.js +1 -0
- package/dist/lib/performance/request/backend-mastery.js +151 -42
- 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 +298 -46
- 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 +204 -23
- package/dist/lib/performance/request/request-handlers.js +120 -23
- package/dist/lib/performance/request/sql-select-star.js +150 -0
- package/dist/lib/performance/request/unbounded-promise-all.js +54 -29
- package/dist/lib/performance/request/upload-limits.js +5 -1
- package/dist/lib/performance/site-fix.js +4 -4
- package/dist/lib/performance/site-fixes/backend-mastery-fixes.js +298 -16
- 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 +358 -14
- package/dist/lib/performance/site-fixes/helpers.js +3 -4
- package/dist/lib/performance/site-fixes/integrity.js +2 -4
- package/dist/lib/performance/site-fixes/migration-context.js +8 -1
- package/dist/lib/performance/site-fixes/migration-lock-rules.js +66 -30
- package/dist/lib/performance/site-fixes/prisma-aggregates.js +29 -9
- package/dist/lib/performance/site-fixes/small-rewrites.js +168 -10
- package/dist/lib/performance/site-fixes/sync-calls.js +14 -12
- package/dist/lib/performance/site-fixes/upload-limits.js +13 -7
- package/dist/lib/performance/sql/mysql-tokens.js +38 -12
- package/dist/lib/reliability/boundary-access.js +114 -57
- package/dist/lib/reliability/react-bugs.js +29 -7
- package/dist/lib/reliability/resource-leak-intervals.js +258 -0
- package/dist/lib/reliability/resource-leaks.js +209 -195
- package/dist/lib/reliability/rule-ids.js +10 -1
- package/dist/lib/reliability/site-fixes/resource-leaks.js +16 -1
- package/dist/lib/reliability/swallowed-errors.js +107 -21
- package/dist/lib/reliability/test-cleanup-after-await.js +92 -18
- package/dist/lib/reliability/usage.js +16 -5
- package/dist/lib/reliability/walk.js +3 -2
- package/dist/lib/security/auth-crypto/hashing.js +24 -8
- package/dist/lib/security/auth-crypto/jwt.js +21 -6
- package/dist/lib/security/auth-crypto/secrets.js +44 -1
- package/dist/lib/security/auth-crypto/shared.js +3 -1
- package/dist/lib/security/auth-crypto/signing-algorithm.js +79 -0
- package/dist/lib/security/auth-crypto/transport-and-ciphers.js +85 -1
- package/dist/lib/security/cli.js +21 -6
- package/dist/lib/security/cookie-credentials.js +115 -0
- package/dist/lib/security/cookie-csrf.js +241 -0
- package/dist/lib/security/deps/advisory.js +50 -109
- package/dist/lib/security/deps/cli.js +1 -1
- package/dist/lib/security/deps/cvss-score.js +14 -0
- package/dist/lib/security/deps/fixed-version.js +97 -0
- package/dist/lib/security/deps/lockfiles.js +135 -74
- package/dist/lib/security/deps/osv.js +11 -3
- package/dist/lib/security/deps/scan.js +47 -20
- package/dist/lib/security/deps/yarn-lock.js +158 -0
- package/dist/lib/security/examples/injection.cjs +4 -0
- package/dist/lib/security/exposure/cookies.js +17 -2
- package/dist/lib/security/exposure/cors-origin-regex.js +2 -3
- package/dist/lib/security/exposure/frontend-security.js +21 -14
- package/dist/lib/security/exposure/jsx-url.js +18 -33
- package/dist/lib/security/exposure/logging.js +49 -10
- package/dist/lib/security/exposure/prototype-pollution.js +126 -56
- package/dist/lib/security/exposure/react-html.js +26 -0
- package/dist/lib/security/exposure/reflected-xss.js +34 -5
- package/dist/lib/security/files/compose.js +126 -1
- package/dist/lib/security/files/dockerfile.js +62 -4
- package/dist/lib/security/files/index.js +1 -1
- package/dist/lib/security/injection/command.js +46 -18
- package/dist/lib/security/injection/index.js +2 -0
- package/dist/lib/security/injection/ldap.js +86 -0
- package/dist/lib/security/injection/nosql.js +28 -4
- package/dist/lib/security/injection/redos.js +1 -1
- package/dist/lib/security/injection/rule-ids.js +1 -0
- package/dist/lib/security/injection/shared.js +5 -1
- package/dist/lib/security/injection/sql.js +28 -13
- package/dist/lib/security/lexical-declaration.js +113 -0
- package/dist/lib/security/pg-dynamic-query.js +28 -1
- package/dist/lib/security/pg-identifier-guards.js +107 -3
- package/dist/lib/security/phase5-rules.js +26 -135
- package/dist/lib/security/polyglot.js +2 -2
- package/dist/lib/security/redirect-settings.js +98 -0
- package/dist/lib/security/request-forgery/open-redirect.js +18 -5
- package/dist/lib/security/request-forgery/path-traversal.js +84 -6
- package/dist/lib/security/request-forgery/shared.js +1 -7
- package/dist/lib/security/request-forgery/ssrf.js +176 -14
- package/dist/lib/security/rule-descriptions.js +5 -1
- package/dist/lib/security/rule-ids.js +7 -0
- package/dist/lib/security/site-fixes/auth-crypto.js +5 -78
- package/dist/lib/security/site-fixes/exposure.js +21 -3
- package/dist/lib/security/site-fixes/files.js +11 -13
- package/dist/lib/security/site-fixes/frontend-security-fixes.js +2 -2
- package/dist/lib/security/site-fixes/injection.js +17 -4
- package/dist/lib/security/site-fixes/jwt.js +1 -20
- package/dist/lib/security/site-fixes/request-forgery.js +37 -29
- package/dist/lib/security/taint/binding-inputs.js +236 -0
- package/dist/lib/security/taint/filename-guard.js +45 -45
- package/dist/lib/security/taint/guards.js +14 -8
- package/dist/lib/security/taint/index.js +126 -154
- package/dist/lib/security/taint/propagate.js +43 -9
- package/dist/lib/security/taint/record-writes.js +161 -0
- package/dist/lib/security/taint/resolution-cache.js +13 -7
- package/dist/lib/security/taint/sanitizers.js +89 -5
- package/dist/lib/security/taint/trace-nodes.js +61 -0
- package/dist/lib/security/taint/validators.js +89 -9
- package/dist/lib/shared/agent/agent-init.js +28 -5
- 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 +58 -11
- package/dist/lib/shared/agent/git-hook.js +17 -6
- package/dist/lib/shared/agent/review-delivery.js +1 -1
- package/dist/lib/shared/agent/review-mcp.js +8 -2
- package/dist/lib/shared/analysis/ast-semantics.js +2 -2
- package/dist/lib/shared/analysis/scan-cache.js +99 -14
- package/dist/lib/shared/check.js +172 -20
- package/dist/lib/shared/cli-dispatch.js +17 -0
- package/dist/lib/shared/config.js +27 -10
- package/dist/lib/shared/explain.js +1 -1
- package/dist/lib/shared/fix/fix-convergence.js +19 -31
- package/dist/lib/shared/fix/fix-handoff.js +16 -11
- package/dist/lib/shared/fix/fix-imports.js +4 -162
- package/dist/lib/shared/fix/fix-presentation-comments.js +23 -9
- 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 +9 -6
- package/dist/lib/shared/fix/fix-safety.js +32 -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/fix-typecheck.js +8 -4
- package/dist/lib/shared/fix/import-text-edits.js +148 -0
- 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 +241 -104
- package/dist/lib/shared/formats/finding-location.js +4 -1
- package/dist/lib/shared/formats/github.js +3 -3
- package/dist/lib/shared/formats/sarif.js +9 -3
- package/dist/lib/shared/report-fp.js +97 -0
- package/dist/lib/shared/reporting/automatic-fix-signal.js +10 -0
- package/dist/lib/shared/reporting/baseline.js +7 -5
- package/dist/lib/shared/reporting/check-text.js +50 -0
- package/dist/lib/shared/reporting/pillars.js +54 -19
- package/dist/lib/shared/reporting/source-report.js +3 -0
- package/dist/lib/shared/system/atomic-write.js +5 -2
- package/dist/lib/shared/system/glob.js +34 -8
- package/dist/lib/shared/system/sentry.js +222 -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/dist/lib/shared/workspaces.js +15 -3
- 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 +15 -3
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/commands/loadwise.md +11 -6
- package/plugin/hooks/check-edited-file.mjs +27 -5
- package/polyglot/performance/rules/csharp.yml +34 -5
- package/polyglot/performance/rules/java.yml +24 -1
- package/polyglot/performance/rules/python.yml +74 -2
- package/polyglot/performance/sgconfig.yml +1 -0
- package/polyglot/reliability/rules/csharp.yml +12 -6
- package/polyglot/reliability/rules/go.yml +86 -6
- package/polyglot/reliability/rules/java.yml +22 -1
- package/polyglot/reliability/sgconfig.yml +1 -0
- package/polyglot/security/rules/go.yml +100 -22
- package/polyglot/security/rules/python.yml +74 -6
- package/polyglot/security/rules/rust.yml +65 -0
- package/polyglot/security/sgconfig.yml +1 -0
- package/schema/loadwise.config.schema.json +556 -76
- /package/polyglot/{performance/rules → shared-rules}/input.yml +0 -0
|
@@ -5,16 +5,40 @@
|
|
|
5
5
|
// can be shared through version control.
|
|
6
6
|
import fs from 'node:fs';
|
|
7
7
|
import path from 'node:path';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { unlinkWithRetry, writeResolvedFileAtomic } from '../shared/system/atomic-write.js';
|
|
9
|
+
import { realTarget } from '../shared/system/real-target.js';
|
|
10
|
+
import { errorCode, errorMessage } from '../shared/system/error-code.js';
|
|
10
11
|
import { isRecord } from '../shared/system/is-record.js';
|
|
11
|
-
import {
|
|
12
|
+
import { isInside, samePathSpelling } from './workspace-paths.js';
|
|
12
13
|
const dismissalsPath = path.join('.loadwise', 'dismissed.json');
|
|
13
14
|
// The file is read synchronously on every change to it; a file this large is not a list of
|
|
14
15
|
// dismissals anyone curates, and parsing it would stall the server.
|
|
15
16
|
const maxDismissalBytes = 4 * 1024 * 1024;
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
// A real source line never contains a newline. Older clients preserve this string through writes,
|
|
18
|
+
// but cannot mistake an occurrence-specific dismissal for every statement with the same text.
|
|
19
|
+
const occurrenceMarker = '\nloadwise-occurrence:';
|
|
20
|
+
function keyOf({ file, ruleId, lineText, occurrence }) {
|
|
21
|
+
return JSON.stringify([file.toLowerCase(), ruleId, lineText ?? null, occurrence ?? null]);
|
|
22
|
+
}
|
|
23
|
+
function dismissalIndex(entries) {
|
|
24
|
+
const pathsByKey = new Map();
|
|
25
|
+
for (const entry of entries) {
|
|
26
|
+
const key = keyOf(entry);
|
|
27
|
+
const files = pathsByKey.get(key) ?? new Set();
|
|
28
|
+
files.add(entry.file);
|
|
29
|
+
pathsByKey.set(key, files);
|
|
30
|
+
}
|
|
31
|
+
return (entry) => {
|
|
32
|
+
const files = pathsByKey.get(keyOf(entry));
|
|
33
|
+
if (!files)
|
|
34
|
+
return false;
|
|
35
|
+
if (files.has(entry.file))
|
|
36
|
+
return true;
|
|
37
|
+
for (const file of files)
|
|
38
|
+
if (samePathSpelling(file, entry.file))
|
|
39
|
+
return true;
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
18
42
|
}
|
|
19
43
|
function storedEntry(root, stored) {
|
|
20
44
|
if (!isRecord(stored) || typeof stored.file !== 'string' || typeof stored.ruleId !== 'string')
|
|
@@ -22,8 +46,17 @@ function storedEntry(root, stored) {
|
|
|
22
46
|
if (stored.file.includes('\0'))
|
|
23
47
|
return;
|
|
24
48
|
const entry = { file: path.resolve(root, stored.file), ruleId: stored.ruleId };
|
|
25
|
-
if (typeof stored.lineText === 'string')
|
|
26
|
-
|
|
49
|
+
if (typeof stored.lineText === 'string') {
|
|
50
|
+
const marker = stored.lineText.lastIndexOf(occurrenceMarker);
|
|
51
|
+
entry.lineText = marker < 0 ? stored.lineText : stored.lineText.slice(0, marker);
|
|
52
|
+
if (marker >= 0)
|
|
53
|
+
entry.occurrence = stored.lineText.slice(marker + occurrenceMarker.length);
|
|
54
|
+
}
|
|
55
|
+
if (stored.occurrence !== undefined) {
|
|
56
|
+
if (entry.lineText === undefined || typeof stored.occurrence !== 'string')
|
|
57
|
+
return;
|
|
58
|
+
entry.occurrence = stored.occurrence;
|
|
59
|
+
}
|
|
27
60
|
return entry;
|
|
28
61
|
}
|
|
29
62
|
function readEntries(filename, root) {
|
|
@@ -44,10 +77,12 @@ function readEntries(filename, root) {
|
|
|
44
77
|
return { entries: stored.flatMap((item) => storedEntry(root, item) ?? []) };
|
|
45
78
|
}
|
|
46
79
|
function serialize(root, entries) {
|
|
47
|
-
const stored = entries.map(({ file, ruleId, lineText }) => ({
|
|
80
|
+
const stored = entries.map(({ file, ruleId, lineText, occurrence }) => ({
|
|
48
81
|
file: path.relative(root, file).split(path.sep).join('/'),
|
|
49
82
|
ruleId,
|
|
50
|
-
...(typeof lineText === 'string'
|
|
83
|
+
...(typeof lineText === 'string'
|
|
84
|
+
? { lineText: occurrence ? lineText + occurrenceMarker + occurrence : lineText }
|
|
85
|
+
: {}),
|
|
51
86
|
}));
|
|
52
87
|
return JSON.stringify(stored, null, 2) + '\n';
|
|
53
88
|
}
|
|
@@ -55,11 +90,11 @@ function createDismissals(root, { onProblem }) {
|
|
|
55
90
|
const filename = path.join(root, dismissalsPath);
|
|
56
91
|
const describe = (problem) => dismissalsPath.split(path.sep).join('/') + ' in ' + root + ' ' + problem + '.';
|
|
57
92
|
let current = [];
|
|
58
|
-
let
|
|
93
|
+
let matches = dismissalIndex([]);
|
|
59
94
|
let pendingWrite = Promise.resolve();
|
|
60
95
|
function replace(next) {
|
|
61
96
|
current = next;
|
|
62
|
-
|
|
97
|
+
matches = dismissalIndex(current);
|
|
63
98
|
}
|
|
64
99
|
// A file that does not parse keeps the dismissals already shown: it may be mid-rewrite by a
|
|
65
100
|
// checkout, and an edit the user is still making should not flood the editor with findings.
|
|
@@ -74,19 +109,40 @@ function createDismissals(root, { onProblem }) {
|
|
|
74
109
|
// one. The shown state changes only once the file holds it.
|
|
75
110
|
function update(transform) {
|
|
76
111
|
const next = pendingWrite
|
|
77
|
-
.catch(() => {
|
|
112
|
+
.catch(() => {
|
|
113
|
+
// A failed earlier write already reported its error to its own caller; this one starts afresh.
|
|
114
|
+
})
|
|
78
115
|
.then(() => {
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
throw new Error(describe(stored.problem) + ' Fix or remove it, then try again; it was left unchanged.');
|
|
82
|
-
}
|
|
83
|
-
if (!isRealPathInside(root, filename)) {
|
|
116
|
+
const target = realTarget(filename);
|
|
117
|
+
if (!isInside(realTarget(root), target)) {
|
|
84
118
|
throw new Error(describe('resolves outside the workspace folder') + ' Nothing was written.');
|
|
85
119
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
120
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
121
|
+
const lock = target + '.lock';
|
|
122
|
+
let descriptor;
|
|
123
|
+
try {
|
|
124
|
+
descriptor = fs.openSync(lock, 'wx', 0o600);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
if (errorCode(error) !== 'EEXIST')
|
|
128
|
+
throw error;
|
|
129
|
+
throw new Error('A dismissal update is already locked. Retry after the other editor finishes. If all editors are closed, remove the stale lock at ' +
|
|
130
|
+
lock +
|
|
131
|
+
'.');
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
const stored = readEntries(target, root);
|
|
135
|
+
if (stored.entries === undefined) {
|
|
136
|
+
throw new Error(describe(stored.problem) + ' Fix or remove it, then try again; it was left unchanged.');
|
|
137
|
+
}
|
|
138
|
+
const entries = transform(stored.entries);
|
|
139
|
+
writeResolvedFileAtomic(target, serialize(root, entries));
|
|
140
|
+
replace(entries);
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
fs.closeSync(descriptor);
|
|
144
|
+
unlinkWithRetry(lock);
|
|
145
|
+
}
|
|
90
146
|
});
|
|
91
147
|
pendingWrite = next;
|
|
92
148
|
return next;
|
|
@@ -95,15 +151,18 @@ function createDismissals(root, { onProblem }) {
|
|
|
95
151
|
return {
|
|
96
152
|
entries: () => [...current],
|
|
97
153
|
has(site) {
|
|
98
|
-
|
|
154
|
+
if (matches(site) || matches({ file: site.file, ruleId: site.ruleId }))
|
|
155
|
+
return true;
|
|
156
|
+
// Older line-only entries are safe only when exactly one finding currently matches.
|
|
157
|
+
return site.occurrence === '1/1' && matches({ ...site, occurrence: undefined });
|
|
99
158
|
},
|
|
100
159
|
add(entry) {
|
|
101
|
-
const
|
|
102
|
-
return update((entries) =>
|
|
160
|
+
const matchesNew = dismissalIndex([entry]);
|
|
161
|
+
return update((entries) => (entries.some(matchesNew) ? entries : [...entries, entry]));
|
|
103
162
|
},
|
|
104
163
|
remove(removed) {
|
|
105
|
-
const
|
|
106
|
-
return update((entries) => entries.filter((entry) => !
|
|
164
|
+
const matchesRemoved = dismissalIndex(removed);
|
|
165
|
+
return update((entries) => entries.filter((entry) => !matchesRemoved(entry)));
|
|
107
166
|
},
|
|
108
167
|
reload: load,
|
|
109
168
|
};
|
|
@@ -44,7 +44,7 @@ function createEditorDocument(filename, text, { languageId = languageIdOf(filena
|
|
|
44
44
|
const lines = text.split(/\r?\n/);
|
|
45
45
|
return {
|
|
46
46
|
filename,
|
|
47
|
-
languageId,
|
|
47
|
+
languageId: languageId === 'cs' ? 'csharp' : languageId,
|
|
48
48
|
version,
|
|
49
49
|
isDirty,
|
|
50
50
|
eol: text.includes('\r\n') ? '\r\n' : '\n',
|
|
@@ -53,8 +53,11 @@ function createEditorDocument(filename, text, { languageId = languageIdOf(filena
|
|
|
53
53
|
getText: () => text,
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
-
function readDiskDocument(filename) {
|
|
56
|
+
function readDiskDocument(filename, maxBytes = Infinity) {
|
|
57
57
|
try {
|
|
58
|
+
const stats = fs.statSync(filename);
|
|
59
|
+
if (!stats.isFile() || stats.size > maxBytes)
|
|
60
|
+
return;
|
|
58
61
|
return createEditorDocument(filename, fs.readFileSync(filename, 'utf8'));
|
|
59
62
|
}
|
|
60
63
|
catch {
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createInterface } from 'node:readline';
|
|
5
|
+
import { absoluteSetting } from './setup-server.js';
|
|
6
|
+
const products = {
|
|
7
|
+
'antigravity-ide': { folder: 'Antigravity IDE', app: 'Antigravity IDE.app', exe: 'Antigravity IDE.exe' },
|
|
8
|
+
cursor: { folder: 'cursor', app: 'Cursor.app', exe: 'Cursor.exe' },
|
|
9
|
+
windsurf: { folder: 'Windsurf', app: 'Windsurf.app', exe: 'Windsurf.exe' },
|
|
10
|
+
code: { folder: 'Microsoft VS Code', app: 'Visual Studio Code.app', exe: 'Code.exe' },
|
|
11
|
+
codium: { folder: 'VSCodium', app: 'VSCodium.app', exe: 'VSCodium.exe' },
|
|
12
|
+
};
|
|
13
|
+
function pathDirectories() {
|
|
14
|
+
return (process.env.PATH ?? '').split(path.delimiter).filter((dir) => path.isAbsolute(dir));
|
|
15
|
+
}
|
|
16
|
+
function binDirectories(product) {
|
|
17
|
+
const directories = pathDirectories();
|
|
18
|
+
if (process.platform === 'win32') {
|
|
19
|
+
const local = absoluteSetting(process.env.LOCALAPPDATA);
|
|
20
|
+
const bases = [
|
|
21
|
+
local && path.join(local, 'Programs'),
|
|
22
|
+
absoluteSetting(process.env.ProgramFiles),
|
|
23
|
+
absoluteSetting(process.env['ProgramFiles(x86)']),
|
|
24
|
+
];
|
|
25
|
+
for (const base of bases) {
|
|
26
|
+
if (!base)
|
|
27
|
+
continue;
|
|
28
|
+
const root = path.join(base, products[product].folder);
|
|
29
|
+
directories.push(path.join(root, 'bin'), path.join(root, 'resources', 'app', 'bin'));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (process.platform === 'darwin') {
|
|
33
|
+
for (const base of ['/Applications', path.join(os.homedir(), 'Applications')])
|
|
34
|
+
directories.push(path.join(base, products[product].app, 'Contents', 'Resources', 'app', 'bin'));
|
|
35
|
+
}
|
|
36
|
+
return directories;
|
|
37
|
+
}
|
|
38
|
+
function locate(product) {
|
|
39
|
+
for (const directory of binDirectories(product)) {
|
|
40
|
+
const file = path.join(directory, process.platform === 'win32' ? product + '.cmd' : product);
|
|
41
|
+
if (!fs.statSync(file, { throwIfNoEntry: false })?.isFile())
|
|
42
|
+
continue;
|
|
43
|
+
if (process.platform !== 'win32') {
|
|
44
|
+
if (fs.statSync(file).mode & 0o111)
|
|
45
|
+
return { product, executable: file, args: [] };
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
// Windows distributions may move the CLI under a build hash. Read the official
|
|
49
|
+
// launcher's relative path, then execute Electron directly with an argument array.
|
|
50
|
+
const launch = /^"%~dp0((?:\.\.\\){1,3}[^"\\]+\.exe)"\s+"%~dp0((?:\.\.\\){1,3}(?:[\da-f]+\\)?(?:resources\\app\\)?out\\cli\.js)"(?:\s|$)/im.exec(fs.readFileSync(file, 'utf8'));
|
|
51
|
+
if (!launch || path.basename(launch[1]).toLowerCase() !== products[product].exe.toLowerCase())
|
|
52
|
+
continue;
|
|
53
|
+
const executable = path.resolve(directory, launch[1]);
|
|
54
|
+
const script = path.resolve(directory, launch[2]);
|
|
55
|
+
if (fs.existsSync(executable) && fs.existsSync(script))
|
|
56
|
+
return { product, executable, args: [script] };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function terminalProduct() {
|
|
60
|
+
const evidence = [
|
|
61
|
+
process.env.VSCODE_GIT_ASKPASS_NODE,
|
|
62
|
+
process.env.VSCODE_GIT_ASKPASS_MAIN,
|
|
63
|
+
process.env.__CFBundleIdentifier,
|
|
64
|
+
process.env.TERM_PROGRAM,
|
|
65
|
+
]
|
|
66
|
+
.filter(Boolean)
|
|
67
|
+
.join('\n');
|
|
68
|
+
if (/antigravity[ -]ide/i.test(evidence))
|
|
69
|
+
return 'antigravity-ide';
|
|
70
|
+
if (/windsurf/i.test(evidence))
|
|
71
|
+
return 'windsurf';
|
|
72
|
+
if (/cursor/i.test(evidence))
|
|
73
|
+
return 'cursor';
|
|
74
|
+
if (/vscodium|com\.vscodium\.codium|[/\\]codium[/\\]/i.test(evidence))
|
|
75
|
+
return 'codium';
|
|
76
|
+
if (/visual studio code|microsoft vs code|com\.microsoft\.vscode|[/\\]code(?:\.exe|[/\\]resources)/i.test(evidence))
|
|
77
|
+
return 'code';
|
|
78
|
+
// Both products set TERM_PROGRAM=vscode in integrated terminals.
|
|
79
|
+
}
|
|
80
|
+
export function isProduct(value) {
|
|
81
|
+
return Object.hasOwn(products, value);
|
|
82
|
+
}
|
|
83
|
+
async function chooseEditor(available) {
|
|
84
|
+
const names = available.join(', ');
|
|
85
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
86
|
+
throw new Error(`Choose one of the detected editors with --editor: ${names}. See loadwise editor --help for all integrations.`);
|
|
87
|
+
const input = createInterface({ input: process.stdin, output: process.stdout });
|
|
88
|
+
try {
|
|
89
|
+
const choices = available.map((product, index) => `${index + 1}) ${product}`).join(' ');
|
|
90
|
+
process.stdout.write(`Install Loadwise in which editor? ${choices}\nEnter a name or number: `);
|
|
91
|
+
for await (const line of input) {
|
|
92
|
+
const answer = line.trim().toLowerCase();
|
|
93
|
+
const selected = available.find((product, index) => answer === product || answer === String(index + 1));
|
|
94
|
+
if (selected)
|
|
95
|
+
return selected;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
throw new Error(`Invalid editor selection. Use --editor with one of: ${names}.`);
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
input.close();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export function editorLauncher(product) {
|
|
105
|
+
const launcher = locate(product);
|
|
106
|
+
if (launcher)
|
|
107
|
+
return launcher;
|
|
108
|
+
throw new Error(`Cannot find the ${product} editor CLI. Add its bin directory to PATH or use Install from VSIX in the editor.`);
|
|
109
|
+
}
|
|
110
|
+
const nativeCommands = {
|
|
111
|
+
nvim: ['nvim'],
|
|
112
|
+
helix: ['hx', 'helix'],
|
|
113
|
+
vim: ['vim', 'gvim'],
|
|
114
|
+
emacs: ['emacs', 'emacsclient'],
|
|
115
|
+
jetbrains: [
|
|
116
|
+
'idea',
|
|
117
|
+
'idea64',
|
|
118
|
+
'pycharm',
|
|
119
|
+
'pycharm64',
|
|
120
|
+
'webstorm',
|
|
121
|
+
'goland',
|
|
122
|
+
'clion',
|
|
123
|
+
'rider',
|
|
124
|
+
'rustrover',
|
|
125
|
+
'rubymine',
|
|
126
|
+
'phpstorm',
|
|
127
|
+
'datagrip',
|
|
128
|
+
],
|
|
129
|
+
zed: ['zed'],
|
|
130
|
+
sublime: ['subl', 'sublime_text'],
|
|
131
|
+
};
|
|
132
|
+
function hasNativeExecutable(command, directories) {
|
|
133
|
+
const suffixes = process.platform === 'win32' ? ['.exe', '.cmd', '.bat'] : [''];
|
|
134
|
+
return directories.some((directory) => suffixes.some((suffix) => {
|
|
135
|
+
const file = fs.statSync(path.join(directory, command + suffix), { throwIfNoEntry: false });
|
|
136
|
+
return file?.isFile() && (process.platform === 'win32' || (file.mode & 0o111) !== 0);
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
export async function detectEditor(vsixOnly) {
|
|
140
|
+
const preferred = (!vsixOnly && nativeTerminal()) || terminalProduct();
|
|
141
|
+
if (preferred)
|
|
142
|
+
return preferred;
|
|
143
|
+
const available = Object.keys(products)
|
|
144
|
+
.filter(isProduct)
|
|
145
|
+
.filter((product) => locate(product));
|
|
146
|
+
if (!vsixOnly) {
|
|
147
|
+
const directories = pathDirectories();
|
|
148
|
+
for (const [editor, commands] of Object.entries(nativeCommands)) {
|
|
149
|
+
if (commands.some((command) => hasNativeExecutable(command, directories)))
|
|
150
|
+
available.push(editor);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (available.length === 1)
|
|
154
|
+
return available[0];
|
|
155
|
+
if (available.length > 1)
|
|
156
|
+
return chooseEditor(available);
|
|
157
|
+
throw new Error('--editor must be supplied when no supported editor is detected. See loadwise editor --help for the full --editor list.');
|
|
158
|
+
}
|
|
159
|
+
function nativeTerminal() {
|
|
160
|
+
if (process.env.NVIM)
|
|
161
|
+
return 'nvim';
|
|
162
|
+
if (process.env.VIM_TERMINAL)
|
|
163
|
+
return 'vim';
|
|
164
|
+
if (process.env.INSIDE_EMACS)
|
|
165
|
+
return 'emacs';
|
|
166
|
+
if (process.env.TERM_PROGRAM?.toLowerCase() === 'zed')
|
|
167
|
+
return 'zed';
|
|
168
|
+
if (process.env.TERMINAL_EMULATOR === 'JetBrains-JediTerm')
|
|
169
|
+
return 'jetbrains';
|
|
170
|
+
}
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
// editor, so undo restores the original code.
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import path from 'node:path';
|
|
7
|
+
import { currentText } from '../shared/fix/read-fix-text.js';
|
|
8
|
+
import { errorMessage } from '../shared/system/error-code.js';
|
|
7
9
|
import { isChangeApplied, locateChange } from './apply-fix.js';
|
|
8
10
|
const staleFixMessage = 'The code changed since the last scan. Save the file to rescan, then try again.';
|
|
9
11
|
const noCreateMessage = 'This editor cannot create files through the language server, so the fix was not applied.';
|
|
@@ -125,8 +127,22 @@ function workspaceEdit(operations, workspace) {
|
|
|
125
127
|
}
|
|
126
128
|
return { edit: { changes: plainChanges(operations, workspace) }, createdFiles };
|
|
127
129
|
}
|
|
130
|
+
// The editor may supply a decoded buffer even if the original bytes cannot be saved as UTF-8.
|
|
131
|
+
function fixTargetError(fixes) {
|
|
132
|
+
const targets = new Set(fixes.flatMap((fix) => fix.changes.map((change) => change.filename)));
|
|
133
|
+
try {
|
|
134
|
+
for (const file of targets)
|
|
135
|
+
currentText(file);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
return errorMessage(error);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
128
141
|
/** The edit applying one fix, or why it cannot apply. */
|
|
129
142
|
function fixEdit(fix, workspace) {
|
|
143
|
+
const error = fixTargetError([fix]);
|
|
144
|
+
if (error)
|
|
145
|
+
return { error };
|
|
130
146
|
const plan = planFix(fix, workspace);
|
|
131
147
|
if (plan.operations === undefined)
|
|
132
148
|
return plan;
|
|
@@ -169,6 +185,9 @@ function bulkFixesFor(entries) {
|
|
|
169
185
|
// Every applicable fix in one edit, so one undo reverts them all. Stale fixes, fixes that would
|
|
170
186
|
// create an existing file, and fixes overlapping an earlier one are skipped whole.
|
|
171
187
|
function fixAllEdit(fixes, workspace) {
|
|
188
|
+
const error = fixTargetError(fixes);
|
|
189
|
+
if (error)
|
|
190
|
+
return { ...workspaceEdit([], workspace), applied: 0, skipped: fixes.length, error };
|
|
172
191
|
const claimed = new Map();
|
|
173
192
|
const operations = [];
|
|
174
193
|
let applied = 0;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { writeResolvedFileAtomic } from '../shared/system/atomic-write.js';
|
|
4
|
+
import { editorDataDirectory, ensureEditorServer } from './setup-server.js';
|
|
5
|
+
const languageExtensions = {
|
|
6
|
+
javascript: ['js', 'mjs', 'cjs'],
|
|
7
|
+
javascriptreact: ['jsx'],
|
|
8
|
+
typescript: ['ts', 'mts', 'cts'],
|
|
9
|
+
typescriptreact: ['tsx'],
|
|
10
|
+
html: ['html', 'htm'],
|
|
11
|
+
vue: ['vue'],
|
|
12
|
+
svelte: ['svelte'],
|
|
13
|
+
python: ['py'],
|
|
14
|
+
go: ['go'],
|
|
15
|
+
java: ['java'],
|
|
16
|
+
csharp: ['cs'],
|
|
17
|
+
rust: ['rs'],
|
|
18
|
+
ruby: ['rb'],
|
|
19
|
+
php: ['php'],
|
|
20
|
+
kotlin: ['kt', 'kts'],
|
|
21
|
+
c: ['c', 'h'],
|
|
22
|
+
cpp: ['cc', 'cpp', 'cxx', 'hh', 'hpp', 'hxx'],
|
|
23
|
+
};
|
|
24
|
+
// LSP4IJ accepts a command line, and starts it directly. Quote paths for IntelliJ's argument parser.
|
|
25
|
+
function quotePath(filename) {
|
|
26
|
+
const portable = filename.split(path.sep).join('/');
|
|
27
|
+
return '"' + portable.replaceAll('"', '\\"') + '"';
|
|
28
|
+
}
|
|
29
|
+
export function writeJetBrainsTemplate(directory, node, cli) {
|
|
30
|
+
const template = {
|
|
31
|
+
id: 'loadwise',
|
|
32
|
+
name: 'Loadwise',
|
|
33
|
+
programArgs: { default: `${quotePath(node)} ${quotePath(cli)} lsp --stdio` },
|
|
34
|
+
fileTypeMappings: Object.entries(languageExtensions).map(([languageId, extensions]) => ({
|
|
35
|
+
fileType: { patterns: extensions.map((extension) => '*.' + extension) },
|
|
36
|
+
languageId,
|
|
37
|
+
})),
|
|
38
|
+
};
|
|
39
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
40
|
+
writeResolvedFileAtomic(path.join(directory, 'template.json'), JSON.stringify(template, null, 2) + '\n');
|
|
41
|
+
}
|
|
42
|
+
export async function setupJetBrains() {
|
|
43
|
+
const { command, args } = await ensureEditorServer();
|
|
44
|
+
const directory = path.join(editorDataDirectory(), 'jetbrains', 'loadwise');
|
|
45
|
+
writeJetBrainsTemplate(directory, command, args[0]);
|
|
46
|
+
return [
|
|
47
|
+
'Install the LSP4IJ plugin from Settings > Plugins in your JetBrains IDE.',
|
|
48
|
+
'In the LSP4IJ language server settings, choose +, then Template > Import from custom template.',
|
|
49
|
+
'Select this folder and confirm the Loadwise server:',
|
|
50
|
+
directory,
|
|
51
|
+
'Open a supported source file and check the Loadwise server in the LSP Consoles tool window.',
|
|
52
|
+
].join('\n');
|
|
53
|
+
}
|