commenting_range_provider.ts 1.1 KB
Newer Older
1
import * as vscode from 'vscode';
2 3
import { FF_COMMENTING_RANGES, REVIEW_URI_SCHEME } from '../constants';
import { getExtensionConfiguration } from '../utils/get_extension_configuration';
4 5 6 7 8 9 10 11 12 13 14 15 16
import { fromReviewUri } from './review_uri';

export class CommentingRangeProvider implements vscode.CommentingRangeProvider {
  private mr: RestIssuable;

  private mrVersion: RestMrVersion;

  constructor(mr: RestIssuable, mrVersion: RestMrVersion) {
    this.mr = mr;
    this.mrVersion = mrVersion;
  }

  provideCommentingRanges(document: vscode.TextDocument): vscode.Range[] {
17
    if (!getExtensionConfiguration().featureFlags?.includes(FF_COMMENTING_RANGES)) return [];
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
    const { uri } = document;
    if (uri.scheme !== REVIEW_URI_SCHEME) return [];
    const params = fromReviewUri(uri);
    if (params.mrId !== this.mr.id || params.projectId !== this.mr.project_id || !params.path) {
      return [];
    }
    const oldFile = params.commit === this.mrVersion.base_commit_sha;
    if (oldFile) {
      return [
        new vscode.Range(new vscode.Position(0, 0), new vscode.Position(document.lineCount - 1, 0)),
      ];
    }

    return [];
  }
}