Search in sources :

Example 16 with Position

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

the class PositionComparatorTest method withoutNull.

@Test
public void withoutNull() {
    Position _position = new Position(2, 2);
    Position _position_1 = new Position(2, 1);
    Position _position_2 = new Position(1, 2);
    Position _position_3 = new Position(1, 1);
    final List<? extends Position> input = this.sort(CollectionLiterals.<Position>newArrayList(_position, _position_1, _position_2, _position_3));
    Assert.assertEquals(1, input.get(0).getLine());
    Assert.assertEquals(1, input.get(0).getCharacter());
    Assert.assertEquals(1, input.get(1).getLine());
    Assert.assertEquals(2, input.get(1).getCharacter());
    Assert.assertEquals(2, input.get(2).getLine());
    Assert.assertEquals(1, input.get(2).getCharacter());
    Assert.assertEquals(2, input.get(3).getLine());
    Assert.assertEquals(2, input.get(3).getCharacter());
}
Also used : Position(org.eclipse.lsp4j.Position) Test(org.junit.Test)

Example 17 with Position

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

the class RangeComparatorTest method newRange.

private Range newRange(final int startLine, final int startChar, final int endLine, final int endChar) {
    Position _position = new Position(startLine, startChar);
    Position _position_1 = new Position(endLine, endChar);
    return new Range(_position, _position_1);
}
Also used : Position(org.eclipse.lsp4j.Position) Range(org.eclipse.lsp4j.Range)

Example 18 with Position

use of org.eclipse.lsp4j.Position 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();
        TextDocumentPositionParams _textDocumentPositionParams = new TextDocumentPositionParams();
        final Procedure1<TextDocumentPositionParams> _function = (TextDocumentPositionParams 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);
        };
        TextDocumentPositionParams _doubleArrow = ObjectExtensions.<TextDocumentPositionParams>operator_doubleArrow(_textDocumentPositionParams, _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) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) SignatureHelpConfiguration(org.eclipse.xtext.testing.SignatureHelpConfiguration) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams)

Example 19 with Position

use of org.eclipse.lsp4j.Position 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 : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) Extension(org.eclipse.xtext.xbase.lib.Extension) ReferenceTestConfiguration(org.eclipse.xtext.testing.ReferenceTestConfiguration) 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 20 with Position

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

the class ActionScriptTextDocumentService method definitionToSymbol.

private SymbolInformation definitionToSymbol(IDefinition definition) {
    SymbolInformation symbol = new SymbolInformation();
    if (definition instanceof IClassDefinition) {
        symbol.setKind(SymbolKind.Class);
    } else if (definition instanceof IInterfaceDefinition) {
        symbol.setKind(SymbolKind.Interface);
    } else if (definition instanceof IFunctionDefinition) {
        IFunctionDefinition functionDefinition = (IFunctionDefinition) definition;
        if (functionDefinition.isConstructor()) {
            symbol.setKind(SymbolKind.Constructor);
        } else {
            symbol.setKind(SymbolKind.Function);
        }
    } else if (definition instanceof IFunctionDefinition) {
        symbol.setKind(SymbolKind.Function);
    } else if (definition instanceof IConstantDefinition) {
        symbol.setKind(SymbolKind.Constant);
    } else {
        symbol.setKind(SymbolKind.Variable);
    }
    symbol.setName(definition.getQualifiedName());
    Location location = new Location();
    String sourcePath = definition.getSourcePath();
    if (sourcePath == null) {
        //I'm not sure why getSourcePath() can sometimes return null, but
        //getContainingFilePath() seems to work as a fallback -JT
        sourcePath = definition.getContainingFilePath();
    }
    Path definitionPath = Paths.get(sourcePath);
    location.setUri(definitionPath.toUri().toString());
    Position start = new Position();
    Position end = new Position();
    //getLine() and getColumn() may include things like metadata, so it
    //makes more sense to jump to where the definition name starts
    int line = definition.getNameLine();
    int column = definition.getNameColumn();
    if (line < 0 || column < 0) {
        //this is not ideal, but MXML variable definitions may not have a
        //node associated with them, so we need to figure this out from the
        //offset instead of a pre-calculated line and column -JT
        String code = sourceByPath.get(Paths.get(sourcePath));
        offsetToLineAndCharacter(new StringReader(code), definition.getNameStart(), start);
        end.setLine(start.getLine());
        end.setCharacter(start.getCharacter());
    } else {
        start.setLine(line);
        start.setCharacter(column);
        end.setLine(line);
        end.setCharacter(column);
    }
    Range range = new Range();
    range.setStart(start);
    range.setEnd(end);
    location.setRange(range);
    symbol.setLocation(location);
    return symbol;
}
Also used : Path(java.nio.file.Path) IClassDefinition(org.apache.flex.compiler.definitions.IClassDefinition) IInterfaceDefinition(org.apache.flex.compiler.definitions.IInterfaceDefinition) IFunctionDefinition(org.apache.flex.compiler.definitions.IFunctionDefinition) Position(org.eclipse.lsp4j.Position) StringReader(java.io.StringReader) Range(org.eclipse.lsp4j.Range) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) IConstantDefinition(org.apache.flex.compiler.definitions.IConstantDefinition) Location(org.eclipse.lsp4j.Location) ISourceLocation(org.apache.flex.compiler.common.ISourceLocation)

Aggregations

Position (org.eclipse.lsp4j.Position)37 Range (org.eclipse.lsp4j.Range)18 Test (org.junit.Test)10 List (java.util.List)9 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)9 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)7 CompletionList (org.eclipse.lsp4j.CompletionList)6 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)6 AbstractTestLangLanguageServerTest (org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)6 Extension (org.eclipse.xtext.xbase.lib.Extension)6 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)5 CompletionItem (org.eclipse.lsp4j.CompletionItem)4 Diagnostic (org.eclipse.lsp4j.Diagnostic)4 Location (org.eclipse.lsp4j.Location)4 TextEdit (org.eclipse.lsp4j.TextEdit)4 XtextResource (org.eclipse.xtext.resource.XtextResource)4 StringReader (java.io.StringReader)3 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)3 Path (java.nio.file.Path)2 ISourceLocation (org.apache.flex.compiler.common.ISourceLocation)2