refactor: use dotted LSP command names
This commit is contained in:
+42
-16
@@ -464,13 +464,13 @@ const CORE_ACTIONS: &[(&str, Action, &[Mode])] = &[
|
||||
&[Mode::Normal, Mode::Visual],
|
||||
),
|
||||
(
|
||||
"core.lsp_definition",
|
||||
"core.lsp.definition",
|
||||
Action::LspDefinition,
|
||||
&[Mode::Normal],
|
||||
),
|
||||
("core.lsp_hover", Action::LspHover, &[Mode::Normal]),
|
||||
("core.lsp.hover", Action::LspHover, &[Mode::Normal]),
|
||||
(
|
||||
"core.lsp_diagnostics",
|
||||
"core.lsp.diagnostics",
|
||||
Action::LspDiagnostics,
|
||||
&[Mode::Normal],
|
||||
),
|
||||
@@ -953,9 +953,9 @@ impl Editor {
|
||||
"bprev",
|
||||
"bdelete",
|
||||
"bdelete!",
|
||||
"lsp_definition",
|
||||
"lsp_hover",
|
||||
"lsp_diagnostics",
|
||||
"lsp.definition",
|
||||
"lsp.hover",
|
||||
"lsp.diagnostics",
|
||||
]
|
||||
.into_iter()
|
||||
.map(str::to_owned)
|
||||
@@ -2113,9 +2113,9 @@ impl Editor {
|
||||
}
|
||||
Action::FilePicker => self.open_file_picker(FilePresentation::Floating),
|
||||
Action::FileExplorer => self.open_file_picker(FilePresentation::Docked),
|
||||
Action::LspDefinition => return self.execute("lsp_definition"),
|
||||
Action::LspHover => return self.execute("lsp_hover"),
|
||||
Action::LspDiagnostics => return self.execute("lsp_diagnostics"),
|
||||
Action::LspDefinition => return self.execute("lsp.definition"),
|
||||
Action::LspHover => return self.execute("lsp.hover"),
|
||||
Action::LspDiagnostics => return self.execute("lsp.diagnostics"),
|
||||
Action::Insert
|
||||
| Action::InsertFirstNonblank
|
||||
| Action::AppendLineEnd
|
||||
@@ -2537,10 +2537,10 @@ impl Editor {
|
||||
});
|
||||
}
|
||||
match name {
|
||||
"lsp_definition" | "lsp_hover" | "lsp_diagnostics" if !args.is_empty() => {
|
||||
"lsp.definition" | "lsp.hover" | "lsp.diagnostics" if !args.is_empty() => {
|
||||
self.set_message(format!("The {name} command takes no arguments"));
|
||||
}
|
||||
"lsp_definition" | "lsp_hover" | "lsp_diagnostics" => {
|
||||
"lsp.definition" | "lsp.hover" | "lsp.diagnostics" => {
|
||||
return Some(Invocation {
|
||||
plugin: "core".into(),
|
||||
command: name.into(),
|
||||
@@ -4043,9 +4043,11 @@ fn word_tokens(
|
||||
|
||||
fn valid_command(command: &str) -> bool {
|
||||
let command = command.strip_suffix('!').unwrap_or(command);
|
||||
let mut chars = command.chars();
|
||||
chars.next().is_some_and(|ch| ch.is_ascii_alphabetic())
|
||||
&& chars.all(|ch| ch.is_ascii_alphanumeric() || ch == '_' || ch == '-')
|
||||
command.split('.').all(|segment| {
|
||||
let mut chars = segment.chars();
|
||||
chars.next().is_some_and(|ch| ch.is_ascii_alphabetic())
|
||||
&& chars.all(|ch| ch.is_ascii_alphanumeric() || ch == '_' || ch == '-')
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn validate_hover_text(text: &str) -> Result<(), String> {
|
||||
@@ -4265,15 +4267,25 @@ mod tests {
|
||||
let text = editor.context().text;
|
||||
let revision = editor.text_revision();
|
||||
let history = (editor.active.undo.len(), editor.active.redo.len());
|
||||
for command in [
|
||||
":lsp_hover",
|
||||
":lsp_definition",
|
||||
":lsp_diagnostics",
|
||||
":lsp.hover unexpected extra",
|
||||
":lsp.definition unexpected extra",
|
||||
":lsp.diagnostics unexpected extra",
|
||||
] {
|
||||
assert!(editor.execute(command).is_none(), "{command}");
|
||||
}
|
||||
editor
|
||||
.bind("normal", "K", Some("core.lsp_hover".into()))
|
||||
.bind("normal", "K", Some("core.lsp.hover".into()))
|
||||
.unwrap();
|
||||
type_text(&mut editor, "9");
|
||||
assert_eq!(
|
||||
editor.handle(Input::Char('K')),
|
||||
Some(Invocation {
|
||||
plugin: "core".into(),
|
||||
command: "lsp_hover".into(),
|
||||
command: "lsp.hover".into(),
|
||||
args: String::new(),
|
||||
})
|
||||
);
|
||||
@@ -9513,6 +9525,20 @@ mod tests {
|
||||
.is_err()
|
||||
);
|
||||
assert!(editor.register(plugin("invalid", &["bad name"])).is_err());
|
||||
for name in [
|
||||
".hover",
|
||||
"lsp.",
|
||||
"lsp..hover",
|
||||
"lsp.3hover",
|
||||
"lsp.hover!extra",
|
||||
] {
|
||||
assert!(
|
||||
editor
|
||||
.register(plugin("invalid", &["newcmd", name]))
|
||||
.is_err()
|
||||
);
|
||||
assert!(editor.bind("normal", "g", Some("newcmd".into())).is_err());
|
||||
}
|
||||
assert!(editor.register(plugin("", &["emptyname"])).is_err());
|
||||
let mut feature = plugin("forged", &["override"]);
|
||||
feature.core = true;
|
||||
|
||||
Reference in New Issue
Block a user