1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Bug 536320 - Do not show LSP4E diagnostics in the C++ editor

Requires https://git.eclipse.org/r/c/lsp4e/lsp4e/+/168414
Allow LS to be started
	from "Generic Editor" only
		and
	if ".settings/org.eclipse.cdt.lsp.core.prefs" has "prefer=false"
actually this blocks LSP from launching until user will configure it
explicitly.
UI to configure for workspace and project.

Change-Id: I7104d21f90380a5de7ccae157ea4299e0558a27c
Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
This commit is contained in:
Alexander Fedorov 2020-08-29 19:46:35 +03:00
parent 718088b907
commit 4a3e046dda
23 changed files with 501 additions and 14 deletions

View file

@ -11,11 +11,11 @@
* Contributors:
* Alexander Fedorov (ArSysOp) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.lsp.text.tests;
package org.eclipse.cdt.lsp.internal.core.workspace.tests;
import static org.junit.Assert.assertFalse;
import org.eclipse.cdt.lsp.internal.text.ResolveDocumentUri;
import org.eclipse.cdt.lsp.internal.core.workspace.ResolveDocumentUri;
import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.core.runtime.Path;

View file

@ -8,6 +8,7 @@ Bundle-Vendor: %Bundle-Vendor
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: com.google.gson;bundle-version="2.8.2",
org.eclipse.cdt.core,
org.eclipse.core.filebuffers;bundle-version="3.6.1000",
org.eclipse.core.resources,
org.eclipse.core.runtime,
org.eclipse.lsp4e,
@ -18,8 +19,10 @@ Require-Bundle: com.google.gson;bundle-version="2.8.2",
org.eclipse.ui
Export-Package: org.eclipse.cdt.lsp;x-friends:="org.eclipse.cdt.lsp.ui,org.eclipse.cdt.lsp.clangd",
org.eclipse.cdt.lsp.core;x-friends:="org.eclipse.cdt.lsp.ui",
org.eclipse.cdt.lsp.core.preferences;x-friends:="org.eclipse.cdt.lsp.ui",
org.eclipse.cdt.lsp.internal.core;x-internal:=true,
org.eclipse.cdt.lsp.internal.text;x-friends:="org.eclipse.cdt.lsp.ui"
org.eclipse.cdt.lsp.internal.core.preferences;x-friends:="org.eclipse.cdt.lsp.ui",
org.eclipse.cdt.lsp.internal.core.workspace;x-friends:="org.eclipse.cdt.lsp.ui"
Bundle-Activator: org.eclipse.cdt.lsp.core.Activator
Bundle-ActivationPolicy: lazy
Service-Component: OSGI-INF/org.eclipse.cdt.lsp.internal.core.ContributedLanguageServers.xml,

View file

@ -36,6 +36,12 @@
<contentTypeMapping
contentType="org.eclipse.cdt.lsp.core"
id="org.eclipse.cdt.lsp.core">
<enabledWhen
description="Project-level settings">
<reference
definitionId="org.eclipse.cdt.lsp.core.projectAllows">
</reference>
</enabledWhen>
</contentTypeMapping>
</extension>
<extension
@ -44,4 +50,22 @@
class="org.eclipse.cdt.lsp.core.PreferenceInitializer">
</initializer>
</extension>
<extension
point="org.eclipse.core.expressions.definitions">
<definition
id="org.eclipse.cdt.lsp.core.projectAllows">
<and>
<reference
definitionId="org.eclipse.ui.genericeditor.GenericEditor.active">
</reference>
<with
variable="activeEditor">
<test
property="org.eclipse.cdt.lsp.documents.prefer"
value="true">
</test>
</with>
</and>
</definition>
</extension>
</plugin>

View file

@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp 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
*
* Contributors:
* Alexander Fedorov (ArSysOp) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.lsp.core.preferences;
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
/**
* The metadata for preferences to configure language server
*
*/
public interface LanguageServerPreferenceMetadata {
/**
* Returns the metadata for the "Prefer Language Server" preference, must not return <code>null</code>.
*
* @return the metadata for the "Prefer Language Server" preference
*
* @see LanguageServerPreferences#preferLanguageServer()
*/
PreferenceMetadata<Boolean> preferLanguageServer();
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Eclipse Foundation and others.
* Copyright (c) 2019, 2020 Eclipse Contributors 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
@ -8,7 +8,7 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - initial API and implementatin
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - ongoing support
*******************************************************************************/
package org.eclipse.cdt.lsp.internal.core;
@ -23,6 +23,8 @@ public class LspCoreMessages extends NLS {
NLS.initializeMessages(BUNDLE_NAME, LspCoreMessages.class);
}
public static String LanguageServerDefaults_prefer_description;
public static String LanguageServerDefaults_prefer_name;
public static String ShowStatus_busy;
public static String ShowStatus_idle;

View file

@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2019 Eclipse Foundation and others
# Copyright (c) 2019, 2020 Eclipse Contributors 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
@ -8,9 +8,10 @@
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Eclipse Foundation - initial API and implementation
# Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 558484
# Alexander Fedorov <alexander.fedorov@arsysop.ru> - ongoing support
###############################################################################
LanguageServerDefaults_prefer_description=Prefer to use language server instead of "classic" facilities
LanguageServerDefaults_prefer_name=Prefer Language Server
ShowStatus_busy={0} : Busy | {1} Jobs
ShowStatus_idle={0} : Idle

View file

@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp 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
*
* Contributors:
* Alexander Fedorov (ArSysOp) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.lsp.internal.core.preferences;
import org.eclipse.cdt.lsp.core.preferences.LanguageServerPreferenceMetadata;
import org.eclipse.cdt.lsp.internal.core.LspCoreMessages;
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
public class LanguageServerDefaults implements LanguageServerPreferenceMetadata {
@Override
public PreferenceMetadata<Boolean> preferLanguageServer() {
return new PreferenceMetadata<>(Boolean.class, "prefer_language_server", false, //$NON-NLS-1$
LspCoreMessages.LanguageServerDefaults_prefer_name,
LspCoreMessages.LanguageServerDefaults_prefer_description);
}
}

View file

@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp 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
*
* Contributors:
* Alexander Fedorov (ArSysOp) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.lsp.internal.core.workspace;
import java.util.Optional;
import java.util.function.Predicate;
import org.eclipse.cdt.lsp.core.Activator;
import org.eclipse.cdt.lsp.core.preferences.LanguageServerPreferenceMetadata;
import org.eclipse.cdt.lsp.internal.core.preferences.LanguageServerDefaults;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
import org.eclipse.jface.text.IDocument;
public final class PreferLanguageServer implements Predicate<IDocument> {
private final ResolveDocumentFile file;
private final LanguageServerPreferenceMetadata metadata;
public PreferLanguageServer() {
file = new ResolveDocumentFile();
metadata = new LanguageServerDefaults();
}
@Override
public boolean test(IDocument document) {
Optional<IProject> project = file.apply(document).map(IFile::getProject);
if (project.isPresent()) {
return forProject(project.get());
}
return forExternal(document);
}
private boolean forExternal(IDocument document) {
//let's use workspace-level setting
PreferenceMetadata<Boolean> option = metadata.preferLanguageServer();
return Platform.getPreferencesService().getBoolean(Activator.PLUGIN_ID, option.identifer(),
option.defaultValue(), null);
}
private boolean forProject(IProject project) {
PreferenceMetadata<Boolean> option = metadata.preferLanguageServer();
return Platform.getPreferencesService().getBoolean(Activator.PLUGIN_ID, option.identifer(),
option.defaultValue(), new IScopeContext[] { new ProjectScope(project) });
}
}

View file

@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp 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
*
* Contributors:
* Alexander Fedorov (ArSysOp) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.lsp.internal.core.workspace;
import java.util.Optional;
import java.util.function.Function;
import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.jface.text.IDocument;
public final class ResolveDocumentBuffer implements Function<IDocument, Optional<ITextFileBuffer>> {
@Override
public Optional<ITextFileBuffer> apply(IDocument document) {
return Optional.ofNullable(document).map(FileBuffers.getTextFileBufferManager()::getTextFileBuffer);
}
}

View file

@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp 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
*
* Contributors:
* Alexander Fedorov (ArSysOp) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.lsp.internal.core.workspace;
import java.util.Optional;
import java.util.function.Function;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.text.IDocument;
public final class ResolveDocumentFile implements Function<IDocument, Optional<IFile>> {
private final ResolveDocumentPath path;
public ResolveDocumentFile() {
path = new ResolveDocumentPath();
}
@Override
public Optional<IFile> apply(IDocument document) {
return Optional.ofNullable(document)//
.flatMap(path)//
.map(ResourcesPlugin.getWorkspace().getRoot()::findMember)//
.filter(IFile.class::isInstance)//
.map(IFile.class::cast);
}
}

View file

@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp 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
*
* Contributors:
* Alexander Fedorov (ArSysOp) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.lsp.internal.core.workspace;
import java.util.Optional;
import java.util.function.Function;
import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.text.IDocument;
public final class ResolveDocumentPath implements Function<IDocument, Optional<IPath>> {
private final ResolveDocumentBuffer buffer;
public ResolveDocumentPath() {
buffer = new ResolveDocumentBuffer();
}
@Override
public Optional<IPath> apply(IDocument document) {
return Optional.ofNullable(document).flatMap(buffer).map(ITextFileBuffer::getLocation);
}
}

View file

@ -11,7 +11,7 @@
* Contributors:
* Alexander Fedorov (ArSysOp) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.lsp.internal.text;
package org.eclipse.cdt.lsp.internal.core.workspace;
import java.net.URI;
import java.util.Optional;
@ -23,11 +23,17 @@ import org.eclipse.lsp4e.LSPEclipseUtils;
@SuppressWarnings("restriction")
public final class ResolveDocumentUri implements Function<IDocument, Optional<URI>> {
private final ResolveDocumentFile file;
public ResolveDocumentUri() {
file = new ResolveDocumentFile();
}
@Override
public Optional<URI> apply(IDocument document) {
return Optional.ofNullable(document)//
//FIXME rewrite involved static utilities and contribute the result back to LSP4E
.flatMap(d -> Optional.ofNullable(LSPEclipseUtils.getFile(d)))
.flatMap(file)//
//FIXME rewrite involved static utilities
.flatMap(f -> Optional.ofNullable(LSPEclipseUtils.toUri(f)));
}

View file

@ -17,9 +17,9 @@ import java.util.function.Consumer;
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightedPosition;
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightingStyle;
import org.eclipse.cdt.lsp.internal.core.workspace.ResolveDocumentUri;
import org.eclipse.cdt.lsp.internal.cquery.CquerySemanticHighlights;
import org.eclipse.cdt.lsp.internal.cquery.HighlightSymbol;
import org.eclipse.cdt.lsp.internal.text.ResolveDocumentUri;
import org.eclipse.cdt.lsp.internal.ui.text.PresentationReconcilerCPP;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;

View file

@ -7,6 +7,7 @@ Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: org.eclipse.osgi;bundle-version="[3.15.0,4.0.0)",
org.eclipse.core.expressions;bundle-version="3.7.0",
org.eclipse.core.resources;bundle-version="3.13.800",
org.eclipse.core.runtime;bundle-version="3.19.0",
org.eclipse.equinox.preferences;bundle-version="[3.7.0,4.0.0)",

View file

@ -18,3 +18,5 @@ Bundle-Vendor = Eclipse CDT
preferencePages.languageServer.name=C/C++ Language Server
cDocumentSetupParticipant =C Document Setup Participant
properties.ls.name = C/C++ Language Server

View file

@ -22,6 +22,26 @@
name="%preferencePages.languageServer.name">
</page>
</extension>
<extension
point="org.eclipse.ui.propertyPages">
<page
category="org.eclipse.cdt.ui.newui.Page_head_general"
class="org.eclipse.cdt.lsp.internal.ui.properties.LanguageServerPropertyPage"
id="org.eclipse.cdt.lsp.ui.properties.ls"
name="%properties.ls.name">
<filter
name="projectNature"
value="org.eclipse.cdt.core.cnature">
</filter>
<enabledWhen>
<or>
<adapt
type="org.eclipse.core.resources.IProject">
</adapt>
</or>
</enabledWhen>
</page>
</extension>
<extension
point="org.eclipse.ui.editors">
<editorContentTypeBinding
@ -52,4 +72,14 @@
contentTypeId="org.eclipse.cdt.lsp.core">
</participant>
</extension>
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="org.eclipse.cdt.lsp.internal.ui.expressions.DocumentsTester"
id="org.eclipse.cdt.lsp.workspace.documents"
namespace="org.eclipse.cdt.lsp.documents"
properties="prefer"
type="org.eclipse.ui.texteditor.AbstractDecoratedTextEditor">
</propertyTester>
</extension>
</plugin>

View file

@ -28,6 +28,7 @@ public class LspUiMessages extends NLS {
public static String CPPLanguageServerPreferencePage_server_options;
public static String CPPLanguageServerPreferencePage_server_path;
public static String CPPLanguageServerPreferencePage_server_selector;
public static String LanguageServerPropertyPage_w_ls_experimental;
private LspUiMessages() {
}

View file

@ -17,3 +17,4 @@ CPPLanguageServerPreferencePage_description=Preferences for the C/C++ Language S
CPPLanguageServerPreferencePage_server_options=Command-line options for the server
CPPLanguageServerPreferencePage_server_path=Path to the server executable
CPPLanguageServerPreferencePage_server_selector=Please select the C/C++ Language Server you want to use in Eclipse :
LanguageServerPropertyPage_w_ls_experimental=The C/C++ Language Server support is experimental

View file

@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp 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
*
* Contributors:
* Alexander Fedorov (ArSysOp) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.lsp.internal.ui.expressions;
import org.eclipse.cdt.lsp.internal.core.workspace.PreferLanguageServer;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
public final class DocumentsTester extends PropertyTester {
private final String key = "prefer"; //$NON-NLS-1$
private final PreferLanguageServer predicate;
public DocumentsTester() {
this.predicate = new PreferLanguageServer();
}
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (key.equals(property)) {
if (receiver instanceof AbstractDecoratedTextEditor) {
AbstractDecoratedTextEditor editor = (AbstractDecoratedTextEditor) receiver;
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
return predicate.test(document);
}
}
return false;
}
}

View file

@ -25,10 +25,13 @@ import org.eclipse.cdt.lsp.LanguageServerConfiguration;
import org.eclipse.cdt.lsp.SupportedLanguageServers;
import org.eclipse.cdt.lsp.core.CPPStreamConnectionProvider;
import org.eclipse.cdt.lsp.core.PreferenceConstants;
import org.eclipse.cdt.lsp.internal.core.preferences.LanguageServerDefaults;
import org.eclipse.cdt.lsp.internal.ui.LspUiActivator;
import org.eclipse.cdt.lsp.internal.ui.LspUiMessages;
import org.eclipse.cdt.ui.newui.MultiLineTextFieldEditor;
import org.eclipse.core.runtime.ServiceCaller;
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.FileFieldEditor;
@ -55,6 +58,8 @@ public class CPPLanguageServerPreferencePage extends FieldEditorPreferencePage i
@Override
public void createFieldEditors() {
PreferenceMetadata<Boolean> prefer = new LanguageServerDefaults().preferLanguageServer();
addField(new BooleanFieldEditor(prefer.identifer(), prefer.name(), getFieldEditorParent()));
serverChoice = new RadioGroupFieldEditor(PreferenceConstants.P_SERVER_CHOICE,
LspUiMessages.CPPLanguageServerPreferencePage_server_selector, 1, contributedServers(),
getFieldEditorParent());

View file

@ -0,0 +1,139 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp 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
*
* Contributors:
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.lsp.internal.ui.properties;
import java.util.Optional;
import org.eclipse.cdt.lsp.core.Activator;
import org.eclipse.cdt.lsp.core.preferences.LanguageServerPreferenceMetadata;
import org.eclipse.cdt.lsp.internal.core.preferences.LanguageServerDefaults;
import org.eclipse.cdt.lsp.internal.ui.LspUiMessages;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.dialogs.PropertyPage;
import org.osgi.framework.FrameworkUtil;
import org.osgi.service.prefs.BackingStoreException;
public final class LanguageServerPropertyPage extends PropertyPage {
private LanguageServerPreferenceMetadata metadata;
private Button prefer;
public LanguageServerPropertyPage() {
this.metadata = new LanguageServerDefaults();
}
private void addHeaderSection(Composite parent) {
Composite composite = createDefaultComposite(parent);
Label warning = new Label(composite, SWT.NONE);
warning.setText(LspUiMessages.LanguageServerPropertyPage_w_ls_experimental);
}
private void addSeparator(Composite parent) {
Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
separator.setLayoutData(gridData);
}
private void addSettingsSection(Composite parent) {
PreferenceMetadata<Boolean> option = metadata.preferLanguageServer();
Composite composite = createDefaultComposite(parent);
prefer = new Button(composite, SWT.CHECK);
prefer.setLayoutData(new GridData());
prefer.setText(option.name());
prefer.setToolTipText(option.description());
}
private void load() {
Optional<IProject> project = project();
PreferenceMetadata<Boolean> option = metadata.preferLanguageServer();
if (project.isPresent()) {
prefer.setSelection(Platform.getPreferencesService().getBoolean(Activator.PLUGIN_ID, option.identifer(),
option.defaultValue(), new IScopeContext[] { new ProjectScope(project.get()) }));
} else {
prefer.setSelection(option.defaultValue());
}
}
/**
* @see PreferencePage#createContents(Composite)
*/
@Override
protected Control createContents(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
composite.setLayout(layout);
GridData data = new GridData(GridData.FILL);
data.grabExcessHorizontalSpace = true;
composite.setLayoutData(data);
addHeaderSection(composite);
addSeparator(composite);
addSettingsSection(composite);
load();
return composite;
}
private Composite createDefaultComposite(Composite parent) {
Composite composite = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
composite.setLayout(layout);
composite.setLayoutData(GridDataFactory.fillDefaults().create());
return composite;
}
@Override
protected void performDefaults() {
super.performDefaults();
prefer.setSelection(metadata.preferLanguageServer().defaultValue());
}
@Override
public boolean performOk() {
Optional<IProject> project = project();
if (project.isPresent()) {
IEclipsePreferences node = new ProjectScope(project.get()).getNode(Activator.PLUGIN_ID);
node.putBoolean(metadata.preferLanguageServer().identifer(), prefer.getSelection());
try {
node.flush();
return true;
} catch (BackingStoreException e) {
Platform.getLog(FrameworkUtil.getBundle(getClass())).error(e.getMessage(), e);
}
}
return false;
}
private Optional<IProject> project() {
return Optional.ofNullable(getElement())//
.filter(IProject.class::isInstance)//
.map(IProject.class::cast);
}
}

View file

@ -40,7 +40,7 @@ import org.eclipse.cdt.internal.ui.text.CPresentationReconciler;
import org.eclipse.cdt.internal.ui.text.PartitionDamager;
import org.eclipse.cdt.internal.ui.text.SingleTokenCScanner;
import org.eclipse.cdt.internal.ui.text.TokenStore;
import org.eclipse.cdt.lsp.internal.text.ResolveDocumentUri;
import org.eclipse.cdt.lsp.internal.core.workspace.ResolveDocumentUri;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.ILanguageUI;
import org.eclipse.cdt.ui.text.AbstractCScanner;

View file

@ -15,7 +15,7 @@ import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
import org.eclipse.cdt.lsp.internal.text.ResolveDocumentUri;
import org.eclipse.cdt.lsp.internal.core.workspace.ResolveDocumentUri;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.BadPositionCategoryException;