Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. package org.hello.ls.langserver;
  2.  
  3. import org.eclipse.lsp4j.CompletionOptions;
  4. import org.eclipse.lsp4j.InitializeParams;
  5. import org.eclipse.lsp4j.InitializeResult;
  6. import org.eclipse.lsp4j.ServerCapabilities;
  7. import org.eclipse.lsp4j.TextDocumentSyncKind;
  8. import org.eclipse.lsp4j.services.LanguageClient;
  9. import org.eclipse.lsp4j.services.LanguageClientAware;
  10. import org.eclipse.lsp4j.services.LanguageServer;
  11. import org.eclipse.lsp4j.services.TextDocumentService;
  12. import org.eclipse.lsp4j.services.WorkspaceService;
  13.  
  14. import java.util.concurrent.CompletableFuture;
  15.  
  16. public class HelloLanguageServer implements LanguageServer, LanguageClientAware {
  17. private TextDocumentService textDocumentService;
  18. private WorkspaceService workspaceService;
  19. private LanguageClient client;
  20. private int errorCode = 1;
  21.  
  22. public HelloLanguageServer() {
  23. this.textDocumentService = new HelloTextDocumentService();
  24. this.workspaceService = new HelloWorkspaceService();
  25. }
  26.  
  27. @Override
  28. public CompletableFuture<InitializeResult> initialize(InitializeParams initializeParams) {
  29. // Initialize the InitializeResult for this LS.
  30. final InitializeResult initializeResult = new InitializeResult(new ServerCapabilities());
  31.  
  32. // Set the capabilities of the LS to inform the client.
  33. initializeResult.getCapabilities().setTextDocumentSync(TextDocumentSyncKind.Full);
  34. CompletionOptions completionOptions = new CompletionOptions();
  35. initializeResult.getCapabilities().setCompletionProvider(completionOptions);
  36. return CompletableFuture.supplyAsync(()->initializeResult);
  37. }
  38.  
  39. @Override
  40. public CompletableFuture<Object> shutdown() {
  41. // If shutdown request comes from client, set the error code to 0.
  42. errorCode = 0;
  43. return null;
  44. }
  45.  
  46. @Override
  47. public void exit() {
  48. // Kill the LS on exit request from client.
  49. System.exit(errorCode);
  50. }
  51.  
  52. @Override
  53. public TextDocumentService getTextDocumentService() {
  54. // Return the endpoint for language features.
  55. return this.textDocumentService;
  56. }
  57.  
  58. @Override
  59. public WorkspaceService getWorkspaceService() {
  60. // Return the endpoint for workspace functionality.
  61. return this.workspaceService;
  62. }
  63.  
  64. @Override
  65. public void connect(LanguageClient languageClient) {
  66. // Get the client which started this LS.
  67. this.client = languageClient;
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement