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

FR: Metadata for template/revset aliases (types, documentation) #5551

Open
jakobhellermann opened this issue Feb 1, 2025 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@jakobhellermann
Copy link
Contributor

the idea came up in #5541 (review)

Currently, template aliases (builtin_op_log_compact) and template alias functions ('format_short_id(id)' = 'id.shortest(8)') are defined without any type information available.
If you could (optionally) describe what type they expect, that would enable a few potential use cases:

  • jj log -T <tab> could only suggest template aliases that accept a commit
  • if there was an LSP for the template it would benefit from having this information available

How could this look like?

Functions could simply be extended with the obvious syntax for declaring types:

'commit_timestamp(commit: Commit)' = 'commit.committer().timestamp()'

Pure symbols like builtin_log_compact that still take a self parameter (with implicit property access) could maybe look like this:

'builtin_log_compact(self: Commit)' = '''
if(root,
  format_root_commit(self),
  foo # implicitly self.foo
  ...
)
'''

If you wanted to add a docstring, maybe you could just have a comment in the first line (given #5317 is implemented)

'commit_timestamp(commit: Commit)' = 'commit.committer().timestamp()'

That's basically how python does it: https://realpython.com/documenting-python-code/#basics-of-commenting-code

@yuja
Copy link
Contributor

yuja commented Feb 2, 2025

'builtin_log_compact(self: Commit)' = '''

nit: Aliases are kinda syntactic macro, so f() and f are different. Suppose : Type would be processed as a comment during alias substitution, it's weird that the implicit self type is annotated as a function argument.

@yuja yuja added the enhancement New feature or request label Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants