use of org.eclipse.lsp4j.CompletionList in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method completion.
/**
* Returns a list of all items to display in the completion list at a
* specific position in a document. Called automatically by VSCode as the
* user types, and may not necessarily be triggered only on "." or ":".
*/
@Override
public CompletableFuture<CompletionList> completion(TextDocumentPositionParams position) {
String textDocumentUri = position.getTextDocument().getUri();
if (!textDocumentUri.endsWith(AS_EXTENSION) && !textDocumentUri.endsWith(MXML_EXTENSION)) {
CompletionList result = new CompletionList();
result.setIsIncomplete(false);
result.setItems(new ArrayList<>());
return CompletableFuture.completedFuture(result);
}
IMXMLTagData offsetTag = getOffsetMXMLTag(position);
if (offsetTag != null) {
IASNode embeddedNode = getEmbeddedActionScriptNodeInMXMLTag(offsetTag, currentOffset, position);
if (embeddedNode != null) {
return actionScriptCompletionWithNode(position, embeddedNode);
}
//so that's why we call isMXMLTagValidForCompletion()
if (isMXMLTagValidForCompletion(offsetTag)) {
return mxmlCompletion(position, offsetTag);
}
}
if (offsetTag == null && position.getTextDocument().getUri().endsWith(MXML_EXTENSION)) {
//it's possible for the offset tag to be null in an MXML file, but
//we don't want to trigger ActionScript completion.
//for some reason, the offset tag will be null if completion is
//triggered at the asterisk:
//<fx:Declarations>*
CompletionList result = new CompletionList();
result.setIsIncomplete(false);
result.setItems(new ArrayList<>());
return CompletableFuture.completedFuture(result);
}
return actionScriptCompletion(position);
}
use of org.eclipse.lsp4j.CompletionList in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method mxmlCompletion.
private CompletableFuture<CompletionList> mxmlCompletion(TextDocumentPositionParams position, IMXMLTagData offsetTag) {
CompletionList result = new CompletionList();
result.setIsIncomplete(false);
result.setItems(new ArrayList<>());
if (isInXMLComment(position)) {
//if we're inside a comment, no completion!
return CompletableFuture.completedFuture(result);
}
IMXMLTagData parentTag = offsetTag.getParentTag();
//for some reason, the attributes list includes the >, but that's not
//what we want here, so check if currentOffset isn't the end of the tag!
boolean isAttribute = offsetTag.isOffsetInAttributeList(currentOffset) && currentOffset < offsetTag.getAbsoluteEnd();
if (isAttribute && offsetTag.isCloseTag()) {
return CompletableFuture.completedFuture(result);
}
//inside <fx:Declarations>
if (isDeclarationsTag(offsetTag)) {
if (!isAttribute) {
autoCompleteTypesForMXML(result);
}
return CompletableFuture.completedFuture(result);
}
IDefinition offsetDefinition = getDefinitionForMXMLTag(offsetTag);
if (offsetDefinition == null) {
IDefinition parentDefinition = null;
if (parentTag != null) {
parentDefinition = getDefinitionForMXMLTag(parentTag);
}
if (parentDefinition != null) {
if (parentDefinition instanceof IClassDefinition) {
IClassDefinition classDefinition = (IClassDefinition) parentDefinition;
String offsetPrefix = offsetTag.getPrefix();
if (offsetPrefix.length() == 0 || parentTag.getPrefix().equals(offsetPrefix)) {
//only add members if the prefix is the same as the
//parent tag. members can't have different prefixes.
//also allow members when we don't have a prefix.
addMembersForMXMLTypeToAutoComplete(classDefinition, parentTag, offsetPrefix.length() == 0, result);
}
if (!isAttribute) {
//tags can't appear in attributes, so skip types
String defaultPropertyName = classDefinition.getDefaultPropertyName(currentProject);
if (defaultPropertyName != null) {
//only add types if the class defines [DefaultProperty]
//metadata
autoCompleteTypesForMXMLFromExistingTag(result, offsetTag);
}
}
} else {
//the parent is something like a property, so matching the
//prefix is not required
autoCompleteTypesForMXMLFromExistingTag(result, offsetTag);
}
return CompletableFuture.completedFuture(result);
} else if (isDeclarationsTag(parentTag)) {
autoCompleteTypesForMXMLFromExistingTag(result, offsetTag);
return CompletableFuture.completedFuture(result);
}
return CompletableFuture.completedFuture(result);
}
if (offsetDefinition instanceof IClassDefinition) {
IMXMLTagAttributeData attribute = getMXMLTagAttributeWithValueAtOffset(offsetTag, currentOffset);
if (attribute != null) {
return mxmlAttributeCompletion(offsetTag, result);
}
IClassDefinition classDefinition = (IClassDefinition) offsetDefinition;
addMembersForMXMLTypeToAutoComplete(classDefinition, offsetTag, !isAttribute, result);
String defaultPropertyName = classDefinition.getDefaultPropertyName(currentProject);
if (defaultPropertyName != null && !isAttribute) {
//if [DefaultProperty] is set, then we can instantiate
//types as child elements
//but we don't want to do that when in an attribute
autoCompleteTypesForMXML(result);
}
return CompletableFuture.completedFuture(result);
}
if (offsetDefinition instanceof IVariableDefinition || offsetDefinition instanceof IEventDefinition || offsetDefinition instanceof IStyleDefinition) {
if (!isAttribute) {
autoCompleteTypesForMXML(result);
}
return CompletableFuture.completedFuture(result);
}
System.err.println("Unknown definition for MXML completion: " + offsetDefinition.getClass());
return CompletableFuture.completedFuture(result);
}
use of org.eclipse.lsp4j.CompletionList in project xtext-core by eclipse.
the class LanguageServerImpl method completion.
protected Either<List<CompletionItem>, CompletionList> completion(final CancelIndicator origialCancelIndicator, final TextDocumentPositionParams params) {
final LanguageServerImpl.BufferedCancelIndicator cancelIndicator = new LanguageServerImpl.BufferedCancelIndicator(origialCancelIndicator);
final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri());
final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri);
ContentAssistService _get = null;
if (resourceServiceProvider != null) {
_get = resourceServiceProvider.<ContentAssistService>get(ContentAssistService.class);
}
final ContentAssistService contentAssistService = _get;
if ((contentAssistService == null)) {
CompletionList _completionList = new CompletionList();
return Either.<List<CompletionItem>, CompletionList>forRight(_completionList);
}
final Function2<Document, XtextResource, CompletionList> _function = (Document document, XtextResource resource) -> {
return contentAssistService.createCompletionList(document, resource, params, cancelIndicator);
};
final CompletionList completionList = this.workspaceManager.<CompletionList>doRead(uri, _function);
return Either.<List<CompletionItem>, CompletionList>forRight(completionList);
}
use of org.eclipse.lsp4j.CompletionList in project xtext-core by eclipse.
the class ContentAssistService method createCompletionList.
public CompletionList createCompletionList(final Document document, final XtextResource resource, final TextDocumentPositionParams params, final CancelIndicator cancelIndicator) {
try {
final CompletionList result = new CompletionList();
result.setIsIncomplete(true);
final IdeContentProposalAcceptor acceptor = this.proposalAcceptorProvider.get();
final int caretOffset = document.getOffSet(params.getPosition());
final Position caretPosition = params.getPosition();
final TextRegion position = new TextRegion(caretOffset, 0);
try {
this.createProposals(document.getContents(), position, caretOffset, resource, acceptor);
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable t = (Throwable) _t;
boolean _isOperationCanceledException = this.operationCanceledManager.isOperationCanceledException(t);
boolean _not = (!_isOperationCanceledException);
if (_not) {
throw t;
}
} else {
throw Exceptions.sneakyThrow(_t);
}
}
final Procedure2<ContentAssistEntry, Integer> _function = (ContentAssistEntry it, Integer idx) -> {
final CompletionItem item = this.toCompletionItem(it, caretOffset, caretPosition, document);
item.setSortText(Strings.padStart(Integer.toString((idx).intValue()), 5, '0'));
List<CompletionItem> _items = result.getItems();
_items.add(item);
};
IterableExtensions.<ContentAssistEntry>forEach(acceptor.getEntries(), _function);
return result;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandler method completion.
Either<List<CompletionItem>, CompletionList> completion(TextDocumentPositionParams position, IProgressMonitor monitor) {
List<CompletionItem> completionItems = null;
try {
ICompilationUnit unit = JDTUtils.resolveCompilationUnit(position.getTextDocument().getUri());
completionItems = this.computeContentAssist(unit, position.getPosition().getLine(), position.getPosition().getCharacter(), monitor);
} catch (OperationCanceledException ignorable) {
// No need to pollute logs when query is cancelled
monitor.setCanceled(true);
} catch (Exception e) {
JavaLanguageServerPlugin.logException("Problem with codeComplete for " + position.getTextDocument().getUri(), e);
monitor.setCanceled(true);
}
CompletionList $ = new CompletionList();
if (monitor.isCanceled()) {
$.setIsIncomplete(true);
completionItems = null;
JavaLanguageServerPlugin.logInfo("Completion request cancelled");
} else {
JavaLanguageServerPlugin.logInfo("Completion request completed");
}
$.setItems(completionItems == null ? Collections.emptyList() : completionItems);
return Either.forRight($);
}
Aggregations