experiment with initial idea
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -16657,8 +16657,6 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tree-sitter-python"
|
||||
version = "0.23.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d065aaa27f3aaceaf60c1f0e0ac09e1cb9eb8ed28e7bcdaa52129cffc7f4b04"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"tree-sitter-language",
|
||||
@@ -19799,6 +19797,7 @@ dependencies = [
|
||||
"title_bar",
|
||||
"toolchain_selector",
|
||||
"tree-sitter-md",
|
||||
"tree-sitter-python",
|
||||
"tree-sitter-rust",
|
||||
"ui",
|
||||
"ui_input",
|
||||
|
||||
@@ -589,7 +589,7 @@ tree-sitter-html = "0.23"
|
||||
tree-sitter-jsdoc = "0.23"
|
||||
tree-sitter-json = "0.24"
|
||||
tree-sitter-md = { git = "https://github.com/tree-sitter-grammars/tree-sitter-markdown", rev = "9a23c1a96c0513d8fc6520972beedd419a973539" }
|
||||
tree-sitter-python = "0.23"
|
||||
tree-sitter-python = { path = "../repos/tree-sitter-python"}
|
||||
tree-sitter-regex = "0.24"
|
||||
tree-sitter-ruby = "0.23"
|
||||
tree-sitter-rust = "0.24"
|
||||
|
||||
@@ -20750,23 +20750,23 @@ async fn test_outdent_after_input_for_python(cx: &mut TestAppContext) {
|
||||
"});
|
||||
|
||||
// TODO: test `except` auto outdents when typed inside `try` block right after for block
|
||||
// cx.set_state(indoc! {"
|
||||
// def main():
|
||||
// try:
|
||||
// for i in range(n):
|
||||
// pass
|
||||
// ˇ
|
||||
// "});
|
||||
// cx.update_editor(|editor, window, cx| {
|
||||
// editor.handle_input("except:", window, cx);
|
||||
// });
|
||||
// cx.assert_editor_state(indoc! {"
|
||||
// def main():
|
||||
// try:
|
||||
// for i in range(n):
|
||||
// pass
|
||||
// except:ˇ
|
||||
// "});
|
||||
cx.set_state(indoc! {"
|
||||
def main():
|
||||
try:
|
||||
for i in range(n):
|
||||
pass
|
||||
ˇ
|
||||
"});
|
||||
cx.update_editor(|editor, window, cx| {
|
||||
editor.handle_input("except:", window, cx);
|
||||
});
|
||||
cx.assert_editor_state(indoc! {"
|
||||
def main():
|
||||
try:
|
||||
for i in range(n):
|
||||
pass
|
||||
except:ˇ
|
||||
"});
|
||||
|
||||
// TODO: test `else` auto outdents when typed inside `except` block right after for block
|
||||
// cx.set_state(indoc! {"
|
||||
@@ -20792,31 +20792,31 @@ async fn test_outdent_after_input_for_python(cx: &mut TestAppContext) {
|
||||
// "});
|
||||
|
||||
// TODO: test `finally` auto outdents when typed inside `else` block right after for block
|
||||
// cx.set_state(indoc! {"
|
||||
// def main():
|
||||
// try:
|
||||
// i = 2
|
||||
// except:
|
||||
// j = 2
|
||||
// else:
|
||||
// for i in range(n):
|
||||
// pass
|
||||
// ˇ
|
||||
// "});
|
||||
// cx.update_editor(|editor, window, cx| {
|
||||
// editor.handle_input("finally:", window, cx);
|
||||
// });
|
||||
// cx.assert_editor_state(indoc! {"
|
||||
// def main():
|
||||
// try:
|
||||
// i = 2
|
||||
// except:
|
||||
// j = 2
|
||||
// else:
|
||||
// for i in range(n):
|
||||
// pass
|
||||
// finally:ˇ
|
||||
// "});
|
||||
cx.set_state(indoc! {"
|
||||
def main():
|
||||
try:
|
||||
i = 2
|
||||
except:
|
||||
j = 2
|
||||
else:
|
||||
for i in range(n):
|
||||
pass
|
||||
ˇ
|
||||
"});
|
||||
cx.update_editor(|editor, window, cx| {
|
||||
editor.handle_input("finally:", window, cx);
|
||||
});
|
||||
cx.assert_editor_state(indoc! {"
|
||||
def main():
|
||||
try:
|
||||
i = 2
|
||||
except:
|
||||
j = 2
|
||||
else:
|
||||
for i in range(n):
|
||||
pass
|
||||
finally:ˇ
|
||||
"});
|
||||
|
||||
// test `else` stays at correct indent when typed after `for` block
|
||||
cx.set_state(indoc! {"
|
||||
|
||||
@@ -2985,6 +2985,7 @@ impl BufferSnapshot {
|
||||
},
|
||||
);
|
||||
|
||||
dbg!(&indent_change_rows);
|
||||
let mut indent_changes = indent_change_rows.into_iter().peekable();
|
||||
let mut prev_row = if config.auto_indent_using_last_non_empty_line {
|
||||
prev_non_blank_row.unwrap_or(0)
|
||||
@@ -3021,7 +3022,9 @@ impl BufferSnapshot {
|
||||
indent_changes.next();
|
||||
}
|
||||
|
||||
dbg!(&indent_ranges, &row, &prev_row, &row_start, &prev_row_start);
|
||||
for range in &indent_ranges {
|
||||
println!("---");
|
||||
if range.start.row >= row {
|
||||
break;
|
||||
}
|
||||
@@ -3043,27 +3046,37 @@ impl BufferSnapshot {
|
||||
.iter()
|
||||
.any(|e| e.start.row < row && e.end > row_start);
|
||||
|
||||
dbg!(
|
||||
&prev_row,
|
||||
&outdent_to_row,
|
||||
&outdent_from_prev_row,
|
||||
&indent_from_prev_row
|
||||
);
|
||||
let suggestion = if outdent_to_row == prev_row
|
||||
|| (outdent_from_prev_row && indent_from_prev_row)
|
||||
{
|
||||
println!("1");
|
||||
Some(IndentSuggestion {
|
||||
basis_row: prev_row,
|
||||
delta: Ordering::Equal,
|
||||
within_error: within_error && !from_regex,
|
||||
})
|
||||
} else if indent_from_prev_row {
|
||||
println!("2");
|
||||
Some(IndentSuggestion {
|
||||
basis_row: prev_row,
|
||||
delta: Ordering::Greater,
|
||||
within_error: within_error && !from_regex,
|
||||
})
|
||||
} else if outdent_to_row < prev_row {
|
||||
println!("3");
|
||||
Some(IndentSuggestion {
|
||||
basis_row: outdent_to_row,
|
||||
delta: Ordering::Equal,
|
||||
within_error: within_error && !from_regex,
|
||||
})
|
||||
} else if outdent_from_prev_row {
|
||||
println!("4");
|
||||
Some(IndentSuggestion {
|
||||
basis_row: prev_row,
|
||||
delta: Ordering::Less,
|
||||
@@ -3071,12 +3084,14 @@ impl BufferSnapshot {
|
||||
})
|
||||
} else if config.auto_indent_using_last_non_empty_line || !self.is_line_blank(prev_row)
|
||||
{
|
||||
println!("5");
|
||||
Some(IndentSuggestion {
|
||||
basis_row: prev_row,
|
||||
delta: Ordering::Equal,
|
||||
within_error: within_error && !from_regex,
|
||||
})
|
||||
} else {
|
||||
println!("6");
|
||||
None
|
||||
};
|
||||
|
||||
|
||||
@@ -225,7 +225,7 @@ impl Markdown {
|
||||
self.parse(cx);
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-support")]
|
||||
// #[cfg(feature = "test-support")]
|
||||
pub fn parsed_markdown(&self) -> &ParsedMarkdown {
|
||||
&self.parsed_markdown
|
||||
}
|
||||
|
||||
@@ -147,6 +147,7 @@ zed_actions.workspace = true
|
||||
zeta.workspace = true
|
||||
zlog.workspace = true
|
||||
zlog_settings.workspace = true
|
||||
tree-sitter-python.workspace = true
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
windows.workspace = true
|
||||
|
||||
Reference in New Issue
Block a user