g5becks

g5becks

Auto completion for struct fields Elixir ls

According to THIS elixir-ls is supposed to be able to do autocompletion for the names of struct fields.

I am using vscode with the forked ls plugin https://marketplace.visualstudio.com/items?itemName=elixir-lsp.elixir-ls . I have tried quite a bit, but no matter what I do I cannot get any sort of autocompletion for struct fields to work for me, everything else is working quite fine.

It’s kind of hard to remember the names of struct fields in different contexts of a codebase, and coming from primarily writing in statically typed languages, it’s not something I’m accustomed to having to think about, so this would be a big time saver for me. Does anyone have this feature working correctly? In the elixir for programmers course, I see dave using this feature a few times, so I know that it works in emacs at least.

Marked As Solved

mainlymortal

mainlymortal

I’m using the forked plugin and do have auto-completion for struct fields.

Also Liked

g5becks

g5becks

I think elixir would be the best functional language available if it had a HM type system.

Currently, I have programmed professionally in Scala only, and I don’t miss it at all. The complexity of managing to exist in that ecosystem was unbearable, you just never know what to expect. One minute you’re coding like it’s Haskell, and then the next you’re dealing with some huge inheritance hierarchy, and implicits OMG, don’t get me started. I still have nightmares about SBT. I will never accept a job using Scala again.

Other than that, I have written programs using Kotlin, and F#. One thing Elixir, Scala, Kotlin, F#, Clojure all have in common is that they are all built on top of pre-existing platforms, and this is where ( so far ) Elixir outshines all of the competition to me. In Kotlin, Scala, and F#, as soon as you pull in a dependency from the Platform ( jvm / .net), you are right back in OOP land, which defeats the whole purpose. Sure you get access to a huge ecosystem, but at what cost? To some, it may be worth it, but to me, it’s not.

My job requires me to program in Go, which is not as bad a language as a lot of people make it out to be, but if you think functionally, it sucks. For me, Elixir is like the Golang of the Functional programming world, to some that may sound like an insult, but it’s not. Elixir is super simple, and simplicity is hard. Go is unapologetically procedural and it makes very few compromises. It’s a very stripped-down language that gets out of your way and lets you do everything you need to do in order to get work done ( albeit very procedural manner ) and has very good support for concurrency. I would choose it over any OOP language available in a heartbeat.

Elixir is the same except for it lets you do everything you need to do in a functional manner, and it ( like Go ) has great support for concurrency and makes no compromises about what it is. It is not a confused language and it did not have to add language constructs that do not fit its paradigm in order to adapt to the underlying platform, I like that a lot.

thousandsofthem

thousandsofthem

Re: arguments - it’s quote easy to add types to function arguments (guards and inline stuff like fnname(foo = %Abc{}). For me that’s good enough level of static typing

axelson

axelson

Scenic Core Team

As mainlymortal mentioned auto-completion for struct fields is supported within struct definitions for ElixirLS. In practice (for me at least) this isn’t too large of an issue because I generally prefer pattern matching out fields of a struct because then the code will fail to compile if I change a field name. If you use the my_struct_instance.my_field version then you will get a runtime error if you rename your field from my_field to my_better_field. So instead I typically do %MyStruct{my_field: my_field} and then use my_field in the rest of the code.

I suspect that Dave may have either been using Alchemist.el (unfortunately no longer maintained), although I’m not sure if it has the feature that you want, it may have been using some type of heuristics to guess the variable type (or that could have been supplied by some other emacs plugin).

g5becks

g5becks

Thanks for the reply, I think that what is provided by the plugin will be fine for now, I just need to adjust my code to what you advised, pattern matching seems like much more idiomatic elixir approach than accessing struct fields by name.

I do think it would still be a nice added feature though.

axelson

axelson

Scenic Core Team

Yeah, I agree that it would be a nice feature. An PR’s that implement that would most definitely be welcomed :slight_smile:

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement