Skip to content

Commit 1447b42

Browse files
committed
bugfix: search for git markers even when loading files from memory
1 parent c5f980d commit 1447b42

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

snooty/rstparser.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -783,10 +783,7 @@ def __init__(self, project_config: ProjectConfig, visitor_class: Type[_V]) -> No
783783

784784
def parse(self, path: Path, text: Optional[str]) -> Tuple[_V, str]:
785785
diagnostics: List[Diagnostic] = []
786-
if text is None:
787-
text, diagnostics = self.project_config.read(path)
788-
else:
789-
text, diagnostics = self.project_config.substitute(text)
786+
text, diagnostics = self.project_config.read(path, text)
790787

791788
parser = NoTransformRstParser()
792789
settings = docutils.frontend.OptionParser(

snooty/test_project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_merge_conflict() -> None:
155155

156156
assert project_diagnostics[-1].message.startswith(
157157
"git merge conflict"
158-
) and project_diagnostics[-1].start == (69, 0)
158+
) and project_diagnostics[-1].start == (68, 0)
159159
assert project_diagnostics[-2].message.startswith(
160160
"git merge conflict"
161161
) and project_diagnostics[-2].start == (35, 0)

snooty/types.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,18 @@ def render_constants(self) -> Tuple["ProjectConfig", List[Diagnostic]]:
375375
self.constants = constants
376376
return self, all_diagnostics
377377

378-
def read(self, path: Path) -> Tuple[str, List[Diagnostic]]:
379-
text = path.read_text(encoding="utf-8")
380-
source_text, diagnostics = self.substitute(text)
378+
def read(
379+
self, path: Path, text: Optional[str] = None
380+
) -> Tuple[str, List[Diagnostic]]:
381+
if text is None:
382+
text = path.read_text(encoding="utf-8")
383+
384+
text, diagnostics = self.substitute(text)
381385
match_found = PAT_GIT_MARKER.finditer(text)
382386

383387
if match_found:
384388
for match in match_found:
385-
lineno = source_text.count("\n", 0, match.start())
389+
lineno = text.count("\n", 0, match.start())
386390
diagnostics.append(Diagnostic.error("git merge conflict found", lineno))
387391

388392
return (text, diagnostics)

0 commit comments

Comments
 (0)