From d110abd5a43c8958f084124881eec79353291efe Mon Sep 17 00:00:00 2001 From: Mateusz Duda Date: Thu, 9 May 2024 17:40:17 +0200 Subject: [PATCH] added .scope as default ignore --- src/Commands/runAddCommand.ts | 2 +- src/Relevancy/RelevancyManager.ts | 10 ++++++---- src/Scope/FileTagsDatabase.ts | 4 ++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Commands/runAddCommand.ts b/src/Commands/runAddCommand.ts index 7b9f939..00294f5 100644 --- a/src/Commands/runAddCommand.ts +++ b/src/Commands/runAddCommand.ts @@ -33,7 +33,7 @@ export function runAddCommand(args: Array, root: string) { let fileDataRelevancy: Map = new Map(); try { - fileDataRelevancy = await relevancyTagger.start(fileDataToTag); + fileDataRelevancy = await relevancyTagger.start(fileDataToTag, fileTagsDatabase); } catch (e) { console.log("[Scope tags] Could not add relevancy, the changes won't be saved."); return; diff --git a/src/Relevancy/RelevancyManager.ts b/src/Relevancy/RelevancyManager.ts index 16d9e5b..0e9e2b6 100644 --- a/src/Relevancy/RelevancyManager.ts +++ b/src/Relevancy/RelevancyManager.ts @@ -1,6 +1,7 @@ import { Commit } from "nodegit"; import { FileData, FilePath } from "../Git/Types"; import { Relevancy } from "./Relevancy"; +import { FileTagsDatabase } from "../Scope/FileTagsDatabase"; const { Scale } = require('enquirer'); @@ -34,7 +35,6 @@ export class RelevancyManager { private static COMMIT_MSG_PREFIX = "__relevancy__"; private static CURRENT_COMMIT = "__current__"; - private _relevancyDescriptions = new Map([ [Relevancy.LOW, { name: "Low", message: "Does not list file at all (example: formatting changes)" }], [Relevancy.MEDIUM, { name: "Medium", message: "Does list tags for file, but does not search references for it" }], @@ -45,9 +45,11 @@ export class RelevancyManager { public constructor() { } - public async start(entries: Array): Promise> { + public async start(entries: Array, fileTagsDatabase: FileTagsDatabase): Promise> { + + const notIgnoredEntries = entries.filter(entry => !fileTagsDatabase.isIgnored(entry.newPath)); - const uniqueEntries = entries.filter((value, index, self) => + const uniqueEntries = notIgnoredEntries.filter((value, index, self) => index === self.findIndex((t) => ( t.newPath === value.newPath )) @@ -68,7 +70,7 @@ export class RelevancyManager { currentPageEntries.forEach(uniqueEntry => { // Set every matching fileData to the same relevancy, this doesn't neet to be change specific - const matchingFileData = entries.filter(entry => entry.newPath === uniqueEntry.newPath); + const matchingFileData = notIgnoredEntries.filter(entry => entry.newPath === uniqueEntry.newPath); matchingFileData.forEach(fileData => answerMap.set(fileData, this._getRelevancyByIndex(answer[uniqueEntry.newPath]))); }); } diff --git a/src/Scope/FileTagsDatabase.ts b/src/Scope/FileTagsDatabase.ts index 3b63b9d..2d83ced 100644 --- a/src/Scope/FileTagsDatabase.ts +++ b/src/Scope/FileTagsDatabase.ts @@ -302,6 +302,10 @@ export class FileTagsDatabase implements IJSONFileDatabase { } public isIgnored(file: string, ignoredFileExtensions?: Array): boolean { + if (file.startsWith(".scope")) { + return true; + } + const fileExtenstion = path.extname(file); if (ignoredFileExtensions && fileExtenstion) { if (ignoredFileExtensions.includes(fileExtenstion)) {