|
7 | 7 | from concurrent.futures import ProcessPoolExecutor
|
8 | 8 | from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
|
9 | 9 | from threading import Thread
|
10 |
| -from typing import TYPE_CHECKING, Any, List, Optional, Union, cast |
| 10 | +from typing import TYPE_CHECKING, Any, List, Optional, Tuple, Union, cast |
11 | 11 | from urllib.parse import parse_qs, urlparse
|
12 | 12 |
|
13 | 13 | from ....utils.logging import LoggingDescriptor
|
|
21 | 21 | Range,
|
22 | 22 | )
|
23 | 23 | from ...common.text_document import TextDocument
|
24 |
| -from ..diagnostics.library_doc import get_library_doc, get_robot_library_html_doc_str |
25 |
| -from ..diagnostics.namespace import LibraryEntry |
| 24 | +from ..diagnostics.library_doc import ( |
| 25 | + get_library_doc, |
| 26 | + get_robot_library_html_doc_str, |
| 27 | + resolve_robot_variables, |
| 28 | +) |
| 29 | +from ..diagnostics.namespace import LibraryEntry, Namespace |
26 | 30 | from ..utils.ast_utils import Token, get_node_at_position
|
27 | 31 | from .model_helper import ModelHelperMixin
|
28 | 32 |
|
@@ -219,19 +223,18 @@ async def collect(
|
219 | 223 |
|
220 | 224 | if isinstance(node, (LibraryImport, ResourceImport)):
|
221 | 225 |
|
222 |
| - args = f"&args={'::'.join(node.args)}" if isinstance(node, LibraryImport) and node.args else "" |
| 226 | + url = await self.build_url( |
| 227 | + node.name, node.args if isinstance(node, LibraryImport) else (), document, namespace |
| 228 | + ) |
| 229 | + |
223 | 230 | return [
|
224 | 231 | CodeAction(
|
225 | 232 | "Open Documentation",
|
226 | 233 | kind=CodeActionKinds.SOURCE + ".openDocumentation",
|
227 | 234 | command=Command(
|
228 | 235 | "Open Documentation",
|
229 | 236 | "robotcode.showDocumentation",
|
230 |
| - [ |
231 |
| - f"http://localhost:{self._documentation_server_port}/?name={node.name}" |
232 |
| - f"{args}" |
233 |
| - f"&basedir={document.uri.to_path().parent}" |
234 |
| - ], |
| 237 | + [url], |
235 | 238 | ),
|
236 | 239 | )
|
237 | 240 | ]
|
@@ -271,23 +274,56 @@ async def collect(
|
271 | 274 | if entry is None:
|
272 | 275 | return None
|
273 | 276 |
|
274 |
| - args = f"&args={'::'.join(entry.args)}" if entry.args else "" |
| 277 | + url = await self.build_url(entry.import_name, entry.args, document, namespace, kw_doc.name) |
| 278 | + |
275 | 279 | return [
|
276 | 280 | CodeAction(
|
277 | 281 | "Open Documentation",
|
278 | 282 | kind=CodeActionKinds.SOURCE + ".openDocumentation",
|
279 | 283 | command=Command(
|
280 | 284 | "Open Documentation",
|
281 | 285 | "robotcode.showDocumentation",
|
282 |
| - [ |
283 |
| - f"http://localhost:{self._documentation_server_port}" |
284 |
| - f"/?name={entry.import_name}" |
285 |
| - f"{args}" |
286 |
| - f"&basedir={document.uri.to_path().parent}" |
287 |
| - f"#{kw_doc.name}" |
288 |
| - ], |
| 286 | + [url], |
289 | 287 | ),
|
290 | 288 | )
|
291 | 289 | ]
|
292 | 290 |
|
293 | 291 | return None
|
| 292 | + |
| 293 | + async def build_url( |
| 294 | + self, |
| 295 | + name: str, |
| 296 | + args: Tuple[Any, ...], |
| 297 | + document: TextDocument, |
| 298 | + namespace: Namespace, |
| 299 | + target: Optional[str] = None, |
| 300 | + ) -> str: |
| 301 | + |
| 302 | + base_dir = str(document.uri.to_path().parent) |
| 303 | + |
| 304 | + robot_variables = resolve_robot_variables( |
| 305 | + str(namespace.imports_manager.folder.to_path()), |
| 306 | + base_dir, |
| 307 | + variables=await namespace.get_resolvable_variables(), |
| 308 | + ) |
| 309 | + try: |
| 310 | + name = robot_variables.replace_string(name.replace("\\", "\\\\"), ignore_errors=False) |
| 311 | + |
| 312 | + args = tuple(robot_variables.replace_string(v.replace("\\", "\\\\"), ignore_errors=False) for v in args) |
| 313 | + |
| 314 | + except (SystemExit, KeyboardInterrupt): |
| 315 | + raise |
| 316 | + except BaseException: |
| 317 | + pass |
| 318 | + |
| 319 | + url_args = f"&args={'::'.join(args)}" if args else "" |
| 320 | + |
| 321 | + url = ( |
| 322 | + f"http://localhost:{self._documentation_server_port}" |
| 323 | + f"/?name={name}" |
| 324 | + f"{url_args}" |
| 325 | + f"&basedir={base_dir}" |
| 326 | + f"{'#{target}' if target else ''}" |
| 327 | + ) |
| 328 | + |
| 329 | + return url |
0 commit comments