oraios/serena · error · Exception
`sourcekit-lsp -h` resulted in: {result}
Error message
`sourcekit-lsp -h` resulted in: {result} What it means
_get_sourcekit_lsp_version runs `sourcekit-lsp -h` to probe the Apple Swift toolchain LSP. A non-zero exit code raises an Exception which is immediately converted by the outer handler into a RuntimeError telling you to install sourcekit-lsp and ensure it's on PATH. (Note: this exact message is also raised when the command isn't found at all, since the except catches FileNotFoundError too.)
Source
Thrown at src/solidlsp/language_servers/sourcekit_lsp.py:41
@override
def is_ignored_dirname(self, dirname: str) -> bool:
# For Swift projects, we should ignore:
# - .build: Swift Package Manager build artifacts
# - .swiftpm: Swift Package Manager metadata
# - node_modules: if the project has JavaScript components
# - dist/build: common output directories
return super().is_ignored_dirname(dirname) or dirname in [".build", ".swiftpm", "node_modules", "dist", "build"]
@staticmethod
def _get_sourcekit_lsp_version() -> str:
"""Get the installed sourcekit-lsp version or raise error if sourcekit was not found."""
try:
result = subprocess_run(["sourcekit-lsp", "-h"], capture_output=True, text=True, check=False)
if result.returncode == 0:
return result.stdout.strip()
else:
raise Exception(f"`sourcekit-lsp -h` resulted in: {result}")
except Exception as e:
raise RuntimeError(
"Could not find sourcekit-lsp, please install it as described in https://github.com/apple/sourcekit-lsp#installation"
"And make sure it is available on your PATH."
) from e
def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):
sourcekit_version = self._get_sourcekit_lsp_version()
log.info(f"Starting sourcekit lsp with version: {sourcekit_version}")
super().__init__(
config, repository_root_path, ProcessLaunchInfo(cmd="sourcekit-lsp", cwd=repository_root_path), "swift", solidlsp_settings
)
self.request_id = 0
self._did_sleep_before_requesting_references = False
self._initialization_timestamp: float | None = None
@overrideView on GitHub (pinned to 7fcbca7e62)
Solutions
- Install sourcekit-lsp via the Swift toolchain (swift.org) or `xcode-select --install` on macOS, then select it with `sudo xcode-select -s /Applications/Xcode.app`.
- Add the toolchain's usr/bin to PATH and verify with `which sourcekit-lsp` and `sourcekit-lsp -h`.
- On Linux, install a matching Swift toolchain and ensure its bin directory is on PATH.
- If sourcekit-lsp exists but -h fails, repair/reinstall the toolchain or run it once manually to see the real error.
Example fix
// before $ sourcekit-lsp -h # command not found // after export PATH=/usr/share/swift/usr/bin:$PATH sourcekit-lsp -h # prints usage
Defensive patterns
Strategy: validation
Validate before calling
import shutil, subprocess
if not shutil.which("sourcekit-lsp"):
raise SystemExit("Install Swift toolchain / Xcode and add sourcekit-lsp to PATH")
subprocess.run(["sourcekit-lsp", "-h"], check=True, capture_output=True) Type guard
def sourcekit_lsp_available() -> bool:
import shutil, subprocess
if not shutil.which("sourcekit-lsp"):
return False
return subprocess.run(
["sourcekit-lsp", "-h"], capture_output=True
).returncode == 0 Try / catch
try:
server = SourceKitLSP(config, repo_root, settings)
except RuntimeError as e:
if "Could not find sourcekit-lsp" in str(e):
raise SystemExit("Install via swift.org toolchain or xcode-select --install; ensure PATH includes usr/bin") from e
raise Prevention
- Install the full Swift toolchain (swift.org) or full Xcode, not just CLT, in all environments.
- Add the toolchain usr/bin directory to PATH in shell profiles and CI.
- Smoke-test `sourcekit-lsp -h` in Dockerfile/CI before running the server.
When it happens
Trigger: Constructing SourceKitLSP when `sourcekit-lsp -h` returns non-zero (crash, corrupted toolchain, incompatible flags) or the binary is not found on PATH.
Common situations: Linux/CI machines without the Swift toolchain, macOS users with only Xcode (no full Xcode / Command Line Tools selected via xcode-select), PATH missing the Swift usr/bin directory, or broken multiple-toolchain installs.
Related errors
- Could not find sourcekit-lsp, please install it as described
- Mode file not found: {path.resolve()}
- Error: Path does not exist: {project_root}
- Error: Path is not a directory: {project_root}
- Project root not found: {project_root}
AI-assisted analysis of oraios/serena@7fcbca7e62 (2026-08-29).
Data as JSON: /api/errors/88e2781e1711a39c.
Report an issue: GitHub.