diff --git a/crates/preprocessor/src/db.rs b/crates/preprocessor/src/db.rs index d323b06d6..d3f641763 100644 --- a/crates/preprocessor/src/db.rs +++ b/crates/preprocessor/src/db.rs @@ -61,11 +61,8 @@ pub(crate) fn preprocess_file_query( HashableHashMap::default(), HashableHashSet::default(), ); - let Some(params) = res.get(&root_file_id) else { - log::warn!( - "No preprocessing params found for file_id: {}", - root_file_id - ); + let Some(params) = res.get(&file_id) else { + log::warn!("No preprocessing params found for file_id: {}", file_id); return Arc::new(PreprocessingResult::default(db.file_text(file_id).as_ref())); }; diff --git a/crates/preprocessor/src/evaluator.rs b/crates/preprocessor/src/evaluator.rs index 5c8208b36..5494203d3 100644 --- a/crates/preprocessor/src/evaluator.rs +++ b/crates/preprocessor/src/evaluator.rs @@ -180,7 +180,10 @@ impl<'a> IfCondition<'a> { } _ => { if looking_for_defined { + log::debug!("Looking for defined macro: {:?}", symbol.text()); + log::debug!("Defined macros: {:?}", self.macro_store); if let Some(macro_) = self.macro_store.get(&symbol.text()) { + log::debug!("Found defined macro: {:?}", macro_); self.offsets.entry(symbol.range.start.line).or_default().push(Offset { file_id: macro_.file_id, range: symbol.range, diff --git a/crates/preprocessor/src/lib.rs b/crates/preprocessor/src/lib.rs index 582735b40..8911af5a6 100644 --- a/crates/preprocessor/src/lib.rs +++ b/crates/preprocessor/src/lib.rs @@ -250,12 +250,12 @@ where } pub fn preprocess_input(mut self) -> PreprocessingResult { - let _ = (self.include_file)( - &mut self.macros, - "sourcemod".to_string(), - self.file_id, - false, - ); + // let _ = (self.include_file)( + // &mut self.macros, + // "sourcemod".to_string(), + // self.file_id, + // false, + // ); let mut col_offset: Option = None; let mut expanded_symbol: Option<(Symbol, u32, FileId)> = None; while let Some(symbol) = if !self.expansion_stack.is_empty() { diff --git a/crates/sourcepawn_lsp/tests/text_document/goto_definition/macros.rs b/crates/sourcepawn_lsp/tests/text_document/goto_definition/macros.rs index caae58cf7..04b2c5f20 100644 --- a/crates/sourcepawn_lsp/tests/text_document/goto_definition/macros.rs +++ b/crates/sourcepawn_lsp/tests/text_document/goto_definition/macros.rs @@ -204,3 +204,63 @@ int qux = baz; "#, )); } + +#[test] +fn preprocessor_disable_1() { + assert_json_snapshot!(goto_definition( + r#" +%! main.sp +#define FOO +#if defined FOO +int foo; +#endif +void bar() { + foo = 1; + | + ^ +} +"#, + )); +} + +#[test] +fn preprocessor_disable_2() { + assert_json_snapshot!(goto_definition( + r#" +%! main.sp +#define FOO +#include "foo.sp" + +%! foo.sp +#if defined FOO +int foo; +#endif +void bar() { + foo = 1; + | + ^ +} +"#, + )); +} + +#[test] +fn preprocessor_disable_3() { + assert_json_snapshot!(goto_definition( + r#" +%! main.sp +#include "foo.sp" +#if defined FOO +int foo; +#endif +void bar() { + foo = 1; + | + ^ +} + +%! foo.sp +#define FOO +"#, + )); +} diff --git a/crates/sourcepawn_lsp/tests/text_document/goto_definition/snapshots/main__text_document__goto_definition__macros__preprocessor_disable_1.snap b/crates/sourcepawn_lsp/tests/text_document/goto_definition/snapshots/main__text_document__goto_definition__macros__preprocessor_disable_1.snap new file mode 100644 index 000000000..a2d7df52f --- /dev/null +++ b/crates/sourcepawn_lsp/tests/text_document/goto_definition/snapshots/main__text_document__goto_definition__macros__preprocessor_disable_1.snap @@ -0,0 +1,40 @@ +--- +source: crates/sourcepawn_lsp/tests/text_document/goto_definition/macros.rs +assertion_line: 210 +expression: "goto_definition(r#\"\n%! main.sp\n#define FOO\n#if defined FOO\nint foo;\n#endif\nvoid bar() {\n foo = 1;\n |\n ^\n}\n\"#)" +--- +[ + { + "originSelectionRange": { + "start": { + "line": 5, + "character": 4 + }, + "end": { + "line": 5, + "character": 7 + } + }, + "targetUri": "file:///main.sp", + "targetRange": { + "start": { + "line": 2, + "character": 4 + }, + "end": { + "line": 2, + "character": 7 + } + }, + "targetSelectionRange": { + "start": { + "line": 2, + "character": 4 + }, + "end": { + "line": 2, + "character": 7 + } + } + } +] diff --git a/crates/sourcepawn_lsp/tests/text_document/goto_definition/snapshots/main__text_document__goto_definition__macros__preprocessor_disable_2.snap b/crates/sourcepawn_lsp/tests/text_document/goto_definition/snapshots/main__text_document__goto_definition__macros__preprocessor_disable_2.snap new file mode 100644 index 000000000..6febca478 --- /dev/null +++ b/crates/sourcepawn_lsp/tests/text_document/goto_definition/snapshots/main__text_document__goto_definition__macros__preprocessor_disable_2.snap @@ -0,0 +1,40 @@ +--- +source: crates/sourcepawn_lsp/tests/text_document/goto_definition/macros.rs +assertion_line: 228 +expression: "goto_definition(r#\"\n%! main.sp\n#define FOO\n#include \"foo.sp\"\n\n%! foo.sp\n#if defined FOO\nint foo;\n#endif\nvoid bar() {\n foo = 1;\n |\n ^\n}\n\"#)" +--- +[ + { + "originSelectionRange": { + "start": { + "line": 4, + "character": 4 + }, + "end": { + "line": 4, + "character": 7 + } + }, + "targetUri": "file:///foo.sp", + "targetRange": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 7 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 7 + } + } + } +] diff --git a/crates/sourcepawn_lsp/tests/text_document/goto_definition/snapshots/main__text_document__goto_definition__macros__preprocessor_disable_3.snap b/crates/sourcepawn_lsp/tests/text_document/goto_definition/snapshots/main__text_document__goto_definition__macros__preprocessor_disable_3.snap new file mode 100644 index 000000000..2fff95a7e --- /dev/null +++ b/crates/sourcepawn_lsp/tests/text_document/goto_definition/snapshots/main__text_document__goto_definition__macros__preprocessor_disable_3.snap @@ -0,0 +1,40 @@ +--- +source: crates/sourcepawn_lsp/tests/text_document/goto_definition/macros.rs +assertion_line: 249 +expression: "goto_definition(r#\"\n%! main.sp\n#include \"foo.sp\"\n#if defined FOO\nint foo;\n#endif\nvoid bar() {\n foo = 1;\n |\n ^\n}\n\n%! foo.sp\n#define FOO\n\"#)" +--- +[ + { + "originSelectionRange": { + "start": { + "line": 5, + "character": 4 + }, + "end": { + "line": 5, + "character": 7 + } + }, + "targetUri": "file:///main.sp", + "targetRange": { + "start": { + "line": 2, + "character": 4 + }, + "end": { + "line": 2, + "character": 7 + } + }, + "targetSelectionRange": { + "start": { + "line": 2, + "character": 4 + }, + "end": { + "line": 2, + "character": 7 + } + } + } +]