diff --git a/server/src/common/formatter.py b/server/src/common/formatter.py index ebda635..29f72eb 100644 --- a/server/src/common/formatter.py +++ b/server/src/common/formatter.py @@ -15,43 +15,48 @@ def format_tcl(src: str, indent_str=" ") -> str: for raw_line in src.splitlines(): stripped = raw_line.strip() - # 1) Single-line 'if {cond} {action}' → no indent change + # Comments are ignored + if stripped.startswith("#"): + out_lines.append(indent_str * level + stripped) + continue + + # Single-line 'if {cond} {action}' → no indent change if re.match(r"^(if|elseif)\s*\{[^}]+\}\s*\{[^}]+\}$", stripped): out_lines.append(indent_str * level + stripped) continue - # 2) Combined '} else {' → dedent, print, then indent + # Combined '} else {' → dedent, print, then indent if re.match(r"^\}\s*(elseif|else)\b.*\{$", stripped): level = max(level - 1, 0) out_lines.append(indent_str * level + stripped) level += 1 continue - # 3) SPECIAL: closing brace plus tag on same line: '} Tag' + # SPECIAL: closing brace plus tag on same line: '} Tag' m = re.match(r"^\}\s+(.+)", stripped) - if m: + if m and not stripped.startswith("#"): # close one block level = max(level - 1, 0) # stay on one line: "} Tag" out_lines.append(f"{indent_str * level}}} {m.group(1)}") continue - # 4) Pure '}' → dedent then print + # Pure '}' → dedent then print if stripped == "}": level = max(level - 1, 0) out_lines.append(f"{indent_str * level}{stripped}") continue - # 5) 'elseif' or 'else' alone → align with matching 'if' + # 'elseif' or 'else' alone → align with matching 'if' if re.match(r"^(elseif|else)\b(?!.*\{)", stripped): level = max(level - 1, 0) out_lines.append(f"{indent_str * level}{stripped}") continue - # 6) Default: print at current indent + # Default: print at current indent out_lines.append(f"{indent_str * level}{stripped}") - # 7) Open a new block on lines ending with '{' + # Open a new block on lines ending with '{' if re.match(r"^(if|elseif)\b.*\{$", stripped) or stripped.endswith("{"): level += 1 diff --git a/server/src/lsp_server.py b/server/src/lsp_server.py index c49b3ea..c3351d1 100644 --- a/server/src/lsp_server.py +++ b/server/src/lsp_server.py @@ -54,9 +54,6 @@ LSP_SERVER = server.LanguageServer( name="NX Postprocessor Support", version="0.0.1", max_workers=MAX_WORKERS ) - -NX_PROC_LIST = [] - # ********************************************************** # Tool specific code goes below this. # ********************************************************** @@ -185,6 +182,7 @@ def _get_global_defaults(): "args": GLOBAL_SETTINGS.get("args", []), "importStrategy": GLOBAL_SETTINGS.get("importStrategy", "useBundled"), "showNotifications": GLOBAL_SETTINGS.get("showNotifications", "off"), + "formatter": GLOBAL_SETTINGS.get("formatter", False), }