<commit_before>import {
  TextEditor,
  Range,
  TextEditorDecorationType,
  Position,
  window
} from 'vscode';

import ColorUtil from './color-util';
import Color from './util/color';

class ColorDecoration {
  public color: Color;
  public decoration: TextEditorDecorationType;
  public disposed: boolean = false;

  public constructor(color: Color) {
    this.color = color;
    this._generateDecorator();
  }

  public dispose(): void {
    this.color = null;
    this.decoration.dispose();
  }

  public generateRange(line: number) {
    return new Range(new Position(line, this.color.positionInText), new Position(line, this.color.positionInText + this.color.value.length));
  }

  private _generateDecorator(): TextEditorDecorationType {
    let textColor = null;
    let luminance = ColorUtil.luminance(this.color);
    if (luminance < 0.7) {
      textColor = '#fff';
    } else {
      textColor = '#000';
    }
    let backgroundDecorationType = window.createTextEditorDecorationType({
      borderWidth: '1px',
      borderStyle: 'solid',
      borderColor: this.color.toRgbString(),
      backgroundColor: this.color.toRgbString(),
      color: textColor
    });
    this.decoration = backgroundDecorationType;
    return backgroundDecorationType;
  }
}
export default ColorDecoration;
<commit_msg>Regenerate the textDecoration if needed when getting the decoration<commit_after>import {
  TextEditor,
  Range,
  TextEditorDecorationType,
  Position,
  window
} from 'vscode';

import ColorUtil from './color-util';
import Color from './util/color';

class ColorDecoration {
  public color: Color;
  private _decoration: TextEditorDecorationType;
  public disposed: boolean = false;

  get decoration(): TextEditorDecorationType {
    if (this.disposed) {
      this.disposed = false;
      this._generateDecorator();
    }
    return this._decoration;
  }
  set decoration(deco: TextEditorDecorationType) {
    this._decoration = deco;
  }
  public constructor(color: Color) {
    this.color = color;
    this._generateDecorator();
  }

  public dispose(): void {
    // this.color = null;
    this.decoration.dispose();
    this.disposed = true;
  }

  public generateRange(line: number) {
    return new Range(new Position(line, this.color.positionInText), new Position(line, this.color.positionInText + this.color.value.length));
  }

  private _generateDecorator() {
    let textColor = null;
    let luminance = ColorUtil.luminance(this.color);
    if (luminance < 0.7) {
      textColor = '#fff';
    } else {
      textColor = '#000';
    }
    let backgroundDecorationType = window.createTextEditorDecorationType({
      borderWidth: '1px',
      borderStyle: 'solid',
      borderColor: this.color.toRgbString(),
      backgroundColor: this.color.toRgbString(),
      color: textColor
    });
    this.decoration = backgroundDecorationType;
  }
}
export default ColorDecoration;

{'fraction_non_alphanumeric': 0.11023079572855667, 'fraction_numerical': 0.004133654839820875, 'mean_word_length': 3.5588697017268447, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5181784', 'n_tokens_mistral': 895, 'n_tokens_neox': 860, 'n_words': 200}