Skip to content

Commit

Permalink
Merge pull request #3297 from niksilver/master
Browse files Browse the repository at this point in the history
Elm,Units: Type and constructor tags exclude parameters etc.

Quoted from the pull request:

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.
  • Loading branch information
masatake committed Feb 22, 2022
2 parents 8e1e0a2 + bad9fe8 commit 32b8e90
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Units/simple-elm.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Maybe input.elm /^import Maybe exposing (withDefault)$/;" m roles:imported
Je input.elm /^import Json.Encode as Je$/;" n roles:def
Thing input.elm /^type Thing$/;" t roles:def
One input.elm /^ = One$/;" c type:Thing roles:def
Two Int input.elm /^ | Two Int$/;" c type:Thing roles:def
Param a input.elm /^type Param a$/;" t roles:def
Cons a input.elm /^ = Cons a$/;" c type:Param a roles:def
Other a input.elm /^ | Other a$/;" c type:Param a roles:def
Two input.elm /^ | Two Int$/;" c type:Thing roles:def
Param input.elm /^type Param a$/;" t roles:def
Cons input.elm /^ = Cons a$/;" c type:Param roles:def
Other input.elm /^ | Other a$/;" c type:Param roles:def
Num input.elm /^type alias Num =$/;" a roles:def
outward input.elm /^port outward : String -> Cmd a$/;" p roles:def
inward input.elm /^port inward : (b -> a) -> Sub a$/;" p roles:def
Expand Down
4 changes: 2 additions & 2 deletions optlib/elm.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ extern parserDefinition* ElmParser (void)
"m", "{scope=clear}{exclusive}{_role=imported}", NULL, false},
{"^port[[:blank:]]+([[:lower:]][[:alnum:]_]*).*", "\\1",
"p", "{scope=clear}{exclusive}", NULL, false},
{"^type +([[:upper:]][[:alnum:]_]*.*)", "\\1",
{"^type +([[:upper:]][[:alnum:]_]*).*", "\\1",
"t", "{scope=set}{exclusive}", NULL, false},
{"^[[:blank:]]+[|=][[:blank:]]+([[:upper:]][[:alnum:]_]*.*)$", "\\1",
{"^[[:blank:]]+[|=][[:blank:]]+([[:upper:]][[:alnum:]_]*).*$", "\\1",
"c", "{scope=ref}{exclusive}", NULL, false},
{"^type[[:blank:]]+alias[[:blank:]]+([[:upper:]][[:alnum:]_]*[[:blank:][:alnum:]_]*)", "\\1",
"a", "{scope=set}{exclusive}", NULL, false},
Expand Down
4 changes: 2 additions & 2 deletions optlib/elm.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
--regex-Elm=/^import[[:blank:]]+([[:alnum:]_.]+)[[:blank:]]exposing/\1/m/{scope=clear}{exclusive}{_role=imported}
--regex-Elm=/^import[[:blank:]]+([[:alnum:]_.]+)/\1/m/{scope=clear}{exclusive}{_role=imported}
--regex-Elm=/^port[[:blank:]]+([[:lower:]][[:alnum:]_]*).*/\1/p/{scope=clear}{exclusive}
--regex-Elm=/^type +([[:upper:]][[:alnum:]_]*.*)/\1/t/{scope=set}{exclusive}
--regex-Elm=/^[[:blank:]]+[|=][[:blank:]]+([[:upper:]][[:alnum:]_]*.*)$/\1/c/{scope=ref}{exclusive}
--regex-Elm=/^type +([[:upper:]][[:alnum:]_]*).*/\1/t/{scope=set}{exclusive}
--regex-Elm=/^[[:blank:]]+[|=][[:blank:]]+([[:upper:]][[:alnum:]_]*).*$/\1/c/{scope=ref}{exclusive}
--regex-Elm=/^type[[:blank:]]+alias[[:blank:]]+([[:upper:]][[:alnum:]_]*[[:blank:][:alnum:]_]*)/\1/a/{scope=set}{exclusive}
--regex-Elm=/^([[:lower:]_][[:alnum:]_]*)[^=]*=$/\1/f/{scope=set}
--regex-Elm=/^[[:blank:]]+([[:lower:]_][[:alnum:]_]*)[^=]*=$/\1/f/{scope=ref}

0 comments on commit 32b8e90

Please sign in to comment.