-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
718088b
commit 4a3e046
Showing
23 changed files
with
501 additions
and
14 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
33 changes: 33 additions & 0 deletions
33
...t.lsp.core/src/org/eclipse/cdt/lsp/core/preferences/LanguageServerPreferenceMetadata.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,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(); | ||
|
||
} |
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
...dt.lsp.core/src/org/eclipse/cdt/lsp/internal/core/preferences/LanguageServerDefaults.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) 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); | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
...se.cdt.lsp.core/src/org/eclipse/cdt/lsp/internal/core/workspace/PreferLanguageServer.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,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) }); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...e.cdt.lsp.core/src/org/eclipse/cdt/lsp/internal/core/workspace/ResolveDocumentBuffer.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) 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); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...pse.cdt.lsp.core/src/org/eclipse/cdt/lsp/internal/core/workspace/ResolveDocumentFile.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,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); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...pse.cdt.lsp.core/src/org/eclipse/cdt/lsp/internal/core/workspace/ResolveDocumentPath.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,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); | ||
} | ||
|
||
} |
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
Oops, something went wrong.