forked from eclipse-che/che
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue eclipse-che#1802 - Document highlightings (eclipse-che#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 <xcoulon@redhat.com>
- Loading branch information
Showing
9 changed files
with
330 additions
and
18 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
93 changes: 93 additions & 0 deletions
93
...main/java/org/eclipse/che/plugin/languageserver/ide/highlighting/OccurrencesProvider.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,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<OrionOccurrenceOverlay[]> 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<List<DocumentHighlightDTO>> but the typefox API returns a single DocumentHighlightDTO | ||
Promise<DocumentHighlightDTO> promise = client.documentHighlight(paramsDTO); | ||
Promise<OrionOccurrenceOverlay[]> then = promise.then(new Function<DocumentHighlightDTO, OrionOccurrenceOverlay[]>() { | ||
@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<OrionOccurrenceOverlay[]>)then; | ||
|
||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...editor/src/main/java/org/eclipse/che/ide/editor/orion/client/OrionOccurrencesHandler.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,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<OrionOccurrenceOverlay[]> computeOccurrences(OrionOccurrenceContextOverlay context); | ||
} |
61 changes: 61 additions & 0 deletions
61
...tor/src/main/java/org/eclipse/che/ide/editor/orion/client/OrionOccurrencesRegistrant.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,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<OrionCodeEditWidgetOverlay> codeEditWidgetProvider; | ||
private final EditorInitializePromiseHolder editorModule; | ||
|
||
@Inject | ||
public OrionOccurrencesRegistrant(Provider<OrionCodeEditWidgetOverlay> codeEditWidgetProvider, | ||
EditorInitializePromiseHolder editorModule) { | ||
this.codeEditWidgetProvider = codeEditWidgetProvider; | ||
this.editorModule = editorModule; | ||
} | ||
|
||
public void registerOccurrencesHandler(final JsArrayString contentTypes, final OrionOccurrencesHandler handler) { | ||
editorModule.getInitializerPromise().then(new Operation<Void>() { | ||
@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 | ||
}); | ||
}-*/; | ||
|
||
|
||
} |
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
42 changes: 42 additions & 0 deletions
42
.../main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionOccurrenceContextOverlay.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,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 <a href="https://wiki.eclipse.org/Orion/Documentation/Developer_Guide/Plugging_into_the_editor#orion.edit.occurrences">Orion Occurrences</a> | ||
* | ||
* @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; | ||
}-*/; | ||
} | ||
|
Oops, something went wrong.