/*
 * 文件定位：storagePool / baseToolStorage / code.lsp_locateDefinition 共享依赖。
 * 核心目的：把 LSP 定义定位的共用 host 依赖和 provider practice 契约集中在一起。
 */
import { locateDefinitionWithLspRuntime } from "../_shared/runtime.js";
export const lspLocateDefinitionDependencyDeclarations = [
    {
        dependencyId: "host.executor.lsp.locateDefinition",
        kind: "service",
        required: false,
        description: "Optional host-provided LSP executor capable of issuing textDocument/definition requests.",
    },
    {
        dependencyId: "workspace.read",
        kind: "permission",
        required: true,
        description: "Read access to the target workspace file so the LSP server can resolve the symbol context.",
    },
    {
        dependencyId: "lsp.server.forTargetLanguage",
        kind: "runtime",
        required: true,
        description: "A language server configured for the target file language or extension.",
    },
    {
        dependencyId: "node.child_process.stdioJsonRpc",
        kind: "runtime",
        required: true,
        description: "Node.js stdio process runtime used by the built-in Praxis LSP runtime.",
    },
];
export function createHostExecutorLocateDefinitionProvider(executor) {
    const locateDefinition = executor?.lsp?.locateDefinition;
    if (locateDefinition === undefined) {
        return undefined;
    }
    return async (target, context) => {
        const result = await locateDefinition({
            target,
            context: {
                invocationId: context.invocationId,
                workspaceRoot: context.workspaceRoot,
                auditMetadata: context.auditMetadata,
            },
        });
        if (!result.ok) {
            throw new Error(result.error.message);
        }
        return result.output.locations.map((location) => ({
            ...location,
            source: "provider",
        }));
    };
}
export function createNativeLspRuntimeLocateDefinitionProvider(runtime = {}) {
    return async (target, context) => locateDefinitionWithLspRuntime(target, {
        ...runtime,
        workspaceRoot: runtime.workspaceRoot ?? context.workspaceRoot,
    });
}
