From e018d9aec4843460ff9cdb1ba3e714a1a0733734 Mon Sep 17 00:00:00 2001
From: Brett Saviano <bsaviano@intersystems.com>
Date: Thu, 9 Jan 2025 07:59:34 -0500
Subject: [PATCH] Fixes #358

---
 CHANGELOG.md                  | 1 +
 server/src/providers/hover.ts | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 93373b5..bcac693 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
 
 ## [2.7.0] - 2025-XX-XX
 - Fix issue [#357](https://github.com/intersystems/language-server/issues/357): Add completion for globals and routines
+- Fix issue [#358](https://github.com/intersystems/language-server/issues/358): Uncaught error when hovering over a macro that's defined as empty in the current document
 
 ## [2.6.5] - 2024-11-13
 - Fix issue [#356](https://github.com/intersystems/language-server/issues/356): Unexpected new dialog during password retrieval using Server Manager authprovider
diff --git a/server/src/providers/hover.ts b/server/src/providers/hover.ts
index 51c9956..b5eecf6 100644
--- a/server/src/providers/hover.ts
+++ b/server/src/providers/hover.ts
@@ -200,6 +200,10 @@ export async function onHover(params: TextDocumentPositionParams): Promise<Hover
 									}
 								}
 							}
+							if (definitionendtkn == (parsed[ln].length - 1)) {
+								// This is an empty macro definition
+								break;
+							}
 						}
 						
 						if (
@@ -238,6 +242,8 @@ export async function onHover(params: TextDocumentPositionParams): Promise<Hover
 						}
 					}
 
+					if (definition == "") return null;
+
 					// If this macro has a formal spec, attempt to replace the parameters with the arguments from the usage
 					if (formalspec.endsWith(")")) {
 						let macroargs = getMacroArgs();