Skip to content

Commit

Permalink
Use InEmbeddedEditor context for chat code blocks
Browse files Browse the repository at this point in the history
This als:

- Renames the variable to match the context key name
- Uses this context key to disable peek call hierarchy
- Enable the normal go to def commands in these contexts (not the peek versions)
  • Loading branch information
mjbvz committed Feb 7, 2024
1 parent bc056d2 commit 3c33404
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/vs/editor/browser/widget/codeEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2095,7 +2095,7 @@ export class EditorModeContext extends Disposable {
private readonly _hasMultipleDocumentSelectionFormattingProvider: IContextKey<boolean>;
private readonly _hasSignatureHelpProvider: IContextKey<boolean>;
private readonly _hasInlayHintsProvider: IContextKey<boolean>;
private readonly _isInWalkThrough: IContextKey<boolean>;
private readonly _isInEmbeddedEditor: IContextKey<boolean>;

constructor(
private readonly _editor: CodeEditorWidget,
Expand Down Expand Up @@ -2123,7 +2123,7 @@ export class EditorModeContext extends Disposable {
this._hasDocumentSelectionFormattingProvider = EditorContextKeys.hasDocumentSelectionFormattingProvider.bindTo(_contextKeyService);
this._hasMultipleDocumentFormattingProvider = EditorContextKeys.hasMultipleDocumentFormattingProvider.bindTo(_contextKeyService);
this._hasMultipleDocumentSelectionFormattingProvider = EditorContextKeys.hasMultipleDocumentSelectionFormattingProvider.bindTo(_contextKeyService);
this._isInWalkThrough = EditorContextKeys.isInWalkThroughSnippet.bindTo(_contextKeyService);
this._isInEmbeddedEditor = EditorContextKeys.isInEmbeddedEditor.bindTo(_contextKeyService);

const update = () => this._update();

Expand Down Expand Up @@ -2174,7 +2174,7 @@ export class EditorModeContext extends Disposable {
this._hasDocumentFormattingProvider.reset();
this._hasDocumentSelectionFormattingProvider.reset();
this._hasSignatureHelpProvider.reset();
this._isInWalkThrough.reset();
this._isInEmbeddedEditor.reset();
});
}

Expand Down Expand Up @@ -2204,7 +2204,7 @@ export class EditorModeContext extends Disposable {
this._hasDocumentSelectionFormattingProvider.set(this._languageFeaturesService.documentRangeFormattingEditProvider.has(model));
this._hasMultipleDocumentFormattingProvider.set(this._languageFeaturesService.documentFormattingEditProvider.all(model).length + this._languageFeaturesService.documentRangeFormattingEditProvider.all(model).length > 1);
this._hasMultipleDocumentSelectionFormattingProvider.set(this._languageFeaturesService.documentRangeFormattingEditProvider.all(model).length > 1);
this._isInWalkThrough.set(model.uri.scheme === Schemas.walkThroughSnippet);
this._isInEmbeddedEditor.set(model.uri.scheme === Schemas.walkThroughSnippet || model.uri.scheme === Schemas.vscodeChatCodeBlock);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/common/editorContextKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export namespace EditorContextKeys {
export const hasSingleSelection = hasMultipleSelections.toNegated();
export const tabMovesFocus = new RawContextKey<boolean>('editorTabMovesFocus', false, nls.localize('editorTabMovesFocus', "Whether `Tab` will move focus out of the editor"));
export const tabDoesNotMoveFocus = tabMovesFocus.toNegated();
export const isInWalkThroughSnippet = new RawContextKey<boolean>('isInEmbeddedEditor', false, true);
export const isInEmbeddedEditor = new RawContextKey<boolean>('isInEmbeddedEditor', false, true);
export const canUndo = new RawContextKey<boolean>('canUndo', false, true);
export const canRedo = new RawContextKey<boolean>('canRedo', false, true);

Expand Down
30 changes: 12 additions & 18 deletions src/vs/editor/contrib/gotoSymbol/browser/goToCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ registerAction2(class GoToDefinitionAction extends DefinitionAction {
...nls.localize2('actions.goToDecl.label', "Go to Definition"),
mnemonicTitle: nls.localize({ key: 'miGotoDefinition', comment: ['&& denotes a mnemonic'] }, "Go to &&Definition"),
},
precondition: ContextKeyExpr.and(
EditorContextKeys.hasDefinitionProvider,
EditorContextKeys.isInWalkThroughSnippet.toNegated()),
precondition: EditorContextKeys.hasDefinitionProvider,
keybinding: [{
when: EditorContextKeys.editorTextFocus,
primary: KeyCode.F12,
Expand Down Expand Up @@ -327,7 +325,7 @@ registerAction2(class OpenDefinitionToSideAction extends DefinitionAction {
title: nls.localize2('actions.goToDeclToSide.label', "Open Definition to the Side"),
precondition: ContextKeyExpr.and(
EditorContextKeys.hasDefinitionProvider,
EditorContextKeys.isInWalkThroughSnippet.toNegated()),
EditorContextKeys.isInEmbeddedEditor.toNegated()),
keybinding: [{
when: EditorContextKeys.editorTextFocus,
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyCode.F12),
Expand Down Expand Up @@ -357,7 +355,7 @@ registerAction2(class PeekDefinitionAction extends DefinitionAction {
precondition: ContextKeyExpr.and(
EditorContextKeys.hasDefinitionProvider,
PeekContext.notInPeekEditor,
EditorContextKeys.isInWalkThroughSnippet.toNegated()
EditorContextKeys.isInEmbeddedEditor.toNegated()
),
keybinding: {
when: EditorContextKeys.editorTextFocus,
Expand Down Expand Up @@ -417,7 +415,7 @@ registerAction2(class GoToDeclarationAction extends DeclarationAction {
},
precondition: ContextKeyExpr.and(
EditorContextKeys.hasDeclarationProvider,
EditorContextKeys.isInWalkThroughSnippet.toNegated()
EditorContextKeys.isInEmbeddedEditor.toNegated()
),
menu: [{
id: MenuId.EditorContext,
Expand Down Expand Up @@ -451,7 +449,7 @@ registerAction2(class PeekDeclarationAction extends DeclarationAction {
precondition: ContextKeyExpr.and(
EditorContextKeys.hasDeclarationProvider,
PeekContext.notInPeekEditor,
EditorContextKeys.isInWalkThroughSnippet.toNegated()
EditorContextKeys.isInEmbeddedEditor.toNegated()
),
menu: {
id: MenuId.EditorContextPeek,
Expand Down Expand Up @@ -502,9 +500,7 @@ registerAction2(class GoToTypeDefinitionAction extends TypeDefinitionAction {
...nls.localize2('actions.goToTypeDefinition.label', "Go to Type Definition"),
mnemonicTitle: nls.localize({ key: 'miGotoTypeDefinition', comment: ['&& denotes a mnemonic'] }, "Go to &&Type Definition"),
},
precondition: ContextKeyExpr.and(
EditorContextKeys.hasTypeDefinitionProvider,
EditorContextKeys.isInWalkThroughSnippet.toNegated()),
precondition: EditorContextKeys.hasTypeDefinitionProvider,
keybinding: {
when: EditorContextKeys.editorTextFocus,
primary: 0,
Expand Down Expand Up @@ -539,7 +535,7 @@ registerAction2(class PeekTypeDefinitionAction extends TypeDefinitionAction {
precondition: ContextKeyExpr.and(
EditorContextKeys.hasTypeDefinitionProvider,
PeekContext.notInPeekEditor,
EditorContextKeys.isInWalkThroughSnippet.toNegated()
EditorContextKeys.isInEmbeddedEditor.toNegated()
),
menu: {
id: MenuId.EditorContextPeek,
Expand Down Expand Up @@ -590,9 +586,7 @@ registerAction2(class GoToImplementationAction extends ImplementationAction {
...nls.localize2('actions.goToImplementation.label', "Go to Implementations"),
mnemonicTitle: nls.localize({ key: 'miGotoImplementation', comment: ['&& denotes a mnemonic'] }, "Go to &&Implementations"),
},
precondition: ContextKeyExpr.and(
EditorContextKeys.hasImplementationProvider,
EditorContextKeys.isInWalkThroughSnippet.toNegated()),
precondition: EditorContextKeys.hasImplementationProvider,
keybinding: {
when: EditorContextKeys.editorTextFocus,
primary: KeyMod.CtrlCmd | KeyCode.F12,
Expand Down Expand Up @@ -627,7 +621,7 @@ registerAction2(class PeekImplementationAction extends ImplementationAction {
precondition: ContextKeyExpr.and(
EditorContextKeys.hasImplementationProvider,
PeekContext.notInPeekEditor,
EditorContextKeys.isInWalkThroughSnippet.toNegated()
EditorContextKeys.isInEmbeddedEditor.toNegated()
),
keybinding: {
when: EditorContextKeys.editorTextFocus,
Expand Down Expand Up @@ -680,7 +674,7 @@ registerAction2(class GoToReferencesAction extends ReferencesAction {
precondition: ContextKeyExpr.and(
EditorContextKeys.hasReferenceProvider,
PeekContext.notInPeekEditor,
EditorContextKeys.isInWalkThroughSnippet.toNegated()
EditorContextKeys.isInEmbeddedEditor.toNegated()
),
keybinding: {
when: EditorContextKeys.editorTextFocus,
Expand Down Expand Up @@ -718,7 +712,7 @@ registerAction2(class PeekReferencesAction extends ReferencesAction {
precondition: ContextKeyExpr.and(
EditorContextKeys.hasReferenceProvider,
PeekContext.notInPeekEditor,
EditorContextKeys.isInWalkThroughSnippet.toNegated()
EditorContextKeys.isInEmbeddedEditor.toNegated()
),
menu: {
id: MenuId.EditorContextPeek,
Expand Down Expand Up @@ -750,7 +744,7 @@ class GenericGoToLocationAction extends SymbolNavigationAction {
title: nls.localize2('label.generic', "Go to Any Symbol"),
precondition: ContextKeyExpr.and(
PeekContext.notInPeekEditor,
EditorContextKeys.isInWalkThroughSnippet.toNegated()
EditorContextKeys.isInEmbeddedEditor.toNegated()
),
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ registerAction2(class PeekCallHierarchyAction extends EditorAction2 {
order: 1000,
when: ContextKeyExpr.and(
_ctxHasCallHierarchyProvider,
PeekContext.notInPeekEditor
PeekContext.notInPeekEditor,
EditorContextKeys.isInEmbeddedEditor.toNegated(),
),
},
keybinding: {
Expand Down

0 comments on commit 3c33404

Please sign in to comment.