refakts
Version:
TypeScript refactoring tool built for AI coding agents to perform precise refactoring operations via command line instead of requiring complete code regeneration.
59 lines • 2.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TSQueryNodeFinder = void 0;
const node_finder_1 = require("./node-finder");
const ast_service_1 = require("../services/ast-service");
const expression_locator_1 = require("../locators/expression-locator");
class TSQueryNodeFinder extends node_finder_1.NodeFinder {
constructor() {
super();
this.astService = new ast_service_1.ASTService();
this.expressionLocator = new expression_locator_1.ExpressionLocator(this.astService.getProject());
}
findNodes(file, pattern) {
const sourceFile = this.astService.loadSourceFile(file);
const nodes = this.astService.findNodesByQuery(sourceFile, pattern);
const matches = this.createNodeMatches(sourceFile, nodes);
return {
query: pattern,
matches
};
}
async findExpressions(file, pattern) {
const result = await this.expressionLocator.findExpressions(file, pattern);
const serializableMatches = this.createSerializableExpressionMatches(result.matches);
return {
query: result.query,
matches: serializableMatches
};
}
createNodeMatches(sourceFile, nodes) {
return nodes.map(node => this.createNodeMatch(sourceFile, node));
}
createNodeMatch(sourceFile, node) {
const location = sourceFile.getLineAndColumnAtPos(node.getStart());
return {
kind: node.getKindName(),
text: this.truncateText(node.getText()),
line: location.line,
column: location.column
};
}
createSerializableExpressionMatches(matches) {
return matches.map(match => ({
expression: match.expression,
type: match.type,
line: match.line,
column: match.column,
scope: match.scope
}));
}
truncateText(text) {
const maxLength = 50;
if (text.length <= maxLength)
return text;
return text.substring(0, maxLength) + '...';
}
}
exports.TSQueryNodeFinder = TSQueryNodeFinder;
//# sourceMappingURL=tsquery-node-finder.js.map