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));
}
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();
}
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<>();
}
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));
}
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);
});
}
Aggregations