@eagleoutice/flowr-dev
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
37 lines • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.computeReparseInfo = computeReparseInfo;
const edit_computation_1 = require("./edit-computation");
/**
* Computes the information needed to reparse a file incrementally with tree-sitter.
* Returns `undefined` if incremental reparsing is not possible.
*/
function computeReparseInfo(ctx, filePath) {
const previousTree = ctx.inc.getOldParseResultOf(filePath);
if (!previousTree) {
// this file was not parsed before
return undefined;
}
const oldContent = ctx.inc.getOldContentOf(filePath);
if (oldContent === undefined) {
// this file has not been invalidated since the last parse, no reparse needed
return {
previousTree,
editRegion: undefined
};
}
const newContent = ctx.files.resolveRequest({ request: 'file', content: filePath }).r.content;
if (newContent === oldContent) {
// this file was invalidated, but the content did not change, no reparse needed
return {
previousTree,
editRegion: undefined
};
}
const editRegion = (0, edit_computation_1.computeEditRegion)(oldContent, newContent);
return {
previousTree,
editRegion
};
}
//# sourceMappingURL=incremental-parse.js.map