Skip to content

Commit

Permalink
#1801 implement 'Signature Help' LS feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgen Vidolob committed Sep 29, 2016
1 parent 6e3aa1c commit a0f374e
Show file tree
Hide file tree
Showing 37 changed files with 1,268 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* assisting process.
* </p>
*
* @author <a href="mailto:evidolob@exoplatform.com">Evgen Vidolob</a>
* @version $Id:
* @author Evgen Vidolob
*/
public interface CodeAssistProcessor {

Expand All @@ -30,7 +29,7 @@ public interface CodeAssistProcessor {
* specified location within the document that corresponds
* to the current cursor position within the text view.
*
* @param view
* @param editor
* the editor whose document is used to compute the proposals
* @param offset
* an offset within the document for which completions should be computed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.che.ide.api.editor.partition.DocumentPositionMap;
import org.eclipse.che.ide.api.editor.quickfix.QuickAssistProcessor;
import org.eclipse.che.ide.api.editor.reconciler.Reconciler;
import org.eclipse.che.ide.api.editor.signature.SignatureHelpProvider;

import java.util.Map;

Expand Down Expand Up @@ -76,4 +77,9 @@ public QuickAssistProcessor getQuickAssistProcessor() {
public ChangeInterceptorProvider getChangeInterceptorProvider() {
return null;
}

@Override
public SignatureHelpProvider getSignatureHelpProvider() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.che.ide.api.editor.partition.DocumentPositionMap;
import org.eclipse.che.ide.api.editor.quickfix.QuickAssistProcessor;
import org.eclipse.che.ide.api.editor.reconciler.Reconciler;
import org.eclipse.che.ide.api.editor.signature.SignatureHelpProvider;

import javax.validation.constraints.NotNull;
import java.util.Map;
Expand Down Expand Up @@ -97,4 +98,11 @@ public interface TextEditorConfiguration {
*/
@Nullable
ChangeInterceptorProvider getChangeInterceptorProvider();

/**
* Return the {@link SignatureHelpProvider}
* @return the signature help provider
*/
@Nullable
SignatureHelpProvider getSignatureHelpProvider();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* 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.api.editor.signature;

import com.google.common.base.Optional;

import javax.validation.constraints.NotNull;

/**
* Represent a parameter of callable signature.
* Parameter can have label and optional documentation.
*
* @author Evgen Vidolob
*/
public interface ParameterInfo {

/**
* The label of this parameter. Used for UI.
* @return the parameter label.
*/
@NotNull
String getLabel();

/**
* The documentation of this parameter.
* @return the human-readable documentation string.
*/
Optional<String> getDocumentation();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* 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.api.editor.signature;

import com.google.common.base.Optional;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
* Result of calculation of signatures, represent the signature of something callable.
*
* @author Evgen Vidolob
*/
public interface SignatureHelp {

/**
* One or more signature.
* @return
*/
@NotNull
List<SignatureInfo> getSignatures();

/**
* The active signature
*
* @return
*/
Optional<Integer> getActiveSignature();

/**
* The active parameter of the active signature.
* @return
*/
Optional<Integer> getActiveParameter();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* 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.api.editor.signature;

import com.google.common.base.Optional;

import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;

import javax.validation.constraints.NotNull;

/**
* Calculates signature information at cursor position.
*
* @author Evgen Vidolob
*/
public interface SignatureHelpProvider {

/**
* Requests to provide signature information
* @param document
* the document where request called
* @param offset
* the offset where request called
* @return the promise.
*/
@NotNull
Promise<Optional<SignatureHelp>> signatureHelp(Document document, int offset);

/**
* Installs the SignatureHelpProvider on the given text view.
*/
void install(TextEditor editor);

/**
* Removes the SignatureHelpProvider from the text view it has previously been installed on.
*/
void uninstall();
}
Original file line number Diff line number Diff line change
@@ -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.api.editor.signature;

import com.google.common.base.Optional;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
* Represents the signature of something callable. A signature can have label, like method name,
* a documentation and list of parameters
*
* @author Evgen Vidolob
*/
public interface SignatureInfo {
/**
* The label of this signature.
* @return
*/
@NotNull
String getLabel();

/**
* The documentation of this signature
* @return
*/
Optional<String> getDocumentation();

/**
* The parameters of this signature.
* @return
*/
Optional<List<ParameterInfo>> getParameters();
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public interface TextEditorOperations {
* show quick assist and quick fix proposals for the current position.
*/
int QUICK_ASSIST = 15;

/**
* Text operation code for requesting signature help for current cursor position.
*/
int SIGNATURE_HELP = 16;
}
Original file line number Diff line number Diff line change
Expand Up @@ -833,4 +833,10 @@ public interface CoreLocalizationConstant extends Messages {

@Key("action.convert.folder.to.project.description")
String actionConvertFolderToProjectDescription();

@Key("signature.name")
String signatureName();

@Key("signature.description")
String signatureDescription();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*******************************************************************************
* 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.actions;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.eclipse.che.ide.CoreLocalizationConstant;
import org.eclipse.che.ide.api.action.AbstractPerspectiveAction;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.editor.texteditor.HandlesTextOperations;
import org.eclipse.che.ide.api.editor.texteditor.TextEditorOperations;

import javax.validation.constraints.NotNull;

import static java.util.Collections.singletonList;
import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID;

/**
* Action for 'Signature help', in general should show signature of something callable.
*
* @author Evgen Vidolob
*/
@Singleton
public class SignatureHelpAction extends AbstractPerspectiveAction {

private final EditorAgent editorAgent;

@Inject
public SignatureHelpAction(EditorAgent editorAgent, CoreLocalizationConstant constant) {
super(singletonList(PROJECT_PERSPECTIVE_ID), constant.signatureName(), constant.signatureDescription(), null, null);
this.editorAgent = editorAgent;
}

@Override
public void updateInPerspective(@NotNull ActionEvent event) {
final EditorPartPresenter editor = editorAgent.getActiveEditor();
boolean isCanDoOperation = false;

HandlesTextOperations handlesOperations;
if (editor instanceof HandlesTextOperations) {
handlesOperations = (HandlesTextOperations)editor;
isCanDoOperation = handlesOperations.canDoOperation(TextEditorOperations.SIGNATURE_HELP);
}

event.getPresentation().setEnabledAndVisible(isCanDoOperation);
}

@Override
public void actionPerformed(ActionEvent e) {
final EditorPartPresenter editor = editorAgent.getActiveEditor();
HandlesTextOperations handlesOperations;
if (editor instanceof HandlesTextOperations) {
handlesOperations = (HandlesTextOperations)editor;
if (handlesOperations.canDoOperation(TextEditorOperations.SIGNATURE_HELP)) {
handlesOperations.doOperation(TextEditorOperations.SIGNATURE_HELP);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.eclipse.che.ide.statepersistance.AppStateManager;

/**
* Restore workspace state, like opened files.
*
* @author Evgen Vidolob
*/
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.eclipse.che.ide.actions.ShowHiddenFilesAction;
import org.eclipse.che.ide.actions.ShowPreferencesAction;
import org.eclipse.che.ide.actions.ShowReferenceAction;
import org.eclipse.che.ide.actions.SignatureHelpAction;
import org.eclipse.che.ide.actions.UndoAction;
import org.eclipse.che.ide.actions.UploadFileAction;
import org.eclipse.che.ide.actions.UploadFolderAction;
Expand Down Expand Up @@ -296,6 +297,9 @@ public interface ParserResource extends ClientBundle {
@Inject
private RefreshPathAction refreshPathAction;

@Inject
private SignatureHelpAction signatureHelpAction;

@Inject
@Named("XMLFileType")
private FileType xmlFile;
Expand Down Expand Up @@ -635,6 +639,7 @@ public void initialize() {
editorTabContextMenu.add(splitHorizontallyAction);

actionManager.registerAction("noOpAction", new NoOpAction());
actionManager.registerAction("signatureHelp", signatureHelpAction);

// Define hot-keys
keyBinding.getGlobal().addKey(new KeyBuilder().action().alt().charCode('n').build(), "navigateToFile");
Expand All @@ -652,8 +657,10 @@ public void initialize() {

if (UserAgent.isMac()) {
keyBinding.getGlobal().addKey(new KeyBuilder().control().charCode('w').build(), "closeActiveEditor");
keyBinding.getGlobal().addKey(new KeyBuilder().control().charCode('p').build(), "signatureHelp");
} else {
keyBinding.getGlobal().addKey(new KeyBuilder().alt().charCode('w').build(), "closeActiveEditor");
keyBinding.getGlobal().addKey(new KeyBuilder().action().charCode('p').build(), "signatureHelp");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ appearance.category = IDE
format.name = Format
format.description = Formatter of Code

############### Signature Help #####################
signature.name = Signature Help
signature.description = Signature Help

############### Undo ###############################
undo.name = Undo
undo.description = Undo the most recent document action.
Expand Down
Loading

0 comments on commit a0f374e

Please sign in to comment.