commit 08fd1f27b90e71084ba98c4c409ae0f1bef9b606 Author: Josh Date: Wed Dec 4 23:04:43 2024 -0600 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..389159a --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# Created by https://www.toptal.com/developers/gitignore/api/rust +# Edit at https://www.toptal.com/developers/gitignore?templates=rust + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +# End of https://www.toptal.com/developers/gitignore/api/rust diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..74a9997 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[workspace] +members = ["crates/*"] +resolver = "2" + +[workspace.dependencies] +djls = { path = "crates/djls" } + +anyhow = "1.0.94" +pyo3 = { version = "0.23.3", features = ["auto-initialize", "abi3-py39"] } +serde = { version = "1.0.215", features = ["derive"] } +serde_json = "1.0.133" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e42e490 --- /dev/null +++ b/LICENSE @@ -0,0 +1,10 @@ +MIT License + +Copyright (c) 2024 Josh Thomas + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..6f426b6 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# django-language-server + +A Language Server Protocol implementation for Django projects. + diff --git a/crates/djls/Cargo.toml b/crates/djls/Cargo.toml new file mode 100644 index 0000000..1745da5 --- /dev/null +++ b/crates/djls/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "djls" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = { workspace = true } +pyo3 = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } + +tokio = { version = "1.42.0", features = ["full"] } +tower-lsp = { version = "0.20.0", features = ["proposed"] } diff --git a/crates/djls/src/main.rs b/crates/djls/src/main.rs new file mode 100644 index 0000000..1cfc8d0 --- /dev/null +++ b/crates/djls/src/main.rs @@ -0,0 +1,50 @@ +use anyhow::Result; +use tower_lsp::jsonrpc::Result as LspResult; +use tower_lsp::lsp_types::*; +use tower_lsp::{Client, LanguageServer, LspService, Server}; + +#[derive(Debug)] +struct Backend { + client: Client, +} + +#[tower_lsp::async_trait] +impl LanguageServer for Backend { + async fn initialize(&self, _params: InitializeParams) -> LspResult { + Ok(InitializeResult { + capabilities: ServerCapabilities { + text_document_sync: Some(TextDocumentSyncCapability::Kind( + TextDocumentSyncKind::INCREMENTAL, + )), + ..Default::default() + }, + offset_encoding: None, + server_info: Some(ServerInfo { + name: String::from("Django Language Server"), + version: Some(String::from("0.1.0")), + }), + }) + } + + async fn initialized(&self, _: InitializedParams) { + self.client + .log_message(MessageType::INFO, "server initialized!") + .await; + } + + async fn shutdown(&self) -> LspResult<()> { + Ok(()) + } +} + +#[tokio::main] +async fn main() -> Result<()> { + let stdin = tokio::io::stdin(); + let stdout = tokio::io::stdout(); + + let (service, socket) = LspService::build(|client| Backend { client }).finish(); + + Server::new(stdin, stdout, socket).serve(service).await; + + Ok(()) +}