Search in sources :

Example 1 with CompletionParams

use of org.eclipse.lsp4j.CompletionParams 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 2 with CompletionParams

use of org.eclipse.lsp4j.CompletionParams 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 3 with CompletionParams

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

the class AbstractLanguageServerTest method testCompletion.

protected void testCompletion(final Procedure1<? super TestCompletionConfiguration> configurator) {
    try {
        @Extension final TestCompletionConfiguration configuration = new TestCompletionConfiguration();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final String filePath = this.initializeContext(configuration).getUri();
        CompletionParams _completionParams = new CompletionParams();
        final Procedure1<CompletionParams> _function = (CompletionParams it) -> {
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(filePath);
            it.setTextDocument(_textDocumentIdentifier);
            int _line = configuration.getLine();
            int _column = configuration.getColumn();
            Position _position = new Position(_line, _column);
            it.setPosition(_position);
        };
        CompletionParams _doubleArrow = ObjectExtensions.<CompletionParams>operator_doubleArrow(_completionParams, _function);
        final CompletableFuture<Either<List<CompletionItem>, CompletionList>> completionItems = this.languageServer.completion(_doubleArrow);
        final Either<List<CompletionItem>, CompletionList> result = completionItems.get();
        List<CompletionItem> _xifexpression = null;
        boolean _isLeft = result.isLeft();
        if (_isLeft) {
            _xifexpression = result.getLeft();
        } else {
            _xifexpression = result.getRight().getItems();
        }
        final List<CompletionItem> items = _xifexpression;
        final Function1<CompletionItem, String> _function_1 = (CompletionItem it) -> {
            return it.getSortText();
        };
        Assert.assertEquals(items, IterableExtensions.<CompletionItem>toList(IterableExtensions.<CompletionItem, String>sortBy(items, _function_1)));
        Procedure1<? super CompletionList> _assertCompletionList = configuration.getAssertCompletionList();
        boolean _tripleNotEquals = (_assertCompletionList != null);
        if (_tripleNotEquals) {
            configuration.getAssertCompletionList().apply(result.getRight());
        } else {
            final String actualCompletionItems = this.toExpectation(items);
            this.assertEquals(configuration.getExpectedCompletionItems(), actualCompletionItems);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) Extension(org.eclipse.xtext.xbase.lib.Extension) CompletionParams(org.eclipse.lsp4j.CompletionParams) CompletionItem(org.eclipse.lsp4j.CompletionItem) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList)

Aggregations

List (java.util.List)3 CompletionItem (org.eclipse.lsp4j.CompletionItem)3 CompletionList (org.eclipse.lsp4j.CompletionList)3 CompletionParams (org.eclipse.lsp4j.CompletionParams)3 Position (org.eclipse.lsp4j.Position)3 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)3 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)3 Objects (com.google.common.base.Objects)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 LinkedListMultimap (com.google.common.collect.LinkedListMultimap)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 Inject (com.google.inject.Inject)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1