diff --git a/Cargo.lock b/Cargo.lock index 8157f249d..1302aa24f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3138,7 +3138,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "steel-core" version = "0.6.0" -source = "git+https://github.com/mattwparas/steel.git#e6079567fba0ed3d30d9afc6d1ae8bed8d75ff15" +source = "git+https://github.com/mattwparas/steel.git#d470ff03602443499993cda594a725874319c018" dependencies = [ "abi_stable", "anyhow", @@ -3190,7 +3190,7 @@ dependencies = [ [[package]] name = "steel-derive" version = "0.5.0" -source = "git+https://github.com/mattwparas/steel.git#e6079567fba0ed3d30d9afc6d1ae8bed8d75ff15" +source = "git+https://github.com/mattwparas/steel.git#d470ff03602443499993cda594a725874319c018" dependencies = [ "proc-macro2", "quote", @@ -3200,7 +3200,7 @@ dependencies = [ [[package]] name = "steel-doc" version = "0.6.0" -source = "git+https://github.com/mattwparas/steel.git#e6079567fba0ed3d30d9afc6d1ae8bed8d75ff15" +source = "git+https://github.com/mattwparas/steel.git#d470ff03602443499993cda594a725874319c018" dependencies = [ "steel-core", ] @@ -3208,7 +3208,7 @@ dependencies = [ [[package]] name = "steel-gen" version = "0.2.0" -source = "git+https://github.com/mattwparas/steel.git#e6079567fba0ed3d30d9afc6d1ae8bed8d75ff15" +source = "git+https://github.com/mattwparas/steel.git#d470ff03602443499993cda594a725874319c018" dependencies = [ "codegen", "serde", @@ -3217,7 +3217,7 @@ dependencies = [ [[package]] name = "steel-parser" version = "0.6.0" -source = "git+https://github.com/mattwparas/steel.git#e6079567fba0ed3d30d9afc6d1ae8bed8d75ff15" +source = "git+https://github.com/mattwparas/steel.git#d470ff03602443499993cda594a725874319c018" dependencies = [ "compact_str", "fxhash", diff --git a/Cargo.toml b/Cargo.toml index 33c69305d..82c179afb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ tree-sitter = { version = "0.22" } nucleo = "0.5.0" slotmap = "1.0.7" # If working locally, use the local path dependency -# steel-core = { path = "/Users/matt/code/scratch/reviews/steel/crates/steel-core", version = "0.6.0", features = ["anyhow", "dylibs", "sync"] } +# steel-core = { path = "/home/matt/code/scratch/steel/crates/steel-core", version = "0.6.0", features = ["anyhow", "dylibs", "sync"] } steel-core = { git = "https://github.com/mattwparas/steel.git", version = "0.6.0", features = ["anyhow", "dylibs", "sync"] } thiserror = "2.0" tempfile = "3.19.1" diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index 8bddbcf7f..352f89260 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -95,7 +95,7 @@ grep-searcher = "0.1.14" # plugin support steel-core = { workspace = true, optional = true } steel-doc = { git = "https://github.com/mattwparas/steel.git", version = "0.6.0" } -# steel-doc = { path = "/Users/matt/code/scratch/reviews/steel/crates/steel-doc", version = "0.6.0" } +# steel-doc = { path = "/home/matt/code/scratch/steel/crates/steel-doc", version = "0.6.0" } globset = "0.4.16" diff --git a/helix-term/src/commands/engine/steel.rs b/helix-term/src/commands/engine/steel.rs index 9c82bf19d..35ce32cfd 100644 --- a/helix-term/src/commands/engine/steel.rs +++ b/helix-term/src/commands/engine/steel.rs @@ -23,6 +23,7 @@ use helix_view::{ }, events::{DocumentDidOpen, DocumentFocusLost, SelectionDidChange}, extension::document_id_to_usize, + graphics::CursorKind, input::KeyEvent, theme::Color, DocumentId, Editor, Theme, ViewId, @@ -31,7 +32,7 @@ use once_cell::sync::{Lazy, OnceCell}; use steel::{ compiler::modules::steel_home, gc::{unsafe_erased_pointers::CustomReference, ShareableMut}, - rvals::{as_underlying_type, FromSteelVal, IntoSteelVal, SteelString}, + rvals::{as_underlying_type, AsRefMutSteelVal, FromSteelVal, IntoSteelVal, SteelString}, steel_vm::{ engine::Engine, mutex_lock, mutex_unlock, register_fn::RegisterFn, ThreadStateController, }, @@ -639,6 +640,34 @@ fn load_configuration_api(engine: &mut Engine, generate_sources: bool) { update_configuration_for_all_open_documents, ); + module + .register_fn("raw-cursor-shape", || CursorShapeConfig::default()) + .register_fn( + "raw-cursor-shape-set!", + |value: SteelVal, mode: String, shape: String| -> anyhow::Result { + let mut config = CursorShapeConfig::as_mut_ref(&value)?; + + let mode = match mode.as_str() { + "normal" => Mode::Normal, + "select" => Mode::Select, + "insert" => Mode::Insert, + _ => anyhow::bail!("Unable to match mode from string: {}", mode), + }; + + let kind = match shape.as_str() { + "block" => CursorKind::Block, + "bar" => CursorKind::Bar, + "underline" => CursorKind::Underline, + "hidden" => CursorKind::Hidden, + _ => anyhow::bail!("Unable to match cursor kind from string: {}", shape), + }; + + config.update(mode, kind); + drop(config); + Ok(value) + }, + ); + module .register_fn("raw-file-picker", || FilePickerConfig::default()) .register_fn("register-file-picker", HelixConfiguration::file_picker) @@ -708,7 +737,7 @@ fn load_configuration_api(engine: &mut Engine, generate_sources: bool) { ) .register_fn("completion-replace", HelixConfiguration::completion_replace) .register_fn("auto-info", HelixConfiguration::auto_info) - .register_fn("cursor-shape", HelixConfiguration::cursor_shape) + .register_fn("#%raw-cursor-shape", HelixConfiguration::cursor_shape) .register_fn("true-color", HelixConfiguration::true_color) .register_fn( "insert-final-newline", @@ -743,7 +772,110 @@ fn load_configuration_api(engine: &mut Engine, generate_sources: bool) { if generate_sources { let mut builtin_configuration_module = - "(require-builtin helix/core/configuration as helix.)".to_string(); + r#"(require-builtin helix/core/configuration as helix.) +(provide define-lsp) +(define-syntax define-lsp + (syntax-rules (#%crunch #%name #%conf) + ;; Other generic keys + [(_ #%crunch #%name name #%conf conf (key (inner-key value) ...)) + (set-lsp-config! name + (hash-insert conf + (quote key) + (transduce (list (list (quote inner-key) value) ...) + (into-hashmap))))] + + [(_ #%crunch #%name name #%conf conf (key (inner-key value) ...) remaining ...) + ; ;; Crunch the remaining stuff + (define-lsp #%crunch + #%name + name + #%conf + (hash-insert conf + (quote key) + (transduce (list (list (quote inner-key) value) ...) (into-hashmap))) + remaining ...)] + + ;; Other generic keys + [(_ #%crunch #%name name #%conf conf (key value)) + (set-lsp-config! name (hash-insert conf (quote key) value))] + + [(_ #%crunch #%name name #%conf conf (key value) remaining ...) + ; ;; Crunch the remaining stuff + (define-lsp #%crunch #%name name #%conf (hash-insert conf (quote key) value) remaining ...)] + + [(_ name (key value ...) ...) + (define-lsp #%crunch #%name name #%conf (hash "name" name) (key value ...) ...)] + + [(_ name (key value)) (define-lsp #%crunch #%name name #%conf (hash "name" name) (key value))] + + [(_ name (key value) ...) (define-lsp #%crunch #%name name #%conf (hash "name" name) (key value) ...)])) + +(provide language) +(define-syntax language + (syntax-rules (#%crunch #%name #%conf) + + ;; Other generic keys + [(_ #%crunch #%name name #%conf conf (key (inner-key value) ...)) + (update-language-config! name + (hash-insert conf + (quote key) + (transduce (list (list (quote inner-key) value) ...) + (into-hashmap))))] + + [(_ #%crunch #%name name #%conf conf (key (inner-key value) ...) remaining ...) + ; ;; Crunch the remaining stuff + (language #%crunch + #%name + name + #%conf + (hash-insert conf + (quote key) + (transduce (list (list (quote inner-key) value) ...) (into-hashmap))) + remaining ...)] + + ;; Other generic keys + [(_ #%crunch #%name name #%conf conf (key value)) + (update-language-config! name (hash-insert conf (quote key) value))] + + [(_ #%crunch #%name name #%conf conf (key value) remaining ...) + ; ;; Crunch the remaining stuff + (language #%crunch #%name name #%conf (hash-insert conf (quote key) value) remaining ...)] + + [(_ name (key value ...) ...) + (language #%crunch #%name name #%conf (hash "name" name) (key value ...) ...)] + + [(_ name (key value)) (language #%crunch #%name name #%conf (hash "name" name) (key value))] + + [(_ name (key value) ...) + (language #%crunch #%name name #%conf (hash "name" name) (key value) ...)])) +"# + .to_string(); + + builtin_configuration_module.push_str( + r#" +(provide cursor-shape) +;;@doc +;; Shape for cursor in each mode +;; +;; (cursor-shape #:normal (normal 'block) +;; #:select (select 'block) +;; #:insert (insert 'block)) +;; +;; # Examples +;; +;; ```scheme +;; (cursor-shape #:normal 'block #:select 'underline #:insert 'bar) +;; ``` +(define (cursor-shape #:normal (normal 'block) + #:select (select 'block) + #:insert (insert 'block)) + (define cursor-shape-config (helix.raw-cursor-shape)) + (helix.raw-cursor-shape-set! cursor-shape-config 'normal normal) + (helix.raw-cursor-shape-set! cursor-shape-config 'select select) + (helix.raw-cursor-shape-set! cursor-shape-config 'insert insert) + (helix.#%raw-cursor-shape *helix.config* cursor-shape-config)) + "#, + ); builtin_configuration_module.push_str( r#" @@ -1137,7 +1269,7 @@ are shown, set to 5 for instant. Defaults to 250ms. or to only insert new text "#), ("auto-info", "Whether to display infoboxes. Defaults to true."), - ("cursor-shape", "Shape for cursor in each mode"), + // ("cursor-shape", "Shape for cursor in each mode"), ("true-color", "Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. Defaults to `false`."), ("insert-final-newline", "Whether to automatically insert a trailing line-ending on write if missing. Defaults to `true`"), ("color-modes", "Whether to color modes with different colors. Defaults to `false`."), @@ -3446,10 +3578,6 @@ completion : string? engine.register_module(module); } -pub fn helix_runtime_search_path() -> PathBuf { - helix_loader::config_dir().join("helix") -} - // TODO: Generate sources into the cogs directory, so that the // LSP can go find it. When it comes to loading though, it'll look // up internally. diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 4819bb5c3..3de58a0ec 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -617,6 +617,10 @@ pub enum StatusLineElement { pub struct CursorShapeConfig([CursorKind; 3]); impl CursorShapeConfig { + pub fn update(&mut self, mode: Mode, kind: CursorKind) { + self.0[mode as usize] = kind; + } + pub fn from_mode(&self, mode: Mode) -> CursorKind { self.get(mode as usize).copied().unwrap_or_default() }