Improved client-server integration

This commit is contained in:
Noah Santschi-Cooney 2020-07-17 15:31:27 +01:00
parent 17c4f8aa93
commit 39143aefc7
No known key found for this signature in database
GPG key ID: 3B22282472C8AE48
18 changed files with 1794 additions and 1105 deletions

96
server/Cargo.lock generated
View file

@ -2,7 +2,7 @@
# It is not intended for manual editing.
[[package]]
name = "aho-corasick"
version = "0.7.10"
version = "0.7.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -15,7 +15,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "base64"
version = "0.12.2"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -86,7 +86,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.71"
version = "0.2.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -107,13 +107,13 @@ dependencies = [
[[package]]
name = "lsp-types"
version = "0.74.2"
source = "git+https://github.com/gluon-lang/lsp-types#9389656d5310bd9604cc1dafcd3369f9e1b3b73f"
version = "0.77.0"
source = "git+https://github.com/gluon-lang/lsp-types?branch=master#b0f0274b192f69fdd2ac1932a0c0b46ef1d588a1"
dependencies = [
"base64 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.113 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_repr 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -147,7 +147,7 @@ name = "proc-macro2"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -163,7 +163,7 @@ name = "rand"
version = "0.3.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.72 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -173,10 +173,10 @@ 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.71 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.72 (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)",
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -205,7 +205,7 @@ name = "regex"
version = "1.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
"aho-corasick 0.7.13 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -221,20 +221,20 @@ name = "remove_dir_all"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rust_lsp"
version = "0.6.0"
source = "git+https://github.com/Strum355/RustLSP#41fadb86f4b8fd2f08f6e60cd453f52a0acc534f"
source = "git+https://github.com/Strum355/RustLSP?branch=master#41fadb86f4b8fd2f08f6e60cd453f52a0acc534f"
dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"lsp-types 0.74.2 (git+https://github.com/gluon-lang/lsp-types)",
"lsp-types 0.77.0 (git+https://github.com/gluon-lang/lsp-types?branch=master)",
"rustdt-json_rpc 0.3.0 (git+https://github.com/strager/rustdt-json_rpc?branch=serde-1.0)",
"rustdt_util 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.113 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -245,8 +245,8 @@ dependencies = [
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"rustdt_util 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.113 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -269,30 +269,30 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.113"
version = "1.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde_derive 1.0.113 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_derive"
version = "1.0.113"
version = "1.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_json"
version = "1.0.55"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"ryu 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.113 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -302,17 +302,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
version = "1.0.31"
version = "1.0.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -355,7 +355,7 @@ dependencies = [
[[package]]
name = "unicode-xid"
version = "0.2.0"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -366,7 +366,7 @@ dependencies = [
"idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.113 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -379,9 +379,9 @@ dependencies = [
"percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"petgraph 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"rust_lsp 0.6.0 (git+https://github.com/Strum355/RustLSP)",
"serde 1.0.113 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)",
"rust_lsp 0.6.0 (git+https://github.com/Strum355/RustLSP?branch=master)",
"serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)",
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -393,13 +393,13 @@ version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi"
version = "0.3.8"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -416,7 +416,7 @@ name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -425,9 +425,9 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada"
"checksum aho-corasick 0.7.13 (registry+https://github.com/rust-lang/crates.io-index)" = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86"
"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
"checksum base64 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e223af0dc48c96d4f8342ec01a4974f139df863896b316681efd36742f22cc67"
"checksum base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
"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"
@ -439,10 +439,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum indexmap 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c398b2b113b55809ceb9ee3e753fcbac793f1956663f3c36549c1346015c2afe"
"checksum itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)" = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49"
"checksum libc 0.2.72 (registry+https://github.com/rust-lang/crates.io-index)" = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701"
"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 lsp-types 0.74.2 (git+https://github.com/gluon-lang/lsp-types)" = "<none>"
"checksum lsp-types 0.77.0 (git+https://github.com/gluon-lang/lsp-types?branch=master)" = "<none>"
"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
"checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
"checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
@ -457,25 +457,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum regex 1.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6"
"checksum regex-syntax 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)" = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8"
"checksum remove_dir_all 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
"checksum rust_lsp 0.6.0 (git+https://github.com/Strum355/RustLSP)" = "<none>"
"checksum rust_lsp 0.6.0 (git+https://github.com/Strum355/RustLSP?branch=master)" = "<none>"
"checksum rustdt-json_rpc 0.3.0 (git+https://github.com/strager/rustdt-json_rpc?branch=serde-1.0)" = "<none>"
"checksum rustdt_util 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7cfffa8a89d8758be2dd5605c5fc62bce055af2491ebf3ce953d4d31512c59fd"
"checksum ryu 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
"checksum same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
"checksum serde 1.0.113 (registry+https://github.com/rust-lang/crates.io-index)" = "6135c78461981c79497158ef777264c51d9d0f4f3fc3a4d22b915900e42dac6a"
"checksum serde_derive 1.0.113 (registry+https://github.com/rust-lang/crates.io-index)" = "93c5eaa17d0954cb481cdcfffe9d84fcfa7a1a9f2349271e678677be4c26ae31"
"checksum serde_json 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)" = "ec2c5d7e739bc07a3e73381a39d61fdb5f671c60c1df26a130690665803d8226"
"checksum serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)" = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3"
"checksum serde_derive 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)" = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e"
"checksum serde_json 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)" = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3"
"checksum serde_repr 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2dc6b7951b17b051f3210b063f12cc17320e2fe30ae05b0fe2a3abb068551c76"
"checksum syn 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "b5304cfdf27365b7585c25d4af91b35016ed21ef88f17ced89c7093b43dba8b6"
"checksum syn 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)" = "936cae2873c940d92e697597c5eee105fb570cd5689c695806f672883653349b"
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
"checksum tinyvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "53953d2d3a5ad81d9f844a32f14ebb121f50b650cd59d0ee2a07cf13c617efed"
"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
"checksum unicode-normalization 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977"
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
"checksum unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
"checksum url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb"
"checksum walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d"
"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
"checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

34
server/src/lsp_ext.rs Normal file
View file

@ -0,0 +1,34 @@
use rust_lsp::lsp_types::notification::Notification;
use serde::{Deserialize, Serialize};
pub enum Status {}
impl Notification for Status {
type Params = StatusParams;
const METHOD: &'static str = "mc-glsl/status";
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct StatusParams {
pub status: String,
pub message: Option<String>,
pub icon: Option<String>,
}
pub enum ConfigUpdate {}
impl Notification for ConfigUpdate {
type Params = ConfigUpdateParams;
const METHOD: &'static str = "mc-glsl/updateConfig";
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct ConfigUpdateParams {
pub kv: Vec<KV>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct KV {
key: String,
value: String
}

View file

@ -17,12 +17,10 @@ use std::io::{BufRead, BufReader};
use std::ops::Add;
use std::process;
use std::rc::Rc;
use std::num::NonZeroU64;
use std::str::FromStr;
use chan::WaitGroup;
use percent_encoding;
use percent_encoding::percent_decode_str;
use regex::Regex;
@ -30,6 +28,7 @@ use lazy_static::lazy_static;
mod graph;
mod provider;
mod lsp_ext;
#[cfg(test)]
mod test;
@ -89,7 +88,7 @@ impl Default for Configuration {
fn default() -> Self {
let shaderpacks_path = std::env::var("HOME").unwrap() + "/.minecraft/shaderpacks";
Configuration{
glslang_validator_path: String::from("glslangValidator"),
glslang_validator_path: "glslangValidator".into(),
shaderpacks_path
}
}
@ -135,12 +134,9 @@ impl MinecraftShaderLanguageServer {
}
pub fn gen_initial_graph(&self, root: &str) {
self.endpoint
.send_notification("status", vec!["$(loading~spin)", "Building project..."])
.unwrap();
let mut files = HashMap::new();
eprintln!("root of project is {}", root);
eprint!("root of project is {}", root);
// filter directories and files not ending in any of the 3 extensions
let file_iter = walkdir::WalkDir::new(root)
@ -159,7 +155,7 @@ impl MinecraftShaderLanguageServer {
let ext = match path.extension() {
Some(e) => e,
None => {
eprintln!("filepath {} had no extension", path.to_str().unwrap());
eprint!("filepath {} had no extension", path.to_str().unwrap());
return None;
}
};
@ -176,7 +172,7 @@ impl MinecraftShaderLanguageServer {
let idx = self.graph.borrow_mut().add_node(path.clone());
//eprintln!("adding {} with\n{:?}", path.clone(), includes);
//eprint!("adding {} with\n{:?}", path.clone(), includes);
files.insert(path, GLSLFile { idx, includes });
}
@ -184,13 +180,13 @@ impl MinecraftShaderLanguageServer {
// Add edges between nodes, finding target nodes on weight (value)
for (_, v) in files.into_iter() {
for file in v.includes {
//eprintln!("searching for {}", file);
//eprint!("searching for {}", file);
let idx = self.graph.borrow_mut().find_node(file.filepath.as_str());
if idx.is_none() {
eprintln!("couldn't find {} in graph for {}", file, self.graph.borrow().graph[v.idx]);
eprint!("couldn't find {} in graph for {}", file, self.graph.borrow().graph[v.idx]);
continue;
}
//eprintln!("added edge between\n\t{}\n\t{}", k, file);
//eprint!("added edge between\n\t{}\n\t{}", k, file);
self.graph.borrow_mut().add_edge(
v.idx,
idx.unwrap(),
@ -202,15 +198,8 @@ impl MinecraftShaderLanguageServer {
}
}
eprintln!("finished building project include graph");
eprint!("finished building project include graph");
std::thread::sleep(std::time::Duration::from_secs(1));
self.endpoint
.send_notification("status", vec!["$(check)", "Finished building project!"])
.unwrap();
std::thread::sleep(std::time::Duration::from_secs(3));
self.endpoint
.send_notification("clearStatus", None::<()>)
.unwrap();
}
pub fn find_includes(&self, root: &str, file: &str) -> Vec<IncludePosition> {
@ -230,11 +219,11 @@ impl MinecraftShaderLanguageServer {
.unwrap()
.get(1)
.unwrap();
//eprintln!("{:?}", caps);
//eprint!("{:?}", caps);
let start = u64::try_from(cap.start()).unwrap();
let end = u64::try_from(cap.end()).unwrap();
let mut path: String = String::from(cap.as_str());
let mut path: String = cap.as_str().into();
if !path.starts_with("/") {
path.insert(0, '/');
}
@ -245,7 +234,7 @@ impl MinecraftShaderLanguageServer {
start,
end,
});
//eprintln!("{} includes {}", file, full_include);
//eprint!("{} includes {}", file, full_include);
});
return includes;
@ -253,7 +242,7 @@ impl MinecraftShaderLanguageServer {
pub fn lint(&self, source: impl Into<String>) -> Vec<Diagnostic> {
let source: String = source.into();
eprintln!("validator bin path: {}", self.config.glslang_validator_path);
eprint!("validator bin path: {}", self.config.glslang_validator_path);
let cmd = process::Command::new(&self.config.glslang_validator_path)
.args(&["--stdin", "-S", "frag"])
.stdin(process::Stdio::piped())
@ -266,7 +255,7 @@ impl MinecraftShaderLanguageServer {
let output = child.wait_with_output().expect("expected output");
let stdout = String::from_utf8(output.stdout).unwrap();
eprintln!("glslangValidator output: {}\n", stdout);
eprint!("glslangValidator output: {}\n", stdout);
let mut diagnostics: Vec<Diagnostic> = vec![];
@ -278,7 +267,7 @@ impl MinecraftShaderLanguageServer {
None => return
};
eprintln!("match {:?}", diagnostic_capture);
eprint!("match {:?}", diagnostic_capture);
let msg = diagnostic_capture.get(4).unwrap().as_str().trim();
@ -286,14 +275,14 @@ impl MinecraftShaderLanguageServer {
return
}
let line = NonZeroU64::from_str(
diagnostic_capture
.get(3)
.expect("third capture group was None")
.as_str()
).expect("got non-numeric string value");
let line: u64 = line.into();
let line = line - 1;
let line = match diagnostic_capture
.get(3)
.expect("third capture group was None")
.as_str()
.parse::<u64>() {
Ok(line) => line,
Err(_) => return,
} - 1;
let line_text = source_lines[line as usize];
@ -313,8 +302,8 @@ impl MinecraftShaderLanguageServer {
),
code: None,
severity: Some(severity),
source: Some(String::from(SOURCE)),
message: String::from(msg),
source: Some(SOURCE.into()),
message: msg.into(),
related_information: None,
tags: None,
};
@ -329,7 +318,15 @@ impl MinecraftShaderLanguageServer {
uri: uri.into(),
diagnostics,
version: document_version,
}).unwrap();
}).expect("failed to publish diagnostics");
}
fn set_status(&self, status: impl Into<String>, message: impl Into<String>, icon: impl Into<String>) {
self.endpoint.send_notification(lsp_ext::Status::METHOD, lsp_ext::StatusParams {
status: status.into(),
message: Some(message.into()),
icon: Some(icon.into()),
}).unwrap_or(());
}
}
@ -338,7 +335,7 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer {
self.wait.add(1);
let mut capabilities = ServerCapabilities::default();
capabilities.hover_provider = Some(false);
capabilities.hover_provider = None;
capabilities.document_link_provider = Some(DocumentLinkOptions {
resolve_provider: None,
work_done_progress_options: WorkDoneProgressOptions {
@ -346,7 +343,7 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer {
},
});
capabilities.execute_command_provider = Some(ExecuteCommandOptions {
commands: vec![String::from("graphDot")],
commands: vec!["graphDot".into()],
work_done_progress_options: WorkDoneProgressOptions {
work_done_progress: None,
},
@ -357,23 +354,50 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer {
will_save: None,
will_save_wait_until: None,
change: Some(TextDocumentSyncKind::Full),
save: Some(SaveOptions {
save: Some(TextDocumentSyncSaveOptions::SaveOptions(SaveOptions {
include_text: Some(true),
}),
}))
},
));
self.root = Some(percent_encoding::percent_decode_str(params.root_uri.unwrap().path()).decode_utf8().unwrap().into());
self.gen_initial_graph(self.root.as_ref().unwrap());
let root_path = match params.root_uri {
Some(uri) => String::from(uri.path()),
None => {
completable.complete(Err(MethodError {
code: 42069,
message: "Must be in workspace".into(),
data: InitializeError {
retry: false,
},
}));
return;
}
};
completable.complete(Ok(InitializeResult {
capabilities,
server_info: None,
}));
self.set_status("loading", "Building dependency graph...", "$(loading~spin)");
let root: String = match percent_decode_str(root_path.as_str()).decode_utf8() {
Ok(s) => s.into(),
Err(e) => {
self.set_status("failed", format!("{}", e), "$(close)");
return
},
};
self.root = Some(root);
self.gen_initial_graph(self.root.as_ref().unwrap());
self.set_status("ready", "Project initialized", "$(check)");
}
fn shutdown(&mut self, _: (), completable: LSCompletable<()>) {
eprint!("shutting down language server...");
completable.complete(Ok(()));
}
@ -384,15 +408,13 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer {
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
self.config.glslang_validator_path = config
.get("glslangValidatorPath")
.unwrap()
.as_str()
.unwrap(),
);
self.config.shaderpacks_path =
String::from(config.get("shaderpacksPath").unwrap().as_str().unwrap());
.unwrap()
.into();
self.config.shaderpacks_path = config.get("shaderpacksPath").unwrap().as_str().unwrap().into();
if !self.config.validate() {
self.endpoint
@ -400,13 +422,13 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer {
.unwrap();
}
eprintln!("{:?}", params.settings.as_object().unwrap());
eprint!("{:?}", params.settings.as_object().unwrap());
self.wait.done();
}
fn did_open_text_document(&mut self, params: DidOpenTextDocumentParams) {
eprintln!("opened doc {}", params.text_document.uri);
eprint!("opened doc {}", params.text_document.uri);
let diagnostics = self.lint(params.text_document.text);
self.publish_diagnostic(diagnostics, params.text_document.uri, Some(params.text_document.version));
}
@ -416,7 +438,7 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer {
#[allow(unused_variables)]
let text_change = params.content_changes[0].clone();
//eprintln!("changed {} changes: {}", text_change., params.text_document.uri);
//eprint!("changed {} changes: {}", text_change., params.text_document.uri);
}
fn did_close_text_document(&mut self, _: DidCloseTextDocumentParams) {}
@ -463,15 +485,22 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer {
.execute(params.command.as_ref(), params.arguments)
{
Ok(_) => {
eprintln!("executed {} successfully", params.command);
// TODO: notification popup
eprint!("executed {} successfully", params.command);
self.endpoint.send_notification(ShowMessage::METHOD, ShowMessageParams {
typ: MessageType::Info,
message: format!("Command {} executed successfully.", params.command),
}).expect("failed to send popup/show message notification");
completable.complete(Ok(WorkspaceEdit {
changes: None,
document_changes: None,
}))
},
Err(err) => {
eprintln!("failed to execute {}: {}", params.command, err);
self.endpoint.send_notification(ShowMessage::METHOD, ShowMessageParams {
typ: MessageType::Error,
message: format!("Failed to execute command '{}'", params.command),
}).expect("failed to send popup/show message notification");
eprint!("failed to execute {}: {}", params.command, err);
completable.complete(Err(MethodError::new(32420, err, ())))
},
}
@ -514,7 +543,7 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer {
}
fn document_link(&mut self, params: DocumentLinkParams, completable: LSCompletable<Vec<DocumentLink>>) {
eprintln!("document link file: {:?}", params.text_document.uri.to_file_path().unwrap());
eprint!("document link file: {:?}", params.text_document.uri.to_file_path().unwrap());
// node for current document
let curr_doc = params
.text_document
@ -543,7 +572,7 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer {
let url = match Url::from_file_path(path) {
Ok(url) => url,
Err(e) => {
eprintln!("error converting {:?} into url: {:?}", path, e);
eprint!("error converting {:?} into url: {:?}", path, e);
return None;
}
};
@ -560,7 +589,7 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer {
})
})
.collect();
eprintln!("links: {:?}", edges);
eprint!("links: {:?}", edges);
completable.complete(Ok(edges));
}

View file

@ -18,7 +18,7 @@ impl CustomCommandProvider {
pub fn new(commands: Vec<(&str, Box<dyn Invokeable>)>) -> CustomCommandProvider {
CustomCommandProvider{
commands: commands.into_iter().map(|tup| {
(String::from(tup.0), tup.1)
(tup.0.into(), tup.1)
}).collect(),
}
}
@ -27,7 +27,7 @@ impl CustomCommandProvider {
if self.commands.contains_key(command) {
return self.commands.get(command).unwrap().run_command(args);
}
Err(String::from("command doesn't exist"))
Err("command doesn't exist".into())
}
}
@ -44,7 +44,7 @@ impl<'a> Invokeable for GraphDotCommand {
let rootpath = params.get(0).unwrap().to_string();
let rootpath = String::from(rootpath.trim_start_matches('"').trim_end_matches('"'));
let filepath = rootpath + "/graph.dot";
eprintln!("generating dot file at {}", filepath);
eprint!("generating dot file at {}", filepath);
let mut file = OpenOptions::new()
.write(true)
.create(true)