Refactor getFileRelevanceScore function to include content analysis for better relevance scoring
This commit is contained in:
35
main.js
35
main.js
@@ -1965,15 +1965,36 @@ ipcMain.on('show-tree-context-menu', (event, { absPath, relPath, root, type }) =
|
|||||||
return ignore().add(content);
|
return ignore().add(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFileRelevanceScore(filename, relPath) {
|
function getFileRelevanceScore(filename, relPath, content) {
|
||||||
const base = path.basename(filename).toLowerCase();
|
const base = path.basename(filename).toLowerCase();
|
||||||
let score = 0;
|
let score = 0;
|
||||||
if (/main|index|app|server/.test(base)) score += 10;
|
// 1. Dateiname und Entry-Patterns
|
||||||
if (/test|mock|example|spec/.test(base)) score -= 20;
|
if (/^(main|index|app|server)\.(js|py|ts|go|rb|php|java|c|cpp)$/.test(base)) score += 20;
|
||||||
if (/package\.json|requirements\.txt|pyproject\.toml|makefile|cargo\.toml/.test(base)) score += 10;
|
if (/package\.json|requirements\.txt|pyproject\.toml|makefile|cargo\.toml/.test(base)) score += 20;
|
||||||
if (path.dirname(relPath) === '.') score += 5;
|
if (path.dirname(relPath) === '.') score += 10;
|
||||||
if (/\.(js|py|ts|rb|pl|php|java|c|cpp|h|cs|go|rs|json|yml|yaml|toml|md|html|css|txt)$/.test(base)) score += 5;
|
if (/test|mock|example|spec|demo/.test(relPath)) score -= 30;
|
||||||
if (/\.min\./.test(base)) score -= 10;
|
if (/\.min\./.test(base)) score -= 20;
|
||||||
|
// 2. Exports / Functions / Klassen
|
||||||
|
if (content) {
|
||||||
|
// Viele Exports
|
||||||
|
const exportCount = (content.match(/export\s+(function|class|const|let|var)/g) || []).length;
|
||||||
|
const moduleExportCount = (content.match(/module\.exports/g) || []).length;
|
||||||
|
score += (exportCount + moduleExportCount) * 2;
|
||||||
|
// Viele Funktionen/Klassen
|
||||||
|
const functionCount = (content.match(/function\s+/g) || []).length;
|
||||||
|
const classCount = (content.match(/class\s+/g) || []).length;
|
||||||
|
score += (functionCount + classCount);
|
||||||
|
// Für Python
|
||||||
|
const pyDefCount = (content.match(/^def\s+/gm) || []).length;
|
||||||
|
const pyClassCount = (content.match(/^class\s+/gm) || []).length;
|
||||||
|
score += (pyDefCount + pyClassCount);
|
||||||
|
// Typische Utility-Signaturen
|
||||||
|
if (content.includes('main(') || content.includes('if __name__ == "__main__":')) score += 5;
|
||||||
|
}
|
||||||
|
// 3. Reduziere Score für zu kurze Dateien (<20 Zeilen)
|
||||||
|
if (content && content.split('\n').length < 20) score -= 5;
|
||||||
|
// 4. Ein bisschen Bonus für große Dateien (viel Logik, solange keine Data-Files)
|
||||||
|
if (content && content.length > 1500) score += 2;
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user