Skip to content

Commit

Permalink
Merge pull request #75 from kdbinsidebrains/watches
Browse files Browse the repository at this point in the history
v4.2.0 - Watches has been introduced. Many minor changes.
  • Loading branch information
smklimenko authored Aug 25, 2023
2 parents 6479612 + ad72427 commit f55e113
Show file tree
Hide file tree
Showing 39 changed files with 2,101 additions and 143 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# KdbInsideBrains Changelog

## [4.2.0]

### Added

- New Watches functionality has been introduced. Please check more details
here: https://www.kdbinsidebrains.dev/features/watches
- KdbConsole restores last state after restart, including all open connections

### Changed

- Expanding a value of a dictionary uses the key name (if it's a string) for new tab name instead of default "Expanded
Result"

## [4.1.1]

### Added
Expand All @@ -21,7 +34,7 @@

### Fixed

- Move a Instance Tree item to wrong position causes an exception.
- Move an Instance Tree item to wrong position causes an exception.

## [4.0.0]

Expand Down
6 changes: 4 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ platformType=IC
#platformPlugins=java, PsiViewer:2022.3
#platformVersion=2022.3.3
#platformPlugins=java, PsiViewer:2022.3
platformVersion=2023.1.3
platformPlugins=java, PsiViewer:231-SNAPSHOT
#platformVersion=2023.1.3
#platformPlugins=java, PsiViewer:231-SNAPSHOT
platformVersion=2023.2
platformPlugins=java, PsiViewer:232.2
platformDownloadSources=true
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
2 changes: 1 addition & 1 deletion src/main/java/icons/KdbIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static final class Console {
public static final Icon Table = AllIcons.Nodes.DataTables;
public static final Icon Console = AllIcons.Debugger.Console;

public static final Icon ShowOnlyLast = AllIcons.Debugger.AddToWatch;
public static final Icon ShowHistory = AllIcons.Debugger.AddToWatch;

public static final Icon CopyTable = load("/org/kdb/inside/brains/icons/copyTable.svg");
public static final Icon CopyValues = load("/org/kdb/inside/brains/icons/copyValues.svg");
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/kdb/inside/brains/KdbType.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public boolean isOfType(Object object) {
if (type.atomType != null) {
atomToList.put(type.atomType, type);
}
classToType.put(c.Flip.class, TABLE);
classToType.put(c.Dict.class, DICTIONARY);
}
}

Expand Down Expand Up @@ -183,7 +185,7 @@ public boolean isOfType(Object object) {

private static String typeName(KdbType type) {
final String name = type.name().toLowerCase();
int i = name.indexOf('_');
int i = name.indexOf("_list");
if (i > 0) {
return name.substring(0, i) + "[]";
}
Expand Down Expand Up @@ -249,6 +251,9 @@ public static KdbType typeOf(Object obj) {
if (obj == null) {
return ANY;
}
if (KEYED_TABLE.isOfType(obj)) {
return KEYED_TABLE;
}
return typeOf(obj.getClass());
}

Expand Down
43 changes: 25 additions & 18 deletions src/main/java/org/kdb/inside/brains/core/KdbConnectionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,17 @@ private class QueryProgressive implements Progressive {
private ProgressIndicator indicator;

private final KdbQuery query;
private final Consumer<KdbResult> handler;
// private final Consumer<KdbResult> handler;
private final TheInstanceConnection myConnection;

private final KdbResult result = new KdbResult();

private static final int MB_SIZE = 1024 * 1024;

private QueryProgressive(TheInstanceConnection myConnection, KdbQuery query, Consumer<KdbResult> handler) {
private QueryProgressive(TheInstanceConnection myConnection, KdbQuery query) {
// private QueryProgressive(TheInstanceConnection myConnection, KdbQuery query, Consumer<KdbResult> handler) {
this.query = query;
this.handler = handler;
// this.handler = handler;
this.myConnection = myConnection;
}

Expand Down Expand Up @@ -359,9 +360,10 @@ private void validate(@NotNull ProgressIndicator indicator) throws InterruptedEx
}

private void complete(Object res) {
ApplicationManager.getApplication().invokeLater(() ->
handler.accept(result.complete(res))
);
result.complete(res);
// ApplicationManager.getApplication().invokeLater(() ->
// handler.accept(result.complete(res))
// );
}

public void cancel() {
Expand Down Expand Up @@ -570,6 +572,8 @@ public KdbResult query(KdbQuery query) throws ConcurrentQueryException {
final CompletableFuture<KdbResult> res = new CompletableFuture<>();
doQuery(query, res::complete, true);
return res.get();
} catch (ConcurrentQueryException ex) {
throw ex;
} catch (Exception ex) {
return new KdbResult().complete(ex);
}
Expand Down Expand Up @@ -601,40 +605,43 @@ private void doQuery(KdbQuery query, Consumer<KdbResult> handler, boolean modal)
throw new ConcurrentQueryException("Another query is already running");
}

queryProgressive = new QueryProgressive(this, query, handler);

queryProgressive = new QueryProgressive(this, query);
processQueryStarted(TheInstanceConnection.this, query);
final Task task;
createTask(modal, queryProgressive, () -> {
final KdbResult result = queryProgressive.getResult();
queryProgressive = null;
handler.accept(result);
processQueryFinished(TheInstanceConnection.this, query, result);
}).queue();
}

private Task createTask(boolean modal, QueryProgressive progressive, Runnable finished) {
final String title = "Executing query on instance " + instance;
if (modal) {
task = new Task.Modal(project, "Executing query on instance " + instance, true) {
return new Task.Modal(project, title, true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
queryProgressive.run(indicator);
}

@Override
public void onFinished() {
final KdbResult result = queryProgressive.getResult();
queryProgressive = null;
processQueryFinished(TheInstanceConnection.this, query, result);
finished.run();
}
};
} else {
task = new Task.Backgroundable(project, "Executing query on instance " + instance, true, PerformInBackgroundOption.DEAF) {
return new Task.Backgroundable(project, title, true, PerformInBackgroundOption.DEAF) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
queryProgressive.run(indicator);
}

@Override
public void onFinished() {
final KdbResult result = queryProgressive.getResult();
queryProgressive = null;
processQueryFinished(TheInstanceConnection.this, query, result);
finished.run();
}
};
}
task.queue();
}

private KxConnection safeConnection() throws IOException {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/kdb/inside/brains/core/KdbResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,16 @@ public long getRoundtripNanos() {
public long getRoundtripMillis() {
return finishedMillis - statedMillis;
}

@Override
public String toString() {
return "KdbResult{" +
"time=" + time +
", statedMillis=" + statedMillis +
", statedNanos=" + statedNanos +
", finishedMillis=" + finishedMillis +
", finishedNanos=" + finishedNanos +
", result=" + (result != null ? result.getClass() : "null") +
'}';
}
}
32 changes: 32 additions & 0 deletions src/main/java/org/kdb/inside/brains/core/KdbScopesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,34 @@ public void reorderScopes(List<String> orderedNames) {
listeners.forEach(l -> l.scopesReordered(oldSort, getScopes()));
}

/**
* Implementation is very slow so should be used very often. Implemented just to state recovery and nothing else.
*/
public KdbInstance lookupInstance(String canonicalName) {
for (KdbScope scope : scopes) {
final InstanceItem ii = lookupInstance(canonicalName, scope);
if (ii instanceof KdbInstance i) {
return i;
}
}
return null;
}

private InstanceItem lookupInstance(String canonicalName, InstanceItem item) {
if (canonicalName.equals(item.getCanonicalName())) {
return item;
}
if (item instanceof StructuralItem si) {
for (InstanceItem ii : si) {
final InstanceItem i = lookupInstance(canonicalName, ii);
if (i != null) {
return i;
}
}
}
return null;
}

private void restoreManager() {
scopes.addAll(localScopeHolder.getScopes());
scopes.addAll(sharedScopeHolder.getScopes());
Expand Down Expand Up @@ -136,6 +164,10 @@ public static KdbScopesManager getManager(Project project) {
return project.getService(KdbScopesManager.class);
}

public KdbScope getScope(@NotNull String scopeName) {
return scopes.stream().filter(s -> s.getName().equals(scopeName)).findFirst().orElse(null);
}

private class TheScopeListener implements KdbScopeListener {
@Override
public void itemUpdated(KdbScope scope, InstanceItem item) {
Expand Down
Loading

0 comments on commit f55e113

Please sign in to comment.