-
Notifications
You must be signed in to change notification settings - Fork 98
Load and save variable filters #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"title": "Variable Inspector", | ||
"description": "jupyterlab-variableinspector settings.", | ||
"type": "object", | ||
"properties": { | ||
"filteredTypes": { | ||
"type": "array", | ||
"title": "Filter variables by type", | ||
"description": "Filters out all variables with types matching the given filter", | ||
"default": [] | ||
}, | ||
"filteredNames": { | ||
"type": "array", | ||
"title": "Filter variables by name", | ||
"description": "Filters out all variables with names matching the given filter", | ||
"default": [] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import { VariableInspectorManager } from './manager'; | |
import { VariableInspectorPanel } from './variableinspector'; | ||
|
||
import { IVariableInspector, IVariableInspectorManager } from './tokens'; | ||
import { ISettingRegistry } from '@jupyterlab/settingregistry'; | ||
|
||
namespace CommandIDs { | ||
export const open = 'variableinspector:open'; | ||
|
@@ -33,28 +34,36 @@ namespace CommandIDs { | |
* A service providing variable introspection. | ||
*/ | ||
const variableinspector: JupyterFrontEndPlugin<IVariableInspectorManager> = { | ||
id: '@lckr/jupyterlab_variableinspector', | ||
requires: [ICommandPalette, ILayoutRestorer, ILabShell], | ||
id: '@lckr/jupyterlab_variableinspector:plugin', | ||
requires: [ICommandPalette, ILayoutRestorer, ILabShell, ISettingRegistry], | ||
provides: IVariableInspectorManager, | ||
autoStart: true, | ||
activate: ( | ||
activate: async ( | ||
app: JupyterFrontEnd, | ||
palette: ICommandPalette, | ||
restorer: ILayoutRestorer, | ||
labShell: ILabShell | ||
): IVariableInspectorManager => { | ||
labShell: ILabShell, | ||
settingRegistry: ISettingRegistry | ||
): Promise<IVariableInspectorManager> => { | ||
const manager = new VariableInspectorManager(); | ||
const category = 'Variable Inspector'; | ||
const command = CommandIDs.open; | ||
const label = 'Open Variable Inspector'; | ||
const namespace = 'variableinspector'; | ||
const tracker = new WidgetTracker<VariableInspectorPanel>({ namespace }); | ||
let settings: ISettingRegistry.ISettings; | ||
|
||
try { | ||
settings = await settingRegistry.load(variableinspector.id); | ||
} catch (error) { | ||
console.error('Failed to load settings for the Git Extension', error); | ||
} | ||
|
||
/** | ||
* Create and track a new inspector. | ||
*/ | ||
function newPanel(): VariableInspectorPanel { | ||
const panel = new VariableInspectorPanel(); | ||
const panel = new VariableInspectorPanel(settings); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not the best approach as it add an opinionated interface on how the filter state is stored. To ease code maintenance, extensibility and testing, the best is to not passed the settings object but rather to add filter setters on the panel. Now the trouble raises from how to pass information from the
But let's go for a simpler fix for now. You could use a const settings = new PromiseDelegate<ISettingRegistry.ISettings>();
Promise.all([settingRegistry.load(variableinspector.id), app.restored])
.then(settings_ => {
settings.resolve(settings_);
})
.catch(error => {
console.error('Failed to load settings for the Git Extension', error);
settings.reject(error);
}); Then change the command execute: async () => {
if (!manager.panel || manager.panel.isDisposed) {
await settings; // Wait for the settings to be loaded
manager.panel = newPanel();
// Best would be to use a single array of filter object: {filter: '', type: ''}[]
// to clarify the binding between the type and the filter
manager.panel.filters = settings.filters;
}
if (!manager.panel.isAttached) {
labShell.add(manager.panel, 'main');
}
if (manager.source) {
manager.source.performInspection();
}
labShell.activateById(manager.panel.id);
} |
||
|
||
panel.id = 'jp-variableinspector'; | ||
panel.title.label = 'Variable Inspector'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good practice wants that asynchronous code should not block the activation of the plugin as it may delay the full application start up.
A better pattern is therefore to use a Promise approach: