Make python run local worktree LSPs (#18353)

Release Notes:

- Python: made it possible to use locally installed `pyright` if
available

---------

Co-authored-by: conrad <conrad@zed.dev>
This commit is contained in:
Mikayla Maki 2024-09-25 12:45:41 -07:00 committed by GitHub
parent dc7c49bd0b
commit ae6a3d15af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 73 additions and 1 deletions

View file

@ -20,6 +20,7 @@ use task::{TaskTemplate, TaskTemplates, VariableName};
use util::ResultExt;
const SERVER_PATH: &str = "node_modules/pyright/langserver.index.js";
const NODE_MODULE_RELATIVE_SERVER_PATH: &str = "pyright/langserver.index.js";
fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
vec![server_path.into(), "--stdio".into()]
@ -43,6 +44,26 @@ impl LspAdapter for PythonLspAdapter {
Self::SERVER_NAME.clone()
}
async fn check_if_user_installed(
&self,
delegate: &dyn LspAdapterDelegate,
_: &AsyncAppContext,
) -> Option<LanguageServerBinary> {
let node = delegate.which("node".as_ref()).await?;
let (node_modules_path, _) = delegate
.npm_package_installed_version(Self::SERVER_NAME.as_ref())
.await
.log_err()??;
let path = node_modules_path.join(NODE_MODULE_RELATIVE_SERVER_PATH);
Some(LanguageServerBinary {
path: node,
env: None,
arguments: server_binary_arguments(&path),
})
}
async fn fetch_latest_server_version(
&self,
_: &dyn LspAdapterDelegate,