setFixes()

in tools/vscode_automatic_query_fixer/src/code_action_provider.ts [20:64]


  setFixes(fixes: QueryFix[], openEditor: vscode.TextEditor) {
    let hasErrors = false;

    const diagnostics: vscode.Diagnostic[] = [];
    fixes.forEach(fix => {
      if (!fix.error) {
        return;
      }
      hasErrors = true;

      let msg = fix.error!;
      if (fix.approach) {
        msg += '\nSuggestion: ' + fix.approach!;
      }

      // highlight the immediate token
      const regex = new RegExp('[^(\\s|\\t|\\n)]*');
      const range = fix.errorPosition
        ? openEditor.document.getWordRangeAtPosition(
            new vscode.Position(
              fix.errorPosition.row - 1,
              fix.errorPosition.column - 1
            ),
            regex
          )!
        : new vscode.Range(0, 0, 0, 0);

      diagnostics.push(
        new vscode.Diagnostic(range, msg, vscode.DiagnosticSeverity.Error)
      );
    });

    if (!hasErrors) {
      vscode.window.showInformationMessage('No errors were found.');
    }

    this.diagnosticCollection.set(openEditor.document.uri, diagnostics);

    this.fixes = fixes;
    this.uri = openEditor.document.uri;
    // set range to entire document text
    this.range = openEditor.document.validateRange(
      new vscode.Range(0, 0, openEditor.document.lineCount, 0)
    );
  }