initial commit

This commit is contained in:
Josh Thomas 2024-12-04 23:04:43 -06:00
commit 08fd1f27b9
6 changed files with 108 additions and 0 deletions

20
.gitignore vendored Normal file
View file

@ -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

11
Cargo.toml Normal file
View file

@ -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"

10
LICENSE Normal file
View file

@ -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.

4
README.md Normal file
View file

@ -0,0 +1,4 @@
# django-language-server
A Language Server Protocol implementation for Django projects.

13
crates/djls/Cargo.toml Normal file
View file

@ -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"] }

50
crates/djls/src/main.rs Normal file
View file

@ -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<InitializeResult> {
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(())
}