Skip to content

Commit

Permalink
perf(language_server): corrected handling of matching multiple keywor…
Browse files Browse the repository at this point in the history
…ds if keywords have embedded keywords
  • Loading branch information
d-biehl committed Oct 26, 2024
1 parent 47510ac commit c662685
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 24 deletions.
18 changes: 6 additions & 12 deletions packages/robot/src/robotcode/robot/diagnostics/library_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,19 +913,13 @@ class KeywordStore:
source_type: Optional[str] = None
keywords: List[KeywordDoc] = field(default_factory=list)

@property
def _matchers(self) -> Dict[KeywordMatcher, KeywordDoc]:
if not hasattr(self, "__matchers"):
self.__matchers = {v.matcher: v for v in self.keywords}
return self.__matchers

def __getitem__(self, key: str) -> KeywordDoc:
items = [(k, v) for k, v in self._matchers.items() if k == key]
items = [v for v in self.keywords if v.matcher == key]

if not items:
raise KeyError
if len(items) == 1:
return items[0][1]
return items[0]

if self.source and self.source_type:
file_info = ""
Expand All @@ -940,14 +934,14 @@ def __getitem__(self, key: str) -> KeywordDoc:
else:
file_info = "File"
error = [f"{file_info} contains multiple keywords matching name '{key}':"]
names = sorted(k.name for k, v in items)
names = sorted(v.name for v in items)
raise KeywordError(
"\n ".join(error + names),
multiple_keywords=[v for _, v in items],
multiple_keywords=[v for v in items],
)

def __contains__(self, _x: object) -> bool:
return any(k == _x for k in self._matchers.keys())
return any(v.matcher == _x for v in self.keywords)

def __len__(self) -> int:
return len(self.keywords)
Expand Down Expand Up @@ -977,7 +971,7 @@ def get_all(self, key: str) -> List[KeywordDoc]:
return list(self.iter_all(key))

def iter_all(self, key: str) -> Iterable[KeywordDoc]:
yield from (v for k, v in self._matchers.items() if k == key)
yield from (v for v in self.keywords if v.matcher == key)


@dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ data: !GeneratedTestData
character: 1
line: 132
name: Embedded keyword
result: null
result:
- !Location
range:
end:
character: 33
line: 132
start:
character: 0
line: 132
uri: tests/references.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ data: !GeneratedTestData
character: 2
line: 132
name: Embedded keyword
result: null
result:
- !Location
range:
end:
character: 33
line: 132
start:
character: 0
line: 132
uri: tests/references.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ data: !GeneratedTestData
character: 1
line: 132
name: Embedded keyword
result: null
result:
- !Location
range:
end:
character: 33
line: 132
start:
character: 0
line: 132
uri: tests/references.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ data: !GeneratedTestData
character: 2
line: 132
name: Embedded keyword
result: null
result:
- !Location
range:
end:
character: 33
line: 132
start:
character: 0
line: 132
uri: tests/references.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,31 @@ data: !GeneratedTestData
character: 1
line: 132
name: Embedded keyword
result: null
result:
- !Location
range:
end:
character: 25
line: 91
start:
character: 4
line: 91
uri: tests/references.robot
- !Location
range:
end:
character: 25
line: 93
start:
character: 4
line: 93
uri: tests/references.robot
- !Location
range:
end:
character: 33
line: 132
start:
character: 0
line: 132
uri: tests/references.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,31 @@ data: !GeneratedTestData
character: 2
line: 132
name: Embedded keyword
result: null
result:
- !Location
range:
end:
character: 25
line: 91
start:
character: 4
line: 91
uri: tests/references.robot
- !Location
range:
end:
character: 25
line: 93
start:
character: 4
line: 93
uri: tests/references.robot
- !Location
range:
end:
character: 33
line: 132
start:
character: 0
line: 132
uri: tests/references.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,31 @@ data: !GeneratedTestData
character: 1
line: 132
name: Embedded keyword
result: null
result:
- !Location
range:
end:
character: 25
line: 91
start:
character: 4
line: 91
uri: tests/references.robot
- !Location
range:
end:
character: 25
line: 93
start:
character: 4
line: 93
uri: tests/references.robot
- !Location
range:
end:
character: 33
line: 132
start:
character: 0
line: 132
uri: tests/references.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,31 @@ data: !GeneratedTestData
character: 2
line: 132
name: Embedded keyword
result: null
result:
- !Location
range:
end:
character: 25
line: 91
start:
character: 4
line: 91
uri: tests/references.robot
- !Location
range:
end:
character: 25
line: 93
start:
character: 4
line: 93
uri: tests/references.robot
- !Location
range:
end:
character: 33
line: 132
start:
character: 0
line: 132
uri: tests/references.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,31 @@ data: !GeneratedTestData
character: 1
line: 132
name: Embedded keyword
result: null
result:
- !Location
range:
end:
character: 25
line: 91
start:
character: 4
line: 91
uri: tests/references.robot
- !Location
range:
end:
character: 25
line: 93
start:
character: 4
line: 93
uri: tests/references.robot
- !Location
range:
end:
character: 33
line: 132
start:
character: 0
line: 132
uri: tests/references.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,31 @@ data: !GeneratedTestData
character: 2
line: 132
name: Embedded keyword
result: null
result:
- !Location
range:
end:
character: 25
line: 91
start:
character: 4
line: 91
uri: tests/references.robot
- !Location
range:
end:
character: 25
line: 93
start:
character: 4
line: 93
uri: tests/references.robot
- !Location
range:
end:
character: 33
line: 132
start:
character: 0
line: 132
uri: tests/references.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,31 @@ data: !GeneratedTestData
character: 1
line: 132
name: Embedded keyword
result: null
result:
- !Location
range:
end:
character: 25
line: 91
start:
character: 4
line: 91
uri: tests/references.robot
- !Location
range:
end:
character: 25
line: 93
start:
character: 4
line: 93
uri: tests/references.robot
- !Location
range:
end:
character: 33
line: 132
start:
character: 0
line: 132
uri: tests/references.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,31 @@ data: !GeneratedTestData
character: 2
line: 132
name: Embedded keyword
result: null
result:
- !Location
range:
end:
character: 25
line: 91
start:
character: 4
line: 91
uri: tests/references.robot
- !Location
range:
end:
character: 25
line: 93
start:
character: 4
line: 93
uri: tests/references.robot
- !Location
range:
end:
character: 33
line: 132
start:
character: 0
line: 132
uri: tests/references.robot

0 comments on commit c662685

Please sign in to comment.