UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

2 lines • 1.98 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{A as t,K as n,O as r,it as i,k as a,m as o,x as s}from"./dist-CKGuiyqz.js";import{n as c,t as l}from"./code-language-DiXU7oGo.js";function u(e,t){let n=e[t]?.gap;if(!n||n.count<1||n.count>e.length-t-1)return!1;for(let r=0;r<n.count;r++){let i=e[t+r+1];if(i.kind!==`ctx`||i.lineNo!==n.newStart+r)return!1}return!0}async function d(e,t,i=t){let s=new Map,l=[],d=0;for(let t of e)if(d+=t.text.length+1,d>f)return{highlighted:s,folds:l};let p={path:t,oldPath:i,lines:[]},m=[];for(let t=0;t<e.length;t++){let n=e[t];n.kind===`skip`&&u(e,t)||(n.kind===`file`||n.kind===`skip`?(m.push(p),p=n.kind===`file`?{path:n.path??``,oldPath:n.oldPath??n.path??``,lines:[]}:{...p,lines:[]}):p.lines.push(n))}return m.push(p),await Promise.all(m.map(async e=>{if(e.lines.length)for(let t of[`add`,`del`]){let i=await c(t===`add`?e.oldPath:e.path);if(!i)continue;let u=e.lines.filter(e=>e.kind!==t),d=u.map(e=>e.text).join(` `),f=[[]],p=i.language.parser.parse(d),m=n.create({doc:d}),h=[],g=[];p.iterate({enter(e){e.type.isError&&g.push(e.from);let t=e.type.prop(o)?.(e.node,m);t&&h.push({...t,nodeFrom:e.from,nodeTo:e.to,function:/Function|Method|Class/.test(e.name)||/Function|Method|Class/.test(e.node.parent?.name??``)})}}),g.sort((e,t)=>e-t);for(let e of h){let n=0,r=g.length;for(;n<r;){let t=n+r>>>1;g[t]<e.nodeFrom?n=t+1:r=t}if(n<g.length&&g[n]<=e.nodeTo)continue;let i=m.doc.lineAt(e.nodeTo),a=e.nodeTo>0&&e.nodeTo===i.from?e.nodeTo-1:e.nodeTo,o=m.doc.lineAt(a);if(!/^[;,\s]*$/u.test(d.slice(a,o.to)))continue;let s=m.doc.lineAt(e.from).number-1,c=m.doc.lineAt(e.to).number-1;c>s&&u[s]&&u[c]&&l.push({start:u[s],end:u[c],side:t===`add`?`old`:`new`,function:e.function})}a(d,p,r,(e,t)=>f.at(-1).push({text:e,classes:t}),()=>{f.push([])}),u.forEach((e,n)=>{e.text&&(t===`del`||e.kind===`del`)&&s.set(e,f[n])})}})),{highlighted:s,folds:l}}var f;function p(){return(p=e((()=>{s(),i(),t(),l(),f=12e4})))()}p();export{d as analyzeDiffSyntax};