-
Notifications
You must be signed in to change notification settings - Fork 11
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
Stop creating .clangd file per Eclipse project if the config is defined elsewhere #227
Comments
@travkin79 I don't have an immediate answer for you on this. However at our CDT call yesterday I think something similar was being discussed by @Kummallinen and @ghentschke in case they have input here. |
I would possibly argue that the problem is in org.eclipse.cdt.lsp.internal.clangd.CProjectChangeMonitor, where the assumption is that if there are build settings for a given, then this project needs 1) a .clangd file (wrong in our case) and 2) to tell clangd where to look for the corresponding compile_commands.json (also wrong in our case). |
My first idea is to prevent the creation of the |
What about: public interface ClangdConfiguration {
// return true if the .clangd file should be generated in the project root folder if it's missing.
boolean createClangdFile();
} |
The decision should be per project, I would believe. Is this service obtained per project? Otherwise we would possibly add the project as parameter: |
In general, however, I tend to argue that the default behavior of clangd to look for |
That's right. But cmake generates the One purpose of the I think the mentioned behavior above is needed by @Kummallinen
Yes, you are right. The project is needed to determine if it's the root project. |
Hi @ghentschke, |
- Allows vendors to overwrite default behavior fixes eclipse-cdt#227
@travkin79 please check if the PR #229 would fulfill your needs. |
- Fix unit tests fixes eclipse-cdt#227
Hello @ghentschke, |
- Support cmake projects as well fixes eclipse-cdt#227
- Add org.eclipse.cdt.cmake.core to target definition fixes eclipse-cdt#227
Hello @ghentschke, I'm trying to implement a custom
What is the best way to also customize the clangd path for certain projects and leave the settings for all other projects unchanged? I also found a minor issue with the clangd plug-in activator. The following code produces some exceptions during Eclipse start. The call of org.eclipse.cdt.lsp.internal.clangd.editor.ClangdPlugin.java: cProjectChangeMonitor = Optional.ofNullable(
PlatformUI.getWorkbench().getService(CProjectChangeMonitor.class))
.map(m -> m.start()); Stacktrace:
I think, I fixed the @Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
ServiceTracker<IWorkspace, IWorkspace> workspaceTracker = new ServiceTracker<>(context, IWorkspace.class, null);
workspaceTracker.open();
workspace = workspaceTracker.getService();
compileCommandsMonitor = new CompileCommandsMonitor(workspace).start();
ServiceTracker<CProjectChangeMonitor, CProjectChangeMonitor> cProjectChangeMonitorTracker = new ServiceTracker<>(
context, CProjectChangeMonitor.class,
new ServiceTrackerCustomizer<CProjectChangeMonitor, CProjectChangeMonitor>() {
@Override
public CProjectChangeMonitor addingService(ServiceReference<CProjectChangeMonitor> reference) {
CProjectChangeMonitor result = context.getService(reference);
cProjectChangeMonitor = Optional.ofNullable(result);
cProjectChangeMonitor.ifPresent(m -> m.start());
return result;
}
@Override
public void modifiedService(ServiceReference<CProjectChangeMonitor> reference,
CProjectChangeMonitor service) {
}
@Override
public void removedService(ServiceReference<CProjectChangeMonitor> reference,
CProjectChangeMonitor service) {
cProjectChangeMonitor = Optional.empty();
}
});
cProjectChangeMonitorTracker.open();
cProjectChangeMonitor = Optional.ofNullable(cProjectChangeMonitorTracker.getService());
} |
- 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
@travkin79 please take a look at my last commit in the PR #229.
Yes, we haven't tagged it as a stable API right now. The
Yes, that's what I had on my mind as I wrote that code. You should simply extend
This should be fixed with my last commit now.
That's not possible at the moment, since we are supporting only one clangd LS per workspace. There is still this open issue #43 |
Thank you very much, @ghentschke!
Ok. I used only classes from that package anyway. Then, we'll wait for that package to become public API and will ignore the warnings until then.
That's exactly what I did in a first prototype. It works as expected.
Yes, the exceptions do not occur anymore.
Oh, that's good to know. Thank you for the hint. We didn't know there can be only one language server per workspace. We saw the language server extension point and thought we could provide a custom language server with adapted clangd path settings for our selected projects and use the default language server for all other projects. Our customized server provider was meant to be a sub-class of the original language server provider, but the class Maybe, the clangd path could be customized in the same way as we customize the creation of We'll watch the issue #43. |
- make methods protected since they aren't part of the interface anymore. fixes eclipse-cdt#227
My question would be, why would you like to use different language servers? Could the different setting be solved by writing them in the The LS properties in the projects are a little misleading at the moment as they are only used when the project is the initial project. That means a file from within that project is the first file to be opened and triggers the LS to be started. |
In think, we don't really need multiple language servers. I only used a custom language server provider to customize the clangd path for certain Eclipse projects (we just point to a bash script in the git repository's root folder, there we also have our Well, at least one reason for not using In our (quite special) case, we have quite many Eclipse projects in one single git repository (I know that's not the best idea, but there are many, mainly historical and complex reasons for that) and there are many developers working on them. I think, @jens-elmenthaler is more familiar with the rationale and background. Maybe he can give us more insight here. |
@ghentschke , @travkin79: The attached pull request is completely sufficient for our purposes. We only need to suppress the creation of .clangd files for each of our Eclipse C++ projects. Just for the sake of completeness, and to help sorting out some noise that has piled up, our setup looks like this: The important facts:
|
Hello @ghentschke, |
@ruspl-afed do you see any open issues on #229? |
- Allows vendors to overwrite default behavior fixes #227
- Support cmake projects as well fixes #227
- Add org.eclipse.cdt.cmake.core to target definition fixes #227
- 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 #227
- make methods protected since they aren't part of the interface anymore. fixes #227
Hello @ghentschke, |
Hi, I'am workin on it. |
In our team we'd like to replace CDT's classic C/C++ editor with the LSP-based C/C++editor. But at least for our C/C++ projects we face a problem that complicates usage of clangd and the LSP-based C/C++ editor.
Issue
CDT-LSP (class
org.eclipse.cdt.lsp.internal.clangd.ClangdConfigurationManager
) assumes that each C/C++ Eclipse project uses a.clangd
file in its root folder. But for our hierarchical projects that assumption leads to creation of.clangd
files per project with wrong settings. These files break our clangd configuration.Our project setup
.clangd
file or acompile_commands.json
per project, we have acompile_commands.json
in our root folder with details for all our projects in the sub-directories. It seems, clangd does not need ourcompile_commands.json
, since its default behavior is smart enough to find the relevant files in parent folders.compile_commands.json
is being created outside Eclipse.Do you have an idea how CDT-LSP could drop the false assumption and avoid erroneously creating
.clangd
files?The text was updated successfully, but these errors were encountered: