-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement "Try new editing experience" to promote CDT LSP (#421)
Contribute a banner to the CEditor and CLspEditor to promote the new C/C++ editing experience based on LSP. The banner in CEditor enables a quick switch to the LSP editor:  And in the CLspEditor it enables a quick switch back to the traditional CEditor.  If there is no project specific setting for `prefer_lsp` a quick confirmation dialog is displayed with options for help and feedback:  and the other way:  If the editor is open on a specific project and that project has project specific preferences for `prefer_lsp`, instead of automatically changing the setting, the property page is opened:  A notification is also displayed to the user for a short while after the editors are re-opening offering more information and access to the preferences.  A notification is also displayed when closing the banner allowing the user easy access to disable opening the banner on new editors  Finally a new preference is available:  Fixes eclipse-cdt/cdt#968
- Loading branch information
1 parent
6c0dfad
commit dfe1635
Showing
30 changed files
with
1,082 additions
and
11 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
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
bundles/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.internal.switchtolsp.SwitchBack.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.internal.switchtolsp.SwitchBack"> | ||
<property name="service.ranking" type="Integer" value="0"/> | ||
<service> | ||
<provide interface="org.eclipse.cdt.lsp.internal.switchtolsp.ISwitchBackToTraditional"/> | ||
</service> | ||
<implementation class="org.eclipse.cdt.lsp.internal.switchtolsp.SwitchBack"/> | ||
</scr:component> |
8 changes: 8 additions & 0 deletions
8
...les/org.eclipse.cdt.lsp/OSGI-INF/org.eclipse.cdt.lsp.internal.switchtolsp.SwitchToLsp.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.internal.switchtolsp.SwitchToLsp"> | ||
<property name="service.ranking" type="Integer" value="0"/> | ||
<service> | ||
<provide interface="org.eclipse.cdt.internal.ui.switchtolsp.ISwitchToLsp"/> | ||
</service> | ||
<implementation class="org.eclipse.cdt.lsp.internal.switchtolsp.SwitchToLsp"/> | ||
</scr:component> |
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
54 changes: 54 additions & 0 deletions
54
bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/internal/editor/CLspEditor.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,54 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Kichwa Coders Canada Inc. and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.cdt.lsp.internal.editor; | ||
|
||
import org.eclipse.cdt.lsp.internal.switchtolsp.ISwitchBackToTraditional; | ||
import org.eclipse.core.runtime.SafeRunner; | ||
import org.eclipse.jface.text.source.ISourceViewer; | ||
import org.eclipse.jface.text.source.IVerticalRuler; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.ui.PlatformUI; | ||
import org.eclipse.ui.internal.genericeditor.ExtensionBasedTextEditor; | ||
|
||
@SuppressWarnings("restriction") | ||
public class CLspEditor extends ExtensionBasedTextEditor { | ||
|
||
@Override | ||
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) { | ||
Composite editorComposite = createSwitchBackToTraditionalEditorBanner(parent); | ||
return super.createSourceViewer(editorComposite, ruler, styles); | ||
} | ||
|
||
/** | ||
* Wraps {@link ISwitchBackToTraditional#createSwitchBackToTraditional(org.eclipse.ui.texteditor.ITextEditor, Composite)} | ||
* with the needed service access + fallback checks. | ||
* | ||
* If the {@link ISwitchBackToTraditional} service doesn't exist, or fails, this method | ||
* is a no-op that simply returns its input. | ||
* | ||
* @see ISwitchBackToTraditional#createSwitchBackToTraditional(org.eclipse.ui.texteditor.ITextEditor, Composite) | ||
*/ | ||
private Composite createSwitchBackToTraditionalEditorBanner(Composite parent) { | ||
Composite editorComposite = SafeRunner.run(() -> { | ||
ISwitchBackToTraditional switchToLsp = PlatformUI.getWorkbench().getService(ISwitchBackToTraditional.class); | ||
if (switchToLsp != null) { | ||
return switchToLsp.createSwitchBackToTraditional(CLspEditor.this, parent); | ||
} | ||
return null; | ||
}); | ||
if (editorComposite == null) { | ||
editorComposite = parent; | ||
} | ||
return editorComposite; | ||
} | ||
|
||
} |
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
41 changes: 41 additions & 0 deletions
41
...clipse.cdt.lsp/src/org/eclipse/cdt/lsp/internal/switchtolsp/ISwitchBackToTraditional.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,41 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Kichwa Coders Canada Inc. and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.cdt.lsp.internal.switchtolsp; | ||
|
||
import org.eclipse.cdt.lsp.internal.editor.CLspEditor; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.ui.texteditor.ITextEditor; | ||
|
||
/** | ||
* This interface can be implemented by CDT-LSP to display a banner in the {@link CLspEditor} | ||
* to switch back to the traditional C/C++ editing experience | ||
* | ||
* This interface is not public API | ||
* | ||
* @apiNote this interface, at time of initial implementation, is expected to work | ||
* with CDT 11.6 and CDT 12. There should be no requirements on API | ||
* added in CDT 12 (specifically ISwitchToLsp) | ||
* | ||
* See org.eclipse.cdt.internal.ui.switchtolsp.ISwitchToLsp | ||
*/ | ||
public interface ISwitchBackToTraditional { | ||
|
||
/** | ||
* Create the banner controls for the "switch back to traditional" | ||
* | ||
* @param part the editor part that the banner is added on | ||
* @param parent the parent control | ||
* @return the new parent control the editor should use | ||
*/ | ||
public Composite createSwitchBackToTraditional(ITextEditor part, Composite parent); | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/internal/switchtolsp/LinkHelper.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,73 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Kichwa Coders Canada Inc. and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.cdt.lsp.internal.switchtolsp; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.eclipse.cdt.lsp.ui.EditorConfigurationPage; | ||
import org.eclipse.jface.preference.PreferenceDialog; | ||
import org.eclipse.swt.program.Program; | ||
import org.eclipse.swt.widgets.Event; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.eclipse.ui.PlatformUI; | ||
import org.eclipse.ui.dialogs.PreferencesUtil; | ||
|
||
public class LinkHelper { | ||
|
||
public static final String SPARKLES = "\u2728 "; //$NON-NLS-1$ | ||
public static final String LINK_SPACER = " · "; //$NON-NLS-1$ | ||
|
||
public static String A(String linkText) { | ||
return "<a>" + linkText + "</a>"; //$NON-NLS-1$//$NON-NLS-2$ | ||
} | ||
|
||
/** | ||
* Creates the standard set of links to show in notifications and message dialogs. | ||
* | ||
* Some workflows don't make sense to show the preferences link, such as confirmation | ||
* dialog. | ||
* @return string of links that {@link #handleLinkClick(Shell, Event)} will be able to process | ||
*/ | ||
public static String getLinks(boolean showPreferenceLink) { | ||
StringBuilder message = new StringBuilder(); | ||
var texts = new ArrayList<String>(); | ||
texts.add(A(Messages.SwitchToLsp_LearnMoreLink)); | ||
if (showPreferenceLink) { | ||
texts.add(A(Messages.SwitchToLsp_OpenPreferencesLink)); | ||
} | ||
texts.add(A(Messages.SwitchToLsp_GiveFeedbackLink)); | ||
message.append(String.join(LINK_SPACER, texts)); | ||
return message.toString(); | ||
} | ||
|
||
/** | ||
* Handler for the links created by {@link #getLinks(boolean)} | ||
*/ | ||
public static boolean handleLinkClick(Shell parentShell, Event event) { | ||
if (event.text != null && event.text.equals(Messages.SwitchToLsp_LearnMoreLink)) { | ||
PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(SwitchToLspWizard.TRY_LSP_HELP_PATH); | ||
} else if (event.text != null && event.text.equals(Messages.SwitchToLsp_OpenPreferencesLink)) { | ||
PreferenceDialog preferenceDialogOn = PreferencesUtil.createPreferenceDialogOn(parentShell, | ||
EditorConfigurationPage.PREFERENCE_PAGE_ID, null /* display all pages */, | ||
EditorConfigurationPage.HIGHLIGHT_PREFER_LSP); | ||
preferenceDialogOn.setBlockOnOpen(false); | ||
preferenceDialogOn.open(); | ||
} else if (event.text != null && event.text.equals(Messages.SwitchToLsp_GiveFeedbackLink)) { | ||
Program.launch(SwitchToLspWizard.FEEDBACK_URL); | ||
} else { | ||
// Did not detect a link - do nothing | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} |
Oops, something went wrong.