mirror of https://github.com/helix-editor/helix
add macros for language configuration and lsp configuration
parent
3e5710521a
commit
fda1bbf742
|
@ -3138,7 +3138,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "steel-core"
|
name = "steel-core"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
source = "git+https://github.com/mattwparas/steel.git#e6079567fba0ed3d30d9afc6d1ae8bed8d75ff15"
|
source = "git+https://github.com/mattwparas/steel.git#d470ff03602443499993cda594a725874319c018"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"abi_stable",
|
"abi_stable",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
@ -3190,7 +3190,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "steel-derive"
|
name = "steel-derive"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
source = "git+https://github.com/mattwparas/steel.git#e6079567fba0ed3d30d9afc6d1ae8bed8d75ff15"
|
source = "git+https://github.com/mattwparas/steel.git#d470ff03602443499993cda594a725874319c018"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -3200,7 +3200,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "steel-doc"
|
name = "steel-doc"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
source = "git+https://github.com/mattwparas/steel.git#e6079567fba0ed3d30d9afc6d1ae8bed8d75ff15"
|
source = "git+https://github.com/mattwparas/steel.git#d470ff03602443499993cda594a725874319c018"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"steel-core",
|
"steel-core",
|
||||||
]
|
]
|
||||||
|
@ -3208,7 +3208,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "steel-gen"
|
name = "steel-gen"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
source = "git+https://github.com/mattwparas/steel.git#e6079567fba0ed3d30d9afc6d1ae8bed8d75ff15"
|
source = "git+https://github.com/mattwparas/steel.git#d470ff03602443499993cda594a725874319c018"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"codegen",
|
"codegen",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -3217,7 +3217,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "steel-parser"
|
name = "steel-parser"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
source = "git+https://github.com/mattwparas/steel.git#e6079567fba0ed3d30d9afc6d1ae8bed8d75ff15"
|
source = "git+https://github.com/mattwparas/steel.git#d470ff03602443499993cda594a725874319c018"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"compact_str",
|
"compact_str",
|
||||||
"fxhash",
|
"fxhash",
|
||||||
|
|
|
@ -41,7 +41,7 @@ tree-sitter = { version = "0.22" }
|
||||||
nucleo = "0.5.0"
|
nucleo = "0.5.0"
|
||||||
slotmap = "1.0.7"
|
slotmap = "1.0.7"
|
||||||
# If working locally, use the local path dependency
|
# 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"] }
|
steel-core = { git = "https://github.com/mattwparas/steel.git", version = "0.6.0", features = ["anyhow", "dylibs", "sync"] }
|
||||||
thiserror = "2.0"
|
thiserror = "2.0"
|
||||||
tempfile = "3.19.1"
|
tempfile = "3.19.1"
|
||||||
|
|
|
@ -95,7 +95,7 @@ grep-searcher = "0.1.14"
|
||||||
# plugin support
|
# plugin support
|
||||||
steel-core = { workspace = true, optional = true }
|
steel-core = { workspace = true, optional = true }
|
||||||
steel-doc = { git = "https://github.com/mattwparas/steel.git", version = "0.6.0" }
|
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"
|
globset = "0.4.16"
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ use helix_view::{
|
||||||
},
|
},
|
||||||
events::{DocumentDidOpen, DocumentFocusLost, SelectionDidChange},
|
events::{DocumentDidOpen, DocumentFocusLost, SelectionDidChange},
|
||||||
extension::document_id_to_usize,
|
extension::document_id_to_usize,
|
||||||
|
graphics::CursorKind,
|
||||||
input::KeyEvent,
|
input::KeyEvent,
|
||||||
theme::Color,
|
theme::Color,
|
||||||
DocumentId, Editor, Theme, ViewId,
|
DocumentId, Editor, Theme, ViewId,
|
||||||
|
@ -31,7 +32,7 @@ use once_cell::sync::{Lazy, OnceCell};
|
||||||
use steel::{
|
use steel::{
|
||||||
compiler::modules::steel_home,
|
compiler::modules::steel_home,
|
||||||
gc::{unsafe_erased_pointers::CustomReference, ShareableMut},
|
gc::{unsafe_erased_pointers::CustomReference, ShareableMut},
|
||||||
rvals::{as_underlying_type, FromSteelVal, IntoSteelVal, SteelString},
|
rvals::{as_underlying_type, AsRefMutSteelVal, FromSteelVal, IntoSteelVal, SteelString},
|
||||||
steel_vm::{
|
steel_vm::{
|
||||||
engine::Engine, mutex_lock, mutex_unlock, register_fn::RegisterFn, ThreadStateController,
|
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,
|
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<SteelVal> {
|
||||||
|
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
|
module
|
||||||
.register_fn("raw-file-picker", || FilePickerConfig::default())
|
.register_fn("raw-file-picker", || FilePickerConfig::default())
|
||||||
.register_fn("register-file-picker", HelixConfiguration::file_picker)
|
.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("completion-replace", HelixConfiguration::completion_replace)
|
||||||
.register_fn("auto-info", HelixConfiguration::auto_info)
|
.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("true-color", HelixConfiguration::true_color)
|
||||||
.register_fn(
|
.register_fn(
|
||||||
"insert-final-newline",
|
"insert-final-newline",
|
||||||
|
@ -743,7 +772,110 @@ fn load_configuration_api(engine: &mut Engine, generate_sources: bool) {
|
||||||
|
|
||||||
if generate_sources {
|
if generate_sources {
|
||||||
let mut builtin_configuration_module =
|
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(
|
builtin_configuration_module.push_str(
|
||||||
r#"
|
r#"
|
||||||
|
@ -1137,7 +1269,7 @@ are shown, set to 5 for instant. Defaults to 250ms.
|
||||||
or to only insert new text
|
or to only insert new text
|
||||||
"#),
|
"#),
|
||||||
("auto-info", "Whether to display infoboxes. Defaults to true."),
|
("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`."),
|
("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`"),
|
("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`."),
|
("color-modes", "Whether to color modes with different colors. Defaults to `false`."),
|
||||||
|
@ -3446,10 +3578,6 @@ completion : string?
|
||||||
engine.register_module(module);
|
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
|
// TODO: Generate sources into the cogs directory, so that the
|
||||||
// LSP can go find it. When it comes to loading though, it'll look
|
// LSP can go find it. When it comes to loading though, it'll look
|
||||||
// up internally.
|
// up internally.
|
||||||
|
|
|
@ -617,6 +617,10 @@ pub enum StatusLineElement {
|
||||||
pub struct CursorShapeConfig([CursorKind; 3]);
|
pub struct CursorShapeConfig([CursorKind; 3]);
|
||||||
|
|
||||||
impl CursorShapeConfig {
|
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 {
|
pub fn from_mode(&self, mode: Mode) -> CursorKind {
|
||||||
self.get(mode as usize).copied().unwrap_or_default()
|
self.get(mode as usize).copied().unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue