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

PascalCase matches one word #27

Open
kawarimidoll opened this issue Jun 18, 2022 · 4 comments
Open

PascalCase matches one word #27

kawarimidoll opened this issue Jun 18, 2022 · 4 comments

Comments

@kawarimidoll
Copy link

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

@monaqa
Copy link
Owner

monaqa commented Jun 18, 2022

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"?

@kawarimidoll
Copy link
Author

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.

@monaqa
Copy link
Owner

monaqa commented Jun 20, 2022

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 monaqa reopened this Jun 20, 2022
@RobertAudi
Copy link

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

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

No branches or pull requests

3 participants