some more commands

This commit is contained in:
Dongdong Zhou 2022-05-03 21:22:43 +01:00
parent 155a1dea9a
commit cb4adeeee1
6 changed files with 65 additions and 21 deletions

6
Cargo.lock generated
View File

@ -1816,7 +1816,7 @@ dependencies = [
"tree-sitter-java",
"tree-sitter-javascript",
"tree-sitter-json",
"tree-sitter-markdown",
"tree-sitter-md",
"tree-sitter-php",
"tree-sitter-python",
"tree-sitter-ruby",
@ -4139,9 +4139,9 @@ dependencies = [
]
[[package]]
name = "tree-sitter-markdown"
name = "tree-sitter-md"
version = "0.0.1"
source = "git+https://github.com/MDeiml/tree-sitter-markdown.git#d24196f9b3e5af6fcb2ec2a0b6cbc5c06f58b85e"
source = "git+https://github.com/MDeiml/tree-sitter-markdown.git#6d112e7a9c1694504bb78ee0b92dcd509625e0df"
dependencies = [
"cc",
"tree-sitter",

View File

@ -30,7 +30,6 @@ tree-sitter-json = "0.19.0"
tree-sitter-md = { git = "https://github.com/MDeiml/tree-sitter-markdown.git", version = "0.0.1" }
tree-sitter-html = "0.19.0"
tree-sitter-java = { git = "https://github.com/tree-sitter/tree-sitter-java.git", version = "0.20.0" }
tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown.git", version = "0.0.1" }
lsp-types = { version = "0.89.2", features = ["proposed"] }
xi-rope = { git = "https://github.com/lapce/xi-editor", features = ["serde"] }
lapce-rpc = { path = "../lapce-rpc" }

View File

@ -225,6 +225,8 @@ pub enum FocusCommand {
ScrollUp,
#[strum(serialize = "scroll_down")]
ScrollDown,
#[strum(serialize = "center_of_window")]
CenterOfWindow,
#[strum(serialize = "show_code_actions")]
ShowCodeActions,
/// This will close a modal, such as the settings window or completion
@ -238,6 +240,19 @@ pub enum FocusCommand {
JumpLocationBackward,
#[strum(serialize = "jump_location_forward")]
JumpLocationForward,
#[strum(serialize = "next_error")]
NextError,
#[strum(serialize = "previous_error")]
PreviousError,
#[strum(message = "Go to Next Difference")]
#[strum(serialize = "next_diff")]
NextDiff,
#[strum(message = "Go to Previous Difference")]
#[strum(serialize = "previous_diff")]
PreviousDiff,
#[strum(serialize = "format_document")]
#[strum(message = "Format Document")]
FormatDocument,
#[strum(serialize = "search")]
Search,
#[strum(message = "Save")]

View File

@ -52,8 +52,6 @@ pub enum LapceLanguage {
Ruby,
Html,
Java,
Markdown,
Ruby,
}
impl LapceLanguage {
@ -79,8 +77,6 @@ pub fn from_path(path: &Path) -> Option<LapceLanguage> {
"rb" => LapceLanguage::Ruby,
"html" | "htm" => LapceLanguage::Html,
"java" => LapceLanguage::Java,
"md" => LapceLanguage::Markdown,
"rb" => LapceLanguage::Ruby,
_ => return None,
})
}
@ -104,8 +100,6 @@ pub fn comment_token(&self) -> &str {
LapceLanguage::Ruby => "#",
LapceLanguage::Html => "",
LapceLanguage::Java => "//",
LapceLanguage::Markdown => "",
LapceLanguage::Ruby => "#",
}
}
@ -128,8 +122,6 @@ pub fn indent_unit(&self) -> &str {
LapceLanguage::Ruby => " ",
LapceLanguage::Html => " ",
LapceLanguage::Java => " ",
LapceLanguage::Markdown => " ",
LapceLanguage::Ruby => " ",
}
}
@ -154,8 +146,6 @@ fn tree_sitter_language(&self) -> tree_sitter::Language {
LapceLanguage::Ruby => tree_sitter_ruby::language(),
LapceLanguage::Html => tree_sitter_html::language(),
LapceLanguage::Java => tree_sitter_java::language(),
LapceLanguage::Markdown => tree_sitter_markdown::language(),
LapceLanguage::Ruby => tree_sitter_ruby::language(),
}
}
@ -186,8 +176,6 @@ pub(crate) fn new_highlight_config(&self) -> HighlightConfiguration {
LapceLanguage::Ruby => tree_sitter_ruby::HIGHLIGHT_QUERY,
LapceLanguage::Html => tree_sitter_html::HIGHLIGHT_QUERY,
LapceLanguage::Java => tree_sitter_java::HIGHLIGHT_QUERY,
LapceLanguage::Markdown => tree_sitter_markdown::HIGHLIGHTS_QUERY,
LapceLanguage::Ruby => tree_sitter_ruby::HIGHLIGHT_QUERY,
};
HighlightConfiguration::new(language, query, "", "").unwrap()

View File

@ -1220,7 +1220,7 @@ fn edit_with_command(&mut self, command: EditCommandKind) -> Option<RopeDelta> {
None
}
fn next_diff(&mut self, ctx: &mut EventCtx, _env: &Env) {
fn next_diff(&mut self, ctx: &mut EventCtx) {
if let BufferContent::File(buffer_path) = self.buffer.content() {
if self.source_control.file_diffs.is_empty() {
return;
@ -1299,7 +1299,7 @@ fn next_diff(&mut self, ctx: &mut EventCtx, _env: &Env) {
}
}
fn next_error(&mut self, ctx: &mut EventCtx, _env: &Env) {
fn next_error(&mut self, ctx: &mut EventCtx) {
if let BufferContent::File(buffer_path) = self.buffer.content() {
let mut file_diagnostics = self
.main_split
@ -2063,6 +2063,13 @@ fn run_focus_command(
ScrollDown => {
self.scroll(ctx, true, count.unwrap_or(1), mods);
}
CenterOfWindow => {
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::EnsureCursorCenter,
Target::Widget(self.editor.view_id),
));
}
ShowCodeActions => {
if let Some(actions) = self.current_code_actions() {
if !actions.is_empty() {
@ -2153,6 +2160,42 @@ fn run_focus_command(
JumpLocationForward => {
self.jump_location_forward(ctx);
}
NextError => {
self.next_error(ctx);
}
NextDiff => {
self.next_diff(ctx);
}
FormatDocument => {
if let BufferContent::File(path) = self.doc.content() {
let path = path.clone();
let proxy = self.proxy.clone();
let buffer_id = self.doc.id();
let rev = self.doc.rev();
let event_sink = ctx.get_external_handle();
let (sender, receiver) = bounded(1);
thread::spawn(move || {
proxy.get_document_formatting(
buffer_id,
Box::new(move |result| {
let _ = sender.send(result);
}),
);
let result = receiver
.recv_timeout(Duration::from_secs(1))
.map_or_else(
|e| Err(anyhow!("{}", e)),
|v| v.map_err(|e| anyhow!("{:?}", e)),
);
let _ = event_sink.submit_command(
LAPCE_UI_COMMAND,
LapceUICommand::DocumentFormat(path, rev, result),
Target::Auto,
);
});
}
}
Search => {
Arc::make_mut(&mut self.find).visual = true;
let region = match &self.editor.new_cursor.mode {
@ -3246,11 +3289,11 @@ fn run_command(
}
}
LapceCommandOld::NextError => {
self.next_error(ctx, env);
self.next_error(ctx);
}
LapceCommandOld::PreviousError => {}
LapceCommandOld::NextDiff => {
self.next_diff(ctx, env);
self.next_diff(ctx);
}
LapceCommandOld::PreviousDiff => {}
LapceCommandOld::ListNext => {

View File

@ -21,7 +21,6 @@
data::{FocusArea, LapceTabData, PanelKind},
proxy::LapceProxy,
split::SplitDirection,
state::Mode,
terminal::{EventProxy, LapceTerminalData, LapceTerminalViewData},
};
use lapce_rpc::terminal::TermId;