├── Cargo.toml ├── extension.toml ├── .gitignore ├── README.md └── src └── basedpyright.rs /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "basedpyright-zed" 3 | version = "0.1.2" 4 | edition = "2021" 5 | 6 | [lib] 7 | path = "src/basedpyright.rs" 8 | crate-type = ["cdylib"] 9 | 10 | [dependencies] 11 | zed_extension_api = "^0.2.0" 12 | -------------------------------------------------------------------------------- /extension.toml: -------------------------------------------------------------------------------- 1 | id = "basedpyright" 2 | name = "BasedPyright" 3 | description = "Python type checking and language server support from BasedPyright." 4 | version = "0.1.3" 5 | schema_version = 1 6 | authors = ["Jose Miguel "] 7 | repository = "https://github.com/pub-struct/basedpyright-zed" 8 | 9 | [language_servers.basedpyright] 10 | name = "BasedPyright" 11 | languages = ["Python"] 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | debug/ 4 | target/ 5 | 6 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 7 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 8 | Cargo.lock 9 | grammars/ 10 | # These are backup files generated by rustfmt 11 | **/*.rs.bk 12 | 13 | # MSVC Windows builds of rustc generate these, which store debugging information 14 | *.pdb 15 | 16 | # RustRover 17 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 18 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 19 | # and can be added to the global gitignore or merged into this file. For a more nuclear 20 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 21 | #.idea/ 22 | 23 | # Don't upload the built extension from development 24 | extension.wasm 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Basedpyright Extension for Zed 2 | ## in case that basedpyright are now built-in, i think we all no longer need this version :p 3 | ## Pre-requisites 4 | 5 | * Python 3.9+ 6 | * `basedpyright` installed into your python environment 7 | 8 | ## Installation 9 | 10 | Search `basedpyright` in the zed extensions. Click to install. 11 | 12 | ## Enable 13 | 14 | Disable `pyright` and enable `basedpyright` in your settings. 15 | 16 | ```jsonc 17 | { 18 | "languages": { 19 | "Python": { 20 | "language_servers": ["basedpyright", "!pyright"] 21 | }, 22 | } 23 | ``` 24 | 25 | ## Configure 26 | 27 | Configure under `lsp.basedpyright.settings` as required. 28 | 29 | The "binary" setting is optional, if not set, `basedpyright` will be searched for in your `PATH`. 30 | 31 | ```jsonc 32 | { 33 | "lsp": { 34 | "basedpyright": { 35 | "binary": { 36 | "path": ".venv/bin/basedpyright-langserver", 37 | "arguments": ["--stdio"] 38 | }, 39 | "settings": { 40 | "python": { 41 | "pythonPath": ".venv/bin/python" 42 | }, 43 | "basedpyright.analysis": { 44 | "diagnosticMode": "workspace", 45 | "inlayHints": { 46 | "callArgumentNames": false 47 | } 48 | } 49 | } 50 | } 51 | } 52 | } 53 | ``` 54 | -------------------------------------------------------------------------------- /src/basedpyright.rs: -------------------------------------------------------------------------------- 1 | use zed_extension_api::{self as zed, settings::LspSettings}; 2 | 3 | struct BasedPyright; 4 | 5 | impl zed::Extension for BasedPyright { 6 | fn new() -> Self { 7 | Self {} 8 | } 9 | fn language_server_command( 10 | &mut self, 11 | _language_server_id: &zed_extension_api::LanguageServerId, 12 | worktree: &zed_extension_api::Worktree, 13 | ) -> zed_extension_api::Result { 14 | let env = worktree.shell_env(); 15 | 16 | if let Ok(lsp_settings) = LspSettings::for_worktree("basedpyright", worktree) { 17 | if let Some(binary) = lsp_settings.binary { 18 | if let Some(path) = binary.path { 19 | let args = binary.arguments.unwrap_or(vec!["--stdio".to_string()]); 20 | return Ok(zed::Command { 21 | command: path, 22 | args, 23 | env, 24 | }); 25 | } 26 | } 27 | } 28 | 29 | let path = worktree 30 | .which("basedpyright-langserver") 31 | .ok_or_else(|| "basedpyright must be installed and available in $PATH.".to_string())?; 32 | Ok(zed::Command { 33 | command: path, 34 | args: vec!["--stdio".to_string(), Default::default()], 35 | env: env, 36 | }) 37 | } 38 | // ref https://github.com/zed-industries/zed/blob/main/extensions/ruff/src/ruff.rs 39 | fn language_server_initialization_options( 40 | &mut self, 41 | language_server_id: &zed_extension_api::LanguageServerId, 42 | worktree: &zed_extension_api::Worktree, 43 | ) -> zed_extension_api::Result> { 44 | let settings = LspSettings::for_worktree(language_server_id.as_ref(), worktree) 45 | .ok() 46 | .and_then(|lsp_settings| lsp_settings.initialization_options.clone()) 47 | .unwrap_or_default(); 48 | Ok(Some(settings)) 49 | } 50 | fn language_server_workspace_configuration( 51 | &mut self, 52 | language_server_id: &zed_extension_api::LanguageServerId, 53 | worktree: &zed_extension_api::Worktree, 54 | ) -> zed_extension_api::Result> { 55 | let settings = LspSettings::for_worktree(language_server_id.as_ref(), worktree) 56 | .ok() 57 | .and_then(|lsp_settings| lsp_settings.settings.clone()) 58 | .unwrap_or_default(); 59 | Ok(Some(settings)) 60 | } 61 | } 62 | 63 | zed::register_extension!(BasedPyright); 64 | --------------------------------------------------------------------------------