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

[ros2launch] legal tab completion of launch files #126

Merged
merged 13 commits into from Feb 27, 2020

Conversation

sloretz
Copy link
Contributor

@sloretz sloretz commented Feb 21, 2020

Fixes #118

This fixes one issue, but it took multiple steps:

  • LaunchFileNameCompleter belongs on the launch_file_name argument, not launch_arguments.
  • Suppress completions of launch_arguments, since by default it completes all files in the current directory
  • Expose get_launch_file_paths so I can use it in a new completer Add is_launch_file and expose it in API
  • Add a completer that allows first argument to be either a package name or a launch file

Here's the folder structure I used for testing

$ tree
.
├── composition
│   ├── asdf.launch.py
│   ├── foo
│   │   ├── bar.launch.py
│   │   └── baz.launch.py
│   └── foo.launch.py
└── composition_launch.py

2 directories, 5 files

Here are the completions I tested with this PR

$ ros2 launch com<tab><tab>
common_interfaces       composition             composition/            composition_interfaces  composition_launch.py
$ ros2 launch composition<tab><tab>
composition             composition/            composition_interfaces  composition_launch.py
$ ros2 launch composition <tab><tab>
-a                              --debug                         --print-description             --show-args
composition_demo.launch.py      -p                              -s                              --show-arguments
-d                              --print                         --show-all-subprocesses-output
$ ros2 launch composition c<tab>(v completes to v)
$ ros2 launch composition composition_demo.launch.py
$ ros2 launch composition/<tab><tab>
composition/asdf.launch.py  composition/foo/            composition/foo.launch.py
$ ros2 launch composition/foo<tab><tab>
composition/foo/           composition/foo.launch.py
$ ros2 launch composition/foo/<tab>(v completes to v)
$ ros2 launch composition/foo/ba
$ ros2 launch composition/foo/baz<tab>(vcompletes to v)
$ ros2 launch composition/foo/baz.launch.py

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
@sloretz sloretz added bug Something isn't working in review labels Feb 21, 2020
@sloretz sloretz self-assigned this Feb 21, 2020
@sloretz
Copy link
Contributor Author

sloretz commented Feb 21, 2020

CI (testing just ros2launch)

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status
  • Windows-container Build Status

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
@sloretz sloretz added this to In Progress in Eloquent Patch Release 2 Feb 24, 2020
@sloretz
Copy link
Contributor Author

sloretz commented Feb 24, 2020

CI (testing just ros2launch)

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status
  • Windows-container Build Status

arg = parser.add_argument(
'launch_arguments',
nargs='*',
help="Arguments to the launch file; '<name>:=<value>' (for duplicates, last one wins)")
arg.completer = LaunchFileNameCompleter()
arg.completer = SuppressCompleterWorkaround()
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you elaborate why it does work without the workaround in other cases but not here?

Using

$ tree
.
├── composition
│   ├── asdf.launch.py
│   ├── foo
│   │   ├── bar.launch.py
│   │   └── baz.launch.py
│   └── foo.launch.py
├── composition_launch.py
└── file_i_dont_want_completed.txt

With SupressCompleter()

$ ros2 launch composition <tab><tab>
composition/                    composition_launch.py           file_i_dont_want_completed.txt

With SupressCompleterWorkaround()

$ ros2 launch composition <tab><tab>
-a                              --debug                         --print-description             --show-args
composition_demo.launch.py      -p                              -s                              --show-arguments
-d                              --print                         --show-all-subprocesses-output 

I haven't tested colcon-package-information, so I don't know if SuppressCompleter is working as intended there.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know if SuppressCompleter is working as intended there.

It does.

What version of argcomplete are you using?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

argcomplete==1.11.1, and I was also able to reproduce using upstream master

Copy link
Member

Choose a reason for hiding this comment

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

Maybe I am missing the part why it is necessary in this case only.

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
@sloretz
Copy link
Contributor Author

sloretz commented Feb 25, 2020

@dirk-thomas as of 71ae581 the PR now reuses FilesCompleter to do the path and directory completions

CI (testing just ros2launch)

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status
  • Windows-container Build Status

ros2launch/ros2launch/api/api.py Outdated Show resolved Hide resolved
ros2launch/ros2launch/api/api.py Outdated Show resolved Hide resolved
ros2launch/ros2launch/command/launch.py Outdated Show resolved Hide resolved
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
@ros2 ros2 deleted a comment from sloretz Feb 25, 2020
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Copy link
Member

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

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

Beside the comment about the function argument style this works for me.

ros2launch/ros2launch/api/api.py Outdated Show resolved Hide resolved
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
@sloretz
Copy link
Contributor Author

sloretz commented Feb 25, 2020

CI (testing just ros2launch)

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status
  • Windows-container Build Status

@sloretz
Copy link
Contributor Author

sloretz commented Feb 27, 2020

Approved, and test failure appears unrelated (compiler warning in C code, but this PR only changes python code). Merging.

@sloretz sloretz merged commit 5f54cb2 into master Feb 27, 2020
@delete-merged-branch delete-merged-branch bot deleted the sloretz/ros2launch_legal_completion branch February 27, 2020 18:26
@ahcorde ahcorde mentioned this pull request May 8, 2020
@mjcarroll mjcarroll moved this from In Progress to Needs Release in Eloquent Patch Release 2 Dec 4, 2020
@mjcarroll mjcarroll moved this from Needs Release to Released in Eloquent Patch Release 2 Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in review
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Tab autocomplete to only list launch files in package when package is specified
2 participants