Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why members of CompletionItem are pointers? #29

Open
pherrymason opened this issue May 5, 2024 · 6 comments
Open

Why members of CompletionItem are pointers? #29

pherrymason opened this issue May 5, 2024 · 6 comments

Comments

@pherrymason
Copy link

What's the reasoning behind some CompletionItem members like Kind, Details, Deprecated, Preselect, etc... are defined as pointers?

@tliron
Copy link
Owner

tliron commented May 9, 2024

Because they are optional. The nil value should be interpreted as "doesn't exist".

This should definitely be documented better...

@pherrymason
Copy link
Author

pherrymason commented May 10, 2024

Have you considered using an optional type?
Like:

type Option[T any] struct {
   value  T
   isSetted bool
}

func Some[T any](value T) Option[T] {
   return Option[T]{value: value, isSetted: true}
}

func None[T any]() Option[T] {
   return Option[T]{isSetted : false}
}

@tliron
Copy link
Owner

tliron commented May 10, 2024

The project started before generics were available. It is definitely possible to switch, but ... for what it's worth, Go has nils. (Terrible design decision.) And nils are very often used for exactly this semantic intent. I don't love it, but it's common practice in Go (and other null-enabled languages) and I think changing this now may annoy current users of this library.

@pherrymason
Copy link
Author

I'm ok with it!

@tliron
Copy link
Owner

tliron commented May 10, 2024

Thank you for the discussion, it's useful. I'm not opposed to changing in the future. I will re-open this as an issue to document the use of nils, at the very least.

@tliron tliron reopened this May 10, 2024
@pherrymason
Copy link
Author

Thank you too.
I'm not an expert with Go, explaining me the context allowed me to understand better the design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants