-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[VSC] Accounts and contacts (1/5) #955
base: master
Are you sure you want to change the base?
Changes from all commits
899144b
c210446
dc52700
756a06c
7694aa9
9dd874f
c4e866b
2c93df9
eeb7b1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,51 @@ | ||
package saros.lsp; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import org.apache.log4j.Logger; | ||
import java.util.function.Consumer; | ||
import org.eclipse.lsp4j.InitializeParams; | ||
import org.eclipse.lsp4j.InitializeResult; | ||
import org.eclipse.lsp4j.ServerCapabilities; | ||
import org.eclipse.lsp4j.services.TextDocumentService; | ||
import org.eclipse.lsp4j.TextDocumentSyncKind; | ||
import org.eclipse.lsp4j.services.WorkspaceService; | ||
import saros.lsp.extensions.ISarosLanguageServer; | ||
import saros.lsp.extensions.client.ISarosLanguageClient; | ||
import saros.lsp.extensions.client.ISarosLanguageClientAware; | ||
import saros.lsp.extensions.server.account.AccountService; | ||
import saros.lsp.extensions.server.ISarosLanguageServer; | ||
import saros.lsp.extensions.server.account.IAccountService; | ||
import saros.lsp.service.DocumentServiceStub; | ||
import saros.lsp.service.WorkspaceServiceStub; | ||
import saros.lsp.extensions.server.connection.IConnectionService; | ||
import saros.lsp.extensions.server.contact.IContactService; | ||
import saros.lsp.extensions.server.document.IDocumentService; | ||
|
||
/** Implementation of the Saros language server. */ | ||
// TODO: Remove SuppressWarning after Server and Client interaction is on master branch | ||
@SuppressWarnings({"PMD.UnusedPrivateField"}) | ||
public class SarosLanguageServer implements ISarosLanguageServer, ISarosLanguageClientAware { | ||
/** Implmenentation of {@link ISarosLanguageServer}. */ | ||
public class SarosLanguageServer implements ISarosLanguageServer { | ||
|
||
private static final Logger log = Logger.getLogger(SarosLanguageServer.class); | ||
private IAccountService accountService; | ||
|
||
private ISarosLanguageClient languageClient; | ||
private IContactService contactService; | ||
|
||
private IDocumentService documentService; | ||
|
||
private WorkspaceService workspaceService; | ||
|
||
private IConnectionService connectionService; | ||
|
||
public SarosLanguageServer( | ||
IAccountService accountService, | ||
IContactService contactService, | ||
IDocumentService documentService, | ||
IConnectionService connectionService, | ||
WorkspaceService workspaceService) { | ||
this.accountService = accountService; | ||
this.contactService = contactService; | ||
this.documentService = documentService; | ||
this.connectionService = connectionService; | ||
this.workspaceService = workspaceService; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<InitializeResult> initialize(InitializeParams params) { | ||
|
||
this.initializeListeners.forEach(listener -> listener.accept(params)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either name it consumer or visitor. A listener do not accept anything. |
||
|
||
return CompletableFuture.completedFuture(new InitializeResult(this.createCapabilities())); | ||
} | ||
|
||
|
@@ -46,37 +66,57 @@ public CompletableFuture<InitializeResult> initialize(InitializeParams params) { | |
private ServerCapabilities createCapabilities() { | ||
ServerCapabilities capabilities = new ServerCapabilities(); | ||
|
||
capabilities.setExperimental(true); | ||
capabilities.setTextDocumentSync(TextDocumentSyncKind.Incremental); | ||
|
||
return capabilities; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Object> shutdown() { | ||
log.info("shutdown"); | ||
return CompletableFuture.completedFuture(null); | ||
} | ||
|
||
@Override | ||
public void exit() { | ||
log.info("exit"); | ||
this.exitListeners.forEach(listener -> listener.run()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. callback or hook is the correct naming instead of listener, especially when you call |
||
} | ||
|
||
private List<Runnable> exitListeners = new ArrayList<>(); | ||
private List<Consumer<InitializeParams>> initializeListeners = new ArrayList<>(); | ||
|
||
@Override | ||
public TextDocumentService getTextDocumentService() { | ||
return new DocumentServiceStub(); | ||
public void onInitialize(Consumer<InitializeParams> consumer) { | ||
this.initializeListeners.add(consumer); | ||
} | ||
|
||
@Override | ||
public WorkspaceService getWorkspaceService() { | ||
return new WorkspaceServiceStub(); | ||
public void onExit(Runnable runnable) { | ||
this.exitListeners.add(runnable); | ||
} | ||
|
||
@Override | ||
public void connect(ISarosLanguageClient client) { | ||
this.languageClient = client; | ||
public IDocumentService getTextDocumentService() { | ||
return this.documentService; | ||
} | ||
|
||
@Override | ||
public WorkspaceService getWorkspaceService() { | ||
return this.workspaceService; | ||
} | ||
|
||
@Override | ||
public IAccountService getSarosAccountService() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. smurf |
||
return new AccountService(); | ||
return this.accountService; | ||
} | ||
|
||
@Override | ||
public IContactService getSarosContactService() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. smurf |
||
return this.contactService; | ||
} | ||
|
||
@Override | ||
public IConnectionService getSarosConnectionService() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. smurf |
||
return this.connectionService; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you return a Future when it is always completed when this method return ?