Skip to content
This repository has been archived by the owner on Apr 21, 2024. It is now read-only.

Commit

Permalink
workspaces: choose a reasonable default library name
Browse files Browse the repository at this point in the history
Choose a default library to build, test, or use as the project for lsp-dylan if
no default is specified in workspace.json.
  • Loading branch information
cgay committed Mar 23, 2024
1 parent 71fbc03 commit 4d81e79
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
18 changes: 13 additions & 5 deletions sources/workspaces/registry.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ end;
//// REGISTRY

// Keys used to lookup values in a parsed LID file.
// TODO: use 'define enum' in uncommon-dylan
define constant $platforms-key = #"platforms";
define constant $files-key = #"files";
define constant $library-key = #"library";
Expand Down Expand Up @@ -425,14 +424,23 @@ define function parse-lid-file
lid
end function;

define function find-library-names

// Find the names of all libraries defined in `dir`, a directory or registry.
define generic find-library-names (dir) => (names :: <seq>);

define method find-library-names
(dir :: <directory-locator>) => (names :: <seq>)
let registry = make(<registry>, root-directory: dir);
find-library-names(make(<registry>, root-directory: dir))
end method;

define method find-library-names
(registry :: <registry>) => (names :: <seq>)
// It's possible for a LID included via the LID: keyword to not have a library.
remove(map(rcurry(lid-value, $library-key),
find-lids(registry, dir)),
find-lids(registry, registry.root-directory)),
#f)
end function;
end method;


// Build a map from source file names (absolute pathname strings) to the names
// of libraries they belong to (a sequence of strings). For now we only look at
Expand Down
17 changes: 13 additions & 4 deletions sources/workspaces/workspaces.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,19 @@ define function load-workspace
let ws-json = ws-file & load-json-file(ws-file);
let default-library
= ws-json & element(ws-json, $default-library-key, default: #f);
if (~default-library & active-packages.size = 1)
// TODO: this isn't right. Should find the actual libraries, from the LID
// files, and if there's only one "*-test*" library, choose that.
default-library := pm/package-name(active-packages[0]);
if (~default-library)
let libs = find-library-names(registry);
if (~empty?(libs))
local method match (suffix, lib)
ends-with?(lib, suffix) & lib
end;
// The assumption here is that (for small projects) there's usually one
// test library that you want to run.
default-library := (any?(curry(match, "-test-suite-app"), libs)
| any?(curry(match, "-test-suite"), libs)
| any?(curry(match, "-tests"), libs)
| libs[0]);
end;
end;
make(<workspace>,
active-packages: active-packages,
Expand Down

0 comments on commit 4d81e79

Please sign in to comment.