cursorless icon indicating copy to clipboard operation
cursorless copied to clipboard

Elixir support

Open r-tae opened this issue 2 years ago • 12 comments
trafficstars

What

Adds support for the elixir programming language

Checklist

  • [x] Recorded tests for the new language
  • [x] Used "change" / "clear" instead of "take" for selection tests to make recorded tests easier to read
  • [ ] Added a few specific tests that use "chuck" instead of "change" to test removal behaviour when it's interesting, especially:
    • [ ] "chuck arg" with single argument in list
    • [ ] "chuck arg" with multiple arguments in list
    • [ ] "chuck item" with single argument in list
    • [ ] "chuck item" with multiple arguments in list
  • [x] Added @textFragment captures. Usually you want to put these on comment and string nodes. This enables "take round" to work within comments and strings.
  • [ ] Added a test for "change round" inside a string, eg "hello (there)"
  • [/] Supported "type" both for type annotations (eg foo: string) and declarations (eg interface Foo {}) (and added tests for this behaviour 😊)
  • [ ] Supported "item" both for map pairs and list entries (with tests of course)
  • [ ] Add support for "name"

r-tae avatar Sep 03 '23 16:09 r-tae

There's an edge case for maps that I can't quite figure out.

Elixir has two syntaxes for map key-value pairs:

# regular map
%{"string key" => nil, :atom_key => nil, 123 => nil}
# shorthand for all atom keys
%{a: 1, b: 2, c: 3}

however, those can be combined as long as all the shorthand ones go at the end:

%{"a" => 1, b: 2, c: 3}

This means the AST has separators at two different levels, which leads to weird behaviour if you target the separators themselves

%{"a" => 1, b: 2, c: 3}

---

(source
  (map
    (map_content
      (binary_operator
        left: (_)
        right: (_))
      ","
      (keywords
        (pair
          key: (_)
          value: (_))
        ","
        (pair
          key: (_)
          value: (integer))))))
          *
%{"a" => 1, b: 2, c: 3}
  ^^^^^^^^^^^^^^
  item comma
                *
%{"a" => 1, b: 2, c: 3}
            ^^^^^^^^^^
            item blue comma

r-tae avatar Sep 04 '23 13:09 r-tae

This is great! I'm about to be doing some elixir work. What's left to this? Can I help?

jaresty avatar Jan 03 '24 06:01 jaresty

@jaresty help would be great! I haven't had a chance to do any more on this since Sept. The biggest outstanding thing is drink/pour in lists/maps (see Pokey's last comment, I haven't made it to a meetup since).

I don't remember what else is outstanding, but I think its mergable if we get just that working

r-tae avatar Jan 03 '24 15:01 r-tae

@r-tae I'd love to help! Could we maybe find some time where you could introduce me to the work? I sent you a message on slack if you'd like to coordinate.

jaresty avatar Jan 03 '24 16:01 jaresty

"call"

image

⬆️ I'm a bit surprised that a module definition is considered a call

image image

⬆️ It's also surprising that function definitions are considered calls

But maybe the above all technically are function calls, because they're calling def and defmodule, respectively? I guess it depends whether users would view those as function calls

image

⬆️ I'm no Elixir expert, but one_arg(x) looks like the name / arg list, not a call

pokey avatar Jan 26 '24 14:01 pokey

"funk"

image image

Are these not function definitions?

pokey avatar Jan 26 '24 14:01 pokey

"key"

image

doesn't look right to me; should just be a and b

image

shouldn't name and email and "name" be keys? I'm also not convinced user should be a key at all 🤔

image image

We generally prefer if removal range of key extends all the way to start of value, to make it easier to convert a map to a list

pokey avatar Jan 26 '24 14:01 pokey

"value"

image

Looks like nested values are missing here (ie "Jane" and "[email protected]")

image

As with "key", the removal range for value should extend from end of key

pokey avatar Jan 26 '24 14:01 pokey

Ok I kicked the ball down the field a bit; see my changes @jaresty I'm happy to get you up to speed on this PR in a meet-up if you want to carry it to the finish line; not too much left

pokey avatar Jan 26 '24 14:01 pokey

Thank you for that @pokey - I'm unexpectedly in a job search so it may be some time before I can get back to this.

jaresty avatar Jan 26 '24 14:01 jaresty

ok @r-tae if you wanna bring this home go for it. Otherwise I may take a pass again in the future

pokey avatar Jan 26 '24 15:01 pokey

@r-tae wanted to let you know that community now has an elixir language mode 😄

jaresty avatar Oct 18 '24 22:10 jaresty

@r-tae @jaresty Would be great if any of you had the time to finish this one. I will convert it to draft in the meantime.

AndreasArvidsson avatar Jan 14 '25 15:01 AndreasArvidsson