2021-06-18 06:09:10 +08:00
|
|
|
#[macro_use]
|
|
|
|
pub mod macros;
|
|
|
|
|
Move LSP code actions into helix-view, enable internal actions
This change moves the LSP code actions handling code into helix-view
and introduces a generic action type. This encapsulates all of the LSP
code action details in the new `action` module and paves the way for
future internal actions. (Note that we could alternatively encapsulate
the LSP details in `handlers/lsp.rs`.)
For example, the spell checking integration will be able to write
actions for a spelling mistake like so:
let mut actions = Vec::new()
for suggestion in suggestions {
actions.push(Action::new(
format!("Replace '{word}' with '{suggestion}'"),
PRIORITY,
// This closure's environment would capture a `doc_id`,
// `view_id`, and the `suggestion`.
move |editor| {
// Create and apply a Transaction to replace `word`'s
// range in the source document with the suggestion
// string. Clear any diagnostics for that spelling
// mistake.
todo!()
}
))
}
let word = word.to_string();
actions.push(Action::new(
format!("Add '{word}' to the dictionary"),
PRIORITY,
// This closure's environment would capture the word. If
// multiple languages/dictionaries are supported then it would
// also capture the language.
move |editor| {
editor.dictionary.add(&word);
// Re-check any documents using this dictionary.
todo!()
}
))
Since all LSP details are now in `actions`, the `code_action` command
has been moved to the general `commands` module - the function is now
only in charge of UI interactions.
This change also makes a patch to the LSP code actions code: all actions
are now combined into a Vec and sorted together. Beforehand, each
language server's code actions were sorted separately and then collected
into one list based on the order in which the language server was
defined.
2025-03-20 21:44:16 +08:00
|
|
|
mod action;
|
2024-01-30 00:11:00 +08:00
|
|
|
pub mod annotations;
|
2023-12-01 07:03:26 +08:00
|
|
|
pub mod base64;
|
2021-06-15 05:37:17 +08:00
|
|
|
pub mod clipboard;
|
2020-10-22 13:35:07 +08:00
|
|
|
pub mod document;
|
2020-10-16 11:29:22 +08:00
|
|
|
pub mod editor;
|
2023-12-01 07:03:26 +08:00
|
|
|
pub mod events;
|
2025-02-27 09:50:15 +08:00
|
|
|
pub mod expansion;
|
2021-06-25 11:58:15 +08:00
|
|
|
pub mod graphics;
|
2021-11-23 11:56:46 +08:00
|
|
|
pub mod gutter;
|
2023-12-01 07:03:26 +08:00
|
|
|
pub mod handlers;
|
2021-06-19 23:54:37 +08:00
|
|
|
pub mod info;
|
2021-06-23 01:04:04 +08:00
|
|
|
pub mod input;
|
2021-06-25 11:58:15 +08:00
|
|
|
pub mod keyboard;
|
2023-07-11 05:30:42 +08:00
|
|
|
pub mod register;
|
2020-09-21 17:24:16 +08:00
|
|
|
pub mod theme;
|
2021-02-03 18:36:54 +08:00
|
|
|
pub mod tree;
|
2020-09-21 17:24:16 +08:00
|
|
|
pub mod view;
|
|
|
|
|
2021-11-25 10:07:23 +08:00
|
|
|
use std::num::NonZeroUsize;
|
|
|
|
|
|
|
|
// uses NonZeroUsize so Option<DocumentId> use a byte rather than two
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
|
|
|
pub struct DocumentId(NonZeroUsize);
|
|
|
|
|
|
|
|
impl Default for DocumentId {
|
|
|
|
fn default() -> DocumentId {
|
|
|
|
// Safety: 1 is non-zero
|
|
|
|
DocumentId(unsafe { NonZeroUsize::new_unchecked(1) })
|
|
|
|
}
|
|
|
|
}
|
2021-11-04 12:43:45 +08:00
|
|
|
|
2021-11-10 09:06:40 +08:00
|
|
|
impl std::fmt::Display for DocumentId {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
f.write_fmt(format_args!("{}", self.0))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-23 01:04:04 +08:00
|
|
|
slotmap::new_key_type! {
|
|
|
|
pub struct ViewId;
|
|
|
|
}
|
2021-03-16 17:27:57 +08:00
|
|
|
|
2022-03-22 11:53:44 +08:00
|
|
|
pub enum Align {
|
|
|
|
Top,
|
|
|
|
Center,
|
|
|
|
Bottom,
|
|
|
|
}
|
|
|
|
|
2024-07-24 01:54:00 +08:00
|
|
|
pub fn align_view(doc: &mut Document, view: &View, align: Align) {
|
2023-02-01 01:03:19 +08:00
|
|
|
let doc_text = doc.text().slice(..);
|
|
|
|
let cursor = doc.selection(view.id).primary().cursor(doc_text);
|
|
|
|
let viewport = view.inner_area(doc);
|
|
|
|
let last_line_height = viewport.height.saturating_sub(1);
|
2024-07-24 01:54:00 +08:00
|
|
|
let mut view_offset = doc.view_offset(view.id);
|
2022-03-22 11:53:44 +08:00
|
|
|
|
|
|
|
let relative = match align {
|
2022-10-11 01:12:48 +08:00
|
|
|
Align::Center => last_line_height / 2,
|
2022-03-22 11:53:44 +08:00
|
|
|
Align::Top => 0,
|
2022-10-11 01:12:48 +08:00
|
|
|
Align::Bottom => last_line_height,
|
2022-03-22 11:53:44 +08:00
|
|
|
};
|
|
|
|
|
2023-02-01 01:03:19 +08:00
|
|
|
let text_fmt = doc.text_format(viewport.width, None);
|
2024-07-24 01:54:00 +08:00
|
|
|
(view_offset.anchor, view_offset.vertical_offset) = char_idx_at_visual_offset(
|
2023-02-01 01:03:19 +08:00
|
|
|
doc_text,
|
|
|
|
cursor,
|
|
|
|
-(relative as isize),
|
|
|
|
0,
|
|
|
|
&text_fmt,
|
2024-07-24 01:54:00 +08:00
|
|
|
&view.text_annotations(doc, None),
|
2023-02-01 01:03:19 +08:00
|
|
|
);
|
2024-07-24 01:54:00 +08:00
|
|
|
doc.set_view_offset(view.id, view_offset);
|
2022-03-22 11:53:44 +08:00
|
|
|
}
|
|
|
|
|
Move LSP code actions into helix-view, enable internal actions
This change moves the LSP code actions handling code into helix-view
and introduces a generic action type. This encapsulates all of the LSP
code action details in the new `action` module and paves the way for
future internal actions. (Note that we could alternatively encapsulate
the LSP details in `handlers/lsp.rs`.)
For example, the spell checking integration will be able to write
actions for a spelling mistake like so:
let mut actions = Vec::new()
for suggestion in suggestions {
actions.push(Action::new(
format!("Replace '{word}' with '{suggestion}'"),
PRIORITY,
// This closure's environment would capture a `doc_id`,
// `view_id`, and the `suggestion`.
move |editor| {
// Create and apply a Transaction to replace `word`'s
// range in the source document with the suggestion
// string. Clear any diagnostics for that spelling
// mistake.
todo!()
}
))
}
let word = word.to_string();
actions.push(Action::new(
format!("Add '{word}' to the dictionary"),
PRIORITY,
// This closure's environment would capture the word. If
// multiple languages/dictionaries are supported then it would
// also capture the language.
move |editor| {
editor.dictionary.add(&word);
// Re-check any documents using this dictionary.
todo!()
}
))
Since all LSP details are now in `actions`, the `code_action` command
has been moved to the general `commands` module - the function is now
only in charge of UI interactions.
This change also makes a patch to the LSP code actions code: all actions
are now combined into a Vec and sorted together. Beforehand, each
language server's code actions were sorted separately and then collected
into one list based on the order in which the language server was
defined.
2025-03-20 21:44:16 +08:00
|
|
|
pub use action::Action;
|
2020-10-22 13:35:07 +08:00
|
|
|
pub use document::Document;
|
2020-10-16 11:29:22 +08:00
|
|
|
pub use editor::Editor;
|
2023-02-01 01:03:19 +08:00
|
|
|
use helix_core::char_idx_at_visual_offset;
|
2020-10-19 16:18:03 +08:00
|
|
|
pub use theme::Theme;
|
2020-09-21 17:24:16 +08:00
|
|
|
pub use view::View;
|