mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-09-21 00:21:30 +00:00
fix: tree-sitter callback API for Python files >32 KB
This commit is contained in:
parent
368049576b
commit
f36ff72d8d
2 changed files with 10 additions and 3 deletions
|
|
@ -44,6 +44,7 @@ COPY --from=builder --chown=node:node /app/gitnexus/dist ./gitnexus/dist
|
|||
COPY --from=builder --chown=node:node /app/gitnexus/node_modules ./gitnexus/node_modules
|
||||
COPY --from=builder --chown=node:node /app/gitnexus/package.json ./gitnexus/package.json
|
||||
COPY --from=builder --chown=node:node /app/gitnexus/vendor ./gitnexus/vendor
|
||||
COPY --from=builder --chown=node:node /app/gitnexus/scripts ./gitnexus/scripts
|
||||
|
||||
USER node
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ import { getPythonParser, getPythonScopeQuery } from './query.js';
|
|||
import { synthesizeReceiverTypeBinding } from './receiver-binding.js';
|
||||
import { computePythonArityMetadata } from './arity-metadata.js';
|
||||
import { recordCacheHit, recordCacheMiss } from './cache-stats.js';
|
||||
import { getTreeSitterBufferSize } from '../../constants.js';
|
||||
import { Buffer } from 'node:buffer';
|
||||
import { getTreeSitterContentByteLength } from '../../constants.js';
|
||||
import { pythonFunctionDefinitionLabel } from './simple-hooks.js';
|
||||
|
||||
export function emitPythonScopeCaptures(
|
||||
|
|
@ -39,8 +40,13 @@ export function emitPythonScopeCaptures(
|
|||
let tree = cachedTree as ReturnType<ReturnType<typeof getPythonParser>['parse']> | undefined;
|
||||
if (tree === undefined) {
|
||||
try {
|
||||
tree = getPythonParser().parse(sourceText, undefined, {
|
||||
bufferSize: getTreeSitterBufferSize(sourceText),
|
||||
// Callback form avoids the NAPI bufferSize bug in tree-sitter 0.21.x
|
||||
// that triggers "Invalid argument" on files larger than ~32 KB.
|
||||
const encoded = Buffer.from(sourceText, 'utf8');
|
||||
const byteLength = getTreeSitterContentByteLength(sourceText);
|
||||
tree = getPythonParser().parse((startIndex: number) => {
|
||||
if (startIndex >= byteLength) return '';
|
||||
return encoded.slice(startIndex, startIndex + 4096).toString('utf8');
|
||||
});
|
||||
} catch (err) {
|
||||
throw scopeExtractionError('parse', _filePath, err);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue