mirror of
https://github.com/SpaceManiac/SpacemanDMM.git
synced 2025-12-23 05:36:47 +00:00
Autocomplete preprocessor macros
This commit is contained in:
parent
0d2e3cc28d
commit
1ac32d964a
2 changed files with 33 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
|||
//! The preprocessor.
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use std::io;
|
||||
use std::{io, fmt};
|
||||
use std::fs::File;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
|
|
@ -27,6 +27,22 @@ pub enum Define {
|
|||
},
|
||||
}
|
||||
|
||||
impl fmt::Display for Define {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
let subst = match self {
|
||||
Define::Constant { ref subst, .. } |
|
||||
Define::Function { ref subst, .. } => subst,
|
||||
};
|
||||
if subst.is_empty() {
|
||||
fmt.write_str("(macro)")
|
||||
} else if subst.len() == 1 {
|
||||
write!(fmt, "{}", subst[0])
|
||||
} else {
|
||||
fmt.write_str("(macro...)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An interval tree representing historic macro definitions.
|
||||
pub type DefineHistory = IntervalTree<Location, (String, Define)>;
|
||||
|
||||
|
|
|
|||
|
|
@ -342,6 +342,22 @@ impl<'a, R: io::RequestRead, W: io::ResponseWrite> Engine<'a, R, W> {
|
|||
}
|
||||
}
|
||||
|
||||
// macros
|
||||
if let Some(ref preprocessor) = self.preprocessor {
|
||||
// TODO: verify that the macro is in scope at the location
|
||||
for (_, &(ref name, ref define)) in preprocessor.history().iter() {
|
||||
if contains(name, query) {
|
||||
results.push(CompletionItem {
|
||||
label: name.to_owned(),
|
||||
kind: Some(CompletionItemKind::Constant),
|
||||
detail: Some(format!("{}", define)),
|
||||
.. Default::default()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fields
|
||||
let mut next = Some(ty);
|
||||
let mut skip = HashSet::new();
|
||||
while let Some(ty) = next {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue