diff --git a/client/src/commands.ts b/client/src/commands.ts index 627eab2..e719a47 100644 --- a/client/src/commands.ts +++ b/client/src/commands.ts @@ -23,11 +23,14 @@ export function restartExtension(e: Extension): Command { } export function virtualMergedDocument(e: Extension): Command { - const getVirtualDocument = async (path: string): Promise => { - const content = await e.lspClient.sendRequest(lsp.ExecuteCommandRequest.type.method, { - command: 'virtualMerge', - arguments: [path] - }) + const getVirtualDocument = async (path: string): Promise => { + let content: string = "" + try { + content = await e.lspClient.sendRequest(lsp.ExecuteCommandRequest.type.method, { + command: 'virtualMerge', + arguments: [path] + }) + } catch(e) {} return content } diff --git a/server/Cargo.toml b/server/Cargo.toml index 76bd96b..0e57589 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -6,22 +6,22 @@ edition = "2018" [dependencies] rust_lsp = { git = "https://github.com/Strum355/RustLSP", branch = "master" } -serde_json = "1.0.56" -serde = "1.0.114" +serde_json = "1.0.61" +serde = "1.0.118" walkdir = "2.3.1" petgraph = "0.5.1" lazy_static = "1.4.0" -regex = "1.3.9" +regex = "1.4.3" chan = "0.1.23" -url = "2.1.1" +url = "2.2.0" percent-encoding = "2.1.0" -anyhow = "1.0.31" +anyhow = "1.0.37" bit-set = "0.5.2" -thiserror = "1.0.20" +thiserror = "1.0.23" glutin = "0.26.0" gl = "0.14.0" [dev-dependencies] tempdir = "0.3.7" -fs_extra = "1.1.0" +fs_extra = "1.2.0" hamcrest2 = "*" diff --git a/server/src/commands.rs b/server/src/commands.rs index 22a74b0..8738785 100644 --- a/server/src/commands.rs +++ b/server/src/commands.rs @@ -28,16 +28,16 @@ impl CustomCommandProvider { } } - pub fn execute(&self, command: &str, args: Vec) -> Result { + pub fn execute(&self, command: &str, args: Vec, root_path: &str) -> Result { if self.commands.contains_key(command) { - return self.commands.get(command).unwrap().run_command(args); + return self.commands.get(command).unwrap().run_command(root_path, args); } Err("command doesn't exist".into()) } } pub trait Invokeable { - fn run_command(&self, arguments: Vec) -> Result; + fn run_command(&self, root: &str, arguments: Vec) -> Result; } pub struct GraphDotCommand { @@ -45,10 +45,8 @@ pub struct GraphDotCommand { } impl Invokeable for GraphDotCommand { - fn run_command(&self, arguments: Vec) -> Result { - let rootpath = arguments.get(0).unwrap().to_string(); - let rootpath = String::from(rootpath.trim_start_matches('"').trim_end_matches('"')); - let filepath = rootpath + "/graph.dot"; + fn run_command(&self, root: &str, _: Vec) -> Result { + let filepath = String::from(root) + "/graph.dot"; eprintln!("generating dot file at {}", filepath); let mut file = OpenOptions::new() .truncate(true) @@ -120,7 +118,7 @@ impl VirtualMergedDocument { } impl Invokeable for VirtualMergedDocument { - fn run_command(&self, arguments: Vec) -> Result { + fn run_command(&self, root: &str, arguments: Vec) -> Result { let path = arguments.get(0).unwrap().to_string(); let path = String::from(path.trim_start_matches('"').trim_end_matches('"')); @@ -155,11 +153,7 @@ impl Invokeable for VirtualMergedDocument { let graph = self.graph.borrow(); let view = merge_views::generate_merge_list(&tree, &all_sources, &graph); return Ok(serde_json::value::Value::String(view)); - } else { - return Err(format!("{} is not a top-level file aka has ancestors", path)) - }; - - - //Ok(Value::Null) + } + return Err(format!("{} is not a top-level file aka has ancestors", path.trim_start_matches(&(String::from(root) + "/")))) } } \ No newline at end of file diff --git a/server/src/main.rs b/server/src/main.rs index e67871a..e8b027f 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -41,7 +41,7 @@ mod opengl; mod test; lazy_static! { - static ref RE_DIAGNOSTIC: Regex = Regex::new(r#"^(ERROR|WARNING): ([^?<>*|"]+?):(\d+): (?:'.*?' : )?(.+)\r?"#).unwrap(); + static ref RE_DIAGNOSTIC: Regex = Regex::new(r#"^(?P[^?<>*|"]+?)\((?P\d+)\) : (?Perror|warning) [A-C]\d+: (?P.+)"#).unwrap(); static ref RE_VERSION: Regex = Regex::new(r#"#version [\d]{3}"#).unwrap(); static ref RE_INCLUDE: Regex = Regex::new(r#"^(?:\s)*?(?:#include) "(.+)"\r?"#).unwrap(); static ref RE_INCLUDE_EXTENSION: Regex = Regex::new(r#"#extension GL_GOOGLE_include_directive ?: ?require"#).unwrap(); @@ -364,13 +364,13 @@ impl MinecraftShaderLanguageServer { eprintln!("match {:?}", diagnostic_capture); - let msg = diagnostic_capture.get(4).unwrap().as_str().replace("'' : ", ""); + let msg = diagnostic_capture.name("output").unwrap().as_str();//.replace("'' : ", ""); if msg.starts_with("compilation terminated") { continue; } - let line = max(match diagnostic_capture.get(3) { + let line = max(match diagnostic_capture.name("linenum") { Some(c) => match c.as_str().parse::() { Ok(i) => i, Err(_) => 0, @@ -382,16 +382,16 @@ impl MinecraftShaderLanguageServer { /* let line_text = source_lines[line as usize]; let leading_whitespace = line_text.len() - line_text.trim_start().len(); */ - let severity = match diagnostic_capture.get(1) { + let severity = match diagnostic_capture.name("severity") { Some(c) => match c.as_str() { - "ERROR" => DiagnosticSeverity::Error, - "WARNING" => DiagnosticSeverity::Warning, + "error" => DiagnosticSeverity::Error, + "warning" => DiagnosticSeverity::Warning, _ => DiagnosticSeverity::Information, } _ => DiagnosticSeverity::Information, }; - let origin = match diagnostic_capture.get(2) { + let origin = match diagnostic_capture.name("filepath") { Some(o) => o.as_str().to_string(), None => "".to_string(), }; @@ -573,12 +573,7 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer { } } - fn did_change_text_document(&mut self, params: DidChangeTextDocumentParams) { - self.wait.wait(); - - /* #[allow(unused_variables)] - let text_change = params.content_changes[0]; */ - //eprintln!("changed {} changes: {}", text_change., params.text_document.uri); + fn did_change_text_document(&mut self, _: DidChangeTextDocumentParams) { } fn did_close_text_document(&mut self, _: DidCloseTextDocumentParams) {} @@ -617,11 +612,8 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer { })); */ } - fn execute_command(&mut self, mut params: ExecuteCommandParams, completable: LSCompletable>) { - params.arguments.push(serde_json::Value::String(self.root.clone())); - - match self.command_provider.as_ref().unwrap().execute(¶ms.command, params.arguments) - { + fn execute_command(&mut self, params: ExecuteCommandParams, completable: LSCompletable>) { + match self.command_provider.as_ref().unwrap().execute(¶ms.command, params.arguments, &self.root) { Ok(resp) => { eprintln!("executed {} successfully", params.command); self.endpoint.send_notification(ShowMessage::METHOD, ShowMessageParams { @@ -633,7 +625,7 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer { Err(err) => { self.endpoint.send_notification(ShowMessage::METHOD, ShowMessageParams { typ: MessageType::Error, - message: format!("Failed to execute command '{}'", params.command), + message: format!("Failed to execute command '{}'. Reason: {}", params.command, err), }).expect("failed to send popup/show message notification"); eprintln!("failed to execute {}: {}", params.command, err); completable.complete(Err(MethodError::new(32420, err, ())))