dial.nvim icon indicating copy to clipboard operation
dial.nvim copied to clipboard

`PascalCase` matches one word

Open kawarimidoll opened this issue 3 years ago • 4 comments

The help says Currently, this augend does NOT recognize identifiers that consist of only one word., but PascalCase matches to the word starts with capital letter like 'Word' and 'WORD'.

This is a minimum setting to reproduce ↓

lua << EOF
local augend = require("dial.augend")
require("dial.config").augends:register_group{
  default = {
    augend.case.new{
      types = {"camelCase", "PascalCase"},
    },
  },
}
EOF

In this GIF, dial.nvim thinks that 'EOF' is PascalCase ↓

画面収録 2022-06-18 22 03 08

kawarimidoll avatar Jun 18 '22 13:06 kawarimidoll

Thanks for the report. You are right, it is inconvenient. However, I am not sure how to solve this problem, because it is not obvious how to handle a sequence of uppercase letters in PascalCase. For example, if I want to change the word "LicenseMIT" from PascalCase to snake_case, how should that be handled? What about the case of "ParseCLanguage"?

monaqa avatar Jun 18 '22 22:06 monaqa

Using Regex Lookahead, a sequence of capital letters can be considered a single word. Here is an example in JavaScript:

const regex = /[A-Z]([A-Z](?![a-z]))+|[A-Z][a-z]*/g

'LicenseMIT'.match(regex)
// -> ['License', 'MIT']

'ParseCLanguage'.match(regex)
// -> ['Parse', 'C', 'Language']

'JSONToYAMLConverter'.match(regex)
// -> ['JSON', 'To', 'YAML', 'Converter']

In this case, however, there are some probrems.

  • The capital parts cannot be restore once convert to snake_case: LicenseMIT -> license_mit -> LicenseMit
  • The sequence of capital-only-word cannot be detect: JSONYAMLConverter -> jsonyaml_converter

It is a difficult problem and it may good to ignore the word that has a sequence of capital letters.

I reported this issue because the behavior was different from the help.

kawarimidoll avatar Jun 20 '22 02:06 kawarimidoll

Yes, as you say, the current implementation is compatibility oriented. However, the word detection algorithm could use a little more improvement. It may be possible to sacrifice compatibility for greater convenience.

monaqa avatar Jun 20 '22 04:06 monaqa

@monaqa A "potential" solution/workaround could be to implement something similar to ActiveSupport::Inflections#acronym and then keep the current algorithm as it is 🤔

RobertAudi avatar Jun 20 '22 06:06 RobertAudi