Skip to content

Commit

Permalink
5.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
smklimenko committed Mar 25, 2024
1 parent e258c81 commit 2f10e83
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 73 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# KdbInsideBrains Changelog

## [5.5.2]

### Fixed

- Floating point precision sessions lost at unclear conditions (precision settings will be lost if you are updateding
from any version before 5.4)
- Tabs binding doesn't work in NewUI

### Added

- Editors to connection binding stored in settings now

## [5.5.1]

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ pluginJavaVersion=17
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html for available build versions
# or https://jb.gg/intellij-platform-builds-list
pluginVerifierVersions=2022.3, 2022.3.3, 2023.1.1, 2023.2.5, 2023.3.4
pluginVerifierVersions=2022.3, 2022.3.3, 2023.1.1, 2023.2.5, 2023.3.6
platformType=IC
#platformVersion=241-EAP-SNAPSHOT
#platformPlugins=java, PsiViewer:241-SNAPSHOT
platformVersion=2023.3.4
platformVersion=2023.3.6
platformPlugins=java, PsiViewer:233.2
#platformVersion=2023.2.5
#platformPlugins=java, PsiViewer:232.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public KdbInstance lookupInstance(String canonicalName) {
}

private InstanceItem lookupInstance(String canonicalName, InstanceItem item) {
if (canonicalName.equals(item.getCanonicalName())) {
if (item.getCanonicalName().equals(canonicalName)) {
return item;
}
if (item instanceof StructuralItem si) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.kdb.inside.brains.lang.binding;

import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;

public class EditorsBindingListener implements FileEditorManagerListener {
private final EditorsBindingService service;

public EditorsBindingListener(Project project) {
service = project.getService(EditorsBindingService.class);
}

@Override
public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
service.editorOpened(file);
}

@Override
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
service.editorClosed(file);
}

@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
final VirtualFile newFile = event.getNewFile();
if (newFile != null) {
service.editorActivated(newFile);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.kdb.inside.brains.lang.binding;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.messages.MessageBusConnection;
import com.intellij.openapi.vfs.VirtualFileManager;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.kdb.inside.brains.core.*;
import org.kdb.inside.brains.settings.KdbSettingsListener;
import org.kdb.inside.brains.settings.KdbSettingsService;
Expand All @@ -17,45 +19,41 @@
import java.util.Map;
import java.util.Objects;

public class EditorsBindingService implements Disposable {
@State(name = "EditorsBinding", storages = {@Storage(value = "kdb-settings.xml")})
public class EditorsBindingService implements Disposable, PersistentStateComponent<Element> {
private boolean disposed;

private VirtualFile activeFile;
private KdbInstance activeInstance;

private EditorsBindingStrategy strategy;

private final Project project;
private final Map<VirtualFile, KdbInstance> connections = new HashMap<>();

private final KdbSettingsService settingsService;
private final MessageBusConnection busConnection;
private final KdbConnectionManager connectionManager;

private final Map<VirtualFile, KdbInstance> connections = new HashMap<>();

private final TheSettingsListener settingsListener = new TheSettingsListener();
private final TheConnectionListener connectionListener = new TheConnectionListener();

public EditorsBindingService(Project project) {
this.project = project;

connectionManager = KdbConnectionManager.getManager(project);
connectionManager.addConnectionListener(connectionListener);

settingsService = KdbSettingsService.getInstance();
settingsService.addSettingsListener(settingsListener);
strategy = settingsService.getExecutionOptions().getBindingStrategy();

busConnection = project.getMessageBus().connect(this);
busConnection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new TheFileEditorManagerListener());
}

public void toggleBinding(boolean bind) {
if (activeInstance == null || activeFile == null || disposed) {
return;
}

if (bind) {
connections.put(activeFile, activeInstance);
} else {
connections.remove(activeFile);
}
changeInstance(activeFile, bind ? activeInstance : null);
}

public boolean isBindable() {
Expand All @@ -75,24 +73,30 @@ public void dispose() {
disposed = true;
settingsService.removeSettingsListener(settingsListener);
connectionManager.removeConnectionListener(connectionListener);
busConnection.disconnect();
connections.clear();
}

protected void editorOpened(@NotNull VirtualFile file) {
if (disposed) {
return;
}

editorActivated(file);
}

private void editorClosed(@NotNull VirtualFile file) {
protected void editorClosed(@NotNull VirtualFile file) {
if (disposed) {
return;
}

connections.remove(file);
changeInstance(file, null);

if (Objects.equals(activeFile, file)) {
activeFile = null;
}
}

private void editorActivated(@NotNull VirtualFile file) {
protected void editorActivated(@NotNull VirtualFile file) {
if (disposed) {
return;
}
Expand All @@ -103,7 +107,7 @@ private void editorActivated(@NotNull VirtualFile file) {
if (instance != null) {
connectionManager.activate(instance);
} else if (activeInstance != null && strategy == EditorsBindingStrategy.TAB_TO_CONNECT) {
connections.put(activeFile, activeInstance);
changeInstance(activeFile, activeInstance);
}
}

Expand All @@ -115,14 +119,48 @@ private void instanceActivated(KdbInstance activated) {
activeInstance = activated;

if (activeFile != null && strategy == EditorsBindingStrategy.CONNECT_TO_TAB) {
if (activated == null) {
connections.remove(activeFile);
} else {
connections.put(activeFile, activeInstance);
changeInstance(activeFile, activeInstance);
}
}

@Override
public @Nullable Element getState() {
final Element e = new Element("bindings");
for (Map.Entry<VirtualFile, KdbInstance> entry : connections.entrySet()) {
e.addContent(new Element("binding").setAttribute("url", entry.getKey().getUrl()).setAttribute("instance", entry.getValue().getCanonicalName()));
}
return e;
}

@Override
public void loadState(@NotNull Element state) {
final KdbScopesManager scopesManager = KdbScopesManager.getManager(project);
final VirtualFileManager fileManager = VirtualFileManager.getInstance();
for (Element child : state.getChildren()) {
final String url = child.getAttributeValue("url");
final String inst = child.getAttributeValue("instance");
if (url == null || inst == null) {
continue;
}
final VirtualFile vf = fileManager.findFileByUrl(url);
if (vf == null || !vf.exists()) {
continue;
}
final KdbInstance instance = scopesManager.lookupInstance(inst);
if (instance == null) {
continue;
}
connections.put(vf, instance);
}
}

private void changeInstance(VirtualFile file, KdbInstance instance) {
if (instance == null) {
connections.remove(file);
} else {
connections.put(file, instance);
}
}

private class TheSettingsListener implements KdbSettingsListener {
@Override
Expand All @@ -134,25 +172,10 @@ public void settingsChanged(KdbSettingsService service, SettingsBean<?> bean) {
}
}

private class TheFileEditorManagerListener implements FileEditorManagerListener {
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
final VirtualFile newFile = event.getNewFile();
if (newFile != null) {
editorActivated(newFile);
}
}

@Override
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
editorClosed(file);
}
}

private class TheConnectionListener implements KdbConnectionListener {
@Override
public void connectionActivated(InstanceConnection deactivated, InstanceConnection activated) {
instanceActivated(activated == null ? null : activated.getInstance());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.annotations.Transient;
import org.jetbrains.annotations.Nullable;
import org.kdb.inside.brains.core.ExecutionOptions;
import org.kdb.inside.brains.core.InstanceOptions;
Expand Down Expand Up @@ -157,11 +156,6 @@ public void loadState(State state) {
myState.setCredentialPlugins(state.credentialPlugins);
myState.setInspectorOptions(state.inspectorOptions);
myState.setNumericalOptions(state.numericalOptions);

// Legacy migration. To be removed one day
if (state.legacyConsoleOptions.floatPrecision != -1) {
myState.numericalOptions.setFloatPrecision(state.legacyConsoleOptions.floatPrecision);
}
}

public static KdbSettingsService getInstance() {
Expand All @@ -171,10 +165,6 @@ public static KdbSettingsService getInstance() {
return instance;
}

private static final class LegacyConsoleOptions {
private int floatPrecision;
}

public static class State {
private final List<String> credentialPlugins = new ArrayList<>();
private final ChartOptions chartOptions = new ChartOptions();
Expand All @@ -185,10 +175,6 @@ public static class State {
private final InspectorOptions inspectorOptions = new InspectorOptions();
private final NumericalOptions numericalOptions = new NumericalOptions();

@Transient
// Collection of all legacy options for migration copied from other options
private final LegacyConsoleOptions legacyConsoleOptions = new LegacyConsoleOptions();

public List<String> getCredentialPlugins() {
return credentialPlugins;
}
Expand All @@ -214,7 +200,6 @@ public ConsoleOptions getConsoleOptions() {

public void setConsoleOptions(ConsoleOptions consoleOptions) {
this.consoleOptions.copyFrom(consoleOptions);
legacyConsoleOptions.floatPrecision = consoleOptions.getLegacyFloatPrecision();
}

public InstanceOptions getInstanceOptions() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.kdb.inside.brains.view.console;

import com.intellij.util.xmlb.annotations.Property;
import org.kdb.inside.brains.settings.SettingsBean;

import java.util.Objects;
Expand All @@ -15,16 +14,6 @@ public final class ConsoleOptions implements SettingsBean<ConsoleOptions> {
private boolean clearTableResult = true;
private ConsoleSplitType splitType = ConsoleSplitType.NO;

@Property
@Deprecated(forRemoval = true)
private int floatPrecision = -1;

public int getLegacyFloatPrecision() {
int asd = floatPrecision;
floatPrecision = -1;
return asd;
}

public boolean isWrapStrings() {
return wrapStrings;
}
Expand Down Expand Up @@ -93,12 +82,12 @@ public void setClearTableResult(boolean clearTableResult) {
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ConsoleOptions that)) return false;
return floatPrecision == that.floatPrecision && wrapStrings == that.wrapStrings && prefixSymbols == that.prefixSymbols && enlistArrays == that.enlistArrays && dictAsTable == that.dictAsTable && listAsTable == that.listAsTable && consoleBackground == that.consoleBackground && clearTableResult == that.clearTableResult && splitType == that.splitType;
return wrapStrings == that.wrapStrings && prefixSymbols == that.prefixSymbols && enlistArrays == that.enlistArrays && dictAsTable == that.dictAsTable && listAsTable == that.listAsTable && consoleBackground == that.consoleBackground && clearTableResult == that.clearTableResult && splitType == that.splitType;
}

@Override
public int hashCode() {
return Objects.hash(floatPrecision, wrapStrings, prefixSymbols, enlistArrays, dictAsTable, listAsTable, consoleBackground, clearTableResult, splitType);
return Objects.hash(wrapStrings, prefixSymbols, enlistArrays, dictAsTable, listAsTable, consoleBackground, clearTableResult, splitType);
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@
</group>
</actions>

<projectListeners>
<listener class="org.kdb.inside.brains.lang.binding.EditorsBindingListener"
topic="com.intellij.openapi.fileEditor.FileEditorManagerListener"/>
</projectListeners>

<extensions defaultExtensionNs="com.intellij">
<fileType name="KDB+ Q" implementationClass="org.kdb.inside.brains.QFileType"
fieldName="INSTANCE" language="q" extensions="q;k"/>
Expand Down
2 changes: 1 addition & 1 deletion version.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pluginVersion=5.5.1
pluginVersion=5.5.2

0 comments on commit 2f10e83

Please sign in to comment.