chore(lsprotocol): migrate to 2025.0.0 and cleanup artifacts
The changes align the project with the 2025.0.0 lsprotocol release, removing the old backport and updating type hints in the protocol hooks to use Sequence where appropriate. The dist-info and packaging metadata for older lsprotocol versions are replaced with the new 2025.0.0 artifacts. - Remove exceptiongroup backport used on Python <3.11 - Use Sequence instead of List in LS protocol hooks - Replace old dist-info with 2025.0.0 metadata
This commit is contained in:
@@ -69,13 +69,15 @@ class Formatter:
|
||||
assert len(debug_char) == 1
|
||||
if space is None:
|
||||
space = self.opts.indent
|
||||
elif isinstance(space, int):
|
||||
space = space * " "
|
||||
if self.opts.debug_whitespace:
|
||||
# Enable this to return a string of debug_char.
|
||||
return len(space) * debug_char
|
||||
return space
|
||||
|
||||
def get_spaces_in_braces(self, space: tuple[int, int]):
|
||||
spaces_in_braces = self.space("A", " ") if self.opts.spaces_in_braces else ""
|
||||
spaces_in_braces = self.space("A", 1) if self.opts.spaces_in_braces else ""
|
||||
if not self.opts.balanced_spaces_in_braces:
|
||||
# No balancing.
|
||||
return spaces_in_braces
|
||||
@@ -88,7 +90,7 @@ class Formatter:
|
||||
if space[0] != -1 and space[1] == -1:
|
||||
# we've got empty braces. Keep "{}" and "{ }" as is, but normalize
|
||||
# more than one space to a single space.
|
||||
return min(space[0], 1) * self.space("B", " ")
|
||||
return min(space[0], 1) * self.space("B", 1)
|
||||
|
||||
# Normalize more than one space to a single space.
|
||||
before = min(space[0], 1)
|
||||
@@ -101,7 +103,7 @@ class Formatter:
|
||||
# Check that we have a balanced expression.
|
||||
assert before == after
|
||||
# Keep either "{1}" or "{ 1 }".
|
||||
return before * self.space("C", " ")
|
||||
return before * self.space("C", 1)
|
||||
|
||||
def _brace(self, lines: list[str], space: tuple[int, int]) -> list[str]:
|
||||
"""Format content between braces.
|
||||
@@ -307,6 +309,10 @@ class Formatter:
|
||||
|
||||
def format_script(self, script: Script, should_indent=True) -> list[str]:
|
||||
lines = self.format_script_contents(script)
|
||||
if not script.braced:
|
||||
# Script came from a non-braced word argument (e.g. plugin called
|
||||
# parse_script on a BareWord). Don't wrap in braces.
|
||||
return lines
|
||||
if script.pos[0] == script.end_pos[0]:
|
||||
space_before = -1
|
||||
space_after = -1
|
||||
@@ -327,7 +333,7 @@ class Formatter:
|
||||
and isinstance(script.children[0], Comment)
|
||||
and script.pos[0] == script.children[0].pos[0]
|
||||
):
|
||||
open_brace += self.space("D", " ") + lines[0]
|
||||
open_brace += self.space("D", 1) + lines[0]
|
||||
lines = lines[1:]
|
||||
|
||||
if should_indent:
|
||||
@@ -353,14 +359,26 @@ class Formatter:
|
||||
child_lines = self.format(child)
|
||||
|
||||
if last_line == child.pos[0]:
|
||||
formatted[-1] += self.space("F", " ")
|
||||
if self.opts.emacs and child_lines[0][-1] == "\\":
|
||||
base_indent = (len(formatted[-1])) * self.space("G", " ")
|
||||
else:
|
||||
base_indent = ""
|
||||
formatted[-1] += self.space("F", 1)
|
||||
base_indent = ""
|
||||
if self.opts.emacs:
|
||||
if child_lines[0][-1] == "\\":
|
||||
base_indent = (len(formatted[-1])) * self.space("G", 1)
|
||||
elif (isinstance(child, BracedExpression)) and child_lines[
|
||||
-1
|
||||
] == "}":
|
||||
child_lines[1:-1] = self._indent(
|
||||
child_lines[1:-1], self.space("V", len(formatted[-1]))
|
||||
)
|
||||
elif (isinstance(child, BracedExpression)) and child_lines[-1][
|
||||
-1
|
||||
] == "}":
|
||||
child_lines[1:] = self._indent(
|
||||
child_lines[1:], self.space("W", len(formatted[-1]))
|
||||
)
|
||||
formatted[-1] += child_lines[0]
|
||||
else:
|
||||
formatted[-1] += self.space("H", " ") + "\\"
|
||||
formatted[-1] += self.space("H", 1) + "\\"
|
||||
formatted.append(self.space("I") + child_lines[0])
|
||||
hanging_indent = True
|
||||
|
||||
@@ -383,13 +401,19 @@ class Formatter:
|
||||
formatted = []
|
||||
contents = self.format_script_contents(command_sub)
|
||||
if len(command_sub.children) > 1 and len(contents) > 1:
|
||||
formatted.append("[")
|
||||
formatted.extend(self._indent(contents, self.space("K")))
|
||||
formatted.append("]")
|
||||
if self.opts.emacs and command_sub.pos[0] == command_sub.children[0].pos[0]:
|
||||
formatted = contents
|
||||
formatted[0] = "[" + formatted[0]
|
||||
formatted[-1] = formatted[-1] + "]"
|
||||
formatted[1:] = self._indent(formatted[1:], self.space("U", 1))
|
||||
else:
|
||||
formatted.append("[")
|
||||
formatted.extend(self._indent(contents, self.space("K")))
|
||||
formatted.append("]")
|
||||
else:
|
||||
formatted.append("[" + contents[0])
|
||||
if self.opts.emacs:
|
||||
indent = self.space("L", " ")
|
||||
indent = self.space("L", 1)
|
||||
else:
|
||||
indent = ""
|
||||
formatted.extend(self._indent(contents[1:], indent))
|
||||
@@ -460,7 +484,7 @@ class Formatter:
|
||||
for child in list_node.children:
|
||||
if last_line is not None:
|
||||
if last_line == child.pos[0]:
|
||||
contents[-1] += self.space("M", " ")
|
||||
contents[-1] += self.space("M", 1)
|
||||
else:
|
||||
newlines = child.pos[0] - last_line
|
||||
newlines = min(newlines, 3)
|
||||
@@ -516,6 +540,29 @@ class Formatter:
|
||||
space_after = expr.end_pos[1] - expr.children[-1].end_pos[1] - 1
|
||||
return self._brace(formatted, (space_before, space_after))
|
||||
|
||||
if self.opts.emacs:
|
||||
pre = []
|
||||
post = []
|
||||
indent_first = 0
|
||||
indent_last = len(formatted)
|
||||
if expr.pos[0] == expr.children[0].pos[0]:
|
||||
formatted[0] = "{" + formatted[0]
|
||||
indent_first = 1
|
||||
else:
|
||||
pre = ["{"]
|
||||
if expr.end_pos[0] == expr.children[-1].end_pos[0]:
|
||||
formatted[-1] = formatted[-1] + "}"
|
||||
else:
|
||||
post = ["}"]
|
||||
formatted = (
|
||||
pre
|
||||
+ formatted[0:indent_first]
|
||||
+ self._indent(formatted[indent_first:indent_last], self.space("X", 1))
|
||||
+ formatted[indent_last:]
|
||||
+ post
|
||||
)
|
||||
return formatted
|
||||
|
||||
return ["{"] + self._indent(formatted, self.space("P")) + ["}"]
|
||||
|
||||
def format_paren_expression(self, expr) -> list[str]:
|
||||
@@ -556,7 +603,7 @@ class Formatter:
|
||||
if last.end_pos[0] != next.pos[0]:
|
||||
formatted.extend(lines)
|
||||
else:
|
||||
formatted[-1] += self.space("R", " ")
|
||||
formatted[-1] += self.space("R", 1)
|
||||
formatted[-1] += lines[0]
|
||||
formatted.extend(lines[1:])
|
||||
last = next
|
||||
@@ -585,7 +632,7 @@ class Formatter:
|
||||
formatted.extend(lines)
|
||||
else:
|
||||
if i > 0:
|
||||
formatted[-1] += self.space("S", " ")
|
||||
formatted[-1] += self.space("S", 1)
|
||||
formatted[-1] += lines[0]
|
||||
formatted.extend(lines[1:])
|
||||
last = child
|
||||
|
||||
Reference in New Issue
Block a user