Skip to content

Add support for URL completions in buf curl#4402

Open
stefanvanburen wants to merge 5 commits intomainfrom
svanburen/buf-curl-completions
Open

Add support for URL completions in buf curl#4402
stefanvanburen wants to merge 5 commits intomainfrom
svanburen/buf-curl-completions

Conversation

@stefanvanburen
Copy link
Member

First mentioned in #2044, which is long something I've wanted. This adds support for completing URLs based on the available RPCs, which either comes from the existing --schema flag or gRPC reflection.

The completion itself works somewhat similar to LSP completion, in that it attempts to complete as far as it can before giving the user an option between the remaining values to disambiguate. It will complete up to the entire service URL, and then provide completions for RPCs within the service (if there are multiple).

This requires one fix upstream in app-go so that subcommands that define ModifyCobra actually run: bufbuild/app-go#5. We'll want to land upstream to main before landing this.

Open to suggestions on the completion UX. It feels fairly natural to me currently, but I'm sure there are edge cases.

Future work here could include better completions for --schema values, either using local directories or BSR modules, and completions for --data values (if we know the schema and the specific RPC targeted by the URL, we know the shape of the JSON for the --data flag). Also, following this pattern of using ModifyCobra, other commands could be made to have better contextual completion.

Also fixes the buf curl help examples to have consistent indentation.

Resolves #2044.

First mentioned in #2044, which is long something I've wanted. This adds
support for completing URLs based on the available RPCs, which either
comes from the existing `--schema` flag or gRPC reflection.

The completion itself works somewhat similar to LSP completion, in that
it attempts to complete as far as it can before giving the user an
option between the remaining values to disambiguate. It will complete up
to the entire service URL, and then provide completions for RPCs within
the service (if there are multiple).

This requires one fix upstream in app-go so that subcommands that define
`ModifyCobra` actually run: bufbuild/app-go#5. We'll want to land
upstream to `main` before landing this.

Open to suggestions on the completion UX. It feels fairly natural to me
currently, but I'm sure there are edge cases.

Future work here could include better completions for `--schema` values,
either using local directories or BSR modules, and completions for
`--data` values (if we know the schema and the specific RPC targeted by
the URL, we know the shape of the JSON for the `--data` flag). Also,
following this pattern of using ModifyCobra, other commands could be
made to have better contextual completion.

Also fixes the buf curl help examples to have consistent indentation.

Resolves #2044.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMar 20, 2026, 1:36 PM

@stefanvanburen
Copy link
Member Author

stefanvanburen commented Mar 19, 2026

ok, as a quick demo gif:
curl-completion

using the following vhs tape:

Output curl-completion.gif

Set Shell fish
Set FontSize 14
Set Width 900
Set Height 400
Set Padding 16
Set Theme "Catppuccin Mocha"

Env PATH "/Users/stefanvanburen/.cache/buf/Darwin/arm64/gobin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"

Hide
Sleep 1s
Type "source ~/.config/fish/completions/buf.fish"
Enter
Sleep 200ms
Show
Ctrl+L
Sleep 200ms

# --protocol flag: static completions (connect, grpc, grpcweb)
Type "buf curl --protocol "
Sleep 500ms
Tab
Sleep 2s
Ctrl+C
Sleep 1s

# --reflect-protocol flag: static completions (grpc-v1, grpc-v1alpha)
Type "buf curl --reflect-protocol "
Sleep 500ms
Tab
Sleep 2s
Ctrl+C
Sleep 1s

# URL via reflection — Tab 1: unambiguous prefix collapses to full service name
Type "buf curl https://demo.connectrpc.com/"
Sleep 500ms
Tab
Sleep 4s

# Tab 2: method completions (Converse, Introduce, Say)
Tab
Sleep 2s

# Select a method by typing a prefix and completing
Type "Say"
Tab
Sleep 2s
Ctrl+C
Sleep 1s

# Same via --schema (no running server needed) — Tab 1: service name
Type "buf curl --schema buf.build/connectrpc/eliza https://demo.connectrpc.com/"
Sleep 500ms
Tab
Sleep 4s

# Tab 2: method completions
Tab
Sleep 2s
Ctrl+C

via `go get buf.build/go/app@main`.
We've added descriptions to the URL completions about _where_ the
completion is coming from (the local module, the schema flag, or gRPC
reflection), which should help users understand better why they're
getting completions. We've also added error handling, for now targeting
issues with the `--schema` parameter.
@stefanvanburen
Copy link
Member Author

Quick UX update: in 20a16ea I added descriptions to the RPC completions about where the schema is coming from (local module, reflection, --schema flag), and also added some basic error handling.

Updated gif:

curl-completion

via this tape:

Output curl-completion.gif

Set Shell fish
Set FontSize 14
Set Width 900
Set Height 400
Set Padding 16
Set Theme "Catppuccin Mocha"

Env PATH "/Users/stefanvanburen/.cache/buf/Darwin/arm64/gobin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"

Hide
Sleep 1s
Type "source ~/.config/fish/completions/buf.fish"
Enter
Sleep 200ms
Show
Ctrl+L
Sleep 200ms

# --protocol flag: static completions (connect, grpc, grpcweb)
Type "buf curl --protocol "
Sleep 500ms
Tab
Sleep 2s
Ctrl+C
Sleep 1s

# --reflect-protocol flag: static completions (grpc-v1, grpc-v1alpha)
Type "buf curl --reflect-protocol "
Sleep 500ms
Tab
Sleep 2s
Ctrl+C
Sleep 1s

# URL via reflection — Tab 1: unambiguous prefix collapses to full service name
Type "buf curl https://demo.connectrpc.com/"
Sleep 500ms
Tab
Sleep 4s

# Tab 2: method completions (Converse, Introduce, Say)
Tab
Sleep 2s

# Select a method by typing a prefix and completing
Type "Say"
Tab
Sleep 2s
Ctrl+C
Sleep 1s

# Same via --schema (no running server needed) — Tab 1: service name
Type "buf curl --schema buf.build/connectrpc/eliza https://demo.connectrpc.com/"
Sleep 500ms
Tab
Sleep 4s

# Tab 2: method completions
Tab
Sleep 2s
Ctrl+C

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tab completion for buf curl

1 participant