Skip to content

Instantly share code, notes, and snippets.

@NipunaMarcus
Created September 26, 2019 08:25
Show Gist options
  • Save NipunaMarcus/7063183b84d15366500172fc21a58d09 to your computer and use it in GitHub Desktop.
Save NipunaMarcus/7063183b84d15366500172fc21a58d09 to your computer and use it in GitHub Desktop.
package org.hello.ls.langserver;
import org.eclipse.lsp4j.*;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.services.TextDocumentService;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public class HelloTextDocumentService implements TextDocumentService {
@Override
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(CompletionParams completionParams) {
// Provide completion item.
return CompletableFuture.supplyAsync(() -> {
List<CompletionItem> completionItems = new ArrayList<>();
try {
// Sample Completion item for sayHello
CompletionItem completionItem = new CompletionItem();
// Define the text to be inserted in to the file if the completion item is selected.
completionItem.setInsertText("sayHello() {\n print(\"hello\")\n}");
// Set the label that shows when the completion drop down appears in the Editor.
completionItem.setLabel("sayHello()");
// Set the completion kind. This is a snippet.
// That means it replace character which trigger the completion and
// replace it with what defined in inserted text.
completionItem.setKind(CompletionItemKind.Snippet);
// This will set the details for the snippet code which will help user to
// understand what this completion item is.
completionItem.setDetail("sayHello()\n this will say hello to the people");
// Add the sample completion item to the list.
completionItems.add(completionItem);
} catch (Exception e) {
//TODO: Handle the exception.
}
// Return the list of completion items.
return Either.forLeft(completionItems);
});
}
@Override
public CompletableFuture<CompletionItem> resolveCompletionItem(CompletionItem completionItem) {
return null;
}
@Override
public CompletableFuture<Hover> hover(TextDocumentPositionParams textDocumentPositionParams) {
return null;
}
@Override
public CompletableFuture<SignatureHelp> signatureHelp(TextDocumentPositionParams textDocumentPositionParams) {
return null;
}
@Override
public CompletableFuture<List<? extends Location>> definition(TextDocumentPositionParams textDocumentPositionParams) {
return null;
}
@Override
public CompletableFuture<List<? extends Location>> references(ReferenceParams referenceParams) {
return null;
}
@Override
public CompletableFuture<List<? extends DocumentHighlight>> documentHighlight(TextDocumentPositionParams textDocumentPositionParams) {
return null;
}
@Override
public CompletableFuture<List<? extends SymbolInformation>> documentSymbol(DocumentSymbolParams documentSymbolParams) {
return null;
}
@Override
public CompletableFuture<List<? extends Command>> codeAction(CodeActionParams codeActionParams) {
return null;
}
@Override
public CompletableFuture<List<? extends CodeLens>> codeLens(CodeLensParams codeLensParams) {
return null;
}
@Override
public CompletableFuture<CodeLens> resolveCodeLens(CodeLens codeLens) {
return null;
}
@Override
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams documentFormattingParams) {
return null;
}
@Override
public CompletableFuture<List<? extends TextEdit>> rangeFormatting(DocumentRangeFormattingParams documentRangeFormattingParams) {
return null;
}
@Override
public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams documentOnTypeFormattingParams) {
return null;
}
@Override
public CompletableFuture<WorkspaceEdit> rename(RenameParams renameParams) {
return null;
}
@Override
public void didOpen(DidOpenTextDocumentParams didOpenTextDocumentParams) {
}
@Override
public void didChange(DidChangeTextDocumentParams didChangeTextDocumentParams) {
}
@Override
public void didClose(DidCloseTextDocumentParams didCloseTextDocumentParams) {
}
@Override
public void didSave(DidSaveTextDocumentParams didSaveTextDocumentParams) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment