Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,12 @@ export const resolvePath = (inputPath: string): string => {
// On Unix, convert backslashes to forward slashes before normalizing
return path.resolve(path.normalize(inputPath.replace(/\\/g, "/")));
};

/**
* Derive a human-readable design name from a design path by stripping the
* directory and file extension.
*
* Example: "/projects/board-rev-c/top.dsn" -> "top"
*/
export const getDesignName = (design: string): string =>
path.basename(design, path.extname(design));
4 changes: 2 additions & 2 deletions src/service/tools/list-components.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from "path";
import { getDesignName } from "../../paths.js";
import { loadNetlist } from "../load-netlist.js";
import { groupComponentsByMpn } from "../component-grouping.js";
import { matchesRefdesType, getRefdesPrefix, isValidRefdes } from "../../circuit-traversal.js";
Expand Down Expand Up @@ -35,7 +35,7 @@ export const listComponents = async (
new Set(Object.keys(netlist.components).filter(isValidRefdes).map(getRefdesPrefix))
).sort((a, b) => a.localeCompare(b));

const designName = path.basename(design, path.extname(design));
const designName = getDesignName(design);
return {
error: `No components with prefix '${prefix}' found in design '${designName}'. Available prefixes: [${availablePrefixes.join(", ")}]`,
};
Expand Down
4 changes: 2 additions & 2 deletions src/service/tools/query-component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from "path";
import { getDesignName } from "../../paths.js";
import { loadNetlist } from "../load-netlist.js";
import { MPN_MISSING_NOTE } from "../component-grouping.js";
import { isErrorResult, type QueryComponentResult, type ErrorResult } from "../../types.js";
Expand All @@ -24,7 +24,7 @@ export const queryComponent = async (
);

if (!componentEntry) {
const designName = path.basename(design, path.extname(design));
const designName = getDesignName(design);
return {
error: `Component '${refdes}' not found in design '${designName}'. Use list_components() or search_components_by_refdes() to find available components.`,
};
Expand Down
6 changes: 3 additions & 3 deletions src/service/tools/query-xnet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from "path";
import { getDesignName } from "../../paths.js";
import { loadNetlist } from "../load-netlist.js";
import { aggregateCircuitByMpn } from "../component-grouping.js";
import {
Expand Down Expand Up @@ -36,7 +36,7 @@ export const queryXnetByNetName = async (
const { nets, components } = netlist;

if (!nets[netName]) {
const designName = path.basename(design, path.extname(design));
const designName = getDesignName(design);
return {
error: `Net '${netName}' not found in design '${designName}'. Use search_nets() to find available nets.`,
};
Expand Down Expand Up @@ -104,7 +104,7 @@ export const queryXnetByPinName = async (
);

if (!refdesEntry) {
const designName = path.basename(design, path.extname(design));
const designName = getDesignName(design);
return {
error: `Component '${refdesInput}' not found in design '${designName}'. Use list_components() or search_components_by_refdes() to find available components.`,
};
Expand Down
8 changes: 4 additions & 4 deletions src/service/tools/search-components.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from "path";
import { getDesignName } from "../../paths.js";
import { loadNetlist } from "../load-netlist.js";
import { groupComponentsByMpn } from "../component-grouping.js";
import { parseRegexPattern, tooManyMatchesError } from "../regex-helpers.js";
Expand All @@ -25,7 +25,7 @@ export const searchComponentsByRefdes = async (
return netlist;
}

const designName = path.basename(design, path.extname(design));
const designName = getDesignName(design);
const allEntries = Object.entries(netlist.components);
const entries = allEntries.filter(([refdes]) => regex.test(refdes));

Expand Down Expand Up @@ -66,7 +66,7 @@ export const searchComponentsByMpn = async (
return netlist;
}

const designName = path.basename(design, path.extname(design));
const designName = getDesignName(design);
const allComponents = Object.entries(netlist.components);
const componentsWithMpn = allComponents.filter(([, c]) => c.mpn?.trim());
const entries = componentsWithMpn.filter(([, component]) => regex.test(component.mpn!));
Expand Down Expand Up @@ -119,7 +119,7 @@ export const searchComponentsByDescription = async (
return netlist;
}

const designName = path.basename(design, path.extname(design));
const designName = getDesignName(design);
const allComponents = Object.entries(netlist.components);
const componentsWithDescription = allComponents.filter(([, c]) => c.description?.trim());
const entries = componentsWithDescription.filter(([, component]) =>
Expand Down
4 changes: 2 additions & 2 deletions src/service/tools/search-nets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from "path";
import { getDesignName } from "../../paths.js";
import { loadNetlist } from "../load-netlist.js";
import { parseRegexPattern, tooManyMatchesError } from "../regex-helpers.js";
import { isErrorResult, type SearchNetsResult, type ErrorResult } from "../../types.js";
Expand All @@ -22,7 +22,7 @@ export const searchNets = async (
return netlist;
}

const designName = path.basename(design, path.extname(design));
const designName = getDesignName(design);
const allNets = Object.keys(netlist.nets);
const nets = allNets.filter((net) => regex.test(net));

Expand Down
Loading