Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

feat(gui): parameter assignment filter #540

Merged
merged 13 commits into from
Jun 4, 2022
9 changes: 9 additions & 0 deletions api-editor/gui/src/common/FilterHelpButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export const FilterHelpButton = function () {
of <em>public, internal</em>.
</ChakraText>
</ListItem>
<ListItem>
<ChakraText>
<strong>is:[assignedBy]</strong>
</ChakraText>
<ChakraText>
Displays only parameters that are assigned in the given manner. Replace [assignedBy]
with one of <em>implicit, positionOnly, positionOrName, nameOnly</em>.
</ChakraText>
</ListItem>
<ListItem>
<ChakraText>
<strong>name:xy</strong>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default class AnnotatedPythonParameter {
this.qualifiedName = qualifiedName;
this.defaultValue = defaultValue;
switch (assignedBy) {
case PythonParameterAssignment.IMPLICIT:
this.assignedBy = 'IMPLICIT';
break;
case PythonParameterAssignment.NAME_ONLY:
this.assignedBy = 'NAME_ONLY';
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PythonFunction from './PythonFunction';
import PythonModule from './PythonModule';

export enum PythonParameterAssignment {
IMPLICIT,
POSITION_ONLY,
POSITION_OR_NAME,
NAME_ONLY,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import AbstractPythonFilter from './AbstractPythonFilter';
import PythonModule from '../PythonModule';
import PythonClass from '../PythonClass';
import PythonFunction from '../PythonFunction';
import { AnnotationsState } from '../../../annotations/annotationSlice';
import { UsageCountStore } from '../../../usages/model/UsageCountStore';
import PythonParameter, { PythonParameterAssignment } from '../PythonParameter';

export default class ParameterAssignmentFilter extends AbstractPythonFilter {
constructor(readonly assignedBy: PythonParameterAssignment) {
super();
}

shouldKeepModule(_pythonModule: PythonModule, _annotations: AnnotationsState, _usages: UsageCountStore): boolean {
return false;
}

shouldKeepClass(_pythonClass: PythonClass, _annotations: AnnotationsState, _usages: UsageCountStore): boolean {
return false;
}

shouldKeepFunction(
_pythonFunction: PythonFunction,
_annotations: AnnotationsState,
_usages: UsageCountStore,
): boolean {
return false;
}

shouldKeepParameter(
pythonParameter: PythonParameter,
_annotations: AnnotationsState,
_usages: UsageCountStore,
): boolean {
if (this.assignedBy === PythonParameterAssignment.IMPLICIT) {
return !pythonParameter.isExplicitParameter();
} else if (!pythonParameter.isExplicitParameter()) {
return false;
} else {
return pythonParameter.assignedBy === this.assignedBy;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import AnnotationFilter, { AnnotationType } from './AnnotationFilter';
import UsageFilter from './UsageFilter';
import UsefulnessFilter from './UsefulnessFilter';
import { equals, greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual } from './comparisons';
import ParameterAssignmentFilter from './ParameterAssignmentFilter';
import { PythonParameterAssignment } from '../PythonParameter';

/**
* Creates a filter from the given string. This method handles conjunctions, negations, and non-negated tokens.
Expand Down Expand Up @@ -69,6 +71,16 @@ const parsePositiveToken = function (token: string): Optional<AbstractPythonFilt
case 'is:internal':
return new VisibilityFilter(Visibility.Internal);

// Parameter assignment
case 'is:implicit':
return new ParameterAssignmentFilter(PythonParameterAssignment.IMPLICIT);
case 'is:positiononly':
return new ParameterAssignmentFilter(PythonParameterAssignment.POSITION_ONLY);
case 'is:positionorname':
return new ParameterAssignmentFilter(PythonParameterAssignment.POSITION_OR_NAME);
case 'is:nameonly':
return new ParameterAssignmentFilter(PythonParameterAssignment.NAME_ONLY);

// Annotations
case 'annotation:any':
return new AnnotationFilter(AnnotationType.Any);
Expand Down