Skip to content

Commit 849e642

Browse files
committed
Fix _parse_file and add new test
Signed-off-by: konstantin <[email protected]>
1 parent 059d120 commit 849e642

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

lookout/style/format/features.py

+2
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ def _parse_file(self, contents: str, root: bblfsh.Node, path: str) -> \
639639
parser = self.tokens.PARSER
640640
searchsorted = numpy.searchsorted
641641
for node in node_tokens:
642+
if node.start_position.offset < pos:
643+
continue
642644
if node.start_position.offset > pos:
643645
sumlen = 0
644646
diff = contents[pos:node.start_position.offset]
1.86 KB
Binary file not shown.

lookout/style/format/tests/test_features.py

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ def setUpClass(cls):
2525
cls.uast = bblfsh.Node.FromString(fin.read())
2626
cls.extractor = FeatureExtractor("javascript", parents_depth=2, siblings_window=5)
2727

28+
def test_parse_file2(self):
29+
test_js_code_filepath = Path(__file__).parent / "for_parse_test.js.xz"
30+
with lzma.open(str(test_js_code_filepath), mode="rt") as f:
31+
code = f.read()
32+
uast = bblfsh.BblfshClient("0.0.0.0:9432").parse(
33+
filename="", language="javascript", contents=code.encode()).uast
34+
nodes, parents = self.extractor._parse_file(code, uast, test_js_code_filepath)
35+
self.assertEqual("".join(n.value for n in nodes), code)
36+
2837
def test_parse_file(self):
2938
nodes, parents = self.extractor._parse_file(self.contents, self.uast, "test_file")
3039
text = []

0 commit comments

Comments
 (0)