DanielGavin / ols

Language server for Odin
MIT License
375 stars 56 forks source link

add additional completion snippets for dynamic arrays #407

Closed hhhapz closed 2 weeks ago

hhhapz commented 2 weeks ago

This commit adds a handful of completion snippets for dynamic arrays from the builtin package.

Some of these are less often used than others, however since the completion entries otherwise should always be empty, I think that filling in all of these should be OK.

The most useful one for me, personally is append, however I felt like while I was at it, I might as well add the rest as well :).

DanielGavin commented 2 weeks ago

Yeah it's fine to add them as snippets.

There seems to be one issue:

newText = fmt.tprintf("%s(&%v, $0)", name, symbol_str),

You assume that the array is not a pointer by hardcoding &.

It might have to be something like this:

if symbol.pointers > 0 {
  common.repeat(
  "^",
  symbol.pointers-1, //If it's zero it just doesn't do anything
  context.temp_allocator,
  )
} else {
  just hardcode &
}

Possible arrays: ^[dynamic]int, ^^[dynamic]int, [dynamic]int

hhhapz commented 2 weeks ago

good catch

hhhapz commented 2 weeks ago

@DanielGavin I'm still relatively new odin, and the lack of + was painful. Let me know if you feel there's a more 'idiomatic' way to do this that I might have missed. This seemed the most clear and straightforward to me.

DanielGavin commented 2 weeks ago

Seems good now.