MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / renderSnippet

Function renderSnippet

lib/command/query.js:172–194  ·  view source on GitHub ↗
(node, source, snippetLen, full)

Source from the content-addressed store, hash-verified

170}
171
172function renderSnippet(node, source, snippetLen, full) {
173 if (typeof node.__startOffset !== 'number') {
174 try {
175 return new XMLSerializer().serializeToString(node)
176 } catch {
177 return `<${node.nodeName || '?'}>`
178 }
179 }
180 const start = node.__startOffset
181 const end = node.__endOffset ?? start
182 if (full) return source.slice(start, end)
183
184 const tagEnd = node.__startTagEndOffset ?? end
185 const openingTag = source.slice(start, tagEnd)
186 if (end <= tagEnd) return openingTag
187
188 const totalLen = end - start
189 if (totalLen <= snippetLen) return source.slice(start, end)
190
191 const remaining = Math.max(0, snippetLen - openingTag.length)
192 if (remaining < 20) return openingTag + ' …'
193 return openingTag + source.slice(tagEnd, tagEnd + remaining) + ' …'
194}
195
196function readStdin() {
197 return new Promise((resolve, reject) => {

Callers 1

queryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…