import { hoverTooltip } from '../../../../../../@codemirror_view@6.28.6/node_modules/@codemirror/view/dist/index.js';
import '../index.js';
import { defaultRenderer } from './renderTooltip.js';
import { tsFacetWorker } from '../facet/tsFacetWorker.js';

/**
 * This binds the CodeMirror `hoverTooltip` method
 * with a code that pulls types and documentation
 * from the TypeScript environment.
 */
function tsHoverWorker({ renderTooltip = defaultRenderer, } = {}) {
    return hoverTooltip(async (view, pos) => {
        const config = view.state.facet(tsFacetWorker);
        if (!config?.worker)
            return null;
        const hoverData = await config.worker.getHover({
            path: config.path,
            pos,
        });
        if (!hoverData)
            return null;
        return {
            pos: hoverData.start,
            end: hoverData.end,
            create: () => renderTooltip(hoverData, view),
        };
    });
}

export { tsHoverWorker };
