Skip to content

Commit

Permalink
fix(langserver): corrected inlay hints for bdd style keyword calls
Browse files Browse the repository at this point in the history
  • Loading branch information
d-biehl committed Oct 23, 2024
1 parent 41ff53f commit 77ce8f1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2144,7 +2144,7 @@ def _complete_KeywordCall_or_Fixture( # noqa: N802
keyword_token,
[t for t in kw_node.get_tokens(Token.ARGUMENT)],
self.namespace,
range_from_token(keyword_token).start,
range_from_token(keyword_token).end,
analyse_run_keywords=False,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ def _handle_keywordcall_fixture_template(
keyword_token,
arguments,
namespace,
range_from_token(keyword_token).start,
range_from_token(keyword_token).end,
)

if kw_result is None:
return None

kw_doc, _ = kw_result
kw_doc, keyword_token = kw_result

if kw_doc is None:
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _signature_help_KeywordCall_or_Fixture( # noqa: N802
keyword_token,
[t for t in kw_node.get_tokens(RobotToken.ARGUMENT)],
namespace,
range_from_token(keyword_token).start,
range_from_token(keyword_token).end,
analyse_run_keywords=False,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def reset_diagnostics(self) -> None:
self.multiple_keywords_result = None
self.result_bdd_prefix = None

# TODO: make this threadsafe
def find_keyword(
self,
name: Optional[str],
Expand Down Expand Up @@ -480,7 +481,7 @@ def _get_bdd_style_keyword(self, name: str) -> Optional[KeywordDoc]:
name[match.end() :], handle_bdd_style=False if get_robot_version() >= (7, 0) else True
)
if result:
self.result_bdd_prefix = str(match)
self.result_bdd_prefix = str(match.group(0))

return result
return None
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,14 @@ def get_keyworddoc_and_token_from_position(
position: Position,
analyse_run_keywords: bool = True,
) -> Optional[Tuple[Optional[KeywordDoc], Token]]:
keyword_doc = namespace.find_keyword(keyword_name, raise_keyword_error=False)
finder = namespace.get_finder()
keyword_doc = finder.find_keyword(keyword_name, raise_keyword_error=False)
if keyword_doc is None:
return None

if finder.result_bdd_prefix:
keyword_token = ModelHelper.strip_bdd_prefix(namespace, keyword_token)

if position.is_in_range(range_from_token(keyword_token)):
return keyword_doc, keyword_token

Expand Down
27 changes: 8 additions & 19 deletions packages/robot/src/robotcode/robot/diagnostics/namespace.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ast
import enum
import itertools
import time
import weakref
from collections import OrderedDict, defaultdict
from concurrent.futures import CancelledError
Expand Down Expand Up @@ -1804,28 +1803,18 @@ def iter_all_keywords(self) -> Iterator[KeywordDoc]:
def get_keywords(self) -> List[KeywordDoc]:
with self._keywords_lock:
if self._keywords is None:
current_time = time.monotonic()
self._logger.debug("start collecting keywords")
try:
i = 0

self.ensure_initialized()
i = 0

result: Dict[KeywordMatcher, KeywordDoc] = {}
self.ensure_initialized()

for doc in self.iter_all_keywords():
i += 1
result[doc.matcher] = doc
result: Dict[KeywordMatcher, KeywordDoc] = {}

self._keywords = list(result.values())
except BaseException:
self._logger.debug("Canceled collecting keywords ")
raise
else:
self._logger.debug(
lambda: f"end collecting {len(self._keywords) if self._keywords else 0}"
f" keywords in {time.monotonic() - current_time}s analyze {i} keywords"
)
for doc in self.iter_all_keywords():
i += 1
result[doc.matcher] = doc

self._keywords = list(result.values())

return self._keywords

Expand Down

0 comments on commit 77ce8f1

Please sign in to comment.