on master help sign in
feat(lsp): pass client_info on initialization (#4904)
8abed3bMatouš Dzivjak
Cargo.lock+1
@@ -1187,6 +1187,7 @@ dependencies = [
1187 "futures-executor",
1187 "futures-executor",
1188 "futures-util",
1188 "futures-util",
1189 "helix-core",
1189 "helix-core",
1190+ "helix-loader",
1190 "log",
1191 "log",
1191 "lsp-types",
1192 "lsp-types",
1192 "serde",
1193 "serde",
helix-loader/build.rs+20
@@ -1,6 +1,26 @@
1+use std::borrow::Cow;
2+use std::process::Command;
3+
4+const VERSION: &str = include_str!("../VERSION");
5+
1fn main() {
6fn main() {
7+ let git_hash = Command::new("git")
8+ .args(["rev-parse", "HEAD"])
9+ .output()
10+ .ok()
11+ .filter(|output| output.status.success())
12+ .and_then(|x| String::from_utf8(x.stdout).ok());
13+
14+ let version: Cow<_> = match git_hash {
15+ Some(git_hash) => format!("{} ({})", VERSION, &git_hash[..8]).into(),
16+ None => VERSION.into(),
17+ };
18+
2 println!(
19 println!(
3 "cargo:rustc-env=BUILD_TARGET={}",
20 "cargo:rustc-env=BUILD_TARGET={}",
4 std::env::var("TARGET").unwrap()
21 std::env::var("TARGET").unwrap()
5 );
22 );
23+
24+ println!("cargo:rerun-if-changed=../VERSION");
25+ println!("cargo:rustc-env=VERSION_AND_GIT_HASH={}", version);
6}
26}
helix-loader/src/lib.rs+2
@@ -4,6 +4,8 @@ pub mod grammar;
4use etcetera::base_strategy::{choose_base_strategy, BaseStrategy};
4use etcetera::base_strategy::{choose_base_strategy, BaseStrategy};
5use std::path::PathBuf;
5use std::path::PathBuf;
6
6
7+pub const VERSION_AND_GIT_HASH: &str = env!("VERSION_AND_GIT_HASH");
8+
7pub static RUNTIME_DIR: once_cell::sync::Lazy<PathBuf> = once_cell::sync::Lazy::new(runtime_dir);
9pub static RUNTIME_DIR: once_cell::sync::Lazy<PathBuf> = once_cell::sync::Lazy::new(runtime_dir);
8
10
9static CONFIG_FILE: once_cell::sync::OnceCell<PathBuf> = once_cell::sync::OnceCell::new();
11static CONFIG_FILE: once_cell::sync::OnceCell<PathBuf> = once_cell::sync::OnceCell::new();
helix-lsp/Cargo.toml+1
@@ -13,6 +13,7 @@ homepage = "https://helix-editor.com"
13
13
14[dependencies]
14[dependencies]
15helix-core = { version = "0.6", path = "../helix-core" }
15helix-core = { version = "0.6", path = "../helix-core" }
16+helix-loader = { version = "0.6", path = "../helix-loader" }
16
17
17anyhow = "1.0"
18anyhow = "1.0"
18futures-executor = "0.3"
19futures-executor = "0.3"
helix-lsp/src/client.rs+5−1
@@ -5,6 +5,7 @@ use crate::{
5};
5};
6
6
7use helix_core::{find_root, ChangeSet, Rope};
7use helix_core::{find_root, ChangeSet, Rope};
8+use helix_loader::{self, VERSION_AND_GIT_HASH};
8use lsp_types as lsp;
9use lsp_types as lsp;
9use serde::Deserialize;
10use serde::Deserialize;
10use serde_json::Value;
11use serde_json::Value;
@@ -376,7 +377,10 @@ impl Client {
376 ..Default::default()
377 ..Default::default()
377 },
378 },
378 trace: None,
379 trace: None,
379− client_info: None,
380+ client_info: Some(lsp::ClientInfo {
381+ name: String::from("helix"),
382+ version: Some(String::from(VERSION_AND_GIT_HASH)),
383+ }),
380 locale: None, // TODO
384 locale: None, // TODO
381 };
385 };
382
386
helix-term/build.rs−21
@@ -1,30 +1,9 @@
1use helix_loader::grammar::{build_grammars, fetch_grammars};
1use helix_loader::grammar::{build_grammars, fetch_grammars};
2−use std::borrow::Cow;
3−use std::process::Command;
4−
5−const VERSION: &str = include_str!("../VERSION");
6
2
7fn main() {
3fn main() {
8− let git_hash = Command::new("git")
9− .args(["rev-parse", "HEAD"])
10− .output()
11− .ok()
12− .filter(|output| output.status.success())
13− .and_then(|x| String::from_utf8(x.stdout).ok());
14−
15− let version: Cow<_> = match git_hash {
16− Some(git_hash) => format!("{} ({})", VERSION, &git_hash[..8]).into(),
17− None => VERSION.into(),
18− };
19−
20 if std::env::var("HELIX_DISABLE_AUTO_GRAMMAR_BUILD").is_err() {
4 if std::env::var("HELIX_DISABLE_AUTO_GRAMMAR_BUILD").is_err() {
21 fetch_grammars().expect("Failed to fetch tree-sitter grammars");
5 fetch_grammars().expect("Failed to fetch tree-sitter grammars");
22 build_grammars(Some(std::env::var("TARGET").unwrap()))
6 build_grammars(Some(std::env::var("TARGET").unwrap()))
23 .expect("Failed to compile tree-sitter grammars");
7 .expect("Failed to compile tree-sitter grammars");
24 }
8 }
25−
26− println!("cargo:rerun-if-changed=../runtime/grammars/");
27− println!("cargo:rerun-if-changed=../VERSION");
28−
29− println!("cargo:rustc-env=VERSION_AND_GIT_HASH={}", version);
30}
9}
helix-term/src/main.rs+3−2
@@ -1,5 +1,6 @@
1use anyhow::{Context, Error, Result};
1use anyhow::{Context, Error, Result};
2use crossterm::event::EventStream;
2use crossterm::event::EventStream;
3+use helix_loader::VERSION_AND_GIT_HASH;
3use helix_term::application::Application;
4use helix_term::application::Application;
4use helix_term::args::Args;
5use helix_term::args::Args;
5use helix_term::config::Config;
6use helix_term::config::Config;
@@ -74,7 +75,7 @@ FLAGS:
74 --hsplit Splits all given files horizontally into different windows
75 --hsplit Splits all given files horizontally into different windows
75",
76",
76 env!("CARGO_PKG_NAME"),
77 env!("CARGO_PKG_NAME"),
77− env!("VERSION_AND_GIT_HASH"),
78+ VERSION_AND_GIT_HASH,
78 env!("CARGO_PKG_AUTHORS"),
79 env!("CARGO_PKG_AUTHORS"),
79 env!("CARGO_PKG_DESCRIPTION"),
80 env!("CARGO_PKG_DESCRIPTION"),
80 logpath.display(),
81 logpath.display(),
@@ -89,7 +90,7 @@ FLAGS:
89 }
90 }
90
91
91 if args.display_version {
92 if args.display_version {
92− println!("helix {}", env!("VERSION_AND_GIT_HASH"));
93+ println!("helix {}", VERSION_AND_GIT_HASH);
93 std::process::exit(0);
94 std::process::exit(0);
94 }
95 }
95
96