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

Elm,Units: Type and constructor tags exclude parameters etc. #3297

Merged
merged 1 commit into from
Feb 22, 2022

Conversation

niksilver
Copy link
Contributor

This has been tested with

make units UNITS=simple-elm

which passes.

This is based on a problem encountered in Vim using ctags. It's possible this problem is entirely different (or maybe isn't even a problem!) with a different Vim configuration, a different editor, or a different use case.

To understand the problem being addressed, consider the following code:

type Param a
    = Cons a
    | Other a

baz : Param Int
baz =
    Cons 42

If the cursor is positioned under the Cons of the last line, then hitting Ctrl-] should take us to the definition of Cons on line 2. However, this fails because Vim identifies the tag under the cursor as the pure alphanumeric string Cons, but the tag in the tag file is Cons a.

Similarly for when the cursor is placed under Param in the third line from the bottom.

Also, if the definition of Param was

type Param a =
    Cons a
    | Other a

then its tag would be recorded as Param a =. Even though that's not the recommended way to format Elm it would still be helpful to generate a useful tag.

So this change is to have tags for types and constructors limited to the initial alphanumeric part, which solves all these problems.

@codecov
Copy link

codecov bot commented Feb 15, 2022

Codecov Report

Merging #3297 (bad9fe8) into master (38c046d) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3297   +/-   ##
=======================================
  Coverage   85.27%   85.27%           
=======================================
  Files         211      211           
  Lines       49826    49826           
=======================================
  Hits        42488    42488           
  Misses       7338     7338           
Impacted Files Coverage Δ
optlib/elm.c 0.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 38c046d...bad9fe8. Read the comment docs.

@masatake masatake merged commit 32b8e90 into universal-ctags:master Feb 22, 2022
@masatake
Copy link
Member

masatake commented Feb 22, 2022

@niksilver, thank you.
type variables (type parameters?) like a can be stored to signature: field.
Do you have an interest in filling the field for tags like:

Param	input.elm	/^type Param a$/;"	kind:type	signature:a
Cons	input.elm	/^    = Cons a$/;"	kind:constructor	signature:a	scope:type:Param	roles:def
Other	input.elm	/^    | Other a$/;"	kind:constructor	signature:a	scope:type:Param	roles:def

@niksilver
Copy link
Contributor Author

Hello @masatake. Thank you for accepting my code change.

I'm currently trying to build a PackCC parser for Elm which will be more robust than the current regexp parser. As part of that I will see if I can add your suggestions. However, it's very slow going as I'm only a hobbyist developer. So I dare not give a timeframe, but it is something I'm working on.

@masatake
Copy link
Member

I'm currently trying to build a PackCC parser for Elm which will be more robust than the current regexp parser. As part of that I will see if I can add your suggestions. However, it's very slow going as I'm only a hobbyist developer. So I dare not give a timeframe, but it is something I'm working on.

Interesting.

Have you ever considered using the --_mtable-regex-<LANG> option?
https://docs.ctags.io/en/latest/optlib.html?highlight=mtable-regex#adding-a-regex-to-a-regex-table

If you are interested in the option, I will write a small initial version of mtable-regex based Elm parser.

@niksilver
Copy link
Contributor Author

Thanks, @masatake, that looks very promising. I'm going to pursue the PackCC parser for a while longer, but will revert to the mtable regexp approach if I feel like I'm losing the battle.

@masatake
Copy link
Member

@niksilver does your ctags link to pcre2?
I would like to write an initial version of mtable based Elm parser using pcre2.

@niksilver
Copy link
Contributor Author

Apparently no pcre2...

$ ./ctags --list-features
#NAME             DESCRIPTION
gnulib_regex      linked with the Gnulib regular expression library
iconv             can convert input/output encodings
option-directory  TO BE WRITTEN
optscript         can use the interpreter
packcc            has peg based parser(s)
regex             can use regular expression based pattern matching
wildcards         can use glob matching

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

Successfully merging this pull request may close these issues.

None yet

2 participants