Skip to content

Commit ae617c7

Browse files
authored
Check for updated source file when formating source (#1043)
Hi, could you please review patch which checks for a newer version of a source file when formatting the source context. It fixes #1042. I've made the check a permanent feature rather than an option passed to `format_source_contest`, as I couldn't think of a scenario where using the cached version would be preferable if the file had been modified (but I could be wrong). Added a test to cover this case. Thanks Co-authored-by: ikappaki <[email protected]>
1 parent 03f1679 commit ae617c7

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
* Fix a bug where `keys` and `vals` would fail for records (#1030)
2020
* Fix a bug where operations on records created by `defrecord` failed for fields whose Python-safe names were mangled by the Python compiler (#1029)
2121
* Fix incorrect line numbers for compiler exceptions in nREPL when evaluating forms in loaded files (#1037)
22+
* Fix issue where the compiler exception message from the nREPL server could refer to the initially loaded file instead of the updated one (#1042)
2223

2324
## [v0.2.1]
2425
### Changed

src/basilisp/lang/source.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def format_source_context( # pylint: disable=too-many-arguments,too-many-locals
7878
else:
7979
cause_range = range(line, line + 1)
8080

81+
linecache.checkcache(filename=filename)
8182
if source_lines := linecache.getlines(filename):
8283
selected_lines: Iterable[str]
8384
if end_line is None and line > len(source_lines):

tests/basilisp/source_test.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,47 @@ def test_format_source_context(monkeypatch, source_file, source_file_path):
6262
" 5 | (let [a 5]" + os.linesep,
6363
" 6 | (b))" + os.linesep,
6464
] == format_bnc
65+
66+
67+
def test_format_source_context_file_change(monkeypatch, source_file, source_file_path):
68+
source_file.write_text(
69+
textwrap.dedent(
70+
"""
71+
(ns source-test)
72+
73+
(a)
74+
(let [a 5]
75+
(b))
76+
"""
77+
)
78+
)
79+
format_nc1 = format_source_context(
80+
source_file_path, 2, end_line=4, disable_color=True
81+
)
82+
assert [
83+
" 1 | " + os.linesep,
84+
" 2 > | (ns source-test)" + os.linesep,
85+
" 3 > | " + os.linesep,
86+
" 4 > | (a)" + os.linesep,
87+
" 5 | (let [a 5]" + os.linesep,
88+
" 6 | (b))" + os.linesep,
89+
] == format_nc1
90+
91+
source_file.write_text(
92+
textwrap.dedent(
93+
"""
94+
(ns source-test)
95+
(a)
96+
(abcd)
97+
"""
98+
)
99+
)
100+
format_nc2 = format_source_context(
101+
source_file_path, 2, end_line=4, disable_color=True
102+
)
103+
assert [
104+
" 1 | " + os.linesep,
105+
" 2 > | (ns source-test)" + os.linesep,
106+
" 3 > | (a)" + os.linesep,
107+
" 4 > | (abcd)" + os.linesep,
108+
] == format_nc2

0 commit comments

Comments
 (0)