Skip to content
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

⚡️Open node's script at specific line #160

Merged
merged 8 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions src/commands/NodeActionCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,39 @@ export function addNodeActionCommands(
return node ?? null;
}

//Add command to open canvas's node its script
//Add command to open node's script at specific line
commands.addCommand(commandIDs.openScript, {
execute: () => {
const widget = tracker.currentWidget?.content as XPipePanel;
execute: async (args) => {
const node = selectedNode();
app.commands.execute(commandIDs.openDocManager, {
path: node.extras.path
const nodePath = args['nodePath'] as string ?? node.extras.path;
const nodeName = args['nodeName'] as string ?? node.name;
const nodeLineNo = args['nodeLineNo'] as number ?? node.extras.lineNo;

if (nodeName.startsWith('Literal') || nodeName.startsWith('Hyperparameter')) {
showDialog({
title: `${node.name} don't have its own script`,
buttons: [Dialog.warnButton({ label: 'OK' })]
})
return;
}

// Open node's file name
const newWidget = await app.commands.execute(
commandIDs.openDocManager,
{
path: nodePath
}
);
newWidget.context.ready.then(() => {
// Go to end of node's line first before go to its class
app.commands.execute('codemirror:go-to-line', {
line: nodeLineNo[0].end_lineno
}).then(() => {
app.commands.execute('codemirror:go-to-line', {
line: nodeLineNo[0].lineno
})
})
});
widget.xircuitsApp.getDiagramEngine().repaintCanvas();
}
});

Expand Down
6 changes: 4 additions & 2 deletions src/context-menu/TrayItemPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ export class TrayItemPanel extends React.Component<TrayItemWidgetProps> {
onClick={(event) => {
if (event.ctrlKey || event.metaKey) {
const { commands } = this.props.app;
commands.execute('docmanager:open', {
path: this.props.currentNode["file_path"]
commands.execute(commandIDs.openScript, {
nodePath: this.props.currentNode["file_path"],
nodeName: this.props.currentNode["class"],
nodeLineNo: this.props.currentNode["lineno"]
});
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/tray_library/AdvanceComponentLib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export function AdvancedComponentLibrary(props: AdvancedComponentLibraryProps) {
extras: {
"type": nodeData.type,
"path": nodeData.file_path,
"description": nodeData.docstring
"description": nodeData.docstring,
"lineNo": nodeData.lineno
}
});
node.addInPortEnhance('▶', 'in-0');
Expand Down
12 changes: 8 additions & 4 deletions src/tray_library/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,14 @@ export default function Sidebar(props: SidebarProps) {
name: componentVal.task,
color: componentVal.color,
path: componentVal.file_path,
docstring: componentVal.docstring
docstring: componentVal.docstring,
lineNo: componentVal.lineno
}}
name={componentVal.task}
color={componentVal.color}
app={props.lab}
path={componentVal.file_path} />
path={componentVal.file_path}
lineNo= {componentVal.lineno}/>
</div>
);
}
Expand All @@ -253,12 +255,14 @@ export default function Sidebar(props: SidebarProps) {
name: val.task,
color: val.color,
path: val.file_path,
docstring: val.docstring
docstring: val.docstring,
lineNo: val.lineno
}}
name={val.task}
color={val.color}
app={props.lab}
path={val.file_path} />
path={val.file_path}
lineNo= {val.lineno} />
</div>
);
})
Expand Down
17 changes: 12 additions & 5 deletions src/tray_library/TrayItemWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import * as React from 'react';
import styled from '@emotion/styled';

import { JupyterFrontEnd } from '@jupyterlab/application';
import { commandIDs } from '../components/xircuitBodyWidget';

export interface TrayItemWidgetProps {
model: any;
color: any;
name: string;
path: string;
app: JupyterFrontEnd;
lineNo: number;
}

interface TrayStyledProps {
Expand Down Expand Up @@ -41,17 +43,22 @@ export class TrayItemWidget extends React.Component<TrayItemWidgetProps> {
onClick={(event) => {
if (event.ctrlKey || event.metaKey) {
const { commands } = this.props.app;
commands.execute('docmanager:open', {
path: this.props.path
commands.execute(commandIDs.openScript, {
nodePath: this.props.path,
nodeName: this.props.name,
nodeLineNo: this.props.lineNo
});

}
this.forceUpdate();
}}
onDoubleClick={(event) => {
onDoubleClick={() => {
if (this.props.path != "") {
const { commands } = this.props.app;
commands.execute('docmanager:open', {
path: this.props.path
commands.execute(commandIDs.openScript, {
nodePath: this.props.path,
nodeName: this.props.name,
nodeLineNo: this.props.lineNo
});
}
this.forceUpdate();
Expand Down
9 changes: 8 additions & 1 deletion xircuits/handlers/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ def extract_component(self, node: ast.ClassDef, file_path, python_path):
]

docstring = ast.get_docstring(node)
lineno = [
{
"lineno": node.lineno,
"end_lineno": node.end_lineno
}
]

output = {
"class": name,
Expand All @@ -170,7 +176,8 @@ def extract_component(self, node: ast.ClassDef, file_path, python_path):
"category": category,
"type": "debug",
"variables": variables,
"docstring": docstring
"docstring": docstring,
"lineno" : lineno
}
output.update(keywords)

Expand Down