checkpoint

pull/8675/merge^2
mattwparas 1 year ago
parent 4aac10fbab
commit a0153fb50b

60
Cargo.lock generated

@ -2053,6 +2053,41 @@ dependencies = [
"minimal-lexical",
]
[[package]]
name = "num"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606"
dependencies = [
"num-bigint",
"num-complex",
"num-integer",
"num-iter",
"num-rational",
"num-traits",
]
[[package]]
name = "num-bigint"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
"serde",
]
[[package]]
name = "num-complex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d"
dependencies = [
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.45"
@ -2063,6 +2098,29 @@ dependencies = [
"num-traits",
]
[[package]]
name = "num-iter"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0"
dependencies = [
"autocfg",
"num-bigint",
"num-integer",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.15"
@ -2636,6 +2694,7 @@ dependencies = [
"lazy_static",
"log",
"logos",
"num",
"once_cell",
"pretty",
"quickscope",
@ -2679,6 +2738,7 @@ name = "steel-parser"
version = "0.2.0"
dependencies = [
"logos",
"num-bigint",
"serde",
"serde_derive",
]

@ -1,6 +1,7 @@
use steel::gc::unsafe_erased_pointers::CustomReference;
impl steel::rvals::Custom for crate::Position {}
impl steel::rvals::Custom for crate::Selection {}
struct SRopeSlice<'a>(crate::RopeSlice<'a>);

@ -858,9 +858,13 @@ fn call_indent_hook(
}
// TODO: Don't unwrap here, we don't want that
if LISP_WORDS.contains(
line.slice(offset..offset + end).as_str().unwrap(),
) {
// if LISP_WORDS.contains(
// line.slice(offset..offset + end).as_str().unwrap(),
// ) {
// return Some(" ".repeat(offset + 1));
// }
if line.slice(offset..offset + end).as_str().map(|x| LISP_WORDS.contains(x)).unwrap_or_default() {
return Some(" ".repeat(offset + 1));
}
@ -1023,6 +1027,10 @@ pub fn custom_indent_for_newline(
return Some(" ".repeat(offset + 1));
}
// if line.slice(offset..offset + end).as_str().map(|x| LISP_WORDS.contains(x)).unwrap_or_default() {
// return Some(" ".repeat(offset + 1));
// }
for _ in char_iter_from_paren
.take_while(|(_, x)| x.is_whitespace())
{

@ -1,6 +1,6 @@
use fuzzy_matcher::FuzzyMatcher;
use helix_core::{graphemes, Tendril};
use helix_view::{document::Mode, Document, DocumentId, Editor};
use helix_core::{graphemes, Tendril, Selection};
use helix_view::{document::Mode, Document, DocumentId, Editor, editor::Action};
use once_cell::sync::Lazy;
use steel::{
gc::unsafe_erased_pointers::CustomReference,
@ -556,6 +556,12 @@ fn configure_engine() -> std::rc::Rc<std::cell::RefCell<steel::steel_vm::engine:
engine.register_fn("editor-focus", current_focus);
engine.register_fn("editor->doc-id", get_document_id);
engine.register_fn("editor-switch!", switch);
engine.register_fn("editor-set-focus!", Editor::focus);
engine.register_fn("editor-mode", editor_get_mode);
engine.register_fn("editor-set-mode!", editor_set_mode);
engine.register_fn("editor-doc-in-view?", is_document_in_view);
// engine.register_fn("editor->get-document", get_document);
// TODO: These are some horrendous type annotations, however... they do work?
@ -634,8 +640,7 @@ fn configure_engine() -> std::rc::Rc<std::cell::RefCell<steel::steel_vm::engine:
// .load_modules_from_directory(Some(
// helix_loader::config_dir()
// .join("extensions")
// .to_str()
// .unwrap()
// .to_str()tor // .unwrap()
// .to_string(),
// ));
@ -710,6 +715,13 @@ fn configure_engine() -> std::rc::Rc<std::cell::RefCell<steel::steel_vm::engine:
module.register_fn("insert_string", insert_string);
module.register_fn("current_selection", get_selection);
module.register_fn("current-highlighted-text!", get_highlighted_text);
module.register_fn("get-current-line-number", current_line_number);
module.register_fn("current-selection-object", current_selection);
module.register_fn("set-current-selection-object!", set_selection);
module.register_fn("run-in-engine!", run_in_engine);
module.register_fn("get-helix-scm-path", get_helix_scm_path);
module.register_fn("get-init-scm-path", get_init_scm_path);
@ -831,6 +843,27 @@ fn get_highlighted_text(cx: &mut Context) -> String {
doc.selection(view.id).primary().slice(text).to_string()
}
fn current_selection(cx: &mut Context) -> Selection {
let (view, doc) = current_ref!(cx.editor);
doc.selection(view.id).clone()
}
fn set_selection(cx: &mut Context, selection: Selection) {
let (view, doc) = current!(cx.editor);
doc.set_selection(view.id, selection)
}
fn current_line_number(cx: &mut Context) -> usize {
let (view, doc) = current_ref!(cx.editor);
helix_core::coords_at_pos(
doc.text().slice(..),
doc
.selection(view.id)
.primary()
.cursor(doc.text().slice(..)),
).row
}
fn get_selection(cx: &mut Context) -> String {
let (view, doc) = current_ref!(cx.editor);
let text = doc.text().slice(..);
@ -921,6 +954,10 @@ fn current_path(cx: &mut Context) -> Option<String> {
current_doc.and_then(|x| x.path().and_then(|x| x.to_str().map(|x| x.to_string())))
}
fn cx_current_focus(cx: &mut Context) -> helix_view::ViewId {
cx.editor.tree.focus
}
// TODO: Expose the below in a separate module, make things a bit more clear!
fn current_focus(editor: &mut Editor) -> helix_view::ViewId {
@ -937,6 +974,10 @@ fn get_document(editor: &mut Editor, doc_id: DocumentId) -> &Document {
editor.documents.get(&doc_id).unwrap()
}
fn is_document_in_view(editor: &mut Editor, doc_id: DocumentId) -> Option<helix_view::ViewId> {
editor.tree.traverse().find(|(_, v)| v.doc == doc_id).map(|(id, _)| id)
}
fn document_exists(editor: &mut Editor, doc_id: DocumentId) -> bool {
editor.documents.get(&doc_id).is_some()
}
@ -945,6 +986,32 @@ fn document_path(doc: &Document) -> Option<String> {
doc.path().and_then(|x| x.to_str()).map(|x| x.to_string())
}
fn switch(editor: &mut Editor, doc_id: DocumentId) {
editor.switch(doc_id, Action::VerticalSplit)
}
// fn editor_set_focus(editor: &mut Editor, view_id: helix_view::ViewId) {
// editor.tree.focus = view_id
// }
fn editor_get_mode(editor: &mut Editor) -> Mode {
editor.mode
}
fn editor_set_mode(editor: &mut Editor, mode: Mode) {
editor.mode = mode
}
// fn insert_text(cx: &mut Context, text: String) {
// let count = cx.count();
// let reg_name = cx.register.unwrap_or('"');
// let (view, doc) = current!(cx.editor);
// let registers = &mut cx.editor.registers;
// if let Some(values) = registers.read(reg_name) {
// paste_impl(values, doc, view, pos, count, cx.editor.mode);
// }
// }
// cx->editor
//

@ -805,6 +805,8 @@ use futures_util::stream::{Flatten, Once};
impl steel::gc::unsafe_erased_pointers::CustomReference for Editor {}
steel::custom_reference!(Editor);
impl steel::rvals::Custom for Mode {}
#[repr(C)]
pub struct Editor {
/// Current editing mode.

Loading…
Cancel
Save