├── .cargo └── config.toml ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── example.py ├── lapce-python.wasm ├── plugin.toml └── src └── main.rs /.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | target = "wasm32-wasi" 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "adler" 7 | version = "1.0.2" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" 10 | 11 | [[package]] 12 | name = "cfg-if" 13 | version = "1.0.0" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 16 | 17 | [[package]] 18 | name = "crc32fast" 19 | version = "1.3.2" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" 22 | dependencies = [ 23 | "cfg-if", 24 | ] 25 | 26 | [[package]] 27 | name = "flate2" 28 | version = "1.0.23" 29 | source = "registry+https://github.com/rust-lang/crates.io-index" 30 | checksum = "b39522e96686d38f4bc984b9198e3a0613264abaebaff2c5c918bfa6b6da09af" 31 | dependencies = [ 32 | "cfg-if", 33 | "crc32fast", 34 | "libc", 35 | "miniz_oxide", 36 | ] 37 | 38 | [[package]] 39 | name = "itoa" 40 | version = "1.0.2" 41 | source = "registry+https://github.com/rust-lang/crates.io-index" 42 | checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" 43 | 44 | [[package]] 45 | name = "lapce-plugin" 46 | version = "0.1.0" 47 | source = "git+https://github.com/lapce/lapce-plugin-rust?branch=master#48f0b0746c23fcd38a0c0aa37c7c85b15af4b4f0" 48 | dependencies = [ 49 | "serde", 50 | "serde_json", 51 | ] 52 | 53 | [[package]] 54 | name = "lapce-python" 55 | version = "0.2.0" 56 | dependencies = [ 57 | "flate2", 58 | "lapce-plugin", 59 | "serde", 60 | "serde_json", 61 | ] 62 | 63 | [[package]] 64 | name = "libc" 65 | version = "0.2.126" 66 | source = "registry+https://github.com/rust-lang/crates.io-index" 67 | checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" 68 | 69 | [[package]] 70 | name = "miniz_oxide" 71 | version = "0.5.1" 72 | source = "registry+https://github.com/rust-lang/crates.io-index" 73 | checksum = "d2b29bd4bc3f33391105ebee3589c19197c4271e3e5a9ec9bfe8127eeff8f082" 74 | dependencies = [ 75 | "adler", 76 | ] 77 | 78 | [[package]] 79 | name = "proc-macro2" 80 | version = "1.0.39" 81 | source = "registry+https://github.com/rust-lang/crates.io-index" 82 | checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" 83 | dependencies = [ 84 | "unicode-ident", 85 | ] 86 | 87 | [[package]] 88 | name = "quote" 89 | version = "1.0.18" 90 | source = "registry+https://github.com/rust-lang/crates.io-index" 91 | checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" 92 | dependencies = [ 93 | "proc-macro2", 94 | ] 95 | 96 | [[package]] 97 | name = "ryu" 98 | version = "1.0.10" 99 | source = "registry+https://github.com/rust-lang/crates.io-index" 100 | checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" 101 | 102 | [[package]] 103 | name = "serde" 104 | version = "1.0.137" 105 | source = "registry+https://github.com/rust-lang/crates.io-index" 106 | checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" 107 | dependencies = [ 108 | "serde_derive", 109 | ] 110 | 111 | [[package]] 112 | name = "serde_derive" 113 | version = "1.0.137" 114 | source = "registry+https://github.com/rust-lang/crates.io-index" 115 | checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" 116 | dependencies = [ 117 | "proc-macro2", 118 | "quote", 119 | "syn", 120 | ] 121 | 122 | [[package]] 123 | name = "serde_json" 124 | version = "1.0.81" 125 | source = "registry+https://github.com/rust-lang/crates.io-index" 126 | checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" 127 | dependencies = [ 128 | "itoa", 129 | "ryu", 130 | "serde", 131 | ] 132 | 133 | [[package]] 134 | name = "syn" 135 | version = "1.0.95" 136 | source = "registry+https://github.com/rust-lang/crates.io-index" 137 | checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942" 138 | dependencies = [ 139 | "proc-macro2", 140 | "quote", 141 | "unicode-ident", 142 | ] 143 | 144 | [[package]] 145 | name = "unicode-ident" 146 | version = "1.0.0" 147 | source = "registry+https://github.com/rust-lang/crates.io-index" 148 | checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" 149 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "lapce-python" 3 | version = "0.2.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | flate2 = "1.0" 8 | serde_json = "1.0" 9 | serde = { version = "1.0", features = ["derive"] } 10 | lapce-plugin = { git = "https://github.com/lapce/lapce-plugin-rust", branch = "master" } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 superlou 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lapce-python 2 | 3 | The python language server pyls must be available on the path. 4 | Install the python language server by `pip install python-lsp-server`. 5 | 6 | Additional functionality like type checking, refactoring, and formatting can be provided by installing dependencies as described in the [README for python-lsp-server](https://github.com/python-lsp/python-lsp-server). 7 | 8 | ## Build 9 | 10 | ``` 11 | rustup target add wasm32-wasi 12 | cargo build 13 | ``` 14 | 15 | ## Develop 16 | 17 | On OSX, 18 | 19 | ``` 20 | pip install pipx 21 | pipx install python-lsp-server 22 | # adds ~/.local/bin/pylsp 23 | ``` 24 | 25 | ``` 26 | cd ~/Library/Application Support/dev.lapce.Lapce/plugins # or dev.lapce.Lapce-Stable 27 | # exact files to link may vary with lapce releases 28 | mkdir lapce-python; cd lapce-python 29 | ln -s ~/prog/lapce-python/target/wasm32-wasi/debug/lapce-python.wasm . 30 | ``` 31 | 32 | Run lapce from the terminal to see error messages. 33 | 34 | ``` 35 | RUST_BACKTRACE=1 /Applications/Lapce.app/Contents/MacOS/lapce 36 | ``` 37 | -------------------------------------------------------------------------------- /example.py: -------------------------------------------------------------------------------- 1 | # This is a test python file 2 | def main(): 3 | pass 4 | 5 | 6 | if __name__ == '__main__': 7 | main() 8 | -------------------------------------------------------------------------------- /lapce-python.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superlou/lapce-python/819f9b016efb136f127500e928e59ce092af51f5/lapce-python.wasm -------------------------------------------------------------------------------- /plugin.toml: -------------------------------------------------------------------------------- 1 | name = "lapce-python" 2 | display-name = "Python" 3 | description = "Python for Lapce: powered by https://github.com/python-lsp/python-lsp-server" 4 | version = "0.3.1" 5 | author = "various" 6 | repository = "superlou/lapce-python" 7 | wasm = "lapce-python.wasm" 8 | 9 | [configuration] 10 | language_id = "python" 11 | # lsp_exec="/path/to/lsp/executable" # Full path or name on PATH 12 | 13 | [configuration.options] 14 | # Options passed to the LSP server 15 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use lapce_plugin::{register_plugin, start_lsp, LapcePlugin}; 2 | use serde::{Deserialize, Serialize}; 3 | use serde_json::Value; 4 | 5 | #[derive(Default)] 6 | struct State {} 7 | 8 | #[derive(Debug, Clone, Serialize, Deserialize)] 9 | pub struct PluginInfo { 10 | arch: String, 11 | os: String, 12 | configuration: Configuration, 13 | } 14 | 15 | #[derive(Debug, Clone, Serialize, Deserialize)] 16 | pub struct Configuration { 17 | language_id: String, 18 | lsp_exec: Option, 19 | options: Option, 20 | } 21 | 22 | register_plugin!(State); 23 | 24 | impl LapcePlugin for State { 25 | fn initialize(&mut self, info: serde_json::Value) { 26 | let info = serde_json::from_value::(info).unwrap(); 27 | let _arch = match info.arch.as_str() { 28 | "x86_64" => "x86_64", 29 | "aarch64" => "aarch64", 30 | _ => return, 31 | }; 32 | let _os = match info.os.as_str() { 33 | "linux" => "unknown-linux-gnu", 34 | "macos" => "apple-darwin", 35 | "windows" => "pc-windows-msvc", 36 | _ => return, 37 | }; 38 | 39 | let (exec_path, use_system_lsp) = match &info.configuration.lsp_exec { 40 | Some(path) => (path.as_str(), true), 41 | None => ("pylsp", true), 42 | }; 43 | 44 | // two copies of us are started 45 | //serde_json::to_writer_pretty(std::io::stderr(), &info).unwrap(); 46 | start_lsp( 47 | exec_path, 48 | "python", 49 | info.configuration.options, 50 | use_system_lsp, 51 | ); 52 | } 53 | } 54 | --------------------------------------------------------------------------------