use of org.eclipse.lsp4j.InitializeResult in project sonarlint-core by SonarSource.
the class SonarLintLanguageServer method initialize.
@Override
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
String rootUri = params.getRootUri();
// rootURI is null when no folder is open (like opening a single file in VSCode)
if (rootUri != null) {
try {
workspaceRoot = new URI(rootUri);
} catch (URISyntaxException e) {
throw new IllegalStateException(e);
}
}
Map<String, Object> options = (Map<String, Object>) params.getInitializationOptions();
userSettings = new UserSettings(options);
String productKey = (String) options.get("productKey");
// deprecated, will be ignored when productKey present
String telemetryStorage = (String) options.get("telemetryStorage");
String productName = (String) options.get("productName");
String productVersion = (String) options.get("productVersion");
telemetry.init(getStoragePath(productKey, telemetryStorage), productName, productVersion);
telemetry.optOut(userSettings.disableTelemetry);
info("Starting SonarLint engine...");
info("Using " + analyzers.size() + " analyzers");
try {
Map<String, String> extraProperties = new HashMap<>();
extraProperties.put("sonar.typescript.internal.typescriptLocation", (String) options.get(TYPESCRIPT_LOCATION));
Builder builder = StandaloneGlobalConfiguration.builder().setLogOutput(logOutput).setExtraProperties(extraProperties).addPlugins(analyzers.toArray(new URL[0]));
this.engine = new StandaloneSonarLintEngineImpl(builder.build());
} catch (Exception e) {
error("Error starting SonarLint engine", e);
throw new IllegalStateException(e);
}
info("SonarLint engine started");
InitializeResult result = new InitializeResult();
ServerCapabilities c = new ServerCapabilities();
TextDocumentSyncOptions textDocumentSyncOptions = new TextDocumentSyncOptions();
textDocumentSyncOptions.setOpenClose(true);
textDocumentSyncOptions.setChange(TextDocumentSyncKind.Full);
textDocumentSyncOptions.setSave(new SaveOptions(true));
c.setTextDocumentSync(textDocumentSyncOptions);
c.setCodeActionProvider(true);
c.setExecuteCommandProvider(new ExecuteCommandOptions(asList(SONARLINT_OPEN_RULE_DESCRIPTION_COMMAND)));
result.setCapabilities(c);
return CompletableFuture.completedFuture(result);
}
use of org.eclipse.lsp4j.InitializeResult 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.InitializeResult in project erlide_eclipse by erlang.
the class ProjectSpecificLanguageServerWrapper method start.
private void start() throws IOException {
if (server != null) {
return;
}
server = new ErlangLanguageServer();
// server.onError(new Procedure2<String, Throwable>() {
// @Override
// public void apply(final String p1, final Throwable p2) {
// System.err.println(p1);
// p2.printStackTrace();
// }
// });
lspStreamProvider.start();
// server.connect(lspStreamProvider.getInputStream(),
// lspStreamProvider.getOutputStream());
// server.getProtocol().addErrorListener(new Procedure2<String, Throwable>() {
// @Override
// public void apply(final String p1, final Throwable p2) {
// System.err.println("error: " + p1);
// }
// });
// server.getProtocol()
// .addIncomingMessageListener(new Procedure2<Message, String>() {
// @Override
// public void apply(final Message p1, final String p2) {
// System.err.println("IN: " + p1.getJsonrpc() + "\n" + p2);
// }
// });
// server.getProtocol()
// .addOutgoingMessageListener(new Procedure2<Message, String>() {
// @Override
// public void apply(final Message p1, final String p2) {
// System.err.println("OUT: " + p1.getJsonrpc() + "\n" + p2);
// }
// });
// initialize
final InitializeParams initParams = new InitializeParams();
initParams.setRootPath(project.getLocation().toFile().getAbsolutePath());
String name = "Eclipse IDE";
if (Platform.getProduct() != null) {
name = Platform.getProduct().getName();
}
initParams.setClientName(name);
Integer.valueOf(java.lang.management.ManagementFactory.getRuntimeMXBean().getName().split("@")[0]);
initParams.setCapabilities(new ClientCapabilities());
connectDiagnostics();
final CompletableFuture<InitializeResult> result = server.initialize(initParams);
try {
final InitializeResult initializeResult = result.get();
} catch (InterruptedException | ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
connectedFiles = new HashMap<>();
}
use of org.eclipse.lsp4j.InitializeResult in project eclipse.jdt.ls by eclipse.
the class InitHandlerTest method testWillSaveAndWillSaveWaitUntilCapabilities.
@Test
public void testWillSaveAndWillSaveWaitUntilCapabilities() throws Exception {
ClientPreferences mockCapabilies = mock(ClientPreferences.class);
when(mockCapabilies.isExecuteCommandDynamicRegistrationSupported()).thenReturn(Boolean.TRUE);
when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);
when(mockCapabilies.isWillSaveRegistered()).thenReturn(Boolean.TRUE);
when(mockCapabilies.isWillSaveWaitUntilRegistered()).thenReturn(Boolean.TRUE);
InitializeResult result = initialize(true);
Either<TextDocumentSyncKind, TextDocumentSyncOptions> o = result.getCapabilities().getTextDocumentSync();
assertTrue(o.isRight());
assertTrue(o.getRight().getWillSave());
assertTrue(o.getRight().getWillSaveWaitUntil());
}
use of org.eclipse.lsp4j.InitializeResult in project eclipse.jdt.ls by eclipse.
the class InitHandlerTest method testExecuteCommandProvider.
@Test
public void testExecuteCommandProvider() throws Exception {
ClientPreferences mockCapabilies = mock(ClientPreferences.class);
when(mockCapabilies.isExecuteCommandDynamicRegistrationSupported()).thenReturn(Boolean.FALSE);
when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);
InitializeResult result = initialize(false);
List<String> commands = result.getCapabilities().getExecuteCommandProvider().getCommands();
assertFalse(commands.isEmpty());
}
Aggregations