Last active
September 26, 2019 07:02
-
-
Save NipunaMarcus/a8e56503a28fc78fa4b3f72a3b2add82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.hello.ls.langserver; | |
import org.eclipse.lsp4j.CompletionOptions; | |
import org.eclipse.lsp4j.InitializeParams; | |
import org.eclipse.lsp4j.InitializeResult; | |
import org.eclipse.lsp4j.ServerCapabilities; | |
import org.eclipse.lsp4j.TextDocumentSyncKind; | |
import org.eclipse.lsp4j.services.LanguageClient; | |
import org.eclipse.lsp4j.services.LanguageClientAware; | |
import org.eclipse.lsp4j.services.LanguageServer; | |
import org.eclipse.lsp4j.services.TextDocumentService; | |
import org.eclipse.lsp4j.services.WorkspaceService; | |
import java.util.concurrent.CompletableFuture; | |
public class HelloLanguageServer implements LanguageServer, LanguageClientAware { | |
private TextDocumentService textDocumentService; | |
private WorkspaceService workspaceService; | |
private LanguageClient client; | |
private int errorCode = 1; | |
public HelloLanguageServer() { | |
this.textDocumentService = new HelloTextDocumentService(); | |
this.workspaceService = new HelloWorkspaceService(); | |
} | |
@Override | |
public CompletableFuture<InitializeResult> initialize(InitializeParams initializeParams) { | |
// Initialize the InitializeResult for this LS. | |
final InitializeResult initializeResult = new InitializeResult(new ServerCapabilities()); | |
// Set the capabilities of the LS to inform the client. | |
initializeResult.getCapabilities().setTextDocumentSync(TextDocumentSyncKind.Full); | |
CompletionOptions completionOptions = new CompletionOptions(); | |
initializeResult.getCapabilities().setCompletionProvider(completionOptions); | |
return CompletableFuture.supplyAsync(()->initializeResult); | |
} | |
@Override | |
public CompletableFuture<Object> shutdown() { | |
// If shutdown request comes from client, set the error code to 0. | |
errorCode = 0; | |
return null; | |
} | |
@Override | |
public void exit() { | |
// Kill the LS on exit request from client. | |
System.exit(errorCode); | |
} | |
@Override | |
public TextDocumentService getTextDocumentService() { | |
// Return the endpoint for language features. | |
return this.textDocumentService; | |
} | |
@Override | |
public WorkspaceService getWorkspaceService() { | |
// Return the endpoint for workspace functionality. | |
return this.workspaceService; | |
} | |
@Override | |
public void connect(LanguageClient languageClient) { | |
// Get the client which started this LS. | |
this.client = languageClient; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment