Skip to content

Commit

Permalink
fix: fill LSP consoles with server which have no language mappings.
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Dec 8, 2023
1 parent b32c456 commit 6b6e01d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ public static LanguageServersRegistry getInstance() {
return INSTANCE;
}

private final Map<String, LanguageServerDefinition> serverDefinitions = new HashMap<>();

private final List<ContentTypeToLanguageServerDefinition> connections = new ArrayList<>();

private Map<String, LanguageServerIconProviderDefinition> serverIcons = new HashMap<>();
Expand All @@ -192,11 +194,10 @@ private LanguageServersRegistry() {
}

private void initialize() {
Map<String, LanguageServerDefinition> servers = new HashMap<>();
List<LanguageMapping> languageMappings = new ArrayList<>();
for (ServerExtensionPointBean server : ServerExtensionPointBean.EP_NAME.getExtensions()) {
if (server.id != null && !server.id.isEmpty()) {
servers.put(server.id, new ExtensionLanguageServerDefinition(server));
serverDefinitions.put(server.id, new ExtensionLanguageServerDefinition(server));
}
}
for (LanguageMappingExtensionPointBean extension : LanguageMappingExtensionPointBean.EP_NAME.getExtensions()) {
Expand All @@ -211,7 +212,7 @@ private void initialize() {
}

for (LanguageMapping mapping : languageMappings) {
LanguageServerDefinition lsDefinition = servers.get(mapping.languageId);
LanguageServerDefinition lsDefinition = serverDefinitions.get(mapping.languageId);
if (lsDefinition != null) {
registerAssociation(lsDefinition, mapping);
} else {
Expand Down Expand Up @@ -248,16 +249,6 @@ public void registerAssociation(@NotNull LanguageServerDefinition serverDefiniti
connections.add(new ContentTypeToLanguageServerDefinition(language, serverDefinition, mapping.getDocumentMatcher()));
}

public @Nullable
LanguageServerDefinition getDefinition(@NonNull String languageServerId) {
for (ContentTypeToLanguageServerDefinition mapping : this.connections) {
if (mapping.getValue().id.equals(languageServerId)) {
return mapping.getValue();
}
}
return null;
}

/**
* internal class to capture content-type mappings for language servers
*/
Expand All @@ -284,13 +275,33 @@ public DocumentMatcher getDocumentMatcher() {
}
}

public Set<LanguageServerDefinition> getAllDefinitions() {
return connections
.stream()
.map(AbstractMap.SimpleEntry::getValue)
.collect(Collectors.toSet());
/**
* Returns the language server definition for the given language server id and null otherwise.
*
* @param languageServerId the language server id.
*
* @return the language server definition for the given language server id and null otherwise.
*/
public @Nullable LanguageServerDefinition getServerDefinition(@NonNull String languageServerId) {
return serverDefinitions.get(languageServerId);
}

/**
* Returns the registered server definitions.
*
* @return the registered server definitions.
*/
public Collection<LanguageServerDefinition> getServerDefinitions() {
return serverDefinitions.values();
}

/**
* Returns true if the given language is supported by a language server and false otherwise.
*
* @param language the IJ language
*
* @return true if the given language is supported by a language server and false otherwise.
*/
public boolean isLanguageSupported(@NotNull Language language) {
return connections
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private static boolean executeCommandServerSide(@NotNull Command command, @Nulla
return false;
}
LanguageServersRegistry.LanguageServerDefinition languageServerDefinition = LanguageServersRegistry.getInstance()
.getDefinition(languageServerId);
.getServerDefinition(languageServerId);
if (languageServerDefinition == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class LanguageServerExplorer extends SimpleToolWindowPanel implements Dis
private final LanguageServerExplorerLifecycleListener listener;
private boolean disposed;

private TreeSelectionListener treeSelectionListener = event -> {
private final TreeSelectionListener treeSelectionListener = event -> {
if (isDisposed()) {
return;
}
Expand Down Expand Up @@ -101,7 +101,7 @@ private Tree buildTree() {
tree.setRootVisible(false);

// Fill tree will all language server definitions, ordered alphabetically
LanguageServersRegistry.getInstance().getAllDefinitions().stream()
LanguageServersRegistry.getInstance().getServerDefinitions().stream()
.sorted(Comparator.comparing(LanguageServersRegistry.LanguageServerDefinition::getDisplayName))
.map(LanguageServerTreeNode::new)
.forEach(top::add);
Expand All @@ -120,8 +120,7 @@ public void invokePopup(Component comp, int x, int y) {
if (path != null) {
DefaultActionGroup group = null;
Object node = path.getLastPathComponent();
if (node instanceof LanguageServerProcessTreeNode) {
LanguageServerProcessTreeNode processTreeNode = (LanguageServerProcessTreeNode) node;
if (node instanceof LanguageServerProcessTreeNode processTreeNode) {
switch (processTreeNode.getServerStatus()) {
case starting:
case started:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.Collection;
import java.util.Objects;
import java.util.Set;

/**
* UI settings which show:
Expand All @@ -43,13 +43,13 @@ public class LanguageServerListConfigurable extends MasterDetailsComponent imple
private static final String ID = "LanguageServers";

private final Project project;
private final Set<LanguageServersRegistry.LanguageServerDefinition> languageServeDefinitions;
private final Collection<LanguageServersRegistry.LanguageServerDefinition> languageServeDefinitions;

private boolean isTreeInitialized;

public LanguageServerListConfigurable(Project project) {
this.project = project;
this.languageServeDefinitions = LanguageServersRegistry.getInstance().getAllDefinitions();
this.languageServeDefinitions = LanguageServersRegistry.getInstance().getServerDefinitions();
}

@Override
Expand Down Expand Up @@ -85,10 +85,9 @@ protected void initTree() {
.installTreeSpeedSearch(myTree, treePath -> ((MyNode) treePath.getLastPathComponent()).getDisplayName(), true);
}

private MyNode addLanguageServerDefinitionNode(LanguageServersRegistry.LanguageServerDefinition languageServerDefinition) {
private void addLanguageServerDefinitionNode(LanguageServersRegistry.LanguageServerDefinition languageServerDefinition) {
MyNode node = new MyNode(new LanguageServerConfigurable(languageServerDefinition, TREE_UPDATER, project));
addNode(node, myRoot);
return node;
}

private void reloadTree() {
Expand Down

0 comments on commit 6b6e01d

Please sign in to comment.