Skip to content

Commit

Permalink
Merge branch 'main' into docs/update-benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
kazushisan authored Dec 15, 2024
2 parents b1091f1 + cfb1d72 commit ce83ae7
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 182 deletions.
57 changes: 0 additions & 57 deletions lib/util/TaskManager.test.ts

This file was deleted.

69 changes: 0 additions & 69 deletions lib/util/TaskManager.ts

This file was deleted.

134 changes: 78 additions & 56 deletions lib/util/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { Vertexes } from './DependencyGraph.js';
import { createDependencyGraph } from './createDependencyGraph.js';
import { MemoryFileService } from './MemoryFileService.js';
import { TaskManager } from './TaskManager.js';
import { findFileUsage } from './findFileUsage.js';
import { parseFile } from './parseFile.js';
import { Output } from './Output.js';
Expand Down Expand Up @@ -627,74 +626,97 @@ export const edit = async ({

initialFiles.sort((a, b) => a.depth - b.depth);

const taskManager = new TaskManager(async (c) => {
// if the file is not in the file service, it means it has been deleted in a previous iteration
if (!fileService.exists(c.file)) {
return;
}

const vertex = dependencyGraph.vertexes.get(c.file);
const queue = [initialFiles];

await Promise.resolve();
while (queue.length > 0) {
const first = queue.shift();

if (c.signal.aborted) {
return;
if (!first) {
break;
}

const result = processFile({
targetFile: c.file,
vertexes: dependencyGraph.eject(),
const current = {
vertexes: dependencyGraph.vertexes,
files: fileService.eject(),
fileNames: fileService.getFileNames(),
deleteUnusedFile,
enableCodeFix,
options,
projectRoot,
});

if (c.signal.aborted) {
return;
}
};

switch (result.operation) {
case 'delete': {
if (entrypoints.includes(c.file)) {
break;
const next = first
.map((v) => {
// if the file is not in the file service, it means it has been deleted in a previous iteration
if (!fileService.exists(v.file)) {
return;
}
output.deleteFile(c.file);
fileService.delete(c.file);

if (vertex) {
dependencyGraph.deleteVertex(c.file);
const result = processFile({
targetFile: v.file,
vertexes: current.vertexes,
files: current.files,
fileNames: current.fileNames,
deleteUnusedFile,
enableCodeFix,
options,
projectRoot,
});

return { result, ...v };
})
.filter((r) => !!r)
.map(({ result, file }) => {
const vertex = dependencyGraph.vertexes.get(file);

if (recursive) {
c.add(
...Array.from(vertex.to).filter((f) => !entrypoints.includes(f)),
);
switch (result.operation) {
case 'delete': {
if (entrypoints.includes(file)) {
return [];
}
output.deleteFile(file);
fileService.delete(file);

if (vertex) {
dependencyGraph.deleteVertex(file);

if (recursive) {
return Array.from(vertex.to).filter(
(f) => !entrypoints.includes(f),
);
}
}
return [];
}
}
break;
}
case 'edit': {
for (const item of result.removedExports) {
output.removeExport({
file: item.fileName,
content: fileService.get(item.fileName),
code: item.code,
position: item.position,
});
}
fileService.set(c.file, result.content);
case 'edit': {
for (const item of result.removedExports) {
output.removeExport({
file: item.fileName,
content: fileService.get(item.fileName),
code: item.code,
position: item.position,
});
}
fileService.set(file, result.content);

if (vertex && result.removedExports.length > 0 && recursive) {
c.add(
...Array.from(vertex.to).filter((f) => !entrypoints.includes(f)),
);
if (vertex && result.removedExports.length > 0 && recursive) {
return Array.from(vertex.to).filter(
(f) => !entrypoints.includes(f),
);
}
return [];
}
}
break;
}
});

const files = Array.from(new Set(next.flat()));

if (files.length > 0) {
queue.push(
files.map((file) => ({
file,
depth: dependencyGraph.vertexes.get(file)?.data.depth || Infinity,
})),
);
}
});
}

await taskManager.execute(initialFiles.map((v) => v.file));
// this is kept for compatibility with the old implementation
return Promise.resolve();
};

0 comments on commit ce83ae7

Please sign in to comment.