提交 de7837fe 编写于 作者: T Tomas Vik

refactor: hide commenting ranges behind feature flag

上级 c34adb9c
......@@ -6,3 +6,6 @@ export const ADDED = 'added';
export const DELETED = 'deleted';
export const RENAMED = 'renamed';
export const MODIFIED = 'modified';
// feature flags
export const FF_COMMENTING_RANGES = 'commenting-ranges';
import * as vscode from 'vscode';
import { mr, mrVersion } from '../test_utils/entities';
import { CommentingRangeProvider } from './commenting_range_provider';
import { toReviewUri } from './review_uri';
import { ReviewParams, toReviewUri } from './review_uri';
import { getExtensionConfiguration } from '../utils/get_extension_configuration';
import { FF_COMMENTING_RANGES } from '../constants';
jest.mock('../utils/get_extension_configuration');
describe('CommentingRangeProvider', () => {
let commentingRangeProvider: CommentingRangeProvider;
const commonUriParams: ReviewParams = {
path: `/path`,
mrId: mr.id,
projectId: mr.project_id,
commit: mrVersion.base_commit_sha,
workspacePath: '/',
};
const oldFileUrl = toReviewUri({
...commonUriParams,
commit: mrVersion.base_commit_sha,
});
const newFileUri = toReviewUri({
...commonUriParams,
commit: mrVersion.head_commit_sha,
});
beforeEach(() => {
(getExtensionConfiguration as jest.Mock).mockReturnValue({
featureFlags: [FF_COMMENTING_RANGES],
});
commentingRangeProvider = new CommentingRangeProvider(mr, mrVersion);
});
......@@ -19,13 +43,7 @@ describe('CommentingRangeProvider', () => {
it('returns full range (all lines in the document) for old file', () => {
const testDocument = {
uri: toReviewUri({
path: `/path`,
mrId: mr.id,
projectId: mr.project_id,
commit: mrVersion.base_commit_sha,
workspacePath: '/',
}),
uri: oldFileUrl,
lineCount: 200,
} as vscode.TextDocument;
expect(commentingRangeProvider.provideCommentingRanges(testDocument)).toEqual([
......@@ -35,13 +53,17 @@ describe('CommentingRangeProvider', () => {
it('returns empty array for new file', () => {
const testDocument = {
uri: toReviewUri({
path: `/path`,
mrId: mr.id,
projectId: mr.project_id,
commit: mrVersion.head_commit_sha,
workspacePath: '/',
}),
uri: newFileUri,
} as vscode.TextDocument;
expect(commentingRangeProvider.provideCommentingRanges(testDocument)).toEqual([]);
});
it('returns empty array with the feature flag off', () => {
(getExtensionConfiguration as jest.Mock).mockReturnValue({
featureFlags: undefined,
});
const testDocument = {
uri: oldFileUrl,
lineCount: 200,
} as vscode.TextDocument;
expect(commentingRangeProvider.provideCommentingRanges(testDocument)).toEqual([]);
......
import * as vscode from 'vscode';
import { REVIEW_URI_SCHEME } from '../constants';
import { FF_COMMENTING_RANGES, REVIEW_URI_SCHEME } from '../constants';
import { getExtensionConfiguration } from '../utils/get_extension_configuration';
import { fromReviewUri } from './review_uri';
export class CommentingRangeProvider implements vscode.CommentingRangeProvider {
......@@ -13,6 +14,7 @@ export class CommentingRangeProvider implements vscode.CommentingRangeProvider {
}
provideCommentingRanges(document: vscode.TextDocument): vscode.Range[] {
if (!getExtensionConfiguration().featureFlags?.includes(FF_COMMENTING_RANGES)) return [];
const { uri } = document;
if (uri.scheme !== REVIEW_URI_SCHEME) return [];
const params = fromReviewUri(uri);
......
......@@ -4,6 +4,7 @@ import { CONFIG_NAMESPACE } from '../constants';
interface ExtensionConfiguration {
remoteName?: string;
pipelineGitRemoteName?: string;
featureFlags?: string[];
}
// VS Code returns a value or `null` but undefined is better for using default function arguments
......@@ -14,5 +15,6 @@ export function getExtensionConfiguration(): ExtensionConfiguration {
return {
remoteName: turnNullToUndefined(workspaceConfig.remoteName),
pipelineGitRemoteName: turnNullToUndefined(workspaceConfig.pipelineGitRemoteName),
featureFlags: turnNullToUndefined(workspaceConfig.featureFlags),
};
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册