Add ability to specify binary path/args for gopls
(#9803)
This uses the language server settings added in #9293 to allow users to specify the binary path and arguments with which to start up `gopls`. Example user settings for `gopls`: ```json { "lsp": { "gopls": { "binary": { "path": "/Users/thorstenball/tmp/gopls", "arguments": ["-debug=0.0.0.0:8080"] }, } } } ``` Constraints: * Right now this only allows ABSOLUTE paths. Release Notes: - Added ability to specify `gopls` binary `path` (must be absolute) and `arguments` in user settings. Example: `{"lsp": {"gopls": {"binary": {"path": "/my/abs/path/gopls", "arguments": ["-debug=0.0.0.0:8080"] }}}}`
This commit is contained in:
parent
b0409ddd68
commit
157fb98a8b
1 changed files with 38 additions and 9 deletions
|
@ -5,8 +5,10 @@ use gpui::{AsyncAppContext, Task};
|
||||||
pub use language::*;
|
pub use language::*;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use lsp::LanguageServerBinary;
|
use lsp::LanguageServerBinary;
|
||||||
|
use project::project_settings::{BinarySettings, ProjectSettings};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
use settings::Settings;
|
||||||
use smol::{fs, process};
|
use smol::{fs, process};
|
||||||
use std::{
|
use std::{
|
||||||
any::Any,
|
any::Any,
|
||||||
|
@ -28,6 +30,10 @@ fn server_binary_arguments() -> Vec<OsString> {
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct GoLspAdapter;
|
pub struct GoLspAdapter;
|
||||||
|
|
||||||
|
impl GoLspAdapter {
|
||||||
|
const SERVER_NAME: &'static str = "gopls";
|
||||||
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref GOPLS_VERSION_REGEX: Regex = Regex::new(r"\d+\.\d+\.\d+").unwrap();
|
static ref GOPLS_VERSION_REGEX: Regex = Regex::new(r"\d+\.\d+\.\d+").unwrap();
|
||||||
}
|
}
|
||||||
|
@ -35,7 +41,7 @@ lazy_static! {
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
impl super::LspAdapter for GoLspAdapter {
|
impl super::LspAdapter for GoLspAdapter {
|
||||||
fn name(&self) -> LanguageServerName {
|
fn name(&self) -> LanguageServerName {
|
||||||
LanguageServerName("gopls".into())
|
LanguageServerName(Self::SERVER_NAME.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch_latest_server_version(
|
async fn fetch_latest_server_version(
|
||||||
|
@ -57,15 +63,38 @@ impl super::LspAdapter for GoLspAdapter {
|
||||||
async fn check_if_user_installed(
|
async fn check_if_user_installed(
|
||||||
&self,
|
&self,
|
||||||
delegate: &dyn LspAdapterDelegate,
|
delegate: &dyn LspAdapterDelegate,
|
||||||
_: &AsyncAppContext,
|
cx: &AsyncAppContext,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
let env = delegate.shell_env().await;
|
let configured_binary = cx.update(|cx| {
|
||||||
let path = delegate.which("gopls".as_ref()).await?;
|
ProjectSettings::get_global(cx)
|
||||||
Some(LanguageServerBinary {
|
.lsp
|
||||||
path,
|
.get(Self::SERVER_NAME)
|
||||||
arguments: server_binary_arguments(),
|
.and_then(|s| s.binary.clone())
|
||||||
env: Some(env),
|
});
|
||||||
})
|
|
||||||
|
if let Ok(Some(BinarySettings {
|
||||||
|
path: Some(path),
|
||||||
|
arguments,
|
||||||
|
})) = configured_binary
|
||||||
|
{
|
||||||
|
Some(LanguageServerBinary {
|
||||||
|
path: path.into(),
|
||||||
|
arguments: arguments
|
||||||
|
.unwrap_or_default()
|
||||||
|
.iter()
|
||||||
|
.map(|arg| arg.into())
|
||||||
|
.collect(),
|
||||||
|
env: None,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
let env = delegate.shell_env().await;
|
||||||
|
let path = delegate.which("gopls".as_ref()).await?;
|
||||||
|
Some(LanguageServerBinary {
|
||||||
|
path,
|
||||||
|
arguments: server_binary_arguments(),
|
||||||
|
env: Some(env),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn will_fetch_server(
|
fn will_fetch_server(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue