Skip to content

Commit

Permalink
Fixes for VSCode
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad committed Apr 22, 2024
1 parent 46fa730 commit 971ac0d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 41 deletions.
4 changes: 4 additions & 0 deletions src/renderer/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3574,6 +3574,10 @@ export class SDFGRenderer extends EventEmitter {
return this.sdfg;
}

public getCFGList(): CFGListType {
return this.cfgList;
}

public get_graph(): DagreGraph | null {
return this.graph;
}
Expand Down
100 changes: 62 additions & 38 deletions src/sdfv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,26 @@ import {
Point2D,
sdfg_property_to_string,
showErrorModal,
traverseSDFGScopes
traverseSDFGScopes,
} from './index';
import { LViewRenderer } from './local_view/lview_renderer';
import {
RuntimeMicroSecondsOverlay
RuntimeMicroSecondsOverlay,
} from './overlays/runtime_micro_seconds_overlay';
import { OverlayManager } from './overlay_manager';
import { SDFGRenderer } from './renderer/renderer';
import {
AccessNode, Edge, Memlet, NestedSDFG, SDFG,
SDFGElement,
SDFGNode,
State
State,
} from './renderer/renderer_elements';
import { htmlSanitize } from './utils/sanitization';
import { checkCompatLoad, parse_sdfg, stringify_sdfg } from './utils/sdfg/json_serializer';
import {
checkCompatLoad,
parse_sdfg,
stringify_sdfg,
} from './utils/sdfg/json_serializer';
import { SDFVSettings } from './utils/sdfv_settings';

declare const vscode: any;
Expand All @@ -47,7 +51,8 @@ export class SDFV {
public static SCOPE_LOD: number = 0.75; // 0.75
// Points-per-pixel threshold for not drawing memlets/interstate edges.
public static EDGE_LOD: number = 5.0; // 5.0
// Points-per-pixel threshold for not drawing Arrowheads of memlets/interstate edges.
// Points-per-pixel threshold for not drawing Arrowheads of
// memlets/interstate edges.
public static ARROW_LOD: number = 2.0; // 2.0
// Points-per-pixel threshold for not drawing connectors.
public static CONNECTOR_LOD = 2.0; // 2.0
Expand Down Expand Up @@ -103,10 +108,11 @@ export class SDFV {
else
window.getSelection()?.removeAllRanges();

if (right)
if (right) {
right.style.width = Math.max(
((e.view ? e.view.innerWidth - e.pageX : 0)), 20
) + 'px';
}
};

if (bar) {
Expand Down Expand Up @@ -169,7 +175,7 @@ export class SDFV {
const stack: any[] = [sidebar];

// Add elements to tree view in sidebar
traverseSDFGScopes(sdfg, (node: SDFGNode, parent: DagreGraph) => {
traverseSDFGScopes(sdfg, (node, parent) => {
// Skip exit nodes when scopes are known
if (node.type().endsWith('Exit') &&
node.data.node.scope_entry >= 0) {
Expand All @@ -187,9 +193,8 @@ export class SDFV {
// If a scope has children, remove the name "Entry" from the type
if (node.type().endsWith('Entry') && node.parent_id && node.id) {
const state = node.parentElem?.data.state.nodes[node.parent_id];
if (state.scope_dict[node.id] !== undefined) {
if (state.scope_dict[node.id] !== undefined)
node_type = node_type.slice(0, -5);
}
}

d.innerHTML = htmlSanitize`
Expand Down Expand Up @@ -310,7 +315,9 @@ export class SDFV {

// If access node, add array information too
if (elem instanceof AccessNode) {
const sdfg_array = elem.sdfg.attributes._arrays[elem.attributes().data];
const sdfg_array = elem.sdfg.attributes._arrays[
elem.attributes().data
];
contents.append($('<br>'));
contents.append($('<h4>', {
text: sdfg_array.type + ' properties:',
Expand Down Expand Up @@ -406,30 +413,33 @@ function init_sdfv(
});
$('#outline').on('click', () => {
const renderer = sdfv.get_renderer();
if (renderer)
if (renderer) {
setTimeout(() => {
const graph = renderer.get_graph();
if (graph)
sdfv.outline(renderer, graph);
}, 1);
}
});
$('#search-btn').on('click', () => {
const renderer = sdfv.get_renderer();
if (renderer)
if (renderer) {
setTimeout(() => {
const graph = renderer.get_graph();
const query = $('#search').val();
if (graph && query)
if (graph && query) {
find_in_graph(
sdfv, renderer, graph, query.toString(),
$('#search-case').is(':checked')
);
}
}, 1);
}
});
$('#advsearch-btn').on('click', (e) => {
e.preventDefault();
const renderer = sdfv.get_renderer();
if (renderer)
if (renderer) {
setTimeout(() => {
const graph = renderer.get_graph();
const code = $('#advsearch').val();
Expand All @@ -440,6 +450,7 @@ function init_sdfv(
);
}
}, 1);
}
return false;
});
$('#search').on('keydown', (e: any) => {
Expand All @@ -461,38 +472,42 @@ function init_sdfv(
add_btns.push(document.getElementById('elem_access_node'));
add_btns.push(document.getElementById('elem_stream'));
add_btns.push(document.getElementById('elem_state'));
if (pan_btn)
if (pan_btn) {
mode_buttons = {
pan: pan_btn,
move: move_btn,
select: select_btn,
add_btns: add_btns,
};
}

if (sdfg !== null) {
const container = document.getElementById('contents');
if (container)
if (container) {
sdfv.set_renderer(new SDFGRenderer(
sdfv, sdfg, container, mouse_event, user_transform, debug_draw,
null, mode_buttons
));
}
}

return sdfv;
}

function start_find_in_graph(sdfv: SDFV): void {
const renderer = sdfv.get_renderer();
if (renderer)
if (renderer) {
setTimeout(() => {
const graph = renderer.get_graph();
const query = $('#search').val();
if (graph && query)
if (graph && query) {
find_in_graph(
sdfv, renderer, graph, query.toString(),
$('#search-case').is(':checked')
);
}
}, 1);
}
}

export function reload_file(sdfv: SDFV): void {
Expand All @@ -511,22 +526,24 @@ function file_read_complete(sdfv: SDFV): void {
const info_field = document.getElementById('task-info-field');

if (result_string && container && info_field) {

// Create the loader element before starting to parse and layout the graph.
// The layouting can take several seconds for large graphs on slow machines.
// The user sees a loading animation in the meantime so that the site doesn't
// appear unresponsive.
// The loader element is removed/cleared again at the end of the layout function in
// the SDFGRenderer.
const loaderDiv = document.createElement("div");
loaderDiv.classList.add("loader");
// Create the loader element before starting to parse and layout the
// graph. The layouting can take several seconds for large graphs on
// slow machines. The user sees a loading animation in the meantime so
// that the site doesn't appear unresponsive. The loader element is
// removed/cleared again at the end of the layout function in the
// SDFGRenderer.
const loaderDiv = document.createElement('div');
loaderDiv.classList.add('loader');
info_field.appendChild(loaderDiv);

// Use setTimeout function to force the browser to reload the dom with the above loader element.
// Use setTimeout function to force the browser to reload the dom with
// the above loader element.
setTimeout(() => {
const sdfg = checkCompatLoad(parse_sdfg(result_string));
sdfv.get_renderer()?.destroy();
sdfv.set_renderer(new SDFGRenderer(sdfv, sdfg, container, mouse_event));
sdfv.set_renderer(
new SDFGRenderer(sdfv, sdfg, container, mouse_event)
);
sdfv.close_menu();
}, 20);
}
Expand Down Expand Up @@ -644,8 +661,10 @@ function getParameterByName(name: string): string | null {
name = name.replace(/[\[\]]/g, '\\$&');
const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
if (!results)
return null;
if (!results[2])
return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

Expand Down Expand Up @@ -683,10 +702,8 @@ function find_recursive(
if (predicate(graph, node))
results.push(node);
// Enter states or nested SDFGs recursively
if (node.data.graph) {
if (node.data.graph)
find_recursive(node.data.graph, predicate, results);

}
}
for (const edgeid of graph.edges()) {
const edge = graph.edge(edgeid);
Expand All @@ -696,7 +713,8 @@ function find_recursive(
}

export function find_in_graph_predicate(
sdfv: SDFV, renderer: SDFGRenderer, sdfg: DagreGraph, predicate: CallableFunction
sdfv: SDFV, renderer: SDFGRenderer, sdfg: DagreGraph,
predicate: CallableFunction
): void {
sdfv.sidebar_set_title('Search Results');

Expand All @@ -715,7 +733,9 @@ export function find_in_graph_predicate(
const d = document.createElement('div');
d.className = 'context_menu_option';
d.innerHTML = htmlSanitize`${result.type()} ${result.label()}`;
d.onclick = () => { renderer.zoom_to_view([result]); };
d.onclick = () => {
renderer.zoom_to_view([result]);
};
d.onmouseenter = () => {
if (!result.highlighted) {
result.highlighted = true;
Expand Down Expand Up @@ -919,7 +939,7 @@ $(() => {
vscode;
if (vscode)
return;
} catch (_) {}
} catch (_) { }

// Set the default settings based on the current script's attributes
// or URL parameters.
Expand Down Expand Up @@ -974,7 +994,11 @@ declare global {
// Exported functions
parse_sdfg: (sdfg_json: string) => JsonSDFG;
stringify_sdfg: (sdfg: JsonSDFG) => string;
init_sdfv: (sdfg: JsonSDFG, user_transform?: DOMMatrix | null, debug_draw?: boolean, existing_sdfv?: SDFV | null, toolbar?: boolean, minimap?: boolean | null) => SDFV;
init_sdfv: (
sdfg: JsonSDFG, user_transform?: DOMMatrix | null,
debug_draw?: boolean, existing_sdfv?: SDFV | null,
toolbar?: boolean, minimap?: boolean | null
) => SDFV;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/utils/sdfg/traversal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved.

import { DagreGraph } from '../../index';
import { DagreGraph, SDFGNode } from '../../index';

/**
* Receives a callback that accepts (node, parent graph) and returns a value.
Expand All @@ -10,8 +10,8 @@ import { DagreGraph } from '../../index';
* signature as `func`).
**/
export function traverseSDFGScopes(
sdfg: DagreGraph, func: CallableFunction,
postSubscopeFunc?: CallableFunction
sdfg: DagreGraph, func: (gNode: SDFGNode, g: DagreGraph) => boolean,
postSubscopeFunc?: (gNode: SDFGNode, g: DagreGraph) => void
): void {
function scopesRecursive(
graph: DagreGraph, nodes: string[], processedNodes?: Set<string>
Expand Down

0 comments on commit 971ac0d

Please sign in to comment.