Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display class subclasses #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
51 changes: 51 additions & 0 deletions deft-browse/deft-browse.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,54 @@ define command inspect ($deft-commands)
implementation
inspect-dylan-object(dylan-object-name);
end;

define method print-class-subclasses
(project :: <project-object>, object, depth :: <integer>, max-depth :: <integer>)
let id = environment-object-id(project, object);
format-out("%s is not a class.\n", id.id-name);
end method;

define method print-class-subclasses
(project :: <project-object>, object == #f, depth :: <integer>, max-depth :: <integer>)
format-out("Object not found.\n");
end method;

define method print-class-subclasses
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One option (in a different PR) would be to add "..." after classes that have already been displayed rather than displaying their subclasses again.

(project :: <project-object>, object :: <class-object>, depth :: <integer>, max-depth :: <integer>)
let id = environment-object-id(project, object);
let subclasses = class-direct-subclasses(project, object);
for (sc in subclasses)
let sc-id = environment-object-id(project, sc);
// use 2 column indent, starting from column 2
let indent = make(<byte-string>, size: (depth + 1) * 2);
format-out("%s%s\n", indent, sc-id.id-name);
if (depth < max-depth)
print-class-subclasses(project, sc, depth + 1, max-depth);
end if;
end for;
end method;

define function subclasses-for-class(name :: <string>, max-depth :: <integer>)
let project = dylan-current-project($deft-context);
if (project)
let library = project-library(project);
let object = find-environment-object(project, name,
library: library,
module: first(library-modules(project, library)));
print-class-subclasses(project, object, 0, max-depth);
else
format-out("No open project found.\n");
end if
end function;

define command subclasses ($deft-commands)
help "Display the subclasses of a class.";
simple parameter dylan-class-name :: <string>,
help: "the dylan class",
required?: #t;
named parameter depth :: <integer>,
help: "the hierarchy depth",
required?: #f;
implementation
subclasses-for-class(dylan-class-name, if (depth) depth else 0 end);
end;