Skip to content

Option to define possible values for custom footer type #153

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

Open
boobiq opened this issue Mar 24, 2025 · 15 comments
Open

Option to define possible values for custom footer type #153

boobiq opened this issue Mar 24, 2025 · 15 comments
Assignees
Labels
enhancement New feature or request

Comments

@boobiq
Copy link

boobiq commented Mar 24, 2025

Hello,

first of all thanks for a very nice plugin and I'd like to ask if it's possible (if it makes sense for you) to add option to define values for custom footer type in conventionalcommit.json schema?

We are using something like Action: <value> where value is one of some predefined values.

I suppose I could create some simple plugin with my own provider (is there maybe some example or documentation about how to do it?) but was wondering if such thing could be builtin feature.

Thanks!

@boobiq boobiq changed the title Option to define values for custom footer type Option to define possible values for custom footer type Mar 24, 2025
@lppedd
Copy link
Owner

lppedd commented Mar 24, 2025

It should be possible by extending the default tokens schema.

I'll take a look soon.

@lppedd lppedd added the enhancement New feature or request label Mar 24, 2025
@lppedd lppedd self-assigned this Mar 24, 2025
@lppedd
Copy link
Owner

lppedd commented Mar 24, 2025

is there maybe some example or documentation about how to do it?

For your use case this seems overkill btw.
Custom providers are good mostly when you need to compute values, maybe from expensive network calls as they don't block the UI thread.

@lppedd
Copy link
Owner

lppedd commented Mar 26, 2025

This is more complex than expected, in the sense that it uncovered a deeper issue: the org.json library does not preserve JSON keys order (well it's the spec, but there is no option for it), resulting in a mess when calling completion.

Thus I'm also replacing the JSON-related libraries now, will take a bit longer.

@boobiq
Copy link
Author

boobiq commented Mar 27, 2025

Thanks for your time and effort!

I was just curious why can't it be defined similar to scopes?

    "action": {
      "description": "Some description",
      "options": {
        "close": {},
        "revert": {},
        "whatever": {}
      }
    },

@lppedd
Copy link
Owner

lppedd commented Mar 27, 2025

It can, but up until now I did not realize the JSON lib is NOT maintaining keys ordering as internally it uses a hash map, and not a linked hash map.

It's not noticeable with three keys, but it is with ten+.

@boobiq
Copy link
Author

boobiq commented Mar 27, 2025

And JSON arrays can't be used? There would be no additional fields to each option possible of course but for our case it's more than enough :)

   "action": {
      "description": "Some description",
      "options": ["close", "revert", "whatever"]
    },

@lppedd
Copy link
Owner

lppedd commented Mar 27, 2025

Sure, but in this specific context they make the schema and the resulting JSON worse to write.

I also want to encode values as objects, so that additional properties are easy to add, and potentially read from extenders.

@boobiq
Copy link
Author

boobiq commented Mar 27, 2025

Thanks, makes sense, it's not feature just for me :)

@lppedd
Copy link
Owner

lppedd commented Mar 27, 2025

It's not easy to go back once you commit something, that's mostly why I take a cautious approach.

@lppedd
Copy link
Owner

lppedd commented Mar 27, 2025

Could you try this version? You'll have to install it manually.
The IDE completion via the schema should point you to the correct JSON structure.

idea-conventional-commit-0.25.0.zip

@boobiq
Copy link
Author

boobiq commented Mar 27, 2025

Completion doesn't seem to be updated somehow, it only suggests existing fields, I checked the structure in repo, is this correct?

    {
      "name": "Action",
      "description": "action description",
      "values": {
        "something": {
          "description": "some description"
        },
        "else": {
          "description": "whatever"
        }
      }
    },

But when I try to type anything in commit msg area, I get "Error reading custom defaults file: the file does not respect the JSON schema. Using built-in tokens instead".

Image

@lppedd
Copy link
Owner

lppedd commented Mar 27, 2025

Completion doesn't seem to be updated somehow

If Action is your custom footer type, you need to use:

// conventionalcommit.json
{
  "types": {
    ...
  },
  "footerTypes": {
    "Action": {
      "description": "action description",
      "values": {
        "something": {
          "description": "Some description"
        },
        "else": {
          "description": "whatever"
        }
      }
    }
  }
}

Also note that manually specifying the schema is not necessary. The correct schema should be injected automatically.

@boobiq
Copy link
Author

boobiq commented Mar 27, 2025

Ah, okay, I didn't realise/notice it's now one of array or object, now it's clear, thanks.

But if you don't mind me asking stupid questions: why couldn't it stay as array with additional values object?

  "footerTypes": [
    {
      "name": "Action",
      "description": "action description",
      "values": [
        {
          "first-value": {
            "description": "some description"
          },
          "second-value": {
            "description": "whatever"
          }
        }
      ]
    }
  ]

values would still be array of objects so it should be easily extendible, shouldn't it? Or it should but now it's at least consistent with scope for example.

Anyway I tested it a bit and it looks like it's working fine except couple things (which I'm not sure can be solved):

If I'm typing footer type value manually, the completion popup only shows defined values which is correct:

Image

After automatic completion (when I finish Action: ) it shows other values from VCS provider (and my values are not even listed as first options):

Image

And if I press Completion shortcut, in addition it also shows commit messages and some files etc from history (or whatever is used for it), could it always only show defined values?

Also when I remove footerTypes key from conventionalcommit.json completely, it shows "Error reading custom defaults file: see IDE logs. Using built-in tokens instead" again. It's working fine when it's empty object.

Also note that manually specifying the schema is not necessary. The correct schema should be injected automatically.

It showed warning (missing schema) in GoLand's status bar when editing conventionalcommit.json so I clicked on it and chose Conventional Commit from the list. Now it seems to work fine and it downloaded it automatically.

@lppedd
Copy link
Owner

lppedd commented Mar 28, 2025

why couldn't it stay as array with additional values object?

It was done to align it to the types schema. It could have been done differently, but I feel like a key-value approach is better than having to define an array of objects.

it shows other values from VCS provider (and my values are not even listed as first options)

You can disable the VCS provider via the com.github.lppedd.cc.providers.vcs registry key, and you can disable Recently used prioritization via Conventional Commit settings.

in addition it also shows commit messages and some files etc from history

Indeed that's what the default completion would give you, I cannot block it. Well I can, but it's dangerous.

Also when I remove footerTypes key from conventionalcommit.json completely, it shows "Error reading custom defaults file: see IDE logs. Using built-in tokens instead" again

Could you let me know what exception you see in the IDE logs?

@boobiq
Copy link
Author

boobiq commented Mar 28, 2025

You can disable the VCS provider via the com.github.lppedd.cc.providers.vcs registry key, and you can disable Recently used prioritization via Conventional Commit settings.

I would need this setting per footer type because I want to get issues for things like Closes: or Relates-to: but not for things with values :)

Could you let me know what exception you see in the IDE logs?

Not sure if there are other logs than popup and notifications, I even tried "Tail Log in Console" but there was nothing, all I see is this:

Image

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