davidsierradz / cmp-conventionalcommits

(WIP) nvim-cmp source for autocompleting git commits with conventional commits types and lerna packages as scope
MIT License
65 stars 4 forks source link

not working #3

Closed ShelpAm closed 1 year ago

ShelpAm commented 1 year ago

I can't get a completion from this plugin.

ShelpAm commented 1 year ago

What I actually want to know is how to 'Reads your configured scopes from [commitlint](https://commitlint.js.org/#/'.

davidsierradz commented 1 year ago

What I actually want to know is how to 'Reads your configured scopes from [commitlint]

Can you run node --eval 'eval("var obj ="+process.argv[1]);console.log(JSON.stringify(obj?.rules?.["type-enum"]?.[2]));' "$(npx commitlint --print-config --no-color | tr '\n' ' ')" 2>/dev/null on the root of your project?

ShelpAm commented 1 year ago

What I actually want to know is how to 'Reads your configured scopes from [commitlint]

Can you run node --eval 'eval("var obj ="+process.argv[1]);console.log(JSON.stringify(obj?.rules?.["type-enum"]?.[2]));' "$(npx commitlint --print-config --no-color | tr '\n' ' ')" 2>/dev/null on the root of your project?

Ok, I will try it tomorrow.

ShelpAm commented 1 year ago

What I actually want to know is how to 'Reads your configured scopes from [commitlint]

Can you run node --eval 'eval("var obj ="+process.argv[1]);console.log(JSON.stringify(obj?.rules?.["type-enum"]?.[2]));' "$(npx commitlint --print-config --no-color | tr '\n' ' ')" 2>/dev/null on the root of your project?

It returns 'undefined'. Then how should I fix it please?

davidsierradz commented 1 year ago

You should install (and configure) @commitlint/cli and a configuration like @commitlint/config-conventional

ShelpAm commented 1 year ago

You should install (and configure) @commitlint/cli and a configuration like @commitlint/config-conventional

Now I have installed and configured them. And what else should I do?

ShelpAm commented 1 year ago

After running this echo '123' | commitlint, I got: ⧗ input: 123 ✖ subject may not be empty [subject-empty] ✖ type may not be empty [type-empty]

✖ found 2 problems, 0 warnings,

Then I ran node --eval 'eval("var obj ="+process.argv[1]);console.log(JSON.stringify(obj?.rules?.["type-enum"]?.[2]));' "$(npx commitlint --print-config --no-color | tr '\n' ' ')" 2>/dev/null, and it returns ["build","chore","ci","docs","feat","fix","perf","refactor","revert","style","test"]. However, when I tried git commit, The plugin didn't work yet.

davidsierradz commented 1 year ago

Well, I'm running out of ideas. Can you add this to your cmp config?:

...
  mapping = cmp.mapping.preset.insert({
    ['<C-Space>'] = cmp.mapping.complete({
      config = {
        sources = {
          { name = 'conventionalcommits' },
        },
      },
    }),
  }),
...

Then, enter neovim (with nvim -c 'set ft=gitcommit', for example) in a gitcommit filetype buffer, enter insert mode on the first row and column (0,0) of the buffer and press <Ctrl-Space> (with your keyboard, something like this should appear:

image

https://user-images.githubusercontent.com/9190258/233401784-87180c6d-8337-40d2-97c6-0d98dcf6b48e.mp4

ShelpAm commented 1 year ago

Well, I'm running out of ideas. Can you add this to your cmp config?:

...
  mapping = cmp.mapping.preset.insert({
    ['<C-Space>'] = cmp.mapping.complete({
      config = {
        sources = {
          { name = 'conventionalcommits' },
        },
      },
    }),
  }),
...

Then, enter neovim (with nvim -c 'set ft=gitcommit', for example) in a gitcommit filetype buffer, enter insert mode on the first row and column (0,0) of the buffer and press <Ctrl-Space> (with your keyboard, something like this should appear:

image 2023-04-20.09-38-23.mp4

Thanks! It works! But when I run git commit, it breaks again.

ShelpAm commented 1 year ago

It seems that only when I commit does it not work.

ShelpAm commented 1 year ago

I find that after setting the filetype, it works. What exactly is the problem??

davidsierradz commented 1 year ago

The completion only activates on gitcommit buffers, so is a requisite. git commit should setup your $EDITOR correctly, can't help you with that.

ShelpAm commented 1 year ago

Ok, still thanks a lot for your help!