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;
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ Set VAMP_RUBY to choose the Ruby executable.
|
||||
|
||||
Native LSP is disabled by default: config.lsp[\"rust\"] = true enables a preset
|
||||
Custom languages: config.lsp[\"my-language\"] = { command: [...], extensions: [...] }
|
||||
LSP commands: :lsp_definition, :lsp_diagnostics, :lsp_hover
|
||||
LSP commands: :lsp.definition, :lsp.diagnostics, :lsp.hover
|
||||
Hover binding: config.bind \"K\", config.core.lsp.hover (no default key)";
|
||||
|
||||
struct Options {
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ module Vamp
|
||||
|
||||
module Lsp
|
||||
%w[definition diagnostics hover].each do |name|
|
||||
action = Action.new("core.lsp_#{name}".freeze).freeze
|
||||
action = Action.new("core.lsp.#{name}".freeze).freeze
|
||||
define_singleton_method(name) { action }
|
||||
end
|
||||
end
|
||||
|
||||
+3
-3
@@ -160,7 +160,7 @@ impl EditorSession {
|
||||
fn dispatch(&mut self, invocation: Invocation) {
|
||||
if invocation.plugin == "core" {
|
||||
let result = match invocation.command.as_str() {
|
||||
"lsp_definition" | "lsp_hover" => {
|
||||
"lsp.definition" | "lsp.hover" => {
|
||||
if let Some(id) = self.lsp_request_id.checked_add(1) {
|
||||
self.lsp_request_id = id;
|
||||
let context = self.editor.context();
|
||||
@@ -170,7 +170,7 @@ impl EditorSession {
|
||||
};
|
||||
self.requests.entry("core".into()).or_default().latest = Some((id, source));
|
||||
self.lsp_source_cursor = Some(self.editor.cursor());
|
||||
self.pending_hover = invocation.command == "lsp_hover";
|
||||
self.pending_hover = invocation.command == "lsp.hover";
|
||||
if self.pending_hover {
|
||||
self.lsp.hover(&context, id)
|
||||
} else {
|
||||
@@ -180,7 +180,7 @@ impl EditorSession {
|
||||
Err("LSP request IDs exhausted".into())
|
||||
}
|
||||
}
|
||||
"lsp_diagnostics" => self.lsp.diagnostics(self.editor.buffer_id()),
|
||||
"lsp.diagnostics" => self.lsp.diagnostics(self.editor.buffer_id()),
|
||||
_ => unreachable!("session-dispatched core command"),
|
||||
};
|
||||
if let Err(error) = result {
|
||||
|
||||
Reference in New Issue
Block a user