From c1f4458c3569f35a1b9477557528ceab4a91cb2c Mon Sep 17 00:00:00 2001 From: Kris De Volder Date: Thu, 19 Apr 2018 11:55:59 -0700 Subject: [PATCH] Add proper stub for add/removeClasspathListener LSP4J doesn't handle it well if the stub returns null. --- .../.settings/org.eclipse.jdt.ui.prefs | 59 +++++++++++++++++++ .../tooling/ls/eclipse/commons/Futures.java | 23 ++++++++ .../commons/STS4LanguageClientImpl.java | 27 ++++----- 3 files changed, 94 insertions(+), 15 deletions(-) create mode 100644 eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/.settings/org.eclipse.jdt.ui.prefs create mode 100644 eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/Futures.java diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/.settings/org.eclipse.jdt.ui.prefs b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 000000000..c743e1c07 --- /dev/null +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,59 @@ +eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=true +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_missing_override_annotations_interface_methods=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_functional_interfaces=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +sp_cleanup.format_source_code_changes_only=false +sp_cleanup.insert_inferred_type_arguments=false +sp_cleanup.make_local_variable_final=true +sp_cleanup.make_parameters_final=false +sp_cleanup.make_private_fields_final=true +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=false +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=false +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=false +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_redundant_type_arguments=false +sp_cleanup.remove_trailing_whitespaces=true +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_lambda=true +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=false +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=false +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/Futures.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/Futures.java new file mode 100644 index 000000000..1cf47b66a --- /dev/null +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/Futures.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * 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.concurrent.CompletableFuture; + +public class Futures { + + public static CompletableFuture fail(Throwable e) { + CompletableFuture f = new CompletableFuture(); + f.completeExceptionally(e); + return f; + } + +} diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java index f9ee43ae5..6cec33112 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java @@ -43,7 +43,6 @@ import org.eclipse.ui.texteditor.AbstractTextEditor; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.util.concurrent.Futures; @SuppressWarnings("restriction") public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4LanguageClient { @@ -51,7 +50,7 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La private static final String ANNOTION_TYPE_ID = "org.springframework.tooling.bootinfo"; class UpdateHighlights extends UIJob { - + private String target; UpdateHighlights(String target) { @@ -60,7 +59,7 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La setSystem(true); schedule(); } - + @Override public IStatus runInUIThread(IProgressMonitor monitor) { IWorkbenchWindow ww = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); @@ -93,23 +92,23 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La return Status.OK_STATUS; } }; - + /** * 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> currentHighlights = new HashMap<>(); - + /** * Current markers... indexed per document uri, needed sp we to be removed upon next update. */ - private Map currentAnnotations = new HashMap<>(); - + private Map currentAnnotations = new HashMap<>(); + private synchronized void updateAnnotations(String target, IDocument doc, IAnnotationModelExtension annotationModel) { if (target!=null) { Collection infos = LanguageServiceAccessor.getLSPDocumentInfosFor(doc, (x) -> true); for (LSPDocumentInfo docInfo : infos) { - URI uri = docInfo.getFileUri(); + URI uri = docInfo.getFileUri(); if (uri!=null && uri.toString().equals(target)) { Annotation[] toRemove = currentAnnotations.get(target); if (toRemove==null) { @@ -140,7 +139,7 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La } return annotations.build(); } - + @Override public synchronized void highlight(HighlightParams highlights) { String target = highlights.getDoc().getUri(); @@ -155,7 +154,7 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La String status = progressEvent.getStatusMsg() != null ? progressEvent.getStatusMsg() : ""; showStatusMessage(status); } - + private void showStatusMessage(final String status) { PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { @Override @@ -179,14 +178,12 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La @Override public CompletableFuture addClasspathListener(ClasspathListenerParams params) { - // TODO Auto-generated method stub - return null; + return Futures.fail(new UnsupportedOperationException("Not implemented")); } @Override public CompletableFuture removeClasspathListener(ClasspathListenerParams classpathListenerParams) { - // TODO Auto-generated method stub - return null; + return Futures.fail(new UnsupportedOperationException("Not implemented")); } - + }