Skip to content

Commit

Permalink
Env variable to control which server to run
Browse files Browse the repository at this point in the history
To use, either patch Kakoune using
mawww/kakoune#5063 and set preferred servers
for each buffer like

	set-option -add buffer env KAK_LSP_LANGUAGE_SERVER=pylsp_main # or pylsp_test

Alternatively, use (untested)

	unset-option buffer lsp_cmd
	set-option buffer lsp_cmd "KAK_LSP_LANGUAGE_SERVER=pylsp_main %opt{lsp_cmd}"
  • Loading branch information
krobelus committed Feb 10, 2024
1 parent 117db92 commit 31b666b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 12 additions & 2 deletions kak-lsp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,22 @@ roots = ["spago.dhall", "spago.yaml", "package.json", ".git", ".hg"]
command = "purescript-language-server"
args = ["--stdio"]

[language_server.pylsp]
[language_server.pylsp_main]
filetypes = ["python"]
roots = ["requirements.txt", "setup.py", ".git", ".hg"]
command = "pylsp"
settings_section = "_"
[language_server.pylsp.settings._]
[language_server.pylsp_main.settings._]
# See https://github.com/python-lsp/python-lsp-server#configuration
# pylsp.configurationSources = ["flake8"]
pylsp.plugins.jedi_completion.include_params = true

[language_server.pylsp_test]
filetypes = ["python"]
roots = ["requirements.txt", "setup.py", ".git", ".hg"]
command = "pylsp" # TODO different path
settings_section = "_"
[language_server.pylsp_test.settings._]
# See https://github.com/python-lsp/python-lsp-server#configuration
# pylsp.configurationSources = ["flake8"]
pylsp.plugins.jedi_completion.include_params = true
Expand Down
14 changes: 14 additions & 0 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use lsp_types::request::Request;
use lsp_types::*;
use regex::Regex;
use std::collections::HashMap;
use std::env;
use std::path::PathBuf;
use std::time::Duration;

Expand Down Expand Up @@ -107,9 +108,22 @@ pub fn start(
continue 'event_loop;
}


let maybe_server_filter = env::var("KAK_LSP_LANGUAGE_SERVER").ok();

let (language_id, servers) = cfg.unwrap();
let routes: Vec<_> = servers
.iter()
.filter(
|&server_name| {
let Some(allowed) = maybe_server_filter.as_ref() else {return true; };
if server_name != allowed {
debug!("Not starting server {server_name} due to KAK_LSP_LANGUAGE_SERVER={allowed}");
return false;
}
true
}
)
.map(|server_name| {
let language = &languages[server_name];
let root = find_project_root(language_id, &language.roots, &request.meta.buffile);
Expand Down

0 comments on commit 31b666b

Please sign in to comment.