[AI][Codex] 쓰레기가 쓰레기를 낳는 광경
주석마다 참조하는 엔티티 정보를 아래와 같이 관리합니다.
export type AnnotationDto = {
seq: number
value: string
refs: AnnotationRef[]
}엔티티에서 주석을 제거하다보면 refs.length 가 0이 될 때가 발생합니다.
불필요한 주석 전체를 삭제함.
일단 돌아가는지 보려고 대강 아래와 같이 짰습니다.
if (dto.refs.length === 0) {
this._annotation.delete(annoRef) // Map<number, AnnotationDto>
const { annotations } = this.modelDto
const idx = annotations.findIndex((anno) => anno.seq === annoRef)
const [deleted] = annotations.splice(idx, 1)
this.workspace.notify('annotation', 'update', deleted)
}초기화 작업에서 빈 주석이 있으면 없애려는데 다시 위의 코드가 필요함.
TODO 를 걸어놓고 refs가 비어있으면 제거하라고 일을 시켰더니…
// remove annotations which are no longer referenced
const toDelete: number[] = []
this._annotation.forEach((dto, key) => {
if (!dto.refs || dto.refs.length === 0) {
toDelete.push(key)
}
})
if (toDelete.length > 0) {
const { annotations } = this.modelDto
toDelete.forEach((key) => {
const dto = this._annotation.get(key)
this._annotation.delete(key)
const idx = annotations.findIndex((anno) => anno.seq === key)
if (idx >= 0) {
const [removed] = annotations.splice(idx, 1)
this.workspace.notify('annotation', 'update', removed)
}
})
this._dirty = true
}기대한 건 주석 삭제하는 로직을 private 메소드로 빼내서 재사용하는 코드였으나, 위와같이 존재하는 코드를 가져다 그대로 복사 붙여넣음.
일 하나를 시켰더니 다른 일을 또 하나 만들고 있음.
이거시 바로 바이브코딩의 무서움입니다.
사방팔방 저렇게 때가 끼면 나중에 감당 안됨…