on master help sign in
Defaults in completions, better schema
commitb42631942b74b2f5ac5c955343861518c38282e8 authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateSun 29 Aug 2021, 14:51 (5 years ago) parentf53d841
7 files changed+88−58
helix-core/src/syntax.rs+35−1 helix-dap/src/client.rs+11−15 helix-dap/src/types.rs+1−21 helix-term/src/commands.rs+7−1 helix-term/src/ui/editor.rs+30−16 helix-view/src/editor.rs+2−2 languages.toml+2−2
helix-core/src/syntax.rs+35−1
@@ -5,7 +5,6 @@ use crate::{
55 Rope, RopeSlice, Tendril,
66};
77
8−use helix_dap::DebugAdapterConfig;
98pub use helix_syntax::get_language;
109
1110use arc_swap::ArcSwap;
@@ -69,6 +68,41 @@ pub struct LanguageServerConfiguration {
6968 pub args: Vec<String>,
7069}
7170
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+
72106#[derive(Debug, Serialize, Deserialize)]
73107#[serde(rename_all = "kebab-case")]
74108pub struct IndentationConfiguration {
helix-dap/src/client.rs+11−15
@@ -38,28 +38,24 @@ pub struct Client {
3838impl Client {
3939 // Spawn a process and communicate with it by either TCP or stdio
4040 pub async fn process(
41− cfg: DebugAdapterConfig,
41+ transport: String,
42+ command: String,
43+ args: Vec<String>,
44+ port_arg: Option<String>,
4245 id: usize,
4346 ) -> Result<(Self, UnboundedReceiver<Payload>)> {
44− if cfg.transport == "tcp" && cfg.port_arg.is_some() {
47+ if transport == "tcp" && port_arg.is_some() {
4548 Self::tcp_process(
46− &cfg.command,
47− cfg.args.iter().map(|s| s.as_str()).collect(),
48− &cfg.port_arg.unwrap(),
49+ &command,
50+ args.iter().map(|s| s.as_str()).collect(),
51+ &port_arg.unwrap(),
4952 id,
5053 )
5154 .await
52− } else if cfg.transport == "stdio" {
53− Self::stdio(
54− &cfg.command,
55− cfg.args.iter().map(|s| s.as_str()).collect(),
56− id,
57− )
55+ } else if transport == "stdio" {
56+ Self::stdio(&command, args.iter().map(|s| s.as_str()).collect(), id)
5857 } else {
59− Result::Err(Error::Other(anyhow!(
60− "Incorrect transport {}",
61− cfg.transport
62− )))
58+ Result::Err(Error::Other(anyhow!("Incorrect transport {}", transport)))
6359 }
6460 }
6561
helix-dap/src/types.rs+1−21
@@ -1,26 +1,6 @@
11use serde::{Deserialize, Serialize};
22use serde_json::Value;
3−use std::{collections::HashMap, 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−}
3+use std::path::PathBuf;
244
255pub trait Request {
266 type Arguments: serde::de::DeserializeOwned + serde::Serialize;
helix-term/src/commands.rs+7−1
@@ -4528,7 +4528,13 @@ pub fn dap_start_impl(
45284528
45294529 let result = match socket {
45304530 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+ )),
45324538 };
45334539
45344540 let (mut debugger, events) = match result {
helix-term/src/ui/editor.rs+30−16
@@ -11,7 +11,7 @@ use helix_core::{
1111 coords_at_pos,
1212 graphemes::{ensure_grapheme_boundary_next, next_grapheme_boundary, prev_grapheme_boundary},
1313 movement::Direction,
14− syntax::{self, HighlightEvent},
14+ syntax::{self, DebugConfigCompletion, HighlightEvent},
1515 unicode::segmentation::UnicodeSegmentation,
1616 unicode::width::UnicodeWidthStr,
1717 LineEnding, Position, Range, Selection,
@@ -710,28 +710,38 @@ impl EditorView {
710710 }
711711
712712 fn debug_parameter_prompt(
713− completions: Vec<String>,
713+ completions: Vec<DebugConfigCompletion>,
714714 config_name: String,
715715 mut params: Vec<String>,
716716 ) -> Prompt {
717717 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+ };
719736
720737 let noop = |_input: &str| Vec::new();
721− let completer = match field_type {
722− Some(field_type) => {
723− if field_type.starts_with("filename") {
724− super::completers::filename
725− } else if field_type.starts_with("directory") {
726− super::completers::directory
727− } else {
728− noop
729− }
730− }
731− None => noop,
738+ let completer = match &field_type[..] {
739+ "filename" => super::completers::filename,
740+ "directory" => super::completers::directory,
741+ _ => noop,
732742 };
733743 Prompt::new(
734− format!("{}: ", field_type.unwrap_or("arg")),
744+ format!("{}: ", name),
735745 None,
736746 completer,
737747 move |cx: &mut crate::compositor::Context, input: &str, event: PromptEvent| {
@@ -739,7 +749,11 @@ impl EditorView {
739749 return;
740750 }
741751
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);
743757
744758 if params.len() < completions.len() {
745759 let completions = completions.clone();
helix-view/src/editor.rs+2−2
@@ -22,7 +22,7 @@ use anyhow::Error;
2222
2323pub use helix_core::diagnostic::Severity;
2424pub use helix_core::register::Registers;
25−use helix_core::syntax;
25+use helix_core::syntax::{self, DebugConfigCompletion};
2626use helix_core::Position;
2727
2828use serde::Deserialize;
@@ -77,7 +77,7 @@ pub struct Editor {
7777 pub debugger: Option<helix_dap::Client>,
7878 pub debugger_events: SelectAll<UnboundedReceiverStream<helix_dap::Payload>>,
7979 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>>>,
8181 pub variables: Option<Vec<String>>,
8282 pub variables_page: usize,
8383
languages.toml+2−2
@@ -173,8 +173,8 @@ args = { mode = "exec", program = "{0}" }
173173[[language.debugger.templates]]
174174name = "test"
175175request = "launch"
176−completion = [ "directory: tests", "directory: cache output" ]
177−args = { mode = "test", program = "{0}", output = "{1}" }
176+completion = [ { name = "tests", completion = "directory", default = "." } ]
177+args = { mode = "test", program = "{0}" }
178178
179179[[language.debugger.templates]]
180180name = "attach"