Detect FreeBSD as a platform (#1947)

Language server initialization failed on FreeBSD with "Unknown platform" as there was no mapping for FreeBSD.
This commit is contained in:
Scott McLeod authored and GitHub committed 2026-09-03 17:15:10 +02:00
1 parent ef30801377
commit bcb3fc74ff
3 files changed
+50 -3

No files matched your search

+1
View File
@@ -30,6 +30,7 @@ Status of the `main` branch. Changes prior to the next official version change w
Serena's own tools to close the gap (#1852)
* Language Servers:
- Add FreeBSD mapping to platform detection
- Fix: the managed Solidity language server could report no diagnostics on macOS when Hardhat could not write
its global state under ``~/Library``; Serena now gives the child process an isolated home-directory view
via ``solidity_state_dir`` without changing the parent process's ``HOME`` (#1817)
+8 -2
View File
@@ -657,6 +657,8 @@ class PlatformId(str, Enum):
LINUX_arm64 = "linux-arm64"
LINUX_MUSL_x64 = "linux-musl-x64"
LINUX_MUSL_arm64 = "linux-musl-arm64"
FREEBSD_x64 = "freebsd-x64"
FREEBSD_arm64 = "freebsd-arm64"
def is_windows(self) -> bool:
return self.value.startswith("win")
@@ -686,10 +688,11 @@ class PlatformUtils:
bitness = platform.architecture()[0]
if system == "Windows" and machine == "":
machine = cls._determine_windows_machine_type()
system_map = {"Windows": "win", "Darwin": "osx", "Linux": "linux"}
system_map = {"Windows": "win", "Darwin": "osx", "Linux": "linux", "FreeBSD": "freebsd"}
machine_map = {
"AMD64": "x64",
"x86_64": "x64",
"amd64": "x64",
"i386": "x86",
"i686": "x86",
"aarch64": "arm64",
@@ -703,7 +706,10 @@ class PlatformUtils:
if libc != "glibc":
# Format: linux-musl-arch (e.g., linux-musl-arm64)
platform_id = f"{system_map[system]}-{libc}-{machine_map[machine]}"
return PlatformId(platform_id)
try:
return PlatformId(platform_id)
except ValueError:
raise SolidLSPException(f"Unknown platform: {system=}, {machine=}, {bitness=}") from None
else:
raise SolidLSPException(f"Unknown platform: {system=}, {machine=}, {bitness=}")
+41 -1
View File
@@ -6,7 +6,8 @@ from unittest.mock import patch
import pytest
from solidlsp.ls_utils import FileUtils
from solidlsp.ls_exceptions import SolidLSPException
from solidlsp.ls_utils import FileUtils, PlatformId, PlatformUtils
class _FakeResponse:
@@ -104,3 +105,42 @@ def test_read_file_primary_path_normalizes_crlf(tmp_path: Path) -> None:
assert "\r" not in content
assert content.splitlines() == lines
@pytest.mark.parametrize(
("system", "machine", "expected"),
[
pytest.param("FreeBSD", "amd64", PlatformId.FREEBSD_x64, id="freebsd-amd64"),
pytest.param("FreeBSD", "arm64", PlatformId.FREEBSD_arm64, id="freebsd-arm64"),
],
)
def test_get_platform_id_freebsd(system: str, machine: str, expected: PlatformId) -> None:
"""FreeBSD should resolve to a freebsd platform id."""
with (
patch("solidlsp.ls_utils.platform.system", return_value=system),
patch("solidlsp.ls_utils.platform.machine", return_value=machine),
patch("solidlsp.ls_utils.platform.architecture", return_value=("64bit",)),
):
assert PlatformUtils.get_platform_id() is expected
def test_get_platform_id_freebsd_i386_raises() -> None:
"""32-bit FreeBSD was deprecated with the release of FreeBSD 15.0 and must fail with the standard error."""
with (
patch("solidlsp.ls_utils.platform.system", return_value="FreeBSD"),
patch("solidlsp.ls_utils.platform.machine", return_value="i386"),
patch("solidlsp.ls_utils.platform.architecture", return_value=("32bit",)),
):
with pytest.raises(SolidLSPException, match="Unknown platform"):
PlatformUtils.get_platform_id()
def test_get_platform_id_unknown_platform_still_raises() -> None:
"""Platforms without an explicit mapping must keep failing explicitly."""
with (
patch("solidlsp.ls_utils.platform.system", return_value="SunOS"),
patch("solidlsp.ls_utils.platform.machine", return_value="i86pc"),
patch("solidlsp.ls_utils.platform.architecture", return_value=("64bit",)),
):
with pytest.raises(SolidLSPException):
PlatformUtils.get_platform_id()