Skip to content

Commit

Permalink
Merge branch 'gotoSource'
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad committed Jun 29, 2020
2 parents 6319164 + 310b8da commit 02a3248
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 4 deletions.
19 changes: 19 additions & 0 deletions media/sdfv_base_layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<div id="info-title-container">
<h3 id="info-title"></h3>
</div>
<div id="goto-source-btn" class="hidden button">
<span>
Go to source
</span>
</div>
<div class="flex-spacer"></div>
<div id="info-clear-btn" class="hidden button" onclick="clear_info_box();">
<span>
Clear Info &times;
Expand Down Expand Up @@ -94,6 +100,19 @@ <h3 id="info-title"></h3>
}
});

// Send a request to the extension to jump to a specific source code
// file and location, if it exists.
function gotoSource(filePath, startRow, startChar, endRow, endChar) {
vscode.postMessage({
type: 'gotoSource',
file_path: filePath,
startRow: startRow,
startChar: startChar,
endRow: endRow,
endChar: endChar,
});
}

// Resize the canvas correctly if the renderer exists. This gets
// called whenever the body's size changes.
function rendererSendResize() {
Expand Down
16 changes: 13 additions & 3 deletions media/sdfv_embedded.css
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,22 @@ pre.code code {
overflow-y: scroll;
}

#info-title-container {
float: left;
#info-header {
display: flex;
flex-direction: row;
align-items: baseline;
}

.flex-spacer {
flex-grow: 1;
}

#goto-source-btn {
margin: 0 1rem;
}

#info-clear-btn {
float: right;
margin: 0 1rem;
}

#info-clear-btn span {
Expand Down
23 changes: 22 additions & 1 deletion media/sdfv_embedded_overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function clear_info_box() {
$('#info-contents').html('');
$('#info-title').text('');
$('#info-clear-btn').hide();
$('#goto-source-btn').hide();
}

/**
Expand All @@ -37,6 +38,11 @@ function clear_info_box() {
* @param {*} elem The element to display info about
*/
function fill_info_embedded(elem) {
const gotoSourceBtn = $('#goto-source-btn');
// Clear and hide the go to source button.
gotoSourceBtn.hide();
gotoSourceBtn.off('click');

if (elem) {
document.getElementById('info-title').innerText =
elem.type() + ' ' + elem.label();
Expand Down Expand Up @@ -80,6 +86,21 @@ function fill_info_embedded(elem) {
);
if (val === null || val === '')
continue;

if (attr[0] === 'debuginfo') {
gotoSourceBtn.on('click', function() {
gotoSource(
attr[1].filename,
attr[1].start_line,
attr[1].start_column,
attr[1].end_line,
attr[1].end_column
);
});
gotoSourceBtn.show();
continue;
}

const row = $('<tr>').appendTo(attr_table_body);
$('<th>', {
'class': 'key-col',
Expand Down Expand Up @@ -141,7 +162,7 @@ function fill_info_embedded(elem) {
}
}

$('#info-clear-button').show();
$('#info-clear-btn').show();
} else {
clear_info_box();
}
Expand Down
31 changes: 31 additions & 0 deletions src/sdfg_viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,37 @@ export class SdfgViewerProvider implements vscode.CustomTextEditorProvider {
// Handle received messages from the webview.
webviewPanel.webview.onDidReceiveMessage(e => {
switch (e.type) {
case 'gotoSource':
// We want to jump to a specific file and location if it
// exists.
const filePath: string = path.normalize(
vscode.workspace.rootPath + '/' + e.file_path
);
if (fs.existsSync(filePath)) {
// The file exists, load it and show it in a new
// editor, highlighting the indicated range.
const fileUri: vscode.Uri = vscode.Uri.file(filePath);
vscode.workspace.openTextDocument(fileUri).then(
(doc: vscode.TextDocument) => {
const startPos = new vscode.Position(
e.startRow, e.startChar
);
const endPos = new vscode.Position(
e.endRow, e.endChar
);
const range = new vscode.Range(
startPos, endPos
);
vscode.window.showTextDocument(
doc, {
preview: true,
selection: range,
}
);
}
);
}
return;
}
});

Expand Down

0 comments on commit 02a3248

Please sign in to comment.