Skip to content

Commit 6ffef45

Browse files
committed
cache lines that should be ignored by analyser
1 parent e713cc3 commit 6ffef45

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

robotcode/language_server/robotframework/diagnostics/analyzer.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,21 +239,34 @@ async def visit(self, node: ast.AST) -> None:
239239
finally:
240240
self.node_stack = self.node_stack[:-1]
241241

242+
@staticmethod
243+
async def get_ignored_lines(document: TextDocument) -> List[int]:
244+
return await document.get_cache(Analyzer.__get_ignored_lines)
245+
246+
@staticmethod
247+
async def __get_ignored_lines(document: TextDocument) -> List[int]:
248+
result = []
249+
lines = await document.get_lines()
250+
for line_no, line in enumerate(lines):
251+
252+
comment = EXTRACT_COMMENT_PATTERN.match(line)
253+
if comment and comment.group("comment"):
254+
for match in ROBOTCODE_PATTERN.finditer(comment.group("comment")):
255+
256+
if match.group("rule") == "ignore":
257+
result.append(line_no)
258+
259+
return result
260+
242261
@staticmethod
243262
async def should_ignore(document: Optional[TextDocument], range: Range) -> bool:
244263
import builtins
245264

246265
if document is not None:
247-
lines = await document.get_lines()
266+
lines = await Analyzer.get_ignored_lines(document)
248267
for line_no in builtins.range(range.start.line, range.end.line + 1):
249-
line = lines[line_no]
250-
251-
comment = EXTRACT_COMMENT_PATTERN.match(line)
252-
if comment and comment.group("comment"):
253-
for match in ROBOTCODE_PATTERN.finditer(comment.group("comment")):
254-
255-
if match.group("rule") == "ignore":
256-
return True
268+
if line_no in lines:
269+
return True
257270

258271
return False
259272

robotcode/language_server/robotframework/diagnostics/namespace.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,6 @@ async def get_global_variables(self) -> List[VariableDefinition]:
856856

857857
return self._global_variables
858858

859-
@_logger.call
860859
async def yield_variables(
861860
self,
862861
nodes: Optional[List[ast.AST]] = None,
@@ -906,7 +905,6 @@ async def get_resolvable_variables(
906905
if v.has_value
907906
}
908907

909-
@_logger.call
910908
async def get_variable_matchers(
911909
self, nodes: Optional[List[ast.AST]] = None, position: Optional[Position] = None
912910
) -> Dict[VariableMatcher, VariableDefinition]:
@@ -945,7 +943,6 @@ async def find_variable(
945943

946944
return None
947945

948-
@_logger.call
949946
async def _import_imports(
950947
self,
951948
imports: Iterable[Import],

0 commit comments

Comments
 (0)