lexical-lsp / lexical

Lexical is a next-generation elixir language server
776 stars 77 forks source link

Completion: show type spec for struct fields #751

Closed kirillrogovoy closed 1 month ago

kirillrogovoy commented 1 month ago

Fixes #749

:type_spec is already a part of the elixir_sense_map, so defining it in defstruct is enough.

If the struct doesn't have a type spec, it would show "Field" in my editor probably because that's how it handles completion.detail == nil

Let me know if it's more desirable to fall back to some string explicitly, e.g.:

builder.plain_text(env, struct_field.name,
  detail: struct_field.type_spec || "Field",
  label: struct_field.name,
  kind: :field
)
scohen commented 1 month ago

I think "Field" is coming from the LSP "kind" of the completion, and detail is nil-able, which means it'll just not display anything. It might be interesting to display "dynamic" or "unknown type" there, but that might just be noisy.

FYI, my editor (emacs) also displays "Field" on completions.

This looks great. Thanks for contributing!