Replies: 3 comments 10 replies
-
Thank you for your example @ddscharfe . Please note, that for command handler in particular and for some other UI objects we can use "native" Eclipse DI. It would be great if you can extend your example to let us see:
|
Beta Was this translation helpful? Give feedback.
-
This looks ok to me. The bindings as written is ok to me, and the tooling works. There is a little magic, but no worse and probably better than the magic of adapters in Eclipse, but not quite as nice as a well written extension. The change as you have presented it makes getUri properly testable which is a good way forward. Do you see using the guice as an internal implementation detail, or does it apply to extending the code too? On the former it doesn't really affect the API and makes the code testable which is a good thing. When it comes to third-parties extending the CDT code with Guice I am less clear on how it would best work. e.g does your suggestion include changing how server providers are done? |
Beta Was this translation helpful? Give feedback.
-
I've made similar experiences with with DI as @ddscharfe. We are using I cannot say which injection framework is better. |
Beta Was this translation helpful? Give feedback.
-
As talked about in the last cdt call, I'd like to discuss whether to use DI in cdt-lsp and how to use it.
What I generally like about using DI is that it makes testing easier (e.g. by avoiding static methods) and helps sharing code between classes. On the other hand it adds some complexity and makes dependencies less obvious, which some people don't like.
I setup an example where I modified
ToggleSourceAndHeaderCommandHandler
to use an external implementation to get the uri for an editor part. As there is no test (yet) for this, using DI there doesn't bring too much benefits, but I think it is enough to show how we could use DI in cdt-lsp.Note that there is some initial boilerplate (e.g.
org.eclipse.cdt.lsp.di.AbstractGuiceAwareExecutableExtensionFactory
which I copied from xtext and theInjector
creation in the activators). However once setup, I think this is an easy way to use DI.See: master...ddscharfe:eclipse-cdt-lsp:di-example
The "interesting" part is in c001fff.
@jonahgraham @ghentschke @ruspl-afed
Beta Was this translation helpful? Give feedback.
All reactions