public async resolveCustomTextEditor()

in src/tdmlEditor/TDMLProvider.ts [42:156]


  public async resolveCustomTextEditor(
    document: vscode.TextDocument,
    webviewPanel: vscode.WebviewPanel,
    _token: vscode.CancellationToken
  ): Promise<void> {
    this.currentPanel = webviewPanel
    webviewPanel.webview.options = {
      enableScripts: true,
      localResourceRoots: [
        vscode.Uri.joinPath(this.context.extensionUri, 'src/tdmlEditor/media'),
        vscode.Uri.joinPath(
          this.context.extensionUri,
          'dist/views/tdmlEditor/webview'
        ),
      ],
    }
    webviewPanel.webview.html = this._getWebviewContent(webviewPanel.webview)
    webviewPanel.onDidChangeViewState((e) => {
      this.currentPanel = e.webviewPanel
    })

    try {
      printChannelOutput(document.uri.toString(), true)
      if (!this.registered) {
        this.registered = true
        let deleteCommand = vscode.commands.registerCommand(
          AppConstants.deleteTestCommand,
          () => {
            this.currentPanel?.webview.postMessage({
              type: 'delete',
            })
          }
        )

        let addCommand = vscode.commands.registerCommand(
          AppConstants.addNewTestCommand,
          () => {
            // get all the inputs we need
            const inputs = newTestCaseInput(this.context)
            // then do something with them
            inputs.then((result) => {
              this.currentPanel?.webview.postMessage({
                type: 'add',
                testCaseName: result.testName,
                testCaseModel: result.testDesc,
                testCaseDescription: result.testModel,
                dataDocuments: result.dfdlInfoset,
                dfdlInfosets: result.dataDocs,
              })
            })
          }
        )

        let openInTextEditorCommand = vscode.commands.registerCommand(
          AppConstants.openInTextEditorCommand,
          () => {
            printChannelOutput('openInTextEditor command called', true)
            vscode.commands.executeCommand(
              'workbench.action.reopenTextEditor',
              document?.uri
            )
          }
        )

        this.context.subscriptions.push(openInTextEditorCommand)
        this.context.subscriptions.push(deleteCommand)
        this.context.subscriptions.push(addCommand)
      }
    } catch (e) {
      console.log(e)
    }

    async function updateWebview() {
      webviewPanel.webview.postMessage({
        type: 'update',
        text: await getTestCaseDisplayData(document.getText()),
      })
    }

    const changeDocumentSubscription = vscode.workspace.onDidChangeTextDocument(
      (e) => {
        if (e.document.uri.toString() === document.uri.toString()) {
          updateWebview()
        }
      }
    )

    webviewPanel.onDidDispose(() => {
      changeDocumentSubscription.dispose()
    })

    webviewPanel.webview.onDidReceiveMessage((e) => {
      switch (e.type) {
        case 'update':
          this.updateTextDocument(document, e.json)
          return
        case 'log':
          printChannelOutput(e.message, true)
          return
        case 'error':
          printChannelOutput(e.message, true)
          vscode.window.showErrorMessage(e.message)
          return
        case 'info':
          printChannelOutput(e.message, true)
          vscode.window.showInformationMessage(e.message)
          return
        case 'add':
          vscode.commands.executeCommand(AppConstants.addNewTestCommand)
          return
      }
    })

    updateWebview()
  }