Search in sources :

Example 16 with TextDocumentIdentifier

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

the class AbstractLanguageServerTest method testReferences.

protected void testReferences(final Procedure1<? super ReferenceTestConfiguration> configurator) {
    try {
        @Extension final ReferenceTestConfiguration configuration = new ReferenceTestConfiguration();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final String fileUri = this.initializeContext(configuration).getUri();
        ReferenceParams _referenceParams = new ReferenceParams();
        final Procedure1<ReferenceParams> _function = (ReferenceParams it) -> {
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
            it.setTextDocument(_textDocumentIdentifier);
            int _line = configuration.getLine();
            int _column = configuration.getColumn();
            Position _position = new Position(_line, _column);
            it.setPosition(_position);
            boolean _isIncludeDeclaration = configuration.isIncludeDeclaration();
            ReferenceContext _referenceContext = new ReferenceContext(_isIncludeDeclaration);
            it.setContext(_referenceContext);
        };
        ReferenceParams _doubleArrow = ObjectExtensions.<ReferenceParams>operator_doubleArrow(_referenceParams, _function);
        final CompletableFuture<List<? extends Location>> referencesFuture = this.languageServer.references(_doubleArrow);
        final List<? extends Location> references = referencesFuture.get();
        Procedure1<? super List<? extends Location>> _assertReferences = configuration.getAssertReferences();
        boolean _tripleNotEquals = (_assertReferences != null);
        if (_tripleNotEquals) {
            configuration.getAssertReferences().apply(references);
        } else {
            final String actualReferences = this.toExpectation(references);
            this.assertEquals(configuration.getExpectedReferences(), actualReferences);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) Extension(org.eclipse.xtext.xbase.lib.Extension) ReferenceParams(org.eclipse.lsp4j.ReferenceParams) ReferenceContext(org.eclipse.lsp4j.ReferenceContext) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) Location(org.eclipse.lsp4j.Location)

Example 17 with TextDocumentIdentifier

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

the class AbstractLanguageServerTest method testRangeFormatting.

protected void testRangeFormatting(final Procedure1<? super DocumentRangeFormattingParams> paramsConfigurator, final Procedure1<? super RangeFormattingConfiguration> configurator) {
    try {
        @Extension final RangeFormattingConfiguration configuration = new RangeFormattingConfiguration();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final FileInfo fileInfo = this.initializeContext(configuration);
        DocumentRangeFormattingParams _documentRangeFormattingParams = new DocumentRangeFormattingParams();
        final Procedure1<DocumentRangeFormattingParams> _function = (DocumentRangeFormattingParams it) -> {
            String _uri = fileInfo.getUri();
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(_uri);
            it.setTextDocument(_textDocumentIdentifier);
            it.setRange(configuration.getRange());
            if ((paramsConfigurator != null)) {
                paramsConfigurator.apply(it);
            }
        };
        DocumentRangeFormattingParams _doubleArrow = ObjectExtensions.<DocumentRangeFormattingParams>operator_doubleArrow(_documentRangeFormattingParams, _function);
        final CompletableFuture<List<? extends TextEdit>> changes = this.languageServer.rangeFormatting(_doubleArrow);
        String _contents = fileInfo.getContents();
        final Document result = new Document(Integer.valueOf(1), _contents).applyChanges(ListExtensions.<TextEdit>reverse(CollectionLiterals.<TextEdit>newArrayList(((TextEdit[]) Conversions.unwrapArray(changes.get(), TextEdit.class)))));
        this.assertEqualsStricter(configuration.getExpectedText(), result.getContents());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) DocumentRangeFormattingParams(org.eclipse.lsp4j.DocumentRangeFormattingParams) TextEdit(org.eclipse.lsp4j.TextEdit) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) Document(org.eclipse.xtext.ide.server.Document)

Example 18 with TextDocumentIdentifier

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

the class AbstractLanguageServerTest method close.

protected void close(final String fileUri) {
    DidCloseTextDocumentParams _didCloseTextDocumentParams = new DidCloseTextDocumentParams();
    final Procedure1<DidCloseTextDocumentParams> _function = (DidCloseTextDocumentParams it) -> {
        TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
        it.setTextDocument(_textDocumentIdentifier);
    };
    DidCloseTextDocumentParams _doubleArrow = ObjectExtensions.<DidCloseTextDocumentParams>operator_doubleArrow(_didCloseTextDocumentParams, _function);
    this.languageServer.didClose(_doubleArrow);
}
Also used : VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) DidCloseTextDocumentParams(org.eclipse.lsp4j.DidCloseTextDocumentParams)

Example 19 with TextDocumentIdentifier

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

the class AbstractLanguageServerTest method testCodeAction.

protected void testCodeAction(final Procedure1<? super AbstractLanguageServerTest.TestCodeActionConfiguration> configurator) {
    try {
        @Extension final AbstractLanguageServerTest.TestCodeActionConfiguration configuration = new AbstractLanguageServerTest.TestCodeActionConfiguration();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final String filePath = this.initializeContext(configuration).getUri();
        CodeActionParams _codeActionParams = new CodeActionParams();
        final Procedure1<CodeActionParams> _function = (CodeActionParams it) -> {
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(filePath);
            it.setTextDocument(_textDocumentIdentifier);
            Range _range = new Range();
            final Procedure1<Range> _function_1 = (Range it_1) -> {
                int _line = configuration.getLine();
                int _column = configuration.getColumn();
                Position _position = new Position(_line, _column);
                it_1.setStart(_position);
                it_1.setEnd(it_1.getStart());
            };
            Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1);
            it.setRange(_doubleArrow);
            CodeActionContext _codeActionContext = new CodeActionContext();
            final Procedure1<CodeActionContext> _function_2 = (CodeActionContext it_1) -> {
                it_1.setDiagnostics(this.getDiagnostics().get(filePath));
            };
            CodeActionContext _doubleArrow_1 = ObjectExtensions.<CodeActionContext>operator_doubleArrow(_codeActionContext, _function_2);
            it.setContext(_doubleArrow_1);
        };
        CodeActionParams _doubleArrow = ObjectExtensions.<CodeActionParams>operator_doubleArrow(_codeActionParams, _function);
        final CompletableFuture<List<Either<Command, CodeAction>>> result = this.languageServer.codeAction(_doubleArrow);
        if ((configuration.assertCodeActions != null)) {
            configuration.assertCodeActions.apply(result.get());
        } else {
            this.assertEquals(configuration.expectedCodeActions, this.toExpectation(result.get()));
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) CodeAction(org.eclipse.lsp4j.CodeAction) FoldingRange(org.eclipse.lsp4j.FoldingRange) Range(org.eclipse.lsp4j.Range) Endpoint(org.eclipse.lsp4j.jsonrpc.Endpoint) Extension(org.eclipse.xtext.xbase.lib.Extension) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Command(org.eclipse.lsp4j.Command) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList)

Example 20 with TextDocumentIdentifier

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

the class AbstractLanguageServerTest method testSignatureHelp.

protected void testSignatureHelp(final Procedure1<? super SignatureHelpConfiguration> configurator) {
    try {
        @Extension final SignatureHelpConfiguration configuration = new SignatureHelpConfiguration();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final String fileUri = this.initializeContext(configuration).getUri();
        SignatureHelpParams _signatureHelpParams = new SignatureHelpParams();
        final Procedure1<SignatureHelpParams> _function = (SignatureHelpParams it) -> {
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
            it.setTextDocument(_textDocumentIdentifier);
            int _line = configuration.getLine();
            int _column = configuration.getColumn();
            Position _position = new Position(_line, _column);
            it.setPosition(_position);
        };
        SignatureHelpParams _doubleArrow = ObjectExtensions.<SignatureHelpParams>operator_doubleArrow(_signatureHelpParams, _function);
        final CompletableFuture<SignatureHelp> signatureHelpFuture = this.languageServer.signatureHelp(_doubleArrow);
        final SignatureHelp signatureHelp = signatureHelpFuture.get();
        Procedure1<? super SignatureHelp> _assertSignatureHelp = configuration.getAssertSignatureHelp();
        boolean _tripleNotEquals = (_assertSignatureHelp != null);
        if (_tripleNotEquals) {
            configuration.getAssertSignatureHelp().apply(signatureHelp);
        } else {
            final String actualSignatureHelp = this.toExpectation(signatureHelp);
            this.assertEquals(configuration.getExpectedSignatureHelp().trim(), actualSignatureHelp.trim());
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) SignatureHelpParams(org.eclipse.lsp4j.SignatureHelpParams)

Aggregations

TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)172 Test (org.junit.Test)113 Position (org.eclipse.lsp4j.Position)102 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)56 Range (org.eclipse.lsp4j.Range)47 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)37 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)35 URI (java.net.URI)34 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)33 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)32 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)32 List (java.util.List)26 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)25 Location (org.eclipse.lsp4j.Location)23 AbstractQuickFixTest (org.eclipse.jdt.ls.core.internal.correction.AbstractQuickFixTest)22 Command (org.eclipse.lsp4j.Command)22 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)20 FormattingOptions (org.eclipse.lsp4j.FormattingOptions)19 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)18 CodeAction (org.eclipse.lsp4j.CodeAction)18