Skip to content

Commit 3b836e3

Browse files
add basic text data loading and logging to table view refresh (#9)
1 parent 2668be2 commit 3b836e3

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/views/tableView.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import {
88
WebviewPanelSerializer,
99
Uri,
1010
window,
11-
Webview
11+
Webview,
12+
workspace
1213
} from 'vscode';
1314

1415
import * as path from 'path';
15-
import * as fileUtils from '../utils/fileUtils';
16+
import { TextDecoder } from 'util';
1617

18+
import * as fileUtils from '../utils/fileUtils';
1719
import { ViewTypes } from './viewTypes';
1820

1921
/**
@@ -153,17 +155,37 @@ export class TableView {
153155
}
154156

155157
/**
156-
* Reloads tablue view on data save chances or vscode IDE realod.
158+
* Reloads table view on data save changes or vscode IDE realod.
157159
*/
158160
public async refresh(): Promise<void> {
159-
// update webview
160-
this.webviewPanel.webview.postMessage({
161-
command: 'refresh',
162-
fileName: this._fileName,
163-
documentUrl: this._documentUri.toString()
161+
// load data
162+
workspace.fs.readFile(this._documentUri).then((binaryData: Uint8Array) => {
163+
const textData: string = new TextDecoder().decode(binaryData);
164+
this.logData(textData);
165+
166+
// update webview
167+
this.webviewPanel.webview.postMessage({
168+
command: 'refresh',
169+
fileName: this._fileName,
170+
documentUrl: this._documentUri.toString()
171+
});
172+
}, reason => {
173+
window.showErrorMessage(`Could not load \`${this._documentUri}\` content. Reason: \n ${reason}`);
164174
});
165175
}
166176

177+
/**
178+
* Logs truncated text data for debug.
179+
*
180+
* @param textData Text data to log.
181+
* @param maxChars Max characters to log.
182+
*/
183+
private logData(textData: string, maxChars: number = 1000): void {
184+
const contentLength: number = textData.length;
185+
console.log('tabular.data.view:refresh(): data:\n',
186+
textData.substring(0, contentLength > maxChars ? maxChars : contentLength), ' ...');
187+
}
188+
167189
/**
168190
* Gets the underlying webview panel instance for this view.
169191
*/

0 commit comments

Comments
 (0)