From 9ac0c951615d624041836cdd7afd869391c72fff Mon Sep 17 00:00:00 2001 From: CossonLeo Date: Mon, 18 Oct 2021 14:14:50 +0800 Subject: Improve completion trigger (#838) * improve idle completion trigger * add completion-trigger-len to book * rename semantics_completion to language_server_completion and optimize idle completion trigger--- helix-term/src/application.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'helix-term/src/application.rs') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 0e7d0e55..a7281ecf 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -235,7 +235,7 @@ impl Application { } pub fn handle_idle_timeout(&mut self) { - use crate::commands::{completion, Context}; + use crate::commands::{insert::idle_completion, Context}; use helix_view::document::Mode; if doc_mut!(self.editor).mode != Mode::Insert || !self.config.editor.auto_completion { @@ -262,7 +262,7 @@ impl Application { callback: None, on_next_key_callback: None, }; - completion(&mut cx); + idle_completion(&mut cx); self.render(); } -- cgit v1.2.3-70-g09d2 From e9b23c29d8e8bca1d4140d02350bdae824a651b0 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Wed, 20 Oct 2021 00:00:28 +0900 Subject: Ignore errors when disabling mouse capture --- helix-term/src/application.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'helix-term/src/application.rs') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index a7281ecf..82ad04d7 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -563,7 +563,9 @@ impl Application { let mut stdout = stdout(); // reset cursor shape write!(stdout, "\x1B[2 q")?; - execute!(stdout, DisableMouseCapture)?; + // Ignore errors on disabling, this might trigger on windows if we call + // disable without calling enable previously + let _ = execute!(stdout, DisableMouseCapture); execute!(stdout, terminal::LeaveAlternateScreen)?; terminal::disable_raw_mode()?; Ok(()) -- cgit v1.2.3-70-g09d2 From d61e5e686be14b61b6d26c591147f8bfedd378bf Mon Sep 17 00:00:00 2001 From: radical3dd Date: Tue, 26 Oct 2021 02:43:14 +0200 Subject: Use current dir for file picker, after change dir. (#910) --- helix-term/src/application.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'helix-term/src/application.rs') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 82ad04d7..662573c6 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -102,7 +102,7 @@ impl Application { if first.is_dir() { std::env::set_current_dir(&first)?; editor.new_file(Action::VerticalSplit); - compositor.push(Box::new(ui::file_picker(first.clone()))); + compositor.push(Box::new(ui::file_picker(".".into()))); } else { let nr_of_files = args.files.len(); editor.open(first.to_path_buf(), Action::VerticalSplit)?; -- cgit v1.2.3-70-g09d2 From e2ed6915373adf27881325ebc4e2c6b98e207af3 Mon Sep 17 00:00:00 2001 From: Omnikar Date: Wed, 27 Oct 2021 21:23:46 -0400 Subject: Implement `hx --tutor` and `:tutor` to load `tutor.txt` (#898) * Implement `hx --tutor` and `:tutor` to load `tutor.txt` * Document `hx --tutor` and `:tutor` * Change `Document::set_path` to take an `Option` * `Document::set_path` accepts an `Option<&Path>` instead of `&Path`. * Remove `Editor::open_tutor` and make tutor-open functionality use `Editor::open` and `Document::set_path`. * Use `PathBuf::join` Co-authored-by: Ivan Tham * Add comments explaining unsetting tutor path Co-authored-by: Ivan Tham --- book/src/usage.md | 2 +- helix-term/src/application.rs | 7 ++++++- helix-term/src/args.rs | 2 ++ helix-term/src/commands.rs | 24 ++++++++++++++++++++++-- helix-view/src/document.rs | 12 ++++++++---- 5 files changed, 39 insertions(+), 8 deletions(-) (limited to 'helix-term/src/application.rs') diff --git a/book/src/usage.md b/book/src/usage.md index d31e03a1..71730fa8 100644 --- a/book/src/usage.md +++ b/book/src/usage.md @@ -2,7 +2,7 @@ (Currently not fully documented, see the [keymappings](./keymap.md) list for more.) -See [tutor.txt](https://github.com/helix-editor/helix/blob/master/runtime/tutor.txt) for a vimtutor-like introduction. +See [tutor.txt](https://github.com/helix-editor/helix/blob/master/runtime/tutor.txt) (accessible via `hx --tutor` or `:tutor`) for a vimtutor-like introduction. ## Registers diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 662573c6..55b12c5a 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -97,7 +97,12 @@ impl Application { let editor_view = Box::new(ui::EditorView::new(std::mem::take(&mut config.keys))); compositor.push(editor_view); - if !args.files.is_empty() { + if args.load_tutor { + let path = helix_core::runtime_dir().join("tutor.txt"); + editor.open(path, Action::VerticalSplit)?; + // Unset path to prevent accidentally saving to the original tutor file. + doc_mut!(editor).set_path(None)?; + } else if !args.files.is_empty() { let first = &args.files[0]; // we know it's not empty if first.is_dir() { std::env::set_current_dir(&first)?; diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index f0ef09eb..40113db9 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -5,6 +5,7 @@ use std::path::PathBuf; pub struct Args { pub display_help: bool, pub display_version: bool, + pub load_tutor: bool, pub verbosity: u64, pub files: Vec, } @@ -22,6 +23,7 @@ impl Args { "--" => break, // stop parsing at this point treat the remaining as files "--version" => args.display_version = true, "--help" => args.display_help = true, + "--tutor" => args.load_tutor = true, arg if arg.starts_with("--") => { return Err(Error::msg(format!( "unexpected double dash argument: {}", diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index d6e5bfe7..b3be6d5b 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1557,7 +1557,8 @@ mod cmd { let (_, doc) = current!(cx.editor); if let Some(path) = path { - doc.set_path(path.as_ref()).context("invalid filepath")?; + doc.set_path(Some(path.as_ref())) + .context("invalid filepath")?; } if doc.path().is_none() { bail!("cannot write a buffer without a filename"); @@ -2099,6 +2100,18 @@ mod cmd { Ok(()) } + fn tutor( + cx: &mut compositor::Context, + _args: &[&str], + _event: PromptEvent, + ) -> anyhow::Result<()> { + let path = helix_core::runtime_dir().join("tutor.txt"); + cx.editor.open(path, Action::Replace)?; + // Unset path to prevent accidentally saving to the original tutor file. + doc_mut!(cx.editor).set_path(None)?; + Ok(()) + } + pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ TypableCommand { name: "quit", @@ -2351,7 +2364,14 @@ mod cmd { doc: "Open the file in a horizontal split.", fun: hsplit, completer: Some(completers::filename), - } + }, + TypableCommand { + name: "tutor", + aliases: &[], + doc: "Open the tutorial.", + fun: tutor, + completer: None, + }, ]; pub static COMMANDS: Lazy> = Lazy::new(|| { diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index b0257f03..4d779656 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -368,7 +368,7 @@ impl Document { let mut doc = Self::from(rope, Some(encoding)); // set the path and try detecting the language - doc.set_path(path)?; + doc.set_path(Some(path))?; if let Some(loader) = config_loader { doc.detect_language(theme, loader); } @@ -553,12 +553,16 @@ impl Document { self.encoding } - pub fn set_path(&mut self, path: &Path) -> Result<(), std::io::Error> { - let path = helix_core::path::get_canonicalized_path(path)?; + pub fn set_path(&mut self, path: Option<&Path>) -> Result<(), std::io::Error> { + let path = if let Some(p) = path { + Some(helix_core::path::get_canonicalized_path(p)?) + } else { + path.map(|p| p.into()) + }; // if parent doesn't exist we still want to open the document // and error out when document is saved - self.path = Some(path); + self.path = path; Ok(()) } -- cgit v1.2.3-70-g09d2 From 49f6c2623fbda5ff4be86e5e7d773bf900d9c75c Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Fri, 29 Oct 2021 11:00:18 +0800 Subject: Bump lsp-types to 0.91.0 (#932) --- Cargo.lock | 4 ++-- helix-lsp/Cargo.toml | 2 +- helix-lsp/src/client.rs | 7 +++--- helix-term/src/application.rs | 9 ++++---- helix-term/src/ui/completion.rs | 51 +++++++++++++++++++++-------------------- 5 files changed, 38 insertions(+), 35 deletions(-) (limited to 'helix-term/src/application.rs') diff --git a/Cargo.lock b/Cargo.lock index 45a8f5da..8af5c45c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -584,9 +584,9 @@ dependencies = [ [[package]] name = "lsp-types" -version = "0.90.1" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f3734ab1d7d157fc0c45110e06b587c31cd82bea2ccfd6b563cbff0aaeeb1d3" +checksum = "be7801b458592d0998af808d97f6a85a6057af3aaf2a2a5c3c677702bbeb4ed7" dependencies = [ "bitflags", "serde", diff --git a/helix-lsp/Cargo.toml b/helix-lsp/Cargo.toml index f9910cc0..8cbff41d 100644 --- a/helix-lsp/Cargo.toml +++ b/helix-lsp/Cargo.toml @@ -19,7 +19,7 @@ futures-executor = "0.3" futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false } jsonrpc-core = { version = "18.0", default-features = false } # don't pull in all of futures log = "0.4" -lsp-types = { version = "0.90", features = ["proposed"] } +lsp-types = { version = "0.91", features = ["proposed"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 4068ae1f..b810feef 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -461,7 +461,7 @@ impl Client { }; let changes = match sync_capabilities { - lsp::TextDocumentSyncKind::Full => { + lsp::TextDocumentSyncKind::FULL => { vec![lsp::TextDocumentContentChangeEvent { // range = None -> whole document range: None, //Some(Range) @@ -469,10 +469,11 @@ impl Client { text: new_text.to_string(), }] } - lsp::TextDocumentSyncKind::Incremental => { + lsp::TextDocumentSyncKind::INCREMENTAL => { Self::changeset_to_changes(old_text, new_text, changes, self.offset_encoding) } - lsp::TextDocumentSyncKind::None => return None, + lsp::TextDocumentSyncKind::NONE => return None, + kind => unimplemented!("{:?}", kind), }; Some(self.notify::( diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 55b12c5a..6037148f 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -389,10 +389,11 @@ impl Application { message: diagnostic.message, severity: diagnostic.severity.map( |severity| match severity { - DiagnosticSeverity::Error => Error, - DiagnosticSeverity::Warning => Warning, - DiagnosticSeverity::Information => Info, - DiagnosticSeverity::Hint => Hint, + DiagnosticSeverity::ERROR => Error, + DiagnosticSeverity::WARNING => Warning, + DiagnosticSeverity::INFORMATION => Info, + DiagnosticSeverity::HINT => Hint, + severity => unimplemented!("{:?}", severity), }, ), // code diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index a893e70b..dcb2bfd8 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -30,31 +30,32 @@ impl menu::Item for CompletionItem { menu::Row::new(vec![ menu::Cell::from(self.label.as_str()), menu::Cell::from(match self.kind { - Some(lsp::CompletionItemKind::Text) => "text", - Some(lsp::CompletionItemKind::Method) => "method", - Some(lsp::CompletionItemKind::Function) => "function", - Some(lsp::CompletionItemKind::Constructor) => "constructor", - Some(lsp::CompletionItemKind::Field) => "field", - Some(lsp::CompletionItemKind::Variable) => "variable", - Some(lsp::CompletionItemKind::Class) => "class", - Some(lsp::CompletionItemKind::Interface) => "interface", - Some(lsp::CompletionItemKind::Module) => "module", - Some(lsp::CompletionItemKind::Property) => "property", - Some(lsp::CompletionItemKind::Unit) => "unit", - Some(lsp::CompletionItemKind::Value) => "value", - Some(lsp::CompletionItemKind::Enum) => "enum", - Some(lsp::CompletionItemKind::Keyword) => "keyword", - Some(lsp::CompletionItemKind::Snippet) => "snippet", - Some(lsp::CompletionItemKind::Color) => "color", - Some(lsp::CompletionItemKind::File) => "file", - Some(lsp::CompletionItemKind::Reference) => "reference", - Some(lsp::CompletionItemKind::Folder) => "folder", - Some(lsp::CompletionItemKind::EnumMember) => "enum_member", - Some(lsp::CompletionItemKind::Constant) => "constant", - Some(lsp::CompletionItemKind::Struct) => "struct", - Some(lsp::CompletionItemKind::Event) => "event", - Some(lsp::CompletionItemKind::Operator) => "operator", - Some(lsp::CompletionItemKind::TypeParameter) => "type_param", + Some(lsp::CompletionItemKind::TEXT) => "text", + Some(lsp::CompletionItemKind::METHOD) => "method", + Some(lsp::CompletionItemKind::FUNCTION) => "function", + Some(lsp::CompletionItemKind::CONSTRUCTOR) => "constructor", + Some(lsp::CompletionItemKind::FIELD) => "field", + Some(lsp::CompletionItemKind::VARIABLE) => "variable", + Some(lsp::CompletionItemKind::CLASS) => "class", + Some(lsp::CompletionItemKind::INTERFACE) => "interface", + Some(lsp::CompletionItemKind::MODULE) => "module", + Some(lsp::CompletionItemKind::PROPERTY) => "property", + Some(lsp::CompletionItemKind::UNIT) => "unit", + Some(lsp::CompletionItemKind::VALUE) => "value", + Some(lsp::CompletionItemKind::ENUM) => "enum", + Some(lsp::CompletionItemKind::KEYWORD) => "keyword", + Some(lsp::CompletionItemKind::SNIPPET) => "snippet", + Some(lsp::CompletionItemKind::COLOR) => "color", + Some(lsp::CompletionItemKind::FILE) => "file", + Some(lsp::CompletionItemKind::REFERENCE) => "reference", + Some(lsp::CompletionItemKind::FOLDER) => "folder", + Some(lsp::CompletionItemKind::ENUM_MEMBER) => "enum_member", + Some(lsp::CompletionItemKind::CONSTANT) => "constant", + Some(lsp::CompletionItemKind::STRUCT) => "struct", + Some(lsp::CompletionItemKind::EVENT) => "event", + Some(lsp::CompletionItemKind::OPERATOR) => "operator", + Some(lsp::CompletionItemKind::TYPE_PARAMETER) => "type_param", + Some(kind) => unimplemented!("{:?}", kind), None => "", }), // self.detail.as_deref().unwrap_or("") -- cgit v1.2.3-70-g09d2