mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
Bug 558664 - Cquery integration should be extracted from LSP Core
Part 1: rework "$cquery/progress" notification handling to be reusable Change-Id: I6995594e51289e7f8a516ffc2cc2ec8bda88f919 Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
This commit is contained in:
parent
240ca9085c
commit
afaa593d34
8 changed files with 150 additions and 29 deletions
|
@ -0,0 +1,41 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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.tests;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.lsp.internal.core.LspCoreMessages;
|
||||||
|
import org.eclipse.cdt.lsp.internal.core.ShowStatus;
|
||||||
|
import org.eclipse.osgi.util.NLS;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ShowStatusTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void busy() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
ShowStatus show = new ShowStatus(() -> "Busy", sb::append);
|
||||||
|
show.accept(() -> 100500);
|
||||||
|
assertEquals(NLS.bind(LspCoreMessages.ShowStatus_busy, "Busy", 100500), sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void idle() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
ShowStatus show = new ShowStatus(() -> "Idle", sb::append);
|
||||||
|
show.accept(() -> 0);
|
||||||
|
assertEquals(NLS.bind(LspCoreMessages.ShowStatus_idle, "Idle"), sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -24,8 +24,7 @@ public class CqueryMessages extends NLS {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String CquerySymbolKind_e_illegal_value;
|
public static String CquerySymbolKind_e_illegal_value;
|
||||||
public static String Server2ClientProtocolExtension_cquery_busy;
|
public static String Server2ClientProtocolExtension_cquery_name;
|
||||||
public static String Server2ClientProtocolExtension_cquery_idle;
|
|
||||||
public static String StorageClass_e_illegal_value;
|
public static String StorageClass_e_illegal_value;
|
||||||
|
|
||||||
private CqueryMessages() {
|
private CqueryMessages() {
|
||||||
|
|
|
@ -13,6 +13,5 @@
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
CquerySymbolKind_e_illegal_value=Illegal value {0} for cquery symbol kind
|
CquerySymbolKind_e_illegal_value=Illegal value {0} for cquery symbol kind
|
||||||
Server2ClientProtocolExtension_cquery_busy=CQuery : Busy | {0} Jobs
|
Server2ClientProtocolExtension_cquery_name=CQuery
|
||||||
Server2ClientProtocolExtension_cquery_idle=CQuery : Idle
|
|
||||||
StorageClass_e_illegal_value=Illegal enum value: {0}
|
StorageClass_e_illegal_value=Illegal enum value: {0}
|
||||||
|
|
|
@ -28,11 +28,11 @@ import org.eclipse.cdt.internal.cquery.CqueryMessages;
|
||||||
import org.eclipse.cdt.internal.cquery.ui.HighlightingNames;
|
import org.eclipse.cdt.internal.cquery.ui.HighlightingNames;
|
||||||
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightedPosition;
|
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightedPosition;
|
||||||
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightingStyle;
|
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightingStyle;
|
||||||
|
import org.eclipse.cdt.lsp.internal.core.ShowStatus;
|
||||||
import org.eclipse.cdt.lsp.internal.text.ResolveDocumentUri;
|
import org.eclipse.cdt.lsp.internal.text.ResolveDocumentUri;
|
||||||
|
import org.eclipse.cdt.lsp.internal.ui.StatusLineMessage;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||||
import org.eclipse.jface.action.StatusLineContributionItem;
|
|
||||||
import org.eclipse.jface.action.StatusLineManager;
|
|
||||||
import org.eclipse.jface.preference.IPreferenceStore;
|
import org.eclipse.jface.preference.IPreferenceStore;
|
||||||
import org.eclipse.jface.preference.PreferenceConverter;
|
import org.eclipse.jface.preference.PreferenceConverter;
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
|
@ -45,45 +45,26 @@ import org.eclipse.jface.text.TextPresentation;
|
||||||
import org.eclipse.lsp4e.LanguageClientImpl;
|
import org.eclipse.lsp4e.LanguageClientImpl;
|
||||||
import org.eclipse.lsp4j.Range;
|
import org.eclipse.lsp4j.Range;
|
||||||
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
|
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
|
||||||
import org.eclipse.osgi.util.NLS;
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.graphics.Color;
|
import org.eclipse.swt.graphics.Color;
|
||||||
import org.eclipse.swt.widgets.Display;
|
import org.eclipse.swt.widgets.Display;
|
||||||
import org.eclipse.ui.IWorkbenchWindow;
|
|
||||||
import org.eclipse.ui.PlatformUI;
|
|
||||||
import org.eclipse.ui.internal.WorkbenchWindow;
|
|
||||||
|
|
||||||
//FIXME: AF: currently this extension is cquery-specific and it should be contributed from cquery-specific part
|
//FIXME: AF: currently this extension is cquery-specific and it should be contributed from cquery-specific part
|
||||||
@SuppressWarnings("restriction")
|
@SuppressWarnings("restriction")
|
||||||
public class Server2ClientProtocolExtension extends LanguageClientImpl {
|
public class Server2ClientProtocolExtension extends LanguageClientImpl {
|
||||||
|
|
||||||
private final ResolveDocumentUri uri;
|
private final ResolveDocumentUri uri;
|
||||||
|
private final ShowStatus progress;
|
||||||
|
|
||||||
public Server2ClientProtocolExtension() {
|
public Server2ClientProtocolExtension() {
|
||||||
this.uri = new ResolveDocumentUri();
|
this.uri = new ResolveDocumentUri();
|
||||||
|
this.progress = new ShowStatus(() -> CqueryMessages.Server2ClientProtocolExtension_cquery_name,
|
||||||
|
new StatusLineMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonNotification("$cquery/progress")
|
@JsonNotification("$cquery/progress")
|
||||||
public final void indexingProgress(IndexingProgressStats stats) {
|
public final void indexingProgress(IndexingProgressStats stats) {
|
||||||
|
progress.accept(stats::getTotalJobs);
|
||||||
Display.getDefault().asyncExec(() -> {
|
|
||||||
final String cqueryStatusFieldId = "org.eclipse.cdt.lsp.core.status"; //$NON-NLS-1$
|
|
||||||
final int width = 28;
|
|
||||||
IWorkbenchWindow[] workbenchWindows = PlatformUI.getWorkbench().getWorkbenchWindows();
|
|
||||||
for (IWorkbenchWindow window : workbenchWindows) {
|
|
||||||
StatusLineManager statusLine = ((WorkbenchWindow) window).getStatusLineManager();
|
|
||||||
StatusLineContributionItem cqueryStatusField = (StatusLineContributionItem) statusLine
|
|
||||||
.find(cqueryStatusFieldId);
|
|
||||||
if (cqueryStatusField == null) {
|
|
||||||
cqueryStatusField = new StatusLineContributionItem(cqueryStatusFieldId, width);
|
|
||||||
statusLine.add(cqueryStatusField);
|
|
||||||
}
|
|
||||||
String msg = stats.getTotalJobs() > 0
|
|
||||||
? NLS.bind(CqueryMessages.Server2ClientProtocolExtension_cquery_busy, stats.getTotalJobs())
|
|
||||||
: CqueryMessages.Server2ClientProtocolExtension_cquery_idle;
|
|
||||||
cqueryStatusField.setText(msg);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonNotification("$cquery/setInactiveRegions")
|
@JsonNotification("$cquery/setInactiveRegions")
|
||||||
|
|
|
@ -24,6 +24,8 @@ public class LspCoreMessages extends NLS {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String CPPStreamConnectionProvider_e_unsupported;
|
public static String CPPStreamConnectionProvider_e_unsupported;
|
||||||
|
public static String ShowStatus_busy;
|
||||||
|
public static String ShowStatus_idle;
|
||||||
|
|
||||||
private LspCoreMessages() {
|
private LspCoreMessages() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,3 +13,5 @@
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
CPPStreamConnectionProvider_e_unsupported=Unsupported Language Server
|
CPPStreamConnectionProvider_e_unsupported=Unsupported Language Server
|
||||||
|
ShowStatus_busy={0} : Busy | {1} Jobs
|
||||||
|
ShowStatus_idle={0} : Idle
|
||||||
|
|
|
@ -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.core;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import org.eclipse.osgi.util.NLS;
|
||||||
|
|
||||||
|
public final class ShowStatus implements Consumer<Supplier<Integer>> {
|
||||||
|
|
||||||
|
private final Supplier<String> name;
|
||||||
|
private final Consumer<String> target;
|
||||||
|
|
||||||
|
public ShowStatus(Supplier<String> name, Consumer<String> target) {
|
||||||
|
this.name = name;
|
||||||
|
this.target = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(Supplier<Integer> jobs) {
|
||||||
|
target.accept(message(jobs.get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String message(int total) {
|
||||||
|
return total > 0 ? //
|
||||||
|
NLS.bind(LspCoreMessages.ShowStatus_busy, name.get(), total) : //
|
||||||
|
NLS.bind(LspCoreMessages.ShowStatus_idle, name.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import org.eclipse.jface.action.StatusLineContributionItem;
|
||||||
|
import org.eclipse.jface.action.StatusLineManager;
|
||||||
|
import org.eclipse.swt.widgets.Display;
|
||||||
|
import org.eclipse.ui.IWorkbenchWindow;
|
||||||
|
import org.eclipse.ui.PlatformUI;
|
||||||
|
import org.eclipse.ui.internal.WorkbenchWindow;
|
||||||
|
|
||||||
|
@SuppressWarnings("restriction")
|
||||||
|
public class StatusLineMessage implements Consumer<String> {
|
||||||
|
|
||||||
|
private final int width = 28;
|
||||||
|
private final String id = "org.eclipse.cdt.lsp.ui.status"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(String message) {
|
||||||
|
Display.getDefault().asyncExec(() -> //
|
||||||
|
Arrays.stream(PlatformUI.getWorkbench().getWorkbenchWindows())//
|
||||||
|
.map(this::ensure)//
|
||||||
|
.forEach(item -> item.setText(message)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private StatusLineContributionItem ensure(IWorkbenchWindow window) {
|
||||||
|
//FIXME: find via MToolControl with "org.eclipse.ui.StatusLine" identifier
|
||||||
|
StatusLineManager line = ((WorkbenchWindow) window).getStatusLineManager();
|
||||||
|
return Optional.ofNullable(line.find(id))//
|
||||||
|
.filter(StatusLineContributionItem.class::isInstance)//
|
||||||
|
.map(StatusLineContributionItem.class::cast)//
|
||||||
|
.orElseGet(() -> create(line));
|
||||||
|
}
|
||||||
|
|
||||||
|
private StatusLineContributionItem create(StatusLineManager line) {
|
||||||
|
StatusLineContributionItem item = new StatusLineContributionItem(id, width);
|
||||||
|
line.add(item);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue