spring-boot-migrator icon indicating copy to clipboard operation
spring-boot-migrator copied to clipboard

Improve handling for Path auto-select or use Path Input component

Open fabapp2 opened this issue 2 years ago • 6 comments

depends-on: spring-projects/spring-shell#474

What needs to be done

The auto-completion added with #261 is already helpful. But the handling can be improved to allow faster navigation through the filesystem.

Before spending time on this it makes sense to see if the new Path Input solves this and can be used instead.

scan <tab>

The scan auto-completion

  • never shows files
  • takes . as current dir
  • shows all dirs in current dir
  • and .. if current dir has parent dir
current

>scan --projectRoot <cursor>

expected
>scan <cursor>
.                  ..                 ./.rewrite-cache   ./src              ./target

scan .<tab>

expected
>scan .<cursor>
.                  ..                 ./.rewrite-cache   ./src              ./target

scan ..<tab>

current

Currently, there's a space added instead of a / which requires user input to replace the space with / when navigating dirs

scan ..** ** <cursor>

expected
`scan ../<cursor>`
..                 ../dir1         ../dir2                  ../etc

https://user-images.githubusercontent.com/56278322/182410264-1eacbe83-6dd1-4d73-aba3-efbf5a96d5b3.mp4

fabapp2 avatar Aug 02 '22 17:08 fabapp2

Took a quick look at PathInput, as it seemed promissing, but it has some hardcoded assumptions about it's usage, with existing directories an immediate error; (reported here).

Unless there's a quick answer & solution through Spring Shell I guess the best bet is to refine the current value provider.

timtebeek avatar Aug 03 '22 17:08 timtebeek

Played around a bit with the value provider as well; it can be slightly improved by leaving out hidden directories

diff --git a/applications/spring-shell/src/main/java/org/springframework/sbm/shell/ScanValueProvider.java b/applications/spring-shell/src/main/java/org/springframework/sbm/shell/ScanValueProvider.java
index 52585d7..645bb0b 100644
--- a/applications/spring-shell/src/main/java/org/springframework/sbm/shell/ScanValueProvider.java
+++ b/applications/spring-shell/src/main/java/org/springframework/sbm/shell/ScanValueProvider.java
@@ -35,8 +35,9 @@ class ScanValueProvider implements ValueProvider {
         String prefix = input.substring(lastSlash + 1, input.length());
 
         BiPredicate<Path, BasicFileAttributes> matchingPrefix = (p, a) -> p.getFileName() != null
-                && p.toFile().isDirectory()
-                && p.getFileName().toString().startsWith(prefix);
+                && a.isDirectory()
+                && p.getFileName().toString().startsWith(prefix)
+                && !p.getFileName().toString().startsWith("."); // Stops suggesting hidden folders
         try (Stream<Path> stream = Files.find(dir, 1, matchingPrefix, FOLLOW_LINKS)) {
             return stream
                     .map(Path::toString)

I tried adding ../ to the list of suggested options, but that does not work as expected/desired. A space is added after selecting that option, requiring another backspace before parent directory siblings are suggested.

diff --git a/applications/spring-shell/src/main/java/org/springframework/sbm/shell/ScanValueProvider.java b/applications/spring-shell/src/main/java/org/springframework/sbm/shell/ScanValueProvider.java
index 52585d7..c96acb6 100644
--- a/applications/spring-shell/src/main/java/org/springframework/sbm/shell/ScanValueProvider.java
+++ b/applications/spring-shell/src/main/java/org/springframework/sbm/shell/ScanValueProvider.java
@@ -38,8 +38,9 @@ class ScanValueProvider implements ValueProvider {
                 && p.toFile().isDirectory()
                 && p.getFileName().toString().startsWith(prefix);
         try (Stream<Path> stream = Files.find(dir, 1, matchingPrefix, FOLLOW_LINKS)) {
-            return stream
-                    .map(Path::toString)
+            return Stream.concat(
+                    Stream.of("../"), // Inserts unwanted space after selection
+                    stream.map(Path::toString))
                     .map(CompletionProposal::new)
                     .toList();
         } catch (IOException e) {

timtebeek avatar Aug 03 '22 17:08 timtebeek

I tried adding ../ to the list of suggested options, but that does not work as expected/desired. A space is added after selecting that option, requiring another backspace before parent directory siblings are suggested.

This space gets always appended (0:20 in the video)? So I think that's unrelated to the added two dots but I didn't investigate. We'd probably want to check if dir has a parent or if it is / and the .. should not be shown. But naively I am hoping that if we'd remove the appended space, things should work as "expected"?

fabapp2 avatar Aug 05 '22 08:08 fabapp2

Not sure if we'd be able to remove the appended space at present; I'm hoping https://github.com/spring-projects/spring-shell/discussions/474 turns up something we can use immediately. Until then I guess the improvements above already limit the current suggestions.

timtebeek avatar Aug 10 '22 06:08 timtebeek

Let's wait then and see what spring-projects/spring-shell#474 brings.

fabapp2 avatar Aug 15 '22 18:08 fabapp2

Think we can pick this up again.

timtebeek avatar Oct 19 '22 06:10 timtebeek

Hi @timtebeek

sorry for my late reply, I was on vacation and fell a bit behind.

Thanks for keeping this in your mind.

I have an open branch where I replaced the old shell with the new Spring Shell using UI components and WebSocket communication. I am uncertain if I'll be able to bring this to main before December. But if this is merged back it would be great to integrate it. Would you like to look into it? Otherwise, we can look at it when my branch is merged?

fabapp2 avatar Oct 31 '22 19:10 fabapp2

Let's wait for your branch to merge first then; I'll be on holiday myself starting next week until the end of the year, so anyone welcome to pick this up in the meantime. :)

timtebeek avatar Oct 31 '22 20:10 timtebeek

Let's wait for your branch to merge first then; I'll be on holiday myself starting next week until the end of the year, so anyone welcome to pick this up in the meantime. :)

Enjoy your well-deserved holiday @timtebeek ! 🌴

fabapp2 avatar Nov 03 '22 21:11 fabapp2

It seems there's now a new PathSearch component in spring-shell that might fit in well here. What was the status of the spring-shell component branch you mentioned before @fabapp2 ?

timtebeek avatar Jan 04 '23 20:01 timtebeek