fix(sf): remove unwired native edit bridge
This commit is contained in:
parent
9f773815d1
commit
7e1eff46a2
1 changed files with 0 additions and 167 deletions
|
|
@ -1,167 +0,0 @@
|
|||
/**
|
||||
* native-edit-bridge.ts — Wire the Rust-backed edit engine from @singularity-forge/native
|
||||
* into the SF extension editing flows.
|
||||
*
|
||||
* Purpose: applyWorkspaceEdit and applyEdits (from @singularity-forge/native/edit)
|
||||
* provide atomic multi-file LSP-style edits with Rust-level staging and fsync.
|
||||
* This bridge makes them available to the SF edit tool so multi-file refactors
|
||||
* (rename, code-action) bypass the JavaScript read-splice-write loop.
|
||||
*
|
||||
* Consumer: tools/edit-tool-executor.ts (registered as an SF tool that delegates
|
||||
* to applyWorkspaceEdit for LSP rename/code-action results).
|
||||
*
|
||||
* Wire status (gap-audit.ts:124):
|
||||
* - applyEdits → imported here (native-edit-bridge.ts)
|
||||
* - applyWorkspaceEdit → imported here (native-edit-bridge.ts)
|
||||
* - replaceSymbol → imported here (native-edit-bridge.ts)
|
||||
* - insertAroundSymbol → imported here (native-edit-bridge.ts)
|
||||
*/
|
||||
|
||||
import { createRequire } from "node:module";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
type NativeEditModule = {
|
||||
applyEdits: (
|
||||
filePath: string,
|
||||
edits: unknown[],
|
||||
options?: unknown,
|
||||
) => unknown;
|
||||
applyWorkspaceEdit: (documentEdits: unknown[], options?: unknown) => unknown;
|
||||
replaceSymbol: (
|
||||
filePath: string,
|
||||
symbolPath: string,
|
||||
newBody: string,
|
||||
options?: unknown,
|
||||
) => unknown;
|
||||
insertAroundSymbol: (
|
||||
filePath: string,
|
||||
symbolPath: string,
|
||||
position: unknown,
|
||||
code: string,
|
||||
options?: unknown,
|
||||
) => unknown;
|
||||
};
|
||||
|
||||
let _native: NativeEditModule | null = null;
|
||||
let _loadAttempted = false;
|
||||
|
||||
function getNative(): NativeEditModule | null {
|
||||
if (_loadAttempted) return _native;
|
||||
_loadAttempted = true;
|
||||
try {
|
||||
// Dynamic require to avoid hard dependency; fails gracefully if native is not built.
|
||||
const mod = require("@singularity-forge/native") as NativeEditModule;
|
||||
if (
|
||||
mod.applyEdits &&
|
||||
mod.applyWorkspaceEdit &&
|
||||
mod.replaceSymbol &&
|
||||
mod.insertAroundSymbol
|
||||
) {
|
||||
_native = mod;
|
||||
}
|
||||
} catch {
|
||||
// Native module not available — callers fall back to JS edit
|
||||
}
|
||||
return _native;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the native edit engine can be loaded in this runtime.
|
||||
*
|
||||
* Purpose: let edit tools choose the Rust-backed path only when the optional
|
||||
* native package is present, preserving JS fallback behavior in dev shells.
|
||||
*
|
||||
* Consumer: SF edit executors before dispatching multi-file workspace edits.
|
||||
*/
|
||||
export function isNativeEditAvailable(): boolean {
|
||||
return getNative() !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply LSP-style TextEdit entries to one file atomically (Rust-backed).
|
||||
*
|
||||
* Purpose: expose atomic native single-file edit application without making
|
||||
* the SF extension hard-depend on a built native package.
|
||||
*
|
||||
* Consumer: SF edit executors for file-scoped LSP text edits.
|
||||
*
|
||||
* Falls back to null when the native module is unavailable.
|
||||
*/
|
||||
export function nativeApplyEdits(
|
||||
filePath: string,
|
||||
edits: unknown[],
|
||||
options?: unknown,
|
||||
): unknown {
|
||||
const native = getNative();
|
||||
if (!native) return null;
|
||||
return native.applyEdits(filePath, edits, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply LSP-style workspace edits across multiple files (Rust-backed).
|
||||
*
|
||||
* Purpose: keep multi-file rename/code-action writes atomic when the native
|
||||
* engine is available.
|
||||
*
|
||||
* Consumer: SF edit executors for LSP workspace edit results.
|
||||
*
|
||||
* Falls back to null when the native module is unavailable.
|
||||
*/
|
||||
export function nativeApplyWorkspaceEdit(
|
||||
documentEdits: unknown[],
|
||||
options?: unknown,
|
||||
): unknown {
|
||||
const native = getNative();
|
||||
if (!native) return null;
|
||||
return native.applyWorkspaceEdit(documentEdits, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a symbol declaration by its semantic path (Rust-backed).
|
||||
*
|
||||
* Purpose: make semantic symbol replacement available to SF tools without
|
||||
* duplicating parser/edit logic in TypeScript.
|
||||
*
|
||||
* Consumer: SF edit executors for native symbol-aware rewrites.
|
||||
*
|
||||
* Falls back to null when the native module is unavailable.
|
||||
*/
|
||||
export function nativeReplaceSymbol(
|
||||
filePath: string,
|
||||
symbolPath: string,
|
||||
newBody: string,
|
||||
options?: unknown,
|
||||
): unknown {
|
||||
const native = getNative();
|
||||
if (!native) return null;
|
||||
return native.replaceSymbol(filePath, symbolPath, newBody, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert code around a symbol declaration (Rust-backed).
|
||||
*
|
||||
* Purpose: make symbol-adjacent insertions available to SF tools without
|
||||
* duplicating parser/edit logic in TypeScript.
|
||||
*
|
||||
* Consumer: SF edit executors for native symbol-aware insertions.
|
||||
*
|
||||
* Falls back to null when the native module is unavailable.
|
||||
*/
|
||||
export function nativeInsertAroundSymbol(
|
||||
filePath: string,
|
||||
symbolPath: string,
|
||||
position: unknown,
|
||||
code: string,
|
||||
options?: unknown,
|
||||
): unknown {
|
||||
const native = getNative();
|
||||
if (!native) return null;
|
||||
return native.insertAroundSymbol(
|
||||
filePath,
|
||||
symbolPath,
|
||||
position,
|
||||
code,
|
||||
options,
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue