Skip to content

Commit

Permalink
lsp feature
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Oct 15, 2023
1 parent 57ab307 commit f0711d1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion libs/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ tracing = { workspace = true }
vfs = { workspace = true }

[features]
hls = []
lsp = []
14 changes: 7 additions & 7 deletions libs/common/src/reporting/processed.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature = "hls")]
#[cfg(feature = "lsp")]
use std::collections::HashMap;
use std::rc::Rc;

Expand All @@ -22,12 +22,12 @@ pub struct Processed {
/// string offset(start, stop), source, source position
mappings: Vec<Mapping>,

#[cfg(feature = "hls")]
#[cfg(feature = "lsp")]
/// Map of token usage to definition
/// (token, definition)
declarations: HashMap<Position, Position>,

#[cfg(feature = "hls")]
#[cfg(feature = "lsp")]
/// Map of token definition to usage
/// (definition, usages)
usage: HashMap<Position, Vec<Position>>,
Expand Down Expand Up @@ -172,14 +172,14 @@ impl Processed {
/// [`Error::Workspace`] if a workspace path could not be read
pub fn new(
output: Vec<Output>,
#[cfg(feature = "hls")] usage: HashMap<Position, Vec<Position>>,
#[cfg(feature = "hls")] declarations: HashMap<Position, Position>,
#[cfg(feature = "lsp")] usage: HashMap<Position, Vec<Position>>,
#[cfg(feature = "lsp")] declarations: HashMap<Position, Position>,
warnings: Vec<Box<dyn Code>>,
) -> Result<Self, Error> {
let mut processed = Self {
#[cfg(feature = "hls")]
#[cfg(feature = "lsp")]
declarations,
#[cfg(feature = "hls")]
#[cfg(feature = "lsp")]
usage,
warnings,
..Default::default()
Expand Down
3 changes: 3 additions & 0 deletions libs/preprocessor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ vfs = { workspace = true }
criterion = "0.5.1"
paste = "1.0.14"

[features]
lsp = ["hemtt-common/lsp"]

[[bench]]
name = "ace_dogtags"
harness = false
4 changes: 2 additions & 2 deletions libs/preprocessor/src/processor/defines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl Processor {
})));
}
};
#[cfg(feature = "hls")]
#[cfg(feature = "lsp")]
self.usage.get_mut(source.position()).map_or_else(
|| {
// println!("missing {:?}", ident.position());
Expand All @@ -264,7 +264,7 @@ impl Processor {
usage.push(ident.position().clone());
},
);
#[cfg(feature = "hls")]
#[cfg(feature = "lsp")]
self.declarations
.insert(ident.position().clone(), source.position().clone());
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion libs/preprocessor/src/processor/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl Processor {
Symbol::Newline | Symbol::Eoi => Definition::Unit,
_ => Definition::Value(self.define_read_body(stream)),
};
#[cfg(feature = "hls")]
#[cfg(feature = "lsp")]
self.usage.insert(ident.position().clone(), Vec::new());
self.defines.insert(&ident_string, (ident, definition));
Ok(())
Expand Down
10 changes: 5 additions & 5 deletions libs/preprocessor/src/processor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature = "hls")]
#[cfg(feature = "lsp")]
use std::collections::HashMap;
use std::rc::Rc;

Expand Down Expand Up @@ -29,12 +29,12 @@ pub struct Processor {

pub(crate) token_count: usize,

#[cfg(feature = "hls")]
#[cfg(feature = "lsp")]
/// Map of token usage to definition
/// (token, definition)
pub(crate) declarations: HashMap<Position, Position>,

#[cfg(feature = "hls")]
#[cfg(feature = "lsp")]
/// Map of token definition to usage
/// (definition, usages)
pub(crate) usage: HashMap<Position, Vec<Position>>,
Expand Down Expand Up @@ -79,9 +79,9 @@ impl Processor {

Processed::new(
buffer,
#[cfg(feature = "hls")]
#[cfg(feature = "lsp")]
processor.usage,
#[cfg(feature = "hls")]
#[cfg(feature = "lsp")]
processor.declarations,
processor.warnings,
)
Expand Down

0 comments on commit f0711d1

Please sign in to comment.