Search in sources :

Example 6 with InitializeParams

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

the class ProjectsManagerTest method testCancelInitJob.

@Test
public void testCancelInitJob() throws Exception {
    File workspaceDir = copyFiles("maven/salut", true);
    String rootPathURI = workspaceDir.toURI().toString();
    Collection<IPath> rootPaths = Collections.singleton(ResourceUtils.canonicalFilePathFromURI(rootPathURI));
    InitializeParams params = new InitializeParams();
    params.setRootUri(rootPathURI);
    server.initialize(params);
    Job[] initWorkspaceJobs = Job.getJobManager().find(rootPaths);
    assertEquals(1, initWorkspaceJobs.length);
    Job initWorkspaceJob = initWorkspaceJobs[0];
    assertNotNull(initWorkspaceJob);
    projectsManager.updateWorkspaceFolders(Collections.emptySet(), rootPaths);
    waitForBackgroundJobs();
    assertTrue("the init job hasn't been cancelled, status is: " + initWorkspaceJob.getResult().getSeverity(), initWorkspaceJob.getResult().matches(IStatus.CANCEL));
}
Also used : IPath(org.eclipse.core.runtime.IPath) InitializeParams(org.eclipse.lsp4j.InitializeParams) Job(org.eclipse.core.runtime.jobs.Job) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 7 with InitializeParams

use of org.eclipse.lsp4j.InitializeParams in project sonarlint-core by SonarSource.

the class ServerMainTest method startServer.

@BeforeClass
public static void startServer() throws Exception {
    System.out.println("Max memory: " + Runtime.getRuntime().maxMemory());
    System.setProperty(SonarLintTelemetry.DISABLE_PROPERTY_KEY, "true");
    serverSocket = new ServerSocket(0);
    int port = serverSocket.getLocalPort();
    client = new FakeLanguageClient();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Callable<LanguageServer> callable = () -> {
        Socket socket = serverSocket.accept();
        Launcher<LanguageServer> launcher = LSPLauncher.createClientLauncher(client, socket.getInputStream(), socket.getOutputStream());
        launcher.startListening();
        return launcher.getRemoteProxy();
    };
    Future<LanguageServer> future = executor.submit(callable);
    executor.shutdown();
    String js = new File("target/plugins/javascript.jar").getAbsoluteFile().toURI().toURL().toString();
    String php = new File("target/plugins/php.jar").getAbsoluteFile().toURI().toURL().toString();
    String py = new File("target/plugins/python.jar").getAbsoluteFile().toURI().toURL().toString();
    String ts = new File("target/plugins/typescript.jar").getAbsoluteFile().toURI().toURL().toString();
    Path fakeTypeScriptProjectPath = globalTemp.newFolder().toPath();
    Path packagejson = fakeTypeScriptProjectPath.resolve("package.json");
    FileUtils.write(packagejson.toFile(), "{" + "\"devDependencies\": {\n" + "    \"typescript\": \"2.6.1\"\n" + "  }" + "}", StandardCharsets.UTF_8);
    ProcessBuilder pb = new ProcessBuilder("npm" + (SystemUtils.IS_OS_WINDOWS ? ".cmd" : ""), "install").directory(fakeTypeScriptProjectPath.toFile()).inheritIO();
    Process process = pb.start();
    if (process.waitFor() != 0) {
        fail("Unable to run npm install");
    }
    try {
        ServerMain.main("" + port, js, php, py, ts);
    } catch (Exception e) {
        e.printStackTrace();
        future.get(1, TimeUnit.SECONDS);
        if (!future.isDone()) {
            future.cancel(true);
        }
        throw e;
    }
    lsProxy = future.get();
    InitializeParams initializeParams = new InitializeParams();
    initializeParams.setInitializationOptions(ImmutableMap.builder().put(TEST_FILE_PATTERN, "{**/test/**,**/*test*,**/*Test*}").put(TYPESCRIPT_LOCATION, fakeTypeScriptProjectPath.resolve("node_modules").toString()).put(DISABLE_TELEMETRY, true).put("telemetryStorage", "not/exists").put("productName", "SLCORE tests").put("productVersion", "0.1").build());
    lsProxy.initialize(initializeParams).get();
}
Also used : Path(java.nio.file.Path) ServerSocket(java.net.ServerSocket) InitializeParams(org.eclipse.lsp4j.InitializeParams) IOException(java.io.IOException) LanguageServer(org.eclipse.lsp4j.services.LanguageServer) ExecutorService(java.util.concurrent.ExecutorService) Launcher(org.eclipse.lsp4j.jsonrpc.Launcher) LSPLauncher(org.eclipse.lsp4j.launch.LSPLauncher) File(java.io.File) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) BeforeClass(org.junit.BeforeClass)

Example 8 with InitializeParams

use of org.eclipse.lsp4j.InitializeParams in project erlide_eclipse by erlang.

the class ProjectSpecificLanguageServerWrapper method start.

private void start() throws IOException {
    if (server != null) {
        return;
    }
    server = new ErlangLanguageServer();
    // server.onError(new Procedure2<String, Throwable>() {
    // @Override
    // public void apply(final String p1, final Throwable p2) {
    // System.err.println(p1);
    // p2.printStackTrace();
    // }
    // });
    lspStreamProvider.start();
    // server.connect(lspStreamProvider.getInputStream(),
    // lspStreamProvider.getOutputStream());
    // server.getProtocol().addErrorListener(new Procedure2<String, Throwable>() {
    // @Override
    // public void apply(final String p1, final Throwable p2) {
    // System.err.println("error: " + p1);
    // }
    // });
    // server.getProtocol()
    // .addIncomingMessageListener(new Procedure2<Message, String>() {
    // @Override
    // public void apply(final Message p1, final String p2) {
    // System.err.println("IN: " + p1.getJsonrpc() + "\n" + p2);
    // }
    // });
    // server.getProtocol()
    // .addOutgoingMessageListener(new Procedure2<Message, String>() {
    // @Override
    // public void apply(final Message p1, final String p2) {
    // System.err.println("OUT: " + p1.getJsonrpc() + "\n" + p2);
    // }
    // });
    // initialize
    final InitializeParams initParams = new InitializeParams();
    initParams.setRootPath(project.getLocation().toFile().getAbsolutePath());
    String name = "Eclipse IDE";
    if (Platform.getProduct() != null) {
        name = Platform.getProduct().getName();
    }
    initParams.setClientName(name);
    Integer.valueOf(java.lang.management.ManagementFactory.getRuntimeMXBean().getName().split("@")[0]);
    initParams.setCapabilities(new ClientCapabilities());
    connectDiagnostics();
    final CompletableFuture<InitializeResult> result = server.initialize(initParams);
    try {
        final InitializeResult initializeResult = result.get();
    } catch (InterruptedException | ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    connectedFiles = new HashMap<>();
}
Also used : ErlangLanguageServer(org.erlide.server.ErlangLanguageServer) InitializeResult(org.eclipse.lsp4j.InitializeResult) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) InitializeParams(org.eclipse.lsp4j.InitializeParams) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with InitializeParams

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

the class RenamePositionTest method renameWithSuccess.

protected void renameWithSuccess(String model, Position position) throws Exception {
    String modelFile = writeFile("MyType.testlang", model);
    initialize((InitializeParams params) -> {
        ClientCapabilities clientCapabilities = new ClientCapabilities();
        TextDocumentClientCapabilities textDocumentClientCapabilities = new TextDocumentClientCapabilities();
        textDocumentClientCapabilities.setRename(new RenameCapabilities(true, false));
        clientCapabilities.setTextDocument(textDocumentClientCapabilities);
        params.setCapabilities(clientCapabilities);
    });
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(modelFile);
    Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
    Assert.assertNotNull(range);
    assertEquals(new Document(Integer.valueOf(0), model).getSubstring(range), "Test");
    RenameParams params = new RenameParams(identifier, position, "Tescht");
    WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
    String expectation = "changes :\n" + "	MyType.testlang : Tescht [[0, 5] .. [0, 9]]\n" + "documentChanges : \n";
    assertEquals(expectation.toString(), toExpectation(workspaceEdit));
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) RenameCapabilities(org.eclipse.lsp4j.RenameCapabilities) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) RenameParams(org.eclipse.lsp4j.RenameParams) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) InitializeParams(org.eclipse.lsp4j.InitializeParams) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) Range(org.eclipse.lsp4j.Range) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) Document(org.eclipse.xtext.ide.server.Document)

Example 10 with InitializeParams

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

the class RenameTest2 method initialize.

@Override
protected InitializeResult initialize() {
    return super.initialize((InitializeParams params) -> {
        ClientCapabilities clientCapabilities = new ClientCapabilities();
        WorkspaceClientCapabilities workspaceClientCapabilities = new WorkspaceClientCapabilities();
        WorkspaceEditCapabilities workspaceEditCapabilities = new WorkspaceEditCapabilities();
        workspaceEditCapabilities.setDocumentChanges(true);
        workspaceClientCapabilities.setWorkspaceEdit(workspaceEditCapabilities);
        clientCapabilities.setWorkspace(workspaceClientCapabilities);
        TextDocumentClientCapabilities textDocumentClientCapabilities = new TextDocumentClientCapabilities();
        textDocumentClientCapabilities.setRename(new RenameCapabilities(true, false));
        clientCapabilities.setTextDocument(textDocumentClientCapabilities);
        params.setCapabilities(clientCapabilities);
    });
}
Also used : WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) WorkspaceEditCapabilities(org.eclipse.lsp4j.WorkspaceEditCapabilities) RenameCapabilities(org.eclipse.lsp4j.RenameCapabilities) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) InitializeParams(org.eclipse.lsp4j.InitializeParams) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities)

Aggregations

InitializeParams (org.eclipse.lsp4j.InitializeParams)19 ClientCapabilities (org.eclipse.lsp4j.ClientCapabilities)11 TextDocumentClientCapabilities (org.eclipse.lsp4j.TextDocumentClientCapabilities)9 WorkspaceClientCapabilities (org.eclipse.lsp4j.WorkspaceClientCapabilities)8 InitializeResult (org.eclipse.lsp4j.InitializeResult)7 RenameCapabilities (org.eclipse.lsp4j.RenameCapabilities)6 ExecuteCommandCapabilities (org.eclipse.lsp4j.ExecuteCommandCapabilities)5 WorkspaceFolder (org.eclipse.lsp4j.WorkspaceFolder)5 File (java.io.File)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Range (org.eclipse.lsp4j.Range)4 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)4 ArrayList (java.util.ArrayList)3 URI (org.eclipse.emf.common.util.URI)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)3 Diagnostic (org.eclipse.lsp4j.Diagnostic)3 DidChangeWorkspaceFoldersParams (org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams)3 DocumentSymbolCapabilities (org.eclipse.lsp4j.DocumentSymbolCapabilities)3 Position (org.eclipse.lsp4j.Position)3