Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bundles/org.eclipse.cdt.lsp/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.lsp4j,
org.eclipse.lsp4j.jsonrpc,
org.eclipse.cdt.codan.core,
org.eclipse.cdt.debug.ui
org.eclipse.cdt.debug.ui,
org.eclipse.ui.workbench.texteditor
Bundle-RequiredExecutionEnvironment: JavaSE-17
Automatic-Module-Name: org.eclipse.cdt.lsp
Bundle-ActivationPolicy: lazy
Expand Down
21 changes: 20 additions & 1 deletion bundles/org.eclipse.cdt.lsp/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@
properties="hasLanguageServer"
type="java.lang.Object">
</propertyTester>
<propertyTester
class="org.eclipse.cdt.lsp.internal.editor.SpellingEnabled"
id="org.eclipse.cdt.lsp.editor.spelling.EnabledTester"
namespace="org.eclipse.cdt.lsp.editor.spelling"
properties="enabled"
type="java.lang.Object">
</propertyTester>
</extension>
<extension
point="org.eclipse.core.expressions.definitions">
Expand Down Expand Up @@ -302,6 +309,18 @@
<keywordReference id="org.eclipse.cdt.ui.saveactions"/>
<keywordReference id="org.eclipse.cdt.ui.common"/>
</page>
</extension>
</extension>
<extension
point="org.eclipse.ui.genericeditor.reconcilers">
<reconciler
class="org.eclipse.cdt.lsp.internal.editor.CSpellingReconciler"
contentType="org.eclipse.core.runtime.text">
<enabledWhen>
<test
property="org.eclipse.cdt.lsp.editor.spelling.enabled">
</test>
</enabledWhen>
</reconciler>
</extension>
</plugin>

Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,25 @@ private Control createPreferenceContent(Composite parent, boolean isProjectScope
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(GridLayoutFactory.fillDefaults().create());
composite.setFont(parent.getFont());
if (!isProjectScope) {
createSpellingPreferencesLink(composite);
Label line = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
line.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1));
}
area = getConfigurationArea(composite, isProjectScope);
return composite;
}

private Control createSpellingPreferencesLink(Composite parent) {
Link link = new Link(parent, SWT.NONE);
link.setText(LspUiMessages.LspEditorConfigurationPage_spelling_link);
link.addListener(SWT.Selection,
event -> PreferencesUtil.createPreferenceDialogOn(getShell(), event.text, null, null));
link.setToolTipText(LspUiMessages.LspEditorConfigurationPage_spelling_link_tooltip);
link.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
return link;
}

protected void refreshWidgets(Object options) {
setErrorMessage(null);
area.load(options, useProjectSettings() || !projectScope().isPresent());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2024 Bachmann electronic GmbH and others.
*
* 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:
* Gesa Hentschke (Bachmann electronic GmbH) - initial implementation
*******************************************************************************/

package org.eclipse.cdt.lsp.internal.editor;

import org.eclipse.cdt.internal.ui.text.spelling.CSpellingService;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.texteditor.spelling.SpellingReconcileStrategy;

public final class CSpellingReconcileStrategy extends SpellingReconcileStrategy {

public CSpellingReconcileStrategy(ISourceViewer viewer) {
super(viewer, CSpellingService.getInstance());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2024 Bachmann electronic GmbH and others.
*
* 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:
* Gesa Hentschke (Bachmann electronic GmbH) - initial implementation
*******************************************************************************/

package org.eclipse.cdt.lsp.internal.editor;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.reconciler.Reconciler;
import org.eclipse.jface.text.source.ISourceViewer;

public final class CSpellingReconciler extends Reconciler {

@Override
public void install(ITextViewer textViewer) {
if (textViewer instanceof ISourceViewer sourceViewer) {
this.setReconcilingStrategy(new CSpellingReconcileStrategy(sourceViewer), IDocument.DEFAULT_CONTENT_TYPE);
}
// call super.install AFTER the CSpellingReconcileStrategy has been added to the super class via setReconcilingStrategy call,
// otherwise reconcilerDocumentChanged (which is called during super.install) would not be performed on our CSpellingReconcileStrategy
super.install(textViewer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*******************************************************************************
* Copyright (c) 2024 Bachmann electronic GmbH and others.
*
* 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:
* Gesa Hentschke (Bachmann electronic GmbH) - initial implementation
*******************************************************************************/

package org.eclipse.cdt.lsp.internal.editor;

import java.util.Optional;

import org.eclipse.cdt.lsp.LspUtils;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.texteditor.spelling.SpellingService;

public final class SpellingEnabled extends PropertyTester {
private static final String EMPTY = ""; //$NON-NLS-1$

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
return isSpellingEnabled() && isCContentType(receiver);
}

private static boolean isSpellingEnabled() {
return EditorsUI.getPreferenceStore().getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED);
}

private static boolean isCContentType(Object receiver) {
if (receiver instanceof TextEditor editor) {
return LspUtils.isCContentType(getContentType(editor.getEditorInput()));
}
return false;
}

private static String getContentType(IEditorInput editorInput) {
if (editorInput instanceof IFileEditorInput fileEditorInput) {
try {
return Optional.ofNullable(fileEditorInput.getFile().getContentDescription())
.map(cd -> cd.getContentType()).map(ct -> ct.getId()).orElse(EMPTY);
} catch (CoreException e) {
// do nothing
}
}
return EMPTY;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public class LspUiMessages extends NLS {
}

public static String NavigatorView_ErrorOnLoad;

public static String LspEditorConfigurationPage_spelling_link;
public static String LspEditorConfigurationPage_spelling_link_tooltip;

public static String LspEditorConfigurationPage_enable_project_specific;
public static String LspEditorConfigurationPage_configure_ws_specific;
public static String LspEditorConfigurationPage_preferLspEditor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

NavigatorView_ErrorOnLoad = Loading the symbols encountered an error; see the Error Log for more information

LspEditorConfigurationPage_spelling_link=Spelling preferences are set via <a href="org.eclipse.ui.editors.preferencePages.Spelling">Text Editors Spelling</a>.
LspEditorConfigurationPage_spelling_link_tooltip=Show the shared text editor spelling preferences

LspEditorConfigurationPage_enable_project_specific=Enable project-specific settings
LspEditorConfigurationPage_configure_ws_specific=Configure Workspace Settings...
LspEditorConfigurationPage_preferLspEditor=Set C/C++ Editor (LSP) as default
Expand Down