Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.
Merged
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
22 changes: 7 additions & 15 deletions api-editor/gui/src/features/usages/model/UsageCountStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,9 @@ export class UsageCountStore {
* its default value, that usage of a value is not part of the UsageStore, so we need to add it.
*
* @param api Description of the API
* @private
*/
private addImplicitUsagesOfDefaultValues(api: PythonPackage) {
for (const [parameterId, parameterUsageCount] of this.parameterUsages.entries()) {
const parameter = api.getDeclarationById(parameterId);
if (!(parameter instanceof PythonParameter)) {
continue;
}

for (const parameter of api.getParameters()) {
const defaultValue = parameter.defaultValue;
if (defaultValue === undefined || defaultValue === null) {
// defaultValue could be an empty string
Expand All @@ -147,21 +141,19 @@ export class UsageCountStore {
continue;
}

const functionUsageCount = this.functionUsages.get(containingFunction.id) ?? 0;
const parameterUsageCount = this.getUsageCount(parameter);
const functionUsageCount = this.getUsageCount(containingFunction);
const nImplicitUsages = functionUsageCount - parameterUsageCount;
if (nImplicitUsages === 0) {
continue;
}

const nExplicitUsage = this.valueUsages.get(parameterId)?.get(defaultValue) ?? 0;
const nExplicitUsages = this.valueUsages.get(parameter.id)?.get(defaultValue) ?? 0;

if (!this.valueUsages.has(parameterId)) {
this.valueUsages.set(parameterId, new Map());
}
if (!this.valueUsages.get(parameterId)!.has(defaultValue)) {
this.valueUsages.get(parameterId)!.set(defaultValue, 0);
if (!this.valueUsages.has(parameter.id)) {
this.valueUsages.set(parameter.id, new Map());
}
this.valueUsages.get(parameterId)!.set(defaultValue, nImplicitUsages + nExplicitUsage);
this.valueUsages.get(parameter.id)!.set(defaultValue, nImplicitUsages + nExplicitUsages);
}
}

Expand Down