-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[#188] add OSGi service to enable clangd via project properties This allows vendors to enable clangd and the LSP based C/C++ Editor based on certain project properties (e.g. the project nature) fixes #188
- Loading branch information
1 parent
3249b7b
commit f6cee85
Showing
12 changed files
with
156 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
bundles/org.eclipse.cdt.lsp.clangd/src/org/eclipse/cdt/lsp/clangd/ClangdEnable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* See git history | ||
*******************************************************************************/ | ||
package org.eclipse.cdt.lsp.clangd; | ||
|
||
import org.eclipse.core.resources.IProject; | ||
|
||
/** | ||
* Should be implemented by bundles as OSGi service to enable the Language | ||
* Server and LSP based C/C++ Editor via project properties. | ||
*/ | ||
public interface ClangdEnable { | ||
|
||
/** | ||
* Checks whether clangd and the LSP based C/C++ Editor should be enabled for the given project. | ||
* The enable can be linked with certain project properties (e.g. project natures). | ||
* @param project | ||
* @return true when clangd and LSP based editor should be enabled for the given project | ||
*/ | ||
public boolean isEnabledFor(IProject project); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...amples.preferences/OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.HidePreferClangd.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.cdt.lsp.examples.preferences.HidePreferClangd"> | ||
<implementation class="org.eclipse.cdt.lsp.examples.preferences.HidePreferClangd"/> | ||
<property name="service.ranking" type="Integer" value="100"/> | ||
<service> | ||
<provide interface="org.eclipse.cdt.lsp.clangd.ClangdConfigurationVisibility"/> | ||
</service> | ||
</scr:component> |
7 changes: 7 additions & 0 deletions
7
...examples.preferences/OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.MyClangdEnable.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.cdt.lsp.examples.preferences.MyClangdEnable"> | ||
<service> | ||
<provide interface="org.eclipse.cdt.lsp.clangd.ClangdEnable"/> | ||
</service> | ||
<implementation class="org.eclipse.cdt.lsp.examples.preferences.MyClangdEnable"/> | ||
</scr:component> |
19 changes: 16 additions & 3 deletions
19
examples/org.eclipse.cdt.lsp.examples.preferences/build.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
source.. = src/ | ||
output.. = bin/ | ||
############################################################################### | ||
# Copyright (c) 2023 Contributors to the Eclipse Foundation. | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Eclipse Public License 2.0 which is available at | ||
# https://www.eclipse.org/legal/epl-2.0/. | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: | ||
# See git history | ||
############################################################################### | ||
|
||
bin.includes = META-INF/,\ | ||
.,\ | ||
OSGI-INF/org.eclipse.cdt.lsp.examples.preferences.MyClangdOptionsDefaults.xml | ||
OSGI-INF/ | ||
source.. = src/ | ||
output.. = bin/ |
30 changes: 30 additions & 0 deletions
30
...p.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/HidePreferClangd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* See git history | ||
*******************************************************************************/ | ||
package org.eclipse.cdt.lsp.examples.preferences; | ||
|
||
import org.eclipse.cdt.lsp.clangd.ClangdConfigurationVisibility; | ||
import org.osgi.service.component.annotations.Component; | ||
|
||
@Component(property = { "service.ranking:Integer=100" }) | ||
public class HidePreferClangd implements ClangdConfigurationVisibility { | ||
|
||
@Override | ||
public boolean showPreferClangd(boolean isProjectScope) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean showClangdOptions(boolean isProjectScope) { | ||
return true; | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...lsp.examples.preferences/src/org/eclipse/cdt/lsp/examples/preferences/MyClangdEnable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* See git history | ||
*******************************************************************************/ | ||
package org.eclipse.cdt.lsp.examples.preferences; | ||
|
||
import org.eclipse.cdt.lsp.clangd.ClangdEnable; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.osgi.service.component.annotations.Component; | ||
|
||
@Component | ||
public class MyClangdEnable implements ClangdEnable { | ||
|
||
@Override | ||
public boolean isEnabledFor(IProject project) { | ||
if (project != null) { | ||
try { | ||
return project.hasNature("org.eclipse.cdt.cmake.core.cmakeNature"); | ||
} catch (CoreException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
} |