Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better openDiffOnClick+showInlineOpenFileActions #6552

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2444,12 +2444,12 @@
{
"command": "review.openFile",
"group": "inline@0",
"when": "openDiffOnClick && view == prStatus:github && viewItem =~ /filechange(?!:DELETE)/ && config.git.showInlineOpenFileAction"
"when": "openDiffOnClick && showInlineOpenFileAction && view == prStatus:github && viewItem =~ /filechange(?!:DELETE)/"
},
{
"command": "pr.openDiffView",
"group": "inline@0",
"when": "!openDiffOnClick && view == prStatus:github && viewItem =~ /filechange(?!:DELETE)/"
"when": "!openDiffOnClick && showInlineOpenFileAction && view == prStatus:github && viewItem =~ /filechange(?!:DELETE)/"
},
{
"command": "pr.openFileOnGitHub",
Expand Down
1 change: 1 addition & 0 deletions src/common/settingKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const EXPERIMENTAL_NOTIFICATIONS_SCORE = 'experimental.notificationsScore
export const GIT = 'git';
export const PULL_BEFORE_CHECKOUT = 'pullBeforeCheckout';
export const OPEN_DIFF_ON_CLICK = 'openDiffOnClick';
export const SHOW_INLINE_OPEN_FILE_ACTION = 'showInlineOpenFileAction';
export const AUTO_STASH = 'autoStash';

// GitHub Enterprise
Expand Down
21 changes: 18 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Logger from './common/logger';
import * as PersistentState from './common/persistentState';
import { parseRepositoryRemotes } from './common/remote';
import { Resource } from './common/resources';
import { BRANCH_PUBLISH, EXPERIMENTAL_CHAT, EXPERIMENTAL_NOTIFICATIONS, FILE_LIST_LAYOUT, GIT, OPEN_DIFF_ON_CLICK, PR_SETTINGS_NAMESPACE } from './common/settingKeys';
import { BRANCH_PUBLISH, EXPERIMENTAL_CHAT, EXPERIMENTAL_NOTIFICATIONS, FILE_LIST_LAYOUT, GIT, OPEN_DIFF_ON_CLICK, PR_SETTINGS_NAMESPACE, SHOW_INLINE_OPEN_FILE_ACTION } from './common/settingKeys';
import { TemporaryState } from './common/temporaryState';
import { Schemes, handler as uriHandler } from './common/uri';
import { EXTENSION_ID, FOCUS_REVIEW_MODE } from './constants';
Expand Down Expand Up @@ -286,8 +286,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<GitApi
await commands.focusView('github:activePullRequest:welcome');
showPRController.shouldShow = shouldShow;
});
const openDiff = vscode.workspace.getConfiguration(GIT, null).get(OPEN_DIFF_ON_CLICK, true);
await vscode.commands.executeCommand('setContext', 'openDiffOnClick', openDiff);
await setGitSettingContexts(context);

// initialize resources
Resource.initialize(context);
Expand All @@ -302,6 +301,22 @@ export async function activate(context: vscode.ExtensionContext): Promise<GitApi
return apiImpl;
}

async function setGitSettingContexts(context: vscode.ExtensionContext) {
// We set contexts instead of using the config directly in package.json because the git extension might not actually be available.
const settings: [string, () => void][] = [
['openDiffOnClick', () => vscode.workspace.getConfiguration(GIT, null).get(OPEN_DIFF_ON_CLICK, true)],
['showInlineOpenFileAction', () => vscode.workspace.getConfiguration(GIT, null).get(SHOW_INLINE_OPEN_FILE_ACTION, true)]
];
for (const [contextName, setting] of settings) {
commands.setContext(contextName, setting());
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(`${GIT}.${contextName}`)) {
commands.setContext(contextName, setting());
}
}));
}
}

async function doRegisterBuiltinGitProvider(context: vscode.ExtensionContext, credentialStore: CredentialStore, apiImpl: GitApiImpl): Promise<boolean> {
const builtInGitProvider = await registerBuiltinGitProvider(credentialStore, apiImpl);
if (builtInGitProvider) {
Expand Down