@mrclrchtr/supi-code-intelligence 11.4.0 → 12.0.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/CHANGELOG.md +22 -0
- package/README.md +13 -7
- package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +1 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +51 -23
- package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/README.md +21 -16
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +1 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +51 -23
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
- package/node_modules/@mrclrchtr/supi-lsp/src/api.ts +2 -2
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-capabilities.ts +13 -3
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +25 -9
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-sync.ts +7 -5
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-edit-capture.ts +258 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +64 -11
- package/node_modules/@mrclrchtr/supi-lsp/src/config/capabilities.ts +8 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/config/operation-support.ts +48 -79
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +3 -1
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-refactor-provider.ts +21 -35
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-command-capture.ts +139 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-planning.ts +202 -47
- package/node_modules/@mrclrchtr/supi-lsp/src/session/route-boundary.ts +26 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +57 -12
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-rename.ts +3 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/session/workspace-lsp-runtime.ts +22 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +1 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +51 -23
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/coordinates.ts +16 -2
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-client.ts +3 -2
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/syntax-errors.ts +2 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-range.ts +94 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-sites.ts +26 -6
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callees.ts +6 -3
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/exports.ts +13 -4
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime.ts +1 -9
- package/package.json +5 -5
- package/src/analysis/health/server-status.ts +41 -12
- package/src/analysis/target/anchored-structural.ts +4 -1
- package/src/analysis/target/symbol.ts +1 -1
- package/src/session/find-types.ts +8 -4
- package/src/session/find-workflow.ts +11 -16
- package/src/session/input/health-refactor.ts +48 -34
- package/src/session/input/workflows.ts +45 -46
- package/src/session/inspect/file-point.ts +2 -2
- package/src/session/inspect-types.ts +1 -1
- package/src/session/inspect-workflow.ts +3 -3
- package/src/session/refactor-file-actions.ts +122 -0
- package/src/session/refactor-plan-pipeline.ts +152 -0
- package/src/session/refactor-plans.ts +18 -15
- package/src/session/refactor-types.ts +24 -12
- package/src/session/refactor-workflow.ts +68 -243
- package/src/tool/code_find/execute.ts +6 -7
- package/src/tool/code_find/spec.ts +9 -16
- package/src/tool/code_find/tui.ts +12 -6
- package/src/tool/code_graph/spec.ts +6 -0
- package/src/tool/code_health/spec.ts +6 -0
- package/src/tool/code_health/structured-schema.ts +4 -4
- package/src/tool/code_health/structured.ts +15 -17
- package/src/tool/code_inspect/execute.ts +1 -1
- package/src/tool/code_inspect/markdown.ts +33 -6
- package/src/tool/code_inspect/result.ts +1 -1
- package/src/tool/code_inspect/spec.ts +14 -6
- package/src/tool/code_inspect/structured.ts +2 -2
- package/src/tool/code_inspect/tui.ts +2 -2
- package/src/tool/code_orientation/spec.ts +8 -0
- package/src/tool/code_refactor_apply/result.ts +2 -1
- package/src/tool/code_refactor_apply/spec.ts +7 -0
- package/src/tool/code_refactor_plan/execute.ts +0 -2
- package/src/tool/code_refactor_plan/result.ts +23 -13
- package/src/tool/code_refactor_plan/spec.ts +8 -2
- package/src/tool/code_refactor_plan/structured.ts +59 -12
- package/src/tool/code_refactor_plan/tui.ts +14 -17
- package/src/tool/code_resolve/markdown.ts +1 -1
- package/src/tool/code_resolve/spec.ts +6 -0
- package/src/tool/namespace.ts +14 -0
- package/src/tool/refactor-markdown.ts +55 -15
- package/src/tool/register.ts +3 -0
- package/src/tool/result/refactor-preview.ts +118 -0
- package/src/tool/result/refactor-unavailable.ts +16 -0
- package/src/tool/result/refactor.ts +8 -2
- package/src/tool/schemas.ts +63 -20
- package/src/tool/specs.ts +3 -0
- package/src/ui/status-overlay.ts +1 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/** Code- and source-action refactor planning for one named file. */
|
|
2
|
+
|
|
3
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
4
|
+
import type { RefactorRequest, SourceRange } from "@mrclrchtr/supi-code-runtime/api";
|
|
5
|
+
import { toLspPosition } from "@mrclrchtr/supi-lsp/api";
|
|
6
|
+
import { normalizePath } from "../analysis/search/paths.ts";
|
|
7
|
+
import {
|
|
8
|
+
ensureFileReadiness,
|
|
9
|
+
finishProviderPlan,
|
|
10
|
+
planWithProvider,
|
|
11
|
+
type RefactorWorkflowDeps,
|
|
12
|
+
} from "./refactor-plan-pipeline.ts";
|
|
13
|
+
import type {
|
|
14
|
+
PublicSourceRange,
|
|
15
|
+
RefactorOperationInput,
|
|
16
|
+
RefactorPlanWorkflowOutcome,
|
|
17
|
+
} from "./refactor-types.ts";
|
|
18
|
+
import { reportProgress, throwIfAborted, type WorkflowControl } from "./workflow-control.ts";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Plan one code or source action. These operations name a file directly and
|
|
22
|
+
* never resolve a symbol target; source actions cover the whole document.
|
|
23
|
+
*/
|
|
24
|
+
export async function planFileAction(
|
|
25
|
+
operation: Exclude<RefactorOperationInput, { rename_symbol: unknown }>,
|
|
26
|
+
deps: RefactorWorkflowDeps,
|
|
27
|
+
control?: WorkflowControl,
|
|
28
|
+
): Promise<RefactorPlanWorkflowOutcome> {
|
|
29
|
+
const { name, selection, range } =
|
|
30
|
+
"code_action" in operation
|
|
31
|
+
? {
|
|
32
|
+
name: "code_action" as const,
|
|
33
|
+
selection: operation.code_action,
|
|
34
|
+
range: operation.code_action.range,
|
|
35
|
+
}
|
|
36
|
+
: { name: "source_action" as const, selection: operation.source_action, range: undefined };
|
|
37
|
+
const file = normalizePath(selection.file, deps.cwd);
|
|
38
|
+
const fileError = validateActionFile(file, selection.file, `operation.${name}.file`);
|
|
39
|
+
if (fileError) return { kind: "invalid-input", message: fileError };
|
|
40
|
+
const rangeError = range
|
|
41
|
+
? validateRangeWithinFile(file, selection.file, range, `operation.${name}.range`)
|
|
42
|
+
: null;
|
|
43
|
+
if (rangeError) return { kind: "invalid-input", message: rangeError };
|
|
44
|
+
|
|
45
|
+
const readiness = await ensureFileReadiness(file, deps, control);
|
|
46
|
+
if (readiness) return readiness;
|
|
47
|
+
reportProgress(control, {
|
|
48
|
+
intent: "refactor-plan",
|
|
49
|
+
phase: "provider",
|
|
50
|
+
message: `Requesting ${selection.kind} code actions`,
|
|
51
|
+
});
|
|
52
|
+
const action = {
|
|
53
|
+
file,
|
|
54
|
+
kind: selection.kind,
|
|
55
|
+
...(selection.title === undefined ? {} : { title: selection.title }),
|
|
56
|
+
};
|
|
57
|
+
const request: RefactorRequest = range
|
|
58
|
+
? { operation: "code_action", ...action, range: toLspRange(range) }
|
|
59
|
+
: { operation: "source_action", ...action };
|
|
60
|
+
const result = await planWithProvider(
|
|
61
|
+
deps.capability.getSemanticProvider(deps.cwd),
|
|
62
|
+
request,
|
|
63
|
+
control,
|
|
64
|
+
);
|
|
65
|
+
throwIfAborted(control);
|
|
66
|
+
return finishProviderPlan(result, deps, {
|
|
67
|
+
operation: name,
|
|
68
|
+
file,
|
|
69
|
+
discriminator: `${selection.kind}:${selection.title ?? ""}:${JSON.stringify(range ?? null)}`,
|
|
70
|
+
fields: range ? { range } : {},
|
|
71
|
+
evidenceSource: "semantic",
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Check that an action file exists and is a file. The routed language server
|
|
77
|
+
* enforces its own project root before any request.
|
|
78
|
+
*/
|
|
79
|
+
function validateActionFile(file: string, input: string, label: string): string | null {
|
|
80
|
+
if (!existsSync(file)) return `File not found: \`${input}\``;
|
|
81
|
+
if (statSync(file).isDirectory()) {
|
|
82
|
+
return `${label} must be a file, not a directory: \`${input}\`.`;
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Check that both range ends lie inside the file's current disk text, so an
|
|
89
|
+
* out-of-range position fails as input instead of as a server error. Positions
|
|
90
|
+
* are one-based UTF-16; a line's maximum character is one past its last character.
|
|
91
|
+
*/
|
|
92
|
+
function validateRangeWithinFile(
|
|
93
|
+
file: string,
|
|
94
|
+
input: string,
|
|
95
|
+
range: PublicSourceRange,
|
|
96
|
+
label: string,
|
|
97
|
+
): string | null {
|
|
98
|
+
let lines: string[];
|
|
99
|
+
try {
|
|
100
|
+
lines = readFileSync(file, "utf-8").split(/\r\n|\r|\n/);
|
|
101
|
+
} catch {
|
|
102
|
+
return `Cannot read file: \`${input}\``;
|
|
103
|
+
}
|
|
104
|
+
for (const end of ["start", "end"] as const) {
|
|
105
|
+
const { line, character } = range[end];
|
|
106
|
+
if (line > lines.length) {
|
|
107
|
+
return `${label}.${end} line ${line} is beyond the end of \`${input}\` (${lines.length} lines).`;
|
|
108
|
+
}
|
|
109
|
+
const maximum = (lines[line - 1] ?? "").length + 1;
|
|
110
|
+
if (character > maximum) {
|
|
111
|
+
return `${label}.${end} character ${character} is beyond line ${line} of \`${input}\` (maximum ${maximum}, 1-based UTF-16).`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function toLspRange(range: PublicSourceRange): SourceRange {
|
|
118
|
+
return {
|
|
119
|
+
start: toLspPosition(range.start.line, range.start.character),
|
|
120
|
+
end: toLspPosition(range.end.line, range.end.character),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/** Shared refactor-plan pipeline: provider calls, readiness, validation, and plan storage. */
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
RefactorOperation,
|
|
5
|
+
RefactorRequest,
|
|
6
|
+
RefactorResult,
|
|
7
|
+
SemanticProvider,
|
|
8
|
+
} from "@mrclrchtr/supi-code-runtime/api";
|
|
9
|
+
import { SEMANTIC_READINESS_TIMEOUT_REASON } from "../analysis/readiness.ts";
|
|
10
|
+
import { establishMutationAuthority } from "../analysis/refactor/mutation-authority.ts";
|
|
11
|
+
import { validateEdit } from "../analysis/refactor/safety.ts";
|
|
12
|
+
import type { CapabilityAdapter } from "./capability-adapter.ts";
|
|
13
|
+
import { collectFileFingerprints, dropIdentityEdits } from "./refactor-identity.ts";
|
|
14
|
+
import {
|
|
15
|
+
generatePlanId,
|
|
16
|
+
type RefactorPlan,
|
|
17
|
+
validateSynchronizedContentFingerprints,
|
|
18
|
+
} from "./refactor-plans.ts";
|
|
19
|
+
import type { RefactorPlanWorkflowOutcome } from "./refactor-types.ts";
|
|
20
|
+
import type { TargetWorkflowDeps } from "./target-workflow.ts";
|
|
21
|
+
import { throwIfAborted, type WorkflowControl } from "./workflow-control.ts";
|
|
22
|
+
|
|
23
|
+
/** Session collaborators for refactor planning and apply workflows. */
|
|
24
|
+
export interface RefactorWorkflowDeps extends TargetWorkflowDeps {
|
|
25
|
+
readonly capability: CapabilityAdapter;
|
|
26
|
+
readonly storePlan: (plan: RefactorPlan) => string;
|
|
27
|
+
readonly getPlan: (id: string) => RefactorPlan | undefined;
|
|
28
|
+
readonly removePlan: (id: string) => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Wait for semantic readiness for one file; returns an outcome only when planning must stop. */
|
|
32
|
+
export async function ensureFileReadiness(
|
|
33
|
+
file: string,
|
|
34
|
+
deps: RefactorWorkflowDeps,
|
|
35
|
+
control?: WorkflowControl,
|
|
36
|
+
): Promise<RefactorPlanWorkflowOutcome | null> {
|
|
37
|
+
const readiness = await deps.capability.ensureSemanticReadiness(
|
|
38
|
+
deps.cwd,
|
|
39
|
+
{ kind: "file", file },
|
|
40
|
+
control,
|
|
41
|
+
);
|
|
42
|
+
throwIfAborted(control);
|
|
43
|
+
if (readiness.kind === "timeout") {
|
|
44
|
+
return { kind: "unavailable", reason: SEMANTIC_READINESS_TIMEOUT_REASON };
|
|
45
|
+
}
|
|
46
|
+
if (readiness.kind === "unavailable") return readiness;
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Validate a provider result and store it as a fingerprinted plan. */
|
|
51
|
+
export async function finishProviderPlan(
|
|
52
|
+
result: RefactorResult,
|
|
53
|
+
deps: RefactorWorkflowDeps,
|
|
54
|
+
plan: {
|
|
55
|
+
readonly operation: RefactorOperation;
|
|
56
|
+
readonly file: string;
|
|
57
|
+
readonly discriminator: string;
|
|
58
|
+
readonly fields: Pick<RefactorPlan, "newName" | "target" | "range">;
|
|
59
|
+
readonly evidenceSource: "semantic" | "structural";
|
|
60
|
+
readonly sourceFingerprint?: string;
|
|
61
|
+
},
|
|
62
|
+
): Promise<RefactorPlanWorkflowOutcome> {
|
|
63
|
+
if (result.kind === "unavailable") return { kind: "unavailable", reason: result.reason };
|
|
64
|
+
if (result.kind === "ambiguous") {
|
|
65
|
+
return { kind: "ambiguous", candidates: result.candidates };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const validation = validateEdit(result.edits);
|
|
69
|
+
if (!validation.safe) {
|
|
70
|
+
return { kind: "invalid-input", message: `Refactor safety check failed: ${validation.reason}` };
|
|
71
|
+
}
|
|
72
|
+
const authority = establishMutationAuthority(
|
|
73
|
+
result.edits.edits.map((edit) => edit.file),
|
|
74
|
+
result.authorizedMutationRoots,
|
|
75
|
+
);
|
|
76
|
+
if (authority.kind === "unavailable") return authority;
|
|
77
|
+
const fileFingerprints = collectFileFingerprints(
|
|
78
|
+
result.edits.edits,
|
|
79
|
+
plan.sourceFingerprint ? { file: plan.file, fingerprint: plan.sourceFingerprint } : undefined,
|
|
80
|
+
);
|
|
81
|
+
const snapshotError = validateSynchronizedContentFingerprints(
|
|
82
|
+
result.edits.documentPreconditions,
|
|
83
|
+
fileFingerprints,
|
|
84
|
+
deps.cwd,
|
|
85
|
+
);
|
|
86
|
+
if (snapshotError) return { kind: "unavailable", reason: snapshotError };
|
|
87
|
+
const changed = dropIdentityEdits(result.edits, fileFingerprints);
|
|
88
|
+
if (changed.kind === "unavailable") return changed;
|
|
89
|
+
if (changed.edits.edits.length === 0) {
|
|
90
|
+
return {
|
|
91
|
+
kind: "invalid-input",
|
|
92
|
+
message: `The ${plan.operation} refactor produces no changes; every planned edit matches the current text.`,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const stored: RefactorPlan = {
|
|
97
|
+
id: generatePlanId(plan.operation, plan.file, plan.discriminator),
|
|
98
|
+
operation: plan.operation,
|
|
99
|
+
file: plan.file,
|
|
100
|
+
...plan.fields,
|
|
101
|
+
...(result.action ? { action: { ...result.action } } : {}),
|
|
102
|
+
edits: changed.edits,
|
|
103
|
+
evidenceSource: plan.evidenceSource,
|
|
104
|
+
authorizedMutationRoots: authority.canonicalRoots,
|
|
105
|
+
fileFingerprints: changed.fileFingerprints,
|
|
106
|
+
createdAt: Date.now(),
|
|
107
|
+
};
|
|
108
|
+
deps.storePlan(stored);
|
|
109
|
+
return { kind: "completed", plan: immutablePlan(stored) };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Ask the active semantic provider for one refactor result. */
|
|
113
|
+
export async function planWithProvider(
|
|
114
|
+
provider: SemanticProvider | null,
|
|
115
|
+
request: RefactorRequest,
|
|
116
|
+
control?: WorkflowControl,
|
|
117
|
+
): Promise<RefactorResult> {
|
|
118
|
+
if (!provider) return { kind: "unavailable", reason: "No semantic provider is active." };
|
|
119
|
+
if (provider.refactor) return provider.refactor(request, control);
|
|
120
|
+
if (request.operation === "rename_symbol" && provider.rename) {
|
|
121
|
+
return provider.rename(request.file, request.position, request.newName, control);
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
kind: "unavailable",
|
|
125
|
+
reason: `The semantic provider cannot plan ${request.operation}.`,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Freeze a stored plan before it leaves the session. */
|
|
130
|
+
export function immutablePlan(plan: RefactorPlan): Readonly<RefactorPlan> {
|
|
131
|
+
return Object.freeze({
|
|
132
|
+
...plan,
|
|
133
|
+
...(plan.target ? { target: Object.freeze({ ...plan.target }) } : {}),
|
|
134
|
+
...(plan.range ? { range: Object.freeze({ ...plan.range }) } : {}),
|
|
135
|
+
...(plan.action ? { action: Object.freeze({ ...plan.action }) } : {}),
|
|
136
|
+
edits: Object.freeze({
|
|
137
|
+
...plan.edits,
|
|
138
|
+
edits: Object.freeze(plan.edits.edits.map((edit) => Object.freeze({ ...edit }))),
|
|
139
|
+
documentPreconditions: plan.edits.documentPreconditions
|
|
140
|
+
? Object.freeze(
|
|
141
|
+
plan.edits.documentPreconditions.map((precondition) =>
|
|
142
|
+
Object.freeze({ ...precondition }),
|
|
143
|
+
),
|
|
144
|
+
)
|
|
145
|
+
: undefined,
|
|
146
|
+
}),
|
|
147
|
+
authorizedMutationRoots: Object.freeze([...plan.authorizedMutationRoots]),
|
|
148
|
+
fileFingerprints: Object.freeze(
|
|
149
|
+
plan.fileFingerprints.map((fingerprint) => Object.freeze({ ...fingerprint })),
|
|
150
|
+
),
|
|
151
|
+
}) as Readonly<RefactorPlan>;
|
|
152
|
+
}
|
|
@@ -8,17 +8,27 @@
|
|
|
8
8
|
|
|
9
9
|
import { createHash } from "node:crypto";
|
|
10
10
|
import { readFileSync } from "node:fs";
|
|
11
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
RefactorActionIdentity,
|
|
13
|
+
RefactorOperation,
|
|
14
|
+
WorkspaceEdit,
|
|
15
|
+
} from "@mrclrchtr/supi-code-runtime/api";
|
|
12
16
|
import { toDisplayPath } from "../analysis/search/paths.ts";
|
|
17
|
+
import type { PublicSourceRange } from "./refactor-types.ts";
|
|
13
18
|
|
|
14
19
|
export interface RefactorPlan {
|
|
15
20
|
id: string;
|
|
16
21
|
operation: RefactorOperation;
|
|
22
|
+
/** Absolute file the operation was requested for. */
|
|
23
|
+
file: string;
|
|
24
|
+
/** `rename_symbol`: the requested name. */
|
|
17
25
|
newName?: string;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
/** `rename_symbol`: one-based target position in `file`. */
|
|
27
|
+
target?: { line: number; character: number };
|
|
28
|
+
/** `code_action`: the one-based requested range in `file`. */
|
|
29
|
+
range?: PublicSourceRange;
|
|
30
|
+
/** `code_action` / `source_action`: the selected server action. */
|
|
31
|
+
action?: RefactorActionIdentity;
|
|
22
32
|
edits: WorkspaceEdit;
|
|
23
33
|
/** Evidence source used to compose this plan. */
|
|
24
34
|
evidenceSource?: "semantic" | "structural";
|
|
@@ -56,17 +66,10 @@ export function validateSynchronizedContentFingerprints(
|
|
|
56
66
|
return null;
|
|
57
67
|
}
|
|
58
68
|
|
|
59
|
-
/** Generate a
|
|
60
|
-
|
|
61
|
-
export function generatePlanId(
|
|
62
|
-
operation: string,
|
|
63
|
-
file: string,
|
|
64
|
-
line: number,
|
|
65
|
-
character: number,
|
|
66
|
-
discriminator: string = "",
|
|
67
|
-
): string {
|
|
69
|
+
/** Generate a plan id from operation details and a time discriminator. */
|
|
70
|
+
export function generatePlanId(operation: string, file: string, discriminator: string): string {
|
|
68
71
|
const hash = createHash("sha256")
|
|
69
|
-
.update(`${operation}:${file}:${
|
|
72
|
+
.update(`${operation}:${file}:${discriminator}:${Date.now()}`)
|
|
70
73
|
.digest("hex")
|
|
71
74
|
.slice(0, 12);
|
|
72
75
|
return `plan-${hash}`;
|
|
@@ -6,38 +6,50 @@ import type { RefactorTargetInput, SourcePointInput } from "./target-input.ts";
|
|
|
6
6
|
/** Public refactor operations exposed by code_refactor_plan. */
|
|
7
7
|
export const PUBLIC_REFACTOR_OPERATION_NAMES = [
|
|
8
8
|
"rename_symbol",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"update_imports",
|
|
12
|
-
"delete_dead_code",
|
|
9
|
+
"code_action",
|
|
10
|
+
"source_action",
|
|
13
11
|
] as const;
|
|
14
12
|
|
|
15
13
|
export type PublicRefactorOperationName = (typeof PUBLIC_REFACTOR_OPERATION_NAMES)[number];
|
|
16
14
|
|
|
15
|
+
/** One-based public source range; the end is exclusive. */
|
|
17
16
|
export interface PublicSourceRange {
|
|
18
17
|
readonly start: Omit<SourcePointInput, "file">;
|
|
19
18
|
readonly end: Omit<SourcePointInput, "file">;
|
|
20
19
|
}
|
|
21
20
|
|
|
21
|
+
/**
|
|
22
|
+
* One refactor operation with its own scope. Only `rename_symbol` needs a
|
|
23
|
+
* symbol target; code and source actions name a file directly.
|
|
24
|
+
*/
|
|
22
25
|
export type RefactorOperationInput =
|
|
23
|
-
| { readonly rename_symbol: { readonly newName: string } }
|
|
24
26
|
| {
|
|
25
|
-
readonly
|
|
27
|
+
readonly rename_symbol: {
|
|
28
|
+
readonly target: RefactorTargetInput;
|
|
26
29
|
readonly newName: string;
|
|
27
|
-
readonly range: PublicSourceRange;
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
32
|
| {
|
|
31
|
-
readonly
|
|
32
|
-
readonly
|
|
33
|
+
readonly code_action: {
|
|
34
|
+
readonly file: string;
|
|
33
35
|
readonly range: PublicSourceRange;
|
|
36
|
+
/** CodeActionKind prefix under `refactor`. */
|
|
37
|
+
readonly kind: string;
|
|
38
|
+
/** Exact action title that selects one matching action. */
|
|
39
|
+
readonly title?: string;
|
|
34
40
|
};
|
|
35
41
|
}
|
|
36
|
-
| {
|
|
37
|
-
|
|
42
|
+
| {
|
|
43
|
+
readonly source_action: {
|
|
44
|
+
readonly file: string;
|
|
45
|
+
/** CodeActionKind prefix under `source`. */
|
|
46
|
+
readonly kind: string;
|
|
47
|
+
/** Exact action title that selects one matching action. */
|
|
48
|
+
readonly title?: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
38
51
|
|
|
39
52
|
export interface RefactorPlanWorkflowInput {
|
|
40
|
-
readonly target: RefactorTargetInput;
|
|
41
53
|
readonly operation: RefactorOperationInput;
|
|
42
54
|
}
|
|
43
55
|
|