@imenam/refactoring-mcp 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +36 -5
- package/dist/utils/outline.js +59 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -38,6 +38,24 @@ const OutlineSchema = z.object({
|
|
|
38
38
|
filePath: z
|
|
39
39
|
.string()
|
|
40
40
|
.describe("Chemin absolu complet du fichier à analyser"),
|
|
41
|
+
depth: z
|
|
42
|
+
.number()
|
|
43
|
+
.int()
|
|
44
|
+
.min(0)
|
|
45
|
+
.optional()
|
|
46
|
+
.describe("Optionnel : profondeur maximale des symboles à retourner. 0 = premier niveau uniquement (classes, fonctions top-level), 1 = +1 niveau imbriqué (méthodes d'une classe), etc. Par défaut : tous les niveaux."),
|
|
47
|
+
startLine: z
|
|
48
|
+
.number()
|
|
49
|
+
.int()
|
|
50
|
+
.positive()
|
|
51
|
+
.optional()
|
|
52
|
+
.describe("Optionnel : première ligne à analyser (1-indexé). Utile pour cibler une section du fichier. Par défaut : début du fichier."),
|
|
53
|
+
endLine: z
|
|
54
|
+
.number()
|
|
55
|
+
.int()
|
|
56
|
+
.positive()
|
|
57
|
+
.optional()
|
|
58
|
+
.describe("Optionnel : dernière ligne à analyser (1-indexé). Utile pour cibler une section du fichier. Par défaut : fin du fichier."),
|
|
41
59
|
});
|
|
42
60
|
const CompareSchema = z.object({
|
|
43
61
|
fileA: z.string().describe("Chemin absolu complet du premier fichier"),
|
|
@@ -110,9 +128,10 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
110
128
|
},
|
|
111
129
|
{
|
|
112
130
|
name: "get_file_outline",
|
|
113
|
-
description: "Retourne la liste des symboles
|
|
114
|
-
"
|
|
115
|
-
"
|
|
131
|
+
description: "Retourne la liste des symboles d'un fichier (fonctions, classes, interfaces, types, constantes, méthodes) " +
|
|
132
|
+
"avec leurs numéros de lignes de début et de fin, et leur profondeur d'imbrication (depth). " +
|
|
133
|
+
"Supporte tous les langages à accolades (TypeScript, JavaScript, PHP, Java, C#…). " +
|
|
134
|
+
"Paramètres optionnels : depth pour filtrer par niveau d'imbrication, startLine/endLine pour cibler une section. " +
|
|
116
135
|
"Le chemin doit être absolu.",
|
|
117
136
|
inputSchema: {
|
|
118
137
|
type: "object",
|
|
@@ -121,6 +140,18 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
121
140
|
type: "string",
|
|
122
141
|
description: "Chemin absolu complet du fichier à analyser",
|
|
123
142
|
},
|
|
143
|
+
depth: {
|
|
144
|
+
type: "number",
|
|
145
|
+
description: "Optionnel : profondeur maximale à retourner. 0 = premier niveau uniquement (classes, fonctions top-level), 1 = +1 niveau (méthodes d'une classe), etc. Par défaut : tous les niveaux.",
|
|
146
|
+
},
|
|
147
|
+
startLine: {
|
|
148
|
+
type: "number",
|
|
149
|
+
description: "Optionnel : première ligne à analyser (1-indexé). Par défaut : début du fichier.",
|
|
150
|
+
},
|
|
151
|
+
endLine: {
|
|
152
|
+
type: "number",
|
|
153
|
+
description: "Optionnel : dernière ligne à analyser (1-indexé). Par défaut : fin du fichier.",
|
|
154
|
+
},
|
|
124
155
|
},
|
|
125
156
|
required: ["filePath"],
|
|
126
157
|
},
|
|
@@ -169,8 +200,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
169
200
|
const { name, arguments: args } = request.params;
|
|
170
201
|
if (name === "get_file_outline") {
|
|
171
202
|
try {
|
|
172
|
-
const { filePath } = OutlineSchema.parse(args);
|
|
173
|
-
const symbols = await getFileOutline(filePath);
|
|
203
|
+
const { filePath, depth, startLine, endLine } = OutlineSchema.parse(args);
|
|
204
|
+
const symbols = await getFileOutline(filePath, { depth, startLine, endLine });
|
|
174
205
|
return {
|
|
175
206
|
content: [{ type: "text", text: JSON.stringify(symbols, null, 2) }],
|
|
176
207
|
};
|
package/dist/utils/outline.js
CHANGED
|
@@ -21,35 +21,81 @@ const SYMBOL_PATTERNS = [
|
|
|
21
21
|
regex: /^(?:export\s+)?(?:const|let|var)\s+(\w+)\s*[=:]/,
|
|
22
22
|
type: "const",
|
|
23
23
|
},
|
|
24
|
-
// Méthodes
|
|
25
|
-
|
|
24
|
+
// Méthodes PHP et autres langages : mot-clé `function` indenté
|
|
25
|
+
{
|
|
26
|
+
regex: /^[ \t]+(?:(?:public|private|protected|static|abstract|final|async|override)\s+)*function\s+(\w+)/,
|
|
27
|
+
type: "method",
|
|
28
|
+
},
|
|
29
|
+
// Méthodes TypeScript/JS indentées sans mot-clé `function`
|
|
30
|
+
// On exclut les mots-clés pour éviter les faux positifs
|
|
26
31
|
{
|
|
27
32
|
regex: /^[ \t]{2,}(?:(?:public|private|protected|static|async|override)\s+)*(?!(if|for|while|switch|catch|return|throw|new|typeof|instanceof|await|yield|delete|void|case|else|do)\b)(\w+)\s*[(<]/,
|
|
28
33
|
type: "method",
|
|
29
34
|
},
|
|
30
35
|
];
|
|
31
|
-
|
|
36
|
+
function countBracesInLine(line) {
|
|
37
|
+
let count = 0;
|
|
38
|
+
let inSingleQuote = false;
|
|
39
|
+
let inDoubleQuote = false;
|
|
40
|
+
for (let i = 0; i < line.length; i++) {
|
|
41
|
+
const ch = line[i];
|
|
42
|
+
if (ch === "'" && !inDoubleQuote)
|
|
43
|
+
inSingleQuote = !inSingleQuote;
|
|
44
|
+
else if (ch === '"' && !inSingleQuote)
|
|
45
|
+
inDoubleQuote = !inDoubleQuote;
|
|
46
|
+
else if (!inSingleQuote && !inDoubleQuote) {
|
|
47
|
+
if (ch === "{")
|
|
48
|
+
count++;
|
|
49
|
+
else if (ch === "}")
|
|
50
|
+
count--;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return count;
|
|
54
|
+
}
|
|
55
|
+
export async function getFileOutline(filePath, options = {}) {
|
|
32
56
|
const resolved = await validateAndResolvePath(filePath);
|
|
33
57
|
await checkFileSize(resolved);
|
|
34
58
|
const content = await fs.readFile(resolved, "utf-8");
|
|
35
59
|
const lines = content.split(/\r?\n/);
|
|
60
|
+
const rangeStart = options.startLine ?? 1;
|
|
61
|
+
const rangeEnd = options.endLine ?? lines.length;
|
|
36
62
|
const symbols = [];
|
|
63
|
+
let braceDepth = 0;
|
|
37
64
|
for (let i = 0; i < lines.length; i++) {
|
|
65
|
+
const lineNum = i + 1;
|
|
38
66
|
const line = lines[i];
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
67
|
+
if (lineNum >= rangeStart && lineNum <= rangeEnd) {
|
|
68
|
+
for (const { regex, type } of SYMBOL_PATTERNS) {
|
|
69
|
+
const match = line.match(regex);
|
|
70
|
+
if (match) {
|
|
71
|
+
// Pour le pattern TS method, le groupe capturant est match[2] (match[1] = lookahead interne)
|
|
72
|
+
const name = match[2] ?? match[1];
|
|
73
|
+
if (name) {
|
|
74
|
+
symbols.push({ name, type, startLine: lineNum, endLine: 0, depth: braceDepth });
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
46
78
|
}
|
|
47
79
|
}
|
|
80
|
+
braceDepth += countBracesInLine(line);
|
|
81
|
+
if (braceDepth < 0)
|
|
82
|
+
braceDepth = 0;
|
|
48
83
|
}
|
|
49
|
-
// Calculer
|
|
84
|
+
// Calculer endLine en tenant compte de la profondeur :
|
|
85
|
+
// un symbole se termine juste avant le prochain symbole de même niveau ou supérieur
|
|
50
86
|
for (let i = 0; i < symbols.length; i++) {
|
|
51
|
-
symbols[i].
|
|
52
|
-
|
|
87
|
+
const currentDepth = symbols[i].depth;
|
|
88
|
+
let nextBoundaryLine = rangeEnd + 1;
|
|
89
|
+
for (let j = i + 1; j < symbols.length; j++) {
|
|
90
|
+
if (symbols[j].depth <= currentDepth) {
|
|
91
|
+
nextBoundaryLine = symbols[j].startLine;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
symbols[i].endLine = Math.min(nextBoundaryLine - 1, rangeEnd);
|
|
96
|
+
}
|
|
97
|
+
if (options.depth !== undefined) {
|
|
98
|
+
return symbols.filter((s) => s.depth <= options.depth);
|
|
53
99
|
}
|
|
54
100
|
return symbols;
|
|
55
101
|
}
|
package/package.json
CHANGED