Boot highlights as CodeLenses in Eclipse
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.boot.ls;
|
||||
|
||||
import static org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.SPRING_BOOT_SERVER;
|
||||
import static org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolePreferenceConstants.SPRING_BOOT_SERVER;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.bosh.ls;
|
||||
|
||||
import static org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.BOSH_SERVER;
|
||||
import static org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolePreferenceConstants.BOSH_SERVER;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.cloudfoundry.manifest.ls;
|
||||
|
||||
import static org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.CLOUDFOUNDRY_SERVER;
|
||||
import static org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolePreferenceConstants.CLOUDFOUNDRY_SERVER;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.concourse.ls;
|
||||
|
||||
import static org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.CONCOURSE_SERVER;
|
||||
import static org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolePreferenceConstants.CONCOURSE_SERVER;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
@@ -25,7 +25,7 @@ Require-Bundle: org.eclipse.jdt.launching;bundle-version="3.8.0",
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Export-Package: org.springframework.tooling.ls.eclipse.commons,
|
||||
org.springframework.tooling.ls.eclipse.commons.console.preferences
|
||||
org.springframework.tooling.ls.eclipse.commons.preferences
|
||||
Bundle-Activator: org.springframework.tooling.ls.eclipse.commons.LanguageServerCommonsActivator
|
||||
Bundle-ClassPath: .,
|
||||
lib/remark-1.0.0.jar,
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<extension
|
||||
point="org.eclipse.ui.preferencePages">
|
||||
<page
|
||||
class="org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolesPreferencesPage"
|
||||
class="org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolesPreferencesPage"
|
||||
id="org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolesPreferencesPage"
|
||||
name="Language Servers STS">
|
||||
</page>
|
||||
@@ -36,10 +36,10 @@
|
||||
<extension
|
||||
point="org.eclipse.core.runtime.preferences">
|
||||
<initializer
|
||||
class="org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolesPrefsInitializer">
|
||||
class="org.springframework.tooling.ls.eclipse.commons.preferences.PrefsInitializer">
|
||||
</initializer>
|
||||
<initializer
|
||||
class="org.springframework.tooling.ls.eclipse.commons.YamlGenericEditorPreferencesInitializer">
|
||||
class="org.springframework.tooling.ls.eclipse.commons.preferences.YamlGenericEditorPreferencesInitializer">
|
||||
</initializer>
|
||||
</extension>
|
||||
<extension
|
||||
@@ -63,4 +63,20 @@
|
||||
name="Generic YAML Editor">
|
||||
</editor>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.workbench.texteditor.codeMiningProviders">
|
||||
<codeMiningProvider
|
||||
class="org.springframework.tooling.ls.eclipse.commons.HighlightsCodeLensProvider"
|
||||
id="org.eclipse.lsp4e.codelens"
|
||||
label="CodeLens">
|
||||
<enabledWhen>
|
||||
<with
|
||||
variable="editorInput">
|
||||
<test
|
||||
property="org.eclipse.lsp4e.hasLanguageServer">
|
||||
</test>
|
||||
</with>
|
||||
</enabledWhen>
|
||||
</codeMiningProvider>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.ls.eclipse.commons;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.jface.text.codemining.AbstractCodeMiningProvider;
|
||||
import org.eclipse.jface.text.codemining.ICodeMining;
|
||||
import org.eclipse.jface.text.codemining.ICodeMiningProvider;
|
||||
import org.eclipse.jface.text.codemining.LineHeaderCodeMining;
|
||||
import org.eclipse.lsp4e.LanguageServiceAccessor;
|
||||
import org.eclipse.lsp4e.LanguageServiceAccessor.LSPDocumentInfo;
|
||||
import org.eclipse.lsp4j.CodeLens;
|
||||
import org.springframework.tooling.ls.eclipse.commons.preferences.PreferenceConstants;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class HighlightsCodeLensProvider extends AbstractCodeMiningProvider {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer,
|
||||
IProgressMonitor monitor) {
|
||||
IPreferenceStore store = LanguageServerCommonsActivator.getInstance().getPreferenceStore();
|
||||
if (store.getBoolean(PreferenceConstants.HIGHLIGHT_CODELENS_PREFS)) {
|
||||
IDocument document = viewer.getDocument();
|
||||
List<LSPDocumentInfo> docInfos = LanguageServiceAccessor.getLSPDocumentInfosFor(document, (x) -> true);
|
||||
if (!docInfos.isEmpty()) {
|
||||
LSPDocumentInfo info = docInfos.get(0);
|
||||
HighlightParams highlights = STS4LanguageClientImpl.currentHighlights.get(info.getFileUri().toString());
|
||||
if (highlights != null) {
|
||||
return CompletableFuture.completedFuture(highlights.getCodeLenses().stream()
|
||||
.filter(codeLens -> codeLens.getCommand() != null).map(codeLens -> {
|
||||
try {
|
||||
return new HighlightCodeMining(codeLens, document, this);
|
||||
} catch (BadLocationException e) {
|
||||
LanguageServerCommonsActivator.logError(e, "Failed to create Eclipse client CodeLens");
|
||||
return null;
|
||||
}
|
||||
}).filter(Objects::nonNull).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class HighlightCodeMining extends LineHeaderCodeMining {
|
||||
|
||||
public HighlightCodeMining(CodeLens codeLens, IDocument document, ICodeMiningProvider provider)
|
||||
throws BadLocationException {
|
||||
super(codeLens.getRange().getStart().getLine(), document, provider);
|
||||
setLabel(codeLens.getCommand().getTitle());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,9 +18,13 @@ import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.springframework.tooling.ls.eclipse.commons.STS4LanguageClientImpl.UpdateHighlights;
|
||||
import org.springframework.tooling.ls.eclipse.commons.preferences.PreferenceConstants;
|
||||
|
||||
public class LanguageServerCommonsActivator extends AbstractUIPlugin {
|
||||
|
||||
@@ -30,6 +34,17 @@ public class LanguageServerCommonsActivator extends AbstractUIPlugin {
|
||||
|
||||
private static LanguageServerCommonsActivator instance;
|
||||
|
||||
private static final IPropertyChangeListener PROPERTY_LISTENER = new IPropertyChangeListener() {
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
if (PreferenceConstants.HIGHLIGHT_CODELENS_PREFS.equals(event.getProperty())) {
|
||||
new UpdateHighlights(null);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public LanguageServerCommonsActivator() {
|
||||
}
|
||||
|
||||
@@ -38,6 +53,7 @@ public class LanguageServerCommonsActivator extends AbstractUIPlugin {
|
||||
instance = this;
|
||||
super.start(context);
|
||||
getImageRegistry().put(BOOT_KEY, getImageDescriptor("icons/boot.png"));
|
||||
getPreferenceStore().addPropertyChangeListener(PROPERTY_LISTENER);
|
||||
}
|
||||
|
||||
public final static ImageDescriptor getImageDescriptor(String path) {
|
||||
@@ -53,6 +69,12 @@ public class LanguageServerCommonsActivator extends AbstractUIPlugin {
|
||||
return desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
getPreferenceStore().removePropertyChangeListener(PROPERTY_LISTENER);
|
||||
super.stop(context);
|
||||
}
|
||||
|
||||
public static LanguageServerCommonsActivator getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -10,45 +10,36 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.ls.eclipse.commons;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.action.IStatusLineManager;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.ITextViewerExtension2;
|
||||
import org.eclipse.jface.text.Position;
|
||||
import org.eclipse.jface.text.source.Annotation;
|
||||
import org.eclipse.jface.text.source.AnnotationPainter;
|
||||
import org.eclipse.jface.text.source.IAnnotationAccess;
|
||||
import org.eclipse.jface.text.source.IAnnotationModel;
|
||||
import org.eclipse.jface.text.source.IAnnotationModelExtension;
|
||||
import org.eclipse.jface.text.source.ISourceViewer;
|
||||
import org.eclipse.jface.text.source.ISourceViewerExtension5;
|
||||
import org.eclipse.lsp4e.LSPEclipseUtils;
|
||||
import org.eclipse.lsp4e.LanguageClientImpl;
|
||||
import org.eclipse.lsp4e.LanguageServiceAccessor;
|
||||
import org.eclipse.lsp4e.LanguageServiceAccessor.LSPDocumentInfo;
|
||||
import org.eclipse.lsp4j.CodeLens;
|
||||
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IEditorReference;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.progress.UIJob;
|
||||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||
import org.springframework.tooling.jdt.ls.commons.Logger;
|
||||
import org.springframework.tooling.jdt.ls.commons.classpath.ReusableClasspathListenerHandler;
|
||||
import org.springframework.tooling.jdt.ls.commons.javadoc.JavadocResponse;
|
||||
import org.springframework.tooling.jdt.ls.commons.javadoc.JavadocUtils;
|
||||
import org.springframework.tooling.ls.eclipse.commons.javadoc.JavaDoc2MarkdownConverter;
|
||||
import org.springframework.tooling.ls.eclipse.commons.preferences.PreferenceConstants;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
@@ -67,7 +58,7 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La
|
||||
|
||||
private static final String ANNOTION_TYPE_ID = "org.springframework.tooling.bootinfo";
|
||||
|
||||
class UpdateHighlights extends UIJob {
|
||||
static class UpdateHighlights extends UIJob {
|
||||
|
||||
private String target;
|
||||
|
||||
@@ -80,50 +71,36 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La
|
||||
|
||||
@Override
|
||||
public IStatus runInUIThread(IProgressMonitor monitor) {
|
||||
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
|
||||
if (windows != null) {
|
||||
for (IWorkbenchWindow ww : windows) {
|
||||
if (ww != null) {
|
||||
IWorkbenchPage[] pages = ww.getPages();
|
||||
if (pages != null) {
|
||||
for (IWorkbenchPage page : pages) {
|
||||
if (page != null) {
|
||||
IEditorReference[] references = page.getEditorReferences();
|
||||
if (references != null) {
|
||||
boolean restore = false;
|
||||
for (IEditorReference reference : references) {
|
||||
IEditorPart editorPart = reference.getEditor(restore);
|
||||
updateEditorPart(editorPart);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Utils.getActiveSourceViewers().forEach(this::updateSourceViewer);
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
protected void updateEditorPart(IEditorPart editorPart) {
|
||||
if (editorPart instanceof AbstractTextEditor) {
|
||||
try {
|
||||
Method m = AbstractTextEditor.class.getDeclaredMethod("getSourceViewer");
|
||||
m.setAccessible(true);
|
||||
ISourceViewer sourceViewer = (ISourceViewer) m.invoke(editorPart);
|
||||
if (sourceViewer!=null) {
|
||||
IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
|
||||
if (annotationModel!=null) {
|
||||
IDocument doc = sourceViewer.getDocument();
|
||||
if (sourceViewer!=null) {
|
||||
if (doc!=null && annotationModel instanceof IAnnotationModelExtension) {
|
||||
updateAnnotations(target, sourceViewer, (IAnnotationModelExtension) annotationModel);
|
||||
}
|
||||
protected void updateSourceViewer(ISourceViewer sourceViewer) {
|
||||
IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
|
||||
if (annotationModel != null) {
|
||||
IDocument doc = sourceViewer.getDocument();
|
||||
if (doc != null && sourceViewer != null) {
|
||||
if (target != null) {
|
||||
HighlightParams highlightParams = currentHighlights.get(target);
|
||||
if (Utils.isProperDocumentIdFor(doc, highlightParams.getDoc())) {
|
||||
if (annotationModel instanceof IAnnotationModelExtension) {
|
||||
updateAnnotations(target, sourceViewer, (IAnnotationModelExtension) annotationModel);
|
||||
}
|
||||
if (sourceViewer instanceof ISourceViewerExtension5) {
|
||||
((ISourceViewerExtension5) sourceViewer).updateCodeMinings();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
URI uri = Utils.findDocUri(doc);
|
||||
if (uri != null) {
|
||||
if (annotationModel instanceof IAnnotationModelExtension) {
|
||||
updateAnnotations(uri.toString(), sourceViewer, (IAnnotationModelExtension) annotationModel);
|
||||
}
|
||||
if (sourceViewer instanceof ISourceViewerExtension5) {
|
||||
((ISourceViewerExtension5) sourceViewer).updateCodeMinings();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//ignore reflection errors
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,109 +110,28 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La
|
||||
* Latest highlight request params. It is sufficient to only remember the last request per uri, because
|
||||
* each new request is expected to replace the previous highlights.
|
||||
*/
|
||||
private Map<String, HighlightParams> currentHighlights = new HashMap<>();
|
||||
static final Map<String, HighlightParams> currentHighlights = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Current markers... indexed per document uri, needed sp we to be removed upon next update.
|
||||
*/
|
||||
private Map<String, Annotation[]> currentAnnotations = new HashMap<>();
|
||||
private static Map<String, Annotation[]> currentAnnotations = new ConcurrentHashMap<>();
|
||||
|
||||
// private Map<ISourceViewer, InlinedAnnotationSupport> viewerInlinedAnnotationSupport = new WeakHashMap<>();
|
||||
|
||||
private synchronized void updateAnnotations(String target, ISourceViewer sourceViewer, IAnnotationModelExtension annotationModel) {
|
||||
if (target!=null) {
|
||||
HighlightParams highlightParams = currentHighlights.get(target);
|
||||
IDocument doc = sourceViewer.getDocument();
|
||||
if (isProperDocumentIdFor(doc, highlightParams.getDoc())) {
|
||||
Annotation[] toRemove = currentAnnotations.get(target);
|
||||
if (toRemove==null) {
|
||||
toRemove = new Annotation[0];
|
||||
}
|
||||
List<CodeLens> highlights = highlightParams == null ? null : highlightParams.getCodeLenses();
|
||||
Map<Annotation, Position> newAnnotations = createAnnotations(doc, highlights);
|
||||
annotationModel.replaceAnnotations(toRemove, newAnnotations);
|
||||
currentAnnotations.put(target, newAnnotations.keySet().toArray(new Annotation[newAnnotations.size()]));
|
||||
// updateInlinedAnnotations(sourceViewer, highlights);
|
||||
}
|
||||
static synchronized void updateAnnotations(String target, ISourceViewer sourceViewer,
|
||||
IAnnotationModelExtension annotationModel) {
|
||||
Annotation[] toRemove = currentAnnotations.get(target);
|
||||
if (toRemove == null) {
|
||||
toRemove = new Annotation[0];
|
||||
}
|
||||
HighlightParams highlightParams = currentHighlights.get(target);
|
||||
IPreferenceStore store = LanguageServerCommonsActivator.getInstance().getPreferenceStore();
|
||||
List<CodeLens> highlights = store.getBoolean(PreferenceConstants.HIGHLIGHT_CODELENS_PREFS) || highlightParams == null ? null : highlightParams.getCodeLenses();
|
||||
Map<Annotation, Position> newAnnotations = createAnnotations(sourceViewer.getDocument(), highlights);
|
||||
annotationModel.replaceAnnotations(toRemove, newAnnotations);
|
||||
currentAnnotations.put(target, newAnnotations.keySet().toArray(new Annotation[newAnnotations.size()]));
|
||||
}
|
||||
|
||||
private static boolean isProperDocumentIdFor(IDocument doc, VersionedTextDocumentIdentifier id) {
|
||||
for (LSPDocumentInfo info : LanguageServiceAccessor.getLSPDocumentInfosFor(doc, (x) -> true)) {
|
||||
if (info.getVersion() == id.getVersion()) {
|
||||
URI uri = info.getFileUri();
|
||||
if (uri != null && uri.toString().equals(id.getUri())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// private void updateInlinedAnnotations(final ISourceViewer sourceViewer, List<CodeLens> highlights) {
|
||||
// InlinedAnnotationSupport support = viewerInlinedAnnotationSupport.get(sourceViewer);
|
||||
// if (support == null) {
|
||||
// final InlinedAnnotationSupport inlinedSupport = new InlinedAnnotationSupport();
|
||||
// inlinedSupport.install(sourceViewer, createAnnotationPainter(sourceViewer));
|
||||
// viewerInlinedAnnotationSupport.put(sourceViewer, inlinedSupport);
|
||||
// sourceViewer.getTextWidget().addDisposeListener((e) -> {
|
||||
// inlinedSupport.uninstall();
|
||||
// viewerInlinedAnnotationSupport.remove(sourceViewer);
|
||||
// });
|
||||
// support = inlinedSupport;
|
||||
// }
|
||||
// Set<AbstractInlinedAnnotation> annotations = new HashSet<>();
|
||||
// if (highlights==null) {
|
||||
// highlights = ImmutableList.of();
|
||||
// }
|
||||
// IDocument doc = sourceViewer.getDocument();
|
||||
// final InlinedAnnotationSupport inlinedSupport = support;
|
||||
// highlights.stream().filter(hl -> hl.getCommand() != null && hl.getCommand().getTitle() != null).forEach(codeLens -> {
|
||||
// try {
|
||||
// Range rng = codeLens.getRange();
|
||||
// int start = LSPEclipseUtils.toOffset(rng.getStart(), doc);
|
||||
//
|
||||
// // "Code Lens" line header annotation
|
||||
// Position headerPos = new Position(start + 1, 1);
|
||||
// BootHeadlineAnnotation headlineAnnotation = inlinedSupport.findExistingAnnotation(headerPos);
|
||||
// if (headlineAnnotation == null) {
|
||||
// headlineAnnotation = new BootHeadlineAnnotation(headerPos, sourceViewer);
|
||||
// }
|
||||
// headlineAnnotation.setText(codeLens.getCommand().getTitle());
|
||||
// annotations.add(headlineAnnotation);
|
||||
// } catch (BadLocationException e) {
|
||||
// //ignore invalid highlights
|
||||
// }
|
||||
// });
|
||||
// highlights.forEach(codeLens -> {
|
||||
// });
|
||||
// support.updateAnnotations(annotations);
|
||||
// }
|
||||
|
||||
private static AnnotationPainter createAnnotationPainter(ISourceViewer viewer) {
|
||||
IAnnotationAccess annotationAccess = new IAnnotationAccess() {
|
||||
@Override
|
||||
public Object getType(Annotation annotation) {
|
||||
return annotation.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMultiLine(Annotation annotation) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTemporary(Annotation annotation) {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
AnnotationPainter painter = new AnnotationPainter(viewer, annotationAccess);
|
||||
((ITextViewerExtension2) viewer).addPainter(painter);
|
||||
return painter;
|
||||
}
|
||||
|
||||
private Map<Annotation, Position> createAnnotations(IDocument doc, List<CodeLens> highlights) {
|
||||
private static Map<Annotation, Position> createAnnotations(IDocument doc, List<CodeLens> highlights) {
|
||||
ImmutableMap.Builder<Annotation, Position> annotations = ImmutableMap.builder();
|
||||
if (highlights==null) {
|
||||
highlights = ImmutableList.of();
|
||||
|
||||
@@ -21,13 +21,12 @@ import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider;
|
||||
import org.springframework.tooling.ls.eclipse.commons.console.ConsoleUtil.Console;
|
||||
import org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolePreferenceConstants.ServerInfo;
|
||||
import org.springframework.tooling.ls.eclipse.commons.console.LanguageServerConsoles;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
import org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.ServerInfo;
|
||||
|
||||
public class STS4LanguageServerProcessStreamConnector extends ProcessStreamConnectionProvider {
|
||||
|
||||
private static LanguageServerProcessReaper processReaper = new LanguageServerProcessReaper();
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.ls.eclipse.commons;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.jface.text.source.ISourceViewer;
|
||||
import org.eclipse.lsp4e.LanguageServiceAccessor;
|
||||
import org.eclipse.lsp4e.LanguageServiceAccessor.LSPDocumentInfo;
|
||||
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class Utils {
|
||||
|
||||
public static Stream<ITextViewer> getActiveTextViewers() {
|
||||
return Arrays.stream(PlatformUI.getWorkbench().getWorkbenchWindows())
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(ww -> Arrays.stream(ww.getPages()))
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(page -> Arrays.stream(page.getEditorReferences()))
|
||||
.filter(Objects::nonNull)
|
||||
.map(ref -> ref.getEditor(false))
|
||||
.filter(Objects::nonNull)
|
||||
.map(editorPart -> editorPart.getAdapter(ITextViewer.class))
|
||||
.filter(Objects::nonNull);
|
||||
}
|
||||
|
||||
public static Stream<ISourceViewer> getActiveSourceViewers() {
|
||||
return getActiveTextViewers()
|
||||
.filter(viewer -> viewer instanceof ISourceViewer)
|
||||
.map(viewer -> (ISourceViewer) viewer);
|
||||
}
|
||||
|
||||
public static URI findDocUri(IDocument doc) {
|
||||
for (LSPDocumentInfo info : LanguageServiceAccessor.getLSPDocumentInfosFor(doc, (x) -> true)) {
|
||||
return info.getFileUri();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isProperDocumentIdFor(IDocument doc, VersionedTextDocumentIdentifier id) {
|
||||
for (LSPDocumentInfo info : LanguageServiceAccessor.getLSPDocumentInfosFor(doc, (x) -> true)) {
|
||||
if (info.getVersion() == id.getVersion()) {
|
||||
URI uri = info.getFileUri();
|
||||
if (uri != null && uri.toString().equals(id.getUri())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import java.util.Map;
|
||||
|
||||
import org.springframework.tooling.ls.eclipse.commons.LanguageServerCommonsActivator;
|
||||
import org.springframework.tooling.ls.eclipse.commons.console.ConsoleUtil.Console;
|
||||
import org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.ServerInfo;
|
||||
import org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolePreferenceConstants.ServerInfo;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.ls.eclipse.commons.console.preferences;
|
||||
package org.springframework.tooling.ls.eclipse.commons.preferences;
|
||||
|
||||
public class LanguageServerConsolePreferenceConstants {
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.ls.eclipse.commons.console.preferences;
|
||||
package org.springframework.tooling.ls.eclipse.commons.preferences;
|
||||
|
||||
import static org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.ALL_SERVERS;
|
||||
import static org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolePreferenceConstants.ALL_SERVERS;
|
||||
|
||||
import org.eclipse.debug.internal.ui.SWTFactory;
|
||||
import org.eclipse.jface.preference.BooleanFieldEditor;
|
||||
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
@@ -19,10 +20,11 @@ import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
import org.eclipse.ui.IWorkbenchPreferencePage;
|
||||
import org.springframework.tooling.ls.eclipse.commons.LanguageServerCommonsActivator;
|
||||
import org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.ServerInfo;
|
||||
import org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolePreferenceConstants.ServerInfo;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class LanguageServerConsolesPreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
|
||||
|
||||
|
||||
static IPreferenceStore getPrefsStoreFromPlugin() {
|
||||
return LanguageServerCommonsActivator.getInstance().getPreferenceStore();
|
||||
}
|
||||
@@ -40,5 +42,12 @@ public class LanguageServerConsolesPreferencesPage extends FieldEditorPreference
|
||||
for (ServerInfo s : ALL_SERVERS) {
|
||||
addField(new BooleanFieldEditor(s.preferenceKey, s.label, parent));
|
||||
}
|
||||
|
||||
SWTFactory.createHorizontalSpacer(parent, 2);
|
||||
|
||||
SWTFactory.createLabel(parent, "Settings for Spring Languare Server extensions:", 2);
|
||||
|
||||
addField(new BooleanFieldEditor(PreferenceConstants.HIGHLIGHT_CODELENS_PREFS, "Highlights CodeLens", parent));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.ls.eclipse.commons.preferences;
|
||||
|
||||
public class PreferenceConstants {
|
||||
|
||||
public static final String HIGHLIGHT_CODELENS_PREFS = "highlight.codelens";
|
||||
|
||||
}
|
||||
@@ -8,20 +8,21 @@
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.ls.eclipse.commons.console.preferences;
|
||||
package org.springframework.tooling.ls.eclipse.commons.preferences;
|
||||
|
||||
import static org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.*;
|
||||
import static org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolePreferenceConstants.*;
|
||||
|
||||
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.ServerInfo;
|
||||
import org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolePreferenceConstants.ServerInfo;
|
||||
|
||||
public class LanguageServerConsolesPrefsInitializer extends AbstractPreferenceInitializer {
|
||||
public class PrefsInitializer extends AbstractPreferenceInitializer {
|
||||
@Override
|
||||
public void initializeDefaultPreferences() {
|
||||
IPreferenceStore store = LanguageServerConsolesPreferencesPage.getPrefsStoreFromPlugin();
|
||||
for (ServerInfo s : ALL_SERVERS) {
|
||||
store.setDefault(s.preferenceKey, ENABLE_BY_DEFAULT);
|
||||
}
|
||||
store.setDefault(PreferenceConstants.HIGHLIGHT_CODELENS_PREFS, true);
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,12 @@
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.ls.eclipse.commons;
|
||||
package org.springframework.tooling.ls.eclipse.commons.preferences;
|
||||
|
||||
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
|
||||
import org.springframework.tooling.ls.eclipse.commons.LanguageServerCommonsActivator;
|
||||
|
||||
/**
|
||||
* Initializers of preferences for Generic editor for YAML ls extensions
|
||||
Reference in New Issue
Block a user