Skip to content

Commit 04966fc

Browse files
committed
Added a method to Match for selecting a particular suggestion to apply
1 parent 50c8ada commit 04966fc

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎language_tool_python/match.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ def matchedText(self):
9696
""" Returns the text that garnered the error (without its surrounding context).
9797
"""
9898
return self.context[self.offsetInContext:self.offsetInContext+self.errorLength]
99+
100+
def select_replacement(self, index: int) -> None:
101+
"""Choose one suggestion and delete the others. Usefull when you want to apply a specific suggestion.\n
102+
By default, the first suggestion is chosen."""
103+
if index < 0 or index >= len(self.replacements):
104+
raise ValueError('This Match\'s suggestions are numbered from 0 to {}'.format(len(self.replacements) - 1))
105+
self.replacements = [self.replacements[index]]
99106

100107
def __eq__(self, other):
101108
return list(self) == list(other)

0 commit comments

Comments
 (0)