|
4 | 4 | import socket |
5 | 5 | import threading |
6 | 6 | import traceback |
| 7 | +import urllib.parse |
7 | 8 | from concurrent.futures import ProcessPoolExecutor |
8 | 9 | from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer |
9 | 10 | from threading import Thread |
10 | 11 | from typing import TYPE_CHECKING, Any, List, Optional, Tuple, Union, cast |
11 | 12 | from urllib.parse import parse_qs, urlparse |
12 | 13 |
|
13 | 14 | from ....utils.logging import LoggingDescriptor |
14 | | -from ....utils.net import check_free_port |
| 15 | +from ....utils.net import find_free_port |
15 | 16 | from ...common.decorators import code_action_kinds, language_id |
16 | 17 | from ...common.lsp_types import ( |
17 | 18 | CodeAction, |
@@ -182,8 +183,9 @@ async def shutdown(self, sender: Any) -> None: |
182 | 183 | self._documentation_server = None |
183 | 184 |
|
184 | 185 | def _run_server(self) -> None: |
185 | | - self._documentation_server_port = check_free_port(3100) |
186 | | - with DualStackServer(("", self._documentation_server_port), LibDocRequestHandler) as server: |
| 186 | + self._documentation_server_port = find_free_port(3100, 3200) |
| 187 | + |
| 188 | + with DualStackServer(("127.0.0.1", self._documentation_server_port), LibDocRequestHandler) as server: |
187 | 189 | self._documentation_server = server |
188 | 190 | try: |
189 | 191 | server.serve_forever() |
@@ -316,14 +318,11 @@ async def build_url( |
316 | 318 | except BaseException: |
317 | 319 | pass |
318 | 320 |
|
319 | | - url_args = f"&args={'::'.join(args)}" if args else "" |
| 321 | + url_args = "::".join(args) if args else "" |
320 | 322 |
|
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 | | - ) |
| 323 | + base_url = f"http://localhost:{self._documentation_server_port}" |
| 324 | + params = urllib.parse.urlencode({"name": name, "args": url_args, "basedir": base_dir}) |
| 325 | + |
| 326 | + url = f"{base_url}" f"/?&{params}" f"{f'#{target}' if target else ''}" |
328 | 327 |
|
329 | 328 | return url |
0 commit comments