Skip to content

Commit

Permalink
feat: store template id in the user ls definition
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Feb 7, 2025
1 parent e841a75 commit 8363e8c
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ private void loadServersAndMappingFromSettings() {
// Register server definition from settings
addServerDefinitionWithoutNotification(new UserDefinedLanguageServerDefinition(
serverId,
launch.getTemplateId(),
launch.getServerName(),
"",
launch.getCommandLine(),
Expand Down Expand Up @@ -370,6 +371,7 @@ private void addServerDefinitionWithoutNotification(@NotNull LanguageServerDefin
// Update settings
if (serverDefinition instanceof UserDefinedLanguageServerDefinition definitionFromSettings) {
UserDefinedLanguageServerSettings.UserDefinedLanguageServerItemSettings settings = new UserDefinedLanguageServerSettings.UserDefinedLanguageServerItemSettings();
settings.setTemplateId(definitionFromSettings.getTemplateId());
settings.setServerId(languageServerId);
settings.setServerName(definitionFromSettings.getDisplayName());
settings.setCommandLine(definitionFromSettings.getCommandLine());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public static class UserDefinedLanguageServerItemSettings {

private String serverId;

private String templateId;

private String serverName;

private String commandLine;
Expand Down Expand Up @@ -134,6 +136,14 @@ public void setServerId(String serverId) {
this.serverId = serverId;
}

public String getTemplateId() {
return templateId;
}

public void setTemplateId(String templateId) {
this.templateId = templateId;
}

public String getServerName() {
return serverName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public String getName() {
public static final String CLIENT_SETTINGS_FILE_NAME = "clientSettings.json";
public static final String README_FILE_NAME = "README.md";

public static final String ID_JSON_PROPERTY = "id";
public static final String NAME_JSON_PROPERTY = "name";
public static final String LANGUAGE_ID_JSON_PROPERTY = "languageId";
public static final String FILE_TYPE_JSON_PROPERTY = "fileType";
public static final String DEFAULT_JSON_PROPERTY = "default";
Expand All @@ -52,7 +54,6 @@ public String getName() {
public static final String LANGUAGE_MAPPINGS_JSON_PROPERTY = "languageMappings";
public static final String PATTERNS_JSON_PROPERTY = "patterns";
public static final String FILE_TYPE_MAPPINGS_JSON_PROPERTY = "fileTypeMappings";
public static final String NAME_JSON_PROPERTY = "name";

private static final String WINDOWS_KEY = "windows";
private static final String MAC_KEY = "mac";
Expand All @@ -61,6 +62,7 @@ public String getName() {

private static final String OS_KEY = SystemInfo.isWindows ? WINDOWS_KEY : (SystemInfo.isMac ? MAC_KEY : (SystemInfo.isUnix ? UNIX_KEY : null));

private String id;
private String name;
private Map<String /* OS */, String /* program args */> programArgs;

Expand All @@ -75,6 +77,14 @@ public String getName() {
private String initializationOptions;
private String clientConfiguration;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public LanguageServerTemplate deserialize(JsonElement jsonElement, Type type, Js
JsonObject jsonObject = jsonElement.getAsJsonObject();
LanguageServerTemplate languageServerTemplate = new LanguageServerTemplate();

var id = jsonObject.get(ID_JSON_PROPERTY);
languageServerTemplate.setId(id != null ? id.getAsString() : null);
languageServerTemplate.setName(jsonObject.get(NAME_JSON_PROPERTY).getAsString());
JsonObject programArgs = jsonObject.get(PROGRAM_ARGS_JSON_PROPERTY).getAsJsonObject();
if (programArgs != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void actionPerformed(ActionEvent e) {
};
}

private void loadFromTemplate(LanguageServerTemplate template) {
private void loadFromTemplate(@NotNull LanguageServerTemplate template) {
// Update name
var serverName = this.languageServerPanel.getServerName();
serverName.setText(template.getName() != null ? template.getName() : "");
Expand Down Expand Up @@ -291,6 +291,7 @@ protected void doOKAction() {
List<ServerMappingSettings> mappingSettings = this.languageServerPanel.getMappingsPanel().getAllMappings();

// Register language server and mappings definition
String templateId = currentTemplate != null && currentTemplate != LanguageServerTemplate.NEW_TEMPLATE ? currentTemplate.getId() : null;
String serverName = this.languageServerPanel.getServerName().getText();
String commandLine = this.languageServerPanel.getCommandLine().getText();
Map<String, String> userEnvironmentVariables = this.languageServerPanel.getEnvironmentVariables().getEnvs();
Expand All @@ -300,6 +301,7 @@ protected void doOKAction() {
String initializationOptions = this.languageServerPanel.getInitializationOptionsWidget().getText();
String clientConfiguration = this.languageServerPanel.getClientConfigurationWidget().getText();
UserDefinedLanguageServerDefinition definition = new UserDefinedLanguageServerDefinition(serverId,
templateId,
serverName,
"",
commandLine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class UserDefinedLanguageServerDefinition extends LanguageServerDefinitio

@SerializedName("displayName")
private String name;
private String templateId;
private String commandLine;
private Map<String, String> userEnvironmentVariables;
private boolean includeSystemEnvironmentVariables;
Expand All @@ -54,6 +55,7 @@ public class UserDefinedLanguageServerDefinition extends LanguageServerDefinitio
private ClientConfigurationSettings clientConfiguration;

public UserDefinedLanguageServerDefinition(@NotNull String id,
@Nullable String templateId,
@NotNull String name,
@Nullable String description,
@NotNull String commandLine,
Expand All @@ -65,6 +67,7 @@ public UserDefinedLanguageServerDefinition(@NotNull String id,
@Nullable String clientConfigurationContent) {
super(id, name, description, true, null, false);
this.name = name;
this.templateId = templateId;
this.commandLine = commandLine;
this.userEnvironmentVariables = userEnvironmentVariables;
this.includeSystemEnvironmentVariables = includeSystemEnvironmentVariables;
Expand All @@ -84,6 +87,7 @@ public UserDefinedLanguageServerDefinition(@NotNull String id,
@Nullable String configurationContent,
@Nullable String initializationOptionsContent) {
this(id,
null,
name,
description,
commandLine,
Expand Down Expand Up @@ -115,6 +119,16 @@ public UserDefinedLanguageServerDefinition(@NotNull String id,
return new UserDefinedClientFeatures();
}

/**
* Returns the template id which has been used to create the language server definition and null otherwise.
*
* @return the template id which has been used to create the language server definition and null otherwise.
*/
@Nullable
public String getTemplateId() {
return templateId;
}

public void setName(String name) {
this.name = name;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/sourcekit-lsp/template.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "sourcekit-lsp",
"name": "SourceKit-LSP",
"programArgs": {
"default": "sourcekit-lsp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class LanguageServerDefinitionSerializerTest {
public void testBasicUserDefinedLsSerialization() {
UserDefinedLanguageServerDefinition lsDef = new UserDefinedLanguageServerDefinition(
"id",
null,
"lsName",
"description",
"./start.sh",
Expand All @@ -56,6 +57,7 @@ public void testBasicUserDefinedLsSerialization() {
public void testLanguageMapping() {
UserDefinedLanguageServerDefinition lsDef = new UserDefinedLanguageServerDefinition(
"id",
null,
"lsName",
"description",
"./start.sh",
Expand Down Expand Up @@ -84,6 +86,7 @@ public void testLanguageMapping() {
public void testFilePatternsMapping() {
UserDefinedLanguageServerDefinition lsDef = new UserDefinedLanguageServerDefinition(
"id",
null,
"lsName",
"description",
"./start.sh",
Expand Down Expand Up @@ -119,6 +122,7 @@ public void testFilePatternsMapping() {
public void testFileTypeMappings() {
UserDefinedLanguageServerDefinition lsDef = new UserDefinedLanguageServerDefinition(
"id",
null,
"lsName",
"description",
"./start.sh",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private void runExport(List<LanguageServerDefinition> templates, int expectedCou
private UserDefinedLanguageServerDefinition createUserDefinedLanguageServerDefinition(String identifier) {
return new UserDefinedLanguageServerDefinition(
identifier,
null,
identifier,
null,
"cmd",
Expand Down

0 comments on commit 8363e8c

Please sign in to comment.