|
1 | | -import { readFile, readFileSync } from "fs"; |
2 | | -import { WebviewViewProvider, WebviewView, Uri, CancellationToken, WebviewViewResolveContext, Webview, DiagnosticSeverity, window, WebviewPanel, ViewColumn, ExtensionContext, workspace, TextDocument, TextEdit, Range, WorkspaceEdit, Position } from "vscode"; |
3 | | -import { basename } from "path"; |
4 | | -import { DisplayFile, FieldInfo } from "./dspf"; |
| 1 | +import { readFileSync } from "fs"; |
| 2 | +import { Uri, Webview, window, WebviewPanel, ViewColumn, ExtensionContext, workspace, TextDocument, Range, WorkspaceEdit, Position } from "vscode"; |
| 3 | +import { DisplayFile, FieldInfo, Keyword, RecordInfo } from "./dspf"; |
5 | 4 |
|
6 | 5 |
|
7 | 6 | export class RendererWebview { |
@@ -126,7 +125,32 @@ export class RendererWebview { |
126 | 125 | ); |
127 | 126 |
|
128 | 127 | await workspace.applyEdit(workspaceEdit); |
129 | | - this.load(false); |
| 128 | + this.load(false); //Field is updated on the client |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + break; |
| 133 | + |
| 134 | + case `updateFormat`: |
| 135 | + // This does not update any of the fields in the record format, only the format header |
| 136 | + recordFormat = message.recordFormat; |
| 137 | + const newKeywords: Keyword[] = message.newKeywords; |
| 138 | + |
| 139 | + if (typeof recordFormat === `string` && Array.isArray(newKeywords)) { |
| 140 | + const formatUpdate = this.dds?.updateFormatHeader(recordFormat, newKeywords); |
| 141 | + |
| 142 | + if (formatUpdate) { |
| 143 | + if (formatUpdate.range && this.document) { |
| 144 | + const workspaceEdit = new WorkspaceEdit(); |
| 145 | + workspaceEdit.replace( |
| 146 | + this.document.uri, |
| 147 | + new Range(formatUpdate.range.start, 0, formatUpdate.range.end, 1000), |
| 148 | + formatUpdate.newLines.join('\n'), // TOOD: use the correct EOL? |
| 149 | + {label: `Update DDS Format`, needsConfirmation: false} |
| 150 | + ); |
| 151 | + |
| 152 | + await workspace.applyEdit(workspaceEdit); |
| 153 | + this.load(true); |
130 | 154 | } |
131 | 155 | } |
132 | 156 | } |
|
0 commit comments