@@ -8,12 +8,14 @@ import {
8
8
WebviewPanelSerializer ,
9
9
Uri ,
10
10
window ,
11
- Webview
11
+ Webview ,
12
+ workspace
12
13
} from 'vscode' ;
13
14
14
15
import * as path from 'path' ;
15
- import * as fileUtils from '../utils/fileUtils ' ;
16
+ import { TextDecoder } from 'util ' ;
16
17
18
+ import * as fileUtils from '../utils/fileUtils' ;
17
19
import { ViewTypes } from './viewTypes' ;
18
20
19
21
/**
@@ -153,17 +155,37 @@ export class TableView {
153
155
}
154
156
155
157
/**
156
- * Reloads tablue view on data save chances or vscode IDE realod.
158
+ * Reloads table view on data save changes or vscode IDE realod.
157
159
*/
158
160
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 } ` ) ;
164
174
} ) ;
165
175
}
166
176
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
+
167
189
/**
168
190
* Gets the underlying webview panel instance for this view.
169
191
*/
0 commit comments