mirror of
https://github.com/SpaceManiac/SpacemanDMM.git
synced 2025-12-23 05:36:47 +00:00
Add an extra notification to make environment loading less noisy
This commit is contained in:
parent
c8b2b6ec2a
commit
c4a5672bc8
4 changed files with 47 additions and 4 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -148,6 +148,7 @@ dependencies = [
|
|||
"languageserver-types 0.36.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"petgraph 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ path = "main.rs"
|
|||
url = "1.6.0"
|
||||
serde = "1.0.27"
|
||||
serde_json = "1.0.10"
|
||||
serde_derive = "1.0.27"
|
||||
jsonrpc-core = "8.0.1"
|
||||
languageserver-types = "0.36"
|
||||
dreammaker = { path = "../dreammaker" }
|
||||
|
|
|
|||
14
src/langserver/extras.rs
Normal file
14
src/langserver/extras.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
//! Extensions to the language server protocol.
|
||||
|
||||
use langserver::notification::*;
|
||||
|
||||
pub enum WindowStatus {}
|
||||
impl Notification for WindowStatus {
|
||||
const METHOD: &'static str = "$window/status";
|
||||
type Params = WindowStatusParams;
|
||||
}
|
||||
#[derive(Debug, Default, Serialize)]
|
||||
pub struct WindowStatusParams {
|
||||
pub environment: Option<String>,
|
||||
pub tasks: Vec<String>,
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
extern crate url;
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
#[macro_use] extern crate serde_derive;
|
||||
extern crate petgraph;
|
||||
extern crate languageserver_types as langserver;
|
||||
extern crate jsonrpc_core as jsonrpc;
|
||||
|
|
@ -18,6 +19,7 @@ extern crate dreammaker as dm;
|
|||
mod io;
|
||||
mod document;
|
||||
mod symbol_search;
|
||||
mod extras;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::collections::HashMap;
|
||||
|
|
@ -114,6 +116,15 @@ impl<'a, R: io::RequestRead, W: io::ResponseWrite> Engine<'a, R, W> {
|
|||
)
|
||||
}
|
||||
|
||||
fn show_status<S>(&mut self, message: S) where
|
||||
S: Into<String>
|
||||
{
|
||||
self.issue_notification::<extras::WindowStatus>(extras::WindowStatusParams {
|
||||
environment: None,
|
||||
tasks: vec![message.into()],
|
||||
});
|
||||
}
|
||||
|
||||
fn file_url(&self, file: dm::FileId) -> Result<Url, jsonrpc::Error> {
|
||||
path_to_url(self.root.join(self.context.file_path(file)))
|
||||
}
|
||||
|
|
@ -139,14 +150,30 @@ impl<'a, R: io::RequestRead, W: io::ResponseWrite> Engine<'a, R, W> {
|
|||
|
||||
fn parse_environment(&mut self, environment: PathBuf) -> Result<(), jsonrpc::Error> {
|
||||
// handle the parsing
|
||||
let file_name = environment.file_name().unwrap_or("..".as_ref()).to_string_lossy();
|
||||
eprintln!("environment: {}", environment.display());
|
||||
if let Some(stem) = environment.file_stem() {
|
||||
self.issue_notification::<extras::WindowStatus>(extras::WindowStatusParams {
|
||||
environment: Some(stem.to_string_lossy().into_owned()),
|
||||
tasks: vec!["loading".to_owned()],
|
||||
})
|
||||
} else {
|
||||
self.show_status("loading");
|
||||
}
|
||||
|
||||
let ctx = self.context;
|
||||
let mut pp = match dm::preprocessor::Preprocessor::new(ctx, environment.clone()) {
|
||||
Ok(pp) => pp,
|
||||
Err(err) => {
|
||||
self.show_message(MessageType::Error, format!("Error loading {}", file_name));
|
||||
use std::error::Error;
|
||||
self.issue_notification::<langserver::notification::PublishDiagnostics>(
|
||||
langserver::PublishDiagnosticsParams {
|
||||
uri: path_to_url(environment)?,
|
||||
diagnostics: vec![langserver::Diagnostic {
|
||||
message: err.description().to_owned(),
|
||||
.. Default::default()
|
||||
}],
|
||||
}
|
||||
);
|
||||
eprintln!("{:?}", err);
|
||||
return Ok(());
|
||||
}
|
||||
|
|
@ -155,7 +182,7 @@ impl<'a, R: io::RequestRead, W: io::ResponseWrite> Engine<'a, R, W> {
|
|||
self.objtree = dm::parser::parse(ctx, dm::indents::IndentProcessor::new(ctx, &mut pp));
|
||||
pp.finalize();
|
||||
self.preprocessor = Some(pp);
|
||||
self.show_message(MessageType::Info, format!("Loaded {}", file_name));
|
||||
self.issue_notification::<extras::WindowStatus>(Default::default());
|
||||
|
||||
// initial diagnostics pump
|
||||
let mut map: HashMap<_, Vec<_>> = HashMap::new();
|
||||
|
|
@ -447,7 +474,7 @@ handle_notification! {
|
|||
if let Some(environment) = environment {
|
||||
self.parse_environment(environment)?;
|
||||
} else {
|
||||
self.show_message(MessageType::Error, "No DME found, language service not available.");
|
||||
self.show_status("no .dme file");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue