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

[#227] Refactor ClangdConfigurationManager #229

Merged
merged 6 commits into from
Jan 26, 2024

Conversation

ghentschke
Copy link
Contributor

  • Allows vendors to overwrite default behavior

fixes #227

- Allows vendors to overwrite default behavior

fixes eclipse-cdt#227
@ghentschke ghentschke requested review from jonahgraham and ruspl-afed and removed request for jonahgraham January 14, 2024 21:39
@ghentschke
Copy link
Contributor Author

Still some unit test issues.

Copy link
Member

@ruspl-afed ruspl-afed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From #227 (comment) :

So, this should also be a default setup (or at least to be achievable without writing your own plugin) with CDT LSP.

I would say "default setup" request is questionable, but "achievable without writing your own plugin" sounds reasonable. Does this PR satisfy the mentioned need?

@@ -48,14 +51,15 @@ public void start(BundleContext context) throws Exception {
workspaceTracker.open();
workspace = workspaceTracker.getService();
compileCommandsMonitor = new CompileCommandsMonitor(workspace).start();
cProjectChangeMonitor = new CProjectChangeMonitor().start();
cProjectChangeMonitor = Optional.ofNullable(PlatformUI.getWorkbench().getService(CProjectChangeMonitor.class))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

component may have methods annotated with
@Activate and @Deactivate, so we can avoid this code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hint. I'll check that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at my last commit

@@ -61,6 +61,24 @@ public static IProject createCProject(String projectName) throws CoreException {
return project;
}

// static IProject createEmptyCMakeProject(String projectName) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this code or not? If not, let's remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* Gesa Hentschke (Bachmann electronic GmbH) - initial implementation
*******************************************************************************/

package org.eclipse.cdt.lsp.clangd;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually the component is a part of implementation, and not a part of [potential] API, it should be placed to internal package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at my last commit

* with a service.ranking property > 0 to implement custom behavior
* and to replace the {@link ClangdConfigurationManager}
*/
public interface ClangdCProjectDescriptionListener {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this interface needs more work, it has 3 methods with tightly-coupled implementation and all of them are open for public invocation. Ideally there should be only one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed with my last commit

@ghentschke
Copy link
Contributor Author

From #227 (comment) :

So, this should also be a default setup (or at least to be achievable without writing your own plugin) with CDT LSP.

I would say "default setup" request is questionable, but "achievable without writing your own plugin" sounds reasonable. Does this PR satisfy the mentioned need?

Yes. They have to implement either CProjectChangeMonitor as an OSGi service if they don't want the listener to CProject changes at all (the start() and stop() methods do nothing in that case),
or implement ClangdCProjectDescriptionListener and overwrite enableSetCompilationDatabasePath(IProject project)

I put the default implementations in the org.eclipse.cdt.lsp.clangd package to allow vendors to extend the defualt implementations (can be usefull when only one methods like enableSetCompilationDatabasePath(IProject project) should be overwritten). That's why the interface ClangdCProjectDescriptionListener has 3 (tightly coupled) methods. The ClangdConfigurationFileManager can be seen as an base class for vendors.

@ruspl-afed
Copy link
Member

Yes, I understand the idea of the fix. My point is that class with @Component annotation usually is not a part of API, however it can extend the API class.

Also, I had an impression that the original request was to have something like preference-controlled strategy rather than API to override. But let's wait for a feedback.

- Fix bundle activator/Service Component Runtime (SCR) problem: The
Bundle Activator's start method must not rely upon SCR having activated
any of the bundle's components. However, the components can rely upon
the Bundle Activator's start method having been called. That is, there
is a happens-before relationship between the Bundle Activator's start
method being run and the components being activated.

fixes eclipse-cdt#227
* @param project managed C/C++ project
* @param newCProjectDescription new CProject description
* @param macroResolver helper to resolve macros in the CWD path of the builder
*/
public void setCompilationDatabasePath(IProject project, ICProjectDescription newCProjectDescription,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, since this is no longer part of ClangdCProjectDescriptionListener interface, it's enough to make this method protected.

* Enabler for {@link setCompilationDatabasePath}. Can be overriden for customization.
* @param project
* @return true if the database path should be written to .clangd file in the project root.
*/
public boolean enableSetCompilationDatabasePath(IProject project) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, since this is no longer part of ClangdCProjectDescriptionListener interface, it's enough to make this method protected.

@travkin79
Copy link
Contributor

Also, I had an impression that the original request was to have something like preference-controlled strategy rather than API to override. But let's wait for a feedback.

I'm not sure how such a preference for our case could look like. Disabling the creation of .clangd files per project with a setting would be tedious in our case since it would involve configuring quite a lot of projects. Thus, it's absolutely good enough for our case to sub-class the default implementation, the ClangdConfigurationFileManager class.

I've implemented a working prototype and it works as expected. Thank you @ghentschke.

- make methods protected since they aren't part of the interface
anymore.

fixes eclipse-cdt#227
@ghentschke ghentschke merged commit 2fe1c1d into eclipse-cdt:master Jan 26, 2024
3 checks passed
@ghentschke ghentschke deleted the fix-issue-227 branch February 9, 2024 07:26
@ghentschke ghentschke added this to the 1.1.0 milestone Feb 19, 2024
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

Successfully merging this pull request may close these issues.

Stop creating .clangd file per Eclipse project if the config is defined elsewhere
3 participants