Skip to content

Commit

Permalink
Merge pull request #140 from piotrtomiak/master
Browse files Browse the repository at this point in the history
Asynchronous requests to Tern Server
  • Loading branch information
angelozerr committed Jan 30, 2015
2 parents c6622b9 + d790879 commit c8527d7
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
import tern.angular.protocol.completions.TernAngularCompletionsQuery;
import tern.eclipse.ide.core.IIDETernProject;
import tern.eclipse.ide.core.TernCorePlugin;
import tern.server.ITernServer;
import tern.server.protocol.IJSONObjectHelper;
import tern.server.protocol.completions.ITernCompletionCollector;
import tern.server.protocol.completions.TernCompletionProposalRec;

public class CustomAngularModulesRegistry extends
AbstractAngularModulesRegistry implements IResourceChangeListener,
Expand Down Expand Up @@ -92,13 +93,11 @@ protected void refreshIfNeeded() {
new ITernCompletionCollector() {

@Override
public void addProposal(String name,
String displayName, String type,
String doc, String url, String origin,
int start, int end, boolean isProperty,
boolean isObjectKey, Object completion,
ITernServer ternServer) {
String moduleName = ternServer.getText(
public void addProposal(
TernCompletionProposalRec proposal,
Object completion,
IJSONObjectHelper jsonObjectHelper) {
String moduleName = jsonObjectHelper.getText(
completion, "module");
if (!StringUtils.isEmpty(moduleName)) {
tern.angular.modules.Module module = CustomAngularModulesRegistry.this
Expand All @@ -109,12 +108,12 @@ public void addProposal(String name,
}

List<String> tagsName = new ArrayList<String>();
String restrict = ternServer.getText(
String restrict = jsonObjectHelper.getText(
completion, "restrict");
DirectiveValue directiveValue = DirectiveValue.none;
new Directive(name, AngularType.model,
null, tagsName, restrict,
directiveValue, module);
new Directive(proposal.name,
AngularType.model, null, tagsName,
restrict, directiveValue, module);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import tern.angular.protocol.definition.TernAngularDefinitionQuery;
import tern.scriptpath.ITernScriptPath;
import tern.server.ITernServer;
import tern.server.protocol.IJSONObjectHelper;
import tern.server.protocol.completions.ITernCompletionCollector;
import tern.server.protocol.completions.TernCompletionProposalRec;
import tern.server.protocol.definition.ITernDefinitionCollector;

public class Module extends BaseModel implements ITernCompletionCollector,
Expand Down Expand Up @@ -49,13 +51,11 @@ public Object[] getAngularElements() {
}

@Override
public void addProposal(String name, String displayName, String type,
String doc, String url, String origin, int start, int end,
boolean isProperty, boolean isObjectKey, Object completion,
ITernServer ternServer) {
AngularType angularType = AngularType.get(ternServer.getText(
public void addProposal(TernCompletionProposalRec proposal,
Object completion, IJSONObjectHelper jsonObjectHelper) {
AngularType angularType = AngularType.get(jsonObjectHelper.getText(
completion, "angularType"));
elements.add(new AngularElement(name, angularType, Module.this));
elements.add(new AngularElement(proposal.name, angularType, Module.this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import tern.angular.protocol.completions.TernAngularCompletionsQuery;
import tern.scriptpath.ITernScriptPath;
import tern.server.ITernServer;
import tern.server.protocol.IJSONObjectHelper;
import tern.server.protocol.completions.ITernCompletionCollector;
import tern.server.protocol.completions.TernCompletionProposalRec;

public class ModulesFolder extends BaseModel implements
ITernCompletionCollector {
Expand All @@ -41,10 +43,8 @@ public Object[] getModules() {
}

@Override
public void addProposal(String name, String displayName, String type,
String doc, String url, String origin, int start, int end,
boolean isProperty, boolean isObjectKey, Object completion,
ITernServer ternServer) {
modules.add(new Module(name, getScriptPath()));
public void addProposal(TernCompletionProposalRec proposal,
Object completion, IJSONObjectHelper jsonObjectHelper) {
modules.add(new Module(proposal.name, getScriptPath()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
import org.eclipse.wst.xml.ui.internal.contentassist.XMLRelevanceConstants;

import tern.angular.AngularType;
import tern.angular.protocol.completions.AngularCompletionProposalRec;
import tern.eclipse.ide.ui.contentassist.JSTernCompletionProposal;
import tern.server.ITernServer;
import tern.server.protocol.IJSONObjectHelper;

/**
* Extrends JavaScript Tern completion proposal to display "module" and
Expand All @@ -26,30 +27,30 @@
public class JSAngularCompletionProposal extends JSTernCompletionProposal
implements IRelevanceCompletionProposal {

private final ITernServer ternServer;
private final IJSONObjectHelper jsonObjectHelper;
private final Object completion;

public JSAngularCompletionProposal(String name, String type, String doc,
String url, String origin, Object completion, ITernServer server,
AngularType angularType, int startOffset) {
super(name, type, doc, url, origin, startOffset, startOffset);
this.ternServer = server;
public JSAngularCompletionProposal(AngularCompletionProposalRec proposal,
Object completion, IJSONObjectHelper jsonObjectHelper,
AngularType angularType) {
super(proposal);
this.jsonObjectHelper = jsonObjectHelper;
this.completion = completion;
super.setTriggerCharacters(new char[] { '.' });
}

@Override
public String getAdditionalProposalInfo() {
String module = ternServer.getText(completion, "module");
String controller = ternServer.getText(completion, "controller");
String module = jsonObjectHelper.getText(completion, "module");
String controller = jsonObjectHelper.getText(completion, "controller");
return HTMLAngularPrinter
.getAngularInfo(this, null, module, controller);
}

// @Override
protected String getAdditionalProposalInfoTitle() {
String module = ternServer.getText(completion, "module");
String controller = ternServer.getText(completion, "controller");
String module = jsonObjectHelper.getText(completion, "module");
String controller = jsonObjectHelper.getText(completion, "controller");

StringBuilder title = new StringBuilder(getName());
if (module != null || controller != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
import org.eclipse.swt.widgets.Shell;

import tern.angular.AngularType;
import tern.angular.protocol.completions.AngularCompletionProposalRec;
import tern.eclipse.ide.ui.TernUIPlugin;
import tern.eclipse.jface.contentassist.TernCompletionProposal;
import tern.server.ITernServer;
import tern.server.protocol.IJSONObjectHelper;

/**
* Extrends Tern completion proposal to display "module" and "controller"
Expand All @@ -25,23 +26,22 @@
*/
public class MarkupAngularCompletionProposal extends TernCompletionProposal {

private final ITernServer ternServer;
private final IJSONObjectHelper jsonObjectHelper;
private final Object completion;

public MarkupAngularCompletionProposal(String name, String type,
String doc, String url, String origin, int start, int end,
Object completion, ITernServer server, AngularType angularType,
int startOffset) {
super(name, type, doc, url, origin, startOffset, startOffset);
this.ternServer = server;
public MarkupAngularCompletionProposal(
AngularCompletionProposalRec proposal, Object completion,
IJSONObjectHelper jsonObjectHelper, AngularType angularType) {
super(proposal);
this.jsonObjectHelper = jsonObjectHelper;
this.completion = completion;
}

@Override
public String getAdditionalProposalInfo() {
String module = ternServer.getText(completion, "module");
String controller = ternServer.getText(completion, "controller");
AngularType angularType = AngularType.get(ternServer.getText(
String module = jsonObjectHelper.getText(completion, "module");
String controller = jsonObjectHelper.getText(completion, "controller");
AngularType angularType = AngularType.get(jsonObjectHelper.getText(
completion, "angularType"));
return HTMLAngularPrinter.getAngularInfo(getType(), getName(), module,
controller, angularType, super.getDoc(), getOrigin());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
import tern.angular.AngularType;
import tern.eclipse.ide.ui.hover.HTMLTernTypeCollector;
import tern.server.ITernServer;
import tern.server.protocol.IJSONObjectHelper;
import tern.server.protocol.type.ITernTypeCollector;

/**
* {@link ITernTypeCollector} implementation for HTML Angular type collector.
*
*
*/
public class HTMLAngularTernTypeCollector extends HTMLTernTypeCollector {

Expand All @@ -28,11 +29,11 @@ public class HTMLAngularTernTypeCollector extends HTMLTernTypeCollector {
@Override
public void setType(String type, boolean guess, String name,
String exprName, String doc, String url, String origin,
Object object, ITernServer ternServer) {
Object object, IJSONObjectHelper objectHelper) {
if (name != null) {
String module = ternServer.getText(object, "module");
String controller = ternServer.getText(object, "controller");
AngularType angularType = AngularType.get(ternServer.getText(
String module = objectHelper.getText(object, "module");
String controller = objectHelper.getText(object, "controller");
AngularType angularType = AngularType.get(objectHelper.getText(
object, "angularType"));
this.info = HTMLAngularPrinter.getAngularInfo(type, name, module,
controller, angularType, doc, origin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@
import tern.angular.modules.IDirectiveParameterCollector;
import tern.angular.modules.Restriction;
import tern.angular.protocol.TernAngularQuery;
import tern.angular.protocol.completions.AngularCompletionProposalRec;
import tern.angular.protocol.completions.TernAngularCompletionsQuery;
import tern.eclipse.ide.core.IIDETernProject;
import tern.eclipse.ide.core.TernCorePlugin;
import tern.eclipse.ide.core.resources.TernDocumentFile;
import tern.scriptpath.ITernScriptPath;
import tern.server.ITernServer;
import tern.server.protocol.IJSONObjectHelper;
import tern.server.protocol.completions.ITernCompletionCollector;
import tern.server.protocol.completions.TernCompletionProposalRec;

/**
* Completion in HTML editor for :
Expand Down Expand Up @@ -330,22 +332,20 @@ private void populateAngularProposals(
ITernCompletionCollector collector = new ITernCompletionCollector() {

@Override
public void addProposal(String name, String displayName,
String type, String doc, String url, String origin,
int start, int end, boolean isProperty,
boolean isObjectKey, Object completion,
ITernServer ternServer) {
public void addProposal(TernCompletionProposalRec proposalItem,
Object completion, IJSONObjectHelper jsonObjectHelper) {
ICompletionProposal proposal = null;
if (isModuleOrController(angularType)) {

MarkupAngularCompletionProposal markupPproposal = new MarkupAngularCompletionProposal(
name, type, doc, url, origin, start, end,
completion, ternServer, angularType,
replacementOffset);
new AngularCompletionProposalRec(proposalItem,
replacementOffset), completion,
jsonObjectHelper, angularType);

// in the case of "module", "controller" completion
// the value must replace the existing value.
String replacementString = "\"" + name + "\"";
String replacementString = "\"" + proposalItem.name
+ "\"";
int replacementLength = contentAssistRequest
.getReplacementLength();
int cursorPosition = getCursorPositionForProposedText(replacementString) - 2;
Expand All @@ -357,9 +357,12 @@ public void addProposal(String name, String displayName,
.getImage(angularType));
proposal = markupPproposal;
} else {
proposal = new JSAngularCompletionProposal(name, type,
doc, url, origin, completion, ternServer,
angularType, replacementOffset - (end - start));
proposal = new JSAngularCompletionProposal(
new AngularCompletionProposalRec(
proposalItem,
replacementOffset
- (proposalItem.end - proposalItem.start)),
completion, jsonObjectHelper, angularType);
}
contentAssistRequest.addProposal(proposal);

Expand Down

0 comments on commit c8527d7

Please sign in to comment.