From 9cc4fe5b633eb5159ef645da31fb1741316a6e77 Mon Sep 17 00:00:00 2001 From: Xavier Coulon Date: Tue, 21 Feb 2017 14:53:15 +0100 Subject: [PATCH] Issue #1802 - Document highlightings (#3343) Providing support for occurrences highlighting, with a restriction due a bug in the io.typefox.lsapi.services 0.3.0 bundle, which assumes that the language server will return a single occurrence to highlight, instead of a list of occurrences. Signed-off-by: Xavier Coulon --- .../ide/LanguageServerFileTypeRegister.java | 43 ++++++--- .../ide/highlighting/OccurrencesProvider.java | 93 +++++++++++++++++++ .../service/TextDocumentServiceClient.java | 28 ++++-- .../orion/client/OrionOccurrencesHandler.java | 22 +++++ .../client/OrionOccurrencesRegistrant.java | 61 ++++++++++++ .../client/inject/OrionEditorGinModule.java | 2 + .../jso/OrionOccurrenceContextOverlay.java | 42 +++++++++ .../client/jso/OrionOccurrenceOverlay.java | 43 +++++++++ .../service/TextDocumentService.java | 14 +++ 9 files changed, 330 insertions(+), 18 deletions(-) create mode 100644 plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/highlighting/OccurrencesProvider.java create mode 100644 plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/OrionOccurrencesHandler.java create mode 100644 plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/OrionOccurrencesRegistrant.java create mode 100644 plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionOccurrenceContextOverlay.java create mode 100644 plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionOccurrenceOverlay.java diff --git a/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/LanguageServerFileTypeRegister.java b/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/LanguageServerFileTypeRegister.java index b7b70af86d5..7d32a8684cd 100644 --- a/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/LanguageServerFileTypeRegister.java +++ b/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/LanguageServerFileTypeRegister.java @@ -14,6 +14,14 @@ import com.google.gwt.core.client.JsArrayString; import com.google.inject.Inject; import com.google.inject.Singleton; +import static com.google.common.collect.Lists.newArrayList; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + import org.eclipse.che.api.languageserver.shared.lsapi.LanguageDescriptionDTO; import org.eclipse.che.api.promises.client.Operation; import org.eclipse.che.api.promises.client.OperationException; @@ -25,17 +33,22 @@ import org.eclipse.che.ide.api.filetypes.FileTypeRegistry; import org.eclipse.che.ide.editor.orion.client.OrionContentTypeRegistrant; import org.eclipse.che.ide.editor.orion.client.OrionHoverRegistrant; +import org.eclipse.che.ide.editor.orion.client.OrionOccurrencesRegistrant; import org.eclipse.che.ide.editor.orion.client.jso.OrionContentTypeOverlay; import org.eclipse.che.ide.editor.orion.client.jso.OrionHighlightingConfigurationOverlay; import org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorProvider; +import org.eclipse.che.plugin.languageserver.ide.highlighting.OccurrencesProvider; import org.eclipse.che.plugin.languageserver.ide.hover.HoverProvider; import org.eclipse.che.plugin.languageserver.ide.service.LanguageServerRegistryServiceClient; import java.util.HashMap; -import java.util.List; import java.util.Map; import static com.google.common.collect.Lists.newArrayList; +import com.google.gwt.core.client.Callback; +import com.google.gwt.core.client.JsArrayString; +import com.google.inject.Inject; +import com.google.inject.Singleton; /** * @author Evgen Vidolob @@ -43,15 +56,18 @@ @Singleton public class LanguageServerFileTypeRegister implements WsAgentComponent { - + + private final LanguageServerRegistryServiceClient serverLanguageRegistry; - private final FileTypeRegistry fileTypeRegistry; - private final LanguageServerResources resources; - private final EditorRegistry editorRegistry; - private final OrionContentTypeRegistrant contentTypeRegistrant; - private final OrionHoverRegistrant orionHoverRegistrant; - private final LanguageServerEditorProvider editorProvider; - private final HoverProvider hoverProvider; + private final FileTypeRegistry fileTypeRegistry; + private final LanguageServerResources resources; + private final EditorRegistry editorRegistry; + private final OrionContentTypeRegistrant contentTypeRegistrant; + private final OrionHoverRegistrant orionHoverRegistrant; + private final OrionOccurrencesRegistrant orionOccurrencesRegistrant; + private final LanguageServerEditorProvider editorProvider; + private final HoverProvider hoverProvider; + private final OccurrencesProvider occurrencesProvider; private final Map ext2langId = new HashMap<>(); @@ -62,16 +78,20 @@ public LanguageServerFileTypeRegister(LanguageServerRegistryServiceClient server EditorRegistry editorRegistry, OrionContentTypeRegistrant contentTypeRegistrant, OrionHoverRegistrant orionHoverRegistrant, + OrionOccurrencesRegistrant orionOccurrencesRegistrant, LanguageServerEditorProvider editorProvider, - HoverProvider hoverProvider) { + HoverProvider hoverProvider, + OccurrencesProvider occurrencesProvider) { this.serverLanguageRegistry = serverLanguageRegistry; this.fileTypeRegistry = fileTypeRegistry; this.resources = resources; this.editorRegistry = editorRegistry; this.contentTypeRegistrant = contentTypeRegistrant; this.orionHoverRegistrant = orionHoverRegistrant; + this.orionOccurrencesRegistrant = orionOccurrencesRegistrant; this.editorProvider = editorProvider; this.hoverProvider = hoverProvider; + this.occurrencesProvider = occurrencesProvider; } @Override @@ -108,11 +128,12 @@ public void apply(List langs) throws OperationException config.setId(lang.getLanguageId() + ".highlighting"); config.setContentTypes(contentTypeId); config.setPatterns(lang.getHighlightingConfiguration()); - + Logger logger = Logger.getLogger(LanguageServerFileTypeRegister.class.getName()); contentTypeRegistrant.registerFileType(contentType, config); } } orionHoverRegistrant.registerHover(contentTypes, hoverProvider); + orionOccurrencesRegistrant.registerOccurrencesHandler(contentTypes, occurrencesProvider); } callback.onSuccess(LanguageServerFileTypeRegister.this); } diff --git a/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/highlighting/OccurrencesProvider.java b/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/highlighting/OccurrencesProvider.java new file mode 100644 index 00000000000..87dbfdc28f6 --- /dev/null +++ b/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/highlighting/OccurrencesProvider.java @@ -0,0 +1,93 @@ +package org.eclipse.che.plugin.languageserver.ide.highlighting; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.eclipse.che.api.languageserver.shared.lsapi.DocumentHighlightDTO; +import org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO; +import org.eclipse.che.api.promises.client.Function; +import org.eclipse.che.api.promises.client.FunctionException; +import org.eclipse.che.api.promises.client.Promise; +import org.eclipse.che.api.promises.client.js.JsPromise; +import org.eclipse.che.ide.api.editor.EditorAgent; +import org.eclipse.che.ide.api.editor.EditorPartPresenter; +import org.eclipse.che.ide.api.editor.document.Document; +import org.eclipse.che.ide.api.editor.texteditor.TextEditor; +import org.eclipse.che.ide.editor.orion.client.OrionOccurrencesHandler; +import org.eclipse.che.ide.editor.orion.client.jso.OrionOccurrenceContextOverlay; +import org.eclipse.che.ide.editor.orion.client.jso.OrionOccurrenceOverlay; +import org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration; +import org.eclipse.che.plugin.languageserver.ide.service.TextDocumentServiceClient; +import org.eclipse.che.plugin.languageserver.ide.util.DtoBuildHelper; + +import com.google.inject.Inject; +import com.google.inject.Singleton; + +/** + * Provides occurrences highlights for the Orion Editor. + * + * @author Xavier Coulon, Red Hat + */ +@Singleton +public class OccurrencesProvider implements OrionOccurrencesHandler { + + private static final Logger LOGGER = Logger.getLogger(OccurrencesProvider.class.getName()); + private final EditorAgent editorAgent; + private final TextDocumentServiceClient client; + private final DtoBuildHelper helper; + + /** + * Constructor. + * @param editorAgent + * @param client + * @param helper + */ + @Inject + public OccurrencesProvider(EditorAgent editorAgent, TextDocumentServiceClient client, DtoBuildHelper helper) { + this.editorAgent = editorAgent; + this.client = client; + this.helper = helper; + } + + @Override + public JsPromise computeOccurrences( + OrionOccurrenceContextOverlay context) { + final EditorPartPresenter activeEditor = editorAgent.getActiveEditor(); + if (activeEditor == null || !(activeEditor instanceof TextEditor)) { + return null; + } + final TextEditor editor = ((TextEditor)activeEditor); + if (!(editor.getConfiguration() instanceof LanguageServerEditorConfiguration)) { + return null; + } + final LanguageServerEditorConfiguration configuration = (LanguageServerEditorConfiguration)editor.getConfiguration(); + if (configuration.getServerCapabilities().isDocumentHighlightProvider() == null || !configuration.getServerCapabilities().isDocumentHighlightProvider()) { + return null; + } + final Document document = editor.getDocument(); + final TextDocumentPositionParamsDTO paramsDTO = helper.createTDPP(document, context.getStart()); + // FIXME: the result should be a Promise> but the typefox API returns a single DocumentHighlightDTO + Promise promise = client.documentHighlight(paramsDTO); + Promise then = promise.then(new Function() { + @Override + public OrionOccurrenceOverlay[] apply(DocumentHighlightDTO highlight) throws FunctionException { + if(highlight == null) { + return new OrionOccurrenceOverlay[0]; + } + final OrionOccurrenceOverlay[] occurrences = new OrionOccurrenceOverlay[1]; + final OrionOccurrenceOverlay occurrence = OrionOccurrenceOverlay.create(); + // FIXME: this assumes that the language server will + // compute a range based on 'line 1', ie, the whole + // file content is on line 1 and the location to + // highlight is given by the 'character' position + // only. + occurrence.setStart(highlight.getRange().getStart().getCharacter()); + occurrence.setEnd(highlight.getRange().getEnd().getCharacter() + 1); + occurrences[0] = occurrence; + return occurrences; + } + }); + return (JsPromise)then; + + } +} diff --git a/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/service/TextDocumentServiceClient.java b/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/service/TextDocumentServiceClient.java index c264dec3378..b8bec633f7d 100644 --- a/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/service/TextDocumentServiceClient.java +++ b/plugins/plugin-languageserver/che-plugin-languageserver-ide/src/main/java/org/eclipse/che/plugin/languageserver/ide/service/TextDocumentServiceClient.java @@ -10,10 +10,11 @@ *******************************************************************************/ package org.eclipse.che.plugin.languageserver.ide.service; -import io.typefox.lsapi.CompletionItem; +import static org.eclipse.che.ide.MimeType.APPLICATION_JSON; +import static org.eclipse.che.ide.rest.HTTPHeader.ACCEPT; +import static org.eclipse.che.ide.rest.HTTPHeader.CONTENT_TYPE; -import com.google.inject.Inject; -import com.google.inject.Singleton; +import java.util.List; import org.eclipse.che.api.languageserver.shared.lsapi.CompletionItemDTO; import org.eclipse.che.api.languageserver.shared.lsapi.CompletionListDTO; @@ -22,6 +23,7 @@ import org.eclipse.che.api.languageserver.shared.lsapi.DidOpenTextDocumentParamsDTO; import org.eclipse.che.api.languageserver.shared.lsapi.DidSaveTextDocumentParamsDTO; import org.eclipse.che.api.languageserver.shared.lsapi.DocumentFormattingParamsDTO; +import org.eclipse.che.api.languageserver.shared.lsapi.DocumentHighlightDTO; import org.eclipse.che.api.languageserver.shared.lsapi.DocumentOnTypeFormattingParamsDTO; import org.eclipse.che.api.languageserver.shared.lsapi.DocumentRangeFormattingParamsDTO; import org.eclipse.che.api.languageserver.shared.lsapi.DocumentSymbolParamsDTO; @@ -52,11 +54,10 @@ import org.eclipse.che.plugin.languageserver.ide.editor.PublishDiagnosticsProcessor; import org.eclipse.che.plugin.languageserver.ide.editor.ShowMessageProcessor; -import java.util.List; +import com.google.inject.Inject; +import com.google.inject.Singleton; -import static org.eclipse.che.ide.MimeType.APPLICATION_JSON; -import static org.eclipse.che.ide.rest.HTTPHeader.ACCEPT; -import static org.eclipse.che.ide.rest.HTTPHeader.CONTENT_TYPE; +import io.typefox.lsapi.CompletionItem; /** @@ -291,6 +292,19 @@ public void didSave(DidSaveTextDocumentParamsDTO saveEvent) { .header(CONTENT_TYPE, APPLICATION_JSON).data(((JsonSerializable)saveEvent).toJson()).send(); } + + /** + * GWT client implementation of {@link io.typefox.lsapi.TextDocumentService#documentHighlight(io.typefox.lsapi.TextDocumentPositionParams position)} + * + * @param position + * @return a {@link Promise} of an array of {@link DocumentHighlightDTO} which will be computed by the language server. + */ + public Promise documentHighlight(TextDocumentPositionParamsDTO position) { + final String requestUrl = appContext.getDevMachine().getWsAgentBaseUrl() + "/languageserver/textDocument/documentHighlight"; + final Unmarshallable unmarshaller = unmarshallerFactory.newUnmarshaller(DocumentHighlightDTO.class); + return asyncRequestFactory.createPostRequest(requestUrl, null).header(ACCEPT, APPLICATION_JSON) + .header(CONTENT_TYPE, APPLICATION_JSON).data(((JsonSerializable)position).toJson()).send(unmarshaller); + } /** * Subscribes to websocket for 'textDocument/publishDiagnostics' notifications. */ diff --git a/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/OrionOccurrencesHandler.java b/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/OrionOccurrencesHandler.java new file mode 100644 index 00000000000..6174263c9fa --- /dev/null +++ b/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/OrionOccurrencesHandler.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2012-2016 Codenvy, S.A. + * 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: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.ide.editor.orion.client; + +import org.eclipse.che.api.promises.client.js.JsPromise; +import org.eclipse.che.ide.editor.orion.client.jso.OrionOccurrenceContextOverlay; +import org.eclipse.che.ide.editor.orion.client.jso.OrionOccurrenceOverlay; + +/** + * @author Xavier Coulon, Red Hat + */ +public interface OrionOccurrencesHandler { + JsPromise computeOccurrences(OrionOccurrenceContextOverlay context); +} diff --git a/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/OrionOccurrencesRegistrant.java b/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/OrionOccurrencesRegistrant.java new file mode 100644 index 00000000000..57ed5ff25d3 --- /dev/null +++ b/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/OrionOccurrencesRegistrant.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012-2016 Codenvy, S.A. + * 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: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.ide.editor.orion.client; + +import com.google.gwt.core.client.JsArrayString; +import com.google.inject.Inject; +import com.google.inject.Provider; +import com.google.inject.Singleton; + +import org.eclipse.che.api.promises.client.Operation; +import org.eclipse.che.api.promises.client.OperationException; +import org.eclipse.che.ide.editor.orion.client.jso.OrionCodeEditWidgetOverlay; +import org.eclipse.che.ide.editor.orion.client.jso.OrionServiceRegistryOverlay; + +/** + * @author Xavier Coulon,Red Hat + */ +@Singleton +public class OrionOccurrencesRegistrant { + + private final Provider codeEditWidgetProvider; + private final EditorInitializePromiseHolder editorModule; + + @Inject + public OrionOccurrencesRegistrant(Provider codeEditWidgetProvider, + EditorInitializePromiseHolder editorModule) { + this.codeEditWidgetProvider = codeEditWidgetProvider; + this.editorModule = editorModule; + } + + public void registerOccurrencesHandler(final JsArrayString contentTypes, final OrionOccurrencesHandler handler) { + editorModule.getInitializerPromise().then(new Operation() { + @Override + public void apply(Void arg) throws OperationException { + registerOccurrencesHandler(codeEditWidgetProvider.get().getServiceRegistry(), contentTypes, handler); + } + }); + } + + private final native void registerOccurrencesHandler(OrionServiceRegistryOverlay serviceRegistry, JsArrayString contentTypes, + OrionOccurrencesHandler handler) /*-{ + serviceRegistry.registerService("orion.edit.occurrences", { + computeOccurrences: function(editorContext, context) { + return handler.@OrionOccurrencesHandler::computeOccurrences(*)(context); + } + }, { + name: "Occurrences", + contentType: contentTypes + }); + }-*/; + + +} diff --git a/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/inject/OrionEditorGinModule.java b/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/inject/OrionEditorGinModule.java index fd40dc4d5db..511e134f45a 100644 --- a/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/inject/OrionEditorGinModule.java +++ b/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/inject/OrionEditorGinModule.java @@ -40,5 +40,7 @@ protected void configure() { install(new GinFactoryModuleBuilder().build(ContentAssistWidgetFactory.class)); GinMultibinder.newSetBinder(binder(), OrionPlugin.class).addBinding().to(JavaHighlightingOrionPlugin.class); + + //GinMultibinder.newSetBinder(binder(), OrionPlugin.class).addBinding().to(LanguageServerHighlightingOrionPlugin.class); } } diff --git a/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionOccurrenceContextOverlay.java b/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionOccurrenceContextOverlay.java new file mode 100644 index 00000000000..345f90d345c --- /dev/null +++ b/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionOccurrenceContextOverlay.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2012-2016 Codenvy, S.A. + * 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: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.ide.editor.orion.client.jso; + +import com.google.gwt.core.client.JavaScriptObject; + +/** + * The 'Occurrence Object' for Orion occurrences + * See Orion Occurrences + * + * @author Xavier Coulon, Red Hat + */ +public class OrionOccurrenceContextOverlay extends JavaScriptObject{ + protected OrionOccurrenceContextOverlay() {} + + public final native String getContentType() /*-{ + return this.contentType; + }-*/; + + /** + * @return The offset into the file for the start of the occurrence. + */ + public final native int getStart() /*-{ + return this.selection.start; + }-*/; + + /** + * @return The offset into the file for the end of the occurrence. + */ + public final native int getEnd() /*-{ + return this.selection.end; + }-*/; +} + diff --git a/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionOccurrenceOverlay.java b/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionOccurrenceOverlay.java new file mode 100644 index 00000000000..f76c69d013a --- /dev/null +++ b/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionOccurrenceOverlay.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2012-2016 Codenvy, S.A. + * 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: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.ide.editor.orion.client.jso; + +import com.google.gwt.core.client.JavaScriptObject; + +/** + * The 'Occurrence Object' for Orion occurrences + * See Orion Occurrences + * + * @author Xavier Coulon, Red Hat + */ +public class OrionOccurrenceOverlay extends JavaScriptObject{ + protected OrionOccurrenceOverlay() {} + + public static native OrionOccurrenceOverlay create() /*-{ + return {}; + }-*/; + + + /** + * @param offset The offset into the file for the start of the occurrence. + */ + public final native void setStart(int offset) /*-{ + this.start = offset; + }-*/; + + /** + * @param offset The offset into the file for the end of the occurrence. + */ + public final native void setEnd(int offset) /*-{ + this.end = offset; + }-*/; +} + diff --git a/wsagent/che-core-api-languageserver/src/main/java/org/eclipse/che/api/languageserver/service/TextDocumentService.java b/wsagent/che-core-api-languageserver/src/main/java/org/eclipse/che/api/languageserver/service/TextDocumentService.java index 3a0ab192d94..b423f60eba6 100644 --- a/wsagent/che-core-api-languageserver/src/main/java/org/eclipse/che/api/languageserver/service/TextDocumentService.java +++ b/wsagent/che-core-api-languageserver/src/main/java/org/eclipse/che/api/languageserver/service/TextDocumentService.java @@ -12,6 +12,7 @@ import io.typefox.lsapi.CompletionItem; import io.typefox.lsapi.CompletionList; +import io.typefox.lsapi.DocumentHighlight; import io.typefox.lsapi.Hover; import io.typefox.lsapi.Location; import io.typefox.lsapi.SignatureHelp; @@ -293,6 +294,19 @@ public void didSave(DidSaveTextDocumentParamsDTO saveEvent) throws LanguageServe } } + @POST + @Path("documentHighlight") + @Consumes(MediaType.APPLICATION_JSON) + public DocumentHighlight documentHighlight(TextDocumentPositionParamsDTO positionParams) + throws LanguageServerException, InterruptedException, ExecutionException { + positionParams.getTextDocument().setUri(prefixURI(positionParams.getTextDocument().getUri())); + LanguageServer server = getServer(positionParams.getTextDocument().getUri()); + if (server != null) { + return server.getTextDocumentService().documentHighlight(positionParams).get(); + } + return null; + } + private LanguageServer getServer(String uri) throws LanguageServerException { return languageServerRegistry.findServer(uri); }