on master help sign in
Defaults in completions, better schema
b426319Dmitry Sharshakov
helix-core/src/syntax.rs+35−1
@@ -5,7 +5,6 @@ use crate::{
5 Rope, RopeSlice, Tendril,
5 Rope, RopeSlice, Tendril,
6};
6};
7
7
8−use helix_dap::DebugAdapterConfig;
9pub use helix_syntax::get_language;
8pub use helix_syntax::get_language;
10
9
11use arc_swap::ArcSwap;
10use arc_swap::ArcSwap;
@@ -69,6 +68,41 @@ pub struct LanguageServerConfiguration {
69 pub args: Vec<String>,
68 pub args: Vec<String>,
70}
69}
71
70
71+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
72+#[serde(rename_all = "kebab-case")]
73+pub struct AdvancedCompletion {
74+ pub name: Option<String>,
75+ pub completion: Option<String>,
76+ pub default: Option<String>,
77+}
78+
79+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
80+#[serde(rename_all = "kebab-case", untagged)]
81+pub enum DebugConfigCompletion {
82+ Named(String),
83+ Advanced(AdvancedCompletion),
84+}
85+
86+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
87+#[serde(rename_all = "kebab-case")]
88+pub struct DebugTemplate {
89+ pub name: String,
90+ pub request: String,
91+ pub completion: Vec<DebugConfigCompletion>,
92+ pub args: HashMap<String, String>,
93+}
94+
95+#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
96+#[serde(rename_all = "kebab-case")]
97+pub struct DebugAdapterConfig {
98+ pub name: String,
99+ pub transport: String,
100+ pub command: String,
101+ pub args: Vec<String>,
102+ pub port_arg: Option<String>,
103+ pub templates: Vec<DebugTemplate>,
104+}
105+
72#[derive(Debug, Serialize, Deserialize)]
106#[derive(Debug, Serialize, Deserialize)]
73#[serde(rename_all = "kebab-case")]
107#[serde(rename_all = "kebab-case")]
74pub struct IndentationConfiguration {
108pub struct IndentationConfiguration {
helix-dap/src/client.rs+11−15
@@ -38,28 +38,24 @@ pub struct Client {
38impl Client {
38impl Client {
39 // Spawn a process and communicate with it by either TCP or stdio
39 // Spawn a process and communicate with it by either TCP or stdio
40 pub async fn process(
40 pub async fn process(
41− cfg: DebugAdapterConfig,
41+ transport: String,
42+ command: String,
43+ args: Vec<String>,
44+ port_arg: Option<String>,
42 id: usize,
45 id: usize,
43 ) -> Result<(Self, UnboundedReceiver<Payload>)> {
46 ) -> Result<(Self, UnboundedReceiver<Payload>)> {
44− if cfg.transport == "tcp" && cfg.port_arg.is_some() {
47+ if transport == "tcp" && port_arg.is_some() {
45 Self::tcp_process(
48 Self::tcp_process(
46− &cfg.command,
49+ &command,
47− cfg.args.iter().map(|s| s.as_str()).collect(),
50+ args.iter().map(|s| s.as_str()).collect(),
48− &cfg.port_arg.unwrap(),
51+ &port_arg.unwrap(),
49 id,
52 id,
50 )
53 )
51 .await
54 .await
52− } else if cfg.transport == "stdio" {
55+ } else if transport == "stdio" {
53− Self::stdio(
54− &cfg.command,
55− cfg.args.iter().map(|s| s.as_str()).collect(),
56+ Self::stdio(&command, args.iter().map(|s| s.as_str()).collect(), id)
56− id,
57− )
58 } else {
57 } else {
59− Result::Err(Error::Other(anyhow!(
58+ Result::Err(Error::Other(anyhow!("Incorrect transport {}", transport)))
60− "Incorrect transport {}",
61− cfg.transport
62− )))
63 }
59 }
64 }
60 }
65
61
helix-dap/src/types.rs+1−21
@@ -1,26 +1,6 @@
1use serde::{Deserialize, Serialize};
1use serde::{Deserialize, Serialize};
2use serde_json::Value;
2use serde_json::Value;
3−use std::{collections::HashMap, path::PathBuf};
3+use std::path::PathBuf;
4−
5−#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
6−#[serde(rename_all = "kebab-case")]
7−pub struct DebugTemplate {
8− pub name: String,
9− pub request: String,
10− pub completion: Vec<String>,
11− pub args: HashMap<String, String>,
12−}
13−
14−#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
15−#[serde(rename_all = "kebab-case")]
16−pub struct DebugAdapterConfig {
17− pub name: String,
18− pub transport: String,
19− pub command: String,
20− pub args: Vec<String>,
21− pub port_arg: Option<String>,
22− pub templates: Vec<DebugTemplate>,
23−}
24
4
25pub trait Request {
5pub trait Request {
26 type Arguments: serde::de::DeserializeOwned + serde::Serialize;
6 type Arguments: serde::de::DeserializeOwned + serde::Serialize;
helix-term/src/commands.rs+7−1
@@ -4528,7 +4528,13 @@ pub fn dap_start_impl(
4528
4528
4529 let result = match socket {
4529 let result = match socket {
4530 Some(socket) => block_on(Client::tcp(socket, 0)),
4530 Some(socket) => block_on(Client::tcp(socket, 0)),
4531− None => block_on(Client::process(config.clone(), 0)),
4531+ None => block_on(Client::process(
4532+ config.transport.clone(),
4533+ config.command.clone(),
4534+ config.args.clone(),
4535+ config.port_arg.clone(),
4536+ 0,
4537+ )),
4532 };
4538 };
4533
4539
4534 let (mut debugger, events) = match result {
4540 let (mut debugger, events) = match result {
helix-term/src/ui/editor.rs+30−16
@@ -11,7 +11,7 @@ use helix_core::{
11 coords_at_pos,
11 coords_at_pos,
12 graphemes::{ensure_grapheme_boundary_next, next_grapheme_boundary, prev_grapheme_boundary},
12 graphemes::{ensure_grapheme_boundary_next, next_grapheme_boundary, prev_grapheme_boundary},
13 movement::Direction,
13 movement::Direction,
14− syntax::{self, HighlightEvent},
14+ syntax::{self, DebugConfigCompletion, HighlightEvent},
15 unicode::segmentation::UnicodeSegmentation,
15 unicode::segmentation::UnicodeSegmentation,
16 unicode::width::UnicodeWidthStr,
16 unicode::width::UnicodeWidthStr,
17 LineEnding, Position, Range, Selection,
17 LineEnding, Position, Range, Selection,
@@ -710,28 +710,38 @@ impl EditorView {
710 }
710 }
711
711
712 fn debug_parameter_prompt(
712 fn debug_parameter_prompt(
713− completions: Vec<String>,
713+ completions: Vec<DebugConfigCompletion>,
714 config_name: String,
714 config_name: String,
715 mut params: Vec<String>,
715 mut params: Vec<String>,
716 ) -> Prompt {
716 ) -> Prompt {
717 let i = params.len();
717 let i = params.len();
718− let field_type = completions.get(i).map(|x| x.as_str());
718+ let completion = completions.get(i).unwrap();
719+ let field_type = if let DebugConfigCompletion::Advanced(cfg) = completion {
720+ cfg.completion.clone().unwrap_or_else(|| "".to_owned())
721+ } else {
722+ "".to_owned()
723+ };
724+ let name = match completion {
725+ DebugConfigCompletion::Advanced(cfg) => {
726+ cfg.name.clone().unwrap_or_else(|| field_type.to_owned())
727+ }
728+ DebugConfigCompletion::Named(name) => name.clone(),
729+ };
730+ let default_val = match completion {
731+ DebugConfigCompletion::Advanced(cfg) => {
732+ cfg.default.clone().unwrap_or_else(|| "".to_owned())
733+ }
734+ _ => "".to_owned(),
735+ };
719
736
720 let noop = |_input: &str| Vec::new();
737 let noop = |_input: &str| Vec::new();
721− let completer = match field_type {
738+ let completer = match &field_type[..] {
722− Some(field_type) => {
723− if field_type.starts_with("filename") {
724− super::completers::filename
739+ "filename" => super::completers::filename,
725− } else if field_type.starts_with("directory") {
726− super::completers::directory
740+ "directory" => super::completers::directory,
727− } else {
728− noop
729− }
730− }
731− None => noop,
741+ _ => noop,
732 };
742 };
733 Prompt::new(
743 Prompt::new(
734− format!("{}: ", field_type.unwrap_or("arg")),
744+ format!("{}: ", name),
735 None,
745 None,
736 completer,
746 completer,
737 move |cx: &mut crate::compositor::Context, input: &str, event: PromptEvent| {
747 move |cx: &mut crate::compositor::Context, input: &str, event: PromptEvent| {
@@ -739,7 +749,11 @@ impl EditorView {
739 return;
749 return;
740 }
750 }
741
751
742− params.push(input.to_owned());
752+ let mut value = input.to_owned();
753+ if value.is_empty() {
754+ value = default_val.clone();
755+ }
756+ params.push(value);
743
757
744 if params.len() < completions.len() {
758 if params.len() < completions.len() {
745 let completions = completions.clone();
759 let completions = completions.clone();
helix-view/src/editor.rs+2−2
@@ -22,7 +22,7 @@ use anyhow::Error;
22
22
23pub use helix_core::diagnostic::Severity;
23pub use helix_core::diagnostic::Severity;
24pub use helix_core::register::Registers;
24pub use helix_core::register::Registers;
25−use helix_core::syntax;
25+use helix_core::syntax::{self, DebugConfigCompletion};
26use helix_core::Position;
26use helix_core::Position;
27
27
28use serde::Deserialize;
28use serde::Deserialize;
@@ -77,7 +77,7 @@ pub struct Editor {
77 pub debugger: Option<helix_dap::Client>,
77 pub debugger: Option<helix_dap::Client>,
78 pub debugger_events: SelectAll<UnboundedReceiverStream<helix_dap::Payload>>,
78 pub debugger_events: SelectAll<UnboundedReceiverStream<helix_dap::Payload>>,
79 pub debug_config_picker: Option<Vec<String>>,
79 pub debug_config_picker: Option<Vec<String>>,
80− pub debug_config_completions: Option<Vec<Vec<String>>>,
80+ pub debug_config_completions: Option<Vec<Vec<DebugConfigCompletion>>>,
81 pub variables: Option<Vec<String>>,
81 pub variables: Option<Vec<String>>,
82 pub variables_page: usize,
82 pub variables_page: usize,
83
83
languages.toml+2−2
@@ -173,8 +173,8 @@ args = { mode = "exec", program = "{0}" }
173[[language.debugger.templates]]
173[[language.debugger.templates]]
174name = "test"
174name = "test"
175request = "launch"
175request = "launch"
176−completion = [ "directory: tests", "directory: cache output" ]
176+completion = [ { name = "tests", completion = "directory", default = "." } ]
177−args = { mode = "test", program = "{0}", output = "{1}" }
177+args = { mode = "test", program = "{0}" }
178
178
179[[language.debugger.templates]]
179[[language.debugger.templates]]
180name = "attach"
180name = "attach"