import{s as e}from"./chunk-Bj-mKKzh.js";import{co as t,lo as n}from"./app-server-manager-signals-Yn0WSnoY.js";import{n as r}from"./jsx-runtime-CiQ1k8xo.js";import{g as i,lt as a}from"./vscode-api-DjORcpSo.js";import{a as o}from"./app-server-manager-hooks-Ps3s58Nc.js";import{t as s}from"./use-platform-D2c1wBYs.js";import{t as c}from"./use-stable-callback-CvFJzJNa.js";import{t as l}from"./sortBy-pYogFIIk.js";import{t as u}from"./score-query-match-DQkgbjbU.js";var d=a(),f=e(l(),1),p=e(r(),1),m=new Set([`.git`,`.hg`,`.next`,`.pnpm-store`,`.svn`,`.turbo`,`.yarn`,`build`,`coverage`,`dist`,`node_modules`]);function h(e){let t=(0,d.c)(14),{hostId:n,includeDirectories:r,onFiles:i,query:a,roots:o}=e,l=r===void 0?!1:r,{platform:u}=s(),f;t[0]!==l||t[1]!==i||t[2]!==u||t[3]!==o?(f=e=>{o!=null&&i?.({files:v({files:e.files,includeDirectories:l,isWindowsHost:u===`windows`,query:e.query,roots:o}),query:e.query})},t[0]=l,t[1]=i,t[2]=u,t[3]=o,t[4]=f):f=t[4];let{response:p,isLoading:m}=g(n,o,a,c(f)),h=a.trim(),_=p!=null&&h.length>0?p:null,y;bb0:{if(_==null||o==null){y=null;break bb0}let e=u===`windows`,n;t[5]!==l||t[6]!==o||t[7]!==e||t[8]!==_.files||t[9]!==_.query?(n=v({files:_.files,includeDirectories:l,isWindowsHost:e,query:_.query,roots:o}),t[5]=l,t[6]=o,t[7]=e,t[8]=_.files,t[9]=_.query,t[10]=n):n=t[10],y=n}let b=y,x;return t[11]!==b||t[12]!==m?(x={files:b,isLoading:m},t[11]=b,t[12]=m,t[13]=x):x=t[13],x}var g=(e,t,n,r)=>{let a=(0,d.c)(24),s=o(e),[c,l]=(0,p.useState)(null),[u,f]=(0,p.useState)(!1),m=(0,p.useRef)(null),h=(0,p.useRef)(null),g=t!=null&&t.length>0,_;a[0]===t?_=a[1]:(_=t?.join(`\0`)??``,a[0]=t,a[1]=_);let v=_,y;a[2]!==s||a[3]!==r||a[4]!==t?(y=async()=>{if(t==null||t.length===0)return null;if(m.current!=null)return m.current;let e={};h.current=e;let n=s.createFuzzyFileSearchSession({roots:t,onUpdated:t=>{if(h.current!==e)return;let n={query:t.query,files:t.files};l(n),r(n),f(!0)},onCompleted:()=>{h.current===e&&f(!1)}}).catch(t=>{throw m.current===n&&(m.current=null),h.current===e&&(h.current=null),t});return m.current=n,n},a[2]=s,a[3]=r,a[4]=t,a[5]=y):y=a[5];let b=(0,p.useEffectEvent)(y),S;a[6]===Symbol.for(`react.memo_cache_sentinel`)?(S=async()=>{let e=m.current;e!=null&&(m.current=null,h.current=null,await(await e).stop())},a[6]=S):S=a[6];let C=(0,p.useEffectEvent)(S),w;a[7]===C?w=a[8]:(w=()=>(l(null),f(!1),()=>{C().catch(x)}),a[7]=C,a[8]=w);let T;a[9]!==s||a[10]!==v?(T=[s,v],a[9]=s,a[10]=v,a[11]=T):T=a[11],(0,p.useEffect)(w,T);let E;a[12]!==b||a[13]!==g||a[14]!==n?(E=()=>{let e=!1;return(async()=>{if(!g||n.length===0){l(null),f(!1);return}try{f(!0);let t=await b();if(e||t==null)return;await t.update(n)}catch(t){let n=t;e||(i.error(`Error fetching fuzzy file search`,{safe:{},sensitive:{error:n}}),f(!1))}})(),()=>{e=!0}},a[12]=b,a[13]=g,a[14]=n,a[15]=E):E=a[15];let D;a[16]!==g||a[17]!==s||a[18]!==n||a[19]!==v?(D=[g,s,n,v],a[16]=g,a[17]=s,a[18]=n,a[19]=v,a[20]=D):D=a[20],(0,p.useEffect)(E,D);let O;return a[21]!==u||a[22]!==c?(O={response:c,isLoading:u},a[21]=u,a[22]=c,a[23]=O):O=a[23],O};function _(e,t){return(e.match_type===`file`||t&&e.match_type===`directory`)&&!e.path.split(/[\\/]+/).some(e=>m.has(e))}function v({files:e,includeDirectories:t,isWindowsHost:n,query:r,roots:i}){return b(e.filter(e=>_(e,t)).map(e=>y(e,i.length>1,n)),r)}function y({file_name:e,match_type:r,path:i,root:a},o,s){let c=t({root:a,relativePath:i,includeWorkspaceRootLabel:o}),l=c.lastIndexOf(`/`);return{label:e,matchType:r,path:o?n(a,i,s):c,relativePathWithoutFileName:c.substring(0,l),fsPath:n(a,i,s)}}function b(e,t){let n=t.trim();return n.length===0?e:(0,f.default)(e.map((e,t)=>({file:e,score:u(e.label,n),index:t})),[e=>-e.score,e=>e.file.label,e=>e.index]).map(e=>e.file)}function x(e){i.warning(`Failed to close fuzzy file search session`,{safe:{},sensitive:{error:e}})}export{h as t};
//# sourceMappingURL=use-workspace-file-search-COvYDJrS.js.map