{"record":{"id":"88e2781e1711a39c","repo":"oraios/serena","slug":"sourcekit-lsp-h-resulted-in-result","errorCode":null,"errorMessage":"`sourcekit-lsp -h` resulted in: {result}","messagePattern":"`sourcekit-lsp -h` resulted in: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/solidlsp/language_servers/sourcekit_lsp.py","lineNumber":41,"sourceCode":"\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        # For Swift projects, we should ignore:\n        # - .build: Swift Package Manager build artifacts\n        # - .swiftpm: Swift Package Manager metadata\n        # - node_modules: if the project has JavaScript components\n        # - dist/build: common output directories\n        return super().is_ignored_dirname(dirname) or dirname in [\".build\", \".swiftpm\", \"node_modules\", \"dist\", \"build\"]\n\n    @staticmethod\n    def _get_sourcekit_lsp_version() -> str:\n        \"\"\"Get the installed sourcekit-lsp version or raise error if sourcekit was not found.\"\"\"\n        try:\n            result = subprocess_run([\"sourcekit-lsp\", \"-h\"], capture_output=True, text=True, check=False)\n            if result.returncode == 0:\n                return result.stdout.strip()\n            else:\n                raise Exception(f\"`sourcekit-lsp -h` resulted in: {result}\")\n        except Exception as e:\n            raise RuntimeError(\n                \"Could not find sourcekit-lsp, please install it as described in https://github.com/apple/sourcekit-lsp#installation\"\n                \"And make sure it is available on your PATH.\"\n            ) from e\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        sourcekit_version = self._get_sourcekit_lsp_version()\n        log.info(f\"Starting sourcekit lsp with version: {sourcekit_version}\")\n\n        super().__init__(\n            config, repository_root_path, ProcessLaunchInfo(cmd=\"sourcekit-lsp\", cwd=repository_root_path), \"swift\", solidlsp_settings\n        )\n        self.request_id = 0\n        self._did_sleep_before_requesting_references = False\n        self._initialization_timestamp: float | None = None\n\n    @override","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/solidlsp/language_servers/sourcekit_lsp.py#L23-L59","documentation":"_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.)","triggerScenarios":"Constructing SourceKitLSP when `sourcekit-lsp -h` returns non-zero (crash, corrupted toolchain, incompatible flags) or the binary is not found on PATH.","commonSituations":"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.","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."],"exampleFix":"// before\n$ sourcekit-lsp -h  # command not found\n// after\nexport PATH=/usr/share/swift/usr/bin:$PATH\nsourcekit-lsp -h  # prints usage","handlingStrategy":"validation","validationCode":"import shutil, subprocess\nif not shutil.which(\"sourcekit-lsp\"):\n    raise SystemExit(\"Install Swift toolchain / Xcode and add sourcekit-lsp to PATH\")\nsubprocess.run([\"sourcekit-lsp\", \"-h\"], check=True, capture_output=True)","typeGuard":"def sourcekit_lsp_available() -> bool:\n    import shutil, subprocess\n    if not shutil.which(\"sourcekit-lsp\"):\n        return False\n    return subprocess.run(\n        [\"sourcekit-lsp\", \"-h\"], capture_output=True\n    ).returncode == 0","tryCatchPattern":"try:\n    server = SourceKitLSP(config, repo_root, settings)\nexcept RuntimeError as e:\n    if \"Could not find sourcekit-lsp\" in str(e):\n        raise SystemExit(\"Install via swift.org toolchain or xcode-select --install; ensure PATH includes usr/bin\") from e\n    raise","preventionTips":["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."],"tags":["swift","sourcekit","path","toolchain"],"backgroundTag":"language-server-not-on-path","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}