Search in sources :

Example 26 with CompletionList

use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.

the class CompletionHandlerTest method testCompletion_import_type.

@Test
public void testCompletion_import_type() throws JavaModelException {
    ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "import java.sq \n" + "public class Foo {\n" + "	void foo() {\n" + "   java.util.Ma\n" + "	}\n" + "}\n");
    int[] loc = findCompletionLocation(unit, "java.util.Ma");
    CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
    assertNotNull(list);
    assertEquals(1, list.getItems().size());
    CompletionItem item = list.getItems().get(0);
    assertEquals(CompletionItemKind.Class, item.getKind());
    assertEquals("Map", item.getInsertText());
    assertNull(item.getAdditionalTextEdits());
    assertNull(item.getTextEdit());
    CompletionItem resolvedItem = server.resolveCompletionItem(item).join();
    assertNotNull(resolvedItem.getTextEdit());
    assertTextEdit(3, 3, 15, "java.util.Map", resolvedItem.getTextEdit());
// Not checking the range end character
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompletionList(org.eclipse.lsp4j.CompletionList) CompletionItem(org.eclipse.lsp4j.CompletionItem) Test(org.junit.Test)

Example 27 with CompletionList

use of org.eclipse.lsp4j.CompletionList in project xtext-core by eclipse.

the class UnknownProjectConfigTest method checkCompletion.

protected void checkCompletion(String uri) throws Exception {
    CompletableFuture<Either<List<CompletionItem>, CompletionList>> completionItems = languageServer.completion(new CompletionParams(new TextDocumentIdentifier(uri), new Position(0, 10)));
    Either<List<CompletionItem>, CompletionList> result = completionItems.get();
    List<CompletionItem> items = null;
    if (result.isLeft()) {
        items = result.getLeft();
    } else {
        items = result.getRight().getItems();
    }
    String actualCompletionItems = Strings.toUnixLineSeparator(toExpectation(items));
    String expectedCompletionItems = "Foo (TypeDeclaration) -> Foo [[0, 10] .. [0, 10]]\n" + "boolean -> boolean [[0, 10] .. [0, 10]]\n" + "int -> int [[0, 10] .. [0, 10]]\n" + "op -> op [[0, 10] .. [0, 10]]\n" + "string -> string [[0, 10] .. [0, 10]]\n" + "void -> void [[0, 10] .. [0, 10]]\n" + "} -> } [[0, 10] .. [0, 10]]\n" + "{ -> { [[0, 9] .. [0, 10]]\n" + "   + } [[0, 11] .. [0, 11]]\n";
    assertEquals(expectedCompletionItems, actualCompletionItems);
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CompletionParams(org.eclipse.lsp4j.CompletionParams) CompletionItem(org.eclipse.lsp4j.CompletionItem) Position(org.eclipse.lsp4j.Position) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList)

Example 28 with CompletionList

use of org.eclipse.lsp4j.CompletionList in project xtext-core by eclipse.

the class LanguageServerImpl method completion.

/**
 * Compute the completion items.
 */
protected Either<List<CompletionItem>, CompletionList> completion(CancelIndicator originalCancelIndicator, CompletionParams params) {
    URI uri = getURI(params);
    ContentAssistService contentAssistService = getService(uri, ContentAssistService.class);
    if (contentAssistService == null) {
        return Either.forRight(new CompletionList());
    }
    BufferedCancelIndicator cancelIndicator = new BufferedCancelIndicator(originalCancelIndicator);
    return Either.forRight(workspaceManager.doRead(uri, (doc, res) -> contentAssistService.createCompletionList(doc, res, params, cancelIndicator)));
}
Also used : Arrays(java.util.Arrays) CodeLensOptions(org.eclipse.lsp4j.CodeLensOptions) DidChangeTextDocumentParams(org.eclipse.lsp4j.DidChangeTextDocumentParams) WorkspaceSymbolParams(org.eclipse.lsp4j.WorkspaceSymbolParams) LanguageServer(org.eclipse.lsp4j.services.LanguageServer) DidSaveTextDocumentParams(org.eclipse.lsp4j.DidSaveTextDocumentParams) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) Map(java.util.Map) RenameParams(org.eclipse.lsp4j.RenameParams) Endpoint(org.eclipse.lsp4j.jsonrpc.Endpoint) IRenameService2(org.eclipse.xtext.ide.server.rename.IRenameService2) TextDocumentService(org.eclipse.lsp4j.services.TextDocumentService) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) SignatureHelpOptions(org.eclipse.lsp4j.SignatureHelpOptions) ISignatureHelpService(org.eclipse.xtext.ide.server.signatureHelp.ISignatureHelpService) Set(java.util.Set) DocumentOnTypeFormattingParams(org.eclipse.lsp4j.DocumentOnTypeFormattingParams) WorkspaceService(org.eclipse.lsp4j.services.WorkspaceService) LocationLink(org.eclipse.lsp4j.LocationLink) FormattingService(org.eclipse.xtext.ide.server.formatting.FormattingService) ExecuteCommandOptions(org.eclipse.lsp4j.ExecuteCommandOptions) ResourceDescriptionsProvider(org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider) JsonRpcMethod(org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethod) WorkspaceFolder(org.eclipse.lsp4j.WorkspaceFolder) FoldingRange(org.eclipse.lsp4j.FoldingRange) ContentAssistService(org.eclipse.xtext.ide.server.contentassist.ContentAssistService) Pair(org.eclipse.xtext.xbase.lib.Pair) LanguageClientAware(org.eclipse.lsp4j.services.LanguageClientAware) URI(org.eclipse.emf.common.util.URI) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) HierarchicalDocumentSymbolService(org.eclipse.xtext.ide.server.symbol.HierarchicalDocumentSymbolService) HoverParams(org.eclipse.lsp4j.HoverParams) Diagnostic(org.eclipse.lsp4j.Diagnostic) Supplier(java.util.function.Supplier) DocumentRangeFormattingParams(org.eclipse.lsp4j.DocumentRangeFormattingParams) Hover(org.eclipse.lsp4j.Hover) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ArrayList(java.util.ArrayList) IHoverService(org.eclipse.xtext.ide.server.hover.IHoverService) LinkedHashMap(java.util.LinkedHashMap) FileChangeType(org.eclipse.lsp4j.FileChangeType) TextDocumentItem(org.eclipse.lsp4j.TextDocumentItem) TextEdit(org.eclipse.lsp4j.TextEdit) Lists(com.google.common.collect.Lists) DocumentFormattingParams(org.eclipse.lsp4j.DocumentFormattingParams) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) InitializeResult(org.eclipse.lsp4j.InitializeResult) DocumentHighlight(org.eclipse.lsp4j.DocumentHighlight) ServiceEndpoints(org.eclipse.lsp4j.jsonrpc.services.ServiceEndpoints) DidChangeWatchedFilesParams(org.eclipse.lsp4j.DidChangeWatchedFilesParams) DocumentHighlightParams(org.eclipse.lsp4j.DocumentHighlightParams) PrepareRenameResult(org.eclipse.lsp4j.PrepareRenameResult) ICodeActionService2(org.eclipse.xtext.ide.server.codeActions.ICodeActionService2) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) TreeMap(java.util.TreeMap) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) Issue(org.eclipse.xtext.validation.Issue) RenameOptions(org.eclipse.lsp4j.RenameOptions) DocumentSymbolService(org.eclipse.xtext.ide.server.symbol.DocumentSymbolService) CompletionOptions(org.eclipse.lsp4j.CompletionOptions) IBuildListener(org.eclipse.xtext.ide.server.ILanguageServerAccess.IBuildListener) SignatureHelpParams(org.eclipse.lsp4j.SignatureHelpParams) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) BufferedCancelIndicator(org.eclipse.xtext.util.BufferedCancelIndicator) LanguageClient(org.eclipse.lsp4j.services.LanguageClient) Inject(com.google.inject.Inject) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) ICodeLensService(org.eclipse.xtext.ide.server.codelens.ICodeLensService) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) FoldingRangeRequestParams(org.eclipse.lsp4j.FoldingRangeRequestParams) Logger(org.apache.log4j.Logger) CodeLens(org.eclipse.lsp4j.CodeLens) DidChangeWorkspaceFoldersParams(org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams) IReferenceFinder(org.eclipse.xtext.findReferences.IReferenceFinder) Location(org.eclipse.lsp4j.Location) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) DidCloseTextDocumentParams(org.eclipse.lsp4j.DidCloseTextDocumentParams) Objects(com.google.common.base.Objects) CodeAction(org.eclipse.lsp4j.CodeAction) LinkedListMultimap(com.google.common.collect.LinkedListMultimap) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) IDocumentSymbolService(org.eclipse.xtext.ide.server.symbol.IDocumentSymbolService) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) ICodeLensResolver(org.eclipse.xtext.ide.server.codelens.ICodeLensResolver) FoldingRangeService(org.eclipse.xtext.ide.server.folding.FoldingRangeService) DefinitionParams(org.eclipse.lsp4j.DefinitionParams) ServerCapabilities(org.eclipse.lsp4j.ServerCapabilities) CompletionItem(org.eclipse.lsp4j.CompletionItem) RenameCapabilities(org.eclipse.lsp4j.RenameCapabilities) List(java.util.List) Command(org.eclipse.lsp4j.Command) IDocumentHighlightService(org.eclipse.xtext.ide.server.occurrences.IDocumentHighlightService) WorkspaceSymbolService(org.eclipse.xtext.ide.server.symbol.WorkspaceSymbolService) DidOpenTextDocumentParams(org.eclipse.lsp4j.DidOpenTextDocumentParams) InitializeParams(org.eclipse.lsp4j.InitializeParams) WorkspaceFoldersOptions(org.eclipse.lsp4j.WorkspaceFoldersOptions) Buildable(org.eclipse.xtext.ide.server.BuildManager.Buildable) CompletionParams(org.eclipse.lsp4j.CompletionParams) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams) CompletableFuture(java.util.concurrent.CompletableFuture) Range(org.eclipse.lsp4j.Range) DocumentSymbolCapabilities(org.eclipse.lsp4j.DocumentSymbolCapabilities) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) ExecuteCommandCapabilities(org.eclipse.lsp4j.ExecuteCommandCapabilities) ImmutableList(com.google.common.collect.ImmutableList) ExecuteCommandParams(org.eclipse.lsp4j.ExecuteCommandParams) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) Position(org.eclipse.lsp4j.Position) CodeLensParams(org.eclipse.lsp4j.CodeLensParams) CompletionList(org.eclipse.lsp4j.CompletionList) DidChangeConfigurationParams(org.eclipse.lsp4j.DidChangeConfigurationParams) TextDocumentSyncKind(org.eclipse.lsp4j.TextDocumentSyncKind) InitializedParams(org.eclipse.lsp4j.InitializedParams) Severity(org.eclipse.xtext.diagnostics.Severity) FoldingRangeCapabilities(org.eclipse.lsp4j.FoldingRangeCapabilities) WorkspaceServerCapabilities(org.eclipse.lsp4j.WorkspaceServerCapabilities) ExecutableCommandRegistry(org.eclipse.xtext.ide.server.commands.ExecutableCommandRegistry) JsonRpcMethodProvider(org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethodProvider) RequestManager(org.eclipse.xtext.ide.server.concurrent.RequestManager) WorkspaceResourceAccess(org.eclipse.xtext.ide.server.findReferences.WorkspaceResourceAccess) Collections(java.util.Collections) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) ReferenceParams(org.eclipse.lsp4j.ReferenceParams) CompletionList(org.eclipse.lsp4j.CompletionList) ContentAssistService(org.eclipse.xtext.ide.server.contentassist.ContentAssistService) BufferedCancelIndicator(org.eclipse.xtext.util.BufferedCancelIndicator) URI(org.eclipse.emf.common.util.URI)

Example 29 with CompletionList

use of org.eclipse.lsp4j.CompletionList in project xtext-core by eclipse.

the class ContentAssistService method createCompletionList.

public CompletionList createCompletionList(Document document, XtextResource resource, CompletionParams params, CancelIndicator cancelIndicator) {
    try {
        CompletionList result = new CompletionList();
        result.setIsIncomplete(true);
        IdeContentProposalAcceptor acceptor = proposalAcceptorProvider.get();
        int caretOffset = document.getOffSet(params.getPosition());
        Position caretPosition = params.getPosition();
        TextRegion position = new TextRegion(caretOffset, 0);
        try {
            createProposals(document.getContents(), position, caretOffset, resource, acceptor);
        } catch (Throwable t) {
            if (!operationCanceledManager.isOperationCanceledException(t)) {
                throw t;
            }
        }
        int idx = 0;
        for (ContentAssistEntry it : acceptor.getEntries()) {
            CompletionItem item = toCompletionItem(it, caretOffset, caretPosition, document);
            item.setSortText(Strings.padStart(Integer.toString(idx), 5, '0'));
            result.getItems().add(item);
            idx++;
        }
        return result;
    } catch (Throwable e) {
        throw Exceptions.sneakyThrow(e);
    }
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) ContentAssistEntry(org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry) TextRegion(org.eclipse.xtext.util.TextRegion) Position(org.eclipse.lsp4j.Position) CompletionItem(org.eclipse.lsp4j.CompletionItem) IdeContentProposalAcceptor(org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalAcceptor) IIdeContentProposalAcceptor(org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor)

Example 30 with CompletionList

use of org.eclipse.lsp4j.CompletionList in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method actionScriptCompletionWithNode.

private CompletableFuture<CompletionList> actionScriptCompletionWithNode(TextDocumentPositionParams position, IASNode offsetNode) {
    CompletionList result = new CompletionList();
    result.setIsIncomplete(false);
    result.setItems(new ArrayList<>());
    if (offsetNode == null) {
        //we couldn't find a node at the specified location
        autoCompletePackageBlock(result);
        return CompletableFuture.completedFuture(result);
    }
    IASNode parentNode = offsetNode.getParent();
    IASNode nodeAtPreviousOffset = null;
    if (parentNode != null) {
        nodeAtPreviousOffset = parentNode.getContainingNode(currentOffset - 1);
    }
    if (!isActionScriptCompletionAllowedInNode(position, offsetNode)) {
        //if we're inside a node that shouldn't have completion!
        return CompletableFuture.completedFuture(new CompletionList());
    }
    //variable types
    if (offsetNode instanceof IVariableNode) {
        IVariableNode variableNode = (IVariableNode) offsetNode;
        IExpressionNode nameExpression = variableNode.getNameExpressionNode();
        IExpressionNode typeNode = variableNode.getVariableTypeNode();
        int line = position.getPosition().getLine();
        int column = position.getPosition().getCharacter();
        if (line >= nameExpression.getEndLine() && line <= typeNode.getLine()) {
            if ((line != nameExpression.getEndLine() && line != typeNode.getLine()) || (line == nameExpression.getEndLine() && column > nameExpression.getEndColumn()) || (line == typeNode.getLine() && column <= typeNode.getColumn())) {
                autoCompleteTypes(offsetNode, result);
            }
            return CompletableFuture.completedFuture(result);
        }
    }
    if (parentNode != null && parentNode instanceof IVariableNode) {
        IVariableNode variableNode = (IVariableNode) parentNode;
        if (offsetNode == variableNode.getVariableTypeNode()) {
            autoCompleteTypes(parentNode, result);
            return CompletableFuture.completedFuture(result);
        }
    }
    //function return types
    if (offsetNode instanceof IFunctionNode) {
        IFunctionNode functionNode = (IFunctionNode) offsetNode;
        IContainerNode parameters = functionNode.getParametersContainerNode();
        IExpressionNode typeNode = functionNode.getReturnTypeNode();
        if (typeNode != null) {
            int line = position.getPosition().getLine();
            int column = position.getPosition().getCharacter();
            if (line >= parameters.getEndLine() && column > parameters.getEndColumn() && line <= typeNode.getLine() && column <= typeNode.getColumn()) {
                autoCompleteTypes(offsetNode, result);
                return CompletableFuture.completedFuture(result);
            }
        }
    }
    if (parentNode != null && parentNode instanceof IFunctionNode) {
        IFunctionNode functionNode = (IFunctionNode) parentNode;
        if (offsetNode == functionNode.getReturnTypeNode()) {
            autoCompleteTypes(parentNode, result);
            return CompletableFuture.completedFuture(result);
        }
    }
    //new keyword types
    if (parentNode != null && parentNode instanceof IFunctionCallNode) {
        IFunctionCallNode functionCallNode = (IFunctionCallNode) parentNode;
        if (functionCallNode.getNameNode() == offsetNode && functionCallNode.isNewExpression()) {
            autoCompleteTypes(parentNode, result);
            return CompletableFuture.completedFuture(result);
        }
    }
    if (nodeAtPreviousOffset != null && nodeAtPreviousOffset instanceof IKeywordNode && nodeAtPreviousOffset.getNodeID() == ASTNodeID.KeywordNewID) {
        autoCompleteTypes(nodeAtPreviousOffset, result);
        return CompletableFuture.completedFuture(result);
    }
    //as and is keyword types
    if (parentNode != null && parentNode instanceof IBinaryOperatorNode && (parentNode.getNodeID() == ASTNodeID.Op_AsID || parentNode.getNodeID() == ASTNodeID.Op_IsID)) {
        IBinaryOperatorNode binaryOperatorNode = (IBinaryOperatorNode) parentNode;
        if (binaryOperatorNode.getRightOperandNode() == offsetNode) {
            autoCompleteTypes(parentNode, result);
            return CompletableFuture.completedFuture(result);
        }
    }
    if (nodeAtPreviousOffset != null && nodeAtPreviousOffset instanceof IBinaryOperatorNode && (nodeAtPreviousOffset.getNodeID() == ASTNodeID.Op_AsID || nodeAtPreviousOffset.getNodeID() == ASTNodeID.Op_IsID)) {
        autoCompleteTypes(nodeAtPreviousOffset, result);
        return CompletableFuture.completedFuture(result);
    }
    //class extends keyword
    if (offsetNode instanceof IClassNode && nodeAtPreviousOffset != null && nodeAtPreviousOffset instanceof IKeywordNode && nodeAtPreviousOffset.getNodeID() == ASTNodeID.KeywordExtendsID) {
        autoCompleteTypes(offsetNode, result);
        return CompletableFuture.completedFuture(result);
    }
    //class implements keyword
    if (offsetNode instanceof IClassNode && nodeAtPreviousOffset != null && nodeAtPreviousOffset instanceof IKeywordNode && nodeAtPreviousOffset.getNodeID() == ASTNodeID.KeywordImplementsID) {
        autoCompleteTypes(offsetNode, result);
        return CompletableFuture.completedFuture(result);
    }
    //interface extends keyword
    if (offsetNode instanceof IInterfaceNode && nodeAtPreviousOffset != null && nodeAtPreviousOffset instanceof IKeywordNode && nodeAtPreviousOffset.getNodeID() == ASTNodeID.KeywordExtendsID) {
        autoCompleteTypes(offsetNode, result);
        return CompletableFuture.completedFuture(result);
    }
    //package (must be before member access)
    if (offsetNode instanceof IPackageNode) {
        IPackageNode packageNode = (IPackageNode) offsetNode;
        autoCompletePackageName(packageNode.getPackageName(), result);
        return CompletableFuture.completedFuture(result);
    }
    if (parentNode != null && parentNode instanceof FullNameNode) {
        IASNode gpNode = parentNode.getParent();
        if (gpNode != null && gpNode instanceof IPackageNode) {
            IPackageNode packageNode = (IPackageNode) gpNode;
            autoCompletePackageName(packageNode.getPackageName(), result);
        }
    }
    if (parentNode != null && parentNode instanceof IPackageNode) {
        //we'll get here if the last character in the package name is .
        IPackageNode packageNode = (IPackageNode) parentNode;
        IExpressionNode nameNode = packageNode.getNameExpressionNode();
        if (offsetNode == nameNode) {
            autoCompletePackageName(packageNode.getPackageName(), result);
            return CompletableFuture.completedFuture(result);
        }
    }
    //import (must be before member access)
    if (parentNode != null && parentNode instanceof IImportNode) {
        IImportNode importNode = (IImportNode) parentNode;
        IExpressionNode nameNode = importNode.getImportNameNode();
        if (offsetNode == nameNode) {
            String importName = importNode.getImportName();
            importName = importName.substring(0, position.getPosition().getCharacter() - nameNode.getColumn());
            autoCompleteImport(importName, result);
            return CompletableFuture.completedFuture(result);
        }
    }
    if (parentNode != null && parentNode instanceof FullNameNode) {
        IASNode gpNode = parentNode.getParent();
        if (gpNode != null && gpNode instanceof IImportNode) {
            IImportNode importNode = (IImportNode) gpNode;
            IExpressionNode nameNode = importNode.getImportNameNode();
            if (parentNode == nameNode) {
                String importName = importNode.getImportName();
                importName = importName.substring(0, position.getPosition().getCharacter() - nameNode.getColumn());
                autoCompleteImport(importName, result);
                return CompletableFuture.completedFuture(result);
            }
        }
    }
    if (nodeAtPreviousOffset != null && nodeAtPreviousOffset instanceof IImportNode) {
        autoCompleteImport("", result);
        return CompletableFuture.completedFuture(result);
    }
    //member access
    if (offsetNode instanceof IMemberAccessExpressionNode) {
        IMemberAccessExpressionNode memberAccessNode = (IMemberAccessExpressionNode) offsetNode;
        IExpressionNode leftOperand = memberAccessNode.getLeftOperandNode();
        IExpressionNode rightOperand = memberAccessNode.getRightOperandNode();
        int line = position.getPosition().getLine();
        int column = position.getPosition().getCharacter();
        if (line >= leftOperand.getEndLine() && line <= rightOperand.getLine()) {
            if ((line != leftOperand.getEndLine() && line != rightOperand.getLine()) || (line == leftOperand.getEndLine() && column > leftOperand.getEndColumn()) || (line == rightOperand.getLine() && column <= rightOperand.getColumn())) {
                autoCompleteMemberAccess(memberAccessNode, result);
                return CompletableFuture.completedFuture(result);
            }
        }
    }
    if (parentNode != null && parentNode instanceof IMemberAccessExpressionNode) {
        IMemberAccessExpressionNode memberAccessNode = (IMemberAccessExpressionNode) parentNode;
        //you would expect that the offset node could only be the right
        //operand, but it's actually possible for it to be the left operand,
        //even if the . has been typed! only sometimes, though.
        boolean isValidLeft = true;
        if (offsetNode == memberAccessNode.getLeftOperandNode() && memberAccessNode.getRightOperandNode() instanceof IIdentifierNode) {
            //if the left and right operands both exist, then this is not
            //member access and we should skip ahead
            isValidLeft = false;
        }
        if (offsetNode == memberAccessNode.getRightOperandNode() || isValidLeft) {
            autoCompleteMemberAccess(memberAccessNode, result);
            return CompletableFuture.completedFuture(result);
        }
    }
    if (nodeAtPreviousOffset != null && nodeAtPreviousOffset instanceof IMemberAccessExpressionNode) {
        //depending on the left operand, if a . is typed, the member access
        //may end up being the previous node instead of the parent or offset
        //node, so check if the right operand is empty
        IMemberAccessExpressionNode memberAccessNode = (IMemberAccessExpressionNode) nodeAtPreviousOffset;
        IExpressionNode rightOperandNode = memberAccessNode.getRightOperandNode();
        if (rightOperandNode instanceof IIdentifierNode) {
            IIdentifierNode identifierNode = (IIdentifierNode) rightOperandNode;
            if (identifierNode.getName().equals("")) {
                autoCompleteMemberAccess(memberAccessNode, result);
                return CompletableFuture.completedFuture(result);
            }
        }
    }
    //local scope
    do {
        //nodes to check
        if (offsetNode instanceof IScopedNode) {
            IScopedNode scopedNode = (IScopedNode) offsetNode;
            //include all members and local things that are in scope
            autoCompleteScope(scopedNode, false, result);
            //include all public definitions
            IASScope scope = scopedNode.getScope();
            IDefinition definitionToSkip = scope.getDefinition();
            autoCompleteDefinitions(result, false, false, null, definitionToSkip);
            return CompletableFuture.completedFuture(result);
        }
        offsetNode = offsetNode.getParent();
    } while (offsetNode != null);
    return CompletableFuture.completedFuture(result);
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) IScopedNode(org.apache.flex.compiler.tree.as.IScopedNode) IPackageNode(org.apache.flex.compiler.tree.as.IPackageNode) IImportNode(org.apache.flex.compiler.tree.as.IImportNode) IIdentifierNode(org.apache.flex.compiler.tree.as.IIdentifierNode) IKeywordNode(org.apache.flex.compiler.tree.as.IKeywordNode) IVariableNode(org.apache.flex.compiler.tree.as.IVariableNode) IFunctionNode(org.apache.flex.compiler.tree.as.IFunctionNode) IContainerNode(org.apache.flex.compiler.tree.as.IContainerNode) IFunctionCallNode(org.apache.flex.compiler.tree.as.IFunctionCallNode) IInterfaceNode(org.apache.flex.compiler.tree.as.IInterfaceNode) IDefinition(org.apache.flex.compiler.definitions.IDefinition) IASScope(org.apache.flex.compiler.scopes.IASScope) IASNode(org.apache.flex.compiler.tree.as.IASNode) FullNameNode(org.apache.flex.compiler.internal.tree.as.FullNameNode) IClassNode(org.apache.flex.compiler.tree.as.IClassNode) IExpressionNode(org.apache.flex.compiler.tree.as.IExpressionNode) IBinaryOperatorNode(org.apache.flex.compiler.tree.as.IBinaryOperatorNode) IMemberAccessExpressionNode(org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode)

Aggregations

CompletionList (org.eclipse.lsp4j.CompletionList)44 CompletionItem (org.eclipse.lsp4j.CompletionItem)36 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)33 Test (org.junit.Test)31 ArrayList (java.util.ArrayList)11 TextEdit (org.eclipse.lsp4j.TextEdit)11 List (java.util.List)10 Lsp4jAssertions.assertTextEdit (org.eclipse.jdt.ls.core.internal.Lsp4jAssertions.assertTextEdit)10 Range (org.eclipse.lsp4j.Range)9 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)7 Map (java.util.Map)6 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)6 Collections (java.util.Collections)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 Path (org.eclipse.core.runtime.Path)5 IJavaProject (org.eclipse.jdt.core.IJavaProject)5 JavaModelException (org.eclipse.jdt.core.JavaModelException)5 ClientPreferences (org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences)5 DidChangeTextDocumentParams (org.eclipse.lsp4j.DidChangeTextDocumentParams)5 Comparator (java.util.Comparator)4