use of org.eclipse.lsp4j.WorkspaceClientCapabilities in project xtext-core by eclipse.
the class CommandServiceTest method testExecute.
@Test
public void testExecute() {
final Procedure1<InitializeParams> _function = (InitializeParams it) -> {
ClientCapabilities _clientCapabilities = new ClientCapabilities();
final Procedure1<ClientCapabilities> _function_1 = (ClientCapabilities it_1) -> {
WorkspaceClientCapabilities _workspaceClientCapabilities = new WorkspaceClientCapabilities();
final Procedure1<WorkspaceClientCapabilities> _function_2 = (WorkspaceClientCapabilities it_2) -> {
ExecuteCommandCapabilities _executeCommandCapabilities = new ExecuteCommandCapabilities();
final Procedure1<ExecuteCommandCapabilities> _function_3 = (ExecuteCommandCapabilities it_3) -> {
it_3.setDynamicRegistration(Boolean.valueOf(true));
};
ExecuteCommandCapabilities _doubleArrow = ObjectExtensions.<ExecuteCommandCapabilities>operator_doubleArrow(_executeCommandCapabilities, _function_3);
it_2.setExecuteCommand(_doubleArrow);
};
WorkspaceClientCapabilities _doubleArrow = ObjectExtensions.<WorkspaceClientCapabilities>operator_doubleArrow(_workspaceClientCapabilities, _function_2);
it_1.setWorkspace(_doubleArrow);
};
ClientCapabilities _doubleArrow = ObjectExtensions.<ClientCapabilities>operator_doubleArrow(_clientCapabilities, _function_1);
it.setCapabilities(_doubleArrow);
};
this.initialize(_function);
final Procedure1<CommandServiceTest.TestExecuteCommandConfiguration> _function_1 = (CommandServiceTest.TestExecuteCommandConfiguration it) -> {
it.command = "testlang.a";
final Consumer<Object> _function_2 = (Object it_1) -> {
if ((it_1 instanceof String)) {
this.assertEquals("a", ((String) it_1));
} else {
Assert.fail("no string");
}
};
it.assertCommandResult = _function_2;
};
this.testExecuteCommand(_function_1);
final Procedure1<CommandServiceTest.TestExecuteCommandConfiguration> _function_2 = (CommandServiceTest.TestExecuteCommandConfiguration it) -> {
it.command = "testlang.b";
final Consumer<Object> _function_3 = (Object it_1) -> {
if ((it_1 instanceof String)) {
this.assertEquals("b", ((String) it_1));
} else {
Assert.fail("no string");
}
};
it.assertCommandResult = _function_3;
};
this.testExecuteCommand(_function_2);
final Procedure1<CommandServiceTest.TestExecuteCommandConfiguration> _function_3 = (CommandServiceTest.TestExecuteCommandConfiguration it) -> {
it.command = "doesnotexist.c";
final Consumer<Object> _function_4 = (Object it_1) -> {
Assert.assertNull(it_1);
};
it.assertCommandResult = _function_4;
};
this.testExecuteCommand(_function_3);
}
use of org.eclipse.lsp4j.WorkspaceClientCapabilities in project xtext-core by eclipse.
the class CommandRegistryTest method testRegistration.
@Test
public void testRegistration() {
final ExecutableCommandRegistry reg = new ExecutableCommandRegistry();
ClientCapabilities _clientCapabilities = new ClientCapabilities();
final Procedure1<ClientCapabilities> _function = (ClientCapabilities it) -> {
WorkspaceClientCapabilities _workspaceClientCapabilities = new WorkspaceClientCapabilities();
final Procedure1<WorkspaceClientCapabilities> _function_1 = (WorkspaceClientCapabilities it_1) -> {
ExecuteCommandCapabilities _executeCommandCapabilities = new ExecuteCommandCapabilities();
final Procedure1<ExecuteCommandCapabilities> _function_2 = (ExecuteCommandCapabilities it_2) -> {
it_2.setDynamicRegistration(Boolean.valueOf(true));
};
ExecuteCommandCapabilities _doubleArrow = ObjectExtensions.<ExecuteCommandCapabilities>operator_doubleArrow(_executeCommandCapabilities, _function_2);
it_1.setExecuteCommand(_doubleArrow);
};
WorkspaceClientCapabilities _doubleArrow = ObjectExtensions.<WorkspaceClientCapabilities>operator_doubleArrow(_workspaceClientCapabilities, _function_1);
it.setWorkspace(_doubleArrow);
};
final ClientCapabilities cap = ObjectExtensions.<ClientCapabilities>operator_doubleArrow(_clientCapabilities, _function);
reg.initialize(Collections.<IResourceServiceProvider>unmodifiableList(CollectionLiterals.<IResourceServiceProvider>newArrayList(this)), cap, this);
Assert.assertEquals("static-command", IterableExtensions.<String>head(reg.getCommands()));
ExecuteCommandParams _executeCommandParams = new ExecuteCommandParams();
final Procedure1<ExecuteCommandParams> _function_1 = (ExecuteCommandParams it) -> {
it.setCommand("static-command");
};
ExecuteCommandParams _doubleArrow = ObjectExtensions.<ExecuteCommandParams>operator_doubleArrow(_executeCommandParams, _function_1);
reg.executeCommand(_doubleArrow, null, null);
ExecuteCommandParams _executeCommandParams_1 = new ExecuteCommandParams();
final Procedure1<ExecuteCommandParams> _function_2 = (ExecuteCommandParams it) -> {
it.setCommand("dynamic-command");
};
ExecuteCommandParams _doubleArrow_1 = ObjectExtensions.<ExecuteCommandParams>operator_doubleArrow(_executeCommandParams_1, _function_2);
reg.executeCommand(_doubleArrow_1, null, null);
Assert.assertEquals(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("static-command")), this.commandsExecuted);
this.commandsExecuted.clear();
final IDisposable disposable = this.register.apply("dynamic-command");
ExecuteCommandParams _executeCommandParams_2 = new ExecuteCommandParams();
final Procedure1<ExecuteCommandParams> _function_3 = (ExecuteCommandParams it) -> {
it.setCommand("dynamic-command");
};
ExecuteCommandParams _doubleArrow_2 = ObjectExtensions.<ExecuteCommandParams>operator_doubleArrow(_executeCommandParams_2, _function_3);
reg.executeCommand(_doubleArrow_2, null, null);
Assert.assertEquals(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("dynamic-command")), this.commandsExecuted);
this.commandsExecuted.clear();
disposable.dispose();
ExecuteCommandParams _executeCommandParams_3 = new ExecuteCommandParams();
final Procedure1<ExecuteCommandParams> _function_4 = (ExecuteCommandParams it) -> {
it.setCommand("dynamic-command");
};
ExecuteCommandParams _doubleArrow_3 = ObjectExtensions.<ExecuteCommandParams>operator_doubleArrow(_executeCommandParams_3, _function_4);
reg.executeCommand(_doubleArrow_3, null, null);
Assert.assertEquals(Collections.<Object>unmodifiableSet(CollectionLiterals.<Object>newHashSet()), this.commandsExecuted);
}
use of org.eclipse.lsp4j.WorkspaceClientCapabilities in project sts4 by spring-projects.
the class LanguageServerHarness method intialize.
public InitializeResult intialize(File workspaceRoot) throws Exception {
server = factory.call();
int parentPid = random.nextInt(40000) + 1000;
InitializeParams initParams = new InitializeParams();
if (workspaceRoot != null) {
initParams.setRootPath(workspaceRoot.toString());
initParams.setRootUri(UriUtil.toUri(workspaceRoot).toString());
}
initParams.setProcessId(parentPid);
ClientCapabilities clientCap = new ClientCapabilities();
TextDocumentClientCapabilities textCap = new TextDocumentClientCapabilities();
CompletionCapabilities completionCap = new CompletionCapabilities(new CompletionItemCapabilities(true));
textCap.setCompletion(completionCap);
clientCap.setTextDocument(textCap);
WorkspaceClientCapabilities workspaceCap = new WorkspaceClientCapabilities();
workspaceCap.setApplyEdit(true);
ExecuteCommandCapabilities exeCap = new ExecuteCommandCapabilities();
exeCap.setDynamicRegistration(true);
workspaceCap.setExecuteCommand(exeCap);
clientCap.setWorkspace(workspaceCap);
initParams.setCapabilities(clientCap);
initResult = getServer().initialize(initParams).get();
if (getServer() instanceof LanguageClientAware) {
((LanguageClientAware) getServer()).connect(new STS4LanguageClient() {
@Override
public void telemetryEvent(Object object) {
// TODO Auto-generated method stub
}
@Override
public CompletableFuture<MessageActionItem> showMessageRequest(ShowMessageRequestParams requestParams) {
// TODO Auto-generated method stub
return CompletableFuture.completedFuture(new MessageActionItem("Some Message Request Answer"));
}
@Override
public void showMessage(MessageParams messageParams) {
// TODO Auto-generated method stub
}
@Override
public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {
receiveDiagnostics(diagnostics);
}
@Override
public void highlight(HighlightParams highlights) {
receiveHighlights(highlights);
}
@Override
public void logMessage(MessageParams message) {
// TODO Auto-generated method stub
}
@Override
public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
return Mono.fromCallable(() -> {
perform(params.getEdit());
return new ApplyWorkspaceEditResponse(true);
}).toFuture();
}
@Override
public CompletableFuture<Void> registerCapability(RegistrationParams params) {
return CompletableFuture.completedFuture(null);
}
@Override
public void progress(ProgressParams progressEvent) {
// TODO Auto-generated method stub
}
@Override
public CompletableFuture<Object> moveCursor(CursorMovement cursorMovement) {
for (Editor editor : activeEditors) {
if (editor.getUri().equals(cursorMovement.getUri())) {
editor.setCursor(cursorMovement.getPosition());
return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(true));
}
}
return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(false));
}
@Override
public CompletableFuture<ProjectResponse> project(String uri) {
return CompletableFuture.completedFuture(null);
}
@Override
public CompletableFuture<Object> addClasspathListener(ClasspathListenerParams params) {
return CompletableFuture.completedFuture("ok");
}
@Override
public CompletableFuture<Object> removeClasspathListener(ClasspathListenerParams classpathListenerParams) {
return CompletableFuture.completedFuture("ok");
}
});
}
getServer().initialized();
return initResult;
}
use of org.eclipse.lsp4j.WorkspaceClientCapabilities in project xtext-core by eclipse.
the class LanguageServerImpl method initialize.
@Override
public CompletableFuture<InitializeResult> initialize(final InitializeParams params) {
if ((this.params != null)) {
throw new IllegalStateException("This language server has already been initialized.");
}
final URI baseDir = this.getBaseDir(params);
boolean _isEmpty = this.languagesRegistry.getExtensionToFactoryMap().isEmpty();
if (_isEmpty) {
throw new IllegalStateException("No Xtext languages have been registered. Please make sure you have added the languages\'s setup class in \'/META-INF/services/org.eclipse.xtext.ISetup\'");
}
this.params = params;
final InitializeResult result = new InitializeResult();
ServerCapabilities _serverCapabilities = new ServerCapabilities();
final Procedure1<ServerCapabilities> _function = (ServerCapabilities it) -> {
it.setHoverProvider(Boolean.valueOf(true));
it.setDefinitionProvider(Boolean.valueOf(true));
it.setReferencesProvider(Boolean.valueOf(true));
it.setDocumentSymbolProvider(Boolean.valueOf(true));
it.setWorkspaceSymbolProvider(Boolean.valueOf(true));
final Function1<IResourceServiceProvider, Boolean> _function_1 = (IResourceServiceProvider it_1) -> {
ICodeLensService _get = it_1.<ICodeLensService>get(ICodeLensService.class);
return Boolean.valueOf((_get != null));
};
boolean _exists = IterableExtensions.exists(this.getAllLanguages(), _function_1);
if (_exists) {
CodeLensOptions _codeLensOptions = new CodeLensOptions();
final Procedure1<CodeLensOptions> _function_2 = (CodeLensOptions it_1) -> {
final Function1<IResourceServiceProvider, Boolean> _function_3 = (IResourceServiceProvider it_2) -> {
ICodeLensResolver _get = it_2.<ICodeLensResolver>get(ICodeLensResolver.class);
return Boolean.valueOf((_get != null));
};
it_1.setResolveProvider(IterableExtensions.exists(this.getAllLanguages(), _function_3));
};
CodeLensOptions _doubleArrow = ObjectExtensions.<CodeLensOptions>operator_doubleArrow(_codeLensOptions, _function_2);
it.setCodeLensProvider(_doubleArrow);
}
final Function1<IResourceServiceProvider, Boolean> _function_3 = (IResourceServiceProvider it_1) -> {
ICodeActionService _get = it_1.<ICodeActionService>get(ICodeActionService.class);
return Boolean.valueOf((_get != null));
};
it.setCodeActionProvider(Boolean.valueOf(IterableExtensions.exists(this.getAllLanguages(), _function_3)));
SignatureHelpOptions _signatureHelpOptions = new SignatureHelpOptions(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("(", ",")));
it.setSignatureHelpProvider(_signatureHelpOptions);
it.setTextDocumentSync(TextDocumentSyncKind.Incremental);
CompletionOptions _completionOptions = new CompletionOptions();
final Procedure1<CompletionOptions> _function_4 = (CompletionOptions it_1) -> {
it_1.setResolveProvider(Boolean.valueOf(false));
it_1.setTriggerCharacters(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(".")));
};
CompletionOptions _doubleArrow_1 = ObjectExtensions.<CompletionOptions>operator_doubleArrow(_completionOptions, _function_4);
it.setCompletionProvider(_doubleArrow_1);
it.setDocumentFormattingProvider(Boolean.valueOf(true));
it.setDocumentRangeFormattingProvider(Boolean.valueOf(true));
it.setDocumentHighlightProvider(Boolean.valueOf(true));
final Function1<IResourceServiceProvider, Boolean> _function_5 = (IResourceServiceProvider it_1) -> {
IRenameService _get = it_1.<IRenameService>get(IRenameService.class);
return Boolean.valueOf((_get != null));
};
it.setRenameProvider(Boolean.valueOf(IterableExtensions.exists(this.getAllLanguages(), _function_5)));
ClientCapabilities _capabilities = params.getCapabilities();
WorkspaceClientCapabilities _workspace = null;
if (_capabilities != null) {
_workspace = _capabilities.getWorkspace();
}
ExecuteCommandCapabilities _executeCommand = null;
if (_workspace != null) {
_executeCommand = _workspace.getExecuteCommand();
}
boolean _tripleNotEquals = (_executeCommand != null);
if (_tripleNotEquals) {
this.commandRegistry.initialize(this.getAllLanguages(), params.getCapabilities(), this.client);
ExecuteCommandOptions _executeCommandOptions = new ExecuteCommandOptions();
final Procedure1<ExecuteCommandOptions> _function_6 = (ExecuteCommandOptions it_1) -> {
it_1.setCommands(this.commandRegistry.getCommands());
};
ExecuteCommandOptions _doubleArrow_2 = ObjectExtensions.<ExecuteCommandOptions>operator_doubleArrow(_executeCommandOptions, _function_6);
it.setExecuteCommandProvider(_doubleArrow_2);
}
};
ServerCapabilities capabilities = ObjectExtensions.<ServerCapabilities>operator_doubleArrow(_serverCapabilities, _function);
Iterable<? extends IResourceServiceProvider> _allLanguages = this.getAllLanguages();
for (final IResourceServiceProvider language : _allLanguages) {
ICapabilitiesContributor _get = language.<ICapabilitiesContributor>get(ICapabilitiesContributor.class);
if (_get != null) {
_get.contribute(capabilities, params);
}
}
result.setCapabilities(capabilities);
this.access.addBuildListener(this);
final Function0<Object> _function_1 = () -> {
final Procedure2<URI, Iterable<Issue>> _function_2 = (URI $0, Iterable<Issue> $1) -> {
this.publishDiagnostics($0, $1);
};
this.workspaceManager.initialize(baseDir, _function_2, CancelIndicator.NullImpl);
return null;
};
final Function2<CancelIndicator, Object, Object> _function_2 = (CancelIndicator $0, Object $1) -> {
return null;
};
final Function<Object, InitializeResult> _function_3 = (Object it) -> {
return result;
};
return this.requestManager.<Object, Object>runWrite(_function_1, _function_2).<InitializeResult>thenApply(_function_3);
}
use of org.eclipse.lsp4j.WorkspaceClientCapabilities in project xtext-core by eclipse.
the class ExecutableCommandRegistry method initialize.
public void initialize(final Iterable<? extends IResourceServiceProvider> allLanguages, final ClientCapabilities capabilities, final LanguageClient client) {
this.client = client;
this.registeredCommands = HashMultimap.<String, IExecutableCommandService>create();
Boolean _elvis = null;
WorkspaceClientCapabilities _workspace = capabilities.getWorkspace();
ExecuteCommandCapabilities _executeCommand = null;
if (_workspace != null) {
_executeCommand = _workspace.getExecuteCommand();
}
Boolean _dynamicRegistration = null;
if (_executeCommand != null) {
_dynamicRegistration = _executeCommand.getDynamicRegistration();
}
if (_dynamicRegistration != null) {
_elvis = _dynamicRegistration;
} else {
_elvis = Boolean.valueOf(false);
}
final boolean hasDynamicRegistration = (boolean) _elvis;
for (final IResourceServiceProvider lang : allLanguages) {
{
final IExecutableCommandService service = lang.<IExecutableCommandService>get(IExecutableCommandService.class);
if ((service != null)) {
final List<String> commands = service.initialize();
for (final String c : commands) {
this.registeredCommands.put(c, service);
}
if (hasDynamicRegistration) {
final Function1<String, IDisposable> _function = (String command) -> {
return this.register(command, service);
};
service.initializeDynamicRegistration(_function);
}
}
}
}
}
Aggregations