Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
579847b56d | ||
|
|
618d6b478b | ||
|
|
cf62044d3e |
+1
-1
@@ -2,7 +2,7 @@
|
||||
"name": "nx-post-support",
|
||||
"displayName": "NX Postprocessor Support",
|
||||
"description": "",
|
||||
"version": "2025.9.0",
|
||||
"version": "2025.8.201",
|
||||
"publisher": "Christoph",
|
||||
"icon": "images/nx-1.png",
|
||||
"serverInfo": {
|
||||
|
||||
@@ -4,7 +4,8 @@ from typing import List, Optional, Tuple
|
||||
import lsprotocol.types as lsp
|
||||
from pygls.workspace.text_document import TextDocument
|
||||
from tclint.lexer import TclSyntaxError
|
||||
from tclint.format import Formatter, FormatterOpts
|
||||
from tclint.format import FormatterOpts
|
||||
from tools.formatter import NxFormatter as Formatter
|
||||
from tclint.violations import Violation
|
||||
from plugins.poco_plugin import commands
|
||||
from tools import checks, parser
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
from tclint.format import Formatter as BaseFormatter
|
||||
from typing import List
|
||||
|
||||
|
||||
class NxFormatter(BaseFormatter):
|
||||
"""
|
||||
Custom formatter that inherits from tclint's Formatter but preserves explicit
|
||||
line continuations (\\) inside braced expressions when they span multiple lines.
|
||||
|
||||
This avoids generating syntax errors in environments that require a trailing
|
||||
backslash for multi-line expressions (e.g., certain NX Post interpreters),
|
||||
while leaving all other formatting behavior unchanged.
|
||||
"""
|
||||
|
||||
def format_braced_expression(self, expr) -> List[str]: # type: ignore[override]
|
||||
# This method mirrors BaseFormatter.format_braced_expression but inserts
|
||||
# a line continuation (" \") between continuation lines similar to
|
||||
# BaseFormatter.format_expression.
|
||||
formatted = [""]
|
||||
for child in expr.children:
|
||||
lines = self.format(child)
|
||||
formatted[-1] += lines[0]
|
||||
for line in lines[1:]:
|
||||
# add continuation on the previous line; keep next line at the same level
|
||||
formatted[-1] += " \\" # keep explicit continuation
|
||||
formatted += [line]
|
||||
|
||||
if expr.pos[0] == expr.end_pos[0]:
|
||||
return self._brace(formatted)
|
||||
|
||||
return ["{"] + self._indent(formatted, self.opts.indent) + ["}"]
|
||||
|
||||
Reference in New Issue
Block a user