Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 14x 1x 1x 1x 1x 13x 13x 13x 13x 13x 14x 14x 11x 14x 2x 2x 2x 2x 2x 2x 14x 9x 2x 2x 2x 2x 9x 7x 7x 7x 7x 7x 11x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 2x 2x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 12x 12x 12x 12x 1x 12x 12x 12x 12x 12x 2x 12x 12x 7x 7x 4x 12x 12x 3x 12x 12x 12x 12x 2x 12x 12x 6x 6x 6x 6x 8x 1x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 2x 2x 2x 3x 3x 1x 1x 1x 1x 1x 1x 5x 4x 4x 4x 4x 5x 10x 10x 7x 7x 7x 7x 7x 7x 10x 5x 5x 5x 10x 1x 10x 3x 3x 3x 2x 2x 2x 2x 2x 2x 3x 1x 1x 4x 1x 1x 10x 4x 4x 1x 1x 1x 1x 1x 1x 4x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 4x 1x 1x 1x 1x 1x 1x 1x 5x 5x 4x 5x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x | const vscode = require("vscode");
const coreReviewMethods = {
/**
* Detecta el modelo de IA y establece los limites de contexto apropiados.
* @param {string} modelId - ID del modelo (gpt-4o, claude-sonnet-4.5, etc.)
* @returns {Object} Limites de contexto para el modelo
*/
_detectModelAndSetLimits(modelId) {
if (!modelId) {
this.logger.info(` ⚙️ Modelo no especificado, usando limites default`);
this.currentModelLimits = this.constructor.MODEL_LIMITS.default;
return this.currentModelLimits;
}
const modelLower = modelId.toLowerCase();
let modelFamily = "default";
if (
modelLower.includes("claude") ||
modelLower.includes("sonnet") ||
modelLower.includes("opus")
) {
modelFamily = modelLower.includes("sonnet")
? "claude-sonnet"
: "claude-3";
this.logger.info(
` ⚙️ Detectado modelo Claude - usando limites conservadores para rate limiting`,
);
} else if (modelLower.includes("gpt-4o") || modelLower.includes("gpt4o")) {
if (modelLower.includes("mini") || modelLower.includes("nano")) {
modelFamily = "gpt-4o-mini";
this.logger.info(
` ⚙️ Detectado modelo GPT-4o mini/nano - usando limites conservadores`,
);
} else {
modelFamily = "gpt-4o";
this.logger.info(
` ⚙️ Detectado modelo GPT-4o - usando limites estandar`,
);
}
} else if (modelLower.includes("gemini")) {
modelFamily = "gemini";
this.logger.info(
` ⚙️ Detectado modelo Gemini - usando limites conservadores`,
);
} else {
this.logger.info(
` ⚙️ Modelo desconocido (${modelId}) - usando limites conservadores`,
);
}
this.currentModelLimits =
this.constructor.MODEL_LIMITS[modelFamily] ||
this.constructor.MODEL_LIMITS.default;
this.logger.info(` 📊 Limites de contexto:`);
this.logger.info(
` • Diff total: ${this.currentModelLimits.maxTotalDiff.toLocaleString()} chars`,
);
this.logger.info(
` • Archivo individual: ${this.currentModelLimits.maxSingleFile.toLocaleString()} chars`,
);
this.logger.info(
` • Instrucciones: ${this.currentModelLimits.maxInstructions.toLocaleString()} chars`,
);
return this.currentModelLimits;
},
/**
* Calcula bloques dinamicos de archivos basado en el tamano estimado del contenido.
* @param {Array} files - Lista de archivos del PR
* @param {string} modelId - ID del modelo de IA a usar
* @returns {Array<Array>} Array de bloques
*/
calculateDynamicBlocks(files, modelId) {
if (!Array.isArray(files) || files.length === 0) {
return [];
}
const limits = this._detectModelAndSetLimits(modelId);
const ESTIMATED_DIFF_PER_FILE = 15000;
const maxBlockSize = Math.floor(limits.maxTotalDiff * 0.7);
const filesPerBlock = Math.max(
5,
Math.floor(maxBlockSize / ESTIMATED_DIFF_PER_FILE),
);
this.logger.info(` 📦 Calculo de bloques dinamicos:`);
this.logger.info(
` • Limite modelo: ${limits.maxTotalDiff.toLocaleString()} chars`,
);
this.logger.info(
` • Tamano maximo bloque: ${maxBlockSize.toLocaleString()} chars (70%)`,
);
this.logger.info(` • Archivos estimados por bloque: ${filesPerBlock}`);
let sortedFiles;
try {
sortedFiles = [...files].sort((a, b) => {
const pathA = (
a?.path ||
a?.serverItem ||
a?.filePath ||
""
).toLowerCase();
const pathB = (
b?.path ||
b?.serverItem ||
b?.filePath ||
""
).toLowerCase();
if (pathA !== pathB) {
return pathA.localeCompare(pathB);
}
const typeA = (
a?.changeType ||
a?.change?.changeType ||
""
).toLowerCase();
const typeB = (
b?.changeType ||
b?.change?.changeType ||
""
).toLowerCase();
return typeA.localeCompare(typeB);
});
this.logger.info(
` • Archivos ordenados deterministicamente por ruta`,
);
} catch (error) {
this.logger.error(` ⚠️ Error ordenando archivos: ${error.message}`);
sortedFiles = files;
}
const blocks = [];
for (let i = 0; i < sortedFiles.length; i += filesPerBlock) {
blocks.push(sortedFiles.slice(i, i + filesPerBlock));
}
this.logger.info(` • Total de bloques: ${blocks.length}`);
this.logger.info(
` • Archivos por bloque: ${blocks.map((b) => b.length).join(", ")}`,
);
return blocks;
},
/**
* Construye URL de Azure DevOps para archivo en PR.
*/
_buildPRFileURL(
organization,
project,
repository,
pullRequestId,
filePath,
line = null,
lineEnd = null,
) {
const normalizedPath = filePath.startsWith("/") ? filePath : "/" + filePath;
let url = `https://dev.azure.com/${organization}/${project}/_git/${repository}/pullrequest/${pullRequestId}?_a=files&path=${normalizedPath}`;
if (line) {
const endLine = lineEnd || line;
url += `&line=${line}&lineEnd=${endLine}&lineStartColumn=1&lineEndColumn=1`;
}
return url;
},
/**
* Parsea string de ubicacion para extraer archivo(s), linea(s) y texto descriptivo.
*/
_parseLocation(location) {
if (!location) return { files: [] };
const parts = location.split(",").map((p) => p.trim());
const files = [];
for (const part of parts) {
const fileMatch = part.match(/^(.+?\.[a-z0-9]+)/i);
if (!fileMatch) continue;
const file = fileMatch[1].trim();
const hasValidExtension =
/\.(sql|cs|ts|js|html|css|json|xml|txt|aspx|config|sqlproj|csproj|vbproj|sln|xaml|razor|cshtml)$/i.test(
file,
);
if (!hasValidExtension) continue;
const afterFile = part.substring(file.length).trim();
if (!afterFile || afterFile === "") {
files.push({ file, line: null, lineEnd: null, note: null });
} else if (afterFile.startsWith(":")) {
const afterColon = afterFile.substring(1).trim();
const lineMatch = afterColon.match(/^(\d+)(?:-(\d+))?(?:\s+(.+))?$/);
if (lineMatch) {
files.push({
file,
line: parseInt(lineMatch[1]),
lineEnd: lineMatch[2] ? parseInt(lineMatch[2]) : null,
note: lineMatch[3] ? lineMatch[3].trim() : null,
});
} else {
files.push({ file, line: null, lineEnd: null, note: afterColon });
}
} else {
files.push({ file, line: null, lineEnd: null, note: afterFile });
}
}
return { files };
},
/**
* Detecta el lenguaje de programacion por extension de archivo.
*/
_detectLanguage(filePath) {
if (!filePath) return "";
const ext = filePath.split(".").pop().toLowerCase();
const languageMap = {
cs: "csharp",
sql: "sql",
ts: "typescript",
js: "javascript",
html: "html",
css: "css",
json: "json",
xml: "xml",
py: "python",
java: "java",
cpp: "cpp",
c: "c",
go: "go",
rb: "ruby",
php: "php",
sh: "bash",
yml: "yaml",
yaml: "yaml",
md: "markdown",
};
return languageMap[ext] || "";
},
/**
* Verifica la disponibilidad de GitHub Copilot.
* @returns {Promise<{available: boolean, message: string}>}
*/
async checkCopilotAvailability() {
try {
const models = await vscode.lm.selectChatModels({ vendor: "copilot" });
if (models.length === 0) {
return {
available: false,
message:
"GitHub Copilot no esta disponible. Verifica tu suscripcion.",
};
}
return {
available: true,
message: `GitHub Copilot disponible: ${
models[0].name || models[0].family || "Modelo activo"
}`,
};
} catch (error) {
return {
available: false,
message: `Error verificando GitHub Copilot: ${error.message}`,
};
}
},
};
module.exports = coreReviewMethods;
|