Search in sources :

Example 11 with DidOpenTextDocumentParams

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

the class UnknownProjectConfigTest method testCompletionWithFileScheme_02.

@Test
public void testCompletionWithFileScheme_02() throws Exception {
    initialize();
    String fileUri = "file:/home/test/workspace/mydoc.testlang";
    languageServer.didOpen(new DidOpenTextDocumentParams(newTextDocumentItem(fileUri, "type Foo {}")));
    checkCompletion(fileUri);
}
Also used : DidOpenTextDocumentParams(org.eclipse.lsp4j.DidOpenTextDocumentParams) Test(org.junit.Test)

Example 12 with DidOpenTextDocumentParams

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

the class UnknownProjectConfigTest method testCompletionWithFileScheme_01.

@Test
public void testCompletionWithFileScheme_01() throws Exception {
    initialize(it -> it.setWorkspaceFolders(Lists.newArrayList()));
    String fileUri = "file:/home/test/workspace/mydoc.testlang";
    languageServer.didOpen(new DidOpenTextDocumentParams(newTextDocumentItem(fileUri, "type Foo {}")));
    checkCompletion(fileUri);
}
Also used : DidOpenTextDocumentParams(org.eclipse.lsp4j.DidOpenTextDocumentParams) Test(org.junit.Test)

Example 13 with DidOpenTextDocumentParams

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

the class LspExtensionTest method testExtension.

@Test
public void testExtension() throws Exception {
    String fileURI = writeFile("mydoc.testlang", "");
    initialize();
    TestLangLSPExtension ext = ServiceEndpoints.toServiceObject(languageServer, TestLangLSPExtension.class);
    DidOpenTextDocumentParams didOpenTextDocumentParams = new DidOpenTextDocumentParams();
    String text = "foo bar" + System.lineSeparator() + "baz test" + System.lineSeparator() + "	bla blubb";
    didOpenTextDocumentParams.setTextDocument(new TextDocumentItem(fileURI, "testlang", 0, text));
    languageServer.didOpen(didOpenTextDocumentParams);
    TextOfLineParam textOfLineParam = new TextOfLineParam();
    textOfLineParam.uri = fileURI;
    textOfLineParam.line = 1;
    TextOfLineResult result = ext.getTextOfLine(textOfLineParam).get();
    Assert.assertEquals("baz test", result.text);
    Assert.assertEquals(2, IterableExtensions.size(Iterables.filter(Iterables.transform(notifications, n -> n.getValue()), TestLangLSPExtension.BuildNotification.class)));
}
Also used : List(java.util.List) TextDocumentItem(org.eclipse.lsp4j.TextDocumentItem) Iterables(com.google.common.collect.Iterables) IterableExtensions(org.eclipse.xtext.xbase.lib.IterableExtensions) Lists(com.google.common.collect.Lists) TestLangLSPExtension(org.eclipse.xtext.ide.tests.testlanguage.ide.TestLangLSPExtension) DidOpenTextDocumentParams(org.eclipse.lsp4j.DidOpenTextDocumentParams) ServiceEndpoints(org.eclipse.lsp4j.jsonrpc.services.ServiceEndpoints) Test(org.junit.Test) TextOfLineParam(org.eclipse.xtext.ide.tests.testlanguage.ide.TestLangLSPExtension.TextOfLineParam) Assert(org.junit.Assert) TextOfLineResult(org.eclipse.xtext.ide.tests.testlanguage.ide.TestLangLSPExtension.TextOfLineResult) TextDocumentItem(org.eclipse.lsp4j.TextDocumentItem) DidOpenTextDocumentParams(org.eclipse.lsp4j.DidOpenTextDocumentParams) TestLangLSPExtension(org.eclipse.xtext.ide.tests.testlanguage.ide.TestLangLSPExtension) TextOfLineResult(org.eclipse.xtext.ide.tests.testlanguage.ide.TestLangLSPExtension.TextOfLineResult) TextOfLineParam(org.eclipse.xtext.ide.tests.testlanguage.ide.TestLangLSPExtension.TextOfLineParam) Test(org.junit.Test)

Example 14 with DidOpenTextDocumentParams

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

the class UnknownProjectConfigTest method testCompletionWithInmemoryScheme_02.

@Test
public void testCompletionWithInmemoryScheme_02() throws Exception {
    initialize();
    String inmemoryUri = "inmemory:/mydoc.testlang";
    languageServer.didOpen(new DidOpenTextDocumentParams(newTextDocumentItem(inmemoryUri, "type Foo {}")));
    checkCompletion(inmemoryUri);
}
Also used : DidOpenTextDocumentParams(org.eclipse.lsp4j.DidOpenTextDocumentParams) Test(org.junit.Test)

Example 15 with DidOpenTextDocumentParams

use of org.eclipse.lsp4j.DidOpenTextDocumentParams in project ballerina by ballerina-lang.

the class CommonUtil method getLanguageServerResponseMessageAsString.

/**
 * Get the definition response message as a string.
 *
 * @param position    hovering position to get the definition.
 * @param file        bal file path
 * @param fileContent bal file content
 * @param method      string name of the language feature method
 * @return json string value of the response
 */
public static String getLanguageServerResponseMessageAsString(Position position, String file, String fileContent, String method) throws InterruptedException {
    Gson gson = new Gson();
    BallerinaLanguageServer ballerinaLanguageServer = new BallerinaLanguageServer();
    Endpoint serviceEndpoint = ServiceEndpoints.toEndpoint(ballerinaLanguageServer);
    TextDocumentPositionParams positionParams = new TextDocumentPositionParams();
    TextDocumentIdentifier identifier = new TextDocumentIdentifier();
    identifier.setUri(Paths.get(file).toUri().toString());
    positionParams.setTextDocument(identifier);
    positionParams.setPosition(position);
    DidOpenTextDocumentParams documentParams = new DidOpenTextDocumentParams();
    TextDocumentItem textDocumentItem = new TextDocumentItem();
    textDocumentItem.setUri(identifier.getUri());
    textDocumentItem.setText(fileContent);
    documentParams.setTextDocument(textDocumentItem);
    serviceEndpoint.notify("textDocument/didOpen", documentParams);
    CompletableFuture result = serviceEndpoint.request(method, positionParams);
    ResponseMessage jsonrpcResponse = new ResponseMessage();
    try {
        jsonrpcResponse.setId("324");
        jsonrpcResponse.setResult(result.get());
    } catch (InterruptedException e) {
        ResponseError responseError = new ResponseError();
        responseError.setCode(-32002);
        responseError.setMessage("Attempted to retrieve the result of a task/s" + "that was aborted by throwing an exception");
        jsonrpcResponse.setError(responseError);
    } catch (ExecutionException e) {
        ResponseError responseError = new ResponseError();
        responseError.setCode(-32001);
        responseError.setMessage("Current thread was interrupted");
        jsonrpcResponse.setError(responseError);
    }
    return gson.toJson(jsonrpcResponse);
}
Also used : TextDocumentItem(org.eclipse.lsp4j.TextDocumentItem) BallerinaLanguageServer(org.ballerinalang.langserver.BallerinaLanguageServer) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CompletableFuture(java.util.concurrent.CompletableFuture) Endpoint(org.eclipse.lsp4j.jsonrpc.Endpoint) DidOpenTextDocumentParams(org.eclipse.lsp4j.DidOpenTextDocumentParams) ResponseError(org.eclipse.lsp4j.jsonrpc.messages.ResponseError) Gson(com.google.gson.Gson) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) ResponseMessage(org.eclipse.lsp4j.jsonrpc.messages.ResponseMessage) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

DidOpenTextDocumentParams (org.eclipse.lsp4j.DidOpenTextDocumentParams)16 TextDocumentItem (org.eclipse.lsp4j.TextDocumentItem)11 Test (org.junit.Test)10 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Gson (com.google.gson.Gson)1 File (java.io.File)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 BallerinaLanguageServer (org.ballerinalang.langserver.BallerinaLanguageServer)1 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)1 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)1 Endpoint (org.eclipse.lsp4j.jsonrpc.Endpoint)1 ResponseError (org.eclipse.lsp4j.jsonrpc.messages.ResponseError)1 ResponseMessage (org.eclipse.lsp4j.jsonrpc.messages.ResponseMessage)1 ServiceEndpoints (org.eclipse.lsp4j.jsonrpc.services.ServiceEndpoints)1 TestLangLSPExtension (org.eclipse.xtext.ide.tests.testlanguage.ide.TestLangLSPExtension)1 TextOfLineParam (org.eclipse.xtext.ide.tests.testlanguage.ide.TestLangLSPExtension.TextOfLineParam)1 TextOfLineResult (org.eclipse.xtext.ide.tests.testlanguage.ide.TestLangLSPExtension.TextOfLineResult)1