Copilot commented on code in PR #14038:
URL: https://github.com/apache/trafficserver/pull/14038#discussion_r4533125409


##########
tools/hrw4u/scripts/hrw4u-lsp:
##########
@@ -127,16 +129,16 @@ class DocumentManager:
             if hasattr(parser, '_syntax_errors'):
                 parser_errors = list(parser._syntax_errors)
 
-            if tree is not None:
-                visitor = HRW4UVisitor(
-                    filename=filename,
-                    error_collector=error_collector,
-                    proc_search_paths=self.proc_search_paths or None,
-                    sandbox=self.sandbox,
-                )
+            # An error-recovered tree has no AST; hover and definition keep 
the last analysis's procedures.
+            if tree is not None and not error_collector.has_errors():
                 try:
-                    visitor.visit(tree)
-                    self.proc_registries[uri] = dict(visitor._proc_registry)
+                    ast = ASTVisitor(filename=filename).visit(tree)
+                    sema = Sema(
+                        error_collector=error_collector, 
proc_search_paths=self.proc_search_paths or None, sandbox=self.sandbox
+                    )
+                    sema.source_map.add(filename, text)
+                    sema.analyze(ast)
+                    self.proc_registries[uri] = sema.procs

Review Comment:
   `Sema.analyze()` collects semantic errors without raising, so this 
assignment can replace the last error-free procedure registry with an 
incomplete one. For example, putting a required parameter after an optional 
parameter prevents registration; a subsequent syntax error then preserves the 
incomplete registry, losing the previous hover signature and definition. Update 
the cache only when the collector has no errors, as promised in the PR 
description.



##########
tools/hrw4u/src/common.py:
##########
@@ -309,24 +302,51 @@ def compile_to_conf(
     sema.source_map.add(filename, source_text)
     program = sema.analyze(ast)
     if error_collector is not None and error_collector.has_errors():
+        return None
+    return sema, ast, program
+
+
+def compile_to_conf(tree: Any, filename: str, source_text: str, **kwargs: Any) 
-> list[str]:
+    """Compile to header_rewrite lines through the resolved tree.
+
+    The single wiring both the CLI and the parity test use, so the two cannot 
drift. A
+    run that reported an error returns no lines: what the emitter renders 
around an
+    unresolved node is not a configuration anyone asked for.
+    """
+    from hrw4u.emit_conf import ConfEmitter
+
+    if (analyzed := _analyze(tree, filename, source_text, **kwargs)) is None:
         return []
+    _, _, program = analyzed
     return ConfEmitter().emit(program)
 
 
+def compile_to_hrw4u(tree: Any, filename: str, source_text: str, **kwargs: 
Any) -> list[str]:
+    """Rewrite to hrw4u with every procedure call written out in place, so the 
program needs no
+    procedures path. Fails like compile_to_conf."""
+    from hrw4u.ast_unparse import unparse
+
+    if (analyzed := _analyze(tree, filename, source_text, **kwargs)) is None:
+        return []
+    sema, ast, _ = analyzed
+    return unparse(sema.expand(ast)).splitlines()

Review Comment:
   `splitlines()` splits on Unicode separators such as U+2028, but the grammar 
only ends comments at CR/LF. A valid comment containing U+2028 followed by 
`REMAP { set-debug(); }` therefore becomes a comment followed by an active 
section in the flattened output, changing program behavior even without 
procedure calls. Split only on the LF separators emitted by `unparse`, removing 
its final trailing LF, so comment and literal contents remain intact.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to