Skip to content

Commit

Permalink
feat: Provide UI settings for Language Servers (#843)
Browse files Browse the repository at this point in the history
Fixes #843

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed May 9, 2023
1 parent 39fb795 commit fbc7788
Show file tree
Hide file tree
Showing 14 changed files with 662 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.extensions.PluginId;
import com.redhat.devtools.intellij.quarkus.TelemetryService;
import com.redhat.devtools.intellij.quarkus.lsp4ij.server.JavaProcessStreamConnectionProvider;
import com.redhat.devtools.intellij.quarkus.lsp4ij.server.JavaProcessCommandBuilder;
import com.redhat.devtools.intellij.quarkus.lsp4ij.server.ProcessStreamConnectionProvider;

import java.io.File;
Expand All @@ -27,21 +27,17 @@
/**
* Start the MicroProfile language server process with the Quarkus extension.
*/
public class QuarkusServer extends JavaProcessStreamConnectionProvider {

private static final String QUARKUS_DEBUG_PORT = "quarkus.debug.port";
public class QuarkusServer extends ProcessStreamConnectionProvider {

public QuarkusServer() {
IdeaPluginDescriptor descriptor = PluginManager.getPlugin(PluginId.getId("com.redhat.devtools.intellij.quarkus"));
File lsp4mpServerPath = new File(descriptor.getPath(), "lib/server/org.eclipse.lsp4mp.ls-uber.jar");
File quarkusServerPath = new File(descriptor.getPath(), "lib/server/com.redhat.quarkus.ls.jar");
String debugPort = System.getProperty(QUARKUS_DEBUG_PORT);

List<String> commands = createJavaCommands(debugPort);
commands.add("-jar");
commands.add(lsp4mpServerPath.getAbsolutePath());
commands.add("-cp");
commands.add(quarkusServerPath.getAbsolutePath());
List<String> commands = new JavaProcessCommandBuilder("quarkus")
.setJar(lsp4mpServerPath.getAbsolutePath())
.setCp(quarkusServerPath.getAbsolutePath())
.create();
commands.add("-DrunAsync=true");
super.setCommands(commands);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.devtools.intellij.quarkus.lsp4ij;

import com.intellij.DynamicBundle;
import com.intellij.json.JsonBundle;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.PropertyKey;

import java.util.function.Supplier;

/**
* Language server messages bundle.
*/
public final class LanguageServerBundle extends DynamicBundle {

@NonNls public static final String BUNDLE = "messages.LanguageServerBundle";
private static final LanguageServerBundle INSTANCE = new LanguageServerBundle();

private LanguageServerBundle() {
super(BUNDLE);
}

@NotNull
public static @Nls String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, Object @NotNull ... params) {
return INSTANCE.getMessage(key, params);
}

@NotNull
public static Supplier<@Nls String> messagePointer(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, Object @NotNull ... params) {
return INSTANCE.getLazyMessage(key, params);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*******************************************************************************
* Copyright (c) 2019 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at https://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package com.redhat.devtools.intellij.quarkus.lsp4ij;

import com.intellij.lang.Language;
Expand All @@ -21,6 +31,10 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
* Language server registry.
*
*/
public class LanguageServersRegistry {
private static final Logger LOGGER = LoggerFactory.getLogger(LanguageServersRegistry.class);

Expand All @@ -29,10 +43,12 @@ public abstract static class LanguageServerDefinition {
public final @Nonnull String label;
public final boolean isSingleton;
public final @Nonnull Map<Language, String> languageIdMappings;
public String description;

public LanguageServerDefinition(@Nonnull String id, @Nonnull String label, boolean isSingleton) {
public LanguageServerDefinition(@Nonnull String id, @Nonnull String label, String description, boolean isSingleton) {
this.id = id;
this.label = label;
this.description = description;
this.isSingleton = isSingleton;
this.languageIdMappings = new ConcurrentHashMap<>();
}
Expand All @@ -41,6 +57,11 @@ public void registerAssociation(@Nonnull Language language, @Nonnull String lang
this.languageIdMappings.put(language, languageId);
}

@Nonnull
public String getDisplayName() {
return label != null ? label : id;
}

public abstract StreamConnectionProvider createConnectionProvider();

public LanguageClientImpl createLanguageClient(Project project) {
Expand All @@ -57,7 +78,7 @@ static class ExtensionLanguageServerDefinition extends LanguageServerDefinition
private ServerExtensionPointBean extension;

public ExtensionLanguageServerDefinition(ServerExtensionPointBean element) {
super(element.id, element.label, element.singleton);
super(element.id, element.label, element.description, element.singleton);
this.extension = element;
}

Expand Down Expand Up @@ -224,6 +245,12 @@ private Set<LanguageServerDefinition> getAvailableLSFor(Language language) {
return res;
}

public Set<LanguageServerDefinition> getAllDefinitions() {
return connections
.stream()
.map(definition -> definition.getValue())
.collect(Collectors.toSet());
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.serviceContainer.BaseKeyedLazyInstance;
import com.intellij.util.xmlb.annotations.Attribute;
import com.intellij.util.xmlb.annotations.Tag;
import com.redhat.devtools.intellij.quarkus.lsp4ij.server.StreamConnectionProvider;
import org.jetbrains.annotations.Nullable;

Expand All @@ -16,6 +17,9 @@ public class ServerExtensionPointBean extends BaseKeyedLazyInstance<StreamConnec
@Attribute("label")
public String label;

@Tag("description")
public String description;

@Attribute("class")
public String clazz;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at https://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package com.redhat.devtools.intellij.quarkus.lsp4ij.server;

import com.redhat.devtools.intellij.quarkus.lsp4ij.settings.LanguageServerSettingsState;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Stream;

/**
* A builder to create Java process command.
*/
public class JavaProcessCommandBuilder {

private final String languageId;

private String javaPath;

private String debugPort;

private boolean debugSuspend;
private String jar;

private String cp;

public JavaProcessCommandBuilder(String languageId) {
this.languageId = languageId;
setJavaPath(computeJavaPath());
LanguageServerSettingsState.LanguageServerDefinitionSettings settings = LanguageServerSettingsState.getInstance().getLanguageServerSettings(languageId);
if (settings != null) {
setDebugPort(settings.getDebugPort());
setDebugSuspend(settings.isDebugSuspend());
}
}

public JavaProcessCommandBuilder setJavaPath(String javaPath) {
this.javaPath = javaPath;
return this;
}

public JavaProcessCommandBuilder setDebugPort(String debugPort) {
this.debugPort = debugPort;
return this;
}

public JavaProcessCommandBuilder setDebugSuspend(boolean debugSuspend) {
this.debugSuspend = debugSuspend;
return this;
}

public JavaProcessCommandBuilder setJar(String jar) {
this.jar = jar;
return this;
}

public JavaProcessCommandBuilder setCp(String cp) {
this.cp = cp;
return this;
}

public List<String> create() {
List<String> commands = new ArrayList<>();
commands.add(computeJavaPath());
if (debugPort != null && !debugPort.isEmpty()) {
String suspend = debugSuspend ? "y" : "n";
commands.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=" + suspend + ",address=" + debugPort);
}
if(jar != null) {
commands.add("-jar");
commands.add(jar);
}
if(cp != null) {
commands.add("-cp");
commands.add(cp);
}
return commands;
}

private static String computeJavaPath() {
String javaPath = "java";
boolean existsInPath = Stream.of(System.getenv("PATH").split(Pattern.quote(File.pathSeparator))).map(Paths::get)
.anyMatch(path -> Files.exists(path.resolve("java")));
if (!existsInPath) {
File f = new File(System.getProperty("java.home"),
"bin/java" + (OS.current() == OS.WINDOWS ? ".exe" : ""));
javaPath = f.getAbsolutePath();
}
return javaPath;
}
}

This file was deleted.

Loading

0 comments on commit fbc7788

Please sign in to comment.