mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-08-30 21:37:25 +00:00
Updated validator output parsing for new method
This commit is contained in:
parent
96eaac213a
commit
8878b20631
4 changed files with 34 additions and 45 deletions
|
@ -23,11 +23,14 @@ export function restartExtension(e: Extension): Command {
|
|||
}
|
||||
|
||||
export function virtualMergedDocument(e: Extension): Command {
|
||||
const getVirtualDocument = async (path: string): Promise<string> => {
|
||||
const content = await e.lspClient.sendRequest<string>(lsp.ExecuteCommandRequest.type.method, {
|
||||
command: 'virtualMerge',
|
||||
arguments: [path]
|
||||
})
|
||||
const getVirtualDocument = async (path: string): Promise<string | null> => {
|
||||
let content: string = ""
|
||||
try {
|
||||
content = await e.lspClient.sendRequest<string>(lsp.ExecuteCommandRequest.type.method, {
|
||||
command: 'virtualMerge',
|
||||
arguments: [path]
|
||||
})
|
||||
} catch(e) {}
|
||||
|
||||
return content
|
||||
}
|
||||
|
|
|
@ -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 = "*"
|
||||
|
|
|
@ -28,16 +28,16 @@ impl CustomCommandProvider {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn execute(&self, command: &str, args: Vec<Value>) -> Result<Value, String> {
|
||||
pub fn execute(&self, command: &str, args: Vec<Value>, root_path: &str) -> Result<Value, String> {
|
||||
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<Value>) -> Result<Value, String>;
|
||||
fn run_command(&self, root: &str, arguments: Vec<Value>) -> Result<Value, String>;
|
||||
}
|
||||
|
||||
pub struct GraphDotCommand {
|
||||
|
@ -45,10 +45,8 @@ pub struct GraphDotCommand {
|
|||
}
|
||||
|
||||
impl Invokeable for GraphDotCommand {
|
||||
fn run_command(&self, arguments: Vec<Value>) -> Result<Value, String> {
|
||||
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<Value>) -> Result<Value, String> {
|
||||
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<Value>) -> Result<Value, String> {
|
||||
fn run_command(&self, root: &str, arguments: Vec<Value>) -> Result<Value, String> {
|
||||
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) + "/"))))
|
||||
}
|
||||
}
|
|
@ -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<filepath>[^?<>*|"]+?)\((?P<linenum>\d+)\) : (?P<severity>error|warning) [A-C]\d+: (?P<output>.+)"#).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::<u32>() {
|
||||
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<Option<Value>>) {
|
||||
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<Option<Value>>) {
|
||||
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, ())))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue