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

Manage when Loading versions... is displayed and alert the user to when no versions are found #80

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

FinlayRJW
Copy link
Contributor

Before this PR

If not versions where found loading versions... would remain present which could be very confusing

After this PR

We now manage the state of loading versions..., this is achieve by using DependencyInfo as an indicator of if the line has been historically computed then display the message accordingly. This also allows us to display a No versions found message when we fail to find any versions
==COMMIT_MSG==
Manage when Loading versions... is displayed and alert the user to when no versions are found
==COMMIT_MSG==

Possible downsides?

We now have to track which lines have been historically loaded, I opted for a EvictionQueue so that it wouldn't get to big in memory but not sure this is the best method

@changelog-app
Copy link

changelog-app bot commented Nov 14, 2024

Generate changelog in changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Manage when Loading versions... is displayed and alert the user to when no versions are found

Check the box to generate changelog(s)

  • Generate changelog entry

@@ -104,52 +113,82 @@ private void addLoadingElement(CompletionResultSet sortedResultSet) {
}

private void handleDependencyWithoutWildcard(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to handle these as a chunk so that we can be sure that there are no versions for all repos rather than just no versions for one repo

.collect(Collectors.toList());

if (!pendingFutures.isEmpty()) {
CompletableFuture.anyOf(pendingFutures.toArray(new CompletableFuture[0]))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should trigger a refresh when any one of the futures completes which should schedule less refreshes than just doing a refresh for each future I think

addAndRefresh(key);
}

if (!versionCounts.isEmpty()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removes Loading Versions... from list of versions which is not strictly nessary as it sinks to the bottom but can be nicer when only a few versions are suggested

addAndRefresh(key);
}

Integer packageCount = packageInRepo.stream()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We actually want to count the number of unique artifact names and not the size of packageInRepo

@@ -47,6 +52,8 @@ public class VersionCompletionContributor extends CompletionContributor {
GroupPartOrPackageNameExplorer.getInstance();
private final VersionExplorer versionExplorer = VersionExplorer.getInstance();

private final Queue<DependencyInfo> loadedDependencies = EvictingQueue.create(100);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this extra state? It looks like it's used just for deciding whether to add the Loading versions... or not. Extra state is in general bad.

I think we can just work out whether to add loading versions/no results based on the info we get from VersionResults. Assuming we change the signature of VersionResults to:

public record VersionResults(Set<DependencyVersion> alreadyLoaded, Optional<CompletableFuture<Set<DependencyVersion>>> stillLoading) {}

If in the combination of VersionResults:

  • There is at least 1 stillLoading: add Loading versions...
  • There are 0 alreadyLoaded and 0 stillLoading: add No versions
  • Otherwise there are some alreadyLoaded and 0 stillLoading: add nothing, completion is complete.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I'm not sure if I'm thinking about this wrong but don't we need some state as we want to add Loading versions right at the top before any work is done so it pops up quickly. So we need a way at the start to determine if we should add Loading Versions - I guess its not essential but I think you would end up with a situation where the output said something like

Loading versions...
No versions found

packageInRepo.stream().map(versionExplorer::getVersions).collect(Collectors.toSet());

List<CompletableFuture<?>> pendingFutures = versionResults.stream()
.filter(results -> results.versions().isEmpty())
Copy link
Contributor

Choose a reason for hiding this comment

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

This is actually super strange to me (I guess I'm still thinking in the mindset where you give a List<PackageInRepo> to VersionExplorer#getVersions).

For each getVersions call, is it the case that it's either some already loaded set of versions or it's a future to get more? If so, we should actually structure VersionsResults as an choice between the two somehow. I think you can do this really nicely in Java 21, but in Java 17 I think you can do something like:

sealed interface VersionsResult permits AlreadyLoadedVersions, StillLoadingVersions {}

record AlreadyLoadedVersions(Set<DependencyVersion>)  {}
record StillLoadingVersions(CompletableFuture<Set<DependencyVersion>>)  {}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's definitely a type somewhere here that takes a set/list of VersionsResult and gives you methods like how many are still loading, how many versions are loaded etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I have made quite a few changes, I've switched getVersions to take a List<PackageInRepo> and now it returns a new type VersionsResults which handles the results aggregation. This makes addToResults alot neater as a lot of the logic is handled in the results type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants