Adds actions so you can have customized keybindings for `insert` and
`replace` modes.
And add `shift-enter` as a default for `replace`, this will override the
default setting
`completions.lsp_insert_mode` which is set to `replace_suffix`, which
tries to "smartly"
decide whether to replace or insert based on the surrounding text.
For those who come from VSCode, if you want to mimic their behavior, you
only have to
set `completions.lsp_insert_mode` to `insert`.
If you want `tab` and `enter` to do different things, you need to remap
them, here is
an example:
```jsonc
[
// ...
{
"context": "Editor && showing_completions",
"bindings": {
"enter": "editor::ConfirmCompletionInsert",
"tab": "editor::ConfirmCompletionReplace"
}
},
]
```
Closes #24577
- [x] Make LSP completion insertion mode decision in guest's machine
(host is currently deciding it and not allowing guests to have their own
setting for it)
- [x] Add shift-enter as a hotkey for `replace` by default.
- [x] Test actions.
- [x] Respect the setting being specified per language, instead of using
the "defaults".
- [x] Move `insert_range` of `Completion` to the Lsp variant of
`.source`.
- [x] Fix broken default, forgotten after
https://github.com/zed-industries/zed/pull/27453#pullrequestreview-2736906628,
should be `replace_suffix` and not `insert`.
Release Notes:
- LSP completions: added actions `ConfirmCompletionInsert` and
`ConfirmCompletionReplace` that control how completions are inserted,
these override `completions.lsp_insert_mode`, by default, `shift-enter`
triggers `ConfirmCompletionReplace` which replaces the whole word.
456 lines
12 KiB
Rust
456 lines
12 KiB
Rust
//! This module contains all actions supported by [`Editor`].
|
|
use super::*;
|
|
use gpui::{action_as, action_with_deprecated_aliases, actions};
|
|
use schemars::JsonSchema;
|
|
use util::serde::default_true;
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct SelectNext {
|
|
#[serde(default)]
|
|
pub replace_newest: bool,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct SelectPrevious {
|
|
#[serde(default)]
|
|
pub replace_newest: bool,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct MoveToBeginningOfLine {
|
|
#[serde(default = "default_true")]
|
|
pub stop_at_soft_wraps: bool,
|
|
#[serde(default)]
|
|
pub stop_at_indent: bool,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct SelectToBeginningOfLine {
|
|
#[serde(default)]
|
|
pub(super) stop_at_soft_wraps: bool,
|
|
#[serde(default)]
|
|
pub stop_at_indent: bool,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct DeleteToBeginningOfLine {
|
|
#[serde(default)]
|
|
pub(super) stop_at_indent: bool,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct MovePageUp {
|
|
#[serde(default)]
|
|
pub(super) center_cursor: bool,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct MovePageDown {
|
|
#[serde(default)]
|
|
pub(super) center_cursor: bool,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct MoveToEndOfLine {
|
|
#[serde(default = "default_true")]
|
|
pub stop_at_soft_wraps: bool,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct SelectToEndOfLine {
|
|
#[serde(default)]
|
|
pub(super) stop_at_soft_wraps: bool,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct ToggleCodeActions {
|
|
// Display row from which the action was deployed.
|
|
#[serde(default)]
|
|
#[serde(skip)]
|
|
pub deployed_from_indicator: Option<DisplayRow>,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct ConfirmCompletion {
|
|
#[serde(default)]
|
|
pub item_ix: Option<usize>,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct ComposeCompletion {
|
|
#[serde(default)]
|
|
pub item_ix: Option<usize>,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct ConfirmCodeAction {
|
|
#[serde(default)]
|
|
pub item_ix: Option<usize>,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct ToggleComments {
|
|
#[serde(default)]
|
|
pub advance_downwards: bool,
|
|
#[serde(default)]
|
|
pub ignore_indent: bool,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct FoldAt {
|
|
#[serde(skip)]
|
|
pub buffer_row: MultiBufferRow,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct UnfoldAt {
|
|
#[serde(skip)]
|
|
pub buffer_row: MultiBufferRow,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct MoveUpByLines {
|
|
#[serde(default)]
|
|
pub(super) lines: u32,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct MoveDownByLines {
|
|
#[serde(default)]
|
|
pub(super) lines: u32,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct SelectUpByLines {
|
|
#[serde(default)]
|
|
pub(super) lines: u32,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct SelectDownByLines {
|
|
#[serde(default)]
|
|
pub(super) lines: u32,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct ExpandExcerpts {
|
|
#[serde(default)]
|
|
pub(super) lines: u32,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct ExpandExcerptsUp {
|
|
#[serde(default)]
|
|
pub(super) lines: u32,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct ExpandExcerptsDown {
|
|
#[serde(default)]
|
|
pub(super) lines: u32,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct ShowCompletions {
|
|
#[serde(default)]
|
|
pub(super) trigger: Option<String>,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
pub struct HandleInput(pub String);
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct DeleteToNextWordEnd {
|
|
#[serde(default)]
|
|
pub ignore_newlines: bool,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct DeleteToPreviousWordStart {
|
|
#[serde(default)]
|
|
pub ignore_newlines: bool,
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
pub struct FoldAtLevel(pub u32);
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct SpawnNearestTask {
|
|
#[serde(default)]
|
|
pub reveal: task::RevealStrategy,
|
|
}
|
|
|
|
#[derive(Debug, PartialEq, Eq, Clone, Copy, Deserialize, Default)]
|
|
pub enum UuidVersion {
|
|
#[default]
|
|
V4,
|
|
V7,
|
|
}
|
|
|
|
impl_actions!(
|
|
editor,
|
|
[
|
|
ComposeCompletion,
|
|
ConfirmCodeAction,
|
|
ConfirmCompletion,
|
|
DeleteToBeginningOfLine,
|
|
DeleteToNextWordEnd,
|
|
DeleteToPreviousWordStart,
|
|
ExpandExcerpts,
|
|
ExpandExcerptsDown,
|
|
ExpandExcerptsUp,
|
|
FoldAt,
|
|
HandleInput,
|
|
MoveDownByLines,
|
|
MovePageDown,
|
|
MovePageUp,
|
|
MoveToBeginningOfLine,
|
|
MoveToEndOfLine,
|
|
MoveUpByLines,
|
|
SelectDownByLines,
|
|
SelectNext,
|
|
SelectPrevious,
|
|
SelectToBeginningOfLine,
|
|
SelectToEndOfLine,
|
|
SelectUpByLines,
|
|
SpawnNearestTask,
|
|
ShowCompletions,
|
|
ToggleCodeActions,
|
|
ToggleComments,
|
|
UnfoldAt,
|
|
FoldAtLevel,
|
|
]
|
|
);
|
|
|
|
actions!(
|
|
editor,
|
|
[
|
|
AcceptEditPrediction,
|
|
AcceptPartialCopilotSuggestion,
|
|
AcceptPartialEditPrediction,
|
|
AddSelectionAbove,
|
|
AddSelectionBelow,
|
|
ApplyAllDiffHunks,
|
|
ApplyDiffHunk,
|
|
Backspace,
|
|
Cancel,
|
|
CancelLanguageServerWork,
|
|
ConfirmRename,
|
|
ConfirmCompletionInsert,
|
|
ConfirmCompletionReplace,
|
|
ContextMenuFirst,
|
|
ContextMenuLast,
|
|
ContextMenuNext,
|
|
ContextMenuPrevious,
|
|
ConvertToKebabCase,
|
|
ConvertToLowerCamelCase,
|
|
ConvertToLowerCase,
|
|
ConvertToOppositeCase,
|
|
ConvertToSnakeCase,
|
|
ConvertToTitleCase,
|
|
ConvertToUpperCamelCase,
|
|
ConvertToUpperCase,
|
|
ConvertToRot13,
|
|
ConvertToRot47,
|
|
Copy,
|
|
CopyAndTrim,
|
|
CopyFileLocation,
|
|
CopyHighlightJson,
|
|
CopyFileName,
|
|
CopyFileNameWithoutExtension,
|
|
CopyPermalinkToLine,
|
|
Cut,
|
|
CutToEndOfLine,
|
|
Delete,
|
|
DeleteLine,
|
|
DeleteToEndOfLine,
|
|
DeleteToNextSubwordEnd,
|
|
DeleteToPreviousSubwordStart,
|
|
DisplayCursorNames,
|
|
DuplicateLineDown,
|
|
DuplicateLineUp,
|
|
DuplicateSelection,
|
|
ExpandMacroRecursively,
|
|
FindAllReferences,
|
|
Fold,
|
|
FoldAll,
|
|
FoldFunctionBodies,
|
|
FoldRecursive,
|
|
FoldSelectedRanges,
|
|
ToggleFold,
|
|
ToggleFoldRecursive,
|
|
Format,
|
|
FormatSelections,
|
|
GoToDeclaration,
|
|
GoToDeclarationSplit,
|
|
GoToDefinition,
|
|
GoToDefinitionSplit,
|
|
GoToDiagnostic,
|
|
GoToHunk,
|
|
GoToPreviousHunk,
|
|
GoToImplementation,
|
|
GoToImplementationSplit,
|
|
GoToPreviousDiagnostic,
|
|
GoToTypeDefinition,
|
|
GoToTypeDefinitionSplit,
|
|
HalfPageDown,
|
|
HalfPageUp,
|
|
Hover,
|
|
Indent,
|
|
InsertUuidV4,
|
|
InsertUuidV7,
|
|
JoinLines,
|
|
KillRingCut,
|
|
KillRingYank,
|
|
LineDown,
|
|
LineUp,
|
|
MoveDown,
|
|
MoveLeft,
|
|
MoveLineDown,
|
|
MoveLineUp,
|
|
MoveRight,
|
|
MoveToBeginning,
|
|
MoveToEnclosingBracket,
|
|
MoveToEnd,
|
|
MoveToEndOfParagraph,
|
|
MoveToNextSubwordEnd,
|
|
MoveToNextWordEnd,
|
|
MoveToPreviousSubwordStart,
|
|
MoveToPreviousWordStart,
|
|
MoveToStartOfParagraph,
|
|
MoveToStartOfExcerpt,
|
|
MoveToStartOfNextExcerpt,
|
|
MoveToEndOfExcerpt,
|
|
MoveToEndOfPreviousExcerpt,
|
|
MoveUp,
|
|
Newline,
|
|
NewlineAbove,
|
|
NewlineBelow,
|
|
NextEditPrediction,
|
|
NextScreen,
|
|
OpenContextMenu,
|
|
OpenExcerpts,
|
|
OpenExcerptsSplit,
|
|
OpenProposedChangesEditor,
|
|
OpenDocs,
|
|
OpenPermalinkToLine,
|
|
OpenSelectionsInMultibuffer,
|
|
OpenUrl,
|
|
OrganizeImports,
|
|
Outdent,
|
|
AutoIndent,
|
|
PageDown,
|
|
PageUp,
|
|
Paste,
|
|
PreviousEditPrediction,
|
|
Redo,
|
|
RedoSelection,
|
|
Rename,
|
|
RestartLanguageServer,
|
|
RevealInFileManager,
|
|
ReverseLines,
|
|
RevertFile,
|
|
ReloadFile,
|
|
Rewrap,
|
|
ScrollCursorBottom,
|
|
ScrollCursorCenter,
|
|
ScrollCursorCenterTopBottom,
|
|
ScrollCursorTop,
|
|
SelectAll,
|
|
SelectAllMatches,
|
|
SelectToStartOfExcerpt,
|
|
SelectToStartOfNextExcerpt,
|
|
SelectToEndOfExcerpt,
|
|
SelectToEndOfPreviousExcerpt,
|
|
SelectDown,
|
|
SelectEnclosingSymbol,
|
|
SelectLargerSyntaxNode,
|
|
SelectLeft,
|
|
SelectLine,
|
|
SelectPageDown,
|
|
SelectPageUp,
|
|
SelectRight,
|
|
SelectSmallerSyntaxNode,
|
|
SelectToBeginning,
|
|
SelectToEnd,
|
|
SelectToEndOfParagraph,
|
|
SelectToNextSubwordEnd,
|
|
SelectToNextWordEnd,
|
|
SelectToPreviousSubwordStart,
|
|
SelectToPreviousWordStart,
|
|
SelectToStartOfParagraph,
|
|
SelectUp,
|
|
ShowCharacterPalette,
|
|
ShowEditPrediction,
|
|
ShowSignatureHelp,
|
|
ShowWordCompletions,
|
|
ShuffleLines,
|
|
SortLinesCaseInsensitive,
|
|
SortLinesCaseSensitive,
|
|
SplitSelectionIntoLines,
|
|
StopLanguageServer,
|
|
SwitchSourceHeader,
|
|
Tab,
|
|
Backtab,
|
|
ToggleBreakpoint,
|
|
DisableBreakpoint,
|
|
EnableBreakpoint,
|
|
EditLogBreakpoint,
|
|
ToggleAutoSignatureHelp,
|
|
ToggleGitBlameInline,
|
|
OpenGitBlameCommit,
|
|
ToggleIndentGuides,
|
|
ToggleInlayHints,
|
|
ToggleInlineDiagnostics,
|
|
ToggleEditPrediction,
|
|
ToggleLineNumbers,
|
|
SwapSelectionEnds,
|
|
SetMark,
|
|
ToggleRelativeLineNumbers,
|
|
ToggleSelectionMenu,
|
|
ToggleSoftWrap,
|
|
ToggleTabBar,
|
|
Transpose,
|
|
Undo,
|
|
UndoSelection,
|
|
UnfoldAll,
|
|
UnfoldLines,
|
|
UnfoldRecursive,
|
|
UniqueLinesCaseInsensitive,
|
|
UniqueLinesCaseSensitive,
|
|
]
|
|
);
|
|
|
|
action_as!(go_to_line, ToggleGoToLine as Toggle);
|
|
|
|
action_with_deprecated_aliases!(editor, OpenSelectedFilename, ["editor::OpenFile"]);
|
|
action_with_deprecated_aliases!(editor, ToggleSelectedDiffHunks, ["editor::ToggleHunkDiff"]);
|
|
action_with_deprecated_aliases!(editor, ExpandAllDiffHunks, ["editor::ExpandAllHunkDiffs"]);
|