mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-08-04 00:49:17 +00:00
Config change handler and valid config waitgroup
This commit is contained in:
parent
7375a9535b
commit
3212848c69
3 changed files with 142 additions and 21 deletions
69
server/Cargo.lock
generated
69
server/Cargo.lock
generated
|
@ -23,11 +23,24 @@ name = "cfg-if"
|
|||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "chan"
|
||||
version = "0.1.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fixedbitset"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "fuchsia-cprng"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "futures"
|
||||
version = "0.1.29"
|
||||
|
@ -76,6 +89,11 @@ name = "lazy_static"
|
|||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.67"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.3.9"
|
||||
|
@ -166,6 +184,48 @@ dependencies = [
|
|||
"proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.3.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "rdrand"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.3.4"
|
||||
|
@ -335,6 +395,7 @@ dependencies = [
|
|||
name = "vscode-mc-shader"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chan 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"petgraph 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -386,13 +447,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
|
||||
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
"checksum chan 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "d14956a3dae065ffaa0d92ece848ab4ced88d32361e7fdfbfd653a5c454a1ed8"
|
||||
"checksum fixedbitset 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d"
|
||||
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
||||
"checksum futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef"
|
||||
"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e"
|
||||
"checksum indexmap 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "076f042c5b7b98f31d205f1249267e12a6518c1481e9dae9764af19b707d2292"
|
||||
"checksum itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e"
|
||||
"checksum languageserver-types 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c511f9ff7488a97fe86ca0f3a020e2515ea0e684fc0048ce9821a9e2f851071a"
|
||||
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
"checksum libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)" = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018"
|
||||
"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
|
||||
"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
|
||||
"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
|
||||
|
@ -405,6 +469,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548"
|
||||
"checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
|
||||
"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
|
||||
"checksum rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)" = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c"
|
||||
"checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
|
||||
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
|
||||
"checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
|
||||
"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
|
||||
"checksum regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "322cf97724bea3ee221b78fe25ac9c46114ebb51747ad5babd51a2fc6a8235a8"
|
||||
"checksum regex-syntax 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)" = "b28dfe3fe9badec5dbf0a79a9cccad2cfc2ab5484bdb3e44cbd1ae8b3ba2be06"
|
||||
"checksum rust_lsp 0.6.0 (git+https://github.com/Strum355/RustLSP)" = "<none>"
|
||||
|
|
|
@ -4,8 +4,6 @@ version = "0.1.0"
|
|||
authors = ["Noah Santschi-Cooney <noah@santschi-cooney.ch>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rust_lsp = { git = "https://github.com/Strum355/RustLSP" }
|
||||
serde_json = "1.0.48"
|
||||
|
@ -13,4 +11,5 @@ serde = "1.0.104"
|
|||
walkdir = "2.3.1"
|
||||
petgraph = "0.5.0"
|
||||
lazy_static = "1.4.0"
|
||||
regex = "1.3.4"
|
||||
regex = "1.3.4"
|
||||
chan = "0.1.23"
|
|
@ -6,17 +6,21 @@ use rust_lsp::jsonrpc::method_types::*;
|
|||
use walkdir;
|
||||
|
||||
use std::ops::Add;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::prelude::*;
|
||||
/* use std::fs::OpenOptions;
|
||||
use std::io::prelude::*; */
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
use std::collections::HashMap;
|
||||
use std::io::{BufReader, BufRead};
|
||||
use std::process;
|
||||
/* use std::path::Path; */
|
||||
use std::collections::HashMap;
|
||||
|
||||
use petgraph::visit::Dfs;
|
||||
use petgraph::dot;
|
||||
/* use petgraph::visit::Dfs;
|
||||
use petgraph::dot; */
|
||||
use petgraph::graph::Graph;
|
||||
|
||||
|
||||
use chan::WaitGroup;
|
||||
|
||||
use regex::Regex;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
|
@ -35,15 +39,17 @@ fn main() {
|
|||
|
||||
let endpoint_output = LSPEndpoint::create_lsp_output_with_output_stream(|| io::stdout());
|
||||
|
||||
let file = OpenOptions::new()
|
||||
/* let file = OpenOptions::new()
|
||||
.write(true)
|
||||
.open("/home/noah/TypeScript/vscode-mc-shader/graph.dot")
|
||||
.unwrap();
|
||||
.unwrap(); */
|
||||
|
||||
let langserver = MinecraftShaderLanguageServer{
|
||||
endpoint: endpoint_output.clone(),
|
||||
graph: Graph::default(),
|
||||
file: file,
|
||||
config: Configuration::default(),
|
||||
wait: WaitGroup::new(),
|
||||
/* file: file, */
|
||||
};
|
||||
|
||||
LSPEndpoint::run_server_from_input(&mut stdin.lock(), endpoint_output, langserver);
|
||||
|
@ -52,7 +58,25 @@ fn main() {
|
|||
struct MinecraftShaderLanguageServer {
|
||||
endpoint: Endpoint,
|
||||
graph: Graph<String, String>,
|
||||
file: std::fs::File,
|
||||
config: Configuration,
|
||||
wait: WaitGroup,
|
||||
/* file: std::fs::File, */
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Configuration {
|
||||
glslang_validator_path: String,
|
||||
shaderpacks_path: String,
|
||||
}
|
||||
|
||||
impl Configuration {
|
||||
fn validate(&self) -> bool {
|
||||
if self.glslang_validator_path == "" || self.shaderpacks_path == "" {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
struct GLSLFile {
|
||||
|
@ -101,9 +125,7 @@ impl MinecraftShaderLanguageServer {
|
|||
|
||||
//eprintln!("adding {} with\n{:?}", stripped_path.clone(), includes);
|
||||
|
||||
files.insert(stripped_path, GLSLFile{
|
||||
idx: idx, includes: includes,
|
||||
});
|
||||
files.insert(stripped_path, GLSLFile{idx, includes});
|
||||
}
|
||||
|
||||
// Add edges between nodes, finding target nodes on weight (value)
|
||||
|
@ -149,10 +171,16 @@ impl MinecraftShaderLanguageServer {
|
|||
|
||||
return includes;
|
||||
}
|
||||
|
||||
pub fn lint(&self) {
|
||||
process::Command::new("program: S");
|
||||
}
|
||||
}
|
||||
|
||||
impl LanguageServerHandling for MinecraftShaderLanguageServer {
|
||||
fn initialize(&mut self, params: InitializeParams, completable: MethodCompletable<InitializeResult, InitializeError>) {
|
||||
self.wait.add(1);
|
||||
|
||||
let mut capabilities = ServerCapabilities::default();
|
||||
capabilities.hover_provider = Some(true);
|
||||
capabilities.text_document_sync = Some(TextDocumentSyncCapability::Options(TextDocumentSyncOptions{
|
||||
|
@ -165,26 +193,50 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer {
|
|||
})
|
||||
}));
|
||||
|
||||
completable.complete(Ok(InitializeResult { capabilities: capabilities }));
|
||||
completable.complete(Ok(InitializeResult{capabilities}));
|
||||
|
||||
self.gen_initial_graph(params.root_path.unwrap());
|
||||
self.lint();
|
||||
}
|
||||
|
||||
fn shutdown(&mut self, _: (), completable: LSCompletable<()>) {
|
||||
completable.complete(Ok(()));
|
||||
}
|
||||
|
||||
fn exit(&mut self, _: ()) {
|
||||
self.endpoint.request_shutdown();
|
||||
}
|
||||
|
||||
fn workspace_change_configuration(&mut self, _: DidChangeConfigurationParams) {}
|
||||
fn did_open_text_document(&mut self, _: DidOpenTextDocumentParams) {}
|
||||
fn did_change_text_document(&mut self, params: DidChangeTextDocumentParams) {
|
||||
eprintln!("changed {} changes: {}", params.content_changes.get(0).unwrap(), params.text_document.uri);
|
||||
fn workspace_change_configuration(&mut self, params: DidChangeConfigurationParams) {
|
||||
let config = params.settings.as_object().unwrap().get("mcglsl").unwrap();
|
||||
|
||||
self.config.glslang_validator_path = String::from(config.get("glslangValidatorPath").unwrap().as_str().unwrap());
|
||||
self.config.shaderpacks_path = String::from(config.get("shaderpacksPath").unwrap().as_str().unwrap());
|
||||
|
||||
if !self.config.validate() {
|
||||
self.endpoint.send_notification("badConfig", None::<()>).unwrap();
|
||||
}
|
||||
|
||||
eprintln!("{:?}", params.settings.as_object().unwrap());
|
||||
|
||||
self.wait.done();
|
||||
}
|
||||
|
||||
fn did_open_text_document(&mut self, _: DidOpenTextDocumentParams) {}
|
||||
|
||||
fn did_change_text_document(&mut self, params: DidChangeTextDocumentParams) {
|
||||
self.wait.wait();
|
||||
let text_change = params.content_changes.get(0).unwrap();
|
||||
//eprintln!("changed {} changes: {}", text_change., params.text_document.uri);
|
||||
}
|
||||
|
||||
fn did_close_text_document(&mut self, _: DidCloseTextDocumentParams) {}
|
||||
|
||||
fn did_save_text_document(&mut self, params: DidSaveTextDocumentParams) {
|
||||
self.wait.wait();
|
||||
eprintln!("saved {}", params.text_document.uri);
|
||||
}
|
||||
|
||||
fn did_change_watched_files(&mut self, _: DidChangeWatchedFilesParams) {}
|
||||
|
||||
fn completion(&mut self, _: TextDocumentPositionParams, completable: LSCompletable<CompletionList>) {
|
||||
|
@ -194,6 +246,7 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer {
|
|||
completable.complete(Err(Self::error_not_available(())));
|
||||
}
|
||||
fn hover(&mut self, _: TextDocumentPositionParams, completable: LSCompletable<Hover>) {
|
||||
self.wait.wait();
|
||||
self.endpoint.send_notification("sampleText", vec![1,2,3]).unwrap();
|
||||
completable.complete(Ok(Hover{
|
||||
contents: HoverContents::Markup(MarkupContent{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue