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

Commit

Permalink
feat(gui): parameter assignment filter (#540)
Browse files Browse the repository at this point in the history
* feat(gui): parse filters for usages/usefulness

* feat(gui): update filter help text

* feat(gui): pass usage data around

* feat(gui): implement usage filter

* feat(gui): implement usefulness filter

* style: apply automatic fixes of linters

* feat(gui): implement assignedBy filters

* style: apply automatic fixes of linters

* fix: build error

* style: apply automatic fixes of linters

* fix: linter errors

* fix: build error

Co-authored-by: lars-reimann <lars-reimann@users.noreply.github.com>
  • Loading branch information
lars-reimann and lars-reimann authored Jun 4, 2022
1 parent 9880366 commit 6038d05
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
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

0 comments on commit 6038d05

Please sign in to comment.