Skip to content

Commit

Permalink
Give a best-guess for unregistered files instead of erroring
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceManiac committed Sep 15, 2018
1 parent fae911a commit 03256bc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
23 changes: 23 additions & 0 deletions src/dreammaker/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,29 @@ impl<'ctx> Preprocessor<'ctx> {
}
}

/// Branch a child preprocessor from this preprocessor's current state.
pub fn branch<'ctx2>(&self, context: &'ctx2 Context) -> Preprocessor<'ctx2> {
Preprocessor {
context: context,
env_file: self.env_file.clone(),
include_stack: Default::default(),
history: Default::default(), // TODO: support branching a second time
defines: self.defines.clone(),
maps: Default::default(),
skins: Default::default(),
scripts: Default::default(),
ifdef_stack: Default::default(), // should be fine
ifdef_history: Default::default(),
last_input_loc: self.last_input_loc,
last_printable_input_loc: self.last_printable_input_loc,
output: Default::default(),
danger_idents: Default::default(),
docs_in: Default::default(),
docs_out: Default::default(),
in_interp_string: 0,
}
}

/// Check whether this preprocessor's state as of the end of the given file
/// matches the given child preprocessor.
pub fn matches_end_of_file(&self, file: FileId, other: &Preprocessor) -> bool {
Expand Down
9 changes: 4 additions & 5 deletions src/langserver/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,11 @@ impl<'a, R: io::RequestRead, W: io::ResponseWrite> Engine<'a, R, W> {
Some(ref pp) => pp,
None => return Err(invalid_request("no preprocessor")),
};
let real_file_id = match self.context.get_file(&stripped) {
Some(id) => id,
None => return Err(invalid_request(format!("unregistered: {}", stripped.display()))),
};
let context = Default::default();
let mut preprocessor = preprocessor.branch_at_file(real_file_id, &context);
let (real_file_id, mut preprocessor) = match self.context.get_file(&stripped) {
Some(id) => (id, preprocessor.branch_at_file(id, &context)),
None => (FileId::default(), preprocessor.branch(&context)),
};
let contents = self.docs.read(path).map_err(invalid_request)?;
let file_id = preprocessor.push_file(stripped.to_owned(), contents);
let indent = dm::indents::IndentProcessor::new(&context, preprocessor);
Expand Down

0 comments on commit 03256bc

Please sign in to comment.