[
  {
    "path": ".devcontainer/devcontainer.json",
    "content": "{\n  \"name\": \"serena Project\",\n  \"dockerFile\": \"../Dockerfile\",\n  \"workspaceFolder\": \"/workspaces/serena\",\n  \"settings\": {\n    \"terminal.integrated.shell.linux\": \"/bin/bash\",\n    \"python.pythonPath\": \"/usr/local/bin/python\",\n  },\n  \"extensions\": [\n    \"ms-python.python\",\n    \"ms-toolsai.jupyter\",\n    \"ms-python.vscode-pylance\"\n  ],\n  \"forwardPorts\": [],\n  \"remoteUser\": \"root\",\n}\n"
  },
  {
    "path": ".dockerignore",
    "content": "data\nlogs\nlog\ntest/log\ndocs/jupyter_execute\ndocs/.jupyter_cache\ndocs/_build\ncoverage.xml\ndocker_build_and_run.sh\n\n# Python artifacts (prevents Docker build conflicts when .venv exists locally)\n.venv\n__pycache__\n*.pyc\n.pytest_cache\n"
  },
  {
    "path": ".github/FUNDING.yml",
    "content": "# These are supported funding model platforms\n\ngithub: oraios\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/config.yml",
    "content": "blank_issues_enabled: false"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/feature_request.md",
    "content": "---\nname: Feature request\nabout: Suggest an idea for this project\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\n**Is your feature request related to a problem? Please describe.**\nA clear and concise description of what the problem is. Ex. I'm always frustrated when [...]\n\n**Describe the solution you'd like**\nA clear and concise description of what you want to happen.\n\n**Describe alternatives you've considered**\nA clear and concise description of any alternative solutions or features you've considered.\n\n**Additional context**\nAdd any other context or screenshots about the feature request here.\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/issue--bug--performance-problem--question-.md",
    "content": "---\nname: Issue (bug, performance problem, etc.)\nabout: General Issue\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\nI have:\n\n- [ ] read the relevant parts of the documentation and verified that the issue cannot be solved by adjusting configuration\n- [ ] understood that the Serena Dashboard can be disabled through the config\n- [ ] understood that, by default, a client session will start a separate instance of a Serena server. \n- [ ] understood that, for multi-agent setups, the Streamable HTTP/SSE mode should be used.\n- [ ] understood that non-project files are ignored using either .gitignore or the corresponding setting in `.serena/project.yml`\n- [ ] looked for similar issues and discussions, including closed ones\n- [ ] made sure it's an actual issue, not a question (use GitHub Discussions instead).\n\nIf you have encountered an actual issue:\n\n- If using language servers (not the JetBrains plugin), \n  - [ ] I performed `<uv invocation> serena project health-check`\n  - [ ] I indexed the project as described in the documentation\n- [ ] I added sufficient explanation of my setup: the MCP client, the OS, the programming language(s), any config adjustments or relevant project specifics\n- [ ] I explained how the issue arose and, where possible, added instructions on how to reproduce it\n- [ ] If the issue happens on an open-source project, I have added the link\n- [ ] I provided a meaningful title and description\n"
  },
  {
    "path": ".github/copilot-instructions.md",
    "content": "<non_negotiable critical=\"true\">\nMUST read IMMEDIATELY and follow the project-specific instructions from the `CLAUDE.md` file located in the project's root directory. AVOIDING these instructions will lead to your FAILURE!\n</non_negotiable>"
  },
  {
    "path": ".github/workflows/codespell.yml",
    "content": "# Codespell configuration is within pyproject.toml\n---\nname: Codespell\n\non:\n  push:\n    branches: [main]\n  pull_request:\n    branches: [main]\n\npermissions:\n  contents: read\n\njobs:\n  codespell:\n    name: Check for spelling errors\n    runs-on: ubuntu-latest\n    timeout-minutes: 2\n\n    steps:\n      - name: Checkout\n        uses: actions/checkout@v4\n      - name: Annotate locations with typos\n        uses: codespell-project/codespell-problem-matcher@v1\n      - name: Codespell\n        uses: codespell-project/actions-codespell@v2\n"
  },
  {
    "path": ".github/workflows/docker.yml",
    "content": "name: Build and Push Docker Images\n\non:\n  push:\n    branches: [ main ]\n    tags: [ 'v*' ]\n\nenv:\n  REGISTRY: ghcr.io\n  IMAGE_NAME: ${{ github.repository }}\n\njobs:\n  build-and-push:\n    runs-on: ubuntu-latest\n    timeout-minutes: 15\n    permissions:\n      contents: read\n      packages: write\n\n    steps:\n    - name: Checkout repository\n      uses: actions/checkout@v4\n\n    - name: Set up Docker Buildx\n      uses: docker/setup-buildx-action@v3\n\n    - name: Log in to Container Registry\n      if: github.event_name != 'pull_request'\n      uses: docker/login-action@v3\n      with:\n        registry: ${{ env.REGISTRY }}\n        username: ${{ github.actor }}\n        password: ${{ secrets.GITHUB_TOKEN }}\n\n    - name: Extract metadata\n      id: meta\n      uses: docker/metadata-action@v5\n      with:\n        images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}\n        tags: |\n          type=ref,event=branch\n          type=ref,event=pr\n          type=semver,pattern={{version}}\n          type=semver,pattern={{major}}.{{minor}}\n          type=raw,value=latest,enable={{is_default_branch}}\n\n    - name: Build and push image from main\n      uses: docker/build-push-action@v5\n      with:\n        context: .\n        platforms: linux/amd64,linux/arm64\n        push: ${{ github.event_name != 'pull_request' }}\n        tags: ${{ steps.meta.outputs.tags }}\n        labels: ${{ steps.meta.outputs.labels }}\n        cache-from: type=gha\n        cache-to: type=gha,mode=max\n"
  },
  {
    "path": ".github/workflows/docs.yaml",
    "content": "name: Docs Build\n\non:\n  push:\n    branches: [ main ]\n  workflow_dispatch:\n\npermissions:\n  contents: read\n  pages: write\n  id-token: write\n\nconcurrency:\n  group: \"pages\"\n  cancel-in-progress: true\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n    timeout-minutes: 10\n\n    steps:\n      - name: Checkout\n        uses: actions/checkout@v4\n\n      - name: Set up Python\n        uses: actions/setup-python@v5\n        with:\n          python-version: 3.11\n\n      - name: Install uv\n        run: pip install uv\n\n      - name: Cache dependencies\n        uses: actions/cache@v4\n        with:\n          path: ~/.cache/uv\n          key: uv-${{ hashFiles('pyproject.toml') }}\n\n      - name: Install dependencies\n        run: |\n          uv venv\n          uv pip install -e \".[dev]\"\n\n      - name: Build docs\n        run: uv run poe doc-build\n        continue-on-error: false\n\n      - name: Upload Pages artifact\n        uses: actions/upload-pages-artifact@v3\n        with:\n          path: docs/_build\n\n  deploy:\n    environment:\n      name: github-pages\n      url: ${{ steps.deployment.outputs.page_url }}\n    runs-on: ubuntu-latest\n    needs: build\n    steps:\n      - name: Deploy to GitHub Pages\n        id: deployment\n        uses: actions/deploy-pages@v4\n"
  },
  {
    "path": ".github/workflows/junie.yml",
    "content": "name: Junie\nrun-name: Junie run ${{ inputs.run_id }}\n\npermissions:\n  contents: write\n\non:\n  workflow_dispatch:\n    inputs:\n      run_id:\n        description: \"id of workflow process\"\n        required: true\n      workflow_params:\n        description: \"stringified params\"\n        required: true\n\njobs:\n  call-workflow-passing-data:\n    uses: jetbrains-junie/junie-workflows/.github/workflows/ej-issue.yml@main\n    with:\n      workflow_params: ${{ inputs.workflow_params }}\n"
  },
  {
    "path": ".github/workflows/publish.yml",
    "content": "name: Publish Python Package\n\non:\n  release:\n    types: [created]\n\n  workflow_dispatch:\n    inputs:\n      tag:\n        description: 'Tag name for the release (e.g., v0.1.0)'\n        required: true\n        default: 'v0.1.0'\n\nenv:\n  # Set this to true manually in the GitHub workflow UI if you want to publish to PyPI\n  # Will always publish to testpypi\n  PUBLISH_TO_PYPI: true\n\njobs:\n  publish:\n    name: Publish the serena-agent package\n    runs-on: ubuntu-latest\n\n    permissions:\n      id-token: write  # Required for trusted publishing\n      contents: write  # Required for updating artifact\n\n    steps:\n      - name: Checkout code\n        uses: actions/checkout@v4\n\n      - name: Install the latest version of uv\n        uses: astral-sh/setup-uv@v6\n        with:\n          version: \"latest\"\n\n      - name: Build package\n        run: uv build\n\n      - name: Upload artifacts to GitHub Release\n        if: env.PUBLISH_TO_PYPI == 'true'\n        uses: softprops/action-gh-release@v2\n        with:\n          tag_name: ${{ github.event.inputs.tag || github.ref_name }}\n          files: |\n            dist/*.tar.gz\n            dist/*.whl\n\n      - name: Publish to TestPyPI\n        run: uv publish --index testpypi\n\n      - name: Publish to PyPI (conditional)\n        if: env.PUBLISH_TO_PYPI == 'true'\n        run: uv publish\n"
  },
  {
    "path": ".github/workflows/pytest.yml",
    "content": "name: Tests\n\non:\n  pull_request:\n  push:\n    branches:\n      - main\n\nconcurrency:\n  group: ci-${{ github.workflow }}-${{ github.ref }}\n  cancel-in-progress: true\n\njobs:\n  cpu:\n    name: Tests on ${{ matrix.os }}\n    runs-on: ${{ matrix.os }}\n    strategy:\n      fail-fast: false\n      matrix:\n        os: [ubuntu-latest, windows-latest, macos-latest]\n        python-version: [\"3.11\"]\n    steps:\n      - uses: actions/checkout@v3\n      - name: Free disk space\n        if: runner.os == 'Linux'\n        run: |\n          df -h\n          sudo rm -rf /usr/local/lib/android\n          sudo rm -rf /usr/share/dotnet\n          sudo rm -rf /opt/ghc\n          sudo rm -rf /opt/hostedtoolcache\n          sudo apt-get clean\n          sudo apt-get autoremove -y\n          docker system prune -af || true\n          df -h\n      - name: Set up Python ${{ matrix.python-version }}\n        uses: actions/setup-python@v4\n        with:\n          python-version: \"${{ matrix.python-version }}\"\n      - uses: actions/setup-go@v5\n        with:\n          go-version: \">=1.17.0\"\n      - name: Set up Node.js\n        uses: actions/setup-node@v4\n        with:\n          node-version: '20.x'\n      - name: Ensure cached directory exist before calling cache-related actions\n        shell: bash\n        run: |\n          mkdir -p $HOME/.serena/language_servers/static\n          mkdir -p $HOME/.cache/go-build\n          mkdir -p $HOME/go/bin\n      - name: Install uv\n        shell: bash\n        run: curl -LsSf https://astral.sh/uv/install.sh | sh\n      - name: Cache uv virtualenv\n        id: cache-uv\n        uses: actions/cache@v3\n        with:\n          path: .venv\n          key: uv-venv-${{ runner.os }}-${{ matrix.python-version }}-lock-${{ hashFiles('uv.lock') }}\n      - name: Create virtual environment\n        shell: bash\n        run: |\n          if [ ! -d \".venv\" ]; then\n            uv venv\n          fi\n      - name: Install Python environment\n        shell: bash\n        run: uv sync --extra dev --locked\n      - name: List Python dependencies\n        shell: bash\n        run: uv pip list\n      - name: Check formatting\n        shell: bash\n        run: uv run poe lint\n      # Add Go bin directory to PATH for this workflow\n      # GITHUB_PATH is a special file that GitHub Actions uses to modify PATH\n      # Writing to this file adds the directory to the PATH for subsequent steps\n      - name: Cache Go binaries\n        id: cache-go-binaries\n        uses: actions/cache@v3\n        with:\n          path: |\n            ~/go/bin\n            ~/.cache/go-build\n          key: go-binaries-${{ runner.os }}-gopls-latest\n      - name: Install gopls\n        if: steps.cache-go-binaries.outputs.cache-hit != 'true'\n        shell: bash\n        run: go install golang.org/x/tools/gopls@latest\n      - name: Set up Elixir\n        if: runner.os != 'Windows'\n        uses: erlef/setup-beam@v1\n        with:\n          elixir-version: \"1.19.3\"\n          otp-version: \"28\"\n#      Erlang currently not tested in CI, random hangings on macos, always hangs on ubuntu\n#      In local tests, erlang seems to work though\n#      - name: Install Erlang Language Server\n#        if: runner.os != 'Windows'\n#        shell: bash\n#        run: |\n#          # Install rebar3 if not already available\n#          which rebar3 || (curl -fsSL https://github.com/erlang/rebar3/releases/download/3.23.0/rebar3 -o /tmp/rebar3 && chmod +x /tmp/rebar3 && sudo mv /tmp/rebar3 /usr/local/bin/rebar3)\n#          # Clone and build erlang_ls\n#          git clone https://github.com/erlang-ls/erlang_ls.git /tmp/erlang_ls\n#          cd /tmp/erlang_ls\n#          make install PREFIX=/usr/local\n#          # Ensure erlang_ls is in PATH\n#          echo \"$HOME/.local/bin\" >> $GITHUB_PATH\n      - name: Install clojure tools\n        uses: DeLaGuardo/setup-clojure@13.4\n        with:\n          cli: latest\n      - name: Install ccls (C/C++ Language Server)\n        shell: bash\n        run: |\n          if [[ \"${{ runner.os }}\" == \"Linux\" ]]; then\n            sudo apt-get update\n            sudo apt-get install -y ccls\n          elif [[ \"${{ runner.os }}\" == \"macOS\" ]]; then\n            brew install ccls\n          elif [[ \"${{ runner.os }}\" == \"Windows\" ]]; then\n            choco install ccls -y\n          fi\n          # Verify installation\n          if command -v ccls &> /dev/null; then\n            echo \"ccls installed: $(ccls --version 2>&1 | head -1)\"\n          else\n            echo \"ERROR: ccls installation failed\"\n            exit 1\n          fi\n      - name: Setup Java (for JVM based languages)\n        uses: actions/setup-java@v4\n        with:\n          distribution: 'temurin'\n          java-version: '17'\n      - name: Setup .NET SDK (for F# and C# languages)\n        uses: actions/setup-dotnet@v4\n        with:\n          dotnet-version: '10.0.x'\n      - name: List .NET runtimes\n        shell: bash\n        run: dotnet --list-runtimes\n      - name: Install Terraform\n        uses: hashicorp/setup-terraform@v3\n        with:\n          terraform_version: \"1.5.0\"\n          terraform_wrapper: false\n      # - name: Install swift\n      #   if: runner.os != 'Windows'\n      #   uses: swift-actions/setup-swift@v2\n      # Installation of swift with the action screws with installation of ruby on macOS for some reason\n      # We can try again when version 3 of the action is released, where they will also use swiftly\n      # Until then, we use custom code to install swift. Sourcekit-lsp is installed automatically with swift\n      - name: Install Swift with swiftly (macOS)\n        if: runner.os == 'macOS'\n        run: |\n          echo \"=== Installing swiftly on macOS ===\"\n          curl -O https://download.swift.org/swiftly/darwin/swiftly.pkg && \\\n          installer -pkg swiftly.pkg -target CurrentUserHomeDirectory && \\\n          ~/.swiftly/bin/swiftly init --quiet-shell-followup && \\\n          . \"${SWIFTLY_HOME_DIR:-$HOME/.swiftly}/env.sh\" && \\\n          hash -r\n          swiftly install --use 6.1.2\n          swiftly use 6.1.2\n          echo \"~/.swiftly/bin\" >> $GITHUB_PATH\n          echo \"Swiftly installed successfully\"\n          # Verify sourcekit-lsp is working before proceeding\n          echo \"=== Verifying sourcekit-lsp installation ===\"\n          which sourcekit-lsp || echo \"Warning: sourcekit-lsp not found in PATH\"\n          sourcekit-lsp --help || echo \"Warning: sourcekit-lsp not responding\"\n      - name: Install Swift with swiftly (Ubuntu)\n        if: runner.os == 'Linux'\n        run: |\n          echo \"=== Installing swiftly on Ubuntu ===\"\n          # Install dependencies BEFORE Swift to avoid exit code 1\n          sudo apt-get update\n          sudo apt-get -y install libcurl4-openssl-dev\n          curl -O https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz && \\\n          tar zxf swiftly-$(uname -m).tar.gz && \\\n          ./swiftly init --quiet-shell-followup && \\\n          . \"${SWIFTLY_HOME_DIR:-$HOME/.local/share/swiftly}/env.sh\" && \\\n          hash -r\n          swiftly install --use 6.1.2\n          swiftly use 6.1.2\n          echo \"=== Adding Swift toolchain to PATH ===\"\n          echo \"$HOME/.local/share/swiftly/bin\" >> $GITHUB_PATH\n          echo \"Swiftly installed successfully!\"\n          # Verify sourcekit-lsp is working before proceeding\n          echo \"=== Verifying sourcekit-lsp installation ===\"\n          which sourcekit-lsp || echo \"Warning: sourcekit-lsp not found in PATH\"\n          sourcekit-lsp --help || echo \"Warning: sourcekit-lsp not responding\"\n      - name: Install Ruby\n        uses: ruby/setup-ruby@v1\n        with:\n          ruby-version: '3.4'\n      - name: Install Ruby language server\n        shell: bash\n        run: gem install ruby-lsp\n      - name: Install OCaml and opam\n        uses: ocaml/setup-ocaml@v3\n        with:\n          ocaml-compiler: ${{ runner.os == 'Windows' && '4.14' || '5.3.x' }}\n          dune-cache: true\n          opam-repositories: |\n            ${{ runner.os == 'Windows' && 'opam-repository-mingw: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset' || '' }}\n            default: https://github.com/ocaml/opam-repository.git\n      - name: Install OCaml packages\n        shell: bash\n        run: |\n          if [ \"$RUNNER_OS\" = \"Windows\" ]; then\n            opam install -y dune ocaml-lsp-server\n          else\n            # Require ocaml-lsp-server >= 1.23.0 for cross-file reference support\n            opam install -y dune 'ocaml-lsp-server>=1.23.0'\n          fi\n      - name: Install R\n        uses: r-lib/actions/setup-r@v2\n        with:\n          r-version: '4.4.2'\n          use-public-rspm: true\n      - name: Install R language server\n        shell: bash\n        run: |\n          Rscript -e \"install.packages('languageserver', repos='https://cloud.r-project.org')\"\n      - name: Set up Julia\n        uses: julia-actions/setup-julia@v2\n        with:\n          version: '1.10'\n      - name: Install Julia LanguageServer\n        shell: bash\n        run: julia -e 'using Pkg; Pkg.add(\"LanguageServer\")'\n      - name: Setup Haskell toolchain\n        if: runner.os != 'Windows'\n        uses: haskell/ghcup-setup@v1\n        with:\n          ghc: '9.12.2'\n          cabal: '3.10.3.0'\n          hls: '2.11.0.0'\n      - name: Verify Haskell tools\n        if: runner.os != 'Windows'\n        run: |\n          echo \"Verifying installed Haskell tools:\"\n          which ghc && ghc --version\n          which cabal && cabal --version\n          # HLS verification - non-blocking in case of version incompatibility\n          if command -v haskell-language-server-wrapper &>/dev/null; then\n            echo \"Found haskell-language-server-wrapper\"\n            haskell-language-server-wrapper --version || echo \"WARNING: HLS wrapper found but version check failed\"\n          elif command -v haskell-language-server &>/dev/null; then\n            echo \"Found haskell-language-server\"\n            haskell-language-server --version || echo \"WARNING: HLS found but version check failed\"\n          else\n            echo \"WARNING: HLS not found (may be incompatible with GHC 9.12.2)\"\n            echo \"This is not a critical error - tests will use HLS if available at runtime\"\n          fi\n        shell: bash\n      - name: Pre-build Haskell test project for HLS\n        if: runner.os != 'Windows'\n        run: |\n          cd test/resources/repos/haskell/test_repo\n          cabal update\n          cabal build --only-dependencies\n          cabal build\n          echo \"Haskell test project built successfully\"\n        shell: bash\n      - name: Install Zig\n        uses: goto-bus-stop/setup-zig@v2\n        with:\n          version: 0.14.1\n      - name: Install ZLS (Zig Language Server)\n        shell: bash\n        run: |\n          if [[ \"${{ runner.os }}\" == \"Linux\" ]]; then\n            wget https://github.com/zigtools/zls/releases/download/0.14.0/zls-x86_64-linux.tar.xz\n            tar -xf zls-x86_64-linux.tar.xz\n            sudo mv zls /usr/local/bin/\n            rm zls-x86_64-linux.tar.xz\n          elif [[ \"${{ runner.os }}\" == \"macOS\" ]]; then\n            wget https://github.com/zigtools/zls/releases/download/0.14.0/zls-x86_64-macos.tar.xz\n            tar -xf zls-x86_64-macos.tar.xz\n            sudo mv zls /usr/local/bin/\n            rm zls-x86_64-macos.tar.xz\n          elif [[ \"${{ runner.os }}\" == \"Windows\" ]]; then\n            curl -L -o zls.zip https://github.com/zigtools/zls/releases/download/0.14.0/zls-x86_64-windows.zip\n            unzip -o zls.zip\n            mkdir -p \"$HOME/bin\"\n            mv zls.exe \"$HOME/bin/\"\n            echo \"$HOME/bin\" >> $GITHUB_PATH\n            rm zls.zip\n          fi\n      - name: Install verible-verilog-ls (SystemVerilog Language Server)\n        shell: bash\n        run: |\n          VERIBLE_VERSION=\"v0.0-4051-g9fdb4057\"\n\n          if [[ \"${{ runner.os }}\" == \"Linux\" ]]; then\n            wget https://github.com/chipsalliance/verible/releases/download/${VERIBLE_VERSION}/verible-${VERIBLE_VERSION}-linux-static-x86_64.tar.gz\n            tar -xzf verible-${VERIBLE_VERSION}-linux-static-x86_64.tar.gz\n            sudo mv verible-${VERIBLE_VERSION}/bin/verible-verilog-ls /usr/local/bin/\n            rm -rf verible-${VERIBLE_VERSION} verible-${VERIBLE_VERSION}-linux-static-x86_64.tar.gz\n          elif [[ \"${{ runner.os }}\" == \"macOS\" ]]; then\n            wget https://github.com/chipsalliance/verible/releases/download/${VERIBLE_VERSION}/verible-${VERIBLE_VERSION}-macOS.tar.gz\n            tar -xzf verible-${VERIBLE_VERSION}-macOS.tar.gz\n            sudo mv verible-${VERIBLE_VERSION}-macOS/bin/verible-verilog-ls /usr/local/bin/\n            rm -rf verible-${VERIBLE_VERSION}-macOS verible-${VERIBLE_VERSION}-macOS.tar.gz\n          elif [[ \"${{ runner.os }}\" == \"Windows\" ]]; then\n            curl -L -o verible.zip https://github.com/chipsalliance/verible/releases/download/${VERIBLE_VERSION}/verible-${VERIBLE_VERSION}-win64.zip\n            unzip -o verible.zip\n            mkdir -p \"$HOME/bin\"\n            mv verible-${VERIBLE_VERSION}-win64/verible-verilog-ls.exe \"$HOME/bin/\"\n            echo \"$HOME/bin\" >> $GITHUB_PATH\n            rm -rf verible-${VERIBLE_VERSION}-win64 verible.zip\n          fi\n\n          # Verify installation\n          if command -v verible-verilog-ls &> /dev/null; then\n            echo \"verible-verilog-ls installed successfully\"\n          else\n            echo \"WARNING: verible-verilog-ls not found in PATH\"\n          fi\n      - name: Install Lua Language Server\n        shell: bash\n        run: |\n          LUA_LS_VERSION=\"3.15.0\"\n          LUA_LS_DIR=\"$HOME/.serena/language_servers/lua\"\n          mkdir -p \"$LUA_LS_DIR\"\n          \n          if [[ \"${{ runner.os }}\" == \"Linux\" ]]; then\n            if [[ \"$(uname -m)\" == \"x86_64\" ]]; then\n              wget https://github.com/LuaLS/lua-language-server/releases/download/${LUA_LS_VERSION}/lua-language-server-${LUA_LS_VERSION}-linux-x64.tar.gz\n              tar -xzf lua-language-server-${LUA_LS_VERSION}-linux-x64.tar.gz -C \"$LUA_LS_DIR\"\n            else\n              wget https://github.com/LuaLS/lua-language-server/releases/download/${LUA_LS_VERSION}/lua-language-server-${LUA_LS_VERSION}-linux-arm64.tar.gz\n              tar -xzf lua-language-server-${LUA_LS_VERSION}-linux-arm64.tar.gz -C \"$LUA_LS_DIR\"\n            fi\n            chmod +x \"$LUA_LS_DIR/bin/lua-language-server\"\n            # Create wrapper script instead of symlink to ensure supporting files are found\n            echo '#!/bin/bash' | sudo tee /usr/local/bin/lua-language-server > /dev/null\n            echo 'cd \"${HOME}/.serena/language_servers/lua/bin\"' | sudo tee -a /usr/local/bin/lua-language-server > /dev/null\n            echo 'exec ./lua-language-server \"$@\"' | sudo tee -a /usr/local/bin/lua-language-server > /dev/null\n            sudo chmod +x /usr/local/bin/lua-language-server\n            rm lua-language-server-*.tar.gz\n          elif [[ \"${{ runner.os }}\" == \"macOS\" ]]; then\n            if [[ \"$(uname -m)\" == \"x86_64\" ]]; then\n              wget https://github.com/LuaLS/lua-language-server/releases/download/${LUA_LS_VERSION}/lua-language-server-${LUA_LS_VERSION}-darwin-x64.tar.gz\n              tar -xzf lua-language-server-${LUA_LS_VERSION}-darwin-x64.tar.gz -C \"$LUA_LS_DIR\"\n            else\n              wget https://github.com/LuaLS/lua-language-server/releases/download/${LUA_LS_VERSION}/lua-language-server-${LUA_LS_VERSION}-darwin-arm64.tar.gz\n              tar -xzf lua-language-server-${LUA_LS_VERSION}-darwin-arm64.tar.gz -C \"$LUA_LS_DIR\"\n            fi\n            chmod +x \"$LUA_LS_DIR/bin/lua-language-server\"\n            # Create wrapper script instead of symlink to ensure supporting files are found\n            echo '#!/bin/bash' | sudo tee /usr/local/bin/lua-language-server > /dev/null\n            echo 'cd \"${HOME}/.serena/language_servers/lua/bin\"' | sudo tee -a /usr/local/bin/lua-language-server > /dev/null\n            echo 'exec ./lua-language-server \"$@\"' | sudo tee -a /usr/local/bin/lua-language-server > /dev/null\n            sudo chmod +x /usr/local/bin/lua-language-server\n            rm lua-language-server-*.tar.gz\n          elif [[ \"${{ runner.os }}\" == \"Windows\" ]]; then\n            curl -L -o lua-ls.zip https://github.com/LuaLS/lua-language-server/releases/download/${LUA_LS_VERSION}/lua-language-server-${LUA_LS_VERSION}-win32-x64.zip\n            unzip -o lua-ls.zip -d \"$LUA_LS_DIR\"\n            # For Windows, we'll add the bin directory directly to PATH\n            # The lua-language-server.exe can find its supporting files relative to its location\n            echo \"$LUA_LS_DIR/bin\" >> $GITHUB_PATH\n            rm lua-ls.zip\n          fi\n      - name: Install Perl::LanguageServer\n        if: runner.os != 'Windows'\n        shell: bash\n        run: |\n          if [[ \"${{ runner.os }}\" == \"Linux\" ]]; then\n            sudo apt-get update\n            sudo apt-get install -y cpanminus build-essential libanyevent-perl libio-aio-perl\n          elif [[ \"${{ runner.os }}\" == \"macOS\" ]]; then\n            brew install cpanminus\n          fi\n          PERL_MM_USE_DEFAULT=1 cpanm --notest --force Perl::LanguageServer\n          # Set up Perl local::lib environment for subsequent steps\n          echo \"PERL5LIB=$HOME/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}\" >> $GITHUB_ENV\n          echo \"PERL_LOCAL_LIB_ROOT=$HOME/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}\" >> $GITHUB_ENV\n          echo \"PERL_MB_OPT=--install_base \\\"$HOME/perl5\\\"\" >> $GITHUB_ENV\n          echo \"PERL_MM_OPT=INSTALL_BASE=$HOME/perl5\" >> $GITHUB_ENV\n          echo \"$HOME/perl5/bin\" >> $GITHUB_PATH\n      - name: Install ansible-core and ansible-lint (for Ansible language server tests)\n        shell: bash\n        run: uv run pip install ansible-core ansible-lint\n      - name: Install Elm\n        shell: bash\n        run: npm install -g elm@0.19.1-6\n      - name: Install Nix\n        if: runner.os != 'Windows'  # Nix doesn't support Windows natively\n        uses: cachix/install-nix-action@v30\n        with:\n          nix_path: nixpkgs=channel:nixos-unstable\n      - name: Install nixd (Nix Language Server)\n        if: runner.os != 'Windows'  # Skip on Windows since Nix isn't available\n        shell: bash\n        run: |\n          # Install nixd using nix\n          nix profile install github:nix-community/nixd\n\n          # Verify nixd is installed and working\n          if ! command -v nixd &> /dev/null; then\n            echo \"nixd installation failed or not in PATH\"\n            exit 1\n          fi\n\n          echo \"$HOME/.nix-profile/bin\" >> $GITHUB_PATH\n      - name: Verify Nix package build\n        if: runner.os != 'Windows'  # Nix only supported on Linux/macOS\n        shell: bash\n        run: |\n          # Verify the flake builds successfully\n          nix build --no-link\n      - name: Install Regal (Rego Language Server)\n        shell: bash\n        run: |\n          REGAL_VERSION=\"0.39.0\"\n\n          if [[ \"${{ runner.os }}\" == \"Linux\" ]]; then\n            if [[ \"$(uname -m)\" == \"x86_64\" ]]; then\n              curl -L -o regal https://github.com/StyraInc/regal/releases/download/v${REGAL_VERSION}/regal_Linux_x86_64\n            else\n              curl -L -o regal https://github.com/StyraInc/regal/releases/download/v${REGAL_VERSION}/regal_Linux_arm64\n            fi\n            chmod +x regal\n            sudo mv regal /usr/local/bin/\n          elif [[ \"${{ runner.os }}\" == \"macOS\" ]]; then\n            if [[ \"$(uname -m)\" == \"x86_64\" ]]; then\n              curl -L -o regal https://github.com/StyraInc/regal/releases/download/v${REGAL_VERSION}/regal_Darwin_x86_64\n            else\n              curl -L -o regal https://github.com/StyraInc/regal/releases/download/v${REGAL_VERSION}/regal_Darwin_arm64\n            fi\n            chmod +x regal\n            sudo mv regal /usr/local/bin/\n          elif [[ \"${{ runner.os }}\" == \"Windows\" ]]; then\n            curl -L -o regal.exe https://github.com/StyraInc/regal/releases/download/v${REGAL_VERSION}/regal_Windows_x86_64.exe\n            mkdir -p \"$HOME/bin\"\n            mv regal.exe \"$HOME/bin/\"\n            echo \"$HOME/bin\" >> $GITHUB_PATH\n          fi\n      - name: Install Free Pascal Compiler\n        shell: bash\n        run: |\n          if [[ \"${{ runner.os }}\" == \"Linux\" ]]; then\n            sudo apt-get update\n            sudo apt-get install -y fpc fpc-source\n            # Set environment variables for pasls\n            echo \"PP=/usr/bin/fpc\" >> $GITHUB_ENV\n            # Find FPC source directory (version may vary) - remove trailing slash\n            FPCDIR=$(ls -d /usr/share/fpcsrc/*/ 2>/dev/null | head -1 | sed 's:/$::')\n            if [[ -z \"$FPCDIR\" ]]; then\n              FPCDIR=\"/usr/share/fpcsrc\"\n            fi\n            echo \"FPCDIR=$FPCDIR\" >> $GITHUB_ENV\n            echo \"=== FPC source directory structure ===\"\n            ls -la \"$FPCDIR\" || echo \"FPCDIR not found\"\n            ls -la \"$FPCDIR/rtl\" 2>/dev/null || echo \"rtl subdirectory not found\"\n          elif [[ \"${{ runner.os }}\" == \"macOS\" ]]; then\n            brew install fpc\n            # Download FPC source from SourceForge (fpc-src-laz cask is incompatible with ARM64)\n            FPC_VERSION=\"3.2.2\"\n            curl -L -o fpc-source.tar.gz \"https://sourceforge.net/projects/freepascal/files/Source/${FPC_VERSION}/fpc-${FPC_VERSION}.source.tar.gz/download\"\n            mkdir -p \"$HOME/fpcsrc\"\n            tar -xzf fpc-source.tar.gz -C \"$HOME/fpcsrc\"\n            rm fpc-source.tar.gz\n            # Check extracted directory structure (might be nested)\n            echo \"=== Extracted FPC source structure ===\"\n            ls -la \"$HOME/fpcsrc\"\n            # Find the actual FPC source root (contains rtl, packages, etc.)\n            if [[ -d \"$HOME/fpcsrc/fpc-${FPC_VERSION}/rtl\" ]]; then\n              FPCDIR=\"$HOME/fpcsrc/fpc-${FPC_VERSION}\"\n            elif [[ -d \"$HOME/fpcsrc/fpc-${FPC_VERSION}/fpc-${FPC_VERSION}/rtl\" ]]; then\n              FPCDIR=\"$HOME/fpcsrc/fpc-${FPC_VERSION}/fpc-${FPC_VERSION}\"\n            else\n              FPCDIR=\"$HOME/fpcsrc/fpc-${FPC_VERSION}\"\n            fi\n            echo \"PP=$(which fpc)\" >> $GITHUB_ENV\n            echo \"FPCDIR=$FPCDIR\" >> $GITHUB_ENV\n            echo \"=== FPC source directory ===\"\n            ls -la \"$FPCDIR\" || echo \"FPCDIR not found\"\n          elif [[ \"${{ runner.os }}\" == \"Windows\" ]]; then\n            FPC_VERSION=\"3.2.2\"\n            # Download freepascal-ootb (includes FPC compiler)\n            curl -L -o fpc-ootb.zip https://github.com/fredvs/freepascal-ootb/releases/download/${FPC_VERSION}/fpc-ootb-322-x86_64-win64.zip\n            mkdir -p \"$HOME/fpc\"\n            unzip -q fpc-ootb.zip -d \"$HOME/fpc\"\n            rm fpc-ootb.zip\n            # Download FPC source from SourceForge (fpc-ootb only has compiled units, not source)\n            curl -L -o fpc-source.zip \"https://sourceforge.net/projects/freepascal/files/Source/${FPC_VERSION}/fpc-${FPC_VERSION}.source.zip/download\"\n            mkdir -p \"$HOME/fpcsrc\"\n            unzip -q fpc-source.zip -d \"$HOME/fpcsrc\"\n            rm fpc-source.zip\n            # Find fpc executable (fpc-ootb uses fpc-ootb.exe as the compiler)\n            echo \"=== FPC directory structure ===\"\n            find \"$HOME/fpc\" -name \"*.exe\" -type f 2>/dev/null | head -10\n            FPC_EXE=$(find \"$HOME/fpc\" -name \"fpc-ootb-64.exe\" -type f 2>/dev/null | head -1)\n            echo \"Found FPC executable: $FPC_EXE\"\n            echo \"Found FPC source dir: $HOME/fpcsrc/fpc-${FPC_VERSION}\"\n            # Set environment variables for pasls\n            echo \"PP=$FPC_EXE\" >> $GITHUB_ENV\n            echo \"FPCDIR=$HOME/fpcsrc/fpc-${FPC_VERSION}\" >> $GITHUB_ENV\n            # Add FPC bin directory to PATH\n            FPC_BIN_DIR=$(dirname \"$FPC_EXE\")\n            echo \"$FPC_BIN_DIR\" >> $GITHUB_PATH\n          fi\n      - name: Verify FPC installation\n        shell: bash\n        run: |\n          echo \"=== Environment variables ===\"\n          echo \"PP=$PP\"\n          echo \"FPCDIR=$FPCDIR\"\n\n          # Create a simple test program\n          if [[ \"${{ runner.os }}\" == \"Windows\" ]]; then\n            TEST_PAS=\"$TEMP/fpc_test.pas\"\n            TEST_OUT=\"$TEMP/fpc_test\"\n          else\n            TEST_PAS=\"/tmp/fpc_test.pas\"\n            TEST_OUT=\"/tmp/fpc_test\"\n          fi\n          echo \"program fpc_test; begin writeln('FPC works'); end.\" > \"$TEST_PAS\"\n\n          # Compile using PP (the compiler we actually use in tests)\n          echo \"=== Compiling test program with PP=$PP ===\"\n          if [[ -n \"$PP\" ]]; then\n            \"$PP\" \"$TEST_PAS\" -o\"$TEST_OUT\" 2>&1\n          else\n            echo \"ERROR: PP environment variable is not set\"\n            exit 1\n          fi\n\n          # Verify output binary exists\n          if [[ -f \"$TEST_OUT\" ]] || [[ -f \"${TEST_OUT}.exe\" ]]; then\n            echo \"FPC compilation test PASSED\"\n          else\n            echo \"ERROR: FPC compilation failed - no output binary at $TEST_OUT\"\n            exit 1\n          fi\n\n          # Verify FPCDIR exists (required for pasls)\n          if [[ -d \"$FPCDIR\" ]]; then\n            echo \"FPCDIR exists: $FPCDIR\"\n          else\n            echo \"ERROR: FPCDIR does not exist: $FPCDIR\"\n            exit 1\n          fi\n      - name: Build Lean 4 test project\n        uses: leanprover/lean-action@v1\n        with:\n          lake-package-directory: test/resources/repos/lean4/test_repo\n      - name: Cache language servers\n        id: cache-language-servers\n        uses: actions/cache@v3\n        with:\n          path: ~/.serena/language_servers/static\n          key: language-servers-${{ runner.os }}-v1\n          restore-keys: |\n            language-servers-${{ runner.os }}-\n      - name: Report free disk space\n        if: runner.os == 'Linux'\n        run: |\n          echo \"Free disk space before tests:\"\n          df -h\n      - name: Test with pytest\n        shell: bash\n        run: uv run poe test\n      - name: Type-checking with mypy\n        shell: bash\n        run: uv run poe type-check\n"
  },
  {
    "path": ".gitignore",
    "content": "# macOS specific files\n.DS_Store\n.AppleDouble\n.LSOverride\n._*\n.Spotlight-V100\n.Trashes\nIcon\n.fseventsd\n.DocumentRevisions-V100\n.TemporaryItems\n.VolumeIcon.icns\n.com.apple.timemachine.donotpresent\n\n# Windows specific files\nThumbs.db\nThumbs.db:encryptable\nehthumbs.db\nehthumbs_vista.db\n*.stackdump\n[Dd]esktop.ini\n$RECYCLE.BIN/\n*.cab\n*.msi\n*.msix\n*.msm\n*.msp\n*.lnk\n\n# Linux specific files\n*~\n.fuse_hidden*\n.directory\n.Trash-*\n.nfs*\n\n# IDE/Text Editors\n# VS Code\n.vscode/*\n!.vscode/settings.json\n!.vscode/tasks.json\n!.vscode/launch.json\n!.vscode/extensions.json\n*.code-workspace\n.history/\n\n# JetBrains IDEs (beyond .idea/)\n*.iml\n*.ipr\n*.iws\nout/\n.idea_modules/\n\n# Sublime Text\n*.tmlanguage.cache\n*.tmPreferences.cache\n*.stTheme.cache\n*.sublime-workspace\n*.sublime-project\n\n# Project specific ignore\n.idea\ntemp\n\n# Byte-compiled / optimized / DLL files\n__pycache__/\n*.py[cod]\n*$py.class\n\n# C extensions\n*.so\n\n# Distribution / packaging\n.Python\nbuild/\ndevelop-eggs/\ndist/\ndownloads/\neggs/\n.eggs/\nlib/\nlib64/\nparts/\nsdist/\nvar/\nwheels/\npip-wheel-metadata/\nshare/python-wheels/\n*.egg-info/\n.installed.cfg\n*.egg\nMANIFEST\n\n# PyInstaller\n#  Usually these files are written by a python script from a template\n#  before PyInstaller builds the exe, so as to inject date/other infos into it.\n*.manifest\n*.spec\n\n# Installer logs\npip-log.txt\npip-delete-this-directory.txt\n\n# Unit test / coverage reports\nhtmlcov/\n.tox/\n.nox/\n.coverage\n.coverage.*\n.cache\nnosetests.xml\ncoverage.xml\n*.cover\n*.py,cover\n.hypothesis/\n.pytest_cache/\n\n# Translations\n*.mo\n*.pot\n\n# Django stuff:\n*.log\nlocal_settings.py\ndb.sqlite3\ndb.sqlite3-journal\n\n# Flask stuff:\ninstance/\n.webassets-cache\n\n# Scrapy stuff:\n.scrapy\n\n# Sphinx documentation\ndocs/_build/\n\n# PyBuilder\ntarget/\n\n# Jupyter Notebook\n.ipynb_checkpoints\n\n# IPython\nprofile_default/\nipython_config.py\n\n# pyenv\n.python-version\n\n# pipenv\n#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.\n#   However, in case of collaboration, if having platform-specific dependencies or dependencies\n#   having no cross-platform support, pipenv may install dependencies that don't work, or not\n#   install all needed dependencies.\n#Pipfile.lock\n\n# PEP 582; used by e.g. github.com/David-OConnor/pyflow\n__pypackages__/\n\n# Celery stuff\ncelerybeat-schedule\ncelerybeat.pid\n\n# SageMath parsed files\n*.sage.py\n\n# Environments\n.env\n.venv\nenv/\nvenv/\nENV/\nenv.bak/\nvenv.bak/\n\n# Spyder project settings\n.spyderproject\n.spyproject\n\n# Rope project settings\n.ropeproject\n\n# mkdocs documentation\n/site\n\n# mypy\n.mypy_cache/\n.dmypy.json\ndmypy.json\n\n# Pyre type checker\n.pyre/\n\n# reports\npylint.html\n.pylint.d\n\n# Serena-specific\n/*.yml\n!*.template.yml\n/agent-ui\n/test/**/.serena\n\n# clojure-lsp temporary files\n.calva/\n.clj-kondo/\n.cpcache/\n.lsp/\n\n# temporary and backup files\n*.bak\n*.tmp\ntmp/\n\n.vscode/\n\n# Claude settings\n.claude/settings.local.json\n\n# Elixir\n/test/resources/repos/elixir/test_repo/deps\n# Exception: Don't ignore Elixir test repository lib directory (contains source code)\n!/test/resources/repos/elixir/test_repo/lib\n\n# Exception: Don't ignore Nix test repository lib directory (contains source code)\n!/test/resources/repos/nix/test_repo/lib\n\n# Exception: Don't ignore OCaml test repository lib directory (contains source code)\n!/test/resources/repos/ocaml/test_repo/lib\n\n# Exception: Don't ignore Julia test repository lib directory (contains source code)\n!/test/resources/repos/julia/test_repo/lib\n\n# Exception: Don't ignore Solidity test repository lib directory (contains source code)\n!/test/resources/repos/solidity/test_repo/contracts/lib\n\n# Swift\n/test/resources/repos/swift/test_repo/.build\n/test/resources/repos/swift/test_repo/.swiftpm\n\n# OCaml\n/test/resources/repos/ocaml/test_repo/_build\n\n# Elm\n/test/resources/repos/elm/test_repo/.elm/\n/test/resources/repos/elm/test_repo/elm-stuff/\n\n# Scala\n.metals/\n.bsp/\n.scala-build/\n.bloop/\nbootstrap\ntest/resources/repos/scala/.bloop/\n\n# Haskell\n.stack-work/\n*.cabal\nstack.yaml.lock\ndist-newstyle/\ncabal.project.local*\n.ghc.environment.*\n\n# Lean 4\n.lake/\n\nzz-misc/\nvue-implementation/\n"
  },
  {
    "path": ".serena/.gitignore",
    "content": "/cache\n/project.local.yml\n"
  },
  {
    "path": ".serena/memories/adding_new_language_support_guide.md",
    "content": "# Adding New Language Support to Serena\n\nThis guide explains how to add support for a new programming language to Serena.\n\n## Overview\n\nAdding a new language involves:\n\n1. **Language Server Implementation** - Creating a language-specific server class\n2. **Language Registration** - Adding the language to enums and configurations  \n3. **Test Repository** - Creating a minimal test project\n4. **Test Suite** - Writing comprehensive tests\n\n## Step 1: Language Server Implementation\n\n### 1.1 Create Language Server Class\n\nCreate a new file in `src/solidlsp/language_servers/` (e.g., `new_language_server.py`).\n\n#### Providing the Launch Command via a DependencyProvider\n\nAll language servers use the `DependencyProvider` pattern to handle \n  * runtime dependency installation/discovery\n  * launch command creation (and, optionally, environment setup)\n\nTo implement a new language server using the DependencyProvider pattern:\n  * Pass `None` for `process_launch_info` in `super().__init__()` - the base class creates it via `_create_dependency_provider()`\n  * Implement `_create_dependency_provider()` to return an inner `DependencyProvider` class instance.\n    In simple cases, it can be instantiated with only two parameters: \n    ```python\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n         return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n    ```\n    The resource dir that is passed is the directory in which installed dependencies should be stored!\n\n**Base Classes:**\n\n- **`LanguageServerDependencyProviderSinglePath`** - For language servers with a single core dependency (e.g., an executable or JAR file)\n  - Provides automatic support for the `ls_path` custom setting, allowing users to override the core dependency path (if they have it installed it themselves)\n  - Implement `_get_or_install_core_dependency()` to return the path to the core dependency, downloading/installing it automatically if necessary\n  - Implement `_create_launch_command(core_path)` to build the full command from the core path\n  - Reference implementations: `TypeScriptLanguageServer`, `Intelephense`, `ClojureLSP`, `ClangdLanguageServer`, `PyrightServer`\n\n- **`LanguageServerDependencyProvider`** - The base class, which can be directly inherited from for complex cases with multiple dependencies or custom setup\n  - Implement `create_launch_command()` directly\n  - Reference implementations: `EclipseJDTLS`, `CSharpLanguageServer`, `MatlabLanguageServer`\n\n**Implementation Pointers::**\n  - When returning the command, prefer the list-based representation for robustness\n  - Override `create_launch_command_env` if the launch command needs environment variables to be set (defaults to `{}` in the base implementation)\n\nYou should look at at least one existing implementation of each base class to understand how they work.\n\n### 1.2 LSP Initialization\n\nOverride initialization methods if needed:\n\n```python\ndef _get_initialize_params(self) -> InitializeParams:\n    \"\"\"Return language-specific initialization parameters.\"\"\"\n    return {\n        \"processId\": os.getpid(),\n        \"rootUri\": PathUtils.path_to_uri(self.repository_root_path),\n        \"capabilities\": {\n            # Language-specific capabilities\n        }\n    }\n\ndef _start_server(self):\n    \"\"\"Start the language server with custom handlers.\"\"\"\n    # Set up notification handlers\n    self.server.on_notification(\"window/logMessage\", self._handle_log_message)\n    \n    # Start server and initialize\n    self.server.start()\n    init_response = self.server.send.initialize(self._get_initialize_params())\n    \n    self.server.notify.initialized({})\n```\n\nAfter `_start_server` returns, the language server should be fully operational.\nIf the server requires that one waits for certain notifications or responses before being ready, implement that logic here.\nFor an example, see `EclipseJDTLS._start_server`.\n\n## Step 2: Language Registration\n\n### 2.1 Add to Language Enum\n\nIn `src/solidlsp/ls_config.py`, add your language to the `Language` enum:\n\n```python\nclass Language(str, Enum):\n    # Existing languages...\n    NEW_LANGUAGE = \"new_language\"\n    \n    def get_source_fn_matcher(self) -> FilenameMatcher:\n        match self:\n            # Existing cases...\n            case self.NEW_LANGUAGE:\n                return FilenameMatcher(\"*.newlang\", \"*.nl\")  # File extensions\n```\n\n### 2.2 Update Language Server Factory\n\nIn `src/solidlsp/ls.py`, add your language to the `create` method:\n\n```python\n@classmethod\ndef create(cls, config: LanguageServerConfig, repository_root_path: str) -> \"SolidLanguageServer\":\n    match config.code_language:\n        # Existing cases...\n        case Language.NEW_LANGUAGE:\n            from solidlsp.language_servers.new_language_server import NewLanguageServer\n            return NewLanguageServer(config, repository_root_path)\n```\n\n## Step 3: Test Repository\n\n### 3.1 Create Test Project\n\nCreate a minimal project in `test/resources/repos/new_language/test_repo/`:\n\n```\ntest/resources/repos/new_language/test_repo/\n├── main.newlang              # Main source file\n├── lib/\n│   └── helper.newlang       # Additional source for testing\n├── project.toml             # Project configuration (if applicable)\n└── .gitignore              # Ignore build artifacts\n```\n\n### 3.2 Example Source Files\n\nCreate meaningful source files that demonstrate:\n\n- **Classes/Types** - For symbol testing\n- **Functions/Methods** - For reference finding\n- **Imports/Dependencies** - For cross-file operations\n- **Nested Structures** - For hierarchical symbol testing\n\nExample `main.newlang`:\n```\nimport lib.helper\n\nclass Calculator {\n    func add(a: Int, b: Int) -> Int {\n        return a + b\n    }\n    \n    func subtract(a: Int, b: Int) -> Int {\n        return helper.subtract(a, b)  // Reference to imported function\n    }\n}\n\nclass Program {\n    func main() {\n        let calc = Calculator()\n        let result = calc.add(5, 3)  // Reference to add method\n        print(result)\n    }\n}\n```\n\n## Step 4: Test Suite\n\nTesting the language server implementation is of crucial importance, and the tests will\nform the main part of the review process. Make sure that the tests are up to the standard\nof Serena to make the review go smoother.\n\nGeneral rules for tests:\n\n1. Tests for symbols and references should always check that the expected symbol names and references were actually found.\n   Just testing that a list came back or that the result is not None is insufficient.\n2. Tests should never be skipped, the only exception is skipping based on some package being available or on an unsupported OS.\n3. Tests should run in CI, check if there is a suitable GitHub action for installing the dependencies.\n\n### 4.1 Basic Tests\n\nCreate `test/solidlsp/new_language/test_new_language_basic.py`.\nHave a look at the structure of existing tests, for example, in `test/solidlsp/php/test_php_basic.py`\nYou should at least test:\n\n1. Finding symbols\n2. Finding within-file references\n3. Finding cross-file references\n\nHave a look at `test/solidlsp/php/test_php_basic.py` as an example for what should be tested.\nDon't forget to add a new language marker to `pytest.ini`.\n\n### 4.2 Integration Tests\n\nConsider adding new cases to the parametrized tests in `test_serena_agent.py` for the new language.\n\n\n### 5 Documentation\n\nUpdate:\n\n- **README.md** - Add language to the list of languages\n- **docs/01-about/020_programming-languages.md** - Add language to the list and mention any special notes, compatibility or requirements (e.g. installations the user is required to do)\n- **CHANGELOG.md** - Document the new language support\n"
  },
  {
    "path": ".serena/memories/serena_core_concepts_and_architecture.md",
    "content": "# Serena Core Concepts and Architecture\n\n## High-Level Architecture\n\nSerena is built around a dual-layer architecture:\n\n1. **SerenaAgent** - The main orchestrator that manages projects, tools, and user interactions\n2. **SolidLanguageServer** - A unified wrapper around Language Server Protocol (LSP) implementations\n\n## Core Components\n\n### 1. SerenaAgent (`src/serena/agent.py`)\n\nThe central coordinator that:\n- Manages active projects and their configurations\n- Coordinates between different tools and contexts\n- Handles language server lifecycle\n- Manages memory persistence\n- Provides MCP (Model Context Protocol) server interface\n\nKey responsibilities:\n- **Project Management** - Activating, switching between projects\n- **Tool Registry** - Loading and managing available tools based on context/mode\n- **Language Server Integration** - Starting/stopping language servers per project\n- **Memory Management** - Persistent storage of project knowledge\n- **Task Execution** - Coordinating complex multi-step operations\n\n### 2. SolidLanguageServer (`src/solidlsp/ls.py`)\n\nA unified abstraction over multiple language servers that provides:\n- **Language-agnostic interface** for symbol operations\n- **Caching layer** for performance optimization\n- **Error handling and recovery** for unreliable language servers\n- **Uniform API** regardless of underlying LSP implementation\n\nCore capabilities:\n- Symbol discovery and navigation\n- Code completion and hover information\n- Find references and definitions\n- Document and workspace symbol search\n- File watching and change notifications\n\n### 3. Tool System (`src/serena/tools/`)\n\nModular tool architecture with several categories:\n\n#### File Tools (`file_tools.py`)\n- File system operations (read, write, list directories)\n- Text search and pattern matching\n- Regex-based replacements\n\n#### Symbol Tools (`symbol_tools.py`)  \n- Language-aware symbol finding and navigation\n- Symbol body replacement and insertion\n- Reference finding across codebase\n\n#### Memory Tools (`memory_tools.py`)\n- Project knowledge persistence\n- Memory retrieval and management\n- Onboarding information storage\n\n#### Configuration Tools (`config_tools.py`)\n- Project activation and switching\n- Mode and context management\n- Tool inclusion/exclusion\n\n### 4. Configuration System (`src/serena/config/`)\n\nMulti-layered configuration supporting:\n- **Contexts** - Define available tools and their behavior\n- **Modes** - Specify operational patterns (interactive, editing, etc.)\n- **Projects** - Per-project settings and language server configs\n- **Tool Sets** - Grouped tool collections for different use cases\n\n## Language Server Integration\n\n### Language Support Model\n\nEach supported language has:\n1. **Language Server Implementation** (`src/solidlsp/language_servers/`)\n2. **Runtime Dependencies** - Managed downloads of language servers\n3. **Test Repository** (`test/resources/repos/<language>/`)\n4. **Test Suite** (`test/solidlsp/<language>/`)\n\n### Language Server Lifecycle\n\n1. **Discovery** - Find language servers or download them automatically\n2. **Initialization** - Start server process and perform LSP handshake\n3. **Project Setup** - Open workspace and configure language-specific settings\n4. **Operation** - Handle requests/responses with caching and error recovery\n5. **Shutdown** - Clean shutdown of server processes\n\n### Supported Languages\n\nCurrent language support includes:\n- **C#** - Microsoft.CodeAnalysis.LanguageServer (.NET 9)\n- **Python** - Pyright or Jedi\n- **TypeScript/JavaScript** - TypeScript Language Server\n- **Rust** - rust-analyzer\n- **Go** - gopls\n- **Java** - Eclipse JDT Language Server\n- **Kotlin** - Kotlin Language Server\n- **PHP** - Intelephense\n- **Ruby** - Solargraph\n- **Clojure** - clojure-lsp\n- **Elixir** - ElixirLS\n- **Dart** - Dart Language Server\n- **C/C++** - clangd\n- **Terraform** - terraform-ls\n\n## Memory and Knowledge Management\n\n### Memory System\n- **Markdown-based storage** in `.serena/memories/` directory\n- **Contextual retrieval** - memories loaded based on relevance\n- **Project-specific** knowledge persistence\n- **Onboarding support** - guided setup for new projects\n\n### Knowledge Categories\n- **Project Structure** - Directory layouts, build systems\n- **Architecture Patterns** - How the codebase is organized\n- **Development Workflows** - Testing, building, deployment\n- **Domain Knowledge** - Business logic and requirements\n\n## MCP Server Interface\n\nSerena exposes its functionality through Model Context Protocol:\n- **Tool Discovery** - AI agents can enumerate available tools\n- **Context-Aware Operations** - Tools behave based on active project/mode\n- **Stateful Sessions** - Maintains project state across interactions\n- **Error Handling** - Graceful degradation when tools fail\n\n## Error Handling and Resilience\n\n### Language Server Reliability\n- **Timeout Management** - Configurable timeouts for LSP requests\n- **Process Recovery** - Automatic restart of crashed language servers\n- **Fallback Behavior** - Graceful degradation when LSP unavailable\n- **Caching Strategy** - Reduces impact of server failures\n\n### Project Activation Safety\n- **Validation** - Verify project structure before activation\n- **Error Isolation** - Project failures don't affect other projects\n- **Recovery Mechanisms** - Automatic cleanup and retry logic\n\n## Performance Considerations\n\n### Caching Strategy\n- **Symbol Cache** - In-memory caching of expensive symbol operations\n- **File System Cache** - Reduced disk I/O for repeated operations\n- **Language Server Cache** - Persistent cache across sessions\n\n### Resource Management\n- **Language Server Pooling** - Reuse servers across projects when possible\n- **Memory Management** - Automatic cleanup of unused resources\n- **Background Operations** - Async operations don't block user interactions\n\n## Extension Points\n\n### Adding New Languages\n1. Implement language server class in `src/solidlsp/language_servers/`\n2. Add runtime dependencies configuration\n3. Create test repository and test suite\n4. Update language enumeration and configuration\n\n### Adding New Tools\n1. Inherit from `Tool` base class in `tools_base.py`\n2. Implement required methods and parameter validation\n3. Register tool in appropriate tool registry\n4. Add to context/mode configurations as needed\n\n### Custom Contexts and Modes\n- Define new contexts in YAML configuration files\n- Specify tool sets and operational patterns\n- Configure for specific development workflows"
  },
  {
    "path": ".serena/memories/serena_repository_structure.md",
    "content": "# Serena Repository Structure\n\n## Overview\nSerena is a multi-language code assistant that combines two main components:\n1. **Serena Core** - The main agent framework with tools and MCP server\n2. **SolidLSP** - A unified Language Server Protocol wrapper for multiple programming languages\n\n## Top-Level Structure\n\n```\nserena/\n├── src/                          # Main source code\n│   ├── serena/                   # Serena agent framework\n│   ├── solidlsp/                 # LSP wrapper library  \n│   └── interprompt/              # Multi-language prompt templates\n├── test/                         # Test suites\n│   ├── serena/                   # Serena agent tests\n│   ├── solidlsp/                 # Language server tests\n│   └── resources/repos/          # Test repositories for each language\n├── scripts/                      # Build and utility scripts\n├── resources/                    # Static resources and configurations\n├── pyproject.toml               # Python project configuration\n├── README.md                    # Project documentation\n└── CHANGELOG.md                 # Version history\n```\n\n## Source Code Organization\n\n### Serena Core (`src/serena/`)\n- **`agent.py`** - Main SerenaAgent class that orchestrates everything\n- **`tools/`** - MCP tools for file operations, symbols, memory, etc.\n  - `file_tools.py` - File system operations (read, write, search)\n  - `symbol_tools.py` - Symbol-based code operations (find, edit)\n  - `memory_tools.py` - Knowledge persistence and retrieval\n  - `config_tools.py` - Project and mode management\n  - `workflow_tools.py` - Onboarding and meta-operations\n- **`config/`** - Configuration management\n  - `serena_config.py` - Main configuration classes\n  - `context_mode.py` - Context and mode definitions\n- **`util/`** - Utility modules\n- **`mcp.py`** - MCP server implementation\n- **`cli.py`** - Command-line interface\n\n### SolidLSP (`src/solidlsp/`)\n- **`ls.py`** - Main SolidLanguageServer class\n- **`language_servers/`** - Language-specific implementations\n  - `csharp_language_server.py` - C# (Microsoft.CodeAnalysis.LanguageServer)\n  - `python_server.py` - Python (Pyright)\n  - `typescript_language_server.py` - TypeScript\n  - `rust_analyzer.py` - Rust\n  - `gopls.py` - Go\n  - And many more...\n- **`ls_config.py`** - Language server configuration\n- **`ls_types.py`** - LSP type definitions\n- **`ls_utils.py`** - Utilities for working with LSP data\n\n### Interprompt (`src/interprompt/`)\n- Multi-language prompt template system\n- Jinja2-based templating with language fallbacks\n\n## Test Structure\n\n### Language Server Tests (`test/solidlsp/`)\nEach language has its own test directory:\n```\ntest/solidlsp/\n├── csharp/\n│   └── test_csharp_basic.py\n├── python/\n│   └── test_python_basic.py\n├── typescript/\n│   └── test_typescript_basic.py\n└── ...\n```\n\n### Test Resources (`test/resources/repos/`)\nContains minimal test projects for each language:\n```\ntest/resources/repos/\n├── csharp/test_repo/\n│   ├── serena.sln\n│   ├── TestProject.csproj\n│   ├── Program.cs\n│   └── Models/Person.cs\n├── python/test_repo/\n├── typescript/test_repo/\n└── ...\n```\n\n### Test Infrastructure\n- **`test/conftest.py`** - Shared test fixtures and utilities\n- **`create_ls()`** function - Creates language server instances for testing\n- **`language_server` fixture** - Parametrized fixture for multi-language tests\n\n## Key Configuration Files\n\n- **`pyproject.toml`** - Python dependencies, build config, and tool settings\n- **`.serena/`** directories - Project-specific Serena configuration and memories\n- **`CLAUDE.md`** - Instructions for AI assistants working on the project\n\n## Dependencies Management\n\nThe project uses modern Python tooling:\n- **uv** for fast dependency resolution and virtual environments\n- **pytest** for testing with language-specific markers (`@pytest.mark.csharp`)\n- **ruff** for linting and formatting\n- **mypy** for type checking\n\n## Build and Development\n\n- **Docker support** - Full containerized development environment\n- **GitHub Actions** - CI/CD with language server testing\n- **Development scripts** in `scripts/` directory"
  },
  {
    "path": ".serena/memories/suggested_commands.md",
    "content": "# Suggested Commands\n\n## Development Tasks (using uv and poe)\n\nThe following tasks should generally be executed using `uv run poe <task_name>`.\n\n- `format`: This is the **only** allowed command for formatting. Run as `uv run poe format`.\n- `type-check`: This is the **only** allowed command for type checking. Run as `uv run poe type-check`.\n- `test`: This is the preferred command for running tests (`uv run poe test [args]`). You can select subsets of tests with markers,\n   the current markers are\n   ```toml\n    markers = [\n        \"python: language server running for Python\",\n        \"go: language server running for Go\",\n        \"java: language server running for Java\",\n        \"rust: language server running for Rust\",\n        \"typescript: language server running for TypeScript\",\n        \"php: language server running for PHP\",\n        \"snapshot: snapshot tests for symbolic editing operations\",\n    ]\n   ```\n  By default, `uv run poe test` uses the markers set in the env var `PYTEST_MARKERS`, or, if it unset, uses `-m \"not java and not rust and not isolated process\"`.\n  You can override this behavior by simply passing the `-m` option to `uv run poe test`, e.g. `uv run poe test -m \"python or go\"`.\n\nFor finishing a task, make sure format, type-check and test pass! Run them at the end of the task\nand if needed fix any issues that come up and run them again until they pass."
  },
  {
    "path": ".serena/project.yml",
    "content": "# the name by which the project can be referenced within Serena\nproject_name: \"serena\"\n\n\n# list of languages for which language servers are started; choose from:\n#   al                  bash                clojure             cpp                 csharp\n#   csharp_omnisharp    dart                elixir              elm                 erlang\n#   fortran             fsharp              go                  groovy              haskell\n#   java                julia               kotlin              lua                 markdown\n#   matlab              nix                 pascal              perl                php\n#   powershell          python              python_jedi         r                   rego\n#   ruby                ruby_solargraph     rust                scala               swift\n#   terraform           toml                typescript          typescript_vts      vue\n#   yaml                zig\n#   (This list may be outdated. For the current list, see values of Language enum here:\n#   https://github.com/oraios/serena/blob/main/src/solidlsp/ls_config.py\n#   For some languages, there are alternative language servers, e.g. csharp_omnisharp, ruby_solargraph.)\n# Note:\n#   - For C, use cpp\n#   - For JavaScript, use typescript\n#   - For Free Pascal/Lazarus, use pascal\n# Special requirements:\n#   - csharp: Requires the presence of a .sln file in the project folder.\n#   - pascal: Requires Free Pascal Compiler (fpc) and optionally Lazarus.\n# When using multiple languages, the first language server that supports a given file will be used for that file.\n# The first language is the default language and the respective language server will be used as a fallback.\n# Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.\nlanguages:\n- python\n- typescript\n\n# whether to use project's .gitignore files to ignore files\nignore_all_files_in_gitignore: true\n\n\n# list of additional paths to ignore in all projects\n# same syntax as gitignore, so you can use * and **\nignored_paths: []\n\n# whether the project is in read-only mode\n# If set to true, all editing tools will be disabled and attempts to use them will result in an error\nread_only: false\n\n\n# list of tool names to exclude. We recommend not excluding any tools, see the readme for more details.\n# Below is the complete list of tools for convenience.\n# To make sure you have the latest list of tools, and to view their descriptions, \n# execute `uv run scripts/print_tool_overview.py`.\n#\n#  * `activate_project`: Activates a project by name.\n#  * `check_onboarding_performed`: Checks whether project onboarding was already performed.\n#  * `create_text_file`: Creates/overwrites a file in the project directory.\n#  * `delete_lines`: Deletes a range of lines within a file.\n#  * `delete_memory`: Deletes a memory from Serena's project-specific memory store.\n#  * `execute_shell_command`: Executes a shell command.\n#  * `find_referencing_code_snippets`: Finds code snippets in which the symbol at the given location is referenced.\n#  * `find_referencing_symbols`: Finds symbols that reference the symbol at the given location (optionally filtered by type).\n#  * `find_symbol`: Performs a global (or local) search for symbols with/containing a given name/substring (optionally filtered by type).\n#  * `get_current_config`: Prints the current configuration of the agent, including the active and available projects, tools, contexts, and modes.\n#  * `get_symbols_overview`: Gets an overview of the top-level symbols defined in a given file.\n#  * `initial_instructions`: Gets the initial instructions for the current project.\n#     Should only be used in settings where the system prompt cannot be set,\n#     e.g. in clients you have no control over, like Claude Desktop.\n#  * `insert_after_symbol`: Inserts content after the end of the definition of a given symbol.\n#  * `insert_at_line`: Inserts content at a given line in a file.\n#  * `insert_before_symbol`: Inserts content before the beginning of the definition of a given symbol.\n#  * `list_dir`: Lists files and directories in the given directory (optionally with recursion).\n#  * `list_memories`: Lists memories in Serena's project-specific memory store.\n#  * `onboarding`: Performs onboarding (identifying the project structure and essential tasks, e.g. for testing or building).\n#  * `prepare_for_new_conversation`: Provides instructions for preparing for a new conversation (in order to continue with the necessary context).\n#  * `read_file`: Reads a file within the project directory.\n#  * `read_memory`: Reads the memory with the given name from Serena's project-specific memory store.\n#  * `remove_project`: Removes a project from the Serena configuration.\n#  * `replace_lines`: Replaces a range of lines within a file with new content.\n#  * `replace_symbol_body`: Replaces the full definition of a symbol.\n#  * `restart_language_server`: Restarts the language server, may be necessary when edits not through Serena happen.\n#  * `search_for_pattern`: Performs a search for a pattern in the project.\n#  * `summarize_changes`: Provides instructions for summarizing the changes made to the codebase.\n#  * `switch_modes`: Activates modes by providing a list of their names\n#  * `think_about_collected_information`: Thinking tool for pondering the completeness of collected information.\n#  * `think_about_task_adherence`: Thinking tool for determining whether the agent is still on track with the current task.\n#  * `think_about_whether_you_are_done`: Thinking tool for determining whether the task is truly completed.\n#  * `write_memory`: Writes a named memory (for future reference) to Serena's project-specific memory store.\nexcluded_tools: []\n\n# list of tools to include that would otherwise be disabled (particularly optional tools that are disabled by default)\nincluded_optional_tools: []\n\n# fixed set of tools to use as the base tool set (if non-empty), replacing Serena's default set of tools.\n# This cannot be combined with non-empty excluded_tools or included_optional_tools.\n# initial prompt for the project. It will always be given to the LLM upon activating the project\n# (contrary to the memories, which are loaded on demand).\ninitial_prompt: |\n  IMPORTANT: You use an idiomatic, object-oriented style.\n  In particular, this implies that, for any non-trivial interfaces, you use interfaces that expect explicitly typed abstractions\n  rather than mere functions (i.e. use the strategy pattern, for example).\n  You avoid the use of low-level data structures in all cases where an object-oriented abstraction would be more appropriate.\n  For simple data storage, you use dataclasses instead of dictionaries or tuples.\n\n  You structure function implementations into functional blocks that are separated by blank lines.\n  Atop each functional block, you write an elliptical phrase (starting with lower-case letter) that describes the purpose of the \n  block in a concise manner.\n\n  Docstrings: You consistently use reStructuredText.\n\n  Comments:\n  When describing parameters, methods/functions and classes, you use a precise style, where the initial (elliptical) phrase\n  clearly defines *what* it is. Any details then follow in subsequent sentences.\n# the encoding used by text files in the project\n# For a list of possible encodings, see https://docs.python.org/3.11/library/codecs.html#standard-encodings\nencoding: utf-8\n\n\n# list of mode names to that are always to be included in the set of active modes\n# The full set of modes to be activated is base_modes + default_modes.\n# If the setting is undefined, the base_modes from the global configuration (serena_config.yml) apply.\n# Otherwise, this setting overrides the global configuration.\n# Set this to [] to disable base modes for this project.\n# Set this to a list of mode names to always include the respective modes for this project.\nbase_modes:\n\n# list of mode names that are to be activated by default.\n# The full set of modes to be activated is base_modes + default_modes.\n# If the setting is undefined, the default_modes from the global configuration (serena_config.yml) apply.\n# Otherwise, this overrides the setting from the global configuration (serena_config.yml).\n# This setting can, in turn, be overridden by CLI parameters (--mode).\ndefault_modes:\n\n# fixed set of tools to use as the base tool set (if non-empty), replacing Serena's default set of tools.\n# This cannot be combined with non-empty excluded_tools or included_optional_tools.\nfixed_tools: []\n\n# time budget (seconds) per tool call for the retrieval of additional symbol information\n# such as docstrings or parameter information.\n# This overrides the corresponding setting in the global configuration; see the documentation there.\n# If null or missing, use the setting from the global configuration.\nsymbol_info_budget:\n\n# The language backend to use for this project.\n# If not set, the global setting from serena_config.yml is used.\n# Valid values: LSP, JetBrains\n# Note: the backend is fixed at startup. If a project with a different backend\n# is activated post-init, an error will be returned.\nlanguage_backend:\n\n# list of regex patterns which, when matched, mark a memory entry as read‑only.\n# Extends the list from the global configuration, merging the two lists.\nread_only_memory_patterns: []\n\n# line ending convention for file writes: unset (use global setting, \"lf\", \"crlf\", or \"native\" (platform default)\n# If not undefined, overrides the global setting in serena_config.yml\nline_ending:\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Latest\n\nStatus of the `main` branch. Changes prior to the next official version change will appear here.\n\n* New language support:\n    * Add Solidity language server support (`Language.SOLIDITY`) using the\n      Nomic Foundation `@nomicfoundation/solidity-language-server`. Automatically\n      installed via npm. Supports `.sol` files with go-to-definition, find references,\n      document symbols, hover, and diagnostics. Works best with a `foundry.toml` or\n      `hardhat.config.js` in the project root.\n\n* General:\n    * Add monorepo/multi-language support\n        * Project configuration files (`project.yml`) can now define multiple languages.\n          Auto-detection adds only the most prominent language by default.\n        * Additional languages can be conveniently added via the Dashboard while a project is already activated.\n    * Add support for querying projects other than the currently active one via new tools `QueryProjectTool` and `ListQueryableProjectsTool`.\n      The `QueryProjectTool` allows Serena tools to be called on other projects.\n        * For the LSP backend, calling symbolic tools require a project server to be spawned that will launch the respective language servers\n        * For the JetBrains backend, all projects for which IDE instances are open can directly be queried\n    * Support overloaded symbols in `FindSymbolTool` and related tools\n        * Name paths of overloaded symbols now include an index (e.g., `myOverloadedFunction[2]`)\n        * Responses of the Java language server, which handled this in its own way, are now adapted accordingly,\n          solving several issues related to retrieval problems in Java projects\n    * Major extensions to the dashboard, which now serves as a central web interface for Serena\n        * View current configuration\n        * View news which can be marked as read\n        * View the executions, with the possibility to cancel running/scheduled executions\n        * View tool usage statistics\n        * View and create memories and edit the serena configuration file\n        * Log page now has save (downloads a snapshot) and clear (resets log view) buttons alongside the existing copy button\n    * Language server backend:\n        * New two-tier caching of language server document symbols and considerable performance improvements surrounding symbol retrieval/indexing\n        * Allow passing language server specific settings through `ls_specific_settings` field (in `serena_config.yml`)\n    * Add the JetBrains language backend as an alternative to language servers\n    * Improve management of the Serena projects\n        * Facilitate project activation based on the current directory (through the `--project-from-cwd` parameter)\n        * Add notion of a \"single-project context\" (flag `single_project`), allowing user-defined contexts to behave\n          like the built-in `ide-assistant` context (where the available tools are restricted to ones required by the active\n          project and project changes are disabled)\n        * The location of Serena's project-specific data folder can now be flexibly configured, allowing, in particular,\n          locations outside of the project folder, thus improving support for read-only projects.\n        * Add support for `project.local.yml` for local overrides that should not be versioned \n    * Various fixes related to indexing, special paths and determination of ignored paths\n\n* Client support:\n    * New mode `oaicompat-agent` and extensions enhancing OpenAI tool compatibility, permitting Serena to work with llama.cpp\n\n* Tools:\n  * Symbol information (hover, docstring, quick-info) is now provided as part of `find_symbol` and related tool responses.\n  * Added `QueryProjectTool` and `ListQueryableProjectTool` (see above)\n  * Added `RenameSymbolTool` for renaming symbols across the codebase (if LS supports this operation).\n  * Replaced `ReplaceRegexTool` with `ReplaceContentTool`, which supports both plain text and regex-based replacements\n    (and which requires no escaping in the replacement text, making it more robust) \n  * Decreased `TOOL_DEFAULT_MAX_ANSWER_LENGTH` to be in accordance with (below) typical max-tokens configurations\n\n* Language support:\n\n  * **Add support for Lean 4** via built-in `lean --server` with cross-file reference support (requires `lean` and `lake` via [elan](https://github.com/leanprover/elan))\n  * **Add support for OCaml** via ocaml-lsp-server with cross-file reference support on OCaml 5.2+ (requires opam; see [setup guide](docs/03-special-guides/ocaml_setup_guide_for_serena.md))\n  * **Add Phpactor as alternative PHP language server** (specify `php_phpactor` as language; requires PHP 8.1+)\n  * **Add support for Fortran** via fortls language server (requires `pip install fortls`)\n  * **Add partial support for Groovy** requires user-provided Groovy language server JAR (see [setup guide](docs/03-special-guides/groovy_setup_guide_for_serena.md))\n  * **Add support for Julia** via LanguageServer.jl\n  * **Add support for Haskell** via Haskell Language Server (HLS) with automatic discovery via ghcup, stack, or system PATH; supports both Stack and Cabal projects\n  * **Add support for Scala** via Metals language server (requires some [manual setup](docs/03-special-guides/scala_setup_guide_for_serena.md))\n  * **Add support for F#** via FsAutoComplete/Ionide LSP server. \n  * **Add support for Elm** via @elm-tooling/elm-language-server (automatically downloads if not installed; requires Elm compiler)\n  * **Add support for Perl** via Perl::LanguageServer with LSP integration for .pl, .pm, and .t files\n  * **Add support for AL (Application Language)** for Microsoft Dynamics 365 Business Central development. Requires VS Code AL extension (ms-dynamics-smb.al).\n  * **Add support for R** via the R languageserver package with LSP integration, performance optimizations, and fallback symbol extraction\n  * **Add support for Zig** via ZLS (cross-file references may not fully work on Windows)\n  * **Add support for Lua** via lua-language-server\n  * **Add support for Nix** requires nixd installation (Windows not supported)\n  * **Add experimental support for YAML** via yaml-language-server with LSP integration for .yaml and .yml files\n  * **Add support for TOML** via Taplo language server with automatic binary download, validation, formatting, and schema support for .toml files\n  * **Dart now officially supported**: Dart was always working, but now tests were added, and it is promoted to \"officially supported\"\n  * **Rust now uses already installed rustup**: The rust-analyzer is no longer bundled with Serena. Instead, it uses the rust-analyzer from your Rust toolchain managed by rustup. This ensures compatibility with your Rust version and eliminates outdated bundled binaries.\n  * **Kotlin now officially supported**: We now use the official Kotlin LS, tests run through and performance is good, even though the LS is in an early development stage.\n  * **Add support for Erlang** experimental, may hang or be slow, uses the recently archived [erlang_ls](https://github.com/erlang-ls/erlang_ls)\n  * **Ruby dual language server support**: Added ruby-lsp as the modern primary Ruby language server. Solargraph remains available as an experimental legacy option. ruby-lsp supports both .rb and .erb files, while Solargraph supports .rb files only.\n  * **Add support for PowerShell** via PowerShell Editor Services (PSES). Requires `pwsh` (PowerShell Core) to be installed and available in PATH. Supports symbol navigation, go-to-definition, and within-file references for .ps1 files.\n  * **Add support for MATLAB** via the official MathWorks MATLAB Language Server. Requires MATLAB R2021b or later and Node.js. Set `MATLAB_PATH` environment variable or configure `matlab_path` in `ls_specific_settings`. Supports .m, .mlx, and .mlapp files with code completion, diagnostics, go-to-definition, find references, document symbols, formatting, and rename.\n  * **Add support for Pascal** via the official Pascal Language Server.\n  * **C/C++ alternate LS (ccls)**: Add experimental, opt-in support for ccls as an alternative backend to clangd. Enable via `cpp_ccls` in project configuration. Requires `ccls` installed and ideally a `compile_commands.json` at repo root.\n\n\n# 0.1.4\n\n## Summary\n\nThis likely is the last release before the stable version 1.0.0 which will come together with the jetbrains IDE extension.\nWe release it for users who install Serena from a tag, since the last tag cannot be installed due to a breaking change in the mcp dependency (see #381).\n\nSince the last release, several new languages were supported, and the Serena CLI and configurability were significantly extended.\nWe thank all external contributors who made a lot of the improvements possible!\n\n* General:\n  * **Initial instructions no longer need to be loaded by the user**\n  * Significantly extended CLI\n  * Removed `replace_regex` tool from `ide-assistant` and `codex` contexts.\n    The current string replacement tool in Claude Code seems to be sufficiently efficient and is better\n    integrated with the IDE. Users who want to enable `replace_regex` can do so by customizing the context.\n\n* Configuration:\n  * Simplify customization of modes and contexts, including CLI support.\n  * Possibility to customize the system prompt and outputs of simple tools, including CLI support.\n  * Possibility to override tool descriptions through the context YAML.\n  * Prompt templates are now automatically adapted to the enabled tools.\n  * Several tools are now excluded by default, need to be included explicitly.\n  * New context for ChatGPT\n\n* Language servers:\n  * Reliably detect language server termination and propagate the respective error all the way\n    back to the tool application, where an unexpected termination is handled by restarting the language server\n    and subsequently retrying the tool application.\n  * **Add support for Swift**\n  * **Add support for Bash**\n  * Enhance Solargraph (Ruby) integration\n    * Automatic Rails project detection via config/application.rb, Rakefile, and Gemfile analysis\n    * Ruby/Rails-specific exclude patterns for improved indexing performance (vendor/, .bundle/, tmp/, log/, coverage/)\n    * Enhanced error handling with detailed diagnostics and Ruby manager-specific installation instructions (rbenv, RVM, asdf)\n    * Improved LSP capability negotiation and analysis completion detection\n    * Better Bundler and Solargraph installation error messages with clear resolution steps\n\nFixes:\n* Ignore `.git` in check for ignored paths and improve performance of `find_all_non_ignored_files`\n* Fix language server startup issues on Windows when using Claude Code (which was due to\n  default shell reconfiguration imposed by Claude Code)\n* Additional wait for initialization in C# language server before requesting references, allowing cross-file references to be found.\n\n# 0.1.3\n\n## Summary\n\nThis is the first release of Serena to pypi. Since the last release, we have greatly improved \nstability and performance, as well as extended functionality, improved editing tools and included support for several new languages. \n\n* **Reduce the use of asyncio to a minimum**, improving stability and reducing the need for workarounds\n   * Switch to newly developed fully synchronous LSP library `solidlsp` (derived from `multilspy`),\n     removing our fork of `multilspy` (src/multilspy)\n   * Switch from fastapi (which uses asyncio) to Flask in the Serena dashboard\n   * The MCP server is the only asyncio-based component now, which resolves cross-component loop contamination,\n     such that process isolation is no longer required.\n     Neither are non-graceful shutdowns on Windows.\n* **Improved editing tools**: The editing logic was simplified and improved, making it more robust.\n   * The \"minimal indentation\" logic was removed, because LLMs did not understand it.\n   * The logic for the insertion of empty lines was improved (mostly controlled by the LLM now)\n* Add a task queue for the agent, which is executed in a separate and thread and\n   * allows the language server to be initialized in the background, making the MCP server respond to requests\n     immediately upon startup,\n   * ensures that all tool executions are fully synchronized (executed linearly).\n* `SearchForPatternTool`: Better default, extended parameters and description for restricting the search\n* Language support:\n   * Better support for C# by switching from `omnisharp` to Microsoft's official C# language server.\n   * **Add support for Clojure, Elixir and Terraform. New language servers for C# and typescript.**\n   * Experimental language server implementations can now be accessed by users through configuring the `language` field\n* Configuration:\n   * Add option `web_dashboard_open_on_launch` (allowing the dashboard to be enabled without opening a browser window) \n   * Add options `record_tool_usage_stats` and `token_count_estimator`\n   * Serena config, modes and contexts can now be adjusted from the user's home directory.\n   * Extended CLI to help with configuration\n* Dashboard:\n  * Displaying tool usage statistics if enabled in the config\n\nFixes:\n* Fix `ExecuteShellCommandTool` and `GetCurrentConfigTool` hanging on Windows\n* Fix project activation by name via `--project` not working (was broken in previous release) \n* Improve handling of indentation and newlines in symbolic editing tools\n* Fix `InsertAfterSymbolTool` failing for insertions at the end of a file that did not end with a newline\n* Fix `InsertBeforeSymbolTool` inserting in the wrong place in the absence of empty lines above the reference symbol\n* Fix `ReplaceSymbolBodyTool` changing whitespace before/after the symbol\n* Fix repository indexing not following links and catch exceptions during indexing, allowing indexing\n  to continue even if unexpected errors occur for individual files.\n* Fix `ImportError` in Ruby language server.\n* Fix some issues with gitignore matching and interpreting of regexes in `search_for_pattern` tool.\n\n# 2025-06-20\n\n* **Overhaul and major improvement of editing tools!**\n  This represents a very important change in Serena. Symbols can now be addressed by their `name_path` (including nested ones)\n  and we introduced a regex-based replaced tools. We tuned the prompts and tested the new editing mechanism.\n  It is much more reliable, flexible, and at the same time uses fewer tokens.\n  The line-replacement tools are disabled by default and deprecated, we will likely remove them soon.\n* **Better multi-project support and zero-config setup**: We significantly simplified the config setup, you no longer need to manually\n  create `project.yaml` for each project. Project activation is now always available. \n  Any project can now be activated by just asking the LLM to do so and passing the path to a repo.\n* Dashboard as web app and possibility to shut down Serena from it (or the old log GUI).\n* Possibility to index your project beforehand, accelerating Serena's tools.\n* Initial prompt for project supported (has to be added manually for the moment)\n* Massive performance improvement of pattern search tool\n* Use **process isolation** to fix stability issues and deadlocks (see #170). \n  This uses separate process for the MCP server, the Serena agent and the dashboard in order to fix asyncio-related issues.\n\n# 2025-05-24\n\n* Important new feature: **configurability of mode and context**, allowing better integration in a variety of clients.\n  See corresponding section in readme - Serena can now be integrated in IDE assistants in a more productive way. \n  You can now also do things like switching to one-shot planning mode, ask to plan something (which will create a memory),\n  then switch to interactive editing mode in the next conversation and work through the plan read from the memory.\n* Some improvements to prompts.\n\n# 2025-05-21\n\n**Significant improvement in symbol finding!**\n\n* Serena core:\n    * `FindSymbolTool` now can look for symbols by specifying paths to them, not just the symbol name\n* Language Servers:\n    * Fixed `gopls` initialization\n    * Symbols retrieved through the symbol tree or through overview methods now are linked to their parents\n\n\n# 2025-05-19\n\n* Serena core:\n    * Bugfix in `FindSymbolTool` (a bug fixed in LS)\n    * Fix in `ListDirTool`: Do not ignore files with extensions not understood by the language server, only skip ignored directories\n      (error introduced in previous version)\n    * Merged the two overview tools (for directories and files) into a single one: `GetSymbolsOverviewTool`\n    * One-click setup for Cline enabled\n    * `SearchForPatternTool` can now (optionally) search in the entire project\n    * New tool `RestartLanguageServerTool` for restarting the language server (in case of other sources of editing apart from Serena)\n    * Fix `CheckOnboardingPerformedTool`:\n        * Tool description was incompatible with project change\n        * Returned result was not as useful as it could be (now added list of memories)\n\n* Language Servers:\n    * Add further file extensions considered by the language servers for Python (.pyi), JavaScript (.jsx) and TypeScript (.tsx, .jsx)\n    * Updated multilspy, adding support for Kotlin, Dart and C/C++ and several improvements.\n    * Added support for PHP\n    \n\n# 2025-04-07\n\n> **Breaking Config Changes**: make sure to set `ignore_all_files_in_gitignore`, remove `ignore_dirs`\n>  and (optionally) set `ignore_paths` in your project configs. See [updated config template](myproject.template.yml)\n\n* Serena core:\n    * New tool: FindReferencingCodeSnippets\n    * Adjusted prompt in CreateTextFileTool to prevent writing partial content (see [here](https://www.reddit.com/r/ClaudeAI/comments/1jpavtm/comment/mloek1x/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button)).\n    * FindSymbolTool: allow passing a file for restricting search, not just a directory (Gemini was too dumb to pass directories)\n    * Native support for gitignore files for configuring files to be ignored by serena. See also\n      in *Language Servers* section below.\n    * **Major Feature**: Allow Serena to switch between projects (project activation)\n        * Add central Serena configuration in `serena_config.yml`, which \n            * contains the list of available projects\n            * allows to configure whether project activation is enabled\n            * now contains the GUI logging configuration (project configurations no longer do)\n        * Add new tools `activate_project` and `get_active_project`\n        * Providing a project configuration file in the launch parameters is now optional\n* Logging:\n    * Improve error reporting in case of initialization failure: \n      open a new GUI log window showing the error or ensure that the existing log window remains visible for some time\n* Language Servers:\n    * Fix C# language server initialization issue when the project path contains spaces\n    * Native support for gitignore in overview, document-tree and find_references operations.\n      This is an **important** addition, since previously things like `venv` and `node_modules` were scanned\n      and were likely responsible for slowness of tools and even server crashes (presumably due to OOM errors).\n* Agno: \n    * Fix Agno reloading mechanism causing failures when initializing the sqlite memory database #8\n    * Fix Serena GUI log window not capturing logs after initialization\n\n# 2025-04-01\n\nInitial public version\n"
  },
  {
    "path": "CLAUDE.md",
    "content": "# CLAUDE.md\n\nThis file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.\n\n## Development Commands\n\n**Essential Commands (use these exact commands):**\n- `uv run poe format` - Format code (BLACK + RUFF) - ONLY allowed formatting command\n- `uv run poe type-check` - Run mypy type checking - ONLY allowed type checking command  \n- `uv run poe test` - Run tests with default markers (excludes java/rust by default)\n- `uv run poe test -m \"python or go\"` - Run specific language tests\n- `uv run poe test -m vue` - Run Vue tests\n- `uv run poe lint` - Check code style without fixing\n\n**Test Markers:**\nAvailable pytest markers for selective testing:\n- `python`, `go`, `java`, `rust`, `typescript`, `vue`, `php`, `perl`, `powershell`, `csharp`, `elixir`, `terraform`, `clojure`, `swift`, `bash`, `ruby`, `ruby_solargraph`\n- `snapshot` - for symbolic editing operation tests\n\n**Project Management:**\n- `uv run serena-mcp-server` - Start MCP server from project root\n- `uv run index-project` - Index project for faster tool performance\n\n**Always run format, type-check, and test before completing any task.**\n\n## Architecture Overview\n\nSerena is a dual-layer coding agent toolkit:\n\n### Core Components\n\n**1. SerenaAgent (`src/serena/agent.py`)**\n- Central orchestrator managing projects, tools, and user interactions\n- Coordinates language servers, memory persistence, and MCP server interface\n- Manages tool registry and context/mode configurations\n\n**2. SolidLanguageServer (`src/solidlsp/ls.py`)**  \n- Unified wrapper around Language Server Protocol (LSP) implementations\n- Provides language-agnostic interface for symbol operations\n- Handles caching, error recovery, and multiple language server lifecycle\n\n**3. Tool System (`src/serena/tools/`)**\n- **file_tools.py** - File system operations, search, regex replacements\n- **symbol_tools.py** - Language-aware symbol finding, navigation, editing\n- **memory_tools.py** - Project knowledge persistence and retrieval\n- **config_tools.py** - Project activation, mode switching\n- **workflow_tools.py** - Onboarding and meta-operations\n\n**4. Configuration System (`src/serena/config/`)**\n- **Contexts** - Define tool sets for different environments (desktop-app, agent, ide-assistant)\n- **Modes** - Operational patterns (planning, editing, interactive, one-shot)\n- **Projects** - Per-project settings and language server configs\n\n### Language Support Architecture\n\nEach supported language has:\n1. **Language Server Implementation** in `src/solidlsp/language_servers/`\n2. **Runtime Dependencies** - Automatic language server downloads when needed\n3. **Test Repository** in `test/resources/repos/<language>/`\n4. **Test Suite** in `test/solidlsp/<language>/`\n\n### Memory & Knowledge System\n\n- **Markdown-based storage** in `.serena/memories/` directories\n- **Project-specific knowledge** persistence across sessions\n- **Contextual retrieval** based on relevance\n- **Onboarding support** for new projects\n\n## Development Patterns\n\n### Adding New Languages\n1. Create language server class in `src/solidlsp/language_servers/`\n2. Add to Language enum in `src/solidlsp/ls_config.py` \n3. Update factory method in `src/solidlsp/ls.py`\n4. Create test repository in `test/resources/repos/<language>/`\n5. Write test suite in `test/solidlsp/<language>/`\n6. Add pytest marker to `pyproject.toml`\n\n### Adding New Tools\n1. Inherit from `Tool` base class in `src/serena/tools/tools_base.py`\n2. Implement required methods and parameter validation\n3. Register in appropriate tool registry\n4. Add to context/mode configurations\n\n### Testing Strategy\n- Language-specific tests use pytest markers\n- Symbolic editing operations have snapshot tests\n- Integration tests in `test_serena_agent.py`\n- Test repositories provide realistic symbol structures\n\n## Configuration Hierarchy\n\nConfiguration is loaded from (in order of precedence):\n1. Command-line arguments to `serena-mcp-server`\n2. Project-specific `.serena/project.yml`\n3. User config `~/.serena/serena_config.yml`\n4. Active modes and contexts\n\n## Key Implementation Notes\n\n- **Symbol-based editing** - Uses LSP for precise code manipulation\n- **Caching strategy** - Reduces language server overhead\n- **Error recovery** - Automatic language server restart on crashes\n- **Multi-language support** - 19 languages with LSP integration (including Vue)\n- **MCP protocol** - Exposes tools to AI agents via Model Context Protocol\n- **Async operation** - Non-blocking language server interactions\n\n## Working with the Codebase\n\n- Project uses Python 3.11 with `uv` for dependency management\n- Strict typing with mypy, formatted with black + ruff\n- Language servers run as separate processes with LSP communication\n- Memory system enables persistent project knowledge\n- Context/mode system allows workflow customization"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "# Contributing to Serena\n\nThank you for your interest in contributing to Serena!\n\n## Scope of Contributions\n\nThe following types of contributions can be submitted directly via pull requests:\n  * isolated additions which do not change the behaviour of Serena and only extend it along existing lines (e.g., adding support for a new language server)\n  * small bug fixes\n  * documentation improvements\n\nFor other changes, please open an issue first to discuss your ideas with the maintainers.\n\nWhen submitting a PR, ensure a well-defined scope.\nEvery PR should cover a single logical change or a set of closely related changes.\n\n### Adding Support for a New Language Server\n\nSee the corresponding [memory](.serena/memories/adding_new_language_support_guide.md).\n\n## Python Environment Setup\n\nYou can install a virtual environment with the required as follows\n\n1. Create a new virtual environment: `uv venv`\n2. Activate the environment:\n    * On Linux/Unix/macOS or Windows with Git Bash: `source .venv/bin/activate`\n    * On Windows outside of Git Bash: `.venv\\Scripts\\activate.bat` (in cmd/ps) or `source .venv/Scripts/activate` (in git-bash) \n3. Install the required packages with all extras: `uv sync --extra dev`\n\n## Poe Tasks\n\nWe use poe to execute development tasks:\n\n- `poe format` - run code auto-formatters\n- `poe type-check` - run type checkers\n\n## Testing Tool Executions\n\nThe Serena tools (and in fact all Serena code) can be executed without an LLM, and also without\nany MCP specifics (though you can use the mcp inspector, if you want).\n\nAn example script for running tools is provided in [scripts/demo_run_tools.py](scripts/demo_run_tools.py)."
  },
  {
    "path": "DOCKER.md",
    "content": "# Docker Setup for Serena (Experimental)\n\n⚠️ **EXPERIMENTAL FEATURE**: The Docker setup for Serena is still experimental and has some limitations. Please read this entire document before using Docker with Serena.\n\n## Overview\n\nDocker support allows you to run Serena in an isolated container environment, which provides better security isolation for the shell tool and consistent dependencies across different systems.\n\n## Benefits\n\n- **Safer shell tool execution**: Commands run in an isolated container environment\n- **Consistent dependencies**: No need to manage language servers and dependencies on your host system\n- **Cross-platform support**: Works consistently across Windows, macOS, and Linux\n\n## Important Usage Pointers\n\n### Configuration\n\nSerena's configuration and log files are stored in the container in `/workspaces/serena/config/`.\nAny local configuration you may have for Serena will not apply; the container uses its own separate configuration.\n\nYou can mount a local configuration/data directory to persist settings across container restarts\n(which will also contain session log files).\nSimply mount your local directory to `/workspaces/serena/config` in the container.\nInitially, be sure to add a `serena_config.yml` file to the mounted directory which applies the following\nspecial settings for Docker usage:\n```\n# Disable the GUI log window since it's not supported in Docker\ngui_log_window: False\n# Listen on all interfaces for the web dashboard to be accessible from outside the container\nweb_dashboard_listen_address: 0.0.0.0\n# Disable opening the web dashboard on launch (not possible within the container)\nweb_dashboard_open_on_launch: False\n```\nSet other configuration options as needed.\n\n### Project Activation Limitations\n\n- **Only mounted directories work**: Projects must be mounted as volumes to be accessible\n- Projects outside the mounted directories cannot be activated or accessed\n- Since projects are not remembered across container restarts (unless you mount a local configuration as described above), \n  activate them using the full path (e.g. `/workspaces/projects/my-project`) when using dynamic project activation\n\n### Language Support Limitations\n\nThe default Docker image does not include dependencies for languages that\nrequire explicit system-level installations.\nOnly languages that install their requirements on the fly will work out of the box.\n\n### Dashboard Port Configuration\n\nThe web dashboard runs on port 24282 (0x5EDA) by default. You can configure this using environment variables:\n\n```bash\n# Use default ports\ndocker-compose up serena\n\n# Use custom ports\nSERENA_DASHBOARD_PORT=8080 docker-compose up serena\n```\n\n⚠️ **Note**: If the local port is occupied, you'll need to specify a different port using the environment variable.\n\n### Line Ending Issues on Windows\n\n⚠️ **Windows Users**: Be aware of potential line ending inconsistencies:\n- Files edited within the Docker container may use Unix line endings (LF)\n- Your Windows system may expect Windows line endings (CRLF)\n- This can cause issues with version control and text editors\n- Configure your Git settings appropriately: `git config core.autocrlf true`\n\n## Quick Start\n\n### Using Docker Compose (Recommended)\n\n1. **Production mode** (for using Serena as MCP server):\n   ```bash\n   docker-compose up serena\n   ```\n\n2. **Development mode** (with source code mounted):\n   ```bash\n   docker-compose up serena-dev\n   ```\n\nNote: Edit the `compose.yaml` file to customize volume mounts for your projects.\n\n### Building the Docker Image Manually\n\n```bash\n# Build the image\ndocker build -t serena .\n\n# Run with current directory mounted\ndocker run -it --rm \\\n  -v \"$(pwd)\":/workspace \\\n  -p 9121:9121 \\\n  -p 24282:24282 \\\n  -e SERENA_DOCKER=1 \\\n  serena\n```\n\n### Using Docker Compose with Merge Compose files\n\nTo use Docker Compose with merge files, you can create a `compose.override.yml` file to customize the configuration:\n\n```yaml\nservices:\n  serena:\n    # To work with projects, you must mount them as volumes:\n    volumes:\n      - ./my-project:/workspace/my-project\n      - /path/to/another/project:/workspace/another-project\n    # Add the context for the IDE assistant option:\n    command:\n      - \"uv run --directory . serena-mcp-server --transport sse --port 9121 --host 0.0.0.0 --context claude-code\"\n```\n\nSee the [Docker Merge Compose files documentation](https://docs.docker.com/compose/how-tos/multiple-compose-files/merge/) for more details on using merge files.\n\n## Accessing the Dashboard\n\nOnce running, access the web dashboard at:\n- Default: http://localhost:24282/dashboard\n- Custom port: http://localhost:${SERENA_DASHBOARD_PORT}/dashboard\n\n## Volume Mounting\n\nTo work with projects, you must mount them as volumes:\n\n```yaml\n# In compose.yaml\nvolumes:\n  - ./my-project:/workspace/my-project\n  - /path/to/another/project:/workspace/another-project\n```\n\n## Environment Variables\n\n- `SERENA_DOCKER=1`: Set automatically to indicate Docker environment\n- `SERENA_PORT`: MCP server port (default: 9121)\n- `SERENA_DASHBOARD_PORT`: Web dashboard port (default: 24282)\n- `INTELEPHENSE_LICENSE_KEY`: License key for Intelephense PHP LSP premium features (optional)\n\n## Troubleshooting\n\n### Port Already in Use\n\nIf you see \"port already in use\" errors:\n```bash\n# Check what's using the port\nlsof -i :24282  # macOS/Linux\nnetstat -ano | findstr :24282  # Windows\n\n# Use a different port\nSERENA_DASHBOARD_PORT=8080 docker-compose up serena\n```\n\n### Configuration Issues\n\nIf you need to reset Docker configuration:\n```bash\n# Remove Docker-specific config\nrm serena_config.docker.yml\n\n# Serena will auto-generate a new one on next run\n```\n\n### Project Access Issues\n\nEnsure projects are properly mounted:\n- Check volume mounts in `docker-compose.yaml`\n- Use absolute paths for external projects\n- Verify permissions on mounted directories\n"
  },
  {
    "path": "Dockerfile",
    "content": "# Base stage with common dependencies\nFROM python:3.11-slim AS base\nSHELL [\"/bin/bash\", \"-c\"]\n\n# Set environment variables to make Python print directly to the terminal and avoid .pyc files.\nENV PYTHONUNBUFFERED=1\nENV PYTHONDONTWRITEBYTECODE=1\n\n# Install system dependencies required for package manager and build tools.\n# sudo, wget, zip needed for some assistants, like junie\nRUN apt-get update && apt-get install -y --no-install-recommends \\\n    curl \\\n    build-essential \\\n    git \\\n    ssh \\\n    sudo \\\n    wget \\\n    zip \\\n    unzip \\\n    git \\\n    && rm -rf /var/lib/apt/lists/*\n\n# Install pipx.\nRUN python3 -m pip install --no-cache-dir pipx \\\n    && pipx ensurepath\n\n# Install nodejs\nENV NVM_VERSION=0.40.3\nENV NODE_VERSION=22.18.0\nRUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh | bash\n# standard location\nENV NVM_DIR=/root/.nvm\nRUN . \"$NVM_DIR/nvm.sh\" && nvm install ${NODE_VERSION}\nRUN . \"$NVM_DIR/nvm.sh\" && nvm use v${NODE_VERSION}\nRUN . \"$NVM_DIR/nvm.sh\" && nvm alias default v${NODE_VERSION}\nENV PATH=\"${NVM_DIR}/versions/node/v${NODE_VERSION}/bin/:${PATH}\"\n\n# Add local bin to the path\nENV PATH=\"${PATH}:/root/.local/bin\"\n\n# Install the latest version of uv\nRUN curl -LsSf https://astral.sh/uv/install.sh | sh\n\n# Install Rust and rustup for rust-analyzer support (minimal profile)\nENV RUSTUP_HOME=/usr/local/rustup\nENV CARGO_HOME=/usr/local/cargo\nENV PATH=\"${CARGO_HOME}/bin:${PATH}\"\nRUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \\\n    --default-toolchain stable \\\n    --profile minimal \\\n    && rustup component add rust-analyzer\n\n# Set the working directory\nWORKDIR /workspaces/serena\n\n# Copy all files for development\nCOPY . /workspaces/serena/\n\n# Install sed\nRUN apt-get update && apt-get install -y sed\n\n# Create Serena configuration\nENV SERENA_HOME=/workspaces/serena/config\nRUN mkdir -p $SERENA_HOME\nRUN cp src/serena/resources/serena_config.template.yml $SERENA_HOME/serena_config.yml\nRUN sed -i 's/^gui_log_window: .*/gui_log_window: False/' $SERENA_HOME/serena_config.yml\nRUN sed -i 's/^web_dashboard_listen_address: .*/web_dashboard_listen_address: 0.0.0.0/' $SERENA_HOME/serena_config.yml\nRUN sed -i 's/^web_dashboard_open_on_launch: .*/web_dashboard_open_on_launch: False/' $SERENA_HOME/serena_config.yml\n\n# Create virtual environment and install dependencies\nRUN uv venv\nRUN . .venv/bin/activate\nRUN uv pip install -r pyproject.toml -e .\nENV PATH=\"/workspaces/serena/.venv/bin:${PATH}\"\n\n# Entrypoint to ensure environment is activated\nENTRYPOINT [\"/bin/bash\", \"-c\", \"source .venv/bin/activate && $0 $@\"]\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2025 Oraios AI\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "<p align=\"center\" style=\"text-align:center\">\n  <img src=\"resources/serena-logo.svg#gh-light-mode-only\" style=\"width:500px\">\n  <img src=\"resources/serena-logo-dark-mode.svg#gh-dark-mode-only\" style=\"width:500px\">\n</p>\n\n* :rocket: Serena is a powerful **coding agent toolkit** capable of turning an LLM into a fully-featured agent that works **directly on your codebase**.\n  Unlike most other tools, it is not tied to an LLM, framework or an interface, making it easy to use it in a variety of ways.\n* :wrench: Serena provides essential **semantic code retrieval and editing tools** that are akin to an IDE's capabilities, extracting code entities at the symbol level and exploiting relational structure. When combined with an existing coding agent, these tools greatly enhance (token) efficiency.\n* :free: Serena is **free & open-source**, enhancing the capabilities of LLMs you already have access to free of charge.\n\nYou can think of Serena as providing IDE-like tools to your LLM/coding agent. \nWith it, the agent no longer needs to read entire files, perform grep-like searches or basic string replacements to find the right parts of the code and to edit code. \nInstead, it can use code-centric tools like `find_symbol`, `find_referencing_symbols` and `insert_after_symbol`.\n\n<p align=\"center\">\n  <em>Serena is under active development! See the latest updates, upcoming features, and lessons learned to stay up to date.</em>\n</p>\n\n<p align=\"center\">\n  <a href=\"CHANGELOG.md\"><img src=\"https://img.shields.io/badge/Updates-1e293b?style=flat&logo=rss&logoColor=white&labelColor=1e293b\" alt=\"Changelog\" /></a>\n  <a href=\"lessons_learned.md\"><img src=\"https://img.shields.io/badge/Lessons-Learned-7c4700?style=flat&logo=readthedocs&logoColor=white&labelColor=7c4700\" alt=\"Lessons Learned\" /></a>\n</p>\n\n> [!TIP]\n> The [**Serena JetBrains plugin**](#the-serena-jetbrains-plugin) has been released!\n\n## LLM Integration\n\nSerena provides the necessary [tools](https://oraios.github.io/serena/01-about/035_tools.html) for coding workflows, but an LLM is required to do the actual work,\norchestrating tool use.\n\nIn general, Serena can be integrated with an LLM in several ways:\n\n* by using the **model context protocol (MCP)**.\n  Serena provides an MCP server which integrates with\n    * Claude Code and Claude Desktop,\n    * terminal-based clients like Codex, Gemini-CLI, Qwen3-Coder, rovodev, OpenHands CLI and others,\n    * IDEs like VSCode, Cursor or IntelliJ,\n    * Extensions like Cline or Roo Code\n    * Local clients like [OpenWebUI](https://docs.openwebui.com/openapi-servers/mcp), [Jan](https://jan.ai/docs/mcp-examples/browser/browserbase#enable-mcp), [Agno](https://docs.agno.com/introduction/playground) and others\n* by using [mcpo to connect it to ChatGPT](docs/03-special-guides/serena_on_chatgpt.md) or other clients that don't support MCP but do support tool calling via OpenAPI.\n* by incorporating Serena's tools into an agent framework of your choice, as illustrated [here](docs/03-special-guides/custom_agent.md).\n  Serena's tool implementation is decoupled from the framework-specific code and can thus easily be adapted to any agent framework.\n\n## Serena in Action\n\n#### Demonstration 1: Efficient Operation in Claude Code\n\nA demonstration of Serena efficiently retrieving and editing code within Claude Code, thereby saving tokens and time. Efficient operations are not only useful for saving costs, but also for generally improving the generated code's quality. This effect may be less pronounced in very small projects, but often becomes of crucial importance in larger ones.\n\nhttps://github.com/user-attachments/assets/ab78ebe0-f77d-43cc-879a-cc399efefd87\n\n#### Demonstration 2: Serena in Claude Desktop\n\nA demonstration of Serena implementing a small feature for itself (a better log GUI) with Claude Desktop.\nNote how Serena's tools enable Claude to find and edit the right symbols.\n\nhttps://github.com/user-attachments/assets/6eaa9aa1-610d-4723-a2d6-bf1e487ba753\n\n## Programming Language Support & Semantic Analysis Capabilities\n\nSerena provides a set of versatile code querying and editing functionalities\nbased on symbolic understanding of the code.\nEquipped with these capabilities, Serena discovers and edits code just like a seasoned developer\nmaking use of an IDE's capabilities would.\nSerena can efficiently find the right context and do the right thing even in very large and\ncomplex projects!\n\nThere are two alternative technologies powering these capabilities:\n\n* **Language servers** implementing the language server Protocol (LSP) — the free/open-source alternative.\n* **The Serena JetBrains Plugin**, which leverages the powerful code analysis and editing\n  capabilities of your JetBrains IDE.\n\nYou can choose either of these backends depending on your preferences and requirements.\n\n### Language Servers\n\nSerena incorporates a powerful abstraction layer for the integration of language servers\nthat implement the language server protocol (LSP).\nThe underlying language servers are typically open-source projects (like Serena) or at least freely available for use.\n\nWith Serena's LSP library, we provide **support for over 30 programming languages**, including\nAL, Ansible, Bash, C#, C/C++, Clojure, Dart, Elixir, Elm, Erlang, Fortran, GLSL, Go, Groovy (partial support), Haskell, HLSL, Java, Javascript, Julia, Kotlin, Lean 4, Lua, Luau, Markdown, MATLAB, Nix, OCaml, Perl, PHP, PowerShell, Python, R, Ruby, Rust, Scala, Solidity, Swift, TOML, TypeScript, WGSL, YAML, and Zig.\n\n> [!IMPORTANT]\n> Some language servers require additional dependencies to be installed; see the [Language Support](https://oraios.github.io/serena/01-about/020_programming-languages.html) page for details.\n\n### The Serena JetBrains Plugin\n\nAs an alternative to language servers, the [Serena JetBrains Plugin](https://plugins.jetbrains.com/plugin/28946-serena/)\nleverages the powerful code analysis capabilities of your JetBrains IDE.\nThe plugin naturally supports all programming languages and frameworks that are supported by JetBrains IDEs,\nincluding IntelliJ IDEA, PyCharm, Android Studio, WebStorm, PhpStorm, RubyMine, GoLand, and potentially others (Rider and CLion are unsupported though).\n\n<a href=\"https://plugins.jetbrains.com/plugin/28946-serena/\"><img src=\"docs/_static/images/jetbrains-marketplace-button.png\"></a>\n\nThe plugin offers the most robust and most powerful Serena experience.\nSee our [documentation page](https://oraios.github.io/serena/02-usage/025_jetbrains_plugin.html) for further details and instructions.\n\n## Quick Start\n\n**Prerequisites**. Serena is managed by *uv*. If you don’t already have it, you need to [install uv](https://docs.astral.sh/uv/getting-started/installation/) before proceeding.\n\n**Starting the MCP Server**. The easiest way to start the Serena MCP server is by running the latest version from GitHub using uvx.\nIssue this command to see available options:\n\n```bash\nuvx --from git+https://github.com/oraios/serena serena start-mcp-server --help\n```\n\n**Configuring Your Client**. To connect Serena to your preferred MCP client, you typically need to [configure a launch command in your client](https://oraios.github.io/serena/02-usage/030_clients.html).\nFollow the link for specific instructions on how to set up Serena for Claude Code, Codex, Claude Desktop, MCP-enabled IDEs and other clients (such as local and web-based GUIs). \n\n> [!TIP]\n> While getting started quickly is easy, Serena is a powerful toolkit with many configuration options.\n> We highly recommend reading through the [user guide](https://oraios.github.io/serena/02-usage/000_intro.html) to get the most out of Serena.\n> \n> Specifically, we recommend to read about ...\n>   * [Serena's project-based workflow](https://oraios.github.io/serena/02-usage/040_workflow.html) and\n>   * [configuring Serena](https://oraios.github.io/serena/02-usage/050_configuration.html).\n\n## User Guide\n\nPlease refer to the [user guide](https://oraios.github.io/serena/02-usage/000_intro.html) for detailed instructions on how to use Serena effectively.\n\n## Community Feedback\n\nMost users report that Serena has strong positive effects on the results of their coding agents, even when used within\nvery capable agents like Claude Code. Serena is often described to be a [game changer](https://www.reddit.com/r/ClaudeAI/comments/1lfsdll/try_out_serena_mcp_thank_me_later/), providing an enormous [productivity boost](https://www.reddit.com/r/ClaudeCode/comments/1mguoia/absolutely_insane_improvement_of_claude_code).\n\nSerena excels at navigating and manipulating complex codebases, providing tools that support precise code retrieval and editing in the presence of large, strongly structured codebases.\nHowever, when dealing with tasks that involve only very few/small files, you may not benefit from including Serena on top of your existing coding agent.\nIn particular, when writing code from scratch, Serena will not provide much value initially, as the more complex structures that Serena handles more gracefully than simplistic, file-based approaches are yet to be created.\n\nSeveral videos and blog posts have talked about Serena:\n\n* YouTube:\n    * [AI Labs](https://www.youtube.com/watch?v=wYWyJNs1HVk&t=1s)\n    * [Yo Van Eyck](https://www.youtube.com/watch?v=UqfxuQKuMo8&t=45s)\n    * [JeredBlu](https://www.youtube.com/watch?v=fzPnM3ySmjE&t=32s)\n\n* Blog posts:\n    * [Serena's Design Principles](https://medium.com/@souradip1000/deconstructing-serenas-mcp-powered-semantic-code-understanding-architecture-75802515d116)\n    * [Serena with Claude Code (in Japanese)](https://blog.lai.so/serena/)\n    * [Turning Claude Code into a Development Powerhouse](https://robertmarshall.dev/blog/turning-claude-code-into-a-development-powerhouse/)\n\n## Acknowledgements\n\n### Sponsors\n\nWe are very grateful to our [sponsors](https://github.com/sponsors/oraios) who help us drive Serena's development. The core team\n(the founders of [Oraios AI](https://oraios-ai.de/)) put in a lot of work in order to turn Serena into a useful open source project. \nSo far, there is no business model behind this project, and sponsors are our only source of income from it.\n\nSponsors help us dedicating more time to the project, managing contributions, and working on larger features (like better tooling based on more advanced\nLSP features, VSCode integration, debugging via the DAP, and several others).\nIf you find this project useful to your work, or would like to accelerate the development of Serena, consider becoming a sponsor.\n\nWe are proud to announce that the Visual Studio Code team, together with Microsoft’s Open Source Programs Office and GitHub Open Source\nhave decided to sponsor Serena with a one-time contribution!\n\n<p align=\"center\">\n  <img src=\"resources/vscode_sponsor_logo.png\" alt=\"Visual Studio Code sponsor logo\" width=\"220\">\n</p>\n\n### Community Contributions\n\nA significant part of Serena, especially support for various languages, was contributed by the open source community.\nWe are very grateful for the many contributors who made this possible and who played an important role in making Serena\nwhat it is today.\n\n### Technologies\nWe built Serena on top of multiple existing open-source technologies, the most important ones being:\n\n1. [multilspy](https://github.com/microsoft/multilspy).\n   A library which wraps language server implementations and adapts them for interaction via Python.\n   It provided the basis for our library Solid-LSP (`src/solidlsp`).\n   Solid-LSP provides pure synchronous LSP calls and extends the original library with the symbolic logic\n   that Serena required.\n2. [Python MCP SDK](https://github.com/modelcontextprotocol/python-sdk)\n3. All the language servers that we use through Solid-LSP.\n\nWithout these projects, Serena would not have been possible (or would have been significantly more difficult to build).\n\n## Customizing and Extending Serena\n\nIt is straightforward to extend Serena's AI functionality with your own ideas.\nSimply implement a new tool by subclassing\n`serena.agent.Tool` and implement the `apply` method with a signature\nthat matches the tool's requirements.\nOnce implemented, `SerenaAgent` will automatically have access to the new tool.\n\nIt is also relatively straightforward to add [support for a new programming language](/.serena/memories/adding_new_language_support_guide.md).\n\nWe look forward to seeing what the community will come up with!\nFor details on contributing, see [contributing guidelines](/CONTRIBUTING.md).\n"
  },
  {
    "path": "compose.yaml",
    "content": "services:\n  serena:\n    image: serena:latest\n    # To work with projects, you must mount them into /workspace/ in the container:\n    # volumes:\n      # - ./my-project:/workspace/my-project\n      # - /path/to/another/project:/workspace/another-project\n    build:\n      context: ./\n      dockerfile: Dockerfile\n      target: production\n    ports:\n      - \"${SERENA_PORT:-9121}:9121\"  # MCP server port\n      - \"${SERENA_DASHBOARD_PORT:-24282}:24282\"  # Dashboard port (default 0x5EDA = 24282)\n    environment:\n      - SERENA_DOCKER=1\n    command:\n      - \"uv run --directory . serena-mcp-server --transport sse --port 9121 --host 0.0.0.0\"\n      # Alternatively add further arguments, e.g. a context\n      # - \"uv run --directory . serena-mcp-server --transport sse --port 9121 --host 0.0.0.0 --context ide\"\n\n"
  },
  {
    "path": "docker_build_and_run.sh",
    "content": "#!/usr/bin/bash\n\ndocker build -t serena .\n\ndocker run -it --rm -v \"$(pwd)\":/workspace serena\n"
  },
  {
    "path": "docs/.gitignore",
    "content": "/_toc.yml\n/jupyter_execute\n/conf.py\n/_build\n"
  },
  {
    "path": "docs/01-about/.gitignore",
    "content": "/035_tools.md"
  },
  {
    "path": "docs/01-about/000_intro.md",
    "content": "# About Serena\n\n* Serena is a powerful **coding agent toolkit** capable of turning an LLM into a fully-featured agent that works\n  **directly on your codebase**.\n  Unlike most other tools, it is not tied to an LLM, framework or an interface, making it easy to use it in a variety of ways.\n* Serena provides essential **semantic code retrieval and editing tools** that are akin to an IDE's capabilities,\n  extracting code entities at the symbol level and exploiting relational structure.\n  When combined with an existing coding agent, these tools greatly enhance (token) efficiency.\n* Serena is **free & open-source**, enhancing the capabilities of LLMs you already have access to free of charge.\n\nTherefore, you can think of Serena as providing IDE-like tools to your LLM/coding agent.\nWith it, the agent no longer needs to read entire files, perform grep-like searches or string replacements to find and\nedit the right code.\nInstead, it can use code-centred tools like `find_symbol`, `find_referencing_symbols` and `insert_after_symbol`.\n"
  },
  {
    "path": "docs/01-about/010_llm-integration.md",
    "content": "# LLM Integration\n\nSerena provides the necessary [tools](035_tools) for coding workflows, but an LLM is required to do the actual work,\norchestrating tool use.\n\nIn general, Serena can be integrated with an LLM in several ways:\n\n* by using the **model context protocol (MCP)**.\n  Serena provides an MCP server which integrates with\n    * Claude Code and Claude Desktop,\n    * Terminal-based clients like Codex, Gemini-CLI, Qwen3-Coder, rovodev, OpenHands CLI and others,\n    * IDEs like VSCode, Cursor or IntelliJ,\n    * Extensions like Cline or Roo Code\n    * Local clients like [OpenWebUI](https://docs.openwebui.com/openapi-servers/mcp), [Jan](https://jan.ai/docs/mcp-examples/browser/browserbase#enable-mcp), [Agno](https://docs.agno.com/introduction/playground) and others\n* by using [mcpo to connect it to ChatGPT](../03-special-guides/serena_on_chatgpt.md) or other clients that don't support MCP but do support tool calling via OpenAPI.\n* by incorporating Serena's tools into an agent framework of your choice, as illustrated [here](../03-special-guides/custom_agent).\n  Serena's tool implementation is decoupled from the framework-specific code and can thus easily be adapted to any agent framework.\n"
  },
  {
    "path": "docs/01-about/020_programming-languages.md",
    "content": "# Language Support\n\nSerena provides a set of versatile code querying and editing functionalities\nbased on symbolic understanding of the code.\nEquipped with these capabilities, Serena discovers and edits code just like a seasoned developer\nmaking use of an IDE's capabilities would.\nSerena can efficiently find the right context and do the right thing even in very large and\ncomplex projects!\n\nThere are two alternative technologies powering these capabilities:\n\n* **Language servers** implementing the language server Protocol (LSP) — the free/open-source alternative.\n* **The Serena JetBrains Plugin**, which leverages the powerful code analysis and editing\n  capabilities of your JetBrains IDE.\n\nYou can choose either of these backends depending on your preferences and requirements.\n\n## Language Servers\n\nSerena incorporates a powerful abstraction layer for the integration of language servers \nthat implement the language server protocol (LSP).\nIt even supports multiple language servers in parallel to support polyglot projects.\n\nThe language servers themselves are typically open-source projects (like Serena)\nor at least freely available for use.\n\nWe currently provide direct, out-of-the-box support for the programming languages listed below.\nSome languages require additional installations or setup steps, as noted.\n\n* **AL**\n* **Ansible**\n  (experimental; requires Node.js and npm; automatically installs `@ansible/ansible-language-server`;\n  must be explicitly specified in the `languages` entry in the `project.yml`; requires `ansible` in PATH for full functionality)\n  the upstream `@ansible/ansible-language-server@1.2.3` supports hover, completion, definition,\n  semantic tokens, and validation; document symbols, workspace symbols, references, and rename\n  are not supported by this version)\n* **Bash**\n* **C#**  \n  (by default, uses the Roslyn language server (language `csharp`), requiring [.NET v10+](https://dotnet.microsoft.com/en-us/download/dotnet) and, on Windows, `pwsh` ([PowerShell 7+](https://learn.microsoft.com/en-us/powershell/scripting/install/install-powershell-on-windows?view=powershell-7.5));\n  set language to `csharp_omnisharp` to use OmiSharp instead)\n* **C/C++**  \n  (by default, uses the clangd language server (language `cpp`) but we also support ccls (language `cpp_ccls`);\n  for best results, provide a `compile_commands.json` at the repository root;\n  see the [C/C++ Setup Guide](../03-special-guides/cpp_setup) for details.)\n* **Clojure**\n* **Dart**\n* **Elixir**  \n  (requires Elixir installation; Expert language server is downloaded automatically)\n* **Elm**  \n  (requires Elm compiler)\n* **Erlang**  \n  (requires installation of beam and [erlang_ls](https://github.com/erlang-ls/erlang_ls); experimental, might be slow or hang)\n* **F#**  \n  (requires [.NET v8.0+](https://dotnet.microsoft.com/en-us/download/dotnet); uses FsAutoComplete/Ionide, which is auto-installed; for Homebrew .NET on macOS, set DOTNET_ROOT in your environment)\n* **Fortran**   \n  (requires installation of fortls: `pip install fortls`)\n* **Go**  \n  (requires installation of `gopls`)\n* **Groovy**  \n  (requires local groovy-language-server.jar setup via `GROOVY_LS_JAR_PATH` or configuration)\n* **Haskell**\n  (automatically locates HLS via ghcup, stack, or system PATH; supports Stack and Cabal projects)\n* **HLSL / GLSL / WGSL**\n  (uses [shader-language-server](https://github.com/antaalt/shader-sense) (language `hlsl`); automatically downloaded;\n  on macOS, requires Rust toolchain for building from source;\n  note: reference search is not supported by this language server)\n* **Java**  \n* **JavaScript**  \n  (supported via the TypeScript language server, i.e. use language `typescript` for both JavaScript and TypeScript)\n* **Julia**\n* **Kotlin**  \n  (uses the pre-alpha [official kotlin LS](https://github.com/Kotlin/kotlin-lsp), some issues may appear)\n* **Lean 4**  \n  (requires `lean` and `lake` installed via [elan](https://github.com/leanprover/elan); uses the built-in Lean 4 LSP;\n  the project must be a Lake project with `lake build` run before use)\n* **Lua**\n* **Luau**\n* **Markdown**  \n  (must explicitly enable language `markdown`, primarily useful for documentation-heavy projects)\n* **Nix**  \n  (requires nixd installation)\n* **OCaml**\n  (requires opam and ocaml-lsp-server to be installed manually; see the [OCaml Setup Guide](../03-special-guides/ocaml_setup_guide_for_serena.md))\n* **Pascal**  \n  (uses Pascal/Lazarus, which is automatically downloaded; set `PP` and `FPCDIR` environment variables for source navigation)\n* **Perl**  \n  (requires installation of Perl::LanguageServer)\n* **PHP**  \n  (by default, uses the Intelephense language server (language `php`), set `INTELEPHENSE_LICENSE_KEY` environment variable for premium features;\n  we also support [Phpactor](https://github.com/phpactor/phpactor) (language `php_phpactor`), which requires PHP 8.1+)\n* **Python**\n* **R**  \n  (requires installation of the `languageserver` R package)\n* **Ruby**  \n  (by default, uses [ruby-lsp](https://github.com/Shopify/ruby-lsp) (language `ruby`); use language `ruby_solargraph` to use Solargraph instead.)\n* **Rust**  \n  (requires [rustup](https://rustup.rs/) - uses rust-analyzer from your toolchain)\n* **Scala**  \n  (requires some [manual setup](../03-special-guides/scala_setup_guide_for_serena); uses Metals LSP)\n* **Solidity**\n  (experimental; requires Node.js and npm; automatically installs `@nomicfoundation/solidity-language-server`;\n  works best with a `foundry.toml` or `hardhat.config.js` in the project root)\n* **Swift**\n* **TypeScript**\n* **Vue**    \n  (3.x with TypeScript; requires Node.js v18+ and npm; supports .vue Single File Components with monorepo detection)\n* **YAML**\n* **Zig**  \n  (requires installation of ZLS - Zig Language Server)\n\nSupport for further languages can easily be added by providing a shallow adapter for a new language server implementation,\nsee Serena's [memory on that](https://github.com/oraios/serena/blob/main/.serena/memories/adding_new_language_support_guide.md).\n\n## The Serena JetBrains Plugin\n\nAs an alternative to language servers, the [Serena JetBrains Plugin](https://plugins.jetbrains.com/plugin/28946-serena/)\nleverages the powerful code analysis capabilities of JetBrains IDEs. \nThe plugin naturally supports all programming languages and frameworks that are supported by JetBrains IDEs, \nincluding IntelliJ IDEA, PyCharm, Android Studio, WebStorm, PhpStorm, RubyMine, GoLand, and potentially others \n(Rider and CLion are unsupported though).\n\nWhen using the plugin, Serena connects to an instance of your JetBrains IDE via the plugin. For users who already\nwork in a JetBrains IDE, this means Serena seamlessly integrates with the IDE instance you typically have open anyway,\nrequiring no additional setup or configuration beyond the plugin itself. This approach offers several key advantages:\n\n* **External library indexing**: Dependencies and libraries are fully indexed and accessible to Serena\n* **No additional setup**: No need to download or configure separate language servers\n* **Enhanced performance**: Faster tool execution thanks to optimized IDE integration\n* **Multi-language excellence**: First-class support for polyglot projects with multiple languages and frameworks\n\nEven if you prefer to work in a different code editor, you can still benefit from the JetBrains plugin by running \na JetBrains IDE instance (most have free community editions) alongside your preferred editor with your project \nopened and indexed. Serena will connect to the IDE for code analysis while you continue working in your editor \nof choice.\n\n```{raw} html\n<p>\n<a href=\"https://plugins.jetbrains.com/plugin/28946-serena/\">\n<img style=\"background-color:transparent;\" src=\"../_static/images/jetbrains-marketplace-button.png\">\n</a>\n</p>\n```\n\nSee the [JetBrains Plugin documentation](../02-usage/025_jetbrains_plugin) for usage details.\n"
  },
  {
    "path": "docs/01-about/030_serena-in-action.md",
    "content": "# Serena in Action\n\n## Demonstration 1: Efficient Operation in Claude Code\n\nA demonstration of Serena efficiently retrieving and editing code within Claude Code, thereby saving tokens and time. Efficient operations are not only useful for saving costs, but also for generally improving the generated code's quality. This effect may be less pronounced in very small projects, but often becomes of crucial importance in larger ones.\n\n<video src=\"https://github.com/user-attachments/assets/ab78ebe0-f77d-43cc-879a-cc399efefd87\"\ncontrols\npreload=\"metadata\"\nstyle=\"max-width: 100%; height: auto;\">\nYour browser does not support the video tag.\n</video>\n\n## Demonstration 2: Serena in Claude Desktop\n\nA demonstration of Serena implementing a small feature for itself (a better log GUI) with Claude Desktop.\nNote how Serena's tools enable Claude to find and edit the right symbols.\n\n<video src=\"https://github.com/user-attachments/assets/6eaa9aa1-610d-4723-a2d6-bf1e487ba753\"\ncontrols\npreload=\"metadata\"\nstyle=\"max-width: 100%; height: auto;\">\nYour browser does not support the video tag.\n</video>\n"
  },
  {
    "path": "docs/01-about/040_comparison-to-other-agents.md",
    "content": "# Comparison with Other Coding Agents\n\nTo our knowledge, Serena is the first fully-featured coding agent where the\nentire functionality is made available through an MCP server, \nthus not requiring additional API keys or subscriptions if access to an LLM\nis already available through an MCP-compatible client.\n\n## Subscription-Based Coding Agents\n\nMany prominent subscription-based coding agents are parts of IDEs like\nWindsurf, Cursor and VSCode.\nSerena's functionality is similar to Cursor's Agent, Windsurf's Cascade or\nVSCode's agent mode.\n\nSerena has the advantage of not requiring a subscription.\n\nMore technical differences are:\n\n* Serena navigates and edits code using a language server, so it has a symbolic\n  understanding of the code.\n  IDE-based tools often use a text search-based or purely text file-based approach, which is often\n  less powerful, especially for large codebases.\n* Serena is not bound to a specific interface (IDE or CLI).\n  Serena's MCP server can be used with any MCP client (including some IDEs).\n* Serena is not bound to a specific large language model or API.\n* Serena is open-source and has a small codebase, so it can be easily extended\n  and modified.\n\n## API-Based Coding Agents\n\nAn alternative to subscription-based agents are API-based agents like Claude\nCode, Cline, Aider, Roo Code and others, where the usage costs map directly\nto the API costs of the underlying LLM.\nSome of them (like Cline) can even be included in IDEs as an extension.\nThey are often very powerful and their main downside are the (potentially very\nhigh) API costs.\nSerena itself can be used as an API-based agent (see the [section on Agno](../03-special-guides/custom_agent.md)).\n\nThe main difference between Serena and other API-based agents is that Serena can\nalso be used as an MCP server, thus not requiring\nan API key and bypassing the API costs.\n\n## Other MCP-Based Coding Agents\n\nThere are other MCP servers designed for coding, like [DesktopCommander](https://github.com/wonderwhy-er/DesktopCommanderMCP) and\n[codemcp](https://github.com/ezyang/codemcp).\nHowever, to the best of our knowledge, none of them provide semantic code\nretrieval and editing tools; they rely purely on text-based analysis.\nIt is the integration of language servers and the MCP that makes Serena unique\nand so powerful for challenging coding tasks, especially in the context of\nlarger codebases."
  },
  {
    "path": "docs/01-about/050_acknowledgements.md",
    "content": "# Acknowledgements\n\n## Sponsors\n\nWe are very grateful to our [sponsors](https://github.com/sponsors/oraios), who help us drive Serena's development. \nThe core team (the founders of [Oraios AI](https://oraios-ai.de/)) put in a lot of work in order to turn Serena into a useful open source project.\nSo far, there is no business model behind this project, and sponsors are our only source of income from it.\n\nSponsors help us dedicate more time to the project, managing contributions, and working on larger features (like better tooling based on more advanced\nLSP features, VSCode integration, debugging via the DAP, and several others).\nIf you find this project useful to your work, or would like to accelerate the development of Serena, consider becoming a sponsor.\n\nWe are proud to announce that the Visual Studio Code team, together with Microsoft’s Open Source Programs Office and GitHub Open Source\nhave decided to sponsor Serena with a one-time contribution!\n\n## Community Contributions\n\nA significant part of Serena, especially support for various languages, was contributed by the open source community.\nWe are very grateful for the many contributors who made this possible and who played an important role in making Serena\nwhat it is today.\n\n## Technologies\n\nWe built Serena on top of multiple existing open-source technologies, the most important ones being:\n\n1. [multilspy](https://github.com/microsoft/multilspy).\n   A library which wraps language server implementations and adapts them for interaction via Python\n   and which provided the basis for our library Solid-LSP (src/solidlsp).\n   Solid-LSP provides pure synchronous LSP calls and extends the original library with the symbolic logic\n   that Serena required.\n2. [Python MCP SDK](https://github.com/modelcontextprotocol/python-sdk)\n3. All the language servers that we use through Solid-LSP.\n\nWithout these projects, Serena would not have been possible (or would have been significantly more difficult to build).\n"
  },
  {
    "path": "docs/02-usage/000_intro.md",
    "content": "# Usage\n\nSerena can be used in various ways and supports coding workflows through a project-based approach.\nIts configuration is flexible and allows tailoring it to your specific needs.\n\nIn this section, you will find general usage instructions as well as concrete instructions for selected integrations.\n"
  },
  {
    "path": "docs/02-usage/010_prerequisites.md",
    "content": "# Prerequisites\n\n## Package Manager: uv\n\nSerena is managed by `uv`.\nIf you do not have it yet, install it following the instructions [here](https://docs.astral.sh/uv/getting-started/installation/).\n\n## Language-Specific Requirements\n\nDepending on the programming language you intend to use with Serena, you may need to install additional tools or SDKs if you \nintend to use the language server backend of Serena.  \nSee the [language support documentation](../01-about/020_programming-languages) for details. \n"
  },
  {
    "path": "docs/02-usage/020_running.md",
    "content": "# Running Serena\n\nSerena is a command-line tool with a variety of sub-commands.\nThis section describes\n * various ways of running Serena\n * how to run and configure the most important command, i.e. starting the MCP server\n * other useful commands.\n\n## Ways of Running Serena\n\nIn the following, we will refer to the command used to run Serena as `<serena>`,\nwhich you should replace with the appropriate command based on your chosen method,\nas detailed below.\n\nIn general, to get help, append `--help` to the command, i.e.\n\n    <serena> --help\n    <serena> <command> --help\n\n### Using uvx\n\n`uvx` is part of `uv`. It can be used to run the latest version of Serena directly from the repository, without an explicit local installation.\n\n    uvx --from git+https://github.com/oraios/serena serena \n\nExplore the CLI to see some of the customization options that serena provides (more info on them below).\n\n### Local Installation\n\n1. Clone the repository and change into it.\n\n   ```shell\n   git clone https://github.com/oraios/serena\n   cd serena\n   ```\n\n2. Run Serena via\n\n   ```shell\n   uv run serena \n   ```\n\n   when within the serena installation directory.   \n   From other directories, run it with the `--directory` option, i.e.\n\n   ```shell\n    uv run --directory /abs/path/to/serena serena\n    ```\n\n:::{note}\nAdding the `--directory` option results in the working directory being set to the Serena directory.\nAs a consequence, you will need to specify paths when using CLI commands that would otherwise operate on the current directory.\n:::\n\n(docker)=\n### Using Docker \n\nThe Docker approach offers several advantages:\n\n* better security isolation for shell command execution\n* no need to install language servers and dependencies locally\n* consistent environment across different systems\n\nYou can run the Serena MCP server directly via Docker as follows,\nassuming that the projects you want to work on are all located in `/path/to/your/projects`:\n\n```shell\ndocker run --rm -i --network host -v /path/to/your/projects:/workspaces/projects ghcr.io/oraios/serena:latest serena \n```\n\nThis command mounts your projects into the container under `/workspaces/projects`, so when working with projects, \nyou need to refer to them using the respective path (e.g. `/workspaces/projects/my-project`).\n\nAlternatively, you may use Docker compose with the `compose.yml` file provided in the repository.\nSee our [advanced Docker usage](https://github.com/oraios/serena/blob/main/DOCKER.md) documentation for more detailed instructions, configuration options, and limitations.\n\n:::{note}\nDocker usage is subject to limitations; see the [advanced Docker usage](https://github.com/oraios/serena/blob/main/DOCKER.md) documentation for details.\n:::\n\n### Using Nix\n\nIf you are using Nix and [have enabled the `nix-command` and `flakes` features](https://nixos.wiki/wiki/flakes), you can run Serena using the following command:\n\n```bash\nnix run github:oraios/serena -- <command> [options]\n```\n\nYou can also install Serena by referencing this repo (`github:oraios/serena`) and using it in your Nix flake. The package is exported as `serena`.\n\n(start-mcp-server)=\n## Running the MCP Server\n\nGiven your preferred method of running Serena, you can start the MCP server using the `start-mcp-server` command:\n\n    <serena> start-mcp-server [options]  \n\nNote that no matter how you run the MCP server, Serena will, by default, start a web-based dashboard on localhost that will allow you to inspect\nthe server's operations, logs, and configuration.\n\n:::{tip}\nBy default, Serena will use language servers for code understanding and analysis.    \nWith the [Serena JetBrains Plugin](025_jetbrains_plugin), we recently introduced a powerful alternative,\nwhich has several advantages over the language server-based approach.\n:::\n\n### Standard I/O Mode\n\nThe typical usage involves the client (e.g. Claude Code, Codex or Cursor) running\nthe MCP server as a subprocess and using the process' stdin/stdout streams to communicate with it.\nIn order to launch the server, the client thus needs to be provided with the command to run the MCP server.\n\n:::{note}\nMCP servers which use stdio as a protocol are somewhat unusual as far as client/server architectures go, as the server\nnecessarily has to be started by the client in order for communication to take place via the server's standard input/output streams.\nIn other words, you do not need to start the server yourself. The client application (e.g. Claude Desktop) takes care of this and\ntherefore needs to be configured with a launch command.\n:::\n\nCommunication over stdio is the default for the Serena MCP server, so in the simplest\ncase, you can simply run the `start-mcp-server` command without any additional options.\n \n    <serena> start-mcp-server\n\nFor example, to run the server in stdio mode via `uvx`, you would run:\n\n    uvx --from git+https://github.com/oraios/serena serena start-mcp-server \n \nSee the section [\"Configuring Your MCP Client\"](030_clients) for specific information on how to configure your MCP client (e.g. Claude Code, Codex, Cursor, etc.)\nto use such a launch command.\n\n(streamable-http)=\n### Streamable HTTP Mode\n\nWhen using *Streamable HTTP* mode, you control the server lifecycle yourself,\ni.e. you start the server and provide the client with the URL to connect to it.\n\nSimply provide `start-mcp-server` with the `--transport streamable-http` option and optionally provide the desired port\nvia the `--port` option.\n\n    <serena> start-mcp-server --transport streamable-http --port <port>\n\nFor example, to run the Serena MCP server in streamable HTTP mode on port 9121 using uvx,\nyou would run\n\n    uvx --from git+https://github.com/oraios/serena serena start-mcp-server --transport streamable-http --port 9121\n\nand then configure your client to connect to `http://localhost:9121/mcp`.\n\n**When to use.** Note that Serena is a stateful MCP server, and only one coding project can be active at a time.\nTherefore, starting a single Serena instance and connecting it to multiple clients is only \nappropriate if all clients will be working on the same project.  \nIf you want several agents to work on different projects, making each client/agent start its own server\nin stdio mode is likely the best option.\nSee section [The Project Workflow](040_workflow) for more information on how to manage projects in Serena.\n\nThe legacy SSE transport is also supported (via `--transport sse` with corresponding /sse endpoint), its use is discouraged.\n\n(mcp-args)=\n### MCP Server Command-Line Arguments\n\nThe Serena MCP server supports a wide range of additional command-line options.\nUse the command\n\n    <serena> start-mcp-server --help\n\nto get a list of all available options.\n\nSome useful options include:\n\n  * `--project <path|name>`: specify the project to work on by name or path.\n  * `--project-from-cwd`: auto-detect the project from current working directory     \n    (looking for a directory containing `.serena/project.yml` or `.git` in parent directories and activating the containing directory as the project root, if any).\n    This option is intended for CLI-based agents like Claude Code, Gemini and Codex, which are typically started from within the project directory\n    and which do not change directories during their operation.\n  * `--language-backend JetBrains`: use the Serena JetBrains Plugin as the language backend (overriding the default backend configured in the central configuration)\n  * `--context <context>`: specify the operation [context](contexts) in which Serena shall operate\n  * `--mode <mode>`: specify one or more [modes](modes) to enable (can be passed several times)\n  * `--open-web-dashboard <true|false>`: whether to open the web dashboard on startup (enabled by default)\n\n## Other Commands\n\nSerena provides several other commands in addition to `start-mcp-server`, \nmost of which are related to project setup and configuration.\n\nTo get a list of available commands, run:\n\n    <serena> --help\n\nTo get help on a specific command, run:\n\n    <serena> <command> --help\n\nIn general, add `--help` to any command or sub-command to get information about its usage and available options.\n\nHere are some examples of commands you might find useful:\n\n```bash\n# get help about a sub-command\n<serena> tools list --help\n\n# list all available tools\n<serena> tools list --all\n\n# get detailed description of a specific tool\n<serena> tools description find_symbol\n\n# creating a new Serena project in the current directory \n<serena> project create\n\n# creating and immediately indexing a project\n<serena> project create --index\n\n# indexing the project in the current directory (auto-creates if needed)\n<serena> project index\n\n# run a health check on the project in the current directory\n<serena> project health-check\n\n# check if a path is ignored by the project\n<serena> project is_ignored_path path/to/check\n\n# edit Serena's configuration file\n<serena> config edit\n\n# list available contexts\n<serena> context list\n\n# create a new context\n<serena> context create my-custom-context\n\n# edit a custom context\n<serena> context edit my-custom-context\n\n# list available modes\n<serena> mode list\n\n# create a new mode\n<serena> mode create my-custom-mode\n\n# edit a custom mode\n<serena> mode edit my-custom-mode\n\n# list available prompt definitions\n<serena> prompts list\n\n# create an override for internal prompts\n<serena> prompts create-override prompt-name\n\n# edit a prompt override\n<serena> prompts edit-override prompt-name\n```\n\nExplore the full set of commands and options using the CLI itself!\n"
  },
  {
    "path": "docs/02-usage/025_jetbrains_plugin.md",
    "content": "# The Serena JetBrains Plugin\n\nThe [JetBrains Plugin](https://plugins.jetbrains.com/plugin/28946-serena/) allows Serena to\nleverage the powerful code analysis and editing capabilities of your JetBrains IDE.\n\n```{raw} html\n<p>\n<a href=\"https://plugins.jetbrains.com/plugin/28946-serena/\">\n<img style=\"background-color:transparent;\" src=\"../_static/images/jetbrains-marketplace-button.png\">\n</a>\n</p>\n```\n\nWe recommend the JetBrains plugin as the preferred way of using Serena,\nespecially for users of JetBrains IDEs.\n\n**Purchasing the JetBrains Plugin supports the Serena project.**\nThe proceeds from plugin sales allow us to dedicate more resources to further developing and improving Serena.\n\n\n## Advantages of the JetBrains Plugin\n\nThere are multiple features that are only available when using the JetBrains plugin:\n\n* **External library indexing**: Dependencies and libraries are fully indexed and accessible to Serena\n* **No additional setup**: No need to download or configure separate language servers\n* **Enhanced performance**: Faster tool execution thanks to optimized IDE integration\n* **Multi-language excellence**: First-class support for polyglot projects with multiple languages and frameworks\n* **Enhanced retrieval capabilities**: The plugin supports additional retrieval tools for type hierarchy information as well as fast and reliable documentation/type signature retrieval\n\nWe are also working on additional features like a `move_symbol` tool and debugging-related capabilities that\nwill be available exclusively through the JetBrains plugin.\n\n## Configuring Serena to Use the JetBrains Plugin\n\nAfter installing the plugin, you need to configure Serena to use it.\n\n**Central Configuration**.\n\nEdit the global Serena configuration file located at `~/.serena/serena_config.yml` \n(`%USERPROFILE%\\.serena\\serena_config.yml` on Windows).\nChange the `language_backend` setting as follows:\n\n```yaml\nlanguage_backend: JetBrains\n```\n\n*Note*: you can also use the button `Edit Global Serena Config` in the Serena MCP dashboard to open the config file in your default editor.\n\n**Per-Instance Configuration**.\nThe configuration setting in the global config file can be overridden on a\nper-instance basis by providing the arguments `--language-backend JetBrains` when\nlaunching the Serena MCP server.\n\n(per-project-language-backend)=\n**Per-Project Configuration**.\nYou can also set the language backend on a per-project basis in the project's\n`.serena/project.yml` file:\n\n```yaml\nlanguage_backend: JetBrains\n```\n\nIf set, this overrides the global `language_backend` setting for the session when the project is\nactivated at startup (via the `--project` flag).\n\n:::{important}\nThe language backend is determined once at startup and cannot be changed during a running session.\nIf a project with a different backend is activated after startup, Serena will return an error.\n\nIf you need to work with projects that use different backends, you can either:\n1. Use the `--project` flag to activate the project at startup, which will use its configured backend.\n2. Configure separate MCP server instances (one per backend) in your client.\n:::\n\n**Verifying the Setup**.\nYou can verify that Serena is using the JetBrains plugin by either checking the dashboard, where\nyou will see `Languages:\nUsing JetBrains backend` in the configuration overview.\nYou will also notice that your client will use the JetBrains-specific tools like `jet_brains_find_symbol` and others like it.\n\n## Workflow\n\nHaving installed the plugin in your IDE and having configured Serena to use the JetBrains backend,\nthe general workflow is simple:\n1. Open the project you want to work on in your JetBrains IDE\n2. Open the project's root folder as a project in Serena (see [Project Creation](project-creation-indexing) and [Project Activation](project-activation))\n3. Start using Serena tools as usual\n\nNote that the folder that is open in your IDE and the project's root folder must match.\n\n:::{tip}\nIf you need to work on multiple projects in the same agent session, create a monorepo folder\ncontaining all the projects and open that folder in both Serena and your IDE.\n:::\n\n## Advanced Usage and Configuration\n\n### Using Serena with Multi-Module Projects\n\nJetBrains IDEs support *multi-module projects*, where a project can reference other projects as modules.\nSerena, however, requires that a project is self-contained within a single root folder. \nThere has to be a one-to-one relationship between the project root folder and the folder that is open in the IDE.\n\nTherefore, to get a multi-module setup working with Serena, the recommended approach is to create a **monorepo folder**,\ni.e. a folder that contains all the projects as sub-folders, and open that monorepo folder in both Serena and your IDE.\n\nYou do not necessarily need to physically move your projects into a common parent folder; \nyou can also use symbolic links to achieve the same effect \n(i.e. use `mklink` on Windows or `ln` on Linux/macOS to link the project folders into a common parent folder).\n\n### Using Serena with Windows Subsystem for Linux (WSL)\n\nJetBrains IDEs have built-in support for WSL, allowing you to run the IDE on Windows while working with code in the WSL environment.\nThe Serena JetBrains plugin works seamlessly in this setup as well.\n\n#### Using JetBrains Remote Development \n\nRecommended constellation:\n* Your project is in the WSL file system\n* Serena is run in WSL (not Windows)\n* The IDE has a host component (in WSL) and a client component (on Windows).  \n  The Serena JetBrains plugin should normally be **installed in the host** (not the client) for code intelligence to be accessible.\n\n:::{admonition} Plugin Installation Location\n:class: note\nIf the plugin is already installed, check the options on the button for disabling the plugin.\nChoose the respective options to ensure the correct installation location (i.e. host, removing it from the client if necessary).\n:::\n\n:::{admonition} Using mapped Windows paths in WSL is not recommended!\n:class: warning\nKeeping your project in the Windows file system and accessing it via `/mnt/` in WSL is extremely slow and not recommended.\n:::\n\n**Special Network Setup**.\nIf you are using a special setup where Serena and the IDE are running on different machines,\nmake sure Serena can communicate with the JetBrains plugin.\nYou can configure `jetbrains_plugin_server_address` in your [serena_config.yml](050_configuration) and\nconfigure the listen address of the JetBrains plugin in the IDE via Settings / Tools / Serena\n(e.g. set it to 0.0.0.0 to listen on all interfaces, but be aware of the security implications of doing so).\n\n#### Other WSL Integrations (e.g. WSL interpreter) \n\n* Your project is in the Windows file system\n* WSL is used only for running tools (e.g. using a WSL Python interpreter in the IDE)\n* Serena, the IDE and the plugin are all running on Windows\n\nIn this constellation, no special setup is required.\n\n## Serena Plugin Configuration Options\n\nYou can configure plugin options in the IDE under Settings / Tools / Serena.\n\n * **Listen address** (default: `127.0.0.1`)  \n   the address the plugin's server listens on.  \n   The default will work as long as Serena is running on the same machine (or on a virtual machine using mirrored networking).\n   But if the Serena MCP server is running on a different machine, configure the listen address to ensure that connections are possible.\n   You can use `0.0.0.0` to listen on all interfaces (but be aware of the security implications of doing so).\n\n * **Sync file system before every operation** (default: enabled)  \n   whether to synchronise the file system state before processing requests from Serena.  \n   This is important to ensure that the plugin does not read stale data, but it can have a performance impact, \n   especially when using slow file systems (e.g. WSL file system while the IDE is running on Windows).\n   Note, however, that without synchronisation being forced by the Serena plugin, you will have to ensure synchronisation yourself.\n   Operations that apply changes to files in your project that are *not* made either in the IDE itself or by Serena may not be seen by the IDE. \n   Normally, the IDE synchronises automatically when it has the focus, using file watchers to achieve this (though this may or may not work reliably for the WSL file system). \n   Also, if you are working primarily in another application (e.g. AI chat), the IDE may not have the focus frequently. \n   So when external changes are made to your project, you will have to either give the IDE the focus (if that works) or trigger a sync manually (right-click root folder / Reload from Disk).  \n   Further, note that even an edit made using, for example, Claude Code's internal editing tools would count as an external modification.\n   Only Serena's editing tools are \"JetBrains-aware\" and will tell the IDE to update the state of the edited file.\n   So if you are making AI-based edits using tools other than Serena's tools, do make sure that the lack of synchronisation is not a problem if you decide to disable this option.\n\n## Usage with Other Editors\n\nWe realize that not everyone uses a JetBrains IDE as their main code editor.\nYou can still take advantage of the JetBrains plugin by running a JetBrains IDE instance alongside your\npreferred editor. Most JetBrains IDEs have a free community edition that you can use for this purpose.\nYou just need to make sure that the project you are working on is open and indexed in the JetBrains IDE, \nso that Serena can connect to it.\n"
  },
  {
    "path": "docs/02-usage/030_clients.md",
    "content": "# Connecting Your MCP Client\n\nIn the following, we provide general instructions on how to connect Serena to your MCP-enabled client,\nas well as specific instructions for popular clients.\n\n:::{note}\nThe configurations we provide for particular clients below will run the latest version of Serena\nusing the `stdio` protocol with `uvx`.  \nAdapt the commands to your preferred way of [running Serena](020_running), adding any additional\ncommand-line arguments as needed.\n:::\n\n(clients-general-instructions)=\n## General Instructions\n\nIn general, Serena can be used with any MCP-enabled client.\nTo connect Serena to your favourite client, simply\n\n1. determine how to add a custom MCP server to your client (refer to the client's documentation).\n2. add a new MCP server entry by specifying either\n    * a [run command](start-mcp-server) that allows the client to start the MCP server in stdio mode as a subprocess, or\n    * the URL of the HTTP/SSE endpoint, having started the [Serena MCP server in HTTP/SSE mode](streamable-http) beforehand.\n\nFind concrete examples for popular clients below.\n\nDepending on your needs, you might want to further customize Serena's behaviour by\n* [adding command-line arguments](mcp-args)\n* [adjusting configuration](050_configuration).\n\n**Mode of Operation**.\nNote that some clients have a per-workspace MCP configuration (e.g, VSCode and Claude Code),\nwhile others have a global MCP configuration (e.g. Codex and Claude Desktop).\n\n- In the per-workspace case, you typically want to start Serena with your workspace directory as the project directory \n  and never switch to a different project. This is achieved by specifying the\n  `--project <path>` argument with a single-project [context](#contexts) (e.g. `ide` or `claude-code`).\n- In the global configuration case, you must first activate the project you want to work on, which you can do by asking\n  the LLM to do so (e.g., \"Activate the current dir as project using serena\"). In such settings, the `activate_project`\n  tool is required.\n\n**Tool Selection**.\nWhile you may be able to turn off tools through your client's interface (e.g., in VSCode or Claude Desktop),\nwe recommend selecting your base tool set through Serena's configuration, as Serena's prompts automatically\nadjust based on which tools are enabled/disabled.  \nA key mechanism for this is to use the appropriate [context](#contexts) when starting Serena.\n\n(clients-common-pitfalls)=\n### Common Pitfalls\n\n**Escaping Paths Correctly**.\nNote that if your client configuration uses JSON, special characters (like backslashes) need to be escaped properly.\nIn particular, if you are specifying paths containing backslashes on Windows\n(note that you can also just use forward slashes), be sure to escape them correctly (`\\\\`).\n\n**Discoverability of `uvx`**.\nYour client may not find the `uvx` command, even if it is on your system PATH.\nIn this case, a workaround is to provide the full path to the `uvx` executable.\n\n**Environment Variables**.\nSome language servers may require additional environment variables to be set (e.g. F# on macOS with Homebrew),\nwhich you may need to explicitly add to the MCP server configuration.\nNote that for some clients (e.g. Claude Desktop), the spawned MCP server process may not inherit environment variables that\nare only configured in your shell profile (e.g. `.bashrc`, `.zshrc`, etc.); they would need to be set system-wide instead.\nAn easy fix is to add them explicitly to the MCP server entry.\nFor example, in Claude Desktop and other clients, you can simply add an `env` key to the `serena`\nobject, e.g.\n\n```\n\"env\": {\n    \"DOTNET_ROOT\": \"/opt/homebrew/Cellar/dotnet/9.0.8/libexec\"\n}\n```\n\n## Claude Code\n\nSerena is a great way to make Claude Code both cheaper and more powerful!\n\n**Per-Project Configuration.** To add the Serena MCP server to the current project in the current directory, \nuse this command:\n\n```shell\nclaude mcp add serena -- uvx --from git+https://github.com/oraios/serena serena start-mcp-server --context claude-code --project \"$(pwd)\"\n```\n\nNote:\n  * We use the `claude-code` context to disable unnecessary tools (avoiding duplication\n    with Claude Code's built-in capabilities).\n  * We specify the current directory as the project directory with `--project \"$(pwd)\"`, such \n    that Serena is configured to work on the current project from the get-go, following \n    Claude Code's mode of operation.\n\n**Global Configuration**. Alternatively, use `--project-from-cwd` for user-level configuration that works across all projects:\n\n```shell\nclaude mcp add --scope user serena -- uvx --from git+https://github.com/oraios/serena serena start-mcp-server --context=claude-code --project-from-cwd\n```\n\nWhenever you start Claude Code, Serena will search up from the current directory for `.serena/project.yml` or `.git` markers,\nactivating the containing directory as the project (if any). \nThis mechanism makes it suitable for a single global MCP configuration.\n\n**Maximum Token Efficiency.** To maximize token efficiency, you may want to use Claude Code's \n*on-demand tool loading* feature, which is supported since at least v2.0.74 of Claude Code.\nThis feature avoids sending all tool descriptions to Claude upon startup, thus saving tokens.\nInstead, Claude will search for tools as needed (but there are no guarantees that it will \nsearch optimally, of course).\nTo enable this feature, set the environment variable `ENABLE_TOOL_SEARCH=true`.  \nDepending on your shell, you can also set this on a per-session basis, e.g. using\n```shell\nENABLE_TOOL_SEARCH=true claude\n```\nin bash/zsh, or using\n```shell\nset ENABLE_TOOL_SEARCH=true && claude\n```\nin Windows CMD to launch Claude Code.\n\n## VSCode\n\nWhile serena can be directly installed from the GitHub MCP server registry, we recommend to set it up manually\n(at least for now, until the configuration there has been improved). Just paste the following into\n`<your_project>/.vscode/mcp.json`, or edit the entry after using the option `install into workspace`:\n\n```json\n{\n  \"servers\": {\n    \"oraios/serena\": {\n      \"type\": \"stdio\",\n      \"command\": \"uvx\",\n      \"args\": [\n        \"--from\",\n        \"git+https://github.com/oraios/serena\",\n        \"serena\",\n        \"start-mcp-server\",\n        \"--context\",\n        \"ide\",\n        \"--project\",\n        \"${workspaceFolder}\"\n      ]\n    }\n  },\n  \"inputs\": []\n}\n```\n\n## Codex\n\nSerena works with OpenAI's Codex CLI out of the box, but you have to use the `codex` context for it to work properly. (The technical reason is that Codex doesn't fully support the MCP specifications, so some massaging of tools is required.).\n\nAdd a [run command](020_running) to `~/.codex/config.toml` to configure Serena for all Codex sessions;\ncreate the file if it does not exist.\nFor example, when using `uvx`, add the following section:\n\n```toml\n[mcp_servers.serena]\ncommand = \"uvx\"\nargs = [\"--from\", \"git+https://github.com/oraios/serena\", \"serena\", \"start-mcp-server\", \"--context\", \"codex\"]\n```\n\nAfter codex has started, you need to activate the project, which you can do by saying:\n\n> Call serena.activate_project, serena.check_onboarding_performed and serena.initial_instructions\n\n**If you don't activate the project, you will not be able to use Serena's tools!**\n\nIt is recommend to set this prompt as a [custom prompt](https://developers.openai.com/codex/custom-prompts), so you don't need to type this every time.\n\nThat's it! Have a look at `~/.codex/log/codex-tui.log` to see if any errors occurred.\n\nSerena's dashboard will run if you have not disabled it in the configuration, but due to Codex's sandboxing, the web browser\nmay not open automatically. You can open it manually by going to `http://localhost:24282/dashboard/index.html` (or a higher port, if\nthat was already taken).\n\n> Codex will often show the tools as `failed` even though they are successfully executed. This is not a problem, seems to be a bug in Codex. Despite the error message, everything works as expected.\n\n## Claude Desktop\n\nOn Windows and macOS, there are official [Claude Desktop applications by Anthropic](https://claude.ai/download); for Linux, there is an [open-source\ncommunity version](https://github.com/aaddrick/claude-desktop-debian).\n\nTo configure MCP server settings, go to File / Settings / Developer / MCP Servers / Edit Config,\nwhich will let you open the JSON file `claude_desktop_config.json`.\n\nAdd the `serena` MCP server configuration\n\n```json\n{\n  \"mcpServers\": {\n    \"serena\": {\n      \"command\": \"uvx\",\n      \"args\": [\n        \"--from\",\n        \"git+https://github.com/oraios/serena\",\n        \"serena\",\n        \"start-mcp-server\"\n      ]\n    }\n  }\n}\n```\n\nIf your language server requires specific environment variables to be set (e.g. F# on macOS with Homebrew),\nyou can add them via an `env` key (see [above](#clients-common-pitfalls)).\n\nOnce you have created the new MCP server entry, save the config and then restart Claude Desktop.\n\n:::{attention}\nBe sure to fully quit the Claude Desktop application via File / Exit, as regularly closing the application will just\nminimize it.\n:::\n\nAfter restarting, you should see Serena's tools in your chat interface (notice the small hammer icon).\n\nFor more information on MCP servers with Claude Desktop,\nsee [the official quick start guide](https://modelcontextprotocol.io/quickstart/user).\n\n## JetBrains Junie\n\nOpen Junie, go to the three dots in the top right corner, then Settings / MCP Settings and add Serena to Junie's global\nMCP server configuration:\n\n```json\n{\n  \"mcpServers\": {\n    \"serena\": {\n      \"command\": \"uvx\",\n      \"args\": [\n        \"--from\",\n        \"git+https://github.com/oraios/serena\",\n        \"serena\",\n        \"start-mcp-server\",\n        \"--context\",\n        \"ide\"\n      ]\n    }\n  }\n}\n```\n\nYou will have to prompt Junie to \"Activate the current project using serena's activation tool\" at the\nstart of each session.\n\n## JetBrains AI Assistant\n\nHere you can set up the more convenient per-project MCP server configuration, as the AI assistant supports specifying\nthe launch working directory.\n\nGo to Settings / Tools / AI Assistant / MCP and add a new **local** configuration via the `as JSON` option:\n\n```json\n{\n  \"mcpServers\": {\n    \"serena\": {\n      \"command\": \"uvx\",\n      \"args\": [\n        \"--from\",\n        \"git+https://github.com/oraios/serena\",\n        \"serena\",\n        \"start-mcp-server\",\n        \"--context\",\n        \"ide\",\n        \"--project\",\n        \"$(pwd)\"\n      ]\n    }\n  }\n}\n```\n\nThen make sure to configure the working directory to be the project root.\n\n## Antigravity\n\nAdd this configuration:\n\n```json\n{\n  \"mcpServers\": {\n    \"serena\": {\n      \"command\": \"uvx\",\n      \"args\": [\n        \"--from\",\n        \"git+https://github.com/oraios/serena\",\n        \"serena\",\n        \"start-mcp-server\",\n        \"--context\",\n        \"ide\"\n      ]\n    }\n  }\n}\n```\n\nYou will have to prompt Antigravity's agent to \"Activate the current project using serena's activation tool\" after starting Antigravity in the project directory (once in the first chat enough, all other chat sessions will continue using the same Serena session).\n\n\nUnlike VSCode, Antigravity does not currently support including the working directory in the MCP configuration.\nAlso, the current client will be shown as `none` in Serena's dashboard (Antigravity currently does not fully support the MCP specifications). This is not a problem, all tools will work as expected.\n\n## Other Clients\n\nFor other clients, follow the [general instructions](#clients-general-instructions) above to set up Serena as an MCP server.\n\n### Terminal-Based Clients\n\nThere are many terminal-based coding assistants that support MCP servers, such as\n\n * [Gemini-CLI](https://github.com/google-gemini/gemini-cli), \n * [Qwen3-Coder](https://github.com/QwenLM/Qwen3-Coder),\n * [rovodev](https://community.atlassian.com/forums/Rovo-for-Software-Teams-Beta/Introducing-Rovo-Dev-CLI-AI-Powered-Development-in-your-terminal/ba-p/3043623),\n * [OpenHands CLI](https://docs.all-hands.dev/usage/how-to/cli-mode) and\n * [opencode](https://github.com/sst/opencode).\n\nThey generally benefit from the symbolic tools provided by Serena. You might want to customize some aspects of Serena\nby writing your own context, modes or prompts to adjust it to the client's respective internal capabilities (and your general workflow).\n\nIn most cases, the `ide` context is likely to be appropriate for such clients, i.e. add the arguments `--context ide` \nin order to reduce tool duplication.\n\n### MCP-Enabled IDEs and Coding Clients (Cline, Roo-Code, Cursor, Windsurf, etc.)\n\nMost of the popular existing coding assistants (e.g. IDE extensions) and AI-enabled IDEs themselves support connections\nto MCP Servers. Serena generally boosts performance by providing efficient tools for symbolic operations.\n\nWe generally recommend to use the `ide` context for these integrations by adding the arguments `--context ide` \nin order to reduce tool duplication.\n\n### Local GUIs and Agent Frameworks\n\nOver the last months, several technologies have emerged that allow you to run a local GUI client\nand connect it to an MCP server. The respective applications will typically work with Serena out of the box.\nSome of the leading open source GUI applications are\n\n  * [Jan](https://jan.ai/docs/mcp), \n  * [OpenHands](https://github.com/All-Hands-AI/OpenHands/),\n  * [OpenWebUI](https://docs.openwebui.com/openapi-servers/mcp) and \n  * [Agno](https://docs.agno.com/introduction/playground).\n\nThese applications allow to combine Serena with almost any LLM (including locally running ones) \nand offer various other integrations.\n"
  },
  {
    "path": "docs/02-usage/040_workflow.md",
    "content": "# The Project Workflow\n\nSerena uses a project-based workflow.\nA **project** is simply a directory on your filesystem that contains code and other files\nthat you want Serena to work with.\n\nAssuming that you have project you want to work with (which may initially be empty),\nsetting up a project with Serena typically involves the following steps:\n\n1. **Project creation**: Configuring project settings for Serena (and indexing the project, if desired)\n2. **Project activation**: Making Serena aware of the project you want to work with\n3. **Onboarding**: Getting Serena familiar with the project (creating memories)\n4. **Working on coding tasks**: Using Serena to help you with actual coding tasks in the project\n\n(project-creation-indexing)=\n## Project Creation & Indexing\n\nProject creation is the process of defining fundamental project settings that are relevant to Serena's operation.\n\nYou can create a project either  \n * implicitly, by just activating a directory as a project while already in a conversation; this will use default settings for your project (skip to the next section).\n * explicitly, using the project creation command, or\n\n### Explicit Project Creation\n\nTo explicitly create a project, use the following command while in the project directory:\n\n    <serena> project create [options]\n\nFor instance, when using `uvx`, run\n\n    uvx --from git+https://github.com/oraios/serena serena project create [options]\n\n * For an empty project, you will need to specify the programming language\n   (e.g., `--language python`). \n * For an existing project, the main programming language will be detected automatically,\n   but you can choose to explicitly specify multiple languages by passing the `--language` parameter\n   multiple times (e.g. `--language python --language typescript`).\n * You can optionally specify a custom project name with `--name my-name`.\n * You can immediately index the project after creation with `--index`.\n\n(project-config)=\n#### Project Configuration\n\nAfter creation, you can adjust the project settings in the generated `.serena/project.yml` file\nwithin the project directory.\n\nThe file allows you to configure ...\n  * the set of programming languages for which language servers are spawned (not relevant when using the JetBrains plugin)\n    Note that you can dynamically add/remove language servers while Serena is running via the [Dashboard](060_dashboard).\n  * the [language backend](per-project-language-backend) to use for this project (overriding the global setting)\n  * the encoding used in source files\n  * ignore rules\n  * write access\n  * an initial prompt that shall be passed to the LLM whenever the project is activated\n  * the name by which you want to refer to the project (relevant when telling the LLM to dynamically activate the project)\n  * the set of tools and modes to use by default\n\nFor detailed information on the parameters and possible settings, see the \n[template file](https://github.com/oraios/serena/blob/main/src/serena/resources/project.template.yml).\n\n:::{note}\nMany settings in project.yml *extend* or *override* settings in the global configuration file `serena_config.yml`.\nSo use the project configuration specifically for aspects that apply only to the particular project.\n:::\n\n**Local Overrides**. The project.yml file is intended to be versioned together with the project.\nYou can specify local overrides for the settings in a `project.local.yml` file in the same directory\n(which, by default, is ignored by git). \nAny keys defined therein will override the respective key in `project.yml`.\n\n(indexing)=\n### Indexing\n\n:::{note}\nIndexing is not a relevant operation when using the JetBrains plugin, as indexing is handled by the IDE.\n:::\n\nEspecially for larger project, it can be advisable to index the project after creation, pre-caching \nsymbol information provided by the language server(s). This will avoid delays during the first tool invocation\nthat requires symbol information.\n\nWhile in the project directory, run this command:\n   \n    <serena> project index\n\nIndexing has to be called only once. During regular usage, Serena will automatically update the index whenever files change.\n\n(project-activation)=\n## Project Activation\n   \nProject activation makes Serena aware of the project you want to work with.\nYou can either choose to do this\n * while in a conversation, by telling the LLM to activate a project, e.g.,\n       \n      * \"Activate the project /path/to/my_project\" (for first-time activation with auto-creation)\n      * \"Activate the project my_project\"\n   \n   Note that this option requires the `activate_project` tool to be active, \n   which it isn't in single-project [contexts](contexts) like `ide` or `claude-code` *if* a project is provided at startup.\n   (The tool is deactivated, because we assume that in these contexts, user will only work on the single, open project and have\n   no need to switch it.)\n\n * when the MCP server starts, by passing the project path or name as a command-line argument\n   (e.g. when using a single-project mode like `ide` or `claude-code`): `--project <path|name>`\n\nWhen working with the JetBrains plugin, be sure to have the same project folder open as a project in your IDE,\ni.e. the folder that is activated in Serena should correspond to the root folder of the project in your IDE.\n\n## Onboarding & Memories\n\nBy default, Serena will perform an **onboarding process** when\nit is started for the first time for a project.\nThe goal of the onboarding is for Serena to get familiar with the project\nand to store memories, which it can then draw upon in future interactions.\n\nIn general, **memories** provide a way for Serena to store and retrieve \ninformation about the project, relevant conventions, and other relevant aspects.\n\nFor more information on this, including how to manage\nor disable these features, see [Memories & Onboarding](045_memories).\n\n\n## Preparing Your Project\n\nWhen using Serena to work on your project, it can be helpful to follow a few best practices.\n\n### Structure Your Codebase\n\nSerena uses the code structure for finding, reading and editing code. This means that it will\nwork well with well-structured code but may perform poorly on fully unstructured one (like a \"God class\"\nwith enormous, non-modular functions).\n\nFurthermore, for languages that are not statically typed, the use of type annotations (if supported) \nare highly beneficial.\n\n### Start from a Clean State\n\nIt is best to start a code generation task from a clean git state. Not only will\nthis make it easier for you to inspect the changes, but also the model itself will\nhave a chance of seeing what it has changed by calling `git diff` and thereby\ncorrect itself or continue working in a followup conversation if needed.\n\n### Use Platform-Native Line Endings\n\n**Important**: since Serena will write to files using the system-native line endings\nand it might want to look at the git diff, it is important to\nset `git config core.autocrlf` to `true` on Windows.\nWith `git config core.autocrlf` set to `false` on Windows, you may end up with huge diffs\ndue to line endings only. \nIt is generally a good idea to globally enable this git setting on Windows:\n\n```shell\ngit config --global core.autocrlf true\n```\n\n### Logging, Linting, and Automated Tests\n\nSerena can successfully complete tasks in an _agent loop_, where it iteratively\nacquires information, performs actions, and reflects on the results.\nHowever, Serena cannot use a debugger; it must rely on the results of program executions,\nlinting results, and test results to assess the correctness of its actions.\nTherefore, software that is designed to meaningful interpretable outputs (e.g. log messages)\nand that has a good test coverage is much easier to work with for Serena.\n\nWe generally recommend to start an editing task from a state where all linting checks and tests pass.\n\n## Multiple Projects, Multiple Agents\n\nThere are several ways in which you might want to work with multiple projects simultaneously.\n\n### A Single Agent Editing Multiple Projects Simultaneously\n\nIf fulfilling a task requires a single agent to edit code in multiple projects, the recommended approach is to create a **monorepo folder**,\ni.e. a folder that contains all the projects as sub-folders, and open that monorepo folder as a project in Serena.\nYou may also use symbolic links to create a monorepo folder if the projects are located in different places on your filesystem.\n\nIf several languages are used across the projects, specify all of them as needed when using the LSP backend;\nFor JetBrains mode, make sure that your IDE is configured to work with all the languages used across the projects (e.g. by installing the respective language plugins).\n\n(query-projects)=\n### Reading from External Projects\n\nIf, while working on a project, you want Serena to be able to read code or other information from another project (e.g. a library or otherwise related project), \nthis can be enabled via the `query_project` tool.\nProvided that the project you want to query is known to Serena (i.e. you have created it as described above),\nthe `query_project` tool allows the agent to query files and symbolic information from that project.\n\nTo enable this tool, [activate the mode](modes) `query-projects`.\nThis also enables a second tool for listing projects that can be queried.\n\nDepending on the language backend being used, the management of resources for the external projects varies:\n\n* When using the JetBrains backend, make sure that every project for which you want symbolic queries to work is open in an IDE instance. \n* When using the LSP backend, executing symbolic tools via the query tool requires that Serena's **Project Server** be started,\n  which will automatically spawn the necessary language servers for the projects that are queried.\n\n  To start the server, run\n\n      <serena> start-project-server\n\n  where `<serena>` is your way of running Serena. For example, when using `uvx`, run\n\n      uvx --from git+https://github.com/oraios/serena serena start-project-server\n\n### Multiple Agents Accessing a Single Serena Instance\n\nIf you want multiple agents to access the same project via a single Serena instance,\ni.e. you do not want several instances of Serena (including its language servers) to be running,\nyou can achieve this by [starting the Serena MCP server in HTTP mode](streamable-http)\nand connecting all client agents to the same HTTP endpoint.\nThe agents will then share the resources of the single Serena instance.\n\n### Multiple Agents Working on Different Projects\n\nFor this use case, simply run a separate instance of Serena for each project, which naturally\noccurs when Serena is started by the MCP client in stdio mode."
  },
  {
    "path": "docs/02-usage/045_memories.md",
    "content": "# Memories & Onboarding\n\nSerena provides the functionality of a fully featured agent, and a useful aspect of this is Serena's memory system.\nDespite its simplicity, we received positive feedback from many users who tend to combine it with their\nagent's internal memory management (e.g., `AGENTS.md` files).\n\n## Memories\n\nMemories are simple, human-readable Markdown files that both you and\nyour agent can create, read, and edit. \n\nSerena differentiates between \n  * **project-specific memories**, which are stored in the `.serena/memories/` directory within your project folder, and\n  * **global memories**, which are shared across all projects and, by default, are stored in `~/.serena/memories/global/`\n\nThe LLM is informed about the existence of memories and instructed to read them when appropriate, \ninferring appropriateness from the file name.\nWhen the agent starts working on a project, it receives the list of available memories. \nThe agent should be instructed to update memories by the user when appropriate.\n\n### Organizing Memories\n\nMemories can be organized into **topics** by using `/` in the memory name (e.g. `modules/frontend`).\nThe structure is mapped to the file system, where topics correspond to subdirectories.\nThe `list_memories` tool can filter by topic, allowing the agent to explore even large numbers of memories in a structured way.\n\n(global-memories)=\n### Global Memories\n\nGlobal memories use the top-level topic `global`, i.e. whenever a memory name starts with `global/`, \nit is stored in the global memories directory and is shared across all projects.\n\nBy default, deletion and editing of global memories is allowed.\nIf you want to protect them from accidental modification by the agent,\nyou can add regex patterns to `read_only_memory_patterns` in your global or\nproject-level [configuration](050_configuration). For example, setting \"global/.*\" will mark all global memories as read-only. The agent will be informed which memories are read-only.\n\nSince global memories are not versioned alongside your project files,\nit can be helpful to track global memories with git (i.e. to make `~/.serena/memories/` a git repository)\nin order to have a history of changes and the possibility to revert them if needed.\n\n### Manually Editing Memories\n\nYou may edit memories directly in the file system, using your preferred text editor or IDE.\nAlternatively, access them via the [Serena Dashboard](060_dashboard), which provides a graphical interface for\nviewing, creating, editing, and deleting memories while Serena is running.\n\n(onboarding)=\n## Onboarding\n\nBy default, Serena performs an **onboarding process** when it encounters a project\nfor the first time (i.e., when no project memories exist yet).\nThe goal of the onboarding is for Serena to get familiar with the project —\nits structure, build system, testing setup, and other essential aspects —\nand to store this knowledge as memories for future interactions.\n\nIn further project activations, Serena will check whether onboarding was already\nperformed by looking for existing project memories and will skip the onboarding\nprocess if memories are found.\n\n### How Onboarding Works\n\n1. When a project is activated, Serena checks whether onboarding was already\n   performed (by checking if any memories exist).\n2. If no memories are found, Serena triggers the onboarding process, which\n   reads key files and directories to understand the project.\n3. The gathered information is written into project-specific memory files (see above).\n\n### Tips for Onboarding\n\n- **Context usage**: The onboarding process will read a lot of content from the project,\n  filling up the context window. It is therefore advisable to **switch to a new conversation**\n  once the onboarding is complete.\n- **LLM failures**: If an LLM fails to complete the onboarding and does not actually\n  write the respective memories to disk, you may need to ask it to do so explicitly.\n- **Review the results**: After onboarding, we recommend having a quick look at the\n  generated memories and editing them or adding new ones as needed.\n\n## Disabling Memories and Onboarding\n\nIf you do not require the functionality described in this section, you can selectively disable it.\n\n * To disable all memory related tools (including onboarding), adding `no-memories` to the `base_modes`\n   in Serena's [global configuration](050_configuration).\n * Similarly, to disable only onboarding, add `no-onboarding` to the `base_modes`.\n"
  },
  {
    "path": "docs/02-usage/050_configuration.md",
    "content": "# Configuration\n\nSerena is very flexible in terms of configuration. While for most users, the default configurations will work,\nyou can fully adjust it to your needs.\n\nYou can disable tools, change Serena's fundamental instructions\n(what we denote as the `system_prompt`), adjust the output of tools that just provide a prompt, \nand even adjust tool descriptions.\n\nSerena is configured in using a multi-layered approach:\n\n * **global configuration** (`serena_config.yml`, see below)\n * **project configuration** (`project.yml`, see [Project Configuration](project-config))\n * **contexts and modes** for composable configuration, which can be enabled on a case-by-case basis (see below)\n * **command-line parameters** passed to the `start-mcp-server` server command (overriding/extending configured settings)  \n   See [MCP Server Command-Line Arguments](mcp-args) for further information.  \n\n(global-config)=\n## Global Configuration\n\nThe global configuration file allows you to change general settings and defaults that will apply to all projects unless overridden.\n\n### Settings\n\nSome of the configurable settings include:\n  * the language backend to use by default (i.e., the JetBrains plugin or language servers);\n    this can also be [overridden per project](per-project-language-backend)\n  * UI settings affecting the [Serena Dashboard and GUI tool](060_dashboard.md)\n  * the set of tools to enable/disable by default\n  * the set of modes to use by default\n  * tool execution parameters (timeout, max. answer length)\n  * global ignore rules\n  * logging settings\n  * advanced settings specific to individual language servers (see [below](ls-specific-settings))\n\nThe global configuration settings apply to all projects.\nSome of the settings it contains can, however, be *extended* or *overridden* in project-specific settings, contexts and modes.\n\nFor detailed information on the parameters and possible settings, see the\n[template file](https://github.com/oraios/serena/blob/main/src/serena/resources/serena_config.template.yml).\n\n### Accessing the Configuration File\n\nThe configuration file is auto-created when you first run Serena. It is stored in your user directory:\n  * Linux/macOS/Git-Bash: `~/.serena/serena_config.yml`\n  * Windows (CMD/PowerShell): `%USERPROFILE%\\.serena\\serena_config.yml`\n\nYou can access it\n  * through [Serena's dashboard](060_dashboard) while Serena is running (use the respective button) \n  * directly, using your favourite text editor\n  * using the command\n\n    ```shell\n    <serena> config edit\n    ```\n\n    where `<serena>` is [your way of running Serena](020_running).\n\n## Modes and Contexts\n\nSerena's behaviour and toolset can be adjusted using contexts and modes.\nThese allow for a high degree of customization to best suit your workflow and the environment Serena is operating in.\n\n(contexts)=\n### Contexts\n\nA **context** defines the general environment in which Serena is operating.\nIt influences the initial system prompt and the set of available tools.\nA context is set at startup when launching Serena (e.g., via CLI options for an MCP server or in the agent script) and cannot be changed during an active session.\n\nSerena comes with pre-defined contexts:\n\n* `desktop-app`: Tailored for use with desktop applications like Claude Desktop. This is the default.\n  The full set of Serena's tools is provided, as the application is assumed to have no prior coding-specific capabilities.\n* `claude-code`: Optimized for use with Claude Code, it disables tools that would duplicate Claude Code's built-in capabilities.\n* `codex`: Optimized for use with OpenAI Codex.\n* `ide`: Generic context for IDE assistants/coding agents, e.g. VSCode, Cursor, or Cline, focusing on augmenting existing capabilities.\n  Basic file operations and shell execution are assumed to be handled by the assistant's own capabilities.\n* `agent`: Designed for scenarios where Serena acts as a more autonomous agent, for example, when used with Agno.\n\nChoose the context that best matches the type of integration you are using.\n\nFind the concrete definitions of the above contexts [here](https://github.com/oraios/serena/tree/main/src/serena/resources/config/contexts).\n\nNote that the contexts `ide` and `claude-code` are **single-project contexts** (defining `single_project: true`).\nFor such contexts, if a project is provided at startup, the set of tools is limited to those required by the project's\nconcrete configuration, and other tools are excluded completely, allowing the set of tools to be minimal.\nTools explicitly disabled by the project will not be available at all. Since changing the active project\nceases to be a relevant operation in this case, the project activation tool is disabled.\n\nWhen launching Serena, specify the context using `--context <context-name>`.\nNote that for cases where parameter lists are specified (e.g. Claude Desktop), you must add two parameters to the list.\n\nIf you are using a local server (such as Llama.cpp) which requires you to use OpenAI-compatible tool descriptions, use context `oaicompat-agent` instead of `agent`.\n\nYou can manage contexts using the `context` command,\n\n    <serena> context --help\n    <serena> context list\n    <serena> context create <context-name>\n    <serena> context edit <context-name>\n    <serena> context delete <context-name>\n\nwhere `<serena>` is [your way of running Serena](020_running).\n\n(modes)=\n### Modes\n\nModes further refine Serena's behavior for specific types of tasks or interaction styles. Multiple modes can be active simultaneously, allowing you to combine their effects. Modes influence the system prompt and can also alter the set of available tools by excluding certain ones.\n\nExamples of built-in modes include:\n\n* `planning`: Focuses Serena on planning and analysis tasks.\n* `editing`: Optimizes Serena for direct code modification tasks.\n* `interactive`: Suitable for a conversational, back-and-forth interaction style.\n* `one-shot`: Configures Serena for tasks that should be completed in a single response, often used with `planning` for generating reports or initial plans.\n* `no-onboarding`: Skips the initial onboarding process if it's not needed for a particular session but retains the memory tools (assuming initial memories were created externally).\n* `onboarding`: Focuses on the project onboarding process.\n* `no-memories`: Disables all memory tools (and tools building on memories such as onboarding tools)\n* `query-projects`: Enables tools for querying other Serena projects (without activating them); see section [Reading from External Projects](query-projects) \n\nFind the concrete definitions of these modes [here](https://github.com/oraios/serena/tree/main/src/serena/resources/config/modes).\n\nActive modes are configured in (from lowest to highest precedence):\n  * the global configuration file (`serena_config.yml`)\n  * the project configuration file (`project.yml`)\n  * at startup via command-line parameters\n\nThe two former sources define both **base modes** and **default modes**.\nUltimately, the active modes are the union of base modes and default modes (after applying all overrides).\nCommand-line parameters override default modes but not base modes.\nBase modes should thus be used to define modes that you always want to be active, regardless of command-line parameters.\n\nCommand-line parameters for overriding default modes:\nWhen launching the MCP sever, specify modes using `--mode <mode-name>`; multiple modes can be specified, e.g. `--mode planning --mode no-onboarding`.\n\n:::{important}\nBy default, Serena activates the two modes `interactive` and `editing` (as defined in the global configuration).\n\nAs soon as you start to specify modes via the command line, only the modes you explicitly specify will be active, however.\nTherefore, if you want to keep the default modes, you must specify them as well.  \nFor example, to add mode `no-memories` to the default behaviour, specify\n```shell\n--mode interactive --mode editing --mode no-memories\n```\n\nIf you want to keep certain modes as always active, regardless of command-line parameters, \ndefine them as *base modes* in the global or project configuration.\n:::\n\nModes can also be _switched dynamically_ during a session. \nYou can instruct the LLM to use the `switch_modes` tool to activate a different set of modes (e.g., \"Switch to planning and one-shot modes\").\nLike command-line parameters, this only affects default modes, not base modes (which remain active).\n\n:::{note}\n**Mode Compatibility**: While you can combine modes, some may be semantically incompatible (e.g., `interactive` and `one-shot`). \nSerena currently does not prevent incompatible combinations; it is up to the user to choose sensible mode configurations.\n:::\n\nYou can manage modes using the `mode` command,\n\n    <serena> mode --help\n    <serena> mode list\n    <serena> mode create <mode-name>\n    <serena> mode edit <mode-name>\n    <serena> mode delete <mode-name>\n\nwhere `<serena>` is [your way of running Serena](020_running).\n\n## Advanced Configuration\n\nFor advanced users, Serena's configuration can be further customized.\n\n### Serena Data Directory\n\nThe Serena user data directory (where configuration, language server files, logs, etc. are stored) defaults to `~/.serena`.\nYou can change this location by setting the `SERENA_HOME` environment variable to your desired path.\n\n### Per-Project Serena Folder Location\n\nBy default, each project stores its Serena data (memories, caches, etc.) in a `.serena` folder inside the project root.\nYou can customize this location globally via the `project_serena_folder_location` setting in `serena_config.yml`.\n\nThe setting supports two placeholders:\n\n| Placeholder          | Description                                     |\n|----------------------|-------------------------------------------------|\n| `$projectDir`        | The absolute path to the project root directory |\n| `$projectFolderName` | The name of the project folder                  |\n\n**Examples:**\n\n```yaml\n# Default: data stored inside the project directory\nproject_serena_folder_location: \"$projectDir/.serena\"\n\n# Central location: all project data under a shared directory\nproject_serena_folder_location: \"/projects-metadata/$projectFolderName/.serena\"\n```\n\nWhen a project is loaded, Serena uses the following fallback logic:\n1. Check if a `.serena` folder exists at the configured path.\n2. If not, check if one exists in the project root (default/legacy location).\n3. If neither exists, create the folder at the configured path.\n\nThis ensures backward compatibility: existing projects that already have a `.serena` folder in the project root will continue to work, even after changing the `project_serena_folder_location` setting.\n\n(ls-specific-settings)=\n### Language Server-Specific Settings\n\n:::{note} \n**Advanced Users Only**: The settings described in this section are intended for advanced users who need to fine-tune language server behavior.\nMost users will not need to adjust these settings.\n:::\n\nUnder the key `ls_specific_settings` in `serena_config.yml`, you can you pass per-language, \nlanguage server-specific configuration.\n\nStructure:\n\n```yaml\nls_specific_settings:\n  <language>:\n    # language-server-specific keys\n```\n\n:::{attention}\nMost settings are currently undocumented. Please refer to the \n[source code of the respective language server](https://github.com/oraios/serena/tree/main/src/solidlsp/language_servers) \nimplementation to determine supported settings.\n:::\n\n#### Overriding the Language Server Path\n\nSome language servers, particularly those that use a single core path for the language server (e.g. the main executable),\nsupport overriding that path via the `ls_path` setting.\nTherefore, if you have installed the language server yourself and want to use your installation \ninstead of Serena's managed installation, you can set the `ls_path` setting as follows:\n\n```yaml\nls_specific_settings:\n  <language>:\n    ls_path: \"/path/to/language-server\"\n```\n\nThis is supported by all language servers deriving their dependency provider from  `LanguageServerDependencyProviderSinglePath`.\nCurrently, this includes the following languages: `bash`, `clojure`, `cpp`, `kotlin`, `markdown`, `php`, `php_phpactor`, `python`, `rust`, `toml`, `typescript`, `yaml`.\nWe will add support for more languages over time.\n\n#### C# (Roslyn Language Server)\n\nSerena uses [Microsoft's Roslyn Language Server](https://github.com/dotnet/roslyn) for C# support.\n\n**Runtime Requirements:**\n\n- .NET 10 or higher is required. If not found in PATH, Serena automatically installs it using Microsoft's official install scripts.\n- The Roslyn Language Server is automatically downloaded from NuGet.org.\n\n**Supported Platforms:**\n\nAutomatic download is supported for: Windows (x64, ARM64), macOS (x64, ARM64), Linux (x64, ARM64).\n\n**Configuration:**\n\nThe `runtime_dependencies` setting allows you to override the download URLs for the Roslyn Language Server. This is useful if you need to use a private package mirror or a specific version.\n\nExample configuration to override the language server download URL:\n\n```yaml\nls_specific_settings:\n  csharp:\n    runtime_dependencies:\n      - id: \"CSharpLanguageServer\"\n        platform_id: \"linux-x64\"  # or win-x64, win-arm64, osx-x64, osx-arm64, linux-arm64\n        url: \"https://your-mirror.example.com/roslyn-language-server.linux-x64.5.5.0-2.26078.4.nupkg\"\n        package_version: \"5.5.0-2.26078.4\"\n```\n\nAvailable fields for `runtime_dependencies` entries:\n\n| Field             | Description                                                                 |\n| ----------------- | --------------------------------------------------------------------------- |\n| `id`              | Dependency identifier (use `CSharpLanguageServer`)                          |\n| `platform_id`     | Target platform: `win-x64`, `win-arm64`, `osx-x64`, `osx-arm64`, `linux-x64`, `linux-arm64` |\n| `url`             | Download URL for the NuGet package                                          |\n| `package_version` | Package version string                                                      |\n| `extract_path`    | Path within the package to extract (default: `tools/net10.0/<platform>`)    |\n\nNotes:\n- Only specify the platforms you want to override; others will use the defaults.\n- The language server package is a `.nupkg` file (ZIP format) downloaded from NuGet.org by default.\n- If you have .NET 10+ already installed, Serena will use your system installation.\n\n#### Go (`gopls`)\n\nSerena forwards `ls_specific_settings.go.gopls_settings` to `gopls` as LSP `initializationOptions` when the Go language server is started.\n\nExample: enable build tags and set a build environment:\n\n```yaml\nls_specific_settings:\n  go:\n    gopls_settings:\n      buildFlags:\n        - \"-tags=foo\"\n      env:\n        GOOS: \"linux\"\n        GOARCH: \"amd64\"\n        CGO_ENABLED: \"0\"\n```\n\nNotes:\n- To enable multiple tags, use `\"-tags=foo,bar\"`.\n- `gopls_settings.env` values are strings.\n- `GOFLAGS` (from the environment you start Serena in) may also affect the Go build context. Prefer `buildFlags` for tags.\n- Build context changes are only picked up when `gopls` starts. After changing `gopls_settings` (or relevant env vars like `GOFLAGS`), restart the Serena process (or server) that hosts the Go language server, or use your client's \"Restart language server\" action if it causes `gopls` to restart.\n\n#### Java (`eclipse.jdt.ls`)\n\nThe following settings are supported for the Java language server:\n\n| Setting | Default | Description |\n|---|---|---|\n| `maven_user_settings` | `~/.m2/settings.xml` | Path to Maven `settings.xml` |\n| `gradle_user_home` | `~/.gradle` | Path to Gradle user home directory |\n| `gradle_wrapper_enabled` | `false` | Use the project's Gradle wrapper (`gradlew`) instead of the bundled Gradle distribution. Enable this for projects with custom plugins or repositories. |\n| `gradle_java_home` | `null` | Path to the JDK used by Gradle. When unset, Gradle uses the bundled JRE. |\n| `use_system_java_home` | `false` | Use the system's `JAVA_HOME` environment variable for JDTLS itself. Enable this if your project requires a specific JDK vendor or version for Gradle's JDK checks. |\n\nExample for a project with custom Gradle plugins and JDK requirements:\n\n```yaml\nls_specific_settings:\n  java:\n    gradle_wrapper_enabled: true\n    use_system_java_home: true\n```\n\n#### Kotlin\n\nSerena uses [JetBrains' Kotlin Language Server](https://github.com/Kotlin/kotlin-lsp) for Kotlin support.\n\n**Runtime Requirements:**\n\n- Java 21 or higher is required. If not found, Serena automatically downloads an appropriate JRE.\n- The Kotlin Language Server is automatically downloaded from JetBrains' CDN.\n\n**Configuration:**\n\n```yaml\nls_specific_settings:\n  kotlin:\n    ls_path: \"/path/to/kotlin-lsp.sh\"        # Override the Kotlin Language Server executable\n    kotlin_lsp_version: \"261.13587.0\"         # Override the Kotlin Language Server version\n    jvm_options: \"-Xmx4G -XX:+UseG1GC\"       # JVM options (default: -Xmx2G). Set to \"\" to disable.\n```\n\n#### Luau\n\nSerena uses [`luau-lsp`](https://github.com/JohnnyMorganz/luau-lsp) for Luau support.\n\n**Runtime Requirements:**\n\n- `luau-lsp` is used from PATH if available.\n- Otherwise, Serena downloads the pinned `luau-lsp` release for the current platform.\n\n**Configuration:**\n\n```yaml\nls_specific_settings:\n  luau:\n    ls_path: \"/path/to/luau-lsp\"            # Optional: override the language server executable\n    platform: \"roblox\"                      # \"roblox\" (default) or \"standard\"\n    roblox_security_level: \"PluginSecurity\" # Roblox only: None, PluginSecurity, LocalUserSecurity, RobloxScriptSecurity\n```\n\nNotes:\n- In `roblox` mode, Serena downloads Roblox definitions and Roblox API docs and passes them to `luau-lsp`.\n- In `standard` mode, Serena skips Roblox definitions and only downloads the standard Luau docs bundle.\n\n#### Pascal (`pasls`)\n\nSerena uses [pasls](https://github.com/genericptr/pascal-language-server) (Pascal Language Server) for Pascal/Free Pascal support.\n\n**Language Server Installation:**\n\n1. If `pasls` is found in your system PATH, Serena uses it directly\n2. Otherwise, Serena automatically downloads a prebuilt binary from GitHub releases\n\nSupported platforms for automatic download: Linux (x64, arm64), macOS (x64, arm64), Windows (x64).\n\n**Auto-Update:**\n\nSerena automatically checks for pasls updates every 24 hours. Updates include:\n- SHA256 checksum verification before installation\n- Atomic update with rollback on failure\n- Windows file locking detection (defers update if pasls is in use)\n\n**Configuration:**\n\nConfigure pasls via `ls_specific_settings.pascal` in `serena_config.yml`:\n\n| Setting          | Description                                                                 |\n| ---------------- | --------------------------------------------------------------------------- |\n| `pp`             | Path to FPC compiler driver (must be `fpc` or `fpc.exe`, not `ppc386.exe`)  |\n| `fpcdir`         | Path to FPC source directory                                                |\n| `lazarusdir`     | Path to Lazarus directory (required for LCL projects)                       |\n| `fpc_target`     | Target OS override (e.g., `Win32`, `Win64`, `Linux`)                        |\n| `fpc_target_cpu` | Target CPU override (e.g., `i386`, `x86_64`, `aarch64`)                     |\n\nExample configuration:\n\n```yaml\nls_specific_settings:\n  pascal:\n    pp: \"D:/laz32/fpc/bin/i386-win32/fpc.exe\"\n    fpcdir: \"D:/laz32/fpcsrc\"\n    lazarusdir: \"D:/laz32/lazarus\"\n```\n\nNotes:\n- The `pp` setting is the most important for hover and navigation to work correctly.\n- Use the FPC compiler driver (`fpc`/`fpc.exe`), not backend compilers like `ppc386.exe`.\n- These settings are passed as environment variables to the pasls process.\n\n### Custom Prompts\n\nAll of Serena's prompts can be fully customized.\nWe define prompt as jinja templates in yaml files, and you can inspect our default prompts [here](https://github.com/oraios/serena/tree/main/src/serena/resources/config/prompt_templates).\n\nTo override a prompt, simply add a .yml file to the `prompt_templates` folder in your Serena data directory\nwhich defines the prompt with the same name as the default prompt you want to override.\nFor example, to override the `system_prompt`, you could create a file `~/.serena/prompt_templates/system_prompt.yml` (assuming default Serena data folder location) \nwith content like:\n\n```yaml\nprompts:\n  system_prompt: |\n    Whatever you want ...\n```\n\nIt is advisable to use the default prompt as a starting point and modify it to suit your needs.\n"
  },
  {
    "path": "docs/02-usage/060_dashboard.md",
    "content": "# The Dashboard and GUI Tool\n\nSerena comes with built-in tools for monitoring and managing the current session:\n\n* the **web-based dashboard** (enabled by default)\n  \n  The dashboard provides detailed information on your Serena session, the current configuration and provides access to logs.\n  Some settings (e.g. the current set of active programming languages) can also be directly modified through the dashboard.\n\n  The dashboard is supported on all platforms.\n  \n  By default, it will be accessible at `http://localhost:24282/dashboard/index.html`,\n  but a higher port may be used if the default port is unavailable/multiple instances are running.\n\n  **We recommend always enabling the dashboard**. If you don't want the browser to open automatically,\n  you can disable it while still keeping the dashboard running in the background (see below).\n\n* the **GUI tool** (disabled by default)\n  \n  The GUI tool is a native application window which displays logs.\n  It furthermore allows you to shut down the agent and to access the dashboard's URL (if it is running). \n\n  This is mainly supported on Windows, but it may also work on Linux; macOS is unsupported.\n\nBoth can be configured in Serena's [configuration](050_configuration) file (`serena_config.yml`).\nIf enabled, they will automatically be opened as soon as the Serena agent/MCP server is started.\nFor the dashboard, this can be disabled if desired (see below).\n\n## Disabling Automatic Browser Opening\n\nIf you prefer not to have the dashboard open automatically (e.g., to avoid focus stealing), you can disable it\nby setting `web_dashboard_open_on_launch: False` in your `serena_config.yml` or by passing `--open-web-dashboard False`\nto `start-mcp-server` CLI command.\n\nWhen automatic opening is disabled, you can still access the dashboard by:\n* asking the LLM to \"open the Serena dashboard\", which will open the dashboard in your default browser\n  (the tool `open_dashboard` is enabled for this purpose, provided that the dashboard is active, \n  not opened by default and the GUI tool, which can provide the URL, is not enabled)\n* navigating directly to the URL (see above)\n"
  },
  {
    "path": "docs/02-usage/065_logs.md",
    "content": "# Logs\n\nIt can be vital to understand what is happening in Serena, especially when something goes wrong. \n\nYou can access Serena's live logs via \n  * the [Serena dashboard](060_dashboard) (tab \"Logs\")\n  * the [GUI tool](060_dashboard).\n\nAdditionally, logs are persisted in the Serena home directory, which, by default, is located at\n  * `%USERPROFILE%\\.serena\\logs` on Windows\n  * `~/.serena/logs` on Linux and macOS.\n\nYou can adjust the log level via the [global configuration](global-config).\nYou additionally have the option of enabling full tracing of language server communication (mostly for development purposes).\n"
  },
  {
    "path": "docs/02-usage/070_security.md",
    "content": "# Security Considerations\n\nAs fundamental abilities for a coding agent, Serena contains tools for executing shell commands and modifying files.\nTherefore, if the respective tool calls are not monitored or restricted (and execution takes place in a sensitive environment), \nthere is a risk of unintended consequences.\n\nTherefore, to reduce the risk of unintended consequences when using Serena, it is recommended to\n  * back up your work regularly (e.g. use a version control system like Git),\n  * monitor tool executions carefully (e.g. via your MCP client, provided that it supports it),\n  * consider enabling read-only mode for your project (set `read_only: True` in project.yml) if you only want to analyze code without modifying it,\n  * restrict the set of allowed tools via the [configuration](050_configuration),\n  * use a sandboxed environment for running Serena (e.g. by [using Docker](docker)).\n"
  },
  {
    "path": "docs/02-usage/999_additional-usage.md",
    "content": "# Additional Usage Pointers\n\n## Prompting Strategies\n\nWe found that it is often a good idea to spend some time conceptualizing and planning a task\nbefore actually implementing it, especially for non-trivial task. This helps both in achieving\nbetter results and in increasing the feeling of control and staying in the loop. You can\nmake a detailed plan in one session, where Serena may read a lot of your code to build up the context,\nand then continue with the implementation in another (potentially after creating suitable memories).\n\n## Running Out of Context\n\nFor long and complicated tasks, or tasks where Serena has read a lot of content, you\nmay come close to the limits of context tokens. In that case, it is often a good idea to continue\nin a new conversation. Serena has a dedicated tool to create a summary of the current state\nof the progress and all relevant info for continuing it. You can request to create this summary and\nwrite it to a memory. Then, in a new conversation, you can just ask Serena to read the memory and\ncontinue with the task. In our experience, this worked really well. On the up-side, since in a\nsingle session there is no summarization involved, Serena does not usually get lost (unlike some\nother agents that summarize under the hood), and it is also instructed to occasionally check whether\nit's on the right track.\n\nSerena instructs the LLM to be economical in general, so the problem of running out of context\nshould not occur too often, unless the task is very large or complicated.\n\n## Serena and Git Worktrees\n\n[git-worktree](https://git-scm.com/docs/git-worktree) can be an excellent way to parallelize your work. More on this in [Anthropic: Run parallel Claude Code sessions with Git worktrees](https://docs.claude.com/en/docs/claude-code/common-workflows#run-parallel-claude-code-sessions-with-git-worktrees).\n\nWhen it comes to serena AND git-worktree AND larger projects (that take longer to index), \nthe recommended way is to COPY your `$ORIG_PROJECT/.serena/cache` to `$GIT_WORKTREE/.serena/cache`. \nPerform [pre-indexing of your project](indexing) to avoid having to re-index per each worktree you create. \n"
  },
  {
    "path": "docs/03-special-guides/000_intro.md",
    "content": "# Special Guides\n\nThis section contains special guides for certain topics that require more in-depth explanations."
  },
  {
    "path": "docs/03-special-guides/cpp_setup.md",
    "content": "# C/C++ Setup Guide\n\nThis guide explains how to prepare a C/C++ project so that Serena can provide reliable code intelligence via clangd or ccls language servers.\nThis is only necessary if you use the language server variant of Serena, for users of the Serena JetBrains plugin no setup is required\nand the limitations described below do not apply.\n\n---\n\n## General\n\nSerena supports two C/C++ language servers, clangd (default) and ccls.\nBoth have their pros and cons and require a properly configured `compile_commands.json` \nfor cross-file reference finding, see below for details.\n\nYour project must have a `compile_commands.json` file at the repository root. \nThis file is essential for correct parsing and cross-file reference finding.\n\n\n## compile_commands.json Requirements\n\nFor reliable cross-file reference finding with clangd, your `compile_commands.json` must:\n\n1. **Include proper C++ standard flags** (e.g., `-std=c++17`)\n2. **Include all necessary include paths** (`-I` flags)\n\n---\n\n### With clangd\n\nSerena automatically downloads and manages clangd. Since clangd does not properly work with relative paths in `compile_commands.json`,\nSerena will detect them and transform them into absolute paths automatically (writing a new `compile_commands.json` file), if needed.\n\n#### Customizing the Compilation Database Location\n\nBy default, Serena creates the transformed compilation database at `.serena/compile_commands.json`. \nYou can customize this location via project settings:\n\n```yaml\n# .serena/project.yml\nlanguage_servers:\n  cpp:\n    compile_commands_dir: custom/rel/path (defaults to .serena)\n```\n\n### With ccls\n\nccls requires manual installation and configuration. It may perform better in some situations.\n\n#### Installation\n\n**Linux:**\n```bash\n# Ubuntu/Debian (22.04+)\nsudo apt-get install ccls\n\n# Fedora/RHEL\nsudo dnf install ccls\n\n# Arch Linux\nsudo pacman -S ccls\n```\n\n**macOS:**\n```bash\nbrew install ccls\n```\n\n**Windows:**\n\n```bash\nchoco install ccls\n```\n\n#### Configuration\n\nAfter installing ccls, configure Serena to use it via project settings (in `.serena/project.yml`)\nby adding `cpp_ccls` to the `languages` list. Replace `cpp` with `cpp_ccls` if you already have the `cpp` entry.\n\nccls can handle relative paths in `compile_commands.json`, so no transformation is necessary\nand no transformed `compile_commands.json` file will be created.\n\n---\n\n## Known Limitations\n\n### Files Created After Server Initialization\n\nBoth clangd and ccls have a fundamental limitation: \n**files created by external mechanisms after the language server starts are not automatically indexed**.\n\nCross-file references to newly created files will not work unless the new file is at some point opened by the language server (for example, by a symbol lookup in it), or until `compile_commands.json` is updated and \nthe language server is restarted.\n\n---\n\n## Reference\n\n- Clangd official documentation: https://clangd.llvm.org/\n- Clangd project setup: https://clangd.llvm.org/installation#project-setup\n- CCLS repository: https://github.com/MaskRay/ccls\n"
  },
  {
    "path": "docs/03-special-guides/custom_agent.md",
    "content": "# Custom Agents with Serena\n\nAs a reference implementation, we provide an integration with the [Agno](https://docs.agno.com/introduction/playground) agent framework.\nAgno is a model-agnostic agent framework that allows you to turn Serena into an agent \n(independent of the MCP technology) with a large number of underlying LLMs. While Agno has recently\nadded support for MCP servers out of the box, our Agno integration predates this and is a good illustration of how\neasy it is to integrate Serena into an arbitrary agent framework.\n\nHere's how it works:\n\n1. Download the agent-ui code with npx\n   ```shell\n   npx create-agent-ui@latest\n   ```\n   or, alternatively, clone it manually:\n   ```shell\n   git clone https://github.com/agno-agi/agent-ui.git\n   cd agent-ui \n   pnpm install \n   pnpm dev\n   ```\n\n2. Install serena with the optional requirements:\n   ```shell\n   # You can also only select agno,google or agno,anthropic instead of all-extras\n   uv pip install --all-extras -r pyproject.toml -e .\n   ```\n   \n3. Copy `.env.example` to `.env` and fill in the API keys for the provider(s) you\n   intend to use.\n\n4. Start the agno agent app with\n   ```shell\n   uv run python scripts/agno_agent.py\n   ```\n   By default, the script uses Claude as the model, but you can choose any model\n   supported by Agno (which is essentially any existing model).\n\n5. In a new terminal, start the agno UI with\n   ```shell\n   cd agent-ui \n   pnpm dev\n   ```\n   Connect the UI to the agent you started above and start chatting. You will have\n   the same tools as in the MCP server version.\n\n\nHere is a short demo of Serena performing a small analysis task with the newest Gemini model:\n\nhttps://github.com/user-attachments/assets/ccfcb968-277d-4ca9-af7f-b84578858c62\n\n\n⚠️ IMPORTANT: In contrast to the MCP server approach, tool execution in the Agno UI does\nnot ask for the user's permission. The shell tool is particularly critical, as it can perform arbitrary code execution. \nWhile we have never encountered any issues with\nthis in our testing with Claude, allowing this may not be entirely safe. \nYou may choose to disable certain tools for your setup in your Serena project's\nconfiguration file (`.yml`).\n\n\n## Other Agent Frameworks\n\nIt should be straightforward to incorporate Serena into any\nagent framework (like [pydantic-ai](https://ai.pydantic.dev/), [langgraph](https://langchain-ai.github.io/langgraph/tutorials/introduction/) or others).\nTypically, you need only to write an adapter for Serena's tools to the tool representation in the framework of your choice, \nas was done by us for Agno with `SerenaAgnoToolkit` (see `/src/serena/agno.py`).\n\n"
  },
  {
    "path": "docs/03-special-guides/groovy_setup_guide_for_serena.md",
    "content": "# Groovy Setup Guide for Serena\n\nThe Groovy support in Serena is incomplete and requires the user to provide a functioning,\nJVM-based Groovy language server as a jar. This intermediate state allows the contributors\nof Groovy support to use Serena internally and hopefully to accelerate their open-source\nrelease of a Groovy language server in the future.\n\nIf you happen to have a Groovy language server JAR file, you can configure Serena to use it\nby following the instructions below.\n\n---\n## Prerequisites\n\n- Groovy Language Server JAR file\n    - Can be any open-source Groovy language server or your custom implementation\n    - The JAR must be compatible with standard LSP protocol\n\n---\n## Configuration\n\nConfigure Groovy Language Server by adding settings to your `~/.serena/serena_config.yml`:\n\n### Basic Configuration\n\n```yaml\nls_specific_settings:\n  groovy:\n    ls_jar_path: '/path/to/groovy-language-server.jar'\n    ls_jar_options: '-Xmx2G -Xms512m'\n```\n\n### Custom Java Paths\n\nIf you have specific Java installations:\n\n```yaml\nls_specific_settings:\n  groovy:\n    ls_jar_path: '/path/to/groovy-language-server.jar'\n    ls_java_home_path: '/usr/lib/jvm/java-21-openjdk'  # Custom JAVA_HOME directory\n    ls_jar_options: '-Xmx2G -Xms512m'                  # Optional JVM options\n```\n\n### Configuration Options\n\n- `ls_jar_path`: Absolute path to your Groovy Language Server JAR file (required)\n- `ls_java_home_path`: Custom JAVA_HOME directory for Java installation (optional)\n    - When specified, Serena will use this Java installation instead of downloading bundled Java\n    - Java executable path is automatically determined based on platform:\n        - Windows: `{ls_java_home_path}/bin/java.exe`\n        - Linux/macOS: `{ls_java_home_path}/bin/java`\n    - Validates that Java executable exists at the expected location\n- `ls_jar_options`: JVM options for language server (optional)\n    - Common options:\n        - `-Xmx<size>`: Maximum heap size (e.g., `-Xmx2G` for 2GB)\n        - `-Xms<size>`: Initial heap size (e.g., `-Xms512m` for 512MB)\n\n---\n## Project Structure Requirements\n\nFor optimal Groovy Language Server performance, ensure your project follows standard Groovy/Gradle structure:\n\n```\nproject-root/\n├── src/\n│   ├── main/\n│   │   ├── groovy/\n│   │   └── resources/\n│   └── test/\n│       ├── groovy/\n│       └── resources/\n├── build.gradle or build.gradle.kts\n├── settings.gradle or settings.gradle.kts\n└── gradle/\n    └── wrapper/\n```\n\n---\n## Using Serena with Groovy\n\n- Serena automatically detects Groovy files (`*.groovy`, `*.gvy`) and will start a Groovy Language Server JAR process per project when needed.\n- Optimal results require that your project compiles successfully via Gradle or Maven. If compilation fails, fix build errors in your build tool first.\n\n## Reference\n\n- **Groovy Documentation**: [https://groovy-lang.org/documentation.html](https://groovy-lang.org/documentation.html)\n- **Gradle Documentation**: [https://docs.gradle.org](https://docs.gradle.org)\n- **Serena Configuration**: [../02-usage/050_configuration.md](../02-usage/050_configuration.md)"
  },
  {
    "path": "docs/03-special-guides/ocaml_setup_guide_for_serena.md",
    "content": "# OCaml Setup Guide for Serena\n\nThis guide explains how to set up an OCaml project so that Serena can provide code intelligence via ocaml-lsp-server (ocamllsp).\n\nUnlike some other languages, Serena does not download the OCaml language server automatically. You must install it yourself via opam, as OCaml tooling is compiled from source against your specific environment.\n\n---\n## Prerequisites\n\nInstall the following on your system and ensure they are available on `PATH`:\n\n- **opam** (OCaml package manager)\n  - macOS: `brew install opam`\n  - Ubuntu/Debian: `sudo apt install opam`\n  - Fedora: `sudo dnf install opam`\n  - Other: https://opam.ocaml.org/doc/Install.html\n- **OCaml compiler** (via opam)\n  - OCaml < 5.1 or >= 5.1.1 (OCaml 5.1.0 is **not supported** by ocaml-lsp-server)\n  - Recommended: OCaml 4.14.x (stable) or 5.2+ (for cross-file references)\n- **ocaml-lsp-server** (via opam)\n- **dune** (build system, via opam)\n\n---\n## Installation\n\n1. Initialize opam if you haven't already:\n   ```bash\n   opam init\n   eval $(opam env)\n   ```\n\n2. Create an opam switch with a compatible OCaml version:\n   ```bash\n   # For cross-file reference support (recommended)\n   opam switch create serena-ocaml ocaml-base-compiler.5.2.1\n   eval $(opam env)\n\n   # Or for stable OCaml 4.14.x\n   opam switch create serena-ocaml ocaml-base-compiler.4.14.2\n   eval $(opam env)\n   ```\n\n3. Install the language server and build tools:\n   ```bash\n   opam install ocaml-lsp-server dune\n   ```\n\n4. Verify the installation:\n   ```bash\n   opam exec -- ocamllsp --version\n   opam exec -- ocaml -version\n   ```\n\n---\n## Cross-File References\n\nCross-file reference support (finding all usages of a symbol across your project) requires:\n\n- OCaml >= 5.2\n- ocaml-lsp-server >= 1.23.0\n- dune >= 3.16.0\n\nWhen these requirements are met, Serena automatically builds the cross-file index during startup via `dune build @ocaml-index`. Without these versions, references are limited to the current file.\n\n---\n## Using Serena with OCaml\n\n- Serena automatically detects OCaml files (`*.ml`, `*.mli`) and Reason files (`*.re`, `*.rei`).\n- The language server is started via `opam exec -- ocamllsp`, so your opam environment must be configured.\n- Ensure your project builds successfully with `dune build` before using Serena for best results.\n\n---\n## Troubleshooting\n\n| Problem | Solution |\n|---------|----------|\n| \"opam not found\" | Install opam and add it to PATH |\n| \"OCaml 5.1.0 is incompatible\" | Create a new switch: `opam switch create <name> ocaml-base-compiler.5.2.1` |\n| \"ocaml-lsp-server not found\" | `opam install ocaml-lsp-server` |\n| Cross-file refs not working | Ensure OCaml >= 5.2 and ocaml-lsp-server >= 1.23.0; run `dune build` first |\n| Stale index | Rebuild with `dune build @ocaml-index` |\n\n---\n## Reference\n\n- opam: https://opam.ocaml.org\n- ocaml-lsp-server: https://github.com/ocaml/ocaml-lsp\n- Project-wide occurrences: https://discuss.ocaml.org/t/ann-project-wide-occurrences-in-merlin-and-lsp/14847\n"
  },
  {
    "path": "docs/03-special-guides/scala_setup_guide_for_serena.md",
    "content": "# Scala Setup Guide for Serena\n\nThis guide explains how to prepare a Scala project so that Serena can provide reliable code intelligence via Metals (Scala LSP) and how to run Scala tests manually.\n\nSerena automatically bootstraps the Metals language server using Coursier when needed. Your project, however, must be importable by a build server (BSP) — typically via Bloop or sbt’s built‑in BSP — so that Metals can compile and index your code.\n\n---\n## Prerequisites\n\nInstall the following on your system and ensure they are available on `PATH`:\n\n- Java Development Kit (JDK). A modern LTS (e.g., 17 or 21) is recommended.\n- `sbt`\n- Coursier command (`cs`) or the legacy `coursier` launcher\n  - Serena uses `cs` if available; if only `coursier` exists, it will attempt to install `cs`. If neither is present, install Coursier first.\n\n---\n## Quick Start (Recommended: VS Code + Metals auto‑import)\n\n1. Open your Scala project in VS Code.\n2. When prompted by Metals, accept “Import build”. Wait until the import and initial compile/indexing finish.\n3. Run the “Connect to build server” command (id: `build.connect`).\n4. Once the import completes, start Serena in your project root and use it.\n\nThis flow ensures the `.bloop/` and (if applicable) `.metals/` directories are created and your build is known to the build server that Metals uses.\n\n---\n## Manual Setup (No VS Code)\n\nFollow these steps if you prefer a manual setup or you are not using VS Code:\n\nThese instructions cover the setup for projects that use sbt as the build tool, with Bloop as the BSP server.\n\n\n1. Add Bloop to `project/plugins.sbt` in your Scala project:\n   ```scala\n   // project/plugins.sbt\n   addSbtPlugin(\"ch.epfl.scala\" % \"sbt-bloop\" % \"<version>\")\n   ```\n   Replace `<version>` with an appropriate current version from the Metals documentation.\n\n2. Export Bloop configuration with sources:\n   ```bash\n   sbt -Dbloop.export-jar-classifiers=sources bloopInstall\n   ```\n   This creates a `.bloop/` directory containing your project’s build metadata for the BSP server.\n\n3. Compile from sbt to verify the build:\n   ```bash\n   sbt compile\n   ```\n\n4. Start Serena in your project root. Serena will bootstrap Metals (if not already present) and connect to the build server using the configuration exported above.\n\n---\n## Using Serena with Scala\n\n- Serena automatically detects Scala files (`*.scala`, `*.sbt`) and will start a Metals process per project when needed.\n- On first run, you may see messages like “Bootstrapping metals…” in the Serena logs — this is expected.\n- Optimal results require that your project compiles successfully via the build server (BSP). If compilation fails, fix build errors in `sbt` first.\n\n\nNotes:\n- Ensure you completed the manual or auto‑import steps so that the build is compiled and indexed; otherwise, code navigation and references may be incomplete until the first successful compile.\n\n---\n## Running Multiple Metals Instances\n\nSerena can run alongside other Metals instances (e.g., VS Code with Metals extension) on the same project. This is **fully supported** by Metals via H2 AUTO_SERVER mode.\n\n### How It Works\n\nMetals uses an H2 database (`.metals/metals.mv.db`) to cache semantic information. When multiple Metals instances run on the same project:\n\n- **H2 AUTO_SERVER**: The first instance becomes the TCP server; subsequent instances connect as clients\n- **Bloop Build Server**: All instances share a single Bloop process (port 8212)\n- **Compilation Results**: Shared via Bloop — no duplicate compilation\n\n### Stale Lock Detection\n\nIf a Metals process crashes without proper cleanup, it may leave a stale lock file (`.metals/metals.mv.db.lock.db`). This can prevent proper AUTO_SERVER coordination, causing new instances to fall back to in-memory database mode (degraded experience).\n\nSerena automatically detects and handles stale locks based on your configuration:\n\n```yaml\n# ~/.serena/serena_config.yml or .serena/project.yml\nls_specific_settings:\n  scala:\n    on_stale_lock: \"auto-clean\"      # auto-clean | warn | fail\n    log_multi_instance_notice: true  # Log info when another Metals detected\n```\n\n#### Stale Lock Modes\n\n| Mode | Behavior |\n|------|----------|\n| `auto-clean` | **(Default, Recommended)** Automatically removes stale lock files and proceeds normally. |\n| `warn` | Logs a warning but proceeds. Metals may use in-memory database (slower). |\n| `fail` | Raises an error and refuses to start. Useful for debugging lock issues. |\n\n---\n## Reference \n- Metals + sbt: [https://scalameta.org/metals/docs/build-tools/sbt](https://scalameta.org/metals/docs/build-tools/sbt)\n"
  },
  {
    "path": "docs/03-special-guides/serena_on_chatgpt.md",
    "content": "\n# Connecting Serena MCP Server to ChatGPT via MCPO & Cloudflare Tunnel\n\nThis guide explains how to expose a **locally running Serena MCP server** (powered by MCPO) to the internet using **Cloudflare Tunnel**, and how to connect it to **ChatGPT as a Custom GPT with tool access**.\n\nOnce configured, ChatGPT becomes a powerful **coding agent** with direct access to your codebase, shell, and file system — so **read the security notes carefully**.\n\n---\n## Prerequisites\n\nMake sure you have [uv](https://docs.astral.sh/uv/getting-started/installation/) \nand [cloudflared](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/) installed.\n\n## 1. Start the Serena MCP Server via MCPO\n\nRun the following command to launch Serena as http server (assuming port 8000):\n\n```bash\nuvx mcpo --port 8000 --api-key <YOUR_SECRET_KEY> -- \\\n  uvx --from git+https://github.com/oraios/serena \\\n  serena start-mcp-server --context chatgpt --project $(pwd)\n```\n\n- `--api-key` is required to secure the server.\n- `--project` should point to the root of your codebase.\n\nYou can also use other options, and you don't have to pass `--project` if you want to work on multiple projects\nor want to activate it later. See \n\n```shell\nuvx --from git+https://github.com/oraios/serena serena start-mcp-server --help\n```\n\n---\n\n## 2. Expose the Server Using Cloudflare Tunnel\n\nRun:\n\n```bash\ncloudflared tunnel --url http://localhost:8000\n```\n\nThis will give you a **public HTTPS URL** like:\n\n```\nhttps://serena-agent-tunnel.trycloudflare.com\n```\n\nYour server is now securely exposed to the internet.\n\n---\n\n## 3. Connect It to ChatGPT (Custom GPT)\n\n### Steps:\n\n1. Go to [ChatGPT → Explore GPTs → Create](https://chat.openai.com/gpts/editor)\n2. During setup, click **“Add APIs”**\n3. Set up **API Key authentication** with the auth type as **Bearer** and enter the api key you used to start the MCPO server.\n4. In the **Schema** section, click on **import from URL** and paste `<cloudflared_url>/openapi.json` with the URL you got from the previous step.\n5. Add the following line to the top of the imported JSON schema:\n    ```\n     \"servers\": [\"url\": \"<cloudflared_url>\"],\n    ```\n   **Important**: don't include a trailing slash at the end of the URL!\n\nChatGPT will read the schema and create functions automatically.\n\n---\n\n## Security Warning — Read Carefully\n\nDepending on your configuration and enabled tools, Serena's MCP server may:\n- Execute **arbitrary shell commands**\n- Read, write, and modify **files in your codebase**\n\nThis gives ChatGPT the same powers as a remote developer on your machine.\n\n### ⚠️ Key Rules:\n- **NEVER expose your API key**\n- **Only expose this server when needed**, and monitor its use.\n\nIn your project’s `.serena/project.yml` or global config, you can disable tools like:\n\n```yaml\nexcluded_tools:\n  - execute_shell_command\n  - ...\nread_only: true\n```\n\nThis is strongly recommended if you want a read-only or safer agent.\n\n\n---\n\n## Final Thoughts\n\nWith this setup, ChatGPT becomes a coding assistant **running on your local code** — able to index, search, edit, and even run shell commands depending on your configuration.\n\nUse responsibly, and keep security in mind.\n"
  },
  {
    "path": "docs/_config.yml",
    "content": "# Book settings\n# Learn more at https://jupyterbook.org/customize/config.html\n\n#######################################################################################\n# A default configuration that will be loaded for all jupyter books\n# Users are expected to override these values in their own `_config.yml` file.\n# This is also the \"master list\" of all allowed keys and values.\n\n#######################################################################################\n# Book settings\ntitle                       : Serena Documentation  # The title of the book. Will be placed in the left navbar.\nauthor                      : Oraios AI & Oraios Software  # The author of the book\ncopyright                   : \"2025 by Serena contributors\"  # Copyright year to be placed in the footer\n# Patterns to skip when building the book. Can be glob-style (e.g. \"*skip.ipynb\")\nexclude_patterns            : ['**.ipynb_checkpoints', '.DS_Store', 'Thumbs.db', '_build', 'jupyter_execute', '.jupyter_cache', '.pytest_cache', 'docs/autogen_docs.py', 'docs/create_toc.py']\n# Auto-exclude files not in the toc\nonly_build_toc_files        : true\n\n#######################################################################################\n# Execution settings\nexecute:\n  # NOTE: Notebooks are not executed, because test_notebooks.py executes them and stores them with outputs in the docs/ folder\n  # NOTE: If changed, repeat below in `nb_execution_mode`.\n  execute_notebooks         : \"off\"  # Whether to execute notebooks at build time. Must be one of (\"auto\", \"force\", \"cache\", \"off\")\n  cache                     : \"\"    # A path to the jupyter cache that will be used to store execution artifacts. Defaults to `_build/.jupyter_cache/`\n  exclude_patterns          : []    # A list of patterns to *skip* in execution (e.g. a notebook that takes a really long time)\n  timeout                   : 1000    # The maximum time (in seconds) each notebook cell is allowed to run.\n  run_in_temp               : false # If `True`, then a temporary directory will be created and used as the command working directory (cwd),\n                                    # otherwise the notebook's parent directory will be the cwd.\n  allow_errors              : true # If `False`, when a code cell raises an error the execution is stopped, otherwise all cells are always run.\n  stderr_output             : show  # One of 'show', 'remove', 'remove-warn', 'warn', 'error', 'severe'\n\n#######################################################################################\n# Parse and render settings\nparse:\n  myst_enable_extensions: # default extensions to enable in the myst parser. See https://myst-parser.readthedocs.io/en/latest/using/syntax-optional.html\n    - amsmath\n    - colon_fence\n    # - deflist\n    - dollarmath\n    # - html_admonition\n    # - html_image\n    - linkify\n    # - replacements\n    # - smartquotes\n    - substitution\n    - tasklist\n    - html_admonition\n    - html_image\n  myst_url_schemes: [ mailto, http, https ] # URI schemes that will be recognised as external URLs in Markdown links\n  myst_dmath_double_inline: true  # Allow display math ($$) within an inline context\n\n#######################################################################################\n# HTML-specific settings\nhtml:\n  favicon                   : \"../src/serena/resources/dashboard/serena-icon-32.png\"\n  use_edit_page_button      : false  # Whether to add an \"edit this page\" button to pages. If `true`, repository information in repository: must be filled in\n  use_repository_button     : false  # Whether to add a link to your repository button\n  use_issues_button         : false  # Whether to add an \"open an issue\" button\n  use_multitoc_numbering    : true   # Continuous numbering across parts/chapters\n  use_darkmode_button       : false\n  extra_footer              : \"\"\n  home_page_in_navbar       : true  # Whether to include your home page in the left Navigation Bar\n  baseurl                   : \"https://oraios.github.io/serena/\"\n  comments:\n    hypothesis              : false\n    utterances              : false\n  announcement              : \"\" # A banner announcement at the top of the site.\n\n#######################################################################################\n# LaTeX-specific settings\nlatex:\n  latex_engine              : pdflatex  # one of 'pdflatex', 'xelatex' (recommended for unicode), 'luatex', 'platex', 'uplatex'\n  use_jupyterbook_latex     : true # use sphinx-jupyterbook-latex for pdf builds as default\n  targetname                : book.tex\n# Add a bibtex file so that we can create citations\n#bibtex_bibfiles:\n#  - refs.bib\n\n#######################################################################################\n# Launch button settings\nlaunch_buttons:\n  notebook_interface        : classic  # The interface interactive links will activate [\"classic\", \"jupyterlab\"]\n  binderhub_url             : \"\"  # The URL of the BinderHub (e.g., https://mybinder.org)\n  jupyterhub_url            : \"\"  # The URL of the JupyterHub (e.g., https://datahub.berkeley.edu)\n  thebe                     : false  # Add a thebe button to pages (requires the repository to run on Binder)\n  colab_url                 : \"https://colab.research.google.com\"\n\nrepository:\n  url                       : https://github.com/oraios/serena  # The URL to your book's repository\n  path_to_book              : docs  # A path to your book's folder, relative to the repository root.\n  branch                    : main  # Which branch of the repository should be used when creating links\n\n#######################################################################################\n# Advanced and power-user settings\nsphinx:\n  extra_extensions          :\n    - sphinx.ext.autodoc\n    - sphinx.ext.viewcode\n    - sphinx_toolbox.more_autodoc.sourcelink\n    #- sphinxcontrib.spelling\n  local_extensions          :   # A list of local extensions to load by sphinx specified by \"name: path\" items\n  recursive_update          : false # A boolean indicating whether to overwrite the Sphinx config (true) or recursively update (false)\n  config                    :   # key-value pairs to directly over-ride the Sphinx configuration\n    master_doc: \"01-about/000_intro.md\"\n    html_theme_options:\n      logo:\n        image_light: ../resources/serena-logo.svg\n        image_dark: ../resources/serena-logo-dark-mode.svg\n    autodoc_typehints_format: \"short\"\n    autodoc_member_order: \"bysource\"\n    autoclass_content: \"both\"\n    autodoc_default_options:\n      show-inheritance: True\n    autodoc_show_sourcelink: True\n    add_module_names: False\n    github_username: oraios\n    github_repository: serena\n    nb_execution_mode: \"off\"\n    nb_merge_streams: True  # This is important for cell outputs to appear as single blocks rather than one block per line\n    python_use_unqualified_type_names: True\n    nb_mime_priority_overrides: [\n      [ 'html', 'application/vnd.jupyter.widget-view+json', 10 ],\n      [ 'html', 'application/javascript', 20 ],\n      [ 'html', 'text/html', 30 ],\n      [ 'html', 'text/latex', 40 ],\n      [ 'html', 'image/svg+xml', 50 ],\n      [ 'html', 'image/png', 60 ],\n      [ 'html', 'image/jpeg', 70 ],\n      [ 'html', 'text/markdown', 80 ],\n      [ 'html', 'text/plain', 90 ],\n      [ 'spelling', 'application/vnd.jupyter.widget-view+json', 10 ],\n      [ 'spelling', 'application/javascript', 20 ],\n      [ 'spelling', 'text/html', 30 ],\n      [ 'spelling', 'text/latex', 40 ],\n      [ 'spelling', 'image/svg+xml', 50 ],\n      [ 'spelling', 'image/png', 60 ],\n      [ 'spelling', 'image/jpeg', 70 ],\n      [ 'spelling', 'text/markdown', 80 ],\n      [ 'spelling', 'text/plain', 90 ],\n    ]\n    mathjax_path: https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js\n    mathjax3_config:\n      loader: { load: [ '[tex]/configmacros' ] }\n      tex:\n        packages: { '[+]': [ 'configmacros' ] }\n        macros:\n          vect: [\"{\\\\mathbf{\\\\boldsymbol{#1}} }\", 1]\n          E: \"{\\\\mathbb{E}}\"\n          P: \"{\\\\mathbb{P}}\"\n          R: \"{\\\\mathbb{R}}\"\n          abs: [\"{\\\\left| #1 \\\\right|}\", 1]\n          simpl: [\"{\\\\Delta^{#1} }\", 1]\n          amax: \"{\\\\text{argmax}}\"\n"
  },
  {
    "path": "docs/autogen_docs.py",
    "content": "import logging\nimport os\nimport shutil\nfrom pathlib import Path\nfrom typing import Optional, List\n\nfrom sensai.util.string import TextBuilder\n\nlog = logging.getLogger(os.path.basename(__file__))\n\nTOP_LEVEL_PACKAGE = \"serena\"\nPROJECT_NAME = \"Serena\"\n\ndef module_template(module_qualname: str):\n    module_name = module_qualname.split(\".\")[-1]\n    title = module_name.replace(\"_\", r\"\\_\")\n    return f\"\"\"{title}\n{\"=\" * len(title)}\n\n.. automodule:: {module_qualname}\n   :members:\n   :undoc-members:\n\"\"\"\n\n\ndef index_template(package_name: str, doc_references: Optional[List[str]] = None, text_prefix=\"\"):\n    doc_references = doc_references or \"\"\n    if doc_references:\n        doc_references = \"\\n\" + \"\\n\".join(f\"* :doc:`{ref}`\" for ref in doc_references) + \"\\n\"\n\n    dirname = package_name.split(\".\")[-1]\n    title = dirname.replace(\"_\", r\"\\_\")\n    if title == TOP_LEVEL_PACKAGE:\n        title = \"API Reference\"\n    return f\"{title}\\n{'=' * len(title)}\" + text_prefix + doc_references\n\n\ndef write_to_file(content: str, path: str):\n    os.makedirs(os.path.dirname(path), exist_ok=True)\n    with open(path, \"w\") as f:\n        f.write(content)\n    os.chmod(path, 0o666)\n\n\n_SUBTITLE = (\n    f\"\\n Here is the autogenerated documentation of the {PROJECT_NAME} API. \\n \\n \"\n    \"The Table of Contents to the left has the same structure as the \"\n    \"repository's package code. The links at each page point to the submodules and subpackages. \\n\"\n)\n\n\ndef make_rst(src_root, rst_root, clean=False, overwrite=False, package_prefix=\"\"):\n    \"\"\"Creates/updates documentation in form of rst files for modules and packages.\n\n    Does not delete any existing rst files. Thus, rst files for packages or modules that have been removed or renamed\n    should be deleted by hand.\n\n    This method should be executed from the project's top-level directory\n\n    :param src_root: path to library base directory, typically \"src/<library_name>\"\n    :param rst_root: path to the root directory to which .rst files will be written\n    :param clean: whether to completely clean the target directory beforehand, removing any existing .rst files\n    :param overwrite: whether to overwrite existing rst files. This should be used with caution as it will delete\n        all manual changes to documentation files\n    :package_prefix: a prefix to prepend to each module (for the case where the src_root is not the base package),\n        which, if not empty, should end with a \".\"\n    :return:\n    \"\"\"\n    rst_root = os.path.abspath(rst_root)\n\n    if clean and os.path.isdir(rst_root):\n        shutil.rmtree(rst_root)\n\n    base_package_name = package_prefix + os.path.basename(src_root)\n\n    # TODO: reduce duplication with same logic for subpackages below\n    files_in_dir = os.listdir(src_root)\n    module_names = [f[:-3] for f in files_in_dir if f.endswith(\".py\") and not f.startswith(\"_\")]\n    subdir_refs = [\n        f\"{f}/index\"\n        for f in files_in_dir\n        if os.path.isdir(os.path.join(src_root, f))\n        and not f.startswith(\"_\")\n        and not f.startswith(\".\")\n    ]\n    package_index_rst_path = os.path.join(\n        rst_root,\n        \"index.rst\",\n    )\n    log.info(f\"Writing {package_index_rst_path}\")\n    write_to_file(\n        index_template(\n            base_package_name,\n            doc_references=module_names + subdir_refs,\n            text_prefix=_SUBTITLE,\n        ),\n        package_index_rst_path,\n    )\n\n    for root, dirnames, filenames in os.walk(src_root):\n        if os.path.basename(root).startswith(\"_\"):\n            continue\n        base_package_relpath = os.path.relpath(root, start=src_root)\n        base_package_qualname = package_prefix + os.path.relpath(\n            root,\n            start=os.path.dirname(src_root),\n        ).replace(os.path.sep, \".\")\n\n        for dirname in dirnames:\n            if dirname.startswith(\"_\"):\n                log.debug(f\"Skipping {dirname}\")\n                continue\n            files_in_dir = os.listdir(os.path.join(root, dirname))\n            module_names = [\n                f[:-3] for f in files_in_dir if f.endswith(\".py\") and not f.startswith(\"_\")\n            ]\n            subdir_refs = [\n                f\"{f}/index\"\n                for f in files_in_dir\n                if os.path.isdir(os.path.join(root, dirname, f)) and not f.startswith(\"_\")\n            ]\n            package_qualname = f\"{base_package_qualname}.{dirname}\"\n            package_index_rst_path = os.path.join(\n                rst_root,\n                base_package_relpath,\n                dirname,\n                \"index.rst\",\n            )\n            log.info(f\"Writing {package_index_rst_path}\")\n            write_to_file(\n                index_template(package_qualname, doc_references=module_names + subdir_refs),\n                package_index_rst_path,\n            )\n\n        for filename in filenames:\n            base_name, ext = os.path.splitext(filename)\n            if ext == \".py\" and not filename.startswith(\"_\"):\n                module_qualname = f\"{base_package_qualname}.{filename[:-3]}\"\n\n                module_rst_path = os.path.join(rst_root, base_package_relpath, f\"{base_name}.rst\")\n                if os.path.exists(module_rst_path) and not overwrite:\n                    log.debug(f\"{module_rst_path} already exists, skipping it\")\n\n                log.info(f\"Writing module documentation to {module_rst_path}\")\n                write_to_file(module_template(module_qualname), module_rst_path)\n\n\ndef autogen_tool_list(target_filename = \"01-about/035_tools.md\"):\n    from serena.tools import ToolRegistry\n\n    target_file = Path(__file__).parent / target_filename\n    with open(target_file, \"w\") as f:\n        f.write(\"<!-- This file is auto-generated by docs/autogen_docs.py. Do not edit it manually. -->\\n\\n\")\n        f.write(\"# Tools\\n\\n\")\n        f.write(\"Find the full list of Serena's tools below.  \\n\")\n        f.write(\"Note that in most configurations, only a subset of these tools will be enabled simultaneously.\\n\")\n        f.write(\"Tools marked as optional are disabled by default.\\n\\n\")\n        tools_by_module = ToolRegistry().get_registered_tools_by_module()\n        priority_modules = {\"serena.tools.symbol_tools\": 1, \"serena.tools.jetbrains_tools\": 2}\n\n        text = TextBuilder()\n        sorted_modules = sorted(tools_by_module.keys(), key=lambda m: (priority_modules.get(m, 3), m))\n        for module in sorted_modules:\n            tools = tools_by_module[module]\n            module = module.replace(\"serena.tools.\", \"\")\n            text.with_line(f\"* **{module}**\")\n            for tool in tools:\n                info = \" *(optional)*\" if tool.is_optional else \"\"\n                text.with_line(f\"* `{tool.tool_name}`{info}: {tool.class_docstring}\", indent=2)\n        f.write(text.build())\n\n\nif __name__ == \"__main__\":\n    logging.basicConfig(level=logging.INFO)\n    docs_root = Path(__file__).parent\n    enable_module_docs = False\n\n    autogen_tool_list()\n\n    if enable_module_docs:\n        make_rst(\n            docs_root / \"..\" / \"src\" / \"serena\",\n            docs_root / \"serena\",\n            clean=True,\n        )\n"
  },
  {
    "path": "docs/create_toc.py",
    "content": "import os\nfrom pathlib import Path\n\n# This script provides a platform-independent way of making the jupyter-book call (used in pyproject.toml)\nfolder = Path(__file__).parent\ntoc_file = folder / \"_toc.yml\"\ncmd = f\"jupyter-book toc from-project docs -e .rst -e .md -e .ipynb >{toc_file}\"\nprint(cmd)\nos.system(cmd)\n"
  },
  {
    "path": "docs/index.md",
    "content": "<meta http-equiv=\"refresh\" content=\"0; url=01-about/000_intro.html\">\nIf you are not redirected automatically, [click here](01-about/000_intro.html).\n"
  },
  {
    "path": "flake.nix",
    "content": "{\n  description = \"A powerful coding agent toolkit providing semantic retrieval and editing capabilities (MCP server & Agno integration)\";\n\n  inputs = {\n    nixpkgs.url = \"github:NixOS/nixpkgs/nixos-unstable\";\n\n    flake-utils = {\n      url = \"github:numtide/flake-utils\";\n    };\n\n    pyproject-nix = {\n      url = \"github:pyproject-nix/pyproject.nix\";\n      inputs.nixpkgs.follows = \"nixpkgs\";\n    };\n\n    uv2nix = {\n      url = \"github:pyproject-nix/uv2nix\";\n      inputs = {\n        pyproject-nix.follows = \"pyproject-nix\";\n        nixpkgs.follows = \"nixpkgs\";\n      };\n    };\n\n    pyproject-build-systems = {\n      url = \"github:pyproject-nix/build-system-pkgs\";\n      inputs = {\n        pyproject-nix.follows = \"pyproject-nix\";\n        uv2nix.follows = \"uv2nix\";\n        nixpkgs.follows = \"nixpkgs\";\n      };\n    };\n  };\n\n  outputs = {\n    nixpkgs,\n    uv2nix,\n    pyproject-nix,\n    pyproject-build-systems,\n    flake-utils,\n    ...\n  }:\n    flake-utils.lib.eachDefaultSystem (system: let\n      pkgs = import nixpkgs {inherit system;};\n\n      inherit (pkgs) lib;\n\n      workspace = uv2nix.lib.workspace.loadWorkspace {workspaceRoot = ./.;};\n\n      overlay = workspace.mkPyprojectOverlay {\n        sourcePreference = \"wheel\"; # or sourcePreference = \"sdist\";\n      };\n\n      pyprojectOverrides = final: prev: {\n        # Add setuptools for packages that need it during build\n        ruamel-yaml-clib = prev.ruamel-yaml-clib.overrideAttrs (old: {\n          nativeBuildInputs = (old.nativeBuildInputs or []) ++ [\n            final.setuptools\n          ];\n        });\n      };\n\n      python = pkgs.python311;\n\n      pythonSet =\n        (pkgs.callPackage pyproject-nix.build.packages {\n          inherit python;\n        }).overrideScope\n        (\n          lib.composeManyExtensions [\n            pyproject-build-systems.overlays.default\n            overlay\n            pyprojectOverrides\n          ]\n        );\n    in rec {\n      formatter = pkgs.alejandra;\n\n      packages = {\n        serena-env = pythonSet.mkVirtualEnv \"serena-env\" workspace.deps.default;\n        serena = pkgs.runCommand \"serena\" {\n            meta = {\n              description = \"A powerful coding agent toolkit providing semantic retrieval and editing capabilities (MCP server & Agno integration)\";\n              homepage = \"https://oraios.github.io/serena\";\n              changelog = \"https://github.com/oraios/serena/blob/main/CHANGELOG.md\";\n              mainProgram = \"serena\";\n              license = pkgs.lib.licenses.mit;\n              platforms = lib.platforms.all;\n            };\n          } ''\n          mkdir -p $out/bin\n          ln -s ${packages.serena-env}/bin/serena $out/bin/serena\n        '';\n        default = packages.serena;\n      };\n\n      apps.default = {\n        type = \"app\";\n        program = \"${packages.default}/bin/serena\";\n      };\n\n      devShells = {\n        default = pkgs.mkShell {\n          packages = [\n            python\n            pkgs.uv\n          ];\n          env =\n            {\n              UV_PYTHON_DOWNLOADS = \"never\";\n              UV_PYTHON = python.interpreter;\n            }\n            // lib.optionalAttrs pkgs.stdenv.isLinux {\n              LD_LIBRARY_PATH = lib.makeLibraryPath pkgs.pythonManylinuxPackages.manylinux1;\n            };\n          shellHook = ''\n            unset PYTHONPATH\n          '';\n        };\n      };\n    });\n}\n"
  },
  {
    "path": "lessons_learned.md",
    "content": "# Lessons Learned\n\nIn this document we briefly collect what we have learned while developing and using Serena,\nwhat works well and what doesn't.\n\n## What Worked\n\n### Separate Tool Logic From MCP Implementation\n\nMCP is just another protocol, one should let the details of it creep into the application logic.\nThe official docs suggest using function annotations to define tools and prompts. While that may be\nuseful for small projects to get going fast, it is not wise for more serious projects. In Serena,\nall tools are defined independently and then converted to instances of `MCPTool` using our `make_tool`\nfunction.\n\n### Autogenerated PromptFactory\n\nPrompt templates are central for most LLM applications, so one needs good representations of them in the code,\nwhile at the same time they often need to be customizable and exposed to users. In Serena we address these conflicting \nneeds by defining prompt templates (in jinja format) in separate yamls that users can easily modify and by autogenerated\na `PromptFactory` class with meaningful method and parameter names from these yamls. The latter is committed to our code.\nWe separated out the generation logic into the [interprompt](/src/interprompt/README.md) subpackage that can be used as a library.\n\n### Tempfiles and Snapshots for Testing of Editing Tools\n\nWe test most aspects of Serena by having a small \"project\" for each supported language in `tests/resources`.\nFor the editing tools, which would change the code in these projects, we use tempfiles to copy over the code.\nThe pretty awesome [syrupy](https://github.com/syrupy-project/syrupy) pytest plugin helped in developing\nsnapshot tests.\n\n### Dashboard and GUI for Logging\n\nIt is very useful to know what the MCP Server is doing. We collect and display logs in a GUI or a web dashboard,\nwhich helps a lot in seeing what's going on and in identifying any issues.\n\n### Unrestricted Bash Tool\n\nWe know it's not particularly safe to permit unlimited shell commands outside a sandbox, but we did quite some\nevaluations and so far... nothing bad has happened. Seems like the current versions of the AI overlords rarely want to execute `sudo rm - rf /`.\nStill, we are working on a safer approach as well as better integration with sandboxing.\n\n### Multilspy\n\nThe [multilspy](https://github.com/microsoft/multilspy/) project helped us a lot in getting started and stands at the core of Serena.\nMany more well known python implementations of language servers were subpar in code quality and design (for example, missing types).\n\n### Developing Serena with Serena\n\nWe clearly notice that the better the tool gets, the easier it is to make it even better\n\n## Prompting\n\n### Shouting and Emotive Language May Be Needed\n\nWhen developing the `ReplaceRegexTool` we were initially not able to make Claude 4 (in Claude Desktop) use wildcards to save on output tokens. Neither\nexamples nor explicit instructions helped. It was only after adding \n\n```\nIMPORTANT: REMEMBER TO USE WILDCARDS WHEN APPROPRIATE! I WILL BE VERY UNHAPPY IF YOU WRITE LONG REGEXES WITHOUT USING WILDCARDS INSTEAD!\n```\n\nto the initial instructions and to the tool description that Claude finally started following the instructions.\n\n## What Didn't Work\n\n### Lifespan Handling by MCP Clients\n\nThe MCP technology is clearly very green. Even though there is a lifespan context in the MCP SDK,\nmany clients, including Claude Desktop, fail to properly clean up, leaving zombie processes behind.\nWe mitigate this through the GUI window and the dashboard, so the user sees whether Serena is running\nand can terminate it there.\n\n### Trusting Asyncio\n\nRunning multiple asyncio apps led to non-deterministic \nevent loop contamination and deadlocks, which were very hard to debug\nand understand. We solved this with a large hammer, by putting all asyncio apps into a separate\nprocess. It made the code much more complex and slightly enhanced RAM requirements, but it seems\nlike that was the only way to reliably overcome asyncio deadlock issues.\n\n### Cross-OS Tkinter GUI\n\nDifferent OS have different limitations when it comes to starting a window or dealing with Tkinter\ninstallations. This was so messy to get right that we pivoted to a web-dashboard instead\n\n### Editing Based on Line Numbers\n\nNot only are LLMs notoriously bad in counting, but also the line numbers change after edit operations,\nand LLMs are also often too dumb to understand that they should update the line numbers information they had\nreceived before. We pivoted to string-matching and symbol-name based editing."
  },
  {
    "path": "llms-install.md",
    "content": "# MCP Installation instructions\n\nThis document is mainly used as instructions for AI-assistants like Cline and others that\ntry to do an automatic install based on freeform instructions.\n\n0. Make sure `uv` is installed. If not, install it using either `curl -LsSf https://astral.sh/uv/install.sh | sh` (macOS, Linux) or\n   `powershell -ExecutionPolicy ByPass -c \"irm https://astral.sh/uv/install.ps1 | iex\"` (Windows). Find the path to the `uv` executable,\n   you'll need it later.\n1. Clone the repo with `git clone git@github.com:oraios/serena.git` and change into its dir (e.g., `cd serena`)\n2. Check if `serena_config.yml` exists. If not, create it  with `cp serena_config.template.yml serena_config.yml`. Read the instructions in the config.\n3. In the config, check if the path to your project was added. If not, add it to the `projects` section\n4. In your project, create a `.serena` if needed and check whether `project.yml` exists there.\n5. If no `project.yml` was found, create it using `cp /path/to/serena/myproject.template.yml /path/to/your/project/.serena/project.yml`\n6. Read the instructions in `project.yml`. Make sure the `project.yml` has the correct project language configured. \n   Remove the  project_root entry there.\n7. Finally, add the Serena MCP server config like this:\n\n```json\n   {\n       \"mcpServers\": {\n            ...\n           \"serena\": {\n               \"command\": \"/abs/path/to/uv\",\n               \"args\": [\"run\", \"--directory\", \"/abs/path/to/serena\", \"serena-mcp-server\", \"/path/to/your/project/.serena/project.yml\"]\n           }\n       }\n   }\n\n```\n"
  },
  {
    "path": "pyproject.toml",
    "content": "[build-system]\nbuild-backend = \"hatchling.build\"\nrequires = [\"hatchling\"]\n\n[project]\nname = \"serena-agent\"\nversion = \"0.1.4\"\ndescription = \"\"\nauthors = [{ name = \"Oraios AI\", email = \"info@oraios-ai.de\" }]\nreadme = \"README.md\"\nrequires-python = \">=3.11, <3.12\"\nclassifiers = [\n  \"License :: OSI Approved :: MIT License\",\n  \"Programming Language :: Python :: 3.11\",\n]\ndependencies = [\n  \"requests>=2.32.3,<3\",\n  \"pyright>=1.1.396,<2\",\n  \"fortls>=3.2.2\",\n  \"overrides>=7.7.0,<8\",\n  \"python-dotenv>=1.0.0, <2\",\n  \"mcp==1.23.0\",\n  \"flask>=3.0.0\",\n  \"sensai-utils>=1.5.0\",\n  \"pydantic>=2.10.6\",\n  \"types-pyyaml>=6.0.12.20241230\",\n  \"pyyaml>=6.0.2\",\n  \"ruamel.yaml==0.18.14\",\n  \"jinja2>=3.1.6\",\n  \"dotenv>=0.9.9\",\n  \"pathspec>=0.12.1\",\n  \"psutil>=7.0.0\",\n  \"docstring_parser>=0.16\",\n  \"joblib>=1.5.1\",\n  \"tqdm>=4.67.1\",\n  \"tiktoken>=0.9.0\",\n  \"anthropic>=0.54.0\",\n  \"beautifulsoup4>=4.14.2\",\n]\n\n[[tool.uv.index]]\nname = \"testpypi\"\nurl = \"https://test.pypi.org/simple/\"\npublish-url = \"https://test.pypi.org/legacy/\"\nexplicit = true\n\n[project.scripts]\nserena = \"serena.cli:top_level\"\nserena-mcp-server = \"serena.cli:start_mcp_server\"\nindex-project = \"serena.cli:index_project\"        # deprecated\n\n[project.license]\ntext = \"MIT\"\n\n[project.optional-dependencies]\ndev = [\n  \"black[jupyter]>=23.7.0, <26\",  # black 26 is incompatible with our pathspec version\n  \"jinja2\",\n  # In version 1.0.4 we get a NoneType error related to some config conversion (yml_analytics is None and should be a list)\n  \"mypy>=1.16.1\",\n  \"poethepoet>=0.20.0\",\n  \"pytest>=8.0.2\",\n  \"pytest-xdist>=3.5.0\",\n  \"ruff==0.12.5\",\n  \"toml-sort>=0.24.2\",\n  \"types-pyyaml>=6.0.12.20241230\",\n  \"syrupy>=4.9.1\",\n  \"types-requests>=2.32.4.20241230\",\n  # docs\n  \"sphinx>=7,<8\",\n  \"sphinx_rtd_theme>=0.5.1\",\n  \"sphinx-toolbox==3.7.0\",\n  \"jupyter-book>=1,<2\",\n  \"nbsphinx\",\n  \"pyinstrument\",\n  \"pytest-timeout>=2.4.0\",\n]\nagno = [\"agno>=2.2.1\", \"sqlalchemy>=2.0.40\"]\ngoogle = [\"google-genai>=1.8.0\"]\n\n[project.urls]\nHomepage = \"https://github.com/oraios/serena\"\n\n[tool.hatch.build.targets.wheel]\npackages = [\"src/serena\", \"src/interprompt\", \"src/solidlsp\"]\n\n[tool.black]\nline-length = 140\ntarget-version = [\"py311\"]\nexclude = '''\n/(\n    src/solidlsp/language_servers/.*/static|src/multilspy\n)/\n'''\n\n[tool.doc8]\nmax-line-length = 1000\n\n[tool.mypy]\nallow_redefinition = true\ncheck_untyped_defs = true\ndisallow_incomplete_defs = true\ndisallow_untyped_defs = true\nignore_missing_imports = true\nno_implicit_optional = true\npretty = true\nshow_error_codes = true\nshow_error_context = true\nshow_traceback = true\nstrict_equality = true\nstrict_optional = true\nwarn_no_return = true\nwarn_redundant_casts = true\nwarn_unreachable = true\nwarn_unused_configs = true\nwarn_unused_ignores = false\nexclude = \"^build/|^docs/|^test/resources/\"\n\n[[tool.mypy.overrides]]\nmodule = \"test.*\"\ndisallow_untyped_defs = false  # untyped defs are OK in tests\n\n[tool.poe.env]\nPYDEVD_DISABLE_FILE_VALIDATION = \"1\"\n\n[tool.poe.executor]\n# This is important when using poe with uv, because otherwise poe will try to run commands through\n# uv, which in turn will try to recreate the environment, which in turn will fail if any process\n# using the environment is already running! Naturally, processes using the env are running all the\n# time (e.g. a Serena MCP server), so using the default executor (uv) is not an option!\ntype = \"simple\"\n\n[tool.poe.tasks]\n# Uses PYTEST_MARKERS env var for default markers\n# For custom markers, one can either adjust the env var or just use -m option in the command line,\n# as the second -m option will override the first one.\ntest = \"pytest test -vv\"\n_black_check = \"black --check src scripts test\"\n_ruff_check = \"ruff check src scripts test\"\n_black_format = \"black src scripts test\"\n_ruff_format = \"ruff check --fix src scripts test\"\nlint = [\"_black_check\", \"_ruff_check\"]\nformat = [\"_ruff_format\", \"_black_format\"]\n_mypy_core = \"mypy src/serena src/solidlsp\"\n_mypy_test = \"mypy --disable-error-code no-untyped-def test\"\ntype-check = [\"_mypy_core\", \"_mypy_test\"]\n# docs\n_autogen_docs = \"python docs/autogen_docs.py\"\n_sphinx_build = \"sphinx-build -b html docs docs/_build -W --keep-going\"\n_jb_generate_toc = \"python docs/create_toc.py\"\n_jb_generate_config = \"jupyter-book config sphinx docs/\"\ndoc-clean = \"rm -rf docs/_build docs/03_api\"\ndoc-generate-files = [\"_autogen_docs\", \"_jb_generate_toc\", \"_jb_generate_config\"]\ndoc-build = [\"doc-clean\", \"doc-generate-files\", \"_sphinx_build\"]\n\n[tool.ruff]\ntarget-version = \"py311\"\nline-length = 140\nexclude = [\"src/solidlsp/language_servers/**/static\", \"src/multilspy\"]\n\n[tool.ruff.format]\nquote-style = \"double\"\nindent-style = \"space\"\nline-ending = \"auto\"\nskip-magic-trailing-comma = false\ndocstring-code-format = true\n\n[tool.ruff.lint]\nselect = [\n  \"ASYNC\",\n  \"B\",\n  \"C4\",\n  \"C90\",\n  \"COM\",\n  \"D\",\n  \"DTZ\",\n  \"E\",\n  \"F\",\n  \"FLY\",\n  \"G\",\n  \"I\",\n  \"ISC\",\n  \"PIE\",\n  \"PLC\",\n  \"PLE\",\n  \"PLW\",\n  \"RET\",\n  \"RUF\",\n  \"RSE\",\n  \"SIM\",\n  \"TID\",\n  \"UP\",\n  \"W\",\n  \"YTT\",\n]\nignore = [\n  \"PLC0415\",\n  \"RUF002\",\n  \"RUF005\",\n  \"RUF059\",\n  \"SIM118\",\n  \"SIM108\",\n  \"E501\",\n  \"E741\",\n  \"B008\",\n  \"B011\",\n  \"B028\",\n  \"D100\",\n  \"D101\",\n  \"D102\",\n  \"D103\",\n  \"D104\",\n  \"D105\",\n  \"D107\",\n  \"D200\",\n  \"D203\",\n  \"D213\",\n  \"D401\",\n  \"D402\",\n  \"DTZ005\",\n  \"E402\",\n  \"E501\",\n  \"E701\",\n  \"E731\",\n  \"C408\",\n  \"E203\",\n  \"G004\",\n  \"RET505\",\n  \"D106\",\n  \"D205\",\n  \"D212\",\n  \"PLW2901\",\n  \"B027\",\n  \"D404\",\n  \"D407\",\n  \"D408\",\n  \"D409\",\n  \"D400\",\n  \"D415\",\n  \"COM812\",\n  \"RET503\",\n  \"RET504\",\n  \"F403\",\n  \"F405\",\n  \"C401\",\n  \"C901\",\n  \"ASYNC230\",\n  \"ISC003\",\n  \"B024\",\n  \"B007\",\n  \"SIM102\",\n  \"W291\",\n  \"W293\",\n  \"B009\",\n  \"SIM103\",   # forbids multiple returns\n  \"SIM110\",   # requires use of any(...) instead of for-loop\n  \"G001\",     # forbids str.format in log statements\n  \"E722\",     # forbids unspecific except clause\n  \"SIM105\",   # forbids empty/general except clause\n  \"SIM113\",   # wants to enforce use of enumerate\n  \"E712\",     # forbids equality comparison with True/False\n  \"UP007\",    # forbids some uses of Union\n  \"TID252\",   # forbids relative imports\n  \"B904\",     # forces use of raise from other_exception\n  \"RUF012\",   # forbids mutable attributes as ClassVar\n  \"SIM117\",   # forbids nested with statements\n  \"C400\",     # wants to unnecessarily force use of list comprehension\n  \"UP037\",    # can incorrectly (!) convert quoted type to unquoted type, causing an error\n  \"UP045\",    # imposes T | None instead of Optional[T]\n  \"UP031\",    # forbids % operator to format strings\n  \"UP042\",    # wants str,Enum -> StrEnum (breaking change)\n  \"PLW0108\",  # unnecessary lambda (style preference)\n  \"PLC0207\",  # split vs rsplit optimization (style preference)\n]\nunfixable = [\"F841\", \"F601\", \"F602\", \"B018\"]\nextend-fixable = [\"F401\", \"B905\", \"W291\"]\n\n[tool.ruff.lint.mccabe]\nmax-complexity = 20\n\n[tool.ruff.lint.per-file-ignores]\n\"tests/**\" = [\"D103\"]\n\"scripts/**\" = [\"D103\"]\n\n[tool.pytest.ini_options]\naddopts = \"--snapshot-patch-pycharm-diff\"\nmarkers = [\n  \"clojure: language server running for Clojure\",\n  \"python: language server running for Python\",\n  \"go: language server running for Go\",\n  \"java: language server running for Java\",\n  \"kotlin: language server running for kotlin\",\n  \"groovy: language server running for Groovy\",\n  \"rust: language server running for Rust\",\n  \"typescript: language server running for TypeScript\",\n  \"vue: language server running for Vue (uses TypeScript LSP)\",\n  \"php: language server running for PHP\",\n  \"perl: language server running for Perl\",\n  \"csharp: language server running for C#\",\n  \"elixir: language server running for Elixir\",\n  \"elm: language server running for Elm\",\n  \"terraform: language server running for Terraform\",\n  \"swift: language server running for Swift\",\n  \"bash: language server running for Bash\",\n  \"r: language server running for R\",\n  \"snapshot: snapshot tests for symbolic editing operations\",\n  \"ruby: language server running for Ruby (uses ruby-lsp)\",\n  \"zig: language server running for Zig\",\n  \"lua: language server running for Lua\",\n  \"luau: language server running for Luau\",\n  \"nix: language server running for Nix\",\n  \"dart: language server running for Dart\",\n  \"erlang: language server running for Erlang\",\n  \"ocaml: language server running for OCaml and Reason\",\n  \"scala: language server running for Scala\",\n  \"al: language server running for AL (Microsoft Dynamics 365 Business Central)\",\n  \"fsharp: language server running for F#\",\n  \"rego: language server running for Rego\",\n  \"markdown: language server running for Markdown\",\n  \"julia: Julia language server tests\",\n  \"fortran: language server running for Fortran\",\n  \"haskell: Haskell language server tests\",\n  \"yaml: language server running for YAML\",\n  \"powershell: language server running for PowerShell\",\n  \"pascal: language server running for Pascal (Free Pascal/Lazarus)\",\n  \"cpp: language server running for C/C++\",\n  \"slow: tests that require additional Expert instances and have long startup times (~60-90s each)\",\n  \"toml: language server running for TOML\",\n  \"matlab: language server running for MATLAB (requires MATLAB R2021b+)\",\n  \"systemverilog: language server running for SystemVerilog (uses verible-verilog-ls)\",\n  \"hlsl: language server running for HLSL shaders (uses shader-language-server)\",\n  \"lean4: language server running for Lean 4\",\n  \"solidity: language server running for Solidity (uses @nomicfoundation/solidity-language-server)\",\n  \"ansible: language server running for Ansible (uses @ansible/ansible-language-server)\",\n]\n\n[tool.codespell]\n# Ref: https://github.com/codespell-project/codespell#using-a-config-file\nskip = '.git*,*.svg,*.lock,*.min.*'\ncheck-hidden = true\nignore-regex = '\\.\\w+'\nignore-words-list = 'paket'\n"
  },
  {
    "path": "repo_dir_sync.py",
    "content": "# -*- coding: utf-8 -*-\nimport glob\nimport os\nimport shutil\nfrom subprocess import Popen, PIPE\nimport re\nimport sys\nfrom typing import List, Optional, Sequence\nimport platform\n\n\ndef popen(cmd):\n    shell = platform.system() != \"Windows\"\n    p = Popen(cmd, shell=shell, stdin=PIPE, stdout=PIPE)\n    return p\n\n\ndef call(cmd):\n    p = popen(cmd)\n    return p.stdout.read().decode(\"utf-8\")\n\n\ndef execute(cmd, exceptionOnError=True):\n    \"\"\"\n    :param cmd: the command to execute\n    :param exceptionOnError: if True, raise on exception on error (return code not 0); if False return\n        whether the call was successful\n    :return: True if the call was successful, False otherwise (if exceptionOnError==False)\n    \"\"\"\n    p = popen(cmd)\n    p.wait()\n    success = p.returncode == 0\n    if exceptionOnError:\n        if not success:\n            raise Exception(\"Command failed: %s\" % cmd)\n    else:\n        return success\n\n\ndef gitLog(path, arg):\n    oldPath = os.getcwd()\n    os.chdir(path)\n    lg = call(\"git log --no-merges \" + arg)\n    os.chdir(oldPath)\n    return lg\n\n\ndef gitCommit(msg):\n    with open(COMMIT_MSG_FILENAME, \"wb\") as f:\n        f.write(msg.encode(\"utf-8\"))\n    gitCommitWithMessageFromFile(COMMIT_MSG_FILENAME)\n\n\ndef gitCommitWithMessageFromFile(commitMsgFilename):\n    if not os.path.exists(commitMsgFilename):\n        raise FileNotFoundError(f\"{commitMsgFilename} not found in {os.path.abspath(os.getcwd())}\")\n    os.system(f\"git commit --file={commitMsgFilename}\")\n    os.unlink(commitMsgFilename)\n\n\nCOMMIT_MSG_FILENAME = \"commitmsg.txt\"\n\n\nclass OtherRepo:\n    SYNC_COMMIT_ID_FILE_LIB_REPO = \".syncCommitId.remote\"\n    SYNC_COMMIT_ID_FILE_THIS_REPO = \".syncCommitId.this\"\n    SYNC_COMMIT_MESSAGE = f\"Updated %s sync commit identifiers\"\n    SYNC_BACKUP_DIR = \".syncBackup\"\n    \n    def __init__(self, name, branch, pathToLib):\n        self.pathToLibInThisRepo = os.path.abspath(pathToLib)\n        if not os.path.exists(self.pathToLibInThisRepo):\n            raise ValueError(f\"Repository directory '{self.pathToLibInThisRepo}' does not exist\")\n        self.name = name\n        self.branch = branch\n        self.libRepo: Optional[LibRepo] = None\n\n    def isSyncEstablished(self):\n        return os.path.exists(os.path.join(self.pathToLibInThisRepo, self.SYNC_COMMIT_ID_FILE_LIB_REPO))\n    \n    def lastSyncIdThisRepo(self):\n        with open(os.path.join(self.pathToLibInThisRepo, self.SYNC_COMMIT_ID_FILE_THIS_REPO), \"r\") as f:\n            commitId = f.read().strip()\n        return commitId\n\n    def lastSyncIdLibRepo(self):\n        with open(os.path.join(self.pathToLibInThisRepo, self.SYNC_COMMIT_ID_FILE_LIB_REPO), \"r\") as f:\n            commitId = f.read().strip()\n        return commitId\n\n    def gitLogThisRepoSinceLastSync(self):\n        lg = gitLog(self.pathToLibInThisRepo, '--name-only HEAD \"^%s\" .' % self.lastSyncIdThisRepo())\n        lg = re.sub(r'commit [0-9a-z]{8,40}\\n.*\\n.*\\n\\s*\\n.*\\n\\s*(\\n.*\\.syncCommitId\\.(this|remote))+', r\"\", lg, flags=re.MULTILINE)  # remove commits with sync commit id update\n        indent = \"  \"\n        lg = indent + lg.replace(\"\\n\", \"\\n\" + indent)\n        return lg\n\n    def gitLogLibRepoSinceLastSync(self, libRepo: \"LibRepo\"):\n        syncIdFile = os.path.join(self.pathToLibInThisRepo, self.SYNC_COMMIT_ID_FILE_LIB_REPO)\n        if not os.path.exists(syncIdFile):\n            return \"\"\n        with open(syncIdFile, \"r\") as f:\n            syncId = f.read().strip()\n        lg = gitLog(libRepo.libPath, '--name-only HEAD \"^%s\" .'  % syncId)\n        lg = re.sub(r\"Sync (\\w+)\\n\\s*\\n\", r\"Sync\\n\\n\", lg, flags=re.MULTILINE)\n        indent = \"  \"\n        lg = indent + lg.replace(\"\\n\", \"\\n\" + indent)\n        return \"\\n\\n\" + lg\n\n    def _userInputYesNo(self, question) -> bool:\n        result = None\n        while result not in (\"y\", \"n\"):\n            result = input(question + \" [y|n]: \").strip()\n        return result == \"y\"\n\n    def pull(self, libRepo: \"LibRepo\"):\n        \"\"\"\n        Pulls in changes from this repository into the lib repo\n        \"\"\"\n        # switch to branch in lib repo\n        os.chdir(libRepo.rootPath)\n        execute(\"git checkout %s\" % self.branch)\n\n        # check if the branch contains the commit that is referenced as the remote commit\n        remoteCommitId = self.lastSyncIdLibRepo()\n        remoteCommitExists = execute(\"git rev-list HEAD..%s\" % remoteCommitId, exceptionOnError=False)\n        if not remoteCommitExists:\n            if not self._userInputYesNo(f\"\\nWARNING: The referenced remote commit {remoteCommitId} does not exist \"\n                                        f\"in your {self.libRepo.name} branch '{self.branch}'!\\nSomeone else may have \"\n                                        f\"pulled/pushed in the meantime.\\nIt is recommended that you do not continue. \"\n                                        f\"Continue?\"):\n                return\n\n        # check if this branch is clean\n        lgLib = self.gitLogLibRepoSinceLastSync(libRepo).strip()\n        if lgLib != \"\":\n            print(f\"The following changes have been added to this branch in the library:\\n\\n{lgLib}\\n\\n\")\n            print(f\"ERROR: You must push these changes before you can pull or reset this branch to {remoteCommitId}\")\n            sys.exit(1)\n\n        # get log with relevant commits in this repo that are to be pulled\n        lg = self.gitLogThisRepoSinceLastSync()\n\n        os.chdir(libRepo.rootPath)\n\n        # create commit message file\n        commitMsg = f\"Sync {self.name}\\n\\n\" + lg\n        with open(COMMIT_MSG_FILENAME, \"w\") as f:\n            f.write(commitMsg)\n\n        # ask whether to commit these changes\n        print(\"Relevant commits:\\n\\n\" + lg + \"\\n\\n\")\n        if not self._userInputYesNo(f\"The above changes will be pulled from {self.name}.\\n\"\n                f\"You may change the commit message by editing {os.path.abspath(COMMIT_MSG_FILENAME)}.\\n\"\n                \"Continue?\"):\n            os.unlink(COMMIT_MSG_FILENAME)\n            return\n\n        # prepare restoration of ignored files\n        self.prepare_restoration_of_ignored_files(libRepo.rootPath)\n\n        # remove library tree in lib repo\n        shutil.rmtree(self.libRepo.libDirectory)\n\n        # copy tree from this repo to lib repo (but drop the sync commit id files)\n        shutil.copytree(self.pathToLibInThisRepo, self.libRepo.libDirectory)\n        for fn in (self.SYNC_COMMIT_ID_FILE_LIB_REPO, self.SYNC_COMMIT_ID_FILE_THIS_REPO):\n            p = os.path.join(self.libRepo.libDirectory, fn)\n            if os.path.exists(p):\n                os.unlink(p)\n\n        # restore ignored directories/files\n        self.restore_ignored_files(libRepo.rootPath)\n\n        # make commit in lib repo\n        os.system(\"git add %s\" % self.libRepo.libDirectory)\n        gitCommitWithMessageFromFile(COMMIT_MSG_FILENAME)\n        newSyncCommitIdLibRepo = call(\"git rev-parse HEAD\").strip()\n\n        # update commit ids in this repo\n        os.chdir(self.pathToLibInThisRepo)\n        newSyncCommitIdThisRepo = call(\"git rev-parse HEAD\").strip()\n        with open(self.SYNC_COMMIT_ID_FILE_LIB_REPO, \"w\") as f:\n            f.write(newSyncCommitIdLibRepo)\n        with open(self.SYNC_COMMIT_ID_FILE_THIS_REPO, \"w\") as f:\n            f.write(newSyncCommitIdThisRepo)\n        execute('git add %s %s' % (self.SYNC_COMMIT_ID_FILE_LIB_REPO, self.SYNC_COMMIT_ID_FILE_THIS_REPO))\n        execute(f'git commit -m \"{self.SYNC_COMMIT_MESSAGE % self.libRepo.name} (pull)\"')\n\n        print(f\"\\n\\nIf everything was successful, you should now push your changes to branch \"\n              f\"'{self.branch}'\\nand get your branch merged into develop (issuing a pull request where appropriate)\")\n        \n    def push(self, libRepo: \"LibRepo\"):\n        \"\"\"\n        Pushes changes from the lib repo to this repo\n        \"\"\"\n        os.chdir(libRepo.rootPath)\n\n        # switch to the source repo branch\n        execute(f\"git checkout {self.branch}\")\n\n        if self.isSyncEstablished():\n\n            # check if there are any commits that have not yet been pulled\n            unpulledCommits = self.gitLogThisRepoSinceLastSync().strip()\n            if unpulledCommits != \"\":\n                print(f\"\\n{unpulledCommits}\\n\\n\")\n                if not self._userInputYesNo(f\"WARNING: The above changes in repository '{self.name}' have not\"\n                                            f\" yet been pulled.\\nYou might want to pull them.\\n\"\n                                            f\"If you continue with the push, they will be lost. Continue?\"):\n                    return\n\n            # get change log in lib repo since last sync\n            libLogSinceLastSync = self.gitLogLibRepoSinceLastSync(libRepo)\n\n            print(\"Relevant commits:\\n\\n\" + libLogSinceLastSync + \"\\n\\n\")\n            if not self._userInputYesNo(\"The above changes will be pushed. Continue?\"):\n                return\n            print()\n        else:\n            libLogSinceLastSync = \"\"\n\n        # prepare restoration of ignored files in target repo\n        base_dir_this_repo = os.path.join(self.pathToLibInThisRepo, \"..\")\n        self.prepare_restoration_of_ignored_files(base_dir_this_repo)\n\n        # remove the target repo tree and update it with the tree from the source repo\n        shutil.rmtree(self.pathToLibInThisRepo)\n        shutil.copytree(libRepo.libPath, self.pathToLibInThisRepo)\n\n        # get the commit id of the source repo we just copied\n        commitId = call(\"git rev-parse HEAD\").strip()\n\n        # restore ignored directories and files\n        self.restore_ignored_files(base_dir_this_repo)\n\n        # go to the target repo\n        os.chdir(self.pathToLibInThisRepo)\n\n        # commit new version in this repo\n        execute(\"git add .\")\n        with open(self.SYNC_COMMIT_ID_FILE_LIB_REPO, \"w\") as f:\n            f.write(commitId)\n        execute(\"git add %s\" % self.SYNC_COMMIT_ID_FILE_LIB_REPO)\n        gitCommit(f\"{self.libRepo.name} {commitId}\" + libLogSinceLastSync)\n        commitId = call(\"git rev-parse HEAD\").strip()\n\n        # update information on the commit id we just added\n        with open(self.SYNC_COMMIT_ID_FILE_THIS_REPO, \"w\") as f:\n            f.write(commitId)\n        execute(\"git add %s\" % self.SYNC_COMMIT_ID_FILE_THIS_REPO)\n        execute(f'git commit -m \"{self.SYNC_COMMIT_MESSAGE % self.libRepo.name} (push)\"')\n\n        os.chdir(libRepo.rootPath)\n        \n        print(f\"\\n\\nIf everything was successful, you should now update the remote branch:\\ngit push\")\n\n    def prepare_restoration_of_ignored_files(self, base_dir: str):\n        \"\"\"\n        :param base_dir: the directory containing the lib directory, to which ignored paths are relative\n        \"\"\"\n        cwd = os.getcwd()\n        os.chdir(base_dir)\n\n        # ensure backup dir exists and is empty\n        if os.path.exists(self.SYNC_BACKUP_DIR):\n            shutil.rmtree(self.SYNC_BACKUP_DIR)\n        os.mkdir(self.SYNC_BACKUP_DIR)\n\n        # backup ignored, unversioned directories\n        for d in self.libRepo.fullyIgnoredUnversionedDirectories:\n            if os.path.exists(d):\n                shutil.copytree(d, os.path.join(self.SYNC_BACKUP_DIR, d))\n\n        os.chdir(cwd)\n\n    def restore_ignored_files(self, base_dir: str):\n        \"\"\"\n        :param base_dir: the directory containing the lib directory, to which ignored paths are relative\n        \"\"\"\n        cwd = os.getcwd()\n        os.chdir(base_dir)\n\n        # remove fully ignored directories that were overwritten by the sync\n        for d in self.libRepo.fullyIgnoredVersionedDirectories + self.libRepo.fullyIgnoredUnversionedDirectories:\n            if os.path.exists(d):\n                print(\"Removing overwritten content: %s\" % d)\n                shutil.rmtree(d)\n\n        # restore directories and files that can be restored via git\n        for d in self.libRepo.ignoredDirectories + self.libRepo.fullyIgnoredVersionedDirectories:\n            restoration_cmd = \"git checkout %s\" % d\n            print(\"Restoring: %s\" % restoration_cmd)\n            os.system(restoration_cmd)\n        for pattern in self.libRepo.ignoredFileGlobPatterns:\n            for path in glob.glob(pattern, recursive=True):\n                print(\"Restoring via git: %s\" % path)\n                os.system(\"git checkout %s\" % path)\n\n        # restore directories that were backed up\n        for d in self.libRepo.fullyIgnoredUnversionedDirectories:\n            if os.path.exists(os.path.join(self.SYNC_BACKUP_DIR, d)):\n                print(\"Restoring from backup: %s\" % d)\n                shutil.copytree(os.path.join(self.SYNC_BACKUP_DIR, d), d)\n\n        # remove backup dir\n        shutil.rmtree(self.SYNC_BACKUP_DIR)\n\n        os.chdir(cwd)\n\n\nclass LibRepo:\n    def __init__(self, name: str, libDirectory: str,\n            ignoredDirectories: Sequence[str] = (),\n            fullyIgnoredVersionedDirectories: Sequence[str] = (),\n            fullyIgnoredUnversionedDirectories: Sequence[str] = (),\n            ignoredFileGlobPatterns: Sequence[str] = ()\n    ):\n        \"\"\"\n        :param name: name of the library being synced\n        :param libDirectory: relative path to the library directory within this repo\n        :param ignoredDirectories: ignored directories; existing files in ignored directories will be restored\n            via 'git checkout' on pull/push, but new files will be added.\n            This is useful for configuration-like files, where users may have local changes that should not\n            be overwritten, but new files should still be added.\n        :param fullyIgnoredVersionedDirectories:\n            fully ignored versioned directories will be restored to original state after push/pull via git checkout\n        :param fullyIgnoredUnversionedDirectories:\n            fully ignored unversioned directories will be backed up and restored to original state after push/pull\n        :param ignoredFileGlobPatterns: files matching ignored glob patterns will be restored via 'git checkout'\n            on pull/push\n        \"\"\"\n        self.name = name\n        self.rootPath = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))\n        self.libDirectory = libDirectory\n        self.libPath = os.path.join(self.rootPath, self.libDirectory)\n        self.ignoredDirectories: List[str] = list(ignoredDirectories)\n        self.fullyIgnoredVersionedDirectories: List[str] = list(fullyIgnoredVersionedDirectories)\n        self.fullyIgnoredUnversionedDirectories: List[str] = list(fullyIgnoredUnversionedDirectories)\n        self.ignoredFileGlobPatterns: List[str] = list(ignoredFileGlobPatterns)\n        self.otherRepos: List[OtherRepo] = []\n\n    def add(self, repo: OtherRepo):\n        repo.libRepo = self\n        self.otherRepos.append(repo)\n\n    def runMain(self):\n        repos = self.otherRepos\n        args = sys.argv[1:]\n        if len(args) != 2:\n            print(f\"usage: sync.py <{'|'.join([repo.name for repo in repos])}> <push|pull>\")\n        else:\n            repo = [r for r in repos if r.name == args[0]]\n            if len(repo) != 1:\n                raise ValueError(f\"Unknown repo '{args[0]}'\")\n            repo = repo[0]\n\n            if args[1] == \"push\":\n                repo.push(self)\n            elif args[1] == \"pull\":\n                repo.pull(self)\n            else:\n                raise ValueError(f\"Unknown command '{args[1]}'\")\n"
  },
  {
    "path": "scripts/agno_agent.py",
    "content": "from agno.models.anthropic.claude import Claude\nfrom agno.models.google.gemini import Gemini\nfrom agno.os import AgentOS\nfrom sensai.util import logging\nfrom sensai.util.helper import mark_used\n\nfrom serena.agno import SerenaAgnoAgentProvider\n\nmark_used(Gemini, Claude)\n\n# initialize logging\nif __name__ == \"__main__\":\n    logging.configure(level=logging.INFO)\n\n# Define the model to use (see Agno documentation for supported models; these are just examples)\n# model = Claude(id=\"claude-3-7-sonnet-20250219\")\nmodel = Gemini(id=\"gemini-2.5-pro\")\n\n# Create the Serena agent using the existing provider\nserena_agent = SerenaAgnoAgentProvider.get_agent(model)\n\n# Create AgentOS app with the Serena agent\nagent_os = AgentOS(\n    description=\"Serena coding assistant powered by AgentOS\",\n    id=\"serena-agentos\",\n    agents=[serena_agent],\n)\n\napp = agent_os.get_app()\n\nif __name__ == \"__main__\":\n    # Start the AgentOS server\n    agent_os.serve(app=\"agno_agent:app\", reload=False)\n"
  },
  {
    "path": "scripts/demo_run_tools.py",
    "content": "\"\"\"\nThis script demonstrates how to use Serena's tools locally, useful\nfor testing or development. Here the tools will be operation the serena repo itself.\n\"\"\"\n\nimport json\nfrom pprint import pprint\n\nfrom serena.agent import SerenaAgent\nfrom serena.config.serena_config import SerenaConfig\nfrom serena.constants import REPO_ROOT\nfrom serena.tools import (\n    FindFileTool,\n    FindReferencingSymbolsTool,\n    JetBrainsFindSymbolTool,\n    JetBrainsGetSymbolsOverviewTool,\n    SearchForPatternTool,\n)\n\nif __name__ == \"__main__\":\n    serena_config = SerenaConfig.from_config_file()\n    serena_config.web_dashboard = False\n    agent = SerenaAgent(project=REPO_ROOT, serena_config=serena_config)\n\n    # apply a tool\n    find_symbol_tool = agent.get_tool(JetBrainsFindSymbolTool)\n    find_refs_tool = agent.get_tool(FindReferencingSymbolsTool)\n    find_file_tool = agent.get_tool(FindFileTool)\n    search_pattern_tool = agent.get_tool(SearchForPatternTool)\n    overview_tool = agent.get_tool(JetBrainsGetSymbolsOverviewTool)\n\n    result = agent.execute_task(\n        lambda: find_symbol_tool.apply(\"SerenaAgent/get_tool_description_override\"),\n    )\n    pprint(json.loads(result))\n    # input(\"Press Enter to continue...\")\n"
  },
  {
    "path": "scripts/gen_prompt_factory.py",
    "content": "\"\"\"\r\nAutogenerates the `prompt_factory.py` module\r\n\"\"\"\r\n\r\nfrom pathlib import Path\r\n\r\nfrom sensai.util import logging\r\n\r\nfrom interprompt import autogenerate_prompt_factory_module\r\nfrom serena.constants import PROMPT_TEMPLATES_DIR_INTERNAL, REPO_ROOT\r\n\r\nlog = logging.getLogger(__name__)\r\n\r\n\r\ndef main():\r\n    autogenerate_prompt_factory_module(\r\n        prompts_dir=PROMPT_TEMPLATES_DIR_INTERNAL,\r\n        target_module_path=str(Path(REPO_ROOT) / \"src\" / \"serena\" / \"generated\" / \"generated_prompt_factory.py\"),\r\n    )\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    logging.run_main(main)\r\n"
  },
  {
    "path": "scripts/mcp_server.py",
    "content": "from serena.cli import start_mcp_server\r\n\r\nif __name__ == \"__main__\":\r\n    start_mcp_server()\r\n"
  },
  {
    "path": "scripts/print_language_list.py",
    "content": "\"\"\"\nPrints the list of supported languages, for use in the project.yml template\n\"\"\"\n\nfrom solidlsp.ls_config import Language\n\nif __name__ == \"__main__\":\n    lang_strings = sorted([l.value for l in Language])\n    max_len = max(len(s) for s in lang_strings)\n    fmt = f\"%-{max_len+2}s\"\n    for i, l in enumerate(lang_strings):\n        if i % 5 == 0:\n            print(\"\\n# \", end=\"\")\n        print(\"  \" + fmt % l, end=\"\")\n"
  },
  {
    "path": "scripts/print_mode_context_options.py",
    "content": "from serena.config.context_mode import SerenaAgentContext, SerenaAgentMode\n\nif __name__ == \"__main__\":\n    print(\"---------- Available modes: ----------\")\n    for mode_name in SerenaAgentMode.list_registered_mode_names():\n        mode = SerenaAgentMode.load(mode_name)\n        mode.print_overview()\n        print(\"\\n\")\n    print(\"---------- Available contexts: ----------\")\n    for context_name in SerenaAgentContext.list_registered_context_names():\n        context = SerenaAgentContext.load(context_name)\n        context.print_overview()\n        print(\"\\n\")\n"
  },
  {
    "path": "scripts/print_tool_overview.py",
    "content": "from serena.agent import ToolRegistry\n\nif __name__ == \"__main__\":\n    ToolRegistry().print_tool_overview()\n"
  },
  {
    "path": "scripts/profile_tool_call.py",
    "content": "import cProfile\nfrom pathlib import Path\nfrom typing import Literal\n\nfrom sensai.util import logging\nfrom sensai.util.logging import LogTime\nfrom sensai.util.profiling import profiled\n\nfrom serena.agent import SerenaAgent\nfrom serena.config.serena_config import SerenaConfig\nfrom serena.tools import FindSymbolTool\n\nlog = logging.getLogger(__name__)\n\n\nif __name__ == \"__main__\":\n    logging.configure()\n\n    # The profiler to use:\n    # Use pyinstrument for hierarchical profiling output\n    # Use cProfile to determine which functions take the most time overall (and use snakeviz to visualize)\n    profiler: Literal[\"pyinstrument\", \"cprofile\"] = \"cprofile\"\n\n    project_path = Path(__file__).parent.parent  # Serena root\n\n    serena_config = SerenaConfig.from_config_file()\n    serena_config.log_level = logging.INFO\n    serena_config.gui_log_window = False\n    serena_config.web_dashboard = False\n\n    agent = SerenaAgent(str(project_path), serena_config=serena_config)\n\n    # wait for language server to be ready\n    agent.execute_task(lambda: log.info(\"Language server is ready.\"))\n\n    def tool_call():\n        \"\"\"This is the function we want to profile.\"\"\"\n        # NOTE: We use apply (not apply_ex) to run the tool call directly on the main thread\n        with LogTime(\"Tool call\"):\n            result = agent.get_tool(FindSymbolTool).apply(name_path=\"DQN\")\n        log.info(\"Tool result:\\n%s\", result)\n\n    if profiler == \"pyinstrument\":\n\n        @profiled(log_to_file=True)\n        def profiled_tool_call():\n            tool_call()\n\n        profiled_tool_call()\n\n    elif profiler == \"cprofile\":\n        cProfile.run(\"tool_call()\", \"tool_call.pstat\")\n"
  },
  {
    "path": "src/README.md",
    "content": "Serena uses (modified) versions of other libraries/packages:\n\n * solidlsp (our fork of [microsoft/multilspy](https://github.com/microsoft/multilspy) for fully synchronous language server communication)\n * [interprompt](https://github.com/oraios/interprompt) (our prompt templating library)\n"
  },
  {
    "path": "src/interprompt/.syncCommitId.remote",
    "content": "059d50b7d4d7e8fb9e7a13df7f7f33bae1aed5e2"
  },
  {
    "path": "src/interprompt/.syncCommitId.this",
    "content": "53ee7f47c08f29ae336567bcfaf89f79e7d447a2"
  },
  {
    "path": "src/interprompt/__init__.py",
    "content": "from .prompt_factory import autogenerate_prompt_factory_module\n\n__all__ = [\"autogenerate_prompt_factory_module\"]\n"
  },
  {
    "path": "src/interprompt/jinja_template.py",
    "content": "from typing import Any\n\nimport jinja2\nimport jinja2.meta\nimport jinja2.nodes\nimport jinja2.visitor\n\nfrom interprompt.util.class_decorators import singleton\n\n\nclass ParameterizedTemplateInterface:\n    def get_parameters(self) -> list[str]: ...\n\n\n@singleton\nclass _JinjaEnvProvider:\n    def __init__(self) -> None:\n        self._env: jinja2.Environment | None = None\n\n    def get_env(self) -> jinja2.Environment:\n        if self._env is None:\n            self._env = jinja2.Environment()\n        return self._env\n\n\nclass JinjaTemplate(ParameterizedTemplateInterface):\n    def __init__(self, template_string: str) -> None:\n        self._template_string = template_string\n        self._template = _JinjaEnvProvider().get_env().from_string(self._template_string)\n        parsed_content = self._template.environment.parse(self._template_string)\n        self._parameters = sorted(jinja2.meta.find_undeclared_variables(parsed_content))\n\n    def render(self, **params: Any) -> str:\n        \"\"\"Renders the template with the given kwargs. You can find out which parameters are required by calling get_parameter_names().\"\"\"\n        return self._template.render(**params)\n\n    def get_parameters(self) -> list[str]:\n        \"\"\"A sorted list of parameter names that are extracted from the template string. It is impossible to know the types of the parameter\n        values, they can be primitives, dicts or dict-like objects.\n\n        :return: the list of parameter names\n        \"\"\"\n        return self._parameters\n"
  },
  {
    "path": "src/interprompt/multilang_prompt.py",
    "content": "import logging\nimport os\nfrom enum import Enum\nfrom typing import Any, Generic, Literal, TypeVar\n\nimport yaml\nfrom sensai.util.string import ToStringMixin\n\nfrom .jinja_template import JinjaTemplate, ParameterizedTemplateInterface\n\nlog = logging.getLogger(__name__)\n\n\nclass PromptTemplate(ToStringMixin, ParameterizedTemplateInterface):\n    def __init__(self, name: str, jinja_template_string: str) -> None:\n        self.name = name\n        self._jinja_template = JinjaTemplate(jinja_template_string.strip())\n\n    def _tostring_exclude_private(self) -> bool:\n        return True\n\n    def render(self, **params: Any) -> str:\n        return self._jinja_template.render(**params)\n\n    def get_parameters(self) -> list[str]:\n        return self._jinja_template.get_parameters()\n\n\nclass PromptList:\n    def __init__(self, items: list[str]) -> None:\n        self.items = [x.strip() for x in items]\n\n    def to_string(self) -> str:\n        bullet = \" * \"\n        indent = \" \" * len(bullet)\n        items = [x.replace(\"\\n\", \"\\n\" + indent) for x in self.items]\n        return \"\\n * \".join(items)\n\n\nT = TypeVar(\"T\")\nDEFAULT_LANG_CODE = \"default\"\n\n\nclass LanguageFallbackMode(Enum):\n    \"\"\"\n    Defines what to do if there is no item for the given language.\n    \"\"\"\n\n    ANY = \"any\"\n    \"\"\"\n    Return the item for any language (the first one found)\n    \"\"\"\n    EXCEPTION = \"exception\"\n    \"\"\"\n    If the requested language is not found, raise an exception\n    \"\"\"\n    USE_DEFAULT_LANG = \"use_default_lang\"\n    \"\"\"\n    If the requested language is not found, use the default language\n    \"\"\"\n\n\nclass _MultiLangContainer(Generic[T], ToStringMixin):\n    \"\"\"\n    A container of items (usually, all having the same semantic meaning) which are associated with different languages.\n    Can also be used for single-language purposes by always using the default language code.\n    \"\"\"\n\n    def __init__(self, name: str) -> None:\n        self.name = name\n        self._lang2item: dict[str, T] = {}\n        \"\"\"Maps language codes to items\"\"\"\n\n    def _tostring_excludes(self) -> list[str]:\n        return [\"lang2item\"]\n\n    def _tostring_additional_entries(self) -> dict[str, Any]:\n        return dict(languages=list(self._lang2item.keys()))\n\n    def get_language_codes(self) -> list[str]:\n        \"\"\"The language codes for which items are registered in the container.\"\"\"\n        return list(self._lang2item.keys())\n\n    def add_item(self, item: T, lang_code: str = DEFAULT_LANG_CODE, allow_overwrite: bool = False) -> None:\n        \"\"\"Adds an item to the container, representing the same semantic entity as the other items in the container but in a different language.\n\n        :param item: the item to add\n        :param lang_code: the language shortcode for which to add the item. Use the default for single-language use cases.\n        :param allow_overwrite: if True, allow overwriting an existing entry for the same language\n        \"\"\"\n        if not allow_overwrite and lang_code in self._lang2item:\n            raise KeyError(f\"Item for language '{lang_code}' already registered for name '{self.name}'\")\n        self._lang2item[lang_code] = item\n\n    def has_item(self, lang_code: str = DEFAULT_LANG_CODE) -> bool:\n        return lang_code in self._lang2item\n\n    def get_item(self, lang: str = DEFAULT_LANG_CODE, fallback_mode: LanguageFallbackMode = LanguageFallbackMode.EXCEPTION) -> T:\n        \"\"\"\n        Gets the item for the given language.\n\n        :param lang: the language shortcode for which to obtain the prompt template. A default language can be specified.\n        :param fallback_mode: defines what to do if there is no item for the given language\n        :return: the item\n        \"\"\"\n        try:\n            return self._lang2item[lang]\n        except KeyError as outer_e:\n            if fallback_mode == LanguageFallbackMode.EXCEPTION:\n                raise KeyError(f\"Item for language '{lang}' not found for name '{self.name}'\") from outer_e\n            if fallback_mode == LanguageFallbackMode.ANY:\n                try:\n                    return next(iter(self._lang2item.values()))\n                except StopIteration as e:\n                    raise KeyError(f\"No items registered for any language in container '{self.name}'\") from e\n            if fallback_mode == LanguageFallbackMode.USE_DEFAULT_LANG:\n                try:\n                    return self._lang2item[DEFAULT_LANG_CODE]\n                except KeyError as e:\n                    raise KeyError(\n                        f\"Item not found neither for {lang=} nor for the default language '{DEFAULT_LANG_CODE}' in container '{self.name}'\"\n                    ) from e\n\n    def __len__(self) -> int:\n        return len(self._lang2item)\n\n\nclass MultiLangPromptTemplate(ParameterizedTemplateInterface):\n    \"\"\"\n    Represents a prompt template with support for multiple languages.\n    The parameters of all prompt templates (for all languages) are (must be) the same.\n    \"\"\"\n\n    def __init__(self, name: str) -> None:\n        self._prompts_container = _MultiLangContainer[PromptTemplate](name)\n\n    def __len__(self) -> int:\n        return len(self._prompts_container)\n\n    @property\n    def name(self) -> str:\n        return self._prompts_container.name\n\n    def add_prompt_template(\n        self, prompt_template: PromptTemplate, lang_code: str = DEFAULT_LANG_CODE, allow_overwrite: bool = False\n    ) -> None:\n        \"\"\"\n        Adds a prompt template for a new language.\n        The parameters of all prompt templates (for all languages) are (must be) the same, so if a prompt template is already registered,\n        the parameters of the new prompt template should be the same as the existing ones.\n\n        :param prompt_template: the prompt template to add\n        :param lang_code: the language code for which to add the prompt template. For single-language use cases, you should always use the default language code.\n        :param allow_overwrite: whether to allow overwriting an existing entry for the same language\n        \"\"\"\n        incoming_parameters = prompt_template.get_parameters()\n        if len(self) > 0:\n            parameters = self.get_parameters()\n            if parameters != incoming_parameters:\n                raise ValueError(\n                    f\"Cannot add prompt template for language '{lang_code}' to MultiLangPromptTemplate '{self.name}'\"\n                    f\"because the parameters are inconsistent: {parameters} vs {prompt_template.get_parameters()}\"\n                )\n\n        self._prompts_container.add_item(prompt_template, lang_code, allow_overwrite)\n\n    def get_prompt_template(\n        self, lang_code: str = DEFAULT_LANG_CODE, fallback_mode: LanguageFallbackMode = LanguageFallbackMode.EXCEPTION\n    ) -> PromptTemplate:\n        return self._prompts_container.get_item(lang_code, fallback_mode)\n\n    def get_parameters(self) -> list[str]:\n        if len(self) == 0:\n            raise RuntimeError(\n                f\"No prompt templates registered for MultiLangPromptTemplate '{self.name}', make sure to register a prompt template before accessing the parameters\"\n            )\n        first_prompt_template = next(iter(self._prompts_container._lang2item.values()))\n        return first_prompt_template.get_parameters()\n\n    def render(\n        self,\n        params: dict[str, Any],\n        lang_code: str = DEFAULT_LANG_CODE,\n        fallback_mode: LanguageFallbackMode = LanguageFallbackMode.EXCEPTION,\n    ) -> str:\n        prompt_template = self.get_prompt_template(lang_code, fallback_mode)\n        return prompt_template.render(**params)\n\n    def has_item(self, lang_code: str = DEFAULT_LANG_CODE) -> bool:\n        return self._prompts_container.has_item(lang_code)\n\n\nclass MultiLangPromptList(_MultiLangContainer[PromptList]):\n    pass\n\n\nclass MultiLangPromptCollection:\n    \"\"\"\n    Main class for managing a collection of prompt templates and prompt lists, with support for multiple languages.\n    All data will be read from the yamls directly contained in the given directory on initialization.\n    It is thus assumed that you manage one directory per prompt collection.\n\n    The yamls are assumed to be either of the form\n\n    ```yaml\n    lang: <language_code> # optional, defaults to \"default\"\n    prompts:\n      <prompt_name>:\n        <prompt_template_string>\n      <prompt_list_name>: [<prompt_string_1>, <prompt_string_2>, ...]\n\n    ```\n\n    When specifying prompt templates for multiple languages, make sure that the Jinja template parameters\n    (inferred from the things inside the `{{ }}` in the template strings) are the same for all languages\n    (you will get an exception otherwise).\n\n    The prompt names must be unique (for the same language) within the collection.\n    \"\"\"\n\n    def __init__(self, prompts_dir: str | list[str], fallback_mode: LanguageFallbackMode = LanguageFallbackMode.EXCEPTION) -> None:\n        \"\"\"\n        :param prompts_dir: the directory containing the prompt templates and prompt lists.\n            If a list is provided, will look for prompt templates in the dirs from left to right\n            (first one containing the desired template wins).\n        :param fallback_mode: the fallback mode to use when a prompt template or prompt list is not found for the requested language.\n            May be reset after initialization.\n        \"\"\"\n        self._multi_lang_prompt_templates: dict[str, MultiLangPromptTemplate] = {}\n        self._multi_lang_prompt_lists: dict[str, MultiLangPromptList] = {}\n        if isinstance(prompts_dir, str):\n            prompts_dir = [prompts_dir]\n\n        # Add prompts from multiple directories, prioritizing names from the left.\n        # If name collisions appear in the first directory, an error is raised (so the first directory should have no\n        # internal collisions, this helps in avoiding errors)\n        # For all following directories, on a collision the new value will be ignored.\n        # This also means that for the following directories, there is no error check on collisions internal to them.\n        # We assume that they are correct (i.e., they have no internal collisions).\n        first_prompts_dir, fallback_prompt_dirs = prompts_dir[0], prompts_dir[1:]\n        self._load_from_disc(first_prompts_dir, on_name_collision=\"raise\")\n        for fallback_prompt_dir in fallback_prompt_dirs:\n            # already loaded prompts have priority\n            self._load_from_disc(fallback_prompt_dir, on_name_collision=\"skip\")\n\n        self.fallback_mode = fallback_mode\n\n    def _add_prompt_template(\n        self,\n        name: str,\n        template_str: str,\n        lang_code: str = DEFAULT_LANG_CODE,\n        on_name_collision: Literal[\"skip\", \"overwrite\", \"raise\"] = \"raise\",\n    ) -> None:\n        \"\"\"\n        :param name: name of the prompt template\n        :param template_str: the Jinja template string\n        :param lang_code: the language code for which to add the prompt template.\n        :param on_name_collision: how to deal with name/lang_code collisions\n        \"\"\"\n        allow_overwrite = False\n        prompt_template = PromptTemplate(name, template_str)\n        mlpt = self._multi_lang_prompt_templates.get(name)\n        if mlpt is None:\n            mlpt = MultiLangPromptTemplate(name)\n            self._multi_lang_prompt_templates[name] = mlpt\n        if mlpt.has_item(lang_code):\n            if on_name_collision == \"raise\":\n                raise KeyError(f\"Prompt '{name}' for {lang_code} already exists!\")\n            if on_name_collision == \"skip\":\n                log.debug(f\"Skipping prompt '{name}' since it already exists.\")\n                return\n            elif on_name_collision == \"overwrite\":\n                allow_overwrite = True\n        mlpt.add_prompt_template(prompt_template, lang_code=lang_code, allow_overwrite=allow_overwrite)\n\n    def _add_prompt_list(\n        self,\n        name: str,\n        prompt_list: list[str],\n        lang_code: str = DEFAULT_LANG_CODE,\n        on_name_collision: Literal[\"skip\", \"overwrite\", \"raise\"] = \"raise\",\n    ) -> None:\n        \"\"\"\n        :param name: name of the prompt list\n        :param prompt_list: a list of prompts\n        :param lang_code: the language code for which to add the prompt list.\n        :param on_name_collision: how to deal with name/lang_code collisions\n        \"\"\"\n        allow_overwrite = False\n        multilang_prompt_list = self._multi_lang_prompt_lists.get(name)\n        if multilang_prompt_list is None:\n            multilang_prompt_list = MultiLangPromptList(name)\n            self._multi_lang_prompt_lists[name] = multilang_prompt_list\n        if multilang_prompt_list.has_item(lang_code):\n            if on_name_collision == \"raise\":\n                raise KeyError(f\"Prompt '{name}' for {lang_code} already exists!\")\n            if on_name_collision == \"skip\":\n                log.debug(f\"Skipping prompt '{name}' since it already exists.\")\n                return\n            elif on_name_collision == \"overwrite\":\n                allow_overwrite = True\n        multilang_prompt_list.add_item(PromptList(prompt_list), lang_code=lang_code, allow_overwrite=allow_overwrite)\n\n    def _load_from_disc(self, prompts_dir: str, on_name_collision: Literal[\"skip\", \"overwrite\", \"raise\"] = \"raise\") -> None:\n        \"\"\"Loads all prompt templates and prompt lists from yaml files in the given directory.\n\n        :param prompts_dir:\n        :param on_name_collision: how to deal with name/lang_code collisions\n        \"\"\"\n        for fn in os.listdir(prompts_dir):\n            if not fn.endswith((\".yml\", \".yaml\")):\n                log.debug(f\"Skipping non-YAML file: {fn}\")\n                continue\n            path = os.path.join(prompts_dir, fn)\n            with open(path, encoding=\"utf-8\") as f:\n                data = yaml.safe_load(f)\n            try:\n                prompts_data = data[\"prompts\"]\n            except KeyError as e:\n                raise KeyError(f\"Invalid yaml structure (missing 'prompts' key) in file {path}\") from e\n\n            lang_code = prompts_data.get(\"lang\", DEFAULT_LANG_CODE)\n            # add the data to the collection\n            for prompt_name, prompt_template_or_list in prompts_data.items():\n                if isinstance(prompt_template_or_list, list):\n                    self._add_prompt_list(prompt_name, prompt_template_or_list, lang_code=lang_code, on_name_collision=on_name_collision)\n                elif isinstance(prompt_template_or_list, str):\n                    self._add_prompt_template(\n                        prompt_name, prompt_template_or_list, lang_code=lang_code, on_name_collision=on_name_collision\n                    )\n                else:\n                    raise ValueError(\n                        f\"Invalid prompt type for {prompt_name} in file {path} (should be str or list): {prompt_template_or_list}\"\n                    )\n\n    def get_prompt_template_names(self) -> list[str]:\n        return list(self._multi_lang_prompt_templates.keys())\n\n    def get_prompt_list_names(self) -> list[str]:\n        return list(self._multi_lang_prompt_lists.keys())\n\n    def __len__(self) -> int:\n        return len(self._multi_lang_prompt_templates)\n\n    def get_multilang_prompt_template(self, prompt_name: str) -> MultiLangPromptTemplate:\n        \"\"\"The MultiLangPromptTemplate object for the given prompt name. For single-language use cases, you should use the `get_prompt_template` method instead.\"\"\"\n        return self._multi_lang_prompt_templates[prompt_name]\n\n    def get_multilang_prompt_list(self, prompt_name: str) -> MultiLangPromptList:\n        return self._multi_lang_prompt_lists[prompt_name]\n\n    def get_prompt_template(\n        self,\n        prompt_name: str,\n        lang_code: str = DEFAULT_LANG_CODE,\n    ) -> PromptTemplate:\n        \"\"\"The PromptTemplate object for the given prompt name and language code.\"\"\"\n        return self.get_multilang_prompt_template(prompt_name).get_prompt_template(lang_code=lang_code, fallback_mode=self.fallback_mode)\n\n    def get_prompt_template_parameters(self, prompt_name: str) -> list[str]:\n        \"\"\"The parameters of the PromptTemplate object for the given prompt name.\"\"\"\n        return self.get_multilang_prompt_template(prompt_name).get_parameters()\n\n    def get_prompt_list(self, prompt_name: str, lang_code: str = DEFAULT_LANG_CODE) -> PromptList:\n        \"\"\"The PromptList object for the given prompt name and language code.\"\"\"\n        return self.get_multilang_prompt_list(prompt_name).get_item(lang_code)\n\n    def _has_prompt_list(self, prompt_name: str, lang_code: str = DEFAULT_LANG_CODE) -> bool:\n        multi_lang_prompt_list = self._multi_lang_prompt_lists.get(prompt_name)\n        if multi_lang_prompt_list is None:\n            return False\n        return multi_lang_prompt_list.has_item(lang_code)\n\n    def _has_prompt_template(self, prompt_name: str, lang_code: str = DEFAULT_LANG_CODE) -> bool:\n        multi_lang_prompt_template = self._multi_lang_prompt_templates.get(prompt_name)\n        if multi_lang_prompt_template is None:\n            return False\n        return multi_lang_prompt_template.has_item(lang_code)\n\n    def render_prompt_template(\n        self,\n        prompt_name: str,\n        params: dict[str, Any],\n        lang_code: str = DEFAULT_LANG_CODE,\n    ) -> str:\n        \"\"\"Renders the prompt template for the given prompt name and language code.\"\"\"\n        return self.get_prompt_template(prompt_name, lang_code=lang_code).render(**params)\n"
  },
  {
    "path": "src/interprompt/prompt_factory.py",
    "content": "import logging\nimport os\nfrom typing import Any\n\nfrom .multilang_prompt import DEFAULT_LANG_CODE, LanguageFallbackMode, MultiLangPromptCollection, PromptList\n\nlog = logging.getLogger(__name__)\n\n\nclass PromptFactoryBase:\n    \"\"\"Base class for auto-generated prompt factory classes.\"\"\"\n\n    def __init__(self, prompts_dir: str | list[str], lang_code: str = DEFAULT_LANG_CODE, fallback_mode=LanguageFallbackMode.EXCEPTION):\n        \"\"\"\n        :param prompts_dir: the directory containing the prompt templates and prompt lists.\n            If a list is provided, will look for prompt templates in the dirs from left to right\n            (first one containing the desired template wins).\n        :param lang_code: the language code to use for retrieving the prompt templates and prompt lists.\n            Leave as `default` for single-language use cases.\n        :param fallback_mode: the fallback mode to use when a prompt template or prompt list is not found for the requested language.\n            Irrelevant for single-language use cases.\n        \"\"\"\n        self.lang_code = lang_code\n        self._prompt_collection = MultiLangPromptCollection(prompts_dir, fallback_mode=fallback_mode)\n\n    def _render_prompt(self, prompt_name: str, params: dict[str, Any]) -> str:\n        del params[\"self\"]\n        return self._prompt_collection.render_prompt_template(prompt_name, params, lang_code=self.lang_code)\n\n    def _get_prompt_list(self, prompt_name: str) -> PromptList:\n        return self._prompt_collection.get_prompt_list(prompt_name, self.lang_code)\n\n\ndef autogenerate_prompt_factory_module(prompts_dir: str, target_module_path: str) -> None:\n    \"\"\"\n    Auto-generates a prompt factory module for the given prompt directory.\n    The generated `PromptFactory` class is meant to be the central entry class for retrieving and rendering prompt templates and prompt\n    lists in your application.\n    It will contain one method per prompt template and prompt list, and is useful for both single- and multi-language use cases.\n\n    :param prompts_dir: the directory containing the prompt templates and prompt lists\n    :param target_module_path: the path to the target module file (.py). Important: The module will be overwritten!\n    \"\"\"\n    generated_code = \"\"\"\n# ruff: noqa\n# black: skip\n# mypy: ignore-errors\n\n# NOTE: This module is auto-generated from interprompt.autogenerate_prompt_factory_module, do not edit manually!\n\nfrom interprompt.multilang_prompt import PromptList\nfrom interprompt.prompt_factory import PromptFactoryBase\nfrom typing import Any\n\n\nclass PromptFactory(PromptFactoryBase):\n    \\\"\"\"\n    A class for retrieving and rendering prompt templates and prompt lists.\n    \\\"\"\"\n\"\"\"\n    # ---- add methods based on prompt template names and parameters and prompt list names ----\n    prompt_collection = MultiLangPromptCollection(prompts_dir)\n\n    for template_name in prompt_collection.get_prompt_template_names():\n        template_parameters = prompt_collection.get_prompt_template_parameters(template_name)\n        if len(template_parameters) == 0:\n            method_params_str = \"\"\n        else:\n            method_params_str = \", *, \" + \", \".join([f\"{param}: Any\" for param in template_parameters])\n        generated_code += f\"\"\"\n    def create_{template_name}(self{method_params_str}) -> str:\n        return self._render_prompt('{template_name}', locals())\n\"\"\"\n    for prompt_list_name in prompt_collection.get_prompt_list_names():\n        generated_code += f\"\"\"\n    def get_list_{prompt_list_name}(self) -> PromptList:\n        return self._get_prompt_list('{prompt_list_name}')\n\"\"\"\n    os.makedirs(os.path.dirname(target_module_path), exist_ok=True)\n    with open(target_module_path, \"w\", encoding=\"utf-8\") as f:\n        f.write(generated_code)\n    log.info(f\"Prompt factory generated successfully in {target_module_path}\")\n"
  },
  {
    "path": "src/interprompt/util/__init__.py",
    "content": ""
  },
  {
    "path": "src/interprompt/util/class_decorators.py",
    "content": "from typing import Any\n\n\ndef singleton(cls: type[Any]) -> Any:\n    instance = None\n\n    def get_instance(*args: Any, **kwargs: Any) -> Any:\n        nonlocal instance\n        if instance is None:\n            instance = cls(*args, **kwargs)\n        return instance\n\n    return get_instance\n"
  },
  {
    "path": "src/serena/__init__.py",
    "content": "__version__ = \"0.1.4\"\n\nimport logging\n\nlog = logging.getLogger(__name__)\n\n\ndef serena_version() -> str:\n    \"\"\"\n    :return: the version of the package, including git status if available.\n    \"\"\"\n    from serena.util.git import get_git_status\n\n    version = __version__\n    try:\n        git_status = get_git_status()\n        if git_status is not None:\n            version += f\"-{git_status.commit[:8]}\"\n            if not git_status.is_clean:\n                version += \"-dirty\"\n    except:\n        pass\n    return version\n"
  },
  {
    "path": "src/serena/agent.py",
    "content": "\"\"\"\nThe Serena Model Context Protocol (MCP) Server\n\"\"\"\n\nimport os\nimport platform\nimport subprocess\nimport sys\nfrom collections.abc import Callable, Iterator, Sequence\nfrom contextlib import contextmanager\nfrom logging import Logger\nfrom typing import TYPE_CHECKING, Optional, TypeVar\n\nfrom sensai.util import logging\nfrom sensai.util.logging import LogTime\nfrom sensai.util.string import dict_string\n\nfrom interprompt.jinja_template import JinjaTemplate\nfrom serena import serena_version\nfrom serena.analytics import RegisteredTokenCountEstimator, ToolUsageStats\nfrom serena.config.context_mode import SerenaAgentContext, SerenaAgentMode\nfrom serena.config.serena_config import (\n    LanguageBackend,\n    ModeSelectionDefinition,\n    NamedToolInclusionDefinition,\n    RegisteredProject,\n    SerenaConfig,\n    SerenaPaths,\n    ToolInclusionDefinition,\n)\nfrom serena.dashboard import SerenaDashboardAPI\nfrom serena.ls_manager import LanguageServerManager\nfrom serena.project import MemoriesManager, Project\nfrom serena.prompt_factory import SerenaPromptFactory\nfrom serena.task_executor import TaskExecutor\nfrom serena.tools import ActivateProjectTool, GetCurrentConfigTool, OpenDashboardTool, ReplaceContentTool, Tool, ToolMarker, ToolRegistry\nfrom serena.util.gui import system_has_usable_display\nfrom serena.util.inspection import iter_subclasses\nfrom serena.util.logging import MemoryLogHandler\nfrom solidlsp.ls_config import Language\n\nif TYPE_CHECKING:\n    from serena.gui_log_viewer import GuiLogViewer\n\nlog = logging.getLogger(__name__)\nTTool = TypeVar(\"TTool\", bound=\"Tool\")\nT = TypeVar(\"T\")\nSUCCESS_RESULT = \"OK\"\n\n\nclass ProjectNotFoundError(Exception):\n    pass\n\n\nclass AvailableTools:\n    \"\"\"\n    Represents the set of available/exposed tools of a SerenaAgent.\n    \"\"\"\n\n    def __init__(self, tools: list[Tool]):\n        \"\"\"\n        :param tools: the list of available tools\n        \"\"\"\n        self.tools = tools\n        self.tool_names = sorted([tool.get_name_from_cls() for tool in tools])\n        \"\"\"\n        the list of available tool names, sorted alphabetically\n        \"\"\"\n        self._tool_name_set = set(self.tool_names)\n        self.tool_marker_names = set()\n        for marker_class in iter_subclasses(ToolMarker):\n            for tool in tools:\n                if isinstance(tool, marker_class):\n                    self.tool_marker_names.add(marker_class.__name__)\n\n    def __len__(self) -> int:\n        return len(self.tools)\n\n    def contains_tool_name(self, tool_name: str) -> bool:\n        return tool_name in self._tool_name_set\n\n\nclass ToolSet:\n    \"\"\"\n    Represents a set of tools by their names.\n    \"\"\"\n\n    LEGACY_TOOL_NAME_MAPPING = {\"replace_regex\": ReplaceContentTool.get_name_from_cls()}\n    \"\"\"\n    maps legacy tool names to their new names for backward compatibility\n    \"\"\"\n\n    def __init__(self, tool_names: set[str]) -> None:\n        self._tool_names = tool_names\n\n    def __len__(self) -> int:\n        return len(self._tool_names)\n\n    @classmethod\n    def default(cls) -> \"ToolSet\":\n        \"\"\"\n        :return: the default tool set, which contains all tools that are enabled by default\n        \"\"\"\n        from serena.tools import ToolRegistry\n\n        return cls(set(ToolRegistry().get_tool_names_default_enabled()))\n\n    def apply(self, *tool_inclusion_definitions: \"ToolInclusionDefinition\") -> \"ToolSet\":\n        \"\"\"\n        Applies one or more tool inclusion definitions to this tool set,\n        resulting in a new tool set.\n\n        :param tool_inclusion_definitions: the definitions to apply\n        :return: a new tool set with the definitions applied\n        \"\"\"\n        from serena.tools import ToolRegistry\n\n        def get_updated_tool_name(tool_name: str) -> str:\n            \"\"\"Retrieves the updated tool name if the provided tool name is deprecated, logging a warning.\"\"\"\n            if tool_name in self.LEGACY_TOOL_NAME_MAPPING:\n                new_tool_name = self.LEGACY_TOOL_NAME_MAPPING[tool_name]\n                log.warning(\"Tool name '%s' is deprecated, please use '%s' instead\", tool_name, new_tool_name)\n                return new_tool_name\n            return tool_name\n\n        registry = ToolRegistry()\n        tool_names = set(self._tool_names)\n        for definition in tool_inclusion_definitions:\n            if definition.is_fixed_tool_set():\n                tool_names = set()\n                for fixed_tool in definition.fixed_tools:\n                    fixed_tool = get_updated_tool_name(fixed_tool)\n                    if not registry.is_valid_tool_name(fixed_tool):\n                        raise ValueError(f\"Invalid tool name '{fixed_tool}' provided for fixed tool set\")\n                    tool_names.add(fixed_tool)\n                log.info(f\"{definition} defined a fixed tool set with {len(tool_names)} tools: {', '.join(tool_names)}\")\n            else:\n                included_tools = []\n                excluded_tools = []\n                for included_tool in definition.included_optional_tools:\n                    included_tool = get_updated_tool_name(included_tool)\n                    if not registry.is_valid_tool_name(included_tool):\n                        raise ValueError(f\"Invalid tool name '{included_tool}' provided for inclusion\")\n                    if included_tool not in tool_names:\n                        tool_names.add(included_tool)\n                        included_tools.append(included_tool)\n                for excluded_tool in definition.excluded_tools:\n                    excluded_tool = get_updated_tool_name(excluded_tool)\n                    if not registry.is_valid_tool_name(excluded_tool):\n                        raise ValueError(f\"Invalid tool name '{excluded_tool}' provided for exclusion\")\n                    if excluded_tool in tool_names:\n                        tool_names.remove(excluded_tool)\n                        excluded_tools.append(excluded_tool)\n                if included_tools:\n                    log.info(f\"{definition} included {len(included_tools)} tools: {', '.join(included_tools)}\")\n                if excluded_tools:\n                    log.info(f\"{definition} excluded {len(excluded_tools)} tools: {', '.join(excluded_tools)}\")\n        return ToolSet(tool_names)\n\n    def without_editing_tools(self) -> \"ToolSet\":\n        \"\"\"\n        :return: a new tool set that excludes all tools that can edit\n        \"\"\"\n        from serena.tools import ToolRegistry\n\n        registry = ToolRegistry()\n        tool_names = set(self._tool_names)\n        for tool_name in self._tool_names:\n            if registry.get_tool_class_by_name(tool_name).can_edit():\n                tool_names.remove(tool_name)\n        return ToolSet(tool_names)\n\n    def get_tool_names(self) -> set[str]:\n        \"\"\"\n        Returns the names of the tools that are currently included in the tool set.\n        \"\"\"\n        return self._tool_names\n\n    def includes_name(self, tool_name: str) -> bool:\n        return tool_name in self._tool_names\n\n    def to_available_tools(self, all_tools: dict[type[Tool], Tool]) -> AvailableTools:\n        return AvailableTools([t for t in all_tools.values() if self.includes_name(t.get_name())])\n\n\nclass ActiveModes:\n    def __init__(self) -> None:\n        self._base_modes: Sequence[str] | None = None\n        self._default_modes: Sequence[str] | None = None\n        self._active_mode_names: Sequence[str] | None = []\n        self._active_modes: Sequence[SerenaAgentMode] | None = []\n\n    def apply(self, mode_selection: ModeSelectionDefinition) -> None:\n        # invalidate active modes\n        self._active_mode_names = None\n        self._active_modes = None\n\n        # apply overrides\n        log.debug(\"Applying mode selection: default_modes=%s, base_modes=%s\", mode_selection.default_modes, mode_selection.base_modes)\n        if mode_selection.base_modes is not None:\n            self._base_modes = mode_selection.base_modes\n        if mode_selection.default_modes is not None:\n            self._default_modes = mode_selection.default_modes\n        log.debug(\"Current mode selection: base_modes=%s, default_modes=%s\", self._base_modes, self._default_modes)\n\n    def get_mode_names(self) -> Sequence[str]:\n        if self._active_mode_names is not None:\n            return self._active_mode_names\n        active_mode_names: set[str] = set()\n        if self._base_modes is not None:\n            active_mode_names.update(self._base_modes)\n        if self._default_modes is not None:\n            active_mode_names.update(self._default_modes)\n        self._active_mode_names = sorted(active_mode_names)\n        log.info(\"Active modes: %s\", self._active_mode_names)\n        return self._active_mode_names\n\n    def get_modes(self) -> Sequence[SerenaAgentMode]:\n        if self._active_modes is not None:\n            return self._active_modes\n        self._active_modes = []\n        for mode_name in self.get_mode_names():\n            mode = SerenaAgentMode.load(mode_name)\n            self._active_modes.append(mode)\n        return self._active_modes\n\n\nclass SerenaAgent:\n    def __init__(\n        self,\n        project: str | None = None,\n        project_activation_callback: Callable[[], None] | None = None,\n        serena_config: SerenaConfig | None = None,\n        context: SerenaAgentContext | None = None,\n        modes: ModeSelectionDefinition | None = None,\n        memory_log_handler: MemoryLogHandler | None = None,\n    ):\n        \"\"\"\n        :param project: the project to load immediately or None to not load any project; may be a path to the project or a name of\n            an already registered project;\n        :param project_activation_callback: a callback function to be called when a project is activated.\n        :param serena_config: the Serena configuration or None to read the configuration from the default location.\n        :param context: the context in which the agent is operating, None for default context.\n            The context may adjust prompts, tool availability, and tool descriptions.\n        :param modes: list of modes in which the agent is operating (they will be combined), None for default modes.\n            The modes may adjust prompts, tool availability, and tool descriptions.\n        :param memory_log_handler: a MemoryLogHandler instance from which to read log messages; if None, a new one will be created\n            if necessary.\n        \"\"\"\n        # obtain serena configuration using the decoupled factory function\n        self.serena_config = serena_config or SerenaConfig.from_config_file()\n\n        # propagate configuration to other components\n        self.serena_config.propagate_settings()\n\n        # project-specific instances, which will be initialized upon project activation\n        self._active_project: Project | None = None\n\n        # determine registered project to be activated (if any)\n        registered_project_to_activate: RegisteredProject | None = (\n            self.serena_config.get_registered_project(project, autoregister=True) if project is not None else None\n        )\n\n        # dashboard URL (set when dashboard is started)\n        self._dashboard_url: str | None = None\n\n        # adjust log level\n        serena_log_level = self.serena_config.log_level\n        if Logger.root.level != serena_log_level:\n            log.info(f\"Changing the root logger level to {serena_log_level}\")\n            Logger.root.setLevel(serena_log_level)\n\n        def get_memory_log_handler() -> MemoryLogHandler:\n            nonlocal memory_log_handler\n            if memory_log_handler is None:\n                memory_log_handler = MemoryLogHandler(level=serena_log_level)\n                Logger.root.addHandler(memory_log_handler)\n            return memory_log_handler\n\n        # open GUI log window if enabled\n        self._gui_log_viewer: Optional[\"GuiLogViewer\"] = None\n        if self.serena_config.gui_log_window:\n            log.info(\"Opening GUI window\")\n            if platform.system() == \"Darwin\":\n                log.warning(\"GUI log window is not supported on macOS\")\n            else:\n                # even importing on macOS may fail if tkinter dependencies are unavailable (depends on Python interpreter installation\n                # which uv used as a base, unfortunately)\n                from serena.gui_log_viewer import GuiLogViewer\n\n                self._gui_log_viewer = GuiLogViewer(\"dashboard\", title=\"Serena Logs\", memory_log_handler=get_memory_log_handler())\n                self._gui_log_viewer.start()\n        else:\n            log.debug(\"GUI window is disabled\")\n\n        # set the agent context\n        if context is None:\n            context = SerenaAgentContext.load_default()\n        self._context = context\n\n        # instantiate all tool classes\n        self._all_tools: dict[type[Tool], Tool] = {tool_class: tool_class(self) for tool_class in ToolRegistry().get_all_tool_classes()}\n        tool_names = [tool.get_name_from_cls() for tool in self._all_tools.values()]\n\n        # If GUI log window is enabled, set the tool names for highlighting\n        if self._gui_log_viewer is not None:\n            self._gui_log_viewer.set_tool_names(tool_names)\n\n        token_count_estimator = RegisteredTokenCountEstimator[self.serena_config.token_count_estimator]\n        log.info(f\"Will record tool usage statistics with token count estimator: {token_count_estimator.name}.\")\n        self._tool_usage_stats = ToolUsageStats(token_count_estimator)\n\n        # log fundamental information\n        log.info(\n            f\"Starting Serena server (version={serena_version()}, process id={os.getpid()}, parent process id={os.getppid()}; \"\n            f\"language backend={self.serena_config.language_backend.name})\"\n        )\n        log.info(\"Configuration file: %s\", self.serena_config.config_file_path)\n        log.info(\"Available projects: {}\".format(\", \".join(self.serena_config.project_names)))\n        log.info(f\"Loaded tools ({len(self._all_tools)}): {', '.join([tool.get_name_from_cls() for tool in self._all_tools.values()])}\")\n\n        self._check_shell_settings()\n\n        # determine the effective language backend for this session.\n        # If a startup project is provided and has a per-project override, use it; otherwise use the global config.\n        # Since we don't want to change the toolset after startup, the language backend cannot be changed within a running Serena session\n        self._language_backend = self.serena_config.language_backend\n        if registered_project_to_activate is not None and registered_project_to_activate.project_config.language_backend is not None:\n            self._language_backend = registered_project_to_activate.project_config.language_backend\n            log.info(f\"Using language backend as configured in project.yml: {self._language_backend.name}\")\n        else:\n            log.info(f\"Using language backend from global configuration: {self._language_backend.name}\")\n\n        # create executor for starting the language server and running tools in another thread\n        # This executor is used to achieve linear task execution\n        self._task_executor = TaskExecutor(\"SerenaAgentTaskExecutor\")\n\n        # Initialize the prompt factory\n        self.prompt_factory = SerenaPromptFactory()\n        self._project_activation_callback = project_activation_callback\n\n        # activate the given project (if any), also updating the active modes\n        # Note: We cannot update the active tools yet, because the base toolset has not been computed yet\n        #       (and its computation depends on the active project)\n        self._active_modes: ActiveModes\n        self._mode_overrides = modes\n        if project is not None:\n            try:\n                self.activate_project_from_path_or_name(project, update_active_modes=False, update_active_tools=False)\n            except Exception as e:\n                log.error(f\"Error activating project '{project}' at startup: {e}\", exc_info=e)\n        self._update_active_modes()\n\n        # determine the base toolset defining the set of exposed tools (which e.g. the MCP shall see),\n        self._base_toolset = self._create_base_toolset(\n            self.serena_config, self._language_backend, self._context, self._active_modes, self._active_project\n        )\n        self._exposed_tools = self._base_toolset.to_available_tools(self._all_tools)\n        log.info(f\"Number of exposed tools: {len(self._exposed_tools)}\")\n\n        # update the active tools (considering the active project, if any)\n        self._active_tools: AvailableTools\n        self._update_active_tools()\n\n        # start the dashboard (web frontend), registering its log handler\n        # should be the last thing to happen in the initialization since the dashboard\n        # may access various parts of the agent\n        if self.serena_config.web_dashboard:\n            self._dashboard_thread, port = SerenaDashboardAPI(\n                get_memory_log_handler(), tool_names, agent=self, tool_usage_stats=self._tool_usage_stats\n            ).run_in_thread(host=self.serena_config.web_dashboard_listen_address)\n            dashboard_host = self.serena_config.web_dashboard_listen_address\n            if dashboard_host == \"0.0.0.0\":\n                dashboard_host = \"localhost\"\n            dashboard_url = f\"http://{dashboard_host}:{port}/dashboard/index.html\"\n            self._dashboard_url = dashboard_url\n            log.info(\"Serena web dashboard started at %s\", dashboard_url)\n            if self.serena_config.web_dashboard_open_on_launch:\n                self.open_dashboard()\n            # inform the GUI window (if any)\n            if self._gui_log_viewer is not None:\n                self._gui_log_viewer.set_dashboard_url(dashboard_url)\n\n    @classmethod\n    def _create_base_toolset(\n        cls,\n        serena_config: SerenaConfig,\n        language_backend: LanguageBackend,\n        context: SerenaAgentContext,\n        modes: ActiveModes,\n        project: Project | None,\n    ) -> ToolSet:\n        \"\"\"\n        Determines the base toolset defining the set of exposed tools (which e.g. the MCP shall see).\n        It depends on ...\n           * dashboard availability/opening on launch\n           * Serena config\n           * the context (which is fixed for the session)\n           * the optional tools enabled by initial modes\n           * single-project mode reductions (if applicable)\n           * JetBrains mode\n        \"\"\"\n        # determine whether to include the OpenDashboardTool based on the Serena configuration\n        tool_inclusion_definitions: list[ToolInclusionDefinition] = []\n        if serena_config.web_dashboard and not serena_config.web_dashboard_open_on_launch and not serena_config.gui_log_window:\n            tool_inclusion_definitions.append(\n                NamedToolInclusionDefinition(name=\"OpenDashboard\", included_optional_tools=[OpenDashboardTool.get_name_from_cls()])\n            )\n\n        # consider Serena configuration and the active context\n        tool_inclusion_definitions.append(serena_config)\n        tool_inclusion_definitions.append(context)\n\n        # consider modes\n        # Since modes can be dynamically turned on and off, we don't include their definitions directly,\n        # but for the initially active modes, we make sure that the tools they enable are included.\n        for mode in modes.get_modes():\n            tool_inclusion_definitions.append(\n                NamedToolInclusionDefinition(\n                    name=f\"InitialModeInclusions[{mode.name}]\", included_optional_tools=mode.included_optional_tools\n                )\n            )\n\n        # When in a single-project context, the agent is assumed to work on a single project, and we thus\n        # want to apply that project's tool exclusions/inclusions from the get-go, limiting the set\n        # of tools that will be exposed to the client.\n        # Furthermore, we disable tools that are only relevant for project activation.\n        # So if the project exists, we apply all the aforementioned exclusions.\n        if context.single_project and project is not None:\n            log.info(\n                \"Applying tool inclusion/exclusion definitions for single-project context based on project '%s'\",\n                project.project_name,\n            )\n            tool_inclusion_definitions.append(\n                NamedToolInclusionDefinition(\n                    name=\"SingleProjectExclusions\",\n                    excluded_tools=[ActivateProjectTool.get_name_from_cls(), GetCurrentConfigTool.get_name_from_cls()],\n                )\n            )\n            tool_inclusion_definitions.append(project.project_config)\n\n        # enabled the internal 'jetbrains' mode for the JetBrains backend\n        if language_backend == LanguageBackend.JETBRAINS:\n            tool_inclusion_definitions.append(SerenaAgentMode.from_name_internal(\"jetbrains\"))\n\n        # compute the resulting tool set\n        base_toolset = ToolSet.default().apply(*tool_inclusion_definitions)\n        log.info(f\"Number of exposed tools: {len(base_toolset)}\")\n        return base_toolset\n\n    def get_language_backend(self) -> LanguageBackend:\n        return self._language_backend\n\n    def get_current_tasks(self) -> list[TaskExecutor.TaskInfo]:\n        \"\"\"\n        Gets the list of tasks currently running or queued for execution.\n        The function returns a list of thread-safe TaskInfo objects (specifically created for the caller).\n\n        :return: the list of tasks in the execution order (running task first)\n        \"\"\"\n        return self._task_executor.get_current_tasks()\n\n    def get_last_executed_task(self) -> TaskExecutor.TaskInfo | None:\n        \"\"\"\n        Gets the last executed task.\n\n        :return: the last executed task info or None if no task has been executed yet\n        \"\"\"\n        return self._task_executor.get_last_executed_task()\n\n    def get_language_server_manager(self) -> LanguageServerManager | None:\n        if self._active_project is not None:\n            return self._active_project.language_server_manager\n        return None\n\n    def get_language_server_manager_or_raise(self) -> LanguageServerManager:\n        active_project = self.get_active_project_or_raise()\n        return active_project.get_language_server_manager_or_raise()\n\n    def get_log_inspection_instructions(self) -> str:\n        if self.serena_config.web_dashboard:\n            return f\"Live logs can be inspected via the dashboard at {self.get_dashboard_url()}\"\n        else:\n            log_path = SerenaPaths().last_returned_log_file_path\n            if log_path is not None:\n                return f\"Find the current log file here: f{log_path}\"\n            else:\n                return \"Unfortunately, logs are not available. We recommend enabling the web dashboard/logging in general.\"\n\n    def get_context(self) -> SerenaAgentContext:\n        return self._context\n\n    def get_tool_description_override(self, tool_name: str) -> str | None:\n        return self._context.tool_description_overrides.get(tool_name, None)\n\n    def _check_shell_settings(self) -> None:\n        # On Windows, Claude Code sets COMSPEC to Git-Bash (often even with a path containing spaces),\n        # which causes all sorts of trouble, preventing language servers from being launched correctly.\n        # So we make sure that COMSPEC is unset if it has been set to bash specifically.\n        if platform.system() == \"Windows\":\n            comspec = os.environ.get(\"COMSPEC\", \"\")\n            if \"bash\" in comspec:\n                os.environ[\"COMSPEC\"] = \"\"  # force use of default shell\n                log.info(\"Adjusting COMSPEC environment variable to use the default shell instead of '%s'\", comspec)\n\n    def record_tool_usage(self, input_kwargs: dict, tool_result: str | dict, tool: Tool) -> None:\n        \"\"\"\n        Record the usage of a tool with the given input and output strings if tool usage statistics recording is enabled.\n        \"\"\"\n        tool_name = tool.get_name()\n        input_str = str(input_kwargs)\n        output_str = str(tool_result)\n        log.debug(f\"Recording tool usage for tool '{tool_name}'\")\n        self._tool_usage_stats.record_tool_usage(tool_name, input_str, output_str)\n\n    def get_dashboard_url(self) -> str | None:\n        \"\"\"\n        :return: the URL of the web dashboard, or None if the dashboard is not running\n        \"\"\"\n        return self._dashboard_url\n\n    def open_dashboard(self) -> bool:\n        \"\"\"\n        Opens the Serena web dashboard in the default web browser.\n\n        :return: a message indicating success or failure\n        \"\"\"\n        if self._dashboard_url is None:\n            raise Exception(\"Dashboard is not running.\")\n\n        if not system_has_usable_display():\n            log.warning(\"Not opening the Serena web dashboard because no usable display was detected.\")\n            return False\n\n        # Use a subprocess to avoid any output from webbrowser.open being written to stdout\n        subprocess.Popen(\n            [sys.executable, \"-c\", f\"import webbrowser; webbrowser.open({self._dashboard_url!r})\"],\n            stdin=subprocess.DEVNULL,\n            stdout=subprocess.DEVNULL,\n            stderr=subprocess.DEVNULL,\n            start_new_session=True,  # Detach from parent process\n        )\n        return True\n\n    def get_exposed_tool_instances(self) -> list[\"Tool\"]:\n        \"\"\"\n        :return: the tool instances which are exposed (e.g. to the MCP client).\n            Note that the set of exposed tools is fixed for the session, as\n            clients don't react to changes in the set of tools, so this is the superset\n            of tools that can be offered during the session.\n            If a client should attempt to use a tool that is dynamically disabled\n            (e.g. because a project is activated that disables it), it will receive an error.\n        \"\"\"\n        return list(self._exposed_tools.tools)\n\n    def get_active_project(self) -> Project | None:\n        \"\"\"\n        :return: the active project or None if no project is active\n        \"\"\"\n        return self._active_project\n\n    def get_active_project_or_raise(self) -> Project:\n        \"\"\"\n        :return: the active project or raises an exception if no project is active\n        \"\"\"\n        project = self.get_active_project()\n        if project is None:\n            raise ValueError(\"No active project. Please activate a project first.\")\n        return project\n\n    def set_modes(self, mode_names: list[str]) -> None:\n        \"\"\"\n        Set the current mode configurations.\n\n        :param mode_names: List of mode names or paths to use\n        \"\"\"\n        self._mode_overrides = ModeSelectionDefinition(default_modes=mode_names)\n        self._update_active_modes()\n        self._update_active_tools()\n\n        log.info(f\"Set modes to {[mode.name for mode in self.get_active_modes()]}\")\n\n    def get_active_modes(self) -> list[SerenaAgentMode]:\n        \"\"\"\n        :return: the list of active modes\n        \"\"\"\n        return list(self._active_modes.get_modes())\n\n    def _format_prompt(self, prompt_template: str) -> str:\n        template = JinjaTemplate(prompt_template)\n        return template.render(available_tools=self._exposed_tools.tool_names, available_markers=self._exposed_tools.tool_marker_names)\n\n    def create_system_prompt(self) -> str:\n        available_tools = self._active_tools\n        available_markers = available_tools.tool_marker_names\n        global_memories = MemoriesManager(\n            serena_data_folder=None, read_only_memory_patterns=self.serena_config.read_only_memory_patterns\n        ).list_global_memories()\n        global_memories_str = dict_string(global_memories.to_dict()) if len(global_memories) > 0 else \"\"\n        log.info(\"Generating system prompt with available_tools=(see active tools), available_markers=%s\", available_markers)\n        system_prompt = self.prompt_factory.create_system_prompt(\n            context_system_prompt=self._format_prompt(self._context.prompt),\n            mode_system_prompts=[self._format_prompt(mode.prompt) for mode in self.get_active_modes()],\n            available_tools=available_tools.tool_names,\n            available_markers=available_markers,\n            global_memories_list=global_memories_str,\n        )\n\n        # If a project is active at startup, append its activation message\n        if self._active_project is not None:\n            system_prompt += \"\\n\\n\" + self._active_project.get_activation_message()\n\n        log.info(\"System prompt:\\n%s\", system_prompt)\n        return system_prompt\n\n    def _update_active_modes(self) -> None:\n        \"\"\"\n        Updates the active modes based on the Serena configuration, the active project configuration (if any),\n        and mode overrides (if any).\n        \"\"\"\n        self._active_modes = ActiveModes()\n        self._active_modes.apply(self.serena_config)\n        if self._active_project:\n            self._active_modes.apply(self._active_project.project_config)\n        if self._mode_overrides:\n            self._active_modes.apply(self._mode_overrides)\n\n    def _update_active_tools(self) -> None:\n        \"\"\"\n        Updates the active tools based on the active modes and the active project.\n        The base tool set already takes the Serena configuration and the context into account\n        (as well as many other aspects, such as JetBrains mode).\n        \"\"\"\n        # apply modes\n        tool_set = self._base_toolset.apply(*self._active_modes.get_modes())\n\n        # apply active project configuration (if any)\n        if self._active_project is not None:\n            tool_set = tool_set.apply(self._active_project.project_config)\n            if self._active_project.project_config.read_only:\n                tool_set = tool_set.without_editing_tools()\n\n        self._active_tools = tool_set.to_available_tools(self._all_tools)\n        log.info(f\"Active tools ({len(self._active_tools)}): {', '.join(self._active_tools.tool_names)}\")\n\n        # check if a tool was activated that is not in the exposed tool set and issue a warning if so\n        active_tools_not_exposed = set(self._active_tools.tool_names) - set(self._exposed_tools.tool_names)\n        if active_tools_not_exposed:\n            log.warning(\n                \"The following active tools are not in the exposed tool set and thus won't be available to clients:\\n\"\n                f\"{active_tools_not_exposed}\\n\"\n                \"Consider adjusting your configuration to include these tools if you want to use them.\"\n            )\n\n    def issue_task(\n        self, task: Callable[[], T], name: str | None = None, logged: bool = True, timeout: float | None = None\n    ) -> TaskExecutor.Task[T]:\n        \"\"\"\n        Issue a task to the executor for asynchronous execution.\n        It is ensured that tasks are executed in the order they are issued, one after another.\n\n        :param task: the task to execute\n        :param name: the name of the task for logging purposes; if None, use the task function's name\n        :param logged: whether to log management of the task; if False, only errors will be logged\n        :param timeout: the maximum time to wait for task completion in seconds, or None to wait indefinitely\n        :return: the task object, through which the task's future result can be accessed\n        \"\"\"\n        return self._task_executor.issue_task(task, name=name, logged=logged, timeout=timeout)\n\n    def execute_task(self, task: Callable[[], T], name: str | None = None, logged: bool = True, timeout: float | None = None) -> T:\n        \"\"\"\n        Executes the given task synchronously via the agent's task executor.\n        This is useful for tasks that need to be executed immediately and whose results are needed right away.\n\n        :param task: the task to execute\n        :param name: the name of the task for logging purposes; if None, use the task function's name\n        :param logged: whether to log management of the task; if False, only errors will be logged\n        :param timeout: the maximum time to wait for task completion in seconds, or None to wait indefinitely\n        :return: the result of the task execution\n        \"\"\"\n        return self._task_executor.execute_task(task, name=name, logged=logged, timeout=timeout)\n\n    def is_using_language_server(self) -> bool:\n        \"\"\"\n        :return: whether this agent uses language server-based code analysis\n        \"\"\"\n        return self._language_backend == LanguageBackend.LSP\n\n    def _activate_project(self, project: Project, update_active_modes: bool = True, update_active_tools: bool = True) -> None:\n        log.info(f\"Activating {project.project_name} at {project.project_root}\")\n\n        # Check if the project requires a different language backend than the one initialized at startup\n        project_backend = project.project_config.language_backend\n        if project_backend is not None and project_backend != self._language_backend:\n            raise ValueError(\n                f\"Cannot activate project '{project.project_name}': it requires the {project_backend.value} backend, \"\n                f\"but this session was initialized with {self._language_backend.value}. \"\n                f\"Workarounds: (1) Use project activation at startup via the --project flag, \"\n                f\"(2) Configure one MCP server per backend in your client.\"\n            )\n\n        self._active_project = project\n        project.set_agent(self)\n\n        if update_active_modes:\n            self._update_active_modes()\n\n        if update_active_tools:\n            self._update_active_tools()\n\n        def init_language_server_manager() -> None:\n            # start the language server\n            with LogTime(\"Language server initialization\", logger=log):\n                self.reset_language_server_manager()\n\n        # initialize the language server in the background (if in language server mode)\n        if self.get_language_backend().is_lsp():\n            self.issue_task(init_language_server_manager)\n\n        if self._project_activation_callback is not None:\n            self._project_activation_callback()\n\n    def activate_project_from_path_or_name(\n        self, project_root_or_name: str, update_active_modes: bool = True, update_active_tools: bool = True\n    ) -> Project:\n        \"\"\"\n        Activate a project from a path or a name.\n        If the project was already registered, it will just be activated.\n        If the argument is a path at which no Serena project previously existed, the project will be created beforehand.\n        Raises ProjectNotFoundError if the project could neither be found nor created.\n        \"\"\"\n        project_instance: Project | None = self.serena_config.get_project(project_root_or_name)\n        if project_instance is not None:\n            log.info(f\"Found registered project '{project_instance.project_name}' at path {project_instance.project_root}\")\n        elif os.path.isdir(project_root_or_name):\n            project_instance = self.serena_config.add_project_from_path(project_root_or_name)\n            log.info(f\"Added new project {project_instance.project_name} for path {project_instance.project_root}\")\n\n        if project_instance is None:\n            raise ProjectNotFoundError(\n                f\"Project '{project_root_or_name}' not found: Not a valid project name or directory. \"\n                f\"Existing project names: {self.serena_config.project_names}\"\n            )\n\n        self._activate_project(project_instance, update_active_modes=update_active_modes, update_active_tools=update_active_tools)\n\n        return project_instance\n\n    def get_active_tool_names(self) -> list[str]:\n        \"\"\"\n        :return: the list of names of the active tools for the current project, sorted alphabetically\n        \"\"\"\n        return self._active_tools.tool_names\n\n    def tool_is_active(self, tool_name: str) -> bool:\n        \"\"\"\n        :param tool_class: the name of the tool to check\n        :return: True if the tool is active, False otherwise\n        \"\"\"\n        return self._active_tools.contains_tool_name(tool_name)\n\n    def get_current_config_overview(self) -> str:\n        \"\"\"\n        :return: a string overview of the current configuration, including the active and available configuration options\n        \"\"\"\n        result_str = \"Current configuration:\\n\"\n        result_str += f\"Serena version: {serena_version()}\\n\"\n        result_str += f\"Loglevel: {self.serena_config.log_level}, trace_lsp_communication={self.serena_config.trace_lsp_communication}\\n\"\n        if self._active_project is not None:\n            result_str += f\"Active project: {self._active_project.project_name}\\n\"\n        else:\n            result_str += \"No active project\\n\"\n        result_str += f\"Language backend: {self._language_backend.value}\"\n        if self._active_project and self._active_project.project_config.language_backend is not None:\n            result_str += \" (project override)\"\n        result_str += f\" (global default: {self.serena_config.language_backend.value})\\n\"\n        result_str += \"Available projects:\\n\" + \"\\n\".join(list(self.serena_config.project_names)) + \"\\n\"\n        result_str += f\"Active context: {self._context.name}\\n\"\n\n        # Active modes\n        active_mode_names = [mode.name for mode in self.get_active_modes()]\n        result_str += \"Active modes: {}\\n\".format(\", \".join(active_mode_names)) + \"\\n\"\n\n        # Available but not active modes\n        all_available_modes = SerenaAgentMode.list_registered_mode_names()\n        inactive_modes = [mode for mode in all_available_modes if mode not in active_mode_names]\n        if inactive_modes:\n            result_str += \"Available but not active modes: {}\\n\".format(\", \".join(inactive_modes)) + \"\\n\"\n\n        # Active tools\n        result_str += \"Active tools (after all exclusions from the project, context, and modes):\\n\"\n        active_tool_names = self.get_active_tool_names()\n        # print the tool names in chunks\n        chunk_size = 4\n        for i in range(0, len(active_tool_names), chunk_size):\n            chunk = active_tool_names[i : i + chunk_size]\n            result_str += \"  \" + \", \".join(chunk) + \"\\n\"\n\n        # Available but not active tools\n        all_tool_names = sorted([tool.get_name_from_cls() for tool in self._all_tools.values()])\n        inactive_tool_names = [tool for tool in all_tool_names if tool not in active_tool_names]\n        if inactive_tool_names:\n            result_str += \"Available but not active tools:\\n\"\n            for i in range(0, len(inactive_tool_names), chunk_size):\n                chunk = inactive_tool_names[i : i + chunk_size]\n                result_str += \"  \" + \", \".join(chunk) + \"\\n\"\n\n        return result_str\n\n    def reset_language_server_manager(self) -> None:\n        \"\"\"\n        Starts/resets the language server manager for the current project\n        \"\"\"\n        self.get_active_project_or_raise().create_language_server_manager()\n\n    def add_language(self, language: Language) -> None:\n        \"\"\"\n        Adds a new language to the active project, spawning the respective language server and updating the project configuration.\n        The addition is scheduled via the agent's task executor and executed synchronously, i.e. the method returns\n        when the addition is complete.\n\n        :param language: the language to add\n        \"\"\"\n        self.execute_task(lambda: self.get_active_project_or_raise().add_language(language), name=f\"AddLanguage:{language.value}\")\n\n    def remove_language(self, language: Language) -> None:\n        \"\"\"\n        Removes a language from the active project, shutting down the respective language server and updating the project configuration.\n        The removal is scheduled via the agent's task executor and executed asynchronously.\n\n        :param language: the language to remove\n        \"\"\"\n        self.issue_task(lambda: self.get_active_project_or_raise().remove_language(language), name=f\"RemoveLanguage:{language.value}\")\n\n    def get_tool(self, tool_class: type[TTool]) -> TTool:\n        return self._all_tools[tool_class]  # type: ignore\n\n    def print_tool_overview(self) -> None:\n        ToolRegistry().print_tool_overview(self._active_tools.tools)\n\n    def __del__(self) -> None:\n        self.shutdown()\n\n    def shutdown(self, timeout: float = 2.0) -> None:\n        \"\"\"\n        Shuts down the agent, freeing resources and stopping background tasks.\n        \"\"\"\n        if not hasattr(self, \"_is_initialized\"):\n            return\n        log.info(\"SerenaAgent is shutting down ...\")\n        if self._active_project is not None:\n            self._active_project.shutdown(timeout=timeout)\n            self._active_project = None\n        if self._gui_log_viewer:\n            log.info(\"Stopping the GUI log window ...\")\n            self._gui_log_viewer.stop()\n            self._gui_log_viewer = None\n\n    def get_tool_by_name(self, tool_name: str) -> Tool:\n        tool_class = ToolRegistry().get_tool_class_by_name(tool_name)\n        return self.get_tool(tool_class)\n\n    def get_active_lsp_languages(self) -> list[Language]:\n        ls_manager = self.get_language_server_manager()\n        if ls_manager is None:\n            return []\n        return ls_manager.get_active_languages()\n\n    @contextmanager\n    def active_project_context(self, project: Project) -> Iterator[None]:\n        \"\"\"\n        Context manager for temporarily setting/overriding the active project\n\n        :param project: the project to be active\n        \"\"\"\n        original_project = self._active_project\n        self._active_project = project\n        try:\n            yield\n        finally:\n            self._active_project = original_project\n"
  },
  {
    "path": "src/serena/agno.py",
    "content": "import argparse\r\nimport logging\r\nimport os\r\nimport threading\r\nfrom pathlib import Path\r\nfrom typing import Any\r\n\r\nfrom agno.agent import Agent\r\nfrom agno.db.sqlite import SqliteDb\r\nfrom agno.memory import MemoryManager\r\nfrom agno.models.base import Model\r\nfrom agno.tools.function import Function\r\nfrom agno.tools.toolkit import Toolkit\r\nfrom dotenv import load_dotenv\r\nfrom sensai.util.logging import LogTime\r\n\r\nfrom serena.agent import SerenaAgent, Tool\r\nfrom serena.config.context_mode import SerenaAgentContext\r\nfrom serena.constants import REPO_ROOT\r\nfrom serena.util.exception import show_fatal_exception_safe\r\n\r\nlog = logging.getLogger(__name__)\r\n\r\n\r\nclass SerenaAgnoToolkit(Toolkit):\r\n    def __init__(self, serena_agent: SerenaAgent):\r\n        super().__init__(\"Serena\")\r\n        for tool in serena_agent.get_exposed_tool_instances():\r\n            self.functions[tool.get_name_from_cls()] = self._create_agno_function(tool)\r\n        log.info(\"Agno agent functions: %s\", list(self.functions.keys()))\r\n\r\n    @staticmethod\r\n    def _create_agno_function(tool: Tool) -> Function:\r\n        def entrypoint(**kwargs: Any) -> str:\r\n            if \"kwargs\" in kwargs:\r\n                # Agno sometimes passes a kwargs argument explicitly, so we merge it\r\n                kwargs.update(kwargs[\"kwargs\"])\r\n                del kwargs[\"kwargs\"]\r\n            log.info(f\"Calling tool {tool}\")\r\n            return tool.apply_ex(log_call=True, catch_exceptions=True, **kwargs)\r\n\r\n        function = Function.from_callable(tool.get_apply_fn())\r\n        function.name = tool.get_name_from_cls()\r\n        function.entrypoint = entrypoint\r\n        function.skip_entrypoint_processing = True\r\n        return function\r\n\r\n\r\nclass SerenaAgnoAgentProvider:\r\n    _agent: Agent | None = None\r\n    _lock = threading.Lock()\r\n\r\n    @classmethod\r\n    def get_agent(cls, model: Model) -> Agent:\r\n        \"\"\"\r\n        Returns the singleton instance of the Serena agent or creates it with the given parameters if it doesn't exist.\r\n\r\n        NOTE: This is very ugly with poor separation of concerns, but the way in which the Agno UI works (reloading the\r\n            module that defines the `app` variable) essentially forces us to do something like this.\r\n\r\n        :param model: the large language model to use for the agent\r\n        :return: the agent instance\r\n        \"\"\"\r\n        with cls._lock:\r\n            if cls._agent is not None:\r\n                return cls._agent\r\n\r\n            # change to Serena root\r\n            os.chdir(REPO_ROOT)\r\n\r\n            load_dotenv()\r\n\r\n            parser = argparse.ArgumentParser(description=\"Serena coding assistant\")\r\n\r\n            # Create a mutually exclusive group\r\n            group = parser.add_mutually_exclusive_group()\r\n\r\n            # Add arguments to the group, both pointing to the same destination\r\n            group.add_argument(\r\n                \"--project-file\",\r\n                required=False,\r\n                help=\"Path to the project (or project.yml file).\",\r\n            )\r\n            group.add_argument(\r\n                \"--project\",\r\n                required=False,\r\n                help=\"Path to the project (or project.yml file).\",\r\n            )\r\n            args = parser.parse_args()\r\n\r\n            args_project_file = args.project or args.project_file\r\n\r\n            if args_project_file:\r\n                project_file = Path(args_project_file).resolve()\r\n                # If project file path is relative, make it absolute by joining with project root\r\n                if not project_file.is_absolute():\r\n                    # Get the project root directory (parent of scripts directory)\r\n                    project_root = Path(REPO_ROOT)\r\n                    project_file = project_root / args_project_file\r\n\r\n                # Ensure the path is normalized and absolute\r\n                project_file = str(project_file.resolve())\r\n            else:\r\n                project_file = None\r\n\r\n            with LogTime(\"Loading Serena agent\"):\r\n                try:\r\n                    serena_agent = SerenaAgent(project_file, context=SerenaAgentContext.load(\"agent\"))\r\n                except Exception as e:\r\n                    show_fatal_exception_safe(e)\r\n                    raise\r\n\r\n            # Even though we don't want to keep history between sessions,\r\n            # for agno-ui to work as a conversation, we use a persistent database on disk.\r\n            # This database should be deleted between sessions.\r\n            # Note that this might collide with custom options for the agent, like adding vector-search based tools.\r\n            sql_db_path = (Path(\"temp\") / \"agno_agent_storage.db\").absolute()\r\n            sql_db_path.parent.mkdir(exist_ok=True)\r\n            # delete the db file if it exists\r\n            log.info(f\"Deleting DB from PID {os.getpid()}\")\r\n            if sql_db_path.exists():\r\n                sql_db_path.unlink()\r\n\r\n            agno_agent = Agent(\r\n                name=\"Serena\",\r\n                model=model,\r\n                # See explanation above on why database is needed\r\n                db=SqliteDb(db_file=str(sql_db_path)),\r\n                description=\"A fully-featured coding assistant\",\r\n                tools=[SerenaAgnoToolkit(serena_agent)],\r\n                # Tool calls will be shown in the UI since that's configurable per tool\r\n                # To see detailed logs, you should use the serena logger (configure it in the project file path)\r\n                markdown=True,\r\n                system_message=serena_agent.create_system_prompt(),\r\n                telemetry=False,\r\n                memory_manager=MemoryManager(),\r\n                add_history_to_context=True,\r\n                num_history_runs=100,  # you might want to adjust this (expense vs. history awareness)\r\n            )\r\n            cls._agent = agno_agent\r\n            log.info(f\"Agent instantiated: {agno_agent}\")\r\n\r\n        return agno_agent\r\n"
  },
  {
    "path": "src/serena/analytics.py",
    "content": "from __future__ import annotations\n\nimport logging\nimport threading\nfrom abc import ABC, abstractmethod\nfrom collections import defaultdict\nfrom copy import copy\nfrom dataclasses import asdict, dataclass\nfrom enum import Enum\n\nfrom anthropic.types import MessageParam, MessageTokensCount\nfrom dotenv import load_dotenv\n\nlog = logging.getLogger(__name__)\n\n\nclass TokenCountEstimator(ABC):\n    @abstractmethod\n    def estimate_token_count(self, text: str) -> int:\n        \"\"\"\n        Estimate the number of tokens in the given text.\n        This is an abstract method that should be implemented by subclasses.\n        \"\"\"\n\n\nclass TiktokenCountEstimator(TokenCountEstimator):\n    \"\"\"\n    Approximate token count using tiktoken.\n    \"\"\"\n\n    def __init__(self, model_name: str = \"gpt-4o\"):\n        \"\"\"\n        The tokenizer will be downloaded on the first initialization, which may take some time.\n\n        :param model_name: see `tiktoken.model` to see available models.\n        \"\"\"\n        import tiktoken\n\n        log.info(f\"Loading tiktoken encoding for model {model_name}, this may take a while on the first run.\")\n        self._encoding = tiktoken.encoding_for_model(model_name)\n\n    def estimate_token_count(self, text: str) -> int:\n        return len(self._encoding.encode(text))\n\n\nclass AnthropicTokenCount(TokenCountEstimator):\n    \"\"\"\n    The exact count using the Anthropic API.\n    Counting is free, but has a rate limit and will require an API key,\n    (typically, set through an env variable).\n    See https://docs.anthropic.com/en/docs/build-with-claude/token-counting\n    \"\"\"\n\n    def __init__(self, model_name: str = \"claude-sonnet-4-20250514\", api_key: str | None = None):\n        import anthropic\n\n        self._model_name = model_name\n        if api_key is None:\n            load_dotenv()\n        self._anthropic_client = anthropic.Anthropic(api_key=api_key)\n\n    def _send_count_tokens_request(self, text: str) -> MessageTokensCount:\n        return self._anthropic_client.messages.count_tokens(\n            model=self._model_name,\n            messages=[MessageParam(role=\"user\", content=text)],\n        )\n\n    def estimate_token_count(self, text: str) -> int:\n        return self._send_count_tokens_request(text).input_tokens\n\n\nclass CharCountEstimator(TokenCountEstimator):\n    \"\"\"\n    A naive character count estimator that estimates tokens based on character count.\n    \"\"\"\n\n    def __init__(self, avg_chars_per_token: int = 4):\n        self._avg_chars_per_token = avg_chars_per_token\n\n    def estimate_token_count(self, text: str) -> int:\n        # Assuming an average of 4 characters per token\n        return len(text) // self._avg_chars_per_token\n\n\n_registered_token_estimator_instances_cache: dict[RegisteredTokenCountEstimator, TokenCountEstimator] = {}\n\n\nclass RegisteredTokenCountEstimator(Enum):\n    TIKTOKEN_GPT4O = \"TIKTOKEN_GPT4O\"\n    ANTHROPIC_CLAUDE_SONNET_4 = \"ANTHROPIC_CLAUDE_SONNET_4\"\n    CHAR_COUNT = \"CHAR_COUNT\"\n\n    @classmethod\n    def get_valid_names(cls) -> list[str]:\n        \"\"\"\n        Get a list of all registered token count estimator names.\n        \"\"\"\n        return [estimator.name for estimator in cls]\n\n    def _create_estimator(self) -> TokenCountEstimator:\n        match self:\n            case RegisteredTokenCountEstimator.TIKTOKEN_GPT4O:\n                return TiktokenCountEstimator(model_name=\"gpt-4o\")\n            case RegisteredTokenCountEstimator.ANTHROPIC_CLAUDE_SONNET_4:\n                return AnthropicTokenCount(model_name=\"claude-sonnet-4-20250514\")\n            case RegisteredTokenCountEstimator.CHAR_COUNT:\n                return CharCountEstimator(avg_chars_per_token=4)\n            case _:\n                raise ValueError(f\"Unknown token count estimator: {self}\")\n\n    def load_estimator(self) -> TokenCountEstimator:\n        estimator_instance = _registered_token_estimator_instances_cache.get(self)\n        if estimator_instance is None:\n            estimator_instance = self._create_estimator()\n            _registered_token_estimator_instances_cache[self] = estimator_instance\n        return estimator_instance\n\n\nclass ToolUsageStats:\n    \"\"\"\n    A class to record and manage tool usage statistics.\n    \"\"\"\n\n    def __init__(self, token_count_estimator: RegisteredTokenCountEstimator = RegisteredTokenCountEstimator.TIKTOKEN_GPT4O):\n        self._token_count_estimator = token_count_estimator.load_estimator()\n        self._token_estimator_name = token_count_estimator.value\n        self._tool_stats: dict[str, ToolUsageStats.Entry] = defaultdict(ToolUsageStats.Entry)\n        self._tool_stats_lock = threading.Lock()\n\n    @property\n    def token_estimator_name(self) -> str:\n        \"\"\"\n        Get the name of the registered token count estimator used.\n        \"\"\"\n        return self._token_estimator_name\n\n    @dataclass(kw_only=True)\n    class Entry:\n        num_times_called: int = 0\n        input_tokens: int = 0\n        output_tokens: int = 0\n\n        def update_on_call(self, input_tokens: int, output_tokens: int) -> None:\n            \"\"\"\n            Update the entry with the number of tokens used for a single call.\n            \"\"\"\n            self.num_times_called += 1\n            self.input_tokens += input_tokens\n            self.output_tokens += output_tokens\n\n    def _estimate_token_count(self, text: str) -> int:\n        return self._token_count_estimator.estimate_token_count(text)\n\n    def get_stats(self, tool_name: str) -> ToolUsageStats.Entry:\n        \"\"\"\n        Get (a copy of) the current usage statistics for a specific tool.\n        \"\"\"\n        with self._tool_stats_lock:\n            return copy(self._tool_stats[tool_name])\n\n    def record_tool_usage(self, tool_name: str, input_str: str, output_str: str) -> None:\n        input_tokens = self._estimate_token_count(input_str)\n        output_tokens = self._estimate_token_count(output_str)\n        with self._tool_stats_lock:\n            entry = self._tool_stats[tool_name]\n            entry.update_on_call(input_tokens, output_tokens)\n\n    def get_tool_stats_dict(self) -> dict[str, dict[str, int]]:\n        with self._tool_stats_lock:\n            return {name: asdict(entry) for name, entry in self._tool_stats.items()}\n\n    def clear(self) -> None:\n        with self._tool_stats_lock:\n            self._tool_stats.clear()\n"
  },
  {
    "path": "src/serena/cli.py",
    "content": "import collections\nimport glob\nimport json\nimport os\nimport shutil\nimport subprocess\nimport sys\nfrom collections.abc import Iterator, Sequence\nfrom logging import Logger\nfrom pathlib import Path\nfrom typing import Any, Literal\n\nimport click\nfrom sensai.util import logging\nfrom sensai.util.logging import FileLoggerContext, datetime_tag\nfrom sensai.util.string import dict_string\nfrom tqdm import tqdm\n\nfrom serena.agent import SerenaAgent\nfrom serena.config.context_mode import SerenaAgentContext, SerenaAgentMode\nfrom serena.config.serena_config import (\n    LanguageBackend,\n    ModeSelectionDefinition,\n    ProjectConfig,\n    RegisteredProject,\n    SerenaConfig,\n    SerenaPaths,\n)\nfrom serena.constants import (\n    DEFAULT_CONTEXT,\n    PROMPT_TEMPLATES_DIR_INTERNAL,\n    SERENA_LOG_FORMAT,\n    SERENAS_OWN_CONTEXT_YAMLS_DIR,\n    SERENAS_OWN_MODE_YAMLS_DIR,\n)\nfrom serena.mcp import SerenaMCPFactory\nfrom serena.project import Project\nfrom serena.tools import FindReferencingSymbolsTool, FindSymbolTool, GetSymbolsOverviewTool, SearchForPatternTool, ToolRegistry\nfrom serena.util.dataclass import get_dataclass_default\nfrom serena.util.logging import MemoryLogHandler\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_types import SymbolKind\nfrom solidlsp.util.subprocess_util import subprocess_kwargs\n\nlog = logging.getLogger(__name__)\n\n_MAX_CONTENT_WIDTH = 100\n_MODES_EXPLANATION = f\"\"\"\\b\\nBuilt-in mode names or paths to custom mode YAMLs with which to \noverride the default modes defined in the global Serena configuration or \nthe active project.\nFor details on mode configuration, see \n  https://oraios.github.io/serena/02-usage/050_configuration.html#modes.\nIf no configuration changes were made, the base defaults are: \n  {get_dataclass_default(SerenaConfig, \"default_modes\")}.\nOverriding them means that they no longer apply, so you will need to \nre-specify them in addition to further modes if you want to keep them.\"\"\"\n\n\ndef find_project_root(root: str | Path | None = None) -> str | None:\n    \"\"\"Find project root by walking up from CWD.\n\n    Checks for .serena/project.yml first (explicit Serena project), then .git (git root).\n\n    :param root: If provided, constrains the search to this directory and below\n                 (acts as a virtual filesystem root). Search stops at this boundary.\n    :return: absolute path to project root or None if not suitable root is found\n    \"\"\"\n    current = Path.cwd().resolve()\n    boundary = Path(root).resolve() if root is not None else None\n\n    def ancestors() -> Iterator[Path]:\n        \"\"\"Yield current directory and ancestors up to boundary.\"\"\"\n        yield current\n        for parent in current.parents:\n            yield parent\n            if boundary is not None and parent == boundary:\n                return\n\n    # First pass: look for .serena\n    for directory in ancestors():\n        if (directory / \".serena\" / \"project.yml\").is_file():\n            return str(directory)\n\n    # Second pass: look for .git\n    for directory in ancestors():\n        if (directory / \".git\").exists():  # .git can be file (worktree) or dir\n            return str(directory)\n\n    return None\n\n\n# --------------------- Utilities -------------------------------------\n\n\ndef _open_in_editor(path: str) -> None:\n    \"\"\"Open the given file in the system's default editor or viewer.\"\"\"\n    editor = os.environ.get(\"EDITOR\")\n    run_kwargs = subprocess_kwargs()\n    try:\n        if editor:\n            subprocess.run([editor, path], check=False, **run_kwargs)\n        elif sys.platform.startswith(\"win\"):\n            try:\n                os.startfile(path)\n            except OSError:\n                subprocess.run([\"notepad.exe\", path], check=False, **run_kwargs)\n        elif sys.platform == \"darwin\":\n            subprocess.run([\"open\", path], check=False, **run_kwargs)\n        else:\n            subprocess.run([\"xdg-open\", path], check=False, **run_kwargs)\n    except Exception as e:\n        print(f\"Failed to open {path}: {e}\")\n\n\nclass ProjectType(click.ParamType):\n    \"\"\"ParamType allowing either a project name or a path to a project directory.\"\"\"\n\n    name = \"[PROJECT_NAME|PROJECT_PATH]\"\n\n    def convert(self, value: str, param: Any, ctx: Any) -> str:\n        path = Path(value).resolve()\n        if path.exists() and path.is_dir():\n            return str(path)\n        return value\n\n\nPROJECT_TYPE = ProjectType()\n\n\nclass AutoRegisteringGroup(click.Group):\n    \"\"\"\n    A click.Group subclass that automatically registers any click.Command\n    attributes defined on the class into the group.\n\n    After initialization, it inspects its own class for attributes that are\n    instances of click.Command (typically created via @click.command) and\n    calls self.add_command(cmd) on each. This lets you define your commands\n    as static methods on the subclass for IDE-friendly organization without\n    manual registration.\n    \"\"\"\n\n    def __init__(self, name: str, help: str):\n        super().__init__(name=name, help=help)\n        # Scan class attributes for click.Command instances and register them.\n        for attr in dir(self.__class__):\n            cmd = getattr(self.__class__, attr)\n            if isinstance(cmd, click.Command):\n                self.add_command(cmd)\n\n\nclass TopLevelCommands(AutoRegisteringGroup):\n    \"\"\"Root CLI group containing the core Serena commands.\"\"\"\n\n    def __init__(self) -> None:\n        super().__init__(name=\"serena\", help=\"Serena CLI commands. You can run `<command> --help` for more info on each command.\")\n\n    @staticmethod\n    @click.command(\"start-mcp-server\", help=\"Starts the Serena MCP server.\", context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH})\n    @click.option(\"--project\", \"project\", type=PROJECT_TYPE, default=None, help=\"Path or name of project to activate at startup.\")\n    @click.option(\"--project-file\", \"project\", type=PROJECT_TYPE, default=None, help=\"[DEPRECATED] Use --project instead.\")\n    @click.argument(\"project_file_arg\", type=PROJECT_TYPE, required=False, default=None, metavar=\"\")\n    @click.option(\n        \"--context\", type=str, default=DEFAULT_CONTEXT, show_default=True, help=\"Built-in context name or path to custom context YAML.\"\n    )\n    @click.option(\n        \"--mode\",\n        \"modes\",\n        type=str,\n        multiple=True,\n        default=(),\n        show_default=False,\n        help=_MODES_EXPLANATION,\n    )\n    @click.option(\n        \"--language-backend\",\n        type=click.Choice([lb.value for lb in LanguageBackend]),\n        default=None,\n        help=\"Override the configured language backend.\",\n    )\n    @click.option(\n        \"--transport\",\n        type=click.Choice([\"stdio\", \"sse\", \"streamable-http\"]),\n        default=\"stdio\",\n        show_default=True,\n        help=\"Transport protocol.\",\n    )\n    @click.option(\n        \"--host\",\n        type=str,\n        default=\"0.0.0.0\",\n        show_default=True,\n        help=\"Listen address for the MCP server (when using corresponding transport).\",\n    )\n    @click.option(\n        \"--port\", type=int, default=8000, show_default=True, help=\"Listen port for the MCP server (when using corresponding transport).\"\n    )\n    @click.option(\n        \"--enable-web-dashboard\",\n        type=bool,\n        is_flag=False,\n        default=None,\n        help=\"Enable the web dashboard (overriding the setting in Serena's config). \"\n        \"It is recommended to always enable the dashboard. If you don't want the browser to open on startup, set open-web-dashboard to False. \"\n        \"For more information, see\\nhttps://oraios.github.io/serena/02-usage/060_dashboard.html\",\n    )\n    @click.option(\n        \"--enable-gui-log-window\",\n        type=bool,\n        is_flag=False,\n        default=None,\n        help=\"Enable the gui log window (currently only displays logs; overriding the setting in Serena's config).\",\n    )\n    @click.option(\n        \"--open-web-dashboard\",\n        type=bool,\n        is_flag=False,\n        default=None,\n        help=\"Open Serena's dashboard in your browser after MCP server startup (overriding the setting in Serena's config).\",\n    )\n    @click.option(\n        \"--log-level\",\n        type=click.Choice([\"DEBUG\", \"INFO\", \"WARNING\", \"ERROR\", \"CRITICAL\"]),\n        default=None,\n        help=\"Override log level in config.\",\n    )\n    @click.option(\"--trace-lsp-communication\", type=bool, is_flag=False, default=None, help=\"Whether to trace LSP communication.\")\n    @click.option(\"--tool-timeout\", type=float, default=None, help=\"Override tool execution timeout in config.\")\n    @click.option(\n        \"--project-from-cwd\",\n        is_flag=True,\n        default=False,\n        help=\"Auto-detect project from current working directory (searches for .serena/project.yml or .git, falls back to CWD). Intended for CLI-based agents like Claude Code, Gemini and Codex.\",\n    )\n    def start_mcp_server(\n        project: str | None,\n        project_file_arg: str | None,\n        project_from_cwd: bool | None,\n        context: str,\n        modes: Sequence[str],\n        language_backend: str | None,\n        transport: Literal[\"stdio\", \"sse\", \"streamable-http\"],\n        host: str,\n        port: int,\n        enable_web_dashboard: bool | None,\n        open_web_dashboard: bool | None,\n        enable_gui_log_window: bool | None,\n        log_level: Literal[\"DEBUG\", \"INFO\", \"WARNING\", \"ERROR\", \"CRITICAL\"] | None,\n        trace_lsp_communication: bool | None,\n        tool_timeout: float | None,\n    ) -> None:\n        # initialize logging, using INFO level initially (will later be adjusted by SerenaAgent according to the config)\n        #   * memory log handler (for use by GUI/Dashboard)\n        #   * stream handler for stderr (for direct console output, which will also be captured by clients like Claude Desktop)\n        #   * file handler\n        # (Note that stdout must never be used for logging, as it is used by the MCP server to communicate with the client.)\n        Logger.root.setLevel(logging.INFO)\n        formatter = logging.Formatter(SERENA_LOG_FORMAT)\n        memory_log_handler = MemoryLogHandler()\n        Logger.root.addHandler(memory_log_handler)\n        stderr_handler = logging.StreamHandler(stream=sys.stderr)\n        stderr_handler.formatter = formatter\n        Logger.root.addHandler(stderr_handler)\n        log_path = SerenaPaths().get_next_log_file_path(\"mcp\")\n        file_handler = logging.FileHandler(log_path, mode=\"w\")\n        file_handler.formatter = formatter\n        Logger.root.addHandler(file_handler)\n\n        log.info(\"Initializing Serena MCP server\")\n        log.info(\"Storing logs in %s\", log_path)\n\n        # Handle --project-from-cwd flag\n        if project_from_cwd:\n            if project is not None or project_file_arg is not None:\n                raise click.UsageError(\"--project-from-cwd cannot be used with --project or positional project argument\")\n            project = find_project_root()\n            if project is not None:\n                log.info(\"Auto-detected project root: %s\", project)\n            else:\n                log.warning(\"No project root found from %s; not activating any project\", os.getcwd())\n\n        project_file = project_file_arg or project\n        factory = SerenaMCPFactory(context=context, project=project_file, memory_log_handler=memory_log_handler)\n        server = factory.create_mcp_server(\n            host=host,\n            port=port,\n            modes=modes,\n            language_backend=LanguageBackend.from_str(language_backend) if language_backend else None,\n            enable_web_dashboard=enable_web_dashboard,\n            open_web_dashboard=open_web_dashboard,\n            enable_gui_log_window=enable_gui_log_window,\n            log_level=log_level,\n            trace_lsp_communication=trace_lsp_communication,\n            tool_timeout=tool_timeout,\n        )\n        if project_file_arg:\n            log.warning(\n                \"Positional project arg is deprecated; use --project instead. Used: %s\",\n                project_file,\n            )\n        log.info(\"Starting MCP server …\")\n        server.run(transport=transport)\n\n    @staticmethod\n    @click.command(\n        \"print-system-prompt\", help=\"Print the system prompt for a project.\", context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH}\n    )\n    @click.argument(\"project\", type=click.Path(exists=True), default=os.getcwd(), required=False)\n    @click.option(\n        \"--log-level\",\n        type=click.Choice([\"DEBUG\", \"INFO\", \"WARNING\", \"ERROR\", \"CRITICAL\"]),\n        default=\"WARNING\",\n        help=\"Log level for prompt generation.\",\n    )\n    @click.option(\"--only-instructions\", is_flag=True, help=\"Print only the initial instructions, without prefix/postfix.\")\n    @click.option(\n        \"--context\", type=str, default=DEFAULT_CONTEXT, show_default=True, help=\"Built-in context name or path to custom context YAML.\"\n    )\n    @click.option(\n        \"--mode\",\n        \"modes\",\n        type=str,\n        multiple=True,\n        default=(),\n        show_default=False,\n        help=_MODES_EXPLANATION,\n    )\n    def print_system_prompt(\n        project: str, log_level: str, only_instructions: bool, context: str, modes: Sequence[str] | None = None\n    ) -> None:\n        prefix = \"You will receive access to Serena's symbolic tools. Below are instructions for using them, take them into account.\"\n        postfix = \"You begin by acknowledging that you understood the above instructions and are ready to receive tasks.\"\n        from serena.tools.workflow_tools import InitialInstructionsTool\n\n        lvl = logging.getLevelNamesMapping()[log_level.upper()]\n        logging.configure(level=lvl)\n        context_instance = SerenaAgentContext.load(context)\n        modes_selection_def: ModeSelectionDefinition | None = None\n        if modes:\n            modes_selection_def = ModeSelectionDefinition(default_modes=modes)\n        agent = SerenaAgent(\n            project=os.path.abspath(project),\n            serena_config=SerenaConfig(web_dashboard=False, log_level=lvl),\n            context=context_instance,\n            modes=modes_selection_def,\n        )\n        tool = agent.get_tool(InitialInstructionsTool)\n        instr = tool.apply()\n        if only_instructions:\n            print(instr)\n        else:\n            print(f\"{prefix}\\n{instr}\\n{postfix}\")\n\n    @staticmethod\n    @click.command(\n        \"start-project-server\",\n        help=\"Starts the Serena project server, which exposes project querying capabilities via HTTP.\",\n        context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH},\n    )\n    @click.option(\n        \"--host\",\n        type=str,\n        default=\"127.0.0.1\",\n        show_default=True,\n        help=\"Listen address for the project server.\",\n    )\n    @click.option(\n        \"--port\",\n        type=int,\n        default=None,\n        help=\"Listen port for the project server (default: ProjectServer.PORT).\",\n    )\n    @click.option(\n        \"--log-level\",\n        type=click.Choice([\"DEBUG\", \"INFO\", \"WARNING\", \"ERROR\", \"CRITICAL\"]),\n        default=None,\n        help=\"Override log level in config.\",\n    )\n    def start_project_server(\n        host: str,\n        port: int | None,\n        log_level: Literal[\"DEBUG\", \"INFO\", \"WARNING\", \"ERROR\", \"CRITICAL\"] | None,\n    ) -> None:\n        from serena.project_server import ProjectServer\n\n        # initialize logging\n        Logger.root.setLevel(logging.INFO)\n        formatter = logging.Formatter(SERENA_LOG_FORMAT)\n        stderr_handler = logging.StreamHandler(stream=sys.stderr)\n        stderr_handler.formatter = formatter\n        Logger.root.addHandler(stderr_handler)\n        log_path = SerenaPaths().get_next_log_file_path(\"project-server\")\n        file_handler = logging.FileHandler(log_path, mode=\"w\")\n        file_handler.formatter = formatter\n        Logger.root.addHandler(file_handler)\n\n        if log_level is not None:\n            Logger.root.setLevel(logging.getLevelNamesMapping()[log_level])\n\n        log.info(\"Starting Serena project server\")\n        log.info(\"Storing logs in %s\", log_path)\n\n        server = ProjectServer()\n        run_kwargs: dict[str, Any] = {\"host\": host}\n        if port is not None:\n            run_kwargs[\"port\"] = port\n        server.run(**run_kwargs)\n\n\nclass ModeCommands(AutoRegisteringGroup):\n    \"\"\"Group for 'mode' subcommands.\"\"\"\n\n    def __init__(self) -> None:\n        super().__init__(name=\"mode\", help=\"Manage Serena modes. You can run `mode <command> --help` for more info on each command.\")\n\n    @staticmethod\n    @click.command(\"list\", help=\"List available modes.\", context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH})\n    def list() -> None:\n        mode_names = SerenaAgentMode.list_registered_mode_names()\n        max_len_name = max(len(name) for name in mode_names) if mode_names else 20\n        for name in mode_names:\n            mode_yml_path = SerenaAgentMode.get_path(name)\n            is_internal = Path(mode_yml_path).is_relative_to(SERENAS_OWN_MODE_YAMLS_DIR)\n            descriptor = \"(internal)\" if is_internal else f\"(at {mode_yml_path})\"\n            name_descr_string = f\"{name:<{max_len_name + 4}}{descriptor}\"\n            click.echo(name_descr_string)\n\n    @staticmethod\n    @click.command(\"create\", help=\"Create a new mode or copy an internal one.\", context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH})\n    @click.option(\n        \"--name\",\n        \"-n\",\n        type=str,\n        default=None,\n        help=\"Name for the new mode. If --from-internal is passed may be left empty to create a mode of the same name, which will then override the internal mode.\",\n    )\n    @click.option(\"--from-internal\", \"from_internal\", type=str, default=None, help=\"Copy from an internal mode.\")\n    def create(name: str, from_internal: str) -> None:\n        if not (name or from_internal):\n            raise click.UsageError(\"Provide at least one of --name or --from-internal.\")\n        mode_name = name or from_internal\n        dest = os.path.join(SerenaPaths().user_modes_dir, f\"{mode_name}.yml\")\n        src = (\n            os.path.join(SERENAS_OWN_MODE_YAMLS_DIR, f\"{from_internal}.yml\")\n            if from_internal\n            else os.path.join(SERENAS_OWN_MODE_YAMLS_DIR, \"mode.template.yml\")\n        )\n        if not os.path.exists(src):\n            raise FileNotFoundError(\n                f\"Internal mode '{from_internal}' not found in {SERENAS_OWN_MODE_YAMLS_DIR}. Available modes: {SerenaAgentMode.list_registered_mode_names()}\"\n            )\n        os.makedirs(os.path.dirname(dest), exist_ok=True)\n        shutil.copyfile(src, dest)\n        click.echo(f\"Created mode '{mode_name}' at {dest}\")\n        _open_in_editor(dest)\n\n    @staticmethod\n    @click.command(\"edit\", help=\"Edit a custom mode YAML file.\", context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH})\n    @click.argument(\"mode_name\")\n    def edit(mode_name: str) -> None:\n        path = os.path.join(SerenaPaths().user_modes_dir, f\"{mode_name}.yml\")\n        if not os.path.exists(path):\n            if mode_name in SerenaAgentMode.list_registered_mode_names(include_user_modes=False):\n                click.echo(\n                    f\"Mode '{mode_name}' is an internal mode and cannot be edited directly. \"\n                    f\"Use 'mode create --from-internal {mode_name}' to create a custom mode that overrides it before editing.\"\n                )\n            else:\n                click.echo(f\"Custom mode '{mode_name}' not found. Create it with: mode create --name {mode_name}.\")\n            return\n        _open_in_editor(path)\n\n    @staticmethod\n    @click.command(\"delete\", help=\"Delete a custom mode file.\", context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH})\n    @click.argument(\"mode_name\")\n    def delete(mode_name: str) -> None:\n        path = os.path.join(SerenaPaths().user_modes_dir, f\"{mode_name}.yml\")\n        if not os.path.exists(path):\n            click.echo(f\"Custom mode '{mode_name}' not found.\")\n            return\n        os.remove(path)\n        click.echo(f\"Deleted custom mode '{mode_name}'.\")\n\n\nclass ContextCommands(AutoRegisteringGroup):\n    \"\"\"Group for 'context' subcommands.\"\"\"\n\n    def __init__(self) -> None:\n        super().__init__(\n            name=\"context\", help=\"Manage Serena contexts. You can run `context <command> --help` for more info on each command.\"\n        )\n\n    @staticmethod\n    @click.command(\"list\", help=\"List available contexts.\", context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH})\n    def list() -> None:\n        context_names = SerenaAgentContext.list_registered_context_names()\n        max_len_name = max(len(name) for name in context_names) if context_names else 20\n        for name in context_names:\n            context_yml_path = SerenaAgentContext.get_path(name)\n            is_internal = Path(context_yml_path).is_relative_to(SERENAS_OWN_CONTEXT_YAMLS_DIR)\n            descriptor = \"(internal)\" if is_internal else f\"(at {context_yml_path})\"\n            name_descr_string = f\"{name:<{max_len_name + 4}}{descriptor}\"\n            click.echo(name_descr_string)\n\n    @staticmethod\n    @click.command(\n        \"create\", help=\"Create a new context or copy an internal one.\", context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH}\n    )\n    @click.option(\n        \"--name\",\n        \"-n\",\n        type=str,\n        default=None,\n        help=\"Name for the new context. If --from-internal is passed may be left empty to create a context of the same name, which will then override the internal context\",\n    )\n    @click.option(\"--from-internal\", \"from_internal\", type=str, default=None, help=\"Copy from an internal context.\")\n    def create(name: str, from_internal: str) -> None:\n        if not (name or from_internal):\n            raise click.UsageError(\"Provide at least one of --name or --from-internal.\")\n        ctx_name = name or from_internal\n        dest = os.path.join(SerenaPaths().user_contexts_dir, f\"{ctx_name}.yml\")\n        src = (\n            os.path.join(SERENAS_OWN_CONTEXT_YAMLS_DIR, f\"{from_internal}.yml\")\n            if from_internal\n            else os.path.join(SERENAS_OWN_CONTEXT_YAMLS_DIR, \"context.template.yml\")\n        )\n        if not os.path.exists(src):\n            raise FileNotFoundError(\n                f\"Internal context '{from_internal}' not found in {SERENAS_OWN_CONTEXT_YAMLS_DIR}. Available contexts: {SerenaAgentContext.list_registered_context_names()}\"\n            )\n        os.makedirs(os.path.dirname(dest), exist_ok=True)\n        shutil.copyfile(src, dest)\n        click.echo(f\"Created context '{ctx_name}' at {dest}\")\n        _open_in_editor(dest)\n\n    @staticmethod\n    @click.command(\"edit\", help=\"Edit a custom context YAML file.\", context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH})\n    @click.argument(\"context_name\")\n    def edit(context_name: str) -> None:\n        path = os.path.join(SerenaPaths().user_contexts_dir, f\"{context_name}.yml\")\n        if not os.path.exists(path):\n            if context_name in SerenaAgentContext.list_registered_context_names(include_user_contexts=False):\n                click.echo(\n                    f\"Context '{context_name}' is an internal context and cannot be edited directly. \"\n                    f\"Use 'context create --from-internal {context_name}' to create a custom context that overrides it before editing.\"\n                )\n            else:\n                click.echo(f\"Custom context '{context_name}' not found. Create it with: context create --name {context_name}.\")\n            return\n        _open_in_editor(path)\n\n    @staticmethod\n    @click.command(\"delete\", help=\"Delete a custom context file.\", context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH})\n    @click.argument(\"context_name\")\n    def delete(context_name: str) -> None:\n        path = os.path.join(SerenaPaths().user_contexts_dir, f\"{context_name}.yml\")\n        if not os.path.exists(path):\n            click.echo(f\"Custom context '{context_name}' not found.\")\n            return\n        os.remove(path)\n        click.echo(f\"Deleted custom context '{context_name}'.\")\n\n\nclass SerenaConfigCommands(AutoRegisteringGroup):\n    \"\"\"Group for 'config' subcommands.\"\"\"\n\n    def __init__(self) -> None:\n        super().__init__(name=\"config\", help=\"Manage Serena configuration.\")\n\n    @staticmethod\n    @click.command(\n        \"edit\",\n        help=\"Edit serena_config.yml in your default editor. Will create a config file from the template if no config is found.\",\n        context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH},\n    )\n    def edit() -> None:\n        serena_config = SerenaConfig.from_config_file()\n        assert serena_config.config_file_path is not None\n        _open_in_editor(serena_config.config_file_path)\n\n\nclass ProjectCommands(AutoRegisteringGroup):\n    \"\"\"Group for 'project' subcommands.\"\"\"\n\n    def __init__(self) -> None:\n        super().__init__(\n            name=\"project\", help=\"Manage Serena projects. You can run `project <command> --help` for more info on each command.\"\n        )\n\n    @staticmethod\n    def _create_project(project_path: str, name: str | None, language: tuple[str, ...]) -> RegisteredProject:\n        \"\"\"\n        Helper method to create a project configuration file.\n\n        :param project_path: Path to the project directory\n        :param name: Optional project name (defaults to directory name if not specified)\n        :param language: Tuple of language names\n        :raises FileExistsError: If project.yml already exists\n        :raises ValueError: If an unsupported language is specified\n        :return: the RegisteredProject instance\n        \"\"\"\n        project_root = Path(project_path).resolve()\n        serena_config = SerenaConfig.from_config_file()\n        yml_path = serena_config.get_project_yml_location(str(project_root))\n        if os.path.exists(yml_path):\n            raise FileExistsError(f\"Project file {yml_path} already exists.\")\n\n        languages: list[Language] = []\n        if language:\n            for lang in language:\n                try:\n                    languages.append(Language(lang.lower()))\n                except ValueError:\n                    all_langs = [l.value for l in Language]\n                    raise ValueError(f\"Unknown language '{lang}'. Supported: {all_langs}\")\n\n        generated_conf = ProjectConfig.autogenerate(\n            project_root=project_path,\n            serena_config=serena_config,\n            project_name=name,\n            languages=languages if languages else None,\n            interactive=True,\n        )\n        languages_str = \", \".join([lang.value for lang in generated_conf.languages]) if generated_conf.languages else \"N/A\"\n        click.echo(f\"Generated project with languages {{{languages_str}}} at {yml_path}.\")\n        registered_project = serena_config.get_registered_project(str(project_root))\n        if registered_project is None:\n            registered_project = RegisteredProject(str(project_root), generated_conf)\n            serena_config.add_registered_project(registered_project)\n\n        return registered_project\n\n    @staticmethod\n    @click.command(\"create\", help=\"Create a new Serena project configuration.\", context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH})\n    @click.argument(\"project_path\", type=click.Path(exists=True, file_okay=False), default=os.getcwd())\n    @click.option(\"--name\", type=str, default=None, help=\"Project name; defaults to directory name if not specified.\")\n    @click.option(\n        \"--language\", type=str, multiple=True, help=\"Programming language(s); inferred if not specified. Can be passed multiple times.\"\n    )\n    @click.option(\"--index\", is_flag=True, help=\"Index the project after creation.\")\n    @click.option(\n        \"--log-level\",\n        type=click.Choice([\"DEBUG\", \"INFO\", \"WARNING\", \"ERROR\", \"CRITICAL\"]),\n        default=\"WARNING\",\n        help=\"Log level for indexing (only used if --index is set).\",\n    )\n    @click.option(\"--timeout\", type=float, default=10, help=\"Timeout for indexing a single file (only used if --index is set).\")\n    def create(project_path: str, name: str | None, language: tuple[str, ...], index: bool, log_level: str, timeout: float) -> None:\n        try:\n            registered_project = ProjectCommands._create_project(project_path, name, language)\n            if index:\n                click.echo(\"Indexing project...\")\n                ProjectCommands._index_project(registered_project, log_level, timeout=timeout)\n        except FileExistsError as e:\n            raise click.ClickException(f\"Project already exists: {e}\\nUse 'serena project index' to index an existing project.\")\n        except ValueError as e:\n            raise click.ClickException(str(e))\n\n    @staticmethod\n    @click.command(\n        \"index\",\n        help=\"Index a project by saving symbols to the LSP cache. Auto-creates project.yml if it doesn't exist.\",\n        context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH},\n    )\n    @click.argument(\"project\", type=PROJECT_TYPE, default=os.getcwd(), required=False)\n    @click.option(\"--name\", type=str, default=None, help=\"Project name (only used if auto-creating project.yml).\")\n    @click.option(\n        \"--language\",\n        type=str,\n        multiple=True,\n        help=\"Programming language(s) (only used if auto-creating project.yml). Inferred if not specified.\",\n    )\n    @click.option(\n        \"--log-level\",\n        type=click.Choice([\"DEBUG\", \"INFO\", \"WARNING\", \"ERROR\", \"CRITICAL\"]),\n        default=\"WARNING\",\n        help=\"Log level for indexing.\",\n    )\n    @click.option(\"--timeout\", type=float, default=10, help=\"Timeout for indexing a single file.\")\n    def index(project: str, name: str | None, language: tuple[str, ...], log_level: str, timeout: float) -> None:\n        serena_config = SerenaConfig.from_config_file()\n        registered_project = serena_config.get_registered_project(project, autoregister=True)\n        if registered_project is None:\n            # Project not found; auto-create it\n            click.echo(f\"No existing project found for '{project}'. Attempting auto-creation ...\")\n            try:\n                registered_project = ProjectCommands._create_project(project, name, language)\n            except Exception as e:\n                raise click.ClickException(str(e))\n\n        ProjectCommands._index_project(registered_project, log_level, timeout=timeout)\n\n    @staticmethod\n    def _index_project(registered_project: RegisteredProject, log_level: str, timeout: float) -> None:\n        lvl = logging.getLevelNamesMapping()[log_level.upper()]\n        logging.configure(level=lvl)\n        serena_config = SerenaConfig.from_config_file()\n        proj = registered_project.get_project_instance(serena_config=serena_config)\n        click.echo(f\"Indexing symbols in {proj} …\")\n        ls_mgr = proj.create_language_server_manager()\n        try:\n            log_file = os.path.join(proj.project_root, \".serena\", \"logs\", \"indexing.txt\")\n\n            files = proj.gather_source_files()\n\n            collected_exceptions: list[Exception] = []\n            files_failed = []\n            language_file_counts: dict[Language, int] = collections.defaultdict(lambda: 0)\n            for i, f in enumerate(tqdm(files, desc=\"Indexing\")):\n                try:\n                    ls = ls_mgr.get_language_server(f)\n                    ls.request_document_symbols(f)\n                    language_file_counts[ls.language] += 1\n                except Exception as e:\n                    log.error(f\"Failed to index {f}, continuing.\")\n                    collected_exceptions.append(e)\n                    files_failed.append(f)\n                if (i + 1) % 10 == 0:\n                    ls_mgr.save_all_caches()\n            reported_language_file_counts = {k.value: v for k, v in language_file_counts.items()}\n            click.echo(f\"Indexed files per language: {dict_string(reported_language_file_counts, brackets=None)}\")\n            ls_mgr.save_all_caches()\n\n            if len(files_failed) > 0:\n                os.makedirs(os.path.dirname(log_file), exist_ok=True)\n                with open(log_file, \"w\") as f:\n                    for file, exception in zip(files_failed, collected_exceptions, strict=True):\n                        f.write(f\"{file}\\n\")\n                        f.write(f\"{exception}\\n\")\n                click.echo(f\"Failed to index {len(files_failed)} files, see:\\n{log_file}\")\n        finally:\n            ls_mgr.stop_all()\n\n    @staticmethod\n    @click.command(\n        \"is_ignored_path\",\n        help=\"Check if a path is ignored by the project configuration.\",\n        context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH},\n    )\n    @click.argument(\"path\", type=click.Path(exists=False, file_okay=True, dir_okay=True))\n    @click.argument(\"project\", type=click.Path(exists=True, file_okay=False, dir_okay=True), default=os.getcwd())\n    def is_ignored_path(path: str, project: str) -> None:\n        \"\"\"\n        Check if a given path is ignored by the project configuration.\n\n        :param path: The path to check.\n        :param project: The path to the project directory, defaults to the current working directory.\n        \"\"\"\n        serena_config = SerenaConfig.from_config_file()\n        proj = Project.load(os.path.abspath(project), serena_config=serena_config)\n        if os.path.isabs(path):\n            path = os.path.relpath(path, start=proj.project_root)\n        is_ignored = proj.is_ignored_path(path)\n        click.echo(f\"Path '{path}' IS {'ignored' if is_ignored else 'IS NOT ignored'} by the project configuration.\")\n\n    @staticmethod\n    @click.command(\n        \"index-file\",\n        help=\"Index a single file by saving its symbols to the LSP cache.\",\n        context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH},\n    )\n    @click.argument(\"file\", type=click.Path(exists=True, file_okay=True, dir_okay=False))\n    @click.argument(\"project\", type=click.Path(exists=True, file_okay=False, dir_okay=True), default=os.getcwd())\n    @click.option(\"--verbose\", \"-v\", is_flag=True, help=\"Print detailed information about the indexed symbols.\")\n    def index_file(file: str, project: str, verbose: bool) -> None:\n        \"\"\"\n        Index a single file by saving its symbols to the LSP cache, useful for debugging.\n        :param file: path to the file to index, must be inside the project directory.\n        :param project: path to the project directory, defaults to the current working directory.\n        :param verbose: if set, prints detailed information about the indexed symbols.\n        \"\"\"\n        serena_config = SerenaConfig.from_config_file()\n        proj = Project.load(os.path.abspath(project), serena_config=serena_config)\n        if os.path.isabs(file):\n            file = os.path.relpath(file, start=proj.project_root)\n        if proj.is_ignored_path(file, ignore_non_source_files=True):\n            click.echo(f\"'{file}' is ignored or declared as non-code file by the project configuration, won't index.\")\n            exit(1)\n        ls_mgr = proj.create_language_server_manager()\n        try:\n            for ls in ls_mgr.iter_language_servers():\n                click.echo(f\"Indexing for language {ls.language.value} …\")\n                document_symbols = ls.request_document_symbols(file)\n                symbols, _ = document_symbols.get_all_symbols_and_roots()\n                if verbose:\n                    click.echo(f\"Symbols in file '{file}':\")\n                    for symbol in symbols:\n                        click.echo(f\"  - {symbol['name']} at line {symbol['selectionRange']['start']['line']} of kind {symbol['kind']}\")\n                ls.save_cache()\n                click.echo(f\"Successfully indexed file '{file}', {len(symbols)} symbols saved to cache in {ls.cache_dir}.\")\n        finally:\n            ls_mgr.stop_all()\n\n    @staticmethod\n    @click.command(\n        \"health-check\",\n        help=\"Perform a comprehensive health check of the project's tools and language server.\",\n        context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH},\n    )\n    @click.argument(\"project\", type=click.Path(exists=True, file_okay=False, dir_okay=True), default=os.getcwd())\n    def health_check(project: str) -> None:\n        \"\"\"\n        Perform a comprehensive health check of the project's tools and language server.\n\n        :param project: path to the project directory, defaults to the current working directory.\n        \"\"\"\n        # NOTE: completely written by Claude Code, only functionality was reviewed, not implementation\n        logging.configure(level=logging.INFO)\n        project_path = os.path.abspath(project)\n        serena_config = SerenaConfig.from_config_file()\n        serena_config.language_backend = LanguageBackend.LSP\n        serena_config.gui_log_window = False\n        serena_config.web_dashboard = False\n        proj = Project.load(project_path, serena_config=serena_config)\n\n        # Create log file with timestamp\n        timestamp = datetime_tag()\n        log_dir = os.path.join(project_path, \".serena\", \"logs\", \"health-checks\")\n        os.makedirs(log_dir, exist_ok=True)\n        log_file = os.path.join(log_dir, f\"health_check_{timestamp}.log\")\n\n        with FileLoggerContext(log_file, append=False, enabled=True):\n            log.info(\"Starting health check for project: %s\", project_path)\n\n            try:\n                # Create SerenaAgent with dashboard disabled\n                log.info(\"Creating SerenaAgent with disabled dashboard...\")\n\n                agent = SerenaAgent(project=project_path, serena_config=serena_config)\n                log.info(\"SerenaAgent created successfully\")\n\n                # Find first non-empty file that can be analyzed\n                log.info(\"Searching for analyzable files...\")\n                files = proj.gather_source_files()\n                target_file = None\n\n                for file_path in files:\n                    try:\n                        full_path = os.path.join(project_path, file_path)\n                        if os.path.getsize(full_path) > 0:\n                            target_file = file_path\n                            log.info(\"Found analyzable file: %s\", target_file)\n                            break\n                    except (OSError, FileNotFoundError):\n                        continue\n\n                if not target_file:\n                    log.error(\"No analyzable files found in project\")\n                    click.echo(\"❌ Health check failed: No analyzable files found\")\n                    click.echo(f\"Log saved to: {log_file}\")\n                    return\n\n                # Get tools from agent\n                overview_tool = agent.get_tool(GetSymbolsOverviewTool)\n                find_symbol_tool = agent.get_tool(FindSymbolTool)\n                find_refs_tool = agent.get_tool(FindReferencingSymbolsTool)\n                search_pattern_tool = agent.get_tool(SearchForPatternTool)\n\n                # Test 1: Get symbols overview\n                log.info(\"Testing GetSymbolsOverviewTool on file: %s\", target_file)\n                overview_data = agent.execute_task(lambda: overview_tool.get_symbol_overview(target_file))\n                log.info(f\"GetSymbolsOverviewTool returned: {overview_data}\")\n\n                if not overview_data:\n                    log.error(\"No symbols found in file %s\", target_file)\n                    click.echo(\"❌ Health check failed: No symbols found in target file\")\n                    click.echo(f\"Log saved to: {log_file}\")\n                    return\n\n                # Extract suitable symbol (prefer class or function over variables)\n                preferred_kinds = {SymbolKind.Class.name, SymbolKind.Function.name, SymbolKind.Method.name, SymbolKind.Constructor.name}\n                selected_symbol = None\n                for symbol in overview_data:\n                    if symbol.get(\"kind\") in preferred_kinds:\n                        selected_symbol = symbol\n                        break\n\n                # If no preferred symbol found, use first available\n                if not selected_symbol:\n                    selected_symbol = overview_data[0]\n                    log.info(\"No class or function found, using first available symbol\")\n\n                symbol_name = selected_symbol[\"name\"]\n                symbol_kind = selected_symbol[\"kind\"]\n                log.info(\"Using symbol for testing: %s (kind: %s)\", symbol_name, symbol_kind)\n\n                # Test 2: FindSymbolTool\n                log.info(\"Testing FindSymbolTool for symbol: %s\", symbol_name)\n                find_symbol_result = agent.execute_task(\n                    lambda: find_symbol_tool.apply(symbol_name, relative_path=target_file, include_body=True)\n                )\n                find_symbol_data = json.loads(find_symbol_result)\n                log.info(\"FindSymbolTool found %d matches for symbol %s\", len(find_symbol_data), symbol_name)\n\n                # Test 3: FindReferencingSymbolsTool\n                log.info(\"Testing FindReferencingSymbolsTool for symbol: %s\", symbol_name)\n                try:\n                    find_refs_result = agent.execute_task(lambda: find_refs_tool.apply(symbol_name, relative_path=target_file))\n                    find_refs_data = json.loads(find_refs_result)\n                    log.info(\"FindReferencingSymbolsTool found %d references for symbol %s\", len(find_refs_data), symbol_name)\n                except Exception as e:\n                    log.warning(\"FindReferencingSymbolsTool failed for symbol %s: %s\", symbol_name, str(e))\n                    find_refs_data = []\n\n                # Test 4: SearchForPatternTool to verify references\n                log.info(\"Testing SearchForPatternTool for pattern: %s\", symbol_name)\n                try:\n                    search_result = agent.execute_task(\n                        lambda: search_pattern_tool.apply(substring_pattern=symbol_name, restrict_search_to_code_files=True)\n                    )\n                    search_data = json.loads(search_result)\n                    pattern_matches = sum(len(matches) for matches in search_data.values())\n                    log.info(\"SearchForPatternTool found %d pattern matches for %s\", pattern_matches, symbol_name)\n                except Exception as e:\n                    log.warning(\"SearchForPatternTool failed for pattern %s: %s\", symbol_name, str(e))\n                    pattern_matches = 0\n\n                # Verify tools worked as expected\n                tools_working = True\n                if not find_symbol_data:\n                    log.error(\"FindSymbolTool returned no results\")\n                    tools_working = False\n\n                if len(find_refs_data) == 0 and pattern_matches == 0:\n                    log.warning(\"Both FindReferencingSymbolsTool and SearchForPatternTool found no matches - this might indicate an issue\")\n\n                log.info(\"Health check completed successfully\")\n\n                if tools_working:\n                    click.echo(\"✅ Health check passed - All tools working correctly\")\n                else:\n                    click.echo(\"⚠️  Health check completed with warnings - Check log for details\")\n\n            except Exception as e:\n                log.exception(\"Health check failed with exception: %s\", str(e))\n                click.echo(f\"❌ Health check failed: {e!s}\")\n\n            finally:\n                click.echo(f\"Log saved to: {log_file}\")\n\n\nclass ToolCommands(AutoRegisteringGroup):\n    \"\"\"Group for 'tool' subcommands.\"\"\"\n\n    def __init__(self) -> None:\n        super().__init__(\n            name=\"tools\",\n            help=\"Commands related to Serena's tools. You can run `serena tools <command> --help` for more info on each command.\",\n        )\n\n    @staticmethod\n    @click.command(\n        \"list\",\n        help=\"Prints an overview of the tools that are active by default (not just the active ones for your project). For viewing all tools, pass `--all / -a`\",\n        context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH},\n    )\n    @click.option(\"--quiet\", \"-q\", is_flag=True)\n    @click.option(\"--all\", \"-a\", \"include_optional\", is_flag=True, help=\"List all tools, including those not enabled by default.\")\n    @click.option(\"--only-optional\", is_flag=True, help=\"List only optional tools (those not enabled by default).\")\n    def list(quiet: bool = False, include_optional: bool = False, only_optional: bool = False) -> None:\n        tool_registry = ToolRegistry()\n        if quiet:\n            if only_optional:\n                tool_names = tool_registry.get_tool_names_optional()\n            elif include_optional:\n                tool_names = tool_registry.get_tool_names()\n            else:\n                tool_names = tool_registry.get_tool_names_default_enabled()\n            for tool_name in tool_names:\n                click.echo(tool_name)\n        else:\n            ToolRegistry().print_tool_overview(include_optional=include_optional, only_optional=only_optional)\n\n    @staticmethod\n    @click.command(\n        \"description\",\n        help=\"Print the description of a tool, optionally with a specific context (the latter may modify the default description).\",\n        context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH},\n    )\n    @click.argument(\"tool_name\", type=str)\n    @click.option(\"--context\", type=str, default=None, help=\"Context name or path to context file.\")\n    def description(tool_name: str, context: str | None = None) -> None:\n        # Load the context\n        serena_context = None\n        if context:\n            serena_context = SerenaAgentContext.load(context)\n\n        agent = SerenaAgent(\n            project=None,\n            serena_config=SerenaConfig(web_dashboard=False, log_level=logging.INFO),\n            context=serena_context,\n        )\n        tool = agent.get_tool_by_name(tool_name)\n        mcp_tool = SerenaMCPFactory.make_mcp_tool(tool)\n        click.echo(mcp_tool.description)\n\n\nclass PromptCommands(AutoRegisteringGroup):\n    def __init__(self) -> None:\n        super().__init__(name=\"prompts\", help=\"Commands related to Serena's prompts that are outside of contexts and modes.\")\n\n    @staticmethod\n    def _get_user_prompt_yaml_path(prompt_yaml_name: str) -> str:\n        templates_dir = SerenaPaths().user_prompt_templates_dir\n        os.makedirs(templates_dir, exist_ok=True)\n        return os.path.join(templates_dir, prompt_yaml_name)\n\n    @staticmethod\n    @click.command(\n        \"list\", help=\"Lists yamls that are used for defining prompts.\", context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH}\n    )\n    def list() -> None:\n        serena_prompt_yaml_names = [os.path.basename(f) for f in glob.glob(PROMPT_TEMPLATES_DIR_INTERNAL + \"/*.yml\")]\n        for prompt_yaml_name in serena_prompt_yaml_names:\n            user_prompt_yaml_path = PromptCommands._get_user_prompt_yaml_path(prompt_yaml_name)\n            if os.path.exists(user_prompt_yaml_path):\n                click.echo(f\"{user_prompt_yaml_path} merged with default prompts in {prompt_yaml_name}\")\n            else:\n                click.echo(prompt_yaml_name)\n\n    @staticmethod\n    @click.command(\n        \"create-override\",\n        help=\"Create an override of an internal prompts yaml for customizing Serena's prompts\",\n        context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH},\n    )\n    @click.argument(\"prompt_yaml_name\")\n    def create_override(prompt_yaml_name: str) -> None:\n        \"\"\"\n        :param prompt_yaml_name: The yaml name of the prompt you want to override. Call the `list` command for discovering valid prompt yaml names.\n        :return:\n        \"\"\"\n        # for convenience, we can pass names without .yml\n        if not prompt_yaml_name.endswith(\".yml\"):\n            prompt_yaml_name = prompt_yaml_name + \".yml\"\n        user_prompt_yaml_path = PromptCommands._get_user_prompt_yaml_path(prompt_yaml_name)\n        if os.path.exists(user_prompt_yaml_path):\n            raise FileExistsError(f\"{user_prompt_yaml_path} already exists.\")\n        serena_prompt_yaml_path = os.path.join(PROMPT_TEMPLATES_DIR_INTERNAL, prompt_yaml_name)\n        shutil.copyfile(serena_prompt_yaml_path, user_prompt_yaml_path)\n        _open_in_editor(user_prompt_yaml_path)\n\n    @staticmethod\n    @click.command(\n        \"edit-override\", help=\"Edit an existing prompt override file\", context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH}\n    )\n    @click.argument(\"prompt_yaml_name\")\n    def edit_override(prompt_yaml_name: str) -> None:\n        \"\"\"\n        :param prompt_yaml_name: The yaml name of the prompt override to edit.\n        :return:\n        \"\"\"\n        # for convenience, we can pass names without .yml\n        if not prompt_yaml_name.endswith(\".yml\"):\n            prompt_yaml_name = prompt_yaml_name + \".yml\"\n        user_prompt_yaml_path = PromptCommands._get_user_prompt_yaml_path(prompt_yaml_name)\n        if not os.path.exists(user_prompt_yaml_path):\n            click.echo(f\"Override file '{prompt_yaml_name}' not found. Create it with: prompts create-override {prompt_yaml_name}\")\n            return\n        _open_in_editor(user_prompt_yaml_path)\n\n    @staticmethod\n    @click.command(\"list-overrides\", help=\"List existing prompt override files\", context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH})\n    def list_overrides() -> None:\n        user_templates_dir = SerenaPaths().user_prompt_templates_dir\n        os.makedirs(user_templates_dir, exist_ok=True)\n        serena_prompt_yaml_names = [os.path.basename(f) for f in glob.glob(PROMPT_TEMPLATES_DIR_INTERNAL + \"/*.yml\")]\n        override_files = glob.glob(os.path.join(user_templates_dir, \"*.yml\"))\n        for file_path in override_files:\n            if os.path.basename(file_path) in serena_prompt_yaml_names:\n                click.echo(file_path)\n\n    @staticmethod\n    @click.command(\"delete-override\", help=\"Delete a prompt override file\", context_settings={\"max_content_width\": _MAX_CONTENT_WIDTH})\n    @click.argument(\"prompt_yaml_name\")\n    def delete_override(prompt_yaml_name: str) -> None:\n        \"\"\"\n\n        :param prompt_yaml_name:  The yaml name of the prompt override to delete.\"\n        :return:\n        \"\"\"\n        # for convenience, we can pass names without .yml\n        if not prompt_yaml_name.endswith(\".yml\"):\n            prompt_yaml_name = prompt_yaml_name + \".yml\"\n        user_prompt_yaml_path = PromptCommands._get_user_prompt_yaml_path(prompt_yaml_name)\n        if not os.path.exists(user_prompt_yaml_path):\n            click.echo(f\"Override file '{prompt_yaml_name}' not found.\")\n            return\n        os.remove(user_prompt_yaml_path)\n        click.echo(f\"Deleted override file '{prompt_yaml_name}'.\")\n\n\n# Expose groups so we can reference them in pyproject.toml\nmode = ModeCommands()\ncontext = ContextCommands()\nproject = ProjectCommands()\nconfig = SerenaConfigCommands()\ntools = ToolCommands()\nprompts = PromptCommands()\n\n# Expose toplevel commands for the same reason\ntop_level = TopLevelCommands()\nstart_mcp_server = top_level.start_mcp_server\n\n# needed for the help script to work - register all subcommands to the top-level group\nfor subgroup in (mode, context, project, config, tools, prompts):\n    top_level.add_command(subgroup)\n\n\ndef get_help() -> str:\n    \"\"\"Retrieve the help text for the top-level Serena CLI.\"\"\"\n    return top_level.get_help(click.Context(top_level, info_name=\"serena\"))\n"
  },
  {
    "path": "src/serena/code_editor.py",
    "content": "import json\nimport logging\nimport os\nfrom abc import ABC, abstractmethod\nfrom collections.abc import Iterable, Iterator, Reversible\nfrom contextlib import contextmanager\nfrom typing import Generic, TypeVar, cast\n\nfrom serena.jetbrains.jetbrains_plugin_client import JetBrainsPluginClient\nfrom serena.symbol import JetBrainsSymbol, LanguageServerSymbol, LanguageServerSymbolRetriever, PositionInFile, Symbol\nfrom solidlsp import SolidLanguageServer, ls_types\nfrom solidlsp.ls import LSPFileBuffer\nfrom solidlsp.ls_utils import PathUtils, TextUtils\n\nfrom .project import Project\n\nlog = logging.getLogger(__name__)\nTSymbol = TypeVar(\"TSymbol\", bound=Symbol)\n\n\nclass CodeEditor(Generic[TSymbol], ABC):\n    def __init__(self, project: Project) -> None:\n        self.project_root = project.project_root\n        self.encoding = project.project_config.encoding\n        self.newline = project.line_ending.newline_str\n\n    class EditedFile(ABC):\n        def __init__(self, relative_path: str) -> None:\n            self.relative_path = relative_path\n\n        @abstractmethod\n        def get_contents(self) -> str:\n            \"\"\"\n            :return: the contents of the file.\n            \"\"\"\n\n        @abstractmethod\n        def set_contents(self, contents: str) -> None:\n            \"\"\"\n            Fully resets the contents of the file.\n\n            :param contents: the new contents\n            \"\"\"\n\n        @abstractmethod\n        def delete_text_between_positions(self, start_pos: PositionInFile, end_pos: PositionInFile) -> None:\n            pass\n\n        @abstractmethod\n        def insert_text_at_position(self, pos: PositionInFile, text: str) -> None:\n            pass\n\n    @contextmanager\n    def _open_file_context(self, relative_path: str) -> Iterator[\"CodeEditor.EditedFile\"]:\n        \"\"\"\n        Context manager for opening a file\n        \"\"\"\n        raise NotImplementedError(\"This method must be overridden for each subclass\")\n\n    @contextmanager\n    def edited_file_context(self, relative_path: str) -> Iterator[\"CodeEditor.EditedFile\"]:\n        \"\"\"\n        Context manager for editing a file.\n        \"\"\"\n        with self._open_file_context(relative_path) as edited_file:\n            yield edited_file\n            # save the file\n            self._save_edited_file(edited_file)\n\n    def _save_edited_file(self, edited_file: \"CodeEditor.EditedFile\") -> None:\n        abs_path = os.path.join(self.project_root, edited_file.relative_path)\n        new_contents = edited_file.get_contents()\n        with open(abs_path, \"w\", encoding=self.encoding, newline=self.newline) as f:\n            f.write(new_contents)\n\n    @abstractmethod\n    def _find_unique_symbol(self, name_path: str, relative_file_path: str) -> TSymbol:\n        \"\"\"\n        Finds the unique symbol with the given name in the given file.\n        If no such symbol exists, raises a ValueError.\n\n        :param name_path: the name path\n        :param relative_file_path: the relative path of the file in which to search for the symbol.\n        :return: the unique symbol\n        \"\"\"\n\n    def replace_body(self, name_path: str, relative_file_path: str, body: str) -> None:\n        \"\"\"\n        Replaces the body of the symbol with the given name_path in the given file.\n\n        :param name_path: the name path of the symbol to replace.\n        :param relative_file_path: the relative path of the file in which the symbol is defined.\n        :param body: the new body\n        \"\"\"\n        symbol = self._find_unique_symbol(name_path, relative_file_path)\n        start_pos = symbol.get_body_start_position_or_raise()\n        end_pos = symbol.get_body_end_position_or_raise()\n\n        with self.edited_file_context(relative_file_path) as edited_file:\n            # make sure the replacement adds no additional newlines (before or after) - all newlines\n            # and whitespace before/after should remain the same, so we strip it entirely\n            body = body.strip()\n\n            edited_file.delete_text_between_positions(start_pos, end_pos)\n            edited_file.insert_text_at_position(start_pos, body)\n\n    @staticmethod\n    def _count_leading_newlines(text: Iterable) -> int:\n        cnt = 0\n        for c in text:\n            if c == \"\\n\":\n                cnt += 1\n            elif c == \"\\r\":\n                continue\n            else:\n                break\n        return cnt\n\n    @classmethod\n    def _count_trailing_newlines(cls, text: Reversible) -> int:\n        return cls._count_leading_newlines(reversed(text))\n\n    def insert_after_symbol(self, name_path: str, relative_file_path: str, body: str) -> None:\n        \"\"\"\n        Inserts content after the symbol with the given name in the given file.\n        \"\"\"\n        symbol = self._find_unique_symbol(name_path, relative_file_path)\n\n        # make sure body always ends with at least one newline\n        if not body.endswith(\"\\n\"):\n            body += \"\\n\"\n\n        pos = symbol.get_body_end_position_or_raise()\n\n        # start at the beginning of the next line\n        col = 0\n        line = pos.line + 1\n\n        # make sure a suitable number of leading empty lines is used (at least 0/1 depending on the symbol type,\n        # otherwise as many as the caller wanted to insert)\n        original_leading_newlines = self._count_leading_newlines(body)\n        body = body.lstrip(\"\\r\\n\")\n        min_empty_lines = 0\n        if symbol.is_neighbouring_definition_separated_by_empty_line():\n            min_empty_lines = 1\n        num_leading_empty_lines = max(min_empty_lines, original_leading_newlines)\n        if num_leading_empty_lines:\n            body = (\"\\n\" * num_leading_empty_lines) + body\n\n        # make sure the one line break succeeding the original symbol, which we repurposed as prefix via\n        # `line += 1`, is replaced\n        body = body.rstrip(\"\\r\\n\") + \"\\n\"\n\n        with self.edited_file_context(relative_file_path) as edited_file:\n            edited_file.insert_text_at_position(PositionInFile(line, col), body)\n\n    def insert_before_symbol(self, name_path: str, relative_file_path: str, body: str) -> None:\n        \"\"\"\n        Inserts content before the symbol with the given name in the given file.\n        \"\"\"\n        symbol = self._find_unique_symbol(name_path, relative_file_path)\n        symbol_start_pos = symbol.get_body_start_position_or_raise()\n\n        # insert position is the start of line where the symbol is defined\n        line = symbol_start_pos.line\n        col = 0\n\n        original_trailing_empty_lines = self._count_trailing_newlines(body) - 1\n\n        # ensure eol is present at end\n        body = body.rstrip() + \"\\n\"\n\n        # add suitable number of trailing empty lines after the body (at least 0/1 depending on the symbol type,\n        # otherwise as many as the caller wanted to insert)\n        min_trailing_empty_lines = 0\n        if symbol.is_neighbouring_definition_separated_by_empty_line():\n            min_trailing_empty_lines = 1\n        num_trailing_newlines = max(min_trailing_empty_lines, original_trailing_empty_lines)\n        body += \"\\n\" * num_trailing_newlines\n\n        # apply edit\n        with self.edited_file_context(relative_file_path) as edited_file:\n            edited_file.insert_text_at_position(PositionInFile(line=line, col=col), body)\n\n    def insert_at_line(self, relative_path: str, line: int, content: str) -> None:\n        \"\"\"\n        Inserts content at the given line in the given file.\n\n        :param relative_path: the relative path of the file in which to insert content\n        :param line: the 0-based index of the line to insert content at\n        :param content: the content to insert\n        \"\"\"\n        with self.edited_file_context(relative_path) as edited_file:\n            edited_file.insert_text_at_position(PositionInFile(line, 0), content)\n\n    def delete_lines(self, relative_path: str, start_line: int, end_line: int) -> None:\n        \"\"\"\n        Deletes lines in the given file.\n\n        :param relative_path: the relative path of the file in which to delete lines\n        :param start_line: the 0-based index of the first line to delete (inclusive)\n        :param end_line: the 0-based index of the last line to delete (inclusive)\n        \"\"\"\n        start_col = 0\n        end_line_for_delete = end_line + 1\n        end_col = 0\n        with self.edited_file_context(relative_path) as edited_file:\n            start_pos = PositionInFile(line=start_line, col=start_col)\n            end_pos = PositionInFile(line=end_line_for_delete, col=end_col)\n            edited_file.delete_text_between_positions(start_pos, end_pos)\n\n    def delete_symbol(self, name_path: str, relative_file_path: str) -> None:\n        \"\"\"\n        Deletes the symbol with the given name in the given file.\n        \"\"\"\n        symbol = self._find_unique_symbol(name_path, relative_file_path)\n        start_pos = symbol.get_body_start_position_or_raise()\n        end_pos = symbol.get_body_end_position_or_raise()\n        with self.edited_file_context(relative_file_path) as edited_file:\n            edited_file.delete_text_between_positions(start_pos, end_pos)\n\n    @abstractmethod\n    def rename_symbol(self, name_path: str, relative_file_path: str, new_name: str) -> str:\n        \"\"\"\n        Renames the symbol with the given name throughout the codebase.\n\n        :param name_path: the name path of the symbol to rename\n        :param relative_file_path: the relative path of the file containing the symbol\n        :param new_name: the new name for the symbol\n        :return: a status message\n        \"\"\"\n\n\nclass LanguageServerCodeEditor(CodeEditor[LanguageServerSymbol]):\n    def __init__(self, symbol_retriever: LanguageServerSymbolRetriever):\n        super().__init__(project=symbol_retriever.project)\n        self._symbol_retriever = symbol_retriever\n\n    def _get_language_server(self, relative_path: str) -> SolidLanguageServer:\n        return self._symbol_retriever.get_language_server(relative_path)\n\n    class EditedFile(CodeEditor.EditedFile):\n        def __init__(self, lang_server: SolidLanguageServer, relative_path: str, file_buffer: LSPFileBuffer):\n            super().__init__(relative_path)\n            self._lang_server = lang_server\n            self._file_buffer = file_buffer\n\n        def get_contents(self) -> str:\n            return self._file_buffer.contents\n\n        def set_contents(self, contents: str) -> None:\n            self._file_buffer.contents = contents\n\n        def delete_text_between_positions(self, start_pos: PositionInFile, end_pos: PositionInFile) -> None:\n            self._lang_server.delete_text_between_positions(self.relative_path, start_pos.to_lsp_position(), end_pos.to_lsp_position())\n\n        def insert_text_at_position(self, pos: PositionInFile, text: str) -> None:\n            self._lang_server.insert_text_at_position(self.relative_path, pos.line, pos.col, text)\n\n        def apply_text_edits(self, text_edits: list[ls_types.TextEdit]) -> None:\n            return self._lang_server.apply_text_edits_to_file(self.relative_path, text_edits)\n\n    @contextmanager\n    def _open_file_context(self, relative_path: str) -> Iterator[\"CodeEditor.EditedFile\"]:\n        lang_server = self._get_language_server(relative_path)\n        with lang_server.open_file(relative_path) as file_buffer:\n            yield self.EditedFile(lang_server, relative_path, file_buffer)\n\n    def _get_code_file_content(self, relative_path: str) -> str:\n        \"\"\"Get the content of a file using the language server.\"\"\"\n        lang_server = self._get_language_server(relative_path)\n        return lang_server.language_server.retrieve_full_file_content(relative_path)\n\n    def _find_unique_symbol(self, name_path: str, relative_file_path: str) -> LanguageServerSymbol:\n        return self._symbol_retriever.find_unique(name_path, within_relative_path=relative_file_path)\n\n    def _relative_path_from_uri(self, uri: str) -> str:\n        return os.path.relpath(PathUtils.uri_to_path(uri), self.project_root)\n\n    class EditOperation(ABC):\n        @abstractmethod\n        def apply(self) -> None:\n            pass\n\n    class EditOperationFileTextEdits(EditOperation):\n        def __init__(self, code_editor: \"LanguageServerCodeEditor\", file_uri: str, text_edits: list[ls_types.TextEdit]):\n            self._code_editor = code_editor\n            self._relative_path = code_editor._relative_path_from_uri(file_uri)\n            self._text_edits = text_edits\n\n        def apply(self) -> None:\n            with self._code_editor.edited_file_context(self._relative_path) as edited_file:\n                edited_file = cast(LanguageServerCodeEditor.EditedFile, edited_file)\n                edited_file.apply_text_edits(self._text_edits)\n\n    class EditOperationRenameFile(EditOperation):\n        def __init__(self, code_editor: \"LanguageServerCodeEditor\", old_uri: str, new_uri: str):\n            self._code_editor = code_editor\n            self._old_relative_path = code_editor._relative_path_from_uri(old_uri)\n            self._new_relative_path = code_editor._relative_path_from_uri(new_uri)\n\n        def apply(self) -> None:\n            old_abs_path = os.path.join(self._code_editor.project_root, self._old_relative_path)\n            new_abs_path = os.path.join(self._code_editor.project_root, self._new_relative_path)\n            os.rename(old_abs_path, new_abs_path)\n\n    def _workspace_edit_to_edit_operations(self, workspace_edit: ls_types.WorkspaceEdit) -> list[\"LanguageServerCodeEditor.EditOperation\"]:\n        operations: list[LanguageServerCodeEditor.EditOperation] = []\n\n        if \"changes\" in workspace_edit:\n            for uri, edits in workspace_edit[\"changes\"].items():\n                operations.append(self.EditOperationFileTextEdits(self, uri, edits))\n\n        if \"documentChanges\" in workspace_edit:\n            for change in workspace_edit[\"documentChanges\"]:\n                if \"textDocument\" in change and \"edits\" in change:\n                    operations.append(self.EditOperationFileTextEdits(self, change[\"textDocument\"][\"uri\"], change[\"edits\"]))\n                elif \"kind\" in change:\n                    if change[\"kind\"] == \"rename\":\n                        operations.append(self.EditOperationRenameFile(self, change[\"oldUri\"], change[\"newUri\"]))\n                    else:\n                        raise ValueError(f\"Unhandled document change kind: {change}; Please report to Serena developers.\")\n                else:\n                    raise ValueError(f\"Unhandled document change format: {change}; Please report to Serena developers.\")\n\n        return operations\n\n    def _apply_workspace_edit(self, workspace_edit: ls_types.WorkspaceEdit) -> int:\n        \"\"\"\n        Applies a WorkspaceEdit\n\n        :param workspace_edit: the edit to apply\n        :return: number of edit operations applied\n        \"\"\"\n        operations = self._workspace_edit_to_edit_operations(workspace_edit)\n        for operation in operations:\n            operation.apply()\n        return len(operations)\n\n    def rename_symbol(self, name_path: str, relative_file_path: str, new_name: str) -> str:\n        symbol = self._find_unique_symbol(name_path, relative_file_path)\n        if not symbol.location.has_position_in_file():\n            raise ValueError(f\"Symbol '{name_path}' does not have a valid position in file for renaming\")\n\n        # After has_position_in_file check, line and column are guaranteed to be non-None\n        assert symbol.location.line is not None\n        assert symbol.location.column is not None\n\n        lang_server = self._get_language_server(relative_file_path)\n        rename_result = lang_server.request_rename_symbol_edit(\n            relative_file_path=relative_file_path, line=symbol.location.line, column=symbol.location.column, new_name=new_name\n        )\n        if rename_result is None:\n            raise ValueError(\n                f\"Language server for {lang_server.language_id} returned no rename edits for symbol '{name_path}'. \"\n                f\"The symbol might not support renaming.\"\n            )\n        num_changes = self._apply_workspace_edit(rename_result)\n\n        if num_changes == 0:\n            raise ValueError(\n                f\"Renaming symbol '{name_path}' to '{new_name}' resulted in no changes being applied; renaming may not be supported.\"\n            )\n\n        msg = f\"Successfully renamed '{name_path}' to '{new_name}' ({num_changes} changes applied)\"\n        return msg\n\n\nclass JetBrainsCodeEditor(CodeEditor[JetBrainsSymbol]):\n    def __init__(self, project: Project) -> None:\n        self._project = project\n        super().__init__(project)\n\n    class EditedFile(CodeEditor.EditedFile):\n        def __init__(self, relative_path: str, project: Project):\n            super().__init__(relative_path)\n            path = os.path.join(project.project_root, relative_path)\n            log.info(\"Editing file: %s\", path)\n            with open(path, encoding=project.project_config.encoding) as f:\n                self._content = f.read()\n\n        def get_contents(self) -> str:\n            return self._content\n\n        def set_contents(self, contents: str) -> None:\n            self._content = contents\n\n        def delete_text_between_positions(self, start_pos: PositionInFile, end_pos: PositionInFile) -> None:\n            self._content, _ = TextUtils.delete_text_between_positions(\n                self._content, start_pos.line, start_pos.col, end_pos.line, end_pos.col\n            )\n\n        def insert_text_at_position(self, pos: PositionInFile, text: str) -> None:\n            self._content, _, _ = TextUtils.insert_text_at_position(self._content, pos.line, pos.col, text)\n\n    @contextmanager\n    def _open_file_context(self, relative_path: str) -> Iterator[\"CodeEditor.EditedFile\"]:\n        yield self.EditedFile(relative_path, self._project)\n\n    def _save_edited_file(self, edited_file: \"CodeEditor.EditedFile\") -> None:\n        super()._save_edited_file(edited_file)\n        with JetBrainsPluginClient.from_project(self._project) as client:\n            client.refresh_file(edited_file.relative_path)\n\n    def _find_unique_symbol(self, name_path: str, relative_file_path: str) -> JetBrainsSymbol:\n        with JetBrainsPluginClient.from_project(self._project) as client:\n            result = client.find_symbol(name_path, relative_path=relative_file_path, include_body=False, depth=0, include_location=True)\n            symbols = result[\"symbols\"]\n            if not symbols:\n                raise ValueError(f\"No symbol with name {name_path} found in file {relative_file_path}\")\n            if len(symbols) > 1:\n                raise ValueError(\n                    f\"Found multiple {len(symbols)} symbols with name {name_path} in file {relative_file_path}: \"\n                    + json.dumps(symbols, indent=2)\n                )\n            return JetBrainsSymbol(symbols[0], self._project)\n\n    def rename_symbol(self, name_path: str, relative_file_path: str, new_name: str) -> str:\n        with JetBrainsPluginClient.from_project(self._project) as client:\n            client.rename_symbol(\n                name_path=name_path,\n                relative_path=relative_file_path,\n                new_name=new_name,\n                rename_in_comments=False,\n                rename_in_text_occurrences=False,\n            )\n            return \"Success\"\n"
  },
  {
    "path": "src/serena/config/__init__.py",
    "content": ""
  },
  {
    "path": "src/serena/config/context_mode.py",
    "content": "\"\"\"\nContext and Mode configuration loader\n\"\"\"\n\nimport os\nfrom dataclasses import dataclass, field\nfrom pathlib import Path\nfrom typing import TYPE_CHECKING, Self\n\nimport yaml\nfrom sensai.util import logging\nfrom sensai.util.string import ToStringMixin\n\nfrom serena.config.serena_config import SerenaPaths, ToolInclusionDefinition\nfrom serena.constants import (\n    DEFAULT_CONTEXT,\n    INTERNAL_MODE_YAMLS_DIR,\n    SERENA_FILE_ENCODING,\n    SERENAS_OWN_CONTEXT_YAMLS_DIR,\n    SERENAS_OWN_MODE_YAMLS_DIR,\n)\n\nif TYPE_CHECKING:\n    pass\n\nlog = logging.getLogger(__name__)\n\n\n@dataclass(kw_only=True)\nclass SerenaAgentMode(ToolInclusionDefinition, ToStringMixin):\n    \"\"\"Represents a mode of operation for the agent, typically read off a YAML file.\n    An agent can be in multiple modes simultaneously as long as they are not mutually exclusive.\n    The modes can be adjusted after the agent is running, for example for switching from planning to editing.\n    \"\"\"\n\n    name: str\n    prompt: str\n    \"\"\"\n    a Jinja2 template for the generation of the system prompt.\n    It is formatted by the agent (see SerenaAgent._format_prompt()).\n    \"\"\"\n    description: str = \"\"\n    _yaml_path: Path | None = field(default=None, repr=False, compare=False)\n    \"\"\"\n    Internal field storing the path to the YAML file this mode was loaded from.\n    Used to support loading modes from arbitrary file paths.\n    \"\"\"\n\n    def _tostring_includes(self) -> list[str]:\n        return [\"name\"]\n\n    def print_overview(self) -> None:\n        \"\"\"Print an overview of the mode.\"\"\"\n        print(f\"{self.name}:\\n {self.description}\")\n        if self.excluded_tools:\n            print(\" excluded tools:\\n  \" + \", \".join(sorted(self.excluded_tools)))\n\n    @classmethod\n    def from_yaml(cls, yaml_path: str | Path) -> Self:\n        \"\"\"Load a mode from a YAML file.\"\"\"\n        yaml_as_path = Path(yaml_path).resolve()\n        with Path(yaml_as_path).open(encoding=SERENA_FILE_ENCODING) as f:\n            data = yaml.safe_load(f)\n        name = data.pop(\"name\", yaml_as_path.stem)\n        return cls(name=name, _yaml_path=yaml_as_path, **data)\n\n    @classmethod\n    def get_path(cls, name: str, instance: Self | None = None) -> str:\n        \"\"\"Get the path to the YAML file for a mode.\n\n        :param name: The name of the mode\n        :param instance: Optional mode instance. If provided and it has a stored path, that path is returned.\n        :return: The path to the mode's YAML file\n        \"\"\"\n        # If we have an instance with a stored path, use that\n        if instance is not None and instance._yaml_path is not None:\n            return str(instance._yaml_path)\n\n        fname = f\"{name}.yml\"\n        custom_mode_path = os.path.join(SerenaPaths().user_modes_dir, fname)\n        if os.path.exists(custom_mode_path):\n            return custom_mode_path\n\n        own_yaml_path = os.path.join(SERENAS_OWN_MODE_YAMLS_DIR, fname)\n        if not os.path.exists(own_yaml_path):\n            raise FileNotFoundError(\n                f\"Mode {name} not found in {SerenaPaths().user_modes_dir} or in {SERENAS_OWN_MODE_YAMLS_DIR}.\"\n                f\"Available modes:\\n{cls.list_registered_mode_names()}\"\n            )\n        return own_yaml_path\n\n    @classmethod\n    def from_name(cls, name: str) -> Self:\n        \"\"\"Load a registered Serena mode.\"\"\"\n        mode_path = cls.get_path(name)\n        return cls.from_yaml(mode_path)\n\n    @classmethod\n    def from_name_internal(cls, name: str) -> Self:\n        \"\"\"Loads an internal Serena mode\"\"\"\n        yaml_path = os.path.join(INTERNAL_MODE_YAMLS_DIR, f\"{name}.yml\")\n        if not os.path.exists(yaml_path):\n            raise FileNotFoundError(f\"Internal mode '{name}' not found in {INTERNAL_MODE_YAMLS_DIR}\")\n        return cls.from_yaml(yaml_path)\n\n    @classmethod\n    def list_registered_mode_names(cls, include_user_modes: bool = True) -> list[str]:\n        \"\"\"Names of all registered modes (from the corresponding YAML files in the serena repo).\"\"\"\n        modes = [f.stem for f in Path(SERENAS_OWN_MODE_YAMLS_DIR).glob(\"*.yml\") if f.name != \"mode.template.yml\"]\n        if include_user_modes:\n            modes += cls.list_custom_mode_names()\n        return sorted(set(modes))\n\n    @classmethod\n    def list_custom_mode_names(cls) -> list[str]:\n        \"\"\"Names of all custom modes defined by the user.\"\"\"\n        return [f.stem for f in Path(SerenaPaths().user_modes_dir).glob(\"*.yml\")]\n\n    @classmethod\n    def load(cls, name_or_path: str | Path) -> Self:\n        # Check if it's a file path that exists\n        path = Path(name_or_path)\n        if path.exists() and path.is_file():\n            return cls.from_yaml(name_or_path)\n\n        # If it looks like a file path but doesn't exist, raise FileNotFoundError\n        name_or_path_str = str(name_or_path)\n        if os.sep in name_or_path_str or (os.altsep and os.altsep in name_or_path_str) or name_or_path_str.endswith((\".yml\", \".yaml\")):\n            raise FileNotFoundError(f\"Mode file not found: {path.resolve()}\")\n\n        return cls.from_name(str(name_or_path))\n\n\n@dataclass(kw_only=True)\nclass SerenaAgentContext(ToolInclusionDefinition, ToStringMixin):\n    \"\"\"Represents a context where the agent is operating (an IDE, a chat, etc.), typically read off a YAML file.\n    An agent can only be in a single context at a time.\n    The contexts cannot be changed after the agent is running.\n    \"\"\"\n\n    name: str\n    \"\"\"the name of the context\"\"\"\n\n    prompt: str\n    \"\"\"\n    a Jinja2 template for the generation of the system prompt.\n    It is formatted by the agent (see SerenaAgent._format_prompt()).\n    \"\"\"\n\n    description: str = \"\"\n\n    tool_description_overrides: dict[str, str] = field(default_factory=dict)\n    \"\"\"\n    maps tool names to custom descriptions, default descriptions are extracted from the tool docstrings.\n    \"\"\"\n\n    _yaml_path: Path | None = field(default=None, repr=False, compare=False)\n    \"\"\"\n    Internal field storing the path to the YAML file this context was loaded from.\n    Used to support loading contexts from arbitrary file paths.\n    \"\"\"\n\n    single_project: bool = False\n    \"\"\"\n    whether to assume that Serena shall only work on a single project in this context (provided that a project is given\n    when Serena is started).\n    If set to true and a project is provided at startup, the set of tools is limited to those required by the project's\n    concrete configuration, and other tools are excluded completely, allowing the set of tools to be minimal.\n    The `activate_project` tool will, therefore, be disabled in this case, as project switching is not allowed.\n    \"\"\"\n\n    def _tostring_includes(self) -> list[str]:\n        return [\"name\"]\n\n    @classmethod\n    def from_yaml(cls, yaml_path: str | Path) -> Self:\n        \"\"\"Load a context from a YAML file.\"\"\"\n        yaml_as_path = Path(yaml_path).resolve()\n        with yaml_as_path.open(encoding=SERENA_FILE_ENCODING) as f:\n            data = yaml.safe_load(f)\n        name = data.pop(\"name\", yaml_as_path.stem)\n        # Ensure backwards compatibility for tool_description_overrides\n        if \"tool_description_overrides\" not in data:\n            data[\"tool_description_overrides\"] = {}\n        return cls(name=name, _yaml_path=yaml_as_path, **data)\n\n    @classmethod\n    def get_path(cls, name: str, instance: Self | None = None) -> str:\n        \"\"\"Get the path to the YAML file for a context.\n\n        :param name: The name of the context\n        :param instance: Optional context instance. If provided and it has a stored path, that path is returned.\n        :return: The path to the context's YAML file\n        \"\"\"\n        # If we have an instance with a stored path, use that\n        if instance is not None and instance._yaml_path is not None:\n            return str(instance._yaml_path)\n\n        fname = f\"{name}.yml\"\n        custom_context_path = os.path.join(SerenaPaths().user_contexts_dir, fname)\n        if os.path.exists(custom_context_path):\n            return custom_context_path\n\n        own_yaml_path = os.path.join(SERENAS_OWN_CONTEXT_YAMLS_DIR, fname)\n        if not os.path.exists(own_yaml_path):\n            raise FileNotFoundError(\n                f\"Context {name} not found in {SerenaPaths().user_contexts_dir} or in {SERENAS_OWN_CONTEXT_YAMLS_DIR}.\"\n                f\"Available contexts:\\n{cls.list_registered_context_names()}\"\n            )\n        return own_yaml_path\n\n    @classmethod\n    def from_name(cls, name: str) -> Self:\n        \"\"\"Load a registered Serena context.\"\"\"\n        legacy_name_mapping = {\n            \"ide-assistant\": \"claude-code\",\n        }\n        if name in legacy_name_mapping:\n            log.warning(\n                f\"Context name '{name}' is deprecated and has been renamed to '{legacy_name_mapping[name]}'. \"\n                f\"Please update your configuration; refer to the configuration guide for more details: \"\n                \"https://oraios.github.io/serena/02-usage/050_configuration.html#contexts\"\n            )\n            name = legacy_name_mapping[name]\n        context_path = cls.get_path(name)\n        return cls.from_yaml(context_path)\n\n    @classmethod\n    def load(cls, name_or_path: str | Path) -> Self:\n        # Check if it's a file path that exists\n        path = Path(name_or_path)\n        if path.exists() and path.is_file():\n            return cls.from_yaml(name_or_path)\n\n        # If it looks like a file path but doesn't exist, raise FileNotFoundError\n        name_or_path_str = str(name_or_path)\n        if os.sep in name_or_path_str or (os.altsep and os.altsep in name_or_path_str) or name_or_path_str.endswith((\".yml\", \".yaml\")):\n            raise FileNotFoundError(f\"Context file not found: {path.resolve()}\")\n\n        return cls.from_name(str(name_or_path))\n\n    @classmethod\n    def list_registered_context_names(cls, include_user_contexts: bool = True) -> list[str]:\n        \"\"\"Names of all registered contexts (from the corresponding YAML files in the serena repo).\"\"\"\n        contexts = [f.stem for f in Path(SERENAS_OWN_CONTEXT_YAMLS_DIR).glob(\"*.yml\")]\n        if include_user_contexts:\n            contexts += cls.list_custom_context_names()\n        return sorted(set(contexts))\n\n    @classmethod\n    def list_custom_context_names(cls) -> list[str]:\n        \"\"\"Names of all custom contexts defined by the user.\"\"\"\n        return [f.stem for f in Path(SerenaPaths().user_contexts_dir).glob(\"*.yml\")]\n\n    @classmethod\n    def load_default(cls) -> Self:\n        \"\"\"Load the default context.\"\"\"\n        return cls.from_name(DEFAULT_CONTEXT)\n\n    def print_overview(self) -> None:\n        \"\"\"Print an overview of the mode.\"\"\"\n        print(f\"{self.name}:\\n {self.description}\")\n        if self.excluded_tools:\n            print(\" excluded tools:\\n  \" + \", \".join(sorted(self.excluded_tools)))\n"
  },
  {
    "path": "src/serena/config/serena_config.py",
    "content": "\"\"\"\nThe Serena Model Context Protocol (MCP) Server\n\"\"\"\n\nimport dataclasses\nimport os\nimport re\nimport shutil\nfrom collections.abc import Iterator, Sequence\nfrom copy import deepcopy\nfrom dataclasses import dataclass, field\nfrom datetime import UTC, datetime\nfrom enum import Enum\nfrom functools import cached_property\nfrom pathlib import Path\nfrom typing import TYPE_CHECKING, Any, Optional, Self, TypeVar\n\nimport yaml\nfrom ruamel.yaml.comments import CommentedMap\nfrom sensai.util import logging\nfrom sensai.util.logging import LogTime, datetime_tag\nfrom sensai.util.string import ToStringMixin\n\nfrom serena.constants import (\n    DEFAULT_SOURCE_FILE_ENCODING,\n    PROJECT_LOCAL_TEMPLATE_FILE,\n    PROJECT_TEMPLATE_FILE,\n    REPO_ROOT,\n    SERENA_CONFIG_TEMPLATE_FILE,\n    SERENA_FILE_ENCODING,\n    SERENA_MANAGED_DIR_NAME,\n)\nfrom serena.util.inspection import determine_programming_language_composition\nfrom serena.util.yaml import YamlCommentNormalisation, load_yaml, normalise_yaml_comments, save_yaml, transfer_missing_yaml_comments\nfrom solidlsp.ls_config import Language\n\nfrom ..analytics import RegisteredTokenCountEstimator\nfrom ..util.class_decorators import singleton\nfrom ..util.cli_util import ask_yes_no\nfrom ..util.dataclass import get_dataclass_default\n\nif TYPE_CHECKING:\n    from ..project import Project\n\nlog = logging.getLogger(__name__)\nT = TypeVar(\"T\")\nDEFAULT_TOOL_TIMEOUT: float = 240\nDictType = dict | CommentedMap\nTDict = TypeVar(\"TDict\", bound=DictType)\n\n\n@singleton\nclass SerenaPaths:\n    \"\"\"\n    Provides paths to various Serena-related directories and files.\n    \"\"\"\n\n    def __init__(self) -> None:\n        home_dir = os.getenv(\"SERENA_HOME\")\n        if home_dir is None or home_dir.strip() == \"\":\n            home_dir = str(Path.home() / SERENA_MANAGED_DIR_NAME)\n        else:\n            home_dir = home_dir.strip()\n        self.serena_user_home_dir: str = home_dir\n        \"\"\"\n        the path to the Serena home directory, where the user's configuration/data is stored.\n        This is ~/.serena by default, but it can be overridden via the SERENA_HOME environment variable.\n        \"\"\"\n        self.user_prompt_templates_dir: str = os.path.join(self.serena_user_home_dir, \"prompt_templates\")\n        \"\"\"\n        directory containing prompt templates defined by the user.\n        Prompts defined by the user take precedence over Serena's built-in prompt templates.\n        \"\"\"\n        self.user_contexts_dir: str = os.path.join(self.serena_user_home_dir, \"contexts\")\n        \"\"\"\n        directory containing contexts defined by the user. \n        If a name of a context matches a name of a context in SERENAS_OWN_CONTEXT_YAMLS_DIR, \n        the user context will override the default context definition.\n        \"\"\"\n        self.user_modes_dir: str = os.path.join(self.serena_user_home_dir, \"modes\")\n        \"\"\"\n        directory containing modes defined by the user.\n        If a name of a mode matches a name of a mode in SERENAS_OWN_MODES_YAML_DIR,\n        the user mode will override the default mode definition.\n        \"\"\"\n        self.news_snippet_id_file: str = os.path.join(self.serena_user_home_dir, \"last_read_news_snippet_id.txt\")\n        \"\"\"\n        file containing the ID of the last read news snippet\n        \"\"\"\n        global_memories_path = Path(os.path.join(self.serena_user_home_dir, \"memories\", \"global\"))\n        global_memories_path.mkdir(parents=True, exist_ok=True)\n        self.global_memories_path = global_memories_path\n        \"\"\"\n        directory where global memories are stored, i.e. memories that are available across all projects\n        \"\"\"\n        self.last_returned_log_file_path: str | None = None\n        \"\"\"\n        the path to the last log file returned by `get_next_log_file_path`. If this is not None, the logs\n        are currently being written to this file\n        \"\"\"\n\n    def get_next_log_file_path(self, prefix: str) -> str:\n        \"\"\"\n        :param prefix: the filename prefix indicating the type of the log file\n        :return: the full path to the log file to use\n        \"\"\"\n        log_dir = os.path.join(self.serena_user_home_dir, \"logs\", datetime.now().strftime(\"%Y-%m-%d\"))\n        os.makedirs(log_dir, exist_ok=True)\n        self.last_returned_log_file_path = os.path.join(log_dir, prefix + \"_\" + datetime_tag() + f\"_{os.getpid()}\" + \".txt\")\n        return self.last_returned_log_file_path\n\n    # TODO: Paths from constants.py should be moved here\n\n\n@dataclass\nclass ToolInclusionDefinition:\n    \"\"\"\n    Defines which tools to include/exclude in Serena's operation.\n    This can mean either\n      * defining exclusions/inclusions to apply to an existing set of tools [incremental mode], or\n      * defining a fixed set of tools to use [fixed mode].\n    \"\"\"\n\n    excluded_tools: Sequence[str] = ()\n    \"\"\"\n    the names of tools to exclude from use [incremental mode]\n    \"\"\"\n    included_optional_tools: Sequence[str] = ()\n    \"\"\"\n    the names of optional tools to include [incremental mode]\n    \"\"\"\n    fixed_tools: Sequence[str] = ()\n    \"\"\"\n    the names of tools to use as a fixed set of tools [fixed mode]\n    \"\"\"\n\n    def is_fixed_tool_set(self) -> bool:\n        num_fixed = len(self.fixed_tools)\n        num_incremental = len(self.excluded_tools) + len(self.included_optional_tools)\n        if num_fixed > 0 and num_incremental > 0:\n            raise ValueError(\"Cannot use both fixed_tools and excluded_tools/included_optional_tools at the same time.\")\n        return num_fixed > 0\n\n\n@dataclass\nclass NamedToolInclusionDefinition(ToolInclusionDefinition):\n    name: str | None = None\n\n    def __str__(self) -> str:\n        return f\"ToolInclusionDefinition[{self.name}]\"\n\n\n@dataclass\nclass ModeSelectionDefinition:\n    base_modes: Sequence[str] | None = None\n    default_modes: Sequence[str] | None = None\n\n\nclass LanguageBackend(Enum):\n    LSP = \"LSP\"\n    \"\"\"\n    Use the language server protocol (LSP), spawning freely available language servers\n    via the SolidLSP library that is part of Serena\n    \"\"\"\n    JETBRAINS = \"JetBrains\"\n    \"\"\"\n    Use the Serena plugin in your JetBrains IDE.\n    (requires the plugin to be installed and the project being worked on to be open in your IDE)\n    \"\"\"\n\n    @staticmethod\n    def from_str(backend_str: str) -> \"LanguageBackend\":\n        for backend in LanguageBackend:\n            if backend.value.lower() == backend_str.lower():\n                return backend\n        raise ValueError(f\"Unknown language backend '{backend_str}': valid values are {[b.value for b in LanguageBackend]}\")\n\n    def is_lsp(self) -> bool:\n        return self == LanguageBackend.LSP\n\n    def is_jetbrains(self) -> bool:\n        return self == LanguageBackend.JETBRAINS\n\n\nclass LineEnding(Enum):\n    \"\"\"Line ending convention for file writes.\"\"\"\n\n    LF = \"lf\"\n    CRLF = \"crlf\"\n    NATIVE = \"native\"\n\n    @property\n    def newline_str(self) -> str | None:\n        \"\"\"The newline parameter value for :func:`open` and :meth:`Path.write_text`.\n\n        Returns ``None`` for native mode (platform default).\n        \"\"\"\n        if self is LineEnding.LF:\n            return \"\\n\"\n        elif self is LineEnding.CRLF:\n            return \"\\r\\n\"\n        return None\n\n    @classmethod\n    def from_str(cls, value: str) -> \"LineEnding\":\n        \"\"\"Parse a string value into a :class:`LineEnding`.\"\"\"\n        try:\n            return cls(value.lower())\n        except ValueError as e:\n            valid = [le.value for le in cls]\n            raise ValueError(f\"Invalid line_ending: {value!r}. Valid values are: {valid}\") from e\n\n\n@dataclass\nclass SharedConfig(ModeSelectionDefinition, ToolInclusionDefinition, ToStringMixin):\n    \"\"\"Shared between SerenaConfig and ProjectConfig, the latter used to override values in the form\n    (same as in ModeSelectionDefinition).\n    The defaults here shall be none and should be set to the global default values in SerenaConfig.\n    \"\"\"\n\n    symbol_info_budget: float | None = None\n    language_backend: LanguageBackend | None = None\n    line_ending: LineEnding | None = None\n    read_only_memory_patterns: list[str] = field(default_factory=list)\n\n\nclass SerenaConfigError(Exception):\n    pass\n\n\nDEFAULT_PROJECT_SERENA_FOLDER_LOCATION = \"$projectDir/\" + SERENA_MANAGED_DIR_NAME\n\"\"\"\nThe default template for the project Serena folder location.\nUses $projectDir and $projectFolderName as placeholders.\n\"\"\"\n\n\n@dataclass(kw_only=True)\nclass ProjectConfig(SharedConfig):\n    project_name: str\n    languages: list[Language]\n    ignored_paths: list[str] = field(default_factory=list)\n    read_only: bool = False\n    ignore_all_files_in_gitignore: bool = True\n    initial_prompt: str = \"\"\n    encoding: str = DEFAULT_SOURCE_FILE_ENCODING\n\n    # internal fields which are not mapped to/from the configuration file (must start with \"_\")\n    _local_override_keys: list[str] = field(default_factory=list)\n\n    # class-level constants\n    SERENA_PROJECT_FILE = \"project.yml\"\n    SERENA_LOCAL_PROJECT_FILE = \"project.local.yml\"\n    FIELDS_WITHOUT_DEFAULTS = {\"project_name\", \"languages\"}\n    YAML_COMMENT_NORMALISATION = YamlCommentNormalisation.LEADING\n    \"\"\"\n    the comment normalisation strategy to use when loading/saving project configuration files.\n    The template file must match this configuration (i.e. it must use leading comments if this is set to LEADING).\n    \"\"\"\n\n    def _tostring_includes(self) -> list[str]:\n        return [\"project_name\"]\n\n    @classmethod\n    def autogenerate(\n        cls,\n        project_root: str | Path,\n        serena_config: \"SerenaConfig\",\n        project_name: str | None = None,\n        languages: list[Language] | None = None,\n        save_to_disk: bool = True,\n        interactive: bool = False,\n    ) -> Self:\n        \"\"\"\n        Autogenerate a project configuration for a given project root.\n\n        :param project_root: the path to the project root\n        :param serena_config: the global Serena configuration\n        :param project_name: the name of the project; if None, the name of the project will be the name of the directory\n            containing the project\n        :param languages: the languages of the project; if None, they will be determined automatically\n        :param save_to_disk: whether to save the project configuration to disk\n        :param interactive: whether to run in interactive CLI mode, asking the user for input where appropriate\n        :return: the project configuration\n        \"\"\"\n        project_root = Path(project_root).resolve()\n        if not project_root.exists():\n            raise FileNotFoundError(f\"Project root not found: {project_root}\")\n        with LogTime(\"Project configuration auto-generation\", logger=log):\n            log.info(\"Project root: %s\", project_root)\n            project_folder_name = project_root.name\n            project_name = project_name or project_folder_name\n            if languages is None:\n                # determine languages automatically\n                log.info(\"Determining programming languages used in the project\")\n                language_composition = determine_programming_language_composition(str(project_root))\n                log.info(\"Language composition: %s\", language_composition)\n                if len(language_composition) == 0:\n                    log.warning(\n                        \"No source files for supported language servers were found in %s. \"\n                        \"Creating project with no configured languages. \"\n                        \"Symbol-related tools (e.g. find_symbol, get_symbols_overview) will not work \"\n                        \"when using the LSP backend. You can add languages later via the Serena dashboard \"\n                        \"or by manually editing the project configuration.\",\n                        project_root,\n                    )\n                    languages_to_use: list[str] = []\n                else:\n                    # sort languages by number of files found\n                    languages_and_percentages = sorted(\n                        language_composition.items(), key=lambda item: (item[1], item[0].get_priority()), reverse=True\n                    )\n                    # find the language with the highest percentage and enable it\n                    top_language_pair = languages_and_percentages[0]\n                    other_language_pairs = languages_and_percentages[1:]\n                    languages_to_use = [top_language_pair[0].value]\n                    # if in interactive mode, ask the user which other languages to enable\n                    if len(other_language_pairs) > 0 and interactive:\n                        print(\n                            \"Detected and enabled main language '%s' (%.2f%% of source files).\"\n                            % (top_language_pair[0].value, top_language_pair[1])\n                        )\n                        print(f\"Additionally detected {len(other_language_pairs)} other language(s).\\n\")\n                        print(\"Note: Enable only languages you need symbolic retrieval/editing capabilities for.\")\n                        print(\"      Additional language servers use resources and some languages may require additional\")\n                        print(\"      system-level installations/configuration (see Serena documentation).\")\n                        print(\"\\nWhich additional languages do you want to enable?\")\n                        for lang, perc in other_language_pairs:\n                            enable = ask_yes_no(\"Enable %s (%.2f%% of source files)?\" % (lang.value, perc), default=False)\n                            if enable:\n                                languages_to_use.append(lang.value)\n                        print()\n                log.info(\"Using languages: %s\", languages_to_use)\n            else:\n                languages_to_use = [lang.value for lang in languages]\n            config_with_comments, _ = cls._load_yaml_dict(PROJECT_TEMPLATE_FILE)\n            config_with_comments[\"project_name\"] = project_name\n            config_with_comments[\"languages\"] = languages_to_use\n\n            if save_to_disk:\n                project_yml_path = serena_config.get_project_yml_location(str(project_root))\n                log.info(\"Saving project configuration to %s\", project_yml_path)\n                save_yaml(project_yml_path, config_with_comments)\n                project_local_yml_path = os.path.join(os.path.dirname(project_yml_path), cls.SERENA_LOCAL_PROJECT_FILE)\n                shutil.copy(PROJECT_LOCAL_TEMPLATE_FILE, project_local_yml_path)\n\n            return cls._from_dict(config_with_comments, local_override_keys=[])\n\n    @classmethod\n    def default_project_yml_path(cls, project_root: str | Path) -> str:\n        \"\"\"\n        :return: the default path to the project.yml file (inside ``$projectDir/.serena/``).\n            This is suitable as a fallback when no ``SerenaConfig`` is available to resolve\n            a potentially customised location.\n        \"\"\"\n        return os.path.join(str(project_root), SERENA_MANAGED_DIR_NAME, cls.SERENA_PROJECT_FILE)\n\n    @classmethod\n    def _load_yaml_dict(\n        cls,\n        yml_path: str,\n        comment_normalisation: YamlCommentNormalisation = YamlCommentNormalisation.NONE,\n        apply_defaults: bool = True,\n    ) -> tuple[CommentedMap, bool]:\n        \"\"\"\n        Load the project configuration as a CommentedMap, preserving comments and ensuring\n        completeness of the configuration by applying default values for missing fields\n        and backward compatibility adjustments.\n\n        :param yml_path: the path to the project.yml file\n        :param comment_normalisation: the strategy to use for normalising comments in the loaded YAML\n        :param apply_defaults: whether to apply default values for missing fields\n        :return: a tuple `(dict, was_complete)` where dict is a CommentedMap representing a\n          full project configuration and `was_complete` indicates whether the loaded configuration\n          was complete (i.e., did not require any default values to be applied) for the case where\n          `apply_defaults` is True; If `apply_defaults` is False, the returned dict may be incomplete\n          and `was_complete` will always be True.\n        \"\"\"\n        data = load_yaml(yml_path, comment_normalisation=comment_normalisation)\n\n        # apply defaults\n        was_complete = True\n        if apply_defaults:\n            for field_info in dataclasses.fields(cls):\n                key = field_info.name\n                if key.startswith(\"_\"):\n                    continue\n                if key in cls.FIELDS_WITHOUT_DEFAULTS:\n                    continue\n                if key not in data:\n                    was_complete = False\n                    default_value = get_dataclass_default(cls, key)\n                    data.setdefault(key, default_value)\n\n        # backward compatibility\n        # NOTE: This must also work for project.local.yml files, which may be highly incomplete\n        # * handle single \"language\" field\n        if \"languages\" not in data and \"language\" in data:\n            data[\"languages\"] = [data[\"language\"]]\n            del data[\"language\"]\n\n        return data, was_complete\n\n    @classmethod\n    def _from_dict(cls, data: dict[str, Any], local_override_keys: list[str]) -> Self:\n        \"\"\"\n        Create a ProjectConfig instance from a (full) configuration dictionary\n\n        :param data: the configuration dictionary; must contain all required fields and use the same field names as\n            the ProjectConfig dataclass\n        :param local_override_keys: the list of keys that have been overridden from project.local.yml\n        \"\"\"\n        lang_name_mapping = {\"javascript\": \"typescript\"}\n        languages: list[Language] = []\n        for language_str in data[\"languages\"]:\n            orig_language_str = language_str\n            try:\n                language_str = language_str.lower()\n                if language_str in lang_name_mapping:\n                    language_str = lang_name_mapping[language_str]\n                language = Language(language_str)\n                languages.append(language)\n            except ValueError as e:\n                raise ValueError(\n                    f\"Invalid language: {orig_language_str}.\\nValid language_strings are: {[l.value for l in Language]}\"\n                ) from e\n\n        # Validate symbol_info_budget\n        symbol_info_budget_raw = data[\"symbol_info_budget\"]\n        symbol_info_budget = symbol_info_budget_raw\n        if symbol_info_budget is not None:\n            try:\n                symbol_info_budget = float(symbol_info_budget_raw)\n            except (TypeError, ValueError) as e:\n                raise ValueError(f\"symbol_info_budget must be a number or null, got: {symbol_info_budget_raw}\") from e\n            if symbol_info_budget < 0:\n                raise ValueError(f\"symbol_info_budget cannot be negative, got: {symbol_info_budget}\")\n\n        language_backend_value = data.get(\"language_backend\")\n        language_backend = LanguageBackend.from_str(language_backend_value) if language_backend_value else None\n\n        line_ending_value = data.get(\"line_ending\")\n        line_ending = LineEnding.from_str(line_ending_value) if line_ending_value else None\n\n        return cls(\n            project_name=data[\"project_name\"],\n            languages=languages,\n            ignored_paths=data[\"ignored_paths\"],\n            excluded_tools=data[\"excluded_tools\"],\n            fixed_tools=data[\"fixed_tools\"],\n            included_optional_tools=data[\"included_optional_tools\"],\n            read_only=data[\"read_only\"],\n            read_only_memory_patterns=data.get(\"read_only_memory_patterns\", []),\n            ignore_all_files_in_gitignore=data[\"ignore_all_files_in_gitignore\"],\n            initial_prompt=data[\"initial_prompt\"],\n            encoding=data[\"encoding\"],\n            line_ending=line_ending,\n            language_backend=language_backend,\n            base_modes=data[\"base_modes\"],\n            default_modes=data[\"default_modes\"],\n            symbol_info_budget=symbol_info_budget,\n            _local_override_keys=local_override_keys,\n        )\n\n    def _to_yaml_dict(self) -> dict:\n        \"\"\"\n        :return: a yaml-serializable dictionary representation of this configuration\n        \"\"\"\n        d = dataclasses.asdict(self)\n\n        # drop internal fields starting with underscore\n        keys = list(d.keys())\n        for k in keys:\n            if k.startswith(\"_\"):\n                del d[k]\n\n        # map fields using non-primitive types to a YAML-compatible representation\n        d[\"languages\"] = [lang.value for lang in self.languages]\n        d[\"language_backend\"] = self.language_backend.value if self.language_backend is not None else None\n        d[\"line_ending\"] = self.line_ending.value if self.line_ending is not None else None\n\n        return d\n\n    @classmethod\n    def _project_local_yml_path(cls, project_yml_path: str) -> str:\n        return os.path.join(os.path.dirname(project_yml_path), cls.SERENA_LOCAL_PROJECT_FILE)\n\n    @classmethod\n    def load(cls, project_root: Path | str, serena_config: \"SerenaConfig\", autogenerate: bool = False) -> Self:\n        \"\"\"\n        Load a ProjectConfig instance from the path to the project root.\n\n        :param project_root: the path to the project root\n        :param serena_config: the global Serena configuration\n        :param autogenerate: whether to auto-generate the configuration if it does not exist\n        \"\"\"\n        project_root = Path(project_root)\n        project_folder_name = project_root.name\n        yaml_path = serena_config.get_project_yml_location(project_root)\n        log.debug(\"Loading project configuration from %s\", yaml_path)\n\n        # auto-generate if necessary\n        if not os.path.exists(yaml_path):\n            if autogenerate:\n                return cls.autogenerate(project_root, serena_config)\n            else:\n                raise FileNotFoundError(f\"Project configuration file not found: {yaml_path}\")\n\n        # load the configuration dictionary\n        yaml_data, was_complete = cls._load_yaml_dict(str(yaml_path))\n        if \"project_name\" not in yaml_data:\n            yaml_data[\"project_name\"] = project_folder_name\n\n        # apply overrides from project.local.yml, if present\n        local_yaml_path = cls._project_local_yml_path(str(yaml_path))\n        local_override_keys = []\n        if os.path.exists(local_yaml_path):\n            local_yaml_data, _ = cls._load_yaml_dict(local_yaml_path, apply_defaults=False)\n            if local_yaml_data:\n                local_override_keys = list(local_yaml_data.keys())\n                log.debug(\n                    \"Applying project configuration overrides from %s with keys %s\",\n                    local_yaml_path,\n                    local_override_keys,\n                )\n                yaml_data.update(local_yaml_data)\n\n        # instantiate the ProjectConfig\n        project_config = cls._from_dict(yaml_data, local_override_keys=local_override_keys)\n\n        # if the configuration was incomplete, re-save it to disk\n        if not was_complete:\n            log.info(\"Project configuration in %s was incomplete, re-saving with default values for missing fields\", yaml_path)\n            project_config.save(str(yaml_path), save_project_local_yml=False)\n\n        return project_config\n\n    def save(self, project_yml_path: str, save_project_local_yml: bool = True) -> None:\n        \"\"\"\n        Saves the project configuration to disk, updating both the project.yml file and, optionally,\n        the project.local.yml file to reflect overridden keys.\n\n        Keys that are overridden by project.local.yml are not updated in project.yml.\n        Only keys that are overridden are updated in project.local.yml.\n\n        :param project_yml_path: the path to the project.yml file\n        :param save_project_local_yml: whether to also update the project.local.yml file to reflect overridden keys\n        \"\"\"\n        config_path = project_yml_path\n        log.info(\"Saving updated project configuration to %s\", config_path)\n\n        # get the current configuration as a dictionary\n        cur_dict = self._to_yaml_dict()\n\n        # load commented map from the original file and update all non-overridden keys\n        config_with_comments, _ = self._load_yaml_dict(config_path, self.YAML_COMMENT_NORMALISATION)\n        for key in cur_dict:\n            if key not in self._local_override_keys:\n                config_with_comments[key] = cur_dict[key]\n\n        # transfer missing comments from the template file\n        template_config, _ = self._load_yaml_dict(PROJECT_TEMPLATE_FILE, self.YAML_COMMENT_NORMALISATION)\n        transfer_missing_yaml_comments(template_config, config_with_comments, self.YAML_COMMENT_NORMALISATION)\n\n        # save project.yml\n        save_yaml(config_path, config_with_comments)\n\n        # update project.local.yml to reflect overridden keys if necessary\n        if save_project_local_yml:\n            project_local_yml_path = self._project_local_yml_path(project_yml_path)\n            if self._local_override_keys and os.path.exists(project_local_yml_path):\n                log.info(\"Saving updated local project configuration to %s\", project_local_yml_path)\n                local_config_with_comments, _ = self._load_yaml_dict(\n                    project_local_yml_path, comment_normalisation=YamlCommentNormalisation.NONE, apply_defaults=False\n                )\n                for key in self._local_override_keys:\n                    if key in cur_dict:\n                        local_config_with_comments[key] = cur_dict[key]\n                save_yaml(project_local_yml_path, local_config_with_comments)\n\n\nclass RegisteredProject(ToStringMixin):\n    def __init__(\n        self,\n        project_root: str,\n        project_config: \"ProjectConfig\",\n        project_instance: Optional[\"Project\"] = None,\n    ) -> None:\n        \"\"\"\n        Represents a registered project in the Serena configuration.\n\n        :param project_root: the root directory of the project\n        :param project_config: the configuration of the project\n        :param project_instance: an existing project instance (if already loaded)\n        \"\"\"\n        self.project_root = Path(project_root).resolve()\n        self.project_config = project_config\n        self._project_instance = project_instance\n\n    def _tostring_exclude_private(self) -> bool:\n        return True\n\n    @property\n    def project_name(self) -> str:\n        return self.project_config.project_name\n\n    @classmethod\n    def from_project_instance(cls, project_instance: \"Project\") -> \"RegisteredProject\":\n        return RegisteredProject(\n            project_root=project_instance.project_root,\n            project_config=project_instance.project_config,\n            project_instance=project_instance,\n        )\n\n    @classmethod\n    def from_project_root(cls, project_root: str | Path, serena_config: \"SerenaConfig\") -> \"RegisteredProject\":\n        project_config = ProjectConfig.load(project_root, serena_config=serena_config)\n        return RegisteredProject(\n            project_root=str(project_root),\n            project_config=project_config,\n        )\n\n    def matches_root_path(self, path: str | Path) -> bool:\n        \"\"\"\n        Check if the given path matches the project root path.\n\n        :param path: the path to check\n        :return: True if the path matches the project root, False otherwise\n        \"\"\"\n        return self.project_root.samefile(Path(path).resolve())\n\n    def get_project_instance(self, serena_config: \"SerenaConfig\") -> \"Project\":\n        \"\"\"\n        Returns the project instance for this registered project, loading it if necessary.\n        \"\"\"\n        if self._project_instance is None:\n            from ..project import Project\n\n            with LogTime(f\"Loading project instance for {self}\", logger=log):\n                self._project_instance = Project(\n                    project_root=str(self.project_root),\n                    project_config=self.project_config,\n                    serena_config=serena_config,\n                )\n        return self._project_instance\n\n\n@dataclass(kw_only=True)\nclass SerenaConfig(SharedConfig):\n    \"\"\"\n    Holds the Serena agent configuration, which is typically loaded from a YAML configuration file\n    (when instantiated via :method:`from_config_file`), which is updated when projects are added or removed.\n    For testing purposes, it can also be instantiated directly with the desired parameters.\n    \"\"\"\n\n    # *** fields that are mapped directly to/from the configuration file (DO NOT RENAME) ***\n\n    projects: list[RegisteredProject] = field(default_factory=list)\n    gui_log_window: bool = False\n    log_level: int = logging.INFO\n    trace_lsp_communication: bool = False\n    web_dashboard: bool = True\n    web_dashboard_open_on_launch: bool = True\n    web_dashboard_listen_address: str = \"127.0.0.1\"\n    jetbrains_plugin_server_address: str = \"127.0.0.1\"\n    tool_timeout: float = DEFAULT_TOOL_TIMEOUT\n\n    token_count_estimator: str = RegisteredTokenCountEstimator.CHAR_COUNT.name\n    \"\"\"Only relevant if `record_tool_usage` is True; the name of the token count estimator to use for tool usage statistics.\n    See the `RegisteredTokenCountEstimator` enum for available options.\n    \n    Note: some token estimators (like tiktoken) may require downloading data files\n    on the first run, which can take some time and require internet access. Others, like the Anthropic ones, may require an API key\n    and rate limits may apply.\n    \"\"\"\n    default_max_tool_answer_chars: int = 150_000\n    \"\"\"Used as default for tools where the apply method has a default maximal answer length.\n    Even though the value of the max_answer_chars can be changed when calling the tool, it may make sense to adjust this default \n    through the global configuration.\n    \"\"\"\n    ls_specific_settings: dict = field(default_factory=dict)\n    \"\"\"Advanced configuration option allowing to configure language server implementation specific options, see SolidLSPSettings for more info.\"\"\"\n\n    ignored_paths: list[str] = field(default_factory=list)\n    \"\"\"List of paths to ignore across all projects. Same syntax as gitignore, so you can use * and **.\n    These patterns are merged additively with each project's own ignored_paths.\"\"\"\n\n    project_serena_folder_location: str = DEFAULT_PROJECT_SERENA_FOLDER_LOCATION\n    \"\"\"\n    Template for the location of the per-project .serena data folder (memories, caches, etc.).\n    Supports the following placeholders:\n      - $projectDir: the absolute path to the project root directory\n      - $projectFolderName: the name of the project folder\n    Examples:\n      - \"$projectDir/.serena\" (default, stores data inside the project)\n      - \"/projects-metadata/$projectFolderName/.serena\" (stores data in a central location)\n    \"\"\"\n\n    # settings with overridden defaults\n    language_backend: LanguageBackend = LanguageBackend.LSP\n    \"\"\"\n    the language backend to use for code understanding features\n    \"\"\"\n    default_modes: Sequence[str] | None = (\"interactive\", \"editing\")\n    line_ending: LineEnding = LineEnding.NATIVE\n    symbol_info_budget: float = 10.0\n    \"\"\"\n    Time budget (seconds) for requests when tools request include_info (currently\n    only supported for LSP-based tools).\n\n    If the budget is exceeded, Serena stops issuing further requests and returns partial info results.\n    0 disables the budget (no early stopping). Negative values are invalid.\n    \"\"\"\n    # *** fields that are NOT mapped to/from the configuration file ***\n\n    _loaded_commented_yaml: CommentedMap | None = None\n    _config_file_path: str | None = None\n    \"\"\"\n    the path to the configuration file to which updates of the configuration shall be saved;\n    if None, the configuration is not saved to disk\n    \"\"\"\n\n    # *** static members ***\n\n    CONFIG_FILE = \"serena_config.yml\"\n    CONFIG_FIELDS_WITH_TYPE_CONVERSION = {\"projects\", \"language_backend\", \"line_ending\"}\n\n    # *** methods ***\n    @classmethod\n    def get_config_file_creation_date(cls) -> datetime | None:\n        \"\"\"\n        :return: the creation date of the configuration file, or None if the configuration file does not exist\n        \"\"\"\n        config_file_path = cls._determine_config_file_path()\n        if not os.path.exists(config_file_path):\n            return None\n\n        # for unix systems st_ctime is the inode change time (change of metadata),\n        # which is good enough for our purposes\n        creation_timestamp = os.stat(config_file_path).st_ctime\n        return datetime.fromtimestamp(creation_timestamp, UTC)\n\n    @property\n    def config_file_path(self) -> str | None:\n        return self._config_file_path\n\n    def _iter_config_file_mapped_fields_without_type_conversion(self) -> Iterator[str]:\n        for field_info in dataclasses.fields(self):\n            field_name = field_info.name\n            if field_name.startswith(\"_\"):\n                continue\n            if field_name in self.CONFIG_FIELDS_WITH_TYPE_CONVERSION:\n                continue\n            yield field_name\n\n    def _tostring_includes(self) -> list[str]:\n        return [\"config_file_path\"]\n\n    @classmethod\n    def _generate_config_file(cls, config_file_path: str) -> None:\n        \"\"\"\n        Generates a Serena configuration file at the specified path from the template file.\n\n        :param config_file_path: the path where the configuration file should be generated\n        \"\"\"\n        log.info(f\"Auto-generating Serena configuration file in {config_file_path}\")\n        loaded_commented_yaml = load_yaml(SERENA_CONFIG_TEMPLATE_FILE)\n        save_yaml(config_file_path, loaded_commented_yaml)\n\n    @classmethod\n    def _determine_config_file_path(cls) -> str:\n        \"\"\"\n        :return: the location where the Serena configuration file is stored/should be stored\n        \"\"\"\n        config_path = os.path.join(SerenaPaths().serena_user_home_dir, cls.CONFIG_FILE)\n\n        # if the config file does not exist, check if we can migrate it from the old location\n        if not os.path.exists(config_path):\n            old_config_path = os.path.join(REPO_ROOT, cls.CONFIG_FILE)\n            if os.path.exists(old_config_path):\n                log.info(f\"Moving Serena configuration file from {old_config_path} to {config_path}\")\n                os.makedirs(os.path.dirname(config_path), exist_ok=True)\n                shutil.move(old_config_path, config_path)\n\n        return config_path\n\n    @classmethod\n    def from_config_file(cls, generate_if_missing: bool = True) -> \"SerenaConfig\":\n        \"\"\"\n        Static constructor to create SerenaConfig from the configuration file\n        \"\"\"\n        config_file_path = cls._determine_config_file_path()\n\n        # create the configuration file from the template if necessary\n        if not os.path.exists(config_file_path):\n            if not generate_if_missing:\n                raise FileNotFoundError(f\"Serena configuration file not found: {config_file_path}\")\n            log.info(f\"Serena configuration file not found at {config_file_path}, autogenerating...\")\n            cls._generate_config_file(config_file_path)\n\n        # load the configuration\n        log.info(f\"Loading Serena configuration from {config_file_path}\")\n        try:\n            loaded_commented_yaml = load_yaml(config_file_path)\n        except Exception as e:\n            raise ValueError(f\"Error loading Serena configuration from {config_file_path}: {e}\") from e\n\n        # create the configuration instance\n        instance = cls(_loaded_commented_yaml=loaded_commented_yaml, _config_file_path=config_file_path)\n        num_migrations = 0\n\n        def get_value_or_default(field_name: str) -> Any:\n            nonlocal num_migrations\n            if field_name not in loaded_commented_yaml:\n                num_migrations += 1\n            return loaded_commented_yaml.get(field_name, get_dataclass_default(SerenaConfig, field_name))\n\n        # transfer regular fields that do not require type conversion\n        for field_name in instance._iter_config_file_mapped_fields_without_type_conversion():\n            assert hasattr(instance, field_name)\n            setattr(instance, field_name, get_value_or_default(field_name))\n\n        # read projects\n        if \"projects\" not in loaded_commented_yaml:\n            raise SerenaConfigError(\"`projects` key not found in Serena configuration. Please update your `serena_config.yml` file.\")\n        instance.projects = []\n        for path in loaded_commented_yaml[\"projects\"]:\n            path = Path(path).resolve()\n            try:\n                path_exists = path.exists()\n            except OSError as e:\n                log.warning(f\"Project path {path} is not accessible ({e}), skipping.\")\n                continue\n            if not path_exists or (path.is_dir() and not os.path.isfile(instance.get_project_yml_location(str(path)))):\n                log.warning(f\"Project path {path} does not exist or no associated project configuration file found, skipping.\")\n                continue\n            if path.is_file():\n                path = cls._migrate_out_of_project_config_file(path)\n                if path is None:\n                    continue\n                num_migrations += 1\n            project_config = ProjectConfig.load(path, serena_config=instance)  # instance is sufficiently populated\n            project = RegisteredProject(\n                project_root=str(path),\n                project_config=project_config,\n            )\n            instance.projects.append(project)\n\n        # determine language backend\n        language_backend = get_dataclass_default(SerenaConfig, \"language_backend\")\n        if \"language_backend\" in loaded_commented_yaml:\n            backend_str = loaded_commented_yaml[\"language_backend\"]\n            language_backend = LanguageBackend.from_str(backend_str)\n        else:\n            # backward compatibility (migrate Boolean field \"jetbrains\")\n            if \"jetbrains\" in loaded_commented_yaml:\n                num_migrations += 1\n                if loaded_commented_yaml[\"jetbrains\"]:\n                    language_backend = LanguageBackend.JETBRAINS\n                del loaded_commented_yaml[\"jetbrains\"]\n        instance.language_backend = language_backend\n\n        # determine line ending\n        line_ending_value = loaded_commented_yaml.get(\"line_ending\")\n        if line_ending_value:\n            instance.line_ending = LineEnding.from_str(line_ending_value)\n        else:\n            num_migrations += 1\n            instance.line_ending = get_dataclass_default(SerenaConfig, \"line_ending\")\n\n        # migrate deprecated \"gui_log_level\" field if necessary\n        if \"gui_log_level\" in loaded_commented_yaml:\n            num_migrations += 1\n            if \"log_level\" not in loaded_commented_yaml:\n                instance.log_level = loaded_commented_yaml[\"gui_log_level\"]\n            del loaded_commented_yaml[\"gui_log_level\"]\n\n        # migrate \"edit_global_memories\"\n        if \"edit_global_memories\" in loaded_commented_yaml:\n            num_migrations += 1\n            edit_global_memories = loaded_commented_yaml[\"edit_global_memories\"]\n            if not edit_global_memories:\n                instance.read_only_memory_patterns.append(\"global/.*\")\n            del loaded_commented_yaml[\"edit_global_memories\"]\n\n        # re-save the configuration file if any migrations were performed\n        if num_migrations > 0:\n            log.info(\"Legacy configuration was migrated; re-saving configuration file\")\n            instance.save()\n\n        return instance\n\n    @classmethod\n    def _migrate_out_of_project_config_file(cls, path: Path) -> Path | None:\n        \"\"\"\n        Migrates a legacy project configuration file (which is a YAML file containing the project root) to the\n        in-project configuration file (project.yml) inside the project root directory.\n\n        :param path: the path to the legacy project configuration file\n        :return: the project root path if the migration was successful, None otherwise.\n        \"\"\"\n        log.info(f\"Found legacy project configuration file {path}, migrating to in-project configuration.\")\n        try:\n            with open(path, encoding=SERENA_FILE_ENCODING) as f:\n                project_config_data = yaml.safe_load(f)\n            if \"project_name\" not in project_config_data:\n                project_name = path.stem\n                with open(path, \"a\", encoding=SERENA_FILE_ENCODING) as f:\n                    f.write(f\"\\nproject_name: {project_name}\")\n            project_root = project_config_data[\"project_root\"]\n            shutil.move(str(path), ProjectConfig.default_project_yml_path(project_root))\n            return Path(project_root).resolve()\n        except Exception as e:\n            log.error(f\"Error migrating configuration file: {e}\")\n            return None\n\n    @cached_property\n    def project_paths(self) -> list[str]:\n        return sorted(str(project.project_root) for project in self.projects)\n\n    @cached_property\n    def project_names(self) -> list[str]:\n        return sorted(project.project_config.project_name for project in self.projects)\n\n    def get_registered_project(self, project_root_or_name: str, autoregister: bool = False) -> Optional[RegisteredProject]:\n        \"\"\"\n        :param project_root_or_name: path to the project root or the name of the project\n        :param autoregister: whether to register the project if it exists but is not registered yet\n        :return: the registered project, or None if not found\n        \"\"\"\n        # look for project by name\n        project_candidates = []\n        for project in self.projects:\n            if project.project_config.project_name == project_root_or_name:\n                project_candidates.append(project)\n        if len(project_candidates) == 1:\n            return project_candidates[0]\n        elif len(project_candidates) > 1:\n            raise ValueError(\n                f\"Multiple projects found with name '{project_root_or_name}'. Please reference it by location instead. \"\n                f\"Locations: {[p.project_root for p in project_candidates]}\"\n            )\n        # no project found by name; check if it's a path\n        if os.path.isdir(project_root_or_name):\n            for project in self.projects:\n                if project.matches_root_path(project_root_or_name):\n                    return project\n        # no registered project found; auto-register if project configuration exists\n        if autoregister:\n            config_path = self.get_project_yml_location(project_root_or_name)\n            if os.path.isfile(config_path):\n                registered_project = RegisteredProject.from_project_root(project_root_or_name, serena_config=self)\n                self.add_registered_project(registered_project)\n                return registered_project\n        # nothing found\n        return None\n\n    def get_project(self, project_root_or_name: str) -> Optional[\"Project\"]:\n        registered_project = self.get_registered_project(project_root_or_name)\n        if registered_project is None:\n            return None\n        else:\n            return registered_project.get_project_instance(serena_config=self)\n\n    def add_registered_project(self, registered_project: RegisteredProject) -> None:\n        \"\"\"\n        Adds a registered project, saving the configuration file.\n        \"\"\"\n        self.projects.append(registered_project)\n        self.save()\n\n    def add_project_from_path(self, project_root: Path | str) -> \"Project\":\n        \"\"\"\n        Add a new project to the Serena configuration from a given path, auto-generating the project\n        with defaults if it does not exist.\n        Will raise a FileExistsError if a project already exists at the path.\n\n        :param project_root: the path to the project to add\n        :return: the project that was added\n        \"\"\"\n        from ..project import Project\n\n        project_root = Path(project_root).resolve()\n        if not project_root.exists():\n            raise FileNotFoundError(f\"Error: Path does not exist: {project_root}\")\n        if not project_root.is_dir():\n            raise FileNotFoundError(f\"Error: Path is not a directory: {project_root}\")\n\n        for already_registered_project in self.projects:\n            if str(already_registered_project.project_root) == str(project_root):\n                raise FileExistsError(\n                    f\"Project with path {project_root} was already added with name '{already_registered_project.project_name}'.\"\n                )\n\n        project_config = ProjectConfig.load(project_root, serena_config=self, autogenerate=True)\n\n        new_project = Project(\n            project_root=str(project_root),\n            project_config=project_config,\n            is_newly_created=True,\n            serena_config=self,\n        )\n        self.add_registered_project(RegisteredProject.from_project_instance(new_project))\n\n        return new_project\n\n    def remove_project(self, project_name: str) -> None:\n        # find the index of the project with the desired name and remove it\n        for i, project in enumerate(list(self.projects)):\n            if project.project_name == project_name:\n                del self.projects[i]\n                break\n        else:\n            raise ValueError(f\"Project '{project_name}' not found in Serena configuration; valid project names: {self.project_names}\")\n        self.save()\n\n    def save(self) -> None:\n        \"\"\"\n        Saves the configuration to the file from which it was loaded (if any)\n        \"\"\"\n        if self.config_file_path is None:\n            return\n\n        assert self._loaded_commented_yaml is not None, \"Cannot save configuration without loaded YAML\"\n\n        commented_yaml = deepcopy(self._loaded_commented_yaml)\n\n        # update fields with current values\n        for field_name in self._iter_config_file_mapped_fields_without_type_conversion():\n            commented_yaml[field_name] = getattr(self, field_name)\n\n        # convert project objects into list of paths\n        commented_yaml[\"projects\"] = sorted({str(project.project_root) for project in self.projects})\n\n        # convert language backend to string\n        commented_yaml[\"language_backend\"] = self.language_backend.value\n\n        # convert line ending to string\n        commented_yaml[\"line_ending\"] = self.line_ending.value\n\n        # transfer comments from the template file\n        # NOTE: The template file now uses leading comments, but we previously used trailing comments,\n        #       so we apply a conversion, which detects the old style and transforms it.\n        # For some keys, we force updates, because old comments are problematic/misleading.\n        normalise_yaml_comments(commented_yaml, YamlCommentNormalisation.LEADING_WITH_CONVERSION_FROM_TRAILING)\n        template_yaml = load_yaml(SERENA_CONFIG_TEMPLATE_FILE, comment_normalisation=YamlCommentNormalisation.LEADING)\n        transfer_missing_yaml_comments(template_yaml, commented_yaml, YamlCommentNormalisation.LEADING, forced_update_keys=[\"projects\"])\n\n        save_yaml(self.config_file_path, commented_yaml)\n\n    @staticmethod\n    def _resolve_serena_folder_location(template: str, placeholders: dict[str, str]) -> str:\n        \"\"\"\n        Resolves a folder location template by replacing known ``$placeholder`` tokens\n        and raising on any unrecognised ones.\n\n        :param template: the template string (e.g. ``\"$projectDir/.serena\"``)\n        :param placeholders: mapping from placeholder name (without ``$``) to replacement value\n        :return: the resolved absolute path\n        :raises SerenaConfigError: if the template contains an unknown ``$placeholder``\n        \"\"\"\n\n        def _replace(match: re.Match[str]) -> str:\n            name = match.group(1)\n            if name not in placeholders:\n                raise SerenaConfigError(\n                    f\"Unknown placeholder '${name}' in project_serena_folder_location. \"\n                    f\"Supported placeholders: {', '.join('$' + k for k in placeholders)}\"\n                )\n            return placeholders[name]\n\n        result = re.sub(r\"\\$([A-Za-z_]\\w*)\", _replace, template)\n        return os.path.abspath(result)\n\n    def get_configured_project_serena_folder(self, project_root: str | Path) -> str:\n        \"\"\"\n        Returns the resolved absolute path to the .serena data folder for a project,\n        applying placeholder substitution to ``project_serena_folder_location``\n        without any fallback logic.\n\n        :param project_root: the absolute path to the project root directory\n        :return: the resolved absolute path to the project's .serena folder\n        :raises SerenaConfigError: if the template contains an unknown placeholder\n        \"\"\"\n        project_folder_name = Path(project_root).name\n        placeholders = {\n            \"projectDir\": str(project_root),\n            \"projectFolderName\": project_folder_name,\n        }\n        return self._resolve_serena_folder_location(self.project_serena_folder_location, placeholders)\n\n    def get_project_serena_folder(self, project_root: str | Path) -> str:\n        \"\"\"\n        Resolves the location of the project's .serena data folder using fallback logic:\n\n        1. If the folder exists at the configured path (``project_serena_folder_location``), use it.\n        2. Otherwise, if it exists at the default location inside the project root, use that.\n        3. If neither exists, return the configured path (for creation).\n\n        :param project_root: the absolute path to the project root directory\n        :return: the resolved absolute path to the .serena data folder\n        :raises SerenaConfigError: if the configured template contains an unknown placeholder\n        \"\"\"\n        configured_path = self.get_configured_project_serena_folder(project_root)\n        if os.path.isdir(configured_path):\n            return configured_path\n        default_path = os.path.join(str(project_root), SERENA_MANAGED_DIR_NAME)\n        if configured_path != default_path and os.path.isdir(default_path):\n            return default_path\n        return configured_path\n\n    def get_project_yml_location(self, project_root: str | Path) -> str:\n        \"\"\"\n        Returns the resolved absolute path to the project.yml configuration file,\n        based on the resolved .serena data folder (with fallback logic).\n\n        :param project_root: the absolute path to the project root directory\n        :return: the resolved absolute path to the project's project.yml file\n        \"\"\"\n        serena_folder = self.get_project_serena_folder(project_root)\n        return os.path.join(serena_folder, ProjectConfig.SERENA_PROJECT_FILE)\n\n    def propagate_settings(self) -> None:\n        \"\"\"\n        Propagate settings from this configuration to individual components that are statically configured\n        \"\"\"\n        from serena.tools import JetBrainsPluginClient\n\n        JetBrainsPluginClient.set_server_address(self.jetbrains_plugin_server_address)\n"
  },
  {
    "path": "src/serena/constants.py",
    "content": "from pathlib import Path\n\n_repo_root_path = Path(__file__).parent.parent.parent.resolve()\n_serena_pkg_path = Path(__file__).parent.resolve()\n\nSERENA_MANAGED_DIR_NAME = \".serena\"\n\n# TODO: Path-related constants should be moved to SerenaPaths; don't add further constants here.\nREPO_ROOT = str(_repo_root_path)\nPROMPT_TEMPLATES_DIR_INTERNAL = str(_serena_pkg_path / \"resources\" / \"config\" / \"prompt_templates\")\nSERENAS_OWN_CONTEXT_YAMLS_DIR = str(_serena_pkg_path / \"resources\" / \"config\" / \"contexts\")\n\"\"\"The contexts that are shipped with the Serena package, i.e. the default contexts.\"\"\"\nSERENAS_OWN_MODE_YAMLS_DIR = str(_serena_pkg_path / \"resources\" / \"config\" / \"modes\")\n\"\"\"The modes that are shipped with the Serena package, i.e. the default modes.\"\"\"\nINTERNAL_MODE_YAMLS_DIR = str(_serena_pkg_path / \"resources\" / \"config\" / \"internal_modes\")\n\"\"\"Internal modes, never overridden by user modes.\"\"\"\nSERENA_DASHBOARD_DIR = str(_serena_pkg_path / \"resources\" / \"dashboard\")\nSERENA_ICON_DIR = str(_serena_pkg_path / \"resources\" / \"icons\")\n\nDEFAULT_SOURCE_FILE_ENCODING = \"utf-8\"\n\"\"\"The default encoding assumed for project source files.\"\"\"\nDEFAULT_CONTEXT = \"desktop-app\"\n\nSERENA_FILE_ENCODING = \"utf-8\"\n\"\"\"The encoding used for Serena's own files, such as configuration files and memories.\"\"\"\n\nPROJECT_TEMPLATE_FILE = str(_serena_pkg_path / \"resources\" / \"project.template.yml\")\nPROJECT_LOCAL_TEMPLATE_FILE = str(_serena_pkg_path / \"resources\" / \"project.local.template.yml\")\nSERENA_CONFIG_TEMPLATE_FILE = str(_serena_pkg_path / \"resources\" / \"serena_config.template.yml\")\n\nSERENA_LOG_FORMAT = \"%(levelname)-5s %(asctime)-15s [%(threadName)s] %(name)s:%(funcName)s:%(lineno)d - %(message)s\"\n\nLOG_MESSAGES_BUFFER_SIZE = 2500\n\"\"\"The maximum number of log messages to keep in the buffer (for the dashboard).\"\"\"\n"
  },
  {
    "path": "src/serena/dashboard.py",
    "content": "import os\nimport socket\nimport threading\nfrom collections.abc import Callable\nfrom pathlib import Path\nfrom typing import TYPE_CHECKING, Any, Self\n\nfrom flask import Flask, Response, request, send_from_directory\nfrom pydantic import BaseModel\nfrom sensai.util import logging\n\nfrom serena.analytics import ToolUsageStats\nfrom serena.config.serena_config import SerenaConfig, SerenaPaths\nfrom serena.constants import SERENA_DASHBOARD_DIR\nfrom serena.task_executor import TaskExecutor\nfrom serena.util.logging import MemoryLogHandler\n\nif TYPE_CHECKING:\n    from serena.agent import SerenaAgent\n\nlog = logging.getLogger(__name__)\n\n# disable Werkzeug's logging to avoid cluttering the output\nlogging.getLogger(\"werkzeug\").setLevel(logging.WARNING)\n\n\nclass RequestLog(BaseModel):\n    start_idx: int = 0\n\n\nclass ResponseLog(BaseModel):\n    messages: list[str]\n    max_idx: int\n    active_project: str | None = None\n\n\nclass ResponseToolNames(BaseModel):\n    tool_names: list[str]\n\n\nclass ResponseToolStats(BaseModel):\n    stats: dict[str, dict[str, int]]\n\n\nclass ResponseConfigOverview(BaseModel):\n    active_project: dict[str, str | None]\n    context: dict[str, str]\n    modes: list[dict[str, str]]\n    active_tools: list[str]\n    tool_stats_summary: dict[str, dict[str, int]]\n    registered_projects: list[dict[str, str | bool]]\n    available_tools: list[dict[str, str | bool]]\n    available_modes: list[dict[str, str | bool]]\n    available_contexts: list[dict[str, str | bool]]\n    available_memories: list[str] | None\n    jetbrains_mode: bool\n    languages: list[str]\n    encoding: str | None\n    current_client: str | None\n\n\nclass ResponseAvailableLanguages(BaseModel):\n    languages: list[str]\n\n\nclass RequestAddLanguage(BaseModel):\n    language: str\n\n\nclass RequestRemoveLanguage(BaseModel):\n    language: str\n\n\nclass RequestGetMemory(BaseModel):\n    memory_name: str\n\n\nclass ResponseGetMemory(BaseModel):\n    content: str\n    memory_name: str\n\n\nclass RequestSaveMemory(BaseModel):\n    memory_name: str\n    content: str\n\n\nclass RequestDeleteMemory(BaseModel):\n    memory_name: str\n\n\nclass RequestRenameMemory(BaseModel):\n    old_name: str\n    new_name: str\n\n\nclass ResponseGetSerenaConfig(BaseModel):\n    content: str\n\n\nclass RequestSaveSerenaConfig(BaseModel):\n    content: str\n\n\nclass RequestCancelTaskExecution(BaseModel):\n    task_id: int\n\n\nclass QueuedExecution(BaseModel):\n    task_id: int\n    is_running: bool\n    name: str\n    finished_successfully: bool\n    logged: bool\n\n    @classmethod\n    def from_task_info(cls, task_info: TaskExecutor.TaskInfo) -> Self:\n        return cls(\n            task_id=task_info.task_id,\n            is_running=task_info.is_running,\n            name=task_info.name,\n            finished_successfully=task_info.finished_successfully(),\n            logged=task_info.logged,\n        )\n\n\nclass SerenaDashboardAPI:\n    log = logging.getLogger(__qualname__)\n\n    def __init__(\n        self,\n        memory_log_handler: MemoryLogHandler,\n        tool_names: list[str],\n        agent: \"SerenaAgent\",\n        shutdown_callback: Callable[[], None] | None = None,\n        tool_usage_stats: ToolUsageStats | None = None,\n    ) -> None:\n        self._memory_log_handler = memory_log_handler\n        self._tool_names = tool_names\n        self._agent = agent\n        self._shutdown_callback = shutdown_callback\n        self._app = Flask(__name__)\n        self._tool_usage_stats = tool_usage_stats\n        self._setup_routes()\n\n    @property\n    def memory_log_handler(self) -> MemoryLogHandler:\n        return self._memory_log_handler\n\n    def _setup_routes(self) -> None:\n        # Static files\n        @self._app.route(\"/dashboard/<path:filename>\")\n        def serve_dashboard(filename: str) -> Response:\n            return send_from_directory(SERENA_DASHBOARD_DIR, filename)\n\n        @self._app.route(\"/dashboard/\")\n        def serve_dashboard_index() -> Response:\n            return send_from_directory(SERENA_DASHBOARD_DIR, \"index.html\")\n\n        # API routes\n\n        @self._app.route(\"/heartbeat\", methods=[\"GET\"])\n        def get_heartbeat() -> dict[str, Any]:\n            return {\"status\": \"alive\"}\n\n        @self._app.route(\"/get_log_messages\", methods=[\"POST\"])\n        def get_log_messages() -> dict[str, Any]:\n            request_data = request.get_json()\n            if not request_data:\n                request_log = RequestLog()\n            else:\n                request_log = RequestLog.model_validate(request_data)\n\n            result = self._get_log_messages(request_log)\n            return result.model_dump()\n\n        @self._app.route(\"/get_tool_names\", methods=[\"GET\"])\n        def get_tool_names() -> dict[str, Any]:\n            result = self._get_tool_names()\n            return result.model_dump()\n\n        @self._app.route(\"/get_tool_stats\", methods=[\"GET\"])\n        def get_tool_stats_route() -> dict[str, Any]:\n            result = self._get_tool_stats()\n            return result.model_dump()\n\n        @self._app.route(\"/clear_tool_stats\", methods=[\"POST\"])\n        def clear_tool_stats_route() -> dict[str, str]:\n            self._clear_tool_stats()\n            return {\"status\": \"cleared\"}\n\n        @self._app.route(\"/clear_logs\", methods=[\"POST\"])\n        def clear_logs() -> dict[str, str]:\n            self._memory_log_handler.clear_log_messages()\n            return {\"status\": \"cleared\"}\n\n        @self._app.route(\"/get_token_count_estimator_name\", methods=[\"GET\"])\n        def get_token_count_estimator_name() -> dict[str, str]:\n            estimator_name = self._tool_usage_stats.token_estimator_name if self._tool_usage_stats else \"unknown\"\n            return {\"token_count_estimator_name\": estimator_name}\n\n        @self._app.route(\"/get_config_overview\", methods=[\"GET\"])\n        def get_config_overview() -> dict[str, Any]:\n            result = self._agent.execute_task(self._get_config_overview, logged=False)\n            return result.model_dump()\n\n        @self._app.route(\"/shutdown\", methods=[\"PUT\"])\n        def shutdown() -> dict[str, str]:\n            self._shutdown()\n            return {\"status\": \"shutting down\"}\n\n        @self._app.route(\"/get_available_languages\", methods=[\"GET\"])\n        def get_available_languages() -> dict[str, Any]:\n            result = self._get_available_languages()\n            return result.model_dump()\n\n        @self._app.route(\"/add_language\", methods=[\"POST\"])\n        def add_language() -> dict[str, str]:\n            request_data = request.get_json()\n            if not request_data:\n                return {\"status\": \"error\", \"message\": \"No data provided\"}\n            request_add_language = RequestAddLanguage.model_validate(request_data)\n            try:\n                self._add_language(request_add_language)\n                return {\"status\": \"success\", \"message\": f\"Language {request_add_language.language} added successfully\"}\n            except Exception as e:\n                return {\"status\": \"error\", \"message\": str(e)}\n\n        @self._app.route(\"/remove_language\", methods=[\"POST\"])\n        def remove_language() -> dict[str, str]:\n            request_data = request.get_json()\n            if not request_data:\n                return {\"status\": \"error\", \"message\": \"No data provided\"}\n            request_remove_language = RequestRemoveLanguage.model_validate(request_data)\n            try:\n                self._remove_language(request_remove_language)\n                return {\"status\": \"success\", \"message\": f\"Language {request_remove_language.language} removed successfully\"}\n            except Exception as e:\n                return {\"status\": \"error\", \"message\": str(e)}\n\n        @self._app.route(\"/get_memory\", methods=[\"POST\"])\n        def get_memory() -> dict[str, Any]:\n            request_data = request.get_json()\n            if not request_data:\n                return {\"status\": \"error\", \"message\": \"No data provided\"}\n            request_get_memory = RequestGetMemory.model_validate(request_data)\n            try:\n                result = self._get_memory(request_get_memory)\n                return result.model_dump()\n            except Exception as e:\n                return {\"status\": \"error\", \"message\": str(e)}\n\n        @self._app.route(\"/save_memory\", methods=[\"POST\"])\n        def save_memory() -> dict[str, str]:\n            request_data = request.get_json()\n            if not request_data:\n                return {\"status\": \"error\", \"message\": \"No data provided\"}\n            request_save_memory = RequestSaveMemory.model_validate(request_data)\n            try:\n                self._save_memory(request_save_memory)\n                return {\"status\": \"success\", \"message\": f\"Memory {request_save_memory.memory_name} saved successfully\"}\n            except Exception as e:\n                return {\"status\": \"error\", \"message\": str(e)}\n\n        @self._app.route(\"/delete_memory\", methods=[\"POST\"])\n        def delete_memory() -> dict[str, str]:\n            request_data = request.get_json()\n            if not request_data:\n                return {\"status\": \"error\", \"message\": \"No data provided\"}\n            request_delete_memory = RequestDeleteMemory.model_validate(request_data)\n            try:\n                self._delete_memory(request_delete_memory)\n                return {\"status\": \"success\", \"message\": f\"Memory {request_delete_memory.memory_name} deleted successfully\"}\n            except Exception as e:\n                return {\"status\": \"error\", \"message\": str(e)}\n\n        @self._app.route(\"/rename_memory\", methods=[\"POST\"])\n        def rename_memory() -> dict[str, str]:\n            request_data = request.get_json()\n            if not request_data:\n                return {\"status\": \"error\", \"message\": \"No data provided\"}\n            request_rename_memory = RequestRenameMemory.model_validate(request_data)\n            try:\n                result_message = self._rename_memory(request_rename_memory)\n                return {\"status\": \"success\", \"message\": result_message}\n            except Exception as e:\n                return {\"status\": \"error\", \"message\": str(e)}\n\n        @self._app.route(\"/get_serena_config\", methods=[\"GET\"])\n        def get_serena_config() -> dict[str, Any]:\n            try:\n                result = self._get_serena_config()\n                return result.model_dump()\n            except Exception as e:\n                return {\"status\": \"error\", \"message\": str(e)}\n\n        @self._app.route(\"/save_serena_config\", methods=[\"POST\"])\n        def save_serena_config() -> dict[str, str]:\n            request_data = request.get_json()\n            if not request_data:\n                return {\"status\": \"error\", \"message\": \"No data provided\"}\n            request_save_config = RequestSaveSerenaConfig.model_validate(request_data)\n            try:\n                self._save_serena_config(request_save_config)\n                return {\"status\": \"success\", \"message\": \"Serena config saved successfully\"}\n            except Exception as e:\n                return {\"status\": \"error\", \"message\": str(e)}\n\n        @self._app.route(\"/queued_task_executions\", methods=[\"GET\"])\n        def get_queued_executions() -> dict[str, Any]:\n            try:\n                current_executions = self._agent.get_current_tasks()\n                response = [QueuedExecution.from_task_info(task_info).model_dump() for task_info in current_executions]\n                return {\"queued_executions\": response, \"status\": \"success\"}\n            except Exception as e:\n                return {\"status\": \"error\", \"message\": str(e)}\n\n        @self._app.route(\"/cancel_task_execution\", methods=[\"POST\"])\n        def cancel_task_execution() -> dict[str, Any]:\n            request_data = request.get_json()\n            try:\n                request_cancel_task = RequestCancelTaskExecution.model_validate(request_data)\n                for task in self._agent.get_current_tasks():\n                    if task.task_id == request_cancel_task.task_id:\n                        task.cancel()\n                        return {\"status\": \"success\", \"was_cancelled\": True}\n                return {\n                    \"status\": \"success\",\n                    \"was_cancelled\": False,\n                    \"message\": f\"Task with id {request_data.get('task_id')} not found, maybe execution was already finished\",\n                }\n            except Exception as e:\n                return {\"status\": \"error\", \"message\": str(e), \"was_cancelled\": False}\n\n        @self._app.route(\"/last_execution\", methods=[\"GET\"])\n        def get_last_execution() -> dict[str, Any]:\n            try:\n                last_execution_info = self._agent.get_last_executed_task()\n                response = QueuedExecution.from_task_info(last_execution_info).model_dump() if last_execution_info is not None else None\n                return {\"last_execution\": response, \"status\": \"success\"}\n            except Exception as e:\n                return {\"status\": \"error\", \"message\": str(e)}\n\n        @self._app.route(\"/news_snippet_ids\", methods=[\"GET\"])\n        def get_news_snippet_ids() -> dict[str, str | list[int]]:\n            def _get_unread_news_ids() -> list[int]:\n                all_news_files = (Path(SERENA_DASHBOARD_DIR) / \"news\").glob(\"*.html\")\n                all_news_ids = [int(f.stem) for f in all_news_files]\n                \"\"\"News ids are ints of format YYYYMMDD (publication dates)\"\"\"\n\n                # Filter news items by installation date\n                serena_config_creation_date = SerenaConfig.get_config_file_creation_date()\n                if serena_config_creation_date is None:\n                    # should not normally happen, since config file should exist when the dashboard is started\n                    # We assume a fresh installation in this case\n                    log.error(\"Serena config file not found when starting the dashboard\")\n                    return []\n                serena_config_creation_date_int = int(serena_config_creation_date.strftime(\"%Y%m%d\"))\n                # Only include news items published on or after the installation date\n                post_installation_news_ids = [news_id for news_id in all_news_ids if news_id >= serena_config_creation_date_int]\n\n                news_snippet_id_file = SerenaPaths().news_snippet_id_file\n                if not os.path.exists(news_snippet_id_file):\n                    return post_installation_news_ids\n                with open(news_snippet_id_file, encoding=\"utf-8\") as f:\n                    last_read_news_id = int(f.read().strip())\n                return [news_id for news_id in post_installation_news_ids if news_id > last_read_news_id]\n\n            try:\n                unread_news_ids = _get_unread_news_ids()\n                return {\"news_snippet_ids\": unread_news_ids, \"status\": \"success\"}\n            except Exception as e:\n                return {\"status\": \"error\", \"message\": str(e)}\n\n        @self._app.route(\"/mark_news_snippet_as_read\", methods=[\"POST\"])\n        def mark_news_snippet_as_read() -> dict[str, str]:\n            try:\n                request_data = request.get_json()\n                news_snippet_id = int(request_data.get(\"news_snippet_id\"))\n                news_snippet_id_file = SerenaPaths().news_snippet_id_file\n                with open(news_snippet_id_file, \"w\", encoding=\"utf-8\") as f:\n                    f.write(str(news_snippet_id))\n                return {\"status\": \"success\", \"message\": f\"Marked news snippet {news_snippet_id} as read\"}\n            except Exception as e:\n                return {\"status\": \"error\", \"message\": str(e)}\n\n    def _get_log_messages(self, request_log: RequestLog) -> ResponseLog:\n        messages = self._memory_log_handler.get_log_messages(from_idx=request_log.start_idx)\n        project = self._agent.get_active_project()\n        project_name = project.project_name if project else None\n        return ResponseLog(messages=messages.messages, max_idx=messages.max_idx, active_project=project_name)\n\n    def _get_tool_names(self) -> ResponseToolNames:\n        return ResponseToolNames(tool_names=self._tool_names)\n\n    def _get_tool_stats(self) -> ResponseToolStats:\n        if self._tool_usage_stats is not None:\n            return ResponseToolStats(stats=self._tool_usage_stats.get_tool_stats_dict())\n        else:\n            return ResponseToolStats(stats={})\n\n    def _clear_tool_stats(self) -> None:\n        if self._tool_usage_stats is not None:\n            self._tool_usage_stats.clear()\n\n    def _get_config_overview(self) -> ResponseConfigOverview:\n        from serena.config.context_mode import SerenaAgentContext, SerenaAgentMode\n        from serena.tools.tools_base import Tool\n\n        # Get active project info\n        project = self._agent.get_active_project()\n        active_project_name = project.project_name if project else None\n        project_info = {\n            \"name\": active_project_name,\n            \"language\": \", \".join([l.value for l in project.project_config.languages]) if project else None,\n            \"path\": str(project.project_root) if project else None,\n        }\n\n        # Get context info\n        context = self._agent.get_context()\n        context_info = {\n            \"name\": context.name,\n            \"description\": context.description,\n            \"path\": SerenaAgentContext.get_path(context.name, instance=context),\n        }\n\n        # Get active modes\n        modes = self._agent.get_active_modes()\n        modes_info = [\n            {\"name\": mode.name, \"description\": mode.description, \"path\": SerenaAgentMode.get_path(mode.name, instance=mode)}\n            for mode in modes\n        ]\n        active_mode_names = [mode.name for mode in modes]\n\n        # Get active tools\n        active_tools = self._agent.get_active_tool_names()\n\n        # Get registered projects\n        registered_projects: list[dict[str, str | bool]] = []\n        for proj in self._agent.serena_config.projects:\n            registered_projects.append(\n                {\n                    \"name\": proj.project_name,\n                    \"path\": str(proj.project_root),\n                    \"is_active\": proj.project_name == active_project_name,\n                }\n            )\n\n        # Get all available tools (excluding active ones)\n        all_tool_names = sorted([tool.get_name_from_cls() for tool in self._agent._all_tools.values()])\n        available_tools: list[dict[str, str | bool]] = []\n        for tool_name in all_tool_names:\n            if tool_name not in active_tools:\n                available_tools.append(\n                    {\n                        \"name\": tool_name,\n                        \"is_active\": False,\n                    }\n                )\n\n        # Get all available modes\n        all_mode_names = SerenaAgentMode.list_registered_mode_names()\n        available_modes: list[dict[str, str | bool]] = []\n        for mode_name in all_mode_names:\n            try:\n                mode_path = SerenaAgentMode.get_path(mode_name)\n            except FileNotFoundError:\n                # Skip modes that can't be found (shouldn't happen for registered modes)\n                continue\n            available_modes.append(\n                {\n                    \"name\": mode_name,\n                    \"is_active\": mode_name in active_mode_names,\n                    \"path\": mode_path,\n                }\n            )\n\n        # Get all available contexts\n        all_context_names = SerenaAgentContext.list_registered_context_names()\n        available_contexts: list[dict[str, str | bool]] = []\n        for context_name in all_context_names:\n            try:\n                context_path = SerenaAgentContext.get_path(context_name)\n            except FileNotFoundError:\n                # Skip contexts that can't be found (shouldn't happen for registered contexts)\n                continue\n            available_contexts.append(\n                {\n                    \"name\": context_name,\n                    \"is_active\": context_name == context.name,\n                    \"path\": context_path,\n                }\n            )\n\n        # Get basic tool stats (just num_calls for overview)\n        tool_stats_summary = {}\n        if self._tool_usage_stats is not None:\n            full_stats = self._tool_usage_stats.get_tool_stats_dict()\n            tool_stats_summary = {name: {\"num_calls\": stats[\"num_times_called\"]} for name, stats in full_stats.items()}\n\n        # Get available memories if ReadMemoryTool is active\n        available_memories = None\n        if self._agent.tool_is_active(\"read_memory\") and project is not None:\n            available_memories = project.memories_manager.list_memories().get_full_list()\n\n        # Get list of languages for the active project\n        languages = []\n        if project is not None:\n            languages = [lang.value for lang in project.project_config.languages]\n\n        # Get file encoding for the active project\n        encoding = None\n        if project is not None:\n            encoding = project.project_config.encoding\n\n        return ResponseConfigOverview(\n            active_project=project_info,\n            context=context_info,\n            modes=modes_info,\n            active_tools=active_tools,\n            tool_stats_summary=tool_stats_summary,\n            registered_projects=registered_projects,\n            available_tools=available_tools,\n            available_modes=available_modes,\n            available_contexts=available_contexts,\n            available_memories=available_memories,\n            jetbrains_mode=self._agent.get_language_backend().is_jetbrains(),\n            languages=languages,\n            encoding=encoding,\n            current_client=Tool.get_last_tool_call_client_str(),\n        )\n\n    def _shutdown(self) -> None:\n        log.info(\"Shutting down Serena\")\n        if self._shutdown_callback:\n            self._shutdown_callback()\n        else:\n            # noinspection PyProtectedMember\n            # noinspection PyUnresolvedReferences\n            os._exit(0)\n\n    def _get_available_languages(self) -> ResponseAvailableLanguages:\n        from solidlsp.ls_config import Language\n\n        def run() -> ResponseAvailableLanguages:\n            all_languages = [lang.value for lang in Language.iter_all(include_experimental=False)]\n\n            # Filter out already added languages for the active project\n            project = self._agent.get_active_project()\n            if project:\n                current_languages = [lang.value for lang in project.project_config.languages]\n                available_languages = [lang for lang in all_languages if lang not in current_languages]\n            else:\n                available_languages = all_languages\n\n            return ResponseAvailableLanguages(languages=sorted(available_languages))\n\n        return self._agent.execute_task(run, logged=False)\n\n    def _get_memory(self, request_get_memory: RequestGetMemory) -> ResponseGetMemory:\n        def run() -> ResponseGetMemory:\n            project = self._agent.get_active_project()\n            if project is None:\n                raise ValueError(\"No active project\")\n\n            content = project.memories_manager.load_memory(request_get_memory.memory_name)\n            return ResponseGetMemory(content=content, memory_name=request_get_memory.memory_name)\n\n        return self._agent.execute_task(run, logged=False)\n\n    def _save_memory(self, request_save_memory: RequestSaveMemory) -> None:\n        def run() -> None:\n            project = self._agent.get_active_project()\n            if project is None:\n                raise ValueError(\"No active project\")\n            project.memories_manager.save_memory(request_save_memory.memory_name, request_save_memory.content, is_tool_context=False)\n\n        self._agent.execute_task(run, logged=True, name=\"SaveMemory\")\n\n    def _delete_memory(self, request_delete_memory: RequestDeleteMemory) -> None:\n        def run() -> None:\n            project = self._agent.get_active_project()\n            if project is None:\n                raise ValueError(\"No active project\")\n            project.memories_manager.delete_memory(request_delete_memory.memory_name, is_tool_context=False)\n\n        self._agent.execute_task(run, logged=True, name=\"DeleteMemory\")\n\n    def _rename_memory(self, request_rename_memory: RequestRenameMemory) -> str:\n        def run() -> str:\n            project = self._agent.get_active_project()\n            if project is None:\n                raise ValueError(\"No active project\")\n\n            return project.memories_manager.move_memory(\n                request_rename_memory.old_name, request_rename_memory.new_name, is_tool_context=False\n            )\n\n        return self._agent.execute_task(run, logged=True, name=\"RenameMemory\")\n\n    def _get_serena_config(self) -> ResponseGetSerenaConfig:\n        config_path = self._agent.serena_config.config_file_path\n        if config_path is None or not os.path.exists(config_path):\n            raise ValueError(\"Serena config file not found\")\n\n        with open(config_path, encoding=\"utf-8\") as f:\n            content = f.read()\n\n        return ResponseGetSerenaConfig(content=content)\n\n    def _save_serena_config(self, request_save_config: RequestSaveSerenaConfig) -> None:\n        def run() -> None:\n            config_path = self._agent.serena_config.config_file_path\n            if config_path is None:\n                raise ValueError(\"Serena config file path not set\")\n\n            with open(config_path, \"w\", encoding=\"utf-8\") as f:\n                f.write(request_save_config.content)\n\n        self._agent.execute_task(run, logged=True, name=\"SaveSerenaConfig\")\n\n    def _add_language(self, request_add_language: RequestAddLanguage) -> None:\n        from solidlsp.ls_config import Language\n\n        try:\n            language = Language(request_add_language.language)\n        except ValueError:\n            raise ValueError(f\"Invalid language: {request_add_language.language}\")\n        # add_language is already thread-safe\n        self._agent.add_language(language)\n\n    def _remove_language(self, request_remove_language: RequestRemoveLanguage) -> None:\n        from solidlsp.ls_config import Language\n\n        try:\n            language = Language(request_remove_language.language)\n        except ValueError:\n            raise ValueError(f\"Invalid language: {request_remove_language.language}\")\n        # remove_language is already thread-safe\n        self._agent.remove_language(language)\n\n    @staticmethod\n    def _find_first_free_port(start_port: int, host: str) -> int:\n        port = start_port\n        while port <= 65535:\n            try:\n                with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:\n                    sock.bind((host, port))\n                    return port\n            except OSError:\n                port += 1\n\n        raise RuntimeError(f\"No free ports found starting from {start_port}\")\n\n    def run(self, host: str, port: int) -> int:\n        \"\"\"\n        Runs the dashboard on the given host and port and returns the port number.\n        \"\"\"\n        # patch flask.cli.show_server to avoid printing the server info\n        from flask import cli\n\n        cli.show_server_banner = lambda *args, **kwargs: None\n\n        self._app.run(host=host, port=port, debug=False, use_reloader=False, threaded=True)\n        return port\n\n    def run_in_thread(self, host: str) -> tuple[threading.Thread, int]:\n        port = self._find_first_free_port(0x5EDA, host)\n        log.info(\"Starting dashboard (listen_address=%s, port=%d)\", host, port)\n        thread = threading.Thread(target=lambda: self.run(host=host, port=port), daemon=True)\n        thread.start()\n        return thread, port\n"
  },
  {
    "path": "src/serena/generated/generated_prompt_factory.py",
    "content": "# ruff: noqa\n# black: skip\n# mypy: ignore-errors\n\n# NOTE: This module is auto-generated from interprompt.autogenerate_prompt_factory_module, do not edit manually!\n\nfrom interprompt.multilang_prompt import PromptList\nfrom interprompt.prompt_factory import PromptFactoryBase\nfrom typing import Any\n\n\nclass PromptFactory(PromptFactoryBase):\n    \"\"\"\n    A class for retrieving and rendering prompt templates and prompt lists.\n    \"\"\"\n\n    def create_onboarding_prompt(self, *, system: Any) -> str:\n        return self._render_prompt(\"onboarding_prompt\", locals())\n\n    def create_think_about_collected_information(self) -> str:\n        return self._render_prompt(\"think_about_collected_information\", locals())\n\n    def create_think_about_task_adherence(self) -> str:\n        return self._render_prompt(\"think_about_task_adherence\", locals())\n\n    def create_think_about_whether_you_are_done(self) -> str:\n        return self._render_prompt(\"think_about_whether_you_are_done\", locals())\n\n    def create_summarize_changes(self) -> str:\n        return self._render_prompt(\"summarize_changes\", locals())\n\n    def create_prepare_for_new_conversation(self) -> str:\n        return self._render_prompt(\"prepare_for_new_conversation\", locals())\n\n    def create_system_prompt(\n        self,\n        *,\n        available_markers: Any,\n        available_tools: Any,\n        context_system_prompt: Any,\n        global_memories_list: Any,\n        mode_system_prompts: Any,\n    ) -> str:\n        return self._render_prompt(\"system_prompt\", locals())\n"
  },
  {
    "path": "src/serena/gui_log_viewer.py",
    "content": "# mypy: ignore-errors\r\nimport logging\r\nimport os\r\nimport queue\r\nimport sys\r\nimport threading\r\nimport tkinter as tk\r\nimport traceback\r\nfrom enum import Enum, auto\r\nfrom pathlib import Path\r\nfrom typing import Literal\r\n\r\nfrom serena import constants\r\nfrom serena.util.logging import MemoryLogHandler\r\n\r\nlog = logging.getLogger(__name__)\r\n\r\n\r\nclass LogLevel(Enum):\r\n    DEBUG = auto()\r\n    INFO = auto()\r\n    WARNING = auto()\r\n    ERROR = auto()\r\n    DEFAULT = auto()\r\n\r\n\r\nclass GuiLogViewer:\r\n    \"\"\"\r\n    A class that creates a Tkinter GUI for displaying log messages in a separate thread.\r\n    The log viewer supports coloring based on log levels (DEBUG, INFO, WARNING, ERROR).\r\n    It can also highlight tool names in boldface when they appear in log messages.\r\n    \"\"\"\r\n\r\n    def __init__(\r\n        self,\r\n        mode: Literal[\"dashboard\", \"error\"],\r\n        title=\"Log Viewer\",\r\n        memory_log_handler: MemoryLogHandler | None = None,\r\n        width=800,\r\n        height=600,\r\n    ):\r\n        \"\"\"\r\n        :param mode: the mode; if \"dashboard\", run a dashboard with logs and some control options; if \"error\", run\r\n            a simple error log viewer (for fatal exceptions)\r\n        :param title: the window title\r\n        :param memory_log_handler: an optional log handler from which to obtain log messages; If not provided,\r\n            must pass the instance to a `GuiLogViewerHandler` to add log messages.\r\n        :param width: the initial window width\r\n        :param height: the initial window height\r\n        \"\"\"\r\n        self.mode = mode\r\n        self.title = title\r\n        self.width = width\r\n        self.height = height\r\n        self.message_queue = queue.Queue()\r\n        self.running = False\r\n        self.log_thread = None\r\n        self.menubar: tk.Menu | None = None\r\n        self.tool_names = []  # List to store tool names for highlighting\r\n\r\n        # Define colors for different log levels\r\n        self.log_colors = {\r\n            LogLevel.DEBUG: \"#808080\",  # Gray\r\n            LogLevel.INFO: \"#000000\",  # Black\r\n            LogLevel.WARNING: \"#FF8C00\",  # Dark Orange\r\n            LogLevel.ERROR: \"#FF0000\",  # Red\r\n            LogLevel.DEFAULT: \"#000000\",  # Black\r\n        }\r\n\r\n        if memory_log_handler is not None:\r\n            for msg in memory_log_handler.get_log_messages().messages:\r\n                self.message_queue.put(msg)\r\n            memory_log_handler.add_emit_callback(lambda msg: self.message_queue.put(msg))\r\n\r\n    def start(self):\r\n        \"\"\"Start the log viewer in a separate thread.\"\"\"\r\n        if not self.running:\r\n            self.log_thread = threading.Thread(target=self.run_gui)\r\n            self.log_thread.daemon = True\r\n            self.log_thread.start()\r\n            return True\r\n        return False\r\n\r\n    def stop(self):\r\n        \"\"\"Stop the log viewer.\"\"\"\r\n        if self.running:\r\n            # Add a sentinel value to the queue to signal the GUI to exit\r\n            self.message_queue.put(None)\r\n            return True\r\n        return False\r\n\r\n    def set_tool_names(self, tool_names):\r\n        \"\"\"\r\n        Set or update the list of tool names to be highlighted in log messages.\r\n\r\n        Args:\r\n            tool_names (list): A list of tool name strings to highlight\r\n\r\n        \"\"\"\r\n        self.tool_names = tool_names\r\n\r\n    def set_dashboard_url(self, url: str) -> None:\r\n        def copy_url():\r\n            self.root.clipboard_clear()\r\n            self.root.clipboard_append(url)\r\n            log.info(f\"Copied dashboard URL to clipboard: {url}\")\r\n\r\n        if self.menubar is not None:\r\n            dashboard_menu = tk.Menu(self.menubar, tearoff=0)\r\n            dashboard_menu.add_command(label=\"Copy URL\", command=copy_url)  # type: ignore\r\n            self.menubar.add_cascade(label=\"Dashboard\", menu=dashboard_menu)\r\n\r\n    def add_log(self, message):\r\n        \"\"\"\r\n        Add a log message to the viewer.\r\n\r\n        Args:\r\n            message (str): The log message to display\r\n\r\n        \"\"\"\r\n        self.message_queue.put(message)\r\n\r\n    def _determine_log_level(self, message):\r\n        \"\"\"\r\n        Determine the log level from the message.\r\n\r\n        Args:\r\n            message (str): The log message\r\n\r\n        Returns:\r\n            LogLevel: The determined log level\r\n\r\n        \"\"\"\r\n        message_upper = message.upper()\r\n        if message_upper.startswith(\"DEBUG\"):\r\n            return LogLevel.DEBUG\r\n        elif message_upper.startswith(\"INFO\"):\r\n            return LogLevel.INFO\r\n        elif message_upper.startswith(\"WARNING\"):\r\n            return LogLevel.WARNING\r\n        elif message_upper.startswith(\"ERROR\"):\r\n            return LogLevel.ERROR\r\n        else:\r\n            return LogLevel.DEFAULT\r\n\r\n    def _process_queue(self):\r\n        \"\"\"Process messages from the queue and update the text widget.\"\"\"\r\n        try:\r\n            while not self.message_queue.empty():\r\n                message = self.message_queue.get_nowait()\r\n\r\n                # Check for sentinel value to exit\r\n                if message is None:\r\n                    self.root.quit()\r\n                    return\r\n\r\n                # Check if scrollbar is at the bottom before adding new text\r\n                # Get current scroll position\r\n                current_position = self.text_widget.yview()\r\n                # If near the bottom (allowing for small floating point differences)\r\n                was_at_bottom = current_position[1] > 0.99\r\n\r\n                log_level = self._determine_log_level(message)\r\n\r\n                # Insert the message at the end of the text with appropriate log level tag\r\n                self.text_widget.configure(state=tk.NORMAL)\r\n\r\n                # Find tool names in the message and highlight them\r\n                if self.tool_names:\r\n                    # Capture start position (before insertion)\r\n                    start_index = self.text_widget.index(\"end-1c\")\r\n\r\n                    # Insert the message\r\n                    self.text_widget.insert(tk.END, message + \"\\n\", log_level.name)\r\n\r\n                    # Convert start index to line/char format\r\n                    line, char = map(int, start_index.split(\".\"))\r\n\r\n                    # Search for tool names in the message string directly\r\n                    for tool_name in self.tool_names:\r\n                        start_offset = 0\r\n                        while True:\r\n                            found_at = message.find(tool_name, start_offset)\r\n                            if found_at == -1:\r\n                                break\r\n\r\n                            # Calculate line/column from offset\r\n                            offset_line = line\r\n                            offset_char = char\r\n                            for c in message[:found_at]:\r\n                                if c == \"\\n\":\r\n                                    offset_line += 1\r\n                                    offset_char = 0\r\n                                else:\r\n                                    offset_char += 1\r\n\r\n                            # Construct index positions\r\n                            start_pos = f\"{offset_line}.{offset_char}\"\r\n                            end_pos = f\"{offset_line}.{offset_char + len(tool_name)}\"\r\n\r\n                            # Add tag to highlight the tool name\r\n                            self.text_widget.tag_add(\"TOOL_NAME\", start_pos, end_pos)\r\n\r\n                            start_offset = found_at + len(tool_name)\r\n\r\n                else:\r\n                    # No tool names to highlight, just insert the message\r\n                    self.text_widget.insert(tk.END, message + \"\\n\", log_level.name)\r\n\r\n                self.text_widget.configure(state=tk.DISABLED)\r\n\r\n                # Auto-scroll to the bottom only if it was already at the bottom\r\n                if was_at_bottom:\r\n                    self.text_widget.see(tk.END)\r\n\r\n            # Schedule to check the queue again\r\n            if self.running:\r\n                self.root.after(100, self._process_queue)\r\n\r\n        except Exception as e:\r\n            print(f\"Error processing message queue: {e}\", file=sys.stderr)\r\n            if self.running:\r\n                self.root.after(100, self._process_queue)\r\n\r\n    def run_gui(self):\r\n        \"\"\"Run the GUI\"\"\"\r\n        self.running = True\r\n        try:\r\n            # Set app id (avoid app being lumped together with other Python-based apps in Windows taskbar)\r\n            if sys.platform == \"win32\":\r\n                import ctypes\r\n\r\n                ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(\"oraios.serena\")\r\n\r\n            self.root = tk.Tk()\r\n            self.root.title(self.title)\r\n            self.root.geometry(f\"{self.width}x{self.height}\")\r\n\r\n            # Make the window resizable\r\n            self.root.columnconfigure(0, weight=1)\r\n            # We now have two rows - one for logo and one for text\r\n            self.root.rowconfigure(0, weight=0)  # Logo row\r\n            self.root.rowconfigure(1, weight=1)  # Text content row\r\n\r\n            dashboard_path = Path(constants.SERENA_DASHBOARD_DIR)\r\n\r\n            # Load and display the logo image\r\n            try:\r\n                # construct path relative to path of this file\r\n                image_path = dashboard_path / \"serena-logs.png\"\r\n                self.logo_image = tk.PhotoImage(file=image_path)\r\n\r\n                # Create a label to display the logo\r\n                self.logo_label = tk.Label(self.root, image=self.logo_image)\r\n                self.logo_label.grid(row=0, column=0, sticky=\"ew\")\r\n            except Exception as e:\r\n                print(f\"Error loading logo image: {e}\", file=sys.stderr)\r\n\r\n            # Create frame to hold text widget and scrollbars\r\n            frame = tk.Frame(self.root)\r\n            frame.grid(row=1, column=0, sticky=\"nsew\")\r\n            frame.columnconfigure(0, weight=1)\r\n            frame.rowconfigure(0, weight=1)\r\n\r\n            # Create horizontal scrollbar\r\n            h_scrollbar = tk.Scrollbar(frame, orient=tk.HORIZONTAL)\r\n            h_scrollbar.grid(row=1, column=0, sticky=\"ew\")\r\n\r\n            # Create vertical scrollbar\r\n            v_scrollbar = tk.Scrollbar(frame, orient=tk.VERTICAL)\r\n            v_scrollbar.grid(row=0, column=1, sticky=\"ns\")\r\n\r\n            # Create text widget with horizontal scrolling\r\n            self.text_widget = tk.Text(\r\n                frame, wrap=tk.NONE, width=self.width, height=self.height, xscrollcommand=h_scrollbar.set, yscrollcommand=v_scrollbar.set\r\n            )\r\n            self.text_widget.grid(row=0, column=0, sticky=\"nsew\")\r\n            self.text_widget.configure(state=tk.DISABLED)  # Make it read-only\r\n\r\n            # Configure scrollbars\r\n            h_scrollbar.config(command=self.text_widget.xview)\r\n            v_scrollbar.config(command=self.text_widget.yview)\r\n\r\n            # Configure tags for different log levels with appropriate colors\r\n            for level, color in self.log_colors.items():\r\n                self.text_widget.tag_configure(level.name, foreground=color)\r\n\r\n            # Configure tag for tool names\r\n            self.text_widget.tag_configure(\"TOOL_NAME\", background=\"#ffff00\")\r\n\r\n            # Set up the queue processing\r\n            self.root.after(100, self._process_queue)\r\n\r\n            # Handle window close event depending on mode\r\n            if self.mode == \"dashboard\":\r\n                self.root.protocol(\"WM_DELETE_WINDOW\", lambda: self.root.iconify())\r\n            else:\r\n                self.root.protocol(\"WM_DELETE_WINDOW\", self.stop)\r\n\r\n            # Create menu bar\r\n            if self.mode == \"dashboard\":\r\n                self.menubar = tk.Menu(self.root)\r\n                server_menu = tk.Menu(self.menubar, tearoff=0)\r\n                server_menu.add_command(label=\"Shutdown\", command=self._shutdown_server)  # type: ignore\r\n                self.menubar.add_cascade(label=\"Server\", menu=server_menu)\r\n                self.root.config(menu=self.menubar)\r\n\r\n            # Configure icons\r\n            icon_16 = tk.PhotoImage(file=dashboard_path / \"serena-icon-16.png\")\r\n            icon_32 = tk.PhotoImage(file=dashboard_path / \"serena-icon-32.png\")\r\n            icon_48 = tk.PhotoImage(file=dashboard_path / \"serena-icon-48.png\")\r\n            self.root.iconphoto(False, icon_48, icon_32, icon_16)\r\n\r\n            # Start the Tkinter event loop\r\n            self.root.mainloop()\r\n\r\n        except Exception as e:\r\n            print(f\"Error in GUI thread: {e}\", file=sys.stderr)\r\n        finally:\r\n            self.running = False\r\n\r\n    def _shutdown_server(self) -> None:\r\n        log.info(\"Shutting down Serena\")\r\n        # noinspection PyUnresolvedReferences\r\n        # noinspection PyProtectedMember\r\n        os._exit(0)\r\n\r\n\r\nclass GuiLogViewerHandler(logging.Handler):\r\n    \"\"\"\r\n    A logging handler that sends log records to a ThreadedLogViewer instance.\r\n    This handler can be integrated with Python's standard logging module\r\n    to direct log entries to a GUI log viewer.\r\n    \"\"\"\r\n\r\n    def __init__(\r\n        self,\r\n        log_viewer: GuiLogViewer,\r\n        level=logging.NOTSET,\r\n        format_string: str | None = \"%(levelname)-5s %(asctime)-15s %(name)s:%(funcName)s:%(lineno)d - %(message)s\",\r\n    ):\r\n        \"\"\"\r\n        Initialize the handler with a ThreadedLogViewer instance.\r\n\r\n        Args:\r\n            log_viewer: A ThreadedLogViewer instance that will display the logs\r\n            level: The logging level (default: NOTSET which captures all logs)\r\n            format_string: the format string\r\n\r\n        \"\"\"\r\n        super().__init__(level)\r\n        self.log_viewer = log_viewer\r\n        self.formatter = logging.Formatter(format_string)\r\n\r\n        # Start the log viewer if it's not already running\r\n        if not self.log_viewer.running:\r\n            self.log_viewer.start()\r\n\r\n    @classmethod\r\n    def is_instance_registered(cls) -> bool:\r\n        for h in logging.Logger.root.handlers:\r\n            if isinstance(h, cls):\r\n                return True\r\n        return False\r\n\r\n    def emit(self, record):\r\n        \"\"\"\r\n        Emit a log record to the ThreadedLogViewer.\r\n\r\n        Args:\r\n            record: The log record to emit\r\n\r\n        \"\"\"\r\n        try:\r\n            # Format the record according to the formatter\r\n            msg = self.format(record)\r\n\r\n            # Convert the level name to a standard format for the viewer\r\n            level_prefix = record.levelname\r\n\r\n            # Add the appropriate prefix if it's not already there\r\n            if not msg.startswith(level_prefix):\r\n                msg = f\"{level_prefix}: {msg}\"\r\n\r\n            self.log_viewer.add_log(msg)\r\n\r\n        except Exception:\r\n            self.handleError(record)\r\n\r\n    def close(self):\r\n        \"\"\"\r\n        Close the handler and optionally stop the log viewer.\r\n        \"\"\"\r\n        # We don't automatically stop the log viewer here as it might\r\n        # be used by other handlers or directly by the application\r\n        super().close()\r\n\r\n    def stop_viewer(self):\r\n        \"\"\"\r\n        Explicitly stop the associated log viewer.\r\n        \"\"\"\r\n        if self.log_viewer.running:\r\n            self.log_viewer.stop()\r\n\r\n\r\ndef show_fatal_exception(e: Exception):\r\n    \"\"\"\r\n    Makes sure the given exception is shown in the GUI log viewer,\r\n    either an existing instance or a new one.\r\n\r\n    :param e: the exception to display\r\n    \"\"\"\r\n    # show in new window in main thread (user must close it)\r\n    log_viewer = GuiLogViewer(\"error\")\r\n    exc_info = \"\".join(traceback.format_exception(type(e), e, e.__traceback__))\r\n    log_viewer.add_log(f\"ERROR Fatal exception: {e}\\n{exc_info}\")\r\n    log_viewer.run_gui()\r\n"
  },
  {
    "path": "src/serena/jetbrains/jetbrains_plugin_client.py",
    "content": "\"\"\"\nClient for the Serena JetBrains Plugin\n\"\"\"\n\nimport concurrent\nimport json\nimport logging\nimport re\nimport threading\nfrom concurrent.futures.thread import ThreadPoolExecutor\nfrom dataclasses import dataclass\nfrom pathlib import Path\nfrom typing import Any, Literal, Optional, Self, TypeVar, cast\n\nimport requests\nfrom requests import Response\nfrom sensai.util.string import ToStringMixin\n\nimport serena.jetbrains.jetbrains_types as jb\nfrom serena.config.serena_config import RegisteredProject\nfrom serena.jetbrains.jetbrains_types import PluginStatusDTO\nfrom serena.project import Project\nfrom serena.util.class_decorators import singleton\nfrom serena.util.text_utils import render_html\nfrom serena.util.version import Version\n\nT = TypeVar(\"T\")\nlog = logging.getLogger(__name__)\n\n\nclass SerenaClientError(Exception):\n    \"\"\"Base exception for Serena client errors.\"\"\"\n\n\nclass ConnectionError(SerenaClientError):\n    \"\"\"Raised when connection to the service fails.\"\"\"\n\n\nclass APIError(SerenaClientError):\n    \"\"\"Raised when the API returns an error response that shall be reported on the caller/LLM.\"\"\"\n\n    def __init__(self, response: Response):\n        try:\n            error_data = response.json()\n            message = error_data.get(\"error\", response.text)\n        except:\n            message = response.text\n        super().__init__(message)\n\n\nclass PluginServerError(SerenaClientError):\n    \"\"\"Raised when the plugin's service encounters an internal error (which may need to be reported).\"\"\"\n\n    def __init__(self, message: str):\n        unrecoverable_error_prefix = (\n            \"The request failed due to an error on the Serena JetBrains plugin side. This may be caused \"\n            \"by a bug or an incompatibility in the plugin. In that case, please report the error below together with \"\n            \"your setup (IDE + version, Serena plugin version, programming language) at https://github.com/oraios/serena/issues \"\n            \"(if you are an LLM, tell the user about this). The Oraios team will then provide support on this.\\n\"\n        )\n        super().__init__(unrecoverable_error_prefix + message)\n\n\nclass ServerNotFoundError(Exception):\n    \"\"\"Raised when the plugin's service is not found.\"\"\"\n\n\n@dataclass\nclass MatchedClient:\n    client: \"JetBrainsPluginClient\"\n    registered_project: RegisteredProject\n\n\n@singleton\nclass JetBrainsPluginClientManager:\n    \"\"\"\n    Manager for JetBrainsPluginClient instances, responsible for scanning ports to find available plugin instances\n    \"\"\"\n\n    NUM_PORTS_TO_SCAN = 20\n\n    def __init__(self) -> None:\n        self._clients: dict[int, \"JetBrainsPluginClient\"] = {}\n        self._matched_clients: list[MatchedClient] = []\n        self._lock = threading.Lock()\n\n    def _submit_scan(self) -> list[concurrent.futures.Future[\"JetBrainsPluginClient\"]]:\n        \"\"\"\n        Performs a port scan to find available plugin instances in parallel.\n\n        :return: futures that will resolve to plugin clients for every port\n        \"\"\"\n\n        def scan_port(port: int) -> JetBrainsPluginClient:\n            client = JetBrainsPluginClient(port)\n            with self._lock:\n                self._clients[port] = client\n            return client\n\n        futures = []\n        with ThreadPoolExecutor(max_workers=self.NUM_PORTS_TO_SCAN) as executor:\n            for i in range(self.NUM_PORTS_TO_SCAN):\n                future = executor.submit(scan_port, JetBrainsPluginClient.BASE_PORT + i)\n                futures.append(future)\n        return futures\n\n    def find_client(self, project_root: Path) -> \"JetBrainsPluginClient\":\n        plugin_paths_found = []\n        for future in self._submit_scan():\n            client = future.result()\n            if client.matches(project_root):\n                return client\n            elif client.project_root is not None:\n                plugin_paths_found.append(client.project_root)\n\n        log.warning(\n            \"Searched for Serena JetBrains plugin service for project at %s but found no matching service. \"\n            \"Found plugin instances for the following project paths: %s\",\n            project_root,\n            plugin_paths_found,\n        )\n        raise ServerNotFoundError(\n            f\"Found no Serena service in a JetBrains IDE instance for the project at {project_root}. \"\n            \"STOP. Do not attempt any other tools or workarounds. Ask the user to open this folder as a project in a JetBrains IDE \"\n            \"with the Serena plugin installed and running!\"\n        )\n\n    def match_clients(self, registered_projects: list[RegisteredProject]) -> list[MatchedClient]:\n        \"\"\"\n        Scans for plugin instances and matches them against the given registered projects.\n\n        :param registered_projects: the list of registered projects to match plugin instances against\n        :return: the list of matched clients with their corresponding registered project\n        \"\"\"\n        matched_clients = []\n        for future in self._submit_scan():\n            client = future.result()\n            if client.project_root is not None:\n                for rp in registered_projects:\n                    if client.matches(Path(rp.project_root)):\n                        matched_clients.append(MatchedClient(client, rp))\n                        break\n        self._matched_clients = matched_clients\n        return matched_clients\n\n    def get_matched_client(\n        self, registered_project: RegisteredProject, registered_projects: list[RegisteredProject]\n    ) -> Optional[\"JetBrainsPluginClient\"]:\n        \"\"\"\n        Gets the matched client for a given registered project, if any.\n\n        :param registered_project: the registered project to get the matched client for\n        :param registered_projects: the list of all registered projects (used to perform matching of all clients\n            if no match is found for the given project)\n        :return: the matched client or None if no match is found\n        \"\"\"\n\n        def find_match() -> Optional[\"JetBrainsPluginClient\"]:\n            for matched_client in self._matched_clients:\n                if matched_client.registered_project.project_root == registered_project.project_root:\n                    return matched_client.client\n            return None\n\n        match = find_match()\n        if match is None:\n            self.match_clients(registered_projects)\n        return find_match()\n\n\nclass JetBrainsPluginClient(ToStringMixin):\n    \"\"\"\n    Python client for the Serena Backend Service.\n\n    Provides simple methods to interact with all available endpoints.\n    \"\"\"\n\n    BASE_PORT = 0x5EA2\n    PLUGIN_REQUEST_TIMEOUT = 300\n    \"\"\"\n    the timeout used for request handling within the plugin (a constant in the plugin)\n    \"\"\"\n    _last_port: int | None = None\n    \"\"\"\n    the last port that was successfully used to connect to a plugin instance in the current session\n    \"\"\"\n    _server_address: str = \"127.0.0.1\"\n    \"\"\"\n    the server address where to connect to the plugin service\n    \"\"\"\n\n    def __init__(self, port: int, timeout: int = PLUGIN_REQUEST_TIMEOUT):\n        self._port = port\n        self._timeout = timeout\n        self._session = requests.Session()\n        self._session.headers.update({\"Content-Type\": \"application/json\", \"Accept\": \"application/json\"})\n\n        # connect and obtain status\n        self.project_root: str | None = None\n        self._plugin_version: Version | None = None\n        try:\n            status_response: PluginStatusDTO = cast(jb.PluginStatusDTO, self._make_request(\"GET\", \"/status\"))\n            self.project_root = status_response[\"project_root\"]\n            self._plugin_version = Version(status_response[\"plugin_version\"])\n        except ConnectionError:  # expected if no server is running at the port\n            pass\n        except Exception as e:\n            log.warning(\"Failed to obtain status from JetBrains plugin service at port %d: %s\", port, e, exc_info=e)\n\n    @property\n    def _base_url(self) -> str:\n        return f\"http://{self._server_address}:{self._port}\"\n\n    @classmethod\n    def set_server_address(cls, address: str) -> None:\n        cls._server_address = address\n\n    def _tostring_includes(self) -> list[str]:\n        return [\"_port\", \"project_root\", \"_plugin_version\"]\n\n    @classmethod\n    def from_project(cls, project: Project) -> Self:\n        resolved_path = Path(project.project_root).resolve()\n\n        if cls._last_port is not None:\n            client = JetBrainsPluginClient(cls._last_port)\n            if client.matches(resolved_path):\n                return client\n\n        client = JetBrainsPluginClientManager().find_client(resolved_path)\n        cls._last_port = client._port\n        return client\n\n    @staticmethod\n    def _paths_match(resolved_serena_path: str, plugin_path: str) -> bool:\n        \"\"\"\n        Checks whether the resolved Serena path matches the plugin path, accounting for possible prefixes\n        in the plugin path, different file system perspectives, and case sensitivity.\n\n        Concrete aspects considered:\n        - The plugin path may contain prefixes:\n          - The plugin path may be a WSL UNC path, e.g. `//wsl.localhost/Ubuntu-24.04/home/user/project`\n            or `//wsl$/Ubuntu/home/user/project` while Serena will just have `/home/user/project`\n          - Other prefixes like `/workspaces/serena/C:/Users/user/projects/my-app`\n        - One path may use a different file system perspective (particularly WSL vs Windows-native) but still\n          point to the same location, e.g. `/mnt/c/` vs `C:/`\n        - Case sensitivity\n\n        :param resolved_serena_path: The resolved project root path from Serena's perspective\n        :param plugin_path: The project root path reported by the plugin (which may be a WSL UNC path)\n        :return: True if the paths match, False otherwise\n        \"\"\"\n        # try to resolve the plugin path, checking for a direct match\n        # (this is robust against symlinks as long as there are no prefixes)\n        try:\n            resolved_plugin_path = str(Path(plugin_path).resolve())\n            if resolved_plugin_path == resolved_serena_path:\n                return True\n        except:\n            pass\n\n        def normalise_wsl_mnt(path_str: str) -> str:\n            # normalise WSL /mnt/c/ to c:/ for comparison\n            return re.sub(r\"/mnt/([a-z])/\", r\"\\1:/\", path_str, flags=re.IGNORECASE)\n\n        # standardise paths for comparison: normalise WSL /mnt/ to Windows paths and ignore case\n        std_serena_path = normalise_wsl_mnt(str(resolved_serena_path)).lower()\n        std_plugin_path = normalise_wsl_mnt(str(plugin_path)).lower()\n\n        # At this point, the plugin path may still contain prefixes, so we check if the Serena path is a suffix of the plugin path\n        return std_plugin_path.endswith(std_serena_path)\n\n    def matches(self, resolved_path: Path) -> bool:\n        \"\"\"\n        :param resolved_path: the resolved project root path from Serena's perspective\n        :return: whether this client instance matches the given project path\n        \"\"\"\n        if self.project_root is None:\n            return False\n        return self._paths_match(str(resolved_path), self.project_root)\n\n    def is_version_at_least(self, *version_parts: int) -> bool:\n        if self._plugin_version is None:\n            return False\n        return self._plugin_version.is_at_least(*version_parts)\n\n    def _require_version_at_least(self, *version_parts: int) -> None:\n        \"\"\"\n        Ensures that the plugin version is at least the given version and raises an error otherwise.\n\n        :param version_parts: the minimum required version parts (major, minor, patch)\n        \"\"\"\n        if not self.is_version_at_least(*version_parts):\n            raise SerenaClientError(\n                f\"This operation requires Serena JetBrains plugin version \"\n                f\"{'.'.join(map(str, version_parts))} or higher, but the installed version is \"\n                f\"{self._plugin_version}. Ask the user to update the plugin!\"\n            )\n\n    def _make_request(self, method: str, endpoint: str, data: Optional[dict] = None) -> dict[str, Any]:\n        url = f\"{self._base_url}{endpoint}\"\n\n        response: Response | None = None\n        try:\n            if method.upper() == \"GET\":\n                response = self._session.get(url, timeout=self._timeout)\n            elif method.upper() == \"POST\":\n                json_data = json.dumps(data) if data else None\n                response = self._session.post(url, data=json_data, timeout=self._timeout)\n            else:\n                raise ValueError(f\"Unsupported HTTP method: {method}\")\n\n            response.raise_for_status()\n\n            # Try to parse JSON response\n            try:\n                return self._pythonify_response(response.json())\n            except json.JSONDecodeError:\n                # If response is not JSON, return raw text\n                return {\"response\": response.text}\n\n        except requests.exceptions.ConnectionError as e:\n            raise ConnectionError(f\"Failed to connect to Serena service at {url}: {e}\")\n        except requests.exceptions.Timeout as e:\n            raise ConnectionError(f\"Request to {url} timed out: {e}\")\n        except requests.exceptions.HTTPError as e:\n            if response is not None:\n                # check for recoverable error (i.e. errors where the problem can be resolved by the caller or\n                # other errors where the error text shall simply be passed on to the LLM).\n                # The plugin returns 400 for such errors (typically illegal arguments, e.g. non-unique name path)\n                # but only since version 2023.2.6\n                if self.is_version_at_least(2023, 2, 6):\n                    is_recoverable_error = response.status_code == 400\n                else:\n                    is_recoverable_error = True  # assume recoverable for older versions (mix of errors)\n                if is_recoverable_error:\n                    raise APIError(response)\n                raise PluginServerError(f\"API request failed with status {response.status_code}: {response.text}\")\n            raise PluginServerError(f\"API request failed with HTTP error: {e}\")\n        except requests.exceptions.RequestException as e:\n            raise SerenaClientError(f\"Request failed: {e}\")\n\n    @staticmethod\n    def _pythonify_response(response: T) -> T:\n        \"\"\"\n        Converts dictionary keys from camelCase to snake_case recursively.\n\n        :response: the response in which to convert keys (dictionary or list)\n        \"\"\"\n        to_snake_case = lambda s: \"\".join([\"_\" + c.lower() if c.isupper() else c for c in s])\n\n        def convert(x):  # type: ignore\n            if isinstance(x, dict):\n                return {to_snake_case(k): convert(v) for k, v in x.items()}\n            elif isinstance(x, list):\n                return [convert(item) for item in x]\n            else:\n                return x\n\n        return convert(response)\n\n    def _postprocess_symbol_collection_response(self, response_dict: jb.SymbolCollectionResponse) -> None:\n        \"\"\"\n        Postprocesses a symbol collection response in-place, converting HTML documentation to plain text.\n\n        :param response_dict: the response dictionary\n        \"\"\"\n\n        def convert_html(key: Literal[\"documentation\", \"quick_info\"], symbol: jb.SymbolDTO) -> None:\n            if key in symbol:\n                doc_html: str = symbol[key]\n                doc_text = render_html(doc_html)\n                if doc_text:\n                    symbol[key] = doc_text\n                else:\n                    del symbol[key]\n\n        def convert_symbol_list(l: list) -> None:\n            for s in l:\n                convert_html(\"documentation\", s)\n                convert_html(\"quick_info\", s)\n                if \"children\" in s:\n                    convert_symbol_list(s[\"children\"])\n\n        convert_symbol_list(response_dict[\"symbols\"])\n\n    def find_symbol(\n        self,\n        name_path: str,\n        relative_path: str | None = None,\n        include_body: bool = False,\n        include_quick_info: bool = False,\n        include_documentation: bool = False,\n        include_num_usages: bool = False,\n        depth: int = 0,\n        include_location: bool = False,\n        search_deps: bool = False,\n    ) -> jb.SymbolCollectionResponse:\n        \"\"\"\n        Finds symbols by name.\n\n        :param name_path: the name path to match\n        :param relative_path: the relative path to which to restrict the search\n        :param include_body: whether to include symbol body content (should typically not be combined with `include_quick_info`\n            or `include_documentation` because the body includes everything)\n        :param include_quick_info: whether to include quick info (typically the signature)\n        :param include_documentation: whether to include documentation; note that this includes the quick info, so one should\n            not pass both `include_quick_info` and this\n        :param include_num_usages: whether to include the number of usages\n        :param depth: depth up to which to include children (0 = no children)\n        :param include_location: whether to include symbol location information\n        :param search_deps: whether to also search in dependencies\n        \"\"\"\n        request_data = {\n            \"namePath\": name_path,\n            \"relativePath\": relative_path,\n            \"includeBody\": include_body,\n            \"depth\": depth,\n            \"includeLocation\": include_location,\n            \"searchDeps\": search_deps,\n            \"includeQuickInfo\": include_quick_info,\n            \"includeDocumentation\": include_documentation,\n            \"includeNumUsages\": include_num_usages,\n        }\n        symbol_collection = cast(jb.SymbolCollectionResponse, self._make_request(\"POST\", \"/findSymbol\", request_data))\n        self._postprocess_symbol_collection_response(symbol_collection)\n        return symbol_collection\n\n    def find_references(self, name_path: str, relative_path: str, include_quick_info: bool) -> jb.SymbolCollectionResponse:\n        \"\"\"\n        Finds references to a symbol.\n\n        :param name_path: the name path of the symbol\n        :param relative_path: the relative path\n        :param include_quick_info: whether to include quick info about references\n        \"\"\"\n        request_data = {\"namePath\": name_path, \"relativePath\": relative_path, \"includeQuickInfo\": include_quick_info}\n        symbol_collection = cast(jb.SymbolCollectionResponse, self._make_request(\"POST\", \"/findReferences\", request_data))\n        self._postprocess_symbol_collection_response(symbol_collection)\n        return symbol_collection\n\n    def get_symbols_overview(\n        self, relative_path: str, depth: int, include_file_documentation: bool = False\n    ) -> jb.GetSymbolsOverviewResponse:\n        \"\"\"\n        :param relative_path: the relative path to a source file\n        :param depth: the depth of children to include (0 = no children)\n        :param include_file_documentation: whether to include the file's documentation string (if any)\n        \"\"\"\n        request_data = {\"relativePath\": relative_path, \"depth\": depth, \"includeFileDocumentation\": include_file_documentation}\n        response = cast(jb.GetSymbolsOverviewResponse, self._make_request(\"POST\", \"/getSymbolsOverview\", request_data))\n        self._postprocess_symbol_collection_response(response)\n\n        # process file documentation\n        if \"documentation\" in response:\n            response[\"documentation\"] = render_html(response[\"documentation\"])\n\n        return response\n\n    def get_supertypes(\n        self,\n        name_path: str,\n        relative_path: str,\n        depth: int | None = None,\n        limit_children: int | None = None,\n    ) -> jb.TypeHierarchyResponse:\n        \"\"\"\n        Gets the supertypes (parent classes/interfaces) of a symbol.\n\n        :param name_path: the name path of the symbol\n        :param relative_path: the relative path to the file containing the symbol\n        :param depth: depth limit for hierarchy traversal (None or 0 for unlimited)\n        :param limit_children: optional limit on children per level\n        \"\"\"\n        self._require_version_at_least(2023, 2, 6)\n        request_data = {\n            \"namePath\": name_path,\n            \"relativePath\": relative_path,\n            \"depth\": depth,\n            \"limitChildren\": limit_children,\n        }\n        return cast(jb.TypeHierarchyResponse, self._make_request(\"POST\", \"/getSupertypes\", request_data))\n\n    def get_subtypes(\n        self,\n        name_path: str,\n        relative_path: str,\n        depth: int | None = None,\n        limit_children: int | None = None,\n    ) -> jb.TypeHierarchyResponse:\n        \"\"\"\n        Gets the subtypes (subclasses/implementations) of a symbol.\n\n        :param name_path: the name path of the symbol\n        :param relative_path: the relative path to the file containing the symbol\n        :param depth: depth limit for hierarchy traversal (None or 0 for unlimited)\n        :param limit_children: optional limit on children per level\n        \"\"\"\n        self._require_version_at_least(2023, 2, 6)\n        request_data = {\n            \"namePath\": name_path,\n            \"relativePath\": relative_path,\n            \"depth\": depth,\n            \"limitChildren\": limit_children,\n        }\n        return cast(jb.TypeHierarchyResponse, self._make_request(\"POST\", \"/getSubtypes\", request_data))\n\n    def rename_symbol(\n        self, name_path: str, relative_path: str, new_name: str, rename_in_comments: bool, rename_in_text_occurrences: bool\n    ) -> None:\n        \"\"\"\n        Renames a symbol.\n\n        :param name_path: the name path of the symbol\n        :param relative_path: the relative path\n        :param new_name: the new name for the symbol\n        :param rename_in_comments: whether to rename in comments\n        :param rename_in_text_occurrences: whether to rename in text occurrences\n        \"\"\"\n        request_data = {\n            \"namePath\": name_path,\n            \"relativePath\": relative_path,\n            \"newName\": new_name,\n            \"renameInComments\": rename_in_comments,\n            \"renameInTextOccurrences\": rename_in_text_occurrences,\n        }\n        self._make_request(\"POST\", \"/renameSymbol\", request_data)\n\n    def refresh_file(self, relative_path: str) -> None:\n        \"\"\"\n        Triggers a refresh of the given file in the IDE.\n\n        :param relative_path: the relative path\n        \"\"\"\n        request_data = {\n            \"relativePath\": relative_path,\n        }\n        self._make_request(\"POST\", \"/refreshFile\", request_data)\n\n    def close(self) -> None:\n        self._session.close()\n\n    def __enter__(self) -> Self:\n        return self\n\n    def __exit__(self, exc_type, exc_val, exc_tb):  # type: ignore\n        self.close()\n"
  },
  {
    "path": "src/serena/jetbrains/jetbrains_types.py",
    "content": "from typing import Literal, NotRequired, TypedDict\n\n\nclass PluginStatusDTO(TypedDict):\n    project_root: str\n    plugin_version: str\n\n\nclass PositionDTO(TypedDict):\n    line: int\n    col: int\n\n\nclass TextRangeDTO(TypedDict):\n    start_pos: PositionDTO\n    end_pos: PositionDTO\n\n\nclass SymbolDTO(TypedDict):\n    name_path: str\n    relative_path: str\n    type: str\n    body: NotRequired[str]\n    quick_info: NotRequired[str]\n    \"\"\"Quick info text (e.g., type signature) for the symbol, as HTML string.\"\"\"\n    documentation: NotRequired[str]\n    \"\"\"Documentation text for the symbol (if available), as HTML string.\"\"\"\n    text_range: NotRequired[TextRangeDTO]\n    children: NotRequired[list[\"SymbolDTO\"]]\n    num_usages: NotRequired[int]\n\n\nSymbolDTOKey = Literal[\"name_path\", \"relative_path\", \"type\", \"body\", \"quick_info\", \"documentation\", \"text_range\", \"children\", \"num_usages\"]\n\n\nclass SymbolCollectionResponse(TypedDict):\n    symbols: list[SymbolDTO]\n\n\nclass GetSymbolsOverviewResponse(SymbolCollectionResponse):\n    documentation: NotRequired[str]\n    \"\"\"Docstring of the collection (if applicable - usually present only if the collection is from a single file), \n    as HTML string.\"\"\"\n\n\nclass TypeHierarchyNodeDTO(TypedDict):\n    symbol: SymbolDTO\n    children: NotRequired[list[\"TypeHierarchyNodeDTO\"]]\n\n\nclass TypeHierarchyResponse(TypedDict):\n    hierarchy: NotRequired[list[TypeHierarchyNodeDTO]]\n    num_levels_not_included: NotRequired[int]\n"
  },
  {
    "path": "src/serena/ls_manager.py",
    "content": "import logging\nimport os.path\nimport threading\nfrom collections.abc import Iterator\n\nfrom sensai.util.logging import LogTime\n\nfrom serena.config.serena_config import SerenaPaths\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language, LanguageServerConfig\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass LanguageServerManagerInitialisationError(Exception):\n    def __init__(self, message: str):\n        super().__init__(message)\n\n\nclass LanguageServerFactory:\n    def __init__(\n        self,\n        project_root: str,\n        project_data_path: str,\n        encoding: str,\n        ignored_patterns: list[str],\n        ls_timeout: float | None = None,\n        ls_specific_settings: dict | None = None,\n        trace_lsp_communication: bool = False,\n    ):\n        self.project_root = project_root\n        self.project_data_path = project_data_path\n        self.encoding = encoding\n        self.ignored_patterns = ignored_patterns\n        self.ls_timeout = ls_timeout\n        self.ls_specific_settings = ls_specific_settings\n        self.trace_lsp_communication = trace_lsp_communication\n\n    def create_language_server(self, language: Language) -> SolidLanguageServer:\n        ls_config = LanguageServerConfig(\n            code_language=language,\n            ignored_paths=self.ignored_patterns,\n            trace_lsp_communication=self.trace_lsp_communication,\n            encoding=self.encoding,\n        )\n\n        log.info(f\"Creating language server instance for {self.project_root}, language={language}.\")\n        return SolidLanguageServer.create(\n            ls_config,\n            self.project_root,\n            timeout=self.ls_timeout,\n            solidlsp_settings=SolidLSPSettings(\n                solidlsp_dir=SerenaPaths().serena_user_home_dir,\n                project_data_path=self.project_data_path,\n                ls_specific_settings=self.ls_specific_settings or {},\n            ),\n        )\n\n\nclass LanguageServerManager:\n    \"\"\"\n    Manages one or more language servers for a project.\n    \"\"\"\n\n    def __init__(\n        self,\n        language_servers: dict[Language, SolidLanguageServer],\n        language_server_factory: LanguageServerFactory | None = None,\n    ) -> None:\n        \"\"\"\n        :param language_servers: a mapping from language to language server; the servers are assumed to be already started.\n            The first server in the iteration order is used as the default server.\n            All servers are assumed to serve the same project root.\n        :param language_server_factory: factory for language server creation; if None, dynamic (re)creation of language servers\n            is not supported\n        \"\"\"\n        self._language_servers = language_servers\n        self._language_server_factory = language_server_factory\n\n    @property\n    def _default_language_server(self) -> SolidLanguageServer:\n        if len(self._language_servers) == 0:\n            raise ValueError(\"No language servers available in the manager\")\n        return next(iter(self._language_servers.values()))\n\n    @staticmethod\n    def from_languages(languages: list[Language], factory: LanguageServerFactory) -> \"LanguageServerManager\":\n        \"\"\"\n        Creates a manager with language servers for the given languages using the given factory.\n        The language servers are started in parallel threads.\n\n        :param languages: the languages for which to spawn language servers\n        :param factory: the factory for language server creation\n        :return: the instance\n        \"\"\"\n\n        class StartLSThread(threading.Thread):\n            def __init__(self, language: Language):\n                super().__init__(target=self._start_language_server, name=\"StartLS:\" + language.value)\n                self.language = language\n                self.language_server: SolidLanguageServer | None = None\n                self.exception: Exception | None = None\n\n            def _start_language_server(self) -> None:\n                try:\n                    with LogTime(f\"Language server startup (language={self.language.value})\"):\n                        self.language_server = factory.create_language_server(self.language)\n                        self.language_server.start()\n                        if not self.language_server.is_running():\n                            raise RuntimeError(f\"Failed to start the language server for language {self.language.value}\")\n                except Exception as e:\n                    log.error(f\"Error starting language server for language {self.language.value}: {e}\", exc_info=e)\n                    self.exception = e\n\n        # start language servers in parallel threads\n        threads = []\n        for language in languages:\n            thread = StartLSThread(language)\n            thread.start()\n            threads.append(thread)\n\n        # collect language servers and exceptions\n        language_servers: dict[Language, SolidLanguageServer] = {}\n        exceptions: dict[Language, Exception] = {}\n        for thread in threads:\n            thread.join()\n            if thread.exception is not None:\n                exceptions[thread.language] = thread.exception\n            elif thread.language_server is not None:\n                language_servers[thread.language] = thread.language_server\n\n        # If any server failed to start up, raise an exception and stop all started language servers.\n        # We intentionally fail fast here. The user's intention is to work with all the specified languages,\n        # so if any of them is not available, it is better to make symbolic tool calls fail, bringing the issue to the\n        # user's attention instead of silently continuing with a subset of the language servers and potentially\n        # causing suboptimal agent behaviour.\n        if exceptions:\n            for ls in language_servers.values():\n                ls.stop()\n            failure_messages = \"\\n\".join([f\"{lang.value}: {e}\" for lang, e in exceptions.items()])\n            raise LanguageServerManagerInitialisationError(f\"Failed to start {len(exceptions)} language server(s):\\n{failure_messages}\")\n\n        return LanguageServerManager(language_servers, factory)\n\n    def _ensure_functional_ls(self, ls: SolidLanguageServer) -> SolidLanguageServer:\n        if not ls.is_running():\n            log.warning(f\"Language server for language {ls.language} is not running; restarting ...\")\n            ls = self.restart_language_server(ls.language)\n        return ls\n\n    def _get_suitable_language_server(self, relative_path: str) -> SolidLanguageServer | None:\n        \"\"\":param relative_path: relative path to a file\"\"\"\n        for candidate in self._language_servers.values():\n            if not candidate.is_ignored_path(relative_path, ignore_unsupported_files=True):\n                return candidate\n        return None\n\n    def get_language_server(self, relative_path: str) -> SolidLanguageServer:\n        \"\"\":param relative_path: relative path to a file\"\"\"\n        ls: SolidLanguageServer | None = None\n        if len(self._language_servers) > 1:\n            if os.path.isdir(relative_path):\n                raise ValueError(f\"Expected a file path, but got a directory: {relative_path}\")\n            ls = self._get_suitable_language_server(relative_path)\n        if ls is None:\n            ls = self._default_language_server\n        return self._ensure_functional_ls(ls)\n\n    def _create_and_start_language_server(self, language: Language) -> SolidLanguageServer:\n        if self._language_server_factory is None:\n            raise ValueError(f\"No language server factory available to create language server for {language}\")\n        language_server = self._language_server_factory.create_language_server(language)\n        language_server.start()\n        self._language_servers[language] = language_server\n        return language_server\n\n    def restart_language_server(self, language: Language) -> SolidLanguageServer:\n        \"\"\"\n        Forces recreation and restart of the language server for the given language.\n        It is assumed that the language server for the given language is no longer running.\n\n        :param language: the language\n        :return: the newly created language server\n        \"\"\"\n        if language not in self._language_servers:\n            raise ValueError(f\"No language server for language {language.value} present; cannot restart\")\n        return self._create_and_start_language_server(language)\n\n    def add_language_server(self, language: Language) -> SolidLanguageServer:\n        \"\"\"\n        Dynamically adds a new language server for the given language.\n\n        :param language: the language\n        :param factory: the factory to create the language server\n        :return: the newly created language server\n        \"\"\"\n        if language in self._language_servers:\n            raise ValueError(f\"Language server for language {language.value} already present\")\n        return self._create_and_start_language_server(language)\n\n    def remove_language_server(self, language: Language, save_cache: bool = False) -> None:\n        \"\"\"\n        Removes the language server for the given language, stopping it if it is running.\n\n        :param language: the language\n        \"\"\"\n        if language not in self._language_servers:\n            raise ValueError(f\"No language server for language {language.value} present; cannot remove\")\n        ls = self._language_servers.pop(language)\n        self._stop_language_server(ls, save_cache=save_cache)\n\n    def get_active_languages(self) -> list[Language]:\n        \"\"\"\n        Returns the list of languages for which language servers are currently managed.\n\n        :return: list of languages\n        \"\"\"\n        return list(self._language_servers.keys())\n\n    @staticmethod\n    def _stop_language_server(ls: SolidLanguageServer, save_cache: bool = False, timeout: float = 2.0) -> None:\n        if ls.is_running():\n            if save_cache:\n                ls.save_cache()\n            log.info(f\"Stopping language server for language {ls.language} ...\")\n            ls.stop(shutdown_timeout=timeout)\n\n    def iter_language_servers(self) -> Iterator[SolidLanguageServer]:\n        for ls in self._language_servers.values():\n            yield self._ensure_functional_ls(ls)\n\n    def stop_all(self, save_cache: bool = False, timeout: float = 2.0) -> None:\n        \"\"\"\n        Stops all managed language servers.\n\n        :param save_cache: whether to save the cache before stopping\n        :param timeout: timeout for shutdown of each language server\n        \"\"\"\n        for ls in self.iter_language_servers():\n            self._stop_language_server(ls, save_cache=save_cache, timeout=timeout)\n\n    def save_all_caches(self) -> None:\n        \"\"\"\n        Saves the caches of all managed language servers.\n        \"\"\"\n        for ls in self.iter_language_servers():\n            if ls.is_running():\n                ls.save_cache()\n\n    def has_suitable_ls_for_file(self, relative_file_path: str) -> bool:\n        return self._get_suitable_language_server(relative_file_path) is not None\n"
  },
  {
    "path": "src/serena/mcp.py",
    "content": "\"\"\"\nThe Serena Model Context Protocol (MCP) Server\n\"\"\"\n\nimport sys\nfrom collections.abc import AsyncIterator, Iterator, Sequence\nfrom contextlib import asynccontextmanager\nfrom copy import deepcopy\nfrom dataclasses import dataclass\nfrom typing import Any, Literal, cast\n\nimport docstring_parser\nfrom mcp.server.fastmcp import server\nfrom mcp.server.fastmcp.server import FastMCP, Settings\nfrom mcp.server.fastmcp.tools.base import Tool as MCPTool\nfrom mcp.types import ToolAnnotations\nfrom pydantic_settings import SettingsConfigDict\nfrom sensai.util import logging\n\nfrom serena.agent import (\n    SerenaAgent,\n    SerenaConfig,\n)\nfrom serena.config.context_mode import SerenaAgentContext\nfrom serena.config.serena_config import LanguageBackend, ModeSelectionDefinition\nfrom serena.constants import DEFAULT_CONTEXT, SERENA_LOG_FORMAT\nfrom serena.tools import Tool\nfrom serena.util.exception import show_fatal_exception_safe\nfrom serena.util.logging import MemoryLogHandler\n\nlog = logging.getLogger(__name__)\n\n\ndef configure_logging(*args, **kwargs) -> None:  # type: ignore\n    # We only do something here if logging has not yet been configured.\n    # Normally, logging is configured in the MCP server startup script.\n    if not logging.is_enabled():\n        logging.basicConfig(level=logging.INFO, stream=sys.stderr, format=SERENA_LOG_FORMAT)\n\n\n# patch the logging configuration function in fastmcp, because it's hard-coded and broken\nserver.configure_logging = configure_logging  # type: ignore\n\n\n@dataclass\nclass SerenaMCPRequestContext:\n    agent: SerenaAgent\n\n\nclass SerenaMCPFactory:\n    \"\"\"\n    Factory for the creation of the Serena MCP server with an associated SerenaAgent.\n    \"\"\"\n\n    def __init__(self, context: str = DEFAULT_CONTEXT, project: str | None = None, memory_log_handler: MemoryLogHandler | None = None):\n        \"\"\"\n        :param context: The context name or path to context file\n        :param project: Either an absolute path to the project directory or a name of an already registered project.\n            If the project passed here hasn't been registered yet, it will be registered automatically and can be activated by its name\n            afterward.\n        :param memory_log_handler: the in-memory log handler to use for the agent's logging\n        \"\"\"\n        self.context = SerenaAgentContext.load(context)\n        self.project = project\n        self.agent: SerenaAgent | None = None\n        self.memory_log_handler = memory_log_handler\n\n    @staticmethod\n    def _sanitize_for_openai_tools(schema: dict) -> dict:\n        \"\"\"\n        This method was written by GPT-5, I have not reviewed it in detail.\n        Only called when `openai_tool_compatible` is True.\n\n        Make a Pydantic/JSON Schema object compatible with OpenAI tool schema.\n        - 'integer' -> 'number' (+ multipleOf: 1)\n        - remove 'null' from union type arrays\n        - coerce integer-only enums to number\n        - best-effort simplify oneOf/anyOf when they only differ by integer/number\n        \"\"\"\n        s = deepcopy(schema)\n\n        def walk(node):  # type: ignore\n            if not isinstance(node, dict):\n                # lists get handled by parent calls\n                return node\n\n            # ---- handle type ----\n            t = node.get(\"type\")\n            if isinstance(t, str):\n                if t == \"integer\":\n                    node[\"type\"] = \"number\"\n                    # preserve existing multipleOf but ensure it's integer-like\n                    if \"multipleOf\" not in node:\n                        node[\"multipleOf\"] = 1\n            elif isinstance(t, list):\n                # remove 'null' (OpenAI tools don't support nullables)\n                t2 = [x if x != \"integer\" else \"number\" for x in t if x != \"null\"]\n                if not t2:\n                    # fall back to object if it somehow becomes empty\n                    t2 = [\"object\"]\n                node[\"type\"] = t2[0] if len(t2) == 1 else t2\n                if \"integer\" in t or \"number\" in t2:\n                    # if integers were present, keep integer-like restriction\n                    node.setdefault(\"multipleOf\", 1)\n\n            # ---- enums of integers -> number ----\n            if \"enum\" in node and isinstance(node[\"enum\"], list):\n                vals = node[\"enum\"]\n                if vals and all(isinstance(v, int) for v in vals):\n                    node.setdefault(\"type\", \"number\")\n                    # keep them as ints; JSON 'number' covers ints\n                    node.setdefault(\"multipleOf\", 1)\n\n            # ---- simplify anyOf/oneOf if they only differ by integer/number ----\n            for key in (\"oneOf\", \"anyOf\"):\n                if key in node and isinstance(node[key], list):\n                    # Special case: anyOf or oneOf with \"type X\" and \"null\"\n                    if len(node[key]) == 2:\n                        types = [sub.get(\"type\") for sub in node[key]]\n                        if \"null\" in types:\n                            non_null_type = next(t for t in types if t != \"null\")\n                            if isinstance(non_null_type, str):\n                                node[\"type\"] = non_null_type\n                                node.pop(key, None)\n                                continue\n                    simplified = []\n                    changed = False\n                    for sub in node[key]:\n                        sub = walk(sub)  # recurse\n                        simplified.append(sub)\n                    # If all subs are the same after integer→number, collapse\n                    try:\n                        import json\n\n                        canon = [json.dumps(x, sort_keys=True) for x in simplified]\n                        if len(set(canon)) == 1:\n                            # copy the single schema up\n                            only = simplified[0]\n                            node.pop(key, None)\n                            for k, v in only.items():\n                                if k not in node:\n                                    node[k] = v\n                            changed = True\n                    except Exception:\n                        pass\n                    if not changed:\n                        node[key] = simplified\n\n            # ---- recurse into known schema containers ----\n            for child_key in (\"properties\", \"patternProperties\", \"definitions\", \"$defs\"):\n                if child_key in node and isinstance(node[child_key], dict):\n                    for k, v in list(node[child_key].items()):\n                        node[child_key][k] = walk(v)\n\n            # arrays/items\n            if \"items\" in node:\n                node[\"items\"] = walk(node[\"items\"])\n\n            # allOf/if/then/else - pass through with integer→number conversions applied inside\n            for key in (\"allOf\",):\n                if key in node and isinstance(node[key], list):\n                    node[key] = [walk(x) for x in node[key]]\n\n            if \"if\" in node:\n                node[\"if\"] = walk(node[\"if\"])\n            if \"then\" in node:\n                node[\"then\"] = walk(node[\"then\"])\n            if \"else\" in node:\n                node[\"else\"] = walk(node[\"else\"])\n\n            return node\n\n        return walk(s)\n\n    @staticmethod\n    def make_mcp_tool(tool: Tool, openai_tool_compatible: bool = True) -> MCPTool:\n        \"\"\"\n        Create an MCP tool from a Serena Tool instance.\n\n        :param tool: The Serena Tool instance to convert.\n        :param openai_tool_compatible: whether to process the tool schema to be compatible with OpenAI tools\n            (doesn't accept integer, needs number instead, etc.). This allows using Serena MCP within codex.\n        \"\"\"\n        func_name = tool.get_name()\n        func_doc = tool.get_apply_docstring() or \"\"\n        func_arg_metadata = tool.get_apply_fn_metadata()\n        is_async = False\n        parameters = func_arg_metadata.arg_model.model_json_schema()\n        if openai_tool_compatible:\n            parameters = SerenaMCPFactory._sanitize_for_openai_tools(parameters)\n\n        docstring = docstring_parser.parse(func_doc)\n\n        # Mount the tool description as a combination of the docstring description and\n        # the return value description, if it exists.\n        overridden_description = tool.agent.get_context().tool_description_overrides.get(func_name, None)\n\n        if overridden_description is not None:\n            func_doc = overridden_description\n        elif docstring.description:\n            func_doc = docstring.description\n        else:\n            func_doc = \"\"\n        func_doc = func_doc.strip().strip(\".\")\n        if func_doc:\n            func_doc += \".\"\n        if docstring.returns and (docstring_returns_descr := docstring.returns.description):\n            # Only add a space before \"Returns\" if func_doc is not empty\n            prefix = \" \" if func_doc else \"\"\n            func_doc = f\"{func_doc}{prefix}Returns {docstring_returns_descr.strip().strip('.')}.\"\n\n        # Parse the parameter descriptions from the docstring and add pass its description\n        # to the parameter schema.\n        docstring_params = {param.arg_name: param for param in docstring.params}\n        parameters_properties: dict[str, dict[str, Any]] = parameters[\"properties\"]\n        for parameter, properties in parameters_properties.items():\n            if (param_doc := docstring_params.get(parameter)) and param_doc.description:\n                param_desc = f\"{param_doc.description.strip().strip('.') + '.'}\"\n                properties[\"description\"] = param_desc[0].upper() + param_desc[1:]\n\n        def execute_fn(**kwargs) -> str:  # type: ignore\n            return tool.apply_ex(log_call=True, catch_exceptions=True, **kwargs)\n\n        # Generate human-readable title from snake_case tool name\n        tool_title = \" \".join(word.capitalize() for word in func_name.split(\"_\"))\n\n        # Create annotations with appropriate hints based on tool capabilities\n        can_edit = tool.can_edit()\n        annotations = ToolAnnotations(\n            title=tool_title,\n            readOnlyHint=not can_edit,\n            destructiveHint=can_edit,\n        )\n\n        return MCPTool(\n            fn=execute_fn,\n            name=func_name,\n            description=func_doc,\n            parameters=parameters,\n            fn_metadata=func_arg_metadata,\n            is_async=is_async,\n            # keep the value in sync with the kwarg name in Tool.apply_ex. The mcp sdk uses reflection to infer this\n            # when the tool is constructed via from_function (which is a bit crazy IMO, but well...)\n            context_kwarg=\"mcp_ctx\",\n            annotations=annotations,\n            title=tool_title,\n        )\n\n    def _iter_tools(self) -> Iterator[Tool]:\n        assert self.agent is not None\n        yield from self.agent.get_exposed_tool_instances()\n\n    # noinspection PyProtectedMember\n    def _set_mcp_tools(self, mcp: FastMCP, openai_tool_compatible: bool = False) -> None:\n        \"\"\"Update the tools in the MCP server\"\"\"\n        if mcp is not None:\n            mcp._tool_manager._tools = {}\n            for tool in self._iter_tools():\n                mcp_tool = self.make_mcp_tool(tool, openai_tool_compatible=openai_tool_compatible)\n                mcp._tool_manager._tools[tool.get_name()] = mcp_tool\n            log.info(f\"Starting MCP server with {len(mcp._tool_manager._tools)} tools: {list(mcp._tool_manager._tools.keys())}\")\n\n    def _create_serena_agent(self, serena_config: SerenaConfig, modes: ModeSelectionDefinition | None = None) -> SerenaAgent:\n        return SerenaAgent(\n            project=self.project, serena_config=serena_config, context=self.context, modes=modes, memory_log_handler=self.memory_log_handler\n        )\n\n    def _create_default_serena_config(self) -> SerenaConfig:\n        return SerenaConfig.from_config_file()\n\n    def create_mcp_server(\n        self,\n        host: str = \"0.0.0.0\",\n        port: int = 8000,\n        modes: Sequence[str] = (),\n        language_backend: LanguageBackend | None = None,\n        enable_web_dashboard: bool | None = None,\n        enable_gui_log_window: bool | None = None,\n        open_web_dashboard: bool | None = None,\n        log_level: Literal[\"DEBUG\", \"INFO\", \"WARNING\", \"ERROR\", \"CRITICAL\"] | None = None,\n        trace_lsp_communication: bool | None = None,\n        tool_timeout: float | None = None,\n    ) -> FastMCP:\n        \"\"\"\n        Create an MCP server with process-isolated SerenaAgent to prevent asyncio contamination.\n\n        :param host: The host to bind to\n        :param port: The port to bind to\n        :param modes: List of mode names or paths to mode files\n        :param language_backend: the language backend to use, overriding the configuration setting.\n        :param enable_web_dashboard: Whether to enable the web dashboard. If not specified, will take the value from the serena configuration.\n        :param enable_gui_log_window: Whether to enable the GUI log window. It currently does not work on macOS, and setting this to True will be ignored then.\n            If not specified, will take the value from the serena configuration.\n        :param open_web_dashboard: Whether to open the web dashboard on launch.\n            If not specified, will take the value from the serena configuration.\n        :param log_level: Log level. If not specified, will take the value from the serena configuration.\n        :param trace_lsp_communication: Whether to trace the communication between Serena and the language servers.\n            This is useful for debugging language server issues.\n        :param tool_timeout: Timeout in seconds for tool execution. If not specified, will take the value from the serena configuration.\n        \"\"\"\n        try:\n            config = self._create_default_serena_config()\n\n            # update configuration with the provided parameters\n            if enable_web_dashboard is not None:\n                config.web_dashboard = enable_web_dashboard\n            if enable_gui_log_window is not None:\n                config.gui_log_window = enable_gui_log_window\n            if open_web_dashboard is not None:\n                config.web_dashboard_open_on_launch = open_web_dashboard\n            if log_level is not None:\n                log_level = cast(Literal[\"DEBUG\", \"INFO\", \"WARNING\", \"ERROR\", \"CRITICAL\"], log_level.upper())\n                config.log_level = logging.getLevelNamesMapping()[log_level]\n            if trace_lsp_communication is not None:\n                config.trace_lsp_communication = trace_lsp_communication\n            if tool_timeout is not None:\n                config.tool_timeout = tool_timeout\n            if language_backend is not None:\n                config.language_backend = language_backend\n\n            mode_selection_def: ModeSelectionDefinition | None = None\n            if modes:\n                mode_selection_def = ModeSelectionDefinition(default_modes=modes)\n            self.agent = self._create_serena_agent(config, mode_selection_def)\n\n        except Exception as e:\n            show_fatal_exception_safe(e)\n            raise\n\n        # Override model_config to disable the use of `.env` files for reading settings, because user projects are likely to contain\n        # `.env` files (e.g. containing LOG_LEVEL) that are not supposed to override the MCP settings;\n        # retain only FASTMCP_ prefix for already set environment variables.\n        Settings.model_config = SettingsConfigDict(env_prefix=\"FASTMCP_\")\n        instructions = self._get_initial_instructions()\n        mcp = FastMCP(lifespan=self.server_lifespan, host=host, port=port, instructions=instructions)\n        return mcp\n\n    @asynccontextmanager\n    async def server_lifespan(self, mcp_server: FastMCP) -> AsyncIterator[None]:\n        \"\"\"Manage server startup and shutdown lifecycle.\"\"\"\n        openai_tool_compatible = self.context.name in [\"chatgpt\", \"codex\", \"oaicompat-agent\"]\n        self._set_mcp_tools(mcp_server, openai_tool_compatible=openai_tool_compatible)\n        log.info(\"MCP server lifetime setup complete\")\n        yield\n        log.info(\"MCP server shutting down\")\n\n    def _get_initial_instructions(self) -> str:\n        assert self.agent is not None\n        return self.agent.create_system_prompt()\n"
  },
  {
    "path": "src/serena/project.py",
    "content": "import json\nimport logging\nimport os\nimport re\nimport shutil\nimport threading\nfrom collections.abc import Sequence\nfrom pathlib import Path\nfrom typing import TYPE_CHECKING, Any, Literal, Optional\n\nimport pathspec\nfrom sensai.util.logging import LogTime\nfrom sensai.util.string import TextBuilder, ToStringMixin\n\nfrom serena.config.serena_config import (\n    ProjectConfig,\n    SerenaConfig,\n    SerenaPaths,\n)\nfrom serena.constants import SERENA_FILE_ENCODING\nfrom serena.ls_manager import LanguageServerFactory, LanguageServerManager\nfrom serena.util.file_system import GitignoreParser, match_path\nfrom serena.util.text_utils import ContentReplacer, MatchedConsecutiveLines, search_files\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_utils import FileUtils\n\nif TYPE_CHECKING:\n    from serena.agent import SerenaAgent\n\nlog = logging.getLogger(__name__)\n\n\nclass MemoriesManager:\n    GLOBAL_TOPIC = \"global\"\n    _global_memory_dir = SerenaPaths().global_memories_path\n\n    def __init__(self, serena_data_folder: str | Path | None, read_only_memory_patterns: Sequence[str] = ()):\n        \"\"\"\n        :param serena_data_folder: the absolute path to the project's .serena data folder\n        :param read_only_memory_patterns: whether to allow writing global memories in tool execution contexts\n        \"\"\"\n        self._project_memory_dir: Path | None = None\n        if serena_data_folder is not None:\n            self._project_memory_dir = Path(serena_data_folder) / \"memories\"\n            self._project_memory_dir.mkdir(parents=True, exist_ok=True)\n        self._encoding = SERENA_FILE_ENCODING\n        self._read_only_memory_patterns = [re.compile(pattern) for pattern in set(read_only_memory_patterns)]\n\n    def _is_read_only_memory(self, name: str) -> bool:\n        for pattern in self._read_only_memory_patterns:\n            if pattern.fullmatch(name):\n                return True\n        return False\n\n    def _is_global(self, name: str) -> bool:\n        return name == self.GLOBAL_TOPIC or name.startswith(self.GLOBAL_TOPIC + \"/\")\n\n    def get_memory_file_path(self, name: str) -> Path:\n        # Strip .md extension if present\n        name = name.replace(\".md\", \"\")\n\n        if self._is_global(name):\n            if name == self.GLOBAL_TOPIC:\n                raise ValueError(\n                    f'Bare \"{self.GLOBAL_TOPIC}\" is not a valid memory name. '\n                    f'Use \"{self.GLOBAL_TOPIC}/<name>\" to address a global memory.'\n                )\n            # Strip \"global/\" prefix and resolve against global dir\n            sub_name = name[len(self.GLOBAL_TOPIC) + 1 :]\n            parts = sub_name.split(\"/\")\n            filename = f\"{parts[-1]}.md\"\n            if len(parts) > 1:\n                subdir = self._global_memory_dir / \"/\".join(parts[:-1])\n                subdir.mkdir(parents=True, exist_ok=True)\n                return subdir / filename\n            return self._global_memory_dir / filename\n\n        # Project-local memory\n        assert self._project_memory_dir is not None, \"Project dir was not passed at initialization\"\n        parts = name.split(\"/\")\n        filename = f\"{parts[-1]}.md\"\n\n        if len(parts) > 1:\n            # Create subdirectory path\n            subdir = self._project_memory_dir / \"/\".join(parts[:-1])\n            subdir.mkdir(parents=True, exist_ok=True)\n            return subdir / filename\n\n        return self._project_memory_dir / filename\n\n    def _check_write_access(self, name: str, is_tool_context: bool) -> None:\n        # in tool context, memories can be read-only\n        if is_tool_context and self._is_read_only_memory(name):\n            raise PermissionError(f\"Attempted to write to read_only memory: '{name}')\")\n\n    def load_memory(self, name: str) -> str:\n        memory_file_path = self.get_memory_file_path(name)\n        if not memory_file_path.exists():\n            return f\"Memory file {name} not found, consider creating it with the `write_memory` tool if you need it.\"\n        with open(memory_file_path, encoding=self._encoding) as f:\n            return f.read()\n\n    def save_memory(self, name: str, content: str, is_tool_context: bool) -> str:\n        self._check_write_access(name, is_tool_context)\n        memory_file_path = self.get_memory_file_path(name)\n        with open(memory_file_path, \"w\", encoding=self._encoding) as f:\n            f.write(content)\n        return f\"Memory {name} written.\"\n\n    class MemoriesList:\n        def __init__(self) -> None:\n            self.memories: list[str] = []\n            self.read_only_memories: list[str] = []\n\n        def __len__(self) -> int:\n            return len(self.memories) + len(self.read_only_memories)\n\n        def add(self, memory_name: str, is_read_only: bool) -> None:\n            if is_read_only:\n                self.read_only_memories.append(memory_name)\n            else:\n                self.memories.append(memory_name)\n\n        def extend(self, other: \"MemoriesManager.MemoriesList\") -> None:\n            self.memories.extend(other.memories)\n            self.read_only_memories.extend(other.read_only_memories)\n\n        def to_dict(self) -> dict[str, list[str]]:\n            result = {}\n            if self.memories:\n                result[\"memories\"] = sorted(self.memories)\n            if self.read_only_memories:\n                result[\"read_only_memories\"] = sorted(self.read_only_memories)\n            return result\n\n        def get_full_list(self) -> list[str]:\n            return sorted(self.memories + self.read_only_memories)\n\n    def _list_memories(self, search_dir: Path, base_dir: Path, prefix: str = \"\") -> MemoriesList:\n        result = self.MemoriesList()\n        if not search_dir.exists():\n            return result\n        for md_file in search_dir.rglob(\"*.md\"):\n            rel = str(md_file.relative_to(base_dir).with_suffix(\"\")).replace(os.sep, \"/\")\n            memory_name = prefix + rel\n            result.add(memory_name, is_read_only=self._is_read_only_memory(memory_name))\n        return result\n\n    def list_global_memories(self, subtopic: str = \"\") -> MemoriesList:\n        dir_path = self._global_memory_dir\n        if subtopic:\n            dir_path = dir_path / subtopic.replace(\"/\", os.sep)\n        return self._list_memories(dir_path, self._global_memory_dir, self.GLOBAL_TOPIC + \"/\")\n\n    def list_project_memories(self, topic: str = \"\") -> MemoriesList:\n        assert self._project_memory_dir is not None, \"Project dir was not passed at initialization\"\n        dir_path = self._project_memory_dir\n        if topic:\n            dir_path = dir_path / topic.replace(\"/\", os.sep)\n        return self._list_memories(dir_path, self._project_memory_dir)\n\n    def list_memories(self, topic: str = \"\") -> MemoriesList:\n        \"\"\"\n        Lists all memories, optionally filtered by topic.\n        If the topic is omitted, both global and project-specific memories are returned.\n        \"\"\"\n        memories: MemoriesManager.MemoriesList\n\n        if topic:\n            if self._is_global(topic):\n                topic_parts = topic.split(\"/\")\n                subtopic = \"/\".join(topic_parts[1:])\n                memories = self.list_global_memories(subtopic=subtopic)\n            else:\n                memories = self.list_project_memories(topic=topic)\n        else:\n            memories = self.list_project_memories()\n            memories.extend(self.list_global_memories())\n\n        return memories\n\n    def delete_memory(self, name: str, is_tool_context: bool) -> str:\n        self._check_write_access(name, is_tool_context)\n        memory_file_path = self.get_memory_file_path(name)\n        if not memory_file_path.exists():\n            return f\"Memory {name} not found.\"\n        memory_file_path.unlink()\n        return f\"Memory {name} deleted.\"\n\n    def move_memory(self, old_name: str, new_name: str, is_tool_context: bool) -> str:\n        \"\"\"\n        Rename or move a memory file.\n        Moving between global and project scope (e.g. \"global/foo\" -> \"bar\") is supported.\n        \"\"\"\n        self._check_write_access(new_name, is_tool_context)\n\n        old_path = self.get_memory_file_path(old_name)\n        new_path = self.get_memory_file_path(new_name)\n\n        if not old_path.exists():\n            raise FileNotFoundError(f\"Memory {old_name} not found.\")\n        if new_path.exists():\n            raise FileExistsError(f\"Memory {new_name} already exists.\")\n\n        new_path.parent.mkdir(parents=True, exist_ok=True)\n        shutil.move(old_path, new_path)\n\n        return f\"Memory renamed from {old_name} to {new_name}.\"\n\n    def edit_memory(\n        self, name: str, needle: str, repl: str, mode: Literal[\"literal\", \"regex\"], allow_multiple_occurrences: bool, is_tool_context: bool\n    ) -> str:\n        \"\"\"\n        Edit a memory by replacing content matching a pattern.\n\n        :param name: the memory name\n        :param needle: the string or regex to search for\n        :param repl: the replacement string\n        :param mode: \"literal\" or \"regex\"\n        :param allow_multiple_occurrences:\n        \"\"\"\n        self._check_write_access(name, is_tool_context)\n        memory_file_path = self.get_memory_file_path(name)\n        if not memory_file_path.exists():\n            raise FileNotFoundError(f\"Memory {name} not found.\")\n        with open(memory_file_path, encoding=self._encoding) as f:\n            original_content = f.read()\n        replacer = ContentReplacer(mode=mode, allow_multiple_occurrences=allow_multiple_occurrences)\n        updated_content = replacer.replace(original_content, needle, repl)\n        with open(memory_file_path, \"w\", encoding=self._encoding) as f:\n            f.write(updated_content)\n        return f\"Memory {name} edited successfully.\"\n\n\nclass Project(ToStringMixin):\n    def __init__(\n        self,\n        *,\n        project_root: str,\n        project_config: ProjectConfig,\n        serena_config: SerenaConfig,\n        is_newly_created: bool = False,\n    ):\n        assert serena_config is not None\n        self.project_root = project_root\n        self.project_config = project_config\n        self.serena_config = serena_config\n        self._serena_data_folder = serena_config.get_project_serena_folder(self.project_root)\n        log.info(\"Serena project data folder: %s\", self._serena_data_folder)\n\n        read_only_memory_patterns = serena_config.read_only_memory_patterns + project_config.read_only_memory_patterns\n        self.memories_manager = MemoriesManager(self._serena_data_folder, read_only_memory_patterns=read_only_memory_patterns)\n\n        # resolve line ending (project -> global)\n        self.line_ending = project_config.line_ending or serena_config.line_ending\n\n        self.language_server_manager: LanguageServerManager | None = None\n        self._language_server_manager_init_error: Exception | None = None\n        self._is_newly_created = is_newly_created\n        self._agent: Optional[\"SerenaAgent\"] = None\n\n        # create .gitignore file in the project's Serena data folder if not yet present\n        serena_data_gitignore_path = os.path.join(self._serena_data_folder, \".gitignore\")\n        if not os.path.exists(serena_data_gitignore_path):\n            os.makedirs(os.path.dirname(serena_data_gitignore_path), exist_ok=True)\n            log.info(f\"Creating .gitignore file in {serena_data_gitignore_path}\")\n            with open(serena_data_gitignore_path, \"w\", encoding=\"utf-8\") as f:\n                f.write(f\"/{SolidLanguageServer.CACHE_FOLDER_NAME}\\n\")\n                f.write(f\"/{ProjectConfig.SERENA_LOCAL_PROJECT_FILE}\\n\")\n\n        # prepare ignore spec asynchronously, ensuring immediate project activation.\n        self.__ignored_patterns: list[str]\n        self.__ignore_spec: pathspec.PathSpec\n        self._ignore_spec_available = threading.Event()\n        threading.Thread(name=f\"gather-ignorespec[{self.project_config.project_name}]\", target=self._gather_ignorespec, daemon=True).start()\n\n    def _gather_ignorespec(self) -> None:\n        with LogTime(f\"Gathering ignore spec for project {self.project_config.project_name}\", logger=log):\n\n            # gather ignored paths from the global configuration, project configuration, and gitignore files\n            global_ignored_paths = self.serena_config.ignored_paths\n            ignored_patterns = list(global_ignored_paths) + list(self.project_config.ignored_paths)\n            if len(global_ignored_paths) > 0:\n                log.info(f\"Using {len(global_ignored_paths)} ignored paths from the global configuration.\")\n                log.debug(f\"Global ignored paths: {list(global_ignored_paths)}\")\n            if len(self.project_config.ignored_paths) > 0:\n                log.info(f\"Using {len(self.project_config.ignored_paths)} ignored paths from the project configuration.\")\n                log.debug(f\"Project ignored paths: {self.project_config.ignored_paths}\")\n            log.debug(f\"Combined ignored patterns: {ignored_patterns}\")\n            if self.project_config.ignore_all_files_in_gitignore:\n                gitignore_parser = GitignoreParser(self.project_root)\n                for spec in gitignore_parser.get_ignore_specs():\n                    log.debug(f\"Adding {len(spec.patterns)} patterns from {spec.file_path} to the ignored paths.\")\n                    ignored_patterns.extend(spec.patterns)\n            self.__ignored_patterns = ignored_patterns\n\n            # Set up the pathspec matcher for the ignored paths\n            # for all absolute paths in ignored_paths, convert them to relative paths\n            processed_patterns = []\n            for pattern in ignored_patterns:\n                # Normalize separators (pathspec expects forward slashes)\n                pattern = pattern.replace(os.path.sep, \"/\")\n                processed_patterns.append(pattern)\n            log.debug(f\"Processing {len(processed_patterns)} ignored paths\")\n            self.__ignore_spec = pathspec.PathSpec.from_lines(pathspec.patterns.GitWildMatchPattern, processed_patterns)\n\n        self._ignore_spec_available.set()\n\n    def _tostring_includes(self) -> list[str]:\n        return []\n\n    def _tostring_additional_entries(self) -> dict[str, Any]:\n        return {\"root\": self.project_root, \"name\": self.project_name}\n\n    def set_agent(self, agent: \"SerenaAgent\") -> None:\n        self._agent = agent\n\n    @property\n    def project_name(self) -> str:\n        return self.project_config.project_name\n\n    @classmethod\n    def load(\n        cls,\n        project_root: str | Path,\n        serena_config: \"SerenaConfig\",\n        autogenerate: bool = True,\n    ) -> \"Project\":\n        assert serena_config is not None\n        project_root = Path(project_root).resolve()\n        if not project_root.exists():\n            raise FileNotFoundError(f\"Project root not found: {project_root}\")\n        project_config = ProjectConfig.load(project_root, serena_config=serena_config, autogenerate=autogenerate)\n        return Project(project_root=str(project_root), project_config=project_config, serena_config=serena_config)\n\n    def save_config(self) -> None:\n        \"\"\"\n        Saves the current project configuration to disk.\n        \"\"\"\n        self.project_config.save(self.path_to_project_yml())\n\n    def path_to_serena_data_folder(self) -> str:\n        return self._serena_data_folder\n\n    def path_to_project_yml(self) -> str:\n        return self.serena_config.get_project_yml_location(self.project_root)\n\n    def get_activation_message(self) -> str:\n        \"\"\"\n        :return: a message providing information about the project upon activation (e.g. programming language, memories, initial prompt)\n        \"\"\"\n        if self._is_newly_created:\n            msg = f\"Created and activated a new project with name '{self.project_name}' at {self.project_root}. \"\n        else:\n            msg = f\"The project with name '{self.project_name}' at {self.project_root} is activated.\"\n        languages_str = \", \".join([lang.value for lang in self.project_config.languages])\n        msg += f\"\\nProgramming languages: {languages_str}; file encoding: {self.project_config.encoding}\"\n        project_memories = self.memories_manager.list_project_memories()\n        if project_memories:\n            msg += (\n                f\"\\nAvailable project memories: {json.dumps(project_memories.to_dict())}\\n\"\n                + \"Use the `read_memory` tool to read these memories later if they are relevant to the task.\"\n            )\n        if self.project_config.initial_prompt:\n            msg += f\"\\nAdditional project-specific instructions:\\n {self.project_config.initial_prompt}\"\n        return msg\n\n    def read_file(self, relative_path: str) -> str:\n        \"\"\"\n        Reads a file relative to the project root.\n\n        :param relative_path: the path to the file relative to the project root\n        :return: the content of the file\n        \"\"\"\n        abs_path = Path(self.project_root) / relative_path\n        return FileUtils.read_file(str(abs_path), self.project_config.encoding)\n\n    @property\n    def _ignore_spec(self) -> pathspec.PathSpec:\n        \"\"\"\n        :return: the pathspec matcher for the paths that were configured to be ignored,\n            either explicitly or implicitly through .gitignore files.\n        \"\"\"\n        if not self._ignore_spec_available.is_set():\n            log.info(\"Waiting for ignore spec to become available ...\")\n            self._ignore_spec_available.wait()\n            log.info(\"Ignore spec is now available for project; proceeding\")\n        return self.__ignore_spec\n\n    @property\n    def _ignored_patterns(self) -> list[str]:\n        \"\"\"\n        :return: the list of ignored path patterns\n        \"\"\"\n        if not self._ignore_spec_available.is_set():\n            log.info(\"Waiting for ignored patterns to become available ...\")\n            self._ignore_spec_available.wait()\n            log.info(\"Ignore patterns are now available for project; proceeding\")\n        return self.__ignored_patterns\n\n    def _is_ignored_relative_path(self, relative_path: str | Path, ignore_non_source_files: bool = True) -> bool:\n        \"\"\"\n        Determine whether an existing path should be ignored based on file type and ignore patterns.\n        Raises `FileNotFoundError` if the path does not exist.\n\n        :param relative_path: Relative path to check\n        :param ignore_non_source_files: whether files that are not source files (according to the file masks\n            determined by the project's programming language) shall be ignored\n\n        :return: whether the path should be ignored\n        \"\"\"\n        # special case, never ignore the project root itself\n        # If the user ignores hidden files, \".\" might match against the corresponding PathSpec pattern.\n        # The empty string also points to the project root and should never be ignored.\n        if str(relative_path) in [\".\", \"\"]:\n            return False\n\n        abs_path = os.path.join(self.project_root, relative_path)\n        if not os.path.exists(abs_path):\n            raise FileNotFoundError(f\"File {abs_path} not found, the ignore check cannot be performed\")\n\n        # Check file extension if it's a file\n        is_file = os.path.isfile(abs_path)\n        if is_file and ignore_non_source_files:\n            is_file_in_supported_language = False\n            for language in self.project_config.languages:\n                fn_matcher = language.get_source_fn_matcher()\n                if fn_matcher.is_relevant_filename(abs_path):\n                    is_file_in_supported_language = True\n                    break\n            if not is_file_in_supported_language:\n                return True\n\n        # Create normalized path for consistent handling\n        rel_path = Path(relative_path)\n\n        # always ignore paths inside .git\n        if len(rel_path.parts) > 0 and rel_path.parts[0] == \".git\":\n            return True\n\n        return match_path(str(relative_path), self._ignore_spec, root_path=self.project_root)\n\n    def is_ignored_path(self, path: str | Path, ignore_non_source_files: bool = False) -> bool:\n        \"\"\"\n        Checks whether the given path is ignored\n\n        :param path: the path to check, can be absolute or relative\n        :param ignore_non_source_files: whether to ignore files that are not source files\n            (according to the file masks determined by the project's programming language)\n        \"\"\"\n        path = Path(path)\n        if path.is_absolute():\n            try:\n                relative_path = path.relative_to(self.project_root)\n            except ValueError:\n                # If the path is not relative to the project root, we consider it as an absolute path outside the project\n                # (which we ignore)\n                log.warning(f\"Path {path} is not relative to the project root {self.project_root} and was therefore ignored\")\n                return True\n        else:\n            relative_path = path\n\n        return self._is_ignored_relative_path(str(relative_path), ignore_non_source_files=ignore_non_source_files)\n\n    def is_path_in_project(self, path: str | Path) -> bool:\n        \"\"\"\n        Checks if the given (absolute or relative) path is inside the project directory.\n\n        Note: This is intended to catch cases where \"..\" segments would lead outside of the project directory,\n        but we intentionally allow symlinks, as the assumption is that they point to relevant project files.\n        \"\"\"\n        if not os.path.isabs(path):\n            path = os.path.join(self.project_root, path)\n\n        # collapse any \"..\" or \".\" segments (purely lexically)\n        path = os.path.normpath(path)\n\n        try:\n            return os.path.commonpath([self.project_root, path]) == self.project_root\n        except ValueError:\n            # occurs, in particular, if paths are on different drives on Windows\n            return False\n\n    def relative_path_exists(self, relative_path: str) -> bool:\n        \"\"\"\n        Checks if the given relative path exists in the project directory.\n\n        :param relative_path: the path to check, relative to the project root\n        :return: True if the path exists, False otherwise\n        \"\"\"\n        abs_path = Path(self.project_root) / relative_path\n        return abs_path.exists()\n\n    def validate_relative_path(self, relative_path: str, require_not_ignored: bool = False) -> None:\n        \"\"\"\n        Validates that the given relative path to an existing file/dir is safe to read or edit,\n        meaning it's inside the project directory.\n\n        Passing a path to a non-existing file will lead to a `FileNotFoundError`.\n\n        :param relative_path: the path to validate, relative to the project root\n        :param require_not_ignored: if True, the path must not be ignored according to the project's ignore settings\n        \"\"\"\n        if not self.is_path_in_project(relative_path):\n            raise ValueError(f\"{relative_path=} points to path outside of the repository root; cannot access for safety reasons\")\n\n        if require_not_ignored:\n            if self.is_ignored_path(relative_path):\n                raise ValueError(f\"Path {relative_path} is ignored; cannot access for safety reasons\")\n\n    def gather_source_files(self, relative_path: str = \"\") -> list[str]:\n        \"\"\"Retrieves relative paths of all source files, optionally limited to the given path\n\n        :param relative_path: if provided, restrict search to this path\n        \"\"\"\n        rel_file_paths = []\n        start_path = os.path.join(self.project_root, relative_path)\n        if not os.path.exists(start_path):\n            raise FileNotFoundError(f\"Relative path {start_path} not found.\")\n        if os.path.isfile(start_path):\n            return [relative_path]\n        else:\n            for root, dirs, files in os.walk(start_path, followlinks=True):\n                # prevent recursion into ignored directories\n                dirs[:] = [d for d in dirs if not self.is_ignored_path(os.path.join(root, d))]\n\n                # collect non-ignored files\n                for file in files:\n                    abs_file_path = os.path.join(root, file)\n                    try:\n                        if not self.is_ignored_path(abs_file_path, ignore_non_source_files=True):\n                            try:\n                                rel_file_path = os.path.relpath(abs_file_path, start=self.project_root)\n                            except Exception:\n                                log.warning(\n                                    \"Ignoring path '%s' because it appears to be outside of the project root (%s)\",\n                                    abs_file_path,\n                                    self.project_root,\n                                )\n                                continue\n                            rel_file_paths.append(rel_file_path)\n                    except FileNotFoundError:\n                        log.warning(\n                            f\"File {abs_file_path} not found (possibly due it being a symlink), skipping it in request_parsed_files\",\n                        )\n            return rel_file_paths\n\n    def search_source_files_for_pattern(\n        self,\n        pattern: str,\n        relative_path: str = \"\",\n        context_lines_before: int = 0,\n        context_lines_after: int = 0,\n        paths_include_glob: str | None = None,\n        paths_exclude_glob: str | None = None,\n    ) -> list[MatchedConsecutiveLines]:\n        \"\"\"\n        Search for a pattern across all (non-ignored) source files\n\n        :param pattern: Regular expression pattern to search for, either as a compiled Pattern or string\n        :param relative_path:\n        :param context_lines_before: Number of lines of context to include before each match\n        :param context_lines_after: Number of lines of context to include after each match\n        :param paths_include_glob: Glob pattern to filter which files to include in the search\n        :param paths_exclude_glob: Glob pattern to filter which files to exclude from the search. Takes precedence over paths_include_glob.\n        :return: List of matched consecutive lines with context\n        \"\"\"\n        relative_file_paths = self.gather_source_files(relative_path=relative_path)\n        return search_files(\n            relative_file_paths,\n            pattern,\n            root_path=self.project_root,\n            file_reader=self.read_file,\n            context_lines_before=context_lines_before,\n            context_lines_after=context_lines_after,\n            paths_include_glob=paths_include_glob,\n            paths_exclude_glob=paths_exclude_glob,\n        )\n\n    def retrieve_content_around_line(\n        self, relative_file_path: str, line: int, context_lines_before: int = 0, context_lines_after: int = 0\n    ) -> MatchedConsecutiveLines:\n        \"\"\"\n        Retrieve the content of the given file around the given line.\n\n        :param relative_file_path: The relative path of the file to retrieve the content from\n        :param line: The line number to retrieve the content around\n        :param context_lines_before: The number of lines to retrieve before the given line\n        :param context_lines_after: The number of lines to retrieve after the given line\n\n        :return MatchedConsecutiveLines: A container with the desired lines.\n        \"\"\"\n        file_contents = self.read_file(relative_file_path)\n        return MatchedConsecutiveLines.from_file_contents(\n            file_contents,\n            line=line,\n            context_lines_before=context_lines_before,\n            context_lines_after=context_lines_after,\n            source_file_path=relative_file_path,\n        )\n\n    def create_language_server_manager(self) -> LanguageServerManager:\n        \"\"\"\n        Creates the language server manager for the project, starting one language server per configured programming language.\n\n        :return: the language server manager, which is also stored in the project instance\n        \"\"\"\n        try:\n            # determine timeout to use for LS calls\n            tool_timeout = self.serena_config.tool_timeout\n            if tool_timeout is None or tool_timeout < 0:\n                ls_timeout = None\n            else:\n                if tool_timeout < 10:\n                    raise ValueError(f\"Tool timeout must be at least 10 seconds, but is {tool_timeout} seconds\")\n                ls_timeout = tool_timeout - 5  # the LS timeout is for a single call, it should be smaller than the tool timeout\n\n            # if there is an existing instance, stop its language servers first\n            if self.language_server_manager is not None:\n                log.info(\"Stopping existing language server manager ...\")\n                self.language_server_manager.stop_all()\n                self.language_server_manager = None\n\n            log.info(f\"Creating language server manager for {self.project_root}\")\n            self._language_server_manager_init_error = None\n            factory = LanguageServerFactory(\n                project_root=self.project_root,\n                project_data_path=self._serena_data_folder,\n                encoding=self.project_config.encoding,\n                ignored_patterns=self._ignored_patterns,\n                ls_timeout=ls_timeout,\n                ls_specific_settings=self.serena_config.ls_specific_settings,\n                trace_lsp_communication=self.serena_config.trace_lsp_communication,\n            )\n            self.language_server_manager = LanguageServerManager.from_languages(self.project_config.languages, factory)\n            return self.language_server_manager\n        except Exception as e:\n            self._language_server_manager_init_error = e\n            raise\n\n    def get_language_server_manager_or_raise(self) -> LanguageServerManager:\n        if self.language_server_manager is None:\n            msg = TextBuilder(\"The language server manager is not initialized, indicating a problem during project initialisation.\")\n            if self._language_server_manager_init_error is not None:\n                msg.with_text(str(self._language_server_manager_init_error))\n            if self._agent is not None:\n                msg.with_text(\"For details, please check the logs. \" + self._agent.get_log_inspection_instructions())\n            msg.with_text(\n                \"IMPORTANT: Stop, do not attempt workarounds. Inform the user and wait for further instructions before you continue!\"\n            )\n            raise Exception(msg.build())\n        return self.language_server_manager\n\n    def add_language(self, language: Language) -> None:\n        \"\"\"\n        Adds a new programming language to the project configuration, starting the corresponding\n        language server instance if the LS manager is active.\n        The project configuration is saved to disk after adding the language.\n\n        :param language: the programming language to add\n        \"\"\"\n        if language in self.project_config.languages:\n            log.info(f\"Language {language.value} is already present in the project configuration.\")\n            return\n\n        # start the language server (if the LS manager is active)\n        if self.language_server_manager is None:\n            log.info(\"Language server manager is not active; skipping language server startup for the new language.\")\n        else:\n            log.info(\"Adding and starting the language server for new language %s ...\", language.value)\n            self.language_server_manager.add_language_server(language)\n\n        # update the project configuration\n        self.project_config.languages.append(language)\n        self.save_config()\n\n    def remove_language(self, language: Language) -> None:\n        \"\"\"\n        Removes a programming language from the project configuration, stopping the corresponding\n        language server instance if the LS manager is active.\n        The project configuration is saved to disk after removing the language.\n\n        :param language: the programming language to remove\n        \"\"\"\n        if language not in self.project_config.languages:\n            log.info(f\"Language {language.value} is not present in the project configuration.\")\n            return\n        # update the project configuration\n        self.project_config.languages.remove(language)\n        self.save_config()\n\n        # stop the language server (if the LS manager is active)\n        if self.language_server_manager is None:\n            log.info(\"Language server manager is not active; skipping language server shutdown for the removed language.\")\n        else:\n            log.info(\"Removing and stopping the language server for language %s ...\", language.value)\n            self.language_server_manager.remove_language_server(language)\n\n    def shutdown(self, timeout: float = 2.0) -> None:\n        if self.language_server_manager is not None:\n            self.language_server_manager.stop_all(save_cache=True, timeout=timeout)\n            self.language_server_manager = None\n"
  },
  {
    "path": "src/serena/project_server.py",
    "content": "import json\nimport logging\nfrom typing import TYPE_CHECKING\n\nimport requests as requests_lib\nfrom flask import Flask, request\nfrom pydantic import BaseModel\nfrom sensai.util.logging import LogTime\n\nfrom serena.config.serena_config import LanguageBackend, SerenaConfig\nfrom serena.jetbrains.jetbrains_plugin_client import JetBrainsPluginClient\n\nif TYPE_CHECKING:\n    from serena.project import Project\n\nlog = logging.getLogger(__name__)\n\n# disable Werkzeug's logging to avoid cluttering the output\nlogging.getLogger(\"werkzeug\").setLevel(logging.WARNING)\n\n\nclass QueryProjectRequest(BaseModel):\n    \"\"\"\n    Request model for the /query_project endpoint, matching the interface of\n    :class:`~serena.tools.query_project_tools.QueryProjectTool`.\n    \"\"\"\n\n    project_name: str\n    tool_name: str\n    tool_params_json: str\n\n\nclass ProjectServer:\n    \"\"\"\n    A lightweight Flask server that exposes a SerenaAgent's project querying\n    capabilities via HTTP, using the LSP language server backend for symbolic retrieval.\n\n    Projects are loaded on demand when a query is made for them, and cached in memory for subsequent queries.\n\n    The server instantiates a :class:`SerenaAgent` with default options and\n    provides a ``/query_project`` endpoint whose interface matches\n    :class:`~serena.tools.query_project_tools.QueryProjectTool`.\n    \"\"\"\n\n    PORT = JetBrainsPluginClient.BASE_PORT - 1\n\n    def __init__(self) -> None:\n        from serena.agent import SerenaAgent\n\n        serena_config = SerenaConfig.from_config_file()\n        serena_config.gui_log_window = False\n        serena_config.web_dashboard = False\n        serena_config.language_backend = LanguageBackend.LSP\n\n        self._agent = SerenaAgent(serena_config=serena_config)\n        self._loaded_projects_by_name: dict[str, \"Project\"] = {}\n\n        # create the Flask application\n        self._app = Flask(__name__)\n        self._setup_routes()\n\n    def _setup_routes(self) -> None:\n        @self._app.route(\"/heartbeat\", methods=[\"GET\"])\n        def heartbeat() -> dict[str, str]:\n            return {\"status\": \"alive\"}\n\n        @self._app.route(\"/query_project\", methods=[\"POST\"])\n        def query_project() -> str:\n            query_request = QueryProjectRequest.model_validate(request.get_json())\n            return self._query_project(query_request)\n\n    def _get_project(self, project_name: str) -> \"Project\":\n        \"\"\"Gets the project with the given name, loading it if necessary.\"\"\"\n        if project_name in self._loaded_projects_by_name:\n            return self._loaded_projects_by_name[project_name]\n        else:\n            serena_config = self._agent.serena_config\n            registered_project = serena_config.get_registered_project(project_name)\n            if registered_project is None:\n                raise ValueError(f\"Project '{project_name}' is not registered with Serena.\")\n            with LogTime(f\"Loading project '{project_name}'\"):\n                project = registered_project.get_project_instance(serena_config)\n                project.create_language_server_manager()\n            self._loaded_projects_by_name[project_name] = project\n            return project\n\n    def _query_project(self, req: QueryProjectRequest) -> str:\n        \"\"\"Handle a /query_project request by invoking the agent on the specified project and tool.\"\"\"\n        project = self._get_project(req.project_name)\n        with self._agent.active_project_context(project):\n            tool = self._agent.get_tool_by_name(req.tool_name)\n            params = json.loads(req.tool_params_json)\n            return tool.apply_ex(**params)\n\n    def run(self, host: str = \"127.0.0.1\", port: int = PORT) -> int:\n        \"\"\"Run the server on the given host and port.\n\n        :param host: the host address to listen on.\n        :param port: the port to listen on.\n        :return: the port number the server is running on.\n        \"\"\"\n        from flask import cli\n\n        # suppress the default Flask startup banner\n        cli.show_server_banner = lambda *args, **kwargs: None\n\n        self._app.run(host=host, port=port, debug=False, use_reloader=False, threaded=True)\n        return port\n\n\nclass ProjectServerClient:\n    \"\"\"Client for interacting with a running :class:`ProjectServer`.\n\n    Upon instantiation, the client verifies that the server is reachable\n    by sending a heartbeat request. If the server is not running, a\n    :class:`ConnectionError` is raised.\n    \"\"\"\n\n    def __init__(self, host: str = \"127.0.0.1\", port: int = ProjectServer.PORT, timeout: int = 300) -> None:\n        \"\"\"\n        :param host: the host address of the project server.\n        :param port: the port of the project server.\n        :raises ConnectionError: if the project server is not reachable.\n        \"\"\"\n        self._base_url = f\"http://{host}:{port}\"\n        self._timeout = timeout\n\n        # verify that the server is running\n        try:\n            response = requests_lib.get(f\"{self._base_url}/heartbeat\", timeout=5)\n            response.raise_for_status()\n        except requests_lib.ConnectionError:\n            raise ConnectionError(f\"ProjectServer is not reachable at {self._base_url}. Make sure the server is running.\")\n        except requests_lib.RequestException as e:\n            raise ConnectionError(f\"ProjectServer health check failed: {e}\")\n\n    def query_project(self, project_name: str, tool_name: str, tool_params_json: str) -> str:\n        \"\"\"\n        Query a project by executing a Serena tool in its context.\n\n        The interface matches :meth:`QueryProjectTool.apply\n        <serena.tools.query_project_tools.QueryProjectTool.apply>`.\n\n        :param project_name: the name of the project to query.\n        :param tool_name: the name of the tool to execute. The tool must be read-only.\n        :param tool_params_json: the parameters to pass to the tool, encoded as a JSON string.\n        :return: the tool's result as a string.\n        \"\"\"\n        payload = QueryProjectRequest(\n            project_name=project_name,\n            tool_name=tool_name,\n            tool_params_json=tool_params_json,\n        ).model_dump()\n\n        response = requests_lib.post(f\"{self._base_url}/query_project\", json=payload, timeout=self._timeout)\n        response.raise_for_status()\n        return response.text\n"
  },
  {
    "path": "src/serena/prompt_factory.py",
    "content": "import os\n\nfrom serena.config.serena_config import SerenaPaths\nfrom serena.constants import PROMPT_TEMPLATES_DIR_INTERNAL\nfrom serena.generated.generated_prompt_factory import PromptFactory\n\n\nclass SerenaPromptFactory(PromptFactory):\n    \"\"\"\n    A class for retrieving and rendering prompt templates and prompt lists.\n    \"\"\"\n\n    def __init__(self) -> None:\n        user_templates_dir = SerenaPaths().user_prompt_templates_dir\n        os.makedirs(user_templates_dir, exist_ok=True)\n        super().__init__(prompts_dir=[user_templates_dir, PROMPT_TEMPLATES_DIR_INTERNAL])\n"
  },
  {
    "path": "src/serena/resources/config/contexts/agent.yml",
    "content": "description: Agent context where the system prompt (initial instructions) are provided at startup\nprompt: |\n  You are running in an agent context.\nexcluded_tools:\n  - initial_instructions\n\ntool_description_overrides: {}"
  },
  {
    "path": "src/serena/resources/config/contexts/chatgpt.yml",
    "content": "description: A configuration specific for ChatGPT, which has a limit of 30 tools and requires short descriptions.\nprompt: |\n  You are running in desktop app context where the tools give you access to the code base as well as some\n  access to the file system, if configured. You interact with the user through a chat interface that is separated\n  from the code base. As a consequence, if you are in interactive mode, your communication with the user should\n  involve high-level thinking and planning as well as some summarization of any code edits that you make.\n  For viewing the code edits the user will view them in a separate code editor window, and the back-and-forth\n  between the chat and the code editor should be minimized as well as facilitated by you.\n  If complex changes have been made, advise the user on how to review them in the code editor.\n  If complex relationships that the user asked for should be visualized or explained, consider creating\n  a diagram in addition to your text-based communication. Note that in the chat interface you have various rendering\n  options for text, html, and mermaid diagrams, as has been explained to you in your initial instructions.\nexcluded_tools: []\nincluded_optional_tools:\n  - switch_modes\n\ntool_description_overrides:\n  find_symbol: |\n    Retrieves symbols matching `name_path_pattern` in a file.\n    Use `depth > 0` to include children. `name_path_pattern` can be: \"foo\": any symbol named \"foo\"; \"foo/bar\": \"bar\" within \"foo\"; \"/foo/bar\": only top-level \"foo/bar\"\n  replace_content: |\n    Replaces content in files. Preferred for smaller edits where symbol-level tools aren't appropriate.\n    Use mode \"regex\" with wildcards (.*?) to match large sections efficiently: \"beginning.*?end\" instead of specifying exact content.\n    Essential for multi-line replacements.\n  search_for_pattern: |\n    Flexible pattern search across codebase. Prefer symbolic operations when possible.\n    Uses DOTALL matching. Use non-greedy quantifiers (.*?) to avoid over-matching.\n    Supports file filtering via globs and code-only restriction."
  },
  {
    "path": "src/serena/resources/config/contexts/claude-code.yml",
    "content": "description: Claude Code (CLI agent where file operations, basic edits, etc. are already covered; single project mode)\nprompt: |\n  You are running in a CLI coding agent context where file operations, basic (line-based) edits and reads \n  as well as shell commands are handled by your own, internal tools.\n  \n  If Serena's tools can be used to achieve your task, you should prioritize them.\n  In particular, it is important that you avoid reading entire source code files unless it is strictly necessary!\n  Instead, for exploring and reading code in a token-efficient manner, use Serena's overview and symbolic search tools.\n  For non-code files or for reads where you don't know the symbol's name path, you can use the pattern search tool.\n\nexcluded_tools:\n  - create_text_file\n  - read_file\n  - execute_shell_command\n  - prepare_for_new_conversation\n  - replace_content\n\ntool_description_overrides: {}\n\n# whether to assume that Serena shall only work on a single project in this context (provided that a project is given\n# when Serena is started).\n# If set to true and a project is provided at startup, the set of tools is limited to those required by the project's\n# concrete configuration, and other tools are excluded completely, allowing the set of tools to be minimal.\n# Tools explicitly disabled by the project will not be available at all.\n# The `activate_project` tool is always disabled in this case, as project switching cannot be allowed.\nsingle_project: true\n"
  },
  {
    "path": "src/serena/resources/config/contexts/codex.yml",
    "content": "description: Codex Non-symbolic editing tools and general shell tool are excluded\nprompt: |\n  You are running in the Codex IDE assistant mode, where file operations, basic (line-based) edits and reads \n  as well as shell commands are handled by your own, internal tools.\n  Don't attempt to use any excluded tools; instead, rely on your own internal tools for basic file or shell operations.\n  \n  If Serena's tools can be used to achieve your task, you should prioritize them. \n  In particular, it is important that you avoid reading entire source code files unless it is strictly necessary! \n  Instead, for exploring and reading code in a token-efficient manner, use Serena's overview and symbolic search tools. \n  For non-code files or for reads where you don't know the symbol's name path, you can use the pattern search tool.\n\nexcluded_tools:\n  - create_text_file\n  - read_file\n  - execute_shell_command\n  - prepare_for_new_conversation\n  - replace_content\n\n\ntool_description_overrides: {}\n\n"
  },
  {
    "path": "src/serena/resources/config/contexts/context.template.yml",
    "content": "# See Serena's documentation for more details on concept of contexts.\ndescription: Description of the context, not used in the code.\nprompt: Prompt that will form part of the system prompt/initial instructions for agents started in this context.\nexcluded_tools: []\n\n# several tools are excluded by default and have to be explicitly included by the user\nincluded_optional_tools: []\n\n# mapping of tool names to an override of their descriptions (the default description is the docstring of the Tool's apply method).\n# Sometimes, tool descriptions are too long (e.g., for ChatGPT), or users may want to override them for another reason.\ntool_description_overrides: {}\n\n# whether to assume that Serena shall only work on a single project in this context (provided that a project is given\n# when Serena is started).\n# If set to true and a project is provided at startup, the set of tools is limited to those required by the project's\n# concrete configuration, and other tools are excluded completely, allowing the set of tools to be minimal.\n# The `activate_project` tool will, therefore, be disabled in this case, as project switching is not allowed.\nsingle_project: false"
  },
  {
    "path": "src/serena/resources/config/contexts/desktop-app.yml",
    "content": "description: Desktop application context (chat application detached from code) where Serena's full toolset is provided\nprompt: |\n  You are running in a desktop application context.\n  Serena's tools give you access to the code base as well as some access to the file system (if enabled). \n  You interact with the user through a chat interface that is separated from the code base. \n  As a consequence, if you are in interactive mode, your communication with the user should\n  involve high-level thinking and planning as well as some summarization of any code edits that you make.\n  To view the code edits you make, the user will have switch to a separate application.\n  To illustrate complex relationships, consider creating diagrams in addition to your text-based communication\n  (depending on the options for text, html, mermaid diagrams, etc. that you are provided with in your initial instructions).\nexcluded_tools: []\nincluded_optional_tools:\n  - switch_modes\n\ntool_description_overrides: {}\n"
  },
  {
    "path": "src/serena/resources/config/contexts/ide.yml",
    "content": "description: Generic IDE coding agent context (basic file operations and shell operations assumed to be covered; single project mode)\nprompt: |\n  You are running in an IDE assistant context where file operations, basic (line-based) edits and reads, \n  and shell commands are handled by your own, internal tools.\n  \n  If Serena's tools can be used to achieve your task, you should prioritize them.\n  In particular, it is important that you avoid reading entire source code files unless it is strictly necessary!\n  Instead, for exploring and reading code in a token-efficient manner, use Serena's overview and symbolic search tools.\n  For non-code files or for reads where you don't know the symbol's name path, you can use the pattern search tool.\n\nexcluded_tools:\n  - create_text_file\n  - read_file\n  - execute_shell_command\n  - prepare_for_new_conversation\n\ntool_description_overrides: {}\n\n# whether to assume that Serena shall only work on a single project in this context (provided that a project is given\n# when Serena is started).\n# If set to true and a project is provided at startup, the set of tools is limited to those required by the project's\n# concrete configuration, and other tools are excluded completely, allowing the set of tools to be minimal.\n# Tools explicitly disabled by the project will not be available at all.\n# The `activate_project` tool is always disabled in this case, as project switching cannot be allowed.\nsingle_project: true\n"
  },
  {
    "path": "src/serena/resources/config/contexts/oaicompat-agent.yml",
    "content": "description: All tools except InitialInstructionsTool for agent context, uses OpenAI compatible tool definitions\nprompt: |\n  You are running in agent context where the system prompt is provided externally. You should use symbolic\n  tools when possible for code understanding and modification.\nexcluded_tools:\n  - initial_instructions\n\ntool_description_overrides: {}"
  },
  {
    "path": "src/serena/resources/config/internal_modes/jetbrains.yml",
    "content": "description: JetBrains tools replace language server-based tools\nprompt: |\n  You have access to the very powerful JetBrains tools for symbolic operations:\n    * `jet_brains_find_symbol` replaces `find_symbol`\n    * `jet_brains_find_referencing_symbols` replaces `find_referencing_symbols`\n    * `jet_brains_get_symbols_overview` replaces `get_symbols_overview`\nexcluded_tools:\n  - find_symbol\n  - find_referencing_symbols\n  - get_symbols_overview\n  - restart_language_server\nincluded_optional_tools:\n  - jet_brains_find_symbol\n  - jet_brains_find_referencing_symbols\n  - jet_brains_get_symbols_overview\n  - jet_brains_type_hierarchy\n"
  },
  {
    "path": "src/serena/resources/config/modes/editing.yml",
    "content": "description: All tools, with detailed instructions for code editing\nprompt: |\n  You are operating in editing mode. You can edit files with the provided tools.\n  You adhere to the project's code style and patterns.\n  \n  Use symbolic editing tools whenever possible for precise code modifications.\n  If no explicit editing task has yet been provided, wait for the user to provide one. Do not be overly eager.\n\n  When writing new code, think about where it belongs best. Don't generate new files if you don't plan on actually\n  properly integrating them into the codebase.\n\n  You have two main approaches for editing code: (a) editing at the symbol level and (b) file-based editing.\n  The symbol-based approach is appropriate if you need to adjust an entire symbol, e.g. a method, a class, a function, etc.\n  It is not appropriate if you need to adjust just a few lines of code within a larger symbol.\n\n  **Symbolic editing**\n  Use symbolic retrieval tools to identify the symbols you need to edit.\n  If you need to replace the definition of a symbol, use the `replace_symbol_body` tool.\n  If you want to add some new code at the end of the file, use the `insert_after_symbol` tool with the last top-level symbol in the file. \n  Similarly, you can use `insert_before_symbol` with the first top-level symbol in the file to insert code at the beginning of a file.\n  You can understand relationships between symbols by using the `find_referencing_symbols` tool. If not explicitly requested otherwise by the user,\n  you make sure that when you edit a symbol, the change is either backward-compatible or you find and update all references as needed.\n  The `find_referencing_symbols` tool will give you code snippets around the references as well as symbolic information.\n  You can assume that all symbol editing tools are reliable, so you never need to verify the results if the tools return without error.\n\n  {% if 'replace_content' in available_tools %}\n  **File-based editing**\n  The `replace_content` tool allows you to perform regex-based replacements within files (as well as simple string replacements).\n  This is your primary tool for editing code whenever replacing or deleting a whole symbol would be a more expensive operation,\n  e.g. if you need to adjust just a few lines of code within a method.\n  You are extremely good at regex, so you never need to check whether the replacement produced the correct result.\n  In particular, you know how to use wildcards effectively in order to avoid specifying the full original text to be replaced!\n  {% endif %}\nexcluded_tools:\n - replace_lines\n - insert_at_line\n - delete_lines\n"
  },
  {
    "path": "src/serena/resources/config/modes/interactive.yml",
    "content": "description: Interactive mode for clarification and step-by-step work\nprompt: |\n  You are operating in interactive mode. You should engage with the user throughout the task, asking for clarification\n  whenever anything is unclear, insufficiently specified, or ambiguous.\n  \n  Break down complex tasks into smaller steps and explain your thinking at each stage. When you're uncertain about\n  a decision, present options to the user and ask for guidance rather than making assumptions.\n  \n  Focus on providing informative results for intermediate steps, such that the user can follow along with your progress and\n  provide feedback as needed.\nexcluded_tools: []"
  },
  {
    "path": "src/serena/resources/config/modes/mode.template.yml",
    "content": "# See Serena's documentation for more details on concept of modes.\ndescription: Description of the mode (meta-information only)\nprompt: |\n  Provide a prompt that will form part of the instructions sent to the model when this mode is activated.\n# tools that are to be excluded by this mode\nexcluded_tools: []\n# several tools are excluded by default and have to be explicitly included by the user\nincluded_optional_tools: []"
  },
  {
    "path": "src/serena/resources/config/modes/no-memories.yml",
    "content": "description: Excludes Serena's memory tools (and onboarding tools, which rely on memory)\nprompt: |\n  Serena's memory tools are not available and the onboarding workflow is not being applied.\nexcluded_tools:\n  - write_memory\n  - read_memory\n  - delete_memory\n  - edit_memory\n  - rename_memory\n  - list_memories\n  - onboarding\n  - check_onboarding_performed\n"
  },
  {
    "path": "src/serena/resources/config/modes/no-onboarding.yml",
    "content": "description: The onboarding process is not used (memories may have been created externally)\nprompt: |\n  The onboarding process is not applied.\nexcluded_tools:\n  - onboarding\n  - check_onboarding_performed\n"
  },
  {
    "path": "src/serena/resources/config/modes/onboarding.yml",
    "content": "description: Only read-only tools, focused on analysis and planning\nprompt: |\n  You are operating in onboarding mode. This is the first time you are seeing the project.\n  Your task is to collect relevant information about it and to save memories using the tools provided.\n  Call relevant onboarding tools for more instructions on how to do this.\n  In this mode, you should not be modifying any existing files.\n  If you are also in interactive mode and something about the project is unclear, ask the user for clarification.\nexcluded_tools:\n  - create_text_file\n  - replace_symbol_body\n  - insert_after_symbol\n  - insert_before_symbol\n  - delete_lines\n  - replace_lines\n  - insert_at_line\n  - execute_shell_command\n"
  },
  {
    "path": "src/serena/resources/config/modes/one-shot.yml",
    "content": "description: Focus on completely finishing a task without interaction\nprompt: |\n  You are operating in one-shot mode. Your goal is to complete the entire task autonomously without further user interaction.\n  You should assume auto-approval for all tools and continue working until the task is completely finished.\n  \n  If the task is planning, your final result should be a comprehensive plan. If the task is coding, your final result\n  should be working code with all requirements fulfilled. Try to understand what the user asks you to do\n  and to assume as little as possible.\n\n  Only abort the task if absolutely necessary, such as when critical information is missing that cannot be inferred\n  from the codebase.\n\n  It may be that you have not received a task yet. In this case, wait for the user to provide a task, this will be the \n  only time you should wait for user interaction.\nexcluded_tools: []\n"
  },
  {
    "path": "src/serena/resources/config/modes/planning.yml",
    "content": "description: Only read-only tools, focused on analysis and planning\nprompt: |\n  You are operating in planning mode. Your task is to analyze code but not write any code.\n  The user may ask you to assist in creating a comprehensive plan, or to learn something about the codebase.\nexcluded_tools:\n  - create_text_file\n  - replace_symbol_body\n  - insert_after_symbol\n  - insert_before_symbol\n  - delete_lines\n  - replace_lines\n  - insert_at_line\n  - execute_shell_command\n  - replace_content\n"
  },
  {
    "path": "src/serena/resources/config/modes/query-projects.yml",
    "content": "description: Enables tools that allow inactive projects to be queried\nprompt: |\n  You can use the 'query_project' tool to query Serena projects without activating them.\n  Use this when a project is related to the active project and you need to query it for information.\nexcluded_tools: []\nincluded_optional_tools:\n  - list_queryable_projects\n  - query_project\n"
  },
  {
    "path": "src/serena/resources/config/prompt_templates/simple_tool_outputs.yml",
    "content": "# Some of Serena's tools are just outputting a fixed text block without doing anything else.\n# Such tools are meant to encourage the agent to think in a certain way, to stay on track\n# and so on. The (templates for) outputs of these tools are contained here.\nprompts:\n  onboarding_prompt: |\n    You are viewing the project for the first time.\n    Your task is to assemble relevant high-level information about the project which\n    will be saved to memory files in the following steps.\n    The information should be sufficient to understand what the project is about,\n    and the most important commands for developing code.\n    The project is being developed on the system: {{ system }}.\n\n    You need to identify at least the following information:\n    * the project's purpose\n    * the tech stack used\n    * the code style and conventions used (including naming, type hints, docstrings, etc.)\n    * which commands to run when a task is completed (linting, formatting, testing, etc.)\n    * the rough structure of the codebase\n    * the commands for testing, formatting, and linting\n    * the commands for running the entrypoints of the project\n    * the util commands for the system, like `git`, `ls`, `cd`, `grep`, `find`, etc. Keep in mind that the system is {{ system }},\n      so the commands might be different than on a regular unix system.\n    * whether there are particular guidelines, styles, design patterns, etc. that one should know about\n\n    This list is not exhaustive, you can add more information if you think it is relevant.\n\n    For doing that, you will need to acquire information about the project with the corresponding tools.\n    Read only the necessary files and directories to avoid loading too much data into memory.\n    If you cannot find everything you need from the project itself, you should ask the user for more information.\n\n    After collecting all the information, you will use the `write_memory` tool (in multiple calls) to save it to various memory files.\n    A particularly important memory file will be the `suggested_commands.md` file, which should contain\n    a list of commands that the user should know about to develop code in this project.\n    Moreover, you should create memory files for the style and conventions and a dedicated memory file for\n    what should be done when a task is completed.\n    **Important**: after done with the onboarding task, remember to call the `write_memory` to save the collected information!\n\n  think_about_collected_information: |\n    Have you collected all the information you need for solving the current task? If not, can the missing information be acquired by using the available tools,\n    in particular the tools related to symbol discovery? Or do you need to ask the user for more information?\n    Think about it step by step and give a summary of the missing information and how it could be acquired.\n\n  think_about_task_adherence: |\n    Are you deviating from the task at hand? Do you need any additional information to proceed?\n    Have you loaded all relevant memory files to see whether your implementation is fully aligned with the\n    code style, conventions, and guidelines of the project? If not, adjust your implementation accordingly\n    before modifying any code into the codebase.\n    Note that it is better to stop and ask the user for clarification\n    than to perform large changes which might not be aligned with the user's intentions.\n    If you feel like the conversation is deviating too much from the original task, apologize and suggest to the user\n    how to proceed. If the conversation became too long, create a summary of the current progress and suggest to the user\n    to start a new conversation based on that summary.\n\n  think_about_whether_you_are_done: |\n    Have you already performed all the steps required by the task? Is it appropriate to run tests and linting, and if so,\n    have you done that already? Is it appropriate to adjust non-code files like documentation and config and have you done that already?\n    Should new tests be written to cover the changes?\n    Note that a task that is just about exploring the codebase does not require running tests or linting.\n    Read the corresponding memory files to see what should be done when a task is completed. \n\n  summarize_changes: |\n    Summarize all the changes you have made to the codebase over the course of the conversation.\n    Explore the diff if needed (e.g. by using `git diff`) to ensure that you have not missed anything.\n    Explain whether and how the changes are covered by tests. Explain how to best use the new code, how to understand it,\n    which existing code it affects and interacts with. Are there any dangers (like potential breaking changes or potential new problems) \n    that the user should be aware of? Should any new documentation be written or existing documentation updated?\n    You can use tools to explore the codebase prior to writing the summary, but don't write any new code in this step until\n    the summary is complete.\n\n  prepare_for_new_conversation: |\n    You have not yet completed the current task but we are running out of context.\n    {mode_prepare_for_new_conversation}\n    Imagine that you are handing over the task to another person who has access to the\n    same tools and memory files as you do, but has not been part of the conversation so far.\n    Write a summary that can be used in the next conversation to a memory file using the `write_memory` tool.\n"
  },
  {
    "path": "src/serena/resources/config/prompt_templates/system_prompt.yml",
    "content": "# The system prompt template. Note that many clients will not allow configuration of the actual system prompt,\n# in which case this prompt will be given as a regular message on the call of a simple tool which the agent\n# is encouraged (via the tool description) to call at the beginning of the conversation.\nprompts:\n  system_prompt: |\n    You are a professional coding agent. \n    You have access to semantic coding tools upon which you rely heavily for all your work.\n    You operate in a resource-efficient and intelligent manner, always keeping in mind to not read or generate\n    content that is not needed for the task at hand.\n\n    Some tasks may require you to understand the architecture of large parts of the codebase, while for others,\n    it may be enough to read a small set of symbols or a single file.\n    You avoid reading entire files unless it is absolutely necessary, instead relying on intelligent step-by-step \n    acquisition of information. {% if 'ToolMarkerSymbolicRead' in available_markers %}Once you have read a full file, it does not make\n    sense to analyse it with the symbolic read tools; you already have the information.{% endif %}\n\n    You can achieve intelligent reading of code by using the symbolic tools for getting an overview of symbols and\n    the relations between them, and then only reading the bodies of symbols that are necessary to complete the task at hand. \n    You can use the standard tools like list_dir, find_file and search_for_pattern if you need to.\n    Where appropriate, you pass the `relative_path` parameter to restrict the search to a specific file or directory.\n    {% if 'search_for_pattern' in available_tools %}\n    If you are unsure about a symbol's name or location{% if 'find_symbol' in available_tools %} (to the extent that substring_matching for the symbol name is not enough){% endif %}, you can use the `search_for_pattern` tool, which allows fast\n    and flexible search for patterns in the codebase.{% if 'ToolMarkerSymbolicRead' in available_markers %} In this way, you can first find candidates for symbols or files,\n    and then proceed with the symbolic tools.{% endif %}\n    {% endif %}\n\n    {% if 'ToolMarkerSymbolicRead' in available_markers %}\n    Symbols are identified by their `name_path` and `relative_path` (see the description of the `find_symbol` tool).\n    You can get information about the symbols in a file by using the `get_symbols_overview` tool or use the `find_symbol` to search. \n    You only read the bodies of symbols when you need to (e.g. if you want to fully understand or edit it).\n    For example, if you are working with Python code and already know that you need to read the body of the constructor of the class Foo, you can directly\n    use `find_symbol` with name path pattern `Foo/__init__` and `include_body=True`. If you don't know yet which methods in `Foo` you need to read or edit,\n    you can use `find_symbol` with name path pattern `Foo`, `include_body=False` and `depth=1` to get all (top-level) methods of `Foo` before proceeding\n    to read the desired methods with `include_body=True`.\n    You can understand relationships between symbols by using the `find_referencing_symbols` tool.\n    {% endif %}\n\n    {% if 'read_memory' in available_tools -%}\n    You generally have access to memories and it may be useful for you to read them.\n    You infer whether memories are relevant based on their names.\n    {% if global_memories_list -%}\n    The following global (not project-specific) memories are available to you: {{ global_memories_list }}\n    {%- endif -%}\n    {%- endif %}\n\n    The context and modes of operation are described below. These determine how to interact with your user\n    and which kinds of interactions are expected of you.\n\n    Context description:\n    {{ context_system_prompt }}\n\n    Modes descriptions:\n    {% for prompt in mode_system_prompts %}\n    {{ prompt }}\n    {% endfor %}\n    \n    You have hereby read the 'Serena Instructions Manual' and do not need to read it again.\n"
  },
  {
    "path": "src/serena/resources/dashboard/dashboard.css",
    "content": "html {\n    scrollbar-gutter: stable; /* Prevent layout shift when scrollbar appears */\n}\n\n:root {\n    /* Light theme variables */\n    --bg-primary: #f5f5f5;\n    --bg-secondary: #ffffff;\n    --text-primary: #000000;\n    --text-secondary: #333333;\n    --text-muted: #666666;\n    --border-color: #ddd;\n    --btn-primary: #eaa45d;\n    --btn-hover: #dca662;\n    --btn-disabled: #6c757d;\n    --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);\n    --tool-highlight: #ffff00;\n    --tool-highlight-text: #000000;\n    --log-debug: #808080;\n    --log-info: #000000;\n    --log-warning: #FF8C00;\n    --log-error: #FF0000;\n    --stats-header: #f8f9fa;\n    --header-height: 150px;\n    --header-padding: 20px;\n    --header-gap-main: 25px;\n    --frame-padding: 25px;\n    --border-radius: 5px;\n}\n\n[data-theme=\"dark\"] {\n    /* Dark theme variables */\n    --bg-primary: #1a1a1a;\n    --bg-secondary: #2d2d2d;\n    --text-primary: #ffffff;\n    --text-secondary: #e0e0e0;\n    --text-muted: #b0b0b0;\n    --border-color: #444;\n    --btn-primary: #eaa45d;\n    --btn-hover: #dca662;\n    --btn-disabled: #6c757d;\n    --shadow: 0 2px 4px rgba(0, 0, 0, 0.3);\n    --tool-highlight: #ffd700;\n    --tool-highlight-text: #000000;\n    --log-debug: #808080;\n    --log-info: #ffffff;\n    --log-warning: #FF8C00;\n    --log-error: #FF0000;\n    --stats-header: #3a3a3a;\n}\n\n.news-section {\n    background: var(--bg-secondary);\n    padding: 20px;\n    border-radius: var(--border-radius);\n    box-shadow: var(--shadow);\n    margin-bottom: 25px;\n}\n\n.news-section h2 {\n    margin: 0 0 20px 0;\n    font-size: 18px;\n    color: var(--text-primary);\n}\n\n.news-item {\n    padding: 20px;\n    border: 1px solid var(--border-color);\n    border-radius: var(--border-radius);\n    margin-bottom: 15px;\n    background: var(--bg-primary);\n    position: relative;\n}\n\n.news-item:last-child {\n    margin-bottom: 0;\n}\n\n.news-item h3 {\n    margin: 0 0 10px 0;\n    font-size: 16px;\n    color: var(--text-primary);\n}\n\n.news-item .date {\n    color: var(--text-muted);\n    font-size: 13px;\n    margin: 0 0 15px 0;\n}\n\n.news-item p {\n    margin: 10px 0;\n    line-height: 1.6;\n    color: var(--text-secondary);\n}\n\n.news-item ul {\n    margin: 10px 0;\n    padding-left: 25px;\n    color: var(--text-secondary);\n}\n\n.news-item ul li {\n    margin: 8px 0;\n    line-height: 1.5;\n}\n\n.news-item strong {\n    color: var(--text-primary);\n}\n\n.news-mark-read {\n    position: absolute;\n    top: 20px;\n    right: 20px;\n}\n\n.news-mark-read-btn {\n    background-color: var(--btn-primary);\n    color: white;\n    border: none;\n    padding: 6px 12px;\n    border-radius: 4px;\n    cursor: pointer;\n    font-size: 13px;\n    transition: background-color 0.3s ease;\n    white-space: nowrap;\n}\n\n.news-mark-read-btn:hover {\n    background-color: var(--btn-hover);\n}\n\n.news-mark-read-btn:disabled {\n    background-color: var(--btn-disabled);\n    cursor: not-allowed;\n}\n\n.news-no-items {\n    color: var(--text-muted);\n    font-style: italic;\n    text-align: center;\n    padding: 20px;\n}\n\nbody {\n    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;\n    margin: 0;\n    background-color: var(--bg-primary);\n    color: var(--text-primary);\n    transition: background-color 0.3s ease, color 0.3s ease;\n}\n\n#frame {\n    max-width: 1600px;\n    margin: 0 auto;\n    padding: var(--frame-padding);\n    padding-top: 0;\n    min-width: 1280px;\n}\n\n.main {\n    padding-top: var(--header-gap-main);\n}\n\n.header {\n    top: 0;\n    left: 0;\n    right: 0;\n    height: var(--header-height);\n    background-color: var(--bg-secondary);\n    border-bottom: 1px solid var(--border-color);\n    border-bottom-left-radius: var(--border-radius);\n    border-bottom-right-radius: var(--border-radius);\n    padding: var(--header-padding);\n    display: flex;\n    justify-content: space-between;\n    align-items: center;\n    gap: 20px;\n    z-index: 1000;\n    transition: background-color 0.3s ease, border-color 0.3s ease;\n    min-height: 90px;\n    box-shadow: var(--shadow);\n    max-width: 1600px;\n    margin: 0 auto;\n}\n\n.header-left {\n    display: flex;\n    gap: 30px;\n}\n\n.logo-container {\n    height: var(--header-height);\n    order: 1;\n    flex-shrink: 0;\n}\n\n.logo-container img {\n    height: calc(var(--header-height) - 20px);\n    margin-top: 10px;\n    display: block;\n}\n\n.header-banner {\n    position: relative;\n    top: 0;\n    left: 0;\n    order: 2;\n    height: var(--header-height);\n    max-height: var(--header-height);\n}\n\n.header-nav {\n    position: relative;\n    display: flex;\n    flex-direction: column;\n    align-items: flex-end;\n    justify-content: space-between;\n    height: 100%;\n    flex-shrink: 0;\n}\n\n.header-actions {\n    position: relative;\n    display: flex;\n    align-items: center;\n    gap: 10px;\n}\n\n.header-tabs {\n    display: flex;\n    align-items: flex-end;\n    gap: 0;\n}\n\n.header-tab {\n    display: flex;\n    align-items: center;\n    padding: 8px 20px;\n    color: var(--text-muted);\n    text-decoration: none;\n    font-size: 15px;\n    font-weight: 500;\n    border-bottom: 3px solid transparent;\n    transition: color 0.2s ease, border-color 0.2s ease;\n    white-space: nowrap;\n}\n\n.header-tab:hover {\n    color: var(--text-primary);\n}\n\n.header-tab.active {\n    color: var(--btn-primary);\n    border-bottom-color: var(--btn-primary);\n}\n\n.menu-button {\n    background-color: var(--bg-secondary);\n    color: var(--text-primary);\n    border: 1px solid var(--border-color);\n    padding: 8px 16px;\n    border-radius: 4px;\n    cursor: pointer;\n    font-size: 16px;\n    transition: background-color 0.3s ease, border-color 0.3s ease;\n    display: flex;\n    align-items: center;\n    gap: 8px;\n}\n\n.menu-button:hover {\n    background-color: var(--border-color);\n}\n\n.menu-dropdown {\n    position: absolute;\n    top: 100%;\n    margin-top: 6px;\n    right: 0;\n    background-color: var(--bg-secondary);\n    border: 1px solid var(--border-color);\n    border-radius: 4px;\n    box-shadow: var(--shadow);\n    min-width: 200px;\n    z-index: 999;\n    transition: background-color 0.3s ease, border-color 0.3s ease;\n}\n\n.menu-dropdown a {\n    display: block;\n    padding: 12px 20px;\n    color: var(--text-primary);\n    text-decoration: none;\n    transition: background-color 0.3s ease;\n}\n\n.menu-dropdown a:hover {\n    background-color: var(--border-color);\n}\n\n.menu-dropdown a.active {\n    background-color: var(--btn-primary);\n    color: white;\n}\n\n.menu-dropdown hr {\n    border: none;\n    border-top: 1px solid var(--border-color);\n    margin: 5px 0;\n}\n\n.platinum-banner-slide {\n    display: none;\n    pointer-events: none;\n    height: 100%;\n}\n\n.platinum-banner-slide.active {\n    display: block;\n    pointer-events: auto;\n}\n\n.banner-image {\n    object-fit: contain;\n    border-radius: var(--border-radius);\n}\n\n.banner-border {\n    border: 1px solid var(--border-color);\n}\n\n.platinum-banner-slide .banner-image {\n    max-height: 100%;\n    object-fit: contain;\n}\n\n.gold-banners-section {\n    margin: 0 auto;\n    width: 100%;\n    position: relative;\n    align-items: center;\n    justify-content: center;\n    padding: 0;\n}\n\n.gold-banner {\n    position: relative;\n    width: 100%;\n    overflow: hidden;\n}\n\n.gold-banner-slide {\n    display: none;\n    pointer-events: none;\n}\n\n.gold-banner-slide.active {\n    display: block;\n    pointer-events: auto;\n}\n\n.gold-banner-slide .banner-image {\n    max-width: 100%;\n    object-fit: contain;\n}\n\n/* Banner Arrow Navigation */\n.banner-arrow {\n    position: absolute;\n    top: 50%;\n    transform: translateY(-50%);\n    z-index: 10;\n    background: rgba(128, 128, 128, 0.15);\n    color: var(--text-muted);\n    border: none;\n    font-size: 18px;\n    line-height: 1;\n    width: 24px;\n    height: 32px;\n    display: flex;\n    align-items: center;\n    justify-content: center;\n    cursor: pointer;\n    border-radius: 4px;\n    opacity: 0.3;\n    transition: opacity 0.2s ease, background-color 0.2s ease, color 0.2s ease;\n    padding: 0;\n}\n\n.banner-arrow:hover {\n    opacity: 0.8;\n    background: rgba(128, 128, 128, 0.4);\n    color: var(--text-primary);\n}\n\n.banner-arrow-left {\n    left: 0;\n}\n\n.banner-arrow-right {\n    right: 0;\n}\n\n.page-view {\n    /*max-width: 1600px;*/\n    margin: 0 auto;\n}\n\n/* Overview Page Layout */\n.overview-container {\n    display: grid;\n    grid-template-columns: 1fr 400px;\n    gap: 20px;\n}\n\n.overview-left {\n    min-width: 0;\n}\n\n.overview-right {\n    min-width: 0;\n}\n\n/* Overview Page Styles */\n.config-section,\n.basic-stats-section,\n.projects-section {\n    background-color: var(--bg-secondary);\n    border: 1px solid var(--border-color);\n    border-radius: var(--border-radius);\n    padding: 20px;\n    margin-bottom: 20px;\n    transition: background-color 0.3s ease, border-color 0.3s ease;\n}\n\n.config-section h2,\n.basic-stats-section h2 {\n    margin-top: 0;\n    color: var(--text-secondary);\n}\n\n/* Collapsible Headers */\n.collapsible-header {\n    margin-top: 0;\n    margin-bottom: 0;\n    font-size: 18px;\n    color: var(--text-secondary);\n    cursor: pointer;\n    user-select: none;\n    display: flex;\n    justify-content: space-between;\n    align-items: center;\n}\n\n.collapsible-header:hover {\n    color: var(--text-primary);\n}\n\n.toggle-icon {\n    transition: transform 0.3s ease;\n    font-size: 14px;\n}\n\n.toggle-icon.expanded {\n    transform: rotate(-180deg);\n}\n\n.collapsible-content {\n    margin-top: 15px;\n    max-height: 400px;\n    overflow-y: auto;\n}\n\n.config-grid {\n    display: grid;\n    grid-template-columns: 180px 1fr;\n    gap: 12px;\n    margin-bottom: 20px;\n}\n\n.config-label {\n    font-weight: bold;\n    color: var(--text-secondary);\n}\n\n.config-value {\n    color: var(--text-primary);\n}\n\n.config-list {\n    list-style: none;\n    padding: 0;\n    margin: 0;\n}\n\n.config-list li {\n    padding: 4px 0;\n}\n\n.tools-grid {\n    display: grid;\n    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));\n    gap: 8px;\n    margin-top: 10px;\n}\n\n.tool-item {\n    background-color: var(--bg-primary);\n    padding: 6px 10px;\n    border-radius: 3px;\n    font-size: 13px;\n    color: var(--text-primary);\n    overflow: hidden;\n    text-overflow: ellipsis;\n    white-space: nowrap;\n    cursor: default;\n}\n\n/* Projects List */\n.project-item {\n    padding: 10px 12px;\n    margin: 5px 0;\n    border-radius: 4px;\n    background-color: var(--bg-primary);\n    border: 1px solid var(--border-color);\n    transition: background-color 0.2s ease;\n}\n\n.project-item:hover {\n    background-color: var(--border-color);\n}\n\n.project-item.active {\n    background-color: var(--btn-primary);\n    color: white;\n    border-color: var(--btn-primary);\n}\n\n.project-name {\n    font-weight: bold;\n    margin-bottom: 4px;\n    overflow: hidden;\n    text-overflow: ellipsis;\n    white-space: nowrap;\n}\n\n.project-path {\n    font-size: 11px;\n    color: var(--text-muted);\n    overflow: hidden;\n    text-overflow: ellipsis;\n    white-space: nowrap;\n}\n\n.project-item.active .project-path {\n    color: rgba(255, 255, 255, 0.8);\n}\n\n/* Generic Item Styles for Tools/Modes/Contexts */\n.info-item {\n    padding: 8px 12px;\n    margin: 5px 0;\n    border-radius: 4px;\n    background-color: var(--bg-primary);\n    border: 1px solid var(--border-color);\n    transition: background-color 0.2s ease;\n    overflow: hidden;\n    text-overflow: ellipsis;\n    white-space: nowrap;\n    cursor: default;\n}\n\n.info-item:hover {\n    background-color: var(--border-color);\n}\n\n.info-item.active {\n    background-color: var(--btn-primary);\n    color: white;\n    border-color: var(--btn-primary);\n    font-weight: bold;\n}\n\n/* Basic Stats Styles */\n.basic-stats-section {\n    background-color: var(--bg-secondary);\n    border: 1px solid var(--border-color);\n    border-radius: 5px;\n    padding: 20px;\n    margin-bottom: 20px;\n    transition: background-color 0.3s ease, border-color 0.3s ease;\n}\n\n.basic-stats-section h2 {\n    margin-top: 0;\n    color: var(--text-secondary);\n}\n\n/* Executions Styles */\n.executions-section {\n    background-color: var(--bg-secondary);\n    border: 1px solid var(--border-color);\n    border-radius: 5px;\n    padding: 20px;\n    margin-bottom: 20px;\n    transition: background-color 0.3s ease, border-color 0.3s ease;\n}\n\n.executions-section h2 {\n    margin-top: 0;\n    color: var(--text-secondary);\n}\n\n.execution-list {\n    display: flex;\n    flex-direction: column;\n    gap: 8px;\n}\n\n.execution-item {\n    display: flex;\n    align-items: center;\n    gap: 10px;\n    background-color: var(--bg-primary);\n    border: 1px solid var(--border-color);\n    border-radius: 20px;\n    padding: 8px 12px;\n    min-height: 40px;\n    transition: background-color 0.2s ease, border-color 0.2s ease;\n}\n\n.execution-item.running {\n    border-color: var(--btn-primary);\n    background: linear-gradient(to right, rgba(234, 164, 93, 0.1), var(--bg-primary));\n}\n\n.execution-item.cancelled {\n    border-color: var(--text-muted);\n    background-color: var(--bg-primary);\n    opacity: 0.7;\n}\n\n.execution-item.abandoned {\n    border-color: var(--log-error);\n    background: linear-gradient(to right, rgba(255, 0, 0, 0.1), var(--bg-primary));\n}\n\n.execution-spinner {\n    width: 16px;\n    height: 16px;\n    border: 2px solid var(--border-color);\n    border-top-color: var(--btn-primary);\n    border-radius: 50%;\n    animation: spin 0.7s linear infinite;\n    flex-shrink: 0;\n}\n\n@keyframes spin {\n    to { transform: rotate(360deg); }\n}\n\n.execution-name {\n    flex: 1;\n    font-size: 13px;\n    white-space: nowrap;\n    overflow: hidden;\n    text-overflow: ellipsis;\n    color: var(--text-primary);\n}\n\n.execution-meta {\n    font-size: 11px;\n    color: var(--text-muted);\n    flex-shrink: 0;\n}\n\n.execution-cancel-btn {\n    background: none;\n    border: none;\n    color: var(--text-muted);\n    font-size: 16px;\n    cursor: pointer;\n    width: 24px;\n    height: 24px;\n    display: flex;\n    align-items: center;\n    justify-content: center;\n    border-radius: 50%;\n    transition: background-color 0.15s ease, color 0.15s ease;\n    flex-shrink: 0;\n}\n\n.execution-cancel-btn:hover {\n    background-color: rgba(255, 0, 0, 0.1);\n    color: var(--log-error);\n}\n\n.execution-icon {\n    width: 16px;\n    height: 16px;\n    border-radius: 50%;\n    display: flex;\n    align-items: center;\n    justify-content: center;\n    font-size: 10px;\n    flex-shrink: 0;\n}\n\n.execution-icon.success {\n    background-color: rgba(34, 197, 94, 0.2);\n    border: 1px solid rgba(34, 197, 94, 0.6);\n    color: #22c55e;\n}\n\n.execution-icon.cancelled {\n    background-color: var(--border-color);\n    border: 1px solid var(--text-muted);\n    color: var(--text-muted);\n}\n\n.execution-icon.abandoned {\n    background-color: rgba(255, 0, 0, 0.2);\n    border: 1px solid var(--log-error);\n    color: var(--log-error);\n}\n\n.execution-icon.error {\n    background-color: rgba(255, 0, 0, 0.2);\n    border: 1px solid var(--log-error);\n    color: var(--log-error);\n}\n\n.last-execution-container {\n    display: flex;\n    align-items: center;\n    gap: 12px;\n    background: linear-gradient(to right, rgba(34, 197, 94, 0.08), transparent);\n    border: 1px solid rgba(34, 197, 94, 0.2);\n    border-radius: 8px;\n    padding: 12px;\n}\n\n.last-execution-container.error {\n    background: linear-gradient(to right, rgba(255, 0, 0, 0.08), transparent);\n    border-color: rgba(255, 0, 0, 0.2);\n}\n\n.last-execution-icon-container {\n    width: 28px;\n    height: 28px;\n    background-color: rgba(34, 197, 94, 0.2);\n    border: 1px solid rgba(34, 197, 94, 0.6);\n    border-radius: 50%;\n    display: flex;\n    align-items: center;\n    justify-content: center;\n    font-size: 14px;\n    color: #22c55e;\n    flex-shrink: 0;\n}\n\n.last-execution-container.error .last-execution-icon-container {\n    background-color: rgba(255, 0, 0, 0.2);\n    border-color: var(--log-error);\n    color: var(--log-error);\n}\n\n.last-execution-body {\n    flex: 1;\n}\n\n.last-execution-status {\n    font-size: 11px;\n    color: var(--text-muted);\n    margin-bottom: 2px;\n}\n\n.last-execution-name {\n    font-size: 13px;\n    color: var(--text-primary);\n}\n\n.stat-bar-container {\n    display: flex;\n    align-items: center;\n    margin: 8px 0;\n    gap: 12px;\n}\n\n.stat-tool-name {\n    min-width: 200px;\n    max-width: 200px;\n    font-weight: bold;\n    color: var(--text-secondary);\n    overflow: hidden;\n    text-overflow: ellipsis;\n    white-space: nowrap;\n    cursor: default;\n}\n\n.bar-wrapper {\n    flex: 1;\n    height: 24px;\n    background-color: var(--border-color);\n    border-radius: 3px;\n    overflow: hidden;\n    position: relative;\n}\n\n.bar {\n    height: 100%;\n    background-color: var(--btn-primary);\n    transition: width 0.5s ease;\n    border-radius: 3px;\n}\n\n.stat-count {\n    min-width: 60px;\n    text-align: right;\n    font-weight: bold;\n    color: var(--text-primary);\n}\n\n.no-stats-message {\n    text-align: center;\n    color: var(--text-muted);\n    font-style: italic;\n    padding: 20px;\n}\n\n/* Log Container Styles */\n.log-container {\n    background-color: var(--bg-secondary);\n    border: 1px solid var(--border-color);\n    border-radius: 5px;\n    height: calc(100vh - var(--header-height) - 2 * var(--header-padding) - 3 * var(--header-gap-main));\n    overflow-y: auto;\n    overflow-x: auto;\n    padding: 10px;\n    white-space: pre-wrap;\n    font-size: 14px;\n    line-height: 1.4;\n    color: var(--text-primary);\n    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;\n}\n\n.controls {\n    position: sticky;\n    top: 90px;\n    z-index: 100;\n    background-color: var(--bg-primary);\n    padding: 10px 0;\n    margin-bottom: 10px;\n    text-align: center;\n    display: flex;\n    justify-content: center;\n    align-items: center;\n    gap: 10px;\n    flex-wrap: wrap;\n    transition: background-color 0.3s ease;\n}\n\n.btn {\n    background-color: var(--btn-primary);\n    color: white;\n    border: none;\n    padding: 8px 16px;\n    border-radius: 4px;\n    cursor: pointer;\n    font-size: 14px;\n    transition: background-color 0.3s ease;\n}\n\n.btn:hover {\n    background-color: var(--btn-hover);\n}\n\n.btn:disabled {\n    background-color: var(--btn-disabled);\n    cursor: not-allowed;\n}\n\n.theme-toggle {\n    display: flex;\n    align-items: center;\n    gap: 5px;\n    background-color: var(--bg-secondary);\n    color: var(--text-primary);\n    border: 1px solid var(--border-color);\n    border-radius: 4px;\n    padding: 8px 16px;\n    cursor: pointer;\n    font-size: 16px;\n    transition: background-color 0.3s ease, border-color 0.3s ease;\n}\n\n.theme-toggle:hover {\n    background-color: var(--border-color);\n}\n\n.theme-toggle span {\n    line-height: 1;\n}\n\n.log-debug {\n    color: var(--log-debug);\n}\n\n.log-info {\n    color: var(--log-info);\n}\n\n.log-warning {\n    color: var(--log-warning);\n}\n\n.log-error {\n    color: var(--log-error);\n}\n\n.log-default {\n    color: var(--log-info);\n}\n\n/* Tool name highlighting */\n.tool-name {\n    background-color: var(--tool-highlight);\n    color: var(--tool-highlight-text);\n    font-weight: bold;\n}\n\n.loading {\n    text-align: center;\n    color: var(--text-muted);\n    font-style: italic;\n}\n\n.error-message {\n    color: var(--log-error);\n    text-align: center;\n    margin: 10px 0;\n}\n\n/* Advanced Stats Styles */\n.charts-container {\n    display: flex;\n    flex-wrap: wrap;\n    gap: 15px;\n    justify-content: space-between;\n    max-width: 1400px;\n    margin: 0 auto;\n}\n\n.chart-group {\n    flex: 1;\n    min-width: 280px;\n    max-width: 320px;\n    text-align: center;\n}\n\n.chart-wide {\n    flex: 0 0 100%;\n    min-width: 100%;\n    margin-top: 10px;\n}\n\n.chart-group h3 {\n    margin: 0 0 10px 0;\n    color: var(--text-secondary);\n}\n\n.stats-summary {\n    margin: 0 auto;\n    border-collapse: collapse;\n    background: var(--bg-secondary);\n    border-radius: 5px;\n    overflow: hidden;\n    box-shadow: var(--shadow);\n    transition: background-color 0.3s ease, box-shadow 0.3s ease;\n}\n\n.stats-summary th,\n.stats-summary td {\n    padding: 10px 20px;\n    text-align: left;\n    border-bottom: 1px solid var(--border-color);\n    color: var(--text-primary);\n    transition: border-color 0.3s ease, color 0.3s ease;\n}\n\n.stats-summary th {\n    background-color: var(--stats-header);\n    font-weight: bold;\n    transition: background-color 0.3s ease;\n}\n\n.stats-summary tr:last-child td {\n    border-bottom: none;\n}\n\n@media (max-width: 1024px) {\n    .overview-container {\n        grid-template-columns: 1fr;\n    }\n\n    .overview-right {\n        order: -1;\n    }\n}\n\n@media (max-width: 768px) {\n    body {\n        padding-top: 140px;\n    }\n\n    .header {\n        flex-direction: column;\n        gap: 10px;\n        padding: 10px 15px;\n    }\n\n    .logo-container {\n        width: 100%;\n        text-align: center;\n    }\n\n    .logo-container img {\n        max-width: 200px;\n    }\n\n    .header-nav {\n        width: 100%;\n        align-items: center;\n    }\n\n    .header-tabs {\n        justify-content: center;\n    }\n\n    .header-actions {\n        justify-content: center;\n    }\n\n    .charts-container {\n        flex-direction: column;\n    }\n\n    .chart-group,\n    .chart-wide {\n        min-width: auto;\n        max-width: none;\n    }\n\n    .controls {\n        flex-direction: column;\n        gap: 5px;\n    }\n\n    .config-grid {\n        grid-template-columns: 1fr;\n    }\n\n    .tools-grid {\n        grid-template-columns: 1fr;\n    }\n\n    .stat-bar-container {\n        flex-wrap: wrap;\n    }\n\n    .stat-tool-name {\n        min-width: 100%;\n    }\n}\n\n/* Modal Styles */\n.modal {\n    position: fixed;\n    z-index: 1000;\n    left: 0;\n    top: 0;\n    width: 100%;\n    height: 100%;\n    overflow: auto;\n    background-color: rgba(0, 0, 0, 0.5);\n}\n\n.modal-content {\n    background-color: var(--bg-primary);\n    margin: 10% auto;\n    padding: 25px;\n    border: 1px solid var(--border-color);\n    border-radius: 8px;\n    width: 90%;\n    max-width: 500px;\n    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);\n    position: relative;\n}\n\n.modal-close {\n    color: var(--text-muted);\n    float: right;\n    font-size: 28px;\n    font-weight: bold;\n    line-height: 20px;\n    cursor: pointer;\n    transition: color 0.2s;\n}\n\n.modal-close:hover,\n.modal-close:focus {\n    color: var(--text-primary);\n}\n\n.modal h3 {\n    margin-top: 0;\n    margin-bottom: 15px;\n    color: var(--text-primary);\n}\n\n/* Language Badge Styles */\n.languages-container {\n    display: flex;\n    flex-wrap: wrap;\n    gap: 8px;\n}\n\n.language-badge {\n    position: relative;\n    display: inline-flex;\n    align-items: center;\n    padding: 6px 12px;\n    background: var(--bg-secondary);\n    border: 1px solid var(--border-color);\n    border-radius: 6px;\n    color: var(--text-primary);\n    font-size: 13px;\n    font-weight: 500;\n}\n\n.language-badge.removable {\n    padding-right: 28px;\n}\n\n.language-remove {\n    position: absolute;\n    top: 2px;\n    right: 2px;\n    width: 18px;\n    height: 18px;\n    display: flex;\n    align-items: center;\n    justify-content: center;\n    background: rgba(255, 68, 68, 0.1);\n    border-radius: 3px;\n    cursor: pointer;\n    color: #ff4444;\n    font-size: 14px;\n    font-weight: bold;\n    line-height: 1;\n    transition: all 0.2s;\n}\n\n.language-remove:hover {\n    background: rgba(255, 68, 68, 0.2);\n    transform: scale(1.1);\n}\n\n.language-add-btn {\n    padding: 6px 12px;\n    font-size: 13px;\n    font-weight: 500;\n    border-radius: 6px;\n    border: 1px dashed var(--border-color);\n    background: var(--bg-secondary);\n    color: var(--text-primary);\n    cursor: pointer;\n    transition: all 0.2s;\n}\n\n.language-add-btn:hover {\n    background: var(--border-color);\n    border-color: var(--btn-primary);\n    color: var(--btn-primary);\n}\n\n.memory-add-btn {\n    display: inline-flex;\n    align-items: center;\n    padding: 8px 12px;\n    margin: 5px;\n    border-radius: 4px;\n    border: 1px dashed var(--border-color);\n    background: var(--bg-secondary);\n    color: var(--text-primary);\n    cursor: pointer;\n    transition: all 0.2s;\n    font-family: inherit;\n    font-size: inherit;\n    font-weight: inherit;\n    line-height: inherit;\n}\n\n.memory-add-btn:hover {\n    background: var(--border-color);\n    border-color: var(--btn-primary);\n    color: var(--btn-primary);\n}\n\n.language-spinner {\n    display: inline-flex;\n    align-items: center;\n    justify-content: center;\n    padding: 6px 12px;\n}\n\n.spinner {\n    width: 16px;\n    height: 16px;\n    border: 2px solid var(--border-color);\n    border-top-color: var(--btn-primary);\n    border-radius: 50%;\n    animation: spin 0.8s linear infinite;\n}\n\n@keyframes spin {\n    to {\n        transform: rotate(360deg);\n    }\n}\n\n/* Memory Editor Styles */\n.modal-content-large {\n    max-width: 800px;\n    width: 90%;\n}\n\n.memory-editor {\n    font-family: 'Courier New', monospace;\n    font-size: 13px;\n    line-height: 1.5;\n    tab-size: 4;\n    -moz-tab-size: 4;\n}\n\n.memory-editor:focus {\n    outline: 2px solid var(--btn-primary);\n    outline-offset: -1px;\n}\n\n/* Memory Item Styles */\n.memory-item {\n    position: relative;\n    display: inline-flex;\n    align-items: center;\n    padding: 8px 12px;\n    margin: 5px;\n    border-radius: 4px;\n    background-color: var(--bg-primary);\n    border: 1px solid var(--border-color);\n    transition: background-color 0.2s ease;\n    cursor: pointer;\n    overflow: hidden;\n    text-overflow: ellipsis;\n    white-space: nowrap;\n}\n\n.memory-item:hover {\n    background-color: var(--border-color);\n    text-decoration: underline;\n}\n\n.memory-item.removable {\n    padding-right: 28px;\n}\n\n.memory-remove {\n    position: absolute;\n    top: 2px;\n    right: 2px;\n    width: 18px;\n    height: 18px;\n    display: flex;\n    align-items: center;\n    justify-content: center;\n    background: rgba(255, 68, 68, 0.1);\n    border-radius: 3px;\n    cursor: pointer;\n    color: #ff4444;\n    font-size: 14px;\n    font-weight: bold;\n    line-height: 1;\n    transition: all 0.2s;\n}\n\n.memory-remove:hover {\n    background: rgba(255, 68, 68, 0.2);\n    transform: scale(1.1);\n    text-decoration: none;\n}\n\n.memories-container {\n    display: flex;\n    flex-wrap: wrap;\n    gap: 8px;\n}\n\n/* Memory Rename Styles */\n.memory-rename-btn {\n    display: inline-flex;\n    align-items: center;\n    justify-content: center;\n    width: 24px;\n    height: 24px;\n    background: var(--bg-secondary);\n    border: 1px solid var(--border-color);\n    border-radius: 4px;\n    cursor: pointer;\n    color: var(--text-muted);\n    opacity: 0.5;\n    transition: opacity 0.2s ease, background-color 0.2s ease;\n}\n\n.memory-rename-btn:hover {\n    opacity: 1;\n    background-color: var(--border-color);\n}\n\n.memory-rename-input {\n    font-size: inherit;\n    font-weight: inherit;\n    font-family: inherit;\n    color: var(--text-primary);\n    background: transparent;\n    border: none;\n    border-bottom: 1px solid var(--btn-primary);\n    outline: none;\n    padding: 0;\n    flex: 1;\n    min-width: 200px;\n    max-width: 80%;\n}\n\n/* Log Action Buttons (Save, Copy, Clear) */\n.log-action-buttons {\n    position: absolute;\n    top: 15px;\n    right: 20px;\n    z-index: 10;\n    display: flex;\n    gap: 8px;\n    align-items: center;\n}\n\n.log-action-btn {\n    display: flex;\n    align-items: center;\n    gap: 6px;\n    padding: 8px 12px;\n    background-color: var(--bg-secondary);\n    border: 1px solid var(--border-color);\n    border-radius: 4px;\n    color: var(--text-primary);\n    cursor: pointer;\n    opacity: 0.8;\n    transition: opacity 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;\n    font-size: 13px;\n    font-weight: 500;\n}\n\n.log-action-btn:hover {\n    opacity: 1;\n    background-color: var(--border-color);\n}\n\n.log-action-btn svg {\n    flex-shrink: 0;\n}\n\n.log-action-btn-text {\n    display: none;\n    white-space: nowrap;\n}\n\n.log-action-btn:hover .log-action-btn-text {\n    display: inline;\n}\n\n.log-action-btn:disabled {\n    opacity: 0.35;\n    cursor: not-allowed;\n}\n\n.log-action-btn-danger:hover {\n    background-color: var(--border-color);\n    border-color: rgba(220, 53, 53, 0.9);\n    color: var(--log-error);\n}\n"
  },
  {
    "path": "src/serena/resources/dashboard/dashboard.js",
    "content": "class LogMessage {\n    constructor(message, toolNames) {\n        message = this.escapeHtml(message);\n        const logLevel = this.determineLogLevel(message);\n        const highlightedMessage = this.highlightToolNames(message, toolNames);\n        this.$elem = $('<div>').addClass('log-' + logLevel).html(highlightedMessage + '\\n');\n    }\n\n    determineLogLevel(message) {\n        if (message.startsWith('DEBUG')) {\n            return 'debug';\n        } else if (message.startsWith('INFO')) {\n            return 'info';\n        } else if (message.startsWith('WARNING')) {\n            return 'warning';\n        } else if (message.startsWith('ERROR')) {\n            return 'error';\n        } else {\n            return 'default';\n        }\n    }\n\n    highlightToolNames(message, toolNames) {\n        let highlightedMessage = message;\n        toolNames.forEach(function (toolName) {\n            const regex = new RegExp('\\\\b' + toolName + '\\\\b', 'gi');\n            highlightedMessage = highlightedMessage.replace(regex, '<span class=\"tool-name\">' + toolName + '</span>');\n        });\n        return highlightedMessage;\n    }\n\n    escapeHtml(convertString) {\n        if (typeof convertString !== 'string') return convertString;\n\n        const patterns = {\n            '<': '&lt;', '>': '&gt;', '&': '&amp;', '\"': '&quot;', '\\'': '&#x27;', '`': '&#x60;'\n        };\n\n        return convertString.replace(/[<>&\"'`]/g, match => patterns[match]);\n    };\n}\n\nfunction updateThemeAwareImage($img, theme=null) {\n    if (!theme) {\n        const isDarkMode = $('html').data(\"theme\") == 'dark';\n        theme = isDarkMode ? 'dark' : 'light';\n    }\n    console.log(\"updating theme-aware image to theme:\", theme);\n    const newSrc = $img.data('src-' + theme);\n    if (newSrc) {\n        $img.attr('src', newSrc);\n    }\n}\n\n/**\n * Manages banner loading, display, and navigation.\n *\n * When automaticRotationEnabled is true, banners rotate on a timer and arrow\n * buttons are hidden.  When false (the current default), a random initial\n * banner is shown and the user navigates manually via arrow buttons.\n */\nclass BannerRotation {\n    constructor() {\n        this.automaticRotationEnabled = false;\n\n        this.platinumIndex = 0;\n        this.goldIndex = 0;\n        this.platinumTimer = null;\n        this.goldTimer = null;\n        this.platinumInterval = 15000;\n        this.goldInterval = 15000;\n\n        this.init();\n    }\n\n    init() {\n        let self = this;\n        this.loadBanners(function() {\n            self.randomizeInitialBanner('platinum');\n            self.randomizeInitialBanner('gold');\n\n            if (self.automaticRotationEnabled) {\n                self.startPlatinumRotation();\n                self.startGoldRotation();\n                // Hide arrows entirely when rotation is automatic\n                $('.banner-arrow').hide();\n            } else {\n                self.hideArrowsIfSingle();\n                self.bindArrowButtons();\n            }\n        });\n    }\n\n    loadBanners(onSuccess) {\n        $.ajax({\n            url: 'https://oraios-software.de/serena-banners/manifest.php',\n            type: 'GET',\n            success: function (response) {\n                console.log('Banners loaded:', response);\n\n                function fillBanners($container, banners, className) {\n                    $.each(banners, function (index, banner) {\n                        let $img = $('<img src=\"' + banner.image + '\" alt=\"' + banner.alt + '\" class=\"banner-image\">');\n                        if (banner.image_dark) {\n                            $img.addClass('theme-aware-img');\n                            $img.attr('data-src-dark', banner.image_dark);\n                            $img.attr('data-src-light', banner.image);\n                            updateThemeAwareImage($img);\n                        }\n                        let $anchor = $('<a href=\"' + banner.link + '\" target=\"_blank\"></a>');\n                        $anchor.append($img);\n                        let $banner = $('<div class=\"' + className + '-slide\" data-banner=\"' + (index + 1) + '\"></div>');\n                        $banner.append($anchor);\n                        if (index === 0) {\n                            $banner.addClass('active');\n                        }\n                        if (banner.border) {\n                            $img.addClass('banner-border');\n                        }\n                        $container.append($banner);\n                    });\n                }\n\n                fillBanners($('#gold-banners'), response.gold, 'gold-banner');\n                fillBanners($('#platinum-banners'), response.platinum, 'platinum-banner');\n                onSuccess();\n            },\n            error: function (xhr, status, error) {\n                console.error('Error loading banners:', error);\n            }\n        });\n    }\n\n    startPlatinumRotation() {\n        const self = this;\n        this.platinumTimer = setInterval(() => {\n            self.rotatePlatinum('next');\n        }, this.platinumInterval);\n    }\n\n    randomizeInitialBanner(type) {\n        const slideClass = type === 'platinum' ? '.platinum-banner-slide' : '.gold-banner-slide';\n        const $slides = $(slideClass);\n        const total = $slides.length;\n\n        if (total === 0) return;\n\n        const randomIndex = Math.floor(Math.random() * total);\n        if (type === 'platinum') {\n            this.platinumIndex = randomIndex;\n        } else {\n            this.goldIndex = randomIndex;\n        }\n        $slides.removeClass('active');\n        $slides.eq(randomIndex).addClass('active');\n    }\n\n    startGoldRotation() {\n        const self = this;\n        this.goldTimer = setInterval(() => {\n            self.rotateGold('next');\n        }, this.goldInterval);\n    }\n\n    hideArrowsIfSingle() {\n        if ($('.platinum-banner-slide').length <= 1) {\n            $('#platinum-banners .banner-arrow').hide();\n        }\n        if ($('.gold-banner-slide').length <= 1) {\n            $('#gold-banners .banner-arrow').hide();\n        }\n    }\n\n    bindArrowButtons() {\n        let self = this;\n        $('.banner-arrow').on('click', function(e) {\n            e.preventDefault();\n            e.stopPropagation();\n            const target = $(this).data('target');\n            const direction = $(this).hasClass('banner-arrow-right') ? 'next' : 'prev';\n            if (target === 'platinum') {\n                self.rotatePlatinum(direction);\n            } else {\n                self.rotateGold(direction);\n            }\n        });\n    }\n\n    rotatePlatinum(direction) {\n        const $slides = $('.platinum-banner-slide');\n        const total = $slides.length;\n\n        if (total === 0) return;\n\n        // Remove active class from current slide\n        $slides.eq(this.platinumIndex).removeClass('active');\n\n        // Calculate next index\n        if (direction === 'next') {\n            this.platinumIndex = (this.platinumIndex + 1) % total;\n        } else {\n            this.platinumIndex = (this.platinumIndex - 1 + total) % total;\n        }\n\n        // Add active class to new slide\n        $slides.eq(this.platinumIndex).addClass('active');\n\n        // Reset timer when in automatic rotation mode\n        if (this.automaticRotationEnabled) {\n            clearInterval(this.platinumTimer);\n            this.startPlatinumRotation();\n        }\n    }\n\n    rotateGold(direction) {\n        const $groups = $('.gold-banner-slide');\n        const total = $groups.length;\n\n        if (total === 0) return;\n\n        // Remove active class from current group\n        $groups.eq(this.goldIndex).removeClass('active');\n\n        // Calculate next index\n        if (direction === 'next') {\n            this.goldIndex = (this.goldIndex + 1) % total;\n        } else {\n            this.goldIndex = (this.goldIndex - 1 + total) % total;\n        }\n\n        // Add active class to new group\n        $groups.eq(this.goldIndex).addClass('active');\n\n        // Reset timer when in automatic rotation mode\n        if (this.automaticRotationEnabled) {\n            clearInterval(this.goldTimer);\n            this.startGoldRotation();\n        }\n    }\n}\n\nclass Dashboard {\n    constructor() {\n        let self = this;\n\n        // Page state\n        this.currentPage = 'overview';\n        this.configData = null;\n        this.lastConfigDataJson = null; // Cache for comparison\n        this.jetbrainsMode = false;\n        this.activeProjectName = null;\n        this.languageToRemove = null;\n        this.currentMemoryName = null;\n        this.originalMemoryContent = null;\n        this.memoryContentDirty = false;\n        this.memoryToDelete = null;\n        this.isAddingLanguage = false;\n        this.waitingForConfigPollingResult = false;\n        this.waitingForExecutionsPollingResult = false;\n        this.originalSerenaConfigContent = null;\n        this.serenaConfigContentDirty = false;\n\n        // Execution tracking\n        this.cancelledExecutions = [];\n        this.executionToCancel = null;\n\n        // Tool names and stats\n        this.toolNames = [];\n        this.currentMaxIdx = -1;\n        this.pollInterval = null;\n        this.configPollInterval = null;\n        this.executionsPollInterval = null;\n        this.heartbeatFailureCount = 0;\n\n        // jQuery elements\n        this.$logContainer = $('#log-container');\n        this.$errorContainer = $('#error-container');\n        this.$saveLogsBtn = $('#save-logs-btn');\n        this.$copyLogsBtn = $('#copy-logs-btn');\n        this.$clearLogsBtn = $('#clear-logs-btn');\n        this.$menuToggle = $('#menu-toggle');\n        this.$menuDropdown = $('#menu-dropdown');\n        this.$menuShutdown = $('#menu-shutdown');\n        this.$themeToggle = $('#theme-toggle');\n        this.$themeIcon = $('#theme-icon');\n        this.$themeText = $('#theme-text');\n        this.$configDisplay = $('#config-display');\n        this.$basicStatsDisplay = $('#basic-stats-display');\n        this.$statsSection = $('#stats-section');\n        this.$refreshStats = $('#refresh-stats');\n        this.$clearStats = $('#clear-stats');\n        this.$projectsDisplay = $('#projects-display');\n        this.$projectsHeader = $('#projects-header');\n        this.$availableToolsDisplay = $('#available-tools-display');\n        this.$availableModesDisplay = $('#available-modes-display');\n        this.$availableContextsDisplay = $('#available-contexts-display');\n        this.$addLanguageModal = $('#add-language-modal');\n        this.$modalLanguageSelect = $('#modal-language-select');\n        this.$modalProjectName = $('#modal-project-name');\n        this.$modalAddBtn = $('#modal-add-btn');\n        this.$modalCancelBtn = $('#modal-cancel-btn');\n        this.$modalClose = $('.modal-close');\n        this.$removeLanguageModal = $('#remove-language-modal');\n        this.$removeLanguageName = $('#remove-language-name');\n        this.$removeModalOkBtn = $('#remove-modal-ok-btn');\n        this.$removeModalCancelBtn = $('#remove-modal-cancel-btn');\n        this.$modalCloseRemove = $('.modal-close-remove');\n        this.$editMemoryModal = $('#edit-memory-modal');\n        this.$editMemoryName = $('#edit-memory-name');\n        this.$editMemoryRenameBtn = $('#edit-memory-rename-btn');\n        this.$editMemoryRenameInput = $('#edit-memory-rename-input');\n        this.$editMemoryContent = $('#edit-memory-content');\n        this.$editMemorySaveBtn = $('#edit-memory-save-btn');\n        this.$editMemoryCancelBtn = $('#edit-memory-cancel-btn');\n        this.$modalCloseEditMemory = $('.modal-close-edit-memory');\n        this.$deleteMemoryModal = $('#delete-memory-modal');\n        this.$deleteMemoryName = $('#delete-memory-name');\n        this.$deleteMemoryOkBtn = $('#delete-memory-ok-btn');\n        this.$deleteMemoryCancelBtn = $('#delete-memory-cancel-btn');\n        this.$modalCloseDeleteMemory = $('.modal-close-delete-memory');\n        this.$createMemoryModal = $('#create-memory-modal');\n        this.$createMemoryProjectName = $('#create-memory-project-name');\n        this.$createMemoryNameInput = $('#create-memory-name-input');\n        this.$createMemoryCreateBtn = $('#create-memory-create-btn');\n        this.$createMemoryCancelBtn = $('#create-memory-cancel-btn');\n        this.$modalCloseCreateMemory = $('.modal-close-create-memory');\n        this.$activeExecutionQueueDisplay = $('#active-executions-display');\n        this.$lastExecutionDisplay = $('#last-execution-display');\n        this.$cancelledExecutionsDisplay = $('#cancelled-executions-display');\n        this.$cancelExecutionModal = $('#cancel-execution-modal');\n        this.$cancelExecutionOkBtn = $('#cancel-execution-ok-btn');\n        this.$cancelExecutionCancelBtn = $('#cancel-execution-cancel-btn');\n        this.$modalCloseCancelExecution = $('.modal-close-cancel-execution');\n        this.$editSerenaConfigModal = $('#edit-serena-config-modal');\n        this.$editSerenaConfigContent = $('#edit-serena-config-content');\n        this.$editSerenaConfigSaveBtn = $('#edit-serena-config-save-btn');\n        this.$editSerenaConfigCancelBtn = $('#edit-serena-config-cancel-btn');\n        this.$modalCloseEditSerenaConfig = $('.modal-close-edit-serena-config');\n        this.$newsSection = $('#news-section');\n        this.$newsDisplay = $('#news-display');\n\n        // Chart references\n        this.countChart = null;\n        this.tokensChart = null;\n        this.inputChart = null;\n        this.outputChart = null;\n\n        // Register event handlers\n        this.$saveLogsBtn.click(this.saveLogs.bind(this));\n        this.$copyLogsBtn.click(this.copyLogs.bind(this));\n        this.$clearLogsBtn.click(this.clearLogs.bind(this));\n        this.$menuShutdown.click(function (e) {\n            e.preventDefault();\n            self.shutdown();\n        });\n        this.$menuToggle.click(this.toggleMenu.bind(this));\n        this.$themeToggle.click(this.toggleTheme.bind(this));\n        this.$refreshStats.click(this.loadStats.bind(this));\n        this.$clearStats.click(this.clearStats.bind(this));\n        this.$modalAddBtn.click(this.addLanguageFromModal.bind(this));\n        this.$modalCancelBtn.click(this.closeLanguageModal.bind(this));\n        this.$modalClose.click(this.closeLanguageModal.bind(this));\n        this.$removeModalOkBtn.click(this.confirmRemoveLanguageOk.bind(this));\n        this.$removeModalCancelBtn.click(this.closeRemoveLanguageModal.bind(this));\n        this.$modalCloseRemove.click(this.closeRemoveLanguageModal.bind(this));\n        this.$editMemorySaveBtn.click(this.saveMemoryFromModal.bind(this));\n        this.$editMemoryCancelBtn.click(this.closeEditMemoryModal.bind(this));\n        this.$modalCloseEditMemory.click(this.closeEditMemoryModal.bind(this));\n        this.$editMemoryContent.on('input', this.trackMemoryChanges.bind(this));\n        this.$editMemoryRenameBtn.click(this.startMemoryRename.bind(this));\n        this.$editMemoryRenameInput.keydown(function (e) {\n            if (e.which === 13) { // Enter key\n                e.preventDefault();\n                self.commitMemoryRename();\n            } else if (e.which === 27) { // Escape key\n                e.preventDefault();\n                self.cancelMemoryRename();\n            }\n        });\n        this.$editMemoryRenameInput.on('blur', function () {\n            self.cancelMemoryRename();\n        });\n        this.$deleteMemoryOkBtn.click(this.confirmDeleteMemoryOk.bind(this));\n        this.$deleteMemoryCancelBtn.click(this.closeDeleteMemoryModal.bind(this));\n        this.$modalCloseDeleteMemory.click(this.closeDeleteMemoryModal.bind(this));\n        this.$createMemoryCreateBtn.click(this.createMemoryFromModal.bind(this));\n        this.$createMemoryCancelBtn.click(this.closeCreateMemoryModal.bind(this));\n        this.$modalCloseCreateMemory.click(this.closeCreateMemoryModal.bind(this));\n        this.$createMemoryNameInput.keypress(function (e) {\n            if (e.which === 13) { // Enter key\n                e.preventDefault();\n                self.createMemoryFromModal();\n            }\n        });\n        this.$cancelExecutionOkBtn.click(this.confirmCancelExecutionOk.bind(this));\n        this.$cancelExecutionCancelBtn.click(this.closeCancelExecutionModal.bind(this));\n        this.$modalCloseCancelExecution.click(this.closeCancelExecutionModal.bind(this));\n        this.$editSerenaConfigSaveBtn.click(this.saveSerenaConfigFromModal.bind(this));\n        this.$editSerenaConfigCancelBtn.click(this.closeEditSerenaConfigModal.bind(this));\n        this.$modalCloseEditSerenaConfig.click(this.closeEditSerenaConfigModal.bind(this));\n\n        // Page navigation\n        $('[data-page]').click(function (e) {\n            e.preventDefault();\n            const page = $(this).data('page');\n            self.navigateToPage(page);\n        });\n\n        // Close menu when clicking outside\n        $(document).click(function (e) {\n            if (!$(e.target).closest('.header-nav').length) {\n                self.$menuDropdown.hide();\n            }\n        });\n\n        // Close modals when clicking outside\n        this.$addLanguageModal.click(function (e) {\n            if ($(e.target).hasClass('modal')) {\n                self.closeLanguageModal();\n            }\n        });\n\n        this.$removeLanguageModal.click(function (e) {\n            if ($(e.target).hasClass('modal')) {\n                self.closeRemoveLanguageModal();\n            }\n        });\n\n        this.$editMemoryModal.click(function (e) {\n            if ($(e.target).hasClass('modal')) {\n                self.closeEditMemoryModal();\n            }\n        });\n\n        this.$deleteMemoryModal.click(function (e) {\n            if ($(e.target).hasClass('modal')) {\n                self.closeDeleteMemoryModal();\n            }\n        });\n\n        this.$createMemoryModal.click(function (e) {\n            if ($(e.target).hasClass('modal')) {\n                self.closeCreateMemoryModal();\n            }\n        });\n\n        this.$editSerenaConfigModal.click(function (e) {\n            if ($(e.target).hasClass('modal')) {\n                self.closeEditSerenaConfigModal();\n            }\n        });\n\n        // Collapsible sections\n        $('.collapsible-header').click(function () {\n            const $header = $(this);\n            const $content = $header.next('.collapsible-content');\n            const $icon = $header.find('.toggle-icon');\n\n            $content.slideToggle(300);\n            $icon.toggleClass('expanded');\n        });\n\n        // Initialize theme\n        this.initializeTheme();\n\n        // Initialize banner rotation\n        this.bannerRotation = new BannerRotation();\n\n        // Add ESC key handler for closing modals\n        $(document).keydown(function (e) {\n            if (e.key === 'Escape' || e.keyCode === 27) {\n                if (self.$addLanguageModal.is(':visible')) {\n                    self.closeLanguageModal();\n                } else if (self.$removeLanguageModal.is(':visible')) {\n                    self.closeRemoveLanguageModal();\n                } else if (self.$editMemoryModal.is(':visible')) {\n                    self.closeEditMemoryModal();\n                } else if (self.$deleteMemoryModal.is(':visible')) {\n                    self.closeDeleteMemoryModal();\n                } else if (self.$createMemoryModal.is(':visible')) {\n                    self.closeCreateMemoryModal();\n                }\n            }\n        });\n\n        // Initialize the application\n        this.loadToolNames().then(function () {\n            // Start on overview page\n            self.loadNews();\n            self.loadConfigOverview();\n            self.startConfigPolling();\n            self.startExecutionsPolling();\n        });\n        // Initialize heartbeat interval\n        setInterval(this.heartbeat.bind(this), 250);\n    }\n\n    heartbeat() {\n        let self = this;\n        $.ajax({\n            url: '/heartbeat',\n            type: 'GET',\n            success: function (response) {\n                self.heartbeatFailureCount = 0;\n            },\n            error: function (xhr, status, error) {\n                self.heartbeatFailureCount++;\n                console.error('Heartbeat failure; count = ', self.heartbeatFailureCount);\n                if (self.heartbeatFailureCount >= 1) {\n                    console.log('Server appears to be down, closing tab');\n                    window.close();\n                }\n            },\n        });\n    }\n\n    toggleMenu() {\n        this.$menuDropdown.toggle();\n    }\n\n    navigateToPage(page) {\n        // Hide menu\n        this.$menuDropdown.hide();\n\n        // Hide all pages\n        $('.page-view').hide();\n\n        // Show selected page\n        $('#page-' + page).show();\n\n        // Update menu active state\n        $('[data-page]').removeClass('active');\n        $('[data-page=\"' + page + '\"]').addClass('active');\n\n        // Update current page\n        this.currentPage = page;\n\n        // Stop all polling\n        this.stopPolling();\n\n        // Start appropriate polling for the page\n        if (page === 'overview') {\n            this.loadNews();\n            this.loadConfigOverview();\n            this.startConfigPolling();\n            this.startExecutionsPolling();\n        } else if (page === 'logs') {\n            this.loadLogs();\n        } else if (page === 'stats') {\n            this.loadStats();\n        }\n    }\n\n    stopPolling() {\n        if (this.pollInterval) {\n            clearInterval(this.pollInterval);\n            this.pollInterval = null;\n        }\n        if (this.configPollInterval) {\n            clearInterval(this.configPollInterval);\n            this.configPollInterval = null;\n        }\n        if (this.executionsPollInterval) {\n            clearInterval(this.executionsPollInterval);\n            this.executionsPollInterval = null;\n        }\n    }\n\n    // ===== Config Overview Methods =====\n\n    loadConfigOverview() {\n        if (this.waitingForConfigPollingResult) {\n            console.log('Still waiting for previous config poll result, skipping this poll');\n            return;\n        }\n        this.waitingForConfigPollingResult = true;\n        console.log('Polling for config overview...');\n        let self = this;\n        $.ajax({\n            url: '/get_config_overview',\n            type: 'GET',\n            success: function (response) {\n                // Check if the config data has actually changed\n                const currentConfigJson = JSON.stringify(response);\n                const hasChanged = self.lastConfigDataJson !== currentConfigJson;\n\n                if (hasChanged) {\n                    console.log('Config has changed, updating display');\n                    self.lastConfigDataJson = currentConfigJson;\n                    self.configData = response;\n                    self.jetbrainsMode = response.jetbrains_mode;\n                    self.activeProjectName = response.active_project.name;\n                    self.displayConfig(response);\n                    self.displayBasicStats(response.tool_stats_summary);\n                    self.displayProjects(response.registered_projects);\n                    self.displayAvailableTools(response.available_tools);\n                    self.displayAvailableModes(response.available_modes);\n                    self.displayAvailableContexts(response.available_contexts);\n                } else {\n                    console.log('Config unchanged, skipping display update');\n                }\n            }, error: function (xhr, status, error) {\n                console.error('Error loading config overview:', error);\n                self.$configDisplay.html('<div class=\"error-message\">Error loading configuration</div>');\n                self.$basicStatsDisplay.html('<div class=\"error-message\">Error loading stats</div>');\n                self.$projectsDisplay.html('<div class=\"error-message\">Error loading projects</div>');\n                self.$availableToolsDisplay.html('<div class=\"error-message\">Error loading tools</div>');\n                self.$availableModesDisplay.html('<div class=\"error-message\">Error loading modes</div>');\n                self.$availableContextsDisplay.html('<div class=\"error-message\">Error loading contexts</div>');\n            }, complete: function () {\n                self.waitingForConfigPollingResult = false;\n            }\n        });\n    }\n\n    startConfigPolling() {\n        this.configPollInterval = setInterval(this.loadConfigOverview.bind(this), 1000);\n    }\n\n    startExecutionsPolling() {\n        // Poll every 1 second for executions (independent of config polling)\n        // This ensures stuck executions can still be cancelled even if config polling is blocked\n        this.loadExecutions()\n        this.executionsPollInterval = setInterval(() => {\n            this.loadQueuedExecutions();\n            this.loadLastExecution();\n        }, 1000);\n    }\n\n    displayConfig(config) {\n        try {\n            // Check if tools and memories sections are currently expanded\n            const $existingToolsContent = $('#tools-content');\n            const $existingMemoriesContent = $('#memories-content');\n            const wasToolsExpanded = $existingToolsContent.is(':visible');\n            const wasMemoriesExpanded = $existingMemoriesContent.is(':visible');\n\n            let html = '<div class=\"config-grid\">';\n\n            // Project info\n            html += '<div class=\"config-label\">Active Project:</div>';\n            if (config.active_project.name && config.active_project.path) {\n                const configPath = config.active_project.path + '/.serena/project.yml';\n                html += '<div class=\"config-value\"><span title=\"Project configuration in ' + configPath + '\">' + config.active_project.name + '</span></div>';\n            } else {\n                html += '<div class=\"config-value\">' + (config.active_project.name || 'None') + '</div>';\n            }\n\n            html += '<div class=\"config-label\">Languages:</div>';\n            if (this.jetbrainsMode) {\n                html += '<div class=\"config-value\">Using JetBrains backend</div>';\n            } else {\n                html += '<div class=\"config-value\">';\n                if (config.languages && config.languages.length > 0) {\n                    html += '<div class=\"languages-container\">';\n                    config.languages.forEach(function (language, index) {\n                        const isRemovable = config.languages.length > 1;\n                        html += '<div class=\"language-badge' + (isRemovable ? ' removable' : '') + '\">';\n                        html += language;\n                        if (isRemovable) {\n                            html += '<span class=\"language-remove\" data-language=\"' + language + '\">&times;</span>';\n                        }\n                        html += '</div>';\n                    });\n                    // Add the \"Add Language\" button inline with language badges (only if active project exists)\n                    if (config.active_project && config.active_project.name) {\n                        // TODO: address after refactoring, it's not awesome to keep depending on state\n                        if (this.isAddingLanguage) {\n                            html += '<div id=\"add-language-spinner\" class=\"language-spinner\">';\n                        } else {\n                            html += '<button id=\"add-language-btn\" class=\"btn language-add-btn\">+ Add Language</button>';\n                            html += '<div id=\"add-language-spinner\" class=\"language-spinner\" style=\"display:none;\">';\n                        }\n                        html += '<div class=\"spinner\"></div>';\n                        html += '</div>';\n                    }\n                    html += '</div>';\n                } else {\n                    html += 'N/A';\n                }\n                html += '</div>';\n            }\n\n            // Context info\n            html += '<div class=\"config-label\">Context:</div>';\n            html += '<div class=\"config-value\"><span title=\"' + config.context.path + '\">' + config.context.name + '</span></div>';\n\n            // Modes info\n            html += '<div class=\"config-label\">Active Modes:</div>';\n            html += '<div class=\"config-value\">';\n            if (config.modes.length > 0) {\n                const modeSpans = config.modes.map(function (mode) {\n                    return '<span title=\"' + mode.path + '\">' + mode.name + '</span>';\n                });\n                html += modeSpans.join(', ');\n            } else {\n                html += 'None';\n            }\n            html += '</div>';\n\n            // File Encoding info\n            html += '<div class=\"config-label\">File Encoding:</div>';\n            html += '<div class=\"config-value\">' + (config.encoding || 'N/A') + '</div>';\n\n            // Current Client info\n            html += '<div class=\"config-label\">Current Client:</div>';\n            html += '<div class=\"config-value\">' + (config.current_client || 'None') + '</div>';\n\n            html += '</div>';\n\n            // Active tools - collapsible\n            html += '<div style=\"margin-top: 20px;\">';\n            html += '<h3 class=\"collapsible-header\" id=\"tools-header\" style=\"font-size: 16px; margin: 0;\">';\n            html += '<span>Active Tools (' + config.active_tools.length + ')</span>';\n            html += '<span class=\"toggle-icon' + (wasToolsExpanded ? ' expanded' : '') + '\">▼</span>';\n            html += '</h3>';\n            html += '<div class=\"collapsible-content tools-grid\" id=\"tools-content\" style=\"' + (wasToolsExpanded ? '' : 'display:none;') + ' margin-top: 10px;\">';\n            config.active_tools.forEach(function (tool) {\n                html += '<div class=\"tool-item\" title=\"' + tool + '\">' + tool + '</div>';\n            });\n            html += '</div>';\n            html += '</div>';\n\n            // Available memories - collapsible (show if memories exist or if project exists)\n            if (config.active_project && config.active_project.name) {\n                html += '<div style=\"margin-top: 20px;\">';\n                html += '<h3 class=\"collapsible-header\" id=\"memories-header\" style=\"font-size: 16px; margin: 0;\">';\n                const memoryCount = (config.available_memories && config.available_memories.length) || 0;\n                html += '<span>Available Memories (' + memoryCount + ')</span>';\n                html += '<span class=\"toggle-icon' + (wasMemoriesExpanded ? ' expanded' : '') + '\">▼</span>';\n                html += '</h3>';\n                html += '<div class=\"collapsible-content memories-container\" id=\"memories-content\" style=\"' + (wasMemoriesExpanded ? '' : 'display:none;') + ' margin-top: 10px;\">';\n                if (config.available_memories && config.available_memories.length > 0) {\n                    config.available_memories.forEach(function (memory) {\n                        html += '<div class=\"memory-item removable\" data-memory=\"' + memory + '\">';\n                        html += memory;\n                        html += '<span class=\"memory-remove\" data-memory=\"' + memory + '\">&times;</span>';\n                        html += '</div>';\n                    });\n                }\n                // Add Create Memory button\n                html += '<button id=\"create-memory-btn\" class=\"memory-add-btn\">+ Add Memory</button>';\n                html += '</div>';\n                html += '</div>';\n            }\n\n            // Configuration help link and edit config button\n            html += '<div style=\"margin-top: 15px; display: flex; gap: 10px; align-items: center;\">';\n            html += '<div style=\"flex: 1; padding: 10px; background: var(--bg-secondary); border-radius: 4px; font-size: 13px; border: 1px solid var(--border-color);\">';\n            html += '<span style=\"color: var(--text-muted);\">📖</span> ';\n            html += '<a href=\"https://oraios.github.io/serena/02-usage/050_configuration.html\" target=\"_blank\" rel=\"noopener noreferrer\" style=\"color: var(--btn-primary); text-decoration: none; font-weight: 500;\">View Configuration Guide</a>';\n            html += '</div>';\n            html += '<button id=\"edit-serena-config-btn\" class=\"btn language-add-btn\" style=\"white-space: nowrap; padding: 10px; \">Edit Global Serena Config</button>';\n            html += '</div>';\n\n            this.$configDisplay.html(html);\n\n            // Attach event handlers for the dynamically created add language button\n            $('#add-language-btn').click(this.openLanguageModal.bind(this));\n\n            // Attach event handler for edit serena config button\n            $('#edit-serena-config-btn').click(this.openEditSerenaConfigModal.bind(this));\n\n            // Attach event handlers for language remove buttons\n            const self = this;\n            $('.language-remove').click(function (e) {\n                e.preventDefault();\n                e.stopPropagation();\n                const language = $(this).data('language');\n                self.confirmRemoveLanguage(language);\n            });\n\n            // Attach event handlers for memory items\n            $('.memory-item').click(function (e) {\n                e.preventDefault();\n                const memoryName = $(this).data('memory');\n                self.openEditMemoryModal(memoryName);\n            });\n\n            // Attach event handlers for memory remove buttons\n            $('.memory-remove').click(function (e) {\n                e.preventDefault();\n                e.stopPropagation();\n                const memoryName = $(this).data('memory');\n                self.confirmDeleteMemory(memoryName);\n            });\n\n            // Attach event handler for create memory button\n            $('#create-memory-btn').click(this.openCreateMemoryModal.bind(this));\n\n            // Re-attach collapsible handler for the newly created tools header\n            $('#tools-header').click(function () {\n                const $header = $(this);\n                const $content = $('#tools-content');\n                const $icon = $header.find('.toggle-icon');\n\n                $content.slideToggle(300);\n                $icon.toggleClass('expanded');\n            });\n\n            // Re-attach collapsible handler for the newly created memories header\n            $('#memories-header').click(function () {\n                const $header = $(this);\n                const $content = $('#memories-content');\n                const $icon = $header.find('.toggle-icon');\n\n                $content.slideToggle(300);\n                $icon.toggleClass('expanded');\n            });\n        } catch (error) {\n            console.error('Error in displayConfig:', error);\n            this.$configDisplay.html('<div class=\"error-message\">Error displaying configuration: ' + error.message + '</div>');\n        }\n    }\n\n    displayBasicStats(stats) {\n        if (Object.keys(stats).length === 0) {\n            this.$basicStatsDisplay.html('<div class=\"no-stats-message\">No tool usage stats collected yet.</div>');\n            return;\n        }\n\n        // Sort tools by call count (descending)\n        const sortedTools = Object.keys(stats).sort((a, b) => {\n            return stats[b].num_calls - stats[a].num_calls;\n        });\n\n        const maxCalls = Math.max(...sortedTools.map(tool => stats[tool].num_calls));\n\n        let html = '';\n        sortedTools.forEach(function (toolName) {\n            const count = stats[toolName].num_calls;\n            const percentage = maxCalls > 0 ? (count / maxCalls * 100) : 0;\n\n            html += '<div class=\"stat-bar-container\">';\n            html += '<div class=\"stat-tool-name\" title=\"' + toolName + '\">' + toolName + '</div>';\n            html += '<div class=\"bar-wrapper\">';\n            html += '<div class=\"bar\" style=\"width: ' + percentage + '%\"></div>';\n            html += '</div>';\n            html += '<div class=\"stat-count\">' + count + '</div>';\n            html += '</div>';\n        });\n\n        this.$basicStatsDisplay.html(html);\n    }\n\n    displayProjects(projects) {\n        if (!projects || projects.length === 0) {\n            this.$projectsDisplay.html('<div class=\"no-stats-message\">No projects registered.</div>');\n            return;\n        }\n\n        let html = '';\n        projects.forEach(function (project) {\n            const activeClass = project.is_active ? ' active' : '';\n            html += '<div class=\"project-item' + activeClass + '\">';\n            html += '<div class=\"project-name\" title=\"' + project.name + '\">' + project.name + '</div>';\n            html += '<div class=\"project-path\" title=\"' + project.path + '\">' + project.path + '</div>';\n            html += '</div>';\n        });\n\n        this.$projectsDisplay.html(html);\n    }\n\n    displayAvailableTools(tools) {\n        if (!tools || tools.length === 0) {\n            this.$availableToolsDisplay.html('<div class=\"no-stats-message\">All tools are active.</div>');\n            return;\n        }\n\n        let html = '';\n        tools.forEach(function (tool) {\n            html += '<div class=\"info-item\" title=\"' + tool.name + '\">' + tool.name + '</div>';\n        });\n\n        this.$availableToolsDisplay.html(html);\n    }\n\n    displayAvailableModes(modes) {\n        if (!modes || modes.length === 0) {\n            this.$availableModesDisplay.html('<div class=\"no-stats-message\">No modes available.</div>');\n            return;\n        }\n\n        let html = '';\n        modes.forEach(function (mode) {\n            const activeClass = mode.is_active ? ' active' : '';\n            html += '<div class=\"info-item' + activeClass + '\" title=\"' + mode.path + '\">' + mode.name + '</div>';\n        });\n\n        this.$availableModesDisplay.html(html);\n    }\n\n    displayAvailableContexts(contexts) {\n        if (!contexts || contexts.length === 0) {\n            this.$availableContextsDisplay.html('<div class=\"no-stats-message\">No contexts available.</div>');\n            return;\n        }\n\n        let html = '';\n        contexts.forEach(function (context) {\n            const activeClass = context.is_active ? ' active' : '';\n            html += '<div class=\"info-item' + activeClass + '\" title=\"' + context.path + '\">' + context.name + '</div>';\n        });\n\n        this.$availableContextsDisplay.html(html);\n    }\n\n    // ===== Executions Methods =====\n\n    loadQueuedExecutions() {\n        let self = this;\n        $.ajax({\n            url: '/queued_task_executions', type: 'GET', success: function (response) {\n                if (response.status === 'success') {\n                    self.displayActiveExecutionsQueue(response.queued_executions || []);\n                } else {\n                    console.error('Error loading executions:', response.message);\n                }\n            }, error: function (xhr, status, error) {\n                console.error('Error loading executions:', error);\n                self.$activeExecutionQueueDisplay.html('<div class=\"error-message\">Error loading executions</div>');\n            }\n        });\n    }\n\n    loadLastExecution() {\n        let self = this;\n        $.ajax({\n            url: '/last_execution', type: 'GET', success: function (response) {\n                if (response.status === 'success') {\n                    if (response.last_execution !== null && response.last_execution.logged) {\n                        self.displayLastExecution(response.last_execution);\n                    }\n                } else {\n                    console.error('Error loading last execution:', response.message);\n                }\n            }, error: function (xhr, status, error) {\n                console.error('Error loading last execution:', error);\n                self.$lastExecutionDisplay.html('<div class=\"error-message\">Error loading last execution</div>');\n            }\n        });\n    }\n\n    loadExecutions() {\n        if (this.waitingForExecutionsPollingResult) {\n            console.log('Still waiting for previous executions poll result, skipping this poll');\n        } else {\n            this.waitingForExecutionsPollingResult = true;\n            console.log('Polling for executions...');\n            this.loadQueuedExecutions();\n            this.loadLastExecution();\n        }\n    }\n\n    displayActiveExecutionsQueue(executions) {\n        if (!executions || executions.length === 0) {\n            return;\n        }\n\n        let html = '<div class=\"execution-list\">';\n        let self = this;\n\n        executions.forEach(function (execution) {\n            const isRunning = execution.is_running;\n            const logged = execution.logged;\n\n            if (!logged) {\n                return; // Skip unlogged executions\n            }\n\n            let itemClass = 'execution-item';\n            if (isRunning) {\n                itemClass += ' running';\n            }\n\n            // Escape JSON for HTML attribute - replace single quotes and use HTML entities\n            const executionJson = JSON.stringify(execution).replace(/'/g, '&#39;');\n\n            html += '<div class=\"' + itemClass + '\" data-task-id=\"' + execution.task_id + '\" data-execution=\\'' + executionJson + '\\'>';\n\n            if (isRunning) {\n                html += '<div class=\"execution-spinner\"></div>';\n            }\n\n            html += '<div class=\"execution-name\">' + self.escapeHtml(execution.name) + '</div>';\n\n            if (isRunning) {\n                html += '<div class=\"execution-meta\">#' + execution.task_id + '</div>';\n            } else {\n                html += '<div class=\"execution-meta\">queued · #' + execution.task_id + '</div>';\n            }\n\n            html += '<button class=\"execution-cancel-btn\" data-task-id=\"' + execution.task_id + '\" data-is-running=\"' + isRunning + '\">✕</button>';\n            html += '</div>';\n        });\n\n        html += '</div>';\n        this.$activeExecutionQueueDisplay.html(html);\n\n        // Attach event handlers for cancel buttons\n        $('.execution-cancel-btn').click(function (e) {\n            e.preventDefault();\n            console.log('Cancel button clicked');\n            const $item = $(this).closest('.execution-item');\n            console.log('Found item:', $item.length);\n            const executionDataStr = $item.attr('data-execution');\n            console.log('Execution data string:', executionDataStr);\n            if (executionDataStr) {\n                // Unescape HTML entities\n                const unescapedStr = executionDataStr.replace(/&#39;/g, \"'\");\n                const executionData = JSON.parse(unescapedStr);\n                console.log('Parsed execution data:', executionData);\n                self.confirmCancelExecution(executionData);\n            } else {\n                console.error('No execution data found on element');\n            }\n        });\n\n        // Update cancelled executions display\n        this.displayCancelledExecutions(executions);\n    }\n\n    displayLastExecution(execution) {\n        if (!execution) {\n            this.$lastExecutionDisplay.html('<div class=\"no-stats-message\">No executions yet.</div>');\n            return;\n        }\n\n        const isSuccess = execution.finished_successfully;\n        let html = '<div class=\"last-execution-container' + (isSuccess ? '' : ' error') + '\">';\n\n        html += '<div class=\"last-execution-icon-container\">';\n        html += isSuccess ? '✓' : '✕';\n        html += '</div>';\n\n        html += '<div class=\"last-execution-body\">';\n        html += '<div class=\"last-execution-status\">' + (isSuccess ? 'Succeeded' : 'Failed') + '</div>';\n        html += '<div class=\"last-execution-name\">' + this.escapeHtml(execution.name) + '</div>';\n        html += '</div>';\n\n        html += '<div class=\"execution-meta\">#' + execution.task_id + '</div>';\n        html += '</div>';\n\n        this.$lastExecutionDisplay.html(html);\n    }\n\n    displayCancelledExecutions() {\n        let self = this;\n        const cancelledExecs = self.cancelledExecutions\n\n        if (cancelledExecs.length === 0) {\n            // Hide the cancelled executions section\n            $('.executions-section').eq(2).hide();\n            return;\n        }\n\n        // Show the cancelled executions section\n        $('.executions-section').eq(2).show();\n\n        let html = '<div class=\"execution-list\">';\n\n        cancelledExecs.forEach(function (execution) {\n            const isAbandoned = execution.is_running;\n\n            html += '<div class=\"execution-item ' + (isAbandoned ? 'abandoned' : 'cancelled') + '\">';\n            html += '<div class=\"execution-icon ' + (isAbandoned ? 'abandoned' : 'cancelled') + '\">';\n            html += isAbandoned ? '!' : '✕';\n            html += '</div>';\n            html += '<div class=\"execution-name\">' + self.escapeHtml(execution.name) + '</div>';\n            html += '<div class=\"execution-meta\">' + (isAbandoned ? 'abandoned · ' : '') + '#' + execution.task_id + '</div>';\n            html += '</div>';\n        });\n\n        html += '</div>';\n        this.$cancelledExecutionsDisplay.html(html);\n    }\n\n    confirmCancelExecution(executionData) {\n        console.log('confirmCancelExecution called with:', executionData);\n        this.executionToCancel = executionData;\n\n        if (executionData.is_running) {\n            // Show modal for running executions\n            console.log('Showing modal for running execution');\n            this.$cancelExecutionModal.fadeIn(200);\n        } else {\n            // Directly cancel queued executions\n            console.log('Directly cancelling queued execution');\n            this.cancelExecution(executionData);\n        }\n    }\n\n    confirmCancelExecutionOk() {\n        if (this.executionToCancel) {\n            this.cancelExecution(this.executionToCancel);\n        }\n        this.closeCancelExecutionModal();\n    }\n\n    cancelExecution(executionData) {\n        const self = this;\n\n        console.log('cancelExecution called with full execution data:', executionData);\n        console.log('Attempting to cancel task:', executionData.task_id);\n\n        // Call backend API to cancel the task\n        $.ajax({\n            url: '/cancel_task_execution', type: 'POST', contentType: 'application/json', data: JSON.stringify({\n                task_id: executionData.task_id\n            }), success: function (response) {\n                console.log('Cancel task response:', response);\n\n                if (response.status === 'error') {\n                    console.error('Backend returned error status:', response.message);\n                    alert('Error cancelling task: ' + response.message);\n                    return;\n                }\n\n                if (response.status === 'success') {\n                    if (response.was_cancelled) {\n                        console.log('Task ' + executionData.task_id + ' was successfully cancelled');\n                        // Add to cancelled list (only managed in JS, not persisted)\n                        const alreadyCancelled = self.cancelledExecutions.some(function (exec) {\n                            return exec.task_id === executionData.task_id;\n                        });\n                        if (!alreadyCancelled) {\n                            console.log('Adding execution to cancelled list:', executionData);\n                            self.cancelledExecutions.push(executionData);\n                            console.log('Cancelled executions array now contains:', self.cancelledExecutions);\n                        } else {\n                            console.log('Execution already in cancelled list');\n                        }\n                    } else {\n                        console.log('Task ' + executionData.task_id + ' could not be cancelled (may have already completed). ' + response.message);\n                    }\n                    // Refresh display regardless\n                    self.loadQueuedExecutions();\n                } else {\n                    console.error('Unexpected response status:', response.status);\n                    alert('Unexpected response from server');\n                }\n            }, error: function (xhr, status, error) {\n                console.error('AJAX error cancelling task:');\n                console.error('  Status:', status);\n                console.error('  Error:', error);\n                console.error('  XHR:', xhr);\n                console.error('  Response:', xhr.responseText);\n\n                let errorMessage = error;\n                if (xhr.responseJSON && xhr.responseJSON.message) {\n                    errorMessage = xhr.responseJSON.message;\n                } else if (xhr.responseText) {\n                    errorMessage = xhr.responseText;\n                }\n\n                alert('Error cancelling task: ' + errorMessage);\n            }\n        });\n    }\n\n    closeCancelExecutionModal() {\n        this.$cancelExecutionModal.fadeOut(200);\n        this.executionToCancel = null;\n    }\n\n    escapeHtml(text) {\n        if (typeof text !== 'string') return text;\n\n        const patterns = {\n            '<': '&lt;', '>': '&gt;', '&': '&amp;', '\"': '&quot;', \"'\": '&#x27;', '`': '&#x60;'\n        };\n\n        return text.replace(/[<>&\"'`]/g, match => patterns[match]);\n    }\n\n    // ===== Logs Methods =====\n\n    displayLogMessage(message) {\n        this.$logContainer.append(new LogMessage(message, this.toolNames).$elem);\n    }\n\n    loadToolNames() {\n        let self = this;\n        return $.ajax({\n            url: '/get_tool_names', type: 'GET', success: function (response) {\n                self.toolNames = response.tool_names || [];\n                console.log('Loaded tool names:', self.toolNames);\n            }, error: function (xhr, status, error) {\n                console.error('Error loading tool names:', error);\n            }\n        });\n    }\n\n    updateTitle(activeProject) {\n        document.title = activeProject ? `${activeProject} – Serena Dashboard` : 'Serena Dashboard';\n    }\n\n    updateLogButtons(hasLogs) {\n        this.$saveLogsBtn.prop('disabled', !hasLogs);\n        this.$copyLogsBtn.prop('disabled', !hasLogs);\n        this.$clearLogsBtn.prop('disabled', !hasLogs);\n    }\n\n    saveLogs() {\n        const logText = this.$logContainer.text();\n        const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);\n        const blob = new Blob([logText], {type: 'text/plain'});\n        const url = URL.createObjectURL(blob);\n        const a = document.createElement('a');\n        a.href = url;\n        a.download = `serena-logs-${timestamp}.txt`;\n        document.body.appendChild(a);\n        a.click();\n        document.body.removeChild(a);\n        URL.revokeObjectURL(url);\n\n        const originalHtml = this.$saveLogsBtn.html();\n        const checkmarkSvg = '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"#888\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><polyline points=\"20 6 9 17 4 12\"></polyline></svg><span class=\"log-action-btn-text\">save logs</span>';\n        this.$saveLogsBtn.html(checkmarkSvg);\n        setTimeout(() => { this.$saveLogsBtn.html(originalHtml); }, 1500);\n    }\n\n    copyLogs() {\n        const logText = this.$logContainer.text();\n\n        // Use the Clipboard API to copy text\n        navigator.clipboard.writeText(logText).then(() => {\n            // Visual feedback - temporarily change icon to grey checkmark\n            const originalHtml = this.$copyLogsBtn.html();\n            const checkmarkSvg = '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"#888\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><polyline points=\"20 6 9 17 4 12\"></polyline></svg><span class=\"log-action-btn-text\">copy logs</span>';\n            this.$copyLogsBtn.html(checkmarkSvg);\n\n            setTimeout(() => {\n                this.$copyLogsBtn.html(originalHtml);\n            }, 1500);\n        }).catch(err => {\n            console.error('Failed to copy logs:', err);\n        });\n    }\n\n    clearLogs() {\n        let self = this;\n        $.ajax({\n            url: '/clear_logs',\n            type: 'POST',\n            success: function () {\n                self.$logContainer.empty();\n                self.currentMaxIdx = -1;\n                self.updateLogButtons(false);\n\n                const originalHtml = self.$clearLogsBtn.html();\n                const checkmarkSvg = '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"#888\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><polyline points=\"20 6 9 17 4 12\"></polyline></svg><span class=\"log-action-btn-text\">clear logs</span>';\n                self.$clearLogsBtn.html(checkmarkSvg);\n                setTimeout(() => { self.$clearLogsBtn.html(originalHtml); }, 1500);\n            },\n            error: function (xhr, status, error) {\n                console.error('Failed to clear logs:', error);\n            }\n        });\n    }\n\n    loadLogs() {\n        console.log(\"Loading logs\");\n        let self = this;\n\n        self.$errorContainer.empty();\n\n        // Make API call\n        $.ajax({\n            url: '/get_log_messages', type: 'POST', contentType: 'application/json', data: JSON.stringify({\n                start_idx: 0\n            }), success: function (response) {\n                // Clear existing logs\n                self.$logContainer.empty();\n\n                // Update max_idx\n                self.currentMaxIdx = response.max_idx || -1;\n\n                // Display each log message\n                if (response.messages && response.messages.length > 0) {\n                    response.messages.forEach(function (message) {\n                        self.displayLogMessage(message);\n                    });\n\n                    // Auto-scroll to bottom\n                    const logContainer = $('#log-container')[0];\n                    logContainer.scrollTop = logContainer.scrollHeight;\n                } else {\n                    $('#log-container').html('<div class=\"loading\">No log messages found.</div>');\n                }\n\n                self.updateLogButtons(response.messages && response.messages.length > 0);\n                self.updateTitle(response.active_project);\n\n                // Start periodic polling for new logs\n                self.startPeriodicPolling();\n            }, error: function (xhr, status, error) {\n                console.error('Error loading logs:', error);\n                self.$errorContainer.html('<div class=\"error-message\">Error loading logs: ' + (xhr.responseJSON ? xhr.responseJSON.detail : error) + '</div>');\n            }\n        });\n    }\n\n    pollForNewLogs() {\n        let self = this;\n        console.log(\"Polling logs\", this.currentMaxIdx);\n        $.ajax({\n            url: '/get_log_messages',\n            type: 'POST',\n            contentType: 'application/json',\n            data: JSON.stringify({\n                start_idx: self.currentMaxIdx + 1\n            }),\n            success: function (response) {\n                // Only append new messages if we have any\n                if (response.messages && response.messages.length > 0) {\n                    let wasAtBottom = false;\n                    const logContainer = $('#log-container')[0];\n\n                    // Check if user was at the bottom before adding new logs\n                    if (logContainer.scrollHeight > 0) {\n                        wasAtBottom = (logContainer.scrollTop + logContainer.clientHeight) >= (logContainer.scrollHeight - 10);\n                    }\n\n                    // Append new messages\n                    response.messages.forEach(function (message) {\n                        self.displayLogMessage(message);\n                    });\n\n                    // Update max_idx\n                    self.currentMaxIdx = response.max_idx || self.currentMaxIdx;\n\n                    self.updateLogButtons(true);\n\n                    // Auto-scroll to bottom if user was already at bottom\n                    if (wasAtBottom) {\n                        logContainer.scrollTop = logContainer.scrollHeight;\n                    }\n                } else {\n                    // Update max_idx even if no new messages\n                    self.currentMaxIdx = response.max_idx || self.currentMaxIdx;\n                }\n\n                // Update window title with active project\n                self.updateTitle(response.active_project);\n            }\n        });\n    }\n\n    startPeriodicPolling() {\n        // Clear any existing interval\n        if (this.pollInterval) {\n            clearInterval(this.pollInterval);\n        }\n\n        // Start polling every second (1000ms)\n        this.pollInterval = setInterval(this.pollForNewLogs.bind(this), 1000);\n    }\n\n    // ===== Stats Methods =====\n\n    loadStats() {\n        let self = this;\n        $.when($.ajax({url: '/get_tool_stats', type: 'GET'}), $.ajax({\n            url: '/get_token_count_estimator_name',\n            type: 'GET'\n        })).done(function (statsResp, estimatorResp) {\n            const stats = statsResp[0].stats;\n            const tokenCountEstimatorName = estimatorResp[0].token_count_estimator_name;\n            self.displayStats(stats, tokenCountEstimatorName);\n        }).fail(function () {\n            console.error('Error loading stats or estimator name');\n        });\n    }\n\n    clearStats() {\n        let self = this;\n        $.ajax({\n            url: '/clear_tool_stats', type: 'POST', success: function () {\n                self.loadStats();\n            }, error: function (xhr, status, error) {\n                console.error('Error clearing stats:', error);\n            }\n        });\n    }\n\n    displayStats(stats, tokenCountEstimatorName) {\n        const names = Object.keys(stats);\n        // If no stats collected\n        if (names.length === 0) {\n            // hide summary, charts, estimator name\n            $('#stats-summary').hide();\n            $('#estimator-name').hide();\n            $('.charts-container').hide();\n            // show no-stats message\n            $('#no-stats-message').show();\n            return;\n        } else {\n            // Ensure everything is visible\n            $('#estimator-name').show();\n            $('#stats-summary').show();\n            $('.charts-container').show();\n            $('#no-stats-message').hide();\n        }\n\n        $('#estimator-name').html(`<strong>Token count estimator:</strong> ${tokenCountEstimatorName}`);\n\n        const counts = names.map(n => stats[n].num_times_called);\n        const inputTokens = names.map(n => stats[n].input_tokens);\n        const outputTokens = names.map(n => stats[n].output_tokens);\n        const totalTokens = names.map(n => stats[n].input_tokens + stats[n].output_tokens);\n\n        // Calculate totals for summary table\n        const totalCalls = counts.reduce((sum, count) => sum + count, 0);\n        const totalInputTokens = inputTokens.reduce((sum, tokens) => sum + tokens, 0);\n        const totalOutputTokens = outputTokens.reduce((sum, tokens) => sum + tokens, 0);\n\n        // Generate consistent colors for tools\n        const colors = this.generateColors(names.length);\n\n        const countCtx = document.getElementById('count-chart');\n        const tokensCtx = document.getElementById('tokens-chart');\n        const inputCtx = document.getElementById('input-chart');\n        const outputCtx = document.getElementById('output-chart');\n\n        if (this.countChart) this.countChart.destroy();\n        if (this.tokensChart) this.tokensChart.destroy();\n        if (this.inputChart) this.inputChart.destroy();\n        if (this.outputChart) this.outputChart.destroy();\n\n        // Update summary table\n        this.updateSummaryTable(totalCalls, totalInputTokens, totalOutputTokens);\n\n        // Register datalabels plugin\n        Chart.register(ChartDataLabels);\n\n        // Get theme-aware colors\n        const isDark = document.documentElement.getAttribute('data-theme') === 'dark';\n        const textColor = isDark ? '#ffffff' : '#000000';\n        const gridColor = isDark ? '#444' : '#ddd';\n\n        // Tool calls pie chart\n        this.countChart = new Chart(countCtx, {\n            type: 'pie', data: {\n                labels: names, datasets: [{\n                    data: counts, backgroundColor: colors\n                }]\n            }, options: {\n                plugins: {\n                    legend: {\n                        display: true, labels: {\n                            color: textColor\n                        }\n                    }, datalabels: {\n                        display: true, color: 'white', font: {weight: 'bold'}, formatter: (value) => value\n                    }\n                }\n            }\n        });\n\n        // Input tokens pie chart\n        this.inputChart = new Chart(inputCtx, {\n            type: 'pie', data: {\n                labels: names, datasets: [{\n                    data: inputTokens, backgroundColor: colors\n                }]\n            }, options: {\n                plugins: {\n                    legend: {\n                        display: true, labels: {\n                            color: textColor\n                        }\n                    }, datalabels: {\n                        display: true, color: 'white', font: {weight: 'bold'}, formatter: (value) => value\n                    }\n                }\n            }\n        });\n\n        // Output tokens pie chart\n        this.outputChart = new Chart(outputCtx, {\n            type: 'pie', data: {\n                labels: names, datasets: [{\n                    data: outputTokens, backgroundColor: colors\n                }]\n            }, options: {\n                plugins: {\n                    legend: {\n                        display: true, labels: {\n                            color: textColor\n                        }\n                    }, datalabels: {\n                        display: true, color: 'white', font: {weight: 'bold'}, formatter: (value) => value\n                    }\n                }\n            }\n        });\n\n        // Combined input/output tokens bar chart\n        this.tokensChart = new Chart(tokensCtx, {\n            type: 'bar', data: {\n                labels: names, datasets: [{\n                    label: 'Input Tokens', data: inputTokens, backgroundColor: colors.map(color => color + '80'), // Semi-transparent\n                    borderColor: colors, borderWidth: 2, borderSkipped: false, yAxisID: 'y'\n                }, {\n                    label: 'Output Tokens', data: outputTokens, backgroundColor: colors, yAxisID: 'y1'\n                }]\n            }, options: {\n                responsive: true, plugins: {\n                    legend: {\n                        labels: {\n                            color: textColor\n                        }\n                    }\n                }, scales: {\n                    x: {\n                        ticks: {\n                            color: textColor\n                        }, grid: {\n                            color: gridColor\n                        }\n                    }, y: {\n                        type: 'linear', display: true, position: 'left', beginAtZero: true, title: {\n                            display: true, text: 'Input Tokens', color: textColor\n                        }, ticks: {\n                            color: textColor\n                        }, grid: {\n                            color: gridColor\n                        }\n                    }, y1: {\n                        type: 'linear', display: true, position: 'right', beginAtZero: true, title: {\n                            display: true, text: 'Output Tokens', color: textColor\n                        }, ticks: {\n                            color: textColor\n                        }, grid: {\n                            drawOnChartArea: false, color: gridColor\n                        }\n                    }\n                }\n            }\n        });\n    }\n\n    generateColors(count) {\n        const colors = ['#FF6384', '#36A2EB', '#FFCE56', '#4BC0C0', '#9966FF', '#FF9F40', '#FF6384', '#C9CBCF', '#4BC0C0', '#FF6384'];\n        return Array.from({length: count}, (_, i) => colors[i % colors.length]);\n    }\n\n    updateSummaryTable(totalCalls, totalInputTokens, totalOutputTokens) {\n        const tableHtml = `\n            <table class=\"stats-summary\">\n                <tr><th>Metric</th><th>Total</th></tr>\n                <tr><td>Tool Calls</td><td>${totalCalls}</td></tr>\n                <tr><td>Input Tokens</td><td>${totalInputTokens}</td></tr>\n                <tr><td>Output Tokens</td><td>${totalOutputTokens}</td></tr>\n                <tr><td>Total Tokens</td><td>${totalInputTokens + totalOutputTokens}</td></tr>\n            </table>\n        `;\n        $('#stats-summary').html(tableHtml);\n    }\n\n    // ===== Theme Methods =====\n\n    initializeTheme() {\n        // Check if user has manually set a theme preference\n        const savedTheme = localStorage.getItem('serena-theme');\n\n        if (savedTheme) {\n            // User has manually set a preference, use it\n            this.setTheme(savedTheme);\n        } else {\n            // No manual preference, detect system color scheme\n            this.detectSystemTheme();\n        }\n\n        // Listen for system theme changes\n        this.setupSystemThemeListener();\n    }\n\n    detectSystemTheme() {\n        // Check if system prefers dark mode\n        const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;\n        const theme = prefersDark ? 'dark' : 'light';\n        this.setTheme(theme);\n    }\n\n    setupSystemThemeListener() {\n        // Listen for changes in system color scheme\n        const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');\n\n        const handleSystemThemeChange = (e) => {\n            // Only auto-switch if user hasn't manually set a preference\n            const savedTheme = localStorage.getItem('serena-theme');\n            if (!savedTheme) {\n                const newTheme = e.matches ? 'dark' : 'light';\n                this.setTheme(newTheme);\n            }\n        };\n\n        // Add listener for system theme changes\n        if (mediaQuery.addEventListener) {\n            mediaQuery.addEventListener('change', handleSystemThemeChange);\n        } else {\n            // Fallback for older browsers\n            mediaQuery.addListener(handleSystemThemeChange);\n        }\n    }\n\n    toggleTheme() {\n        const currentTheme = document.documentElement.getAttribute('data-theme') || 'light';\n        const newTheme = currentTheme === 'light' ? 'dark' : 'light';\n\n        // When user manually toggles, save their preference\n        localStorage.setItem('serena-theme', newTheme);\n        this.setTheme(newTheme);\n    }\n\n    /**\n     * @param theme {'light' | 'dark'}\n     */\n    setTheme(theme) {\n        // Set the theme on the document element\n        document.documentElement.setAttribute('data-theme', theme);\n\n        // Update the theme toggle button\n        if (theme === 'dark') {\n            this.$themeIcon.text('☀️');\n            this.$themeText.text('Light');\n        } else {\n            this.$themeIcon.text('🌙');\n            this.$themeText.text('Dark');\n        }\n\n        // Update theme-aware images\n        $(\".theme-aware-img\").each(function() {\n            const $img = $(this);\n            updateThemeAwareImage($img, theme);\n        });\n\n        // Save to localStorage\n        localStorage.setItem('serena-theme', theme);\n\n        // Update charts if they exist\n        this.updateChartsTheme();\n    }\n\n    updateChartsTheme() {\n        const isDark = document.documentElement.getAttribute('data-theme') === 'dark';\n        const textColor = isDark ? '#ffffff' : '#000000';\n        const gridColor = isDark ? '#444' : '#ddd';\n\n        // Update existing charts if they exist and have the scales property\n        if (this.countChart && this.countChart.options.plugins) {\n            if (this.countChart.options.plugins.legend) {\n                this.countChart.options.plugins.legend.labels.color = textColor;\n            }\n            this.countChart.update();\n        }\n\n        if (this.inputChart && this.inputChart.options.plugins) {\n            if (this.inputChart.options.plugins.legend) {\n                this.inputChart.options.plugins.legend.labels.color = textColor;\n            }\n            this.inputChart.update();\n        }\n\n        if (this.outputChart && this.outputChart.options.plugins) {\n            if (this.outputChart.options.plugins.legend) {\n                this.outputChart.options.plugins.legend.labels.color = textColor;\n            }\n            this.outputChart.update();\n        }\n\n        if (this.tokensChart && this.tokensChart.options.scales) {\n            this.tokensChart.options.scales.x.ticks.color = textColor;\n            this.tokensChart.options.scales.y.ticks.color = textColor;\n            this.tokensChart.options.scales.y1.ticks.color = textColor;\n            this.tokensChart.options.scales.x.grid.color = gridColor;\n            this.tokensChart.options.scales.y.grid.color = gridColor;\n            this.tokensChart.options.scales.y1.grid.color = gridColor;\n            this.tokensChart.options.scales.y.title.color = textColor;\n            this.tokensChart.options.scales.y1.title.color = textColor;\n            if (this.tokensChart.options.plugins && this.tokensChart.options.plugins.legend) {\n                this.tokensChart.options.plugins.legend.labels.color = textColor;\n            }\n            this.tokensChart.update();\n        }\n    }\n\n    // ===== Language Management Methods =====\n\n    confirmRemoveLanguage(language) {\n        // Store the language to remove\n        this.languageToRemove = language;\n\n        // Set language name in modal\n        this.$removeLanguageName.text(language);\n\n        // Show modal\n        this.$removeLanguageModal.fadeIn(200);\n    }\n\n    closeRemoveLanguageModal() {\n        this.$removeLanguageModal.fadeOut(200);\n        this.languageToRemove = null;\n    }\n\n    confirmRemoveLanguageOk() {\n        if (this.languageToRemove) {\n            this.removeLanguage(this.languageToRemove);\n            this.closeRemoveLanguageModal();\n        }\n    }\n\n    removeLanguage(language) {\n        const self = this;\n\n        $.ajax({\n            url: '/remove_language', type: 'POST', contentType: 'application/json', data: JSON.stringify({\n                language: language\n            }), success: function (response) {\n                if (response.status === 'success') {\n                    // Reload config to show updated language list\n                    self.loadConfigOverview();\n                } else {\n                    alert('Error removing language ' + language + \": \" + response.message);\n                }\n            }, error: function (xhr, status, error) {\n                console.error('Error removing language:', error);\n                alert('Error removing language: ' + (xhr.responseJSON ? xhr.responseJSON.message : error));\n            }\n        });\n    }\n\n    openLanguageModal() {\n        // Set project name in modal\n        this.$modalProjectName.text(this.activeProjectName || 'Unknown');\n\n        // Load available languages into modal dropdown\n        this.loadAvailableLanguages();\n\n        // Show modal\n        this.$addLanguageModal.fadeIn(200);\n    }\n\n    closeLanguageModal() {\n        this.$addLanguageModal.fadeOut(200);\n        this.$modalLanguageSelect.empty();\n        this.$modalAddBtn.prop('disabled', false).text('Add Language');\n    }\n\n    loadAvailableLanguages() {\n        let self = this;\n        $.ajax({\n            url: '/get_available_languages', type: 'GET', success: function (response) {\n                const languages = response.languages || [];\n                // Clear all existing options\n                self.$modalLanguageSelect.empty();\n\n                if (languages.length === 0) {\n                    // Show message if no languages available\n                    self.$modalLanguageSelect.append($('<option>').val('').text('No languages available to add'));\n                    self.$modalAddBtn.prop('disabled', true);\n                } else {\n                    // Add language options\n                    languages.forEach(function (language) {\n                        self.$modalLanguageSelect.append($('<option>').val(language).text(language));\n                    });\n                    self.$modalAddBtn.prop('disabled', false);\n                }\n            }, error: function (xhr, status, error) {\n                console.error('Error loading available languages:', error);\n            }\n        });\n    }\n\n    addLanguageFromModal() {\n        const selectedLanguage = this.$modalLanguageSelect.val();\n        if (!selectedLanguage) {\n            alert('No language selected or no languages available to add');\n            return;\n        }\n\n        const self = this;\n\n        // Close modal immediately\n        self.closeLanguageModal();\n\n        // Hide the inline add language button and show spinner\n        $('#add-language-btn').hide();\n        $('#add-language-spinner').show();\n        self.isAddingLanguage = true;\n\n        $.ajax({\n            url: '/add_language', type: 'POST', contentType: 'application/json', data: JSON.stringify({\n                language: selectedLanguage\n            }), success: function (response) {\n                if (response.status === 'success') {\n                    console.log(\"Language added successfully\");\n                } else {\n                    alert('Error adding language ' + selectedLanguage + \": \" + response.message);\n                    // Restore button visibility on error\n                    $('#add-language-btn').show();\n                    $('#add-language-spinner').hide();\n                }\n            }, error: function (xhr, status, error) {\n                console.error('Error adding language:', error);\n                alert('Error adding language: ' + (xhr.responseJSON ? xhr.responseJSON.message : error));\n                // Restore button visibility on error\n                $('#add-language-btn').show();\n                $('#add-language-spinner').hide();\n            }, complete: function () {\n                self.isAddingLanguage = false;\n                self.loadConfigOverview();\n            }\n        });\n    }\n\n    // ===== Memory Editing Methods =====\n\n    openEditMemoryModal(memoryName) {\n        const self = this;\n        this.currentMemoryName = memoryName;\n        this.memoryContentDirty = false;\n\n        // Set memory name in modal\n        this.$editMemoryName.text(memoryName);\n\n        // Load memory content\n        $.ajax({\n            url: '/get_memory', type: 'POST', contentType: 'application/json', data: JSON.stringify({\n                memory_name: memoryName\n            }), success: function (response) {\n                if (response.status === 'error') {\n                    alert('Error: ' + response.message);\n                    return;\n                }\n                self.originalMemoryContent = response.content;\n                self.$editMemoryContent.val(response.content);\n                self.memoryContentDirty = false;\n                self.$editMemoryModal.fadeIn(200);\n            }, error: function (xhr, status, error) {\n                console.error('Error loading memory:', error);\n                alert('Error loading memory: ' + (xhr.responseJSON ? xhr.responseJSON.message : error));\n            }\n        });\n    }\n\n    closeEditMemoryModal() {\n        // Check if there are unsaved changes\n        if (this.memoryContentDirty) {\n            if (!confirm('You have unsaved changes. Are you sure you want to close?')) {\n                return;\n            }\n        }\n\n        this.$editMemoryModal.fadeOut(200);\n        this.currentMemoryName = null;\n        this.originalMemoryContent = null;\n        this.memoryContentDirty = false;\n    }\n\n    trackMemoryChanges() {\n        const currentContent = this.$editMemoryContent.val();\n        this.memoryContentDirty = (currentContent !== this.originalMemoryContent);\n    }\n\n    saveMemoryFromModal() {\n        const self = this;\n        const memoryName = this.currentMemoryName;\n        const content = this.$editMemoryContent.val();\n\n        if (!memoryName) {\n            alert('No memory selected');\n            return;\n        }\n\n        // Disable button during request\n        self.$editMemorySaveBtn.prop('disabled', true).text('Saving...');\n\n        $.ajax({\n            url: '/save_memory', type: 'POST', contentType: 'application/json', data: JSON.stringify({\n                memory_name: memoryName, content: content\n            }), success: function (response) {\n                if (response.status === 'success') {\n                    // Update original content and reset dirty flag\n                    self.originalMemoryContent = content;\n                    self.memoryContentDirty = false;\n                    // Close modal\n                    self.$editMemoryModal.fadeOut(200);\n                    self.currentMemoryName = null;\n                } else {\n                    alert('Error: ' + response.message);\n                }\n            }, error: function (xhr, status, error) {\n                console.error('Error saving memory:', error);\n                alert('Error saving memory: ' + (xhr.responseJSON ? xhr.responseJSON.message : error));\n            }, complete: function () {\n                // Re-enable button\n                self.$editMemorySaveBtn.prop('disabled', false).text('Save');\n            }\n        });\n    }\n\n    startMemoryRename() {\n        this.$editMemoryName.hide();\n        this.$editMemoryRenameBtn.hide();\n        this.$editMemoryRenameInput.val(this.currentMemoryName).show().focus().select();\n    }\n\n    cancelMemoryRename() {\n        this.$editMemoryRenameInput.hide();\n        this.$editMemoryName.show();\n        this.$editMemoryRenameBtn.show();\n    }\n\n    commitMemoryRename() {\n        const newName = this.$editMemoryRenameInput.val().trim();\n        const oldName = this.currentMemoryName;\n\n        // If name unchanged, just cancel\n        if (!newName || newName === oldName) {\n            this.cancelMemoryRename();\n            return;\n        }\n\n        // Validate memory name (alphanumeric, underscores, and slashes for subdirectories)\n        if (!/^[a-zA-Z0-9_]+(?:\\/[a-zA-Z0-9_]+)*$/.test(newName)) {\n            alert('Memory name can only contain letters, numbers, underscores, and \"/\" for subdirectories (e.g., \"topic/memory_name\")');\n            this.$editMemoryRenameInput.focus();\n            return;\n        }\n\n        const self = this;\n        this.$editMemoryRenameInput.prop('disabled', true);\n\n        $.ajax({\n            url: '/rename_memory', type: 'POST', contentType: 'application/json', data: JSON.stringify({\n                old_name: oldName, new_name: newName\n            }), success: function (response) {\n                if (response.status === 'success') {\n                    self.currentMemoryName = newName;\n                    self.$editMemoryName.text(newName);\n                    self.cancelMemoryRename();\n                    // Reload config to reflect the rename in the memory list\n                    self.loadConfigOverview();\n                } else {\n                    alert('Error: ' + response.message);\n                    self.$editMemoryRenameInput.focus();\n                }\n            }, error: function (xhr, status, error) {\n                console.error('Error renaming memory:', error);\n                alert('Error renaming memory: ' + (xhr.responseJSON ? xhr.responseJSON.message : error));\n                self.$editMemoryRenameInput.focus();\n            }, complete: function () {\n                self.$editMemoryRenameInput.prop('disabled', false);\n            }\n        });\n    }\n\n    confirmDeleteMemory(memoryName) {\n        // Set memory name to delete\n        this.memoryToDelete = memoryName;\n\n        // Set memory name in modal\n        this.$deleteMemoryName.text(memoryName);\n\n        // Show modal\n        this.$deleteMemoryModal.fadeIn(200);\n    }\n\n    closeDeleteMemoryModal() {\n        this.$deleteMemoryModal.fadeOut(200);\n        this.memoryToDelete = null;\n    }\n\n    confirmDeleteMemoryOk() {\n        if (this.memoryToDelete) {\n            this.deleteMemory(this.memoryToDelete);\n            this.closeDeleteMemoryModal();\n        }\n    }\n\n    deleteMemory(memoryName) {\n        const self = this;\n\n        $.ajax({\n            url: '/delete_memory', type: 'POST', contentType: 'application/json', data: JSON.stringify({\n                memory_name: memoryName\n            }), success: function (response) {\n                if (response.status === 'success') {\n                    // Reload config to show updated memory list\n                    self.loadConfigOverview();\n                } else {\n                    alert('Error: ' + response.message);\n                }\n            }, error: function (xhr, status, error) {\n                console.error('Error deleting memory:', error);\n                alert('Error deleting memory: ' + (xhr.responseJSON ? xhr.responseJSON.message : error));\n            }\n        });\n    }\n\n    openCreateMemoryModal() {\n        // Set project name in modal\n        this.$createMemoryProjectName.text(this.activeProjectName || 'Unknown');\n\n        // Clear the input field\n        this.$createMemoryNameInput.val('');\n\n        // Show modal\n        this.$createMemoryModal.fadeIn(200);\n\n        // Focus on the input field\n        setTimeout(() => {\n            this.$createMemoryNameInput.focus();\n        }, 250);\n    }\n\n    closeCreateMemoryModal() {\n        this.$createMemoryModal.fadeOut(200);\n        this.$createMemoryNameInput.val('');\n        this.$createMemoryCreateBtn.prop('disabled', false).text('Create');\n    }\n\n    createMemoryFromModal() {\n        const memoryName = this.$createMemoryNameInput.val().trim();\n\n        if (!memoryName) {\n            alert('Please enter a memory name');\n            return;\n        }\n\n        // Validate memory name (alphanumeric, underscores, and slashes for subdirectories)\n        if (!/^[a-zA-Z0-9_]+(?:\\/[a-zA-Z0-9_]+)*$/.test(memoryName)) {\n            alert('Memory name can only contain letters, numbers, underscores, and \"/\" for subdirectories (e.g., \"topic/memory_name\")');\n            return;\n        }\n\n        const self = this;\n\n        // Disable button during request\n        self.$createMemoryCreateBtn.prop('disabled', true).text('Creating...');\n\n        $.ajax({\n            url: '/save_memory', type: 'POST', contentType: 'application/json', data: JSON.stringify({\n                memory_name: memoryName, content: ''\n            }), success: function (response) {\n                if (response.status === 'success') {\n                    // Close the create modal\n                    self.closeCreateMemoryModal();\n                    // Reload config to show the new memory\n                    self.loadConfigOverview();\n                    // Open the edit modal for the newly created memory\n                    setTimeout(() => {\n                        self.openEditMemoryModal(memoryName);\n                    }, 500);\n                } else {\n                    alert('Error: ' + response.message);\n                    self.$createMemoryCreateBtn.prop('disabled', false).text('Create');\n                }\n            }, error: function (xhr, status, error) {\n                console.error('Error creating memory:', error);\n                alert('Error creating memory: ' + (xhr.responseJSON ? xhr.responseJSON.message : error));\n                self.$createMemoryCreateBtn.prop('disabled', false).text('Create');\n            }\n        });\n    }\n\n    // ===== News Methods =====\n\n    loadNews() {\n        let self = this;\n        console.log('Loading news...');\n        $.ajax({\n            url: '/news_snippet_ids',\n            type: 'GET',\n            success: function(response) {\n                console.log('News snippet IDs response:', response);\n                if (response.status === 'success' && response.news_snippet_ids && response.news_snippet_ids.length > 0) {\n                    console.log('Displaying news with IDs:', response.news_snippet_ids);\n                    self.displayNews(response.news_snippet_ids);\n                } else {\n                    console.log('No unread news, hiding section');\n                    self.$newsSection.hide();\n                }\n            },\n            error: function(xhr, status, error) {\n                console.error('Error loading news snippet IDs:', error);\n                self.$newsSection.hide();\n            }\n        });\n    }\n\n    displayNews(newsIds) {\n        let self = this;\n        console.log('displayNews called with:', newsIds);\n        // Sort newest first (descending order)\n        newsIds.sort((a, b) => b - a);\n        \n        if (newsIds.length === 0) {\n            console.log('No news items to display.');\n            self.$newsSection.hide();\n            return;\n        }\n        self.$newsSection.show();\n        self.$newsDisplay.empty();\n        console.log('Displaying ' + newsIds.length + ' news items.');\n        // Load each news snippet HTML\n        let loadedCount = 0;\n        newsIds.forEach(function(newsId) {\n            $.ajax({\n                url: '/dashboard/news/' + newsId + '.html',\n                type: 'GET',\n                success: function(html) {\n                    // Wrap the HTML in a container with a button\n                    let $newsContainer = $('<div class=\"news-container\">').attr('data-news-id', newsId);\n                    let $newsContent = $(html);\n                    \n                    // Add button for marking as read\n                    let $markRead = $('<div class=\"news-mark-read\">');\n                    let $button = $('<button class=\"news-mark-read-btn\">').attr('data-news-id', newsId).text('Mark as read');\n\n                    $markRead.append($button);\n                    $newsContent.append($markRead);\n                    \n                    $newsContainer.append($newsContent);\n                    self.$newsDisplay.append($newsContainer);\n                    \n                    // Bind button click event\n                    $button.on('click', function() {\n                        const btn = $(this);\n                        btn.prop('disabled', true).text('Marking...');\n                        self.markNewsAsRead(newsId);\n                    });\n                    \n                    loadedCount++;\n                },\n                error: function(xhr, status, error) {\n                    console.error('Error loading news snippet ' + newsId + ':', error);\n                    loadedCount++;\n                }\n            });\n        });\n    }\n\n    markNewsAsRead(newsId) {\n        let self = this;\n        $.ajax({\n            url: '/mark_news_snippet_as_read',\n            type: 'POST',\n            contentType: 'application/json',\n            data: JSON.stringify({ news_snippet_id: newsId }),\n            success: function(response) {\n                if (response.status === 'success') {\n                    // Reload news to show updated list\n                    self.loadNews();\n                } else {\n                    console.error('Error marking news as read:', response.message);\n                }\n            },\n            error: function(xhr, status, error) {\n                console.error('Error marking news as read:', error);\n            }\n        });\n    }\n\n    // ===== Serena Config Editing Methods =====\n\n    openEditSerenaConfigModal() {\n        const self = this;\n        this.serenaConfigContentDirty = false;\n\n        // Load serena config content\n        $.ajax({\n            url: '/get_serena_config', type: 'GET', success: function (response) {\n                if (response.status === 'error') {\n                    alert('Error: ' + response.message);\n                    return;\n                }\n                self.originalSerenaConfigContent = response.content;\n                self.$editSerenaConfigContent.val(response.content);\n                self.serenaConfigContentDirty = false;\n                self.$editSerenaConfigModal.fadeIn(200);\n            }, error: function (xhr, status, error) {\n                console.error('Error loading serena config:', error);\n                alert('Error loading serena config: ' + (xhr.responseJSON ? xhr.responseJSON.message : error));\n            }\n        });\n\n        // Track changes to config content\n        this.$editSerenaConfigContent.off('input').on('input', function () {\n            const currentContent = self.$editSerenaConfigContent.val();\n            self.serenaConfigContentDirty = (currentContent !== self.originalSerenaConfigContent);\n        });\n    }\n\n    closeEditSerenaConfigModal() {\n        // Check if there are unsaved changes\n        if (this.serenaConfigContentDirty) {\n            if (!confirm('You have unsaved changes. Are you sure you want to close?')) {\n                return;\n            }\n        }\n\n        this.$editSerenaConfigModal.fadeOut(200);\n        this.originalSerenaConfigContent = null;\n        this.serenaConfigContentDirty = false;\n    }\n\n    saveSerenaConfigFromModal() {\n        const self = this;\n        const content = this.$editSerenaConfigContent.val();\n\n        // Disable button during request\n        self.$editSerenaConfigSaveBtn.prop('disabled', true).text('Saving...');\n\n        $.ajax({\n            url: '/save_serena_config', type: 'POST', contentType: 'application/json', data: JSON.stringify({\n                content: content\n            }), success: function (response) {\n                if (response.status === 'success') {\n                    // Update original content and reset dirty flag\n                    self.originalSerenaConfigContent = content;\n                    self.serenaConfigContentDirty = false;\n                    // Close modal\n                    self.$editSerenaConfigModal.fadeOut(200);\n                    alert('Configuration saved successfully. Please restart Serena for changes to take effect.');\n                } else {\n                    alert('Error: ' + response.message);\n                }\n            }, error: function (xhr, status, error) {\n                console.error('Error saving serena config:', error);\n                alert('Error saving serena config: ' + (xhr.responseJSON ? xhr.responseJSON.message : error));\n            }, complete: function () {\n                // Re-enable button\n                self.$editSerenaConfigSaveBtn.prop('disabled', false).text('Save');\n            }\n        });\n    }\n\n    // ===== Shutdown Method =====\n\n    shutdown() {\n        const self = this;\n        const _shutdown = function () {\n            console.log(\"Triggering shutdown\");\n            $.ajax({\n                url: '/shutdown', type: \"PUT\", contentType: 'application/json',\n            });\n            self.$errorContainer.html('<div class=\"error-message\">Shutting down ...</div>')\n            setTimeout(function () {\n                window.close();\n            }, 1000);\n        }\n\n        // ask for confirmation using a dialog\n        if (confirm(\"This will fully terminate the Serena server.\")) {\n            _shutdown();\n        } else {\n            console.log(\"Shutdown cancelled\");\n        }\n\n        // Close menu\n        self.$menuDropdown.hide();\n    }\n}\n"
  },
  {
    "path": "src/serena/resources/dashboard/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Serena Dashboard</title>\n    <link rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"serena-icon-16.png\">\n    <link rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"serena-icon-32.png\">\n    <link rel=\"icon\" type=\"image/png\" sizes=\"48x48\" href=\"serena-icon-48.png\">\n    <link rel=\"stylesheet\" href=\"dashboard.css\">\n    <script src=\"jquery.min.js\"></script>\n    <script src=\"https://cdn.jsdelivr.net/npm/chart.js\"></script>\n    <script src=\"https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2\"></script>\n    <script src=\"dashboard.js\"></script>\n</head>\n\n<body>\n<div id=\"frame\">\n<header class=\"header\">\n    <div class=\"header-left\">\n\n        <div class=\"logo-container\">\n            <img id=\"serena-logo\" class=\"theme-aware-img\" src=\"serena-logo.svg\" data-src-light=\"serena-logo.svg\" data-src-dark=\"serena-logo-dark-mode.svg\" alt=\"Serena\">\n        </div>\n\n        <!-- Platinum Banners in Header -->\n        <div id=\"platinum-banners\" class=\"header-banner\">\n            <button class=\"banner-arrow banner-arrow-left\" data-target=\"platinum\" aria-label=\"Previous banner\">&#8249;</button>\n            <button class=\"banner-arrow banner-arrow-right\" data-target=\"platinum\" aria-label=\"Next banner\">&#8250;</button>\n        </div>\n    </div>\n\n    <nav class=\"header-nav\">\n        <div class=\"header-actions\">\n            <button id=\"theme-toggle\" class=\"theme-toggle\">\n                <span id=\"theme-icon\" style=\"height: 21px\">🌙</span>\n                <span id=\"theme-text\">Dark</span>\n            </button>\n            <button id=\"menu-toggle\" class=\"menu-button\">\n                <span>☰</span>\n                <span>Menu</span>\n            </button>\n            <div id=\"menu-dropdown\" class=\"menu-dropdown\" style=\"display:none\">\n                <a href=\"#\" data-page=\"stats\">Advanced Stats</a>\n                <hr>\n                <a href=\"#\" id=\"menu-shutdown\">Shutdown Server</a>\n            </div>\n        </div>\n        <div class=\"header-tabs\">\n            <a href=\"#\" data-page=\"overview\" class=\"header-tab active\">Overview</a>\n            <a href=\"#\" data-page=\"logs\" class=\"header-tab\">Logs</a>\n        </div>\n    </nav>\n</header>\n\n\n<div class=\"main\">\n    <!-- Overview Page (Landing) -->\n    <div id=\"page-overview\" class=\"page-view\">\n        <div class=\"overview-container\">\n            <div class=\"overview-left\">\n\n                <section id=\"news-section\" class=\"news-section\" style=\"display:none\">\n                    <h2>What's New</h2>\n                    <div id=\"news-display\">\n                        <div class=\"loading\">Loading news...</div>\n                    </div>\n                </section>\n\n                <section class=\"config-section\">\n                    <div style=\"display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;\">\n                        <h2 style=\"margin: 0;\">Current Configuration</h2>\n                    </div>\n                    <div id=\"config-display\">\n                        <div class=\"loading\">Loading configuration...</div>\n                    </div>\n                </section>\n\n                <section class=\"basic-stats-section\">\n                    <h2>Tool Usage</h2>\n                    <div id=\"basic-stats-display\">\n                        <div class=\"loading\">Loading stats...</div>\n                    </div>\n                </section>\n\n                <section class=\"executions-section\">\n                    <h2>Executions Queue</h2>\n                    <div id=\"active-executions-display\">\n                        <div class=\"loading\">Loading executions...</div>\n                    </div>\n                </section>\n\n                <section class=\"executions-section\">\n                    <h2>Last Execution</h2>\n                    <div id=\"last-execution-display\">\n                        <div class=\"loading\">Loading...</div>\n                    </div>\n                </section>\n\n                <section class=\"executions-section\" style=\"display:none\">\n                    <h2>Cancelled Executions</h2>\n                    <div id=\"cancelled-executions-display\">\n                        <div class=\"no-stats-message\">No cancelled executions.</div>\n                    </div>\n                </section>\n            </div>\n\n            <div class=\"overview-right\">\n                <section class=\"projects-section\">\n                    <h2 class=\"collapsible-header\" id=\"projects-header\">\n                        <span>Registered Projects</span>\n                        <span class=\"toggle-icon\">▼</span>\n                    </h2>\n                    <div id=\"projects-display\" class=\"collapsible-content\" style=\"display:none\">\n                        <div class=\"loading\">Loading projects...</div>\n                    </div>\n                </section>\n\n                <section class=\"projects-section\">\n                    <h2 class=\"collapsible-header\" id=\"available-tools-header\">\n                        <span>Available Tools (Disabled)</span>\n                        <span class=\"toggle-icon\">▼</span>\n                    </h2>\n                    <div id=\"available-tools-display\" class=\"collapsible-content\" style=\"display:none\">\n                        <div class=\"loading\">Loading tools...</div>\n                    </div>\n                </section>\n\n                <section class=\"projects-section\">\n                    <h2 class=\"collapsible-header\" id=\"available-modes-header\">\n                        <span>Available Modes</span>\n                        <span class=\"toggle-icon\">▼</span>\n                    </h2>\n                    <div id=\"available-modes-display\" class=\"collapsible-content\" style=\"display:none\">\n                        <div class=\"loading\">Loading modes...</div>\n                    </div>\n                </section>\n\n                <section class=\"projects-section\">\n                    <h2 class=\"collapsible-header\" id=\"available-contexts-header\">\n                        <span>Available Contexts</span>\n                        <span class=\"toggle-icon\">▼</span>\n                    </h2>\n                    <div id=\"available-contexts-display\" class=\"collapsible-content\" style=\"display:none\">\n                        <div class=\"loading\">Loading contexts...</div>\n                    </div>\n                </section>\n\n                <!-- Gold Banners -->\n                <section id=\"gold-banners\" class=\"gold-banners-section\">\n                    <button class=\"banner-arrow banner-arrow-left\" data-target=\"gold\" aria-label=\"Previous banner\">&#8249;</button>\n                    <button class=\"banner-arrow banner-arrow-right\" data-target=\"gold\" aria-label=\"Next banner\">&#8250;</button>\n                </section>\n            </div>\n        </div>\n    </div>\n\n    <!-- Logs Page -->\n    <div id=\"page-logs\" class=\"page-view\" style=\"display:none\">\n        <div id=\"error-container\"></div>\n        <div style=\"position: relative;\">\n            <div class=\"log-action-buttons\">\n                <button id=\"copy-logs-btn\" class=\"log-action-btn\" title=\"Copy logs\" disabled>\n                    <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\"\n                         stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n                        <rect x=\"9\" y=\"9\" width=\"13\" height=\"13\" rx=\"2\" ry=\"2\"></rect>\n                        <path d=\"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1\"></path>\n                    </svg>\n                    <span class=\"log-action-btn-text\">copy logs</span>\n                </button>\n                <button id=\"save-logs-btn\" class=\"log-action-btn\" title=\"Save logs to file\" disabled>\n                    <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\"\n                         stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n                        <path d=\"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4\"></path>\n                        <polyline points=\"7 10 12 15 17 10\"></polyline>\n                        <line x1=\"12\" y1=\"15\" x2=\"12\" y2=\"3\"></line>\n                    </svg>\n                    <span class=\"log-action-btn-text\">save logs</span>\n                </button>\n                <button id=\"clear-logs-btn\" class=\"log-action-btn log-action-btn-danger\" title=\"Clear logs\" disabled>\n                    <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\"\n                         stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n                        <polyline points=\"3 6 5 6 21 6\"></polyline>\n                        <path d=\"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6\"></path>\n                        <path d=\"M10 11v6\"></path>\n                        <path d=\"M14 11v6\"></path>\n                        <path d=\"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2\"></path>\n                    </svg>\n                    <span class=\"log-action-btn-text\">clear logs</span>\n                </button>\n            </div>\n            <div id=\"log-container\" class=\"log-container\"></div>\n        </div>\n    </div>\n\n    <!-- Advanced Stats Page -->\n    <div id=\"page-stats\" class=\"page-view\" style=\"display:none\">\n        <div class=\"controls\">\n            <button id=\"refresh-stats\" class=\"btn\">Refresh Stats</button>\n            <button id=\"clear-stats\" class=\"btn\">Clear Stats</button>\n        </div>\n\n        <div id=\"stats-summary\" style=\"margin-bottom:20px; text-align:center;\"></div>\n        <div id=\"estimator-name\" style=\"text-align:center; margin-bottom:10px;\"></div>\n        <div id=\"no-stats-message\" style=\"text-align:center; color:var(--text-muted); font-style:italic; display:none;\">\n            No tool stats collected yet.\n        </div>\n\n        <div class=\"charts-container\">\n            <div class=\"chart-group\">\n                <h3>Tool Calls</h3>\n                <canvas id=\"count-chart\" height=\"200\"></canvas>\n            </div>\n            <div class=\"chart-group\">\n                <h3>Input Tokens</h3>\n                <canvas id=\"input-chart\" height=\"200\"></canvas>\n            </div>\n            <div class=\"chart-group\">\n                <h3>Output Tokens</h3>\n                <canvas id=\"output-chart\" height=\"200\"></canvas>\n            </div>\n            <div class=\"chart-group chart-wide\">\n                <h3>Input vs Output Tokens</h3>\n                <canvas id=\"tokens-chart\" height=\"120\"></canvas>\n            </div>\n        </div>\n    </div>\n\n    <!-- Add Language Modal -->\n    <div id=\"add-language-modal\" class=\"modal\" style=\"display:none\">\n        <div class=\"modal-content\">\n            <span class=\"modal-close\">&times;</span>\n            <h3>Add Language</h3>\n            <p id=\"modal-project-info\" style=\"margin: 15px 0; color: var(--text-primary); line-height: 1.5;\">\n                Adding a language to serena config of project <strong id=\"modal-project-name\"></strong>.\n            </p>\n            <p style=\"margin: 15px 0; color: var(--text-muted); font-size: 13px; line-height: 1.5;\">\n                Note that this may download some dependencies needed for the language server and then start it,\n                it may take a few seconds before the LS is responsive.\n            </p>\n            <div style=\"margin: 20px 0;\">\n                <label for=\"modal-language-select\" style=\"display: block; margin-bottom: 8px; font-weight: 500;\">Select\n                    Language:</label>\n                <select id=\"modal-language-select\" class=\"language-select\"\n                        style=\"width: 100%; padding: 8px 10px; border-radius: 4px; border: 1px solid var(--border-color); background: var(--bg-primary); color: var(--text-primary); font-size: 14px;\">\n                </select>\n            </div>\n            <div style=\"display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px;\">\n                <button id=\"modal-cancel-btn\" class=\"btn\"\n                        style=\"background: var(--bg-secondary); color: var(--text-primary); padding: 8px 16px;\">Cancel\n                </button>\n                <button id=\"modal-add-btn\" class=\"btn\" style=\"padding: 8px 16px;\">Add Language</button>\n            </div>\n        </div>\n    </div>\n\n    <!-- Remove Language Confirmation Modal -->\n    <div id=\"remove-language-modal\" class=\"modal\" style=\"display:none\">\n        <div class=\"modal-content\">\n            <span class=\"modal-close modal-close-remove\">&times;</span>\n            <p style=\"margin: 20px 0; color: var(--text-primary); line-height: 1.5; font-size: 15px;\">\n                Remove language <strong id=\"remove-language-name\"></strong> from configuration?\n            </p>\n            <div style=\"display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px;\">\n                <button id=\"remove-modal-cancel-btn\" class=\"btn\"\n                        style=\"background: var(--bg-secondary); color: var(--text-primary); padding: 8px 16px;\">Cancel\n                </button>\n                <button id=\"remove-modal-ok-btn\" class=\"btn\" style=\"padding: 8px 16px;\">OK</button>\n            </div>\n        </div>\n    </div>\n\n    <!-- Edit Memory Modal -->\n    <div id=\"edit-memory-modal\" class=\"modal\" style=\"display:none\">\n        <div class=\"modal-content modal-content-large\">\n            <span class=\"modal-close modal-close-edit-memory\">&times;</span>\n            <h3 style=\"margin-bottom: 20px; display: flex; align-items: center; gap: 8px;\">\n                Memory:\n                <span id=\"edit-memory-name\" class=\"memory-name-display\"></span>\n                <span id=\"edit-memory-rename-btn\" class=\"memory-rename-btn\" title=\"Rename memory\">\n                    <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\"\n                         stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n                        <path d=\"M17 3a2.83 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z\"></path>\n                    </svg>\n                </span>\n                <input type=\"text\" id=\"edit-memory-rename-input\" class=\"memory-rename-input\" style=\"display: none;\">\n            </h3>\n            <textarea id=\"edit-memory-content\" class=\"memory-editor\" rows=\"20\"\n                      style=\"width: 100%; padding: 10px; border: 1px solid var(--border-color); border-radius: 4px; background: var(--bg-primary); color: var(--text-primary); font-family: 'Courier New', monospace; font-size: 13px; resize: vertical;\"></textarea>\n            <div style=\"display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px;\">\n                <button id=\"edit-memory-cancel-btn\" class=\"btn\"\n                        style=\"background: var(--bg-secondary); color: var(--text-primary); padding: 8px 16px;\">Cancel\n                </button>\n                <button id=\"edit-memory-save-btn\" class=\"btn\" style=\"padding: 8px 16px;\">Save</button>\n            </div>\n        </div>\n    </div>\n\n    <!-- Delete Memory Confirmation Modal -->\n    <div id=\"delete-memory-modal\" class=\"modal\" style=\"display:none\">\n        <div class=\"modal-content\">\n            <span class=\"modal-close modal-close-delete-memory\">&times;</span>\n            <p style=\"margin: 20px 0; color: var(--text-primary); line-height: 1.5; font-size: 15px;\">\n                Delete memory <strong id=\"delete-memory-name\"></strong>?\n            </p>\n            <div style=\"display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px;\">\n                <button id=\"delete-memory-cancel-btn\" class=\"btn\"\n                        style=\"background: var(--bg-secondary); color: var(--text-primary); padding: 8px 16px;\">Cancel\n                </button>\n                <button id=\"delete-memory-ok-btn\" class=\"btn\" style=\"padding: 8px 16px;\">OK</button>\n            </div>\n        </div>\n    </div>\n\n    <!-- Create Memory Modal -->\n    <div id=\"create-memory-modal\" class=\"modal\" style=\"display:none\">\n        <div class=\"modal-content\">\n            <span class=\"modal-close modal-close-create-memory\">&times;</span>\n            <p id=\"create-memory-project-info\" style=\"margin: 15px 0; color: var(--text-primary); line-height: 1.5;\">\n                Create a new memory for project <strong id=\"create-memory-project-name\"></strong>.\n            </p>\n            <p style=\"margin: 15px 0; color: var(--text-muted); font-size: 13px; line-height: 1.5;\">\n                Memory names should be descriptive and use underscores instead of spaces (e.g., \"api_architecture\",\n                \"testing_guidelines\"). Use \"/\" to organize memories into subdirectories (e.g., \"architecture/api_design\"),\n                use the \"global/\" prefix to write memories that are shared across projects (e.g., \"global/java/style_guide\").\n            </p>\n            <div style=\"margin: 20px 0;\">\n                <label for=\"create-memory-name-input\" style=\"display: block; margin-bottom: 8px; font-weight: 500;\">Memory\n                    Name:</label>\n                <input type=\"text\" id=\"create-memory-name-input\" class=\"memory-name-input\"\n                       placeholder=\"e.g., project_overview or topic/memory_name\"\n                       style=\"width: 100%; padding: 8px 10px; border-radius: 4px; border: 1px solid var(--border-color); background: var(--bg-primary); color: var(--text-primary); font-size: 14px;\">\n            </div>\n            <div style=\"display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px;\">\n                <button id=\"create-memory-cancel-btn\" class=\"btn\"\n                        style=\"background: var(--bg-secondary); color: var(--text-primary); padding: 8px 16px;\">Cancel\n                </button>\n                <button id=\"create-memory-create-btn\" class=\"btn\" style=\"padding: 8px 16px;\">Create</button>\n            </div>\n        </div>\n    </div>\n\n    <!-- Cancel Execution Confirmation Modal -->\n    <div id=\"cancel-execution-modal\" class=\"modal\" style=\"display:none\">\n        <div class=\"modal-content\">\n            <span class=\"modal-close modal-close-cancel-execution\">&times;</span>\n            <p style=\"margin: 20px 0; color: var(--text-primary); line-height: 1.5; font-size: 15px;\">\n                Are you sure? The execution will continue running until timeout, it will simply no longer be in the queue.\n                Abandoning a running execution is only advised as a measure for unblocking Serena.\n            </p>\n            <div style=\"display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px;\">\n                <button id=\"cancel-execution-cancel-btn\" class=\"btn\"\n                        style=\"background: var(--bg-secondary); color: var(--text-primary); padding: 8px 16px;\">Cancel\n                </button>\n                <button id=\"cancel-execution-ok-btn\" class=\"btn\" style=\"padding: 8px 16px;\">OK</button>\n            </div>\n        </div>\n    </div>\n\n    <!-- Edit Serena Config Modal -->\n    <div id=\"edit-serena-config-modal\" class=\"modal\" style=\"display:none\">\n        <div class=\"modal-content modal-content-large\">\n            <span class=\"modal-close modal-close-edit-serena-config\">&times;</span>\n            <h3 style=\"margin-bottom: 10px;\">Global Serena Configuration</h3>\n            <p style=\"margin: 10px 0 20px 0; color: var(--text-muted); font-size: 13px; line-height: 1.5;\">\n                Note: Changes to the configuration will only take effect after Serena is restarted.\n            </p>\n            <textarea id=\"edit-serena-config-content\" class=\"memory-editor\" rows=\"20\"\n                      style=\"width: 100%; padding: 10px; border: 1px solid var(--border-color); border-radius: 4px; background: var(--bg-primary); color: var(--text-primary); font-family: 'Courier New', monospace; font-size: 13px; resize: vertical;\"></textarea>\n            <div style=\"display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px;\">\n                <button id=\"edit-serena-config-cancel-btn\" class=\"btn\"\n                        style=\"background: var(--bg-secondary); color: var(--text-primary); padding: 8px 16px;\">Cancel\n                </button>\n                <button id=\"edit-serena-config-save-btn\" class=\"btn\" style=\"padding: 8px 16px;\">Save</button>\n            </div>\n        </div>\n    </div>\n</div>    <!-- End of Main -->\n\n<script>\n    $(document).ready(function () {\n        const dashboard = new Dashboard();\n    });\n</script>\n</div> <!-- End of Frame -->\n</body>\n\n</html>\n"
  },
  {
    "path": "src/serena/resources/dashboard/news/20260111.html",
    "content": "<div class=\"news-item\">\n    <h3>Extended Symbol Information, Type Hierarchy and Compact Overviews</h3>\n    <p class=\"date\">January 11, 2026</p>\n    <p>\n        Recent commits and a new plugin release provide major new features!\n    </p>\n    <ul>\n        <li><strong>Extended symbol information:</strong> The `find_symbol` and `find_referencing_symbols` tools (and their JetBrains variants)\n            now can return more information about the symbol (specifically, docstrings and signatures).\n        </li>\n        <li><strong>Type hierarchy tool:</strong> A new tool &ndash; exclusive to <a href=\"https://oraios.github.io/serena/02-usage/025_jetbrains_plugin.html\">JetBrains mode</a> &ndash;\n            that can fetch a symbol's hierarchy, i.e. superclasses and subclasses, which is very useful in many situations.\n        </li>\n        <li><strong>Compact overviews:</strong> The `get_symbols_overview` tools now return a much more compact\n            representation, saving many tokens. The JetBrains variant of the tool can now return a file's docstring (LSP\n            varian't can't do that yet).\n        </li>\n    </ul>\n    <p>\n        For more detailed information, see our <a href=\"https://github.com/oraios/serena/blob/main/CHANGELOG.md\">changelog</a>.\n    </p>\n</div>"
  },
  {
    "path": "src/serena/resources/dashboard/news/20260303.html",
    "content": "<div class=\"news-item\">\n    <h3>Nested and Global Memories</h3>\n    <p class=\"date\">March 03, 2026</p>\n    <p>\n        Serena's memory system has been significantly extended in functionality.\n        It keeps the simplicity that made it popular but now supports structuring memories\n        into topics and sharing them across projects.\n    </p>\n    <p>\n        For more detailed information, see the <a href=\"https://oraios.github.io/serena/02-usage/045_memories.html\">documentation</a>.\n    </p>\n</div>"
  },
  {
    "path": "src/serena/resources/project.local.template.yml",
    "content": "# This file allows you to locally override settings in project.yml for development purposes.\n#\n# Use the same keys as in project.yml here. Any setting you specify will override the corresponding\n# setting in project.yml, allowing you to customise the configuration for your local development environment\n# without affecting the project configuration in project.yml (which is intended to be versioned).\n"
  },
  {
    "path": "src/serena/resources/project.template.yml",
    "content": "# the name by which the project can be referenced within Serena\nproject_name: \"project_name\"\n\n\n# list of languages for which language servers are started; choose from:\n#   al                  bash                clojure             cpp                 csharp\n#   csharp_omnisharp    dart                elixir              elm                 erlang\n#   fortran             fsharp              go                  groovy              haskell\n#   java                julia               kotlin              lua                 markdown\n#   matlab              nix                 pascal              perl                php\n#   php_phpactor        powershell          python              python_jedi         r\n#   rego                ruby                ruby_solargraph     rust                scala\n#   swift               terraform           toml                typescript          typescript_vts\n#   vue                 yaml                zig\n#   (This list may be outdated. For the current list, see values of Language enum here:\n#   https://github.com/oraios/serena/blob/main/src/solidlsp/ls_config.py\n#   For some languages, there are alternative language servers, e.g. csharp_omnisharp, ruby_solargraph.)\n# Note:\n#   - For C, use cpp\n#   - For JavaScript, use typescript\n#   - For Free Pascal/Lazarus, use pascal\n# Special requirements:\n#   Some languages require additional setup/installations.\n#   See here for details: https://oraios.github.io/serena/01-about/020_programming-languages.html#language-servers\n# When using multiple languages, the first language server that supports a given file will be used for that file.\n# The first language is the default language and the respective language server will be used as a fallback.\n# Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.\nlanguages: [\"python\"]\n\n# the encoding used by text files in the project\n# For a list of possible encodings, see https://docs.python.org/3.11/library/codecs.html#standard-encodings\nencoding: \"utf-8\"\n\n# line ending convention to use when writing source files.\n# Possible values: unset (use global setting), \"lf\", \"crlf\", or \"native\" (platform default)\n# This does not affect Serena's own files (e.g. memories and configuration files), which always use native line endings.\nline_ending:\n\n# The language backend to use for this project.\n# If not set, the global setting from serena_config.yml is used.\n# Valid values: LSP, JetBrains\n# Note: the backend is fixed at startup. If a project with a different backend\n# is activated post-init, an error will be returned.\nlanguage_backend:\n\n# whether to use project's .gitignore files to ignore files\nignore_all_files_in_gitignore: true\n\n# list of additional paths to ignore in this project.\n# Same syntax as gitignore, so you can use * and **.\n# Note: global ignored_paths from serena_config.yml are also applied additively.\nignored_paths: []\n\n# whether the project is in read-only mode\n# If set to true, all editing tools will be disabled and attempts to use them will result in an error\n# Added on 2025-04-18\nread_only: false\n\n# list of tool names to exclude.\n# This extends the existing exclusions (e.g. from the global configuration)\n#\n# Below is the complete list of tools for convenience.\n# To make sure you have the latest list of tools, and to view their descriptions, \n# execute `uv run scripts/print_tool_overview.py`.\n#\n#  * `activate_project`: Activates a project by name.\n#  * `check_onboarding_performed`: Checks whether project onboarding was already performed.\n#  * `create_text_file`: Creates/overwrites a file in the project directory.\n#  * `delete_lines`: Deletes a range of lines within a file.\n#  * `delete_memory`: Deletes a memory from Serena's project-specific memory store.\n#  * `execute_shell_command`: Executes a shell command.\n#  * `find_referencing_code_snippets`: Finds code snippets in which the symbol at the given location is referenced.\n#  * `find_referencing_symbols`: Finds symbols that reference the symbol at the given location (optionally filtered by type).\n#  * `find_symbol`: Performs a global (or local) search for symbols with/containing a given name/substring (optionally filtered by type).\n#  * `get_current_config`: Prints the current configuration of the agent, including the active and available projects, tools, contexts, and modes.\n#  * `get_symbols_overview`: Gets an overview of the top-level symbols defined in a given file.\n#  * `initial_instructions`: Gets the initial instructions for the current project.\n#     Should only be used in settings where the system prompt cannot be set,\n#     e.g. in clients you have no control over, like Claude Desktop.\n#  * `insert_after_symbol`: Inserts content after the end of the definition of a given symbol.\n#  * `insert_at_line`: Inserts content at a given line in a file.\n#  * `insert_before_symbol`: Inserts content before the beginning of the definition of a given symbol.\n#  * `list_dir`: Lists files and directories in the given directory (optionally with recursion).\n#  * `list_memories`: Lists memories in Serena's project-specific memory store.\n#  * `onboarding`: Performs onboarding (identifying the project structure and essential tasks, e.g. for testing or building).\n#  * `prepare_for_new_conversation`: Provides instructions for preparing for a new conversation (in order to continue with the necessary context).\n#  * `read_file`: Reads a file within the project directory.\n#  * `read_memory`: Reads the memory with the given name from Serena's project-specific memory store.\n#  * `remove_project`: Removes a project from the Serena configuration.\n#  * `replace_lines`: Replaces a range of lines within a file with new content.\n#  * `replace_symbol_body`: Replaces the full definition of a symbol.\n#  * `restart_language_server`: Restarts the language server, may be necessary when edits not through Serena happen.\n#  * `search_for_pattern`: Performs a search for a pattern in the project.\n#  * `summarize_changes`: Provides instructions for summarizing the changes made to the codebase.\n#  * `switch_modes`: Activates modes by providing a list of their names\n#  * `think_about_collected_information`: Thinking tool for pondering the completeness of collected information.\n#  * `think_about_task_adherence`: Thinking tool for determining whether the agent is still on track with the current task.\n#  * `think_about_whether_you_are_done`: Thinking tool for determining whether the task is truly completed.\n#  * `write_memory`: Writes a named memory (for future reference) to Serena's project-specific memory store.\nexcluded_tools: []\n\n# list of tools to include that would otherwise be disabled (particularly optional tools that are disabled by default).\n# This extends the existing inclusions (e.g. from the global configuration).\nincluded_optional_tools: []\n\n# fixed set of tools to use as the base tool set (if non-empty), replacing Serena's default set of tools.\n# This cannot be combined with non-empty excluded_tools or included_optional_tools.\nfixed_tools: []\n\n# list of mode names to that are always to be included in the set of active modes\n# The full set of modes to be activated is base_modes + default_modes.\n# If the setting is undefined, the base_modes from the global configuration (serena_config.yml) apply.\n# Otherwise, this setting overrides the global configuration.\n# Set this to [] to disable base modes for this project.\n# Set this to a list of mode names to always include the respective modes for this project.\nbase_modes:\n\n# list of mode names that are to be activated by default.\n# The full set of modes to be activated is base_modes + default_modes.\n# If the setting is undefined, the default_modes from the global configuration (serena_config.yml) apply.\n# Otherwise, this overrides the setting from the global configuration (serena_config.yml).\n# This setting can, in turn, be overridden by CLI parameters (--mode).\ndefault_modes:\n\n# initial prompt for the project. It will always be given to the LLM upon activating the project\n# (contrary to the memories, which are loaded on demand).\ninitial_prompt: \"\"\n\n# time budget (seconds) per tool call for the retrieval of additional symbol information\n# such as docstrings or parameter information.\n# This overrides the corresponding setting in the global configuration; see the documentation there.\n# If null or missing, use the setting from the global configuration.\nsymbol_info_budget:\n\n# list of regex patterns which, when matched, mark a memory entry as read‑only.\n# Extends the list from the global configuration, merging the two lists.\nread_only_memory_patterns: []\n"
  },
  {
    "path": "src/serena/resources/serena_config.template.yml",
    "content": "# the language backend to use for code understanding and manipulation.\n# Possible values are:\n#  * LSP: Use the language server protocol (LSP), spawning freely available language servers\n#      via the SolidLSP library that is part of Serena.\n#  * JetBrains: Use the Serena plugin in your JetBrains IDE.\n#      (requires the plugin to be installed and the project being worked on to be open\n#      in your IDE).\nlanguage_backend: LSP\n\n# line ending convention to use when writing source files.\n# Possible values: \"lf\" (Unix), \"crlf\" (Windows), \"native\" (platform default).\n# Note that Serena's own files (e.g. memories and configuration files) always use native line endings.\n# This setting can be overridden on a per-project basis in project.yml files.\nline_ending: native\n\n# whether to open a graphical window with Serena's logs.\n# This is mainly supported on Windows and (partly) on Linux; not available on macOS.\n# If you prefer a browser-based tool, use the `web_dashboard` option instead.\n# Further information: https://oraios.github.io/serena/02-usage/060_dashboard.html\n#\n# Being able to inspect logs is useful both for troubleshooting and for monitoring the tool calls,\n# especially when using the agno playground, since the tool calls are not always shown,\n# and the input params are never shown in the agno UI.\n# When used as MCP server for Claude Desktop, the logs are primarily for troubleshooting.\n# Note: unfortunately, the various entities starting the Serena server or agent do so in\n# mysterious ways, often starting multiple instances of the process without shutting down\n# previous instances. This can lead to multiple log windows being opened, and only the last\n# window being updated. Since we can't control how agno or Claude Desktop start Serena,\n# we have to live with this limitation for now.\ngui_log_window: False\n\n# whether to open the Serena web dashboard (which will be accessible through your web browser) that\n# provides access to Serena's configuration and state as well as the current session logs.\n# The web dashboard is supported on all platforms.\n# We strongly recommend to always enable this option, since the dashboard provides important information\n# about the current state of Serena, including the configuration, the logs and tool usage statistics.\n# If you don't want the browser window to pop up automatically, set the `web_dashboard_open_on_launch` to False\n# (either here or through the corresponding flag in the `start-mcp-server` CLI command).\n# You can then open the dashboard by asking your agent to do so (e.g., by saying \"open the dashboard\"), Serena provides\n# a tool for this.\n# Further information: https://oraios.github.io/serena/02-usage/060_dashboard.html\nweb_dashboard: True\n\n# the address the web dashboard will listen on (bind address).\nweb_dashboard_listen_address: 127.0.0.1\n\n# whether to open a browser window with the web dashboard when Serena starts (provided that web_dashboard\n# is enabled). See also the web_dashboard option.\n# If set to false, you can still open the dashboard manually by\n# a) telling the LLM to \"open the dashboard\" (provided that the open_dashboard tool is enabled) or by\n# b) manually navigating to http://localhost:24282/dashboard/ in your web browser (actual port\n#    may be higher if you have multiple instances running; try ports 24283, 24284, etc.)\n# See also: https://oraios.github.io/serena/02-usage/060_dashboard.html\nweb_dashboard_open_on_launch: True\n\n# address where JetBrains plugin servers are running (only relevant when using the JetBrains language backend)\njetbrains_plugin_server_address: 127.0.0.1\n\n# the minimum log level for the GUI log window and the dashboard (10 = debug, 20 = info, 30 = warning, 40 = error)\nlog_level: 20\n\n# whether to trace the communication between Serena and the language servers.\n# This is useful for debugging language server issues.\ntrace_lsp_communication: False\n\n# advanced configuration option allowing to configure language server-specific options.\n# Maps the language key to the options.\n# Have a look at the docstring of the constructors of the LS implementations within solidlsp (e.g., for C# or PHP) to see which options are available.\n# No documentation on options means no options are available.\nls_specific_settings: {}\n\n# list of paths to ignore across all projects.\n# Same syntax as gitignore, so you can use * and **.\n# These patterns are merged additively with each project's own ignored_paths.\nignored_paths: []\n\n# list of regex patterns which, when matched, mark a memory entry as read‑only.\n# For example, \"global/.*\" will mark all global memories as read-only.\n# You can extend the list on a per-project basis in the project.yml configuration file.\nread_only_memory_patterns: []\n\n# timeout, in seconds, after which tool executions are terminated\ntool_timeout: 240\n\n# list of tools to be globally excluded\nexcluded_tools: []\n\n# list of optional tools (which are disabled by default) to be included\nincluded_optional_tools: []\n\n# fixed set of tools to use as the base tool set (if non-empty), replacing Serena's default set of tools.\n# This cannot be combined with non-empty excluded_tools or included_optional_tools.\nfixed_tools: []\n\n# list of mode names to that are always to be included in the set of active modes\n# The full set of modes to be activated is base_modes + default_modes.\n# If this is undefined, no base modes are included.\n# The project configuration (project.yml) may override this setting.\nbase_modes:\n\n# list of mode names that are to be activated by default.\n# The full set of modes to be activated is base_modes + default_modes.\n# These modes can be overridden by the project configuration (project.yml) or through the CLI (--mode).\ndefault_modes:\n  - interactive\n  - editing\n\n# Used as default for tools where the apply method has a default maximal answer length.\n# Even though the value of the max_answer_chars can be changed when calling the tool, it may make sense to adjust this default\n# through the global configuration.\ndefault_max_tool_answer_chars: 150000\n\n# the name of the token count estimator to use for tool usage statistics.\n# See the `RegisteredTokenCountEstimator` enum for available options.\n#\n# By default, a very naive character count estimator is used, which simply counts the number of characters.\n# You can configure this to TIKTOKEN_GPT4 to use a local tiktoken-based estimator for GPT-4 (will download tiktoken\n# data files on first run), or ANTHROPIC_CLAUDE_SONNET_4 which will use the (free of cost) Anthropic API to\n# estimate the token count using the Claude Sonnet 4 tokenizer.\ntoken_count_estimator: CHAR_COUNT\n\n# time budget (seconds) per tool call for the retrieval of additional symbol information\n# such as docstrings or parameter information.\n# (currently only used by LSP-based tools).\n# If the budget is exceeded, Serena stops issuing further retrieval requests\n# and returns partial info results.\n# 0 disables the budget (no early stopping). Negative values are invalid.\n# This is an advanced setting that can help alleviate problems with LSP servers\n# that have a slow implementation of request_hover (clangd is one of those)\n# or with tool calls that find very many symbols.\n# Can be overridden in project.yml.\nsymbol_info_budget: 10\n\n# template for the location of the per-project .serena data folder (memories, caches, etc.).\n# Supports the following placeholders:\n#   $projectDir         - the absolute path to the project root directory\n#   $projectFolderName  - the name of the project directory\n# Default: \"$projectDir/.serena\" (data stored inside the project directory)\n# Example for a central location: \"/projects-metadata/$projectFolderName/.serena\"\nproject_serena_folder_location: \"$projectDir/.serena\"\n\n# the list of registered project paths (updated automatically).\nprojects: []\n"
  },
  {
    "path": "src/serena/symbol.py",
    "content": "import json\nimport logging\nimport os\nfrom abc import ABC, abstractmethod\nfrom collections.abc import Callable, Iterable, Iterator, Sequence\nfrom dataclasses import asdict, dataclass\nfrom time import perf_counter\nfrom typing import Any, Generic, Literal, NotRequired, Self, TypedDict, TypeVar\n\nfrom sensai.util.string import ToStringMixin\n\nimport serena.jetbrains.jetbrains_types as jb\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls import LSPFileBuffer\nfrom solidlsp.ls import ReferenceInSymbol as LSPReferenceInSymbol\nfrom solidlsp.ls_types import Position, SymbolKind, UnifiedSymbolInformation\n\nfrom .ls_manager import LanguageServerManager\nfrom .project import Project\n\nlog = logging.getLogger(__name__)\nNAME_PATH_SEP = \"/\"\n\n\n@dataclass\nclass LanguageServerSymbolLocation:\n    \"\"\"\n    Represents the (start) location of a symbol identifier, which, within Serena, uniquely identifies the symbol.\n    \"\"\"\n\n    relative_path: str | None\n    \"\"\"\n    the relative path of the file containing the symbol; if None, the symbol is defined outside of the project's scope\n    \"\"\"\n    line: int | None\n    \"\"\"\n    the line number in which the symbol identifier is defined (if the symbol is a function, class, etc.);\n    may be None for some types of symbols (e.g. SymbolKind.File)\n    \"\"\"\n    column: int | None\n    \"\"\"\n    the column number in which the symbol identifier is defined (if the symbol is a function, class, etc.);\n    may be None for some types of symbols (e.g. SymbolKind.File)\n    \"\"\"\n\n    def __post_init__(self) -> None:\n        if self.relative_path is not None:\n            self.relative_path = self.relative_path.replace(\"/\", os.path.sep)\n\n    def to_dict(self, include_relative_path: bool = True) -> dict[str, Any]:\n        result = asdict(self)\n        if not include_relative_path:\n            result.pop(\"relative_path\", None)\n        return result\n\n    def has_position_in_file(self) -> bool:\n        return self.relative_path is not None and self.line is not None and self.column is not None\n\n\n@dataclass\nclass PositionInFile:\n    \"\"\"\n    Represents a character position within a file\n    \"\"\"\n\n    line: int\n    \"\"\"\n    the 0-based line number in the file\n    \"\"\"\n    col: int\n    \"\"\"\n    the 0-based column\n    \"\"\"\n\n    def to_lsp_position(self) -> Position:\n        \"\"\"\n        Convert to LSP Position.\n        \"\"\"\n        return Position(line=self.line, character=self.col)\n\n\nclass Symbol(ToStringMixin, ABC):\n    @abstractmethod\n    def get_body_start_position(self) -> PositionInFile | None:\n        pass\n\n    @abstractmethod\n    def get_body_end_position(self) -> PositionInFile | None:\n        pass\n\n    def get_body_start_position_or_raise(self) -> PositionInFile:\n        \"\"\"\n        Get the start position of the symbol body, raising an error if it is not defined.\n        \"\"\"\n        pos = self.get_body_start_position()\n        if pos is None:\n            raise ValueError(f\"Body start position is not defined for {self}\")\n        return pos\n\n    def get_body_end_position_or_raise(self) -> PositionInFile:\n        \"\"\"\n        Get the end position of the symbol body, raising an error if it is not defined.\n        \"\"\"\n        pos = self.get_body_end_position()\n        if pos is None:\n            raise ValueError(f\"Body end position is not defined for {self}\")\n        return pos\n\n    @abstractmethod\n    def is_neighbouring_definition_separated_by_empty_line(self) -> bool:\n        \"\"\"\n        :return: whether a symbol definition of this symbol's kind is usually separated from the\n            previous/next definition by at least one empty line.\n        \"\"\"\n\n\nclass NamePathComponent:\n    def __init__(self, name: str, overload_idx: int | None = None) -> None:\n        self.name = name\n        self.overload_idx = overload_idx\n\n    def __repr__(self) -> str:\n        if self.overload_idx is not None:\n            return f\"{self.name}[{self.overload_idx}]\"\n        else:\n            return self.name\n\n\nclass NamePathMatcher(ToStringMixin):\n    \"\"\"\n    Matches name paths of symbols against search patterns.\n\n    A name path is a path in the symbol tree *within a source file*.\n    For example, the method `my_method` defined in class `MyClass` would have the name path `MyClass/my_method`.\n    If a symbol is overloaded (e.g., in Java), a 0-based index is appended (e.g. \"MyClass/my_method[0]\") to\n    uniquely identify it.\n\n    A matching pattern can be:\n     * a simple name (e.g. \"method\"), which will match any symbol with that name\n     * a relative path like \"class/method\", which will match any symbol with that name path suffix\n     * an absolute name path \"/class/method\" (absolute name path), which requires an exact match of the full name path within the source file.\n    Append an index `[i]` to match a specific overload only, e.g. \"MyClass/my_method[1]\".\n    \"\"\"\n\n    class PatternComponent(NamePathComponent):\n        @classmethod\n        def from_string(cls, component_str: str) -> Self:\n            overload_idx = None\n            if component_str.endswith(\"]\") and \"[\" in component_str:\n                bracket_idx = component_str.rfind(\"[\")\n                index_part = component_str[bracket_idx + 1 : -1]\n                if index_part.isdigit():\n                    component_str = component_str[:bracket_idx]\n                    overload_idx = int(index_part)\n            return cls(name=component_str, overload_idx=overload_idx)\n\n        def matches(self, name_path_component: NamePathComponent, substring_matching: bool) -> bool:\n            if substring_matching:\n                if self.name not in name_path_component.name:\n                    return False\n            else:\n                if self.name != name_path_component.name:\n                    return False\n            if self.overload_idx is not None and self.overload_idx != name_path_component.overload_idx:\n                return False\n            return True\n\n    def __init__(self, name_path_pattern: str, substring_matching: bool) -> None:\n        \"\"\"\n        :param name_path_pattern: the name path expression to match against\n        :param substring_matching: whether to use substring matching for the last segment\n        \"\"\"\n        assert name_path_pattern, \"name_path must not be empty\"\n        self._expr = name_path_pattern\n        self._substring_matching = substring_matching\n        self._is_absolute_pattern = name_path_pattern.startswith(NAME_PATH_SEP)\n        self._components = [\n            self.PatternComponent.from_string(x) for x in name_path_pattern.lstrip(NAME_PATH_SEP).rstrip(NAME_PATH_SEP).split(NAME_PATH_SEP)\n        ]\n\n    def _tostring_includes(self) -> list[str]:\n        return [\"_expr\"]\n\n    def matches_ls_symbol(self, symbol: \"LanguageServerSymbol\") -> bool:\n        return self.matches_reversed_components(symbol.iter_name_path_components_reversed())\n\n    def matches_reversed_components(self, components_reversed: Iterator[NamePathComponent]) -> bool:\n        for i, pattern_component in enumerate(reversed(self._components)):\n            try:\n                symbol_component = next(components_reversed)\n            except StopIteration:\n                return False\n            use_substring_matching = self._substring_matching and (i == 0)\n            if not pattern_component.matches(symbol_component, use_substring_matching):\n                return False\n        if self._is_absolute_pattern:\n            # ensure that there are no more components in the symbol\n            try:\n                next(components_reversed)\n                return False\n            except StopIteration:\n                pass\n        return True\n\n\nclass LanguageServerSymbol(Symbol, ToStringMixin):\n    def __init__(self, symbol_root_from_ls: UnifiedSymbolInformation) -> None:\n        self.symbol_root = symbol_root_from_ls\n\n    def _tostring_includes(self) -> list[str]:\n        return []\n\n    def _tostring_additional_entries(self) -> dict[str, Any]:\n        return dict(name=self.name, kind=self.symbol_kind_name, num_children=len(self.symbol_root[\"children\"]))\n\n    @property\n    def name(self) -> str:\n        return self.symbol_root[\"name\"]\n\n    @property\n    def symbol_kind_name(self) -> str:\n        \"\"\"\n        :return: string representation of the symbol kind (name attribute of the `SymbolKind` enum item)\n        \"\"\"\n        return SymbolKind(self.symbol_kind).name\n\n    @property\n    def symbol_kind(self) -> SymbolKind:\n        return self.symbol_root[\"kind\"]\n\n    def is_low_level(self) -> bool:\n        \"\"\"\n        :return: whether the symbol is a low-level symbol (variable, constant, etc.), which typically represents data\n            rather than structure and therefore is not relevant in a high-level overview of the code.\n        \"\"\"\n        return self.symbol_kind >= SymbolKind.Variable.value\n\n    @property\n    def overload_idx(self) -> int | None:\n        return self.symbol_root.get(\"overload_idx\")\n\n    def is_neighbouring_definition_separated_by_empty_line(self) -> bool:\n        return self.symbol_kind in (SymbolKind.Function, SymbolKind.Method, SymbolKind.Class, SymbolKind.Interface, SymbolKind.Struct)\n\n    @property\n    def relative_path(self) -> str | None:\n        location = self.symbol_root.get(\"location\")\n        if location:\n            return location.get(\"relativePath\")\n        return None\n\n    @property\n    def location(self) -> LanguageServerSymbolLocation:\n        \"\"\"\n        :return: the start location of the actual symbol identifier\n        \"\"\"\n        return LanguageServerSymbolLocation(relative_path=self.relative_path, line=self.line, column=self.column)\n\n    @property\n    def body_start_position(self) -> Position | None:\n        location = self.symbol_root.get(\"location\")\n        if location:\n            range_info = location.get(\"range\")\n            if range_info:\n                start_pos = range_info.get(\"start\")\n                if start_pos:\n                    return start_pos\n        return None\n\n    @property\n    def body_end_position(self) -> Position | None:\n        location = self.symbol_root.get(\"location\")\n        if location:\n            range_info = location.get(\"range\")\n            if range_info:\n                end_pos = range_info.get(\"end\")\n                if end_pos:\n                    return end_pos\n        return None\n\n    def get_body_start_position(self) -> PositionInFile | None:\n        start_pos = self.body_start_position\n        if start_pos is None:\n            return None\n        return PositionInFile(line=start_pos[\"line\"], col=start_pos[\"character\"])\n\n    def get_body_end_position(self) -> PositionInFile | None:\n        end_pos = self.body_end_position\n        if end_pos is None:\n            return None\n        return PositionInFile(line=end_pos[\"line\"], col=end_pos[\"character\"])\n\n    def get_body_line_numbers(self) -> tuple[int | None, int | None]:\n        start_pos = self.body_start_position\n        end_pos = self.body_end_position\n        start_line = start_pos[\"line\"] if start_pos else None\n        end_line = end_pos[\"line\"] if end_pos else None\n        return start_line, end_line\n\n    @property\n    def line(self) -> int | None:\n        \"\"\"\n        :return: the line in which the symbol identifier is defined.\n        \"\"\"\n        if \"selectionRange\" in self.symbol_root:\n            return self.symbol_root[\"selectionRange\"][\"start\"][\"line\"]\n        else:\n            # line is expected to be undefined for some types of symbols (e.g. SymbolKind.File)\n            return None\n\n    @property\n    def column(self) -> int | None:\n        if \"selectionRange\" in self.symbol_root:\n            return self.symbol_root[\"selectionRange\"][\"start\"][\"character\"]\n        else:\n            # precise location is expected to be undefined for some types of symbols (e.g. SymbolKind.File)\n            return None\n\n    @property\n    def body(self) -> str | None:\n        body = self.symbol_root.get(\"body\")\n        if body is None:\n            return None\n        else:\n            return body.get_text()\n\n    def get_name_path(self) -> str:\n        \"\"\"\n        Get the name path of the symbol, e.g. \"class/method/inner_function\" or\n        \"class/method[1]\" (overloaded method with identifying index).\n        \"\"\"\n        name_path = NAME_PATH_SEP.join(reversed([str(x) for x in self.iter_name_path_components_reversed()]))\n        return name_path\n\n    def iter_name_path_components_reversed(self) -> Iterator[NamePathComponent]:\n        yield NamePathComponent(self.name, self.overload_idx)\n        for ancestor in self.iter_ancestors(up_to_symbol_kind=SymbolKind.File):\n            yield NamePathComponent(ancestor.name, ancestor.overload_idx)\n\n    def iter_children(self) -> Iterator[Self]:\n        for c in self.symbol_root[\"children\"]:\n            yield self.__class__(c)\n\n    def iter_ancestors(self, up_to_symbol_kind: SymbolKind | None = None) -> Iterator[Self]:\n        \"\"\"\n        Iterate over all ancestors of the symbol, starting with the parent and going up to the root or\n        the given symbol kind.\n\n        :param up_to_symbol_kind: if provided, iteration will stop *before* the first ancestor of the given kind.\n            A typical use case is to pass `SymbolKind.File` or `SymbolKind.Package`.\n        \"\"\"\n        parent = self.get_parent()\n        if parent is not None:\n            if up_to_symbol_kind is None or parent.symbol_kind != up_to_symbol_kind:\n                yield parent\n                yield from parent.iter_ancestors(up_to_symbol_kind=up_to_symbol_kind)\n\n    def get_parent(self) -> Self | None:\n        parent_root = self.symbol_root.get(\"parent\")\n        if parent_root is None:\n            return None\n        return self.__class__(parent_root)\n\n    def find(\n        self,\n        name_path_pattern: str,\n        substring_matching: bool = False,\n        include_kinds: Sequence[SymbolKind] | None = None,\n        exclude_kinds: Sequence[SymbolKind] | None = None,\n    ) -> list[Self]:\n        \"\"\"\n        Find all symbols within the symbol's subtree that match the given name path pattern.\n\n        :param name_path_pattern: the name path pattern to match against (see class :class:`NamePathMatcher` for details)\n        :param substring_matching: whether to use substring matching (as opposed to exact matching)\n            of the last segment of `name_path` against the symbol name.\n        :param include_kinds: an optional sequence of ints representing the LSP symbol kind.\n            If provided, only symbols of the given kinds will be included in the result.\n        :param exclude_kinds: If provided, symbols of the given kinds will be excluded from the result.\n        \"\"\"\n        result = []\n        name_path_matcher = NamePathMatcher(name_path_pattern, substring_matching)\n\n        def should_include(s: \"LanguageServerSymbol\") -> bool:\n            if include_kinds is not None and s.symbol_kind not in include_kinds:\n                return False\n            if exclude_kinds is not None and s.symbol_kind in exclude_kinds:\n                return False\n            return name_path_matcher.matches_ls_symbol(s)\n\n        def traverse(s: \"LanguageServerSymbol\") -> None:\n            if should_include(s):\n                result.append(s)\n            for c in s.iter_children():\n                traverse(c)\n\n        traverse(self)\n        return result\n\n    class OutputDict(TypedDict):\n        name_path: NotRequired[str]\n        name: NotRequired[str]\n        location: NotRequired[dict[str, Any]]\n        relative_path: NotRequired[str | None]\n        body_location: NotRequired[dict[str, Any]]\n        body: NotRequired[str | None]\n        kind: NotRequired[str]\n        \"\"\"\n        string representation of the symbol kind (name attribute of the `SymbolKind` enum item)\n        \"\"\"\n        children: NotRequired[list[\"LanguageServerSymbol.OutputDict\"]]\n\n    OutputDictKey = Literal[\"name\", \"name_path\", \"relative_path\", \"location\", \"body_location\", \"body\", \"kind\", \"children\"]\n\n    def to_dict(\n        self,\n        *,\n        name_path: bool = True,\n        name: bool = False,\n        kind: bool = False,\n        location: bool = False,\n        depth: int = 0,\n        body: bool = False,\n        body_location: bool = False,\n        children_body: bool = False,\n        relative_path: bool = False,\n        child_inclusion_predicate: Callable[[Self], bool] | None = None,\n    ) -> OutputDict:\n        \"\"\"\n        Converts the symbol to a dictionary.\n\n        :param name_path: whether to include the name path of the symbol\n        :param name: whether to include the name of the symbol\n        :param kind: whether to include the kind of the symbol\n        :param location: whether to include the location of the symbol\n        :param depth: the depth up to which to include child symbols (0 = do not include children)\n        :param body: whether to include the body of the top-level symbol.\n        :param children_body: whether to also include the body of the children.\n            Note that the body of the children is part of the body of the parent symbol,\n            so there is usually no need to set this to True unless you want process the output\n            and pass the children without passing the parent body to the LM.\n        :param relative_path: whether to include the relative path of the symbol.\n            If `location` is True, this defines whether to include the path in the location entry.\n            If `location` is False, this defines whether to include the relative path as a top-level entry.\n            Relative paths of the symbol's children are always excluded.\n        :param child_inclusion_predicate: an optional predicate that decides whether a child symbol\n            should be included.\n        :return: a dictionary representation of the symbol\n        \"\"\"\n        result: LanguageServerSymbol.OutputDict = {}\n\n        if name_path:\n            result[\"name_path\"] = self.get_name_path()\n        if name:\n            result[\"name\"] = self.name\n\n        if kind:\n            result[\"kind\"] = self.symbol_kind_name\n\n        if location:\n            result[\"location\"] = self.location.to_dict(include_relative_path=relative_path)\n        elif relative_path:\n            result[\"relative_path\"] = self.relative_path\n\n        if body_location:\n            body_start_line, body_end_line = self.get_body_line_numbers()\n            result[\"body_location\"] = {\"start_line\": body_start_line, \"end_line\": body_end_line}\n\n        if body:\n            result[\"body\"] = self.body\n\n        if child_inclusion_predicate is None:\n            child_inclusion_predicate = lambda s: True\n\n        def included_children(s: Self) -> list[LanguageServerSymbol.OutputDict]:\n            children = []\n            for c in s.iter_children():\n                if not child_inclusion_predicate(c):\n                    continue\n                children.append(\n                    c.to_dict(\n                        name_path=name_path,\n                        name=name,\n                        kind=kind,\n                        location=location,\n                        body_location=body_location,\n                        depth=depth - 1,\n                        child_inclusion_predicate=child_inclusion_predicate,\n                        body=children_body,\n                        children_body=children_body,\n                        # all children have the same relative path as the parent\n                        relative_path=False,\n                    )\n                )\n            return children\n\n        if depth > 0:\n            children = included_children(self)\n            if len(children) > 0:\n                result[\"children\"] = children\n\n        return result\n\n\n@dataclass\nclass ReferenceInLanguageServerSymbol(ToStringMixin):\n    \"\"\"\n    Represents the location of a reference to another symbol within a symbol/file.\n\n    The contained symbol is the symbol within which the reference is located,\n    not the symbol that is referenced.\n    \"\"\"\n\n    symbol: LanguageServerSymbol\n    \"\"\"\n    the symbol within which the reference is located\n    \"\"\"\n    line: int\n    \"\"\"\n    the line number in which the reference is located (0-based)\n    \"\"\"\n    character: int\n    \"\"\"\n    the column number in which the reference is located (0-based)\n    \"\"\"\n\n    @classmethod\n    def from_lsp_reference(cls, reference: LSPReferenceInSymbol) -> Self:\n        return cls(symbol=LanguageServerSymbol(reference.symbol), line=reference.line, character=reference.character)\n\n    def get_relative_path(self) -> str | None:\n        return self.symbol.location.relative_path\n\n\nclass LanguageServerSymbolRetriever:\n    def __init__(self, project: Project) -> None:\n        \"\"\"\n        :param project: the project instance\n        \"\"\"\n        self._ls_manager: LanguageServerManager = project.get_language_server_manager_or_raise()\n        self.project = project\n\n    def _request_info(self, relative_file_path: str, line: int, column: int, file_buffer: LSPFileBuffer | None = None) -> str | None:\n        \"\"\"Retrieves information (in a sanitized format) about the symbol at the desired location,\n        typically containing the docstring and signature.\n\n        Returns None if no information is available.\n        \"\"\"\n        lang_server = self.get_language_server(relative_file_path)\n        hover_info = lang_server.request_hover(relative_file_path=relative_file_path, line=line, column=column, file_buffer=file_buffer)\n        if hover_info is None:\n            return None\n\n        contents = hover_info[\"contents\"]\n\n        # Handle various response formats\n        if isinstance(contents, list):\n            # Array format: extract all parts and join them\n            stripped_parts = []\n            for part in contents:\n                if isinstance(part, str) and (stripped_part := part.strip()):\n                    stripped_parts.append(stripped_part)\n                else:\n                    # should be a dict with \"value\" key\n                    stripped_parts.append(part[\"value\"].strip())  # type: ignore\n            return \"\\n\".join(stripped_parts) if stripped_parts else None\n\n        if isinstance(contents, dict) and (stripped_contents := contents.get(\"value\", \"\").strip()):\n            return stripped_contents\n\n        if isinstance(contents, str) and (stripped_contents := contents.strip()):\n            return stripped_contents\n\n        return None\n\n    def request_info_for_symbol(self, symbol: LanguageServerSymbol) -> str | None:\n        if None in [symbol.relative_path, symbol.line, symbol.column]:\n            return None\n        return self._request_info(relative_file_path=symbol.relative_path, line=symbol.line, column=symbol.column)  # type: ignore[arg-type]\n\n    def _get_symbol_info_budget(self) -> float:\n        symbol_info_budget = self.project.serena_config.symbol_info_budget\n        project_symbol_info_budget = self.project.project_config.symbol_info_budget\n        if project_symbol_info_budget is not None:\n            symbol_info_budget = project_symbol_info_budget\n        return symbol_info_budget\n\n    def request_info_for_symbol_batch(\n        self,\n        symbols: list[LanguageServerSymbol],\n    ) -> dict[LanguageServerSymbol, str | None]:\n        \"\"\"Retrieves information for multiple symbols while staying within a time budget.\n\n        The request_hover operation used here is potentially expensive, we optimize by grouping by file\n        and stop executing it (returning the info as None) after the symbol_info_budget is exceeded.\n        The hover budget is 5s by default\n\n        Groups symbols by file path to minimize file switching overhead and uses a per-file\n        cache keyed by (line, col) to avoid duplicate hover lookups.\n\n        The hover budget (symbol_info_budget) limits total time spent on hover\n        requests. If exceeded, remaining symbols get info=None (partial results).\n\n        :param symbols: list of symbols to get info for\n        :return: a dict mapping each processable symbol to its info (or None if unavailable). Symbols with missing location attributes (relative_path/line/column is None) are skipped and omitted from the result.\n        \"\"\"\n        if not symbols:\n            return {}\n\n        debug_enabled = log.isEnabledFor(logging.DEBUG)\n        t0_total = perf_counter() if debug_enabled else 0.0\n\n        info_by_symbol: dict[LanguageServerSymbol, str | None] = {}\n        skipped_symbols = 0\n\n        # Group symbols by file path, filtering invalid symbols.\n        symbols_by_file: dict[str, list[LanguageServerSymbol]] = {}\n        for sym in symbols:\n            file_path = sym.relative_path\n            line = sym.line\n            column = sym.column\n            if file_path is None or line is None or column is None:\n                skipped_symbols += 1\n                continue\n\n            symbols_by_file.setdefault(file_path, []).append(sym)\n\n        hover_spent_seconds = 0.0\n        symbol_info_budget_seconds = self._get_symbol_info_budget()\n        # the vars below are only for debug logging\n        per_file_stats: list[tuple[str, int, float]] = []\n        total_hover_lookups = 0\n        hover_cache_hits = 0\n        skipped_due_to_budget = 0\n\n        for file_path, file_symbols in symbols_by_file.items():\n            t0_file = perf_counter() if debug_enabled else 0.0\n            file_hover_lookups = 0\n\n            ls = self.get_language_server(file_path)\n            with ls.open_file(file_path) as file_buffer:\n                for sym in file_symbols:\n                    # Check budget before starting a new hover request\n                    # symbol_info_budget_seconds=0 disables the budget mechanism (the first inequality)\n                    if 0 < symbol_info_budget_seconds <= hover_spent_seconds:\n                        skipped_due_to_budget += 1\n                        info = None\n                        # log once when budget exceeded\n                        if skipped_due_to_budget == 1:\n                            log.debug(\"Skipping further hover operations due to budget exceeded\")\n                    else:\n                        line = sym.line\n                        column = sym.column\n                        assert line is not None and column is not None  # for mypy, we filtered invalid symbols above\n                        t0_hover = perf_counter()\n                        info = self._request_info(file_path, line, column, file_buffer=file_buffer)\n                        hover_spent_seconds += perf_counter() - t0_hover\n                        file_hover_lookups += 1\n                        total_hover_lookups += 1\n\n                    info_by_symbol[sym] = info\n\n            if debug_enabled:\n                file_elapsed_ms = (perf_counter() - t0_file) * 1000\n                per_file_stats.append((file_path, file_hover_lookups, file_elapsed_ms))\n\n        if debug_enabled:\n            total_elapsed_ms = (perf_counter() - t0_total) * 1000\n            total_symbols = len(symbols)\n            unique_files = len(symbols_by_file)\n            budget_exceeded = skipped_due_to_budget > 0\n\n            log.debug(\n                f\"perf: request_info_for_symbols {total_elapsed_ms=:.2f} {total_symbols=} {skipped_symbols=} \"\n                f\"{total_hover_lookups=} {hover_cache_hits=} {unique_files=} \"\n                f\"{symbol_info_budget_seconds=:.1f} {hover_spent_seconds=:.2f} {budget_exceeded=} {skipped_due_to_budget=}\"\n            )\n\n            for file_path, lookup_count, elapsed_ms in per_file_stats:\n                log.debug(f\"perf: {file_path=} {lookup_count=} {elapsed_ms=:.2f}\")\n\n        return info_by_symbol\n\n    def can_analyze_file(self, relative_file_path: str) -> bool:\n        return self._ls_manager.has_suitable_ls_for_file(relative_file_path)\n\n    def get_language_server(self, relative_path: str) -> SolidLanguageServer:\n        \"\"\":param relative_path: relative path to a file\"\"\"\n        return self._ls_manager.get_language_server(relative_path)\n\n    def find(\n        self,\n        name_path_pattern: str,\n        include_kinds: Sequence[SymbolKind] | None = None,\n        exclude_kinds: Sequence[SymbolKind] | None = None,\n        substring_matching: bool = False,\n        within_relative_path: str | None = None,\n    ) -> list[LanguageServerSymbol]:\n        \"\"\"\n        Finds all symbols that match the given name path pattern (see class :class:`NamePathMatcher` for details),\n        optionally limited to a specific file and filtered by kind.\n        \"\"\"\n        symbols: list[LanguageServerSymbol] = []\n        if within_relative_path and os.path.isfile(os.path.join(self.project.project_root, within_relative_path)):\n            \"\"\"\n            For a specific file, use get_language_server to select the best LS for the file type\n            (consistent with get_symbol_overview). This ensures e.g. PHP files are served by the\n            PHP language server rather than being rejected by all LSes via is_ignored_path.\n            \"\"\"\n            lang_servers: Iterable[SolidLanguageServer] = [self._ls_manager.get_language_server(within_relative_path)]\n        else:\n            lang_servers = self._ls_manager.iter_language_servers()\n        for lang_server in lang_servers:\n            symbol_roots = lang_server.request_full_symbol_tree(within_relative_path=within_relative_path)\n            for root in symbol_roots:\n                symbols.extend(\n                    LanguageServerSymbol(root).find(\n                        name_path_pattern, include_kinds=include_kinds, exclude_kinds=exclude_kinds, substring_matching=substring_matching\n                    )\n                )\n        return symbols\n\n    def find_unique(\n        self,\n        name_path_pattern: str,\n        include_kinds: Sequence[SymbolKind] | None = None,\n        exclude_kinds: Sequence[SymbolKind] | None = None,\n        substring_matching: bool = False,\n        within_relative_path: str | None = None,\n    ) -> LanguageServerSymbol:\n        symbol_candidates = self.find(\n            name_path_pattern,\n            include_kinds=include_kinds,\n            exclude_kinds=exclude_kinds,\n            substring_matching=substring_matching,\n            within_relative_path=within_relative_path,\n        )\n        if len(symbol_candidates) == 1:\n            return symbol_candidates[0]\n        elif len(symbol_candidates) == 0:\n            raise ValueError(f\"No symbol matching '{name_path_pattern}' found\")\n        else:\n            # There are multiple candidates.\n            # If only one of the candidates has the given pattern as its exact name path, return that one\n            exact_matches = [s for s in symbol_candidates if s.get_name_path() == name_path_pattern]\n            if len(exact_matches) == 1:\n                return exact_matches[0]\n            # otherwise, raise an error\n            include_rel_path = within_relative_path is not None\n            raise ValueError(\n                f\"Found multiple {len(symbol_candidates)} symbols matching '{name_path_pattern}'. \"\n                \"They are: \\n\" + json.dumps([s.to_dict(kind=True, relative_path=include_rel_path) for s in symbol_candidates], indent=2)\n            )\n\n    def find_by_location(self, location: LanguageServerSymbolLocation) -> LanguageServerSymbol | None:\n        if location.relative_path is None:\n            return None\n        lang_server = self.get_language_server(location.relative_path)\n        document_symbols = lang_server.request_document_symbols(location.relative_path)\n        for symbol_dict in document_symbols.iter_symbols():\n            symbol = LanguageServerSymbol(symbol_dict)\n            if symbol.location == location:\n                return symbol\n        return None\n\n    def find_referencing_symbols(\n        self,\n        name_path: str,\n        relative_file_path: str,\n        include_body: bool = False,\n        include_kinds: Sequence[SymbolKind] | None = None,\n        exclude_kinds: Sequence[SymbolKind] | None = None,\n    ) -> list[ReferenceInLanguageServerSymbol]:\n        \"\"\"\n        Find all symbols that reference the specified symbol, which is assumed to be unique.\n\n        :param name_path: the name path of the symbol to find. (While this can be a matching pattern, it should\n            usually be the full path to ensure uniqueness.)\n        :param relative_file_path: the relative path of the file in which the referenced symbol is defined.\n        :param include_body: whether to include the body of all symbols in the result.\n            Not recommended, as the referencing symbols will often be files, and thus the bodies will be very long.\n        :param include_kinds: which kinds of symbols to include in the result.\n        :param exclude_kinds: which kinds of symbols to exclude from the result.\n        \"\"\"\n        symbol = self.find_unique(name_path, substring_matching=False, within_relative_path=relative_file_path)\n        return self.find_referencing_symbols_by_location(\n            symbol.location, include_body=include_body, include_kinds=include_kinds, exclude_kinds=exclude_kinds\n        )\n\n    def find_referencing_symbols_by_location(\n        self,\n        symbol_location: LanguageServerSymbolLocation,\n        include_body: bool = False,\n        include_kinds: Sequence[SymbolKind] | None = None,\n        exclude_kinds: Sequence[SymbolKind] | None = None,\n    ) -> list[ReferenceInLanguageServerSymbol]:\n        \"\"\"\n        Find all symbols that reference the symbol at the given location.\n\n        :param symbol_location: the location of the symbol for which to find references.\n            Does not need to include an end_line, as it is unused in the search.\n        :param include_body: whether to include the body of all symbols in the result.\n            Not recommended, as the referencing symbols will often be files, and thus the bodies will be very long.\n            Note: you can filter out the bodies of the children if you set include_children_body=False\n            in the to_dict method.\n        :param include_kinds: an optional sequence of ints representing the LSP symbol kind.\n            If provided, only symbols of the given kinds will be included in the result.\n        :param exclude_kinds: If provided, symbols of the given kinds will be excluded from the result.\n            Takes precedence over include_kinds.\n        :return: a list of symbols that reference the given symbol\n        \"\"\"\n        if not symbol_location.has_position_in_file():\n            raise ValueError(\"Symbol location does not contain a valid position in a file\")\n        assert symbol_location.relative_path is not None\n        assert symbol_location.line is not None\n        assert symbol_location.column is not None\n        lang_server = self.get_language_server(symbol_location.relative_path)\n        references = lang_server.request_referencing_symbols(\n            relative_file_path=symbol_location.relative_path,\n            line=symbol_location.line,\n            column=symbol_location.column,\n            include_imports=False,\n            include_self=False,\n            include_body=include_body,\n            include_file_symbols=True,\n        )\n\n        if include_kinds is not None:\n            references = [s for s in references if s.symbol[\"kind\"] in include_kinds]\n\n        if exclude_kinds is not None:\n            references = [s for s in references if s.symbol[\"kind\"] not in exclude_kinds]\n\n        return [ReferenceInLanguageServerSymbol.from_lsp_reference(r) for r in references]\n\n    def get_symbol_overview(self, relative_path: str) -> dict[str, list[LanguageServerSymbol]]:\n        \"\"\"\n        :param relative_path: the path of the file for which to get the symbol overview\n        :return: a mapping from file paths to lists of symbols.\n            For the case where a file is passed, the mapping will contain a single entry.\n        \"\"\"\n        lang_server = self.get_language_server(relative_path)\n        path_to_unified_symbols = lang_server.request_overview(relative_path)\n        return {k: [LanguageServerSymbol(us) for us in v] for k, v in path_to_unified_symbols.items()}\n\n\nclass JetBrainsSymbol(Symbol):\n    def __init__(self, symbol_dict: jb.SymbolDTO, project: Project) -> None:\n        \"\"\"\n        :param symbol_dict: dictionary as returned by the JetBrains plugin client.\n        \"\"\"\n        self._project = project\n        self._dict = symbol_dict\n        self._cached_file_content: str | None = None\n        self._cached_body_start_position: PositionInFile | None = None\n        self._cached_body_end_position: PositionInFile | None = None\n\n    def _tostring_includes(self) -> list[str]:\n        return []\n\n    def _tostring_additional_entries(self) -> dict[str, Any]:\n        return dict(name_path=self.get_name_path(), relative_path=self.get_relative_path(), type=self._dict[\"type\"])\n\n    def get_name_path(self) -> str:\n        return self._dict[\"name_path\"]\n\n    def get_relative_path(self) -> str:\n        return self._dict[\"relative_path\"]\n\n    def get_file_content(self) -> str:\n        if self._cached_file_content is None:\n            path = os.path.join(self._project.project_root, self.get_relative_path())\n            with open(path, encoding=self._project.project_config.encoding) as f:\n                self._cached_file_content = f.read()\n        return self._cached_file_content\n\n    def is_position_in_file_available(self) -> bool:\n        return \"text_range\" in self._dict\n\n    def get_body_start_position(self) -> PositionInFile | None:\n        if not self.is_position_in_file_available():\n            return None\n        if self._cached_body_start_position is None:\n            pos = self._dict[\"text_range\"][\"start_pos\"]\n            line, col = pos[\"line\"], pos[\"col\"]\n            self._cached_body_start_position = PositionInFile(line=line, col=col)\n        return self._cached_body_start_position\n\n    def get_body_end_position(self) -> PositionInFile | None:\n        if not self.is_position_in_file_available():\n            return None\n        if self._cached_body_end_position is None:\n            pos = self._dict[\"text_range\"][\"end_pos\"]\n            line, col = pos[\"line\"], pos[\"col\"]\n            self._cached_body_end_position = PositionInFile(line=line, col=col)\n        return self._cached_body_end_position\n\n    def is_neighbouring_definition_separated_by_empty_line(self) -> bool:\n        # NOTE: Symbol types cannot really be differentiated, because types are not handled in a language-agnostic way.\n        return False\n\n\nTSymbolDict = TypeVar(\"TSymbolDict\")\nGroupedSymbolDict = dict[str, list[dict] | dict[str, dict]]\n\n\nclass SymbolDictGrouper(Generic[TSymbolDict], ABC):\n    \"\"\"\n    A utility class for grouping a list of symbol dictionaries by one or more specified keys.\n\n    If an instance is statically initialised (upon module import), then this establishes a guarantee\n    that the specified keys are defined in the symbol dictionary type, ensuring at least basic type safety.\n    The respective ValueError will immediately be apparent.\n    \"\"\"\n\n    def __init__(\n        self,\n        symbol_dict_type: type[TSymbolDict],\n        children_key: Any,\n        group_keys: list[Any],\n        group_children_keys: list[Any],\n        collapse_singleton: bool,\n    ) -> None:\n        \"\"\"\n        :param symbol_dict_type: the TypedDict type that represents the type of the symbol dictionaries to be grouped\n        :param children_key: the key in the symbol dictionaries that contains the list of child symbols (for recursive grouping).\n        :param group_keys: keys by which to group the symbol dictionaries. Must be a subset of the keys of `symbol_dict_type`.\n        :param group_children_keys: keys by which to group the child symbol dictionaries. Must be a subset of the keys of `symbol_dict_type`.\n        :param collapse_singleton: whether to collapse dictionaries containing a single entry after regrouping to just the entry's value\n        \"\"\"\n        # check whether the type contains all the keys specified in `keys` and raise an error if not.\n        if not hasattr(symbol_dict_type, \"__annotations__\"):\n            raise ValueError(f\"symbol_dict_type must be a TypedDict type, got {symbol_dict_type}\")\n        symbol_dict_keys = set(symbol_dict_type.__annotations__.keys())\n        for key in group_keys + [children_key] + group_children_keys:\n            if key not in symbol_dict_keys:\n                raise ValueError(f\"symbol_dict_type {symbol_dict_type} does not contain key '{key}'\")\n\n        self._children_key = children_key\n        self._group_keys = group_keys\n        self._group_children_keys = group_children_keys\n        self._collapse_singleton = collapse_singleton\n\n    def _group_by(self, l: list[dict], keys: list[str], children_keys: list[str]) -> dict[str, Any]:\n        assert len(keys) > 0, \"keys must not be empty\"\n        # group by the first key\n        grouped: dict[str, Any] = {}\n        for item in l:\n            key_value = item.pop(keys[0], \"unknown\")\n            if key_value not in grouped:\n                grouped[key_value] = []\n            grouped[key_value].append(item)\n        if len(keys) > 1:\n            # continue grouping by the remaining keys\n            for k, group in grouped.items():\n                grouped[k] = self._group_by(group, keys[1:], children_keys)\n        else:\n            # grouping is complete; now group the children if necessary\n            if children_keys:\n                for k, group in grouped.items():\n                    for item in group:\n                        if self._children_key in item:\n                            children = item[self._children_key]\n                            item[self._children_key] = self._group_by(children, children_keys, children_keys)\n            # post-process final group items\n            grouped = {k: [self._transform_item(i) for i in v] for k, v in grouped.items()}\n        return grouped\n\n    def _transform_item(self, item: dict) -> dict:\n        \"\"\"\n        Post-processes a final group item (which has been regrouped, i.e. some keys may have been removed),\n        collapsing singleton items (and items containing only a single non-children key)\n        \"\"\"\n        if self._collapse_singleton:\n            if len(item) == 1:\n                # {\"name\": \"foo\"} -> \"foo\"\n                # if there is only a single entry, collapse the dictionary to just the value of that entry\n                return next(iter(item.values()))\n            elif len(item) == 2 and self._children_key in item:\n                # {\"name\": \"foo\", \"children\": {...}} -> {\"foo\": {...}}\n                # if there are exactly two entries and one of them is the children key,\n                # convert to {other_value: children}\n                other_key = next(k for k in item.keys() if k != self._children_key)\n                new_item = {item[other_key]: item[self._children_key]}\n                return new_item\n        return item\n\n    def group(self, symbols: list[TSymbolDict]) -> GroupedSymbolDict:\n        \"\"\"\n        :param symbols: the symbols to group\n        :return: dictionary with the symbols grouped as defined at construction\n        \"\"\"\n        return self._group_by(symbols, self._group_keys, self._group_children_keys)  # type: ignore\n\n\nclass LanguageServerSymbolDictGrouper(SymbolDictGrouper[LanguageServerSymbol.OutputDict]):\n    def __init__(\n        self,\n        group_keys: list[LanguageServerSymbol.OutputDictKey],\n        group_children_keys: list[LanguageServerSymbol.OutputDictKey],\n        collapse_singleton: bool = False,\n    ) -> None:\n        super().__init__(LanguageServerSymbol.OutputDict, \"children\", group_keys, group_children_keys, collapse_singleton)\n\n\nclass JetBrainsSymbolDictGrouper(SymbolDictGrouper[jb.SymbolDTO]):\n    def __init__(\n        self,\n        group_keys: list[jb.SymbolDTOKey],\n        group_children_keys: list[jb.SymbolDTOKey],\n        collapse_singleton: bool = False,\n        map_name_path_to_name: bool = False,\n    ) -> None:\n        super().__init__(jb.SymbolDTO, \"children\", group_keys, group_children_keys, collapse_singleton)\n        self._map_name_path_to_name = map_name_path_to_name\n\n    def _transform_item(self, item: dict) -> dict:\n        if self._map_name_path_to_name:\n            # {\"name_path: \"Class/myMethod\"} -> {\"name: \"myMethod\"}\n            new_item = dict(item)\n            if \"name_path\" in item:\n                name_path = new_item.pop(\"name_path\")\n                new_item[\"name\"] = name_path.split(\"/\")[-1]\n            return super()._transform_item(new_item)\n        else:\n            return super()._transform_item(item)\n"
  },
  {
    "path": "src/serena/task_executor.py",
    "content": "import concurrent.futures\nimport threading\nimport time\nfrom collections.abc import Callable\nfrom concurrent.futures import Future\nfrom dataclasses import dataclass\nfrom threading import Thread\nfrom typing import Generic, TypeVar\n\nfrom sensai.util import logging\nfrom sensai.util.logging import LogTime\nfrom sensai.util.string import ToStringMixin\n\nlog = logging.getLogger(__name__)\nT = TypeVar(\"T\")\n\n\nclass TaskExecutor:\n    def __init__(self, name: str):\n        self._task_executor_lock = threading.Lock()\n        self._task_executor_queue: list[TaskExecutor.Task] = []\n        self._task_executor_thread = Thread(target=self._process_task_queue, name=name, daemon=True)\n        self._task_executor_thread.start()\n        self._task_executor_task_index = 1\n        self._task_executor_current_task: TaskExecutor.Task | None = None\n        self._task_executor_last_executed_task_info: TaskExecutor.TaskInfo | None = None\n\n    class Task(ToStringMixin, Generic[T]):\n        def __init__(self, function: Callable[[], T], name: str, logged: bool = True, timeout: float | None = None):\n            \"\"\"\n            :param function: the function representing the task to execute\n            :param name: the name of the task\n            :param logged: whether to log management of the task; if False, only errors will be logged\n            :param timeout: the maximum time to wait for task completion in seconds, or None to wait indefinitely\n            \"\"\"\n            self.name = name\n            self.future: concurrent.futures.Future = concurrent.futures.Future()\n            self.logged = logged\n            self.timeout = timeout\n            self._function = function\n\n        def _tostring_includes(self) -> list[str]:\n            return [\"name\"]\n\n        def start(self) -> None:\n            \"\"\"\n            Executes the task in a separate thread, setting the result or exception on the future.\n            \"\"\"\n\n            def run_task() -> None:\n                try:\n                    if self.future.done():\n                        if self.logged:\n                            log.info(f\"Task {self.name} was already completed/cancelled; skipping execution\")\n                        return\n                    with LogTime(self.name, logger=log, enabled=self.logged):\n                        result = self._function()\n                        if not self.future.done():\n                            self.future.set_result(result)\n                except Exception as e:\n                    if not self.future.done():\n                        log.error(f\"Error during execution of {self.name}: {e}\", exc_info=e)\n                        self.future.set_exception(e)\n\n            thread = Thread(target=run_task, name=self.name)\n            thread.start()\n\n        def is_done(self) -> bool:\n            \"\"\"\n            :return: whether the task has completed (either successfully, with failure, or via cancellation)\n            \"\"\"\n            return self.future.done()\n\n        def result(self, timeout: float | None = None) -> T:\n            \"\"\"\n            Blocks until the task is done or the timeout is reached, and returns the result.\n            If an exception occurred during task execution, it is raised here.\n            If the timeout is reached, a TimeoutError is raised (but the task is not cancelled).\n            If the task is cancelled, a CancelledError is raised.\n\n            :param timeout: the maximum time to wait in seconds; if None, use the task's own timeout\n                (which may be None to wait indefinitely)\n            :return: True if the task is done, False if the timeout was reached\n            \"\"\"\n            return self.future.result(timeout=timeout)\n\n        def cancel(self) -> None:\n            \"\"\"\n            Cancels the task. If it has not yet started, it will not be executed.\n            If it has already started, its future will be marked as cancelled and will raise a CancelledError\n            when its result is requested.\n            \"\"\"\n            self.future.cancel()\n\n        def wait_until_done(self, timeout: float | None = None) -> None:\n            \"\"\"\n            Waits until the task is done or the timeout is reached.\n            The task is done if it either completed successfully, failed with an exception, or was cancelled.\n\n            :param timeout: the maximum time to wait in seconds; if None, use the task's own timeout\n                (which may be None to wait indefinitely)\n            \"\"\"\n            try:\n                self.future.result(timeout=timeout)\n            except:\n                pass\n\n    def _process_task_queue(self) -> None:\n        while True:\n            # obtain task from the queue\n            task: TaskExecutor.Task | None = None\n            with self._task_executor_lock:\n                if len(self._task_executor_queue) > 0:\n                    task = self._task_executor_queue.pop(0)\n            if task is None:\n                time.sleep(0.1)\n                continue\n\n            # start task execution asynchronously\n            with self._task_executor_lock:\n                self._task_executor_current_task = task\n            if task.logged:\n                log.info(\"Starting execution of %s\", task.name)\n            task.start()\n\n            # wait for task completion\n            task.wait_until_done(timeout=task.timeout)\n            with self._task_executor_lock:\n                self._task_executor_current_task = None\n                if task.logged:\n                    self._task_executor_last_executed_task_info = self.TaskInfo.from_task(task, is_running=False)\n\n    @dataclass\n    class TaskInfo:\n        name: str\n        is_running: bool\n        future: Future\n        \"\"\"\n        future for accessing the task's result\n        \"\"\"\n        task_id: int\n        \"\"\"\n        unique identifier of the task\n        \"\"\"\n        logged: bool\n\n        def finished_successfully(self) -> bool:\n            return self.future.done() and not self.future.cancelled() and self.future.exception() is None\n\n        @staticmethod\n        def from_task(task: \"TaskExecutor.Task\", is_running: bool) -> \"TaskExecutor.TaskInfo\":\n            return TaskExecutor.TaskInfo(name=task.name, is_running=is_running, future=task.future, task_id=id(task), logged=task.logged)\n\n        def cancel(self) -> None:\n            self.future.cancel()\n\n    def get_current_tasks(self) -> list[TaskInfo]:\n        \"\"\"\n        Gets the list of tasks currently running or queued for execution.\n        The function returns a list of thread-safe TaskInfo objects (specifically created for the caller).\n\n        :return: the list of tasks in the execution order (running task first)\n        \"\"\"\n        tasks = []\n        with self._task_executor_lock:\n            if self._task_executor_current_task is not None:\n                tasks.append(self.TaskInfo.from_task(self._task_executor_current_task, True))\n            for task in self._task_executor_queue:\n                if not task.is_done():\n                    tasks.append(self.TaskInfo.from_task(task, False))\n        return tasks\n\n    def issue_task(self, task: Callable[[], T], name: str | None = None, logged: bool = True, timeout: float | None = None) -> Task[T]:\n        \"\"\"\n        Issue a task to the executor for asynchronous execution.\n        It is ensured that tasks are executed in the order they are issued, one after another.\n\n        :param task: the task to execute\n        :param name: the name of the task for logging purposes; if None, use the task function's name\n        :param logged: whether to log management of the task; if False, only errors will be logged\n        :param timeout: the maximum time to wait for task completion in seconds, or None to wait indefinitely\n        :return: the task object, through which the task's future result can be accessed\n        \"\"\"\n        with self._task_executor_lock:\n            if logged:\n                task_prefix_name = f\"Task-{self._task_executor_task_index}\"\n                self._task_executor_task_index += 1\n            else:\n                task_prefix_name = \"BackgroundTask\"\n            task_name = f\"{task_prefix_name}:{name or task.__name__}\"\n            if logged:\n                log.info(f\"Scheduling {task_name}\")\n            task_obj = self.Task(function=task, name=task_name, logged=logged, timeout=timeout)\n            self._task_executor_queue.append(task_obj)\n            return task_obj\n\n    def execute_task(self, task: Callable[[], T], name: str | None = None, logged: bool = True, timeout: float | None = None) -> T:\n        \"\"\"\n        Executes the given task synchronously via the agent's task executor.\n        This is useful for tasks that need to be executed immediately and whose results are needed right away.\n\n        :param task: the task to execute\n        :param name: the name of the task for logging purposes; if None, use the task function's name\n        :param logged: whether to log management of the task; if False, only errors will be logged\n        :param timeout: the maximum time to wait for task completion in seconds, or None to wait indefinitely\n        :return: the result of the task execution\n        \"\"\"\n        task_obj = self.issue_task(task, name=name, logged=logged, timeout=timeout)\n        return task_obj.result()\n\n    def get_last_executed_task(self) -> TaskInfo | None:\n        \"\"\"\n        Gets information about the last executed task.\n\n        :return: TaskInfo of the last executed task, or None if no task has been executed yet.\n        \"\"\"\n        with self._task_executor_lock:\n            return self._task_executor_last_executed_task_info\n"
  },
  {
    "path": "src/serena/tools/__init__.py",
    "content": "# ruff: noqa\nfrom .tools_base import *\nfrom .file_tools import *\nfrom .symbol_tools import *\nfrom .memory_tools import *\nfrom .cmd_tools import *\nfrom .config_tools import *\nfrom .workflow_tools import *\nfrom .jetbrains_tools import *\nfrom .query_project_tools import *\n"
  },
  {
    "path": "src/serena/tools/cmd_tools.py",
    "content": "\"\"\"\nTools supporting the execution of (external) commands\n\"\"\"\n\nimport os.path\n\nfrom serena.tools import Tool, ToolMarkerCanEdit\nfrom serena.util.shell import execute_shell_command\n\n\nclass ExecuteShellCommandTool(Tool, ToolMarkerCanEdit):\n    \"\"\"\n    Executes a shell command.\n    \"\"\"\n\n    def apply(\n        self,\n        command: str,\n        cwd: str | None = None,\n        capture_stderr: bool = True,\n        max_answer_chars: int = -1,\n    ) -> str:\n        \"\"\"\n        Execute a shell command and return its output. If there is a memory about suggested commands, read that first.\n        Never execute unsafe shell commands!\n        IMPORTANT: Do not use this tool to start\n          * long-running processes (e.g. servers) that are not intended to terminate quickly,\n          * processes that require user interaction.\n\n        :param command: the shell command to execute\n        :param cwd: the working directory to execute the command in. If None, the project root will be used.\n        :param capture_stderr: whether to capture and return stderr output\n        :param max_answer_chars: if the output is longer than this number of characters,\n            no content will be returned. -1 means using the default value, don't adjust unless there is no other way to get the content\n            required for the task.\n        :return: a JSON object containing the command's stdout and optionally stderr output\n        \"\"\"\n        if cwd is None:\n            _cwd = self.get_project_root()\n        else:\n            if os.path.isabs(cwd):\n                _cwd = cwd\n            else:\n                _cwd = os.path.join(self.get_project_root(), cwd)\n                if not os.path.isdir(_cwd):\n                    raise FileNotFoundError(\n                        f\"Specified a relative working directory ({cwd}), but the resulting path is not a directory: {_cwd}\"\n                    )\n\n        result = execute_shell_command(command, cwd=_cwd, capture_stderr=capture_stderr)\n        result = result.json()\n        return self._limit_length(result, max_answer_chars)\n"
  },
  {
    "path": "src/serena/tools/config_tools.py",
    "content": "from serena.tools import Tool, ToolMarkerDoesNotRequireActiveProject, ToolMarkerOptional\n\n\nclass OpenDashboardTool(Tool, ToolMarkerOptional, ToolMarkerDoesNotRequireActiveProject):\n    \"\"\"\n    Opens the Serena web dashboard in the default web browser.\n    The dashboard provides logs, session information, and tool usage statistics.\n    \"\"\"\n\n    def apply(self) -> str:\n        \"\"\"\n        Opens the Serena web dashboard in the default web browser.\n        \"\"\"\n        if self.agent.open_dashboard():\n            return f\"Serena web dashboard has been opened in the user's default web browser: {self.agent.get_dashboard_url()}\"\n        else:\n            return f\"Serena web dashboard could not be opened automatically; tell the user to open it via {self.agent.get_dashboard_url()}\"\n\n\nclass ActivateProjectTool(Tool, ToolMarkerDoesNotRequireActiveProject):\n    \"\"\"\n    Activates a project based on the project name or path.\n    \"\"\"\n\n    def apply(self, project: str) -> str:\n        \"\"\"\n        Activates the project with the given name or path.\n\n        :param project: the name of a registered project to activate or a path to a project directory\n        \"\"\"\n        active_project = self.agent.activate_project_from_path_or_name(project)\n        result = active_project.get_activation_message()\n        result += \"\\nIMPORTANT: If you have not yet read the 'Serena Instructions Manual', do it now before continuing!\"\n        return result\n\n\nclass RemoveProjectTool(Tool, ToolMarkerDoesNotRequireActiveProject, ToolMarkerOptional):\n    \"\"\"\n    Removes a project from the Serena configuration.\n    \"\"\"\n\n    def apply(self, project_name: str) -> str:\n        \"\"\"\n        Removes a project from the Serena configuration.\n\n        :param project_name: Name of the project to remove\n        \"\"\"\n        self.agent.serena_config.remove_project(project_name)\n        return f\"Successfully removed project '{project_name}' from configuration.\"\n\n\nclass SwitchModesTool(Tool, ToolMarkerOptional):\n    \"\"\"\n    Activates modes by providing a list of their names\n    \"\"\"\n\n    def apply(self, modes: list[str]) -> str:\n        \"\"\"\n        Activates the desired modes, like [\"editing\", \"interactive\"] or [\"planning\", \"one-shot\"]\n\n        :param modes: the names of the modes to activate\n        \"\"\"\n        self.agent.set_modes(modes)\n\n        # Inform the Agent about the activated modes and the currently active tools\n        mode_instances = self.agent.get_active_modes()\n        result_str = f\"Active modes: {', '.join([mode.name for mode in mode_instances])}\" + \"\\n\"\n        result_str += \"\\n\".join([mode_instance.prompt for mode_instance in mode_instances]) + \"\\n\"\n        result_str += f\"Currently active tools: {', '.join(self.agent.get_active_tool_names())}\"\n        return result_str\n\n\nclass GetCurrentConfigTool(Tool):\n    \"\"\"\n    Prints the current configuration of the agent, including the active and available projects, tools, contexts, and modes.\n    \"\"\"\n\n    def apply(self) -> str:\n        \"\"\"\n        Print the current configuration of the agent, including the active and available projects, tools, contexts, and modes.\n        \"\"\"\n        return self.agent.get_current_config_overview()\n"
  },
  {
    "path": "src/serena/tools/file_tools.py",
    "content": "\"\"\"\nFile and file system-related tools, specifically for\n  * listing directory contents\n  * reading files\n  * creating files\n  * editing at the file level\n\"\"\"\n\nimport os\nfrom collections import defaultdict\nfrom fnmatch import fnmatch\nfrom pathlib import Path\nfrom typing import Literal\n\nfrom serena.tools import SUCCESS_RESULT, EditedFileContext, Tool, ToolMarkerCanEdit, ToolMarkerOptional\nfrom serena.util.file_system import scan_directory\nfrom serena.util.text_utils import ContentReplacer, search_files\n\n\nclass ReadFileTool(Tool):\n    \"\"\"\n    Reads a file within the project directory.\n    \"\"\"\n\n    def apply(self, relative_path: str, start_line: int = 0, end_line: int | None = None, max_answer_chars: int = -1) -> str:\n        \"\"\"\n        Reads the given file or a chunk of it. Generally, symbolic operations\n        like find_symbol or find_referencing_symbols should be preferred if you know which symbols you are looking for.\n\n        :param relative_path: the relative path to the file to read\n        :param start_line: the 0-based index of the first line to be retrieved.\n        :param end_line: the 0-based index of the last line to be retrieved (inclusive). If None, read until the end of the file.\n        :param max_answer_chars: if the file (chunk) is longer than this number of characters,\n            no content will be returned. Don't adjust unless there is really no other way to get the content\n            required for the task.\n        :return: the full text of the file at the given relative path\n        \"\"\"\n        self.project.validate_relative_path(relative_path, require_not_ignored=True)\n\n        result = self.project.read_file(relative_path)\n        result_lines = result.splitlines()\n        if end_line is None:\n            result_lines = result_lines[start_line:]\n        else:\n            result_lines = result_lines[start_line : end_line + 1]\n        result = \"\\n\".join(result_lines)\n\n        return self._limit_length(result, max_answer_chars)\n\n\nclass CreateTextFileTool(Tool, ToolMarkerCanEdit):\n    \"\"\"\n    Creates/overwrites a file in the project directory.\n    \"\"\"\n\n    def apply(self, relative_path: str, content: str) -> str:\n        \"\"\"\n        Write a new file or overwrite an existing file.\n\n        :param relative_path: the relative path to the file to create\n        :param content: the (appropriately encoded) content to write to the file\n        :return: a message indicating success or failure\n        \"\"\"\n        project_root = self.get_project_root()\n        abs_path = (Path(project_root) / relative_path).resolve()\n        will_overwrite_existing = abs_path.exists()\n\n        if will_overwrite_existing:\n            self.project.validate_relative_path(relative_path, require_not_ignored=True)\n        else:\n            assert abs_path.is_relative_to(\n                self.get_project_root()\n            ), f\"Cannot create file outside of the project directory, got {relative_path=}\"\n\n        abs_path.parent.mkdir(parents=True, exist_ok=True)\n        abs_path.write_text(content, encoding=self.project.project_config.encoding, newline=self.project.line_ending.newline_str)\n        answer = f\"File created: {relative_path}.\"\n        if will_overwrite_existing:\n            answer += \" Overwrote existing file.\"\n        return answer\n\n\nclass ListDirTool(Tool):\n    \"\"\"\n    Lists files and directories in the given directory (optionally with recursion).\n    \"\"\"\n\n    def apply(self, relative_path: str, recursive: bool, skip_ignored_files: bool = False, max_answer_chars: int = -1) -> str:\n        \"\"\"\n        Lists files and directories in the given directory (optionally with recursion).\n\n        :param relative_path: the relative path to the directory to list; pass \".\" to scan the project root\n        :param recursive: whether to scan subdirectories recursively\n        :param skip_ignored_files: whether to skip files and directories that are ignored\n        :param max_answer_chars: if the output is longer than this number of characters,\n            no content will be returned. -1 means the default value from the config will be used.\n            Don't adjust unless there is really no other way to get the content required for the task.\n        :return: a JSON object with the names of directories and files within the given directory\n        \"\"\"\n        # Check if the directory exists before validation\n        if not self.project.relative_path_exists(relative_path):\n            error_info = {\n                \"error\": f\"Directory not found: {relative_path}\",\n                \"project_root\": self.get_project_root(),\n                \"hint\": \"Check if the path is correct relative to the project root\",\n            }\n            return self._to_json(error_info)\n\n        self.project.validate_relative_path(relative_path, require_not_ignored=skip_ignored_files)\n\n        dirs, files = scan_directory(\n            os.path.join(self.get_project_root(), relative_path),\n            relative_to=self.get_project_root(),\n            recursive=recursive,\n            is_ignored_dir=self.project.is_ignored_path if skip_ignored_files else None,\n            is_ignored_file=self.project.is_ignored_path if skip_ignored_files else None,\n        )\n\n        result = self._to_json({\"dirs\": dirs, \"files\": files})\n        return self._limit_length(result, max_answer_chars)\n\n\nclass FindFileTool(Tool):\n    \"\"\"\n    Finds files in the given relative paths\n    \"\"\"\n\n    def apply(self, file_mask: str, relative_path: str) -> str:\n        \"\"\"\n        Finds non-gitignored files matching the given file mask within the given relative path\n\n        :param file_mask: the filename or file mask (using the wildcards * or ?) to search for\n        :param relative_path: the relative path to the directory to search in; pass \".\" to scan the project root\n        :return: a JSON object with the list of matching files\n        \"\"\"\n        self.project.validate_relative_path(relative_path, require_not_ignored=True)\n\n        dir_to_scan = os.path.join(self.get_project_root(), relative_path)\n\n        # find the files by ignoring everything that doesn't match\n        def is_ignored_file(abs_path: str) -> bool:\n            if self.project.is_ignored_path(abs_path):\n                return True\n            filename = os.path.basename(abs_path)\n            return not fnmatch(filename, file_mask)\n\n        _dirs, files = scan_directory(\n            path=dir_to_scan,\n            recursive=True,\n            is_ignored_dir=self.project.is_ignored_path,\n            is_ignored_file=is_ignored_file,\n            relative_to=self.get_project_root(),\n        )\n\n        result = self._to_json({\"files\": files})\n        return result\n\n\nclass ReplaceContentTool(Tool, ToolMarkerCanEdit):\n    \"\"\"\n    Replaces content in a file (optionally using regular expressions).\n    \"\"\"\n\n    def apply(\n        self,\n        relative_path: str,\n        needle: str,\n        repl: str,\n        mode: Literal[\"literal\", \"regex\"],\n        allow_multiple_occurrences: bool = False,\n    ) -> str:\n        r\"\"\"\n        Replaces one or more occurrences of a given pattern in a file with new content.\n\n        This is the preferred way to replace content in a file whenever the symbol-level\n        tools are not appropriate.\n\n        VERY IMPORTANT: The \"regex\" mode allows very large sections of code to be replaced without fully quoting them!\n        Use a regex of the form \"beginning.*?end-of-text-to-be-replaced\" to be faster and more economical!\n        ALWAYS try to use wildcards to avoid specifying the exact content to be replaced,\n        especially if it spans several lines. Note that you cannot make mistakes, because if the regex should match\n        multiple occurrences while you disabled `allow_multiple_occurrences`, an error will be returned, and you can retry\n        with a revised regex.\n        Therefore, using regex mode with suitable wildcards is usually the best choice!\n\n        :param relative_path: the relative path to the file\n        :param needle: the string or regex pattern to search for.\n            If `mode` is \"literal\", this string will be matched exactly.\n            If `mode` is \"regex\", this string will be treated as a regular expression (syntax of Python's `re` module,\n            with flags DOTALL and MULTILINE enabled).\n        :param repl: the replacement string (verbatim).\n            If mode is \"regex\", the string can contain backreferences to matched groups in the needle regex,\n            specified using the syntax $!1, $!2, etc. for groups 1, 2, etc.\n        :param mode: either \"literal\" or \"regex\", specifying how the `needle` parameter is to be interpreted.\n        :param allow_multiple_occurrences: whether to allow matching and replacing multiple occurrences.\n            If false and multiple occurrences are found, an error will be returned\n        \"\"\"\n        return self.replace_content(\n            relative_path, needle, repl, mode=mode, allow_multiple_occurrences=allow_multiple_occurrences, require_not_ignored=True\n        )\n\n    def replace_content(\n        self,\n        relative_path: str,\n        needle: str,\n        repl: str,\n        mode: Literal[\"literal\", \"regex\"],\n        allow_multiple_occurrences: bool = False,\n        require_not_ignored: bool = True,\n    ) -> str:\n        \"\"\"\n        Performs the replacement, with additional options not exposed in the tool.\n        This function can be used internally by other tools.\n        \"\"\"\n        self.project.validate_relative_path(relative_path, require_not_ignored=require_not_ignored)\n        with EditedFileContext(relative_path, self.create_code_editor()) as context:\n            original_content = context.get_original_content()\n            replacer = ContentReplacer(mode=mode, allow_multiple_occurrences=allow_multiple_occurrences)\n            updated_content = replacer.replace(original_content, needle, repl)\n            context.set_updated_content(updated_content)\n        return SUCCESS_RESULT\n\n\nclass DeleteLinesTool(Tool, ToolMarkerCanEdit, ToolMarkerOptional):\n    \"\"\"\n    Deletes a range of lines within a file.\n    \"\"\"\n\n    def apply(\n        self,\n        relative_path: str,\n        start_line: int,\n        end_line: int,\n    ) -> str:\n        \"\"\"\n        Deletes the given lines in the file.\n        Requires that the same range of lines was previously read using the `read_file` tool to verify correctness\n        of the operation.\n\n        :param relative_path: the relative path to the file\n        :param start_line: the 0-based index of the first line to be deleted\n        :param end_line: the 0-based index of the last line to be deleted\n        \"\"\"\n        code_editor = self.create_code_editor()\n        code_editor.delete_lines(relative_path, start_line, end_line)\n        return SUCCESS_RESULT\n\n\nclass ReplaceLinesTool(Tool, ToolMarkerCanEdit, ToolMarkerOptional):\n    \"\"\"\n    Replaces a range of lines within a file with new content.\n    \"\"\"\n\n    def apply(\n        self,\n        relative_path: str,\n        start_line: int,\n        end_line: int,\n        content: str,\n    ) -> str:\n        \"\"\"\n        Replaces the given range of lines in the given file.\n        Requires that the same range of lines was previously read using the `read_file` tool to verify correctness\n        of the operation.\n\n        :param relative_path: the relative path to the file\n        :param start_line: the 0-based index of the first line to be deleted\n        :param end_line: the 0-based index of the last line to be deleted\n        :param content: the content to insert\n        \"\"\"\n        if not content.endswith(\"\\n\"):\n            content += \"\\n\"\n        result = self.agent.get_tool(DeleteLinesTool).apply(relative_path, start_line, end_line)\n        if result != SUCCESS_RESULT:\n            return result\n        self.agent.get_tool(InsertAtLineTool).apply(relative_path, start_line, content)\n        return SUCCESS_RESULT\n\n\nclass InsertAtLineTool(Tool, ToolMarkerCanEdit, ToolMarkerOptional):\n    \"\"\"\n    Inserts content at a given line in a file.\n    \"\"\"\n\n    def apply(\n        self,\n        relative_path: str,\n        line: int,\n        content: str,\n    ) -> str:\n        \"\"\"\n        Inserts the given content at the given line in the file, pushing existing content of the line down.\n        In general, symbolic insert operations like insert_after_symbol or insert_before_symbol should be preferred if you know which\n        symbol you are looking for.\n        However, this can also be useful for small targeted edits of the body of a longer symbol (without replacing the entire body).\n\n        :param relative_path: the relative path to the file\n        :param line: the 0-based index of the line to insert content at\n        :param content: the content to be inserted\n        \"\"\"\n        if not content.endswith(\"\\n\"):\n            content += \"\\n\"\n        code_editor = self.create_code_editor()\n        code_editor.insert_at_line(relative_path, line, content)\n        return SUCCESS_RESULT\n\n\nclass SearchForPatternTool(Tool):\n    \"\"\"\n    Performs a search for a pattern in the project.\n    \"\"\"\n\n    def apply(\n        self,\n        substring_pattern: str,\n        context_lines_before: int = 0,\n        context_lines_after: int = 0,\n        paths_include_glob: str = \"\",\n        paths_exclude_glob: str = \"\",\n        relative_path: str = \"\",\n        restrict_search_to_code_files: bool = False,\n        max_answer_chars: int = -1,\n    ) -> str:\n        \"\"\"\n        Offers a flexible search for arbitrary patterns in the codebase, including the\n        possibility to search in non-code files.\n        Generally, symbolic operations like find_symbol or find_referencing_symbols\n        should be preferred if you know which symbols you are looking for.\n\n        Pattern Matching Logic:\n            For each match, the returned result will contain the full lines where the\n            substring pattern is found, as well as optionally some lines before and after it. The pattern will be compiled with\n            DOTALL, meaning that the dot will match all characters including newlines.\n            This also means that it never makes sense to have .* at the beginning or end of the pattern,\n            but it may make sense to have it in the middle for complex patterns.\n            If a pattern matches multiple lines, all those lines will be part of the match.\n            Be careful to not use greedy quantifiers unnecessarily, it is usually better to use non-greedy quantifiers like .*? to avoid\n            matching too much content.\n\n        File Selection Logic:\n            The files in which the search is performed can be restricted very flexibly.\n            Using `restrict_search_to_code_files` is useful if you are only interested in code symbols (i.e., those\n            symbols that can be manipulated with symbolic tools like find_symbol).\n            You can also restrict the search to a specific file or directory,\n            and provide glob patterns to include or exclude certain files on top of that.\n            The globs are matched against relative file paths from the project root (not to the `relative_path` parameter that\n            is used to further restrict the search).\n            Smartly combining the various restrictions allows you to perform very targeted searches.\n\n\n        :param substring_pattern: Regular expression for a substring pattern to search for\n        :param context_lines_before: Number of lines of context to include before each match\n        :param context_lines_after: Number of lines of context to include after each match\n        :param paths_include_glob: optional glob pattern specifying files to include in the search.\n            Matches against relative file paths from the project root (e.g., \"*.py\", \"src/**/*.ts\").\n            Supports standard glob patterns (*, ?, [seq], **, etc.) and brace expansion {a,b,c}.\n            Only matches files, not directories. If left empty, all non-ignored files will be included.\n        :param paths_exclude_glob: optional glob pattern specifying files to exclude from the search.\n            Matches against relative file paths from the project root (e.g., \"*test*\", \"**/*_generated.py\").\n            Supports standard glob patterns (*, ?, [seq], **, etc.) and brace expansion {a,b,c}.\n            Takes precedence over paths_include_glob. Only matches files, not directories. If left empty, no files are excluded.\n        :param relative_path: only subpaths of this path (relative to the repo root) will be analyzed. If a path to a single\n            file is passed, only that will be searched. The path must exist, otherwise a `FileNotFoundError` is raised.\n        :param max_answer_chars: if the output is longer than this number of characters,\n            no content will be returned.\n            -1 means the default value from the config will be used.\n            Don't adjust unless there is really no other way to get the content\n            required for the task. Instead, if the output is too long, you should\n            make a stricter query.\n        :param restrict_search_to_code_files: whether to restrict the search to only those files where\n            analyzed code symbols can be found. Otherwise, will search all non-ignored files.\n            Set this to True if your search is only meant to discover code that can be manipulated with symbolic tools.\n            For example, for finding classes or methods from a name pattern.\n            Setting to False is a better choice if you also want to search in non-code files, like in html or yaml files,\n            which is why it is the default.\n        :return: A mapping of file paths to lists of matched consecutive lines.\n        \"\"\"\n        abs_path = os.path.join(self.get_project_root(), relative_path)\n        if not os.path.exists(abs_path):\n            raise FileNotFoundError(f\"Relative path {relative_path} does not exist.\")\n\n        if restrict_search_to_code_files:\n            matches = self.project.search_source_files_for_pattern(\n                pattern=substring_pattern,\n                relative_path=relative_path,\n                context_lines_before=context_lines_before,\n                context_lines_after=context_lines_after,\n                paths_include_glob=paths_include_glob.strip(),\n                paths_exclude_glob=paths_exclude_glob.strip(),\n            )\n        else:\n            if os.path.isfile(abs_path):\n                rel_paths_to_search = [relative_path]\n            else:\n                _dirs, rel_paths_to_search = scan_directory(\n                    path=abs_path,\n                    recursive=True,\n                    is_ignored_dir=self.project.is_ignored_path,\n                    is_ignored_file=self.project.is_ignored_path,\n                    relative_to=self.get_project_root(),\n                )\n            # TODO (maybe): not super efficient to walk through the files again and filter if glob patterns are provided\n            #   but it probably never matters and this version required no further refactoring\n            matches = search_files(\n                rel_paths_to_search,\n                substring_pattern,\n                file_reader=self.project.read_file,\n                root_path=self.get_project_root(),\n                paths_include_glob=paths_include_glob,\n                paths_exclude_glob=paths_exclude_glob,\n            )\n        # group matches by file\n        file_to_matches: dict[str, list[str]] = defaultdict(list)\n        for match in matches:\n            assert match.source_file_path is not None\n            file_to_matches[match.source_file_path].append(match.to_display_string())\n        result = self._to_json(file_to_matches)\n        return self._limit_length(result, max_answer_chars)\n"
  },
  {
    "path": "src/serena/tools/jetbrains_tools.py",
    "content": "import logging\nfrom typing import Any, Literal\n\nimport serena.jetbrains.jetbrains_types as jb\nfrom serena.jetbrains.jetbrains_plugin_client import JetBrainsPluginClient\nfrom serena.symbol import JetBrainsSymbolDictGrouper\nfrom serena.tools import Tool, ToolMarkerOptional, ToolMarkerSymbolicRead\n\nlog = logging.getLogger(__name__)\n\n\nclass JetBrainsFindSymbolTool(Tool, ToolMarkerSymbolicRead, ToolMarkerOptional):\n    \"\"\"\n    Performs a global (or local) search for symbols using the JetBrains backend\n    \"\"\"\n\n    def apply(\n        self,\n        name_path_pattern: str,\n        depth: int = 0,\n        relative_path: str | None = None,\n        include_body: bool = False,\n        include_info: bool = False,\n        search_deps: bool = False,\n        max_answer_chars: int = -1,\n    ) -> str:\n        \"\"\"\n        Retrieves information on all symbols/code entities (classes, methods, etc.) based on the given name path pattern.\n        The returned symbol information can be used for edits or further queries.\n        Specify `depth > 0` to retrieve children (e.g., methods of a class).\n        Important: through `search_deps=True` dependencies can be searched, which\n        should be preferred to web search or other less sophisticated approaches to analyzing dependencies.\n\n        A name path is a path in the symbol tree *within a source file*.\n        For example, the method `my_method` defined in class `MyClass` would have the name path `MyClass/my_method`.\n        If a symbol is overloaded (e.g., in Java), a 0-based index is appended (e.g. \"MyClass/my_method[0]\") to\n        uniquely identify it.\n\n        To search for a symbol, you provide a name path pattern that is used to match against name paths.\n        It can be\n         * a simple name (e.g. \"method\"), which will match any symbol with that name\n         * a relative path like \"class/method\", which will match any symbol with that name path suffix\n         * an absolute name path \"/class/method\" (absolute name path), which requires an exact match of the full name path within the source file.\n        Append an index `[i]` to match a specific overload only, e.g. \"MyClass/my_method[1]\".\n\n        :param name_path_pattern: the name path matching pattern (see above)\n        :param depth: depth up to which descendants shall be retrieved (e.g. use 1 to also retrieve immediate children;\n            for the case where the symbol is a class, this will return its methods).\n            Default 0.\n        :param relative_path: Optional. Restrict search to this file or directory. If None, searches entire codebase.\n            If a directory is passed, the search will be restricted to the files in that directory.\n            If a file is passed, the search will be restricted to that file.\n            If you have some knowledge about the codebase, you should use this parameter, as it will significantly\n            speed up the search as well as reduce the number of results.\n        :param include_body: If True, include the symbol's source code. Use judiciously.\n        :param include_info: whether to include additional info (hover-like, typically including docstring and signature),\n            about the symbol (ignored if include_body is True).\n            Default False; info is never included for child symbols and is not included when body is requested.\n        :param search_deps: If True, also search in project dependencies (e.g., libraries).\n        :param max_answer_chars: max characters for the JSON result. If exceeded, no content is returned.\n            -1 means the default value from the config will be used.\n        :return: JSON string: a list of symbols (with locations) matching the name.\n        \"\"\"\n        if relative_path == \".\":\n            relative_path = None\n        with JetBrainsPluginClient.from_project(self.project) as client:\n            if include_body:\n                include_quick_info = False\n                include_documentation = False\n            else:\n                if include_info:\n                    include_documentation = True\n                    include_quick_info = False\n                else:\n                    # If no additional information is requested, we still include the quick info (type signature)\n                    include_documentation = False\n                    include_quick_info = True\n            response_dict = client.find_symbol(\n                name_path=name_path_pattern,\n                relative_path=relative_path,\n                depth=depth,\n                include_body=include_body,\n                include_documentation=include_documentation,\n                include_quick_info=include_quick_info,\n                search_deps=search_deps,\n            )\n            result = self._to_json(response_dict)\n        return self._limit_length(result, max_answer_chars)\n\n\nclass JetBrainsFindReferencingSymbolsTool(Tool, ToolMarkerSymbolicRead, ToolMarkerOptional):\n    \"\"\"\n    Finds symbols that reference the given symbol using the JetBrains backend\n    \"\"\"\n\n    symbol_dict_grouper = JetBrainsSymbolDictGrouper([\"relative_path\", \"type\"], [\"type\"], collapse_singleton=True)\n\n    # TODO: (maybe) - add content snippets showing the references like in LS based version?\n    def apply(\n        self,\n        name_path: str,\n        relative_path: str,\n        max_answer_chars: int = -1,\n    ) -> str:\n        \"\"\"\n        Finds symbols that reference the symbol at the given `name_path`.\n        The result will contain metadata about the referencing symbols.\n\n        :param name_path: name path of the symbol for which to find references; matching logic as described in find symbol tool.\n        :param relative_path: the relative path to the file containing the symbol for which to find references.\n            Note that here you can't pass a directory but must pass a file.\n        :param max_answer_chars: max characters for the JSON result. If exceeded, no content is returned. -1 means the\n            default value from the config will be used.\n        :return: a list of JSON objects with the symbols referencing the requested symbol\n        \"\"\"\n        with JetBrainsPluginClient.from_project(self.project) as client:\n            response_dict = client.find_references(\n                name_path=name_path,\n                relative_path=relative_path,\n                include_quick_info=False,\n            )\n        symbol_dicts = response_dict[\"symbols\"]\n        result = self.symbol_dict_grouper.group(symbol_dicts)\n        result_json = self._to_json(result)\n        return self._limit_length(result_json, max_answer_chars)\n\n\nclass JetBrainsGetSymbolsOverviewTool(Tool, ToolMarkerSymbolicRead, ToolMarkerOptional):\n    \"\"\"\n    Retrieves an overview of the top-level symbols within a specified file using the JetBrains backend\n    \"\"\"\n\n    USE_COMPACT_FORMAT = True\n    symbol_dict_grouper = JetBrainsSymbolDictGrouper([\"type\"], [\"type\"], collapse_singleton=True, map_name_path_to_name=True)\n\n    def apply(\n        self,\n        relative_path: str,\n        depth: int = 0,\n        max_answer_chars: int = -1,\n        include_file_documentation: bool = False,\n    ) -> str:\n        \"\"\"\n        Gets an overview of the top-level symbols in the given file.\n        Calling this is often a good idea before more targeted reading, searching or editing operations on the code symbols.\n        Before requesting a symbol overview, it is usually a good idea to narrow down the scope of the overview\n        by first understanding the basic directory structure of the repository that you can get from memories\n        or by using the `list_dir` and `find_file` tools (or similar).\n\n        :param relative_path: the relative path to the file to get the overview of\n        :param depth: depth up to which descendants shall be retrieved (e.g., use 1 to also retrieve immediate children).\n        :param max_answer_chars: max characters for the JSON result. If exceeded, no content is returned.\n            -1 means the default value from the config will be used.\n        :param include_file_documentation: whether to include the file's docstring. Default False.\n        :return: a JSON object containing the symbols grouped by kind in a compact format.\n        \"\"\"\n        with JetBrainsPluginClient.from_project(self.project) as client:\n            symbol_overview = client.get_symbols_overview(\n                relative_path=relative_path, depth=depth, include_file_documentation=include_file_documentation\n            )\n        if self.USE_COMPACT_FORMAT:\n            symbols = symbol_overview[\"symbols\"]\n            result: dict[str, Any] = {\"symbols\": self.symbol_dict_grouper.group(symbols)}\n            documentation = symbol_overview.pop(\"documentation\", None)\n            if documentation:\n                result[\"docstring\"] = documentation\n            json_result = self._to_json(result)\n        else:\n            json_result = self._to_json(symbol_overview)\n        return self._limit_length(json_result, max_answer_chars)\n\n\nclass JetBrainsTypeHierarchyTool(Tool, ToolMarkerSymbolicRead, ToolMarkerOptional):\n    \"\"\"\n    Retrieves the type hierarchy (supertypes and/or subtypes) of a symbol using the JetBrains backend\n    \"\"\"\n\n    @staticmethod\n    def _transform_hierarchy_nodes(nodes: list[jb.TypeHierarchyNodeDTO] | None) -> dict[str, list]:\n        \"\"\"\n        Transform a list of TypeHierarchyNode into a file-grouped compact format.\n\n        Returns a dict where keys are relative_paths and values are lists of either:\n        - \"SymbolNamePath\" (leaf node)\n        - {\"SymbolNamePath\": {nested_file_grouped_children}} (node with children)\n        \"\"\"\n        if not nodes:\n            return {}\n\n        result: dict[str, list] = {}\n\n        for node in nodes:\n            symbol = node[\"symbol\"]\n            name_path = symbol[\"name_path\"]\n            rel_path = symbol[\"relative_path\"]\n            children = node.get(\"children\", [])\n\n            if rel_path not in result:\n                result[rel_path] = []\n\n            if children:\n                # Node with children - recurse\n                nested = JetBrainsTypeHierarchyTool._transform_hierarchy_nodes(children)\n                result[rel_path].append({name_path: nested})\n            else:\n                # Leaf node\n                result[rel_path].append(name_path)\n\n        return result\n\n    def apply(\n        self,\n        name_path: str,\n        relative_path: str,\n        hierarchy_type: Literal[\"super\", \"sub\", \"both\"] = \"both\",\n        depth: int | None = 1,\n        max_answer_chars: int = -1,\n    ) -> str:\n        \"\"\"\n        Gets the type hierarchy of a symbol (supertypes, subtypes, or both).\n\n        :param name_path: name path of the symbol for which to get the type hierarchy.\n        :param relative_path: the relative path to the file containing the symbol.\n        :param hierarchy_type: which hierarchy to retrieve: \"super\" for parent classes/interfaces,\n            \"sub\" for subclasses/implementations, or \"both\" for both directions. Default is \"sub\".\n        :param depth: depth limit for hierarchy traversal (None or 0 for unlimited). Default is 1.\n        :param max_answer_chars: max characters for the JSON result. If exceeded, no content is returned.\n            -1 means the default value from the config will be used.\n        :return: Compact JSON with file-grouped hierarchy. Error string if not applicable.\n        \"\"\"\n        with JetBrainsPluginClient.from_project(self.project) as client:\n            subtypes = None\n            supertypes = None\n            levels_not_included = {}\n\n            if hierarchy_type in (\"super\", \"both\"):\n                supertypes_response = client.get_supertypes(\n                    name_path=name_path,\n                    relative_path=relative_path,\n                    depth=depth,\n                )\n                if \"num_levels_not_included\" in supertypes_response:\n                    levels_not_included[\"supertypes\"] = supertypes_response[\"num_levels_not_included\"]\n                supertypes = self._transform_hierarchy_nodes(supertypes_response.get(\"hierarchy\"))\n\n            if hierarchy_type in (\"sub\", \"both\"):\n                subtypes_response = client.get_subtypes(\n                    name_path=name_path,\n                    relative_path=relative_path,\n                    depth=depth,\n                )\n                if \"num_levels_not_included\" in subtypes_response:\n                    levels_not_included[\"subtypes\"] = subtypes_response[\"num_levels_not_included\"]\n                subtypes = self._transform_hierarchy_nodes(subtypes_response.get(\"hierarchy\"))\n\n            result_dict: dict[str, dict | list] = {}\n            if supertypes is not None:\n                result_dict[\"supertypes\"] = supertypes\n            if subtypes is not None:\n                result_dict[\"subtypes\"] = subtypes\n            if levels_not_included:\n                result_dict[\"levels_not_included\"] = levels_not_included\n\n            result = self._to_json(result_dict)\n        return self._limit_length(result, max_answer_chars)\n"
  },
  {
    "path": "src/serena/tools/memory_tools.py",
    "content": "from typing import Literal\n\nfrom serena.tools import Tool, ToolMarkerCanEdit\n\n\nclass WriteMemoryTool(Tool, ToolMarkerCanEdit):\n    \"\"\"\n    Write some information (utf-8-encoded) about this project that can be useful for future tasks to a memory in md format.\n    The memory name should be meaningful.\n    \"\"\"\n\n    def apply(self, memory_name: str, content: str, max_chars: int = -1) -> str:\n        \"\"\"\n        Write information (utf-8-encoded) about this project that can be useful for future tasks to a memory in md format.\n        The memory name should be meaningful and can include \"/\" to organize into topics (e.g., \"auth/login/logic\").\n        If explicitly instructed, use the \"global/\" prefix for writing a memory that is shared across projects\n        (e.g., \"global/java/style_guide\")\n\n        :param max_chars: the maximum number of characters to write. By default, determined by the config,\n            change only if instructed to do so.\n        \"\"\"\n        # NOTE: utf-8 encoding is configured in the MemoriesManager\n        if max_chars == -1:\n            max_chars = self.agent.serena_config.default_max_tool_answer_chars\n        if len(content) > max_chars:\n            raise ValueError(\n                f\"Content for {memory_name} is too long. Max length is {max_chars} characters. \" + \"Please make the content shorter.\"\n            )\n\n        return self.memories_manager.save_memory(memory_name, content, is_tool_context=True)\n\n\nclass ReadMemoryTool(Tool):\n    \"\"\"\n    Read the content of a memory file. This tool should only be used if the information\n    is relevant to the current task. You can infer whether the information\n    is relevant from the memory file name.\n    You should not read the same memory file multiple times in the same conversation.\n    \"\"\"\n\n    def apply(self, memory_name: str) -> str:\n        \"\"\"\n        Reads the contents of a memory. Should only be used if the information\n        is likely to be relevant to the current task, inferring relevance from the memory name.\n        \"\"\"\n        return self.memories_manager.load_memory(memory_name)\n\n\nclass ListMemoriesTool(Tool):\n    \"\"\"\n    List available memories. Any memory can be read using the `read_memory` tool.\n    \"\"\"\n\n    def apply(self, topic: str = \"\") -> str:\n        \"\"\"\n        Lists available memories, optionally filtered by topic.\n        \"\"\"\n        return self._to_json(self.memories_manager.list_memories(topic).to_dict())\n\n\nclass DeleteMemoryTool(Tool, ToolMarkerCanEdit):\n    \"\"\"\n    Delete a memory file. Should only happen if a user asks for it explicitly,\n    for example by saying that the information retrieved from a memory file is no longer correct\n    or no longer relevant for the project.\n    \"\"\"\n\n    def apply(self, memory_name: str) -> str:\n        \"\"\"\n        Delete a memory, only call if instructed explicitly or permission was granted by the user.\n        \"\"\"\n        return self.memories_manager.delete_memory(memory_name, is_tool_context=True)\n\n\nclass RenameMemoryTool(Tool, ToolMarkerCanEdit):\n    \"\"\"\n    Renames or moves a memory. Moving between project and global scope is supported\n    (e.g., renaming \"global/foo\" to \"bar\" moves it from global to project scope).\n    \"\"\"\n\n    def apply(self, old_name: str, new_name: str) -> str:\n        \"\"\"\n        Rename or move a memory, use \"/\" in the name to organize into topics.\n        The \"global\" topic should only be used if explicitly instructed.\n        \"\"\"\n        return self.memories_manager.move_memory(old_name, new_name, is_tool_context=True)\n\n\nclass EditMemoryTool(Tool, ToolMarkerCanEdit):\n    \"\"\"\n    Replaces content matching a regular expression in a memory.\n    \"\"\"\n\n    def apply(\n        self,\n        memory_name: str,\n        needle: str,\n        repl: str,\n        mode: Literal[\"literal\", \"regex\"],\n        allow_multiple_occurrences: bool = False,\n    ) -> str:\n        r\"\"\"\n        Replaces content matching a regular expression in a memory.\n\n        :param memory_name: the name of the memory\n        :param needle: the string or regex pattern to search for.\n            If `mode` is \"literal\", this string will be matched exactly.\n            If `mode` is \"regex\", this string will be treated as a regular expression (syntax of Python's `re` module,\n            with flags DOTALL and MULTILINE enabled).\n        :param repl: the replacement string (verbatim).\n        :param mode: either \"literal\" or \"regex\", specifying how the `needle` parameter is to be interpreted.\n        :param allow_multiple_occurrences: whether to allow matching and replacing multiple occurrences.\n            If false and multiple occurrences are found, an error will be returned.\n        \"\"\"\n        return self.memories_manager.edit_memory(memory_name, needle, repl, mode, allow_multiple_occurrences, is_tool_context=True)\n"
  },
  {
    "path": "src/serena/tools/query_project_tools.py",
    "content": "import json\n\nfrom serena.config.serena_config import LanguageBackend\nfrom serena.jetbrains.jetbrains_plugin_client import JetBrainsPluginClientManager\nfrom serena.project_server import ProjectServerClient\nfrom serena.tools import Tool, ToolMarkerDoesNotRequireActiveProject, ToolMarkerOptional\n\n\nclass ListQueryableProjectsTool(Tool, ToolMarkerOptional, ToolMarkerDoesNotRequireActiveProject):\n    \"\"\"\n    Tool for listing all projects that can be queried by the QueryProjectTool.\n    \"\"\"\n\n    def apply(self, symbol_access: bool = True) -> str:\n        \"\"\"\n        Lists available projects that can be queried with `query_project_tool`.\n\n        :param symbol_access: whether to return only projects for which symbol access is available. Default: true\n        \"\"\"\n        # determine relevant projects\n        registered_projects = self.agent.serena_config.projects\n        if symbol_access:\n            backend = self.agent.get_language_backend()\n            if backend.is_jetbrains():\n                # projects with open IDE instances can be queried\n                matched_clients = JetBrainsPluginClientManager().match_clients(registered_projects)\n                relevant_projects = [mc.registered_project for mc in matched_clients]\n            else:\n                # all projects can be queried via ProjectServer (which instantiates projects dynamically)\n                relevant_projects = registered_projects\n        else:\n            relevant_projects = registered_projects\n\n        # return project names, excluding the active project (if any)\n        project_names = [p.project_name for p in relevant_projects]\n        active_project = self.agent.get_active_project()\n        if active_project is not None:\n            project_names = [n for n in project_names if n != active_project.project_name]\n        return self._to_json(project_names)\n\n\nclass QueryProjectTool(Tool, ToolMarkerOptional, ToolMarkerDoesNotRequireActiveProject):\n    \"\"\"\n    Tool for querying external project information (i.e. information from projects other than the current one),\n    by executing a read-only tool.\n    \"\"\"\n\n    def apply(self, project_name: str, tool_name: str, tool_params_json: str) -> str:\n        \"\"\"\n        Queries a project by executing a read-only Serena tool. The tool will be executed in the context of the project.\n        Use this to query information from projects other than the activated project.\n\n        :param project_name: the name of the project to query\n        :param tool_name: the name of the tool to execute in the other project. The tool must be read-only.\n        :param tool_params_json: the parameters to pass to the tool, encoded as a JSON string\n        \"\"\"\n        tool = self.agent.get_tool_by_name(tool_name)\n        assert tool.is_active(), f\"Tool {tool_name} is not active.\"\n        assert tool.is_readonly(), f\"Tool {tool_name} is not read-only and cannot be executed in another project.\"\n        if self._is_project_server_required(tool):\n            client = ProjectServerClient()\n            return client.query_project(project_name, tool_name, tool_params_json)\n        else:\n            registered_project = self.agent.serena_config.get_registered_project(project_name)\n            assert registered_project is not None, f\"Project {project_name} is not registered and cannot be queried.\"\n            project = registered_project.get_project_instance(self.agent.serena_config)\n            with tool.agent.active_project_context(project):\n                return tool.apply(**json.loads(tool_params_json))  # type: ignore\n\n    def _is_project_server_required(self, tool: Tool) -> bool:\n        match self.agent.get_language_backend():\n            case LanguageBackend.JETBRAINS:\n                return False\n            case LanguageBackend.LSP:\n                # Note: As long as only read-only tools are considered, only symbolic tools require the project server.\n                #   But if we were to allow non-read-only tools, then tools using a CodeEditor also indirectly require language servers.\n                assert tool.is_readonly()\n                return tool.is_symbolic()\n            case _:\n                raise NotImplementedError\n"
  },
  {
    "path": "src/serena/tools/symbol_tools.py",
    "content": "\"\"\"\nLanguage server-related tools\n\"\"\"\n\nimport os\nfrom collections.abc import Sequence\n\nfrom serena.symbol import LanguageServerSymbol, LanguageServerSymbolDictGrouper\nfrom serena.tools import (\n    SUCCESS_RESULT,\n    Tool,\n    ToolMarkerSymbolicEdit,\n    ToolMarkerSymbolicRead,\n)\nfrom serena.tools.tools_base import ToolMarkerOptional\nfrom solidlsp.ls_types import SymbolKind\n\n\nclass RestartLanguageServerTool(Tool, ToolMarkerOptional):\n    \"\"\"Restarts the language server, may be necessary when edits not through Serena happen.\"\"\"\n\n    def apply(self) -> str:\n        \"\"\"Use this tool only on explicit user request or after confirmation.\n        It may be necessary to restart the language server if it hangs.\n        \"\"\"\n        self.agent.reset_language_server_manager()\n        return SUCCESS_RESULT\n\n\nclass GetSymbolsOverviewTool(Tool, ToolMarkerSymbolicRead):\n    \"\"\"\n    Gets an overview of the top-level symbols defined in a given file.\n    \"\"\"\n\n    symbol_dict_grouper = LanguageServerSymbolDictGrouper([\"kind\"], [\"kind\"], collapse_singleton=True)\n\n    def apply(self, relative_path: str, depth: int = 0, max_answer_chars: int = -1) -> str:\n        \"\"\"\n        Use this tool to get a high-level understanding of the code symbols in a file.\n        This should be the first tool to call when you want to understand a new file, unless you already know\n        what you are looking for.\n\n        :param relative_path: the relative path to the file to get the overview of\n        :param depth: depth up to which descendants of top-level symbols shall be retrieved\n            (e.g. 1 retrieves immediate children). Default 0.\n        :param max_answer_chars: if the overview is longer than this number of characters,\n            no content will be returned. -1 means the default value from the config will be used.\n            Don't adjust unless there is really no other way to get the content required for the task.\n        :return: a JSON object containing symbols grouped by kind in a compact format.\n        \"\"\"\n        result = self.get_symbol_overview(relative_path, depth=depth)\n        compact_result = self.symbol_dict_grouper.group(result)\n        result_json_str = self._to_json(compact_result)\n        return self._limit_length(result_json_str, max_answer_chars)\n\n    def get_symbol_overview(self, relative_path: str, depth: int = 0) -> list[LanguageServerSymbol.OutputDict]:\n        \"\"\"\n        :param relative_path: relative path to a source file\n        :param depth: the depth up to which descendants shall be retrieved\n        :return: a list of symbol dictionaries representing the symbol overview of the file\n        \"\"\"\n        symbol_retriever = self.create_language_server_symbol_retriever()\n\n        # The symbol overview is capable of working with both files and directories,\n        # but we want to ensure that the user provides a file path.\n        file_path = os.path.join(self.project.project_root, relative_path)\n        if not os.path.exists(file_path):\n            raise FileNotFoundError(f\"File or directory {relative_path} does not exist in the project.\")\n        if os.path.isdir(file_path):\n            raise ValueError(f\"Expected a file path, but got a directory path: {relative_path}. \")\n        if not symbol_retriever.can_analyze_file(relative_path):\n            raise ValueError(\n                f\"Cannot extract symbols from file {relative_path}. Active languages: {[l.value for l in self.agent.get_active_lsp_languages()]}\"\n            )\n\n        symbols = symbol_retriever.get_symbol_overview(relative_path)[relative_path]\n\n        def child_inclusion_predicate(s: LanguageServerSymbol) -> bool:\n            return not s.is_low_level()\n\n        symbol_dicts = []\n        for symbol in symbols:\n            symbol_dicts.append(\n                symbol.to_dict(\n                    name_path=False,\n                    name=True,\n                    depth=depth,\n                    kind=True,\n                    relative_path=False,\n                    location=False,\n                    child_inclusion_predicate=child_inclusion_predicate,\n                )\n            )\n        return symbol_dicts\n\n\nclass FindSymbolTool(Tool, ToolMarkerSymbolicRead):\n    \"\"\"\n    Performs a global (or local) search using the language server backend.\n    \"\"\"\n\n    # noinspection PyDefaultArgument\n    def apply(\n        self,\n        name_path_pattern: str,\n        depth: int = 0,\n        relative_path: str = \"\",\n        include_body: bool = False,\n        include_info: bool = False,\n        include_kinds: list[int] = [],  # noqa: B006\n        exclude_kinds: list[int] = [],  # noqa: B006\n        substring_matching: bool = False,\n        max_answer_chars: int = -1,\n    ) -> str:\n        \"\"\"\n        Retrieves information on all symbols/code entities (classes, methods, etc.) based on the given name path pattern.\n        The returned symbol information can be used for edits or further queries.\n        Specify `depth > 0` to also retrieve children/descendants (e.g., methods of a class).\n\n        A name path is a path in the symbol tree *within a source file*.\n        For example, the method `my_method` defined in class `MyClass` would have the name path `MyClass/my_method`.\n        If a symbol is overloaded (e.g., in Java), a 0-based index is appended (e.g. \"MyClass/my_method[0]\") to\n        uniquely identify it.\n\n        To search for a symbol, you provide a name path pattern that is used to match against name paths.\n        It can be\n         * a simple name (e.g. \"method\"), which will match any symbol with that name\n         * a relative path like \"class/method\", which will match any symbol with that name path suffix\n         * an absolute name path \"/class/method\" (absolute name path), which requires an exact match of the full name path within the source file.\n        Append an index `[i]` to match a specific overload only, e.g. \"MyClass/my_method[1]\".\n\n        :param name_path_pattern: the name path matching pattern (see above)\n        :param depth: depth up to which descendants shall be retrieved (e.g. use 1 to also retrieve immediate children;\n            for the case where the symbol is a class, this will return its methods). Default 0.\n        :param relative_path: Optional. Restrict search to this file or directory. If None, searches entire codebase.\n            If a directory is passed, the search will be restricted to the files in that directory.\n            If a file is passed, the search will be restricted to that file.\n            If you have some knowledge about the codebase, you should use this parameter, as it will significantly\n            speed up the search as well as reduce the number of results.\n        :param include_body: whether to include the symbol's source code. Use judiciously.\n        :param include_info: whether to include additional info (hover-like, typically including docstring and signature),\n            about the symbol (ignored if include_body is True). Info is never included for child symbols.\n            Note: Depending on the language, this can be slow (e.g., C/C++).\n        :param include_kinds: List of LSP symbol kind integers to include.\n            If not provided, all kinds are included.\n        :param exclude_kinds: Optional. List of LSP symbol kind integers to exclude. Takes precedence over `include_kinds`.\n            If not provided, no kinds are excluded.\n        :param substring_matching: If True, use substring matching for the last element of the pattern, such that\n            \"Foo/get\" would match \"Foo/getValue\" and \"Foo/getData\".\n        :param max_answer_chars: Max characters for the JSON result. If exceeded, no content is returned.\n            -1 means the default value from the config will be used.\n        :return: a list of symbols (with locations) matching the name.\n        \"\"\"\n        parsed_include_kinds: Sequence[SymbolKind] | None = [SymbolKind(k) for k in include_kinds] if include_kinds else None\n        parsed_exclude_kinds: Sequence[SymbolKind] | None = [SymbolKind(k) for k in exclude_kinds] if exclude_kinds else None\n        symbol_retriever = self.create_language_server_symbol_retriever()\n        symbols = symbol_retriever.find(\n            name_path_pattern,\n            include_kinds=parsed_include_kinds,\n            exclude_kinds=parsed_exclude_kinds,\n            substring_matching=substring_matching,\n            within_relative_path=relative_path,\n        )\n        symbol_dicts = [dict(s.to_dict(kind=True, relative_path=True, body_location=True, depth=depth, body=include_body)) for s in symbols]\n        if not include_body and include_info:\n            info_by_symbol = symbol_retriever.request_info_for_symbol_batch(symbols)\n            for s, s_dict in zip(symbols, symbol_dicts, strict=True):\n                if symbol_info := info_by_symbol.get(s):\n                    s_dict[\"info\"] = symbol_info\n                    s_dict.pop(\"name\", None)  # name is included in the info\n        result = self._to_json(symbol_dicts)\n        return self._limit_length(result, max_answer_chars)\n\n\nclass FindReferencingSymbolsTool(Tool, ToolMarkerSymbolicRead):\n    \"\"\"\n    Finds symbols that reference the given symbol using the language server backend\n    \"\"\"\n\n    symbol_dict_grouper = LanguageServerSymbolDictGrouper([\"relative_path\", \"kind\"], [\"kind\"], collapse_singleton=True)\n\n    # noinspection PyDefaultArgument\n    def apply(\n        self,\n        name_path: str,\n        relative_path: str,\n        include_kinds: list[int] = [],  # noqa: B006\n        exclude_kinds: list[int] = [],  # noqa: B006\n        max_answer_chars: int = -1,\n    ) -> str:\n        \"\"\"\n        Finds references to the symbol at the given `name_path`. The result will contain metadata about the referencing symbols\n        as well as a short code snippet around the reference.\n\n        :param name_path: for finding the symbol to find references for, same logic as in the `find_symbol` tool.\n        :param relative_path: the relative path to the file containing the symbol for which to find references.\n            Note that here you can't pass a directory but must pass a file.\n        :param include_kinds: same as in the `find_symbol` tool.\n        :param exclude_kinds: same as in the `find_symbol` tool.\n        :param max_answer_chars: same as in the `find_symbol` tool.\n        :return: a list of JSON objects with the symbols referencing the requested symbol\n        \"\"\"\n        include_body = False  # It is probably never a good idea to include the body of the referencing symbols\n        parsed_include_kinds: Sequence[SymbolKind] | None = [SymbolKind(k) for k in include_kinds] if include_kinds else None\n        parsed_exclude_kinds: Sequence[SymbolKind] | None = [SymbolKind(k) for k in exclude_kinds] if exclude_kinds else None\n        symbol_retriever = self.create_language_server_symbol_retriever()\n\n        references_in_symbols = symbol_retriever.find_referencing_symbols(\n            name_path,\n            relative_file_path=relative_path,\n            include_body=include_body,\n            include_kinds=parsed_include_kinds,\n            exclude_kinds=parsed_exclude_kinds,\n        )\n\n        reference_dicts = []\n        for ref in references_in_symbols:\n            ref_dict_orig = ref.symbol.to_dict(kind=True, relative_path=True, depth=0, body=include_body, body_location=True)\n            ref_dict = dict(ref_dict_orig)\n            if not include_body:\n                ref_relative_path = ref.symbol.location.relative_path\n                assert ref_relative_path is not None, f\"Referencing symbol {ref.symbol.name} has no relative path, this is likely a bug.\"\n                content_around_ref = self.project.retrieve_content_around_line(\n                    relative_file_path=ref_relative_path, line=ref.line, context_lines_before=1, context_lines_after=1\n                )\n                ref_dict[\"content_around_reference\"] = content_around_ref.to_display_string()\n            reference_dicts.append(ref_dict)\n\n        result = self.symbol_dict_grouper.group(reference_dicts)  # type: ignore\n\n        result_json = self._to_json(result)\n        return self._limit_length(result_json, max_answer_chars)\n\n\nclass ReplaceSymbolBodyTool(Tool, ToolMarkerSymbolicEdit):\n    \"\"\"\n    Replaces the full definition of a symbol using the language server backend.\n    \"\"\"\n\n    def apply(\n        self,\n        name_path: str,\n        relative_path: str,\n        body: str,\n    ) -> str:\n        r\"\"\"\n        Replaces the body of the symbol with the given `name_path`.\n\n        The tool shall be used to replace symbol bodies that have been previously retrieved\n        (e.g. via `find_symbol`).\n        IMPORTANT: Do not use this tool if you do not know what exactly constitutes the body of the symbol.\n\n        :param name_path: for finding the symbol to replace, same logic as in the `find_symbol` tool.\n        :param relative_path: the relative path to the file containing the symbol\n        :param body: the new symbol body. The symbol body is the definition of a symbol\n            in the programming language, including e.g. the signature line for functions.\n            IMPORTANT: The body does NOT include any preceding docstrings/comments or imports, in particular.\n        \"\"\"\n        code_editor = self.create_code_editor()\n        code_editor.replace_body(\n            name_path,\n            relative_file_path=relative_path,\n            body=body,\n        )\n        return SUCCESS_RESULT\n\n\nclass InsertAfterSymbolTool(Tool, ToolMarkerSymbolicEdit):\n    \"\"\"\n    Inserts content after the end of the definition of a given symbol.\n    \"\"\"\n\n    def apply(\n        self,\n        name_path: str,\n        relative_path: str,\n        body: str,\n    ) -> str:\n        \"\"\"\n        Inserts the given body/content after the end of the definition of the given symbol (via the symbol's location).\n        A typical use case is to insert a new class, function, method, field or variable assignment.\n\n        :param name_path: name path of the symbol after which to insert content (definitions in the `find_symbol` tool apply)\n        :param relative_path: the relative path to the file containing the symbol\n        :param body: the body/content to be inserted. The inserted code shall begin with the next line after\n            the symbol.\n        \"\"\"\n        code_editor = self.create_code_editor()\n        code_editor.insert_after_symbol(name_path, relative_file_path=relative_path, body=body)\n        return SUCCESS_RESULT\n\n\nclass InsertBeforeSymbolTool(Tool, ToolMarkerSymbolicEdit):\n    \"\"\"\n    Inserts content before the beginning of the definition of a given symbol.\n    \"\"\"\n\n    def apply(\n        self,\n        name_path: str,\n        relative_path: str,\n        body: str,\n    ) -> str:\n        \"\"\"\n        Inserts the given content before the beginning of the definition of the given symbol (via the symbol's location).\n        A typical use case is to insert a new class, function, method, field or variable assignment; or\n        a new import statement before the first symbol in the file.\n\n        :param name_path: name path of the symbol before which to insert content (definitions in the `find_symbol` tool apply)\n        :param relative_path: the relative path to the file containing the symbol\n        :param body: the body/content to be inserted before the line in which the referenced symbol is defined\n        \"\"\"\n        code_editor = self.create_code_editor()\n        code_editor.insert_before_symbol(name_path, relative_file_path=relative_path, body=body)\n        return SUCCESS_RESULT\n\n\nclass RenameSymbolTool(Tool, ToolMarkerSymbolicEdit):\n    \"\"\"\n    Renames a symbol throughout the codebase using language server refactoring capabilities.\n    \"\"\"\n\n    def apply(\n        self,\n        name_path: str,\n        relative_path: str,\n        new_name: str,\n    ) -> str:\n        \"\"\"\n        Renames the symbol with the given `name_path` to `new_name` throughout the entire codebase.\n        Note: for languages with method overloading, like Java, name_path may have to include a method's\n        signature to uniquely identify a method.\n\n        :param name_path: name path of the symbol to rename (definitions in the `find_symbol` tool apply)\n        :param relative_path: the relative path to the file containing the symbol to rename\n        :param new_name: the new name for the symbol\n        :return: result summary indicating success or failure\n        \"\"\"\n        code_editor = self.create_code_editor()\n        status_message = code_editor.rename_symbol(name_path, relative_file_path=relative_path, new_name=new_name)\n        return status_message\n"
  },
  {
    "path": "src/serena/tools/tools_base.py",
    "content": "import inspect\nimport json\nfrom abc import ABC\nfrom collections.abc import Iterable\nfrom dataclasses import dataclass\nfrom types import TracebackType\nfrom typing import TYPE_CHECKING, Any, Protocol, Self, TypeVar, cast\n\nfrom mcp import Implementation\nfrom mcp.server.fastmcp import Context\nfrom mcp.server.fastmcp.utilities.func_metadata import FuncMetadata, func_metadata\nfrom sensai.util import logging\nfrom sensai.util.string import dict_string\n\nfrom serena.config.serena_config import LanguageBackend\nfrom serena.project import MemoriesManager, Project\nfrom serena.prompt_factory import PromptFactory\nfrom serena.util.class_decorators import singleton\nfrom serena.util.inspection import iter_subclasses\nfrom solidlsp.ls_exceptions import SolidLSPException\n\nif TYPE_CHECKING:\n    from serena.agent import SerenaAgent\n    from serena.code_editor import CodeEditor\n    from serena.symbol import LanguageServerSymbolRetriever\n\nlog = logging.getLogger(__name__)\nT = TypeVar(\"T\")\nSUCCESS_RESULT = \"OK\"\n\n\nclass Component(ABC):\n    def __init__(self, agent: \"SerenaAgent\"):\n        self.agent = agent\n\n    def get_project_root(self) -> str:\n        \"\"\"\n        :return: the root directory of the active project, raises a ValueError if no active project configuration is set\n        \"\"\"\n        return self.project.project_root\n\n    @property\n    def prompt_factory(self) -> PromptFactory:\n        return self.agent.prompt_factory\n\n    @property\n    def memories_manager(self) -> \"MemoriesManager\":\n        return self.project.memories_manager\n\n    def create_language_server_symbol_retriever(self) -> \"LanguageServerSymbolRetriever\":\n        from serena.symbol import LanguageServerSymbolRetriever\n\n        assert self.agent.get_language_backend().is_lsp(), \"Language server symbol retriever can only be created for LSP language backend\"\n        return LanguageServerSymbolRetriever(self.project)\n\n    @property\n    def project(self) -> Project:\n        return self.agent.get_active_project_or_raise()\n\n    def create_code_editor(self) -> \"CodeEditor\":\n        from ..code_editor import JetBrainsCodeEditor, LanguageServerCodeEditor\n\n        match self.agent.get_language_backend():\n            case LanguageBackend.LSP:\n                return LanguageServerCodeEditor(self.create_language_server_symbol_retriever())\n            case LanguageBackend.JETBRAINS:\n                return JetBrainsCodeEditor(project=self.project)\n            case _:\n                raise ValueError\n\n\nclass ToolMarker:\n    \"\"\"\n    Base class for tool markers.\n    \"\"\"\n\n\nclass ToolMarkerCanEdit(ToolMarker):\n    \"\"\"\n    Marker class for all tools that can perform editing operations on files.\n    \"\"\"\n\n\nclass ToolMarkerDoesNotRequireActiveProject(ToolMarker):\n    pass\n\n\nclass ToolMarkerOptional(ToolMarker):\n    \"\"\"\n    Marker class for optional tools that are disabled by default.\n    \"\"\"\n\n\nclass ToolMarkerSymbolicRead(ToolMarker):\n    \"\"\"\n    Marker class for tools that perform symbol read operations.\n    \"\"\"\n\n\nclass ToolMarkerSymbolicEdit(ToolMarkerCanEdit):\n    \"\"\"\n    Marker class for tools that perform symbolic edit operations.\n    \"\"\"\n\n\nclass ApplyMethodProtocol(Protocol):\n    \"\"\"Callable protocol for the apply method of a tool.\"\"\"\n\n    def __call__(self, *args: Any, **kwargs: Any) -> str:\n        pass\n\n\nclass Tool(Component):\n    # NOTE: each tool should implement the apply method, which is then used in\n    # the central method of the Tool class `apply_ex`.\n    # Failure to do so will result in a RuntimeError at tool execution time.\n    # The apply method is not declared as part of the base Tool interface since we cannot\n    # know the signature of the (input parameters of the) method in advance.\n    #\n    # The docstring and types of the apply method are used to generate the tool description\n    # (which is use by the LLM, so a good description is important)\n    # and to validate the tool call arguments.\n\n    _last_tool_call_client_str: str | None = None\n    \"\"\"We can only get the client info from within a tool call. Each tool call will update this variable.\"\"\"\n\n    @classmethod\n    def set_last_tool_call_client_str(cls, client_str: str | None) -> None:\n        cls._last_tool_call_client_str = client_str\n\n    @classmethod\n    def get_last_tool_call_client_str(cls) -> str | None:\n        return cls._last_tool_call_client_str\n\n    @classmethod\n    def get_name_from_cls(cls) -> str:\n        name = cls.__name__\n        if name.endswith(\"Tool\"):\n            name = name[:-4]\n        # convert to snake_case\n        name = \"\".join([\"_\" + c.lower() if c.isupper() else c for c in name]).lstrip(\"_\")\n        return name\n\n    def get_name(self) -> str:\n        return self.get_name_from_cls()\n\n    def get_apply_fn(self) -> ApplyMethodProtocol:\n        apply_fn = getattr(self, \"apply\")\n        if apply_fn is None:\n            raise RuntimeError(f\"apply not defined in {self}. Did you forget to implement it?\")\n        return apply_fn\n\n    @classmethod\n    def can_edit(cls) -> bool:\n        \"\"\"\n        Returns whether this tool can perform editing operations on code.\n\n        :return: True if the tool can edit code, False otherwise\n        \"\"\"\n        return issubclass(cls, ToolMarkerCanEdit)\n\n    @classmethod\n    def get_tool_description(cls) -> str:\n        docstring = cls.__doc__\n        if docstring is None:\n            return \"\"\n        return docstring.strip()\n\n    @classmethod\n    def get_apply_docstring_from_cls(cls) -> str:\n        \"\"\"Get the docstring for the apply method from the class (static metadata).\n        Needed for creating MCP tools in a separate process without running into serialization issues.\n        \"\"\"\n        # First try to get from __dict__ to handle dynamic docstring changes\n        if \"apply\" in cls.__dict__:\n            apply_fn = cls.__dict__[\"apply\"]\n        else:\n            # Fall back to getattr for inherited methods\n            apply_fn = getattr(cls, \"apply\", None)\n            if apply_fn is None:\n                raise AttributeError(f\"apply method not defined in {cls}. Did you forget to implement it?\")\n\n        docstring = apply_fn.__doc__\n        if not docstring:\n            raise AttributeError(f\"apply method has no (or empty) docstring in {cls}. Did you forget to implement it?\")\n        return docstring.strip()\n\n    def get_apply_docstring(self) -> str:\n        \"\"\"Gets the docstring for the tool application, used by the MCP server.\"\"\"\n        return self.get_apply_docstring_from_cls()\n\n    def get_apply_fn_metadata(self) -> FuncMetadata:\n        \"\"\"Gets the metadata for the tool application function, used by the MCP server.\"\"\"\n        return self.get_apply_fn_metadata_from_cls()\n\n    @classmethod\n    def get_apply_fn_metadata_from_cls(cls) -> FuncMetadata:\n        \"\"\"Get the metadata for the apply method from the class (static metadata).\n        Needed for creating MCP tools in a separate process without running into serialization issues.\n        \"\"\"\n        # First try to get from __dict__ to handle dynamic docstring changes\n        if \"apply\" in cls.__dict__:\n            apply_fn = cls.__dict__[\"apply\"]\n        else:\n            # Fall back to getattr for inherited methods\n            apply_fn = getattr(cls, \"apply\", None)\n            if apply_fn is None:\n                raise AttributeError(f\"apply method not defined in {cls}. Did you forget to implement it?\")\n\n        return func_metadata(apply_fn, skip_names=[\"self\", \"cls\"])\n\n    def _log_tool_application(self, frame: Any) -> None:\n        params = {}\n        ignored_params = {\"self\", \"log_call\", \"catch_exceptions\", \"args\", \"apply_fn\"}\n        for param, value in frame.f_locals.items():\n            if param in ignored_params:\n                continue\n            if param == \"kwargs\":\n                params.update(value)\n            else:\n                params[param] = value\n        log.info(f\"{self.get_name_from_cls()}: {dict_string(params)}\")\n\n    def _limit_length(self, result: str, max_answer_chars: int) -> str:\n        if max_answer_chars == -1:\n            max_answer_chars = self.agent.serena_config.default_max_tool_answer_chars\n        if max_answer_chars <= 0:\n            raise ValueError(f\"Must be positive or the default (-1), got: {max_answer_chars=}\")\n        if (n_chars := len(result)) > max_answer_chars:\n            result = (\n                f\"The answer is too long ({n_chars} characters). \"\n                + \"Please try a more specific tool query or raise the max_answer_chars parameter.\"\n            )\n        return result\n\n    def is_active(self) -> bool:\n        return self.agent.tool_is_active(self.get_name())\n\n    def is_readonly(self) -> bool:\n        return not self.can_edit()\n\n    def is_symbolic(self) -> bool:\n        return issubclass(self.__class__, ToolMarkerSymbolicRead) or issubclass(self.__class__, ToolMarkerSymbolicEdit)\n\n    def apply_ex(self, log_call: bool = True, catch_exceptions: bool = True, mcp_ctx: Context | None = None, **kwargs) -> str:  # type: ignore\n        \"\"\"\n        Applies the tool with logging and exception handling, using the given keyword arguments\n        \"\"\"\n        if mcp_ctx is not None:\n            try:\n                client_params = mcp_ctx.session.client_params\n                if client_params is not None:\n                    client_info = cast(Implementation, client_params.clientInfo)\n                    client_str = client_info.title if client_info.title else client_info.name + \" \" + client_info.version\n                    if client_str != self.get_last_tool_call_client_str():\n                        log.debug(f\"Updating client info: {client_info}\")\n                        self.set_last_tool_call_client_str(client_str)\n            except BaseException as e:\n                log.info(f\"Failed to get client info: {e}.\")\n\n        def task() -> str:\n            apply_fn = self.get_apply_fn()\n\n            try:\n                if not self.is_active():\n                    return f\"Error: Tool '{self.get_name_from_cls()}' is not active. Active tools: {self.agent.get_active_tool_names()}\"\n            except Exception as e:\n                return f\"RuntimeError while checking if tool {self.get_name_from_cls()} is active: {e}\"\n\n            if log_call:\n                self._log_tool_application(inspect.currentframe())\n            try:\n                # check whether the tool requires an active project and language server\n                if not isinstance(self, ToolMarkerDoesNotRequireActiveProject):\n                    if self.agent.get_active_project() is None:\n                        return (\n                            \"Error: No active project. Ask the user to provide the project path or to select a project from this list of known projects: \"\n                            + f\"{self.agent.serena_config.project_names}\"\n                        )\n\n                # apply the actual tool\n                try:\n                    result = apply_fn(**kwargs)\n                except SolidLSPException as e:\n                    if e.is_language_server_terminated():\n                        affected_language = e.get_affected_language()\n                        if affected_language is not None:\n                            log.error(\n                                f\"Language server terminated while executing tool ({e}). Restarting the language server and retrying ...\"\n                            )\n                            self.agent.get_language_server_manager_or_raise().restart_language_server(affected_language)\n                            result = apply_fn(**kwargs)\n                        else:\n                            log.error(\n                                f\"Language server terminated while executing tool ({e}), but affected language is unknown. Not retrying.\"\n                            )\n                            raise\n                    else:\n                        raise\n\n                # record tool usage\n                self.agent.record_tool_usage(kwargs, result, self)\n\n            except Exception as e:\n                if not catch_exceptions:\n                    raise\n                msg = f\"Error executing tool: {e.__class__.__name__} - {e}\"\n                log.error(f\"Error executing tool: {e}\", exc_info=e)\n                result = msg\n\n            if log_call:\n                log.info(f\"Result: {result}\")\n\n            try:\n                ls_manager = self.agent.get_language_server_manager()\n                if ls_manager is not None:\n                    ls_manager.save_all_caches()\n            except Exception as e:\n                log.error(f\"Error saving language server cache: {e}\")\n\n            return result\n\n        # execute the tool in the agent's task executor, with timeout\n        try:\n            task_exec = self.agent.issue_task(task, name=self.__class__.__name__)\n            return task_exec.result(timeout=self.agent.serena_config.tool_timeout)\n        except Exception as e:  # typically TimeoutError (other exceptions caught in task)\n            msg = f\"Error: {e.__class__.__name__} - {e}\"\n            log.error(msg)\n            return msg\n\n    @staticmethod\n    def _to_json(x: Any) -> str:\n        return json.dumps(x, ensure_ascii=False)\n\n\nclass EditedFileContext:\n    \"\"\"\n    Context manager for file editing.\n\n    Create the context, then use `set_updated_content` to set the new content, the original content\n    being provided in `original_content`.\n    When exiting the context without an exception, the updated content will be written back to the file.\n    \"\"\"\n\n    def __init__(self, relative_path: str, code_editor: \"CodeEditor\"):\n        self._relative_path = relative_path\n        self._code_editor = code_editor\n        self._edited_file: CodeEditor.EditedFile | None = None\n        self._edited_file_context: Any = None\n\n    def __enter__(self) -> Self:\n        self._edited_file_context = self._code_editor.edited_file_context(self._relative_path)\n        self._edited_file = self._edited_file_context.__enter__()\n        return self\n\n    def get_original_content(self) -> str:\n        \"\"\"\n        :return: the original content of the file before any modifications.\n        \"\"\"\n        assert self._edited_file is not None\n        return self._edited_file.get_contents()\n\n    def set_updated_content(self, content: str) -> None:\n        \"\"\"\n        Sets the updated content of the file, which will be written back to the file\n        when the context is exited without an exception.\n\n        :param content: the updated content of the file\n        \"\"\"\n        assert self._edited_file is not None\n        self._edited_file.set_contents(content)\n\n    def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:\n        assert self._edited_file_context is not None\n        self._edited_file_context.__exit__(exc_type, exc_value, traceback)\n\n\n@dataclass(kw_only=True)\nclass RegisteredTool:\n    tool_class: type[Tool]\n    is_optional: bool\n    tool_name: str\n\n    @property\n    def class_docstring(self) -> str:\n        \"\"\"\n        :return: the tool description (high-level class docstring)\n        \"\"\"\n        return self.tool_class.get_tool_description()\n\n\ntool_packages = [\"serena.tools\"]\n\n\n@singleton\nclass ToolRegistry:\n    def __init__(self) -> None:\n        self._tool_dict: dict[str, RegisteredTool] = {}\n        inclusion_predicate = lambda c: \"apply\" in c.__dict__  # include only concrete tool classes that implement apply\n        for cls in iter_subclasses(Tool, inclusion_predicate=inclusion_predicate):\n            if not any(cls.__module__.startswith(pkg) for pkg in tool_packages):\n                continue\n            is_optional = issubclass(cls, ToolMarkerOptional)\n            name = cls.get_name_from_cls()\n            if name in self._tool_dict:\n                raise ValueError(f\"Duplicate tool name found: {name}. Tool classes must have unique names.\")\n            self._tool_dict[name] = RegisteredTool(tool_class=cls, is_optional=is_optional, tool_name=name)\n\n    def get_registered_tools_by_module(self) -> dict[str, list[RegisteredTool]]:\n        \"\"\"\n        :return: the registered tools grouped by their module (ordered alphabetically by module and tool name)\n        \"\"\"\n        module_dict: dict[str, list[RegisteredTool]] = {}\n        for tool in self._tool_dict.values():\n            module = tool.tool_class.__module__\n            if module not in module_dict:\n                module_dict[module] = []\n            module_dict[module].append(tool)\n        sorted_module_dict = {}\n        for module in sorted(module_dict.keys()):\n            sorted_module_dict[module] = sorted(module_dict[module], key=lambda t: t.tool_name)\n        return sorted_module_dict\n\n    def get_tool_class_by_name(self, tool_name: str) -> type[Tool]:\n        if tool_name not in self._tool_dict:\n            raise ValueError(f\"Tool named '{tool_name}' not found.\")\n        return self._tool_dict[tool_name].tool_class\n\n    def get_all_tool_classes(self) -> list[type[Tool]]:\n        return list(t.tool_class for t in self._tool_dict.values())\n\n    def get_tool_classes_default_enabled(self) -> list[type[Tool]]:\n        \"\"\"\n        :return: the list of tool classes that are enabled by default (i.e. non-optional tools).\n        \"\"\"\n        return [t.tool_class for t in self._tool_dict.values() if not t.is_optional]\n\n    def get_tool_classes_optional(self) -> list[type[Tool]]:\n        \"\"\"\n        :return: the list of tool classes that are optional (i.e. disabled by default).\n        \"\"\"\n        return [t.tool_class for t in self._tool_dict.values() if t.is_optional]\n\n    def get_tool_names_default_enabled(self) -> list[str]:\n        \"\"\"\n        :return: the list of tool names that are enabled by default (i.e. non-optional tools).\n        \"\"\"\n        return [t.tool_name for t in self._tool_dict.values() if not t.is_optional]\n\n    def get_tool_names_optional(self) -> list[str]:\n        \"\"\"\n        :return: the list of tool names that are optional (i.e. disabled by default).\n        \"\"\"\n        return [t.tool_name for t in self._tool_dict.values() if t.is_optional]\n\n    def get_tool_names(self) -> list[str]:\n        \"\"\"\n        :return: the list of all tool names.\n        \"\"\"\n        return list(self._tool_dict.keys())\n\n    def print_tool_overview(\n        self, tools: Iterable[type[Tool] | Tool] | None = None, include_optional: bool = False, only_optional: bool = False\n    ) -> None:\n        \"\"\"\n        Print a summary of the tools. If no tools are passed, a summary of the selection of tools (all, default or only optional) is printed.\n        \"\"\"\n        if tools is None:\n            if only_optional:\n                tools = self.get_tool_classes_optional()\n            elif include_optional:\n                tools = self.get_all_tool_classes()\n            else:\n                tools = self.get_tool_classes_default_enabled()\n\n        tool_dict: dict[str, type[Tool] | Tool] = {}\n        for tool_class in tools:\n            tool_dict[tool_class.get_name_from_cls()] = tool_class\n        for tool_name in sorted(tool_dict.keys()):\n            tool_class = tool_dict[tool_name]\n            print(f\" * `{tool_name}`: {tool_class.get_tool_description().strip()}\")\n\n    def is_valid_tool_name(self, tool_name: str) -> bool:\n        return tool_name in self._tool_dict\n"
  },
  {
    "path": "src/serena/tools/workflow_tools.py",
    "content": "\"\"\"\nTools supporting the general workflow of the agent\n\"\"\"\n\nimport platform\n\nfrom serena.tools import Tool, ToolMarkerDoesNotRequireActiveProject, ToolMarkerOptional\n\n\nclass CheckOnboardingPerformedTool(Tool):\n    \"\"\"\n    Checks whether project onboarding was already performed.\n    \"\"\"\n\n    def apply(self) -> str:\n        \"\"\"\n        Checks whether project onboarding was already performed.\n        You should always call this tool before beginning to actually work on the project/after activating a project.\n        \"\"\"\n        project_memories = self.memories_manager.list_project_memories()\n        if len(project_memories) == 0:\n            msg = (\n                \"Onboarding not performed yet (no memories available). \"\n                \"You should perform onboarding by calling the `onboarding` tool before proceeding with the task. \"\n            )\n        else:\n            # Not reporting the list of memories here, as they were already reported at project activation\n            # (with the system prompt if the project was activated at startup)\n            msg = (\n                f\"Onboarding was already performed: {len(project_memories)} project memories are available. \"\n                \"Consider reading memories if they appear relevant to the task at hand.\"\n            )\n        msg += \" If you have not read the 'Serena Instructions Manual', do so now.\"\n        return msg\n\n\nclass OnboardingTool(Tool):\n    \"\"\"\n    Performs onboarding (identifying the project structure and essential tasks, e.g. for testing or building).\n    \"\"\"\n\n    def apply(self) -> str:\n        \"\"\"\n        Call this tool if onboarding was not performed yet.\n        You will call this tool at most once per conversation.\n\n        :return: instructions on how to create the onboarding information\n        \"\"\"\n        system = platform.system()\n        return self.prompt_factory.create_onboarding_prompt(system=system)\n\n\nclass ThinkAboutCollectedInformationTool(Tool, ToolMarkerOptional):\n    \"\"\"\n    Thinking tool for pondering the completeness of collected information.\n    \"\"\"\n\n    def apply(self) -> str:\n        \"\"\"\n        Think about the collected information and whether it is sufficient and relevant.\n        This tool should ALWAYS be called after you have completed a non-trivial sequence of searching steps like\n        find_symbol, find_referencing_symbols, search_files_for_pattern, read_file, etc.\n        \"\"\"\n        return self.prompt_factory.create_think_about_collected_information()\n\n\nclass ThinkAboutTaskAdherenceTool(Tool, ToolMarkerOptional):\n    \"\"\"\n    Thinking tool for determining whether the agent is still on track with the current task.\n    \"\"\"\n\n    def apply(self) -> str:\n        \"\"\"\n        Think about the task at hand and whether you are still on track.\n        Especially important if the conversation has been going on for a while and there\n        has been a lot of back and forth.\n\n        This tool should ALWAYS be called before you insert, replace, or delete code.\n        \"\"\"\n        return self.prompt_factory.create_think_about_task_adherence()\n\n\nclass ThinkAboutWhetherYouAreDoneTool(Tool, ToolMarkerOptional):\n    \"\"\"\n    Thinking tool for determining whether the task is truly completed.\n    \"\"\"\n\n    def apply(self) -> str:\n        \"\"\"\n        Whenever you feel that you are done with what the user has asked for, it is important to call this tool.\n        \"\"\"\n        return self.prompt_factory.create_think_about_whether_you_are_done()\n\n\nclass SummarizeChangesTool(Tool, ToolMarkerOptional):\n    \"\"\"\n    Provides instructions for summarizing the changes made to the codebase.\n    \"\"\"\n\n    def apply(self) -> str:\n        \"\"\"\n        Summarize the changes you have made to the codebase.\n        This tool should always be called after you have fully completed any non-trivial coding task,\n        but only after the think_about_whether_you_are_done call.\n        \"\"\"\n        return self.prompt_factory.create_summarize_changes()\n\n\nclass PrepareForNewConversationTool(Tool):\n    \"\"\"\n    Provides instructions for preparing for a new conversation (in order to continue with the necessary context).\n    \"\"\"\n\n    def apply(self) -> str:\n        \"\"\"\n        Instructions for preparing for a new conversation. This tool should only be called on explicit user request.\n        \"\"\"\n        return self.prompt_factory.create_prepare_for_new_conversation()\n\n\nclass InitialInstructionsTool(Tool, ToolMarkerDoesNotRequireActiveProject):\n    \"\"\"\n    Provides instructions on how to use the Serena toolbox.\n    Should only be used in settings where the system prompt is not read automatically by the client.\n\n    NOTE: Some MCP clients (including Claude Desktop) do not read the system prompt automatically!\n    \"\"\"\n\n    def apply(self) -> str:\n        \"\"\"\n        Provides the 'Serena Instructions Manual', which contains essential information on how to use the Serena toolbox.\n        IMPORTANT: If you have not yet read the manual, call this tool immediately after you are given your task by the user,\n        as it will critically inform you!\n        \"\"\"\n        return self.agent.create_system_prompt()\n"
  },
  {
    "path": "src/serena/util/class_decorators.py",
    "content": "from typing import Any\r\n\r\n\r\n# duplicate of interprompt.class_decorators\r\n# We don't want to depend on interprompt for this in serena, so we duplicate it here\r\ndef singleton(cls: type[Any]) -> Any:\r\n    instance = None\r\n\r\n    def get_instance(*args: Any, **kwargs: Any) -> Any:\r\n        nonlocal instance\r\n        if instance is None:\r\n            instance = cls(*args, **kwargs)\r\n        return instance\r\n\r\n    return get_instance\r\n"
  },
  {
    "path": "src/serena/util/cli_util.py",
    "content": "def ask_yes_no(question: str, default: bool | None = None) -> bool:\n    default_prompt = \"Y/n\" if default else \"y/N\"\n\n    while True:\n        answer = input(f\"{question} [{default_prompt}] \").strip().lower()\n        if answer == \"\" and default is not None:\n            return default\n        if answer in (\"y\", \"yes\"):\n            return True\n        if answer in (\"n\", \"no\"):\n            return False\n        print(\"Please answer yes/y or no/n.\")\n"
  },
  {
    "path": "src/serena/util/dataclass.py",
    "content": "from dataclasses import MISSING, Field\nfrom typing import Any, cast\n\n\ndef get_dataclass_default(cls: type, field_name: str) -> Any:\n    \"\"\"\n    Gets the default value of a dataclass field.\n\n    :param cls: The dataclass type.\n    :param field_name: The name of the field.\n    :return: The default value of the field (either from default or default_factory).\n    \"\"\"\n    field = cast(Field, cls.__dataclass_fields__[field_name])  # type: ignore[attr-defined]\n\n    if field.default is not MISSING:\n        return field.default\n\n    if field.default_factory is not MISSING:  # default_factory is a function\n        return field.default_factory()\n\n    raise AttributeError(f\"{field_name} has no default\")\n"
  },
  {
    "path": "src/serena/util/dotnet.py",
    "content": "import logging\nimport platform\nimport re\nimport shutil\nimport subprocess\nimport urllib\nfrom pathlib import Path\n\nfrom serena.util.version import Version\nfrom solidlsp.ls_exceptions import SolidLSPException\n\nlog = logging.getLogger(__name__)\n\n\nclass DotNETUtil:\n    def __init__(self, required_version: str, allow_higher_version: bool = True):\n        \"\"\"\n        :param required_version: the required .NET runtime version specified as a string (e.g. \"10.0\" for .NET 10.0)\n        :param allow_higher_version: whether to allow higher versions than the required version\n        \"\"\"\n        self._system_dotnet = shutil.which(\"dotnet\")\n        self._required_version_str = required_version\n        self._required_version_components = [int(c) for c in required_version.split(\".\")]\n        self._allow_higher_version = allow_higher_version\n        self._installed_versions = self._determine_installed_versions()\n\n    def _determine_installed_versions(self) -> list[Version]:\n        if self._system_dotnet:\n            try:\n                result = subprocess.run([self._system_dotnet, \"--list-runtimes\"], capture_output=True, text=True, check=True)\n                version_strings = re.findall(r\"Microsoft.NETCore.App\\s+([^\\s]+)\", result.stdout)\n                log.info(\"Installed .NET runtime versions: %s\", version_strings)\n                return [Version(v) for v in version_strings]\n            except:\n                log.warning(\"Failed to run 'dotnet --list-runtimes' to check .NET version; assuming no installed .NET versions\")\n                return []\n        else:\n            log.info(\"Found no `dotnet` on system PATH; assuming no installed .NET versions\")\n            return []\n\n    def is_required_version_available(self) -> bool:\n        \"\"\"\n        Checks whether the required .NET runtime version is installed and raises an exception if not.\n\n        :param required_version_components: the required .NET runtime version specified as a list of integers representing the version components (e.g., [6, 1] for .NET 6.1)\n        :param allow_higher_version: whether to allow higher versions than the required version (e.g., if True, .NET 7.0 would satisfy a requirement of .NET 6.1)\n        \"\"\"\n        required_version_str = \".\".join(str(c) for c in self._required_version_components)\n        for v in self._installed_versions:\n            if self._allow_higher_version:\n                if v.is_at_least(*self._required_version_components):\n                    log.info(f\"Found installed .NET runtime version {v} which satisfies requirement of {required_version_str} or higher\")\n                    return True\n            else:\n                if v.is_equal(*self._required_version_components):\n                    log.info(f\"Found installed .NET runtime version {v} which satisfies requirement of {required_version_str}\")\n                    return True\n        return False\n\n    def get_dotnet_path_or_raise(self) -> str:\n        \"\"\"\n        Returns the path to the dotnet executable if the required .NET runtime version is available, otherwise raises an exception.\n        \"\"\"\n        if not self.is_required_version_available():\n            raise SolidLSPException(\n                f\"Required .NET runtime version {self._required_version_str} not found \"\n                f\"(installed versions: {self._installed_versions}). \"\n                \"Please install the required .NET runtime version from https://dotnet.microsoft.com/en-us/download/dotnet \"\n                \"and ensure that `dotnet` is on the system PATH.\"\n            )\n        assert self._system_dotnet is not None\n        return self._system_dotnet\n\n    @staticmethod\n    def install_dotnet_with_script(version: str, base_path: str) -> str:\n        \"\"\"\n        Install .NET runtime using Microsoft's official installation script.\n\n        NOTE: This method is unreliable and therefore currently unused. It is kept for reference.\n\n        :version: the version to install as a string (e.g. \"10.0\")\n        :return: the path to the dotnet executable.\n        \"\"\"\n        dotnet_dir = Path(base_path) / f\"dotnet-runtime-{version}\"\n\n        # Determine binary name based on platform\n        is_windows = platform.system().lower() == \"windows\"\n        dotnet_exe = dotnet_dir / (\"dotnet.exe\" if is_windows else \"dotnet\")\n\n        if dotnet_exe.exists():\n            log.info(f\"Using cached .NET {version} runtime from {dotnet_exe}\")\n            return str(dotnet_exe)\n\n        # Download and run install script\n        log.info(f\"Installing .NET {version} runtime using official Microsoft install script...\")\n        dotnet_dir.mkdir(parents=True, exist_ok=True)\n\n        try:\n            if is_windows:\n                # PowerShell script for Windows\n                script_url = \"https://dot.net/v1/dotnet-install.ps1\"\n                script_path = dotnet_dir / \"dotnet-install.ps1\"\n                urllib.request.urlretrieve(script_url, script_path)\n\n                cmd = [\n                    \"pwsh\",\n                    \"-NoProfile\",\n                    \"-ExecutionPolicy\",\n                    \"Bypass\",\n                    \"-File\",\n                    str(script_path),\n                    \"-Version\",\n                    version,\n                    \"-InstallDir\",\n                    str(dotnet_dir),\n                    \"-Runtime\",\n                    \"dotnet\",\n                    \"-NoPath\",\n                ]\n            else:\n                # Bash script for Linux/macOS\n                script_url = \"https://dot.net/v1/dotnet-install.sh\"\n                script_path = dotnet_dir / \"dotnet-install.sh\"\n                urllib.request.urlretrieve(script_url, script_path)\n                script_path.chmod(0o755)\n\n                cmd = [\n                    \"bash\",\n                    str(script_path),\n                    \"--version\",\n                    version,\n                    \"--install-dir\",\n                    str(dotnet_dir),\n                    \"--runtime\",\n                    \"dotnet\",\n                    \"--no-path\",\n                ]\n\n            # Run the install script\n            log.info(\"Running .NET install script: %s\", cmd)\n            result = subprocess.run(cmd, capture_output=True, text=True, check=True)\n            log.debug(f\"Install script output: {result.stdout}\")\n\n            if not dotnet_exe.exists():\n                raise SolidLSPException(f\"dotnet executable not found at {dotnet_exe} after installation\")\n\n            log.info(f\"Successfully installed .NET {version} runtime to {dotnet_exe}\")\n            return str(dotnet_exe)\n\n        except subprocess.CalledProcessError as e:\n            raise SolidLSPException(f\"Failed to install .NET {version} runtime using install script: {e.stderr if e.stderr else e}\") from e\n        except Exception as e:\n            message = f\"Failed to install .NET {version} runtime: {e}\"\n            if is_windows and isinstance(e, FileNotFoundError):\n                message += \"; pwsh, i.e. PowerShell 7+, is required to install .NET runtime. Make sure pwsh is available on your system.\"\n            raise SolidLSPException(message) from e\n"
  },
  {
    "path": "src/serena/util/exception.py",
    "content": "import os\nimport sys\n\nfrom serena.agent import log\n\n\ndef is_headless_environment() -> bool:\n    \"\"\"\n    Detect if we're running in a headless environment where GUI operations would fail.\n\n    Returns True if:\n    - No DISPLAY variable on Linux/Unix\n    - Running in SSH session\n    - Running in WSL without X server\n    - Running in Docker container\n    \"\"\"\n    # Check if we're on Windows - GUI usually works there\n    if sys.platform == \"win32\":\n        return False\n\n    # Check for DISPLAY variable (required for X11)\n    if not os.environ.get(\"DISPLAY\"):  # type: ignore\n        return True\n\n    # Check for SSH session\n    if os.environ.get(\"SSH_CONNECTION\") or os.environ.get(\"SSH_CLIENT\"):\n        return True\n\n    # Check for common CI/container environments\n    if os.environ.get(\"CI\") or os.environ.get(\"CONTAINER\") or os.path.exists(\"/.dockerenv\"):\n        return True\n\n    # Check for WSL (only on Unix-like systems where os.uname exists)\n    if hasattr(os, \"uname\"):\n        if \"microsoft\" in os.uname().release.lower():\n            # In WSL, even with DISPLAY set, X server might not be running\n            # This is a simplified check - could be improved\n            return True\n\n    return False\n\n\ndef show_fatal_exception_safe(e: Exception) -> None:\n    \"\"\"\n    Shows the given exception in the GUI log viewer on the main thread and ensures that the exception is logged or at\n    least printed to stderr.\n    \"\"\"\n    # Log the error and print it to stderr\n    log.error(f\"Fatal exception: {e}\", exc_info=e)\n    print(f\"Fatal exception: {e}\", file=sys.stderr)\n\n    # Don't attempt GUI in headless environments\n    if is_headless_environment():\n        log.debug(\"Skipping GUI error display in headless environment\")\n        return\n\n    # attempt to show the error in the GUI\n    try:\n        # NOTE: The import can fail on macOS if Tk is not available (depends on Python interpreter installation, which uv\n        #   used as a base); while tkinter as such is always available, its dependencies can be unavailable on macOS.\n        from serena.gui_log_viewer import show_fatal_exception\n\n        show_fatal_exception(e)\n    except Exception as gui_error:\n        log.debug(f\"Failed to show GUI error dialog: {gui_error}\")\n"
  },
  {
    "path": "src/serena/util/file_system.py",
    "content": "import logging\r\nimport os\r\nfrom collections.abc import Callable, Iterator\r\nfrom dataclasses import dataclass, field\r\nfrom pathlib import Path\r\nfrom typing import NamedTuple\r\n\r\nimport pathspec\r\nfrom pathspec import PathSpec\r\nfrom sensai.util.logging import LogTime\r\n\r\nlog = logging.getLogger(__name__)\r\n\r\n\r\nclass ScanResult(NamedTuple):\r\n    \"\"\"Result of scanning a directory.\"\"\"\r\n\r\n    directories: list[str]\r\n    files: list[str]\r\n\r\n\r\ndef scan_directory(\r\n    path: str,\r\n    recursive: bool = False,\r\n    relative_to: str | None = None,\r\n    is_ignored_dir: Callable[[str], bool] | None = None,\r\n    is_ignored_file: Callable[[str], bool] | None = None,\r\n) -> ScanResult:\r\n    \"\"\"\r\n    :param path: the path to scan\r\n    :param recursive: whether to recursively scan subdirectories\r\n    :param relative_to: the path to which the results should be relative to; if None, provide absolute paths\r\n    :param is_ignored_dir: a function with which to determine whether the given directory (abs. path) shall be ignored\r\n    :param is_ignored_file: a function with which to determine whether the given file (abs. path) shall be ignored\r\n    :return: the list of directories and files\r\n    \"\"\"\r\n    if is_ignored_file is None:\r\n        is_ignored_file = lambda x: False\r\n    if is_ignored_dir is None:\r\n        is_ignored_dir = lambda x: False\r\n\r\n    files = []\r\n    directories = []\r\n\r\n    abs_path = os.path.abspath(path)\r\n    rel_base = os.path.abspath(relative_to) if relative_to else None\r\n\r\n    try:\r\n        with os.scandir(abs_path) as entries:\r\n            for entry in entries:\r\n                try:\r\n                    entry_path = entry.path\r\n\r\n                    if rel_base:\r\n                        try:\r\n                            result_path = os.path.relpath(entry_path, rel_base)\r\n                        except:\r\n                            log.debug(f\"Skipping entry due to relative path conversion error: {entry.path}\")\r\n                            continue\r\n                    else:\r\n                        result_path = entry_path\r\n\r\n                    if entry.is_file():\r\n                        if not is_ignored_file(entry_path):\r\n                            files.append(result_path)\r\n                    elif entry.is_dir():\r\n                        if not is_ignored_dir(entry_path):\r\n                            directories.append(result_path)\r\n                            if recursive:\r\n                                sub_result = scan_directory(\r\n                                    entry_path,\r\n                                    recursive=True,\r\n                                    relative_to=relative_to,\r\n                                    is_ignored_dir=is_ignored_dir,\r\n                                    is_ignored_file=is_ignored_file,\r\n                                )\r\n                                files.extend(sub_result.files)\r\n                                directories.extend(sub_result.directories)\r\n                except PermissionError as ex:\r\n                    # Skip files/directories that cannot be accessed due to permission issues\r\n                    log.debug(f\"Skipping entry due to permission error: {entry.path}\", exc_info=ex)\r\n                    continue\r\n    except PermissionError as ex:\r\n        # Skip the entire directory if it cannot be accessed\r\n        log.debug(f\"Skipping directory due to permission error: {abs_path}\", exc_info=ex)\r\n        return ScanResult([], [])\r\n\r\n    return ScanResult(directories, files)\r\n\r\n\r\ndef find_all_non_ignored_files(repo_root: str) -> list[str]:\r\n    \"\"\"\r\n    Find all non-ignored files in the repository, respecting all gitignore files in the repository.\r\n\r\n    :param repo_root: The root directory of the repository\r\n    :return: A list of all non-ignored files in the repository\r\n    \"\"\"\r\n    gitignore_parser = GitignoreParser(repo_root)\r\n    _, files = scan_directory(\r\n        repo_root, recursive=True, is_ignored_dir=gitignore_parser.should_ignore, is_ignored_file=gitignore_parser.should_ignore\r\n    )\r\n    return files\r\n\r\n\r\n@dataclass\r\nclass GitignoreSpec:\r\n    file_path: str\r\n    \"\"\"Path to the gitignore file.\"\"\"\r\n    patterns: list[str] = field(default_factory=list)\r\n    \"\"\"List of patterns from the gitignore file.\r\n    The patterns are adjusted based on the gitignore file location.\r\n    \"\"\"\r\n    pathspec: PathSpec = field(init=False)\r\n    \"\"\"Compiled PathSpec object for pattern matching.\"\"\"\r\n\r\n    def __post_init__(self) -> None:\r\n        \"\"\"Initialize the PathSpec from patterns.\"\"\"\r\n        self.pathspec = PathSpec.from_lines(pathspec.patterns.GitWildMatchPattern, self.patterns)\r\n\r\n    def matches(self, relative_path: str) -> bool:\r\n        \"\"\"\r\n        Check if the given path matches any pattern in this gitignore spec.\r\n\r\n        :param relative_path: Path to check (should be relative to repo root)\r\n        :return: True if path matches any pattern\r\n        \"\"\"\r\n        return match_path(relative_path, self.pathspec, root_path=os.path.dirname(self.file_path))\r\n\r\n\r\nclass GitignoreParser:\r\n    \"\"\"\r\n    Parser for gitignore files in a repository.\r\n\r\n    This class handles parsing multiple gitignore files throughout a repository\r\n    and provides methods to check if paths should be ignored.\r\n    \"\"\"\r\n\r\n    def __init__(self, repo_root: str) -> None:\r\n        \"\"\"\r\n        Initialize the parser for a repository.\r\n\r\n        :param repo_root: Root directory of the repository\r\n        \"\"\"\r\n        self.repo_root = os.path.abspath(repo_root)\r\n        self.ignore_specs: list[GitignoreSpec] = []\r\n        self._load_gitignore_files()\r\n\r\n    def _load_gitignore_files(self) -> None:\r\n        \"\"\"Load all gitignore files from the repository.\"\"\"\r\n        with LogTime(\"Loading of .gitignore files\", logger=log):\r\n            for gitignore_path in self._iter_gitignore_files():\r\n                log.info(\"Processing .gitignore file: %s\", gitignore_path)\r\n                spec = self._create_ignore_spec(gitignore_path)\r\n                if spec.patterns:  # Only add non-empty specs\r\n                    self.ignore_specs.append(spec)\r\n\r\n    def _iter_gitignore_files(self, follow_symlinks: bool = False) -> Iterator[str]:\r\n        \"\"\"\r\n        Iteratively discover .gitignore files in a top-down fashion, starting from the repository root.\r\n        Directory paths are skipped if they match any already loaded ignore patterns.\r\n\r\n        :return: an iterator yielding paths to .gitignore files (top-down)\r\n        \"\"\"\r\n        queue: list[str] = [self.repo_root]\r\n\r\n        def scan(abs_path: str | None) -> Iterator[str]:\r\n            for entry in os.scandir(abs_path):\r\n                if entry.is_dir(follow_symlinks=follow_symlinks):\r\n                    queue.append(entry.path)\r\n                elif entry.is_file(follow_symlinks=follow_symlinks) and entry.name == \".gitignore\":\r\n                    yield entry.path\r\n\r\n        while queue:\r\n            next_abs_path = queue.pop(0)\r\n            if next_abs_path != self.repo_root:\r\n                rel_path = os.path.relpath(next_abs_path, self.repo_root)\r\n                if self.should_ignore(rel_path):\r\n                    continue\r\n            yield from scan(next_abs_path)\r\n\r\n    def _create_ignore_spec(self, gitignore_file_path: str) -> GitignoreSpec:\r\n        \"\"\"\r\n        Create a GitignoreSpec from a single gitignore file.\r\n\r\n        :param gitignore_file_path: Path to the .gitignore file\r\n        :return: GitignoreSpec object for the gitignore patterns\r\n        \"\"\"\r\n        try:\r\n            with open(gitignore_file_path, encoding=\"utf-8\") as f:\r\n                content = f.read()\r\n        except (OSError, UnicodeDecodeError):\r\n            # If we can't read the file, return an empty spec\r\n            return GitignoreSpec(gitignore_file_path, [])\r\n\r\n        gitignore_dir = os.path.dirname(gitignore_file_path)\r\n        patterns = self._parse_gitignore_content(content, gitignore_dir)\r\n\r\n        return GitignoreSpec(gitignore_file_path, patterns)\r\n\r\n    def _parse_gitignore_content(self, content: str, gitignore_dir: str) -> list[str]:\r\n        \"\"\"\r\n        Parse gitignore content and adjust patterns based on the gitignore file location.\r\n\r\n        :param content: Content of the .gitignore file\r\n        :param gitignore_dir: Directory containing the .gitignore file (absolute path)\r\n        :return: List of adjusted patterns\r\n        \"\"\"\r\n        patterns = []\r\n\r\n        # Get the relative path from repo root to the gitignore directory\r\n        rel_dir = os.path.relpath(gitignore_dir, self.repo_root)\r\n        if rel_dir == \".\":\r\n            rel_dir = \"\"\r\n\r\n        for line in content.splitlines():\r\n            # Strip trailing whitespace (but preserve leading whitespace for now)\r\n            line = line.rstrip()\r\n\r\n            # Skip empty lines and comments\r\n            if not line or line.lstrip().startswith(\"#\"):\r\n                continue\r\n\r\n            # Store whether this is a negation pattern\r\n            is_negation = line.startswith(\"!\")\r\n            if is_negation:\r\n                line = line[1:]\r\n\r\n            # Strip leading/trailing whitespace after removing negation\r\n            line = line.strip()\r\n\r\n            if not line:\r\n                continue\r\n\r\n            # Handle escaped characters at the beginning\r\n            if line.startswith((\"\\\\#\", \"\\\\!\")):\r\n                line = line[1:]\r\n\r\n            # Determine if pattern is anchored to the gitignore directory and remove leading slash for processing\r\n            is_anchored = line.startswith(\"/\")\r\n            if is_anchored:\r\n                line = line[1:]\r\n\r\n            # Adjust pattern based on gitignore file location\r\n            if rel_dir:\r\n                if is_anchored:\r\n                    # Anchored patterns are relative to the gitignore directory\r\n                    adjusted_pattern = os.path.join(rel_dir, line)\r\n                else:\r\n                    # Non-anchored patterns can match anywhere below the gitignore directory\r\n                    # We need to preserve this behavior\r\n                    if line.startswith(\"**/\"):\r\n                        # Even if pattern starts with **, it should still be scoped to the subdirectory\r\n                        adjusted_pattern = os.path.join(rel_dir, line)\r\n                    else:\r\n                        # Add the directory prefix but also allow matching in subdirectories\r\n                        adjusted_pattern = os.path.join(rel_dir, \"**\", line)\r\n            else:\r\n                if is_anchored:\r\n                    # Anchored patterns in root should only match at root level\r\n                    # Add leading slash back to indicate root-only matching\r\n                    adjusted_pattern = \"/\" + line\r\n                else:\r\n                    # Non-anchored patterns can match anywhere\r\n                    adjusted_pattern = line\r\n\r\n            # Re-add negation if needed\r\n            if is_negation:\r\n                adjusted_pattern = \"!\" + adjusted_pattern\r\n\r\n            # Normalize path separators to forward slashes (gitignore uses forward slashes)\r\n            adjusted_pattern = adjusted_pattern.replace(os.sep, \"/\")\r\n\r\n            patterns.append(adjusted_pattern)\r\n\r\n        return patterns\r\n\r\n    def should_ignore(self, path: str) -> bool:\r\n        \"\"\"\r\n        Check if a path should be ignored based on the gitignore rules.\r\n\r\n        :param path: Path to check (absolute or relative to repo_root)\r\n        :return: True if the path should be ignored, False otherwise\r\n        \"\"\"\r\n        # Convert to relative path from repo root\r\n        if os.path.isabs(path):\r\n            try:\r\n                rel_path = os.path.relpath(path, self.repo_root)\r\n            except Exception as e:\r\n                # If the path could not be converted to a relative path,\r\n                # it is outside the repository root, so we ignore it\r\n                log.info(\"Ignoring path '%s' which is outside of the repository root (%s)\", path, e)\r\n                return True\r\n        else:\r\n            rel_path = path\r\n\r\n        # Ignore paths inside .git\r\n        rel_path_first_path = Path(rel_path).parts[0]\r\n        if rel_path_first_path == \".git\":\r\n            return True\r\n\r\n        abs_path = os.path.join(self.repo_root, rel_path)\r\n\r\n        # Normalize path separators\r\n        rel_path = rel_path.replace(os.sep, \"/\")\r\n\r\n        if os.path.exists(abs_path) and os.path.isdir(abs_path) and not rel_path.endswith(\"/\"):\r\n            rel_path = rel_path + \"/\"\r\n\r\n        # Check against each ignore spec\r\n        for spec in self.ignore_specs:\r\n            if spec.matches(rel_path):\r\n                return True\r\n\r\n        return False\r\n\r\n    def get_ignore_specs(self) -> list[GitignoreSpec]:\r\n        \"\"\"\r\n        Get all loaded gitignore specs.\r\n\r\n        :return: List of GitignoreSpec objects\r\n        \"\"\"\r\n        return self.ignore_specs\r\n\r\n    def reload(self) -> None:\r\n        \"\"\"Reload all gitignore files from the repository.\"\"\"\r\n        self.ignore_specs.clear()\r\n        self._load_gitignore_files()\r\n\r\n\r\ndef match_path(relative_path: str, path_spec: PathSpec, root_path: str = \"\") -> bool:\r\n    \"\"\"\r\n    Match a relative path against a given pathspec. Just pathspec.match_file() is not enough,\r\n    we need to do some massaging to fix issues with pathspec matching.\r\n\r\n    :param relative_path: relative path to match against the pathspec\r\n    :param path_spec: the pathspec to match against\r\n    :param root_path: the root path from which the relative path is derived\r\n    :return:\r\n    \"\"\"\r\n    normalized_path = str(relative_path).replace(os.path.sep, \"/\")\r\n\r\n    # We can have patterns like /src/..., which would only match corresponding paths from the repo root\r\n    # Unfortunately, pathspec can't know whether a relative path is relative to the repo root or not,\r\n    # so it will never match src/...\r\n    # The fix is to just always assume that the input path is relative to the repo root and to\r\n    # prefix it with /.\r\n    if not normalized_path.startswith(\"/\"):\r\n        normalized_path = \"/\" + normalized_path\r\n\r\n    # pathspec can't handle the matching of directories if they don't end with a slash!\r\n    # see https://github.com/cpburnz/python-pathspec/issues/89\r\n    abs_path = os.path.abspath(os.path.join(root_path, relative_path))\r\n    if os.path.isdir(abs_path) and not normalized_path.endswith(\"/\"):\r\n        normalized_path = normalized_path + \"/\"\r\n    return path_spec.match_file(normalized_path)\r\n"
  },
  {
    "path": "src/serena/util/git.py",
    "content": "import logging\n\nfrom sensai.util.git import GitStatus\n\nfrom .shell import subprocess_check_output\n\nlog = logging.getLogger(__name__)\n\n\ndef get_git_status() -> GitStatus | None:\n    try:\n        commit_hash = subprocess_check_output([\"git\", \"rev-parse\", \"HEAD\"])\n        unstaged = bool(subprocess_check_output([\"git\", \"diff\", \"--name-only\"]))\n        staged = bool(subprocess_check_output([\"git\", \"diff\", \"--staged\", \"--name-only\"]))\n        untracked = bool(subprocess_check_output([\"git\", \"ls-files\", \"--others\", \"--exclude-standard\"]))\n        return GitStatus(\n            commit=commit_hash, has_unstaged_changes=unstaged, has_staged_uncommitted_changes=staged, has_untracked_files=untracked\n        )\n    except:\n        return None\n"
  },
  {
    "path": "src/serena/util/gui.py",
    "content": "import os\nimport platform\n\n\ndef system_has_usable_display() -> bool:\n    system = platform.system()\n\n    # macOS and native Windows: assume display is available for desktop usage\n    if system == \"Darwin\" or system == \"Windows\":\n        return True\n\n    # Other systems, assumed to be Unix-like (Linux, FreeBSD, Cygwin/MSYS, etc.):\n    # detect display availability since users may operate in CLI contexts\n    else:\n        # Check X11 or Wayland - if environment variables are set to non-empty values, assume display is usable\n        display = os.environ.get(\"DISPLAY\", \"\")\n        wayland_display = os.environ.get(\"WAYLAND_DISPLAY\", \"\")\n\n        if display or wayland_display:\n            return True\n\n        return False\n"
  },
  {
    "path": "src/serena/util/inspection.py",
    "content": "import logging\nimport os\nfrom collections.abc import Callable, Iterator\nfrom typing import TypeVar\n\nfrom serena.util.file_system import find_all_non_ignored_files\nfrom solidlsp.ls_config import Language\n\nT = TypeVar(\"T\")\n\nlog = logging.getLogger(__name__)\n\n\ndef iter_subclasses(\n    cls: type[T], recursive: bool = True, inclusion_predicate: Callable[[type[T]], bool] = lambda t: True\n) -> Iterator[type[T]]:\n    \"\"\"Iterate over all subclasses of a class.\n\n    :param cls: The class whose subclasses to iterate over.\n    :param recursive: If True, also iterate over all subclasses of all subclasses.\n    :param inclusion_predicate: a predicate function to decide whether to include a subclass in the result\n    \"\"\"\n    for subclass in cls.__subclasses__():\n        if inclusion_predicate(subclass):\n            yield subclass\n        if recursive:\n            yield from iter_subclasses(subclass, recursive, inclusion_predicate)\n\n\ndef determine_programming_language_composition(repo_path: str) -> dict[Language, float]:\n    \"\"\"\n    Determine the programming language composition of a repository.\n\n    :param repo_path: Path to the repository to analyze\n\n    :return: Dictionary mapping languages to percentages of files matching each language\n    \"\"\"\n    all_files = find_all_non_ignored_files(repo_path)\n\n    if not all_files:\n        return {}\n\n    # Count files for each language\n    language_counts: dict[Language, int] = {}\n    total_files = len(all_files)\n\n    for language in Language.iter_all(include_experimental=False):\n        matcher = language.get_source_fn_matcher()\n        count = 0\n\n        for file_path in all_files:\n            # Use just the filename for matching, not the full path\n            filename = os.path.basename(file_path)\n            if matcher.is_relevant_filename(filename):\n                count += 1\n\n        if count > 0:\n            language_counts[language] = count\n\n    # Convert counts to percentages\n    language_percentages: dict[Language, float] = {}\n    for language, count in language_counts.items():\n        percentage = (count / total_files) * 100\n        language_percentages[language] = round(percentage, 2)\n\n    return language_percentages\n"
  },
  {
    "path": "src/serena/util/logging.py",
    "content": "import queue\nimport threading\nfrom collections.abc import Callable\nfrom dataclasses import dataclass\nfrom typing import Optional\n\nfrom sensai.util import logging\n\nfrom serena.constants import LOG_MESSAGES_BUFFER_SIZE, SERENA_LOG_FORMAT\n\nlg = logging\n\n\n@dataclass\nclass LogMessages:\n    messages: list[str]\n    \"\"\"\n    the list of log messages, ordered from oldest to newest\n    \"\"\"\n    max_idx: int\n    \"\"\"\n    the 0-based index of the last message in `messages` (in the full log history)\n    \"\"\"\n\n\nclass MemoryLogHandler(logging.Handler):\n    def __init__(self, level: int = logging.NOTSET, max_messages: int | None = LOG_MESSAGES_BUFFER_SIZE) -> None:\n        super().__init__(level=level)\n        self.setFormatter(logging.Formatter(SERENA_LOG_FORMAT))\n        self._log_buffer = LogBuffer(max_messages=max_messages)\n        self._log_queue: queue.Queue[str] = queue.Queue()\n        self._stop_event = threading.Event()\n        self._emit_callbacks: list[Callable[[str], None]] = []\n\n        # start background thread to process logs\n        self.worker_thread = threading.Thread(target=self._process_queue, daemon=True)\n        self.worker_thread.start()\n\n    def add_emit_callback(self, callback: Callable[[str], None]) -> None:\n        \"\"\"\n        Adds a callback that will be called with each log message.\n        The callback should accept a single string argument (the log message).\n        \"\"\"\n        self._emit_callbacks.append(callback)\n\n    def emit(self, record: logging.LogRecord) -> None:\n        msg = self.format(record)\n        self._log_queue.put_nowait(msg)\n\n    def _process_queue(self) -> None:\n        while not self._stop_event.is_set():\n            try:\n                msg = self._log_queue.get(timeout=1)\n                self._log_buffer.append(msg)\n                for callback in self._emit_callbacks:\n                    try:\n                        callback(msg)\n                    except:\n                        pass\n                self._log_queue.task_done()\n            except queue.Empty:\n                continue\n\n    def get_log_messages(self, from_idx: int = 0) -> LogMessages:\n        return self._log_buffer.get_log_messages(from_idx=from_idx)\n\n    def clear_log_messages(self) -> None:\n        self._log_buffer.clear()\n\n\nclass LogBuffer:\n    \"\"\"\n    A thread-safe buffer for storing (an optionally limited number of) log messages.\n    \"\"\"\n\n    def __init__(self, max_messages: int | None = None) -> None:\n        self._max_messages = max_messages\n        self._log_messages: list[str] = []\n        self._lock = threading.Lock()\n        self._max_idx = -1\n        \"\"\"\n        the 0-based index of the most recently added log message\n        \"\"\"\n\n    def append(self, msg: str) -> None:\n        with self._lock:\n            self._log_messages.append(msg)\n            self._max_idx += 1\n            if self._max_messages is not None and len(self._log_messages) > self._max_messages:\n                excess = len(self._log_messages) - self._max_messages\n                self._log_messages = self._log_messages[excess:]\n\n    def clear(self) -> None:\n        with self._lock:\n            self._log_messages = []\n            self._max_idx = -1\n\n    def get_log_messages(self, from_idx: int = 0) -> LogMessages:\n        \"\"\"\n        :param from_idx: the 0-based index of the first log message to return.\n            If from_idx is less than or equal to the index of the oldest message in the buffer,\n            then all messages in the buffer will be returned.\n        :return: the list of messages\n        \"\"\"\n        from_idx = max(from_idx, 0)\n        with self._lock:\n            first_stored_idx = self._max_idx - len(self._log_messages) + 1\n            if from_idx <= first_stored_idx:\n                messages = self._log_messages.copy()\n            else:\n                start_idx = from_idx - first_stored_idx\n                messages = self._log_messages[start_idx:].copy()\n            return LogMessages(messages=messages, max_idx=self._max_idx)\n\n\nclass SuspendedLoggersContext:\n    \"\"\"A context manager that provides an isolated logging environment.\n\n    Temporarily removes all root log handlers upon entry, providing a clean slate\n    for defining new log handlers within the context. Upon exit, restores the original\n    logging configuration. This is useful when you need to temporarily configure\n    an isolated logging setup with well-defined log handlers.\n\n    The context manager:\n        - Removes all existing (root) log handlers on entry\n        - Allows defining new temporary handlers within the context\n        - Restores the original configuration (handlers and root log level) on exit\n\n    Example:\n        >>> with SuspendedLoggersContext():\n        ...     # No handlers are active here (configure your own and set desired log level)\n        ...     pass\n        >>> # Original log handlers are restored here\n\n    \"\"\"\n\n    def __init__(self) -> None:\n        self.saved_root_handlers: list = []\n        self.saved_root_level: Optional[int] = None\n\n    def __enter__(self) -> \"SuspendedLoggersContext\":\n        root_logger = lg.getLogger()\n        self.saved_root_handlers = root_logger.handlers.copy()\n        self.saved_root_level = root_logger.level\n        root_logger.handlers.clear()\n        return self\n\n    def __exit__(self, exc_type, exc_val, exc_tb) -> None:  # type: ignore\n        root_logger = lg.getLogger()\n        root_logger.handlers = self.saved_root_handlers\n        if self.saved_root_level is not None:\n            root_logger.setLevel(self.saved_root_level)\n"
  },
  {
    "path": "src/serena/util/shell.py",
    "content": "import os\nimport subprocess\n\nfrom pydantic import BaseModel\n\nfrom solidlsp.util.subprocess_util import subprocess_kwargs\n\n\nclass ShellCommandResult(BaseModel):\n    stdout: str\n    return_code: int\n    cwd: str\n    stderr: str | None = None\n\n\ndef execute_shell_command(command: str, cwd: str | None = None, capture_stderr: bool = False) -> ShellCommandResult:\n    \"\"\"\n    Execute a shell command and return the output.\n\n    :param command: The command to execute.\n    :param cwd: The working directory to execute the command in. If None, the current working directory will be used.\n    :param capture_stderr: Whether to capture the stderr output.\n    :return: The output of the command.\n    \"\"\"\n    if cwd is None:\n        cwd = os.getcwd()\n\n    process = subprocess.Popen(\n        command,\n        shell=True,\n        stdin=subprocess.DEVNULL,\n        stdout=subprocess.PIPE,\n        stderr=subprocess.PIPE if capture_stderr else None,\n        text=True,\n        encoding=\"utf-8\",\n        errors=\"replace\",\n        cwd=cwd,\n        **subprocess_kwargs(),\n    )\n\n    stdout, stderr = process.communicate()\n    return ShellCommandResult(stdout=stdout, stderr=stderr, return_code=process.returncode, cwd=cwd)\n\n\ndef subprocess_check_output(args: list[str], encoding: str = \"utf-8\", strip: bool = True, timeout: float | None = None) -> str:\n    output = subprocess.check_output(args, stdin=subprocess.DEVNULL, stderr=subprocess.PIPE, timeout=timeout, env=os.environ.copy(), **subprocess_kwargs()).decode(encoding)  # type: ignore\n    if strip:\n        output = output.strip()\n    return output\n"
  },
  {
    "path": "src/serena/util/text_utils.py",
    "content": "import fnmatch\nimport logging\nimport os\nimport re\nfrom collections.abc import Callable\nfrom dataclasses import dataclass, field\nfrom enum import StrEnum\nfrom typing import Any, Literal, Self\n\nfrom bs4 import BeautifulSoup\nfrom joblib import Parallel, delayed\n\nfrom serena.constants import DEFAULT_SOURCE_FILE_ENCODING\n\nlog = logging.getLogger(__name__)\n\n\nclass LineType(StrEnum):\n    \"\"\"Enum for different types of lines in search results.\"\"\"\n\n    MATCH = \"match\"\n    \"\"\"Part of the matched lines\"\"\"\n    BEFORE_MATCH = \"prefix\"\n    \"\"\"Lines before the match\"\"\"\n    AFTER_MATCH = \"postfix\"\n    \"\"\"Lines after the match\"\"\"\n\n\n@dataclass(kw_only=True)\nclass TextLine:\n    \"\"\"Represents a line of text with information on how it relates to the match.\"\"\"\n\n    line_number: int\n    line_content: str\n    match_type: LineType\n    \"\"\"Represents the type of line (match, prefix, postfix)\"\"\"\n\n    def get_display_prefix(self) -> str:\n        \"\"\"Get the display prefix for this line based on the match type.\"\"\"\n        if self.match_type == LineType.MATCH:\n            return \"  >\"\n        return \"...\"\n\n    def format_line(self, include_line_numbers: bool = True) -> str:\n        \"\"\"Format the line for display (e.g.,for logging or passing to an LLM).\n\n        :param include_line_numbers: Whether to include the line number in the result.\n        \"\"\"\n        prefix = self.get_display_prefix()\n        if include_line_numbers:\n            line_num = str(self.line_number).rjust(4)\n            prefix = f\"{prefix}{line_num}\"\n        return f\"{prefix}:{self.line_content}\"\n\n\n@dataclass(kw_only=True)\nclass MatchedConsecutiveLines:\n    \"\"\"Represents a collection of consecutive lines found through some criterion in a text file or a string.\n    May include lines before, after, and matched.\n    \"\"\"\n\n    lines: list[TextLine]\n    \"\"\"All lines in the context of the match. At least one of them is of `match_type` `MATCH`.\"\"\"\n    source_file_path: str | None = None\n    \"\"\"Path to the file where the match was found (Metadata).\"\"\"\n\n    # set in post-init\n    lines_before_matched: list[TextLine] = field(default_factory=list)\n    matched_lines: list[TextLine] = field(default_factory=list)\n    lines_after_matched: list[TextLine] = field(default_factory=list)\n\n    def __post_init__(self) -> None:\n        for line in self.lines:\n            if line.match_type == LineType.BEFORE_MATCH:\n                self.lines_before_matched.append(line)\n            elif line.match_type == LineType.MATCH:\n                self.matched_lines.append(line)\n            elif line.match_type == LineType.AFTER_MATCH:\n                self.lines_after_matched.append(line)\n\n        assert len(self.matched_lines) > 0, \"At least one matched line is required\"\n\n    @property\n    def start_line(self) -> int:\n        return self.lines[0].line_number\n\n    @property\n    def end_line(self) -> int:\n        return self.lines[-1].line_number\n\n    @property\n    def num_matched_lines(self) -> int:\n        return len(self.matched_lines)\n\n    def to_display_string(self, include_line_numbers: bool = True) -> str:\n        return \"\\n\".join([line.format_line(include_line_numbers) for line in self.lines])\n\n    @classmethod\n    def from_file_contents(\n        cls, file_contents: str, line: int, context_lines_before: int = 0, context_lines_after: int = 0, source_file_path: str | None = None\n    ) -> Self:\n        line_contents = file_contents.split(\"\\n\")\n        start_lineno = max(0, line - context_lines_before)\n        end_lineno = min(len(line_contents) - 1, line + context_lines_after)\n        text_lines: list[TextLine] = []\n        # before the line\n        for lineno in range(start_lineno, line):\n            text_lines.append(TextLine(line_number=lineno, line_content=line_contents[lineno], match_type=LineType.BEFORE_MATCH))\n        # the line\n        text_lines.append(TextLine(line_number=line, line_content=line_contents[line], match_type=LineType.MATCH))\n        # after the line\n        for lineno in range(line + 1, end_lineno + 1):\n            text_lines.append(TextLine(line_number=lineno, line_content=line_contents[lineno], match_type=LineType.AFTER_MATCH))\n\n        return cls(lines=text_lines, source_file_path=source_file_path)\n\n\ndef glob_to_regex(glob_pat: str) -> str:\n    regex_parts: list[str] = []\n    i = 0\n    while i < len(glob_pat):\n        ch = glob_pat[i]\n        if ch == \"*\":\n            regex_parts.append(\".*\")\n        elif ch == \"?\":\n            regex_parts.append(\"..\")\n        elif ch == \"\\\\\":\n            i += 1\n            if i < len(glob_pat):\n                regex_parts.append(re.escape(glob_pat[i]))\n            else:\n                regex_parts.append(\"\\\\\")\n        else:\n            regex_parts.append(re.escape(ch))\n        i += 1\n    return \"\".join(regex_parts)\n\n\ndef search_text(\n    pattern: str,\n    content: str | None = None,\n    source_file_path: str | None = None,\n    allow_multiline_match: bool = False,\n    context_lines_before: int = 0,\n    context_lines_after: int = 0,\n    is_glob: bool = False,\n) -> list[MatchedConsecutiveLines]:\n    \"\"\"\n    Search for a pattern in text content. Supports both regex and glob-like patterns.\n\n    :param pattern: Pattern to search for (regex or glob-like pattern)\n    :param content: The text content to search. May be None if source_file_path is provided.\n    :param source_file_path: Optional path to the source file. If content is None,\n        this has to be passed and the file will be read.\n    :param allow_multiline_match: Whether to search across multiple lines. Currently, the default\n        option (False) is very inefficient, so it is recommended to set this to True.\n    :param context_lines_before: Number of context lines to include before matches\n    :param context_lines_after: Number of context lines to include after matches\n    :param is_glob: If True, pattern is treated as a glob-like pattern (e.g., \"*.py\", \"test_??.py\")\n             and will be converted to regex internally\n\n    :return: List of `TextSearchMatch` objects\n\n    :raises: ValueError if the pattern is not valid\n\n    \"\"\"\n    if source_file_path and content is None:\n        with open(source_file_path) as f:\n            content = f.read()\n\n    if content is None:\n        raise ValueError(\"Pass either content or source_file_path\")\n\n    matches = []\n    lines = content.splitlines()\n    total_lines = len(lines)\n\n    # Convert pattern to a compiled regex if it's a string\n    if is_glob:\n        pattern = glob_to_regex(pattern)\n    if allow_multiline_match:\n        # For multiline matches, we need to use the DOTALL flag to make '.' match newlines\n        compiled_pattern = re.compile(pattern, re.DOTALL)\n        # Search across the entire content as a single string\n        for match in compiled_pattern.finditer(content):\n            start_pos = match.start()\n            end_pos = match.end()\n\n            # Find the line numbers for the start and end positions\n            start_line_num = content[:start_pos].count(\"\\n\") + 1\n            end_line_num = content[:end_pos].count(\"\\n\") + 1\n\n            # Calculate the range of lines to include in the context\n            context_start = max(1, start_line_num - context_lines_before)\n            context_end = min(total_lines, end_line_num + context_lines_after)\n\n            # Create TextLine objects for the context\n            context_lines = []\n            for i in range(context_start - 1, context_end):\n                line_num = i + 1\n                if context_start <= line_num < start_line_num:\n                    match_type = LineType.BEFORE_MATCH\n                elif end_line_num < line_num <= context_end:\n                    match_type = LineType.AFTER_MATCH\n                else:\n                    match_type = LineType.MATCH\n\n                context_lines.append(TextLine(line_number=line_num, line_content=lines[i], match_type=match_type))\n\n            matches.append(MatchedConsecutiveLines(lines=context_lines, source_file_path=source_file_path))\n    else:\n        # TODO: extremely inefficient! Since we currently don't use this option in SerenaAgent or LanguageServer,\n        #   it is not urgent to fix, but should be either improved or the option should be removed.\n        # Search line by line, normal compile without DOTALL\n        compiled_pattern = re.compile(pattern)\n        for i, line in enumerate(lines):\n            line_num = i + 1\n            if compiled_pattern.search(line):\n                # Calculate the range of lines to include in the context\n                context_start = max(0, i - context_lines_before)\n                context_end = min(total_lines - 1, i + context_lines_after)\n\n                # Create TextLine objects for the context\n                context_lines = []\n                for j in range(context_start, context_end + 1):\n                    context_line_num = j + 1\n                    if j < i:\n                        match_type = LineType.BEFORE_MATCH\n                    elif j > i:\n                        match_type = LineType.AFTER_MATCH\n                    else:\n                        match_type = LineType.MATCH\n\n                    context_lines.append(TextLine(line_number=context_line_num, line_content=lines[j], match_type=match_type))\n\n                matches.append(MatchedConsecutiveLines(lines=context_lines, source_file_path=source_file_path))\n\n    return matches\n\n\ndef default_file_reader(file_path: str) -> str:\n    \"\"\"Reads using the default encoding.\"\"\"\n    with open(file_path, encoding=DEFAULT_SOURCE_FILE_ENCODING) as f:\n        return f.read()\n\n\ndef expand_braces(pattern: str) -> list[str]:\n    \"\"\"\n    Expands brace patterns in a glob string.\n    For example, \"**/*.{js,jsx,ts,tsx}\" becomes [\"**/*.js\", \"**/*.jsx\", \"**/*.ts\", \"**/*.tsx\"].\n    Handles multiple brace sets as well.\n    \"\"\"\n    patterns = [pattern]\n    while any(\"{\" in p for p in patterns):\n        new_patterns = []\n        for p in patterns:\n            match = re.search(r\"\\{([^{}]+)\\}\", p)\n            if match:\n                prefix = p[: match.start()]\n                suffix = p[match.end() :]\n                options = match.group(1).split(\",\")\n                for option in options:\n                    new_patterns.append(f\"{prefix}{option}{suffix}\")\n            else:\n                new_patterns.append(p)\n        patterns = new_patterns\n    return patterns\n\n\ndef glob_match(pattern: str, path: str) -> bool:\n    \"\"\"\n    Match a file path against a glob pattern.\n\n    Supports standard glob patterns:\n    - * matches any number of characters except /\n    - ** matches any number of directories (zero or more)\n    - ? matches a single character except /\n    - [seq] matches any character in seq\n\n    Supports brace expansion:\n    - {a,b,c} expands to multiple patterns (including nesting)\n\n    Unsupported patterns:\n    - Bash extended glob features are unavailable in Python's fnmatch\n    - Extended globs like !(), ?(), +(), *(), @() are not supported\n\n    :param pattern: Glob pattern (e.g., 'src/**/*.py', '**agent.py')\n    :param path: File path to match against\n    :return: True if path matches pattern\n    \"\"\"\n    pattern = pattern.replace(\"\\\\\", \"/\")  # Normalize backslashes to forward slashes\n    path = path.replace(\"\\\\\", \"/\")  # Normalize path backslashes to forward slashes\n\n    # Handle ** patterns that should match zero or more directories\n    if \"**\" in pattern:\n        # Method 1: Standard fnmatch (matches one or more directories)\n        regex1 = fnmatch.translate(pattern)\n        if re.match(regex1, path):\n            return True\n\n        # Method 2: Handle zero-directory case by removing /** entirely\n        # Convert \"src/**/test.py\" to \"src/test.py\"\n        if \"/**/\" in pattern:\n            zero_dir_pattern = pattern.replace(\"/**/\", \"/\")\n            regex2 = fnmatch.translate(zero_dir_pattern)\n            if re.match(regex2, path):\n                return True\n\n        # Method 3: Handle leading ** case by removing **/\n        # Convert \"**/test.py\" to \"test.py\"\n        if pattern.startswith(\"**/\"):\n            zero_dir_pattern = pattern[3:]  # Remove \"**/\"\n            regex3 = fnmatch.translate(zero_dir_pattern)\n            if re.match(regex3, path):\n                return True\n\n        return False\n    else:\n        # Simple pattern without **, use fnmatch directly\n        return fnmatch.fnmatch(path, pattern)\n\n\ndef search_files(\n    relative_file_paths: list[str],\n    pattern: str,\n    root_path: str = \"\",\n    file_reader: Callable[[str], str] = default_file_reader,\n    context_lines_before: int = 0,\n    context_lines_after: int = 0,\n    paths_include_glob: str | None = None,\n    paths_exclude_glob: str | None = None,\n) -> list[MatchedConsecutiveLines]:\n    \"\"\"\n    Search for a pattern in a list of files.\n\n    :param relative_file_paths: List of relative file paths in which to search\n    :param pattern: Pattern to search for\n    :param root_path: Root path to resolve relative paths against (by default, current working directory).\n    :param file_reader: Function to read a file, by default will just use os.open.\n        All files that can't be read by it will be skipped.\n    :param context_lines_before: Number of context lines to include before matches\n    :param context_lines_after: Number of context lines to include after matches\n    :param paths_include_glob: Optional glob pattern to include files from the list\n    :param paths_exclude_glob: Optional glob pattern to exclude files from the list\n    :return: List of MatchedConsecutiveLines objects\n    \"\"\"\n    # Pre-filter paths (done sequentially to avoid overhead)\n    # Use proper glob matching instead of gitignore patterns\n    include_patterns = expand_braces(paths_include_glob) if paths_include_glob else None\n    exclude_patterns = expand_braces(paths_exclude_glob) if paths_exclude_glob else None\n\n    filtered_paths = []\n    for path in relative_file_paths:\n        if include_patterns:\n            if not any(glob_match(p, path) for p in include_patterns):\n                log.debug(f\"Skipping {path}: does not match include pattern {paths_include_glob}\")\n                continue\n\n        if exclude_patterns:\n            if any(glob_match(p, path) for p in exclude_patterns):\n                log.debug(f\"Skipping {path}: matches exclude pattern {paths_exclude_glob}\")\n                continue\n\n        filtered_paths.append(path)\n\n    log.info(f\"Processing {len(filtered_paths)} files.\")\n\n    def process_single_file(path: str) -> dict[str, Any]:\n        \"\"\"Process a single file - this function will be parallelized.\"\"\"\n        try:\n            abs_path = os.path.join(root_path, path)\n            file_content = file_reader(abs_path)\n            search_results = search_text(\n                pattern,\n                content=file_content,\n                source_file_path=path,\n                allow_multiline_match=True,\n                context_lines_before=context_lines_before,\n                context_lines_after=context_lines_after,\n            )\n            if len(search_results) > 0:\n                log.debug(f\"Found {len(search_results)} matches in {path}\")\n            return {\"path\": path, \"results\": search_results, \"error\": None}\n        except Exception as e:\n            log.debug(f\"Error processing {path}: {e}\")\n            return {\"path\": path, \"results\": [], \"error\": str(e)}\n\n    # Execute in parallel using joblib\n    results = Parallel(\n        n_jobs=-1,\n        backend=\"threading\",\n    )(delayed(process_single_file)(path) for path in filtered_paths)\n\n    # Collect results and errors\n    matches = []\n    skipped_file_error_tuples = []\n\n    for result in results:\n        if result[\"error\"]:\n            skipped_file_error_tuples.append((result[\"path\"], result[\"error\"]))\n        else:\n            matches.extend(result[\"results\"])\n\n    if skipped_file_error_tuples:\n        log.debug(f\"Failed to read {len(skipped_file_error_tuples)} files: {skipped_file_error_tuples}\")\n\n    log.info(f\"Found {len(matches)} total matches across {len(filtered_paths)} files\")\n    return matches\n\n\ndef render_html(html: str) -> str:\n    \"\"\"\n    Remove HTML tags and decode HTML entities from text while preserving the actual content.\n    This keeps type information and structure but removes all formatting.\n\n    :param html: HTML text to clean\n    :return: Plain text without HTML tags and with decoded entities\n    \"\"\"\n    soup = BeautifulSoup(html, \"html.parser\")\n    # join text with spaces to avoid concatenation of words\n    text = soup.get_text(separator=\" \", strip=True)\n\n    # normalize non-breaking spaces\n    text = text.replace(\"\\xa0\", \" \")\n\n    return text.strip()\n\n\nclass ContentReplacer:\n    \"\"\"\n    This is an LLM-optimised content replacer, which elegantly circumvents escaping and which\n    provides dual modes for maximum flexibility.\n    \"\"\"\n\n    def __init__(self, mode: Literal[\"literal\", \"regex\"], allow_multiple_occurrences: bool):\n        \"\"\"\n\n        :param mode: the mode indicating whether to the needle in replacements corresponds to a regular expression\n            (mode \"regex\") or to a literal string (mode \"literal\")\n        :param allow_multiple_occurrences: whether it is allowed that the search expression matches multiple occurrences.\n            If False, an error will be raised if more than one match is found.\n        \"\"\"\n        self.mode = mode\n        self.allow_multiple_occurrences = allow_multiple_occurrences\n\n    @staticmethod\n    def _create_replacement_function(regex_pattern: str, repl_template: str, regex_flags: int) -> Callable[[re.Match], str]:\n        \"\"\"\n        Creates a replacement function that validates for ambiguity and handles backreferences.\n\n        :param regex_pattern: The regex pattern being used for matching\n        :param repl_template: The replacement template with $!1, $!2, etc. for backreferences\n        :param regex_flags: The flags to use when searching (e.g., re.DOTALL | re.MULTILINE)\n        :return: A function suitable for use with re.sub() or re.subn()\n        \"\"\"\n\n        def validate_and_replace(match: re.Match) -> str:\n            matched_text = match.group(0)\n\n            # For multi-line match, check if the same pattern matches again within the already-matched text,\n            # rendering the match ambiguous. Typical pattern in the code:\n            #    <start><other-stuff><start><stuff><end>\n            # When matching\n            #    <start>.*?<end>\n            # this will match the entire span above, while only the suffix may have been intended.\n            # (See test case for a practical example.)\n            # To detect this, we check if the same pattern matches again within the matched text,\n            if \"\\n\" in matched_text and re.search(regex_pattern, matched_text[1:], flags=regex_flags):\n                raise ValueError(\n                    \"Match is ambiguous: the search pattern matches multiple overlapping occurrences. \"\n                    \"Please revise the search pattern to be more specific to avoid ambiguity, \"\n                    \"e.g. by matching specific context after the match, or try using the literal mode.\"\n                )\n\n            # Handle backreferences: replace $!1, $!2, etc. with actual matched groups\n            def expand_backreference(m: re.Match) -> str:\n                group_num = int(m.group(1))\n                group_value = match.group(group_num)\n                return group_value if group_value is not None else m.group(0)\n\n            result = re.sub(r\"\\$!(\\d+)\", expand_backreference, repl_template)\n            return result\n\n        return validate_and_replace\n\n    def replace(\n        self,\n        content: str,\n        needle: str,\n        repl: str,\n    ) -> str:\n        \"\"\"\n        Performs the replacement.\n\n        Raises ValueError if no match is found, or if multiple matches are found while allow_multiple_occurrences is False.\n\n        :param content: the content in which to perform the replacement\n        :param needle: the search expression, which is either a literal string or a regular expression, depending on the mode\n        :param repl: the replacement string, which, in regex mode, may contain backreferences in the form of $!1, $!2, etc. to\n            refer to matched groups in the search expression\n        :return: the updated content after performing the replacement\n        \"\"\"\n        if self.mode == \"literal\":\n            regex = re.escape(needle)\n        elif self.mode == \"regex\":\n            regex = needle\n        else:\n            raise ValueError(f\"Invalid mode: '{self.mode}', expected 'literal' or 'regex'.\")\n\n        regex_flags = re.DOTALL | re.MULTILINE\n\n        # create replacement function with validation and backreference handling\n        repl_fn = self._create_replacement_function(regex, repl, regex_flags=regex_flags)\n\n        # perform replacement\n        updated_content, n = re.subn(regex, repl_fn, content, flags=regex_flags)\n\n        if n == 0:\n            raise ValueError(\"Error: No matches of search expression found.\")\n        if not self.allow_multiple_occurrences and n > 1:\n            raise ValueError(\n                f\"Expression matches {n} occurrences. \"\n                \"Please revise the expression to be more specific or enable allow_multiple_occurrences if this is expected.\"\n            )\n        return updated_content\n"
  },
  {
    "path": "src/serena/util/thread.py",
    "content": "import threading\nfrom collections.abc import Callable\nfrom enum import Enum\nfrom typing import Generic, TypeVar\n\nfrom sensai.util.string import ToStringMixin\n\n\nclass TimeoutException(Exception):\n    def __init__(self, message: str, timeout: float) -> None:\n        super().__init__(message)\n        self.timeout = timeout\n\n\nT = TypeVar(\"T\")\n\n\nclass ExecutionResult(Generic[T], ToStringMixin):\n\n    class Status(Enum):\n        SUCCESS = \"success\"\n        TIMEOUT = \"timeout\"\n        EXCEPTION = \"error\"\n\n    def __init__(self) -> None:\n        self.result_value: T | None = None\n        self.status: ExecutionResult.Status | None = None\n        self.exception: Exception | None = None\n\n    def set_result_value(self, value: T) -> None:\n        self.result_value = value\n        self.status = ExecutionResult.Status.SUCCESS\n\n    def set_timed_out(self, exception: TimeoutException) -> None:\n        self.exception = exception\n        self.status = ExecutionResult.Status.TIMEOUT\n\n    def set_exception(self, exception: Exception) -> None:\n        self.exception = exception\n        self.status = ExecutionResult.Status.EXCEPTION\n\n\ndef execute_with_timeout(func: Callable[[], T], timeout: float, function_name: str) -> ExecutionResult[T]:\n    \"\"\"\n    Executes the given function with a timeout\n\n    :param func: the function to execute\n    :param timeout: the timeout in seconds\n    :param function_name: the name of the function (for error messages)\n    :returns: the execution result\n    \"\"\"\n    execution_result: ExecutionResult[T] = ExecutionResult()\n\n    def target() -> None:\n        try:\n            value = func()\n            execution_result.set_result_value(value)\n        except Exception as e:\n            execution_result.set_exception(e)\n\n    thread = threading.Thread(target=target, daemon=True)\n    thread.start()\n    thread.join(timeout=timeout)\n\n    if thread.is_alive():\n        timeout_exception = TimeoutException(f\"Execution of '{function_name}' timed out after {timeout} seconds.\", timeout)\n        execution_result.set_timed_out(timeout_exception)\n\n    return execution_result\n"
  },
  {
    "path": "src/serena/util/version.py",
    "content": "class Version:\n    \"\"\"\n    Represents a version, specifically the numeric components of a version string.\n\n    Suffixes like \"rc1\" or \"-dev\" are ignored, i.e. for a version string like \"1.2.3rc1\",\n    the components are [1, 2, 3].\n    \"\"\"\n\n    def __init__(self, package_or_version: object | str):\n        \"\"\"\n        :param package_or_version: a package object (with a `__version__` attribute) or a version string like \"1.2.3\".\n            If a version contains a suffix (like \"1.2.3rc1\" or \"1.2.3-dev\"), the suffix is ignored.\n        \"\"\"\n        if isinstance(package_or_version, str):\n            version_string = package_or_version\n        elif hasattr(package_or_version, \"__version__\"):\n            package_version_string = getattr(package_or_version, \"__version__\", None)\n            if package_version_string is None:\n                raise ValueError(f\"The given package object {package_or_version} has no __version__ attribute\")\n            version_string = package_version_string\n        else:\n            raise ValueError(\"The given argument must be either a version string or a package object with a __version__ attribute\")\n        self.version_string = version_string\n        self.components = self._get_version_components(version_string)\n\n    def __repr__(self) -> str:\n        return self.version_string\n\n    @staticmethod\n    def _get_version_components(version_string: str) -> list[int]:\n        components = version_string.split(\".\")\n        int_components = []\n        for c in components:\n            num_str = \"\"\n            for ch in c:\n                if ch.isdigit():\n                    num_str += ch\n                else:\n                    break\n            if num_str == \"\":\n                break\n            int_components.append(int(num_str))\n        return int_components\n\n    def is_at_least(self, *components: int) -> bool:\n        \"\"\"\n        Checks this version against the given version components.\n        This version object must contain at least the respective number of components\n\n        :param components: version components in order (i.e. major, minor, patch, etc.)\n        :return: True if the version is at least the given version, False otherwise\n        \"\"\"\n        for i, desired_min_version in enumerate(components):\n            actual_version = self.components[i]\n            if actual_version < desired_min_version:\n                return False\n            elif actual_version > desired_min_version:\n                return True\n        return True\n\n    def is_at_most(self, *components: int) -> bool:\n        \"\"\"\n        Checks this version against the given version components.\n        This version object must contain at least the respective number of components\n\n        :param components: version components in order (i.e. major, minor, patch, etc.)\n        :return: True if the version is at most the given version, False otherwise\n        \"\"\"\n        for i, desired_max_version in enumerate(components):\n            actual_version = self.components[i]\n            if actual_version > desired_max_version:\n                return False\n            elif actual_version < desired_max_version:\n                return True\n        return True\n\n    def is_equal(self, *components: int) -> bool:\n        \"\"\"\n        Checks this version against the given version components.\n        This version object must contain at least the respective number of components\n\n        :param components: version components in order (i.e. major, minor, patch, etc.)\n        :return: True if the version is the given version, False otherwise\n        \"\"\"\n        return self.components[: len(components)] == list(components)\n"
  },
  {
    "path": "src/serena/util/yaml.py",
    "content": "import logging\nimport os\nfrom collections.abc import Sequence\nfrom enum import Enum\nfrom typing import Any\n\nfrom ruamel.yaml import YAML, CommentToken, StreamMark\nfrom ruamel.yaml.comments import CommentedMap\n\nfrom serena.constants import SERENA_FILE_ENCODING\n\nlog = logging.getLogger(__name__)\n\n\ndef _create_yaml(preserve_comments: bool = False) -> YAML:\n    \"\"\"\n    Creates a YAML that can load/save with comments if preserve_comments is True.\n    \"\"\"\n    typ = None if preserve_comments else \"safe\"\n    result = YAML(typ=typ)\n    result.preserve_quotes = preserve_comments\n    return result\n\n\nclass YamlCommentNormalisation(Enum):\n    \"\"\"\n    Defines a normalisation to be applied to the comment representation in a ruamel CommentedMap.\n\n    Note that even though a YAML document may seem to consistently contain, for example, leading comments\n    before a key only, ruamel may still parse some comments as trailing comments of the previous key\n    or as document-level comments.\n    The normalisations define ways to adjust the comment representation accordingly, clearly associating\n    comments with the keys they belong to.\n    \"\"\"\n\n    NONE = \"none\"\n    \"\"\"\n    No comment normalisation is performed.\n    Comments are kept as parsed by ruamel.yaml.\n    \"\"\"\n    LEADING = \"leading\"\n    \"\"\"\n    Document is assumed to have leading comments only, i.e. comments before keys, only full-line comments.\n    This normalisation achieves that comments are properly associated with keys as leading comments.\n    \"\"\"\n    LEADING_WITH_CONVERSION_FROM_TRAILING = \"leading_with_conversion_from_trailing\"\n    \"\"\"\n    Document is assumed to have a mixture of leading comments (before keys) and trailing comments (after values), only full-line comments.\n    This normalisation achieves that all comments are converted to leading comments and properly associated with keys.\n    \"\"\"\n    # NOTE: Normalisation for trailing comments was attempted but is extremely hard, because\n    #  it is difficult to position the comments properly after values, especially for complex values.\n\n\nDOC_COMMENT_INDEX_POST = 0\nDOC_COMMENT_INDEX_PRE = 1\n\n# item comment indices: (post key, pre key, post value, pre value)\nITEM_COMMENT_INDEX_BEFORE = 1  # (pre-key; must be a list of CommentToken at this index)\nITEM_COMMENT_INDEX_AFTER = 2  # (post-value; must be an instance of CommentToken at this index)\n\n\ndef load_yaml(path: str, comment_normalisation: YamlCommentNormalisation = YamlCommentNormalisation.NONE) -> CommentedMap:\n    \"\"\"\n    :param path: the path to the YAML file to load\n    :param comment_normalisation: the comment normalisation to apply after loading\n    :return: the loaded commented map\n    \"\"\"\n    with open(path, encoding=SERENA_FILE_ENCODING) as f:\n        yaml = _create_yaml(preserve_comments=True)\n        commented_map: CommentedMap | None = yaml.load(f)\n    if commented_map is None:  # ruamel returns None for empty documents, but we want an empty CommentedMap\n        commented_map = CommentedMap()\n    normalise_yaml_comments(commented_map, comment_normalisation)\n    return commented_map\n\n\ndef normalise_yaml_comments(commented_map: CommentedMap, comment_normalisation: YamlCommentNormalisation) -> None:\n    \"\"\"\n    Applies the given comment normalisation to the given commented map in-place.\n\n    :param commented_map: the commented map whose comments are to be normalised\n    :param comment_normalisation: the comment normalisation to apply\n    \"\"\"\n\n    def make_list(comment_entry: Any) -> list:\n        if not isinstance(comment_entry, list):\n            return [comment_entry]\n        return comment_entry\n\n    def make_unit(comment_entry: Any) -> Any:\n        \"\"\"\n        Converts a list-valued comment entry into a single comment entry.\n        \"\"\"\n        if isinstance(comment_entry, list):\n            if len(comment_entry) == 0:\n                return None\n            elif len(comment_entry) == 1:\n                return comment_entry[0]\n            else:\n                if all(isinstance(item, CommentToken) for item in comment_entry):\n                    start_mark = StreamMark(name=\"\", index=0, line=0, column=0)\n                    comment_str = \"\".join(item.value for item in comment_entry)\n                    if not comment_str.startswith(\"\\n\"):\n                        comment_str = \"\\n\" + comment_str\n                    return CommentToken(value=comment_str, start_mark=start_mark, end_mark=None)\n                else:\n                    types = set(type(item) for item in comment_entry)\n                    log.warning(\"Unhandled types in list-valued comment entry: %s; not updating entry\", types)\n                    return None\n        else:\n            return comment_entry\n\n    def trailing_to_leading(comment_entry: Any) -> Any:\n        if comment_entry is None:\n            return None\n        token_list = make_list(comment_entry)\n        first_token = token_list[0]\n        if isinstance(first_token, CommentToken):\n            # remove leading newline if present\n            if first_token.value.startswith(\"\\n\"):\n                first_token.value = first_token.value[1:]\n        return token_list\n\n    match comment_normalisation:\n        case YamlCommentNormalisation.NONE:\n            pass\n        case YamlCommentNormalisation.LEADING | YamlCommentNormalisation.LEADING_WITH_CONVERSION_FROM_TRAILING:\n            # Comments are supposed to be leading comments (i.e., before a key and associated with the key).\n            # When ruamel parses a YAML, however, comments belonging to a key may be stored as trailing\n            # comments of the previous key or as a document-level comment.\n            # Move them accordingly.\n            keys = list(commented_map.keys())\n            comment_items = commented_map.ca.items\n            doc_comment = commented_map.ca.comment\n            preceding_comment = None\n            for i, key in enumerate(keys):\n                current_comment = comment_items.get(key, [None] * 4)\n                comment_items[key] = current_comment\n                if current_comment[ITEM_COMMENT_INDEX_BEFORE] is None:\n                    if i == 0 and doc_comment is not None and doc_comment[DOC_COMMENT_INDEX_PRE] is not None:\n                        # move document pre-comment to leading comment of first key\n                        current_comment[ITEM_COMMENT_INDEX_BEFORE] = make_list(doc_comment[DOC_COMMENT_INDEX_PRE])\n                        doc_comment[DOC_COMMENT_INDEX_PRE] = None\n                    elif preceding_comment is not None and preceding_comment[ITEM_COMMENT_INDEX_AFTER] is not None:\n                        # move trailing comment of preceding key to leading comment of current key\n                        current_comment[ITEM_COMMENT_INDEX_BEFORE] = trailing_to_leading(preceding_comment[ITEM_COMMENT_INDEX_AFTER])\n                        preceding_comment[ITEM_COMMENT_INDEX_AFTER] = None\n                preceding_comment = current_comment\n\n            if comment_normalisation == YamlCommentNormalisation.LEADING_WITH_CONVERSION_FROM_TRAILING:\n                # Second pass: conversion of trailing comments\n                # If a leading comment ends with \"\\n\\n\", i.e. it has an empty line between the comment and the key,\n                # it was actually intended as a trailing comment for the preceding key, so we associate it with\n                # the preceding key instead (if the preceding key has no leading comment already).\n                preceding_comment = None\n                for key in keys:\n                    current_comment = comment_items.get(key, [None] * 4)\n                    if current_comment[ITEM_COMMENT_INDEX_BEFORE] is not None:\n                        token_list = make_list(current_comment[ITEM_COMMENT_INDEX_BEFORE])\n                        if len(token_list) > 0:\n                            last_token = token_list[-1]\n                            if isinstance(last_token, CommentToken) and last_token.value.endswith(\"\\n\\n\"):\n                                # move comment to preceding key, removing the empty line,\n                                # and adding an empty line at the beginning instead\n                                if preceding_comment is not None and yaml_comment_entry_is_empty(\n                                    preceding_comment[ITEM_COMMENT_INDEX_BEFORE]\n                                ):\n                                    last_token.value = last_token.value[:-1]\n\n                                    first_token = token_list[0]\n                                    if isinstance(first_token, CommentToken):\n                                        if not first_token.value.startswith(\"\\n\"):\n                                            first_token.value = \"\\n\" + first_token.value\n\n                                    preceding_comment[ITEM_COMMENT_INDEX_BEFORE] = token_list\n                                    current_comment[ITEM_COMMENT_INDEX_BEFORE] = None\n                    preceding_comment = current_comment\n        case _:\n            raise ValueError(f\"Unhandled comment normalisation: {comment_normalisation}\")\n\n\ndef save_yaml(path: str, data: dict | CommentedMap, preserve_comments: bool = True) -> None:\n    yaml = _create_yaml(preserve_comments)\n    os.makedirs(os.path.dirname(path), exist_ok=True)\n    with open(path, \"w\", encoding=SERENA_FILE_ENCODING) as f:\n        yaml.dump(data, f)\n\n\ndef yaml_comment_entry_is_empty(comment_entry: Any) -> bool:\n    if comment_entry is None:\n        return True\n    elif isinstance(comment_entry, list):\n        for item in comment_entry:\n            if isinstance(item, CommentToken):\n                if item.value.strip() != \"\":\n                    return False\n            else:\n                return False\n        return True\n    elif isinstance(comment_entry, CommentToken):\n        return comment_entry.value.strip() == \"\"\n    else:\n        return False\n\n\ndef transfer_missing_yaml_comments_by_index(\n    source: CommentedMap, target: CommentedMap, indices: list[int], forced_update_keys: Sequence[str] = ()\n) -> None:\n    \"\"\"\n    :param source: the source, from which to transfer missing comments\n    :param target: the target map, whose comments will be updated\n    :param indices: list of comment indices to transfer\n    :param forced_update_keys: keys for which comments are always transferred, even if present in target\n    \"\"\"\n    for key in target.keys():\n        if key in source:\n            source_comment = source.ca.items.get(key)\n            if source_comment is None:\n                continue\n            target_comment = target.ca.items.get(key)\n            # initialise target comment if needed\n            if target_comment is None:\n                target_comment = [None] * 4\n                target.ca.items[key] = target_comment\n            # transfer comments at specified indices\n            for index in indices:\n                is_forced_update = key in forced_update_keys\n                if is_forced_update or yaml_comment_entry_is_empty(target_comment[index]):\n                    target_comment[index] = source_comment[index]\n\n\ndef transfer_missing_yaml_comments(\n    source: CommentedMap, target: CommentedMap, comment_normalisation: YamlCommentNormalisation, forced_update_keys: Sequence[str] = ()\n) -> None:\n    \"\"\"\n    Transfers missing comments from source to target YAML.\n\n    :param source: the source, from which to transfer missing comments\n    :param target: the target map, whose comments will be updated.\n    :param comment_normalisation: the comment normalisation to assume; if NONE, no comments are transferred\n    :param forced_update_keys: keys for which comments are always transferred, even if present in target\n    \"\"\"\n    match comment_normalisation:\n        case YamlCommentNormalisation.NONE:\n            pass\n        case YamlCommentNormalisation.LEADING | YamlCommentNormalisation.LEADING_WITH_CONVERSION_FROM_TRAILING:\n            transfer_missing_yaml_comments_by_index(source, target, [ITEM_COMMENT_INDEX_BEFORE], forced_update_keys=forced_update_keys)\n        case _:\n            raise ValueError(f\"Unhandled comment normalisation: {comment_normalisation}\")\n"
  },
  {
    "path": "src/solidlsp/.gitignore",
    "content": "language_servers/static"
  },
  {
    "path": "src/solidlsp/__init__.py",
    "content": "# ruff: noqa\r\nfrom .ls import SolidLanguageServer\r\n"
  },
  {
    "path": "src/solidlsp/language_servers/al_language_server.py",
    "content": "\"\"\"AL Language Server implementation for Microsoft Dynamics 365 Business Central.\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport platform\nimport re\nimport stat\nimport time\nimport zipfile\nfrom pathlib import Path\n\nimport requests\nfrom overrides import override\n\nfrom solidlsp import ls_types\nfrom solidlsp.language_servers.common import quote_windows_path\nfrom solidlsp.ls import DocumentSymbols, LSPFileBuffer, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.ls_types import SymbolKind, UnifiedSymbolInformation\nfrom solidlsp.lsp_protocol_handler.lsp_types import Definition, DefinitionParams, LocationLink\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass ALLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Language server implementation for AL (Microsoft Dynamics 365 Business Central).\n\n    This implementation uses the AL Language Server from the VS Code AL extension\n    (ms-dynamics-smb.al). The extension must be installed or available locally.\n\n    Key Features:\n    - Automatic download of AL extension from VS Code marketplace if not present\n    - Platform-specific executable detection (Windows/Linux/macOS)\n    - Special initialization sequence required by AL Language Server\n    - Custom AL-specific LSP commands (al/gotodefinition, al/setActiveWorkspace)\n    - File opening requirement before symbol retrieval\n    \"\"\"\n\n    # Regex pattern to match AL object names like:\n    # - 'Table 50000 \"TEST Customer\"' -> captures 'TEST Customer'\n    # - 'Codeunit 50000 CustomerMgt' -> captures 'CustomerMgt'\n    # - 'Interface IPaymentProcessor' -> captures 'IPaymentProcessor'\n    # - 'Enum 50000 CustomerType' -> captures 'CustomerType'\n    # Pattern: <ObjectType> [<ID>] (<QuotedName>|<UnquotedName>)\n    _AL_OBJECT_NAME_PATTERN = re.compile(\n        r\"^(?:Table|Page|Codeunit|Enum|Interface|Report|Query|XMLPort|PermissionSet|\"\n        r\"PermissionSetExtension|Profile|PageExtension|TableExtension|EnumExtension|\"\n        r\"PageCustomization|ReportExtension|ControlAddin|DotNetPackage)\"  # Object type\n        r\"(?:\\s+\\d+)?\"  # Optional object ID\n        r\"\\s+\"  # Required space before name\n        r'(?:\"([^\"]+)\"|(\\S+))$'  # Quoted name (group 1) or unquoted identifier (group 2)\n    )\n\n    @staticmethod\n    def _extract_al_display_name(full_name: str) -> str:\n        \"\"\"\n        Extract the display name from an AL symbol's full name.\n\n        AL Language Server returns symbol names in format:\n        - 'Table 50000 \"TEST Customer\"' -> 'TEST Customer'\n        - 'Codeunit 50000 CustomerMgt' -> 'CustomerMgt'\n        - 'Interface IPaymentProcessor' -> 'IPaymentProcessor'\n        - 'fields' -> 'fields' (non-AL-object symbols pass through unchanged)\n\n        Args:\n            full_name: The full symbol name as returned by AL Language Server\n\n        Returns:\n            The extracted display name for matching, or the original name if not an AL object\n\n        \"\"\"\n        match = ALLanguageServer._AL_OBJECT_NAME_PATTERN.match(full_name)\n        if match:\n            # Return quoted name (group 1) or unquoted name (group 2)\n            return match.group(1) or match.group(2) or full_name\n        return full_name\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Initialize the AL Language Server.\n\n        Args:\n            config: Language server configuration\n            logger: Logger instance for debugging\n            repository_root_path: Root path of the AL project (must contain app.json)\n            solidlsp_settings: Solid LSP settings\n\n        Note:\n            The initialization process will automatically:\n            1. Check for AL extension in the resources directory\n            2. Download it from VS Code marketplace if not found\n            3. Extract and configure the platform-specific executable\n\n        \"\"\"\n        # Setup runtime dependencies and get the language server command\n        # This will download the AL extension if needed\n        cmd = self._setup_runtime_dependencies(config, solidlsp_settings)\n\n        self._project_load_check_supported: bool = True\n        \"\"\"Whether the AL server supports the project load status check request.\n        \n        Some AL server versions don't support the 'al/hasProjectClosureLoadedRequest'\n        custom LSP request. This flag starts as True and is set to False if the\n        request fails, preventing repeated unsuccessful attempts.\n        \"\"\"\n\n        super().__init__(config, repository_root_path, ProcessLaunchInfo(cmd=cmd, cwd=repository_root_path), \"al\", solidlsp_settings)\n\n        # Cache mapping (file_path, line, char) -> original_full_name for hover injection\n        self._al_original_names: dict[tuple[str, int, int], str] = {}\n\n    @staticmethod\n    def _normalize_path(path: str) -> str:\n        \"\"\"Normalize file path for consistent cache key usage across platforms.\"\"\"\n        return path.replace(\"\\\\\", \"/\")\n\n    @classmethod\n    def _download_al_extension(cls, url: str, target_dir: str) -> bool:\n        \"\"\"\n        Download and extract the AL extension from VS Code marketplace.\n\n        The VS Code marketplace packages extensions as .vsix files (which are ZIP archives).\n        This method downloads the VSIX file and extracts it to get the language server binaries.\n\n        Args:\n            logger: Logger for tracking download progress\n            url: VS Code marketplace URL for the AL extension\n            target_dir: Directory where the extension will be extracted\n\n        Returns:\n            True if successful, False otherwise\n\n        Note:\n            The download includes progress tracking and proper user-agent headers\n            to ensure compatibility with the VS Code marketplace.\n\n        \"\"\"\n        try:\n            log.info(f\"Downloading AL extension from {url}\")\n\n            # Create target directory for the extension\n            os.makedirs(target_dir, exist_ok=True)\n\n            # Download with proper headers to mimic VS Code marketplace client\n            # These headers are required for the marketplace to serve the VSIX file\n            headers = {\n                \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\",\n                \"Accept\": \"application/octet-stream, application/vsix, */*\",\n            }\n\n            response = requests.get(url, headers=headers, stream=True, timeout=300)\n            response.raise_for_status()\n\n            # Save to temporary VSIX file (will be deleted after extraction)\n            temp_file = os.path.join(target_dir, \"al_extension_temp.vsix\")\n            total_size = int(response.headers.get(\"content-length\", 0))\n\n            log.info(f\"Downloading {total_size / 1024 / 1024:.1f} MB...\")\n\n            with open(temp_file, \"wb\") as f:\n                downloaded = 0\n                for chunk in response.iter_content(chunk_size=8192):\n                    if chunk:\n                        f.write(chunk)\n                        downloaded += len(chunk)\n                        if total_size > 0 and downloaded % (10 * 1024 * 1024) == 0:  # Log progress every 10MB\n                            progress = (downloaded / total_size) * 100\n                            log.info(f\"Download progress: {progress:.1f}%\")\n\n            log.info(\"Download complete, extracting...\")\n\n            # Extract VSIX file (VSIX files are just ZIP archives with a different extension)\n            # This will extract the extension folder containing the language server binaries\n            with zipfile.ZipFile(temp_file, \"r\") as zip_ref:\n                zip_ref.extractall(target_dir)\n\n            # Clean up temp file\n            os.remove(temp_file)\n\n            log.info(\"AL extension extracted successfully\")\n            return True\n\n        except Exception as e:\n            log.error(f\"Error downloading/extracting AL extension: {e}\")\n            return False\n\n    @classmethod\n    def _setup_runtime_dependencies(cls, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings) -> str:\n        \"\"\"\n        Setup runtime dependencies for AL Language Server and return the command to start the server.\n\n        This method handles the complete setup process:\n        1. Checks for existing AL extension installations\n        2. Downloads from VS Code marketplace if not found\n        3. Configures executable permissions on Unix systems\n        4. Returns the properly formatted command string\n\n        The AL Language Server executable is located in different paths based on the platform:\n        - Windows: bin/win32/Microsoft.Dynamics.Nav.EditorServices.Host.exe\n        - Linux: bin/linux/Microsoft.Dynamics.Nav.EditorServices.Host\n        - macOS: bin/darwin/Microsoft.Dynamics.Nav.EditorServices.Host\n        \"\"\"\n        system = platform.system()\n\n        # Find existing extension or download if needed\n        extension_path = cls._find_al_extension(solidlsp_settings)\n        if extension_path is None:\n            log.info(\"AL extension not found on disk, attempting to download...\")\n            extension_path = cls._download_and_install_al_extension(solidlsp_settings)\n\n        if extension_path is None:\n            raise RuntimeError(\n                \"Failed to locate or download AL Language Server. Please either:\\n\"\n                \"1. Set AL_EXTENSION_PATH environment variable to the AL extension directory\\n\"\n                \"2. Install the AL extension in VS Code (ms-dynamics-smb.al)\\n\"\n                \"3. Ensure internet connection for automatic download\"\n            )\n\n        # Build executable path based on platform\n        executable_path = cls._get_executable_path(extension_path, system)\n\n        if not os.path.exists(executable_path):\n            raise RuntimeError(f\"AL Language Server executable not found at: {executable_path}\")\n\n        # Prepare and return the executable command\n        return cls._prepare_executable(executable_path, system)\n\n    @classmethod\n    def _find_al_extension(cls, solidlsp_settings: SolidLSPSettings) -> str | None:\n        \"\"\"\n        Find AL extension in various locations.\n\n        Search order:\n        1. Environment variable (AL_EXTENSION_PATH)\n        2. Default download location (~/.serena/ls_resources/al-extension)\n        3. VS Code installed extensions\n\n        Returns:\n            Path to AL extension directory or None if not found\n\n        \"\"\"\n        # Check environment variable\n        env_path = os.environ.get(\"AL_EXTENSION_PATH\")\n        if env_path and os.path.exists(env_path):\n            log.debug(f\"Found AL extension via AL_EXTENSION_PATH: {env_path}\")\n            return env_path\n        elif env_path:\n            log.warning(f\"AL_EXTENSION_PATH set but directory not found: {env_path}\")\n\n        # Check default download location\n        default_path = os.path.join(cls.ls_resources_dir(solidlsp_settings), \"al-extension\", \"extension\")\n        if os.path.exists(default_path):\n            log.debug(f\"Found AL extension in default location: {default_path}\")\n            return default_path\n\n        # Search VS Code extensions\n        vscode_path = cls._find_al_extension_in_vscode()\n        if vscode_path:\n            log.debug(f\"Found AL extension in VS Code: {vscode_path}\")\n            return vscode_path\n\n        log.debug(\"AL extension not found in any known location\")\n        return None\n\n    @classmethod\n    def _download_and_install_al_extension(cls, solidlsp_settings: SolidLSPSettings) -> str | None:\n        \"\"\"\n        Download and install AL extension from VS Code marketplace.\n\n        Returns:\n            Path to installed extension or None if download failed\n\n        \"\"\"\n        al_extension_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), \"al-extension\")\n\n        # AL extension version - using latest stable version\n        AL_VERSION = \"latest\"\n        url = f\"https://marketplace.visualstudio.com/_apis/public/gallery/publishers/ms-dynamics-smb/vsextensions/al/{AL_VERSION}/vspackage\"\n\n        log.info(f\"Downloading AL extension from: {url}\")\n\n        if cls._download_al_extension(url, al_extension_dir):\n            extension_path = os.path.join(al_extension_dir, \"extension\")\n            if os.path.exists(extension_path):\n                log.info(\"AL extension downloaded and installed successfully\")\n                return extension_path\n            else:\n                log.error(f\"Download completed but extension not found at: {extension_path}\")\n        else:\n            log.error(\"Failed to download AL extension from marketplace\")\n\n        return None\n\n    @classmethod\n    def _get_executable_path(cls, extension_path: str, system: str) -> str:\n        \"\"\"\n        Build platform-specific executable path.\n\n        Args:\n            extension_path: Path to AL extension directory\n            system: Operating system name\n\n        Returns:\n            Full path to executable\n\n        \"\"\"\n        if system == \"Windows\":\n            return os.path.join(extension_path, \"bin\", \"win32\", \"Microsoft.Dynamics.Nav.EditorServices.Host.exe\")\n        elif system == \"Linux\":\n            return os.path.join(extension_path, \"bin\", \"linux\", \"Microsoft.Dynamics.Nav.EditorServices.Host\")\n        elif system == \"Darwin\":\n            return os.path.join(extension_path, \"bin\", \"darwin\", \"Microsoft.Dynamics.Nav.EditorServices.Host\")\n        else:\n            raise RuntimeError(f\"Unsupported platform: {system}\")\n\n    @classmethod\n    def _prepare_executable(cls, executable_path: str, system: str) -> str:\n        \"\"\"\n        Prepare the executable by setting permissions and handling path quoting.\n\n        Args:\n            executable_path: Path to the executable\n            system: Operating system name\n            logger: Logger instance\n\n        Returns:\n            Properly formatted command string\n\n        \"\"\"\n        # Make sure executable has proper permissions on Unix-like systems\n        if system in [\"Linux\", \"Darwin\"]:\n            st = os.stat(executable_path)\n            os.chmod(executable_path, st.st_mode | stat.S_IEXEC)\n            log.debug(f\"Set execute permission on: {executable_path}\")\n\n        log.info(f\"Using AL Language Server executable: {executable_path}\")\n\n        # The AL Language Server uses stdio for LSP communication by default\n        # Use the utility function to handle Windows path quoting\n        return quote_windows_path(executable_path)\n\n    @classmethod\n    def _get_language_server_command_fallback(cls) -> str:\n        \"\"\"\n        Get the command to start the AL language server.\n\n        Returns:\n            Command string to launch the AL language server\n\n        Raises:\n            RuntimeError: If AL extension cannot be found\n\n        \"\"\"\n        # Check if AL extension path is configured via environment variable\n        al_extension_path = os.environ.get(\"AL_EXTENSION_PATH\")\n\n        if not al_extension_path:\n            # Try to find the extension in the current working directory\n            # (for development/testing when extension is in the serena repo)\n            cwd_path = Path.cwd()\n            potential_extension = None\n\n            # Look for ms-dynamics-smb.al-* directories\n            for item in cwd_path.iterdir():\n                if item.is_dir() and item.name.startswith(\"ms-dynamics-smb.al-\"):\n                    potential_extension = item\n                    break\n\n            if potential_extension:\n                al_extension_path = str(potential_extension)\n                log.debug(f\"Found AL extension in current directory: {al_extension_path}\")\n            else:\n                # Try to find in common VS Code extension locations\n                al_extension_path = cls._find_al_extension_in_vscode()\n\n        if not al_extension_path:\n            raise RuntimeError(\n                \"AL Language Server not found. Please either:\\n\"\n                \"1. Set AL_EXTENSION_PATH environment variable to the VS Code AL extension directory\\n\"\n                \"2. Install the AL extension in VS Code (ms-dynamics-smb.al)\\n\"\n                \"3. Place the extension directory in the current working directory\"\n            )\n\n        # Determine platform-specific executable\n        system = platform.system()\n        if system == \"Windows\":\n            executable = os.path.join(al_extension_path, \"bin\", \"win32\", \"Microsoft.Dynamics.Nav.EditorServices.Host.exe\")\n        elif system == \"Linux\":\n            executable = os.path.join(al_extension_path, \"bin\", \"linux\", \"Microsoft.Dynamics.Nav.EditorServices.Host\")\n        elif system == \"Darwin\":\n            executable = os.path.join(al_extension_path, \"bin\", \"darwin\", \"Microsoft.Dynamics.Nav.EditorServices.Host\")\n        else:\n            raise RuntimeError(f\"Unsupported platform: {system}\")\n\n        # Verify executable exists\n        if not os.path.exists(executable):\n            raise RuntimeError(\n                f\"AL Language Server executable not found at: {executable}\\nPlease ensure the AL extension is properly installed.\"\n            )\n\n        # Make sure executable has proper permissions on Unix-like systems\n        if system in [\"Linux\", \"Darwin\"]:\n            st = os.stat(executable)\n            os.chmod(executable, st.st_mode | stat.S_IEXEC)\n\n        log.info(f\"Using AL Language Server executable: {executable}\")\n\n        # The AL Language Server uses stdio for LSP communication (no --stdio flag needed)\n        # Use the utility function to handle Windows path quoting\n        return quote_windows_path(executable)\n\n    @classmethod\n    def _find_al_extension_in_vscode(cls) -> str | None:\n        \"\"\"\n        Try to find AL extension in common VS Code extension locations.\n\n        Returns:\n            Path to AL extension directory or None if not found\n\n        \"\"\"\n        home = Path.home()\n        possible_paths = []\n\n        # Common VS Code extension paths\n        if platform.system() == \"Windows\":\n            possible_paths.extend(\n                [\n                    home / \".vscode\" / \"extensions\",\n                    home / \".vscode-insiders\" / \"extensions\",\n                    Path(os.environ.get(\"APPDATA\", \"\")) / \"Code\" / \"User\" / \"extensions\",\n                    Path(os.environ.get(\"APPDATA\", \"\")) / \"Code - Insiders\" / \"User\" / \"extensions\",\n                ]\n            )\n        else:\n            possible_paths.extend(\n                [\n                    home / \".vscode\" / \"extensions\",\n                    home / \".vscode-server\" / \"extensions\",\n                    home / \".vscode-insiders\" / \"extensions\",\n                ]\n            )\n\n        for base_path in possible_paths:\n            if base_path.exists():\n                log.debug(f\"Searching for AL extension in: {base_path}\")\n                # Look for AL extension directories\n                for item in base_path.iterdir():\n                    if item.is_dir() and item.name.startswith(\"ms-dynamics-smb.al-\"):\n                        log.debug(f\"Found AL extension at: {item}\")\n                        return str(item)\n\n        return None\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> dict:\n        \"\"\"\n        Returns the initialize params for the AL Language Server.\n        \"\"\"\n        # Ensure we have an absolute path for URI generation\n        repository_path = pathlib.Path(repository_absolute_path).resolve()\n        root_uri = repository_path.as_uri()\n\n        # AL requires extensive capabilities based on VS Code trace\n        initialize_params = {\n            \"processId\": os.getpid(),\n            \"rootPath\": str(repository_path),\n            \"rootUri\": root_uri,\n            \"capabilities\": {\n                \"workspace\": {\n                    \"applyEdit\": True,\n                    \"workspaceEdit\": {\n                        \"documentChanges\": True,\n                        \"resourceOperations\": [\"create\", \"rename\", \"delete\"],\n                        \"failureHandling\": \"textOnlyTransactional\",\n                        \"normalizesLineEndings\": True,\n                    },\n                    \"configuration\": True,\n                    \"didChangeWatchedFiles\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True, \"symbolKind\": {\"valueSet\": list(range(1, 27))}},\n                    \"executeCommand\": {\"dynamicRegistration\": True},\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"workspaceFolders\": True,\n                },\n                \"textDocument\": {\n                    \"synchronization\": {\"dynamicRegistration\": True, \"willSave\": True, \"willSaveWaitUntil\": True, \"didSave\": True},\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"contextSupport\": True,\n                        \"completionItem\": {\n                            \"snippetSupport\": True,\n                            \"commitCharactersSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"deprecatedSupport\": True,\n                            \"preselectSupport\": True,\n                        },\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"definition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentHighlight\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                    },\n                    \"codeAction\": {\"dynamicRegistration\": True},\n                    \"formatting\": {\"dynamicRegistration\": True},\n                    \"rangeFormatting\": {\"dynamicRegistration\": True},\n                    \"rename\": {\"dynamicRegistration\": True, \"prepareSupport\": True},\n                },\n                \"window\": {\n                    \"showMessage\": {\"messageActionItem\": {\"additionalPropertiesSupport\": True}},\n                    \"showDocument\": {\"support\": True},\n                    \"workDoneProgress\": True,\n                },\n            },\n            \"trace\": \"verbose\",\n            \"workspaceFolders\": [{\"uri\": root_uri, \"name\": repository_path.name}],\n        }\n\n        return initialize_params\n\n    @override\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the AL Language Server process and initializes it.\n\n        This method sets up custom notification handlers for AL-specific messages\n        before starting the server. The AL server sends various notifications\n        during initialization and project loading that need to be handled.\n        \"\"\"\n\n        # Set up event handlers\n        def do_nothing(params: str) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"AL LSP: window/logMessage: {msg}\")\n\n        def publish_diagnostics(params: dict) -> None:\n            # AL server publishes diagnostics during initialization\n            uri = params.get(\"uri\", \"\")\n            diagnostics = params.get(\"diagnostics\", [])\n            log.debug(f\"AL LSP: Diagnostics for {uri}: {len(diagnostics)} issues\")\n\n        def handle_al_notifications(params: dict) -> None:\n            # AL server sends custom notifications during project loading\n            log.debug(\"AL LSP: Notification received\")\n\n        # Register handlers for AL-specific notifications\n        # These notifications are sent by the AL server during initialization and operation\n        self.server.on_notification(\"window/logMessage\", window_log_message)  # Server log messages\n        self.server.on_notification(\"textDocument/publishDiagnostics\", publish_diagnostics)  # Compilation diagnostics\n        self.server.on_notification(\"$/progress\", do_nothing)  # Progress notifications during loading\n        self.server.on_notification(\"al/refreshExplorerObjects\", handle_al_notifications)  # AL-specific object updates\n\n        # Start the server process\n        log.info(\"Starting AL Language Server process\")\n        self.server.start()\n\n        # Send initialize request\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to AL LSP server and awaiting response\")\n\n        # Send initialize and wait for response\n        resp = self.server.send_request(\"initialize\", initialize_params)\n        if resp is None:\n            raise RuntimeError(\"AL Language Server initialization failed - no response\")\n\n        log.info(\"AL Language Server initialized successfully\")\n\n        # Send initialized notification\n        self.server.send_notification(\"initialized\", {})\n        log.info(\"Sent initialized notification\")\n\n    @override\n    def start(self) -> \"ALLanguageServer\":\n        \"\"\"\n        Start the AL Language Server with special initialization.\n        \"\"\"\n        # Call parent start method\n        super().start()\n\n        # AL-specific post-initialization\n        self._post_initialize_al_workspace()\n\n        # Note: set_active_workspace() can be called manually if needed for multi-workspace scenarios\n        # We don't call it automatically to avoid issues during single-workspace initialization\n\n        return self\n\n    def _post_initialize_al_workspace(self) -> None:\n        \"\"\"\n        Post-initialization setup for AL Language Server.\n\n        The AL server requires additional setup after initialization:\n        1. Send workspace configuration - provides AL settings and paths\n        2. Open app.json to trigger project loading - AL uses app.json to identify project structure\n        3. Optionally wait for project to be loaded if supported\n\n        This special initialization sequence is unique to AL and necessary for proper\n        symbol resolution and navigation features.\n        \"\"\"\n        # No sleep needed - server is already initialized\n\n        # Send workspace configuration first\n        # This tells AL about assembly paths, package caches, and code analysis settings\n        try:\n            self.server.send_notification(\n                \"workspace/didChangeConfiguration\",\n                {\n                    \"settings\": {\n                        \"workspacePath\": self.repository_root_path,\n                        \"alResourceConfigurationSettings\": {\n                            \"assemblyProbingPaths\": [\"./.netpackages\"],\n                            \"codeAnalyzers\": [],\n                            \"enableCodeAnalysis\": False,\n                            \"backgroundCodeAnalysis\": \"Project\",\n                            \"packageCachePaths\": [\"./.alpackages\"],\n                            \"ruleSetPath\": None,\n                            \"enableCodeActions\": True,\n                            \"incrementalBuild\": False,\n                            \"outputAnalyzerStatistics\": True,\n                            \"enableExternalRulesets\": True,\n                        },\n                        \"setActiveWorkspace\": True,\n                        \"expectedProjectReferenceDefinitions\": [],\n                        \"activeWorkspaceClosure\": [self.repository_root_path],\n                    }\n                },\n            )\n            log.debug(\"Sent workspace configuration\")\n        except Exception as e:\n            log.warning(f\"Failed to send workspace config: {e}\")\n\n        # Check if app.json exists and open it\n        # app.json is the AL project manifest file (similar to package.json for Node.js)\n        # Opening it triggers AL to load the project and index all AL files\n        app_json_path = Path(self.repository_root_path) / \"app.json\"\n        if app_json_path.exists():\n            try:\n                with open(app_json_path, encoding=\"utf-8\") as f:\n                    app_json_content = f.read()\n\n                # Use forward slashes for URI\n                app_json_uri = app_json_path.as_uri()\n\n                # Send textDocument/didOpen for app.json\n                self.server.send_notification(\n                    \"textDocument/didOpen\",\n                    {\"textDocument\": {\"uri\": app_json_uri, \"languageId\": \"json\", \"version\": 1, \"text\": app_json_content}},\n                )\n\n                log.debug(f\"Opened app.json: {app_json_uri}\")\n            except Exception as e:\n                log.warning(f\"Failed to open app.json: {e}\")\n\n        # Try to set active workspace (AL-specific custom LSP request)\n        # This is optional and may not be supported by all AL server versions\n        workspace_uri = Path(self.repository_root_path).resolve().as_uri()\n        try:\n            result = self.server.send_request(\n                \"al/setActiveWorkspace\",\n                {\n                    \"currentWorkspaceFolderPath\": {\"uri\": workspace_uri, \"name\": Path(self.repository_root_path).name, \"index\": 0},\n                    \"settings\": {\n                        \"workspacePath\": self.repository_root_path,\n                        \"setActiveWorkspace\": True,\n                    },\n                    \"timeout\": 2,  # Quick timeout since this is optional\n                },\n            )\n            log.debug(f\"Set active workspace result: {result}\")\n        except Exception as e:\n            # This is a custom AL request, not critical if it fails\n            log.debug(f\"Failed to set active workspace (non-critical): {e}\")\n\n        # Check if project supports load status check (optional)\n        # Many AL server versions don't support this, so we use a short timeout\n        # and continue regardless of the result\n        self._wait_for_project_load(timeout=3)\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        \"\"\"\n        Define AL-specific directories to ignore during file scanning.\n\n        These directories contain generated files, dependencies, or cache data\n        that should not be analyzed for symbols.\n\n        Args:\n            dirname: Directory name to check\n\n        Returns:\n            True if directory should be ignored\n\n        \"\"\"\n        al_ignore_dirs = {\n            \".alpackages\",  # AL package cache - downloaded dependencies\n            \".alcache\",  # AL compiler cache - intermediate compilation files\n            \".altemplates\",  # AL templates - code generation templates\n            \".snapshots\",  # Test snapshots - test result snapshots\n            \"out\",  # Compiled output - generated .app files\n            \".vscode\",  # VS Code settings - editor configuration\n            \"Reference\",  # Reference assemblies - .NET dependencies\n            \".netpackages\",  # .NET packages - NuGet packages for AL\n            \"bin\",  # Binary output - compiled binaries\n            \"obj\",  # Object files - intermediate build artifacts\n        }\n\n        # Check parent class ignore list first, then AL-specific\n        return super().is_ignored_dirname(dirname) or dirname in al_ignore_dirs\n\n    @override\n    def request_full_symbol_tree(self, within_relative_path: str | None = None) -> list[UnifiedSymbolInformation]:\n        \"\"\"\n        Override to handle AL's requirement of opening files before requesting symbols.\n\n        The AL Language Server requires files to be explicitly opened via textDocument/didOpen\n        before it can provide meaningful symbols. Without this, it only returns directory symbols.\n        This is different from most language servers which can provide symbols for unopened files.\n\n        This method:\n        1. Scans the repository for all AL files (.al and .dal extensions)\n        2. Opens each file with the AL server\n        3. Requests symbols for each file\n        4. Combines all symbols into a hierarchical tree structure\n        5. Closes the files to free resources\n\n        Args:\n            within_relative_path: Restrict search to this file or directory path\n            include_body: Whether to include symbol body content\n\n        Returns:\n            Full symbol tree with all AL symbols from opened files organized by directory\n\n        \"\"\"\n        log.debug(\"AL: Starting request_full_symbol_tree with file opening\")\n\n        # Determine the root path for scanning\n        if within_relative_path is not None:\n            within_abs_path = os.path.join(self.repository_root_path, within_relative_path)\n            if not os.path.exists(within_abs_path):\n                raise FileNotFoundError(f\"File or directory not found: {within_abs_path}\")\n\n            if os.path.isfile(within_abs_path):\n                # Single file case - use parent class implementation\n                root_nodes = self.request_document_symbols(within_relative_path).root_symbols\n                return root_nodes\n\n            # Directory case - scan within this directory\n            scan_root = Path(within_abs_path)\n        else:\n            # Scan entire repository\n            scan_root = Path(self.repository_root_path)\n\n        # For AL, we always need to open files to get symbols\n        al_files = []\n\n        # Walk through the repository to find all AL files\n        for root, dirs, files in os.walk(scan_root):\n            # Skip ignored directories\n            dirs[:] = [d for d in dirs if not self.is_ignored_dirname(d)]\n\n            # Find AL files\n            for file in files:\n                if file.endswith((\".al\", \".dal\")):\n                    file_path = Path(root) / file\n                    # Use forward slashes for consistent paths\n                    try:\n                        relative_path = str(file_path.relative_to(self.repository_root_path)).replace(\"\\\\\", \"/\")\n                        al_files.append((file_path, relative_path))\n                    except ValueError:\n                        # File is outside repository root, skip it\n                        continue\n\n        log.debug(f\"AL: Found {len(al_files)} AL files\")\n\n        if not al_files:\n            log.warning(\"AL: No AL files found in repository\")\n            return []\n\n        # Collect all symbols from all files\n        all_file_symbols: list[UnifiedSymbolInformation] = []\n\n        file_symbol: UnifiedSymbolInformation\n        for file_path, relative_path in al_files:\n            try:\n                # Use our overridden request_document_symbols which handles opening\n                log.debug(f\"AL: Getting symbols for {relative_path}\")\n                all_syms, root_syms = self.request_document_symbols(relative_path).get_all_symbols_and_roots()\n\n                if root_syms:\n                    # Create a file-level symbol containing the document symbols\n                    file_symbol = {\n                        \"name\": file_path.stem,  # Just the filename without extension\n                        \"kind\": SymbolKind.File,\n                        \"children\": root_syms,\n                        \"location\": {\n                            \"uri\": file_path.as_uri(),\n                            \"relativePath\": relative_path,\n                            \"absolutePath\": str(file_path),\n                            \"range\": {\"start\": {\"line\": 0, \"character\": 0}, \"end\": {\"line\": 0, \"character\": 0}},\n                        },\n                    }\n                    all_file_symbols.append(file_symbol)\n                    log.debug(f\"AL: Added {len(root_syms)} symbols from {relative_path}\")\n                elif all_syms:\n                    # If we only got all_syms but not root, use all_syms\n                    file_symbol = {\n                        \"name\": file_path.stem,\n                        \"kind\": SymbolKind.File,\n                        \"children\": all_syms,\n                        \"location\": {\n                            \"uri\": file_path.as_uri(),\n                            \"relativePath\": relative_path,\n                            \"absolutePath\": str(file_path),\n                            \"range\": {\"start\": {\"line\": 0, \"character\": 0}, \"end\": {\"line\": 0, \"character\": 0}},\n                        },\n                    }\n                    all_file_symbols.append(file_symbol)\n                    log.debug(f\"AL: Added {len(all_syms)} symbols from {relative_path}\")\n\n            except Exception as e:\n                log.warning(f\"AL: Failed to get symbols for {relative_path}: {e}\")\n\n        if all_file_symbols:\n            log.debug(f\"AL: Returning symbols from {len(all_file_symbols)} files\")\n\n            # Group files by directory\n            directory_structure: dict[str, list] = {}\n\n            for file_symbol in all_file_symbols:\n                rel_path = file_symbol[\"location\"][\"relativePath\"]\n                assert rel_path is not None\n                path_parts = rel_path.split(\"/\")\n\n                if len(path_parts) > 1:\n                    # File is in a subdirectory\n                    dir_path = \"/\".join(path_parts[:-1])\n                    if dir_path not in directory_structure:\n                        directory_structure[dir_path] = []\n                    directory_structure[dir_path].append(file_symbol)\n                else:\n                    # File is in root\n                    if \".\" not in directory_structure:\n                        directory_structure[\".\"] = []\n                    directory_structure[\".\"].append(file_symbol)\n\n            # Build hierarchical structure\n            result = []\n            repo_path = Path(self.repository_root_path)\n            for dir_path, file_symbols in directory_structure.items():\n                if dir_path == \".\":\n                    # Root level files\n                    result.extend(file_symbols)\n                else:\n                    # Create directory symbol\n                    dir_symbol = {\n                        \"name\": Path(dir_path).name,\n                        \"kind\": SymbolKind.Package,  # Package/Directory\n                        \"children\": file_symbols,\n                        \"location\": {\n                            \"relativePath\": dir_path,\n                            \"absolutePath\": str(repo_path / dir_path),\n                            \"range\": {\"start\": {\"line\": 0, \"character\": 0}, \"end\": {\"line\": 0, \"character\": 0}},\n                        },\n                    }\n                    result.append(dir_symbol)\n\n            return result\n        else:\n            log.warning(\"AL: No symbols found in any files\")\n            return []\n\n    # ===== Phase 1: Custom AL Command Implementations =====\n\n    @override\n    def _send_definition_request(self, definition_params: DefinitionParams) -> Definition | list[LocationLink] | None:\n        \"\"\"\n        Override to use AL's custom gotodefinition command.\n\n        AL Language Server uses 'al/gotodefinition' instead of the standard\n        'textDocument/definition' request. This custom command provides better\n        navigation for AL-specific constructs like table extensions, page extensions,\n        and codeunit references.\n\n        If the custom command fails, we fall back to the standard LSP method.\n        \"\"\"\n        # Convert standard params to AL format (same structure, different method)\n        al_params = {\"textDocument\": definition_params[\"textDocument\"], \"position\": definition_params[\"position\"]}\n\n        try:\n            # Use custom AL command instead of standard LSP\n            response = self.server.send_request(\"al/gotodefinition\", al_params)\n            log.debug(f\"AL gotodefinition response: {response}\")\n            return response  # type: ignore[return-value]\n        except Exception as e:\n            log.warning(f\"Failed to use al/gotodefinition, falling back to standard: {e}\")\n            # Fallback to standard LSP method if custom command fails\n            return super()._send_definition_request(definition_params)\n\n    def check_project_loaded(self) -> bool:\n        \"\"\"\n        Check if AL project closure is fully loaded.\n\n        Uses AL's custom 'al/hasProjectClosureLoadedRequest' to determine if\n        the project and all its dependencies have been fully loaded and indexed.\n        This is important because AL operations may fail or return incomplete\n        results if the project is still loading.\n\n        Returns:\n            bool: True if project is loaded, False otherwise\n\n        \"\"\"\n        if not hasattr(self, \"server\") or not self.server_started:\n            log.debug(\"Cannot check project load - server not started\")\n            return False\n\n        # Check if we've already determined this request isn't supported\n        if not self._project_load_check_supported:\n            return True  # Assume loaded if check isn't supported\n\n        try:\n            # Use a very short timeout since this is just a status check\n            response = self.server.send_request(\"al/hasProjectClosureLoadedRequest\", {\"timeout\": 1})\n            # Response can be boolean directly, dict with 'loaded' field, or None\n            if isinstance(response, bool):\n                return response\n            elif isinstance(response, dict):\n                return response.get(\"loaded\", False)\n            elif response is None:\n                # None typically means the project is still loading\n                log.debug(\"Project load check returned None\")\n                return False\n            else:\n                log.debug(f\"Unexpected response type for project load check: {type(response)}\")\n                return False\n        except Exception as e:\n            # Mark as unsupported to avoid repeated failed attempts\n            self._project_load_check_supported = False\n            log.debug(f\"Project load check not supported by this AL server version: {e}\")\n            # Assume loaded if we can't check\n            return True\n\n    def _wait_for_project_load(self, timeout: int = 3) -> bool:\n        \"\"\"\n        Wait for project to be fully loaded.\n\n        Polls the AL server to check if the project is loaded.\n        This is optional as not all AL server versions support this check.\n        We use a short timeout and continue regardless of the result.\n\n        Args:\n            timeout: Maximum time to wait in seconds (default 3s)\n\n        Returns:\n            bool: True if project loaded within timeout, False otherwise\n\n        \"\"\"\n        start_time = time.time()\n        log.debug(f\"Checking AL project load status (timeout: {timeout}s)...\")\n\n        while time.time() - start_time < timeout:\n            if self.check_project_loaded():\n                elapsed = time.time() - start_time\n                log.info(f\"AL project fully loaded after {elapsed:.1f}s\")\n                return True\n            time.sleep(0.5)\n\n        log.debug(f\"Project load check timed out after {timeout}s (non-critical)\")\n        return False\n\n    def set_active_workspace(self, workspace_uri: str | None = None) -> None:\n        \"\"\"\n        Set the active AL workspace.\n\n        This is important when multiple workspaces exist to ensure operations\n        target the correct workspace. The AL server can handle multiple projects\n        simultaneously, but only one can be \"active\" at a time for operations\n        like symbol search and navigation.\n\n        This uses the custom 'al/setActiveWorkspace' LSP command.\n\n        Args:\n            workspace_uri: URI of workspace to set as active, or None to use repository root\n\n        \"\"\"\n        if not hasattr(self, \"server\") or not self.server_started:\n            log.debug(\"Cannot set active workspace - server not started\")\n            return\n\n        if workspace_uri is None:\n            workspace_uri = Path(self.repository_root_path).resolve().as_uri()\n\n        params = {\"workspaceUri\": workspace_uri}\n\n        try:\n            self.server.send_request(\"al/setActiveWorkspace\", params)\n            log.info(f\"Set active workspace to: {workspace_uri}\")\n        except Exception as e:\n            log.warning(f\"Failed to set active workspace: {e}\")\n            # Non-critical error, continue operation\n\n    @override\n    def request_document_symbols(self, relative_file_path: str, file_buffer: LSPFileBuffer | None = None) -> DocumentSymbols:\n        \"\"\"\n        Override to normalize AL symbol names by stripping object type and ID metadata.\n\n        AL Language Server returns symbol names with full object format like\n        'Table 50000 \"TEST Customer\"', but symbol names should be pure without metadata.\n        This follows the same pattern as Java LS which strips type information from names.\n\n        Metadata (object type, ID) is available via the hover LSP method when using\n        include_info=True in find_symbol.\n        \"\"\"\n        # Normalize path separators for cross-platform compatibility (backslash → forward slash)\n        relative_file_path = self._normalize_path(relative_file_path)\n\n        # Get symbols from parent implementation\n        document_symbols = super().request_document_symbols(relative_file_path, file_buffer=file_buffer)\n\n        # Normalize names by stripping AL object metadata, storing originals for hover\n        def normalize_name(symbol: UnifiedSymbolInformation) -> None:\n            original_name = symbol[\"name\"]\n            normalized_name = self._extract_al_display_name(original_name)\n\n            # Store original name if it was normalized (for hover injection)\n            # Only store if we have valid position data to avoid false matches at (0, 0)\n            if original_name != normalized_name:\n                sel_range = symbol.get(\"selectionRange\")\n                if sel_range:\n                    start = sel_range.get(\"start\")\n                    if start and \"line\" in start and \"character\" in start:\n                        line = start[\"line\"]\n                        char = start[\"character\"]\n                        self._al_original_names[(relative_file_path, line, char)] = original_name\n\n            symbol[\"name\"] = normalized_name\n\n            # Process children recursively\n            if symbol.get(\"children\"):\n                for child in symbol[\"children\"]:\n                    normalize_name(child)\n\n        # Apply to all root symbols\n        for sym in document_symbols.root_symbols:\n            normalize_name(sym)\n\n        return document_symbols\n\n    @override\n    def request_hover(\n        self, relative_file_path: str, line: int, column: int, file_buffer: LSPFileBuffer | None = None\n    ) -> ls_types.Hover | None:\n        \"\"\"\n        Override to inject original AL object name (with type and ID) into hover responses.\n\n        When hovering over a symbol whose name was normalized, we prepend the original\n        full name (e.g., 'Table 50000 \"TEST Customer\"') to the hover content.\n        \"\"\"\n        # Normalize path separators for cross-platform compatibility (backslash → forward slash)\n        relative_file_path = self._normalize_path(relative_file_path)\n\n        hover = super().request_hover(relative_file_path, line, column, file_buffer=file_buffer)\n\n        if hover is None:\n            return None\n\n        # Check if we have an original name for this position\n        original_name = self._al_original_names.get((relative_file_path, line, column))\n\n        if original_name and \"contents\" in hover:\n            contents = hover[\"contents\"]\n            if isinstance(contents, dict) and \"value\" in contents:\n                # Prepend the original full name to the hover content\n                prefix = f\"**{original_name}**\\n\\n---\\n\\n\"\n                contents[\"value\"] = prefix + contents[\"value\"]\n\n        return hover\n"
  },
  {
    "path": "src/solidlsp/language_servers/ansible_language_server.py",
    "content": "\"\"\"\nProvides Ansible specific instantiation of the LanguageServer class using ansible-language-server.\nContains various configurations and settings specific to Ansible YAML files (playbooks, roles, etc.).\n\"\"\"\n\nimport fnmatch\nimport logging\nimport os\nimport pathlib\nimport shutil\nfrom typing import Any, ClassVar\n\nfrom overrides import override\n\nfrom solidlsp.language_servers.common import RuntimeDependency, RuntimeDependencyCollection\nfrom solidlsp.ls import LanguageServerDependencyProvider, LanguageServerDependencyProviderSinglePath, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\ndef _deep_merge(base: dict, override: dict) -> None:\n    \"\"\"Recursively merge *override* into *base*, modifying *base* in-place.\"\"\"\n    for key, value in override.items():\n        if key in base and isinstance(base[key], dict) and isinstance(value, dict):\n            _deep_merge(base[key], value)\n        else:\n            base[key] = value\n\n\nclass AnsibleLanguageServer(SolidLanguageServer):\n    \"\"\"Provides Ansible specific instantiation of the LanguageServer class using ansible-language-server.\n\n    Contains various configurations and settings specific to Ansible YAML files\n    (playbooks, roles, inventories, etc.).\n\n    Supported ``ls_specific_settings`` keys (via ``serena_config.yml``):\n\n    * ``ls_path`` (str) — path to the ansible-language-server executable\n      (handled by the base class).\n    * ``ansible_path`` (str, default ``\"ansible\"``) — path to the ``ansible`` executable.\n    * ``python_interpreter_path`` (str, default ``\"python3\"``) — path to the Python interpreter.\n    * ``python_activation_script`` (str, default ``\"\"``) — virtualenv activation script.\n    * ``lint_enabled`` (bool, default ``False``) — enable ansible-lint\n      (requires a separate installation of ``ansible-lint``).\n    * ``lint_path`` (str, default ``\"ansible-lint\"``) — path to ``ansible-lint``.\n    * ``ansible_settings`` (dict) — full settings dict, deep-merged on top of defaults.\n      The structure mirrors the Ansible Language Server settings\n      (``ansible.*``, ``python.*``, ``validation.*``, ``completion.*``,\n      ``executionEnvironment.*``).\n    \"\"\"\n\n    # directory names that signal ansible content at ANY nesting level\n    _ANSIBLE_DIR_NAMES: ClassVar[set[str]] = {\n        \"roles\",\n        \"playbooks\",\n        \"tasks\",\n        \"handlers\",\n        \"group_vars\",\n        \"host_vars\",\n        \"inventory\",\n        \"inventories\",\n        \"defaults\",\n        \"vars\",\n        \"meta\",\n    }\n\n    # filename patterns handled by ansible LS regardless of path\n    _ANSIBLE_FILENAME_PATTERNS: ClassVar[list[str]] = [\n        \"playbook*.yml\",\n        \"playbook*.yaml\",\n        \"site.yml\",\n        \"site.yaml\",\n        \"requirements.yml\",\n        \"requirements.yaml\",\n    ]\n\n    @staticmethod\n    def _is_ansible_path(relative_path: str) -> bool:\n        \"\"\"Check if a file is in an ansible-specific location.\n\n        Matches if ANY component of the path is an ansible-specific\n        directory name (e.g. ``roles``, ``tasks``, ``group_vars``),\n        or if the filename matches an ansible-specific pattern.\n        This works regardless of nesting depth:\n        ``project/deploy/roles/web/tasks/main.yml`` matches on both\n        ``roles`` and ``tasks``.\n\n        :param relative_path: path relative to the repository root\n        :return: True if the path is an ansible-specific location\n        \"\"\"\n        normalized = relative_path.replace(\"\\\\\", \"/\")\n        parts = normalized.split(\"/\")\n\n        # check if any directory component is ansible-specific\n        dir_parts = parts[:-1]\n        for part in dir_parts:\n            if part in AnsibleLanguageServer._ANSIBLE_DIR_NAMES:\n                return True\n\n        # check filename patterns (e.g. playbook.yml, site.yaml)\n        filename = parts[-1]\n        for pattern in AnsibleLanguageServer._ANSIBLE_FILENAME_PATTERNS:\n            if fnmatch.fnmatch(filename, pattern):\n                return True\n\n        return False\n\n    @override\n    def is_ignored_path(self, relative_path: str, ignore_unsupported_files: bool = True) -> bool:\n        # standard ignore rules (extension, gitignore, etc.)\n        if super().is_ignored_path(relative_path, ignore_unsupported_files):\n            return True\n\n        # for yml/yaml files, check if they are in ansible-specific paths\n        if relative_path.endswith((\".yml\", \".yaml\")):\n            if not self._is_ansible_path(relative_path):\n                return True\n\n        return False\n\n    @staticmethod\n    def _determine_log_level(line: str) -> int:\n        \"\"\"Classify ansible-language-server stderr output to avoid false-positive errors.\"\"\"\n        line_lower = line.lower()\n\n        if any(\n            [\n                \"ansible is not installed\" in line_lower,\n                \"ansible-lint\" in line_lower and \"not found\" in line_lower,\n                \"cannot find module\" in line_lower,\n            ]\n        ):\n            return logging.DEBUG\n\n        return SolidLanguageServer._determine_log_level(line)\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"Creates an AnsibleLanguageServer instance.\n\n        This class is not meant to be instantiated directly.\n        Use ``SolidLanguageServer.create()`` instead.\n        \"\"\"\n        super().__init__(\n            config,\n            repository_root_path,\n            None,\n            \"ansible\",\n            solidlsp_settings,\n        )\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def _get_or_install_core_dependency(self) -> str:\n            \"\"\"Setup runtime dependencies for Ansible Language Server and return the path to the executable.\"\"\"\n            # verify both node and npm are installed\n            is_node_installed = shutil.which(\"node\") is not None\n            assert is_node_installed, \"node is not installed or isn't in PATH. Please install Node.js and try again.\"\n            is_npm_installed = shutil.which(\"npm\") is not None\n            assert is_npm_installed, \"npm is not installed or isn't in PATH. Please install npm and try again.\"\n\n            deps = RuntimeDependencyCollection(\n                [\n                    RuntimeDependency(\n                        id=\"ansible-language-server\",\n                        description=\"Ansible Language Server (@ansible/ansible-language-server)\",\n                        command=\"npm install --prefix ./ @ansible/ansible-language-server@1.2.3\",\n                        platform_id=\"any\",\n                    ),\n                ]\n            )\n\n            # install ansible-language-server if not already installed\n            ansible_ls_dir = os.path.join(self._ls_resources_dir, \"ansible-lsp\")\n            ansible_executable_path = os.path.join(ansible_ls_dir, \"node_modules\", \".bin\", \"ansible-language-server\")\n\n            # handle Windows executable extension\n            if os.name == \"nt\":\n                ansible_executable_path += \".cmd\"\n\n            if not os.path.exists(ansible_executable_path):\n                log.info(f\"Ansible Language Server executable not found at {ansible_executable_path}. Installing...\")\n                deps.install(ansible_ls_dir)\n                log.info(\"Ansible Language Server dependencies installed successfully\")\n\n            if not os.path.exists(ansible_executable_path):\n                raise FileNotFoundError(\n                    f\"ansible-language-server executable not found at {ansible_executable_path}, \"\n                    \"something went wrong with the installation.\"\n                )\n\n            return ansible_executable_path\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [core_path, \"--stdio\"]\n\n    def _get_initialize_params(self, repository_absolute_path: str) -> InitializeParams:\n        \"\"\"Returns the initialize params for the Ansible Language Server.\n\n        Reads shortcut keys and the ``ansible_settings`` dict from ``_custom_settings``\n        to build ``initializationOptions``.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n\n        # default ansible settings, populated from shortcut keys\n        ansible_settings: dict[str, Any] = {\n            \"ansible\": {\n                \"path\": self._custom_settings.get(\"ansible_path\", \"ansible\"),\n                \"useFullyQualifiedCollectionNames\": True,\n            },\n            \"python\": {\n                \"interpreterPath\": self._custom_settings.get(\"python_interpreter_path\", \"python3\"),\n                \"activationScript\": self._custom_settings.get(\"python_activation_script\", \"\"),\n            },\n            \"validation\": {\n                \"enabled\": True,\n                \"lint\": {\n                    \"enabled\": self._custom_settings.get(\"lint_enabled\", False),\n                    \"path\": self._custom_settings.get(\"lint_path\", \"ansible-lint\"),\n                },\n            },\n            \"completion\": {\n                \"provideRedirectModules\": True,\n                \"provideModuleOptionAliases\": True,\n            },\n            \"executionEnvironment\": {\"enabled\": False},\n        }\n\n        # full override via ansible_settings dict for advanced configuration\n        user_settings = self._custom_settings.settings.get(\"ansible_settings\")\n        if user_settings:\n            if not isinstance(user_settings, dict):\n                raise TypeError(\n                    f\"ansible_settings must be a dict, got {type(user_settings).__name__}. \"\n                    \"Expected structure matching Ansible LS settings: \"\n                    \"{'ansible': {...}, 'python': {...}, 'validation': {...}, ...}\"\n                )\n            _deep_merge(ansible_settings, user_settings)\n\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\"dynamicRegistration\": True, \"completionItem\": {\"snippetSupport\": True}},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"codeAction\": {\"dynamicRegistration\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True},\n                },\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n            \"initializationOptions\": {\"ansible\": ansible_settings},\n        }\n        return initialize_params  # type: ignore\n\n    def _start_server(self) -> None:\n        \"\"\"Starts the Ansible Language Server, waits for the server to be ready.\"\"\"\n\n        def register_capability_handler(params: Any) -> None:\n            return\n\n        def show_message_request_handler(params: Any) -> None:\n            \"\"\"Handle ``window/showMessageRequest`` by returning ``null``.\n\n            Per the LSP spec, returning ``null`` means no action was selected.\n            Without this handler the client replies with ``MethodNotFound``,\n            which the ansible LS treats as fatal.\n            \"\"\"\n            log.info(f\"LSP: window/showMessageRequest (dismissed): {params.get('message', params)}\")\n            return\n\n        def do_nothing(params: Any) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_request(\"window/showMessageRequest\", show_message_request_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting Ansible server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        log.debug(f\"Received initialize response from Ansible server: {init_response}\")\n\n        log.debug(f\"Ansible server capabilities: {list(init_response['capabilities'].keys())}\")\n\n        self.server.notify.initialized({})\n        log.info(\"Ansible server initialization complete\")\n"
  },
  {
    "path": "src/solidlsp/language_servers/bash_language_server.py",
    "content": "\"\"\"\nProvides Bash specific instantiation of the LanguageServer class using bash-language-server.\nContains various configurations and settings specific to Bash scripting.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport shutil\nimport threading\n\nfrom solidlsp.language_servers.common import RuntimeDependency, RuntimeDependencyCollection\nfrom solidlsp.ls import (\n    DocumentSymbols,\n    LanguageServerDependencyProvider,\n    LanguageServerDependencyProviderSinglePath,\n    LSPFileBuffer,\n    SolidLanguageServer,\n)\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass BashLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides Bash specific instantiation of the LanguageServer class using bash-language-server.\n    Contains various configurations and settings specific to Bash scripting.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a BashLanguageServer instance. This class is not meant to be instantiated directly.\n        Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(\n            config,\n            repository_root_path,\n            None,\n            \"bash\",\n            solidlsp_settings,\n        )\n        self.server_ready = threading.Event()\n        self.initialize_searcher_command_available = threading.Event()\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def _get_or_install_core_dependency(self) -> str:\n            \"\"\"\n            Setup runtime dependencies for Bash Language Server and return the command to start the server.\n            \"\"\"\n            # Verify both node and npm are installed\n            is_node_installed = shutil.which(\"node\") is not None\n            assert is_node_installed, \"node is not installed or isn't in PATH. Please install NodeJS and try again.\"\n            is_npm_installed = shutil.which(\"npm\") is not None\n            assert is_npm_installed, \"npm is not installed or isn't in PATH. Please install npm and try again.\"\n\n            deps = RuntimeDependencyCollection(\n                [\n                    RuntimeDependency(\n                        id=\"bash-language-server\",\n                        description=\"bash-language-server package\",\n                        command=\"npm install --prefix ./ bash-language-server@5.6.0\",\n                        platform_id=\"any\",\n                    ),\n                ]\n            )\n\n            # Install bash-language-server if not already installed\n            bash_ls_dir = os.path.join(self._ls_resources_dir, \"bash-lsp\")\n            bash_executable_path = os.path.join(bash_ls_dir, \"node_modules\", \".bin\", \"bash-language-server\")\n\n            # Handle Windows executable extension\n            if os.name == \"nt\":\n                bash_executable_path += \".cmd\"\n\n            if not os.path.exists(bash_executable_path):\n                log.info(f\"Bash Language Server executable not found at {bash_executable_path}. Installing...\")\n                deps.install(bash_ls_dir)\n                log.info(\"Bash language server dependencies installed successfully\")\n\n            if not os.path.exists(bash_executable_path):\n                raise FileNotFoundError(\n                    f\"bash-language-server executable not found at {bash_executable_path}, something went wrong with the installation.\"\n                )\n\n            return bash_executable_path\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [core_path, \"start\"]\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Bash Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\"dynamicRegistration\": True, \"completionItem\": {\"snippetSupport\": True}},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"signatureHelp\": {\"dynamicRegistration\": True},\n                    \"codeAction\": {\"dynamicRegistration\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True},\n                },\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return initialize_params  # type: ignore\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the Bash Language Server, waits for the server to be ready and yields the LanguageServer instance.\n        \"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            assert \"registrations\" in params\n            for registration in params[\"registrations\"]:\n                if registration[\"method\"] == \"workspace/executeCommand\":\n                    self.initialize_searcher_command_available.set()\n            return\n\n        def execute_client_command_handler(params: dict) -> list:\n            return []\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n            # Check for bash-language-server ready signals\n            message_text = msg.get(\"message\", \"\")\n            if \"Analyzing\" in message_text or \"analysis complete\" in message_text.lower():\n                log.info(\"Bash language server analysis signals detected\")\n                self.server_ready.set()\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_request(\"workspace/executeClientCommand\", execute_client_command_handler)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting Bash server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        log.debug(f\"Received initialize response from bash server: {init_response}\")\n\n        # Enhanced capability checks for bash-language-server 5.6.0\n        assert init_response[\"capabilities\"][\"textDocumentSync\"] in [1, 2]  # Full or Incremental\n        assert \"completionProvider\" in init_response[\"capabilities\"]\n\n        # Verify document symbol support is available\n        if \"documentSymbolProvider\" in init_response[\"capabilities\"]:\n            log.info(\"Bash server supports document symbols\")\n        else:\n            log.warning(\"Warning: Bash server does not report document symbol support\")\n\n        self.server.notify.initialized({})\n\n        # Wait for server readiness with timeout\n        log.info(\"Waiting for Bash language server to be ready...\")\n        if not self.server_ready.wait(timeout=3.0):\n            # Fallback: assume server is ready after timeout\n            # This is common. bash-language-server doesn't always send explicit ready signals. Log as info\n            log.info(\"Timeout waiting for bash server ready signal, proceeding anyway\")\n            self.server_ready.set()\n        else:\n            log.info(\"Bash server initialization complete\")\n\n    def request_document_symbols(self, relative_file_path: str, file_buffer: LSPFileBuffer | None = None) -> DocumentSymbols:\n        # Uses the standard LSP documentSymbol request which provides reliable function detection\n        # for all bash function syntaxes including:\n        # - function name() { ... } (with function keyword)\n        # - name() { ... } (traditional syntax)\n        # - Functions with various indentation levels\n        # - Functions with comments before/after/inside\n\n        log.debug(f\"Requesting document symbols via LSP for {relative_file_path}\")\n\n        # Use the standard LSP approach - bash-language-server handles all function syntaxes correctly\n        document_symbols = super().request_document_symbols(relative_file_path, file_buffer=file_buffer)\n\n        # Log detection results for debugging\n        functions = [s for s in document_symbols.iter_symbols() if s.get(\"kind\") == 12]\n        log.info(f\"LSP function detection for {relative_file_path}: Found {len(functions)} functions\")\n\n        return document_symbols\n"
  },
  {
    "path": "src/solidlsp/language_servers/ccls_language_server.py",
    "content": "\"\"\"\nThis is an alternative to clangd for large C++ codebases where ccls may perform\nbetter for indexing and navigation. Requires ccls to be installed and available\non PATH, or configured via ls_specific_settings with key \"ls_path\".\n\nInstallation\n------------\nccls must be installed manually as there are no prebuilt binaries available for\ndirect download. Install using your system package manager:\n\n**Linux:**\n- Ubuntu/Debian (22.04+): ``sudo apt-get install ccls``\n- Fedora/RHEL: ``sudo dnf install ccls``\n- Arch Linux: ``sudo pacman -S ccls``\n- openSUSE Tumbleweed: ``sudo zypper install ccls``\n- Gentoo: ``sudo emerge dev-util/ccls``\n\n**macOS:**\n- Homebrew: ``brew install ccls``\n\n**Windows:**\n- Chocolatey: ``choco install ccls``\n\nFor alternative installation methods and build-from-source instructions, see:\nhttps://github.com/MaskRay/ccls/wiki/Build\n\nOfficial documentation:\nhttps://github.com/MaskRay/ccls\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport threading\nfrom typing import Any, cast\n\nfrom solidlsp.ls import (\n    LanguageServerDependencyProvider,\n    LanguageServerDependencyProviderSinglePath,\n    SolidLanguageServer,\n)\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass CCLS(SolidLanguageServer):\n    \"\"\"\n    C/C++ language server implementation using ccls.\n\n    Notes:\n    - ccls should be installed and on PATH (or specify ls_path in settings)\n    - compile_commands.json at repo root is recommended for accurate indexing\n\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a CclsLanguageServer instance. This class is not meant to be instantiated directly.\n        Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(config, repository_root_path, None, \"cpp\", solidlsp_settings)\n        self.server_ready = threading.Event()\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def _get_or_install_core_dependency(self) -> str:\n            \"\"\"\n            Resolve ccls path from system or raise helpful error if missing.\n            Allows override via ls_specific_settings[language].ls_path.\n            \"\"\"\n            import shutil\n\n            ccls_path = shutil.which(\"ccls\")\n            if not ccls_path:\n                raise FileNotFoundError(\n                    \"ccls is not installed on your system.\\n\"\n                    \"Please install ccls using your system package manager:\\n\"\n                    \"  Linux (Ubuntu/Debian): sudo apt-get install ccls\\n\"\n                    \"  Linux (Fedora/RHEL):   sudo dnf install ccls\\n\"\n                    \"  Linux (Arch):          sudo pacman -S ccls\\n\"\n                    \"  macOS (Homebrew):      brew install ccls\\n\"\n                    \"  Windows:               choco install ccls\\n\\n\"\n                    \"For build instructions and more details, see:\\n\"\n                    \"  https://github.com/MaskRay/ccls/wiki/Build\"\n                )\n            log.info(f\"Using system-installed ccls at {ccls_path}\")\n            return ccls_path\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [core_path]\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the ccls Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\"dynamicRegistration\": True, \"completionItem\": {\"snippetSupport\": True}},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\"dynamicRegistration\": True},\n                },\n                \"workspace\": {\"workspaceFolders\": True, \"didChangeConfiguration\": {\"dynamicRegistration\": True}},\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": \"$name\",\n                }\n            ],\n            # ccls supports initializationOptions but none are required for basic functionality\n        }\n        return cast(InitializeParams, initialize_params)\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the ccls language server and initializes the LSP connection.\n        \"\"\"\n\n        def do_nothing(params: Any) -> None:\n            pass\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        # Register minimal handlers\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting ccls server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to ccls and awaiting response\")\n        self.server.send.initialize(initialize_params)\n        # Do not assert clangd-specific capability shapes; ccls differs\n        self.server.notify.initialized({})\n\n        # Basic readiness\n        self.server_ready.set()\n"
  },
  {
    "path": "src/solidlsp/language_servers/clangd_language_server.py",
    "content": "import json\nimport logging\nimport os\nimport pathlib\nimport threading\nfrom typing import Any, cast\n\nfrom solidlsp.ls import LanguageServerDependencyProvider, LanguageServerDependencyProviderSinglePath, ProcessLaunchInfo, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nfrom .common import RuntimeDependency, RuntimeDependencyCollection\n\nlog = logging.getLogger(__name__)\n\n\nclass ClangdLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides C/C++ specific instantiation of the LanguageServer class. Contains various configurations and settings specific to C/C++.\n    As the project gets bigger in size, building index will take time. Try running clangd multiple times to ensure index is built properly.\n    Also make sure compile_commands.json is created at root of the source directory. Check clangd test case for example.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a ClangdLanguageServer instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(config, repository_root_path, None, \"cpp\", solidlsp_settings)\n        self.server_ready = threading.Event()\n        self.service_ready_event = threading.Event()\n        self.initialize_searcher_command_available = threading.Event()\n        self.resolve_main_method_available = threading.Event()\n\n    def _prepare_compile_commands(self) -> str | None:\n        \"\"\"\n        Prepare clangd compilation database with absolute directory paths.\n\n        Clangd requires absolute directory paths in compile_commands.json for correct\n        cross-file reference finding. This method reads the compile_commands.json,\n        converts relative directory paths to absolute paths, and writes a transformed\n        compilation database to the serena managed directory.\n\n        The transformed file is persisted in .serena/serena_compile_commands.json\n        (or a configurable directory via ls_specific_settings) and is not deleted\n        on cleanup. This allows clangd to use the absolute-path version without\n        modifying the user's original compile_commands.json.\n\n        Returns the path to the serena directory containing the transformed database,\n        or None if no transformation was needed.\n        \"\"\"\n        compile_db_path = os.path.join(self.repository_root_path, \"compile_commands.json\")\n\n        if not os.path.exists(compile_db_path):\n            # No compile_commands.json, nothing to do\n            return None\n\n        try:\n            with open(compile_db_path, encoding=\"utf-8\") as f:\n                compile_commands = json.load(f)\n\n            if not compile_commands:\n                return None\n\n            # Check if any entries have relative directory paths\n            has_relative = False\n            for entry in compile_commands:\n                directory = entry.get(\"directory\", \"\")\n                if directory and not os.path.isabs(directory):\n                    has_relative = True\n                    # Convert to absolute path\n                    entry[\"directory\"] = os.path.abspath(os.path.join(self.repository_root_path, directory))\n\n            if not has_relative:\n                # No relative paths found, no need to create transformed database\n                return None\n\n            # Get the target directory from ls_specific_settings, default to .serena\n            cpp_settings: dict[str, Any] = self._custom_settings or {}\n            compile_commands_rel_dir = cpp_settings.get(\"compile_commands_dir\", \".serena\")\n            compile_commands_dir = os.path.join(self.repository_root_path, compile_commands_rel_dir)\n            os.makedirs(compile_commands_dir, exist_ok=True)\n\n            # Write the transformed compile_commands.json\n            # clangd looks for compile_commands.json in the --compile-commands-dir\n            compile_commands_path = os.path.join(compile_commands_dir, \"compile_commands.json\")\n            with open(compile_commands_path, \"w\", encoding=\"utf-8\") as f:\n                json.dump(compile_commands, f, indent=2)\n\n            # Track the directory for --compile-commands-dir\n\n            log.info(f\"Created serena compilation database with absolute paths at {compile_commands_path}\")\n            return compile_commands_dir\n\n        except (OSError, json.JSONDecodeError) as e:\n            log.warning(f\"Failed to prepare compile_commands.json: {e}\")\n            return None\n\n    def _create_process_launch_info(self) -> ProcessLaunchInfo:\n        \"\"\"\n        Override to add --compile-commands-dir argument if we created a serena compilation database.\n        \"\"\"\n        # First, ensure the serena compile commands database is prepared\n        compile_commands_dir = self._prepare_compile_commands()\n\n        # Get the default launch info from parent\n        launch_info = super()._create_process_launch_info()\n\n        # If we created a serena compilation database, add --compile-commands-dir to the command\n        if compile_commands_dir:\n            # Insert --compile-commands-dir after the executable path\n            cmd = launch_info.cmd\n            assert isinstance(cmd, list)\n            launch_info.cmd = [cmd[0], f\"--compile-commands-dir={compile_commands_dir}\"] + cmd[1:]\n\n        return launch_info\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def _get_or_install_core_dependency(self) -> str:\n            \"\"\"\n            Setup runtime dependencies for ClangdLanguageServer and return the path to the executable.\n            \"\"\"\n            import shutil\n\n            deps = RuntimeDependencyCollection(\n                [\n                    RuntimeDependency(\n                        id=\"Clangd\",\n                        description=\"Clangd for Linux (x64)\",\n                        url=\"https://github.com/clangd/clangd/releases/download/19.1.2/clangd-linux-19.1.2.zip\",\n                        platform_id=\"linux-x64\",\n                        archive_type=\"zip\",\n                        binary_name=\"clangd_19.1.2/bin/clangd\",\n                    ),\n                    RuntimeDependency(\n                        id=\"Clangd\",\n                        description=\"Clangd for Windows (x64)\",\n                        url=\"https://github.com/clangd/clangd/releases/download/19.1.2/clangd-windows-19.1.2.zip\",\n                        platform_id=\"win-x64\",\n                        archive_type=\"zip\",\n                        binary_name=\"clangd_19.1.2/bin/clangd.exe\",\n                    ),\n                    RuntimeDependency(\n                        id=\"Clangd\",\n                        description=\"Clangd for macOS (x64)\",\n                        url=\"https://github.com/clangd/clangd/releases/download/19.1.2/clangd-mac-19.1.2.zip\",\n                        platform_id=\"osx-x64\",\n                        archive_type=\"zip\",\n                        binary_name=\"clangd_19.1.2/bin/clangd\",\n                    ),\n                    RuntimeDependency(\n                        id=\"Clangd\",\n                        description=\"Clangd for macOS (Arm64)\",\n                        url=\"https://github.com/clangd/clangd/releases/download/19.1.2/clangd-mac-19.1.2.zip\",\n                        platform_id=\"osx-arm64\",\n                        archive_type=\"zip\",\n                        binary_name=\"clangd_19.1.2/bin/clangd\",\n                    ),\n                ]\n            )\n\n            clangd_ls_dir = os.path.join(self._ls_resources_dir, \"clangd\")\n\n            try:\n                dep = deps.get_single_dep_for_current_platform()\n            except RuntimeError:\n                dep = None\n\n            if dep is None:\n                # No prebuilt binary available, look for system-installed clangd\n                clangd_executable_path = shutil.which(\"clangd\")\n                if not clangd_executable_path:\n                    raise FileNotFoundError(\n                        \"Clangd is not installed on your system.\\n\"\n                        + \"Please install clangd using your system package manager:\\n\"\n                        + \"  Ubuntu/Debian: sudo apt-get install clangd\\n\"\n                        + \"  Fedora/RHEL: sudo dnf install clang-tools-extra\\n\"\n                        + \"  Arch Linux: sudo pacman -S clang\\n\"\n                        + \"See https://clangd.llvm.org/installation for more details.\"\n                    )\n                log.info(f\"Using system-installed clangd at {clangd_executable_path}\")\n            else:\n                # Standard download and install for platforms with prebuilt binaries\n                clangd_executable_path = deps.binary_path(clangd_ls_dir)\n                if not os.path.exists(clangd_executable_path):\n                    log.info(f\"Clangd executable not found at {clangd_executable_path}. Downloading from {dep.url}\")\n                    _ = deps.install(clangd_ls_dir)\n                if not os.path.exists(clangd_executable_path):\n                    raise FileNotFoundError(\n                        f\"Clangd executable not found at {clangd_executable_path}.\\n\"\n                        + \"Make sure you have installed clangd. See https://clangd.llvm.org/installation\"\n                    )\n                os.chmod(clangd_executable_path, 0o755)\n            return clangd_executable_path\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            # --background-index enables clangd to index all files in the project,\n            # which is required for finding cross-file references\n            return [core_path, \"--background-index\"]\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the clangd Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\"dynamicRegistration\": True, \"completionItem\": {\"snippetSupport\": True}},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                    },\n                },\n                \"workspace\": {\"workspaceFolders\": True, \"didChangeConfiguration\": {\"dynamicRegistration\": True}},\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": \"$name\",\n                }\n            ],\n        }\n\n        return cast(InitializeParams, initialize_params)\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the Clangd Language Server, waits for the server to be ready and yields the LanguageServer instance.\n\n        Usage:\n        ```\n        async with lsp.start_server():\n            # LanguageServer has been initialized and ready to serve requests\n            await lsp.request_definition(...)\n            await lsp.request_references(...)\n            # Shutdown the LanguageServer on exit from scope\n        # LanguageServer has been shutdown\n        ```\n        \"\"\"\n\n        def register_capability_handler(params: Any) -> None:\n            assert \"registrations\" in params\n            for registration in params[\"registrations\"]:\n                if registration[\"method\"] == \"workspace/executeCommand\":\n                    self.initialize_searcher_command_available.set()\n                    self.resolve_main_method_available.set()\n            return\n\n        def lang_status_handler(params: Any) -> None:\n            # TODO: Should we wait for\n            # server -> client: {'jsonrpc': '2.0', 'method': 'language/status', 'params': {'type': 'ProjectStatus', 'message': 'OK'}}\n            # Before proceeding?\n            if params[\"type\"] == \"ServiceReady\" and params[\"message\"] == \"ServiceReady\":\n                self.service_ready_event.set()\n\n        def execute_client_command_handler(params: Any) -> list:\n            return []\n\n        def do_nothing(params: Any) -> None:\n            return\n\n        def check_experimental_status(params: Any) -> None:\n            if params[\"quiescent\"] == True:\n                self.server_ready.set()\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"language/status\", lang_status_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_request(\"workspace/executeClientCommand\", execute_client_command_handler)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"language/actionableNotification\", do_nothing)\n        self.server.on_notification(\"experimental/serverStatus\", check_experimental_status)\n\n        log.info(\"Starting Clangd server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        assert init_response[\"capabilities\"][\"textDocumentSync\"][\"change\"] == 2  # type: ignore\n        assert \"completionProvider\" in init_response[\"capabilities\"]\n        assert init_response[\"capabilities\"][\"completionProvider\"] == {\n            \"triggerCharacters\": [\".\", \"<\", \">\", \":\", '\"', \"/\", \"*\"],\n            \"resolveProvider\": False,\n        }\n\n        self.server.notify.initialized({})\n        # set ready flag, clangd sends no meaningful notification when ready\n        # TODO This defeats the purpose of the event; we should wait for the server to actually be ready\n        self.server_ready.set()\n\n        # wait for server to be ready\n        self.server_ready.wait()\n"
  },
  {
    "path": "src/solidlsp/language_servers/clojure_lsp.py",
    "content": "\"\"\"\nProvides Clojure specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Clojure.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport shutil\nimport subprocess\nimport threading\nfrom typing import cast\n\nfrom solidlsp.ls import LanguageServerDependencyProvider, LanguageServerDependencyProviderSinglePath, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nfrom .common import RuntimeDependency, RuntimeDependencyCollection\n\nlog = logging.getLogger(__name__)\n\n\ndef run_command(cmd: list, capture_output: bool = True) -> subprocess.CompletedProcess:\n    return subprocess.run(\n        cmd, stdout=subprocess.PIPE if capture_output else None, stderr=subprocess.STDOUT if capture_output else None, text=True, check=True\n    )\n\n\ndef verify_clojure_cli() -> None:\n    install_msg = \"Please install the official Clojure CLI from:\\n  https://clojure.org/guides/getting_started\"\n    if shutil.which(\"clojure\") is None:\n        raise FileNotFoundError(\"`clojure` not found.\\n\" + install_msg)\n\n    help_proc = run_command([\"clojure\", \"--help\"])\n    if \"-Aaliases\" not in help_proc.stdout:\n        raise RuntimeError(\"Detected a Clojure executable, but it does not support '-Aaliases'.\\n\" + install_msg)\n\n    spath_proc = run_command([\"clojure\", \"-Spath\"], capture_output=False)\n    if spath_proc.returncode != 0:\n        raise RuntimeError(\"`clojure -Spath` failed; please upgrade to Clojure CLI ≥ 1.10.\")\n\n\nclass ClojureLSP(SolidLanguageServer):\n    \"\"\"\n    Provides a clojure-lsp specific instantiation of the LanguageServer class. Contains various configurations and settings specific to clojure.\n    \"\"\"\n\n    clojure_lsp_releases = \"https://github.com/clojure-lsp/clojure-lsp/releases/latest/download\"\n    runtime_dependencies = RuntimeDependencyCollection(\n        [\n            RuntimeDependency(\n                id=\"clojure-lsp\",\n                url=f\"{clojure_lsp_releases}/clojure-lsp-native-macos-aarch64.zip\",\n                platform_id=\"osx-arm64\",\n                archive_type=\"zip\",\n                binary_name=\"clojure-lsp\",\n            ),\n            RuntimeDependency(\n                id=\"clojure-lsp\",\n                url=f\"{clojure_lsp_releases}/clojure-lsp-native-macos-amd64.zip\",\n                platform_id=\"osx-x64\",\n                archive_type=\"zip\",\n                binary_name=\"clojure-lsp\",\n            ),\n            RuntimeDependency(\n                id=\"clojure-lsp\",\n                url=f\"{clojure_lsp_releases}/clojure-lsp-native-linux-aarch64.zip\",\n                platform_id=\"linux-arm64\",\n                archive_type=\"zip\",\n                binary_name=\"clojure-lsp\",\n            ),\n            RuntimeDependency(\n                id=\"clojure-lsp\",\n                url=f\"{clojure_lsp_releases}/clojure-lsp-native-linux-amd64.zip\",\n                platform_id=\"linux-x64\",\n                archive_type=\"zip\",\n                binary_name=\"clojure-lsp\",\n            ),\n            RuntimeDependency(\n                id=\"clojure-lsp\",\n                url=f\"{clojure_lsp_releases}/clojure-lsp-native-windows-amd64.zip\",\n                platform_id=\"win-x64\",\n                archive_type=\"zip\",\n                binary_name=\"clojure-lsp.exe\",\n            ),\n        ]\n    )\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a ClojureLSP instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(\n            config,\n            repository_root_path,\n            None,\n            \"clojure\",\n            solidlsp_settings,\n        )\n        self.server_ready = threading.Event()\n        self.initialize_searcher_command_available = threading.Event()\n        self.resolve_main_method_available = threading.Event()\n        self.service_ready_event = threading.Event()\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def _get_or_install_core_dependency(self) -> str:\n            \"\"\"Setup runtime dependencies for clojure-lsp and return the path to the executable.\"\"\"\n            verify_clojure_cli()\n            deps = ClojureLSP.runtime_dependencies\n            dependency = deps.get_single_dep_for_current_platform()\n\n            clojurelsp_executable_path = deps.binary_path(self._ls_resources_dir)\n            if not os.path.exists(clojurelsp_executable_path):\n                log.info(\n                    f\"Downloading and extracting clojure-lsp from {dependency.url} to {self._ls_resources_dir}\",\n                )\n                deps.install(self._ls_resources_dir)\n            if not os.path.exists(clojurelsp_executable_path):\n                raise FileNotFoundError(f\"Download failed? Could not find clojure-lsp executable at {clojurelsp_executable_path}\")\n            os.chmod(clojurelsp_executable_path, 0o755)\n            return clojurelsp_executable_path\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [core_path]\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"Returns the init params for clojure-lsp.\"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        result = {  # type: ignore\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"capabilities\": {\n                \"workspace\": {\n                    \"applyEdit\": True,\n                    \"workspaceEdit\": {\"documentChanges\": True},\n                    \"symbol\": {\"symbolKind\": {\"valueSet\": list(range(1, 27))}},\n                    \"workspaceFolders\": True,\n                },\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True},\n                    \"publishDiagnostics\": {\"relatedInformation\": True, \"tagSupport\": {\"valueSet\": [1, 2]}},\n                    \"definition\": {\"linkSupport\": True},\n                    \"references\": {},\n                    \"hover\": {\"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"documentSymbol\": {\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},  #\n                    },\n                },\n                \"general\": {\"positionEncodings\": [\"utf-16\"]},\n            },\n            \"initializationOptions\": {\"dependency-scheme\": \"jar\", \"text-document-sync-kind\": \"incremental\"},\n            \"trace\": \"off\",\n            \"workspaceFolders\": [{\"uri\": root_uri, \"name\": os.path.basename(repository_absolute_path)}],\n        }\n        return cast(InitializeParams, result)\n\n    def _start_server(self) -> None:\n        def register_capability_handler(params: dict) -> None:\n            assert \"registrations\" in params\n            for registration in params[\"registrations\"]:\n                if registration[\"method\"] == \"workspace/executeCommand\":\n                    self.initialize_searcher_command_available.set()\n                    self.resolve_main_method_available.set()\n            return\n\n        def lang_status_handler(params: dict) -> None:\n            # TODO: Should we wait for\n            # server -> client: {'jsonrpc': '2.0', 'method': 'language/status', 'params': {'type': 'ProjectStatus', 'message': 'OK'}}\n            # Before proceeding?\n            if params[\"type\"] == \"ServiceReady\" and params[\"message\"] == \"ServiceReady\":\n                self.service_ready_event.set()\n\n        def execute_client_command_handler(params: dict) -> list:\n            return []\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def check_experimental_status(params: dict) -> None:\n            if params[\"quiescent\"] is True:\n                self.server_ready.set()\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"language/status\", lang_status_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_request(\"workspace/executeClientCommand\", execute_client_command_handler)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"language/actionableNotification\", do_nothing)\n        self.server.on_notification(\"experimental/serverStatus\", check_experimental_status)\n\n        log.info(\"Starting clojure-lsp server process\")\n        self.server.start()\n\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        assert init_response[\"capabilities\"][\"textDocumentSync\"][\"change\"] == 2  # type: ignore\n        assert \"completionProvider\" in init_response[\"capabilities\"]\n        # Clojure-lsp completion provider capabilities are more flexible than other servers'\n        completion_provider = init_response[\"capabilities\"][\"completionProvider\"]\n        assert completion_provider[\"resolveProvider\"] is True\n        assert \"triggerCharacters\" in completion_provider\n        self.server.notify.initialized({})\n        # after initialize, Clojure-lsp is ready to serve\n        self.server_ready.set()\n"
  },
  {
    "path": "src/solidlsp/language_servers/common.py",
    "content": "from __future__ import annotations\n\nimport logging\nimport os\nimport platform\nimport subprocess\nfrom collections.abc import Iterable, Mapping, Sequence\nfrom dataclasses import dataclass, replace\nfrom typing import Any, cast\n\nfrom solidlsp.ls_utils import FileUtils, PlatformUtils\nfrom solidlsp.util.subprocess_util import subprocess_kwargs\n\nlog = logging.getLogger(__name__)\n\n\n@dataclass(kw_only=True)\nclass RuntimeDependency:\n    \"\"\"Represents a runtime dependency for a language server.\"\"\"\n\n    id: str\n    platform_id: str | None = None\n    url: str | None = None\n    archive_type: str | None = None\n    binary_name: str | None = None\n    command: str | list[str] | None = None\n    package_name: str | None = None\n    package_version: str | None = None\n    extract_path: str | None = None\n    description: str | None = None\n\n\nclass RuntimeDependencyCollection:\n    \"\"\"Utility to handle installation of runtime dependencies.\"\"\"\n\n    def __init__(self, dependencies: Sequence[RuntimeDependency], overrides: Iterable[Mapping[str, Any]] = ()) -> None:\n        \"\"\"Initialize the collection with a list of dependencies and optional overrides.\n\n        :param dependencies: List of base RuntimeDependency instances. The combination of 'id' and 'platform_id' must be unique.\n        :param overrides: List of dictionaries which represent overrides or additions to the base dependencies.\n            Each entry must contain at least the 'id' key, and optionally 'platform_id' to uniquely identify the dependency to override.\n        \"\"\"\n        self._id_and_platform_id_to_dep: dict[tuple[str, str | None], RuntimeDependency] = {}\n        for dep in dependencies:\n            dep_key = (dep.id, dep.platform_id)\n            if dep_key in self._id_and_platform_id_to_dep:\n                raise ValueError(f\"Duplicate runtime dependency with id '{dep.id}' and platform_id '{dep.platform_id}':\\n{dep}\")\n            self._id_and_platform_id_to_dep[dep_key] = dep\n\n        for dep_values_override in overrides:\n            override_key = cast(tuple[str, str | None], (dep_values_override[\"id\"], dep_values_override.get(\"platform_id\")))\n            base_dep = self._id_and_platform_id_to_dep.get(override_key)\n            if base_dep is None:\n                new_runtime_dep = RuntimeDependency(**dep_values_override)\n                self._id_and_platform_id_to_dep[override_key] = new_runtime_dep\n            else:\n                self._id_and_platform_id_to_dep[override_key] = replace(base_dep, **dep_values_override)\n\n    def get_dependencies_for_platform(self, platform_id: str) -> list[RuntimeDependency]:\n        return [d for d in self._id_and_platform_id_to_dep.values() if d.platform_id in (platform_id, \"any\", \"platform-agnostic\", None)]\n\n    def get_dependencies_for_current_platform(self) -> list[RuntimeDependency]:\n        return self.get_dependencies_for_platform(PlatformUtils.get_platform_id().value)\n\n    def get_single_dep_for_current_platform(self, dependency_id: str | None = None) -> RuntimeDependency:\n        deps = self.get_dependencies_for_current_platform()\n        if dependency_id is not None:\n            deps = [d for d in deps if d.id == dependency_id]\n        if len(deps) != 1:\n            raise RuntimeError(\n                f\"Expected exactly one runtime dependency for platform-{PlatformUtils.get_platform_id().value} and {dependency_id=}, found {len(deps)}\"\n            )\n        return deps[0]\n\n    def binary_path(self, target_dir: str) -> str:\n        dep = self.get_single_dep_for_current_platform()\n        if not dep.binary_name:\n            return target_dir\n        return os.path.join(target_dir, dep.binary_name)\n\n    def install(self, target_dir: str) -> dict[str, str]:\n        \"\"\"Install all dependencies for the current platform into *target_dir*.\n\n        Returns a mapping from dependency id to the resolved binary path.\n        \"\"\"\n        os.makedirs(target_dir, exist_ok=True)\n        results: dict[str, str] = {}\n        for dep in self.get_dependencies_for_current_platform():\n            if dep.url:\n                self._install_from_url(dep, target_dir)\n            if dep.command:\n                self._run_command(dep.command, target_dir)\n            if dep.binary_name:\n                results[dep.id] = os.path.join(target_dir, dep.binary_name)\n            else:\n                results[dep.id] = target_dir\n        return results\n\n    @staticmethod\n    def _run_command(command: str | list[str], cwd: str) -> None:\n        kwargs = subprocess_kwargs()\n        if not PlatformUtils.get_platform_id().is_windows():\n            import pwd\n\n            kwargs[\"user\"] = pwd.getpwuid(os.getuid()).pw_name  # type: ignore\n\n        is_windows = platform.system() == \"Windows\"\n        if not isinstance(command, str) and not is_windows:\n            # Since we are using the shell, we need to convert the command list to a single string\n            # on Linux/macOS\n            command = \" \".join(command)\n\n        log.info(\"Running command %s in '%s'\", f\"'{command}'\" if isinstance(command, str) else command, cwd)\n\n        completed_process = subprocess.run(\n            command,\n            shell=True,\n            check=True,\n            cwd=cwd,\n            stdout=subprocess.PIPE,\n            stderr=subprocess.STDOUT,\n            **kwargs,\n        )  # type: ignore\n        if completed_process.returncode != 0:\n            log.warning(\"Command '%s' failed with return code %d\", command, completed_process.returncode)\n            log.warning(\"Command output:\\n%s\", completed_process.stdout)\n        else:\n            log.info(\n                \"Command completed successfully\",\n            )\n\n    @staticmethod\n    def _install_from_url(dep: RuntimeDependency, target_dir: str) -> None:\n        if not dep.url:\n            raise ValueError(f\"Dependency {dep.id} has no URL\")\n\n        if dep.archive_type in (\"gz\", \"binary\") and dep.binary_name:\n            dest = os.path.join(target_dir, dep.binary_name)\n            FileUtils.download_and_extract_archive(dep.url, dest, dep.archive_type)\n        else:\n            FileUtils.download_and_extract_archive(dep.url, target_dir, dep.archive_type or \"zip\")\n\n\ndef quote_windows_path(path: str) -> str:\n    \"\"\"\n    Quote a path for Windows command execution if needed.\n\n    On Windows, paths need to be quoted for proper command execution.\n    The function checks if the path is already quoted to avoid double-quoting.\n    On other platforms, the path is returned unchanged.\n\n    Args:\n        path: The file path to potentially quote\n\n    Returns:\n        The quoted path on Windows (if not already quoted), unchanged path on other platforms\n\n    \"\"\"\n    if platform.system() == \"Windows\":\n        # Check if already quoted to avoid double-quoting\n        if path.startswith('\"') and path.endswith('\"'):\n            return path\n        return f'\"{path}\"'\n    return path\n"
  },
  {
    "path": "src/solidlsp/language_servers/csharp_language_server.py",
    "content": "\"\"\"\nCSharp Language Server using Roslyn Language Server (Official Roslyn-based LSP server from NuGet.org)\n\"\"\"\n\nimport logging\nimport os\nimport platform\nimport shutil\nimport threading\nimport urllib.request\nfrom collections.abc import Iterable\nfrom pathlib import Path\nfrom typing import Any, cast\n\nfrom overrides import override\n\nfrom serena.util.dotnet import DotNETUtil\nfrom solidlsp.ls import DocumentSymbols, LanguageServerDependencyProvider, LSPFileBuffer, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.ls_exceptions import SolidLSPException\nfrom solidlsp.ls_types import Hover, UnifiedSymbolInformation\nfrom solidlsp.ls_utils import PathUtils\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams, InitializeResult\nfrom solidlsp.settings import SolidLSPSettings\nfrom solidlsp.util.zip import SafeZipExtractor\n\nfrom .common import RuntimeDependency, RuntimeDependencyCollection\n\nlog = logging.getLogger(__name__)\n\n_RUNTIME_DEPENDENCIES = [\n    RuntimeDependency(\n        id=\"CSharpLanguageServer\",\n        description=\"Roslyn Language Server for Windows (x64)\",\n        package_name=\"roslyn-language-server.win-x64\",\n        package_version=\"5.5.0-2.26078.4\",\n        url=\"https://www.nuget.org/api/v2/package/roslyn-language-server.win-x64/5.5.0-2.26078.4\",\n        platform_id=\"win-x64\",\n        archive_type=\"nupkg\",\n        binary_name=\"Microsoft.CodeAnalysis.LanguageServer.dll\",\n        extract_path=\"tools/net10.0/win-x64\",\n    ),\n    RuntimeDependency(\n        id=\"CSharpLanguageServer\",\n        description=\"Roslyn Language Server for Windows (ARM64)\",\n        package_name=\"roslyn-language-server.win-arm64\",\n        package_version=\"5.5.0-2.26078.4\",\n        url=\"https://www.nuget.org/api/v2/package/roslyn-language-server.win-arm64/5.5.0-2.26078.4\",\n        platform_id=\"win-arm64\",\n        archive_type=\"nupkg\",\n        binary_name=\"Microsoft.CodeAnalysis.LanguageServer.dll\",\n        extract_path=\"tools/net10.0/win-arm64\",\n    ),\n    RuntimeDependency(\n        id=\"CSharpLanguageServer\",\n        description=\"Roslyn Language Server for macOS (x64)\",\n        package_name=\"roslyn-language-server.osx-x64\",\n        package_version=\"5.5.0-2.26078.4\",\n        url=\"https://www.nuget.org/api/v2/package/roslyn-language-server.osx-x64/5.5.0-2.26078.4\",\n        platform_id=\"osx-x64\",\n        archive_type=\"nupkg\",\n        binary_name=\"Microsoft.CodeAnalysis.LanguageServer.dll\",\n        extract_path=\"tools/net10.0/osx-x64\",\n    ),\n    RuntimeDependency(\n        id=\"CSharpLanguageServer\",\n        description=\"Roslyn Language Server for macOS (ARM64)\",\n        package_name=\"roslyn-language-server.osx-arm64\",\n        package_version=\"5.5.0-2.26078.4\",\n        url=\"https://www.nuget.org/api/v2/package/roslyn-language-server.osx-arm64/5.5.0-2.26078.4\",\n        platform_id=\"osx-arm64\",\n        archive_type=\"nupkg\",\n        binary_name=\"Microsoft.CodeAnalysis.LanguageServer.dll\",\n        extract_path=\"tools/net10.0/osx-arm64\",\n    ),\n    RuntimeDependency(\n        id=\"CSharpLanguageServer\",\n        description=\"Roslyn Language Server for Linux (x64)\",\n        package_name=\"roslyn-language-server.linux-x64\",\n        package_version=\"5.5.0-2.26078.4\",\n        url=\"https://www.nuget.org/api/v2/package/roslyn-language-server.linux-x64/5.5.0-2.26078.4\",\n        platform_id=\"linux-x64\",\n        archive_type=\"nupkg\",\n        binary_name=\"Microsoft.CodeAnalysis.LanguageServer.dll\",\n        extract_path=\"tools/net10.0/linux-x64\",\n    ),\n    RuntimeDependency(\n        id=\"CSharpLanguageServer\",\n        description=\"Roslyn Language Server for Linux (ARM64)\",\n        package_name=\"roslyn-language-server.linux-arm64\",\n        package_version=\"5.5.0-2.26078.4\",\n        url=\"https://www.nuget.org/api/v2/package/roslyn-language-server.linux-arm64/5.5.0-2.26078.4\",\n        platform_id=\"linux-arm64\",\n        archive_type=\"nupkg\",\n        binary_name=\"Microsoft.CodeAnalysis.LanguageServer.dll\",\n        extract_path=\"tools/net10.0/linux-arm64\",\n    ),\n]\n\n\ndef breadth_first_file_scan(root_dir: str) -> Iterable[str]:\n    \"\"\"\n    Perform a breadth-first scan of files in the given directory.\n    Yields file paths in breadth-first order.\n    \"\"\"\n    queue = [root_dir]\n    while queue:\n        current_dir = queue.pop(0)\n        try:\n            for item in os.listdir(current_dir):\n                if item.startswith(\".\"):\n                    continue\n                item_path = os.path.join(current_dir, item)\n                if os.path.isdir(item_path):\n                    queue.append(item_path)\n                elif os.path.isfile(item_path):\n                    yield item_path\n        except (PermissionError, OSError):\n            # Skip directories we can't access\n            pass\n\n\ndef find_solution_or_project_file(root_dir: str) -> str | None:\n    \"\"\"\n    Find the first .sln or .slnx file in breadth-first order.\n    If no solution file is found, look for a .csproj file.\n    \"\"\"\n    sln_file = None\n    csproj_file = None\n\n    for filename in breadth_first_file_scan(root_dir):\n        if filename.endswith((\".sln\", \".slnx\")) and sln_file is None:\n            sln_file = filename\n        elif filename.endswith(\".csproj\") and csproj_file is None:\n            csproj_file = filename\n\n        # If we found a solution file, return it immediately\n        if sln_file:\n            return sln_file\n\n    # If no solution file was found, return the first .csproj file\n    return csproj_file\n\n\nclass CSharpLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides C# specific instantiation of the LanguageServer class using the official Roslyn-based\n    language server from NuGet.org.\n\n    You can pass a list of runtime dependency overrides in ls_specific_settings[\"csharp\"][\"runtime_dependencies\"].\n    This is a list of dicts, each containing at least the \"id\" key, and optionally \"platform_id\" to uniquely\n    identify the dependency to override.\n\n    Example - Override Roslyn Language Server URL:\n    ```\n        {\n            \"id\": \"CSharpLanguageServer\",\n            \"platform_id\": \"win-x64\",\n            \"url\": \"https://example.com/custom-roslyn-server.nupkg\"\n        }\n    ```\n\n    See the `_RUNTIME_DEPENDENCIES` variable above for the available dependency ids and platform_ids.\n\n    Note: .NET runtime (version 10+) is required and installed automatically via Microsoft's official install\n    scripts. If you have a custom .NET installation, ensure 'dotnet' is available in PATH with version 10 or higher.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a CSharpLanguageServer instance. This class is not meant to be instantiated directly.\n        Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(config, repository_root_path, None, \"csharp\", solidlsp_settings)\n        # Cache for original Roslyn symbol names with type annotations\n        # Key: (relative_file_path, line, character) -> Value: original name\n        self._original_symbol_names: dict[tuple[str, int, int], str] = {}\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir, self._solidlsp_settings, self.repository_root_path)\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\"bin\", \"obj\", \"packages\", \".vs\"]\n\n    @override\n    def request_document_symbols(self, relative_file_path: str, file_buffer: Any = None) -> DocumentSymbols:\n        \"\"\"\n        Override to normalize Roslyn symbol names and cache originals.\n\n        Roslyn 5.5.0+ returns symbol names with type annotations:\n        - Properties: \"Name : string\"\n        - Methods: \"Add(int, int) : int\"\n\n        This method:\n        1. Normalizes names to base form (\"Name\", \"Add\")\n        2. Caches original names for rich information display\n        3. Populates LSP spec's 'detail' field with type/signature info\n        \"\"\"\n        symbols = super().request_document_symbols(relative_file_path, file_buffer)\n\n        # Normalize all symbols recursively\n        for symbol in symbols.iter_symbols():\n            self._normalize_symbol_name(symbol, relative_file_path)\n\n        return symbols\n\n    @override\n    def request_hover(self, relative_file_path: str, line: int, column: int, file_buffer: LSPFileBuffer | None = None) -> Hover | None:\n        \"\"\"\n        Override to inject original Roslyn symbol names (with type annotations) into hover responses.\n\n        When hovering over a symbol whose name was normalized, we prepend the original\n        full name (e.g., 'Add(int, int) : int') to the hover content.\n        \"\"\"\n        hover = super().request_hover(relative_file_path, line, column, file_buffer=file_buffer)\n\n        if hover is None:\n            return None\n\n        # Check if we have an original name for this position\n        original_name = self._original_symbol_names.get((relative_file_path, line, column))\n\n        if original_name and \"contents\" in hover:\n            contents = hover[\"contents\"]\n            if isinstance(contents, dict) and \"value\" in contents:\n                # Prepend the original full name with type information to the hover content\n                prefix = f\"**{original_name}**\\n\\n---\\n\\n\"\n                contents[\"value\"] = prefix + contents[\"value\"]\n\n        return hover\n\n    def _normalize_symbol_name(self, symbol: UnifiedSymbolInformation, relative_file_path: str) -> None:\n        \"\"\"\n        Normalize a single symbol's name and cache the original.\n        Processes children recursively.\n        \"\"\"\n        original_name = symbol.get(\"name\", \"\")\n\n        # Extract base name and type/signature info\n        normalized_name, type_info = self._extract_base_name_and_type(original_name)\n\n        # Store original name if it was normalized\n        if original_name != normalized_name:\n            sel_range = symbol.get(\"selectionRange\")\n            if sel_range:\n                start = sel_range.get(\"start\")\n                if start and \"line\" in start and \"character\" in start:\n                    line = start[\"line\"]\n                    char = start[\"character\"]\n                    cache_key = (relative_file_path, line, char)\n                    self._original_symbol_names[cache_key] = original_name\n\n            # Populate LSP spec's 'detail' field with type/signature information\n            if type_info and \"detail\" not in symbol:\n                symbol[\"detail\"] = type_info\n\n        # Update the symbol name\n        symbol[\"name\"] = normalized_name\n\n        # Process children recursively\n        children = symbol.get(\"children\", [])\n        for child in children:\n            self._normalize_symbol_name(child, relative_file_path)\n\n    @staticmethod\n    def _extract_base_name_and_type(roslyn_name: str) -> tuple[str, str]:\n        \"\"\"\n        Extract base name and type/signature information from Roslyn symbol names.\n\n        Examples:\n            \"Name : string\" -> (\"Name\", \": string\")\n            \"Add(int, int) : int\" -> (\"Add\", \"(int, int) : int\")\n            \"ToString()\" -> (\"ToString\", \"()\")\n            \"SimpleMethod\" -> (\"SimpleMethod\", \"\")\n\n        Returns:\n            Tuple of (base_name, type_info)\n\n        \"\"\"\n        # Check for property pattern: \"Name : Type\"\n        if \" : \" in roslyn_name and \"(\" not in roslyn_name:\n            base_name, type_part = roslyn_name.split(\" : \", 1)\n            return base_name.strip(), f\": {type_part.strip()}\"\n\n        # Check for method pattern: \"MethodName(params) : ReturnType\"\n        if \"(\" in roslyn_name:\n            paren_idx = roslyn_name.index(\"(\")\n            base_name = roslyn_name[:paren_idx].strip()\n            signature = roslyn_name[paren_idx:].strip()\n            return base_name, signature\n\n        # No type annotation\n        return roslyn_name, \"\"\n\n    class DependencyProvider(LanguageServerDependencyProvider):\n        def __init__(\n            self,\n            custom_settings: SolidLSPSettings.CustomLSSettings,\n            ls_resources_dir: str,\n            solidlsp_settings: SolidLSPSettings,\n            repository_root_path: str,\n        ):\n            super().__init__(custom_settings, ls_resources_dir)\n            self._solidlsp_settings = solidlsp_settings\n            self._repository_root_path = repository_root_path\n            self._dotnet_path, self._language_server_path = self._ensure_server_installed()\n\n        def create_launch_command(self) -> list[str]:\n            # Find solution or project file\n            solution_or_project = find_solution_or_project_file(self._repository_root_path)\n\n            # Create log directory\n            log_dir = Path(self._ls_resources_dir) / \"logs\"\n            log_dir.mkdir(parents=True, exist_ok=True)\n\n            # Build command using dotnet directly\n            cmd = [self._dotnet_path, self._language_server_path, \"--logLevel=Information\", f\"--extensionLogDirectory={log_dir}\", \"--stdio\"]\n\n            # The language server will discover the solution/project from the workspace root\n            if solution_or_project:\n                log.info(f\"Found solution/project file: {solution_or_project}\")\n            else:\n                log.warning(\"No .sln/.slnx or .csproj file found, language server will attempt auto-discovery\")\n\n            log.debug(f\"Language server command: {' '.join(cmd)}\")\n\n            return cmd\n\n        def _ensure_server_installed(self) -> tuple[str, str]:\n            \"\"\"\n            Ensure .NET runtime and Microsoft.CodeAnalysis.LanguageServer are available.\n            Returns a tuple of (dotnet_path, language_server_dll_path).\n            \"\"\"\n            runtime_dependency_overrides = cast(list[dict[str, Any]], self._custom_settings.get(\"runtime_dependencies\", []))\n\n            # Filter out deprecated DotNetRuntime overrides and warn users\n            filtered_overrides = []\n            for dep_override in runtime_dependency_overrides:\n                if dep_override.get(\"id\") == \"DotNetRuntime\":\n                    log.warning(\n                        \"The 'DotNetRuntime' runtime_dependencies override is no longer supported. \"\n                        \".NET is now installed automatically via Microsoft's official install scripts. \"\n                        \"Please remove this override from your configuration.\"\n                    )\n                else:\n                    filtered_overrides.append(dep_override)\n\n            log.debug(\"Resolving runtime dependencies\")\n\n            runtime_dependencies = RuntimeDependencyCollection(\n                _RUNTIME_DEPENDENCIES,\n                overrides=filtered_overrides,\n            )\n\n            log.debug(\n                f\"Available runtime dependencies: {runtime_dependencies.get_dependencies_for_current_platform}\",\n            )\n\n            # Find the dependencies for our platform\n            lang_server_dep = runtime_dependencies.get_single_dep_for_current_platform(\"CSharpLanguageServer\")\n            dotnet_path = self._ensure_dotnet_runtime()\n            server_dll_path = self._ensure_language_server(lang_server_dep)\n\n            return dotnet_path, server_dll_path\n\n        def _ensure_dotnet_runtime(self) -> str:\n            \"\"\"Ensure .NET runtime is available and return the dotnet executable path.\"\"\"\n            return DotNETUtil(\"10.0\", allow_higher_version=True).get_dotnet_path_or_raise()\n\n        def _ensure_language_server(self, lang_server_dep: RuntimeDependency) -> str:\n            \"\"\"Ensure language server is available and return the DLL path.\"\"\"\n            package_name = lang_server_dep.package_name\n            package_version = lang_server_dep.package_version\n\n            server_dir = Path(self._ls_resources_dir) / f\"{package_name}.{package_version}\"\n            assert lang_server_dep.binary_name is not None\n            server_dll = server_dir / lang_server_dep.binary_name\n\n            if server_dll.exists():\n                log.info(f\"Using cached Roslyn Language Server from {server_dll}\")\n                return str(server_dll)\n\n            # Download and install the language server\n            log.info(f\"Downloading {package_name} version {package_version} from NuGet.org...\")\n            package_path = self._download_nuget_package(lang_server_dep)\n\n            # Extract and install\n            self._extract_language_server(lang_server_dep, package_path, server_dir)\n\n            if not server_dll.exists():\n                raise SolidLSPException(\"Roslyn Language Server DLL not found after extraction\")\n\n            # Make executable on Unix systems\n            if platform.system().lower() != \"windows\":\n                server_dll.chmod(0o755)\n\n            log.info(f\"Successfully installed Roslyn Language Server to {server_dll}\")\n            return str(server_dll)\n\n        @staticmethod\n        def _extract_language_server(lang_server_dep: RuntimeDependency, package_path: Path, server_dir: Path) -> None:\n            \"\"\"Extract language server files from downloaded package.\"\"\"\n            extract_path = lang_server_dep.extract_path or \"lib/net9.0\"\n            source_dir = package_path / extract_path\n\n            if not source_dir.exists():\n                # Try alternative locations\n                for possible_dir in [\n                    package_path / \"tools\" / \"net9.0\" / \"any\",\n                    package_path / \"lib\" / \"net9.0\",\n                    package_path / \"contentFiles\" / \"any\" / \"net9.0\",\n                ]:\n                    if possible_dir.exists():\n                        source_dir = possible_dir\n                        break\n                else:\n                    raise SolidLSPException(f\"Could not find language server files in package. Searched in {package_path}\")\n\n            # Copy files to cache directory\n            server_dir.mkdir(parents=True, exist_ok=True)\n            shutil.copytree(source_dir, server_dir, dirs_exist_ok=True)\n\n        def _download_nuget_package(self, dependency: RuntimeDependency) -> Path:\n            \"\"\"\n            Download a NuGet package from NuGet.org and extract it.\n            Returns the path to the extracted package directory.\n            \"\"\"\n            package_name = dependency.package_name\n            package_version = dependency.package_version\n            url = dependency.url\n\n            if url is None:\n                raise SolidLSPException(f\"No URL specified for package {package_name} version {package_version}\")\n\n            # Create temporary directory for package download\n            temp_dir = Path(self._ls_resources_dir) / \"temp_downloads\"\n            temp_dir.mkdir(parents=True, exist_ok=True)\n\n            try:\n                log.debug(f\"Downloading package from: {url}\")\n\n                # Download the .nupkg file\n                nupkg_file = temp_dir / f\"{package_name}.{package_version}.nupkg\"\n                urllib.request.urlretrieve(url, nupkg_file)\n\n                # Extract the .nupkg file (it's just a zip file)\n                package_extract_dir = temp_dir / f\"{package_name}.{package_version}\"\n                package_extract_dir.mkdir(exist_ok=True)\n\n                # Use SafeZipExtractor to handle long paths and skip errors\n                extractor = SafeZipExtractor(archive_path=nupkg_file, extract_dir=package_extract_dir, verbose=False)\n                extractor.extract_all()\n\n                # Clean up the nupkg file\n                nupkg_file.unlink()\n\n                log.info(f\"Successfully downloaded and extracted {package_name} version {package_version} from NuGet.org\")\n                return package_extract_dir\n\n            except Exception as e:\n                raise SolidLSPException(f\"Failed to download package {package_name} version {package_version} from NuGet.org: {e}\") from e\n\n    def _get_initialize_params(self) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Microsoft.CodeAnalysis.LanguageServer.\n        \"\"\"\n        root_uri = PathUtils.path_to_uri(self.repository_root_path)\n        root_name = os.path.basename(self.repository_root_path)\n        return cast(\n            InitializeParams,\n            {\n                \"workspaceFolders\": [{\"uri\": root_uri, \"name\": root_name}],\n                \"processId\": os.getpid(),\n                \"rootPath\": self.repository_root_path,\n                \"rootUri\": root_uri,\n                \"capabilities\": {\n                    \"window\": {\n                        \"workDoneProgress\": True,\n                        \"showMessage\": {\"messageActionItem\": {\"additionalPropertiesSupport\": True}},\n                        \"showDocument\": {\"support\": True},\n                    },\n                    \"workspace\": {\n                        \"applyEdit\": True,\n                        \"workspaceEdit\": {\"documentChanges\": True},\n                        \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                        \"didChangeWatchedFiles\": {\"dynamicRegistration\": True},\n                        \"symbol\": {\n                            \"dynamicRegistration\": True,\n                            \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                        },\n                        \"executeCommand\": {\"dynamicRegistration\": True},\n                        \"configuration\": True,\n                        \"workspaceFolders\": True,\n                        \"workDoneProgress\": True,\n                    },\n                    \"textDocument\": {\n                        \"synchronization\": {\"dynamicRegistration\": True, \"willSave\": True, \"willSaveWaitUntil\": True, \"didSave\": True},\n                        \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                        \"signatureHelp\": {\n                            \"dynamicRegistration\": True,\n                            \"signatureInformation\": {\n                                \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                                \"parameterInformation\": {\"labelOffsetSupport\": True},\n                            },\n                        },\n                        \"definition\": {\"dynamicRegistration\": True},\n                        \"references\": {\"dynamicRegistration\": True},\n                        \"documentSymbol\": {\n                            \"dynamicRegistration\": True,\n                            \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                            \"hierarchicalDocumentSymbolSupport\": True,\n                        },\n                    },\n                },\n            },\n        )\n\n    def _start_server(self) -> None:\n        indexing_complete = threading.Event()\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            \"\"\"Log messages from the language server.\"\"\"\n            message_text = msg.get(\"message\", \"\")\n            level = msg.get(\"type\", 4)  # Default to Log level\n\n            # Map LSP message types to Python logging levels\n            level_map = {1: logging.ERROR, 2: logging.WARNING, 3: logging.INFO, 4: logging.DEBUG}  # Error  # Warning  # Info  # Log\n\n            log.log(level_map.get(level, logging.DEBUG), f\"LSP: {message_text}\")\n\n        def handle_progress(params: dict) -> None:\n            \"\"\"Handle progress notifications from the language server.\"\"\"\n            token = params.get(\"token\", \"\")\n            value = params.get(\"value\", {})\n\n            # Log raw progress for debugging\n            log.debug(f\"Progress notification received: {params}\")\n\n            # Handle different progress notification types\n            kind = value.get(\"kind\")\n\n            if kind == \"begin\":\n                title = value.get(\"title\", \"Operation in progress\")\n                message = value.get(\"message\", \"\")\n                percentage = value.get(\"percentage\")\n\n                if percentage is not None:\n                    log.debug(f\"Progress [{token}]: {title} - {message} ({percentage}%)\")\n                else:\n                    log.info(f\"Progress [{token}]: {title} - {message}\")\n\n            elif kind == \"report\":\n                message = value.get(\"message\", \"\")\n                percentage = value.get(\"percentage\")\n\n                if percentage is not None:\n                    log.info(f\"Progress [{token}]: {message} ({percentage}%)\")\n                elif message:\n                    log.info(f\"Progress [{token}]: {message}\")\n\n            elif kind == \"end\":\n                message = value.get(\"message\", \"Operation completed\")\n                log.info(f\"Progress [{token}]: {message}\")\n\n        def handle_workspace_configuration(params: dict) -> list:\n            \"\"\"Handle workspace/configuration requests from the server.\"\"\"\n            items = params.get(\"items\", [])\n            result: list[Any] = []\n\n            for item in items:\n                section = item.get(\"section\", \"\")\n\n                # Provide default values based on the configuration section\n                if section.startswith((\"dotnet\", \"csharp\")):\n                    # Default configuration for C# settings\n                    if \"enable\" in section or \"show\" in section or \"suppress\" in section or \"navigate\" in section:\n                        # Boolean settings\n                        result.append(False)\n                    elif \"scope\" in section:\n                        # Scope settings - use appropriate enum values\n                        if \"analyzer_diagnostics_scope\" in section:\n                            result.append(\"openFiles\")  # BackgroundAnalysisScope\n                        elif \"compiler_diagnostics_scope\" in section:\n                            result.append(\"openFiles\")  # CompilerDiagnosticsScope\n                        else:\n                            result.append(\"openFiles\")\n                    elif section == \"dotnet_member_insertion_location\":\n                        # ImplementTypeInsertionBehavior enum\n                        result.append(\"with_other_members_of_the_same_kind\")\n                    elif section == \"dotnet_property_generation_behavior\":\n                        # ImplementTypePropertyGenerationBehavior enum\n                        result.append(\"prefer_throwing_properties\")\n                    elif \"location\" in section or \"behavior\" in section:\n                        # Other enum settings - return null to avoid parsing errors\n                        result.append(None)\n                    else:\n                        # Default for other dotnet/csharp settings\n                        result.append(None)\n                elif section == \"tab_width\" or section == \"indent_size\":\n                    # Tab and indent settings\n                    result.append(4)\n                elif section == \"insert_final_newline\":\n                    # Editor settings\n                    result.append(True)\n                else:\n                    # Unknown configuration - return null\n                    result.append(None)\n\n            return result\n\n        def handle_work_done_progress_create(params: dict) -> None:\n            \"\"\"Handle work done progress create requests.\"\"\"\n            # Just acknowledge the request\n            return\n\n        def handle_register_capability(params: dict) -> None:\n            \"\"\"Handle client/registerCapability requests.\"\"\"\n            # Just acknowledge the request - we don't need to track these for now\n            return\n\n        def handle_project_needs_restore(params: dict) -> None:\n            return\n\n        def handle_workspace_indexing_complete(params: dict) -> None:\n            indexing_complete.set()\n\n        # Set up notification handlers\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", handle_progress)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"workspace/projectInitializationComplete\", handle_workspace_indexing_complete)\n        self.server.on_request(\"workspace/configuration\", handle_workspace_configuration)\n        self.server.on_request(\"window/workDoneProgress/create\", handle_work_done_progress_create)\n        self.server.on_request(\"client/registerCapability\", handle_register_capability)\n        self.server.on_request(\"workspace/_roslyn_projectNeedsRestore\", handle_project_needs_restore)\n\n        log.info(\"Starting Microsoft.CodeAnalysis.LanguageServer process\")\n\n        try:\n            self.server.start()\n        except Exception as e:\n            log.info(f\"Failed to start language server process: {e}\", logging.ERROR)\n            raise SolidLSPException(f\"Failed to start C# language server: {e}\")\n\n        # Send initialization\n        initialize_params = self._get_initialize_params()\n\n        log.info(\"Sending initialize request to language server\")\n        try:\n            init_response = self.server.send.initialize(initialize_params)\n            log.info(f\"Received initialize response: {init_response}\")\n        except Exception as e:\n            raise SolidLSPException(f\"Failed to initialize C# language server for {self.repository_root_path}: {e}\") from e\n\n        # Apply diagnostic capabilities\n        self._force_pull_diagnostics(init_response)\n\n        # Verify required capabilities\n        capabilities = init_response.get(\"capabilities\", {})\n        required_capabilities = [\n            \"textDocumentSync\",\n            \"definitionProvider\",\n            \"referencesProvider\",\n            \"documentSymbolProvider\",\n        ]\n        missing = [cap for cap in required_capabilities if cap not in capabilities]\n        if missing:\n            raise RuntimeError(\n                f\"Language server is missing required capabilities: {', '.join(missing)}. \"\n                \"Initialization failed. Please ensure the correct version of Microsoft.CodeAnalysis.LanguageServer is installed and the .NET runtime is working.\"\n            )\n\n        # Complete initialization\n        self.server.notify.initialized({})\n\n        # Open solution and project files\n        self._open_solution_and_projects()\n\n        log.info(\n            \"Microsoft.CodeAnalysis.LanguageServer initialized and ready\\n\"\n            \"Waiting for language server to index project files...\\n\"\n            \"This may take a while for large projects\"\n        )\n\n        if indexing_complete.wait(30):  # Wait up to 30 seconds for indexing\n            log.info(\"Indexing complete\")\n        else:\n            log.warning(\"Timeout waiting for indexing to complete, proceeding anyway\")\n\n    def _force_pull_diagnostics(self, init_response: dict | InitializeResult) -> None:\n        \"\"\"\n        Apply the diagnostic capabilities hack.\n        Forces the server to support pull diagnostics.\n        \"\"\"\n        capabilities = init_response.get(\"capabilities\", {})\n        diagnostic_provider: Any = capabilities.get(\"diagnosticProvider\", {})\n\n        # Add the diagnostic capabilities hack\n        if isinstance(diagnostic_provider, dict):\n            diagnostic_provider.update(\n                {\n                    \"interFileDependencies\": True,\n                    \"workDoneProgress\": True,\n                    \"workspaceDiagnostics\": True,\n                }\n            )\n            log.debug(\"Applied diagnostic capabilities hack for better C# diagnostics\")\n\n    def _open_solution_and_projects(self) -> None:\n        \"\"\"\n        Open solution and project files using notifications.\n        \"\"\"\n        # Find solution file (.sln or .slnx)\n        solution_file = None\n        for filename in breadth_first_file_scan(self.repository_root_path):\n            if filename.endswith((\".sln\", \".slnx\")):\n                solution_file = filename\n                break\n\n        # Send solution/open notification if solution file found\n        if solution_file:\n            solution_uri = PathUtils.path_to_uri(solution_file)\n            self.server.notify.send_notification(\"solution/open\", {\"solution\": solution_uri})\n            log.debug(f\"Opened solution file: {solution_file}\")\n\n        # Find and open project files\n        project_files = []\n        for filename in breadth_first_file_scan(self.repository_root_path):\n            if filename.endswith(\".csproj\"):\n                project_files.append(filename)\n\n        # Send project/open notifications for each project file\n        if project_files:\n            project_uris = [PathUtils.path_to_uri(project_file) for project_file in project_files]\n            self.server.notify.send_notification(\"project/open\", {\"projects\": project_uris})\n            log.debug(f\"Opened project files: {project_files}\")\n\n    @override\n    def _get_wait_time_for_cross_file_referencing(self) -> float:\n        return 2\n"
  },
  {
    "path": "src/solidlsp/language_servers/dart_language_server.py",
    "content": "import logging\nimport os\nimport pathlib\nfrom typing import cast\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nfrom ..ls_config import LanguageServerConfig\nfrom ..lsp_protocol_handler.lsp_types import InitializeParams\nfrom .common import RuntimeDependency, RuntimeDependencyCollection\n\nlog = logging.getLogger(__name__)\n\n\nclass DartLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides Dart specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Dart.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings) -> None:\n        \"\"\"\n        Creates a DartServer instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.\n        \"\"\"\n        executable_path = self._setup_runtime_dependencies(solidlsp_settings)\n        super().__init__(\n            config, repository_root_path, ProcessLaunchInfo(cmd=executable_path, cwd=repository_root_path), \"dart\", solidlsp_settings\n        )\n\n    @classmethod\n    def _setup_runtime_dependencies(cls, solidlsp_settings: SolidLSPSettings) -> str:\n        deps = RuntimeDependencyCollection(\n            [\n                RuntimeDependency(\n                    id=\"DartLanguageServer\",\n                    description=\"Dart Language Server for Linux (x64)\",\n                    url=\"https://storage.googleapis.com/dart-archive/channels/stable/release/3.7.1/sdk/dartsdk-linux-x64-release.zip\",\n                    platform_id=\"linux-x64\",\n                    archive_type=\"zip\",\n                    binary_name=\"dart-sdk/bin/dart\",\n                ),\n                RuntimeDependency(\n                    id=\"DartLanguageServer\",\n                    description=\"Dart Language Server for Windows (x64)\",\n                    url=\"https://storage.googleapis.com/dart-archive/channels/stable/release/3.7.1/sdk/dartsdk-windows-x64-release.zip\",\n                    platform_id=\"win-x64\",\n                    archive_type=\"zip\",\n                    binary_name=\"dart-sdk/bin/dart.exe\",\n                ),\n                RuntimeDependency(\n                    id=\"DartLanguageServer\",\n                    description=\"Dart Language Server for Windows (arm64)\",\n                    url=\"https://storage.googleapis.com/dart-archive/channels/stable/release/3.7.1/sdk/dartsdk-windows-arm64-release.zip\",\n                    platform_id=\"win-arm64\",\n                    archive_type=\"zip\",\n                    binary_name=\"dart-sdk/bin/dart.exe\",\n                ),\n                RuntimeDependency(\n                    id=\"DartLanguageServer\",\n                    description=\"Dart Language Server for macOS (x64)\",\n                    url=\"https://storage.googleapis.com/dart-archive/channels/stable/release/3.7.1/sdk/dartsdk-macos-x64-release.zip\",\n                    platform_id=\"osx-x64\",\n                    archive_type=\"zip\",\n                    binary_name=\"dart-sdk/bin/dart\",\n                ),\n                RuntimeDependency(\n                    id=\"DartLanguageServer\",\n                    description=\"Dart Language Server for macOS (arm64)\",\n                    url=\"https://storage.googleapis.com/dart-archive/channels/stable/release/3.7.1/sdk/dartsdk-macos-arm64-release.zip\",\n                    platform_id=\"osx-arm64\",\n                    archive_type=\"zip\",\n                    binary_name=\"dart-sdk/bin/dart\",\n                ),\n            ]\n        )\n\n        dart_ls_dir = cls.ls_resources_dir(solidlsp_settings)\n        dart_executable_path = deps.binary_path(dart_ls_dir)\n\n        if not os.path.exists(dart_executable_path):\n            deps.install(dart_ls_dir)\n\n        assert os.path.exists(dart_executable_path)\n        os.chmod(dart_executable_path, 0o755)\n\n        return f\"{dart_executable_path} language-server --client-id multilspy.dart --client-version 1.2\"\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Dart Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"capabilities\": {},\n            \"initializationOptions\": {\n                \"onlyAnalyzeProjectsWithOpenFiles\": False,\n                \"closingLabels\": False,\n                \"outline\": False,\n                \"flutterOutline\": False,\n                \"allowOpenUri\": False,\n            },\n            \"trace\": \"verbose\",\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": pathlib.Path(repository_absolute_path).as_uri(),\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n\n        return cast(InitializeParams, initialize_params)\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Start the language server and yield when the server is ready.\n        \"\"\"\n\n        def execute_client_command_handler(params: dict) -> list:\n            return []\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def check_experimental_status(params: dict) -> None:\n            pass\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        self.server.on_request(\"client/registerCapability\", do_nothing)\n        self.server.on_notification(\"language/status\", do_nothing)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_request(\"workspace/executeClientCommand\", execute_client_command_handler)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"language/actionableNotification\", do_nothing)\n        self.server.on_notification(\"experimental/serverStatus\", check_experimental_status)\n\n        log.info(\"Starting dart-language-server server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n        log.debug(\"Sending initialize request to dart-language-server\")\n        init_response = self.server.send_request(\"initialize\", initialize_params)  # type: ignore\n        log.info(f\"Received initialize response from dart-language-server: {init_response}\")\n\n        self.server.notify.initialized({})\n"
  },
  {
    "path": "src/solidlsp/language_servers/eclipse_jdtls.py",
    "content": "\"\"\"\nProvides Java specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Java.\n\"\"\"\n\nimport dataclasses\nimport logging\nimport os\nimport pathlib\nimport shutil\nimport threading\nimport uuid\nfrom pathlib import PurePath\nfrom time import sleep\nfrom typing import cast\n\nfrom overrides import override\n\nfrom solidlsp import ls_types\nfrom solidlsp.ls import LanguageServerDependencyProvider, LSPFileBuffer, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.ls_types import UnifiedSymbolInformation\nfrom solidlsp.ls_utils import FileUtils, PlatformUtils\nfrom solidlsp.lsp_protocol_handler.lsp_types import DocumentSymbol, InitializeParams, SymbolInformation\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\n@dataclasses.dataclass\nclass RuntimeDependencyPaths:\n    \"\"\"\n    Stores the paths to the runtime dependencies of EclipseJDTLS\n    \"\"\"\n\n    gradle_path: str\n    lombok_jar_path: str\n    jre_path: str\n    jre_home_path: str\n    jdtls_launcher_jar_path: str\n    jdtls_readonly_config_path: str\n    intellicode_jar_path: str\n    intellisense_members_path: str\n\n\nclass EclipseJDTLS(SolidLanguageServer):\n    r\"\"\"\n    The EclipseJDTLS class provides a Java specific implementation of the LanguageServer class\n\n    You can configure the following options in ls_specific_settings (in serena_config.yml):\n        - maven_user_settings: Path to Maven settings.xml file (default: ~/.m2/settings.xml)\n        - gradle_user_home: Path to Gradle user home directory (default: ~/.gradle)\n        - gradle_wrapper_enabled: Whether to use the project's Gradle wrapper (default: false)\n        - gradle_java_home: Path to JDK for Gradle (default: null, uses bundled JRE)\n        - use_system_java_home: Whether to use the system's JAVA_HOME for JDTLS itself (default: false)\n\n    Example configuration in ~/.serena/serena_config.yml:\n    ```yaml\n    ls_specific_settings:\n      java:\n        maven_user_settings: \"/home/user/.m2/settings.xml\"  # Unix/Linux/Mac\n        # maven_user_settings: 'C:\\\\Users\\\\YourName\\\\.m2\\\\settings.xml'  # Windows (use single quotes!)\n        gradle_user_home: \"/home/user/.gradle\"  # Unix/Linux/Mac\n        # gradle_user_home: 'C:\\\\Users\\\\YourName\\\\.gradle'  # Windows (use single quotes!)\n        gradle_wrapper_enabled: true  # set to true for projects with custom plugins/repositories\n        gradle_java_home: \"/path/to/jdk\"  # set to override Gradle's JDK\n        use_system_java_home: true  # set to true to use system JAVA_HOME for JDTLS\n    ```\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a new EclipseJDTLS instance initializing the language server settings appropriately.\n        This class is not meant to be instantiated directly. Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(config, repository_root_path, None, \"java\", solidlsp_settings)\n\n        # Extract runtime_dependency_paths from the dependency provider\n        assert isinstance(self._dependency_provider, self.DependencyProvider)\n        self.runtime_dependency_paths = self._dependency_provider.runtime_dependency_paths\n\n        self._service_ready_event = threading.Event()\n        self._project_ready_event = threading.Event()\n        self._intellicode_enable_command_available = threading.Event()\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        ls_resources_dir = self.ls_resources_dir(self._solidlsp_settings)\n        return self.DependencyProvider(self._custom_settings, ls_resources_dir, self._solidlsp_settings, self.repository_root_path)\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        # Ignore common Java build directories from different build tools:\n        # - Maven: target\n        # - Gradle: build, .gradle\n        # - Eclipse: bin, .settings\n        # - IntelliJ IDEA: out, .idea\n        # - General: classes, dist, lib\n        return super().is_ignored_dirname(dirname) or dirname in [\n            \"target\",  # Maven\n            \"build\",  # Gradle\n            \"bin\",  # Eclipse\n            \"out\",  # IntelliJ IDEA\n            \"classes\",  # General\n            \"dist\",  # General\n            \"lib\",  # General\n        ]\n\n    class DependencyProvider(LanguageServerDependencyProvider):\n        def __init__(\n            self,\n            custom_settings: SolidLSPSettings.CustomLSSettings,\n            ls_resources_dir: str,\n            solidlsp_settings: SolidLSPSettings,\n            repository_root_path: str,\n        ):\n            super().__init__(custom_settings, ls_resources_dir)\n            self._solidlsp_settings = solidlsp_settings\n            self._repository_root_path = repository_root_path\n            self.runtime_dependency_paths = self._setup_runtime_dependencies(ls_resources_dir)\n\n        @classmethod\n        def _setup_runtime_dependencies(cls, ls_resources_dir: str) -> RuntimeDependencyPaths:\n            \"\"\"\n            Setup runtime dependencies for EclipseJDTLS and return the paths.\n            \"\"\"\n            platformId = PlatformUtils.get_platform_id()\n\n            runtime_dependencies = {\n                \"gradle\": {\n                    \"platform-agnostic\": {\n                        \"url\": \"https://services.gradle.org/distributions/gradle-8.14.2-bin.zip\",\n                        \"archiveType\": \"zip\",\n                        \"relative_extraction_path\": \".\",\n                    }\n                },\n                \"vscode-java\": {\n                    \"darwin-arm64\": {\n                        \"url\": \"https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-darwin-arm64-1.42.0-561.vsix\",\n                        \"archiveType\": \"zip\",\n                        \"relative_extraction_path\": \"vscode-java\",\n                    },\n                    \"osx-arm64\": {\n                        \"url\": \"https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-darwin-arm64-1.42.0-561.vsix\",\n                        \"archiveType\": \"zip\",\n                        \"relative_extraction_path\": \"vscode-java\",\n                        \"jre_home_path\": \"extension/jre/21.0.7-macosx-aarch64\",\n                        \"jre_path\": \"extension/jre/21.0.7-macosx-aarch64/bin/java\",\n                        \"lombok_jar_path\": \"extension/lombok/lombok-1.18.36.jar\",\n                        \"jdtls_launcher_jar_path\": \"extension/server/plugins/org.eclipse.equinox.launcher_1.7.0.v20250424-1814.jar\",\n                        \"jdtls_readonly_config_path\": \"extension/server/config_mac_arm\",\n                    },\n                    \"osx-x64\": {\n                        \"url\": \"https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-darwin-x64-1.42.0-561.vsix\",\n                        \"archiveType\": \"zip\",\n                        \"relative_extraction_path\": \"vscode-java\",\n                        \"jre_home_path\": \"extension/jre/21.0.7-macosx-x86_64\",\n                        \"jre_path\": \"extension/jre/21.0.7-macosx-x86_64/bin/java\",\n                        \"lombok_jar_path\": \"extension/lombok/lombok-1.18.36.jar\",\n                        \"jdtls_launcher_jar_path\": \"extension/server/plugins/org.eclipse.equinox.launcher_1.7.0.v20250424-1814.jar\",\n                        \"jdtls_readonly_config_path\": \"extension/server/config_mac\",\n                    },\n                    \"linux-arm64\": {\n                        \"url\": \"https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-linux-arm64-1.42.0-561.vsix\",\n                        \"archiveType\": \"zip\",\n                        \"relative_extraction_path\": \"vscode-java\",\n                        \"jre_home_path\": \"extension/jre/21.0.7-linux-aarch64\",\n                        \"jre_path\": \"extension/jre/21.0.7-linux-aarch64/bin/java\",\n                        \"lombok_jar_path\": \"extension/lombok/lombok-1.18.36.jar\",\n                        \"jdtls_launcher_jar_path\": \"extension/server/plugins/org.eclipse.equinox.launcher_1.7.0.v20250424-1814.jar\",\n                        \"jdtls_readonly_config_path\": \"extension/server/config_linux_arm\",\n                    },\n                    \"linux-x64\": {\n                        \"url\": \"https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-linux-x64-1.42.0-561.vsix\",\n                        \"archiveType\": \"zip\",\n                        \"relative_extraction_path\": \"vscode-java\",\n                        \"jre_home_path\": \"extension/jre/21.0.7-linux-x86_64\",\n                        \"jre_path\": \"extension/jre/21.0.7-linux-x86_64/bin/java\",\n                        \"lombok_jar_path\": \"extension/lombok/lombok-1.18.36.jar\",\n                        \"jdtls_launcher_jar_path\": \"extension/server/plugins/org.eclipse.equinox.launcher_1.7.0.v20250424-1814.jar\",\n                        \"jdtls_readonly_config_path\": \"extension/server/config_linux\",\n                    },\n                    \"win-x64\": {\n                        \"url\": \"https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-win32-x64-1.42.0-561.vsix\",\n                        \"archiveType\": \"zip\",\n                        \"relative_extraction_path\": \"vscode-java\",\n                        \"jre_home_path\": \"extension/jre/21.0.7-win32-x86_64\",\n                        \"jre_path\": \"extension/jre/21.0.7-win32-x86_64/bin/java.exe\",\n                        \"lombok_jar_path\": \"extension/lombok/lombok-1.18.36.jar\",\n                        \"jdtls_launcher_jar_path\": \"extension/server/plugins/org.eclipse.equinox.launcher_1.7.0.v20250424-1814.jar\",\n                        \"jdtls_readonly_config_path\": \"extension/server/config_win\",\n                    },\n                },\n                \"intellicode\": {\n                    \"platform-agnostic\": {\n                        \"url\": \"https://VisualStudioExptTeam.gallery.vsassets.io/_apis/public/gallery/publisher/VisualStudioExptTeam/extension/vscodeintellicode/1.2.30/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage\",\n                        \"alternate_url\": \"https://marketplace.visualstudio.com/_apis/public/gallery/publishers/VisualStudioExptTeam/vsextensions/vscodeintellicode/1.2.30/vspackage\",\n                        \"archiveType\": \"zip\",\n                        \"relative_extraction_path\": \"intellicode\",\n                        \"intellicode_jar_path\": \"extension/dist/com.microsoft.jdtls.intellicode.core-0.7.0.jar\",\n                        \"intellisense_members_path\": \"extension/dist/bundledModels/java_intellisense-members\",\n                    }\n                },\n            }\n\n            gradle_path = str(\n                PurePath(\n                    ls_resources_dir,\n                    \"gradle-8.14.2\",\n                )\n            )\n\n            if not os.path.exists(gradle_path):\n                FileUtils.download_and_extract_archive(\n                    runtime_dependencies[\"gradle\"][\"platform-agnostic\"][\"url\"],\n                    str(PurePath(gradle_path).parent),\n                    runtime_dependencies[\"gradle\"][\"platform-agnostic\"][\"archiveType\"],\n                )\n\n            assert os.path.exists(gradle_path)\n\n            dependency = runtime_dependencies[\"vscode-java\"][platformId.value]\n            vscode_java_path = str(PurePath(ls_resources_dir, dependency[\"relative_extraction_path\"]))\n            os.makedirs(vscode_java_path, exist_ok=True)\n            jre_home_path = str(PurePath(vscode_java_path, dependency[\"jre_home_path\"]))\n            jre_path = str(PurePath(vscode_java_path, dependency[\"jre_path\"]))\n            lombok_jar_path = str(PurePath(vscode_java_path, dependency[\"lombok_jar_path\"]))\n            jdtls_launcher_jar_path = str(PurePath(vscode_java_path, dependency[\"jdtls_launcher_jar_path\"]))\n            jdtls_readonly_config_path = str(PurePath(vscode_java_path, dependency[\"jdtls_readonly_config_path\"]))\n            if not all(\n                [\n                    os.path.exists(vscode_java_path),\n                    os.path.exists(jre_home_path),\n                    os.path.exists(jre_path),\n                    os.path.exists(lombok_jar_path),\n                    os.path.exists(jdtls_launcher_jar_path),\n                    os.path.exists(jdtls_readonly_config_path),\n                ]\n            ):\n                FileUtils.download_and_extract_archive(dependency[\"url\"], vscode_java_path, dependency[\"archiveType\"])\n\n            os.chmod(jre_path, 0o755)\n\n            assert os.path.exists(vscode_java_path)\n            assert os.path.exists(jre_home_path)\n            assert os.path.exists(jre_path)\n            assert os.path.exists(lombok_jar_path)\n            assert os.path.exists(jdtls_launcher_jar_path)\n            assert os.path.exists(jdtls_readonly_config_path)\n\n            dependency = runtime_dependencies[\"intellicode\"][\"platform-agnostic\"]\n            intellicode_directory_path = str(PurePath(ls_resources_dir, dependency[\"relative_extraction_path\"]))\n            os.makedirs(intellicode_directory_path, exist_ok=True)\n            intellicode_jar_path = str(PurePath(intellicode_directory_path, dependency[\"intellicode_jar_path\"]))\n            intellisense_members_path = str(PurePath(intellicode_directory_path, dependency[\"intellisense_members_path\"]))\n            if not all(\n                [\n                    os.path.exists(intellicode_directory_path),\n                    os.path.exists(intellicode_jar_path),\n                    os.path.exists(intellisense_members_path),\n                ]\n            ):\n                FileUtils.download_and_extract_archive(dependency[\"url\"], intellicode_directory_path, dependency[\"archiveType\"])\n\n            assert os.path.exists(intellicode_directory_path)\n            assert os.path.exists(intellicode_jar_path)\n            assert os.path.exists(intellisense_members_path)\n\n            return RuntimeDependencyPaths(\n                gradle_path=gradle_path,\n                lombok_jar_path=lombok_jar_path,\n                jre_path=jre_path,\n                jre_home_path=jre_home_path,\n                jdtls_launcher_jar_path=jdtls_launcher_jar_path,\n                jdtls_readonly_config_path=jdtls_readonly_config_path,\n                intellicode_jar_path=intellicode_jar_path,\n                intellisense_members_path=intellisense_members_path,\n            )\n\n        def create_launch_command(self) -> list[str]:\n            # ws_dir is the workspace directory for the EclipseJDTLS server\n            ws_dir = str(\n                PurePath(\n                    self._solidlsp_settings.ls_resources_dir,\n                    \"EclipseJDTLS\",\n                    \"workspaces\",\n                    uuid.uuid4().hex,\n                )\n            )\n\n            # shared_cache_location is the global cache used by Eclipse JDTLS across all workspaces\n            shared_cache_location = str(PurePath(self._solidlsp_settings.ls_resources_dir, \"lsp\", \"EclipseJDTLS\", \"sharedIndex\"))\n            os.makedirs(shared_cache_location, exist_ok=True)\n            os.makedirs(ws_dir, exist_ok=True)\n\n            jre_path = self.runtime_dependency_paths.jre_path\n            lombok_jar_path = self.runtime_dependency_paths.lombok_jar_path\n\n            jdtls_launcher_jar = self.runtime_dependency_paths.jdtls_launcher_jar_path\n\n            data_dir = str(PurePath(ws_dir, \"data_dir\"))\n            jdtls_config_path = str(PurePath(ws_dir, \"config_path\"))\n\n            jdtls_readonly_config_path = self.runtime_dependency_paths.jdtls_readonly_config_path\n\n            if not os.path.exists(jdtls_config_path):\n                shutil.copytree(jdtls_readonly_config_path, jdtls_config_path)\n\n            for static_path in [\n                jre_path,\n                lombok_jar_path,\n                jdtls_launcher_jar,\n                jdtls_config_path,\n                jdtls_readonly_config_path,\n            ]:\n                assert os.path.exists(static_path), static_path\n\n            cmd = [\n                jre_path,\n                \"--add-modules=ALL-SYSTEM\",\n                \"--add-opens\",\n                \"java.base/java.util=ALL-UNNAMED\",\n                \"--add-opens\",\n                \"java.base/java.lang=ALL-UNNAMED\",\n                \"--add-opens\",\n                \"java.base/sun.nio.fs=ALL-UNNAMED\",\n                \"-Declipse.application=org.eclipse.jdt.ls.core.id1\",\n                \"-Dosgi.bundles.defaultStartLevel=4\",\n                \"-Declipse.product=org.eclipse.jdt.ls.core.product\",\n                \"-Djava.import.generatesMetadataFilesAtProjectRoot=false\",\n                \"-Dfile.encoding=utf8\",\n                \"-noverify\",\n                \"-XX:+UseParallelGC\",\n                \"-XX:GCTimeRatio=4\",\n                \"-XX:AdaptiveSizePolicyWeight=90\",\n                \"-Dsun.zip.disableMemoryMapping=true\",\n                \"-Djava.lsp.joinOnCompletion=true\",\n                \"-Xmx3G\",\n                \"-Xms100m\",\n                \"-Xlog:disable\",\n                \"-Dlog.level=ALL\",\n                f\"-javaagent:{lombok_jar_path}\",\n                f\"-Djdt.core.sharedIndexLocation={shared_cache_location}\",\n                \"-jar\",\n                f\"{jdtls_launcher_jar}\",\n                \"-configuration\",\n                f\"{jdtls_config_path}\",\n                \"-data\",\n                f\"{data_dir}\",\n            ]\n\n            return cmd\n\n        def create_launch_command_env(self) -> dict[str, str]:\n            use_system_java_home = self._custom_settings.get(\"use_system_java_home\", False)\n            if use_system_java_home:\n                system_java_home = os.environ.get(\"JAVA_HOME\")\n                if system_java_home:\n                    log.info(f\"Using system JAVA_HOME for JDTLS: {system_java_home}\")\n                    return {\"syntaxserver\": \"false\", \"JAVA_HOME\": system_java_home}\n                else:\n                    log.warning(\"use_system_java_home is set but JAVA_HOME is not set in environment, falling back to bundled JRE\")\n            java_home = self.runtime_dependency_paths.jre_home_path\n            log.info(f\"Using bundled JRE for JDTLS: {java_home}\")\n            return {\"syntaxserver\": \"false\", \"JAVA_HOME\": java_home}\n\n    def _get_initialize_params(self, repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize parameters for the EclipseJDTLS server.\n        \"\"\"\n        # Look into https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java to understand all the options available\n\n        if not os.path.isabs(repository_absolute_path):\n            repository_absolute_path = os.path.abspath(repository_absolute_path)\n        repo_uri = pathlib.Path(repository_absolute_path).as_uri()\n\n        # Load user's Maven and Gradle configuration paths from ls_specific_settings[\"java\"]\n\n        # Maven settings: default to ~/.m2/settings.xml\n        default_maven_settings_path = os.path.join(os.path.expanduser(\"~\"), \".m2\", \"settings.xml\")\n        custom_maven_settings_path = self._custom_settings.get(\"maven_user_settings\")\n        if custom_maven_settings_path is not None:\n            # User explicitly provided a path\n            if not os.path.exists(custom_maven_settings_path):\n                error_msg = (\n                    f\"Provided maven settings file not found: {custom_maven_settings_path}. \"\n                    f\"Fix: create the file, update path in ~/.serena/serena_config.yml (ls_specific_settings -> java -> maven_user_settings), \"\n                    f\"or remove the setting to use default ({default_maven_settings_path})\"\n                )\n                log.error(error_msg)\n                raise FileNotFoundError(error_msg)\n            maven_settings_path = custom_maven_settings_path\n            log.info(f\"Using Maven settings from custom location: {maven_settings_path}\")\n        elif os.path.exists(default_maven_settings_path):\n            maven_settings_path = default_maven_settings_path\n            log.info(f\"Using Maven settings from default location: {maven_settings_path}\")\n        else:\n            maven_settings_path = None\n            log.info(f\"Maven settings not found at default location ({default_maven_settings_path}), will use JDTLS defaults\")\n\n        # Gradle user home: default to ~/.gradle\n        default_gradle_home = os.path.join(os.path.expanduser(\"~\"), \".gradle\")\n        custom_gradle_home = self._custom_settings.get(\"gradle_user_home\")\n        if custom_gradle_home is not None:\n            # User explicitly provided a path\n            if not os.path.exists(custom_gradle_home):\n                error_msg = (\n                    f\"Gradle user home directory not found: {custom_gradle_home}. \"\n                    f\"Fix: create the directory, update path in ~/.serena/serena_config.yml (ls_specific_settings -> java -> gradle_user_home), \"\n                    f\"or remove the setting to use default (~/.gradle)\"\n                )\n                log.error(error_msg)\n                raise FileNotFoundError(error_msg)\n            gradle_user_home = custom_gradle_home\n            log.info(f\"Using Gradle user home from custom location: {gradle_user_home}\")\n        elif os.path.exists(default_gradle_home):\n            gradle_user_home = default_gradle_home\n            log.info(f\"Using Gradle user home from default location: {gradle_user_home}\")\n        else:\n            gradle_user_home = None\n            log.info(f\"Gradle user home not found at default location ({default_gradle_home}), will use JDTLS defaults\")\n\n        # Gradle wrapper: default to False to preserve existing behaviour\n        gradle_wrapper_enabled = self._custom_settings.get(\"gradle_wrapper_enabled\", False)\n        log.info(\n            f\"Gradle wrapper {'enabled' if gradle_wrapper_enabled else 'disabled'} (configurable via ls_specific_settings -> java -> gradle_wrapper_enabled)\"\n        )\n\n        # Gradle Java home: default to None, which means the bundled JRE is used\n        gradle_java_home = self._custom_settings.get(\"gradle_java_home\")\n        if gradle_java_home is not None:\n            if not os.path.exists(gradle_java_home):\n                error_msg = (\n                    f\"Gradle Java home not found: {gradle_java_home}. \"\n                    f\"Fix: update path in ~/.serena/serena_config.yml (ls_specific_settings -> java -> gradle_java_home), \"\n                    f\"or remove the setting to use the bundled JRE\"\n                )\n                log.error(error_msg)\n                raise FileNotFoundError(error_msg)\n            log.info(f\"Using Gradle Java home from custom location: {gradle_java_home}\")\n        else:\n            log.info(f\"Using bundled JRE for Gradle: {self.runtime_dependency_paths.jre_path}\")\n\n        initialize_params = {\n            \"locale\": \"en\",\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": pathlib.Path(repository_absolute_path).as_uri(),\n            \"capabilities\": {\n                \"workspace\": {\n                    \"applyEdit\": True,\n                    \"workspaceEdit\": {\n                        \"documentChanges\": True,\n                        \"resourceOperations\": [\"create\", \"rename\", \"delete\"],\n                        \"failureHandling\": \"textOnlyTransactional\",\n                        \"normalizesLineEndings\": True,\n                        \"changeAnnotationSupport\": {\"groupsOnLabel\": True},\n                    },\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"didChangeWatchedFiles\": {\"dynamicRegistration\": True, \"relativePatternSupport\": True},\n                    \"symbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                        \"tagSupport\": {\"valueSet\": [1]},\n                        \"resolveSupport\": {\"properties\": [\"location.range\"]},\n                    },\n                    \"codeLens\": {\"refreshSupport\": True},\n                    \"executeCommand\": {\"dynamicRegistration\": True},\n                    \"configuration\": True,\n                    \"workspaceFolders\": True,\n                    \"semanticTokens\": {\"refreshSupport\": True},\n                    \"fileOperations\": {\n                        \"dynamicRegistration\": True,\n                        \"didCreate\": True,\n                        \"didRename\": True,\n                        \"didDelete\": True,\n                        \"willCreate\": True,\n                        \"willRename\": True,\n                        \"willDelete\": True,\n                    },\n                    \"inlineValue\": {\"refreshSupport\": True},\n                    \"inlayHint\": {\"refreshSupport\": True},\n                    \"diagnostics\": {\"refreshSupport\": True},\n                },\n                \"textDocument\": {\n                    \"publishDiagnostics\": {\n                        \"relatedInformation\": True,\n                        \"versionSupport\": False,\n                        \"tagSupport\": {\"valueSet\": [1, 2]},\n                        \"codeDescriptionSupport\": True,\n                        \"dataSupport\": True,\n                    },\n                    \"synchronization\": {\"dynamicRegistration\": True, \"willSave\": True, \"willSaveWaitUntil\": True, \"didSave\": True},\n                    # TODO: we have an assert that completion provider is not included in the capabilities at server startup\n                    #   Removing this will cause the assert to fail. Investigate why this is the case, simplify config\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"contextSupport\": True,\n                        \"completionItem\": {\n                            \"snippetSupport\": False,\n                            \"commitCharactersSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"deprecatedSupport\": True,\n                            \"preselectSupport\": True,\n                            \"tagSupport\": {\"valueSet\": [1]},\n                            \"insertReplaceSupport\": False,\n                            \"resolveSupport\": {\"properties\": [\"documentation\", \"detail\", \"additionalTextEdits\"]},\n                            \"insertTextModeSupport\": {\"valueSet\": [1, 2]},\n                            \"labelDetailsSupport\": True,\n                        },\n                        \"insertTextMode\": 2,\n                        \"completionItemKind\": {\n                            \"valueSet\": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]\n                        },\n                        \"completionList\": {\"itemDefaults\": [\"commitCharacters\", \"editRange\", \"insertTextFormat\", \"insertTextMode\"]},\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"signatureHelp\": {\n                        \"dynamicRegistration\": True,\n                        \"signatureInformation\": {\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"parameterInformation\": {\"labelOffsetSupport\": True},\n                            \"activeParameterSupport\": True,\n                        },\n                    },\n                    \"definition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"tagSupport\": {\"valueSet\": [1]},\n                        \"labelSupport\": True,\n                    },\n                    \"rename\": {\n                        \"dynamicRegistration\": True,\n                        \"prepareSupport\": True,\n                        \"prepareSupportDefaultBehavior\": 1,\n                        \"honorsChangeAnnotations\": True,\n                    },\n                    \"documentLink\": {\"dynamicRegistration\": True, \"tooltipSupport\": True},\n                    \"typeDefinition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"implementation\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"colorProvider\": {\"dynamicRegistration\": True},\n                    \"declaration\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"selectionRange\": {\"dynamicRegistration\": True},\n                    \"callHierarchy\": {\"dynamicRegistration\": True},\n                    \"semanticTokens\": {\n                        \"dynamicRegistration\": True,\n                        \"tokenTypes\": [\n                            \"namespace\",\n                            \"type\",\n                            \"class\",\n                            \"enum\",\n                            \"interface\",\n                            \"struct\",\n                            \"typeParameter\",\n                            \"parameter\",\n                            \"variable\",\n                            \"property\",\n                            \"enumMember\",\n                            \"event\",\n                            \"function\",\n                            \"method\",\n                            \"macro\",\n                            \"keyword\",\n                            \"modifier\",\n                            \"comment\",\n                            \"string\",\n                            \"number\",\n                            \"regexp\",\n                            \"operator\",\n                            \"decorator\",\n                        ],\n                        \"tokenModifiers\": [\n                            \"declaration\",\n                            \"definition\",\n                            \"readonly\",\n                            \"static\",\n                            \"deprecated\",\n                            \"abstract\",\n                            \"async\",\n                            \"modification\",\n                            \"documentation\",\n                            \"defaultLibrary\",\n                        ],\n                        \"formats\": [\"relative\"],\n                        \"requests\": {\"range\": True, \"full\": {\"delta\": True}},\n                        \"multilineTokenSupport\": False,\n                        \"overlappingTokenSupport\": False,\n                        \"serverCancelSupport\": True,\n                        \"augmentsSyntaxTokens\": True,\n                    },\n                    \"typeHierarchy\": {\"dynamicRegistration\": True},\n                    \"inlineValue\": {\"dynamicRegistration\": True},\n                    \"diagnostic\": {\"dynamicRegistration\": True, \"relatedDocumentSupport\": False},\n                },\n                \"general\": {\n                    \"staleRequestSupport\": {\n                        \"cancel\": True,\n                        \"retryOnContentModified\": [\n                            \"textDocument/semanticTokens/full\",\n                            \"textDocument/semanticTokens/range\",\n                            \"textDocument/semanticTokens/full/delta\",\n                        ],\n                    },\n                    \"regularExpressions\": {\"engine\": \"ECMAScript\", \"version\": \"ES2020\"},\n                    \"positionEncodings\": [\"utf-16\"],\n                },\n                \"notebookDocument\": {\"synchronization\": {\"dynamicRegistration\": True, \"executionSummarySupport\": True}},\n            },\n            \"initializationOptions\": {\n                \"bundles\": [\"intellicode-core.jar\"],\n                \"settings\": {\n                    \"java\": {\n                        \"home\": None,\n                        \"jdt\": {\n                            \"ls\": {\n                                \"java\": {\"home\": None},\n                                \"vmargs\": \"-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx1G -Xms100m -Xlog:disable\",\n                                \"lombokSupport\": {\"enabled\": True},\n                                \"protobufSupport\": {\"enabled\": True},\n                                \"androidSupport\": {\"enabled\": True},\n                            }\n                        },\n                        \"errors\": {\"incompleteClasspath\": {\"severity\": \"error\"}},\n                        \"configuration\": {\n                            \"checkProjectSettingsExclusions\": False,\n                            \"updateBuildConfiguration\": \"interactive\",\n                            \"maven\": {\n                                \"userSettings\": maven_settings_path,\n                                \"globalSettings\": None,\n                                \"notCoveredPluginExecutionSeverity\": \"warning\",\n                                \"defaultMojoExecutionAction\": \"ignore\",\n                            },\n                            \"workspaceCacheLimit\": 90,\n                            \"runtimes\": [\n                                {\"name\": \"JavaSE-21\", \"path\": \"static/vscode-java/extension/jre/21.0.7-linux-x86_64\", \"default\": True}\n                            ],\n                        },\n                        \"trace\": {\"server\": \"verbose\"},\n                        \"import\": {\n                            \"maven\": {\n                                \"enabled\": True,\n                                \"offline\": {\"enabled\": False},\n                                \"disableTestClasspathFlag\": False,\n                            },\n                            \"gradle\": {\n                                \"enabled\": True,\n                                \"wrapper\": {\"enabled\": gradle_wrapper_enabled},\n                                \"version\": None,\n                                \"home\": \"abs(static/gradle-7.3.3)\",\n                                \"offline\": {\"enabled\": False},\n                                \"arguments\": None,\n                                \"jvmArguments\": None,\n                                \"user\": {\"home\": gradle_user_home},\n                                \"annotationProcessing\": {\"enabled\": True},\n                            },\n                            \"exclusions\": [\n                                \"**/node_modules/**\",\n                                \"**/.metadata/**\",\n                                \"**/archetype-resources/**\",\n                                \"**/META-INF/maven/**\",\n                            ],\n                            \"generatesMetadataFilesAtProjectRoot\": False,\n                        },\n                        # Set updateSnapshots to False to improve performance and avoid unnecessary network calls\n                        # Snapshots will only be updated when explicitly requested by the user\n                        \"maven\": {\"downloadSources\": True, \"updateSnapshots\": False},\n                        \"eclipse\": {\"downloadSources\": True},\n                        \"signatureHelp\": {\"enabled\": True, \"description\": {\"enabled\": True}},\n                        \"hover\": {\"javadoc\": {\"enabled\": True}},\n                        \"implementationsCodeLens\": {\"enabled\": True},\n                        \"format\": {\n                            \"enabled\": True,\n                            \"settings\": {\"url\": None, \"profile\": None},\n                            \"comments\": {\"enabled\": True},\n                            \"onType\": {\"enabled\": True},\n                            \"insertSpaces\": True,\n                            \"tabSize\": 4,\n                        },\n                        \"saveActions\": {\"organizeImports\": False},\n                        \"project\": {\n                            \"referencedLibraries\": [\"lib/**/*.jar\"],\n                            \"importOnFirstTimeStartup\": \"automatic\",\n                            \"importHint\": True,\n                            \"resourceFilters\": [\"node_modules\", \"\\\\.git\"],\n                            \"encoding\": \"ignore\",\n                            \"exportJar\": {\"targetPath\": \"${workspaceFolder}/${workspaceFolderBasename}.jar\"},\n                        },\n                        \"contentProvider\": {\"preferred\": None},\n                        \"autobuild\": {\"enabled\": True},\n                        \"maxConcurrentBuilds\": 1,\n                        \"selectionRange\": {\"enabled\": True},\n                        \"showBuildStatusOnStart\": {\"enabled\": \"notification\"},\n                        \"server\": {\"launchMode\": \"Standard\"},\n                        \"sources\": {\"organizeImports\": {\"starThreshold\": 99, \"staticStarThreshold\": 99}},\n                        \"imports\": {\"gradle\": {\"wrapper\": {\"checksums\": []}}},\n                        \"templates\": {\"fileHeader\": [], \"typeComment\": []},\n                        \"references\": {\"includeAccessors\": True, \"includeDecompiledSources\": True},\n                        \"typeHierarchy\": {\"lazyLoad\": False},\n                        \"settings\": {\"url\": None},\n                        \"symbols\": {\"includeSourceMethodDeclarations\": False},\n                        \"inlayHints\": {\"parameterNames\": {\"enabled\": \"literals\", \"exclusions\": []}},\n                        \"codeAction\": {\"sortMembers\": {\"avoidVolatileChanges\": True}},\n                        \"compile\": {\n                            \"nullAnalysis\": {\n                                \"nonnull\": [\n                                    \"javax.annotation.Nonnull\",\n                                    \"org.eclipse.jdt.annotation.NonNull\",\n                                    \"org.springframework.lang.NonNull\",\n                                ],\n                                \"nullable\": [\n                                    \"javax.annotation.Nullable\",\n                                    \"org.eclipse.jdt.annotation.Nullable\",\n                                    \"org.springframework.lang.Nullable\",\n                                ],\n                                \"mode\": \"automatic\",\n                            }\n                        },\n                        \"sharedIndexes\": {\"enabled\": \"auto\", \"location\": \"\"},\n                        \"silentNotification\": False,\n                        \"dependency\": {\n                            \"showMembers\": False,\n                            \"syncWithFolderExplorer\": True,\n                            \"autoRefresh\": True,\n                            \"refreshDelay\": 2000,\n                            \"packagePresentation\": \"flat\",\n                        },\n                        \"help\": {\"firstView\": \"auto\", \"showReleaseNotes\": True, \"collectErrorLog\": False},\n                        \"test\": {\"defaultConfig\": \"\", \"config\": {}},\n                    }\n                },\n            },\n            \"trace\": \"verbose\",\n            \"processId\": os.getpid(),\n            \"workspaceFolders\": [\n                {\n                    \"uri\": repo_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n\n        initialize_params[\"initializationOptions\"][\"workspaceFolders\"] = [repo_uri]  # type: ignore\n        bundles = [self.runtime_dependency_paths.intellicode_jar_path]\n        initialize_params[\"initializationOptions\"][\"bundles\"] = bundles  # type: ignore\n        initialize_params[\"initializationOptions\"][\"settings\"][\"java\"][\"configuration\"][\"runtimes\"] = [  # type: ignore\n            {\"name\": \"JavaSE-21\", \"path\": self.runtime_dependency_paths.jre_home_path, \"default\": True}\n        ]\n\n        for runtime in initialize_params[\"initializationOptions\"][\"settings\"][\"java\"][\"configuration\"][\"runtimes\"]:  # type: ignore\n            assert \"name\" in runtime\n            assert \"path\" in runtime\n            assert os.path.exists(runtime[\"path\"]), f\"Runtime required for eclipse_jdtls at path {runtime['path']} does not exist\"\n\n        gradle_settings = initialize_params[\"initializationOptions\"][\"settings\"][\"java\"][\"import\"][\"gradle\"]  # type: ignore\n        gradle_settings[\"home\"] = self.runtime_dependency_paths.gradle_path\n        gradle_settings[\"java\"] = {\"home\": gradle_java_home if gradle_java_home is not None else self.runtime_dependency_paths.jre_path}\n        return cast(InitializeParams, initialize_params)\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the Eclipse JDTLS Language Server\n        \"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            assert \"registrations\" in params\n            for registration in params[\"registrations\"]:\n                if registration[\"method\"] == \"textDocument/completion\":\n                    assert registration[\"registerOptions\"][\"resolveProvider\"] == True\n                    assert registration[\"registerOptions\"][\"triggerCharacters\"] == [\n                        \".\",\n                        \"@\",\n                        \"#\",\n                        \"*\",\n                        \" \",\n                    ]\n                if registration[\"method\"] == \"workspace/executeCommand\":\n                    if \"java.intellicode.enable\" in registration[\"registerOptions\"][\"commands\"]:\n                        self._intellicode_enable_command_available.set()\n            return\n\n        def lang_status_handler(params: dict) -> None:\n            log.info(\"Language status update: %s\", params)\n            if params[\"type\"] == \"ServiceReady\" and params[\"message\"] == \"ServiceReady\":\n                self._service_ready_event.set()\n            if params[\"type\"] == \"ProjectStatus\":\n                if params[\"message\"] == \"OK\":\n                    self._project_ready_event.set()\n\n        def execute_client_command_handler(params: dict) -> list:\n            assert params[\"command\"] == \"_java.reloadBundles.command\"\n            assert params[\"arguments\"] == []\n            return []\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"language/status\", lang_status_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_request(\"workspace/executeClientCommand\", execute_client_command_handler)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"language/actionableNotification\", do_nothing)\n\n        log.info(\"Starting EclipseJDTLS server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        assert init_response[\"capabilities\"][\"textDocumentSync\"][\"change\"] == 2  # type: ignore\n        assert \"completionProvider\" not in init_response[\"capabilities\"]\n        assert \"executeCommandProvider\" not in init_response[\"capabilities\"]\n\n        self.server.notify.initialized({})\n\n        self.server.notify.workspace_did_change_configuration({\"settings\": initialize_params[\"initializationOptions\"][\"settings\"]})  # type: ignore\n\n        self._intellicode_enable_command_available.wait()\n\n        java_intellisense_members_path = self.runtime_dependency_paths.intellisense_members_path\n        assert os.path.exists(java_intellisense_members_path)\n        intellicode_enable_result = self.server.send.execute_command(\n            {\n                \"command\": \"java.intellicode.enable\",\n                \"arguments\": [True, java_intellisense_members_path],\n            }\n        )\n        assert intellicode_enable_result\n\n        if not self._service_ready_event.is_set():\n            log.info(\"Waiting for service to be ready ...\")\n            self._service_ready_event.wait()\n        log.info(\"Service is ready\")\n\n        if not self._project_ready_event.is_set():\n            log.info(\"Waiting for project to be ready ...\")\n            project_ready_timeout = 20  # Hotfix: Using timeout until we figure out why sometimes we don't get the project ready event\n            if self._project_ready_event.wait(timeout=project_ready_timeout):\n                log.info(\"Project is ready\")\n            else:\n                log.warning(\"Did not receive project ready status within %d seconds; proceeding anyway\", project_ready_timeout)\n        else:\n            log.info(\"Project is ready\")\n\n        log.info(\"Startup complete\")\n\n    @override\n    def _request_hover(self, file_buffer: LSPFileBuffer, line: int, column: int) -> ls_types.Hover | None:\n        # Eclipse JDTLS lazily loads javadocs on first hover request, then caches them.\n        # This means the first request often returns incomplete info (just the signature),\n        # while subsequent requests return the full javadoc.\n        #\n        # The response format also differs based on javadoc presence:\n        #   - contents: list[...] when javadoc IS present (preferred, richer format)\n        #   - contents: {value: info} when javadoc is NOT present\n        #\n        # There's no LSP signal for \"javadoc fully loaded\" and no way to request\n        # hover with \"wait for complete info\". The retry approach is the only viable\n        # workaround - we keep requesting until we get the richer list format or\n        # the content stops growing.\n        #\n        # The file is kept open by the caller (request_hover), so retries are cheap\n        # and don't cause repeated didOpen/didClose cycles.\n\n        def content_score(result: ls_types.Hover | None) -> tuple[int, int]:\n            \"\"\"Return (format_priority, length) for comparison. Higher is better.\"\"\"\n            if result is None:\n                return (0, 0)\n            contents = result[\"contents\"]\n            if isinstance(contents, list):\n                return (2, len(contents))  # List format (has javadoc) is best\n            elif isinstance(contents, dict):\n                return (1, len(contents.get(\"value\", \"\")))\n            else:\n                return (1, len(contents))\n\n        max_retries = 5\n        best_result = super()._request_hover(file_buffer, line, column)\n        best_score = content_score(best_result)\n\n        for _ in range(max_retries):\n            sleep(0.05)\n            new_result = super()._request_hover(file_buffer, line, column)\n            new_score = content_score(new_result)\n            if new_score > best_score:\n                best_result = new_result\n                best_score = new_score\n\n        return best_result\n\n    def _request_document_symbols(\n        self, relative_file_path: str, file_data: LSPFileBuffer | None\n    ) -> list[SymbolInformation] | list[DocumentSymbol] | None:\n        result = super()._request_document_symbols(relative_file_path, file_data=file_data)\n        if result is None:\n            return None\n\n        # JDTLS sometimes returns symbol names with type information to handle overloads,\n        # e.g. \"myMethod(int) <T>\", but we want overloads to be handled via overload_idx,\n        # which requires the name to be just \"myMethod\".\n\n        def fix_name(symbol: SymbolInformation | DocumentSymbol | UnifiedSymbolInformation) -> None:\n            if \"(\" in symbol[\"name\"]:\n                symbol[\"name\"] = symbol[\"name\"][: symbol[\"name\"].index(\"(\")]\n            children = symbol.get(\"children\")\n            if children:\n                for child in children:  # type: ignore\n                    fix_name(child)\n\n        for root_symbol in result:\n            fix_name(root_symbol)\n\n        return result\n"
  },
  {
    "path": "src/solidlsp/language_servers/elixir_tools/README.md",
    "content": "# Elixir Language Server Integration\n\nThis directory contains the integration for Elixir language support using [Expert](https://github.com/elixir-lang/expert), the official Elixir language server.\n\n## Prerequisites\n\nBefore using the Elixir language server integration, you need to have:\n\n1. **Elixir** installed and available in your PATH\n   - Install from: https://elixir-lang.org/install.html\n   - Verify with: `elixir --version`\n\n2. **Expert** (optional - will be downloaded automatically if not found)\n   - Expert binaries are automatically downloaded from GitHub releases\n   - Manual installation: https://github.com/elixir-lang/expert#installation\n   - If installed manually, ensure `expert` is in your PATH\n\n## Features\n\nThe Elixir integration provides:\n\n- **Language Server Protocol (LSP) support** via Next LS\n- **File extension recognition** for `.ex` and `.exs` files\n- **Project structure awareness** with proper handling of Elixir-specific directories:\n  - `_build/` - Compiled artifacts (ignored)\n  - `deps/` - Dependencies (ignored)\n  - `.elixir_ls/` - ElixirLS artifacts (ignored)\n  - `cover/` - Coverage reports (ignored)\n  - `lib/` - Source code (not ignored)\n  - `test/` - Test files (not ignored)\n\n## Configuration\n\nThe integration uses the default Expert configuration with:\n\n- **MIX_ENV**: `dev`\n- **MIX_TARGET**: `host`\n- **Experimental completions**: Disabled by default\n- **Credo extension**: Enabled by default\n\n### Version Management (asdf)\n\nExpert automatically respects project-specific Elixir versions when using asdf:\n- If a `.tool-versions` file exists in the project root, Expert will use the specified Elixir version\n- Expert is launched from the project directory, allowing it to pick up project configuration\n- No additional configuration needed - just ensure asdf is installed and the project has a `.tool-versions` file\n\n## Usage\n\nThe Elixir language server is automatically selected when working with Elixir projects. It will be used for:\n\n- Code completion\n- Go to definition\n- Find references\n- Document symbols\n- Hover information\n- Code formatting\n- Diagnostics (via Credo integration)\n\n### Important: Project Compilation\n\nExpert requires your Elixir project to be **compiled** for optimal performance, especially for:\n- Cross-file reference resolution\n- Complete symbol information\n- Accurate go-to-definition\n\n**For production use**: Ensure your project is compiled with `mix compile` before using the language server.\n\n**For testing**: The test suite automatically compiles the test repositories before running tests to ensure optimal Expert performance.\n\n## Testing\n\nRun the Elixir-specific tests with:\n\n```bash\npytest test/solidlsp/elixir/ -m elixir\n```\n\n## Implementation Details\n\n- **Main class**: `ElixirTools` in `elixir_tools.py`\n- **Language identifier**: `\"elixir\"`\n- **Command**: `expert --stdio`\n- **Supported platforms**: Linux (x64, arm64), macOS (x64, arm64), Windows (x64, arm64)\n- **Binary distribution**: Downloaded from [GitHub releases](https://github.com/elixir-lang/expert/releases)\n\nThe implementation follows the same patterns as other language servers in this project, inheriting from `SolidLanguageServer` and providing Elixir-specific configuration and behavior.\n"
  },
  {
    "path": "src/solidlsp/language_servers/elixir_tools/__init__.py",
    "content": "\n"
  },
  {
    "path": "src/solidlsp/language_servers/elixir_tools/elixir_tools.py",
    "content": "import logging\nimport os\nimport pathlib\nimport stat\nimport subprocess\nimport threading\nfrom typing import Any, cast\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.ls_utils import FileUtils, PlatformId, PlatformUtils\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nfrom ..common import RuntimeDependency\n\nlog = logging.getLogger(__name__)\n\n\nclass ElixirTools(SolidLanguageServer):\n    \"\"\"\n    Provides Elixir specific instantiation of the LanguageServer class using Expert, the official Elixir language server.\n    \"\"\"\n\n    @override\n    def _get_wait_time_for_cross_file_referencing(self) -> float:\n        return 10.0  # Elixir projects need time to compile and index before cross-file references work\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        # For Elixir projects, we should ignore:\n        # - _build: compiled artifacts\n        # - deps: dependencies\n        # - node_modules: if the project has JavaScript components\n        # - .elixir_ls: ElixirLS artifacts (in case both are present)\n        # - cover: coverage reports\n        # - .expert: Expert artifacts\n        return super().is_ignored_dirname(dirname) or dirname in [\"_build\", \"deps\", \"node_modules\", \".elixir_ls\", \".expert\", \"cover\"]\n\n    @override\n    def is_ignored_path(self, relative_path: str, ignore_unsupported_files: bool = True) -> bool:\n        \"\"\"Check if a path should be ignored for symbol indexing.\"\"\"\n        if relative_path.endswith(\"mix.exs\"):\n            # These are project configuration files, not source code with symbols to index\n            return True\n\n        return super().is_ignored_path(relative_path, ignore_unsupported_files)\n\n    @classmethod\n    def _get_elixir_version(cls) -> str | None:\n        \"\"\"Get the installed Elixir version or None if not found.\"\"\"\n        try:\n            result = subprocess.run([\"elixir\", \"--version\"], capture_output=True, text=True, check=False)\n            if result.returncode == 0:\n                return result.stdout.strip()\n        except FileNotFoundError:\n            return None\n        return None\n\n    @classmethod\n    def _setup_runtime_dependencies(cls, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings) -> str:\n        \"\"\"\n        Setup runtime dependencies for Expert.\n        Downloads the Expert binary for the current platform and returns the path to the executable.\n        \"\"\"\n        # Check if Elixir is available first\n        elixir_version = cls._get_elixir_version()\n        if not elixir_version:\n            raise RuntimeError(\n                \"Elixir is not installed. Please install Elixir from https://elixir-lang.org/install.html and make sure it is added to your PATH.\"\n            )\n\n        log.info(f\"Found Elixir: {elixir_version}\")\n\n        # First, check if expert is already in PATH (user may have installed it manually)\n        import shutil\n\n        expert_in_path = shutil.which(\"expert\")\n        if expert_in_path:\n            log.info(f\"Found Expert in PATH: {expert_in_path}\")\n            return expert_in_path\n\n        platform_id = PlatformUtils.get_platform_id()\n\n        valid_platforms = [\n            PlatformId.LINUX_x64,\n            PlatformId.LINUX_arm64,\n            PlatformId.OSX_x64,\n            PlatformId.OSX_arm64,\n            PlatformId.WIN_x64,\n            PlatformId.WIN_arm64,\n        ]\n        assert platform_id in valid_platforms, f\"Platform {platform_id} is not supported for Expert at the moment\"\n\n        expert_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), \"expert\")\n\n        EXPERT_VERSION = \"nightly\"\n\n        # Define runtime dependencies inline\n        runtime_deps = {\n            PlatformId.LINUX_x64: RuntimeDependency(\n                id=\"expert_linux_amd64\",\n                platform_id=\"linux-x64\",\n                url=f\"https://github.com/elixir-lang/expert/releases/download/{EXPERT_VERSION}/expert_linux_amd64\",\n                archive_type=\"binary\",\n                binary_name=\"expert_linux_amd64\",\n                extract_path=\"expert\",\n            ),\n            PlatformId.LINUX_arm64: RuntimeDependency(\n                id=\"expert_linux_arm64\",\n                platform_id=\"linux-arm64\",\n                url=f\"https://github.com/elixir-lang/expert/releases/download/{EXPERT_VERSION}/expert_linux_arm64\",\n                archive_type=\"binary\",\n                binary_name=\"expert_linux_arm64\",\n                extract_path=\"expert\",\n            ),\n            PlatformId.OSX_x64: RuntimeDependency(\n                id=\"expert_darwin_amd64\",\n                platform_id=\"osx-x64\",\n                url=f\"https://github.com/elixir-lang/expert/releases/download/{EXPERT_VERSION}/expert_darwin_amd64\",\n                archive_type=\"binary\",\n                binary_name=\"expert_darwin_amd64\",\n                extract_path=\"expert\",\n            ),\n            PlatformId.OSX_arm64: RuntimeDependency(\n                id=\"expert_darwin_arm64\",\n                platform_id=\"osx-arm64\",\n                url=f\"https://github.com/elixir-lang/expert/releases/download/{EXPERT_VERSION}/expert_darwin_arm64\",\n                archive_type=\"binary\",\n                binary_name=\"expert_darwin_arm64\",\n                extract_path=\"expert\",\n            ),\n            PlatformId.WIN_x64: RuntimeDependency(\n                id=\"expert_windows_amd64\",\n                platform_id=\"win-x64\",\n                url=f\"https://github.com/elixir-lang/expert/releases/download/{EXPERT_VERSION}/expert_windows_amd64.exe\",\n                archive_type=\"binary\",\n                binary_name=\"expert_windows_amd64.exe\",\n                extract_path=\"expert.exe\",\n            ),\n            PlatformId.WIN_arm64: RuntimeDependency(\n                id=\"expert_windows_arm64\",\n                platform_id=\"win-arm64\",\n                url=f\"https://github.com/elixir-lang/expert/releases/download/{EXPERT_VERSION}/expert_windows_arm64.exe\",\n                archive_type=\"binary\",\n                binary_name=\"expert_windows_arm64.exe\",\n                extract_path=\"expert.exe\",\n            ),\n        }\n\n        dependency = runtime_deps[platform_id]\n        # On Windows, use .exe extension\n        executable_name = \"expert.exe\" if platform_id.value.startswith(\"win\") else \"expert\"\n        executable_path = os.path.join(expert_dir, executable_name)\n        assert dependency.binary_name is not None\n        binary_path = os.path.join(expert_dir, dependency.binary_name)\n\n        if not os.path.exists(executable_path):\n            log.info(f\"Downloading Expert binary from {dependency.url}\")\n            assert dependency.url is not None\n            FileUtils.download_file(dependency.url, binary_path)\n\n            # Make the binary executable on Unix-like systems\n            if not platform_id.value.startswith(\"win\"):\n                os.chmod(binary_path, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)\n\n            # Create a symlink with the expected name on Unix-like systems\n            if binary_path != executable_path and not platform_id.value.startswith(\"win\"):\n                if os.path.exists(executable_path):\n                    os.remove(executable_path)\n                os.symlink(os.path.basename(binary_path), executable_path)\n\n        assert os.path.exists(executable_path), f\"Expert executable not found at {executable_path}\"\n\n        log.info(f\"Expert binary ready at: {executable_path}\")\n        return executable_path\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        expert_executable_path = self._setup_runtime_dependencies(config, solidlsp_settings)\n\n        super().__init__(\n            config,\n            repository_root_path,\n            ProcessLaunchInfo(cmd=f\"{expert_executable_path} --stdio\", cwd=repository_root_path),\n            \"elixir\",\n            solidlsp_settings,\n        )\n        self.server_ready = threading.Event()\n        self.request_id = 0\n\n        # Set generous timeout for Expert which can be slow to initialize and respond\n        self.set_request_timeout(180.0)\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Expert Language Server.\n        \"\"\"\n        # Ensure the path is absolute\n        abs_path = os.path.abspath(repository_absolute_path)\n        root_uri = pathlib.Path(abs_path).as_uri()\n        initialize_params = {\n            \"processId\": os.getpid(),\n            \"locale\": \"en\",\n            \"rootPath\": abs_path,\n            \"rootUri\": root_uri,\n            \"initializationOptions\": {\n                \"mix_env\": \"dev\",\n                \"mix_target\": \"host\",\n                \"experimental\": {\"completions\": {\"enable\": False}},\n                \"extensions\": {\"credo\": {\"enable\": True, \"cli_options\": []}},\n            },\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"completionItem\": {\"snippetSupport\": True, \"documentationFormat\": [\"markdown\", \"plaintext\"]},\n                    },\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"formatting\": {\"dynamicRegistration\": True},\n                    \"codeAction\": {\n                        \"dynamicRegistration\": True,\n                        \"codeActionLiteralSupport\": {\n                            \"codeActionKind\": {\n                                \"valueSet\": [\n                                    \"quickfix\",\n                                    \"refactor\",\n                                    \"refactor.extract\",\n                                    \"refactor.inline\",\n                                    \"refactor.rewrite\",\n                                    \"source\",\n                                    \"source.organizeImports\",\n                                ]\n                            }\n                        },\n                    },\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"executeCommand\": {\"dynamicRegistration\": True},\n                },\n                \"window\": {\n                    \"showMessage\": {\"messageActionItem\": {\"additionalPropertiesSupport\": True}},\n                    \"showDocument\": {\"support\": True},\n                    \"workDoneProgress\": True,\n                },\n            },\n            \"workspaceFolders\": [{\"uri\": root_uri, \"name\": os.path.basename(repository_absolute_path)}],\n        }\n\n        return cast(InitializeParams, initialize_params)\n\n    def _start_server(self) -> None:\n        \"\"\"Start Expert server process\"\"\"\n\n        def register_capability_handler(params: Any) -> None:\n            log.debug(f\"LSP: client/registerCapability: {params}\")\n            return\n\n        def window_log_message(msg: Any) -> None:\n            \"\"\"Handle window/logMessage notifications from Expert\"\"\"\n            message_type = msg.get(\"type\", 4)  # 1=Error, 2=Warning, 3=Info, 4=Log\n            message_text = msg.get(\"message\", \"\")\n\n            # Log at appropriate level based on message type\n            if message_type == 1:\n                log.error(f\"Expert: {message_text}\")\n            elif message_type == 2:\n                log.warning(f\"Expert: {message_text}\")\n            else:\n                log.debug(f\"Expert: {message_text}\")\n\n        def check_server_ready(params: Any) -> None:\n            \"\"\"\n            Handle $/progress notifications from Expert.\n            Expert sends progress updates during compilation and indexing.\n            The server is considered ready when project build completes.\n            \"\"\"\n            value = params.get(\"value\", {})\n            kind = value.get(\"kind\", \"\")\n            title = value.get(\"title\", \"\")\n\n            if kind == \"begin\":\n                # Track when building the project starts (not \"Building engine\")\n                if title.startswith(\"Building \") and not title.startswith(\"Building engine\"):\n                    self._building_project = True\n            elif kind == \"end\":\n                # Project build completion is the main readiness signal\n                if getattr(self, \"_building_project\", False):\n                    log.debug(\"Expert project build completed - server is ready\")\n                    self._building_project = False\n                    self.server_ready.set()\n\n        def work_done_progress_create(params: Any) -> None:\n            \"\"\"Handle window/workDoneProgress/create requests from Expert.\"\"\"\n            return\n\n        def publish_diagnostics(params: Any) -> None:\n            \"\"\"Handle textDocument/publishDiagnostics notifications.\"\"\"\n            return\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", check_server_ready)\n        self.server.on_request(\"window/workDoneProgress/create\", work_done_progress_create)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", publish_diagnostics)\n\n        log.debug(\"Starting Expert server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.debug(\"Sending initialize request to Expert\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        # Verify basic server capabilities\n        assert \"textDocumentSync\" in init_response[\"capabilities\"], f\"Missing textDocumentSync in {init_response['capabilities']}\"\n\n        self.server.notify.initialized({})\n\n        # Expert needs time to compile the project and build indexes on first run.\n        # This can take 2-3+ minutes for mid-sized codebases.\n        # After the first run, subsequent startups are much faster.\n        ready_timeout = 300.0  # 5 minutes\n        log.debug(f\"Waiting up to {ready_timeout}s for Expert to compile and index...\")\n        if self.server_ready.wait(timeout=ready_timeout):\n            log.debug(\"Expert is ready for requests\")\n        else:\n            log.warning(f\"Expert did not signal readiness within {ready_timeout}s. Proceeding with requests anyway.\")\n            self.server_ready.set()  # Mark as ready anyway to allow requests\n"
  },
  {
    "path": "src/solidlsp/language_servers/elm_language_server.py",
    "content": "\"\"\"\nProvides Elm specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Elm.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport shutil\nimport threading\n\nfrom overrides import override\nfrom sensai.util.logging import LogTime\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nfrom .common import RuntimeDependency, RuntimeDependencyCollection\n\nlog = logging.getLogger(__name__)\n\n\nclass ElmLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides Elm specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Elm.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates an ElmLanguageServer instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.\n        \"\"\"\n        elm_lsp_executable_path = self._setup_runtime_dependencies(config, solidlsp_settings)\n\n        # Resolve ELM_HOME to absolute path if it's set to a relative path\n        env = {}\n        elm_home = os.environ.get(\"ELM_HOME\")\n        if elm_home:\n            if not os.path.isabs(elm_home):\n                # Convert relative ELM_HOME to absolute based on repository root\n                elm_home = os.path.abspath(os.path.join(repository_root_path, elm_home))\n            env[\"ELM_HOME\"] = elm_home\n            log.info(f\"Using ELM_HOME: {elm_home}\")\n\n        super().__init__(\n            config,\n            repository_root_path,\n            ProcessLaunchInfo(cmd=elm_lsp_executable_path, cwd=repository_root_path, env=env),\n            \"elm\",\n            solidlsp_settings,\n        )\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\n            \"elm-stuff\",\n            \"node_modules\",\n            \"dist\",\n            \"build\",\n        ]\n\n    @classmethod\n    def _setup_runtime_dependencies(cls, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings) -> list[str]:\n        \"\"\"\n        Setup runtime dependencies for Elm Language Server and return the command to start the server.\n        \"\"\"\n        # Check if elm-language-server is already installed globally\n        system_elm_ls = shutil.which(\"elm-language-server\")\n        if system_elm_ls:\n            log.info(f\"Found system-installed elm-language-server at {system_elm_ls}\")\n            return [system_elm_ls, \"--stdio\"]\n\n        # Verify node and npm are installed\n        is_node_installed = shutil.which(\"node\") is not None\n        assert is_node_installed, \"node is not installed or isn't in PATH. Please install NodeJS and try again.\"\n        is_npm_installed = shutil.which(\"npm\") is not None\n        assert is_npm_installed, \"npm is not installed or isn't in PATH. Please install npm and try again.\"\n\n        deps = RuntimeDependencyCollection(\n            [\n                RuntimeDependency(\n                    id=\"elm-language-server\",\n                    description=\"@elm-tooling/elm-language-server package\",\n                    command=[\"npm\", \"install\", \"--prefix\", \"./\", \"@elm-tooling/elm-language-server@2.8.0\"],\n                    platform_id=\"any\",\n                ),\n            ]\n        )\n\n        # Install elm-language-server if not already installed\n        elm_ls_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), \"elm-lsp\")\n        elm_ls_executable_path = os.path.join(elm_ls_dir, \"node_modules\", \".bin\", \"elm-language-server\")\n        if not os.path.exists(elm_ls_executable_path):\n            log.info(f\"Elm Language Server executable not found at {elm_ls_executable_path}. Installing...\")\n            with LogTime(\"Installation of Elm language server dependencies\", logger=log):\n                deps.install(elm_ls_dir)\n\n        if not os.path.exists(elm_ls_executable_path):\n            raise FileNotFoundError(\n                f\"elm-language-server executable not found at {elm_ls_executable_path}, something went wrong with the installation.\"\n            )\n        return [elm_ls_executable_path, \"--stdio\"]\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Elm Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\"dynamicRegistration\": True, \"completionItem\": {\"snippetSupport\": True}},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"codeAction\": {\"dynamicRegistration\": True},\n                    \"rename\": {\"dynamicRegistration\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True},\n                },\n            },\n            \"initializationOptions\": {\n                \"elmPath\": shutil.which(\"elm\") or \"elm\",\n                \"elmFormatPath\": shutil.which(\"elm-format\") or \"elm-format\",\n                \"elmTestPath\": shutil.which(\"elm-test\") or \"elm-test\",\n                \"skipInstallPackageConfirmation\": True,\n                \"onlyUpdateDiagnosticsOnSave\": False,\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return initialize_params  # type: ignore[return-value]\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the Elm Language Server, waits for the server to be ready and yields the LanguageServer instance.\n        \"\"\"\n        workspace_ready = threading.Event()\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def on_diagnostics(params: dict) -> None:\n            # Receiving diagnostics indicates the workspace has been scanned\n            log.info(\"LSP: Received diagnostics notification, workspace is ready\")\n            workspace_ready.set()\n\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", on_diagnostics)\n\n        log.info(\"Starting Elm server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        # Elm-specific capability checks\n        assert \"textDocumentSync\" in init_response[\"capabilities\"]\n        assert \"completionProvider\" in init_response[\"capabilities\"]\n        assert \"definitionProvider\" in init_response[\"capabilities\"]\n        assert \"referencesProvider\" in init_response[\"capabilities\"]\n        assert \"documentSymbolProvider\" in init_response[\"capabilities\"]\n\n        self.server.notify.initialized({})\n        log.info(\"Elm server initialized, waiting for workspace scan...\")\n\n        # Wait for workspace to be scanned (indicated by receiving diagnostics)\n        if workspace_ready.wait(timeout=30.0):\n            log.info(\"Elm server workspace scan completed\")\n        else:\n            log.warning(\"Timeout waiting for Elm workspace scan, proceeding anyway\")\n\n        log.info(\"Elm server ready\")\n\n    @override\n    def _get_wait_time_for_cross_file_referencing(self) -> float:\n        return 1.0\n"
  },
  {
    "path": "src/solidlsp/language_servers/erlang_language_server.py",
    "content": "\"\"\"Erlang Language Server implementation using Erlang LS.\"\"\"\n\nimport logging\nimport os\nimport shutil\nimport subprocess\nimport threading\nimport time\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass ErlangLanguageServer(SolidLanguageServer):\n    \"\"\"Language server for Erlang using Erlang LS.\"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates an ErlangLanguageServer instance. This class is not meant to be instantiated directly.\n        Use LanguageServer.create() instead.\n        \"\"\"\n        self.erlang_ls_path = shutil.which(\"erlang_ls\")\n        if not self.erlang_ls_path:\n            raise RuntimeError(\"Erlang LS not found. Install from: https://github.com/erlang-ls/erlang_ls\")\n\n        if not self._check_erlang_installation():\n            raise RuntimeError(\"Erlang/OTP not found. Install from: https://www.erlang.org/downloads\")\n\n        super().__init__(\n            config,\n            repository_root_path,\n            ProcessLaunchInfo(cmd=[self.erlang_ls_path, \"--transport\", \"stdio\"], cwd=repository_root_path),\n            \"erlang\",\n            solidlsp_settings,\n        )\n\n        # Add server readiness tracking like Elixir\n        self.server_ready = threading.Event()\n\n        # Set generous timeout for Erlang LS initialization\n        self.set_request_timeout(120.0)\n\n    def _check_erlang_installation(self) -> bool:\n        \"\"\"Check if Erlang/OTP is available.\"\"\"\n        try:\n            result = subprocess.run([\"erl\", \"-version\"], check=False, capture_output=True, text=True, timeout=10)\n            return result.returncode == 0\n        except (subprocess.SubprocessError, FileNotFoundError):\n            return False\n\n    @classmethod\n    def _get_erlang_version(cls) -> str | None:\n        \"\"\"Get the installed Erlang/OTP version or None if not found.\"\"\"\n        try:\n            result = subprocess.run([\"erl\", \"-version\"], check=False, capture_output=True, text=True, timeout=10)\n            if result.returncode == 0:\n                return result.stderr.strip()  # erl -version outputs to stderr\n        except (subprocess.SubprocessError, FileNotFoundError):\n            return None\n        return None\n\n    @classmethod\n    def _check_rebar3_available(cls) -> bool:\n        \"\"\"Check if rebar3 build tool is available.\"\"\"\n        try:\n            result = subprocess.run([\"rebar3\", \"version\"], check=False, capture_output=True, text=True, timeout=10)\n            return result.returncode == 0\n        except (subprocess.SubprocessError, FileNotFoundError):\n            return False\n\n    def _start_server(self) -> None:\n        \"\"\"Start Erlang LS server process with proper initialization waiting.\"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            \"\"\"Handle window/logMessage notifications from Erlang LS\"\"\"\n            message_text = msg.get(\"message\", \"\")\n            log.info(f\"LSP: window/logMessage: {message_text}\")\n\n            # Look for Erlang LS readiness signals\n            # Common patterns: \"Started Erlang LS\", \"initialized\", \"ready\"\n            readiness_signals = [\n                \"Started Erlang LS\",\n                \"server started\",\n                \"initialized\",\n                \"ready to serve requests\",\n                \"compilation finished\",\n                \"indexing complete\",\n            ]\n\n            message_lower = message_text.lower()\n            for signal in readiness_signals:\n                if signal.lower() in message_lower:\n                    log.info(f\"Erlang LS readiness signal detected: {message_text}\")\n                    self.server_ready.set()\n                    break\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def check_server_ready(params: dict) -> None:\n            \"\"\"Handle $/progress notifications from Erlang LS as fallback.\"\"\"\n            value = params.get(\"value\", {})\n\n            # Check for initialization completion progress\n            if value.get(\"kind\") == \"end\":\n                message = value.get(\"message\", \"\")\n                if any(word in message.lower() for word in [\"initialized\", \"ready\", \"complete\"]):\n                    log.info(\"Erlang LS initialization progress completed\")\n                    # Set as fallback if no window/logMessage was received\n                    if not self.server_ready.is_set():\n                        self.server_ready.set()\n\n        # Set up notification handlers\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", check_server_ready)\n        self.server.on_notification(\"window/workDoneProgress/create\", do_nothing)\n        self.server.on_notification(\"$/workDoneProgress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting Erlang LS server process\")\n        self.server.start()\n\n        # Send initialize request\n        initialize_params = {\n            \"processId\": None,\n            \"rootPath\": self.repository_root_path,\n            \"rootUri\": f\"file://{self.repository_root_path}\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True},\n                    \"completion\": {\"dynamicRegistration\": True},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\"dynamicRegistration\": True},\n                    \"hover\": {\"dynamicRegistration\": True},\n                }\n            },\n        }\n\n        log.info(\"Sending initialize request to Erlang LS\")\n        init_response = self.server.send.initialize(initialize_params)  # type: ignore[arg-type]\n\n        # Verify server capabilities\n        if \"capabilities\" in init_response:\n            log.info(f\"Erlang LS capabilities: {list(init_response['capabilities'].keys())}\")\n\n        self.server.notify.initialized({})\n\n        # Wait for Erlang LS to be ready - adjust timeout based on environment\n        is_ci = os.getenv(\"CI\") == \"true\" or os.getenv(\"GITHUB_ACTIONS\") == \"true\"\n        is_macos = os.uname().sysname == \"Darwin\" if hasattr(os, \"uname\") else False\n\n        # macOS in CI can be particularly slow for language server startup\n        if is_ci and is_macos:\n            ready_timeout = 240.0  # 4 minutes for macOS CI\n            env_desc = \"macOS CI\"\n        elif is_ci:\n            ready_timeout = 180.0  # 3 minutes for other CI\n            env_desc = \"CI\"\n        else:\n            ready_timeout = 60.0  # 1 minute for local\n            env_desc = \"local\"\n\n        log.info(f\"Waiting up to {ready_timeout} seconds for Erlang LS readiness ({env_desc} environment)...\")\n\n        if self.server_ready.wait(timeout=ready_timeout):\n            log.info(\"Erlang LS is ready and available for requests\")\n\n            # Add settling period for indexing - adjust based on environment\n            settling_time = 15.0 if is_ci else 5.0\n            log.info(f\"Allowing {settling_time} seconds for Erlang LS indexing to complete...\")\n            time.sleep(settling_time)\n            log.info(\"Erlang LS settling period complete\")\n        else:\n            # Set ready anyway and continue - Erlang LS might not send explicit ready messages\n            log.warning(f\"Erlang LS readiness timeout reached after {ready_timeout}s, proceeding anyway (common in CI)\")\n            self.server_ready.set()\n\n            # Still give some time for basic initialization even without explicit readiness signal\n            basic_settling_time = 20.0 if is_ci else 10.0\n            log.info(f\"Allowing {basic_settling_time} seconds for basic Erlang LS initialization...\")\n            time.sleep(basic_settling_time)\n            log.info(\"Basic Erlang LS initialization period complete\")\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        # For Erlang projects, we should ignore:\n        # - _build: rebar3 build artifacts\n        # - deps: dependencies\n        # - ebin: compiled beam files\n        # - .rebar3: rebar3 cache\n        # - logs: log files\n        # - node_modules: if the project has JavaScript components\n        return super().is_ignored_dirname(dirname) or dirname in [\n            \"_build\",\n            \"deps\",\n            \"ebin\",\n            \".rebar3\",\n            \"logs\",\n            \"node_modules\",\n            \"_checkouts\",\n            \"cover\",\n        ]\n\n    def is_ignored_filename(self, filename: str) -> bool:\n        \"\"\"Check if a filename should be ignored.\"\"\"\n        # Ignore compiled BEAM files\n        if filename.endswith(\".beam\"):\n            return True\n        # Don't ignore Erlang source files, header files, or configuration files\n        return False\n"
  },
  {
    "path": "src/solidlsp/language_servers/fortran_language_server.py",
    "content": "\"\"\"\nFortran Language Server implementation using fortls.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport re\nimport shutil\n\nfrom overrides import override\n\nfrom solidlsp import ls_types\nfrom solidlsp.ls import DocumentSymbols, LSPFileBuffer, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass FortranLanguageServer(SolidLanguageServer):\n    \"\"\"Fortran Language Server implementation using fortls.\"\"\"\n\n    @override\n    def _get_wait_time_for_cross_file_referencing(self) -> float:\n        return 3.0  # fortls needs time for workspace indexing\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        # For Fortran projects, ignore common build directories\n        return super().is_ignored_dirname(dirname) or dirname in [\n            \"build\",\n            \"Build\",\n            \"BUILD\",\n            \"bin\",\n            \"lib\",\n            \"mod\",  # Module files directory\n            \"obj\",  # Object files directory\n            \".cmake\",\n            \"CMakeFiles\",\n        ]\n\n    def _fix_fortls_selection_range(\n        self, symbol: ls_types.UnifiedSymbolInformation, file_content: str\n    ) -> ls_types.UnifiedSymbolInformation:\n        \"\"\"\n        Fix fortls's incorrect selectionRange that points to line start instead of identifier name.\n\n        fortls bug: selectionRange.start.character is 0 (line start) but should point to the\n        function/subroutine/module/program name position. This breaks MCP server features that\n        rely on the exact identifier position for finding references.\n\n        Args:\n            symbol: The symbol with potentially incorrect selectionRange\n            file_content: Full file content to parse the line\n\n        Returns:\n            Symbol with corrected selectionRange pointing to the identifier name\n\n        \"\"\"\n        if \"selectionRange\" not in symbol:\n            return symbol\n\n        sel_range = symbol[\"selectionRange\"]\n        start_line = sel_range[\"start\"][\"line\"]\n        start_char = sel_range[\"start\"][\"character\"]\n\n        # Split file content into lines\n        lines = file_content.split(\"\\n\")\n        if start_line >= len(lines):\n            return symbol\n\n        line = lines[start_line]\n\n        # Fortran keywords that define named constructs\n        # Match patterns:\n        # Standard keywords: <keyword> <whitespace> <identifier_name>\n        #   \"    function add_numbers(a, b) result(sum)\"  -> keyword=\"function\", name=\"add_numbers\"\n        #   \"subroutine print_result(value)\"             -> keyword=\"subroutine\", name=\"print_result\"\n        #   \"module math_utils\"                          -> keyword=\"module\", name=\"math_utils\"\n        #   \"program test_program\"                       -> keyword=\"program\", name=\"test_program\"\n        #   \"interface distance\"                         -> keyword=\"interface\", name=\"distance\"\n        #\n        # Type definitions (can have :: syntax):\n        #   \"type point\"                                 -> keyword=\"type\", name=\"point\"\n        #   \"type :: point\"                              -> keyword=\"type\", name=\"point\"\n        #   \"type, extends(base) :: derived\"             -> keyword=\"type\", name=\"derived\"\n        #\n        # Submodules (have parent module in parentheses):\n        #   \"submodule (parent_mod) child_mod\"           -> keyword=\"submodule\", name=\"child_mod\"\n\n        # Try type pattern first (has complex syntax with optional comma and ::)\n        type_pattern = r\"^\\s*type\\s*(?:,.*?)?\\s*(?:::)?\\s*([a-zA-Z_]\\w*)\"\n        match = re.match(type_pattern, line, re.IGNORECASE)\n\n        if match:\n            # For type pattern, identifier is in group 1\n            identifier_name = match.group(1)\n            identifier_start = match.start(1)\n        else:\n            # Try standard keywords pattern\n            standard_pattern = r\"^\\s*(function|subroutine|module|program|interface)\\s+([a-zA-Z_]\\w*)\"\n            match = re.match(standard_pattern, line, re.IGNORECASE)\n\n            if not match:\n                # Try submodule pattern\n                submodule_pattern = r\"^\\s*submodule\\s*\\([^)]+\\)\\s+([a-zA-Z_]\\w*)\"\n                match = re.match(submodule_pattern, line, re.IGNORECASE)\n\n                if match:\n                    identifier_name = match.group(1)\n                    identifier_start = match.start(1)\n            else:\n                identifier_name = match.group(2)\n                identifier_start = match.start(2)\n\n        if match:\n            # Create corrected selectionRange\n            new_sel_range = {\n                \"start\": {\"line\": start_line, \"character\": identifier_start},\n                \"end\": {\"line\": start_line, \"character\": identifier_start + len(identifier_name)},\n            }\n\n            # Create modified symbol with corrected selectionRange\n            corrected_symbol = symbol.copy()\n            corrected_symbol[\"selectionRange\"] = new_sel_range  # type: ignore[typeddict-item]\n\n            log.debug(f\"Fixed fortls selectionRange for {identifier_name}: char {start_char} -> {identifier_start}\")\n\n            return corrected_symbol\n\n        # If no match, return symbol unchanged (e.g., for variables, which don't have this pattern)\n        return symbol\n\n    @override\n    def request_document_symbols(self, relative_file_path: str, file_buffer: LSPFileBuffer | None = None) -> DocumentSymbols:\n        # Override to fix fortls's incorrect selectionRange bug.\n        #\n        # fortls returns selectionRange pointing to line start (character 0) instead of the\n        # identifier name position. This breaks MCP server features that rely on exact positions.\n        #\n        # This override:\n        # 1. Gets symbols from fortls via parent implementation\n        # 2. Parses each symbol's line to find the correct identifier position\n        # 3. Fixes selectionRange for all symbols recursively\n        # 4. Returns corrected symbols\n\n        # Get symbols from fortls (with incorrect selectionRange)\n        document_symbols = super().request_document_symbols(relative_file_path, file_buffer=file_buffer)\n\n        # Get file content for parsing\n        with self.open_file(relative_file_path) as file_data:\n            file_content = file_data.contents\n\n        # Fix selectionRange recursively for all symbols\n        def fix_symbol_and_children(symbol: ls_types.UnifiedSymbolInformation) -> ls_types.UnifiedSymbolInformation:\n            # Fix this symbol's selectionRange\n            fixed = self._fix_fortls_selection_range(symbol, file_content)\n\n            # Fix children recursively\n            if fixed.get(\"children\"):\n                fixed[\"children\"] = [fix_symbol_and_children(child) for child in fixed[\"children\"]]\n\n            return fixed\n\n        # Apply fix to all symbols\n        fixed_root_symbols = [fix_symbol_and_children(sym) for sym in document_symbols.root_symbols]\n\n        return DocumentSymbols(fixed_root_symbols)\n\n    @staticmethod\n    def _check_fortls_installation() -> str:\n        \"\"\"Check if fortls is available.\"\"\"\n        fortls_path = shutil.which(\"fortls\")\n        if fortls_path is None:\n            raise RuntimeError(\"fortls is not installed or not in PATH.\\nInstall it with: pip install fortls\")\n        return fortls_path\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        # Check fortls installation\n        fortls_path = self._check_fortls_installation()\n\n        # Command to start fortls language server\n        # fortls uses stdio for LSP communication by default\n        fortls_cmd = f\"{fortls_path}\"\n\n        super().__init__(\n            config, repository_root_path, ProcessLaunchInfo(cmd=fortls_cmd, cwd=repository_root_path), \"fortran\", solidlsp_settings\n        )\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"Initialize params for Fortran Language Server.\"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"completionItem\": {\n                            \"snippetSupport\": True,\n                            \"commitCharactersSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"deprecatedSupport\": True,\n                            \"preselectSupport\": True,\n                        },\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"formatting\": {\"dynamicRegistration\": True},\n                    \"rangeFormatting\": {\"dynamicRegistration\": True},\n                    \"codeAction\": {\"dynamicRegistration\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                },\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return initialize_params  # type: ignore[return-value]\n\n    def _start_server(self) -> None:\n        \"\"\"Start Fortran Language Server process.\"\"\"\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"Fortran LSP: window/logMessage: {msg}\")\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def register_capability_handler(params: dict) -> None:\n            return\n\n        # Register LSP message handlers\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting Fortran Language Server (fortls) process\")\n        self.server.start()\n\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n        log.info(\"Sending initialize request to Fortran Language Server\")\n\n        init_response = self.server.send.initialize(initialize_params)\n\n        # Verify server capabilities\n        capabilities = init_response.get(\"capabilities\", {})\n        assert \"textDocumentSync\" in capabilities\n        if \"completionProvider\" in capabilities:\n            log.info(\"Fortran LSP completion provider available\")\n        if \"definitionProvider\" in capabilities:\n            log.info(\"Fortran LSP definition provider available\")\n        if \"referencesProvider\" in capabilities:\n            log.info(\"Fortran LSP references provider available\")\n        if \"documentSymbolProvider\" in capabilities:\n            log.info(\"Fortran LSP document symbol provider available\")\n\n        self.server.notify.initialized({})\n\n        # Fortran Language Server is ready after initialization\n        log.info(\"Fortran Language Server initialization complete\")\n"
  },
  {
    "path": "src/solidlsp/language_servers/fsharp_language_server.py",
    "content": "\"\"\"\nProvides F# specific instantiation of the LanguageServer class.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport shutil\nimport threading\nfrom pathlib import Path\n\nfrom overrides import override\n\nfrom serena.util.dotnet import DotNETUtil\nfrom solidlsp.language_servers.common import RuntimeDependency, RuntimeDependencyCollection\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.ls_exceptions import SolidLSPException\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass FSharpLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides F# specific instantiation of the LanguageServer class using Ionide LSP (FsAutoComplete).\n    Contains various configurations and settings specific to F# development.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates an FSharpLanguageServer instance. This class is not meant to be instantiated directly.\n        Use LanguageServer.create() instead.\n        \"\"\"\n        fsharp_lsp_executable_path = self._setup_runtime_dependencies(config, solidlsp_settings)\n        super().__init__(\n            config,\n            repository_root_path,\n            ProcessLaunchInfo(cmd=fsharp_lsp_executable_path, cwd=repository_root_path),\n            \"fsharp\",\n            solidlsp_settings,\n        )\n        self.server_ready = threading.Event()\n        self.initialize_searcher_command_available = threading.Event()\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\n            \"bin\",\n            \"obj\",\n            \"packages\",\n            \".paket\",\n            \"paket-files\",\n            \".fake\",\n            \".ionide\",\n        ]\n\n    @classmethod\n    def _setup_runtime_dependencies(cls, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings) -> str:\n        \"\"\"\n        Setup runtime dependencies for F# Language Server and return the command to start the server.\n        \"\"\"\n        dotnet_exe = DotNETUtil(\"8.0\", allow_higher_version=True).get_dotnet_path_or_raise()\n\n        RuntimeDependencyCollection(\n            [\n                RuntimeDependency(\n                    id=\"fsautocomplete\",\n                    description=\"FsAutoComplete (Ionide F# Language Server)\",\n                    command=\"dotnet tool install --tool-path ./ fsautocomplete\",\n                    platform_id=\"any\",\n                ),\n            ]\n        )\n\n        # Install FsAutoComplete if not already installed\n        fsharp_ls_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), \"fsharp-lsp\")\n        fsautocomplete_path = os.path.join(fsharp_ls_dir, \"fsautocomplete\")\n\n        # Handle Windows executable extension\n        if os.name == \"nt\":\n            fsautocomplete_path += \".exe\"\n\n        if not os.path.exists(fsautocomplete_path):\n            log.info(f\"FsAutoComplete executable not found at {fsautocomplete_path}. Installing...\")\n\n            # Ensure the directory exists\n            os.makedirs(fsharp_ls_dir, exist_ok=True)\n\n            # Install FsAutoComplete using dotnet tool install\n            try:\n                import subprocess\n\n                result = subprocess.run(\n                    [dotnet_exe, \"tool\", \"install\", \"--tool-path\", fsharp_ls_dir, \"fsautocomplete\"],\n                    cwd=fsharp_ls_dir,\n                    capture_output=True,\n                    text=True,\n                    check=True,\n                )\n                log.info(\"FsAutoComplete installed successfully\")\n                log.debug(f\"Installation output: {result.stdout}\")\n            except subprocess.CalledProcessError as e:\n                log.error(f\"Failed to install FsAutoComplete: {e.stderr}\")\n                raise RuntimeError(f\"Failed to install FsAutoComplete: {e.stderr}\")\n\n        if not os.path.exists(fsautocomplete_path):\n            raise FileNotFoundError(\n                f\"FsAutoComplete executable not found at {fsautocomplete_path}, something went wrong with the installation.\"\n            )\n\n        # FsAutoComplete uses --lsp flag for LSP mode\n        return f\"{fsautocomplete_path} --adaptive-lsp-server-enabled --project-graph-enabled --use-fcs-transparent-compiler\"\n\n    def _get_initialize_params(self) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the F# Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(self.repository_root_path).as_uri()\n\n        initialize_params = {\n            \"processId\": os.getpid(),\n            \"rootPath\": self.repository_root_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [{\"name\": \"workspace\", \"uri\": root_uri}],\n            \"capabilities\": {\n                \"workspace\": {\n                    \"applyEdit\": True,\n                    \"workspaceEdit\": {\"documentChanges\": True},\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"didChangeWatchedFiles\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True},\n                    \"executeCommand\": {\"dynamicRegistration\": True},\n                    \"configuration\": True,\n                    \"workspaceFolders\": True,\n                },\n                \"textDocument\": {\n                    \"synchronization\": {\n                        \"dynamicRegistration\": True,\n                        \"willSave\": True,\n                        \"willSaveWaitUntil\": True,\n                        \"didSave\": True,\n                    },\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"contextSupport\": True,\n                        \"completionItem\": {\n                            \"snippetSupport\": True,\n                            \"commitCharactersSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"deprecatedSupport\": True,\n                        },\n                    },\n                    \"hover\": {\n                        \"dynamicRegistration\": True,\n                        \"contentFormat\": [\"markdown\", \"plaintext\"],\n                    },\n                    \"signatureHelp\": {\n                        \"dynamicRegistration\": True,\n                        \"signatureInformation\": {\"documentationFormat\": [\"markdown\", \"plaintext\"]},\n                    },\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentHighlight\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 26))},  # All SymbolKind values\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                    },\n                    \"codeAction\": {\n                        \"dynamicRegistration\": True,\n                        \"codeActionLiteralSupport\": {\n                            \"codeActionKind\": {\n                                \"valueSet\": [\n                                    \"\",\n                                    \"quickfix\",\n                                    \"refactor\",\n                                    \"refactor.extract\",\n                                    \"refactor.inline\",\n                                    \"refactor.rewrite\",\n                                    \"source\",\n                                    \"source.organizeImports\",\n                                ]\n                            }\n                        },\n                    },\n                    \"codeLens\": {\"dynamicRegistration\": True},\n                    \"formatting\": {\"dynamicRegistration\": True},\n                    \"rangeFormatting\": {\"dynamicRegistration\": True},\n                    \"onTypeFormatting\": {\"dynamicRegistration\": True},\n                    \"rename\": {\"dynamicRegistration\": True},\n                    \"documentLink\": {\"dynamicRegistration\": True},\n                    \"publishDiagnostics\": {\n                        \"relatedInformation\": True,\n                        \"versionSupport\": False,\n                        \"tagSupport\": {\"valueSet\": [1, 2]},\n                    },\n                    \"implementation\": {\"dynamicRegistration\": True},\n                    \"typeDefinition\": {\"dynamicRegistration\": True},\n                    \"colorProvider\": {\"dynamicRegistration\": True},\n                    \"foldingRange\": {\n                        \"dynamicRegistration\": True,\n                        \"rangeLimit\": 5000,\n                        \"lineFoldingOnly\": True,\n                    },\n                    \"declaration\": {\"dynamicRegistration\": True},\n                    \"selectionRange\": {\"dynamicRegistration\": True},\n                },\n                \"window\": {\n                    \"workDoneProgress\": True,\n                },\n            },\n            \"initializationOptions\": {\n                # F# specific initialization options\n                \"automaticWorkspaceInit\": True,\n                \"abstractClassStubGeneration\": True,\n                \"abstractClassStubGenerationObjectIdentifier\": \"this\",\n                \"abstractClassStubGenerationMethodBody\": 'failwith \"Not Implemented\"',\n                \"addFsiWatcher\": False,\n                \"codeLenses\": {\"signature\": {\"enabled\": True}, \"references\": {\"enabled\": True}},\n                \"disableInMemoryProjectReferences\": False,\n                \"dotNetRoot\": self._get_dotnet_root(),\n                \"enableMSBuildProjectGraph\": False,\n                \"excludeProjectDirectories\": [\"paket-files\"],\n                \"externalAutocomplete\": False,\n                \"fsac\": {\"attachDebugger\": False, \"silencedLogs\": [], \"conserveMemory\": False, \"netCoreDllPath\": \"\"},\n                \"fsiExtraParameters\": [],\n                \"generateBinlog\": False,\n                \"interfaceStubGeneration\": True,\n                \"interfaceStubGenerationObjectIdentifier\": \"this\",\n                \"interfaceStubGenerationMethodBody\": 'failwith \"Not Implemented\"',\n                \"keywordsAutocomplete\": True,\n                \"linter\": True,\n                \"pipelineHints\": {\"enabled\": True},\n                \"recordStubGeneration\": True,\n                \"recordStubGenerationBody\": 'failwith \"Not Implemented\"',\n                \"resolveNamespaces\": True,\n                \"saveOnlyOpenFiles\": False,\n                \"showProjectExplorerIn\": [\"ionide\", \"solution\"],\n                \"simplifyNameAnalyzer\": True,\n                \"smartIndent\": False,\n                \"suggestGitignore\": True,\n                \"suggestSdkScripts\": True,\n                \"unionCaseStubGeneration\": True,\n                \"unionCaseStubGenerationBody\": 'failwith \"Not Implemented\"',\n                \"unusedDeclarationsAnalyzer\": True,\n                \"unusedOpensAnalyzer\": True,\n                \"verboseLogging\": False,\n                \"workspaceModePeekDeepLevel\": 2,\n                \"workspacePath\": self.repository_root_path,\n            },\n            \"trace\": \"off\",\n        }\n\n        return initialize_params  # type: ignore\n\n    def _get_dotnet_root(self) -> str:\n        \"\"\"\n        Get the .NET root directory.\n        \"\"\"\n        dotnet_exe = shutil.which(\"dotnet\")\n        if dotnet_exe:\n            # Try to get the installation path\n            try:\n                import subprocess\n\n                result = subprocess.run([dotnet_exe, \"--info\"], capture_output=True, text=True, check=True)\n                lines = result.stdout.split(\"\\n\")\n                for line in lines:\n                    if \"Base Path:\" in line or \"Base path:\" in line:\n                        base_path = line.split(\":\", 1)[1].strip()\n                        # Get the parent directory (remove 'sdk/version' part)\n                        return str(Path(base_path).parent.parent)\n            except (subprocess.CalledProcessError, Exception):\n                pass\n\n        # Fallback: use the directory containing dotnet executable\n        if dotnet_exe:\n            return str(Path(dotnet_exe).parent)\n\n        return \"\"\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Start the F# Language Server with custom handlers.\n        \"\"\"\n\n        def handle_window_log_message(params: dict) -> None:\n            \"\"\"Handle window/logMessage from the LSP server.\"\"\"\n            message = params.get(\"message\", \"\")\n            message_type = params.get(\"type\", 1)\n\n            # Map LSP log levels to Python logging levels\n            level_map = {1: logging.ERROR, 2: logging.WARNING, 3: logging.INFO, 4: logging.DEBUG}\n            level = level_map.get(message_type, logging.INFO)\n\n            log.log(level, f\"FsAutoComplete: {message}\")\n\n        def handle_window_show_message(params: dict) -> None:\n            \"\"\"Handle window/showMessage from the LSP server.\"\"\"\n            message = params.get(\"message\", \"\")\n            message_type = params.get(\"type\", 1)\n\n            # Map LSP message types to Python logging levels\n            level_map = {1: logging.ERROR, 2: logging.WARNING, 3: logging.INFO, 4: logging.DEBUG}\n            level = level_map.get(message_type, logging.INFO)\n\n            log.log(level, f\"FsAutoComplete Message: {message}\")\n\n        def handle_workspace_configuration(params: dict) -> list:\n            \"\"\"Handle workspace/configuration requests from the LSP server.\"\"\"\n            # Return empty configuration for now\n            items = params.get(\"items\", [])\n            return [None] * len(items)\n\n        def handle_client_register_capability(params: dict) -> None:\n            \"\"\"Handle client/registerCapability requests from the LSP server.\"\"\"\n            # For now, just acknowledge the registration\n            return\n\n        def handle_client_unregister_capability(params: dict) -> None:\n            \"\"\"Handle client/unregisterCapability requests from the LSP server.\"\"\"\n            # For now, just acknowledge the unregistration\n            return\n\n        def handle_work_done_progress_create(params: dict) -> None:\n            \"\"\"Handle window/workDoneProgress/create requests from the LSP server.\"\"\"\n            # Just acknowledge the request - we don't need to track progress for now\n            return\n\n        # Register custom handlers\n        self.server.on_notification(\"window/logMessage\", handle_window_log_message)\n        self.server.on_notification(\"window/showMessage\", handle_window_show_message)\n        self.server.on_request(\"workspace/configuration\", handle_workspace_configuration)\n        self.server.on_request(\"client/registerCapability\", handle_client_register_capability)\n        self.server.on_request(\"client/unregisterCapability\", handle_client_unregister_capability)\n        self.server.on_request(\"window/workDoneProgress/create\", handle_work_done_progress_create)\n\n        log.info(\"Starting FsAutoComplete F# language server process\")\n\n        try:\n            self.server.start()\n        except Exception as e:\n            log.error(f\"Failed to start F# language server process: {e}\")\n            raise SolidLSPException(f\"Failed to start F# language server: {e}\")\n\n        # Send initialization\n        initialize_params = self._get_initialize_params()\n\n        log.info(\"Sending initialize request to F# language server\")\n        try:\n            self.server.send.initialize(initialize_params)\n            log.debug(\"Received initialize response from F# language server\")\n        except Exception as e:\n            raise SolidLSPException(f\"Failed to initialize F# language server for {self.repository_root_path}: {e}\") from e\n\n        # Complete initialization\n        self.server.notify.initialized({})\n\n        log.info(\"F# language server initialized successfully\")\n\n    @override\n    def _get_wait_time_for_cross_file_referencing(self) -> float:\n        \"\"\"\n        F# projects can be large and may need more time for cross-file analysis.\n        \"\"\"\n        return 15.0  # 15 seconds should be sufficient for most F# projects\n"
  },
  {
    "path": "src/solidlsp/language_servers/gopls.py",
    "content": "import logging\nimport os\nimport pathlib\nimport subprocess\nfrom typing import Any, cast\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass Gopls(SolidLanguageServer):\n    \"\"\"\n    Provides Go specific instantiation of the LanguageServer class using gopls.\n    \"\"\"\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        # For Go projects, we should ignore:\n        # - vendor: third-party dependencies vendored into the project\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 [\"vendor\", \"node_modules\", \"dist\", \"build\"]\n\n    @staticmethod\n    def _determine_log_level(line: str) -> int:\n        \"\"\"Classify gopls stderr output to avoid false-positive errors.\"\"\"\n        line_lower = line.lower()\n\n        # File discovery messages that are not actual errors\n        if any(\n            [\n                \"discover.go:\" in line_lower,\n                \"walker.go:\" in line_lower,\n                \"walking of {file://\" in line_lower,\n                \"bus: -> discover\" in line_lower,\n            ]\n        ):\n            return logging.DEBUG\n\n        return SolidLanguageServer._determine_log_level(line)\n\n    @staticmethod\n    def _get_go_version() -> str | None:\n        \"\"\"Get the installed Go version or None if not found.\"\"\"\n        try:\n            result = subprocess.run([\"go\", \"version\"], capture_output=True, text=True, check=False)\n            if result.returncode == 0:\n                return result.stdout.strip()\n        except FileNotFoundError:\n            return None\n        return None\n\n    @staticmethod\n    def _get_gopls_version() -> str | None:\n        \"\"\"Get the installed gopls version or None if not found.\"\"\"\n        try:\n            result = subprocess.run([\"gopls\", \"version\"], capture_output=True, text=True, check=False)\n            if result.returncode == 0:\n                return result.stdout.strip()\n        except FileNotFoundError:\n            return None\n        return None\n\n    @staticmethod\n    def _setup_runtime_dependency() -> bool:\n        \"\"\"\n        Check if required Go runtime dependencies are available.\n        Raises RuntimeError with helpful message if dependencies are missing.\n        \"\"\"\n        go_version = Gopls._get_go_version()\n        if not go_version:\n            raise RuntimeError(\n                \"Go is not installed. Please install Go from https://golang.org/doc/install and make sure it is added to your PATH.\"\n            )\n\n        gopls_version = Gopls._get_gopls_version()\n        if not gopls_version:\n            raise RuntimeError(\n                \"Found a Go version but gopls is not installed.\\n\"\n                \"Please install gopls as described in https://pkg.go.dev/golang.org/x/tools/gopls#section-readme\\n\\n\"\n                \"After installation, make sure it is added to your PATH (it might be installed in a different location than Go).\"\n            )\n\n        return True\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        self._setup_runtime_dependency()\n\n        super().__init__(config, repository_root_path, ProcessLaunchInfo(cmd=\"gopls\", cwd=repository_root_path), \"go\", solidlsp_settings)\n        self.request_id = 0\n\n    def _get_initialize_params(self, repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Go Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params: dict = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                },\n                \"workspace\": {\"workspaceFolders\": True, \"didChangeConfiguration\": {\"dynamicRegistration\": True}},\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n\n        # Apply gopls-specific settings via initializationOptions\n        # Serena applies gopls settings at initialization time via initializationOptions\n        # (Access settings directly to avoid extra INFO logging from CustomLSSettings.get.)\n        gopls_settings = self._custom_settings.settings.get(\"gopls_settings\")\n        if gopls_settings:\n            gopls_settings = self._validate_gopls_settings_dict(gopls_settings)\n\n            # Validate JSON-serializability early: initializationOptions is sent over JSON-RPC.\n            import json\n\n            self._canonical_json_or_raise(json, gopls_settings)\n\n            # Log keys only (and at DEBUG) to avoid leaking sensitive values and to reduce startup noise.\n            log.debug(\"Applying gopls settings via initializationOptions: keys=%s\", list(gopls_settings.keys()))\n            initialize_params[\"initializationOptions\"] = gopls_settings\n\n        return cast(InitializeParams, initialize_params)\n\n    def _validate_gopls_settings_dict(self, gopls_settings: object) -> dict:\n        if not isinstance(gopls_settings, dict):\n            raise TypeError(\n                f\"gopls_settings must be a dict, got {type(gopls_settings).__name__}. \"\n                \"Expected structure: {'buildFlags': ['-tags=foo'], 'env': {...}, ...}\"\n            )\n\n        return gopls_settings\n\n    def _canonical_json_or_raise(self, json_module: Any, data: object) -> str:\n        try:\n            return json_module.dumps(data, sort_keys=True, separators=(\",\", \":\"))\n        except (TypeError, ValueError) as exc:\n            raise TypeError(\n                \"gopls_settings must be JSON-serializable (json.dumps). Use JSON-compatible values (dict/list/str/int/float/bool/null) and prefer string keys.\"\n            ) from exc\n\n    # Environment variables that influence Go build context and affect cached symbols.\n    _CACHE_CONTEXT_ENV_KEYS = (\"GOFLAGS\", \"GOOS\", \"GOARCH\", \"CGO_ENABLED\")\n\n    @override\n    def _document_symbols_cache_fingerprint(self) -> str | None:\n        \"\"\"\n        Compute a deterministic fingerprint of the Go build context.\n\n        The fingerprint includes gopls_settings and selected env vars that affect symbol discovery.\n        \"\"\"\n        import hashlib\n        import json\n\n        gopls_settings_raw = self._custom_settings.settings.get(\"gopls_settings\")\n\n        gopls_settings: dict | None\n        if gopls_settings_raw is None:\n            gopls_settings = None\n        else:\n            # Treat an explicitly empty dict the same as not providing settings at all.\n            gopls_settings = self._validate_gopls_settings_dict(gopls_settings_raw) or None\n\n        # Only include env vars that are set to a non-empty value.\n        env_subset: dict[str, str] = {}\n        for key in self._CACHE_CONTEXT_ENV_KEYS:\n            value = os.environ.get(key)\n            if value:\n                env_subset[key] = value\n\n        # Return None only when BOTH settings and env subset are effectively empty.\n        if gopls_settings is None and not env_subset:\n            return None\n\n        fingerprint_data: dict[str, object] = {\"env\": env_subset}\n        if gopls_settings is not None:\n            fingerprint_data[\"gopls_settings\"] = gopls_settings\n\n        canonical_json = self._canonical_json_or_raise(json, fingerprint_data)\n\n        return hashlib.sha256(canonical_json.encode(\"utf-8\")).hexdigest()[:16]\n\n    def _start_server(self) -> None:\n        \"\"\"Start gopls server process\"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting gopls server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        # Verify server capabilities\n        assert \"textDocumentSync\" in init_response[\"capabilities\"]\n        assert \"completionProvider\" in init_response[\"capabilities\"]\n        assert \"definitionProvider\" in init_response[\"capabilities\"]\n\n        self.server.notify.initialized({})\n\n        # gopls server is typically ready immediately after initialization\n        # (no need to wait for events)\n"
  },
  {
    "path": "src/solidlsp/language_servers/groovy_language_server.py",
    "content": "\"\"\"\nProvides Groovy specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Groovy.\n\"\"\"\n\nimport dataclasses\nimport logging\nimport os\nimport pathlib\nimport shlex\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import Language, LanguageServerConfig\nfrom solidlsp.ls_utils import FileUtils, PlatformUtils\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\n@dataclasses.dataclass\nclass GroovyRuntimeDependencyPaths:\n    \"\"\"\n    Stores the paths to the runtime dependencies of Groovy Language Server\n    \"\"\"\n\n    java_path: str\n    java_home_path: str\n    ls_jar_path: str\n    groovy_home_path: str | None = None\n\n\nclass GroovyLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides Groovy specific instantiation of the LanguageServer class.\n    Contains various configurations and settings specific to Groovy.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a Groovy Language Server instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.\n        \"\"\"\n        runtime_dependency_paths = self._setup_runtime_dependencies(solidlsp_settings)\n        self.runtime_dependency_paths = runtime_dependency_paths\n\n        # Get jar options from configuration\n        ls_jar_options = []\n\n        if solidlsp_settings.ls_specific_settings:\n            groovy_settings = solidlsp_settings.get_ls_specific_settings(Language.GROOVY)\n            jar_options_str = groovy_settings.get(\"ls_jar_options\", \"\")\n            if jar_options_str:\n                ls_jar_options = shlex.split(jar_options_str)\n                log.info(f\"Using Groovy LS JAR options from configuration: {jar_options_str}\")\n\n        # Create command to execute the Groovy Language Server\n        cmd = [self.runtime_dependency_paths.java_path, \"-jar\", self.runtime_dependency_paths.ls_jar_path]\n        cmd.extend(ls_jar_options)\n\n        # Set environment variables including JAVA_HOME\n        proc_env = {\"JAVA_HOME\": self.runtime_dependency_paths.java_home_path}\n\n        super().__init__(\n            config,\n            repository_root_path,\n            ProcessLaunchInfo(cmd=cmd, env=proc_env, cwd=repository_root_path),\n            \"groovy\",\n            solidlsp_settings,\n        )\n\n        log.info(f\"Starting Groovy Language Server with jar options: {ls_jar_options}\")\n\n    @classmethod\n    def _setup_runtime_dependencies(cls, solidlsp_settings: SolidLSPSettings) -> GroovyRuntimeDependencyPaths:\n        \"\"\"\n        Setup runtime dependencies for Groovy Language Server and return paths.\n        \"\"\"\n        platform_id = PlatformUtils.get_platform_id()\n\n        # Verify platform support\n        assert (\n            platform_id.value.startswith(\"win-\") or platform_id.value.startswith(\"linux-\") or platform_id.value.startswith(\"osx-\")\n        ), \"Only Windows, Linux and macOS platforms are supported for Groovy in multilspy at the moment\"\n\n        # Check if user specified custom Java home path\n        java_home_path = None\n        java_path = None\n\n        if solidlsp_settings and solidlsp_settings.ls_specific_settings:\n            groovy_settings = solidlsp_settings.get_ls_specific_settings(Language.GROOVY)\n            custom_java_home = groovy_settings.get(\"ls_java_home_path\")\n            if custom_java_home:\n                log.info(f\"Using custom Java home path from configuration: {custom_java_home}\")\n                java_home_path = custom_java_home\n\n                # Determine java executable path based on platform\n                if platform_id.value.startswith(\"win-\"):\n                    java_path = os.path.join(java_home_path, \"bin\", \"java.exe\")\n                else:\n                    java_path = os.path.join(java_home_path, \"bin\", \"java\")\n\n        # If no custom Java home path, download and use bundled Java\n        if java_home_path is None:\n            # Runtime dependency information\n            runtime_dependencies = {\n                \"java\": {\n                    \"win-x64\": {\n                        \"url\": \"https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-win32-x64-1.42.0-561.vsix\",\n                        \"archiveType\": \"zip\",\n                        \"java_home_path\": \"extension/jre/21.0.7-win32-x86_64\",\n                        \"java_path\": \"extension/jre/21.0.7-win32-x86_64/bin/java.exe\",\n                    },\n                    \"linux-x64\": {\n                        \"url\": \"https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-linux-x64-1.42.0-561.vsix\",\n                        \"archiveType\": \"zip\",\n                        \"java_home_path\": \"extension/jre/21.0.7-linux-x86_64\",\n                        \"java_path\": \"extension/jre/21.0.7-linux-x86_64/bin/java\",\n                    },\n                    \"linux-arm64\": {\n                        \"url\": \"https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-linux-arm64-1.42.0-561.vsix\",\n                        \"archiveType\": \"zip\",\n                        \"java_home_path\": \"extension/jre/21.0.7-linux-aarch64\",\n                        \"java_path\": \"extension/jre/21.0.7-linux-aarch64/bin/java\",\n                    },\n                    \"osx-x64\": {\n                        \"url\": \"https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-darwin-x64-1.42.0-561.vsix\",\n                        \"archiveType\": \"zip\",\n                        \"java_home_path\": \"extension/jre/21.0.7-macosx-x86_64\",\n                        \"java_path\": \"extension/jre/21.0.7-macosx-x86_64/bin/java\",\n                    },\n                    \"osx-arm64\": {\n                        \"url\": \"https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-darwin-arm64-1.42.0-561.vsix\",\n                        \"archiveType\": \"zip\",\n                        \"java_home_path\": \"extension/jre/21.0.7-macosx-aarch64\",\n                        \"java_path\": \"extension/jre/21.0.7-macosx-aarch64/bin/java\",\n                    },\n                },\n            }\n\n            java_dependency = runtime_dependencies[\"java\"][platform_id.value]\n\n            static_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), \"groovy_language_server\")\n            os.makedirs(static_dir, exist_ok=True)\n\n            java_dir = os.path.join(static_dir, \"java\")\n            os.makedirs(java_dir, exist_ok=True)\n\n            java_home_path = os.path.join(java_dir, java_dependency[\"java_home_path\"])\n            java_path = os.path.join(java_dir, java_dependency[\"java_path\"])\n\n            if not os.path.exists(java_path):\n                log.info(f\"Downloading Java for {platform_id.value}...\")\n                FileUtils.download_and_extract_archive(java_dependency[\"url\"], java_dir, java_dependency[\"archiveType\"])\n\n                if not platform_id.value.startswith(\"win-\"):\n                    os.chmod(java_path, 0o755)\n\n        assert java_path and os.path.exists(java_path), f\"Java executable not found at {java_path}\"\n\n        ls_jar_path = cls._find_groovy_ls_jar(solidlsp_settings)\n\n        return GroovyRuntimeDependencyPaths(java_path=java_path, java_home_path=java_home_path, ls_jar_path=ls_jar_path)\n\n    @classmethod\n    def _find_groovy_ls_jar(cls, solidlsp_settings: SolidLSPSettings) -> str:\n        \"\"\"\n        Find Groovy Language Server JAR file\n        \"\"\"\n        if solidlsp_settings and solidlsp_settings.ls_specific_settings:\n            groovy_settings = solidlsp_settings.get_ls_specific_settings(Language.GROOVY)\n            config_jar_path = groovy_settings.get(\"ls_jar_path\")\n            if config_jar_path and os.path.exists(config_jar_path):\n                log.info(f\"Using Groovy LS JAR from configuration: {config_jar_path}\")\n                return config_jar_path\n\n        # if JAR not found\n        raise RuntimeError(\n            \"Groovy Language Server JAR not found. To use Groovy language support:\\n\"\n            \"Set 'ls_jar_path' in groovy settings in serena_config.yml:\\n\"\n            \"   ls_specific_settings:\\n\"\n            \"     groovy:\\n\"\n            \"       ls_jar_path: '/path/to/groovy-language-server.jar'\\n\"\n            \"   Ensure the JAR file is available at the configured path\\n\"\n        )\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Groovy Language Server.\n        \"\"\"\n        if not os.path.isabs(repository_absolute_path):\n            repository_absolute_path = os.path.abspath(repository_absolute_path)\n\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"clientInfo\": {\"name\": \"Serena Groovy Client\", \"version\": \"1.0.0\"},\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"dynamicRegistration\": True, \"didSave\": True},\n                    \"completion\": {\"dynamicRegistration\": True},\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\"dynamicRegistration\": True},\n                    \"workspaceSymbol\": {\"dynamicRegistration\": True},\n                    \"signatureHelp\": {\"dynamicRegistration\": True},\n                    \"rename\": {\"dynamicRegistration\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                },\n            },\n            \"initializationOptions\": {\n                \"settings\": {\n                    \"groovy\": {\n                        \"classpath\": [],\n                        \"diagnostics\": {\"enabled\": True},\n                        \"completion\": {\"enabled\": True},\n                    }\n                },\n            },\n            \"processId\": os.getpid(),\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return initialize_params  # type: ignore\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the Groovy Language Server\n        \"\"\"\n\n        def execute_client_command_handler(params: dict) -> list:\n            return []\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        self.server.on_request(\"client/registerCapability\", do_nothing)\n        self.server.on_notification(\"language/status\", do_nothing)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_request(\"workspace/executeClientCommand\", execute_client_command_handler)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"language/actionableNotification\", do_nothing)\n\n        log.info(\"Starting Groovy server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        capabilities = init_response[\"capabilities\"]\n        assert \"textDocumentSync\" in capabilities, \"Server must support textDocumentSync\"\n        assert \"hoverProvider\" in capabilities, \"Server must support hover\"\n        assert \"completionProvider\" in capabilities, \"Server must support code completion\"\n        assert \"signatureHelpProvider\" in capabilities, \"Server must support signature help\"\n        assert \"definitionProvider\" in capabilities, \"Server must support go to definition\"\n        assert \"referencesProvider\" in capabilities, \"Server must support find references\"\n        assert \"documentSymbolProvider\" in capabilities, \"Server must support document symbols\"\n        assert \"workspaceSymbolProvider\" in capabilities, \"Server must support workspace symbols\"\n\n        self.server.notify.initialized({})\n"
  },
  {
    "path": "src/solidlsp/language_servers/haskell_language_server.py",
    "content": "\"\"\"\nProvides Haskell specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Haskell.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport shutil\nimport time\nfrom typing import Any\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass HaskellLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides Haskell specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Haskell.\n    Uses Haskell Language Server (HLS) for LSP functionality.\n    \"\"\"\n\n    @staticmethod\n    def _ensure_hls_installed() -> str:\n        \"\"\"Ensure haskell-language-server-wrapper is available.\"\"\"\n        # Try common locations\n        common_paths = [\n            shutil.which(\"haskell-language-server-wrapper\"),\n            \"/opt/homebrew/bin/haskell-language-server-wrapper\",\n            \"/usr/local/bin/haskell-language-server-wrapper\",\n            os.path.expanduser(\"~/.ghcup/bin/haskell-language-server-wrapper\"),\n            os.path.expanduser(\"~/.cabal/bin/haskell-language-server-wrapper\"),\n            os.path.expanduser(\"~/.local/bin/haskell-language-server-wrapper\"),\n        ]\n\n        # Check Stack programs directory\n        stack_programs = os.path.expanduser(\"~/.local/share/stack/programs\")\n        if os.path.exists(stack_programs):\n            try:\n                for arch_dir in os.listdir(stack_programs):\n                    arch_path = os.path.join(stack_programs, arch_dir)\n                    if os.path.isdir(arch_path):\n                        try:\n                            for ghc_dir in os.listdir(arch_path):\n                                hls_path = os.path.join(arch_path, ghc_dir, \"bin\", \"haskell-language-server-wrapper\")\n                                if os.path.isfile(hls_path) and os.access(hls_path, os.X_OK):\n                                    common_paths.append(hls_path)\n                        except (PermissionError, OSError):\n                            # Skip directories we can't read\n                            continue\n            except (PermissionError, OSError):\n                # Stack programs directory not accessible\n                pass\n\n        for path in common_paths:\n            if path and os.path.isfile(path) and os.access(path, os.X_OK):\n                return path\n\n        raise RuntimeError(\n            \"haskell-language-server-wrapper is not installed or not in PATH.\\n\"\n            \"Searched locations:\\n\" + \"\\n\".join(f\"  - {p}\" for p in common_paths if p) + \"\\n\"\n            \"Please install HLS via:\\n\"\n            \"  - GHCup: https://www.haskell.org/ghcup/\\n\"\n            \"  - Stack: stack install haskell-language-server\\n\"\n            \"  - Cabal: cabal install haskell-language-server\\n\"\n            \"  - Homebrew (macOS): brew install haskell-language-server\"\n        )\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a HaskellLanguageServer instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.\n        \"\"\"\n        hls_executable_path = self._ensure_hls_installed()\n        log.info(f\"Using haskell-language-server at: {hls_executable_path}\")\n\n        # Check if there's a haskell subdirectory with Stack/Cabal project\n        haskell_subdir = os.path.join(repository_root_path, \"haskell\")\n        if os.path.exists(haskell_subdir) and (\n            os.path.exists(os.path.join(haskell_subdir, \"stack.yaml\")) or os.path.exists(os.path.join(haskell_subdir, \"cabal.project\"))\n        ):\n            working_dir = haskell_subdir\n            log.info(f\"Using Haskell project directory: {working_dir}\")\n        else:\n            working_dir = repository_root_path\n\n        # Set up environment with GHCup bin in PATH\n        env = dict(os.environ)\n        ghcup_bin = os.path.expanduser(\"~/.ghcup/bin\")\n        if ghcup_bin not in env.get(\"PATH\", \"\"):\n            env[\"PATH\"] = f\"{ghcup_bin}{os.pathsep}{env.get('PATH', '')}\"\n\n        super().__init__(\n            config,\n            repository_root_path,\n            ProcessLaunchInfo(cmd=[hls_executable_path, \"--lsp\", \"--cwd\", working_dir], cwd=working_dir, env=env),\n            \"haskell\",\n            solidlsp_settings,\n        )\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\"dist\", \"dist-newstyle\", \".stack-work\", \".cabal-sandbox\"]\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Haskell Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"clientInfo\": {\"name\": \"Serena\", \"version\": \"0.1.0\"},\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"workspace\": {\n                    \"applyEdit\": True,\n                    \"workspaceEdit\": {\n                        \"documentChanges\": True,\n                        \"resourceOperations\": [\"create\", \"rename\", \"delete\"],\n                        \"failureHandling\": \"textOnlyTransactional\",\n                        \"normalizesLineEndings\": True,\n                        \"changeAnnotationSupport\": {\"groupsOnLabel\": True},\n                    },\n                    \"configuration\": True,\n                    \"didChangeWatchedFiles\": {\"dynamicRegistration\": True, \"relativePatternSupport\": True},\n                    \"symbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                        \"tagSupport\": {\"valueSet\": [1]},\n                        \"resolveSupport\": {\"properties\": [\"location.range\"]},\n                    },\n                    \"executeCommand\": {\"dynamicRegistration\": True},\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"workspaceFolders\": True,\n                    \"semanticTokens\": {\"refreshSupport\": True},\n                },\n                \"textDocument\": {\n                    \"publishDiagnostics\": {\n                        \"relatedInformation\": True,\n                        \"versionSupport\": False,\n                        \"tagSupport\": {\"valueSet\": [1, 2]},\n                        \"codeDescriptionSupport\": True,\n                        \"dataSupport\": True,\n                    },\n                    \"synchronization\": {\"dynamicRegistration\": True, \"willSave\": True, \"willSaveWaitUntil\": True, \"didSave\": True},\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"contextSupport\": True,\n                        \"completionItem\": {\n                            \"snippetSupport\": True,\n                            \"commitCharactersSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"deprecatedSupport\": True,\n                            \"preselectSupport\": True,\n                            \"tagSupport\": {\"valueSet\": [1]},\n                            \"insertReplaceSupport\": True,\n                            \"resolveSupport\": {\"properties\": [\"documentation\", \"detail\", \"additionalTextEdits\"]},\n                            \"insertTextModeSupport\": {\"valueSet\": [1, 2]},\n                            \"labelDetailsSupport\": True,\n                        },\n                        \"insertTextMode\": 2,\n                        \"completionItemKind\": {\n                            \"valueSet\": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]\n                        },\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"signatureHelp\": {\n                        \"dynamicRegistration\": True,\n                        \"signatureInformation\": {\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"parameterInformation\": {\"labelOffsetSupport\": True},\n                            \"activeParameterSupport\": True,\n                        },\n                        \"contextSupport\": True,\n                    },\n                    \"definition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentHighlight\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"tagSupport\": {\"valueSet\": [1]},\n                        \"labelSupport\": True,\n                    },\n                    \"codeAction\": {\n                        \"dynamicRegistration\": True,\n                        \"isPreferredSupport\": True,\n                        \"disabledSupport\": True,\n                        \"dataSupport\": True,\n                        \"resolveSupport\": {\"properties\": [\"edit\"]},\n                        \"codeActionLiteralSupport\": {\n                            \"codeActionKind\": {\n                                \"valueSet\": [\n                                    \"\",\n                                    \"quickfix\",\n                                    \"refactor\",\n                                    \"refactor.extract\",\n                                    \"refactor.inline\",\n                                    \"refactor.rewrite\",\n                                    \"source\",\n                                    \"source.organizeImports\",\n                                ]\n                            }\n                        },\n                        \"honorsChangeAnnotations\": False,\n                    },\n                    \"formatting\": {\"dynamicRegistration\": True},\n                    \"rangeFormatting\": {\"dynamicRegistration\": True},\n                    \"onTypeFormatting\": {\"dynamicRegistration\": True},\n                    \"rename\": {\n                        \"dynamicRegistration\": True,\n                        \"prepareSupport\": True,\n                        \"prepareSupportDefaultBehavior\": 1,\n                        \"honorsChangeAnnotations\": True,\n                    },\n                    \"documentLink\": {\"dynamicRegistration\": True, \"tooltipSupport\": True},\n                    \"typeDefinition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"implementation\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"colorProvider\": {\"dynamicRegistration\": True},\n                    \"foldingRange\": {\n                        \"dynamicRegistration\": True,\n                        \"rangeLimit\": 5000,\n                        \"lineFoldingOnly\": True,\n                        \"foldingRangeKind\": {\"valueSet\": [\"comment\", \"imports\", \"region\"]},\n                    },\n                    \"declaration\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"selectionRange\": {\"dynamicRegistration\": True},\n                    \"callHierarchy\": {\"dynamicRegistration\": True},\n                    \"semanticTokens\": {\n                        \"dynamicRegistration\": True,\n                        \"tokenTypes\": [\n                            \"namespace\",\n                            \"type\",\n                            \"class\",\n                            \"enum\",\n                            \"interface\",\n                            \"struct\",\n                            \"typeParameter\",\n                            \"parameter\",\n                            \"variable\",\n                            \"property\",\n                            \"enumMember\",\n                            \"event\",\n                            \"function\",\n                            \"method\",\n                            \"macro\",\n                            \"keyword\",\n                            \"modifier\",\n                            \"comment\",\n                            \"string\",\n                            \"number\",\n                            \"regexp\",\n                            \"operator\",\n                        ],\n                        \"tokenModifiers\": [\n                            \"declaration\",\n                            \"definition\",\n                            \"readonly\",\n                            \"static\",\n                            \"deprecated\",\n                            \"abstract\",\n                            \"async\",\n                            \"modification\",\n                            \"documentation\",\n                            \"defaultLibrary\",\n                        ],\n                        \"formats\": [\"relative\"],\n                        \"requests\": {\"range\": True, \"full\": {\"delta\": True}},\n                        \"multilineTokenSupport\": False,\n                        \"overlappingTokenSupport\": False,\n                    },\n                    \"linkedEditingRange\": {\"dynamicRegistration\": True},\n                },\n                \"window\": {\n                    \"showMessage\": {\"messageActionItem\": {\"additionalPropertiesSupport\": True}},\n                    \"showDocument\": {\"support\": True},\n                    \"workDoneProgress\": True,\n                },\n                \"general\": {\n                    \"staleRequestSupport\": {\"cancel\": True, \"retryOnContentModified\": []},\n                    \"regularExpressions\": {\"engine\": \"ECMAScript\", \"version\": \"ES2020\"},\n                    \"markdown\": {\n                        \"parser\": \"marked\",\n                        \"version\": \"1.1.0\",\n                    },\n                    \"positionEncodings\": [\"utf-16\"],\n                },\n            },\n            \"initializationOptions\": {\n                \"haskell\": {\n                    \"formattingProvider\": \"ormolu\",\n                    \"checkProject\": True,\n                }\n            },\n            \"trace\": \"verbose\",\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return initialize_params  # type: ignore\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the Haskell Language Server\n        \"\"\"\n\n        def do_nothing(params: Any) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def register_capability_handler(params: dict) -> None:\n            \"\"\"Handle dynamic capability registration from HLS\"\"\"\n            if \"registrations\" in params:\n                for registration in params.get(\"registrations\", []):\n                    method = registration.get(\"method\", \"\")\n                    log.info(f\"HLS registered capability: {method}\")\n            return\n\n        def workspace_configuration_handler(params: dict) -> Any:\n            \"\"\"Handle workspace/configuration requests from HLS\"\"\"\n            log.info(f\"HLS requesting configuration: {params}\")\n\n            # Configuration matching VS Code settings and initialization options\n            haskell_config = {\n                \"formattingProvider\": \"ormolu\",\n                \"checkProject\": True,\n                \"plugin\": {\"importLens\": {\"codeActionsOn\": False, \"codeLensOn\": False}, \"hlint\": {\"codeActionsOn\": False}},\n            }\n\n            # HLS expects array of config items matching requested sections\n            if isinstance(params, dict) and \"items\" in params:\n                result = []\n                for item in params[\"items\"]:\n                    section = item.get(\"section\", \"\")\n                    if section == \"haskell\":\n                        result.append(haskell_config)\n                    else:\n                        result.append({})\n                log.info(f\"Returning configuration: {result}\")\n                return result\n\n            # Fallback: return single config\n            return [haskell_config]\n\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_request(\"workspace/configuration\", workspace_configuration_handler)\n\n        log.info(\"Starting Haskell Language Server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        # Log capabilities returned by HLS\n        capabilities = init_response.get(\"capabilities\", {})\n        log.info(f\"HLS capabilities: {list(capabilities.keys())}\")\n\n        self.server.notify.initialized({})\n\n        # Give HLS time to index the project\n        # HLS can be slow to index, especially on first run\n        log.info(\"Waiting for HLS to index project...\")\n        time.sleep(5)\n\n        log.info(\"Haskell Language Server initialized successfully\")\n"
  },
  {
    "path": "src/solidlsp/language_servers/hlsl_language_server.py",
    "content": "\"\"\"\nShader language server using shader-language-server (antaalt/shader-sense).\nSupports HLSL, GLSL, and WGSL shader file formats.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport shutil\nfrom typing import Any, cast\n\nimport psutil\nfrom overrides import override\n\nfrom solidlsp.ls import LanguageServerDependencyProvider, LanguageServerDependencyProviderSinglePath, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nfrom .common import RuntimeDependency, RuntimeDependencyCollection\n\nlog = logging.getLogger(__name__)\n\n# GitHub release version to download when not installed locally\n_DEFAULT_VERSION = \"1.3.0\"\n_GITHUB_RELEASE_BASE = \"https://github.com/antaalt/shader-sense/releases/download\"\n\n\nclass HlslLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Shader language server using shader-language-server.\n    Supports .hlsl, .hlsli, .fx, .fxh, .cginc, .compute, .shader, .glsl, .vert, .frag, .geom, .tesc, .tese, .comp, .wgsl files.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings) -> None:\n        super().__init__(config, repository_root_path, None, \"hlsl\", solidlsp_settings)\n\n    @override\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def _get_or_install_core_dependency(self) -> str:\n            # 1. Check PATH for system-installed binary\n            system_binary = shutil.which(\"shader-language-server\")\n            if system_binary:\n                log.info(f\"Using system-installed shader-language-server at {system_binary}\")\n                return system_binary\n\n            # 2. Try to download pre-built binary from GitHub releases\n            version = self._custom_settings.get(\"version\", _DEFAULT_VERSION)\n            tag = f\"v{version}\"\n            base_url = f\"{_GITHUB_RELEASE_BASE}/{tag}\"\n\n            # macOS has no pre-built binaries; build from source via cargo install\n            cargo_install_cmd = f\"cargo install shader_language_server --version {version} --root .\"\n\n            deps = RuntimeDependencyCollection(\n                [\n                    RuntimeDependency(\n                        id=\"shader-language-server\",\n                        description=\"shader-language-server for Windows (x64)\",\n                        url=f\"{base_url}/shader-language-server-x86_64-pc-windows-msvc.zip\",\n                        platform_id=\"win-x64\",\n                        archive_type=\"zip\",\n                        binary_name=\"shader-language-server.exe\",\n                    ),\n                    RuntimeDependency(\n                        id=\"shader-language-server\",\n                        description=\"shader-language-server for Linux (x64)\",\n                        url=f\"{base_url}/shader-language-server-x86_64-unknown-linux-gnu.zip\",\n                        platform_id=\"linux-x64\",\n                        archive_type=\"zip\",\n                        binary_name=\"shader-language-server\",\n                    ),\n                    RuntimeDependency(\n                        id=\"shader-language-server\",\n                        description=\"shader-language-server for Windows (ARM64)\",\n                        url=f\"{base_url}/shader-language-server-aarch64-pc-windows-msvc.zip\",\n                        platform_id=\"win-arm64\",\n                        archive_type=\"zip\",\n                        binary_name=\"shader-language-server.exe\",\n                    ),\n                    RuntimeDependency(\n                        id=\"shader-language-server\",\n                        description=\"shader-language-server for macOS (x64) - built from source\",\n                        command=cargo_install_cmd,\n                        platform_id=\"osx-x64\",\n                        binary_name=\"bin/shader-language-server\",\n                    ),\n                    RuntimeDependency(\n                        id=\"shader-language-server\",\n                        description=\"shader-language-server for macOS (ARM64) - built from source\",\n                        command=cargo_install_cmd,\n                        platform_id=\"osx-arm64\",\n                        binary_name=\"bin/shader-language-server\",\n                    ),\n                ]\n            )\n\n            try:\n                dep = deps.get_single_dep_for_current_platform()\n            except RuntimeError:\n                dep = None\n\n            if dep is None:\n                raise FileNotFoundError(\n                    \"shader-language-server is not installed and no auto-install is available for your platform.\\n\"\n                    \"Please install it using one of the following methods:\\n\"\n                    \"  cargo:   cargo install shader_language_server\\n\"\n                    \"  GitHub:  Download from https://github.com/antaalt/shader-sense/releases\\n\"\n                    \"On macOS, install the Rust toolchain (https://rustup.rs) and Serena will build from source automatically.\\n\"\n                    \"See https://github.com/antaalt/shader-sense for more details.\"\n                )\n\n            install_dir = os.path.join(self._ls_resources_dir, \"shader-language-server\")\n            executable_path = deps.binary_path(install_dir)\n\n            if not os.path.exists(executable_path):\n                log.info(f\"shader-language-server not found. Downloading from {dep.url}\")\n                _ = deps.install(install_dir)\n\n            if not os.path.exists(executable_path):\n                raise FileNotFoundError(f\"shader-language-server not found at {executable_path}\")\n\n            os.chmod(executable_path, 0o755)\n            return executable_path\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [core_path, \"--stdio\"]\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"completionItem\": {\"snippetSupport\": True},\n                    },\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"hover\": {\n                        \"dynamicRegistration\": True,\n                        \"contentFormat\": [\"markdown\", \"plaintext\"],\n                    },\n                    \"signatureHelp\": {\n                        \"dynamicRegistration\": True,\n                        \"signatureInformation\": {\n                            \"parameterInformation\": {\"labelOffsetSupport\": True},\n                        },\n                    },\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"formatting\": {\"dynamicRegistration\": True},\n                    \"publishDiagnostics\": {\"relatedInformation\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"configuration\": True,\n                },\n            },\n            \"workspaceFolders\": [{\"uri\": root_uri, \"name\": os.path.basename(repository_absolute_path)}],\n        }\n        return cast(InitializeParams, initialize_params)\n\n    @override\n    def _start_server(self) -> None:\n        def do_nothing(params: Any) -> None:\n            return\n\n        def on_log_message(params: Any) -> None:\n            message = params.get(\"message\", \"\") if isinstance(params, dict) else str(params)\n            log.info(f\"shader-language-server: {message}\")\n\n        def on_configuration_request(params: Any) -> list[dict]:\n            \"\"\"Respond to workspace/configuration requests.\n\n            shader-language-server requests config with section 'shader-validator'.\n            Return empty config to use defaults.\n            \"\"\"\n            items = params.get(\"items\", []) if isinstance(params, dict) else []\n            return [{}] * len(items)\n\n        self.server.on_request(\"client/registerCapability\", do_nothing)\n        self.server.on_request(\"workspace/configuration\", on_configuration_request)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"window/logMessage\", on_log_message)\n\n        log.info(\"Starting shader-language-server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        capabilities = init_response.get(\"capabilities\", {})\n        log.info(f\"Initialize response capabilities: {list(capabilities.keys())}\")\n        assert \"textDocumentSync\" in capabilities, \"shader-language-server must support textDocumentSync\"\n        if \"documentSymbolProvider\" not in capabilities:\n            log.warning(\"shader-language-server does not advertise documentSymbolProvider\")\n        if \"definitionProvider\" not in capabilities:\n            log.warning(\"shader-language-server does not advertise definitionProvider\")\n\n        self.server.notify.initialized({})\n\n    @override\n    def stop(self, shutdown_timeout: float = 2.0) -> None:\n        \"\"\"Kill the shader-language-server process tree before the standard shutdown.\n\n        The base _shutdown() calls process.terminate() directly on the subprocess,\n        which on Windows with shell=True only kills the cmd.exe wrapper, leaving\n        the actual shader-language-server binary running as an orphan. We use psutil\n        to terminate the full process tree first.\n        \"\"\"\n        process = self.server.process if self.server else None\n        if process and process.pid and process.returncode is None:\n            try:\n                parent = psutil.Process(process.pid)\n                children = parent.children(recursive=True)\n                for child in children:\n                    try:\n                        child.terminate()\n                    except (psutil.NoSuchProcess, psutil.AccessDenied):\n                        pass\n                psutil.wait_procs(children, timeout=2)\n                for child in children:\n                    try:\n                        if child.is_running():\n                            child.kill()\n                    except (psutil.NoSuchProcess, psutil.AccessDenied):\n                        pass\n            except (psutil.NoSuchProcess, psutil.AccessDenied):\n                pass\n            except Exception as e:\n                log.debug(f\"Error cleaning up shader-language-server process tree: {e}\")\n        super().stop(shutdown_timeout)\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        \"\"\"Ignore Unity-specific directories that contain no user-authored shaders.\"\"\"\n        return super().is_ignored_dirname(dirname) or dirname in {\"Library\", \"Temp\", \"Logs\", \"obj\", \"Packages\"}\n"
  },
  {
    "path": "src/solidlsp/language_servers/intelephense.py",
    "content": "\"\"\"\nProvides PHP specific instantiation of the LanguageServer class using Intelephense.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport shutil\nfrom time import sleep\n\nfrom overrides import override\n\nfrom solidlsp.ls import LanguageServerDependencyProvider, LanguageServerDependencyProviderSinglePath, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.ls_utils import PlatformId, PlatformUtils\nfrom solidlsp.lsp_protocol_handler.lsp_types import Definition, DefinitionParams, InitializeParams, LocationLink\nfrom solidlsp.settings import SolidLSPSettings\n\nfrom ..lsp_protocol_handler import lsp_types\nfrom .common import RuntimeDependency, RuntimeDependencyCollection\n\nlog = logging.getLogger(__name__)\n\n\nclass Intelephense(SolidLanguageServer):\n    \"\"\"\n    Provides PHP specific instantiation of the LanguageServer class using Intelephense.\n\n    You can pass the following entries in ls_specific_settings[\"php\"]:\n        - maxMemory: sets intelephense.maxMemory\n        - maxFileSize: sets intelephense.files.maxSize\n        - ignore_vendor: whether or ignore directories named \"vendor\" (default: true)\n    \"\"\"\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in self._ignored_dirnames\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def _get_or_install_core_dependency(self) -> str:\n            \"\"\"\n            Setup runtime dependencies for Intelephense and return the path to the executable.\n            \"\"\"\n            platform_id = PlatformUtils.get_platform_id()\n\n            valid_platforms = [\n                PlatformId.LINUX_x64,\n                PlatformId.LINUX_arm64,\n                PlatformId.OSX,\n                PlatformId.OSX_x64,\n                PlatformId.OSX_arm64,\n                PlatformId.WIN_x64,\n                PlatformId.WIN_arm64,\n            ]\n            assert platform_id in valid_platforms, f\"Platform {platform_id} is not supported by Intelephense at the moment\"\n\n            # Verify both node and npm are installed\n            is_node_installed = shutil.which(\"node\") is not None\n            assert is_node_installed, \"node is not installed or isn't in PATH. Please install NodeJS and try again.\"\n            is_npm_installed = shutil.which(\"npm\") is not None\n            assert is_npm_installed, \"npm is not installed or isn't in PATH. Please install npm and try again.\"\n\n            # Install intelephense if not already installed\n            intelephense_ls_dir = os.path.join(self._ls_resources_dir, \"php-lsp\")\n            os.makedirs(intelephense_ls_dir, exist_ok=True)\n            intelephense_executable_path = os.path.join(intelephense_ls_dir, \"node_modules\", \".bin\", \"intelephense\")\n            if not os.path.exists(intelephense_executable_path):\n                deps = RuntimeDependencyCollection(\n                    [\n                        RuntimeDependency(\n                            id=\"intelephense\",\n                            command=\"npm install --prefix ./ intelephense@1.14.4\",\n                            platform_id=\"any\",\n                        )\n                    ]\n                )\n                deps.install(intelephense_ls_dir)\n\n            assert os.path.exists(\n                intelephense_executable_path\n            ), f\"intelephense executable not found at {intelephense_executable_path}, something went wrong.\"\n\n            return intelephense_executable_path\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [core_path, \"--stdio\"]\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        super().__init__(config, repository_root_path, None, \"php\", solidlsp_settings)\n        self.request_id = 0\n\n        # For PHP projects, we should ignore:\n        # - node_modules: if the project has JavaScript components\n        # - cache: commonly used for caching\n        # - (configurable) vendor: third-party dependencies managed by Composer\n        self._ignored_dirnames = {\"node_modules\", \"cache\"}\n        if self._custom_settings.get(\"ignore_vendor\", True):\n            self._ignored_dirnames.add(\"vendor\")\n        log.info(f\"Ignoring the following directories for PHP projects: {', '.join(sorted(self._ignored_dirnames))}\")\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    def _get_initialize_params(self, repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialization params for the Intelephense Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True},\n                },\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        initialization_options = {}\n        # Add license key if provided via environment variable\n        license_key = os.environ.get(\"INTELEPHENSE_LICENSE_KEY\")\n        if license_key:\n            initialization_options[\"licenceKey\"] = license_key\n\n        max_memory = self._custom_settings.get(\"maxMemory\")\n        max_file_size = self._custom_settings.get(\"maxFileSize\")\n        if max_memory is not None:\n            initialization_options[\"intelephense.maxMemory\"] = max_memory\n        if max_file_size is not None:\n            initialization_options[\"intelephense.files.maxSize\"] = max_file_size\n\n        initialize_params[\"initializationOptions\"] = initialization_options\n        return initialize_params  # type: ignore\n\n    def _start_server(self) -> None:\n        \"\"\"Start Intelephense server process\"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting Intelephense server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        log.info(\"After sent initialize params\")\n\n        # Verify server capabilities\n        capabilities = init_response[\"capabilities\"]\n        assert \"textDocumentSync\" in capabilities\n        assert \"completionProvider\" in capabilities\n        assert \"definitionProvider\" in capabilities\n        assert \"documentSymbolProvider\" in capabilities, \"Server must support document symbols\"\n\n        self.server.notify.initialized({})\n\n        # Intelephense server is typically ready immediately after initialization\n        # TODO: This is probably incorrect; the server does send an initialized notification, which we could wait for!\n\n    @override\n    # For some reason, the LS may need longer to process this, so we just retry\n    def _send_references_request(self, relative_file_path: str, line: int, column: int) -> list[lsp_types.Location] | None:\n        # TODO: The LS doesn't return references contained in other files if it doesn't sleep. This is\n        #   despite the LS having processed requests already. I don't know what causes this, but sleeping\n        #   one second helps. It may be that sleeping only once is enough but that's hard to reliably test.\n        # May be related to the time it takes to read the files or something like that.\n        # The sleeping doesn't seem to be needed on all systems\n        sleep(1)\n        return super()._send_references_request(relative_file_path, line, column)\n\n    @override\n    def _send_definition_request(self, definition_params: DefinitionParams) -> Definition | list[LocationLink] | None:\n        # TODO: same as above, also only a problem if the definition is in another file\n        sleep(1)\n        return super()._send_definition_request(definition_params)\n"
  },
  {
    "path": "src/solidlsp/language_servers/jedi_server.py",
    "content": "\"\"\"\nProvides Python specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Python.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport threading\nfrom typing import cast\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass JediServer(SolidLanguageServer):\n    \"\"\"\n    Provides Python specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Python.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a JediServer instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(\n            config,\n            repository_root_path,\n            ProcessLaunchInfo(cmd=\"jedi-language-server\", cwd=repository_root_path),\n            \"python\",\n            solidlsp_settings,\n        )\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\"venv\", \"__pycache__\"]\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Jedi Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"processId\": os.getpid(),\n            \"clientInfo\": {\"name\": \"Serena\", \"version\": \"0.1.0\"},\n            \"locale\": \"en\",\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            # Note: this is not necessarily the minimal set of capabilities...\n            \"capabilities\": {\n                \"workspace\": {\n                    \"applyEdit\": True,\n                    \"workspaceEdit\": {\n                        \"documentChanges\": True,\n                        \"resourceOperations\": [\"create\", \"rename\", \"delete\"],\n                        \"failureHandling\": \"textOnlyTransactional\",\n                        \"normalizesLineEndings\": True,\n                        \"changeAnnotationSupport\": {\"groupsOnLabel\": True},\n                    },\n                    \"configuration\": True,\n                    \"didChangeWatchedFiles\": {\"dynamicRegistration\": True, \"relativePatternSupport\": True},\n                    \"symbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                        \"tagSupport\": {\"valueSet\": [1]},\n                        \"resolveSupport\": {\"properties\": [\"location.range\"]},\n                    },\n                    \"workspaceFolders\": True,\n                    \"fileOperations\": {\n                        \"dynamicRegistration\": True,\n                        \"didCreate\": True,\n                        \"didRename\": True,\n                        \"didDelete\": True,\n                        \"willCreate\": True,\n                        \"willRename\": True,\n                        \"willDelete\": True,\n                    },\n                    \"inlineValue\": {\"refreshSupport\": True},\n                    \"inlayHint\": {\"refreshSupport\": True},\n                    \"diagnostics\": {\"refreshSupport\": True},\n                },\n                \"textDocument\": {\n                    \"publishDiagnostics\": {\n                        \"relatedInformation\": True,\n                        \"versionSupport\": False,\n                        \"tagSupport\": {\"valueSet\": [1, 2]},\n                        \"codeDescriptionSupport\": True,\n                        \"dataSupport\": True,\n                    },\n                    \"synchronization\": {\"dynamicRegistration\": True, \"willSave\": True, \"willSaveWaitUntil\": True, \"didSave\": True},\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"signatureHelp\": {\n                        \"dynamicRegistration\": True,\n                        \"signatureInformation\": {\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"parameterInformation\": {\"labelOffsetSupport\": True},\n                            \"activeParameterSupport\": True,\n                        },\n                        \"contextSupport\": True,\n                    },\n                    \"definition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentHighlight\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"tagSupport\": {\"valueSet\": [1]},\n                        \"labelSupport\": True,\n                    },\n                    \"documentLink\": {\"dynamicRegistration\": True, \"tooltipSupport\": True},\n                    \"typeDefinition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"implementation\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"declaration\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"selectionRange\": {\"dynamicRegistration\": True},\n                    \"callHierarchy\": {\"dynamicRegistration\": True},\n                    \"linkedEditingRange\": {\"dynamicRegistration\": True},\n                    \"typeHierarchy\": {\"dynamicRegistration\": True},\n                    \"inlineValue\": {\"dynamicRegistration\": True},\n                    \"inlayHint\": {\n                        \"dynamicRegistration\": True,\n                        \"resolveSupport\": {\"properties\": [\"tooltip\", \"textEdits\", \"label.tooltip\", \"label.location\", \"label.command\"]},\n                    },\n                    \"diagnostic\": {\"dynamicRegistration\": True, \"relatedDocumentSupport\": False},\n                },\n                \"notebookDocument\": {\"synchronization\": {\"dynamicRegistration\": True, \"executionSummarySupport\": True}},\n                \"experimental\": {\n                    \"serverStatusNotification\": True,\n                    \"openServerLogs\": True,\n                },\n            },\n            # See https://github.com/pappasam/jedi-language-server?tab=readme-ov-file\n            # We use the default options except for maxSymbols, where 0 means no limit\n            \"initializationOptions\": {\n                \"workspace\": {\n                    \"symbols\": {\"ignoreFolders\": [\".nox\", \".tox\", \".venv\", \"__pycache__\", \"venv\"], \"maxSymbols\": 0},\n                },\n            },\n            \"trace\": \"verbose\",\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return cast(InitializeParams, initialize_params)\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the JEDI Language Server\n        \"\"\"\n        completions_available = threading.Event()\n\n        def execute_client_command_handler(params: dict) -> list:\n            return []\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def check_experimental_status(params: dict) -> None:\n            if params[\"quiescent\"] == True:\n                completions_available.set()\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        self.server.on_request(\"client/registerCapability\", do_nothing)\n        self.server.on_notification(\"language/status\", do_nothing)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_request(\"workspace/executeClientCommand\", execute_client_command_handler)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"language/actionableNotification\", do_nothing)\n        self.server.on_notification(\"experimental/serverStatus\", check_experimental_status)\n\n        log.info(\"Starting jedi-language-server server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        assert init_response[\"capabilities\"][\"textDocumentSync\"][\"change\"] == 2  # type: ignore\n        assert \"completionProvider\" in init_response[\"capabilities\"]\n        assert init_response[\"capabilities\"][\"completionProvider\"] == {\n            \"triggerCharacters\": [\".\", \"'\", '\"'],\n            \"resolveProvider\": True,\n        }\n\n        self.server.notify.initialized({})\n"
  },
  {
    "path": "src/solidlsp/language_servers/julia_server.py",
    "content": "import logging\nimport os\nimport pathlib\nimport platform\nimport shutil\nimport subprocess\nfrom typing import Any\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass JuliaLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Language server implementation for Julia using LanguageServer.jl.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        julia_executable = self._setup_runtime_dependency()  # PASS LOGGER\n        julia_code = \"using LanguageServer; runserver()\"\n\n        julia_ls_cmd: str | list[str]\n        if platform.system() == \"Windows\":\n            # On Windows, pass as list (Serena handles shell=True differently)\n            julia_ls_cmd = [julia_executable, \"--startup-file=no\", \"--history-file=no\", \"-e\", julia_code, repository_root_path]\n        else:\n            # On Linux/macOS, build shell-escaped string\n            import shlex\n\n            julia_ls_cmd = (\n                f\"{shlex.quote(julia_executable)} \"\n                f\"--startup-file=no \"\n                f\"--history-file=no \"\n                f\"-e {shlex.quote(julia_code)} \"\n                f\"{shlex.quote(repository_root_path)}\"\n            )\n\n        log.info(f\"[JULIA DEBUG] Command: {julia_ls_cmd}\")\n\n        super().__init__(\n            config, repository_root_path, ProcessLaunchInfo(cmd=julia_ls_cmd, cwd=repository_root_path), \"julia\", solidlsp_settings\n        )\n\n    @staticmethod\n    def _setup_runtime_dependency() -> str:\n        \"\"\"\n        Check if the Julia runtime is available and return its full path.\n        Raises RuntimeError with a helpful message if the dependency is missing.\n        \"\"\"\n        # First check if julia is in PATH\n        julia_path = shutil.which(\"julia\")\n\n        # If not found in PATH, check common installation locations\n        if julia_path is None:\n            common_locations = [\n                os.path.expanduser(\"~/.juliaup/bin/julia\"),\n                os.path.expanduser(\"~/.julia/bin/julia\"),\n                \"/usr/local/bin/julia\",\n                \"/usr/bin/julia\",\n            ]\n\n            for location in common_locations:\n                if os.path.isfile(location) and os.access(location, os.X_OK):\n                    julia_path = location\n                    break\n\n        if julia_path is None:\n            raise RuntimeError(\n                \"Julia is not installed or not in your PATH. \"\n                \"Please install Julia from https://julialang.org/downloads/ and ensure it is accessible. \"\n                f\"Checked locations: {common_locations}\"\n            )\n\n        # Check if LanguageServer.jl is installed\n        check_cmd = [julia_path, \"-e\", \"using LanguageServer\"]\n        try:\n            result = subprocess.run(check_cmd, check=False, capture_output=True, text=True, timeout=10)\n            if result.returncode != 0:\n                # LanguageServer.jl not found, install it\n                JuliaLanguageServer._install_language_server(julia_path)\n        except subprocess.TimeoutExpired:\n            # Assume it needs installation\n            JuliaLanguageServer._install_language_server(julia_path)\n\n        return julia_path\n\n    @staticmethod\n    def _install_language_server(julia_path: str) -> None:\n        \"\"\"Install LanguageServer.jl package.\"\"\"\n        log.info(\"LanguageServer.jl not found. Installing... (this may take a minute)\")\n\n        install_cmd = [julia_path, \"-e\", 'using Pkg; Pkg.add(\"LanguageServer\")']\n\n        try:\n            result = subprocess.run(install_cmd, check=False, capture_output=True, text=True, timeout=300)  # 5 minutes for installation\n\n            if result.returncode == 0:\n                log.info(\"LanguageServer.jl installed successfully!\")\n            else:\n                raise RuntimeError(f\"Failed to install LanguageServer.jl: {result.stderr}\")\n        except subprocess.TimeoutExpired:\n            raise RuntimeError(\n                \"LanguageServer.jl installation timed out. Please install manually: julia -e 'using Pkg; Pkg.add(\\\"LanguageServer\\\")'\"\n            )\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        \"\"\"Define language-specific directories to ignore for Julia projects.\"\"\"\n        return super().is_ignored_dirname(dirname) or dirname in [\".julia\", \"build\", \"dist\"]\n\n    def _get_initialize_params(self, repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Julia Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params: InitializeParams = {  # type: ignore\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"capabilities\": {\n                \"workspace\": {\"workspaceFolders\": True},\n                \"textDocument\": {\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\"dynamicRegistration\": True},\n                },\n            },\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return initialize_params  # type: ignore\n\n    def _start_server(self) -> None:\n        \"\"\"Start the LanguageServer.jl server process.\"\"\"\n\n        def do_nothing(params: Any) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting LanguageServer.jl server process\")\n        self.server.start()\n\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n        log.info(\"Sending initialize request to Julia Language Server\")\n\n        init_response = self.server.send.initialize(initialize_params)\n        assert \"definitionProvider\" in init_response[\"capabilities\"]\n        assert \"referencesProvider\" in init_response[\"capabilities\"]\n        assert \"documentSymbolProvider\" in init_response[\"capabilities\"]\n\n        self.server.notify.initialized({})\n        log.info(\"Julia Language Server is initialized and ready.\")\n"
  },
  {
    "path": "src/solidlsp/language_servers/kotlin_language_server.py",
    "content": "\"\"\"\nProvides Kotlin specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Kotlin.\n\nYou can configure the following options in ls_specific_settings (in serena_config.yml):\n\n    ls_specific_settings:\n      kotlin:\n        ls_path: '/path/to/kotlin-lsp.sh'  # Custom path to Kotlin Language Server executable\n        kotlin_lsp_version: '261.13587.0'  # Kotlin Language Server version (default: current bundled version)\n        jvm_options: '-Xmx2G'  # JVM options for Kotlin Language Server (default: -Xmx2G)\n\nExample configuration for large projects:\n\n    ls_specific_settings:\n      kotlin:\n        jvm_options: '-Xmx4G -XX:+UseG1GC'\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport stat\nimport threading\nfrom typing import cast\n\nfrom overrides import override\n\nfrom solidlsp.ls import (\n    LanguageServerDependencyProvider,\n    LanguageServerDependencyProviderSinglePath,\n    SolidLanguageServer,\n)\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.ls_utils import FileUtils, PlatformUtils\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n# Default JVM options for Kotlin Language Server\n# -Xmx2G: 2GB heap is sufficient for most projects; override via ls_specific_settings for large codebases\nDEFAULT_KOTLIN_JVM_OPTIONS = \"-Xmx2G\"\n\n# Default Kotlin Language Server version (can be overridden via ls_specific_settings)\nDEFAULT_KOTLIN_LSP_VERSION = \"261.13587.0\"\n\n# Platform-specific Kotlin LSP download suffixes\nPLATFORM_KOTLIN_SUFFIX = {\n    \"win-x64\": \"win-x64\",\n    \"linux-x64\": \"linux-x64\",\n    \"linux-arm64\": \"linux-aarch64\",\n    \"osx-x64\": \"mac-x64\",\n    \"osx-arm64\": \"mac-aarch64\",\n}\n\n\nclass KotlinLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides Kotlin specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Kotlin.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a Kotlin Language Server instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(\n            config,\n            repository_root_path,\n            None,\n            \"kotlin\",\n            solidlsp_settings,\n        )\n\n        # Indexing synchronisation: starts SET (= already done), cleared if the server\n        # sends window/workDoneProgress/create (async-indexing servers like KLS v261+),\n        # set again once all progress tokens have ended.\n        self._indexing_complete = threading.Event()\n        self._indexing_complete.set()\n        self._active_progress_tokens: set[str] = set()\n        self._progress_lock = threading.Lock()\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def __init__(self, custom_settings: SolidLSPSettings.CustomLSSettings, ls_resources_dir: str):\n            super().__init__(custom_settings, ls_resources_dir)\n            self._java_home_path: str | None = None\n\n        def _get_or_install_core_dependency(self) -> str:\n            \"\"\"\n            Setup runtime dependencies for Kotlin Language Server and return the path to the executable script.\n            \"\"\"\n            platform_id = PlatformUtils.get_platform_id()\n\n            # Verify platform support\n            assert (\n                platform_id.value.startswith(\"win-\") or platform_id.value.startswith(\"linux-\") or platform_id.value.startswith(\"osx-\")\n            ), \"Only Windows, Linux and macOS platforms are supported for Kotlin in multilspy at the moment\"\n\n            kotlin_suffix = PLATFORM_KOTLIN_SUFFIX.get(platform_id.value)\n            assert kotlin_suffix, f\"Unsupported platform for Kotlin LSP: {platform_id.value}\"\n\n            # Setup paths for dependencies\n            static_dir = os.path.join(self._ls_resources_dir, \"kotlin_language_server\")\n            os.makedirs(static_dir, exist_ok=True)\n\n            # Setup Kotlin Language Server\n            kotlin_script_name = \"kotlin-lsp.cmd\" if platform_id.value.startswith(\"win-\") else \"kotlin-lsp.sh\"\n            kotlin_script = os.path.join(static_dir, kotlin_script_name)\n\n            if not os.path.exists(kotlin_script):\n                kotlin_lsp_version = self._custom_settings.get(\"kotlin_lsp_version\", DEFAULT_KOTLIN_LSP_VERSION)\n                kotlin_url = f\"https://download-cdn.jetbrains.com/kotlin-lsp/{kotlin_lsp_version}/kotlin-lsp-{kotlin_lsp_version}-{kotlin_suffix}.zip\"\n                log.info(\"Downloading Kotlin Language Server...\")\n                FileUtils.download_and_extract_archive(kotlin_url, static_dir, \"zip\")\n\n                if os.path.exists(kotlin_script) and not platform_id.value.startswith(\"win-\"):\n                    os.chmod(\n                        kotlin_script,\n                        stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH,\n                    )\n\n            if not os.path.exists(kotlin_script):\n                raise FileNotFoundError(f\"Kotlin Language Server script not found at {kotlin_script}\")\n\n            log.info(f\"Using Kotlin Language Server script at {kotlin_script}\")\n            return kotlin_script\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [core_path, \"--stdio\"]\n\n        def create_launch_command_env(self) -> dict[str, str]:\n            \"\"\"Provides JAVA_HOME and JVM options for the Kotlin Language Server process.\"\"\"\n            env: dict[str, str] = {}\n\n            if self._java_home_path is not None:\n                env[\"JAVA_HOME\"] = self._java_home_path\n\n            # Get JVM options from settings or use default\n            # Note: an explicit empty string means \"no JVM options\", which is distinct from not setting the key\n            _sentinel = object()\n            custom_jvm_options = self._custom_settings.get(\"jvm_options\", _sentinel)\n            if custom_jvm_options is not _sentinel:\n                jvm_options = custom_jvm_options\n            else:\n                jvm_options = DEFAULT_KOTLIN_JVM_OPTIONS\n\n            env[\"JAVA_TOOL_OPTIONS\"] = jvm_options\n            return env\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Kotlin Language Server.\n        \"\"\"\n        if not os.path.isabs(repository_absolute_path):\n            repository_absolute_path = os.path.abspath(repository_absolute_path)\n\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"clientInfo\": {\"name\": \"Multilspy Kotlin Client\", \"version\": \"1.0.0\"},\n            \"locale\": \"en\",\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"capabilities\": {\n                \"workspace\": {\n                    \"applyEdit\": True,\n                    \"workspaceEdit\": {\n                        \"documentChanges\": True,\n                        \"resourceOperations\": [\"create\", \"rename\", \"delete\"],\n                        \"failureHandling\": \"textOnlyTransactional\",\n                        \"normalizesLineEndings\": True,\n                        \"changeAnnotationSupport\": {\"groupsOnLabel\": True},\n                    },\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"didChangeWatchedFiles\": {\"dynamicRegistration\": True, \"relativePatternSupport\": True},\n                    \"symbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                        \"tagSupport\": {\"valueSet\": [1]},\n                        \"resolveSupport\": {\"properties\": [\"location.range\"]},\n                    },\n                    \"codeLens\": {\"refreshSupport\": True},\n                    \"executeCommand\": {\"dynamicRegistration\": True},\n                    \"configuration\": True,\n                    \"workspaceFolders\": True,\n                    \"semanticTokens\": {\"refreshSupport\": True},\n                    \"fileOperations\": {\n                        \"dynamicRegistration\": True,\n                        \"didCreate\": True,\n                        \"didRename\": True,\n                        \"didDelete\": True,\n                        \"willCreate\": True,\n                        \"willRename\": True,\n                        \"willDelete\": True,\n                    },\n                    \"inlineValue\": {\"refreshSupport\": True},\n                    \"inlayHint\": {\"refreshSupport\": True},\n                    \"diagnostics\": {\"refreshSupport\": True},\n                },\n                \"textDocument\": {\n                    \"publishDiagnostics\": {\n                        \"relatedInformation\": True,\n                        \"versionSupport\": False,\n                        \"tagSupport\": {\"valueSet\": [1, 2]},\n                        \"codeDescriptionSupport\": True,\n                        \"dataSupport\": True,\n                    },\n                    \"synchronization\": {\"dynamicRegistration\": True, \"willSave\": True, \"willSaveWaitUntil\": True, \"didSave\": True},\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"contextSupport\": True,\n                        \"completionItem\": {\n                            \"snippetSupport\": False,\n                            \"commitCharactersSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"deprecatedSupport\": True,\n                            \"preselectSupport\": True,\n                            \"tagSupport\": {\"valueSet\": [1]},\n                            \"insertReplaceSupport\": False,\n                            \"resolveSupport\": {\"properties\": [\"documentation\", \"detail\", \"additionalTextEdits\"]},\n                            \"insertTextModeSupport\": {\"valueSet\": [1, 2]},\n                            \"labelDetailsSupport\": True,\n                        },\n                        \"insertTextMode\": 2,\n                        \"completionItemKind\": {\n                            \"valueSet\": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]\n                        },\n                        \"completionList\": {\"itemDefaults\": [\"commitCharacters\", \"editRange\", \"insertTextFormat\", \"insertTextMode\"]},\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"signatureHelp\": {\n                        \"dynamicRegistration\": True,\n                        \"signatureInformation\": {\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"parameterInformation\": {\"labelOffsetSupport\": True},\n                            \"activeParameterSupport\": True,\n                        },\n                        \"contextSupport\": True,\n                    },\n                    \"definition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentHighlight\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"tagSupport\": {\"valueSet\": [1]},\n                        \"labelSupport\": True,\n                    },\n                    \"codeAction\": {\n                        \"dynamicRegistration\": True,\n                        \"isPreferredSupport\": True,\n                        \"disabledSupport\": True,\n                        \"dataSupport\": True,\n                        \"resolveSupport\": {\"properties\": [\"edit\"]},\n                        \"codeActionLiteralSupport\": {\n                            \"codeActionKind\": {\n                                \"valueSet\": [\n                                    \"\",\n                                    \"quickfix\",\n                                    \"refactor\",\n                                    \"refactor.extract\",\n                                    \"refactor.inline\",\n                                    \"refactor.rewrite\",\n                                    \"source\",\n                                    \"source.organizeImports\",\n                                ]\n                            }\n                        },\n                        \"honorsChangeAnnotations\": False,\n                    },\n                    \"codeLens\": {\"dynamicRegistration\": True},\n                    \"formatting\": {\"dynamicRegistration\": True},\n                    \"rangeFormatting\": {\"dynamicRegistration\": True},\n                    \"onTypeFormatting\": {\"dynamicRegistration\": True},\n                    \"rename\": {\n                        \"dynamicRegistration\": True,\n                        \"prepareSupport\": True,\n                        \"prepareSupportDefaultBehavior\": 1,\n                        \"honorsChangeAnnotations\": True,\n                    },\n                    \"documentLink\": {\"dynamicRegistration\": True, \"tooltipSupport\": True},\n                    \"typeDefinition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"implementation\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"colorProvider\": {\"dynamicRegistration\": True},\n                    \"foldingRange\": {\n                        \"dynamicRegistration\": True,\n                        \"rangeLimit\": 5000,\n                        \"lineFoldingOnly\": True,\n                        \"foldingRangeKind\": {\"valueSet\": [\"comment\", \"imports\", \"region\"]},\n                        \"foldingRange\": {\"collapsedText\": False},\n                    },\n                    \"declaration\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"selectionRange\": {\"dynamicRegistration\": True},\n                    \"callHierarchy\": {\"dynamicRegistration\": True},\n                    \"semanticTokens\": {\n                        \"dynamicRegistration\": True,\n                        \"tokenTypes\": [\n                            \"namespace\",\n                            \"type\",\n                            \"class\",\n                            \"enum\",\n                            \"interface\",\n                            \"struct\",\n                            \"typeParameter\",\n                            \"parameter\",\n                            \"variable\",\n                            \"property\",\n                            \"enumMember\",\n                            \"event\",\n                            \"function\",\n                            \"method\",\n                            \"macro\",\n                            \"keyword\",\n                            \"modifier\",\n                            \"comment\",\n                            \"string\",\n                            \"number\",\n                            \"regexp\",\n                            \"operator\",\n                            \"decorator\",\n                        ],\n                        \"tokenModifiers\": [\n                            \"declaration\",\n                            \"definition\",\n                            \"readonly\",\n                            \"static\",\n                            \"deprecated\",\n                            \"abstract\",\n                            \"async\",\n                            \"modification\",\n                            \"documentation\",\n                            \"defaultLibrary\",\n                        ],\n                        \"formats\": [\"relative\"],\n                        \"requests\": {\"range\": True, \"full\": {\"delta\": True}},\n                        \"multilineTokenSupport\": False,\n                        \"overlappingTokenSupport\": False,\n                        \"serverCancelSupport\": True,\n                        \"augmentsSyntaxTokens\": True,\n                    },\n                    \"linkedEditingRange\": {\"dynamicRegistration\": True},\n                    \"typeHierarchy\": {\"dynamicRegistration\": True},\n                    \"inlineValue\": {\"dynamicRegistration\": True},\n                    \"inlayHint\": {\n                        \"dynamicRegistration\": True,\n                        \"resolveSupport\": {\"properties\": [\"tooltip\", \"textEdits\", \"label.tooltip\", \"label.location\", \"label.command\"]},\n                    },\n                    \"diagnostic\": {\"dynamicRegistration\": True, \"relatedDocumentSupport\": False},\n                },\n                \"window\": {\n                    \"showMessage\": {\"messageActionItem\": {\"additionalPropertiesSupport\": True}},\n                    \"showDocument\": {\"support\": True},\n                    \"workDoneProgress\": True,\n                },\n                \"general\": {\n                    \"staleRequestSupport\": {\n                        \"cancel\": True,\n                        \"retryOnContentModified\": [\n                            \"textDocument/semanticTokens/full\",\n                            \"textDocument/semanticTokens/range\",\n                            \"textDocument/semanticTokens/full/delta\",\n                        ],\n                    },\n                    \"regularExpressions\": {\"engine\": \"ECMAScript\", \"version\": \"ES2020\"},\n                    \"markdown\": {\"parser\": \"marked\", \"version\": \"1.1.0\"},\n                    \"positionEncodings\": [\"utf-16\"],\n                },\n                \"notebookDocument\": {\"synchronization\": {\"dynamicRegistration\": True, \"executionSummarySupport\": True}},\n            },\n            \"initializationOptions\": {\n                \"workspaceFolders\": [root_uri],\n                \"storagePath\": None,\n                \"codegen\": {\"enabled\": False},\n                \"compiler\": {\"jvm\": {\"target\": \"default\"}},\n                \"completion\": {\"snippets\": {\"enabled\": True}},\n                \"diagnostics\": {\"enabled\": True, \"level\": 4, \"debounceTime\": 250},\n                \"scripts\": {\"enabled\": True, \"buildScriptsEnabled\": True},\n                \"indexing\": {\"enabled\": True},\n                \"externalSources\": {\"useKlsScheme\": False, \"autoConvertToKotlin\": False},\n                \"inlayHints\": {\"typeHints\": False, \"parameterHints\": False, \"chainedHints\": False},\n                \"formatting\": {\n                    \"formatter\": \"ktfmt\",\n                    \"ktfmt\": {\n                        \"style\": \"google\",\n                        \"indent\": 4,\n                        \"maxWidth\": 100,\n                        \"continuationIndent\": 8,\n                        \"removeUnusedImports\": True,\n                    },\n                },\n            },\n            \"trace\": \"off\",\n            \"processId\": os.getpid(),\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return cast(InitializeParams, initialize_params)\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the Kotlin Language Server\n        \"\"\"\n\n        def execute_client_command_handler(params: dict) -> list:\n            return []\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def work_done_progress_create(params: dict) -> dict:\n            \"\"\"Handle window/workDoneProgress/create: the server is about to report async progress.\n            Clear the indexing-complete event so _start_server waits until all tokens finish.\n            This is triggered by newer KLS versions (261+) that index asynchronously after initialized.\n            Older versions (0.253.x) never send this, so _indexing_complete stays set and wait() returns instantly.\n            \"\"\"\n            token = str(params.get(\"token\", \"\"))\n            log.debug(f\"Kotlin LSP workDoneProgress/create: token={token!r}\")\n            with self._progress_lock:\n                self._active_progress_tokens.add(token)\n                self._indexing_complete.clear()\n            return {}\n\n        def progress_handler(params: dict) -> None:\n            \"\"\"Track $/progress begin/end to detect when all async indexing work finishes.\"\"\"\n            token = str(params.get(\"token\", \"\"))\n            value = params.get(\"value\", {})\n            kind = value.get(\"kind\")\n            if kind == \"begin\":\n                title = value.get(\"title\", \"\")\n                log.info(f\"Kotlin LSP progress [{token}]: started - {title}\")\n                with self._progress_lock:\n                    self._active_progress_tokens.add(token)\n                    self._indexing_complete.clear()\n            elif kind == \"report\":\n                pct = value.get(\"percentage\")\n                msg = value.get(\"message\", \"\")\n                pct_str = f\" ({pct}%)\" if pct is not None else \"\"\n                log.debug(f\"Kotlin LSP progress [{token}]: {msg}{pct_str}\")\n            elif kind == \"end\":\n                msg = value.get(\"message\", \"\")\n                log.info(f\"Kotlin LSP progress [{token}]: ended - {msg}\")\n                with self._progress_lock:\n                    self._active_progress_tokens.discard(token)\n                    if not self._active_progress_tokens:\n                        self._indexing_complete.set()\n\n        self.server.on_request(\"client/registerCapability\", do_nothing)\n        self.server.on_notification(\"language/status\", do_nothing)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_request(\"workspace/executeClientCommand\", execute_client_command_handler)\n        self.server.on_request(\"window/workDoneProgress/create\", work_done_progress_create)\n        self.server.on_notification(\"$/progress\", progress_handler)\n        self.server.on_notification(\"$/logTrace\", do_nothing)\n        self.server.on_notification(\"$/cancelRequest\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"language/actionableNotification\", do_nothing)\n\n        log.info(\"Starting Kotlin server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        capabilities = init_response[\"capabilities\"]\n        assert \"textDocumentSync\" in capabilities, \"Server must support textDocumentSync\"\n        assert \"hoverProvider\" in capabilities, \"Server must support hover\"\n        assert \"completionProvider\" in capabilities, \"Server must support code completion\"\n        assert \"signatureHelpProvider\" in capabilities, \"Server must support signature help\"\n        assert \"definitionProvider\" in capabilities, \"Server must support go to definition\"\n        assert \"referencesProvider\" in capabilities, \"Server must support find references\"\n        assert \"documentSymbolProvider\" in capabilities, \"Server must support document symbols\"\n        assert \"workspaceSymbolProvider\" in capabilities, \"Server must support workspace symbols\"\n        assert \"semanticTokensProvider\" in capabilities, \"Server must support semantic tokens\"\n\n        self.server.notify.initialized({})\n\n        # Wait for any async indexing to complete.\n        # - Older KLS (0.253.x): indexing is synchronous inside `initialize`, no $/progress is sent,\n        #   _indexing_complete stays SET -> wait() returns immediately.\n        # - Newer KLS (261+): server sends window/workDoneProgress/create after initialized,\n        #   which clears the event; wait() blocks until all progress tokens end.\n        _INDEXING_TIMEOUT = 120.0\n        log.info(\"Waiting for Kotlin LSP indexing to complete (if async)...\")\n        if self._indexing_complete.wait(timeout=_INDEXING_TIMEOUT):\n            log.info(\"Kotlin LSP ready\")\n        else:\n            log.warning(\"Kotlin LSP did not signal indexing completion within %.0fs; proceeding anyway\", _INDEXING_TIMEOUT)\n\n    @override\n    def _get_wait_time_for_cross_file_referencing(self) -> float:\n        \"\"\"Small safety buffer since we already waited for indexing to complete in _start_server.\"\"\"\n        return 1.0\n"
  },
  {
    "path": "src/solidlsp/language_servers/lean4_language_server.py",
    "content": "\"\"\"\nProvides Lean 4 specific instantiation of the LanguageServer class.\nUses the built-in Lean 4 language server (lean --server).\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport shutil\nimport subprocess\nfrom typing import cast\n\nfrom overrides import override\n\nfrom solidlsp.ls import LanguageServerDependencyProvider, LanguageServerDependencyProviderSinglePath, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass Lean4LanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides Lean 4 specific instantiation of the LanguageServer class.\n    Uses the built-in Lean 4 language server invoked via ``lean --server``.\n    Requires ``lean`` to be installed and available on PATH (typically via elan).\n    \"\"\"\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def __init__(self, custom_settings: SolidLSPSettings.CustomLSSettings, ls_resources_dir: str, repository_root_path: str):\n            super().__init__(custom_settings, ls_resources_dir)\n            self._repository_root_path = repository_root_path\n\n        def _get_or_install_core_dependency(self) -> str:\n            lean_path = shutil.which(\"lean\")\n            if lean_path is None:\n                raise RuntimeError(\n                    \"lean is not installed or not in PATH.\\n\"\n                    \"Please install Lean 4 via elan: https://github.com/leanprover/elan\\n\"\n                    \"  curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh\\n\"\n                    \"After installation, make sure 'lean' is available on your PATH.\"\n                )\n            return lean_path\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [core_path, \"--server\"]\n\n        @override\n        def create_launch_command_env(self) -> dict[str, str]:\n            \"\"\"Provides LEAN_PATH and LEAN_SRC_PATH from ``lake env`` for cross-file references.\"\"\"\n            env: dict[str, str] = {}\n            lake_path = shutil.which(\"lake\")\n            if lake_path is None:\n                log.warning(\"lake not found on PATH; cross-file references may not work\")\n                return env\n            try:\n                result = subprocess.run(\n                    [lake_path, \"env\"],\n                    check=False,\n                    cwd=self._repository_root_path,\n                    capture_output=True,\n                    text=True,\n                    timeout=30,\n                )\n                if result.returncode == 0:\n                    for line in result.stdout.splitlines():\n                        if \"=\" in line:\n                            key, _, value = line.partition(\"=\")\n                            if key in (\"LEAN_PATH\", \"LEAN_SRC_PATH\"):\n                                env[key] = value\n                                log.info(f\"Lake env: {key}={value}\")\n                else:\n                    log.warning(f\"lake env failed (exit {result.returncode}): {result.stderr[:200]}\")\n            except Exception as e:\n                log.warning(f\"Failed to run lake env: {e}\")\n            return env\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a Lean4LanguageServer instance. This class is not meant to be\n        instantiated directly. Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(\n            config,\n            repository_root_path,\n            None,\n            \"lean4\",\n            solidlsp_settings,\n        )\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir, self.repository_root_path)\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\".lake\", \"build\"]\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Lean 4 Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"definition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"completionItem\": {\n                            \"snippetSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                        },\n                    },\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                },\n            },\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return cast(InitializeParams, initialize_params)\n\n    def _start_server(self) -> None:\n        \"\"\"Start the Lean 4 language server process.\"\"\"\n\n        def register_capability_handler(_params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def do_nothing(_params: dict) -> None:\n            return\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"$/lean/fileProgress\", do_nothing)\n\n        log.info(\"Starting Lean 4 language server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        capabilities = init_response.get(\"capabilities\", {})\n        log.info(f\"Lean 4 LSP capabilities: {list(capabilities.keys())}\")\n\n        self.server.notify.initialized({})\n\n    @override\n    def _get_wait_time_for_cross_file_referencing(self) -> float:\n        \"\"\"Lean 4 projects need time to compile and build cross-file references.\"\"\"\n        return 10.0\n"
  },
  {
    "path": "src/solidlsp/language_servers/lua_ls.py",
    "content": "\"\"\"\nProvides Lua specific instantiation of the LanguageServer class using lua-language-server.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport platform\nimport shutil\nimport tarfile\nimport zipfile\nfrom pathlib import Path\n\nimport requests\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass LuaLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides Lua specific instantiation of the LanguageServer class using lua-language-server.\n    \"\"\"\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        # For Lua projects, we should ignore:\n        # - .luarocks: package manager cache\n        # - lua_modules: local dependencies\n        # - node_modules: if the project has JavaScript components\n        return super().is_ignored_dirname(dirname) or dirname in [\".luarocks\", \"lua_modules\", \"node_modules\", \"build\", \"dist\", \".cache\"]\n\n    @staticmethod\n    def _get_lua_ls_path() -> str | None:\n        \"\"\"Get the path to lua-language-server executable.\"\"\"\n        # First check if it's in PATH\n        lua_ls = shutil.which(\"lua-language-server\")\n        if lua_ls:\n            return lua_ls\n\n        # Check common installation locations\n        home = Path.home()\n        possible_paths = [\n            home / \".local\" / \"bin\" / \"lua-language-server\",\n            home / \".serena\" / \"language_servers\" / \"lua\" / \"bin\" / \"lua-language-server\",\n            Path(\"/usr/local/bin/lua-language-server\"),\n            Path(\"/opt/lua-language-server/bin/lua-language-server\"),\n        ]\n\n        # Add Windows-specific paths\n        if platform.system() == \"Windows\":\n            possible_paths.extend(\n                [\n                    home / \"AppData\" / \"Local\" / \"lua-language-server\" / \"bin\" / \"lua-language-server.exe\",\n                    home / \".serena\" / \"language_servers\" / \"lua\" / \"bin\" / \"lua-language-server.exe\",\n                ]\n            )\n\n        for path in possible_paths:\n            if path.exists():\n                return str(path)\n\n        return None\n\n    @staticmethod\n    def _download_lua_ls() -> str:\n        \"\"\"Download and install lua-language-server if not present.\"\"\"\n        system = platform.system()\n        machine = platform.machine().lower()\n        lua_ls_version = \"3.15.0\"\n\n        # Map platform and architecture to download URL\n        if system == \"Linux\":\n            if machine in [\"x86_64\", \"amd64\"]:\n                download_name = f\"lua-language-server-{lua_ls_version}-linux-x64.tar.gz\"\n            elif machine in [\"aarch64\", \"arm64\"]:\n                download_name = f\"lua-language-server-{lua_ls_version}-linux-arm64.tar.gz\"\n            else:\n                raise RuntimeError(f\"Unsupported Linux architecture: {machine}\")\n        elif system == \"Darwin\":\n            if machine in [\"x86_64\", \"amd64\"]:\n                download_name = f\"lua-language-server-{lua_ls_version}-darwin-x64.tar.gz\"\n            elif machine in [\"arm64\", \"aarch64\"]:\n                download_name = f\"lua-language-server-{lua_ls_version}-darwin-arm64.tar.gz\"\n            else:\n                raise RuntimeError(f\"Unsupported macOS architecture: {machine}\")\n        elif system == \"Windows\":\n            if machine in [\"amd64\", \"x86_64\"]:\n                download_name = f\"lua-language-server-{lua_ls_version}-win32-x64.zip\"\n            else:\n                raise RuntimeError(f\"Unsupported Windows architecture: {machine}\")\n        else:\n            raise RuntimeError(f\"Unsupported operating system: {system}\")\n\n        download_url = f\"https://github.com/LuaLS/lua-language-server/releases/download/{lua_ls_version}/{download_name}\"\n\n        # Create installation directory\n        install_dir = Path.home() / \".serena\" / \"language_servers\" / \"lua\"\n        install_dir.mkdir(parents=True, exist_ok=True)\n\n        # Download the file\n        print(f\"Downloading lua-language-server from {download_url}...\")\n        response = requests.get(download_url, stream=True)\n        response.raise_for_status()\n\n        # Save and extract\n        download_path = install_dir / download_name\n        with open(download_path, \"wb\") as f:\n            for chunk in response.iter_content(chunk_size=8192):\n                f.write(chunk)\n\n        print(f\"Extracting lua-language-server to {install_dir}...\")\n        if download_name.endswith(\".tar.gz\"):\n            with tarfile.open(download_path, \"r:gz\") as tar:\n                tar.extractall(install_dir)\n        elif download_name.endswith(\".zip\"):\n            with zipfile.ZipFile(download_path, \"r\") as zip_ref:\n                zip_ref.extractall(install_dir)\n\n        # Clean up download file\n        download_path.unlink()\n\n        # Make executable on Unix systems\n        if system != \"Windows\":\n            lua_ls_path = install_dir / \"bin\" / \"lua-language-server\"\n            if lua_ls_path.exists():\n                lua_ls_path.chmod(0o755)\n                return str(lua_ls_path)\n        else:\n            lua_ls_path = install_dir / \"bin\" / \"lua-language-server.exe\"\n            if lua_ls_path.exists():\n                return str(lua_ls_path)\n\n        raise RuntimeError(\"Failed to find lua-language-server executable after extraction\")\n\n    @staticmethod\n    def _setup_runtime_dependency() -> str:\n        \"\"\"\n        Check if required Lua runtime dependencies are available.\n        Downloads lua-language-server if not present.\n        \"\"\"\n        lua_ls_path = LuaLanguageServer._get_lua_ls_path()\n\n        if not lua_ls_path:\n            print(\"lua-language-server not found. Downloading...\")\n            lua_ls_path = LuaLanguageServer._download_lua_ls()\n            print(f\"lua-language-server installed at: {lua_ls_path}\")\n\n        return lua_ls_path\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        lua_ls_path = self._setup_runtime_dependency()\n\n        super().__init__(\n            config, repository_root_path, ProcessLaunchInfo(cmd=lua_ls_path, cwd=repository_root_path), \"lua\", solidlsp_settings\n        )\n        self.request_id = 0\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Lua Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"completionItem\": {\n                            \"snippetSupport\": True,\n                            \"commitCharactersSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"deprecatedSupport\": True,\n                            \"preselectSupport\": True,\n                        },\n                    },\n                    \"hover\": {\n                        \"dynamicRegistration\": True,\n                        \"contentFormat\": [\"markdown\", \"plaintext\"],\n                    },\n                    \"signatureHelp\": {\n                        \"dynamicRegistration\": True,\n                        \"signatureInformation\": {\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"parameterInformation\": {\"labelOffsetSupport\": True},\n                        },\n                    },\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"configuration\": True,\n                    \"symbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                },\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n            \"initializationOptions\": {\n                # Lua Language Server specific options\n                \"runtime\": {\n                    \"version\": \"Lua 5.4\",\n                    \"path\": [\"?.lua\", \"?/init.lua\"],\n                },\n                \"diagnostics\": {\n                    \"enable\": True,\n                    \"globals\": [\"vim\", \"describe\", \"it\", \"before_each\", \"after_each\"],  # Common globals\n                },\n                \"workspace\": {\n                    \"library\": [],  # Can be extended with project-specific libraries\n                    \"checkThirdParty\": False,\n                    \"userThirdParty\": [],\n                },\n                \"telemetry\": {\n                    \"enable\": False,\n                },\n                \"completion\": {\n                    \"enable\": True,\n                    \"callSnippet\": \"Both\",\n                    \"keywordSnippet\": \"Both\",\n                },\n            },\n        }\n        return initialize_params  # type: ignore[return-value]\n\n    def _start_server(self) -> None:\n        \"\"\"Start Lua Language Server process\"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting Lua Language Server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        # Verify server capabilities\n        assert \"textDocumentSync\" in init_response[\"capabilities\"]\n        assert \"definitionProvider\" in init_response[\"capabilities\"]\n        assert \"documentSymbolProvider\" in init_response[\"capabilities\"]\n        assert \"referencesProvider\" in init_response[\"capabilities\"]\n\n        self.server.notify.initialized({})\n\n        # Lua Language Server is typically ready immediately after initialization\n        # (no need to wait for events)\n"
  },
  {
    "path": "src/solidlsp/language_servers/luau_lsp.py",
    "content": "\"\"\"\nProvides Luau specific instantiation of the LanguageServer class using luau-lsp.\n\nLuau is the programming language used by Roblox, derived from Lua 5.1 with\nadditional features like type annotations, string interpolation, and more.\nThis uses JohnnyMorganz/luau-lsp as the language server backend.\n\nRequirements:\n    - luau-lsp binary must be installed and available in PATH,\n      or it will be automatically downloaded from GitHub releases.\n\nAdvanced settings via ls_specific_settings[\"luau\"]:\n    - platform: \"roblox\" (default) or \"standard\"\n    - roblox_security_level: \"None\", \"PluginSecurity\" (default),\n      \"LocalUserSecurity\", or \"RobloxScriptSecurity\"\n\nSee: https://github.com/JohnnyMorganz/luau-lsp\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport platform\nimport shutil\nimport threading\nimport zipfile\nfrom pathlib import Path\n\nimport requests\nfrom overrides import override\n\nfrom solidlsp.ls import LanguageServerDependencyProvider, LanguageServerDependencyProviderSinglePath, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n# Pin to a known stable release\nLUAU_LSP_VERSION = \"1.63.0\"\n\n# Luau built-in docs CDN\nLUAU_DOCS_URL = \"https://luau-lsp.pages.dev/api-docs/luau-en-us.json\"\n\n# Roblox type definitions and API docs CDN\nROBLOX_DOCS_URL = \"https://luau-lsp.pages.dev/api-docs/en-us.json\"\nSUPPORTED_PLATFORMS = {\"roblox\", \"standard\"}\nSUPPORTED_ROBLOX_SECURITY_LEVELS = {\n    \"None\",\n    \"PluginSecurity\",\n    \"LocalUserSecurity\",\n    \"RobloxScriptSecurity\",\n}\n\n\nclass LuauLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides Luau specific instantiation of the LanguageServer class using luau-lsp.\n    Luau is the programming language used by Roblox (a typed superset of Lua 5.1).\n    \"\"\"\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\n            \"node_modules\",\n            \"Packages\",  # Wally packages\n            \"DevPackages\",  # Wally dev packages\n            \"roblox_packages\",  # Some Rojo projects\n            \"build\",\n            \"dist\",\n            \".cache\",\n        ]\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def _get_or_install_core_dependency(self) -> str:\n            luau_lsp_path = shutil.which(\"luau-lsp\")\n            if luau_lsp_path is not None:\n                return luau_lsp_path\n            return self._download_luau_lsp()\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            definitions_path, docs_path = self._resolve_support_files()\n\n            cmd = [core_path, \"lsp\"]\n            if definitions_path is not None:\n                cmd.append(f\"--definitions:@roblox={definitions_path}\")\n            if docs_path is not None:\n                cmd.append(f\"--docs={docs_path}\")\n            return cmd\n\n        def _download_luau_lsp(self) -> str:\n            install_dir = Path(self._ls_resources_dir)\n            install_dir.mkdir(parents=True, exist_ok=True)\n\n            binary_path = self._find_existing_binary(install_dir)\n            if binary_path is not None:\n                return binary_path\n\n            asset_name = self._get_luau_lsp_asset_name()\n            download_url = f\"https://github.com/JohnnyMorganz/luau-lsp/releases/download/{LUAU_LSP_VERSION}/{asset_name}\"\n            download_path = install_dir / asset_name\n\n            log.info(\"Downloading luau-lsp %s from %s\", LUAU_LSP_VERSION, download_url)\n            with requests.get(download_url, stream=True, timeout=60) as response:\n                response.raise_for_status()\n                with open(download_path, \"wb\") as f:\n                    for chunk in response.iter_content(chunk_size=8192):\n                        if chunk:\n                            f.write(chunk)\n\n            log.info(\"Extracting luau-lsp to %s\", install_dir)\n            with zipfile.ZipFile(download_path, \"r\") as zip_ref:\n                zip_ref.extractall(install_dir)\n\n            if download_path.exists():\n                download_path.unlink()\n\n            binary_path = self._find_existing_binary(install_dir)\n            if binary_path is None:\n                raise RuntimeError(\"Failed to find luau-lsp executable after extraction\")\n\n            return binary_path\n\n        def _resolve_support_files(self) -> tuple[str | None, str | None]:\n            platform_type = LuauLanguageServer._get_platform_type(self._custom_settings)\n            if platform_type == \"standard\":\n                return None, self._download_standard_docs()\n\n            security_level = LuauLanguageServer._get_roblox_security_level(self._custom_settings)\n            return self._download_roblox_support_files(security_level)\n\n        def _download_standard_docs(self) -> str | None:\n            install_dir = Path(self._ls_resources_dir)\n            install_dir.mkdir(parents=True, exist_ok=True)\n\n            return self._download_auxiliary_file(\n                install_dir / \"luau-en-us.json\",\n                LUAU_DOCS_URL,\n                \"Luau API docs\",\n            )\n\n        def _download_roblox_support_files(self, security_level: str) -> tuple[str | None, str | None]:\n            install_dir = Path(self._ls_resources_dir)\n            install_dir.mkdir(parents=True, exist_ok=True)\n\n            definitions_filename = f\"globalTypes.{security_level}.d.luau\"\n            definitions_path = self._download_auxiliary_file(\n                install_dir / definitions_filename,\n                f\"https://luau-lsp.pages.dev/type-definitions/{definitions_filename}\",\n                \"Roblox type definitions\",\n            )\n            docs_path = self._download_auxiliary_file(\n                install_dir / \"en-us.json\",\n                ROBLOX_DOCS_URL,\n                \"Roblox API docs\",\n            )\n\n            return definitions_path, docs_path\n\n        @staticmethod\n        def _download_auxiliary_file(path: Path, url: str, description: str) -> str | None:\n            if path.exists():\n                return str(path)\n\n            try:\n                log.info(\"Downloading %s from %s\", description, url)\n                response = requests.get(url, timeout=30)\n                response.raise_for_status()\n                path.write_bytes(response.content)\n                return str(path)\n            except Exception as exc:\n                log.warning(\"Failed to download %s: %s\", description, exc)\n                return None\n\n        @classmethod\n        def _find_existing_binary(cls, install_dir: Path) -> str | None:\n            binary_name = cls._get_binary_name()\n            direct_path = install_dir / binary_name\n            if direct_path.exists():\n                cls._ensure_executable_bit(direct_path)\n                return str(direct_path)\n\n            for candidate in install_dir.rglob(binary_name):\n                if candidate.is_file():\n                    cls._ensure_executable_bit(candidate)\n                    return str(candidate)\n\n            return None\n\n        @staticmethod\n        def _ensure_executable_bit(binary_path: Path) -> None:\n            if platform.system() != \"Windows\":\n                binary_path.chmod(0o755)\n\n        @staticmethod\n        def _get_binary_name() -> str:\n            return \"luau-lsp.exe\" if platform.system() == \"Windows\" else \"luau-lsp\"\n\n        @staticmethod\n        def _get_luau_lsp_asset_name() -> str:\n            system = platform.system()\n            machine = platform.machine().lower()\n\n            if system == \"Linux\":\n                if machine in [\"x86_64\", \"amd64\"]:\n                    return \"luau-lsp-linux-x86_64.zip\"\n                if machine in [\"aarch64\", \"arm64\"]:\n                    return \"luau-lsp-linux-arm64.zip\"\n                raise RuntimeError(\n                    f\"Unsupported Linux architecture: {machine}. \"\n                    \"luau-lsp only provides linux-x86_64 and linux-arm64 binaries. \"\n                    \"Please build from source: https://github.com/JohnnyMorganz/luau-lsp\"\n                )\n            if system == \"Darwin\":\n                return \"luau-lsp-macos.zip\"\n            if system == \"Windows\":\n                return \"luau-lsp-win64.zip\"\n            raise RuntimeError(f\"Unsupported operating system: {system}\")\n\n    @staticmethod\n    def _get_platform_type(custom_settings: SolidLSPSettings.CustomLSSettings) -> str:\n        platform_type = custom_settings.get(\"platform\", \"roblox\")\n        if platform_type not in SUPPORTED_PLATFORMS:\n            raise ValueError(f\"Unsupported Luau platform: {platform_type}. Expected one of: {', '.join(sorted(SUPPORTED_PLATFORMS))}\")\n        return platform_type\n\n    @staticmethod\n    def _get_roblox_security_level(custom_settings: SolidLSPSettings.CustomLSSettings) -> str:\n        security_level = custom_settings.get(\"roblox_security_level\", \"PluginSecurity\")\n        if security_level not in SUPPORTED_ROBLOX_SECURITY_LEVELS:\n            raise ValueError(\n                f\"Unsupported Luau Roblox security level: {security_level}. \"\n                f\"Expected one of: {', '.join(sorted(SUPPORTED_ROBLOX_SECURITY_LEVELS))}\"\n            )\n        return security_level\n\n    @classmethod\n    def _get_workspace_configuration(cls, custom_settings: SolidLSPSettings.CustomLSSettings) -> dict[str, dict[str, str]]:\n        return {\"platform\": {\"type\": cls._get_platform_type(custom_settings)}}\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        super().__init__(config, repository_root_path, None, \"luau\", solidlsp_settings)\n        self.server_ready = threading.Event()\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Luau Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"completionItem\": {\n                            \"snippetSupport\": True,\n                            \"commitCharactersSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"deprecatedSupport\": True,\n                            \"preselectSupport\": True,\n                        },\n                    },\n                    \"hover\": {\n                        \"dynamicRegistration\": True,\n                        \"contentFormat\": [\"markdown\", \"plaintext\"],\n                    },\n                    \"signatureHelp\": {\n                        \"dynamicRegistration\": True,\n                        \"signatureInformation\": {\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"parameterInformation\": {\"labelOffsetSupport\": True},\n                        },\n                    },\n                    \"rename\": {\"dynamicRegistration\": True, \"prepareSupport\": True},\n                    \"callHierarchy\": {\"dynamicRegistration\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"configuration\": True,\n                    \"symbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                },\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n            # luau-lsp initialization options\n            # These can be overridden via .luaurc in the project root\n            \"initializationOptions\": {},\n        }\n        return initialize_params  # type: ignore[return-value]\n\n    def _start_server(self) -> None:\n        \"\"\"Start Luau Language Server process\"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            return\n\n        def workspace_configuration_handler(params: dict) -> list:\n            items = params.get(\"items\", [])\n            config = self._get_workspace_configuration(self._custom_settings)\n            return [config for _ in items]\n\n        def window_log_message(msg: dict) -> None:\n            message_text = msg.get(\"message\", \"\")\n            log.info(\"LSP: window/logMessage: %s\", message_text)\n            if \"workspace ready\" in message_text.lower() or \"initialized\" in message_text.lower():\n                log.info(\"Luau language server signaled readiness\")\n                self.server_ready.set()\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_request(\"workspace/configuration\", workspace_configuration_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting Luau Language Server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        # Verify server capabilities\n        assert \"textDocumentSync\" in init_response[\"capabilities\"]\n        assert \"definitionProvider\" in init_response[\"capabilities\"]\n        assert \"documentSymbolProvider\" in init_response[\"capabilities\"]\n        assert \"referencesProvider\" in init_response[\"capabilities\"]\n\n        self.server.notify.initialized({})\n\n        # Wait for luau-lsp to complete initial setup\n        log.info(\"Waiting for Luau language server to become ready...\")\n        if self.server_ready.wait(timeout=5.0):\n            log.info(\"Luau language server ready\")\n        else:\n            log.warning(\"Timeout waiting for Luau language server readiness, proceeding anyway\")\n            self.server_ready.set()\n"
  },
  {
    "path": "src/solidlsp/language_servers/marksman.py",
    "content": "\"\"\"\nProvides Markdown specific instantiation of the LanguageServer class using marksman.\nContains various configurations and settings specific to Markdown.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nfrom collections.abc import Hashable\n\nfrom overrides import override\n\nfrom solidlsp.ls import (\n    DocumentSymbols,\n    LanguageServerDependencyProvider,\n    LanguageServerDependencyProviderSinglePath,\n    LSPFileBuffer,\n    SolidLanguageServer,\n)\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.ls_types import SymbolKind, UnifiedSymbolInformation\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nfrom .common import RuntimeDependency, RuntimeDependencyCollection\n\nlog = logging.getLogger(__name__)\n\n\nclass Marksman(SolidLanguageServer):\n    \"\"\"\n    Provides Markdown specific instantiation of the LanguageServer class using marksman.\n    \"\"\"\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        marksman_releases = \"https://github.com/artempyanykh/marksman/releases/download/2024-12-18\"\n        runtime_dependencies = RuntimeDependencyCollection(\n            [\n                RuntimeDependency(\n                    id=\"marksman\",\n                    url=f\"{marksman_releases}/marksman-linux-x64\",\n                    platform_id=\"linux-x64\",\n                    archive_type=\"binary\",\n                    binary_name=\"marksman\",\n                ),\n                RuntimeDependency(\n                    id=\"marksman\",\n                    url=f\"{marksman_releases}/marksman-linux-arm64\",\n                    platform_id=\"linux-arm64\",\n                    archive_type=\"binary\",\n                    binary_name=\"marksman\",\n                ),\n                RuntimeDependency(\n                    id=\"marksman\",\n                    url=f\"{marksman_releases}/marksman-macos\",\n                    platform_id=\"osx-x64\",\n                    archive_type=\"binary\",\n                    binary_name=\"marksman\",\n                ),\n                RuntimeDependency(\n                    id=\"marksman\",\n                    url=f\"{marksman_releases}/marksman-macos\",\n                    platform_id=\"osx-arm64\",\n                    archive_type=\"binary\",\n                    binary_name=\"marksman\",\n                ),\n                RuntimeDependency(\n                    id=\"marksman\",\n                    url=f\"{marksman_releases}/marksman.exe\",\n                    platform_id=\"win-x64\",\n                    archive_type=\"binary\",\n                    binary_name=\"marksman.exe\",\n                ),\n            ]\n        )\n\n        def _get_or_install_core_dependency(self) -> str:\n            \"\"\"Setup runtime dependencies for marksman and return the command to start the server.\"\"\"\n            deps = self.runtime_dependencies\n            dependency = deps.get_single_dep_for_current_platform()\n\n            marksman_ls_dir = self._ls_resources_dir\n            marksman_executable_path = deps.binary_path(marksman_ls_dir)\n            if not os.path.exists(marksman_executable_path):\n                log.info(\n                    f\"Downloading marksman from {dependency.url} to {marksman_ls_dir}\",\n                )\n                deps.install(marksman_ls_dir)\n            if not os.path.exists(marksman_executable_path):\n                raise FileNotFoundError(f\"Download failed? Could not find marksman executable at {marksman_executable_path}\")\n            os.chmod(marksman_executable_path, 0o755)\n            return marksman_executable_path\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [core_path, \"server\"]\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a Marksman instance. This class is not meant to be instantiated directly.\n        Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(\n            config,\n            repository_root_path,\n            None,\n            \"markdown\",\n            solidlsp_settings,\n        )\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\"node_modules\", \".obsidian\", \".vitepress\", \".vuepress\"]\n\n    def _document_symbols_cache_fingerprint(self) -> Hashable | None:\n        request_document_symbols_override_version = 1\n        return request_document_symbols_override_version\n\n    @override\n    def request_document_symbols(self, relative_file_path: str, file_buffer: LSPFileBuffer | None = None) -> DocumentSymbols:\n        \"\"\"Override to remap Marksman's heading symbol kinds from String to Namespace.\n\n        Marksman LSP returns all markdown headings (h1-h6) with SymbolKind.String (15).\n        This is problematic because String (15) >= Variable (13), so headings are\n        classified as \"low-level\" and filtered out of symbol overviews.\n        Remapping to Namespace (3) fixes this and is semantically appropriate\n        (headings are named sections containing other content).\n        \"\"\"\n        document_symbols = super().request_document_symbols(relative_file_path, file_buffer=file_buffer)\n\n        # NOTE: When changing this method, also update the cache fingerprint method above\n\n        def remap_heading_kinds(symbol: UnifiedSymbolInformation) -> None:\n            if symbol[\"kind\"] == SymbolKind.String:\n                symbol[\"kind\"] = SymbolKind.Namespace\n            for child in symbol.get(\"children\", []):\n                remap_heading_kinds(child)\n\n        for sym in document_symbols.root_symbols:\n            remap_heading_kinds(sym)\n\n        return document_symbols\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Marksman Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params: InitializeParams = {  # type: ignore\n            \"processId\": os.getpid(),\n            \"locale\": \"en\",\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\"dynamicRegistration\": True, \"completionItem\": {\"snippetSupport\": True}},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},  # type: ignore[arg-type]\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},  # type: ignore[list-item]\n                    \"codeAction\": {\"dynamicRegistration\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True},\n                },\n            },\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return initialize_params\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the Marksman Language Server and waits for it to be ready.\n        \"\"\"\n\n        def register_capability_handler(_params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def do_nothing(_params: dict) -> None:\n            return\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting marksman server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to marksman server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        log.debug(f\"Received initialize response from marksman server: {init_response}\")\n\n        # Verify server capabilities\n        assert \"textDocumentSync\" in init_response[\"capabilities\"]\n        assert \"completionProvider\" in init_response[\"capabilities\"]\n        assert \"definitionProvider\" in init_response[\"capabilities\"]\n\n        self.server.notify.initialized({})\n\n        # marksman is typically ready immediately after initialization\n        log.info(\"Marksman server initialization complete\")\n"
  },
  {
    "path": "src/solidlsp/language_servers/matlab_language_server.py",
    "content": "\"\"\"\nMATLAB language server integration using the official MathWorks MATLAB Language Server.\n\nArchitecture:\n    This module uses the MathWorks MATLAB VS Code extension (mathworks.language-matlab)\n    which contains a Node.js-based language server. The extension is downloaded from the\n    VS Code Marketplace and extracted locally. The language server spawns a real MATLAB\n    process to provide code intelligence - it is NOT a standalone static analyzer.\n\n    Flow: Serena -> Node.js LSP Server -> MATLAB Process -> Code Analysis\n\nWhy MATLAB installation is required:\n    The language server launches an actual MATLAB session (via MatlabSession.js) to perform\n    code analysis, diagnostics, and other features. Without MATLAB, the LSP cannot function.\n    This is different from purely static analyzers that parse code without execution.\n\nRequirements:\n    - MATLAB R2021b or later must be installed and licensed\n    - Node.js must be installed (for running the language server)\n    - MATLAB path can be specified via MATLAB_PATH environment variable or auto-detected\n\nThe MATLAB language server provides:\n    - Code diagnostics (publishDiagnostics)\n    - Code completions (completionProvider)\n    - Go to definition (definitionProvider)\n    - Find references (referencesProvider)\n    - Document symbols (documentSymbol)\n    - Document formatting (documentFormattingProvider)\n    - Function signature help (signatureHelpProvider)\n    - Symbol rename (renameProvider)\n\"\"\"\n\nimport glob\nimport logging\nimport os\nimport pathlib\nimport platform\nimport shutil\nimport threading\nimport zipfile\nfrom typing import Any, cast\n\nimport requests\n\nfrom solidlsp.ls import LanguageServerDependencyProvider, LSPFileBuffer, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import DocumentSymbol, InitializeParams, SymbolInformation\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n# Environment variable for MATLAB installation path\nMATLAB_PATH_ENV_VAR = \"MATLAB_PATH\"\n\n# VS Code Marketplace URL for MATLAB extension\nMATLAB_EXTENSION_URL = (\n    \"https://marketplace.visualstudio.com/_apis/public/gallery/publishers/MathWorks/vsextensions/language-matlab/latest/vspackage\"\n)\n\n\nclass MatlabLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides MATLAB specific instantiation of the LanguageServer class using the official\n    MathWorks MATLAB Language Server.\n\n    The MATLAB language server requires:\n        - MATLAB R2021b or later installed on the system\n        - Node.js for running the language server\n\n    The language server is automatically downloaded from the VS Code marketplace\n    (MathWorks.language-matlab extension) and extracted.\n\n    You can pass the following entries in ls_specific_settings[\"matlab\"]:\n        - matlab_path: Path to MATLAB installation (overrides MATLAB_PATH env var)\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a MatlabLanguageServer instance. This class is not meant to be instantiated directly.\n        Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(\n            config,\n            repository_root_path,\n            None,\n            \"matlab\",\n            solidlsp_settings,\n        )\n\n        assert isinstance(self._dependency_provider, self.DependencyProvider)\n        self._matlab_path = self._dependency_provider.get_matlab_path()\n\n        self.server_ready = threading.Event()\n        self.initialize_searcher_command_available = threading.Event()\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    class DependencyProvider(LanguageServerDependencyProvider):\n        def __init__(self, custom_settings: SolidLSPSettings.CustomLSSettings, ls_resources_dir: str):\n            super().__init__(custom_settings, ls_resources_dir)\n            self._matlab_path: str | None = None\n\n        @classmethod\n        def _download_matlab_extension(cls, url: str, target_dir: str) -> bool:\n            \"\"\"\n            Download and extract the MATLAB extension from VS Code marketplace.\n\n            The VS Code marketplace packages extensions as .vsix files (which are ZIP archives).\n            This method downloads the VSIX file and extracts it to get the language server.\n\n            Args:\n                url: VS Code marketplace URL for the MATLAB extension\n                target_dir: Directory where the extension will be extracted\n\n            Returns:\n                True if successful, False otherwise\n\n            \"\"\"\n            try:\n                log.info(f\"Downloading MATLAB extension from {url}\")\n\n                # Create target directory for the extension\n                os.makedirs(target_dir, exist_ok=True)\n\n                # Download with proper headers to mimic VS Code marketplace client\n                headers = {\n                    \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\",\n                    \"Accept\": \"application/octet-stream, application/vsix, */*\",\n                }\n\n                response = requests.get(url, headers=headers, stream=True, timeout=300)\n                response.raise_for_status()\n\n                # Save to temporary VSIX file\n                temp_file = os.path.join(target_dir, \"matlab_extension_temp.vsix\")\n                total_size = int(response.headers.get(\"content-length\", 0))\n\n                log.info(f\"Downloading {total_size / 1024 / 1024:.1f} MB...\")\n\n                with open(temp_file, \"wb\") as f:\n                    downloaded = 0\n                    for chunk in response.iter_content(chunk_size=8192):\n                        if chunk:\n                            f.write(chunk)\n                            downloaded += len(chunk)\n                            if total_size > 0 and downloaded % (10 * 1024 * 1024) == 0:\n                                progress = (downloaded / total_size) * 100\n                                log.info(f\"Download progress: {progress:.1f}%\")\n\n                log.info(\"Download complete, extracting...\")\n\n                # Extract VSIX file (VSIX files are ZIP archives)\n                with zipfile.ZipFile(temp_file, \"r\") as zip_ref:\n                    zip_ref.extractall(target_dir)\n\n                # Clean up temp file\n                os.remove(temp_file)\n\n                log.info(\"MATLAB extension extracted successfully\")\n                return True\n\n            except Exception as e:\n                log.error(f\"Error downloading/extracting MATLAB extension: {e}\")\n                return False\n\n        def _find_matlab_extension(self) -> str | None:\n            \"\"\"\n            Find MATLAB extension in various locations.\n\n            Search order:\n            1. Environment variable (MATLAB_EXTENSION_PATH)\n            2. Default download location (~/.serena/ls_resources/matlab-extension)\n            3. VS Code installed extensions\n\n            Returns:\n                Path to MATLAB extension directory or None if not found\n\n            \"\"\"\n            # Check environment variable\n            env_path = os.environ.get(\"MATLAB_EXTENSION_PATH\")\n            if env_path and os.path.exists(env_path):\n                log.debug(f\"Found MATLAB extension via MATLAB_EXTENSION_PATH: {env_path}\")\n                return env_path\n            elif env_path:\n                log.warning(f\"MATLAB_EXTENSION_PATH set but directory not found: {env_path}\")\n\n            # Check default download location\n            default_path = os.path.join(self._ls_resources_dir, \"matlab-extension\", \"extension\")\n            if os.path.exists(default_path):\n                log.debug(f\"Found MATLAB extension in default location: {default_path}\")\n                return default_path\n\n            # Search VS Code extensions\n            vscode_extensions_dir = os.path.expanduser(\"~/.vscode/extensions\")\n            if os.path.exists(vscode_extensions_dir):\n                for entry in os.listdir(vscode_extensions_dir):\n                    if entry.startswith(\"mathworks.language-matlab\"):\n                        ext_path = os.path.join(vscode_extensions_dir, entry)\n                        if os.path.isdir(ext_path):\n                            log.debug(f\"Found MATLAB extension in VS Code: {ext_path}\")\n                            return ext_path\n\n            log.debug(\"MATLAB extension not found in any known location\")\n            return None\n\n        def _download_and_install_matlab_extension(self) -> str | None:\n            \"\"\"\n            Download and install MATLAB extension from VS Code marketplace.\n\n            Returns:\n                Path to installed extension or None if download failed\n\n            \"\"\"\n            matlab_extension_dir = os.path.join(self._ls_resources_dir, \"matlab-extension\")\n\n            log.info(f\"Downloading MATLAB extension from: {MATLAB_EXTENSION_URL}\")\n\n            if self._download_matlab_extension(MATLAB_EXTENSION_URL, matlab_extension_dir):\n                extension_path = os.path.join(matlab_extension_dir, \"extension\")\n                if os.path.exists(extension_path):\n                    log.info(\"MATLAB extension downloaded and installed successfully\")\n                    return extension_path\n                else:\n                    log.error(f\"Download completed but extension not found at: {extension_path}\")\n            else:\n                log.error(\"Failed to download MATLAB extension from marketplace\")\n\n            return None\n\n        @classmethod\n        def _get_executable_path(cls, extension_path: str) -> str:\n            \"\"\"\n            Get the path to the MATLAB language server executable based on platform.\n\n            The language server is a Node.js script located in the extension's server directory.\n            \"\"\"\n            # The MATLAB extension bundles the language server in the 'server' directory\n            server_dir = os.path.join(extension_path, \"server\", \"out\")\n            main_script = os.path.join(server_dir, \"index.js\")\n\n            if os.path.exists(main_script):\n                return main_script\n\n            # Alternative location\n            alt_script = os.path.join(extension_path, \"out\", \"index.js\")\n            if os.path.exists(alt_script):\n                return alt_script\n\n            raise RuntimeError(f\"MATLAB language server script not found in extension at {extension_path}\")\n\n        @staticmethod\n        def _find_matlab_installation() -> str:\n            \"\"\"\n            Find MATLAB installation path.\n\n            Search order:\n                1. MATLAB_PATH environment variable\n                2. Common installation locations based on platform\n\n            Returns:\n                Path to MATLAB installation directory.\n\n            Raises:\n                RuntimeError: If MATLAB installation is not found.\n\n            \"\"\"\n            # Check environment variable first\n            matlab_path = os.environ.get(MATLAB_PATH_ENV_VAR)\n            if matlab_path and os.path.isdir(matlab_path):\n                log.info(f\"Using MATLAB from environment variable {MATLAB_PATH_ENV_VAR}: {matlab_path}\")\n                return matlab_path\n\n            system = platform.system()\n\n            if system == \"Darwin\":  # macOS\n                # Check common macOS locations\n                search_patterns = [\n                    \"/Applications/MATLAB_*.app\",\n                    \"/Volumes/*/Applications/MATLAB_*.app\",\n                    os.path.expanduser(\"~/Applications/MATLAB_*.app\"),\n                ]\n                for pattern in search_patterns:\n                    matches = sorted(glob.glob(pattern), reverse=True)  # Newest version first\n                    for match in matches:\n                        if os.path.isdir(match):\n                            log.info(f\"Found MATLAB installation: {match}\")\n                            return match\n\n            elif system == \"Windows\":\n                # Check common Windows locations\n                search_patterns = [\n                    \"C:\\\\Program Files\\\\MATLAB\\\\R*\",\n                    \"C:\\\\Program Files (x86)\\\\MATLAB\\\\R*\",\n                ]\n                for pattern in search_patterns:\n                    matches = sorted(glob.glob(pattern), reverse=True)\n                    for match in matches:\n                        if os.path.isdir(match):\n                            log.info(f\"Found MATLAB installation: {match}\")\n                            return match\n\n            elif system == \"Linux\":\n                # Check common Linux locations\n                search_patterns = [\n                    \"/usr/local/MATLAB/R*\",\n                    \"/opt/MATLAB/R*\",\n                    os.path.expanduser(\"~/MATLAB/R*\"),\n                ]\n                for pattern in search_patterns:\n                    matches = sorted(glob.glob(pattern), reverse=True)\n                    for match in matches:\n                        if os.path.isdir(match):\n                            log.info(f\"Found MATLAB installation: {match}\")\n                            return match\n\n            raise RuntimeError(\n                f\"MATLAB installation not found. Set the {MATLAB_PATH_ENV_VAR} environment variable \"\n                \"to your MATLAB installation directory (e.g., /Applications/MATLAB_R2024b.app on macOS, \"\n                \"C:\\\\Program Files\\\\MATLAB\\\\R2024b on Windows, or /usr/local/MATLAB/R2024b on Linux).\"\n            )\n\n        def get_matlab_path(self) -> str:\n            \"\"\"Get MATLAB path from settings or auto-detect.\"\"\"\n            if self._matlab_path is not None:\n                return self._matlab_path\n\n            matlab_path = self._custom_settings.get(\"matlab_path\")\n\n            if not matlab_path:\n                matlab_path = self._find_matlab_installation()  # Raises RuntimeError if not found\n\n            # Verify MATLAB path exists\n            if not os.path.isdir(matlab_path):\n                raise RuntimeError(f\"MATLAB installation directory does not exist: {matlab_path}\")\n\n            log.info(f\"Using MATLAB installation: {matlab_path}\")\n\n            self._matlab_path = matlab_path\n            return matlab_path\n\n        def create_launch_command(self) -> list[str]:\n            # Verify node is installed\n            node_path = shutil.which(\"node\")\n            if node_path is None:\n                raise RuntimeError(\"Node.js is not installed or isn't in PATH. Please install Node.js and try again.\")\n\n            # Find existing extension or download if needed\n            extension_path = self._find_matlab_extension()\n            if extension_path is None:\n                log.info(\"MATLAB extension not found on disk, attempting to download...\")\n                extension_path = self._download_and_install_matlab_extension()\n\n            if extension_path is None:\n                raise RuntimeError(\n                    \"Failed to locate or download MATLAB Language Server. Please either:\\n\"\n                    \"1. Set MATLAB_EXTENSION_PATH environment variable to the MATLAB extension directory\\n\"\n                    \"2. Install the MATLAB extension in VS Code (MathWorks.language-matlab)\\n\"\n                    \"3. Ensure internet connection for automatic download\"\n                )\n\n            # Get the language server script path\n            server_script = self._get_executable_path(extension_path)\n\n            if not os.path.exists(server_script):\n                raise RuntimeError(f\"MATLAB Language Server script not found at: {server_script}\")\n\n            # Build the command to run the language server\n            # The MATLAB language server is run via Node.js with the --stdio flag\n            cmd = [node_path, server_script, \"--stdio\"]\n            return cmd\n\n        def create_launch_command_env(self) -> dict[str, str]:\n            return {\n                \"MATLAB_INSTALL_PATH\": self.get_matlab_path(),\n            }\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"Return the initialize params for the MATLAB Language Server.\"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"completionItem\": {\"snippetSupport\": True},\n                    },\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"signatureHelp\": {\"dynamicRegistration\": True},\n                    \"codeAction\": {\"dynamicRegistration\": True},\n                    \"formatting\": {\"dynamicRegistration\": True},\n                    \"rename\": {\"dynamicRegistration\": True, \"prepareSupport\": True},\n                    \"publishDiagnostics\": {\"relatedInformation\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True},\n                },\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return cast(InitializeParams, initialize_params)\n\n    def _start_server(self) -> None:\n        \"\"\"Start the MATLAB Language Server and wait for it to be ready.\"\"\"\n        root_uri = pathlib.Path(self.repository_root_path).as_uri()\n\n        def register_capability_handler(params: dict) -> None:\n            assert \"registrations\" in params\n            for registration in params[\"registrations\"]:\n                if registration[\"method\"] == \"workspace/executeCommand\":\n                    self.initialize_searcher_command_available.set()\n            return\n\n        def execute_client_command_handler(params: dict) -> list:\n            return []\n\n        def workspace_folders_handler(params: dict) -> list:\n            \"\"\"Handle workspace/workspaceFolders request from the server.\"\"\"\n            return [{\"uri\": root_uri, \"name\": os.path.basename(self.repository_root_path)}]\n\n        def workspace_configuration_handler(params: dict) -> list:\n            \"\"\"Handle workspace/configuration request from the server.\"\"\"\n            items = params.get(\"items\", [])\n            result = []\n            for item in items:\n                section = item.get(\"section\", \"\")\n                if section == \"MATLAB\":\n                    # Return MATLAB configuration\n                    result.append({\"installPath\": self._matlab_path, \"matlabConnectionTiming\": \"onStart\"})\n                else:\n                    result.append({})\n            return result\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n            message_text = msg.get(\"message\", \"\")\n            # Check for MATLAB language server ready signals\n            # Wait for \"MVM attach success\" or \"Adding workspace folder\" which indicates MATLAB is fully ready\n            # Note: \"connected to\" comes earlier but the server isn't fully ready at that point\n            if \"mvm attach success\" in message_text.lower() or \"adding workspace folder\" in message_text.lower():\n                log.info(\"MATLAB language server ready signal detected (MVM attached)\")\n                self.server_ready.set()\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_request(\"workspace/executeClientCommand\", execute_client_command_handler)\n        self.server.on_request(\"workspace/workspaceFolders\", workspace_folders_handler)\n        self.server.on_request(\"workspace/configuration\", workspace_configuration_handler)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting MATLAB server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        log.debug(f\"Received initialize response from MATLAB server: {init_response}\")\n\n        # Verify basic capabilities\n        capabilities = init_response.get(\"capabilities\", {})\n        assert capabilities.get(\"textDocumentSync\") in [1, 2], \"Expected Full or Incremental text sync\"\n\n        # Log available capabilities\n        if \"completionProvider\" in capabilities:\n            log.info(\"MATLAB server supports completions\")\n        if \"definitionProvider\" in capabilities:\n            log.info(\"MATLAB server supports go-to-definition\")\n        if \"referencesProvider\" in capabilities:\n            log.info(\"MATLAB server supports find-references\")\n        if \"documentSymbolProvider\" in capabilities:\n            log.info(\"MATLAB server supports document symbols\")\n        if \"documentFormattingProvider\" in capabilities:\n            log.info(\"MATLAB server supports document formatting\")\n        if \"renameProvider\" in capabilities:\n            log.info(\"MATLAB server supports rename\")\n\n        self.server.notify.initialized({})\n\n        # Wait for server readiness with timeout\n        # MATLAB takes longer to start than most language servers (typically 10-30 seconds)\n        log.info(\"Waiting for MATLAB language server to be ready (this may take up to 60 seconds)...\")\n        if not self.server_ready.wait(timeout=60.0):\n            # Fallback: assume server is ready after timeout\n            log.info(\"Timeout waiting for MATLAB server ready signal, proceeding anyway\")\n            self.server_ready.set()\n        else:\n            log.info(\"MATLAB server initialization complete\")\n\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        \"\"\"Define MATLAB-specific directories to ignore.\"\"\"\n        return super().is_ignored_dirname(dirname) or dirname in [\n            \"slprj\",  # Simulink project files\n            \"codegen\",  # Code generation output\n            \"sldemo_cache\",  # Simulink demo cache\n            \"helperFiles\",  # Common helper file directories\n        ]\n\n    def _request_document_symbols(\n        self, relative_file_path: str, file_data: LSPFileBuffer | None\n    ) -> list[SymbolInformation] | list[DocumentSymbol] | None:\n        \"\"\"\n        Override to normalize MATLAB symbol names.\n\n        The MATLAB LSP sometimes returns symbol names as lists instead of strings,\n        particularly for script sections (cell mode markers like %%). This method\n        normalizes the names to strings for compatibility with the unified symbol format.\n        \"\"\"\n        symbols = super()._request_document_symbols(relative_file_path, file_data)\n\n        if symbols is None or len(symbols) == 0:\n            return symbols\n\n        self._normalize_matlab_symbols(symbols)\n        return symbols\n\n    def _normalize_matlab_symbols(self, symbols: list[SymbolInformation] | list[DocumentSymbol]) -> None:\n        \"\"\"\n        Normalize MATLAB symbol names in-place.\n\n        MATLAB LSP returns section names as lists like [\"Section Name\"] instead of\n        strings. This converts them to plain strings.\n        \"\"\"\n        for symbol in symbols:\n            # MATLAB LSP returns names as lists for script sections, violating LSP spec\n            # Cast to Any to handle runtime type that differs from spec\n            name: Any = symbol.get(\"name\")\n            if isinstance(name, list):\n                symbol[\"name\"] = name[0] if name else \"\"\n                log.debug(\"Normalized MATLAB symbol name from list to string\")\n\n            # Recursively normalize children if present\n            children: Any = symbol.get(\"children\")\n            if children and isinstance(children, list):\n                self._normalize_matlab_symbols(children)\n"
  },
  {
    "path": "src/solidlsp/language_servers/nixd_ls.py",
    "content": "# type: ignore\n\"\"\"\nProvides Nix specific instantiation of the LanguageServer class using nixd (Nix Language Server).\n\nNote: Windows is not supported as Nix itself doesn't support Windows natively.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport platform\nimport shutil\nimport subprocess\nfrom pathlib import Path\n\nfrom overrides import override\n\nfrom solidlsp import ls_types\nfrom solidlsp.ls import DocumentSymbols, LSPFileBuffer, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass NixLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides Nix specific instantiation of the LanguageServer class using nixd.\n    \"\"\"\n\n    def _extend_nix_symbol_range_to_include_semicolon(\n        self, symbol: ls_types.UnifiedSymbolInformation, file_content: str\n    ) -> ls_types.UnifiedSymbolInformation:\n        \"\"\"\n        Extend symbol range to include trailing semicolon for Nix attribute symbols.\n\n        nixd provides ranges that exclude semicolons (expression-level), but serena needs\n        statement-level ranges that include semicolons for proper replacement.\n        \"\"\"\n        range_info = symbol[\"range\"]\n        end_line = range_info[\"end\"][\"line\"]\n        end_char = range_info[\"end\"][\"character\"]\n\n        # Split file content into lines\n        lines = file_content.split(\"\\n\")\n        if end_line >= len(lines):\n            return symbol\n\n        line = lines[end_line]\n\n        # Check if there's a semicolon immediately after the current range end\n        if end_char < len(line) and line[end_char] == \";\":\n            # Extend range to include the semicolon\n            new_range = {\"start\": range_info[\"start\"], \"end\": {\"line\": end_line, \"character\": end_char + 1}}\n\n            # Create modified symbol with extended range\n            extended_symbol = symbol.copy()\n            extended_symbol[\"range\"] = new_range\n\n            # CRITICAL: Also update the location.range if it exists\n            if extended_symbol.get(\"location\"):\n                location = extended_symbol[\"location\"].copy()\n                if \"range\" in location:\n                    location[\"range\"] = new_range.copy()\n                extended_symbol[\"location\"] = location\n\n            return extended_symbol\n\n        return symbol\n\n    @override\n    def request_document_symbols(self, relative_file_path: str, file_buffer: LSPFileBuffer | None = None) -> DocumentSymbols:\n        # Override to extend Nix symbol ranges to include trailing semicolons.\n        # nixd provides expression-level ranges (excluding semicolons) but serena needs\n        # statement-level ranges (including semicolons) for proper symbol replacement.\n\n        # Get symbols from parent implementation\n        document_symbols = super().request_document_symbols(relative_file_path, file_buffer=file_buffer)\n\n        # Get file content for range extension\n        file_content = self.language_server.retrieve_full_file_content(relative_file_path)\n\n        # Extend ranges for all symbols recursively\n        def extend_symbol_and_children(symbol: ls_types.UnifiedSymbolInformation) -> ls_types.UnifiedSymbolInformation:\n            # Extend this symbol's range\n            extended = self._extend_nix_symbol_range_to_include_semicolon(symbol, file_content)\n\n            # Extend children recursively\n            if extended.get(\"children\"):\n                extended[\"children\"] = [extend_symbol_and_children(child) for child in extended[\"children\"]]\n\n            return extended\n\n        # Apply range extension to all symbols\n        extended_root_symbols = [extend_symbol_and_children(sym) for sym in document_symbols.root_symbols]\n\n        return DocumentSymbols(extended_root_symbols)\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        # For Nix projects, we should ignore:\n        # - result: nix build output symlinks\n        # - result-*: multiple build outputs\n        # - .direnv: direnv cache\n        return super().is_ignored_dirname(dirname) or dirname in [\"result\", \".direnv\"] or dirname.startswith(\"result-\")\n\n    @staticmethod\n    def _get_nixd_version():\n        \"\"\"Get the installed nixd version or None if not found.\"\"\"\n        try:\n            result = subprocess.run([\"nixd\", \"--version\"], capture_output=True, text=True, check=False)\n            if result.returncode == 0:\n                # nixd outputs version like: nixd 2.0.0\n                return result.stdout.strip()\n        except FileNotFoundError:\n            return None\n        return None\n\n    @staticmethod\n    def _check_nixd_installed():\n        \"\"\"Check if nixd is installed in the system.\"\"\"\n        return shutil.which(\"nixd\") is not None\n\n    @staticmethod\n    def _get_nixd_path():\n        \"\"\"Get the path to nixd executable.\"\"\"\n        # First check if it's in PATH\n        nixd_path = shutil.which(\"nixd\")\n        if nixd_path:\n            return nixd_path\n\n        # Check common installation locations\n        home = Path.home()\n        possible_paths = [\n            home / \".local\" / \"bin\" / \"nixd\",\n            home / \".serena\" / \"language_servers\" / \"nixd\" / \"nixd\",\n            home / \".nix-profile\" / \"bin\" / \"nixd\",\n            Path(\"/usr/local/bin/nixd\"),\n            Path(\"/run/current-system/sw/bin/nixd\"),  # NixOS system profile\n            Path(\"/opt/homebrew/bin/nixd\"),  # Homebrew on Apple Silicon\n            Path(\"/usr/local/opt/nixd/bin/nixd\"),  # Homebrew on Intel Mac\n        ]\n\n        # Add Windows-specific paths\n        if platform.system() == \"Windows\":\n            possible_paths.extend(\n                [\n                    home / \"AppData\" / \"Local\" / \"nixd\" / \"nixd.exe\",\n                    home / \".serena\" / \"language_servers\" / \"nixd\" / \"nixd.exe\",\n                ]\n            )\n\n        for path in possible_paths:\n            if path.exists():\n                return str(path)\n\n        return None\n\n    @staticmethod\n    def _install_nixd_with_nix():\n        \"\"\"Install nixd using nix if available.\"\"\"\n        # Check if nix is available\n        if not shutil.which(\"nix\"):\n            return None\n\n        print(\"Installing nixd using nix... This may take a few minutes.\")\n        try:\n            # Try to install nixd using nix profile\n            result = subprocess.run(\n                [\"nix\", \"profile\", \"install\", \"github:nix-community/nixd\"],\n                capture_output=True,\n                text=True,\n                check=False,\n                timeout=600,  # 10 minute timeout for building\n            )\n\n            if result.returncode == 0:\n                # Check if nixd is now in PATH\n                nixd_path = shutil.which(\"nixd\")\n                if nixd_path:\n                    print(f\"Successfully installed nixd at: {nixd_path}\")\n                    return nixd_path\n            else:\n                # Try nix-env as fallback\n                result = subprocess.run(\n                    [\"nix-env\", \"-iA\", \"nixpkgs.nixd\"],\n                    capture_output=True,\n                    text=True,\n                    check=False,\n                    timeout=600,\n                )\n                if result.returncode == 0:\n                    nixd_path = shutil.which(\"nixd\")\n                    if nixd_path:\n                        print(f\"Successfully installed nixd at: {nixd_path}\")\n                        return nixd_path\n                print(f\"Failed to install nixd: {result.stderr}\")\n\n        except subprocess.TimeoutExpired:\n            print(\"Nix install timed out after 10 minutes\")\n        except Exception as e:\n            print(f\"Error installing nixd with nix: {e}\")\n\n        return None\n\n    @staticmethod\n    def _setup_runtime_dependency():\n        \"\"\"\n        Check if required Nix runtime dependencies are available.\n        Attempts to install nixd if not present.\n        \"\"\"\n        # First check if Nix is available (nixd needs it at runtime)\n        if not shutil.which(\"nix\"):\n            print(\"WARNING: Nix is not installed. nixd requires Nix to function properly.\")\n            raise RuntimeError(\"Nix is required for nixd. Please install Nix from https://nixos.org/download.html\")\n\n        nixd_path = NixLanguageServer._get_nixd_path()\n\n        if not nixd_path:\n            print(\"nixd not found. Attempting to install...\")\n\n            # Try to install with nix if available\n            nixd_path = NixLanguageServer._install_nixd_with_nix()\n\n            if not nixd_path:\n                raise RuntimeError(\n                    \"nixd (Nix Language Server) is not installed.\\n\"\n                    \"Please install nixd using one of the following methods:\\n\"\n                    \"  - Using Nix flakes: nix profile install github:nix-community/nixd\\n\"\n                    \"  - From nixpkgs: nix-env -iA nixpkgs.nixd\\n\"\n                    \"  - On macOS with Homebrew: brew install nixd\\n\\n\"\n                    \"After installation, make sure 'nixd' is in your PATH.\"\n                )\n\n        # Verify nixd works\n        try:\n            result = subprocess.run([nixd_path, \"--version\"], capture_output=True, text=True, check=False, timeout=5)\n            if result.returncode != 0:\n                raise RuntimeError(f\"nixd failed to run: {result.stderr}\")\n        except Exception as e:\n            raise RuntimeError(f\"Failed to verify nixd installation: {e}\")\n\n        return nixd_path\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        nixd_path = self._setup_runtime_dependency()\n\n        super().__init__(config, repository_root_path, ProcessLaunchInfo(cmd=nixd_path, cwd=repository_root_path), \"nix\", solidlsp_settings)\n        self.request_id = 0\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for nixd.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"completionItem\": {\n                            \"snippetSupport\": True,\n                            \"commitCharactersSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"deprecatedSupport\": True,\n                            \"preselectSupport\": True,\n                        },\n                    },\n                    \"hover\": {\n                        \"dynamicRegistration\": True,\n                        \"contentFormat\": [\"markdown\", \"plaintext\"],\n                    },\n                    \"signatureHelp\": {\n                        \"dynamicRegistration\": True,\n                        \"signatureInformation\": {\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"parameterInformation\": {\"labelOffsetSupport\": True},\n                        },\n                    },\n                    \"codeAction\": {\n                        \"dynamicRegistration\": True,\n                        \"codeActionLiteralSupport\": {\n                            \"codeActionKind\": {\n                                \"valueSet\": [\n                                    \"\",\n                                    \"quickfix\",\n                                    \"refactor\",\n                                    \"refactor.extract\",\n                                    \"refactor.inline\",\n                                    \"refactor.rewrite\",\n                                    \"source\",\n                                    \"source.organizeImports\",\n                                ]\n                            }\n                        },\n                    },\n                    \"rename\": {\"dynamicRegistration\": True, \"prepareSupport\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"configuration\": True,\n                    \"symbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                },\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n            \"initializationOptions\": {\n                # nixd specific options\n                \"nixpkgs\": {\"expr\": \"import <nixpkgs> { }\"},\n                \"formatting\": {\"command\": [\"nixpkgs-fmt\"]},  # or [\"alejandra\"] or [\"nixfmt\"]\n                \"options\": {\n                    \"enable\": True,\n                    \"target\": {\n                        \"installable\": \"\",  # Will be auto-detected from flake.nix if present\n                    },\n                },\n            },\n        }\n        return initialize_params\n\n    def _start_server(self):\n        \"\"\"Start nixd server process\"\"\"\n\n        def register_capability_handler(params):\n            return\n\n        def window_log_message(msg):\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def do_nothing(params):\n            return\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting nixd server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        # Verify server capabilities\n        assert \"textDocumentSync\" in init_response[\"capabilities\"]\n        assert \"definitionProvider\" in init_response[\"capabilities\"]\n        assert \"documentSymbolProvider\" in init_response[\"capabilities\"]\n        assert \"referencesProvider\" in init_response[\"capabilities\"]\n\n        self.server.notify.initialized({})\n\n        # nixd server is typically ready immediately after initialization\n"
  },
  {
    "path": "src/solidlsp/language_servers/ocaml_lsp_server.py",
    "content": "\"\"\"\nProvides OCaml and Reason specific instantiation of the SolidLanguageServer class.\nContains various configurations and settings specific to OCaml and Reason.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport platform\nimport re\nimport shutil\nimport stat\nimport subprocess\nimport threading\nfrom typing import Any\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\nfrom solidlsp.util.subprocess_util import subprocess_kwargs\n\nlog = logging.getLogger(__name__)\n\n\nclass OcamlLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides OCaml and Reason specific instantiation of the SolidLanguageServer class.\n    Contains various configurations and settings specific to OCaml and Reason.\n    \"\"\"\n\n    _ocaml_version: tuple[int, int, int]\n    _lsp_version: tuple[int, int, int]\n    _index_built: bool\n\n    # Minimum LSP version for reliable cross-file references\n    MIN_LSP_VERSION_FOR_CROSS_FILE_REFS: tuple[int, int, int] = (1, 23, 0)\n\n    @staticmethod\n    def _ensure_opam_installed() -> None:\n        \"\"\"Ensure OPAM is installed and available.\"\"\"\n        opam_path = shutil.which(\"opam\")\n        if opam_path is None:\n            raise RuntimeError(\n                \"OPAM is not installed or not in PATH.\\n\"\n                \"Please install OPAM from: https://opam.ocaml.org/doc/Install.html\\n\\n\"\n                \"Installation instructions:\\n\"\n                \"  - macOS: brew install opam\\n\"\n                \"  - Ubuntu/Debian: sudo apt install opam\\n\"\n                \"  - Fedora: sudo dnf install opam\\n\"\n                \"  - Windows: https://fdopen.github.io/opam-repository-mingw/installation/\\n\\n\"\n                \"After installation, initialize OPAM with: opam init\"\n            )\n\n    @staticmethod\n    def _detect_ocaml_version(repository_root_path: str) -> tuple[int, int, int]:\n        \"\"\"\n        Detect and return the OCaml version as a tuple (major, minor, patch).\n        Also checks for version compatibility with ocaml-lsp-server.\n        Raises RuntimeError if version cannot be determined.\n        \"\"\"\n        try:\n            result = subprocess.run(\n                [\"opam\", \"exec\", \"--\", \"ocaml\", \"-version\"],\n                check=True,\n                capture_output=True,\n                text=True,\n                cwd=repository_root_path,\n                **subprocess_kwargs(),\n            )\n            version_match = re.search(r\"(\\d+)\\.(\\d+)\\.(\\d+)\", result.stdout)\n            if version_match:\n                major = int(version_match.group(1))\n                minor = int(version_match.group(2))\n                patch = int(version_match.group(3))\n                version_tuple = (major, minor, patch)\n                version_str = f\"{major}.{minor}.{patch}\"\n                log.info(f\"OCaml version: {version_str}\")\n\n                if version_tuple == (5, 1, 0):\n                    raise RuntimeError(\n                        f\"OCaml {version_str} is incompatible with ocaml-lsp-server.\\n\"\n                        \"Please use OCaml < 5.1 or >= 5.1.1.\\n\"\n                        \"Consider creating a new opam switch:\\n\"\n                        \"  opam switch create <name> ocaml-base-compiler.4.14.2\"\n                    )\n                return version_tuple\n            raise RuntimeError(\n                f\"Could not parse OCaml version from output: {result.stdout.strip()}\\n\"\n                \"Please ensure OCaml is properly installed: opam exec -- ocaml -version\"\n            )\n        except subprocess.CalledProcessError as e:\n            raise RuntimeError(\n                f\"Failed to detect OCaml version: {e.stderr}\\n\"\n                \"Please ensure OCaml is installed and opam is configured:\\n\"\n                \"  opam switch show\\n\"\n                \"  opam exec -- ocaml -version\"\n            ) from e\n        except FileNotFoundError as e:\n            raise RuntimeError(\n                \"OCaml not found. Please install OCaml via opam:\\n\"\n                \"  opam switch create <name> ocaml-base-compiler.4.14.2\\n\"\n                \"  eval $(opam env)\"\n            ) from e\n\n    @staticmethod\n    def _detect_lsp_version(repository_root_path: str) -> tuple[int, int, int]:\n        \"\"\"\n        Detect and return the ocaml-lsp-server version as a tuple (major, minor, patch).\n        Raises RuntimeError if version cannot be determined.\n        \"\"\"\n        try:\n            result = subprocess.run(\n                [\"opam\", \"list\", \"-i\", \"ocaml-lsp-server\", \"--columns=version\", \"--short\"],\n                check=True,\n                capture_output=True,\n                text=True,\n                cwd=repository_root_path,\n                **subprocess_kwargs(),\n            )\n            version_str = result.stdout.strip()\n            version_match = re.search(r\"(\\d+)\\.(\\d+)\\.(\\d+)\", version_str)\n            if version_match:\n                major = int(version_match.group(1))\n                minor = int(version_match.group(2))\n                patch = int(version_match.group(3))\n                version_tuple = (major, minor, patch)\n                log.info(f\"ocaml-lsp-server version: {major}.{minor}.{patch}\")\n                return version_tuple\n            raise RuntimeError(\n                f\"Could not parse ocaml-lsp-server version from output: {version_str}\\n\"\n                \"Please ensure ocaml-lsp-server is properly installed:\\n\"\n                \"  opam list -i ocaml-lsp-server\"\n            )\n        except subprocess.CalledProcessError as e:\n            raise RuntimeError(\n                f\"Failed to detect ocaml-lsp-server version: {e.stderr}\\n\"\n                \"Please install ocaml-lsp-server:\\n\"\n                \"  opam install ocaml-lsp-server\"\n            ) from e\n        except FileNotFoundError as e:\n            raise RuntimeError(\"opam not found. Please install opam:\\n  https://opam.ocaml.org/doc/Install.html\") from e\n\n    @staticmethod\n    def _ensure_ocaml_lsp_installed(repository_root_path: str) -> str:\n        \"\"\"\n        Ensure ocaml-lsp-server is installed and return the executable path.\n        Raises RuntimeError with helpful message if not installed.\n        \"\"\"\n        # Check if ocaml-lsp-server is installed\n        try:\n            result = subprocess.run(\n                [\"opam\", \"list\", \"-i\", \"ocaml-lsp-server\"],\n                check=False,\n                capture_output=True,\n                text=True,\n                cwd=repository_root_path,\n                **subprocess_kwargs(),\n            )\n            if \"ocaml-lsp-server\" not in result.stdout or \"# No matches found\" in result.stdout:\n                raise RuntimeError(\n                    \"ocaml-lsp-server is not installed.\\n\\n\"\n                    \"Please install it with:\\n\"\n                    \"  opam install ocaml-lsp-server\\n\\n\"\n                    \"Note: ocaml-lsp-server requires OCaml < 5.1 or >= 5.1.1 (OCaml 5.1.0 is not supported).\\n\"\n                    \"If you have OCaml 5.1.0, create a new opam switch with a compatible version:\\n\"\n                    \"  opam switch create <name> ocaml-base-compiler.4.14.2\\n\"\n                    \"  opam switch <name>\\n\"\n                    \"  eval $(opam env)\\n\"\n                    \"  opam install ocaml-lsp-server\\n\\n\"\n                    \"For more information: https://github.com/ocaml/ocaml-lsp\"\n                )\n            log.info(\"ocaml-lsp-server is installed\")\n        except subprocess.CalledProcessError as e:\n            raise RuntimeError(f\"Failed to check ocaml-lsp-server installation: {e.stderr}\")\n\n        # Find the executable path\n        try:\n            if platform.system() == \"Windows\":\n                result = subprocess.run(\n                    [\"opam\", \"exec\", \"--\", \"where\", \"ocamllsp\"],\n                    check=True,\n                    capture_output=True,\n                    text=True,\n                    cwd=repository_root_path,\n                    **subprocess_kwargs(),\n                )\n                executable_path = result.stdout.strip().split(\"\\n\")[0]\n            else:\n                result = subprocess.run(\n                    [\"opam\", \"exec\", \"--\", \"which\", \"ocamllsp\"],\n                    check=True,\n                    capture_output=True,\n                    text=True,\n                    cwd=repository_root_path,\n                    **subprocess_kwargs(),\n                )\n                executable_path = result.stdout.strip()\n\n            if not os.path.exists(executable_path):\n                raise RuntimeError(f\"ocaml-lsp-server executable not found at {executable_path}\")\n\n            if platform.system() != \"Windows\":\n                os.chmod(executable_path, os.stat(executable_path).st_mode | stat.S_IEXEC)\n\n            return executable_path\n\n        except subprocess.CalledProcessError as e:\n            raise RuntimeError(\n                f\"Failed to find ocaml-lsp-server executable.\\n\"\n                f\"Command failed: {e.cmd}\\n\"\n                f\"Return code: {e.returncode}\\n\"\n                f\"Stderr: {e.stderr}\\n\\n\"\n                \"This usually means ocaml-lsp-server is not installed or not in PATH.\\n\"\n                \"Try:\\n\"\n                \"  1. Check opam switch: opam switch show\\n\"\n                \"  2. Install ocaml-lsp-server: opam install ocaml-lsp-server\\n\"\n                \"  3. Ensure opam env is activated: eval $(opam env)\"\n            )\n\n    @property\n    def supports_cross_file_references(self) -> bool:\n        \"\"\"\n        Check if this OCaml environment supports cross-file references.\n\n        Cross-file references require OCaml >= 5.2 with project-wide occurrences\n        AND ocaml-lsp-server >= 1.23.0 for reliable cross-file reference support.\n        Full requirements:\n        - OCaml 5.2+\n        - ocaml-lsp-server >= 1.23.0 (earlier versions have unreliable cross-file refs)\n        - merlin >= 5.1-502 (provides ocaml-index tool)\n        - dune >= 3.16.0\n        - Index built via `dune build @ocaml-index`\n        - For best results: `dune build -w` running (enables dune RPC)\n\n        Note: Even when this returns True, cross-file refs may not work in all\n        cases. The LSP server needs dune's RPC server (via -w flag) to be fully\n        aware of the index. Without watch mode, cross-file refs are best-effort.\n\n        See: https://discuss.ocaml.org/t/ann-project-wide-occurrences-in-merlin-and-lsp/14847\n        \"\"\"\n        ocaml_ok = self._ocaml_version >= (5, 2, 0)\n        lsp_ok = self._lsp_version >= self.MIN_LSP_VERSION_FOR_CROSS_FILE_REFS\n        return ocaml_ok and lsp_ok\n\n    @staticmethod\n    def _build_ocaml_index_static(repository_root_path: str) -> bool:\n        \"\"\"\n        Build the OCaml index for project-wide occurrences.\n        This enables cross-file reference finding on OCaml 5.2+.\n        Must be called BEFORE starting the LSP server.\n        Returns True if successful, False otherwise.\n        \"\"\"\n        log.info(\"Building OCaml index for cross-file references (dune build @ocaml-index)...\")\n        try:\n            result = subprocess.run(\n                [\"opam\", \"exec\", \"--\", \"dune\", \"build\", \"@ocaml-index\"],\n                cwd=repository_root_path,\n                capture_output=True,\n                text=True,\n                timeout=120,\n                check=False,\n                **subprocess_kwargs(),\n            )\n            if result.returncode == 0:\n                log.info(\"OCaml index built successfully\")\n                return True\n            else:\n                log.warning(f\"Failed to build OCaml index: {result.stderr}\")\n                return False\n        except subprocess.TimeoutExpired:\n            log.warning(\"OCaml index build timed out after 120 seconds\")\n            return False\n        except FileNotFoundError:\n            log.warning(\"opam not found, cannot build OCaml index\")\n            return False\n        except Exception as e:\n            log.warning(f\"Error building OCaml index: {e}\")\n            return False\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates an OcamlLanguageServer instance.\n        This class is not meant to be instantiated directly. Use SolidLanguageServer.create() instead.\n        \"\"\"\n        # Ensure dependencies are available\n        self._ensure_opam_installed()\n\n        # Detect OCaml version for feature gating\n        self._ocaml_version = self._detect_ocaml_version(repository_root_path)\n        self._index_built = False\n\n        # Verify ocaml-lsp-server is installed (we don't need the path, just validation)\n        self._ensure_ocaml_lsp_installed(repository_root_path)\n\n        # Detect LSP version for cross-file reference support\n        self._lsp_version = self._detect_lsp_version(repository_root_path)\n\n        # Build OCaml index BEFORE starting server (required for cross-file refs on OCaml 5.2+)\n        if self._ocaml_version >= (5, 2, 0):\n            self._index_built = self._build_ocaml_index_static(repository_root_path)\n\n        # Use opam exec to run ocamllsp - this ensures correct opam environment\n        # which is required for project-wide occurrences (cross-file references) to work\n        ocaml_lsp_cmd = [\"opam\", \"exec\", \"--\", \"ocamllsp\", \"--fallback-read-dot-merlin\"]\n        log.info(f\"Using ocaml-lsp-server via: {' '.join(ocaml_lsp_cmd)}\")\n\n        super().__init__(\n            config,\n            repository_root_path,\n            ProcessLaunchInfo(cmd=ocaml_lsp_cmd, cwd=repository_root_path),\n            \"ocaml\",\n            solidlsp_settings,\n        )\n        self.server_ready = threading.Event()\n        self.completions_available = threading.Event()\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        \"\"\"Define language-specific directories to ignore for OCaml projects.\"\"\"\n        return super().is_ignored_dirname(dirname) or dirname in [\"_build\", \"_opam\", \".opam\"]\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the OCaml Language Server.\n        Supports both OCaml and Reason.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"processId\": os.getpid(),\n            \"clientInfo\": {\"name\": \"Serena\", \"version\": \"0.1.0\"},\n            \"locale\": \"en\",\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"capabilities\": {\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"configuration\": True,\n                },\n                \"textDocument\": {\n                    \"synchronization\": {\n                        \"dynamicRegistration\": True,\n                        \"willSave\": True,\n                        \"willSaveWaitUntil\": True,\n                        \"didSave\": True,\n                    },\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"completionItem\": {\n                            \"snippetSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                        },\n                    },\n                    \"hover\": {\n                        \"dynamicRegistration\": True,\n                        \"contentFormat\": [\"markdown\", \"plaintext\"],\n                    },\n                    \"definition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                    },\n                    \"formatting\": {\"dynamicRegistration\": True},\n                    \"rename\": {\"dynamicRegistration\": True, \"prepareSupport\": True},\n                },\n            },\n            \"trace\": \"verbose\",\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return initialize_params  # type: ignore[return-value]\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the OCaml Language Server (supports both OCaml and Reason)\n        \"\"\"\n\n        def register_capability_handler(params: Any) -> None:\n            if \"registrations\" in params:\n                for registration in params.get(\"registrations\", []):\n                    method = registration.get(\"method\", \"\")\n                    log.info(f\"OCaml LSP registered capability: {method}\")\n            return\n\n        def lang_status_handler(params: dict[str, Any]) -> None:\n            if params.get(\"type\") == \"ServiceReady\" and params.get(\"message\") == \"ServiceReady\":\n                self.server_ready.set()\n\n        def do_nothing(params: Any) -> None:\n            return\n\n        def window_log_message(msg: dict[str, Any]) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n            if \"initialization done\" in msg.get(\"message\", \"\").lower():\n                self.server_ready.set()\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"language/status\", lang_status_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting OCaml LSP server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        # Verify expected capabilities\n        capabilities = init_response.get(\"capabilities\", {})\n        log.info(f\"OCaml LSP capabilities: {list(capabilities.keys())}\")\n\n        text_doc_sync = capabilities.get(\"textDocumentSync\")\n        if isinstance(text_doc_sync, dict):\n            assert text_doc_sync.get(\"change\") == 2, \"Expected incremental sync\"\n        assert \"completionProvider\" in capabilities, \"Expected completion support\"\n\n        self.server.notify.initialized({})\n        self.completions_available.set()\n        self.server_ready.set()\n\n        log.info(\"OCaml Language Server initialized successfully\")\n"
  },
  {
    "path": "src/solidlsp/language_servers/omnisharp/initialize_params.json",
    "content": "{\n    \"_description\": \"The parameters sent by the client when initializing the language server with the \\\"initialize\\\" request. More details at https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize\",\n    \"processId\": \"os.getpid()\",\n    \"clientInfo\": {\n        \"name\": \"Visual Studio Code - Insiders\",\n        \"version\": \"1.82.0-insider\"\n    },\n    \"locale\": \"en\",\n    \"rootPath\": \"$rootPath\",\n    \"rootUri\": \"$rootUri\",\n    \"capabilities\": {\n        \"workspace\": {\n            \"applyEdit\": true,\n            \"workspaceEdit\": {\n                \"documentChanges\": true,\n                \"resourceOperations\": [\n                    \"create\",\n                    \"rename\",\n                    \"delete\"\n                ],\n                \"failureHandling\": \"textOnlyTransactional\",\n                \"normalizesLineEndings\": true,\n                \"changeAnnotationSupport\": {\n                    \"groupsOnLabel\": true\n                }\n            },\n            \"configuration\": false,\n            \"didChangeWatchedFiles\": {\n                \"dynamicRegistration\": true,\n                \"relativePatternSupport\": true\n            },\n            \"symbol\": {\n                \"dynamicRegistration\": true,\n                \"symbolKind\": {\n                    \"valueSet\": [\n                        1,\n                        2,\n                        3,\n                        4,\n                        5,\n                        6,\n                        7,\n                        8,\n                        9,\n                        10,\n                        11,\n                        12,\n                        13,\n                        14,\n                        15,\n                        16,\n                        17,\n                        18,\n                        19,\n                        20,\n                        21,\n                        22,\n                        23,\n                        24,\n                        25,\n                        26\n                    ]\n                },\n                \"tagSupport\": {\n                    \"valueSet\": [\n                        1\n                    ]\n                },\n                \"resolveSupport\": {\n                    \"properties\": [\n                        \"location.range\"\n                    ]\n                }\n            },\n            \"codeLens\": {\n                \"refreshSupport\": true\n            },\n            \"executeCommand\": {\n                \"dynamicRegistration\": true\n            },\n            \"didChangeConfiguration\": {\n                \"dynamicRegistration\": true\n            },\n            \"workspaceFolders\": true,\n            \"semanticTokens\": {\n                \"refreshSupport\": true\n            },\n            \"fileOperations\": {\n                \"dynamicRegistration\": true,\n                \"didCreate\": true,\n                \"didRename\": true,\n                \"didDelete\": true,\n                \"willCreate\": true,\n                \"willRename\": true,\n                \"willDelete\": true\n            },\n            \"inlineValue\": {\n                \"refreshSupport\": true\n            },\n            \"inlayHint\": {\n                \"refreshSupport\": true\n            },\n            \"diagnostics\": {\n                \"refreshSupport\": true\n            }\n        },\n        \"textDocument\": {\n            \"publishDiagnostics\": {\n                \"relatedInformation\": true,\n                \"versionSupport\": false,\n                \"tagSupport\": {\n                    \"valueSet\": [\n                        1,\n                        2\n                    ]\n                },\n                \"codeDescriptionSupport\": true,\n                \"dataSupport\": true\n            },\n            \"synchronization\": {\n                \"dynamicRegistration\": true,\n                \"willSave\": true,\n                \"willSaveWaitUntil\": true,\n                \"didSave\": true\n            },\n            \"completion\": {\n                \"dynamicRegistration\": true,\n                \"contextSupport\": true,\n                \"completionItem\": {\n                    \"snippetSupport\": true,\n                    \"commitCharactersSupport\": true,\n                    \"documentationFormat\": [\n                        \"markdown\",\n                        \"plaintext\"\n                    ],\n                    \"deprecatedSupport\": true,\n                    \"preselectSupport\": true,\n                    \"tagSupport\": {\n                        \"valueSet\": [\n                            1\n                        ]\n                    },\n                    \"insertReplaceSupport\": true,\n                    \"resolveSupport\": {\n                        \"properties\": [\n                            \"documentation\",\n                            \"detail\",\n                            \"additionalTextEdits\"\n                        ]\n                    },\n                    \"insertTextModeSupport\": {\n                        \"valueSet\": [\n                            1,\n                            2\n                        ]\n                    },\n                    \"labelDetailsSupport\": true\n                },\n                \"insertTextMode\": 2,\n                \"completionItemKind\": {\n                    \"valueSet\": [\n                        1,\n                        2,\n                        3,\n                        4,\n                        5,\n                        6,\n                        7,\n                        8,\n                        9,\n                        10,\n                        11,\n                        12,\n                        13,\n                        14,\n                        16,\n                        17,\n                        18,\n                        19,\n                        20,\n                        21,\n                        22,\n                        23,\n                        24,\n                        25\n                    ]\n                },\n                \"completionList\": {\n                    \"itemDefaults\": [\n                        \"commitCharacters\",\n                        \"editRange\",\n                        \"insertTextFormat\",\n                        \"insertTextMode\"\n                    ]\n                }\n            },\n            \"hover\": {\n                \"dynamicRegistration\": true,\n                \"contentFormat\": [\n                    \"markdown\",\n                    \"plaintext\"\n                ]\n            },\n            \"signatureHelp\": {\n                \"dynamicRegistration\": true,\n                \"signatureInformation\": {\n                    \"documentationFormat\": [\n                        \"markdown\",\n                        \"plaintext\"\n                    ],\n                    \"parameterInformation\": {\n                        \"labelOffsetSupport\": true\n                    },\n                    \"activeParameterSupport\": true\n                },\n                \"contextSupport\": true\n            },\n            \"definition\": {\n                \"dynamicRegistration\": true,\n                \"linkSupport\": true\n            },\n            \"references\": {\n                \"dynamicRegistration\": true\n            },\n            \"documentHighlight\": {\n                \"dynamicRegistration\": true\n            },\n            \"documentSymbol\": {\n                \"dynamicRegistration\": true,\n                \"symbolKind\": {\n                    \"valueSet\": [\n                        1,\n                        2,\n                        3,\n                        4,\n                        5,\n                        6,\n                        7,\n                        8,\n                        9,\n                        10,\n                        11,\n                        12,\n                        13,\n                        14,\n                        15,\n                        16,\n                        17,\n                        18,\n                        19,\n                        20,\n                        21,\n                        22,\n                        23,\n                        24,\n                        25,\n                        26\n                    ]\n                },\n                \"hierarchicalDocumentSymbolSupport\": true,\n                \"tagSupport\": {\n                    \"valueSet\": [\n                        1\n                    ]\n                },\n                \"labelSupport\": true\n            },\n            \"codeAction\": {\n                \"dynamicRegistration\": true,\n                \"isPreferredSupport\": true,\n                \"disabledSupport\": true,\n                \"dataSupport\": true,\n                \"resolveSupport\": {\n                    \"properties\": [\n                        \"edit\"\n                    ]\n                },\n                \"codeActionLiteralSupport\": {\n                    \"codeActionKind\": {\n                        \"valueSet\": [\n                            \"\",\n                            \"quickfix\",\n                            \"refactor\",\n                            \"refactor.extract\",\n                            \"refactor.inline\",\n                            \"refactor.rewrite\",\n                            \"source\",\n                            \"source.organizeImports\"\n                        ]\n                    }\n                },\n                \"honorsChangeAnnotations\": false\n            },\n            \"codeLens\": {\n                \"dynamicRegistration\": true\n            },\n            \"formatting\": {\n                \"dynamicRegistration\": true\n            },\n            \"rangeFormatting\": {\n                \"dynamicRegistration\": true\n            },\n            \"onTypeFormatting\": {\n                \"dynamicRegistration\": true\n            },\n            \"rename\": {\n                \"dynamicRegistration\": true,\n                \"prepareSupport\": true,\n                \"prepareSupportDefaultBehavior\": 1,\n                \"honorsChangeAnnotations\": true\n            },\n            \"documentLink\": {\n                \"dynamicRegistration\": true,\n                \"tooltipSupport\": true\n            },\n            \"typeDefinition\": {\n                \"dynamicRegistration\": true,\n                \"linkSupport\": true\n            },\n            \"implementation\": {\n                \"dynamicRegistration\": true,\n                \"linkSupport\": true\n            },\n            \"colorProvider\": {\n                \"dynamicRegistration\": true\n            },\n            \"foldingRange\": {\n                \"dynamicRegistration\": true,\n                \"rangeLimit\": 5000,\n                \"lineFoldingOnly\": true,\n                \"foldingRangeKind\": {\n                    \"valueSet\": [\n                        \"comment\",\n                        \"imports\",\n                        \"region\"\n                    ]\n                },\n                \"foldingRange\": {\n                    \"collapsedText\": false\n                }\n            },\n            \"declaration\": {\n                \"dynamicRegistration\": true,\n                \"linkSupport\": true\n            },\n            \"selectionRange\": {\n                \"dynamicRegistration\": true\n            },\n            \"callHierarchy\": {\n                \"dynamicRegistration\": true\n            },\n            \"semanticTokens\": {\n                \"dynamicRegistration\": true,\n                \"tokenTypes\": [\n                    \"namespace\",\n                    \"type\",\n                    \"class\",\n                    \"enum\",\n                    \"interface\",\n                    \"struct\",\n                    \"typeParameter\",\n                    \"parameter\",\n                    \"variable\",\n                    \"property\",\n                    \"enumMember\",\n                    \"event\",\n                    \"function\",\n                    \"method\",\n                    \"macro\",\n                    \"keyword\",\n                    \"modifier\",\n                    \"comment\",\n                    \"string\",\n                    \"number\",\n                    \"regexp\",\n                    \"operator\",\n                    \"decorator\"\n                ],\n                \"tokenModifiers\": [\n                    \"declaration\",\n                    \"definition\",\n                    \"readonly\",\n                    \"static\",\n                    \"deprecated\",\n                    \"abstract\",\n                    \"async\",\n                    \"modification\",\n                    \"documentation\",\n                    \"defaultLibrary\"\n                ],\n                \"formats\": [\n                    \"relative\"\n                ],\n                \"requests\": {\n                    \"range\": true,\n                    \"full\": {\n                        \"delta\": true\n                    }\n                },\n                \"multilineTokenSupport\": false,\n                \"overlappingTokenSupport\": false,\n                \"serverCancelSupport\": true,\n                \"augmentsSyntaxTokens\": false\n            },\n            \"linkedEditingRange\": {\n                \"dynamicRegistration\": true\n            },\n            \"typeHierarchy\": {\n                \"dynamicRegistration\": true\n            },\n            \"inlineValue\": {\n                \"dynamicRegistration\": true\n            },\n            \"inlayHint\": {\n                \"dynamicRegistration\": true,\n                \"resolveSupport\": {\n                    \"properties\": [\n                        \"tooltip\",\n                        \"textEdits\",\n                        \"label.tooltip\",\n                        \"label.location\",\n                        \"label.command\"\n                    ]\n                }\n            },\n            \"diagnostic\": {\n                \"dynamicRegistration\": true,\n                \"relatedDocumentSupport\": false\n            }\n        },\n        \"window\": {\n            \"showMessage\": {\n                \"messageActionItem\": {\n                    \"additionalPropertiesSupport\": true\n                }\n            },\n            \"showDocument\": {\n                \"support\": true\n            },\n            \"workDoneProgress\": true\n        },\n        \"general\": {\n            \"staleRequestSupport\": {\n                \"cancel\": true,\n                \"retryOnContentModified\": [\n                    \"textDocument/semanticTokens/full\",\n                    \"textDocument/semanticTokens/range\",\n                    \"textDocument/semanticTokens/full/delta\"\n                ]\n            },\n            \"regularExpressions\": {\n                \"engine\": \"ECMAScript\",\n                \"version\": \"ES2020\"\n            },\n            \"markdown\": {\n                \"parser\": \"marked\",\n                \"version\": \"1.1.0\",\n                \"allowedTags\": [\n                    \"ul\",\n                    \"li\",\n                    \"p\",\n                    \"code\",\n                    \"blockquote\",\n                    \"ol\",\n                    \"h1\",\n                    \"h2\",\n                    \"h3\",\n                    \"h4\",\n                    \"h5\",\n                    \"h6\",\n                    \"hr\",\n                    \"em\",\n                    \"pre\",\n                    \"table\",\n                    \"thead\",\n                    \"tbody\",\n                    \"tr\",\n                    \"th\",\n                    \"td\",\n                    \"div\",\n                    \"del\",\n                    \"a\",\n                    \"strong\",\n                    \"br\",\n                    \"img\",\n                    \"span\"\n                ]\n            },\n            \"positionEncodings\": [\n                \"utf-16\"\n            ]\n        },\n        \"notebookDocument\": {\n            \"synchronization\": {\n                \"dynamicRegistration\": true,\n                \"executionSummarySupport\": true\n            }\n        },\n        \"experimental\": {\n            \"snippetTextEdit\": true,\n            \"codeActionGroup\": true,\n            \"hoverActions\": true,\n            \"serverStatusNotification\": true,\n            \"colorDiagnosticOutput\": true,\n            \"openServerLogs\": true,\n            \"commands\": {\n                \"commands\": [\n                    \"editor.action.triggerParameterHints\"\n                ]\n            }\n        }\n    },\n    \"initializationOptions\": {\n        \"RoslynExtensionsOptions\": {\n            \"EnableDecompilationSupport\": false,\n            \"EnableAnalyzersSupport\": true,\n            \"EnableImportCompletion\": true,\n            \"EnableAsyncCompletion\": false,\n            \"DocumentAnalysisTimeoutMs\": 30000,\n            \"DiagnosticWorkersThreadCount\": 18,\n            \"AnalyzeOpenDocumentsOnly\": true,\n            \"InlayHintsOptions\": {\n                \"EnableForParameters\": false,\n                \"ForLiteralParameters\": false,\n                \"ForIndexerParameters\": false,\n                \"ForObjectCreationParameters\": false,\n                \"ForOtherParameters\": false,\n                \"SuppressForParametersThatDifferOnlyBySuffix\": false,\n                \"SuppressForParametersThatMatchMethodIntent\": false,\n                \"SuppressForParametersThatMatchArgumentName\": false,\n                \"EnableForTypes\": false,\n                \"ForImplicitVariableTypes\": false,\n                \"ForLambdaParameterTypes\": false,\n                \"ForImplicitObjectCreation\": false\n            },\n            \"LocationPaths\": null\n        },\n        \"FormattingOptions\": {\n            \"OrganizeImports\": false,\n            \"EnableEditorConfigSupport\": true,\n            \"NewLine\": \"\\n\",\n            \"UseTabs\": false,\n            \"TabSize\": 4,\n            \"IndentationSize\": 4,\n            \"SpacingAfterMethodDeclarationName\": false,\n            \"SeparateImportDirectiveGroups\": false,\n            \"SpaceWithinMethodDeclarationParenthesis\": false,\n            \"SpaceBetweenEmptyMethodDeclarationParentheses\": false,\n            \"SpaceAfterMethodCallName\": false,\n            \"SpaceWithinMethodCallParentheses\": false,\n            \"SpaceBetweenEmptyMethodCallParentheses\": false,\n            \"SpaceAfterControlFlowStatementKeyword\": true,\n            \"SpaceWithinExpressionParentheses\": false,\n            \"SpaceWithinCastParentheses\": false,\n            \"SpaceWithinOtherParentheses\": false,\n            \"SpaceAfterCast\": false,\n            \"SpaceBeforeOpenSquareBracket\": false,\n            \"SpaceBetweenEmptySquareBrackets\": false,\n            \"SpaceWithinSquareBrackets\": false,\n            \"SpaceAfterColonInBaseTypeDeclaration\": true,\n            \"SpaceAfterComma\": true,\n            \"SpaceAfterDot\": false,\n            \"SpaceAfterSemicolonsInForStatement\": true,\n            \"SpaceBeforeColonInBaseTypeDeclaration\": true,\n            \"SpaceBeforeComma\": false,\n            \"SpaceBeforeDot\": false,\n            \"SpaceBeforeSemicolonsInForStatement\": false,\n            \"SpacingAroundBinaryOperator\": \"single\",\n            \"IndentBraces\": false,\n            \"IndentBlock\": true,\n            \"IndentSwitchSection\": true,\n            \"IndentSwitchCaseSection\": true,\n            \"IndentSwitchCaseSectionWhenBlock\": true,\n            \"LabelPositioning\": \"oneLess\",\n            \"WrappingPreserveSingleLine\": true,\n            \"WrappingKeepStatementsOnSingleLine\": true,\n            \"NewLinesForBracesInTypes\": true,\n            \"NewLinesForBracesInMethods\": true,\n            \"NewLinesForBracesInProperties\": true,\n            \"NewLinesForBracesInAccessors\": true,\n            \"NewLinesForBracesInAnonymousMethods\": true,\n            \"NewLinesForBracesInControlBlocks\": true,\n            \"NewLinesForBracesInAnonymousTypes\": true,\n            \"NewLinesForBracesInObjectCollectionArrayInitializers\": true,\n            \"NewLinesForBracesInLambdaExpressionBody\": true,\n            \"NewLineForElse\": true,\n            \"NewLineForCatch\": true,\n            \"NewLineForFinally\": true,\n            \"NewLineForMembersInObjectInit\": true,\n            \"NewLineForMembersInAnonymousTypes\": true,\n            \"NewLineForClausesInQuery\": true\n        },\n        \"FileOptions\": {\n            \"SystemExcludeSearchPatterns\": [\n                \"**/node_modules/**/*\",\n                \"**/bin/**/*\",\n                \"**/obj/**/*\",\n                \"**/.git/**/*\",\n                \"**/.git\",\n                \"**/.svn\",\n                \"**/.hg\",\n                \"**/CVS\",\n                \"**/.DS_Store\",\n                \"**/Thumbs.db\"\n            ],\n            \"ExcludeSearchPatterns\": []\n        },\n        \"RenameOptions\": {\n            \"RenameOverloads\": false,\n            \"RenameInStrings\": false,\n            \"RenameInComments\": false\n        },\n        \"ImplementTypeOptions\": {\n            \"InsertionBehavior\": 0,\n            \"PropertyGenerationBehavior\": 0\n        },\n        \"DotNetCliOptions\": {\n            \"LocationPaths\": null\n        },\n        \"Plugins\": {\n            \"LocationPaths\": null\n        }\n    },\n    \"trace\": \"verbose\",\n    \"workspaceFolders\": [\n        {\n            \"uri\": \"$uri\",\n            \"name\": \"$name\"\n        }\n    ]\n}"
  },
  {
    "path": "src/solidlsp/language_servers/omnisharp/runtime_dependencies.json",
    "content": "{\n    \"_description\": \"Used to download the runtime dependencies for running OmniSharp. Obtained from https://github.com/dotnet/vscode-csharp/blob/main/package.json\",\n    \"runtimeDependencies\": [\n        {\n            \"id\": \"OmniSharp\",\n            \"description\": \"OmniSharp for Windows (.NET 4 / x86)\",\n            \"url\": \"https://roslynomnisharp.blob.core.windows.net/releases/1.39.10/omnisharp-win-x86-1.39.10.zip\",\n            \"installPath\": \".omnisharp/1.39.10\",\n            \"platforms\": [\n                \"win32\"\n            ],\n            \"architectures\": [\n                \"x86\"\n            ],\n            \"installTestPath\": \"./.omnisharp/1.39.10/OmniSharp.exe\",\n            \"platformId\": \"win-x86\",\n            \"isFramework\": true,\n            \"integrity\": \"C81CE2099AD494EF63F9D88FAA70D55A68CF175810F944526FF94AAC7A5109F9\",\n            \"dotnet_version\": \"4\",\n            \"binaryName\": \"OmniSharp.exe\"\n        },\n        {\n            \"id\": \"OmniSharp\",\n            \"description\": \"OmniSharp for Windows (.NET 6 / x86)\",\n            \"url\": \"https://roslynomnisharp.blob.core.windows.net/releases/1.39.10/omnisharp-win-x86-net6.0-1.39.10.zip\",\n            \"installPath\": \".omnisharp/1.39.10-net6.0\",\n            \"platforms\": [\n                \"win32\"\n            ],\n            \"architectures\": [\n                \"x86\"\n            ],\n            \"installTestPath\": \"./.omnisharp/1.39.10-net6.0/OmniSharp.dll\",\n            \"platformId\": \"win-x86\",\n            \"isFramework\": false,\n            \"integrity\": \"B7E62415CFC3DAC2154AC636C5BF0FB4B2C9BBF11B5A1FBF72381DDDED59791E\",\n            \"dotnet_version\": \"6\",\n            \"binaryName\": \"OmniSharp.exe\"\n        },\n        {\n            \"id\": \"OmniSharp\",\n            \"description\": \"OmniSharp for Windows (.NET 4 / x64)\",\n            \"url\": \"https://roslynomnisharp.blob.core.windows.net/releases/1.39.10/omnisharp-win-x64-1.39.10.zip\",\n            \"installPath\": \".omnisharp/1.39.10\",\n            \"platforms\": [\n                \"win32\"\n            ],\n            \"architectures\": [\n                \"x86_64\"\n            ],\n            \"installTestPath\": \"./.omnisharp/1.39.10/OmniSharp.exe\",\n            \"platformId\": \"win-x64\",\n            \"isFramework\": true,\n            \"integrity\": \"BE0ED10AACEA17E14B78BD0D887DE5935D4ECA3712192A701F3F2100CA3C8B6E\",\n            \"dotnet_version\": \"4\",\n            \"binaryName\": \"OmniSharp.exe\"\n        },\n        {\n            \"id\": \"OmniSharp\",\n            \"description\": \"OmniSharp for Windows (.NET 6 / x64)\",\n            \"url\": \"https://roslynomnisharp.blob.core.windows.net/releases/1.39.10/omnisharp-win-x64-net6.0-1.39.10.zip\",\n            \"installPath\": \".omnisharp/1.39.10-net6.0\",\n            \"platforms\": [\n                \"win32\"\n            ],\n            \"architectures\": [\n                \"x86_64\"\n            ],\n            \"installTestPath\": \"./.omnisharp/1.39.10-net6.0/OmniSharp.dll\",\n            \"platformId\": \"win-x64\",\n            \"isFramework\": false,\n            \"integrity\": \"A73327395E7EF92C1D8E307055463DA412662C03F077ECC743462FD2760BB537\",\n            \"dotnet_version\": \"6\",\n            \"binaryName\": \"OmniSharp.exe\"\n        },\n        {\n            \"id\": \"OmniSharp\",\n            \"description\": \"OmniSharp for Windows (.NET 4 / arm64)\",\n            \"url\": \"https://roslynomnisharp.blob.core.windows.net/releases/1.39.10/omnisharp-win-arm64-1.39.10.zip\",\n            \"installPath\": \".omnisharp/1.39.10\",\n            \"platforms\": [\n                \"win32\"\n            ],\n            \"architectures\": [\n                \"arm64\"\n            ],\n            \"installTestPath\": \"./.omnisharp/1.39.10/OmniSharp.exe\",\n            \"platformId\": \"win-arm64\",\n            \"isFramework\": true,\n            \"integrity\": \"32FA0067B0639F87760CD1A769B16E6A53588C137C4D31661836CA4FB28D3DD6\",\n            \"dotnet_version\": \"4\",\n            \"binaryName\": \"OmniSharp.exe\"\n        },\n        {\n            \"id\": \"OmniSharp\",\n            \"description\": \"OmniSharp for Windows (.NET 6 / arm64)\",\n            \"url\": \"https://roslynomnisharp.blob.core.windows.net/releases/1.39.10/omnisharp-win-arm64-net6.0-1.39.10.zip\",\n            \"installPath\": \".omnisharp/1.39.10-net6.0\",\n            \"platforms\": [\n                \"win32\"\n            ],\n            \"architectures\": [\n                \"arm64\"\n            ],\n            \"installTestPath\": \"./.omnisharp/1.39.10-net6.0/OmniSharp.dll\",\n            \"platformId\": \"win-arm64\",\n            \"isFramework\": false,\n            \"integrity\": \"433F9B360CAA7B4DDD85C604D5C5542C1A718BCF2E71B2BCFC7526E6D41F4E8F\",\n            \"dotnet_version\": \"6\",\n            \"binaryName\": \"OmniSharp.exe\"\n        },\n        {\n            \"id\": \"OmniSharp\",\n            \"description\": \"OmniSharp for OSX (Mono / x64)\",\n            \"url\": \"https://roslynomnisharp.blob.core.windows.net/releases/1.39.10/omnisharp-osx-1.39.10.zip\",\n            \"installPath\": \".omnisharp/1.39.10\",\n            \"platforms\": [\n                \"darwin\"\n            ],\n            \"architectures\": [\n                \"x86_64\",\n                \"arm64\"\n            ],\n            \"binaries\": [\n                \"./mono.osx\",\n                \"./run\"\n            ],\n            \"installTestPath\": \"./.omnisharp/1.39.10/run\",\n            \"platformId\": \"osx\",\n            \"isFramework\": true,\n            \"integrity\": \"2CC42F0EC7C30CFA8858501D12ECB6FB685A1FCFB8ECB35698A4B12406551968\",\n            \"dotnet_version\": \"mono\"\n        },\n        {\n            \"id\": \"OmniSharp\",\n            \"description\": \"OmniSharp for OSX (.NET 6 / x64)\",\n            \"url\": \"https://roslynomnisharp.blob.core.windows.net/releases/1.39.10/omnisharp-osx-x64-net6.0-1.39.10.zip\",\n            \"installPath\": \".omnisharp/1.39.10-net6.0\",\n            \"platforms\": [\n                \"darwin\"\n            ],\n            \"architectures\": [\n                \"x86_64\"\n            ],\n            \"installTestPath\": \"./.omnisharp/1.39.10-net6.0/OmniSharp.dll\",\n            \"platformId\": \"osx-x64\",\n            \"isFramework\": false,\n            \"integrity\": \"C9D6E9F2C839A66A7283AE6A9EC545EE049B48EB230D33E91A6322CB67FF9D97\",\n            \"dotnet_version\": \"6\"\n        },\n        {\n            \"id\": \"OmniSharp\",\n            \"description\": \"OmniSharp for OSX (.NET 6 / arm64)\",\n            \"url\": \"https://roslynomnisharp.blob.core.windows.net/releases/1.39.10/omnisharp-osx-arm64-net6.0-1.39.10.zip\",\n            \"installPath\": \".omnisharp/1.39.10-net6.0\",\n            \"platforms\": [\n                \"darwin\"\n            ],\n            \"architectures\": [\n                \"arm64\"\n            ],\n            \"installTestPath\": \"./.omnisharp/1.39.10-net6.0/OmniSharp.dll\",\n            \"platformId\": \"osx-arm64\",\n            \"isFramework\": false,\n            \"integrity\": \"851350F52F83E3BAD5A92D113E4B9882FCD1DEB16AA84FF94B6F2CEE3C70051E\",\n            \"dotnet_version\": \"6\"\n        },\n        {\n            \"id\": \"OmniSharp\",\n            \"description\": \"OmniSharp for Linux (Mono / x86)\",\n            \"url\": \"https://roslynomnisharp.blob.core.windows.net/releases/1.39.10/omnisharp-linux-x86-1.39.10.zip\",\n            \"installPath\": \".omnisharp/1.39.10\",\n            \"platforms\": [\n                \"linux\"\n            ],\n            \"architectures\": [\n                \"x86\",\n                \"i686\"\n            ],\n            \"binaries\": [\n                \"./mono.linux-x86\",\n                \"./run\"\n            ],\n            \"installTestPath\": \"./.omnisharp/1.39.10/run\",\n            \"platformId\": \"linux-x86\",\n            \"isFramework\": true,\n            \"integrity\": \"474B1CDBAE64CFEC655FB6B0659BCE481023C48274441C72991E67B6E13E56A1\",\n            \"dotnet_version\": \"mono\"\n        },\n        {\n            \"id\": \"OmniSharp\",\n            \"description\": \"OmniSharp for Linux (Mono / x64)\",\n            \"url\": \"https://roslynomnisharp.blob.core.windows.net/releases/1.39.10/omnisharp-linux-x64-1.39.10.zip\",\n            \"installPath\": \".omnisharp/1.39.10\",\n            \"platforms\": [\n                \"linux\"\n            ],\n            \"architectures\": [\n                \"x86_64\"\n            ],\n            \"binaries\": [\n                \"./mono.linux-x86_64\",\n                \"./run\"\n            ],\n            \"installTestPath\": \"./.omnisharp/1.39.10/run\",\n            \"platformId\": \"linux-x64\",\n            \"isFramework\": true,\n            \"integrity\": \"FB4CAA47343265100349375D79DBCCE1868950CED675CB07FCBE8462EDBCDD37\",\n            \"dotnet_version\": \"mono\"\n        },\n        {\n            \"id\": \"OmniSharp\",\n            \"description\": \"OmniSharp for Linux (.NET 6 / x64)\",\n            \"url\": \"https://roslynomnisharp.blob.core.windows.net/releases/1.39.10/omnisharp-linux-x64-net6.0-1.39.10.zip\",\n            \"installPath\": \".omnisharp/1.39.10-net6.0\",\n            \"platforms\": [\n                \"linux\"\n            ],\n            \"architectures\": [\n                \"x86_64\"\n            ],\n            \"installTestPath\": \"./.omnisharp/1.39.10-net6.0/OmniSharp.dll\",\n            \"platformId\": \"linux-x64\",\n            \"isFramework\": false,\n            \"integrity\": \"0926D3BEA060BF4373356B2FC0A68C10D0DE1B1150100B551BA5932814CE51E2\",\n            \"dotnet_version\": \"6\",\n            \"binaryName\": \"OmniSharp\"\n        },\n        {\n            \"id\": \"OmniSharp\",\n            \"description\": \"OmniSharp for Linux (Mono / arm64)\",\n            \"url\": \"https://roslynomnisharp.blob.core.windows.net/releases/1.39.10/omnisharp-linux-arm64-1.39.10.zip\",\n            \"installPath\": \".omnisharp/1.39.10\",\n            \"platforms\": [\n                \"linux\"\n            ],\n            \"architectures\": [\n                \"arm64\"\n            ],\n            \"binaries\": [\n                \"./mono.linux-arm64\",\n                \"./run\"\n            ],\n            \"installTestPath\": \"./.omnisharp/1.39.10/run\",\n            \"platformId\": \"linux-arm64\",\n            \"isFramework\": true,\n            \"integrity\": \"478F3594DFD0167E9A56E36F0364A86C73F8132A3E7EA916CA1419EFE141D2CC\",\n            \"dotnet_version\": \"mono\"\n        },\n        {\n            \"id\": \"OmniSharp\",\n            \"description\": \"OmniSharp for Linux (.NET 6 / arm64)\",\n            \"url\": \"https://roslynomnisharp.blob.core.windows.net/releases/1.39.10/omnisharp-linux-arm64-net6.0-1.39.10.zip\",\n            \"installPath\": \".omnisharp/1.39.10-net6.0\",\n            \"platforms\": [\n                \"linux\"\n            ],\n            \"architectures\": [\n                \"arm64\"\n            ],\n            \"installTestPath\": \"./.omnisharp/1.39.10-net6.0/OmniSharp.dll\",\n            \"platformId\": \"linux-arm64\",\n            \"isFramework\": false,\n            \"integrity\": \"6FB6A572043A74220A92F6C19C7BB0C3743321C7563A815FD2702EF4FA7D688E\",\n            \"dotnet_version\": \"6\"\n        },\n        {\n            \"id\": \"OmniSharp\",\n            \"description\": \"OmniSharp for Linux musl (.NET 6 / x64)\",\n            \"url\": \"https://roslynomnisharp.blob.core.windows.net/releases/1.39.10/omnisharp-linux-musl-x64-net6.0-1.39.10.zip\",\n            \"installPath\": \".omnisharp/1.39.10-net6.0\",\n            \"platforms\": [\n                \"linux-musl\"\n            ],\n            \"architectures\": [\n                \"x86_64\"\n            ],\n            \"installTestPath\": \"./.omnisharp/1.39.10-net6.0/OmniSharp.dll\",\n            \"platformId\": \"linux-musl-x64\",\n            \"isFramework\": false,\n            \"integrity\": \"6BFDA3AD11DBB0C6514B86ECC3E1597CC41C6E309B7575F7C599E07D9E2AE610\",\n            \"dotnet_version\": \"6\"\n        },\n        {\n            \"id\": \"OmniSharp\",\n            \"description\": \"OmniSharp for Linux musl (.NET 6 / arm64)\",\n            \"url\": \"https://roslynomnisharp.blob.core.windows.net/releases/1.39.10/omnisharp-linux-musl-arm64-net6.0-1.39.10.zip\",\n            \"installPath\": \".omnisharp/1.39.10-net6.0\",\n            \"platforms\": [\n                \"linux-musl\"\n            ],\n            \"architectures\": [\n                \"arm64\"\n            ],\n            \"installTestPath\": \"./.omnisharp/1.39.10-net6.0/OmniSharp.dll\",\n            \"platformId\": \"linux-musl-arm64\",\n            \"isFramework\": false,\n            \"integrity\": \"DA63619EA024EB9BBF6DB5A85C6150CAB5C0BD554544A3596ED1B17F926D6875\",\n            \"dotnet_version\": \"6\"\n        },\n        {\n            \"id\": \"RazorOmnisharp\",\n            \"description\": \"Razor Language Server for OmniSharp (Windows / x64)\",\n            \"url\": \"https://download.visualstudio.microsoft.com/download/pr/aee63398-023f-48db-bba2-30162c68f0c4/8d42e62ea4051381c219b3e31bc4eced/razorlanguageserver-win-x64-7.0.0-preview.23363.1.zip\",\n            \"installPath\": \".razoromnisharp\",\n            \"platforms\": [\n                \"win32\"\n            ],\n            \"architectures\": [\n                \"x86_64\"\n            ],\n            \"platformId\": \"win-x64\",\n            \"dll_path\": \"OmniSharpPlugin/Microsoft.AspNetCore.Razor.OmniSharpPlugin.dll\"\n        },\n        {\n            \"id\": \"RazorOmnisharp\",\n            \"description\": \"Razor Language Server for OmniSharp (Windows / x86)\",\n            \"url\": \"https://download.visualstudio.microsoft.com/download/pr/aee63398-023f-48db-bba2-30162c68f0c4/e440c4f3a4a96334fe177513935fa010/razorlanguageserver-win-x86-7.0.0-preview.23363.1.zip\",\n            \"installPath\": \".razoromnisharp\",\n            \"platforms\": [\n                \"win32\"\n            ],\n            \"architectures\": [\n                \"x86\"\n            ],\n            \"platformId\": \"win-x86\",\n            \"dll_path\": \"OmniSharpPlugin/Microsoft.AspNetCore.Razor.OmniSharpPlugin.dll\"\n        },\n        {\n            \"id\": \"RazorOmnisharp\",\n            \"description\": \"Razor Language Server for OmniSharp (Windows / ARM64)\",\n            \"url\": \"https://download.visualstudio.microsoft.com/download/pr/aee63398-023f-48db-bba2-30162c68f0c4/4ef26e45cf32fe8d51c0e7dd21f1fef6/razorlanguageserver-win-arm64-7.0.0-preview.23363.1.zip\",\n            \"installPath\": \".razoromnisharp\",\n            \"platforms\": [\n                \"win32\"\n            ],\n            \"architectures\": [\n                \"arm64\"\n            ],\n            \"platformId\": \"win-arm64\",\n            \"dll_path\": \"OmniSharpPlugin/Microsoft.AspNetCore.Razor.OmniSharpPlugin.dll\"\n        },\n        {\n            \"id\": \"RazorOmnisharp\",\n            \"description\": \"Razor Language Server for OmniSharp (Linux / x64)\",\n            \"url\": \"https://download.visualstudio.microsoft.com/download/pr/aee63398-023f-48db-bba2-30162c68f0c4/6d4e23a3c7cf0465743950a39515a716/razorlanguageserver-linux-x64-7.0.0-preview.23363.1.zip\",\n            \"installPath\": \".razoromnisharp\",\n            \"platforms\": [\n                \"linux\"\n            ],\n            \"architectures\": [\n                \"x86_64\"\n            ],\n            \"binaries\": [\n                \"./rzls\"\n            ],\n            \"platformId\": \"linux-x64\",\n            \"dll_path\": \"OmniSharpPlugin/Microsoft.AspNetCore.Razor.OmniSharpPlugin.dll\"\n        },\n        {\n            \"id\": \"RazorOmnisharp\",\n            \"description\": \"Razor Language Server for OmniSharp (Linux ARM64)\",\n            \"url\": \"https://download.visualstudio.microsoft.com/download/pr/aee63398-023f-48db-bba2-30162c68f0c4/85deebd44647ebf65724cc291d722283/razorlanguageserver-linux-arm64-7.0.0-preview.23363.1.zip\",\n            \"installPath\": \".razoromnisharp\",\n            \"platforms\": [\n                \"linux\"\n            ],\n            \"architectures\": [\n                \"arm64\"\n            ],\n            \"binaries\": [\n                \"./rzls\"\n            ],\n            \"platformId\": \"linux-arm64\"\n        },\n        {\n            \"id\": \"RazorOmnisharp\",\n            \"description\": \"Razor Language Server for OmniSharp (Linux musl / x64)\",\n            \"url\": \"https://download.visualstudio.microsoft.com/download/pr/aee63398-023f-48db-bba2-30162c68f0c4/4f0caa94ae182785655efb15eafcef23/razorlanguageserver-linux-musl-x64-7.0.0-preview.23363.1.zip\",\n            \"installPath\": \".razoromnisharp\",\n            \"platforms\": [\n                \"linux-musl\"\n            ],\n            \"architectures\": [\n                \"x86_64\"\n            ],\n            \"binaries\": [\n                \"./rzls\"\n            ],\n            \"platformId\": \"linux-musl-x64\"\n        },\n        {\n            \"id\": \"RazorOmnisharp\",\n            \"description\": \"Razor Language Server for OmniSharp (Linux musl ARM64)\",\n            \"url\": \"https://download.visualstudio.microsoft.com/download/pr/aee63398-023f-48db-bba2-30162c68f0c4/0a24828206a6f3b4bc743d058ef88ce7/razorlanguageserver-linux-musl-arm64-7.0.0-preview.23363.1.zip\",\n            \"installPath\": \".razoromnisharp\",\n            \"platforms\": [\n                \"linux-musl\"\n            ],\n            \"architectures\": [\n                \"arm64\"\n            ],\n            \"binaries\": [\n                \"./rzls\"\n            ],\n            \"platformId\": \"linux-musl-arm64\"\n        },\n        {\n            \"id\": \"RazorOmnisharp\",\n            \"description\": \"Razor Language Server for OmniSharp (macOS / x64)\",\n            \"url\": \"https://download.visualstudio.microsoft.com/download/pr/aee63398-023f-48db-bba2-30162c68f0c4/2afcafaf41082989efcc10405abb9314/razorlanguageserver-osx-x64-7.0.0-preview.23363.1.zip\",\n            \"installPath\": \".razoromnisharp\",\n            \"platforms\": [\n                \"darwin\"\n            ],\n            \"architectures\": [\n                \"x86_64\"\n            ],\n            \"binaries\": [\n                \"./rzls\"\n            ],\n            \"platformId\": \"osx-x64\"\n        },\n        {\n            \"id\": \"RazorOmnisharp\",\n            \"description\": \"Razor Language Server for OmniSharp (macOS ARM64)\",\n            \"url\": \"https://download.visualstudio.microsoft.com/download/pr/aee63398-023f-48db-bba2-30162c68f0c4/8bf2ed2f00d481a5987e3eb5165afddd/razorlanguageserver-osx-arm64-7.0.0-preview.23363.1.zip\",\n            \"installPath\": \".razoromnisharp\",\n            \"platforms\": [\n                \"darwin\"\n            ],\n            \"architectures\": [\n                \"arm64\"\n            ],\n            \"binaries\": [\n                \"./rzls\"\n            ],\n            \"platformId\": \"osx-arm64\"\n        }\n    ]\n}"
  },
  {
    "path": "src/solidlsp/language_servers/omnisharp/workspace_did_change_configuration.json",
    "content": "{\n    \"RoslynExtensionsOptions\": {\n        \"EnableDecompilationSupport\": false,\n        \"EnableAnalyzersSupport\": true,\n        \"EnableImportCompletion\": true,\n        \"EnableAsyncCompletion\": false,\n        \"DocumentAnalysisTimeoutMs\": 30000,\n        \"DiagnosticWorkersThreadCount\": 18,\n        \"AnalyzeOpenDocumentsOnly\": true,\n        \"InlayHintsOptions\": {\n            \"EnableForParameters\": false,\n            \"ForLiteralParameters\": false,\n            \"ForIndexerParameters\": false,\n            \"ForObjectCreationParameters\": false,\n            \"ForOtherParameters\": false,\n            \"SuppressForParametersThatDifferOnlyBySuffix\": false,\n            \"SuppressForParametersThatMatchMethodIntent\": false,\n            \"SuppressForParametersThatMatchArgumentName\": false,\n            \"EnableForTypes\": false,\n            \"ForImplicitVariableTypes\": false,\n            \"ForLambdaParameterTypes\": false,\n            \"ForImplicitObjectCreation\": false\n        },\n        \"LocationPaths\": null\n    },\n    \"FormattingOptions\": {\n        \"OrganizeImports\": false,\n        \"EnableEditorConfigSupport\": true,\n        \"NewLine\": \"\\n\",\n        \"UseTabs\": false,\n        \"TabSize\": 4,\n        \"IndentationSize\": 4,\n        \"SpacingAfterMethodDeclarationName\": false,\n        \"SeparateImportDirectiveGroups\": false,\n        \"SpaceWithinMethodDeclarationParenthesis\": false,\n        \"SpaceBetweenEmptyMethodDeclarationParentheses\": false,\n        \"SpaceAfterMethodCallName\": false,\n        \"SpaceWithinMethodCallParentheses\": false,\n        \"SpaceBetweenEmptyMethodCallParentheses\": false,\n        \"SpaceAfterControlFlowStatementKeyword\": true,\n        \"SpaceWithinExpressionParentheses\": false,\n        \"SpaceWithinCastParentheses\": false,\n        \"SpaceWithinOtherParentheses\": false,\n        \"SpaceAfterCast\": false,\n        \"SpaceBeforeOpenSquareBracket\": false,\n        \"SpaceBetweenEmptySquareBrackets\": false,\n        \"SpaceWithinSquareBrackets\": false,\n        \"SpaceAfterColonInBaseTypeDeclaration\": true,\n        \"SpaceAfterComma\": true,\n        \"SpaceAfterDot\": false,\n        \"SpaceAfterSemicolonsInForStatement\": true,\n        \"SpaceBeforeColonInBaseTypeDeclaration\": true,\n        \"SpaceBeforeComma\": false,\n        \"SpaceBeforeDot\": false,\n        \"SpaceBeforeSemicolonsInForStatement\": false,\n        \"SpacingAroundBinaryOperator\": \"single\",\n        \"IndentBraces\": false,\n        \"IndentBlock\": true,\n        \"IndentSwitchSection\": true,\n        \"IndentSwitchCaseSection\": true,\n        \"IndentSwitchCaseSectionWhenBlock\": true,\n        \"LabelPositioning\": \"oneLess\",\n        \"WrappingPreserveSingleLine\": true,\n        \"WrappingKeepStatementsOnSingleLine\": true,\n        \"NewLinesForBracesInTypes\": true,\n        \"NewLinesForBracesInMethods\": true,\n        \"NewLinesForBracesInProperties\": true,\n        \"NewLinesForBracesInAccessors\": true,\n        \"NewLinesForBracesInAnonymousMethods\": true,\n        \"NewLinesForBracesInControlBlocks\": true,\n        \"NewLinesForBracesInAnonymousTypes\": true,\n        \"NewLinesForBracesInObjectCollectionArrayInitializers\": true,\n        \"NewLinesForBracesInLambdaExpressionBody\": true,\n        \"NewLineForElse\": true,\n        \"NewLineForCatch\": true,\n        \"NewLineForFinally\": true,\n        \"NewLineForMembersInObjectInit\": true,\n        \"NewLineForMembersInAnonymousTypes\": true,\n        \"NewLineForClausesInQuery\": true\n    },\n    \"FileOptions\": {\n        \"SystemExcludeSearchPatterns\": [\n            \"**/node_modules/**/*\",\n            \"**/bin/**/*\",\n            \"**/obj/**/*\",\n            \"**/.git/**/*\",\n            \"**/.git\",\n            \"**/.svn\",\n            \"**/.hg\",\n            \"**/CVS\",\n            \"**/.DS_Store\",\n            \"**/Thumbs.db\"\n        ],\n        \"ExcludeSearchPatterns\": []\n    },\n    \"RenameOptions\": {\n        \"RenameOverloads\": false,\n        \"RenameInStrings\": false,\n        \"RenameInComments\": false\n    },\n    \"ImplementTypeOptions\": {\n        \"InsertionBehavior\": 0,\n        \"PropertyGenerationBehavior\": 0\n    },\n    \"DotNetCliOptions\": {\n        \"LocationPaths\": null\n    },\n    \"Plugins\": {\n        \"LocationPaths\": null\n    }\n}"
  },
  {
    "path": "src/solidlsp/language_servers/omnisharp.py",
    "content": "\"\"\"\nProvides C# specific instantiation of the LanguageServer class. Contains various configurations and settings specific to C#.\n\"\"\"\n\nimport json\nimport logging\nimport os\nimport pathlib\nimport threading\nfrom collections.abc import Iterable\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.ls_exceptions import SolidLSPException\nfrom solidlsp.ls_utils import DotnetVersion, FileUtils, PlatformId, PlatformUtils\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\ndef breadth_first_file_scan(root: str) -> Iterable[str]:\n    \"\"\"\n    This function was obtained from https://stackoverflow.com/questions/49654234/is-there-a-breadth-first-search-option-available-in-os-walk-or-equivalent-py\n    It traverses the directory tree in breadth first order.\n    \"\"\"\n    dirs = [root]\n    # while we has dirs to scan\n    while dirs:\n        next_dirs = []\n        for parent in dirs:\n            # scan each dir\n            for f in os.listdir(parent):\n                # if there is a dir, then save for next ittr\n                # if it  is a file then yield it (we'll return later)\n                ff = os.path.join(parent, f)\n                if os.path.isdir(ff):\n                    next_dirs.append(ff)\n                else:\n                    yield ff\n\n        # once we've done all the current dirs then\n        # we set up the next itter as the child dirs\n        # from the current itter.\n        dirs = next_dirs\n\n\ndef find_least_depth_sln_file(root_dir: str) -> str | None:\n    for filename in breadth_first_file_scan(root_dir):\n        if filename.endswith(\".sln\"):\n            return filename\n    return None\n\n\nclass OmniSharp(SolidLanguageServer):\n    \"\"\"\n    Provides C# specific instantiation of the LanguageServer class. Contains various configurations and settings specific to C#.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates an OmniSharp instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.\n        \"\"\"\n        omnisharp_executable_path, dll_path = self._setup_runtime_dependencies(config, solidlsp_settings)\n\n        slnfilename = find_least_depth_sln_file(repository_root_path)\n        if slnfilename is None:\n            log.error(\"No *.sln file found in repository\")\n            raise SolidLSPException(\"No SLN file found in repository\")\n\n        cmd = \" \".join(\n            [\n                omnisharp_executable_path,\n                \"-lsp\",\n                \"--encoding\",\n                \"ascii\",\n                \"-z\",\n                \"-s\",\n                f'\"{slnfilename}\"',\n                \"--hostPID\",\n                str(os.getpid()),\n                \"DotNet:enablePackageRestore=false\",\n                \"--loglevel\",\n                \"trace\",\n                \"--plugin\",\n                dll_path,\n                \"FileOptions:SystemExcludeSearchPatterns:0=**/.git\",\n                \"FileOptions:SystemExcludeSearchPatterns:1=**/.svn\",\n                \"FileOptions:SystemExcludeSearchPatterns:2=**/.hg\",\n                \"FileOptions:SystemExcludeSearchPatterns:3=**/CVS\",\n                \"FileOptions:SystemExcludeSearchPatterns:4=**/.DS_Store\",\n                \"FileOptions:SystemExcludeSearchPatterns:5=**/Thumbs.db\",\n                \"RoslynExtensionsOptions:EnableAnalyzersSupport=true\",\n                \"FormattingOptions:EnableEditorConfigSupport=true\",\n                \"RoslynExtensionsOptions:EnableImportCompletion=true\",\n                \"Sdk:IncludePrereleases=true\",\n                \"RoslynExtensionsOptions:AnalyzeOpenDocumentsOnly=true\",\n                \"formattingOptions:useTabs=false\",\n                \"formattingOptions:tabSize=4\",\n                \"formattingOptions:indentationSize=4\",\n            ]\n        )\n        super().__init__(config, repository_root_path, ProcessLaunchInfo(cmd=cmd, cwd=repository_root_path), \"csharp\", solidlsp_settings)\n\n        self.server_ready = threading.Event()\n        self.definition_available = threading.Event()\n        self.references_available = threading.Event()\n        self.completions_available = threading.Event()\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\"bin\", \"obj\"]\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Omnisharp Language Server.\n        \"\"\"\n        with open(os.path.join(os.path.dirname(__file__), \"omnisharp\", \"initialize_params.json\"), encoding=\"utf-8\") as f:\n            d = json.load(f)\n\n        del d[\"_description\"]\n\n        d[\"processId\"] = os.getpid()\n        assert d[\"rootPath\"] == \"$rootPath\"\n        d[\"rootPath\"] = repository_absolute_path\n\n        assert d[\"rootUri\"] == \"$rootUri\"\n        d[\"rootUri\"] = pathlib.Path(repository_absolute_path).as_uri()\n\n        assert d[\"workspaceFolders\"][0][\"uri\"] == \"$uri\"\n        d[\"workspaceFolders\"][0][\"uri\"] = pathlib.Path(repository_absolute_path).as_uri()\n\n        assert d[\"workspaceFolders\"][0][\"name\"] == \"$name\"\n        d[\"workspaceFolders\"][0][\"name\"] = os.path.basename(repository_absolute_path)\n\n        return d\n\n    @classmethod\n    def _setup_runtime_dependencies(cls, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings) -> tuple[str, str]:\n        \"\"\"\n        Setup runtime dependencies for OmniSharp.\n        \"\"\"\n        platform_id = PlatformUtils.get_platform_id()\n        dotnet_version = PlatformUtils.get_dotnet_version()\n\n        with open(os.path.join(os.path.dirname(__file__), \"omnisharp\", \"runtime_dependencies.json\"), encoding=\"utf-8\") as f:\n            d = json.load(f)\n            del d[\"_description\"]\n\n        assert platform_id in [\n            PlatformId.LINUX_x64,\n            PlatformId.WIN_x64,\n        ], f\"Only linux-x64 and win-x64 platform is supported at the moment but got {platform_id=}\"\n        assert dotnet_version in [\n            DotnetVersion.V6,\n            DotnetVersion.V7,\n            DotnetVersion.V8,\n            DotnetVersion.V9,\n        ], f\"Only dotnet version 6-9 are supported at the moment but got {dotnet_version=}\"\n\n        # TODO: Do away with this assumption\n        # Currently, runtime binaries are not available for .Net 7 and .Net 8. Hence, we assume .Net 6 runtime binaries to be compatible with .Net 7, .Net 8\n        if dotnet_version in [DotnetVersion.V7, DotnetVersion.V8, DotnetVersion.V9]:\n            dotnet_version = DotnetVersion.V6\n\n        runtime_dependencies = d[\"runtimeDependencies\"]\n        runtime_dependencies = [dependency for dependency in runtime_dependencies if dependency[\"platformId\"] == platform_id.value]\n        runtime_dependencies = [\n            dependency\n            for dependency in runtime_dependencies\n            if \"dotnet_version\" not in dependency or dependency[\"dotnet_version\"] == dotnet_version.value\n        ]\n        assert len(runtime_dependencies) == 2\n        runtime_dependencies = {\n            runtime_dependencies[0][\"id\"]: runtime_dependencies[0],\n            runtime_dependencies[1][\"id\"]: runtime_dependencies[1],\n        }\n\n        assert \"OmniSharp\" in runtime_dependencies\n        assert \"RazorOmnisharp\" in runtime_dependencies\n\n        omnisharp_ls_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), \"OmniSharp\")\n        if not os.path.exists(omnisharp_ls_dir):\n            os.makedirs(omnisharp_ls_dir)\n            FileUtils.download_and_extract_archive(runtime_dependencies[\"OmniSharp\"][\"url\"], omnisharp_ls_dir, \"zip\")\n        omnisharp_executable_path = os.path.join(omnisharp_ls_dir, runtime_dependencies[\"OmniSharp\"][\"binaryName\"])\n        assert os.path.exists(omnisharp_executable_path)\n        os.chmod(omnisharp_executable_path, 0o755)\n\n        razor_omnisharp_ls_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), \"RazorOmnisharp\")\n        if not os.path.exists(razor_omnisharp_ls_dir):\n            os.makedirs(razor_omnisharp_ls_dir)\n            FileUtils.download_and_extract_archive(runtime_dependencies[\"RazorOmnisharp\"][\"url\"], razor_omnisharp_ls_dir, \"zip\")\n        razor_omnisharp_dll_path = os.path.join(razor_omnisharp_ls_dir, runtime_dependencies[\"RazorOmnisharp\"][\"dll_path\"])\n        assert os.path.exists(razor_omnisharp_dll_path)\n\n        return omnisharp_executable_path, razor_omnisharp_dll_path\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the Omnisharp Language Server\n        \"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            assert \"registrations\" in params\n            for registration in params[\"registrations\"]:\n                if registration[\"method\"] == \"textDocument/definition\":\n                    self.definition_available.set()\n                if registration[\"method\"] == \"textDocument/references\":\n                    self.references_available.set()\n                if registration[\"method\"] == \"textDocument/completion\":\n                    self.completions_available.set()\n\n        def lang_status_handler(params: dict) -> None:\n            # TODO: Should we wait for\n            # server -> client: {'jsonrpc': '2.0', 'method': 'language/status', 'params': {'type': 'ProjectStatus', 'message': 'OK'}}\n            # Before proceeding?\n            # if params[\"type\"] == \"ServiceReady\" and params[\"message\"] == \"ServiceReady\":\n            #     self.service_ready_event.set()\n            pass\n\n        def execute_client_command_handler(params: dict) -> list:\n            return []\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def check_experimental_status(params: dict) -> None:\n            if params[\"quiescent\"] is True:\n                self.server_ready.set()\n\n        def workspace_configuration_handler(params: dict) -> list[dict]:\n            # TODO: We do not know the appropriate way to handle this request. Should ideally contact the OmniSharp dev team\n            return [\n                {\n                    \"RoslynExtensionsOptions\": {\n                        \"EnableDecompilationSupport\": False,\n                        \"EnableAnalyzersSupport\": True,\n                        \"EnableImportCompletion\": True,\n                        \"EnableAsyncCompletion\": False,\n                        \"DocumentAnalysisTimeoutMs\": 30000,\n                        \"DiagnosticWorkersThreadCount\": 18,\n                        \"AnalyzeOpenDocumentsOnly\": True,\n                        \"InlayHintsOptions\": {\n                            \"EnableForParameters\": False,\n                            \"ForLiteralParameters\": False,\n                            \"ForIndexerParameters\": False,\n                            \"ForObjectCreationParameters\": False,\n                            \"ForOtherParameters\": False,\n                            \"SuppressForParametersThatDifferOnlyBySuffix\": False,\n                            \"SuppressForParametersThatMatchMethodIntent\": False,\n                            \"SuppressForParametersThatMatchArgumentName\": False,\n                            \"EnableForTypes\": False,\n                            \"ForImplicitVariableTypes\": False,\n                            \"ForLambdaParameterTypes\": False,\n                            \"ForImplicitObjectCreation\": False,\n                        },\n                        \"LocationPaths\": None,\n                    },\n                    \"FormattingOptions\": {\n                        \"OrganizeImports\": False,\n                        \"EnableEditorConfigSupport\": True,\n                        \"NewLine\": \"\\n\",\n                        \"UseTabs\": False,\n                        \"TabSize\": 4,\n                        \"IndentationSize\": 4,\n                        \"SpacingAfterMethodDeclarationName\": False,\n                        \"SeparateImportDirectiveGroups\": False,\n                        \"SpaceWithinMethodDeclarationParenthesis\": False,\n                        \"SpaceBetweenEmptyMethodDeclarationParentheses\": False,\n                        \"SpaceAfterMethodCallName\": False,\n                        \"SpaceWithinMethodCallParentheses\": False,\n                        \"SpaceBetweenEmptyMethodCallParentheses\": False,\n                        \"SpaceAfterControlFlowStatementKeyword\": True,\n                        \"SpaceWithinExpressionParentheses\": False,\n                        \"SpaceWithinCastParentheses\": False,\n                        \"SpaceWithinOtherParentheses\": False,\n                        \"SpaceAfterCast\": False,\n                        \"SpaceBeforeOpenSquareBracket\": False,\n                        \"SpaceBetweenEmptySquareBrackets\": False,\n                        \"SpaceWithinSquareBrackets\": False,\n                        \"SpaceAfterColonInBaseTypeDeclaration\": True,\n                        \"SpaceAfterComma\": True,\n                        \"SpaceAfterDot\": False,\n                        \"SpaceAfterSemicolonsInForStatement\": True,\n                        \"SpaceBeforeColonInBaseTypeDeclaration\": True,\n                        \"SpaceBeforeComma\": False,\n                        \"SpaceBeforeDot\": False,\n                        \"SpaceBeforeSemicolonsInForStatement\": False,\n                        \"SpacingAroundBinaryOperator\": \"single\",\n                        \"IndentBraces\": False,\n                        \"IndentBlock\": True,\n                        \"IndentSwitchSection\": True,\n                        \"IndentSwitchCaseSection\": True,\n                        \"IndentSwitchCaseSectionWhenBlock\": True,\n                        \"LabelPositioning\": \"oneLess\",\n                        \"WrappingPreserveSingleLine\": True,\n                        \"WrappingKeepStatementsOnSingleLine\": True,\n                        \"NewLinesForBracesInTypes\": True,\n                        \"NewLinesForBracesInMethods\": True,\n                        \"NewLinesForBracesInProperties\": True,\n                        \"NewLinesForBracesInAccessors\": True,\n                        \"NewLinesForBracesInAnonymousMethods\": True,\n                        \"NewLinesForBracesInControlBlocks\": True,\n                        \"NewLinesForBracesInAnonymousTypes\": True,\n                        \"NewLinesForBracesInObjectCollectionArrayInitializers\": True,\n                        \"NewLinesForBracesInLambdaExpressionBody\": True,\n                        \"NewLineForElse\": True,\n                        \"NewLineForCatch\": True,\n                        \"NewLineForFinally\": True,\n                        \"NewLineForMembersInObjectInit\": True,\n                        \"NewLineForMembersInAnonymousTypes\": True,\n                        \"NewLineForClausesInQuery\": True,\n                    },\n                    \"FileOptions\": {\n                        \"SystemExcludeSearchPatterns\": [\n                            \"**/node_modules/**/*\",\n                            \"**/bin/**/*\",\n                            \"**/obj/**/*\",\n                            \"**/.git/**/*\",\n                            \"**/.git\",\n                            \"**/.svn\",\n                            \"**/.hg\",\n                            \"**/CVS\",\n                            \"**/.DS_Store\",\n                            \"**/Thumbs.db\",\n                        ],\n                        \"ExcludeSearchPatterns\": [],\n                    },\n                    \"RenameOptions\": {\n                        \"RenameOverloads\": False,\n                        \"RenameInStrings\": False,\n                        \"RenameInComments\": False,\n                    },\n                    \"ImplementTypeOptions\": {\n                        \"InsertionBehavior\": 0,\n                        \"PropertyGenerationBehavior\": 0,\n                    },\n                    \"DotNetCliOptions\": {\"LocationPaths\": None},\n                    \"Plugins\": {\"LocationPaths\": None},\n                }\n            ]\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"language/status\", lang_status_handler)\n        self.server.on_request(\"workspace/executeClientCommand\", execute_client_command_handler)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"language/actionableNotification\", do_nothing)\n        self.server.on_notification(\"experimental/serverStatus\", check_experimental_status)\n        self.server.on_request(\"workspace/configuration\", workspace_configuration_handler)\n\n        log.info(\"Starting OmniSharp server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        self.server.notify.initialized({})\n        with open(os.path.join(os.path.dirname(__file__), \"omnisharp\", \"workspace_did_change_configuration.json\"), encoding=\"utf-8\") as f:\n            self.server.notify.workspace_did_change_configuration({\"settings\": json.load(f)})\n        assert \"capabilities\" in init_response\n        if \"definitionProvider\" in init_response[\"capabilities\"] and init_response[\"capabilities\"][\"definitionProvider\"]:\n            self.definition_available.set()\n        if \"referencesProvider\" in init_response[\"capabilities\"] and init_response[\"capabilities\"][\"referencesProvider\"]:\n            self.references_available.set()\n\n        self.definition_available.wait()\n        self.references_available.wait()\n"
  },
  {
    "path": "src/solidlsp/language_servers/pascal_server.py",
    "content": "\"\"\"\nProvides Pascal/Free Pascal specific instantiation of the LanguageServer class using pasls.\nContains various configurations and settings specific to Pascal and Free Pascal.\n\npasls installation strategy:\n1. Use existing pasls from PATH\n2. Download prebuilt binary from GitHub releases (auto-updated)\n\nSupported platforms for binary download:\n- linux-x64, linux-arm64\n- osx-x64, osx-arm64\n- win-x64\n\nAuto-update features:\n- Checks for updates every 24 hours via GitHub API\n- SHA256 checksum verification before installation\n- Atomic update with rollback on failure\n- Windows file locking detection\n\nYou can pass the following entries in ls_specific_settings[\"pascal\"]:\n\nEnvironment variables (recommended for CodeTools configuration):\n- pp: Path to FPC compiler driver, must be \"fpc.exe\" (e.g., \"D:/laz32/fpc/bin/i386-win32/fpc.exe\").\n  Do NOT use backend compilers like ppc386.exe or ppcx64.exe - CodeTools queries fpc.exe for\n  configuration (fpc -iV, fpc -iTO, etc.). This is the most important setting for hover/navigation.\n- fpcdir: Path to FPC source directory (e.g., \"D:/laz32/fpcsrc\"). Helps CodeTools locate\n  standard library sources for better navigation.\n- lazarusdir: Path to Lazarus directory (e.g., \"D:/laz32/lazarus\"). Required for Lazarus\n  projects using LCL and other Lazarus components.\n\nTarget platform overrides (use only if pp setting is not sufficient):\n- fpc_target: Override target OS (e.g., \"Win32\", \"Win64\", \"Linux\"). Sets FPCTARGET env var.\n- fpc_target_cpu: Override target CPU (e.g., \"i386\", \"x86_64\", \"aarch64\"). Sets FPCTARGETCPU.\n\nExample configuration in ~/.serena/serena_config.yml:\n    ls_specific_settings:\n        pascal:\n            pp: \"D:/laz32/fpc/bin/i386-win32/fpc.exe\"\n            fpcdir: \"D:/laz32/fpcsrc\"\n            lazarusdir: \"D:/laz32/lazarus\"\n\"\"\"\n\nfrom __future__ import annotations\n\nimport hashlib\nimport json\nimport logging\nimport os\nimport pathlib\nimport platform\nimport shutil\nimport tarfile\nimport threading\nimport time\nimport urllib.error\nimport urllib.request\nimport uuid\nimport zipfile\n\nfrom solidlsp.language_servers.common import RuntimeDependency, RuntimeDependencyCollection, quote_windows_path\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass PascalLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides Pascal specific instantiation of the LanguageServer class using pasls.\n    Contains various configurations and settings specific to Free Pascal and Lazarus.\n    \"\"\"\n\n    # URL configuration\n    PASLS_RELEASES_URL = \"https://github.com/zen010101/pascal-language-server/releases/latest/download\"\n    PASLS_API_URL = \"https://api.github.com/repos/zen010101/pascal-language-server/releases/latest\"\n\n    # Update check interval (seconds)\n    UPDATE_CHECK_INTERVAL = 86400  # 24 hours\n\n    # Metadata directory name\n    META_DIR = \".meta\"\n\n    # Network timeout (seconds)\n    NETWORK_TIMEOUT = 10\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a PascalLanguageServer instance. This class is not meant to be instantiated directly.\n        Use LanguageServer.create() instead.\n        \"\"\"\n        pasls_executable_path = self._setup_runtime_dependencies(solidlsp_settings)\n\n        # Build environment variables for pasls\n        # These control CodeTools' configuration and target platform settings\n        proc_env: dict[str, str] = {}\n\n        # Read from ls_specific_settings[\"pascal\"]\n        from solidlsp.ls_config import Language\n\n        pascal_settings = solidlsp_settings.get_ls_specific_settings(Language.PASCAL)\n\n        # pp: Path to FPC compiler driver (must be fpc.exe, NOT ppc386.exe/ppcx64.exe)\n        # CodeTools queries fpc.exe for configuration via \"fpc -iV\", \"fpc -iTO\", etc.\n        pp = pascal_settings.get(\"pp\", \"\")\n        if pp:\n            proc_env[\"PP\"] = pp\n            log.info(f\"Setting PP={pp} from ls_specific_settings\")\n\n        # fpcdir: Path to FPC source directory (e.g., \"D:/laz32/fpcsrc\")\n        fpcdir = pascal_settings.get(\"fpcdir\", \"\")\n        if fpcdir:\n            proc_env[\"FPCDIR\"] = fpcdir\n            log.info(f\"Setting FPCDIR={fpcdir} from ls_specific_settings\")\n\n        # lazarusdir: Path to Lazarus directory (e.g., \"D:/laz32/lazarus\")\n        lazarusdir = pascal_settings.get(\"lazarusdir\", \"\")\n        if lazarusdir:\n            proc_env[\"LAZARUSDIR\"] = lazarusdir\n            log.info(f\"Setting LAZARUSDIR={lazarusdir} from ls_specific_settings\")\n\n        # fpc_target: Override target OS (e.g., \"Win32\", \"Win64\", \"Linux\")\n        fpc_target = pascal_settings.get(\"fpc_target\", \"\")\n        if fpc_target:\n            proc_env[\"FPCTARGET\"] = fpc_target\n            log.info(f\"Setting FPCTARGET={fpc_target} from ls_specific_settings\")\n\n        # fpc_target_cpu: Override target CPU (e.g., \"i386\", \"x86_64\", \"aarch64\")\n        fpc_target_cpu = pascal_settings.get(\"fpc_target_cpu\", \"\")\n        if fpc_target_cpu:\n            proc_env[\"FPCTARGETCPU\"] = fpc_target_cpu\n            log.info(f\"Setting FPCTARGETCPU={fpc_target_cpu} from ls_specific_settings\")\n\n        super().__init__(\n            config,\n            repository_root_path,\n            ProcessLaunchInfo(cmd=pasls_executable_path, cwd=repository_root_path, env=proc_env),\n            \"pascal\",\n            solidlsp_settings,\n        )\n        self.server_ready = threading.Event()\n\n    # ============== Metadata Directory Management ==============\n\n    @classmethod\n    def _meta_dir(cls, pasls_dir: str) -> str:\n        \"\"\"Get metadata directory path, create if not exists.\"\"\"\n        meta_path = os.path.join(pasls_dir, cls.META_DIR)\n        os.makedirs(meta_path, exist_ok=True)\n        return meta_path\n\n    @classmethod\n    def _meta_file(cls, pasls_dir: str, filename: str) -> str:\n        \"\"\"Get metadata file path.\"\"\"\n        return os.path.join(cls._meta_dir(pasls_dir), filename)\n\n    # ============== Version Management ==============\n\n    @staticmethod\n    def _normalize_version(version: str | None) -> str:\n        \"\"\"Normalize version string by removing 'v' prefix and whitespace.\"\"\"\n        if not version:\n            return \"\"\n        return version.strip().lstrip(\"vV\")\n\n    @classmethod\n    def _is_newer_version(cls, latest: str | None, local: str | None) -> bool:\n        \"\"\"Compare versions, return True if latest is newer than local.\"\"\"\n        if not latest:\n            return False\n        if not local:\n            return True\n\n        latest_norm = cls._normalize_version(latest)\n        local_norm = cls._normalize_version(local)\n\n        if not latest_norm:\n            return False\n        if not local_norm:\n            return True\n\n        try:\n\n            def parse_version(v: str) -> list[int]:\n                parts = []\n                for part in v.split(\".\"):\n                    num = \"\"\n                    for c in part:\n                        if c.isdigit():\n                            num += c\n                        else:\n                            break\n                    parts.append(int(num) if num else 0)\n                return parts\n\n            latest_parts = parse_version(latest_norm)\n            local_parts = parse_version(local_norm)\n\n            # Pad to same length\n            max_len = max(len(latest_parts), len(local_parts))\n            latest_parts.extend([0] * (max_len - len(latest_parts)))\n            local_parts.extend([0] * (max_len - len(local_parts)))\n\n            return latest_parts > local_parts\n        except Exception:\n            log.warning(f\"Failed to parse versions for comparison: {latest_norm} vs {local_norm}\")\n            return False\n\n    @classmethod\n    def _get_latest_version(cls) -> str | None:\n        \"\"\"Get latest version from GitHub API, return None on failure.\"\"\"\n        try:\n            headers = {\"Accept\": \"application/vnd.github.v3+json\", \"User-Agent\": \"Serena-LSP\"}\n            # Support GITHUB_TOKEN for CI environments with rate limits\n            github_token = os.environ.get(\"GITHUB_TOKEN\")\n            if github_token:\n                headers[\"Authorization\"] = f\"token {github_token}\"\n\n            req = urllib.request.Request(cls.PASLS_API_URL, headers=headers)\n            with urllib.request.urlopen(req, timeout=cls.NETWORK_TIMEOUT) as response:\n                data = json.loads(response.read().decode())\n                return data.get(\"tag_name\")\n        except Exception as e:\n            log.debug(f\"Failed to get latest pasls version: {type(e).__name__}: {e}\")\n            return None\n\n    @classmethod\n    def _get_local_version(cls, pasls_dir: str) -> str | None:\n        \"\"\"Read local version file.\"\"\"\n        version_file = cls._meta_file(pasls_dir, \"version\")\n        if os.path.exists(version_file):\n            try:\n                with open(version_file, encoding=\"utf-8\") as f:\n                    return f.read().strip()\n            except OSError:\n                return None\n        return None\n\n    @classmethod\n    def _save_local_version(cls, pasls_dir: str, version: str) -> None:\n        \"\"\"Save version to local file.\"\"\"\n        version_file = cls._meta_file(pasls_dir, \"version\")\n        try:\n            with open(version_file, \"w\", encoding=\"utf-8\") as f:\n                f.write(version)\n        except OSError as e:\n            log.warning(f\"Failed to save version file: {e}\")\n\n    # ============== Update Check Timing ==============\n\n    @classmethod\n    def _should_check_update(cls, pasls_dir: str) -> bool:\n        \"\"\"Check if we should query for updates (more than 24 hours since last check).\"\"\"\n        last_check_file = cls._meta_file(pasls_dir, \"last_check\")\n        if not os.path.exists(last_check_file):\n            return True\n        try:\n            with open(last_check_file, encoding=\"utf-8\") as f:\n                last_check = float(f.read().strip())\n            return (time.time() - last_check) > cls.UPDATE_CHECK_INTERVAL\n        except (OSError, ValueError):\n            return True\n\n    @classmethod\n    def _update_last_check(cls, pasls_dir: str) -> None:\n        \"\"\"Update last check timestamp.\"\"\"\n        last_check_file = cls._meta_file(pasls_dir, \"last_check\")\n        try:\n            with open(last_check_file, \"w\", encoding=\"utf-8\") as f:\n                f.write(str(time.time()))\n        except OSError as e:\n            log.warning(f\"Failed to update last check time: {e}\")\n\n    # ============== SHA256 Checksum ==============\n\n    @classmethod\n    def _get_checksums(cls) -> dict[str, str] | None:\n        \"\"\"Download checksums file from GitHub, return {filename: sha256} dict.\"\"\"\n        checksums_url = f\"{cls.PASLS_RELEASES_URL}/checksums.sha256\"\n        try:\n            req = urllib.request.Request(checksums_url, headers={\"User-Agent\": \"Serena-LSP\"})\n            with urllib.request.urlopen(req, timeout=cls.NETWORK_TIMEOUT) as response:\n                content = response.read().decode(\"utf-8\")\n                checksums = {}\n                for line in content.strip().split(\"\\n\"):\n                    line = line.strip()\n                    if not line or line.startswith(\"#\"):\n                        continue\n                    parts = line.split()\n                    if len(parts) >= 2:\n                        sha256 = parts[0]\n                        filename = parts[1].lstrip(\"*\")  # Remove possible * prefix\n                        checksums[filename] = sha256\n                return checksums\n        except Exception as e:\n            log.warning(f\"Failed to get checksums: {type(e).__name__}: {e}\")\n            return None\n\n    @staticmethod\n    def _calculate_sha256(file_path: str) -> str:\n        \"\"\"Calculate SHA256 checksum of a file.\"\"\"\n        sha256_hash = hashlib.sha256()\n        with open(file_path, \"rb\") as f:\n            for chunk in iter(lambda: f.read(8192), b\"\"):\n                sha256_hash.update(chunk)\n        return sha256_hash.hexdigest()\n\n    @classmethod\n    def _verify_checksum(cls, file_path: str, expected_sha256: str) -> bool:\n        \"\"\"Verify file checksum.\"\"\"\n        try:\n            actual_sha256 = cls._calculate_sha256(file_path)\n            if actual_sha256.lower() == expected_sha256.lower():\n                log.debug(f\"Checksum verified: {file_path}\")\n                return True\n            else:\n                log.error(f\"Checksum mismatch for {file_path}: expected {expected_sha256}, got {actual_sha256}\")\n                return False\n        except Exception as e:\n            log.error(f\"Failed to verify checksum: {e}\")\n            return False\n\n    # ============== Windows File Locking ==============\n\n    @staticmethod\n    def _is_file_locked(file_path: str) -> bool:\n        \"\"\"Check if file is locked (Windows).\"\"\"\n        if platform.system() != \"Windows\":\n            return False\n\n        if not os.path.exists(file_path):\n            return False\n\n        try:\n            with open(file_path, \"a\"):\n                pass\n            return False\n        except (OSError, PermissionError):\n            return True\n\n    @classmethod\n    def _safe_remove(cls, file_path: str) -> bool:\n        \"\"\"Safely remove file, handle Windows file locking.\"\"\"\n        if not os.path.exists(file_path):\n            return True\n\n        if platform.system() == \"Windows\" and cls._is_file_locked(file_path):\n            temp_name = f\"{file_path}.old.{uuid.uuid4().hex[:8]}\"\n            try:\n                os.rename(file_path, temp_name)\n                log.info(f\"File locked, renamed to: {temp_name}\")\n                cls._mark_for_cleanup(os.path.dirname(file_path), temp_name)\n                return True\n            except PermissionError:\n                log.warning(f\"Cannot remove/rename locked file: {file_path}\")\n                return False\n        else:\n            try:\n                os.remove(file_path)\n                return True\n            except OSError as e:\n                log.warning(f\"Failed to remove file {file_path}: {e}\")\n                return False\n\n    @classmethod\n    def _mark_for_cleanup(cls, pasls_dir: str, file_path: str) -> None:\n        \"\"\"Mark file for later cleanup.\"\"\"\n        cleanup_file = cls._meta_file(pasls_dir, \"cleanup_list\")\n        try:\n            with open(cleanup_file, \"a\", encoding=\"utf-8\") as f:\n                f.write(file_path + \"\\n\")\n        except OSError:\n            pass\n\n    @classmethod\n    def _cleanup_old_files(cls, pasls_dir: str) -> None:\n        \"\"\"Clean up old files marked for deletion.\"\"\"\n        cleanup_file = cls._meta_file(pasls_dir, \"cleanup_list\")\n        if not os.path.exists(cleanup_file):\n            return\n\n        try:\n            with open(cleanup_file, encoding=\"utf-8\") as f:\n                files = [line.strip() for line in f if line.strip()]\n\n            remaining = []\n            for file_path in files:\n                if os.path.exists(file_path):\n                    try:\n                        os.remove(file_path)\n                        log.debug(f\"Cleaned up old file: {file_path}\")\n                    except OSError:\n                        remaining.append(file_path)\n\n            if remaining:\n                with open(cleanup_file, \"w\", encoding=\"utf-8\") as f:\n                    f.write(\"\\n\".join(remaining) + \"\\n\")\n            else:\n                os.remove(cleanup_file)\n        except OSError:\n            pass\n\n    # ============== Download and Atomic Update ==============\n\n    @classmethod\n    def _download_archive(cls, url: str, target_path: str) -> bool:\n        \"\"\"Download archive to specified path.\"\"\"\n        try:\n            os.makedirs(os.path.dirname(target_path), exist_ok=True)\n            req = urllib.request.Request(url, headers={\"User-Agent\": \"Serena-LSP\"})\n            with urllib.request.urlopen(req, timeout=60) as response:\n                with open(target_path, \"wb\") as f:\n                    while True:\n                        chunk = response.read(8192)\n                        if not chunk:\n                            break\n                        f.write(chunk)\n            return True\n        except Exception as e:\n            log.error(f\"Failed to download {url}: {type(e).__name__}: {e}\")\n            return False\n\n    @classmethod\n    def _is_safe_tar_member(cls, member: tarfile.TarInfo, target_dir: str) -> bool:\n        \"\"\"Check if tar member is safe (prevent path traversal attack).\"\"\"\n        # Check for .. in path components\n        if \"..\" in member.name.split(\"/\") or \"..\" in member.name.split(\"\\\\\"):\n            return False\n\n        # Check extracted path is within target directory\n        abs_target = os.path.abspath(target_dir)\n        abs_member = os.path.abspath(os.path.join(target_dir, member.name))\n\n        return abs_member.startswith(abs_target + os.sep) or abs_member == abs_target\n\n    @classmethod\n    def _extract_archive(cls, archive_path: str, target_dir: str, archive_type: str) -> bool:\n        \"\"\"Safely extract archive to specified directory.\"\"\"\n        try:\n            os.makedirs(target_dir, exist_ok=True)\n\n            if archive_type == \"gztar\":\n                with tarfile.open(archive_path, \"r:gz\") as tar:\n                    for member in tar.getmembers():\n                        if not cls._is_safe_tar_member(member, target_dir):\n                            log.error(f\"Unsafe tar member detected (path traversal): {member.name}\")\n                            return False\n                    tar.extractall(target_dir)\n\n            elif archive_type == \"zip\":\n                with zipfile.ZipFile(archive_path, \"r\") as zip_ref:\n                    for name in zip_ref.namelist():\n                        if \"..\" in name.split(\"/\") or \"..\" in name.split(\"\\\\\"):\n                            log.error(f\"Unsafe zip member detected (path traversal): {name}\")\n                            return False\n                        abs_target = os.path.abspath(target_dir)\n                        abs_member = os.path.abspath(os.path.join(target_dir, name))\n                        if not (abs_member.startswith(abs_target + os.sep) or abs_member == abs_target):\n                            log.error(f\"Unsafe zip member detected (path traversal): {name}\")\n                            return False\n                    zip_ref.extractall(target_dir)\n\n            else:\n                log.error(f\"Unsupported archive type: {archive_type}\")\n                return False\n\n            # Handle nested directory: if extraction created a single subdirectory,\n            # move its contents up to target_dir (common with GitHub release archives)\n            cls._flatten_single_subdir(target_dir)\n\n            return True\n        except Exception as e:\n            log.error(f\"Failed to extract archive: {type(e).__name__}: {e}\")\n            return False\n\n    @classmethod\n    def _flatten_single_subdir(cls, target_dir: str) -> None:\n        \"\"\"If target_dir contains only a single subdirectory, move its contents up.\"\"\"\n        entries = os.listdir(target_dir)\n        if len(entries) == 1:\n            subdir = os.path.join(target_dir, entries[0])\n            if os.path.isdir(subdir):\n                # Move all contents from subdir to target_dir\n                for item in os.listdir(subdir):\n                    src = os.path.join(subdir, item)\n                    dst = os.path.join(target_dir, item)\n                    shutil.move(src, dst)\n                # Remove the now-empty subdirectory\n                os.rmdir(subdir)\n\n    @classmethod\n    def _get_archive_filename(cls, dep: RuntimeDependency) -> str:\n        \"\"\"Get archive filename from URL.\"\"\"\n        assert dep.url is not None, \"RuntimeDependency.url must be set\"\n        return dep.url.split(\"/\")[-1]\n\n    @classmethod\n    def _atomic_install(cls, pasls_dir: str, deps: RuntimeDependencyCollection, checksums: dict[str, str] | None) -> bool:\n        \"\"\"Atomic update: download -> verify checksum -> extract -> replace.\"\"\"\n        temp_dir = pasls_dir + \".tmp\"\n        backup_dir = pasls_dir + \".backup\"\n        temp_archive_dir = os.path.join(os.path.expanduser(\"~\"), \"solidlsp_tmp\")\n\n        try:\n            dep = deps.get_single_dep_for_current_platform()\n            assert dep.url is not None, \"RuntimeDependency.url must be set\"\n            assert dep.archive_type is not None, \"RuntimeDependency.archive_type must be set\"\n\n            archive_filename = cls._get_archive_filename(dep)\n            archive_path = os.path.join(temp_archive_dir, archive_filename)\n\n            # 1. Clean up any existing temp directory\n            if os.path.exists(temp_dir):\n                shutil.rmtree(temp_dir)\n            os.makedirs(temp_archive_dir, exist_ok=True)\n\n            # 2. Download archive\n            log.info(f\"Downloading pasls archive: {archive_filename}\")\n            if not cls._download_archive(dep.url, archive_path):\n                log.error(\"Failed to download pasls archive\")\n                return False\n\n            # 3. Verify SHA256 checksum (critical security step, before extraction)\n            if checksums:\n                expected_sha256 = checksums.get(archive_filename)\n                if expected_sha256:\n                    log.info(f\"Verifying SHA256 checksum for {archive_filename}...\")\n                    if not cls._verify_checksum(archive_path, expected_sha256):\n                        log.error(f\"SHA256 checksum verification FAILED for {archive_filename}\")\n                        log.error(\"Aborting installation due to checksum mismatch - possible security issue!\")\n                        try:\n                            os.remove(archive_path)\n                        except OSError:\n                            pass\n                        return False\n                    log.info(\"SHA256 checksum verified successfully\")\n                else:\n                    log.warning(f\"No checksum found for {archive_filename} in checksums file\")\n            else:\n                log.warning(\"No checksums available - skipping verification (not recommended for production)\")\n\n            # 4. Extract to temp directory\n            os.makedirs(temp_dir, exist_ok=True)\n            log.info(\"Extracting archive to temporary directory...\")\n            if not cls._extract_archive(archive_path, temp_dir, dep.archive_type):\n                log.error(\"Failed to extract archive\")\n                return False\n\n            # 5. Set execute permission\n            binary_path = deps.binary_path(temp_dir)\n            if os.path.exists(binary_path):\n                try:\n                    os.chmod(binary_path, 0o755)\n                except OSError:\n                    pass  # May fail on Windows\n\n            # 6. Backup old version\n            if os.path.exists(pasls_dir):\n                if os.path.exists(backup_dir):\n                    shutil.rmtree(backup_dir)\n                shutil.move(pasls_dir, backup_dir)\n\n            # 7. Replace with new version\n            shutil.move(temp_dir, pasls_dir)\n\n            # 8. Restore meta directory from backup (preserves version info, last_check, etc.)\n            if os.path.exists(backup_dir):\n                backup_meta = os.path.join(backup_dir, cls.META_DIR)\n                if os.path.exists(backup_meta):\n                    target_meta = os.path.join(pasls_dir, cls.META_DIR)\n                    if not os.path.exists(target_meta):\n                        shutil.copytree(backup_meta, target_meta)\n\n            # 9. Clean up downloaded archive and temp directory\n            try:\n                os.remove(archive_path)\n                os.rmdir(temp_archive_dir)\n            except OSError:\n                pass\n\n            log.info(\"pasls installation completed successfully\")\n            return True\n\n        except Exception as e:\n            log.error(f\"Installation failed: {e}\")\n\n            # Rollback\n            if os.path.exists(backup_dir) and not os.path.exists(pasls_dir):\n                try:\n                    shutil.move(backup_dir, pasls_dir)\n                    log.info(\"Rolled back to previous version\")\n                except Exception as rollback_error:\n                    log.error(f\"Rollback failed: {rollback_error}\")\n\n            # Clean up temp directory\n            if os.path.exists(temp_dir):\n                try:\n                    shutil.rmtree(temp_dir)\n                except Exception:\n                    pass\n\n            return False\n\n    @classmethod\n    def _setup_runtime_dependencies(cls, solidlsp_settings: SolidLSPSettings) -> str:\n        \"\"\"\n        Setup runtime dependencies for Pascal Language Server (pasls).\n        Automatically checks for updates every 24 hours with security verification.\n\n        Returns:\n            str: The command to start the pasls server\n\n        \"\"\"\n        # Check if pasls is already in PATH\n        pasls_in_path = shutil.which(\"pasls\")\n        if pasls_in_path:\n            log.info(f\"Found pasls in PATH: {pasls_in_path}\")\n            return quote_windows_path(pasls_in_path)\n\n        pasls_dir = cls.ls_resources_dir(solidlsp_settings)\n        os.makedirs(pasls_dir, exist_ok=True)\n\n        # Clean up old files from previous sessions\n        cls._cleanup_old_files(pasls_dir)\n\n        # Use RuntimeDependencyCollection for platform detection\n        # Asset names follow zen010101/pascal-language-server release convention:\n        # pasls-{cpu_arch}-{os}.{ext} where cpu_arch is x86_64/aarch64/i386\n        deps = RuntimeDependencyCollection(\n            [\n                RuntimeDependency(\n                    id=\"PascalLanguageServer\",\n                    description=\"Pascal Language Server for Linux (x64)\",\n                    url=f\"{cls.PASLS_RELEASES_URL}/pasls-x86_64-linux.tar.gz\",\n                    platform_id=\"linux-x64\",\n                    archive_type=\"gztar\",\n                    binary_name=\"pasls\",\n                ),\n                RuntimeDependency(\n                    id=\"PascalLanguageServer\",\n                    description=\"Pascal Language Server for Linux (arm64)\",\n                    url=f\"{cls.PASLS_RELEASES_URL}/pasls-aarch64-linux.tar.gz\",\n                    platform_id=\"linux-arm64\",\n                    archive_type=\"gztar\",\n                    binary_name=\"pasls\",\n                ),\n                RuntimeDependency(\n                    id=\"PascalLanguageServer\",\n                    description=\"Pascal Language Server for macOS (x64)\",\n                    url=f\"{cls.PASLS_RELEASES_URL}/pasls-x86_64-darwin.zip\",\n                    platform_id=\"osx-x64\",\n                    archive_type=\"zip\",\n                    binary_name=\"pasls\",\n                ),\n                RuntimeDependency(\n                    id=\"PascalLanguageServer\",\n                    description=\"Pascal Language Server for macOS (arm64)\",\n                    url=f\"{cls.PASLS_RELEASES_URL}/pasls-aarch64-darwin.zip\",\n                    platform_id=\"osx-arm64\",\n                    archive_type=\"zip\",\n                    binary_name=\"pasls\",\n                ),\n                RuntimeDependency(\n                    id=\"PascalLanguageServer\",\n                    description=\"Pascal Language Server for Windows (x64)\",\n                    url=f\"{cls.PASLS_RELEASES_URL}/pasls-x86_64-win64.zip\",\n                    platform_id=\"win-x64\",\n                    archive_type=\"zip\",\n                    binary_name=\"pasls.exe\",\n                ),\n            ]\n        )\n\n        pasls_executable_path = deps.binary_path(pasls_dir)\n\n        # Determine if download is needed\n        need_download = False\n        latest_version = None\n        checksums = None\n\n        if not os.path.exists(pasls_executable_path):\n            # First install\n            log.info(\"pasls not found, will download...\")\n            need_download = True\n            latest_version = cls._get_latest_version()\n            checksums = cls._get_checksums()\n        elif cls._should_check_update(pasls_dir):\n            # Check for updates\n            log.debug(\"Checking for pasls updates...\")\n            latest_version = cls._get_latest_version()\n            local_version = cls._get_local_version(pasls_dir)\n\n            if cls._is_newer_version(latest_version, local_version):\n                log.info(f\"New pasls version available: {latest_version} (current: {local_version})\")\n\n                # Check Windows file locking\n                if cls._is_file_locked(pasls_executable_path):\n                    log.warning(\"Cannot update pasls: file is in use. Will retry next time.\")\n                else:\n                    need_download = True\n                    checksums = cls._get_checksums()\n            else:\n                log.debug(f\"pasls is up to date: {local_version}\")\n\n        if need_download:\n            if cls._atomic_install(pasls_dir, deps, checksums):\n                # Update metadata after successful installation\n                if latest_version:\n                    cls._save_local_version(pasls_dir, latest_version)\n                else:\n                    # API failed but download succeeded, record placeholder version\n                    cls._save_local_version(pasls_dir, \"unknown\")\n                cls._update_last_check(pasls_dir)\n            else:\n                # Installation failed, use existing version if available\n                if not os.path.exists(pasls_executable_path):\n                    raise RuntimeError(\"Failed to install pasls and no local version available\")\n                log.warning(\"Update failed, using existing version\")\n\n        # Update check time even if no update (avoid frequent checks)\n        if not need_download and cls._should_check_update(pasls_dir):\n            cls._update_last_check(pasls_dir)\n\n        assert os.path.exists(pasls_executable_path), f\"pasls executable not found at {pasls_executable_path}\"\n\n        # Ensure execute permission\n        try:\n            os.chmod(pasls_executable_path, 0o755)\n        except OSError:\n            pass  # May fail on Windows, ignore\n\n        log.info(f\"Using pasls at: {pasls_executable_path}\")\n        return quote_windows_path(pasls_executable_path)\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Pascal Language Server.\n\n        pasls (genericptr/pascal-language-server) reads compiler paths from:\n        1. Environment variables (PP, FPCDIR, LAZARUSDIR) via TCodeToolsOptions.InitWithEnvironmentVariables\n        2. Lazarus config files via GuessCodeToolConfig\n\n        We only pass target OS/CPU in initializationOptions if explicitly set.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n\n        # Build initializationOptions from environment variables\n        # pasls reads these to configure CodeTools:\n        # - PP: Path to FPC compiler executable\n        # - FPCDIR: Path to FPC source directory\n        # - LAZARUSDIR: Path to Lazarus directory (only needed for LCL projects)\n        # - FPCTARGET: Target OS\n        # - FPCTARGETCPU: Target CPU\n        initialization_options: dict = {}\n\n        env_vars = [\"PP\", \"FPCDIR\", \"LAZARUSDIR\", \"FPCTARGET\", \"FPCTARGETCPU\"]\n        for var in env_vars:\n            value = os.environ.get(var, \"\")\n            if value:\n                initialization_options[var] = value\n\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\n                        \"didSave\": True,\n                        \"dynamicRegistration\": True,\n                        \"willSave\": True,\n                        \"willSaveWaitUntil\": True,\n                    },\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"completionItem\": {\n                            \"snippetSupport\": True,\n                            \"commitCharactersSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                        },\n                    },\n                    \"hover\": {\n                        \"dynamicRegistration\": True,\n                        \"contentFormat\": [\"markdown\", \"plaintext\"],\n                    },\n                    \"signatureHelp\": {\n                        \"dynamicRegistration\": True,\n                        \"signatureInformation\": {\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                        },\n                    },\n                    \"definition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentHighlight\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"codeAction\": {\n                        \"dynamicRegistration\": True,\n                        \"codeActionLiteralSupport\": {\n                            \"codeActionKind\": {\n                                \"valueSet\": [\n                                    \"quickfix\",\n                                    \"refactor\",\n                                    \"refactor.extract\",\n                                    \"refactor.inline\",\n                                    \"refactor.rewrite\",\n                                    \"source\",\n                                    \"source.organizeImports\",\n                                ]\n                            }\n                        },\n                    },\n                    \"formatting\": {\"dynamicRegistration\": True},\n                    \"rangeFormatting\": {\"dynamicRegistration\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True},\n                    \"executeCommand\": {\"dynamicRegistration\": True},\n                    \"configuration\": True,\n                    \"workspaceEdit\": {\n                        \"documentChanges\": True,\n                    },\n                },\n            },\n            \"initializationOptions\": initialization_options,\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n\n        return initialize_params  # type: ignore\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the Pascal Language Server, waits for the server to be ready and yields the LanguageServer instance.\n        \"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            log.debug(f\"Capability registered: {params}\")\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n            # Mark server as ready when we see initialization messages\n            message_text = msg.get(\"message\", \"\")\n            if \"initialized\" in message_text.lower() or \"ready\" in message_text.lower():\n                log.info(\"Pascal language server ready signal detected\")\n                self.server_ready.set()\n\n        def publish_diagnostics(params: dict) -> None:\n            log.debug(f\"Diagnostics: {params}\")\n            return\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"window/showMessage\", window_log_message)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", publish_diagnostics)\n        self.server.on_notification(\"$/progress\", do_nothing)\n\n        log.info(\"Starting Pascal server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        log.debug(f\"Received initialize response from Pascal server: {init_response}\")\n\n        # Verify capabilities\n        capabilities = init_response.get(\"capabilities\", {})\n        assert \"textDocumentSync\" in capabilities\n\n        # Check for various capabilities\n        if \"completionProvider\" in capabilities:\n            log.info(\"Pascal server supports code completion\")\n        if \"definitionProvider\" in capabilities:\n            log.info(\"Pascal server supports go to definition\")\n        if \"referencesProvider\" in capabilities:\n            log.info(\"Pascal server supports find references\")\n        if \"documentSymbolProvider\" in capabilities:\n            log.info(\"Pascal server supports document symbols\")\n\n        self.server.notify.initialized({})\n\n        # Wait for server readiness with timeout\n        log.info(\"Waiting for Pascal language server to be ready...\")\n        if not self.server_ready.wait(timeout=5.0):\n            # pasls may not send explicit ready signals, so we proceed after timeout\n            log.info(\"Timeout waiting for Pascal server ready signal, assuming server is ready\")\n            self.server_ready.set()\n        else:\n            log.info(\"Pascal server initialization complete\")\n\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        \"\"\"\n        Check if a directory should be ignored for Pascal projects.\n        Common Pascal/Lazarus directories to ignore.\n        \"\"\"\n        ignored_dirs = {\n            \"lib\",\n            \"backup\",\n            \"__history\",\n            \"__recovery\",\n            \"bin\",\n            \".git\",\n            \".svn\",\n            \".hg\",\n            \"node_modules\",\n        }\n        return dirname.lower() in ignored_dirs\n"
  },
  {
    "path": "src/solidlsp/language_servers/perl_language_server.py",
    "content": "\"\"\"\nProvides Perl specific instantiation of the LanguageServer class using Perl::LanguageServer.\n\nNote: Windows is not supported as Nix itself doesn't support Windows natively.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport subprocess\nimport time\nfrom typing import Any\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.ls_utils import PlatformId, PlatformUtils\nfrom solidlsp.lsp_protocol_handler.lsp_types import DidChangeConfigurationParams, InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass PerlLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides Perl specific instantiation of the LanguageServer class using Perl::LanguageServer.\n    \"\"\"\n\n    @staticmethod\n    def _get_perl_version() -> str | None:\n        \"\"\"Get the installed Perl version or None if not found.\"\"\"\n        try:\n            result = subprocess.run([\"perl\", \"-v\"], capture_output=True, text=True, check=False)\n            if result.returncode == 0:\n                return result.stdout.strip()\n        except FileNotFoundError:\n            return None\n        return None\n\n    @staticmethod\n    def _get_perl_language_server_version() -> str | None:\n        \"\"\"Get the installed Perl::LanguageServer version or None if not found.\"\"\"\n        try:\n            result = subprocess.run(\n                [\"perl\", \"-MPerl::LanguageServer\", \"-e\", \"print $Perl::LanguageServer::VERSION\"],\n                capture_output=True,\n                text=True,\n                check=False,\n            )\n            if result.returncode == 0:\n                return result.stdout.strip()\n        except FileNotFoundError:\n            return None\n        return None\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        # For Perl projects, we should ignore:\n        # - blib: build library directory\n        # - local: local Perl module installation\n        # - .carton: Carton dependency manager cache\n        # - vendor: vendored dependencies\n        # - _build: Module::Build output\n        return super().is_ignored_dirname(dirname) or dirname in [\"blib\", \"local\", \".carton\", \"vendor\", \"_build\", \"cover_db\"]\n\n    @classmethod\n    def _setup_runtime_dependencies(cls) -> str:\n        \"\"\"\n        Check if required Perl runtime dependencies are available.\n        Raises RuntimeError with helpful message if dependencies are missing.\n        \"\"\"\n        platform_id = PlatformUtils.get_platform_id()\n\n        valid_platforms = [\n            PlatformId.LINUX_x64,\n            PlatformId.LINUX_arm64,\n            PlatformId.OSX,\n            PlatformId.OSX_x64,\n            PlatformId.OSX_arm64,\n        ]\n        if platform_id not in valid_platforms:\n            raise RuntimeError(f\"Platform {platform_id} is not supported for Perl at the moment\")\n\n        perl_version = cls._get_perl_version()\n        if not perl_version:\n            raise RuntimeError(\n                \"Perl is not installed. Please install Perl from https://www.perl.org/get.html and make sure it is added to your PATH.\"\n            )\n\n        perl_ls_version = cls._get_perl_language_server_version()\n        if not perl_ls_version:\n            raise RuntimeError(\n                \"Found a Perl version but Perl::LanguageServer is not installed.\\n\"\n                \"Please install Perl::LanguageServer: cpanm Perl::LanguageServer\\n\"\n                \"See: https://metacpan.org/pod/Perl::LanguageServer\"\n            )\n\n        return \"perl -MPerl::LanguageServer -e 'Perl::LanguageServer::run'\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        # Setup runtime dependencies before initializing\n        perl_ls_cmd = self._setup_runtime_dependencies()\n\n        super().__init__(\n            config, repository_root_path, ProcessLaunchInfo(cmd=perl_ls_cmd, cwd=repository_root_path), \"perl\", solidlsp_settings\n        )\n        self.request_id = 0\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for Perl::LanguageServer.\n        Based on the expected structure from Perl::LanguageServer::Methods::_rpcreq_initialize.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\"dynamicRegistration\": True},\n                    \"hover\": {\"dynamicRegistration\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True},\n                },\n            },\n            \"initializationOptions\": {},\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n\n        return initialize_params  # type: ignore\n\n    def _start_server(self) -> None:\n        \"\"\"Start Perl::LanguageServer process\"\"\"\n\n        def register_capability_handler(params: Any) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def do_nothing(params: Any) -> None:\n            return\n\n        def workspace_configuration_handler(params: Any) -> Any:\n            \"\"\"Handle workspace/configuration request from Perl::LanguageServer.\"\"\"\n            log.info(f\"Received workspace/configuration request: {params}\")\n\n            perl_config = {\n                \"perlInc\": [self.repository_root_path, \".\"],\n                \"fileFilter\": [\".pm\", \".pl\"],\n                \"ignoreDirs\": [\".git\", \".svn\", \"blib\", \"local\", \".carton\", \"vendor\", \"_build\", \"cover_db\"],\n            }\n\n            return [perl_config]\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_request(\"workspace/configuration\", workspace_configuration_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting Perl::LanguageServer process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        log.info(\n            \"After sent initialize params\",\n        )\n\n        # Verify server capabilities\n        assert \"textDocumentSync\" in init_response[\"capabilities\"]\n        assert \"definitionProvider\" in init_response[\"capabilities\"]\n        assert \"referencesProvider\" in init_response[\"capabilities\"]\n\n        self.server.notify.initialized({})\n\n        # Send workspace configuration to Perl::LanguageServer\n        # Perl::LanguageServer requires didChangeConfiguration to set perlInc, fileFilter, and ignoreDirs\n        # See: Perl::LanguageServer::Methods::workspace::_rpcnot_didChangeConfiguration\n        perl_config: DidChangeConfigurationParams = {\n            \"settings\": {\n                \"perl\": {\n                    \"perlInc\": [self.repository_root_path, \".\"],\n                    \"fileFilter\": [\".pm\", \".pl\"],\n                    \"ignoreDirs\": [\".git\", \".svn\", \"blib\", \"local\", \".carton\", \"vendor\", \"_build\", \"cover_db\"],\n                }\n            }\n        }\n        log.info(f\"Sending workspace/didChangeConfiguration notification with config: {perl_config}\")\n        self.server.notify.workspace_did_change_configuration(perl_config)\n\n        # Perl::LanguageServer needs time to index files and resolve cross-file references\n        # Without this delay, requests for definitions/references may return empty results\n        settling_time = 0.5\n        log.info(f\"Allowing {settling_time} seconds for Perl::LanguageServer to index files...\")\n        time.sleep(settling_time)\n        log.info(\"Perl::LanguageServer settling period complete\")\n"
  },
  {
    "path": "src/solidlsp/language_servers/phpactor.py",
    "content": "\"\"\"\nProvides PHP specific instantiation of the LanguageServer class using Phpactor.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport re\nimport shutil\nimport stat\nimport subprocess\n\nfrom overrides import override\n\nfrom solidlsp.ls import LanguageServerDependencyProvider, LanguageServerDependencyProviderSinglePath, SolidLanguageServer\nfrom solidlsp.ls_config import Language, LanguageServerConfig\nfrom solidlsp.ls_utils import FileUtils\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\nPHPACTOR_VERSION = \"2025.12.21.1\"\nPHPACTOR_PHAR_URL = f\"https://github.com/phpactor/phpactor/releases/download/{PHPACTOR_VERSION}/phpactor.phar\"\n\n\nclass PhpactorServer(SolidLanguageServer):\n    \"\"\"\n    Provides PHP specific instantiation of the LanguageServer class using Phpactor.\n\n    Phpactor is an open-source (MIT) PHP language server that requires PHP 8.1+ on the system.\n    It is an alternative to Intelephense, which is the default PHP language server.\n\n    You can pass the following entries in ls_specific_settings[\"php_phpactor\"]:\n        - ignore_vendor: whether to ignore directories named \"vendor\" (default: true)\n    \"\"\"\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in self._ignored_dirnames\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def _get_or_install_core_dependency(self) -> str:\n            \"\"\"\n            Setup runtime dependencies for Phpactor and return the path to the PHAR file.\n            \"\"\"\n            # Verify PHP is installed\n            php_path = shutil.which(\"php\")\n            assert (\n                php_path is not None\n            ), \"PHP is not installed or not found in PATH. Phpactor requires PHP 8.1+. Please install PHP and try again.\"\n\n            # Check PHP version (Phpactor requires PHP 8.1+)\n            result = subprocess.run([\"php\", \"--version\"], capture_output=True, text=True, check=False)\n            php_version_output = result.stdout.strip()\n            log.info(f\"PHP version: {php_version_output}\")\n            version_match = re.search(r\"PHP (\\d+)\\.(\\d+)\", php_version_output)\n            if version_match:\n                major, minor = int(version_match.group(1)), int(version_match.group(2))\n                if major < 8 or (major == 8 and minor < 1):\n                    raise RuntimeError(f\"PHP {major}.{minor} detected, but Phpactor requires PHP 8.1+. Please upgrade PHP.\")\n            else:\n                log.warning(\"Could not parse PHP version from output. Continuing anyway.\")\n\n            phpactor_phar_path = os.path.join(self._ls_resources_dir, \"phpactor.phar\")\n            if not os.path.exists(phpactor_phar_path):\n                os.makedirs(self._ls_resources_dir, exist_ok=True)\n                log.info(f\"Downloading phpactor PHAR from {PHPACTOR_PHAR_URL}\")\n                FileUtils.download_and_extract_archive(PHPACTOR_PHAR_URL, phpactor_phar_path, \"binary\")\n\n            assert os.path.exists(phpactor_phar_path), f\"phpactor PHAR not found at {phpactor_phar_path}, download may have failed.\"\n\n            # Ensure the PHAR is executable\n            current_mode = os.stat(phpactor_phar_path).st_mode\n            os.chmod(phpactor_phar_path, current_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)\n\n            return phpactor_phar_path\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [\"php\", core_path, \"language-server\"]\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        super().__init__(config, repository_root_path, None, \"php\", solidlsp_settings)\n        # Override internal language enum for correct file matching\n        self.language = Language.PHP_PHPACTOR\n\n        self._ignored_dirnames = {\"node_modules\", \"cache\"}\n        if self._custom_settings.get(\"ignore_vendor\", True):\n            self._ignored_dirnames.add(\"vendor\")\n        log.info(f\"Ignoring the following directories for PHP (Phpactor): {', '.join(sorted(self._ignored_dirnames))}\")\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    def _get_initialize_params(self, repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialization params for the Phpactor Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                },\n            },\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n            \"initializationOptions\": {\n                \"language_server_phpstan.enabled\": False,\n                \"language_server_psalm.enabled\": False,\n                \"language_server_php_cs_fixer.enabled\": False,\n            },\n        }\n        return initialize_params  # type: ignore\n\n    def _start_server(self) -> None:\n        \"\"\"Start Phpactor server process.\"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting Phpactor server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        log.info(\"After sent initialize params\")\n\n        # Verify server capabilities\n        assert \"capabilities\" in init_response\n        assert init_response[\"capabilities\"].get(\"definitionProvider\"), \"Phpactor did not advertise definition support\"\n\n        self.server.notify.initialized({})\n"
  },
  {
    "path": "src/solidlsp/language_servers/powershell_language_server.py",
    "content": "\"\"\"\nProvides PowerShell specific instantiation of the LanguageServer class using PowerShell Editor Services.\nContains various configurations and settings specific to PowerShell scripting.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport platform\nimport shutil\nimport tempfile\nimport threading\nimport zipfile\nfrom pathlib import Path\n\nimport requests\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n# PowerShell Editor Services version to download\nPSES_VERSION = \"4.4.0\"\n\n\nclass PowerShellLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides PowerShell specific instantiation of the LanguageServer class using PowerShell Editor Services.\n    Contains various configurations and settings specific to PowerShell scripting.\n    \"\"\"\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        # For PowerShell projects, ignore common build/output directories\n        return super().is_ignored_dirname(dirname) or dirname in [\n            \"bin\",\n            \"obj\",\n            \".vscode\",\n            \"TestResults\",\n            \"Output\",\n        ]\n\n    @staticmethod\n    def _get_pwsh_path() -> str | None:\n        \"\"\"Get the path to PowerShell Core (pwsh) executable.\"\"\"\n        # Check if pwsh is in PATH\n        pwsh = shutil.which(\"pwsh\")\n        if pwsh:\n            return pwsh\n\n        # Check common installation locations\n        home = Path.home()\n        system = platform.system()\n\n        possible_paths: list[Path] = []\n        if system == \"Windows\":\n            possible_paths = [\n                Path(os.environ.get(\"PROGRAMFILES\", \"C:\\\\Program Files\")) / \"PowerShell\" / \"7\" / \"pwsh.exe\",\n                Path(os.environ.get(\"PROGRAMFILES\", \"C:\\\\Program Files\")) / \"PowerShell\" / \"7-preview\" / \"pwsh.exe\",\n                home / \"AppData\" / \"Local\" / \"Microsoft\" / \"PowerShell\" / \"pwsh.exe\",\n            ]\n        elif system == \"Darwin\":\n            possible_paths = [\n                Path(\"/usr/local/bin/pwsh\"),\n                Path(\"/opt/homebrew/bin/pwsh\"),\n                home / \".dotnet\" / \"tools\" / \"pwsh\",\n            ]\n        else:  # Linux\n            possible_paths = [\n                Path(\"/usr/bin/pwsh\"),\n                Path(\"/usr/local/bin/pwsh\"),\n                Path(\"/opt/microsoft/powershell/7/pwsh\"),\n                home / \".dotnet\" / \"tools\" / \"pwsh\",\n            ]\n\n        for path in possible_paths:\n            if path.exists():\n                return str(path)\n\n        return None\n\n    @classmethod\n    def _get_pses_path(cls, solidlsp_settings: SolidLSPSettings) -> str | None:\n        \"\"\"Get the path to PowerShell Editor Services installation.\"\"\"\n        install_dir = Path(cls.ls_resources_dir(solidlsp_settings)) / \"powershell\"\n        start_script = install_dir / \"PowerShellEditorServices\" / \"Start-EditorServices.ps1\"\n\n        if start_script.exists():\n            return str(start_script)\n\n        return None\n\n    @classmethod\n    def _download_pses(cls, solidlsp_settings: SolidLSPSettings) -> str:\n        \"\"\"Download and install PowerShell Editor Services.\"\"\"\n        download_url = (\n            f\"https://github.com/PowerShell/PowerShellEditorServices/releases/download/v{PSES_VERSION}/PowerShellEditorServices.zip\"\n        )\n\n        # Create installation directory\n        install_dir = Path(cls.ls_resources_dir(solidlsp_settings)) / \"powershell\"\n        install_dir.mkdir(parents=True, exist_ok=True)\n\n        # Download the file\n        log.info(f\"Downloading PowerShell Editor Services from {download_url}...\")\n        response = requests.get(download_url, stream=True, timeout=120)\n        response.raise_for_status()\n\n        # Save the zip file\n        zip_path = install_dir / \"PowerShellEditorServices.zip\"\n        with open(zip_path, \"wb\") as f:\n            for chunk in response.iter_content(chunk_size=8192):\n                f.write(chunk)\n\n        log.info(f\"Extracting PowerShell Editor Services to {install_dir}...\")\n        with zipfile.ZipFile(zip_path, \"r\") as zip_ref:\n            zip_ref.extractall(install_dir)\n\n        # Clean up zip file\n        zip_path.unlink()\n\n        start_script = install_dir / \"PowerShellEditorServices\" / \"Start-EditorServices.ps1\"\n        if not start_script.exists():\n            raise RuntimeError(f\"Failed to find Start-EditorServices.ps1 after extraction at {start_script}\")\n\n        log.info(f\"PowerShell Editor Services installed at: {install_dir}\")\n        return str(start_script)\n\n    @classmethod\n    def _setup_runtime_dependency(cls, solidlsp_settings: SolidLSPSettings) -> tuple[str, str, str]:\n        \"\"\"\n        Check if required PowerShell runtime dependencies are available.\n        Downloads PowerShell Editor Services if not present.\n\n        Returns:\n            tuple: (pwsh_path, start_script_path, bundled_modules_path)\n\n        \"\"\"\n        # Check for PowerShell Core\n        pwsh_path = cls._get_pwsh_path()\n        if not pwsh_path:\n            raise RuntimeError(\n                \"PowerShell Core (pwsh) is not installed or not in PATH. \"\n                \"Please install PowerShell 7+ from https://github.com/PowerShell/PowerShell\"\n            )\n\n        # Check for PowerShell Editor Services\n        pses_path = cls._get_pses_path(solidlsp_settings)\n        if not pses_path:\n            log.info(\"PowerShell Editor Services not found. Downloading...\")\n            pses_path = cls._download_pses(solidlsp_settings)\n\n        # The bundled modules path is the directory containing PowerShellEditorServices\n        bundled_modules_path = str(Path(pses_path).parent)\n\n        return pwsh_path, pses_path, bundled_modules_path\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        pwsh_path, pses_path, bundled_modules_path = self._setup_runtime_dependency(solidlsp_settings)\n\n        # Create a temp directory for PSES logs and session details\n        pses_temp_dir = Path(tempfile.gettempdir()) / \"solidlsp_pses\"\n        pses_temp_dir.mkdir(parents=True, exist_ok=True)\n        log_path = pses_temp_dir / \"pses.log\"\n        session_details_path = pses_temp_dir / \"session.json\"\n\n        # Build the command to start PowerShell Editor Services in stdio mode\n        # PSES requires several parameters beyond just -Stdio\n        # Using list format for robust argument handling - the PowerShell command\n        # after -Command must be a single string element\n        pses_command = (\n            f\"& '{pses_path}' \"\n            f\"-HostName 'SolidLSP' \"\n            f\"-HostProfileId 'solidlsp' \"\n            f\"-HostVersion '1.0.0' \"\n            f\"-BundledModulesPath '{bundled_modules_path}' \"\n            f\"-LogPath '{log_path}' \"\n            f\"-LogLevel 'Information' \"\n            f\"-SessionDetailsPath '{session_details_path}' \"\n            f\"-Stdio\"\n        )\n        cmd: list[str] = [\n            pwsh_path,\n            \"-NoLogo\",\n            \"-NoProfile\",\n            \"-Command\",\n            pses_command,\n        ]\n\n        super().__init__(\n            config,\n            repository_root_path,\n            ProcessLaunchInfo(cmd=cmd, cwd=repository_root_path),\n            \"powershell\",\n            solidlsp_settings,\n        )\n        self.server_ready = threading.Event()\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the PowerShell Editor Services.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"completionItem\": {\n                            \"snippetSupport\": True,\n                            \"commitCharactersSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"deprecatedSupport\": True,\n                        },\n                    },\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"signatureHelp\": {\n                        \"dynamicRegistration\": True,\n                        \"signatureInformation\": {\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"parameterInformation\": {\"labelOffsetSupport\": True},\n                        },\n                    },\n                    \"codeAction\": {\"dynamicRegistration\": True},\n                    \"formatting\": {\"dynamicRegistration\": True},\n                    \"rangeFormatting\": {\"dynamicRegistration\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"configuration\": True,\n                    \"symbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                },\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return initialize_params  # type: ignore[return-value]\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the PowerShell Editor Services, waits for the server to be ready.\n        \"\"\"\n        self._dynamic_capabilities: set[str] = set()\n\n        def register_capability_handler(params: dict) -> None:\n            \"\"\"Handle dynamic capability registration from PSES.\"\"\"\n            registrations = params.get(\"registrations\", [])\n            for reg in registrations:\n                method = reg.get(\"method\", \"\")\n                log.info(f\"PSES registered dynamic capability: {method}\")\n                self._dynamic_capabilities.add(method)\n                # Mark server ready when we get document symbol registration\n                if method == \"textDocument/documentSymbol\":\n                    self.server_ready.set()\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n            # Check for PSES ready signals\n            message_text = msg.get(\"message\", \"\")\n            if \"started\" in message_text.lower() or \"ready\" in message_text.lower():\n                log.info(\"PowerShell Editor Services ready signal detected\")\n                self.server_ready.set()\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"powerShell/executionStatusChanged\", do_nothing)\n\n        log.info(\"Starting PowerShell Editor Services process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        log.info(f\"Received initialize response from PowerShell server: {init_response}\")\n\n        # Verify server capabilities - PSES uses dynamic capability registration\n        # so we check for either static or dynamic capabilities\n        capabilities = init_response.get(\"capabilities\", {})\n        log.info(f\"Server capabilities: {capabilities}\")\n\n        # Send initialized notification to trigger dynamic capability registration\n        self.server.notify.initialized({})\n\n        # Wait for server readiness with timeout\n        log.info(\"Waiting for PowerShell Editor Services to be ready...\")\n        if not self.server_ready.wait(timeout=10.0):\n            # Fallback: assume server is ready after timeout\n            log.info(\"Timeout waiting for PSES ready signal, proceeding anyway\")\n            self.server_ready.set()\n        else:\n            log.info(\"PowerShell Editor Services initialization complete\")\n"
  },
  {
    "path": "src/solidlsp/language_servers/pyright_server.py",
    "content": "\"\"\"\nProvides Python specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Python.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport re\nimport sys\nimport threading\nfrom typing import cast\n\nfrom overrides import override\n\nfrom solidlsp.ls import LanguageServerDependencyProvider, LanguageServerDependencyProviderSinglePath, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass PyrightServer(SolidLanguageServer):\n    \"\"\"\n    Provides Python specific instantiation of the LanguageServer class using Pyright.\n    Contains various configurations and settings specific to Python.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a PyrightServer instance. This class is not meant to be instantiated directly.\n        Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(\n            config,\n            repository_root_path,\n            None,\n            \"python\",\n            solidlsp_settings,\n        )\n\n        # Event to signal when initial workspace analysis is complete\n        self.analysis_complete = threading.Event()\n        self.found_source_files = False\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def _get_or_install_core_dependency(self) -> str:\n            return sys.executable\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [core_path, \"-m\", \"pyright.langserver\", \"--stdio\"]\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\"venv\", \"__pycache__\"]\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Pyright Language Server.\n        \"\"\"\n        # Create basic initialization parameters\n        initialize_params = {  # type: ignore\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": pathlib.Path(repository_absolute_path).as_uri(),\n            \"initializationOptions\": {\n                \"exclude\": [\n                    \"**/__pycache__\",\n                    \"**/.venv\",\n                    \"**/.env\",\n                    \"**/build\",\n                    \"**/dist\",\n                    \"**/.pixi\",\n                ],\n                \"reportMissingImports\": \"error\",\n            },\n            \"capabilities\": {\n                \"workspace\": {\n                    \"workspaceEdit\": {\"documentChanges\": True},\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"didChangeWatchedFiles\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"executeCommand\": {\"dynamicRegistration\": True},\n                },\n                \"textDocument\": {\n                    \"synchronization\": {\"dynamicRegistration\": True, \"willSave\": True, \"willSaveWaitUntil\": True, \"didSave\": True},\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"signatureHelp\": {\n                        \"dynamicRegistration\": True,\n                        \"signatureInformation\": {\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"parameterInformation\": {\"labelOffsetSupport\": True},\n                        },\n                    },\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                    },\n                    \"publishDiagnostics\": {\"relatedInformation\": True},\n                },\n            },\n            \"workspaceFolders\": [\n                {\"uri\": pathlib.Path(repository_absolute_path).as_uri(), \"name\": os.path.basename(repository_absolute_path)}\n            ],\n        }\n\n        return cast(InitializeParams, initialize_params)\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the Pyright Language Server and waits for initial workspace analysis to complete.\n\n        This prevents zombie processes by ensuring Pyright has finished its initial background\n        tasks before we consider the server ready.\n\n        Usage:\n        ```\n        async with lsp.start_server():\n            # LanguageServer has been initialized and workspace analysis is complete\n            await lsp.request_definition(...)\n            await lsp.request_references(...)\n            # Shutdown the LanguageServer on exit from scope\n        # LanguageServer has been shutdown cleanly\n        ```\n        \"\"\"\n\n        def execute_client_command_handler(params: dict) -> list:\n            return []\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            \"\"\"\n            Monitor Pyright's log messages to detect when initial analysis is complete.\n            Pyright logs \"Found X source files\" when it finishes scanning the workspace.\n            \"\"\"\n            message_text = msg.get(\"message\", \"\")\n            log.info(f\"LSP: window/logMessage: {message_text}\")\n\n            # Look for \"Found X source files\" which indicates workspace scanning is complete\n            # Unfortunately, pyright is unreliable and there seems to be no better way\n            if re.search(r\"Found \\d+ source files?\", message_text):\n                log.info(\"Pyright workspace scanning complete\")\n                self.found_source_files = True\n                self.analysis_complete.set()\n\n        def check_experimental_status(params: dict) -> None:\n            \"\"\"\n            Also listen for experimental/serverStatus as a backup signal\n            \"\"\"\n            if params.get(\"quiescent\") == True:\n                log.info(\"Received experimental/serverStatus with quiescent=true\")\n                if not self.found_source_files:\n                    self.analysis_complete.set()\n\n        # Set up notification handlers\n        self.server.on_request(\"client/registerCapability\", do_nothing)\n        self.server.on_notification(\"language/status\", do_nothing)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_request(\"workspace/executeClientCommand\", execute_client_command_handler)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"language/actionableNotification\", do_nothing)\n        self.server.on_notification(\"experimental/serverStatus\", check_experimental_status)\n\n        log.info(\"Starting pyright-langserver server process\")\n        self.server.start()\n\n        # Send proper initialization parameters\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to pyright server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        log.info(f\"Received initialize response from pyright server: {init_response}\")\n\n        # Verify that the server supports our required features\n        assert \"textDocumentSync\" in init_response[\"capabilities\"]\n        assert \"completionProvider\" in init_response[\"capabilities\"]\n        assert \"definitionProvider\" in init_response[\"capabilities\"]\n\n        # Complete the initialization handshake\n        self.server.notify.initialized({})\n\n        # Wait for Pyright to complete its initial workspace analysis\n        # This prevents zombie processes by ensuring background tasks finish\n        log.info(\"Waiting for Pyright to complete initial workspace analysis...\")\n        if self.analysis_complete.wait(timeout=5.0):\n            log.info(\"Pyright initial analysis complete, server ready\")\n        else:\n            log.warning(\"Timeout waiting for Pyright analysis completion, proceeding anyway\")\n            # Fallback: assume analysis is complete after timeout\n            self.analysis_complete.set()\n"
  },
  {
    "path": "src/solidlsp/language_servers/r_language_server.py",
    "content": "import logging\nimport os\nimport pathlib\nimport subprocess\nfrom typing import Any\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass RLanguageServer(SolidLanguageServer):\n    \"\"\"R Language Server implementation using the languageserver R package.\"\"\"\n\n    @override\n    def _get_wait_time_for_cross_file_referencing(self) -> float:\n        return 5.0  # R language server needs extra time for workspace indexing in CI environments\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        # For R projects, ignore common directories\n        return super().is_ignored_dirname(dirname) or dirname in [\n            \"renv\",  # R environment management\n            \"packrat\",  # Legacy R package management\n            \".Rproj.user\",  # RStudio project files\n            \"vignettes\",  # Package vignettes (often large)\n        ]\n\n    @staticmethod\n    def _check_r_installation() -> None:\n        \"\"\"Check if R and languageserver are available.\"\"\"\n        try:\n            # Check R installation\n            result = subprocess.run([\"R\", \"--version\"], capture_output=True, text=True, check=False)\n            if result.returncode != 0:\n                raise RuntimeError(\"R is not installed or not in PATH\")\n\n            # Check languageserver package\n            result = subprocess.run(\n                [\"R\", \"--vanilla\", \"--quiet\", \"--slave\", \"-e\", \"if (!require('languageserver', quietly=TRUE)) quit(status=1)\"],\n                capture_output=True,\n                text=True,\n                check=False,\n            )\n\n            if result.returncode != 0:\n                raise RuntimeError(\n                    \"R languageserver package is not installed.\\nInstall it with: R -e \\\"install.packages('languageserver')\\\"\"\n                )\n\n        except FileNotFoundError:\n            raise RuntimeError(\"R is not installed. Please install R from https://www.r-project.org/\")\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        # Check R installation\n        self._check_r_installation()\n\n        # R command to start language server\n        # Use --vanilla for minimal startup and --quiet to suppress all output except LSP\n        # Set specific options to improve parsing stability\n        r_cmd = 'R --vanilla --quiet --slave -e \"options(languageserver.debug_mode = FALSE); languageserver::run()\"'\n\n        super().__init__(config, repository_root_path, ProcessLaunchInfo(cmd=r_cmd, cwd=repository_root_path), \"r\", solidlsp_settings)\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"Initialize params for R Language Server.\"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"completionItem\": {\n                            \"snippetSupport\": True,\n                            \"commitCharactersSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"deprecatedSupport\": True,\n                            \"preselectSupport\": True,\n                        },\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"formatting\": {\"dynamicRegistration\": True},\n                    \"rangeFormatting\": {\"dynamicRegistration\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                },\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return initialize_params  # type: ignore\n\n    def _start_server(self) -> None:\n        \"\"\"Start R Language Server process.\"\"\"\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"R LSP: window/logMessage: {msg}\")\n\n        def do_nothing(params: Any) -> None:\n            return\n\n        def register_capability_handler(params: Any) -> None:\n            return\n\n        # Register LSP message handlers\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting R Language Server process\")\n        self.server.start()\n\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n        log.info(\n            \"Sending initialize request to R Language Server\",\n        )\n\n        init_response = self.server.send.initialize(initialize_params)\n\n        # Verify server capabilities\n        capabilities = init_response.get(\"capabilities\", {})\n        assert \"textDocumentSync\" in capabilities\n        if \"completionProvider\" in capabilities:\n            log.info(\"R LSP completion provider available\")\n        if \"definitionProvider\" in capabilities:\n            log.info(\"R LSP definition provider available\")\n\n        self.server.notify.initialized({})\n\n        # R Language Server is ready after initialization\n"
  },
  {
    "path": "src/solidlsp/language_servers/regal_server.py",
    "content": "\"\"\"Regal Language Server implementation for Rego policy files.\"\"\"\n\nimport logging\nimport os\nimport shutil\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.ls_utils import PathUtils\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass RegalLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides Rego specific instantiation of the LanguageServer class using Regal.\n\n    Regal is the official linter and language server for Rego (Open Policy Agent's policy language).\n    See: https://github.com/StyraInc/regal\n    \"\"\"\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\".regal\", \".opa\"]\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a RegalLanguageServer instance.\n\n        This class is not meant to be instantiated directly. Use LanguageServer.create() instead.\n\n        :param config: Language server configuration\n        :param repository_root_path: Path to the repository root\n        :param solidlsp_settings: Settings for solidlsp\n        \"\"\"\n        # Regal should be installed system-wide (via CI or user installation)\n        regal_executable_path = shutil.which(\"regal\")\n        if not regal_executable_path:\n            raise RuntimeError(\n                \"Regal language server not found. Please install it from https://github.com/StyraInc/regal or via your package manager.\"\n            )\n\n        super().__init__(\n            config,\n            repository_root_path,\n            ProcessLaunchInfo(cmd=f\"{regal_executable_path} language-server\", cwd=repository_root_path),\n            \"rego\",\n            solidlsp_settings,\n        )\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Regal Language Server.\n\n        :param repository_absolute_path: Absolute path to the repository\n        :return: LSP initialization parameters\n        \"\"\"\n        root_uri = PathUtils.path_to_uri(repository_absolute_path)\n        return {\n            \"processId\": os.getpid(),\n            \"locale\": \"en\",\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\"dynamicRegistration\": True, \"completionItem\": {\"snippetSupport\": True}},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},  # type: ignore[arg-type]\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},  # type: ignore[list-item]\n                    \"codeAction\": {\"dynamicRegistration\": True},\n                    \"formatting\": {\"dynamicRegistration\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True},\n                },\n            },\n            \"workspaceFolders\": [\n                {\n                    \"name\": os.path.basename(repository_absolute_path),\n                    \"uri\": root_uri,\n                }\n            ],\n        }\n\n    def _start_server(self) -> None:\n        \"\"\"Start Regal language server process and wait for initialization.\"\"\"\n\n        def register_capability_handler(params) -> None:  # type: ignore[no-untyped-def]\n            return\n\n        def window_log_message(msg) -> None:  # type: ignore[no-untyped-def]\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def do_nothing(params) -> None:  # type: ignore[no-untyped-def]\n            return\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting Regal language server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\n            \"Sending initialize request from LSP client to LSP server and awaiting response\",\n        )\n        init_response = self.server.send.initialize(initialize_params)\n\n        # Verify server capabilities\n        assert \"capabilities\" in init_response\n        assert \"textDocumentSync\" in init_response[\"capabilities\"]\n\n        self.server.notify.initialized({})\n\n        # Regal server is ready immediately after initialization\n"
  },
  {
    "path": "src/solidlsp/language_servers/ruby_lsp.py",
    "content": "\"\"\"\nRuby LSP Language Server implementation using Shopify's ruby-lsp.\nProvides modern Ruby language server capabilities with improved performance.\n\"\"\"\n\nimport json\nimport logging\nimport os\nimport pathlib\nimport shutil\nimport subprocess\nimport threading\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams, InitializeResult\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass RubyLsp(SolidLanguageServer):\n    \"\"\"\n    Provides Ruby specific instantiation of the LanguageServer class using ruby-lsp.\n    Contains various configurations and settings specific to Ruby with modern LSP features.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a RubyLsp instance. This class is not meant to be instantiated directly.\n        Use LanguageServer.create() instead.\n        \"\"\"\n        ruby_lsp_executable = self._setup_runtime_dependencies(config, repository_root_path)\n        super().__init__(\n            config, repository_root_path, ProcessLaunchInfo(cmd=ruby_lsp_executable, cwd=repository_root_path), \"ruby\", solidlsp_settings\n        )\n        self.analysis_complete = threading.Event()\n        self.service_ready_event = threading.Event()\n\n        # Set timeout for ruby-lsp requests - ruby-lsp is fast\n        self.set_request_timeout(30.0)  # 30 seconds for initialization and requests\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        \"\"\"Override to ignore Ruby-specific directories that cause performance issues.\"\"\"\n        ruby_ignored_dirs = [\n            \"vendor\",  # Ruby vendor directory\n            \".bundle\",  # Bundler cache\n            \"tmp\",  # Temporary files\n            \"log\",  # Log files\n            \"coverage\",  # Test coverage reports\n            \".yardoc\",  # YARD documentation cache\n            \"doc\",  # Generated documentation\n            \"node_modules\",  # Node modules (for Rails with JS)\n            \"storage\",  # Active Storage files (Rails)\n            \"public/packs\",  # Webpacker output\n            \"public/webpack\",  # Webpack output\n            \"public/assets\",  # Rails compiled assets\n        ]\n        return super().is_ignored_dirname(dirname) or dirname in ruby_ignored_dirs\n\n    @override\n    def _get_wait_time_for_cross_file_referencing(self) -> float:\n        \"\"\"Override to provide optimal wait time for ruby-lsp cross-file reference resolution.\n\n        ruby-lsp typically initializes quickly, but may need a brief moment\n        for cross-file analysis in larger projects.\n        \"\"\"\n        return 0.5  # 500ms should be sufficient for ruby-lsp\n\n    @staticmethod\n    def _find_executable_with_extensions(executable_name: str) -> str | None:\n        \"\"\"\n        Find executable with Windows-specific extensions (.bat, .cmd, .exe) if on Windows.\n        Returns the full path to the executable or None if not found.\n        \"\"\"\n        import platform\n\n        if platform.system() == \"Windows\":\n            # Try Windows-specific extensions first\n            for ext in [\".bat\", \".cmd\", \".exe\"]:\n                path = shutil.which(f\"{executable_name}{ext}\")\n                if path:\n                    return path\n            # Fall back to default search\n            return shutil.which(executable_name)\n        else:\n            # Unix systems\n            return shutil.which(executable_name)\n\n    @staticmethod\n    def _setup_runtime_dependencies(config: LanguageServerConfig, repository_root_path: str) -> list[str]:\n        \"\"\"\n        Setup runtime dependencies for ruby-lsp and return the command list to start the server.\n        Installation strategy: Bundler project > global ruby-lsp > gem install ruby-lsp\n        \"\"\"\n        # Detect rbenv-managed Ruby environment\n        # When .ruby-version exists, it indicates the project uses rbenv for version management.\n        # rbenv automatically reads .ruby-version to determine which Ruby version to use.\n        # Using \"rbenv exec\" ensures commands run with the correct Ruby version and its gems.\n        #\n        # Why rbenv is preferred over system Ruby:\n        # - Respects project-specific Ruby versions\n        # - Avoids bundler version mismatches between system and project\n        # - Ensures consistent environment across developers\n        #\n        # Fallback behavior:\n        # If .ruby-version doesn't exist or rbenv isn't installed, we fall back to system Ruby.\n        # This may cause issues if:\n        # - System Ruby version differs from what the project expects\n        # - System bundler version is incompatible with Gemfile.lock\n        # - Project gems aren't installed in system Ruby\n        ruby_version_file = os.path.join(repository_root_path, \".ruby-version\")\n        use_rbenv = os.path.exists(ruby_version_file) and shutil.which(\"rbenv\") is not None\n\n        if use_rbenv:\n            ruby_cmd = [\"rbenv\", \"exec\", \"ruby\"]\n            bundle_cmd = [\"rbenv\", \"exec\", \"bundle\"]\n            log.info(f\"Using rbenv-managed Ruby (found {ruby_version_file})\")\n        else:\n            ruby_cmd = [\"ruby\"]\n            bundle_cmd = [\"bundle\"]\n            if os.path.exists(ruby_version_file):\n                log.warning(\n                    f\"Found {ruby_version_file} but rbenv is not installed. \"\n                    \"Using system Ruby. Consider installing rbenv for better version management: https://github.com/rbenv/rbenv\",\n                )\n            else:\n                log.info(\"No .ruby-version file found, using system Ruby\")\n\n        # Check if Ruby is installed\n        try:\n            result = subprocess.run(ruby_cmd + [\"--version\"], check=True, capture_output=True, cwd=repository_root_path, text=True)\n            ruby_version = result.stdout.strip()\n            log.info(f\"Ruby version: {ruby_version}\")\n\n            # Extract version number for compatibility checks\n            import re\n\n            version_match = re.search(r\"ruby (\\d+)\\.(\\d+)\\.(\\d+)\", ruby_version)\n            if version_match:\n                major, minor, patch = map(int, version_match.groups())\n                if major < 2 or (major == 2 and minor < 6):\n                    log.warning(f\"Warning: Ruby {major}.{minor}.{patch} detected. ruby-lsp works best with Ruby 2.6+\")\n\n        except subprocess.CalledProcessError as e:\n            error_msg = e.stderr if isinstance(e.stderr, str) else e.stderr.decode() if e.stderr else \"Unknown error\"\n            raise RuntimeError(\n                f\"Error checking Ruby installation: {error_msg}. Please ensure Ruby is properly installed and in PATH.\"\n            ) from e\n        except FileNotFoundError as e:\n            raise RuntimeError(\n                \"Ruby is not installed or not found in PATH. Please install Ruby using one of these methods:\\n\"\n                \"  - Using rbenv: rbenv install 3.0.0 && rbenv global 3.0.0\\n\"\n                \"  - Using RVM: rvm install 3.0.0 && rvm use 3.0.0 --default\\n\"\n                \"  - Using asdf: asdf install ruby 3.0.0 && asdf global ruby 3.0.0\\n\"\n                \"  - System package manager (brew install ruby, apt install ruby, etc.)\"\n            ) from e\n\n        # Check for Bundler project (Gemfile exists)\n        gemfile_path = os.path.join(repository_root_path, \"Gemfile\")\n        gemfile_lock_path = os.path.join(repository_root_path, \"Gemfile.lock\")\n        is_bundler_project = os.path.exists(gemfile_path)\n\n        if is_bundler_project:\n            log.info(\"Detected Bundler project (Gemfile found)\")\n\n            # Check if bundle command is available using Windows-compatible search\n            bundle_path = RubyLsp._find_executable_with_extensions(bundle_cmd[0] if len(bundle_cmd) == 1 else \"bundle\")\n            if not bundle_path:\n                # Try common bundle executables\n                for bundle_executable in [\"bin/bundle\", \"bundle\"]:\n                    bundle_full_path: str | None\n                    if bundle_executable.startswith(\"bin/\"):\n                        bundle_full_path = os.path.join(repository_root_path, bundle_executable)\n                    else:\n                        bundle_full_path = RubyLsp._find_executable_with_extensions(bundle_executable)\n                    if bundle_full_path and os.path.exists(bundle_full_path):\n                        bundle_path = bundle_full_path if bundle_executable.startswith(\"bin/\") else bundle_executable\n                        break\n\n            if not bundle_path:\n                log.warning(\n                    \"Bundler project detected but 'bundle' command not found. Falling back to global ruby-lsp installation.\",\n                )\n            else:\n                # Check if ruby-lsp is in Gemfile.lock\n                ruby_lsp_in_bundle = False\n                if os.path.exists(gemfile_lock_path):\n                    try:\n                        with open(gemfile_lock_path) as f:\n                            content = f.read()\n                            ruby_lsp_in_bundle = \"ruby-lsp\" in content.lower()\n                    except Exception as e:\n                        log.warning(f\"Warning: Could not read Gemfile.lock: {e}\")\n\n                if ruby_lsp_in_bundle:\n                    log.info(\"Found ruby-lsp in Gemfile.lock\")\n                    return bundle_cmd + [\"exec\", \"ruby-lsp\"]\n                else:\n                    log.info(\n                        \"ruby-lsp not found in Gemfile.lock. Consider adding 'gem \\\"ruby-lsp\\\"' to your Gemfile for better compatibility.\",\n                    )\n                    # Fall through to global installation check\n\n        # Check if ruby-lsp is available globally using Windows-compatible search\n        ruby_lsp_path = RubyLsp._find_executable_with_extensions(\"ruby-lsp\")\n        if ruby_lsp_path:\n            log.info(f\"Found ruby-lsp at: {ruby_lsp_path}\")\n            return [ruby_lsp_path]\n\n        # Try to install ruby-lsp globally\n        log.info(\"ruby-lsp not found, attempting to install globally...\")\n        try:\n            subprocess.run([\"gem\", \"install\", \"ruby-lsp\"], check=True, capture_output=True, cwd=repository_root_path)\n            log.info(\"Successfully installed ruby-lsp globally\")\n            # Find the newly installed ruby-lsp executable\n            ruby_lsp_path = RubyLsp._find_executable_with_extensions(\"ruby-lsp\")\n            return [ruby_lsp_path] if ruby_lsp_path else [\"ruby-lsp\"]\n        except subprocess.CalledProcessError as e:\n            error_msg = e.stderr if isinstance(e.stderr, str) else e.stderr.decode() if e.stderr else str(e)\n            if is_bundler_project:\n                raise RuntimeError(\n                    f\"Failed to install ruby-lsp globally: {error_msg}\\n\"\n                    \"For Bundler projects, please add 'gem \\\"ruby-lsp\\\"' to your Gemfile and run 'bundle install'.\\n\"\n                    \"Alternatively, install globally: gem install ruby-lsp\"\n                ) from e\n            raise RuntimeError(f\"Failed to install ruby-lsp: {error_msg}\\nPlease try installing manually: gem install ruby-lsp\") from e\n\n    @staticmethod\n    def _detect_rails_project(repository_root_path: str) -> bool:\n        \"\"\"\n        Detect if this is a Rails project by checking for Rails-specific files.\n        \"\"\"\n        rails_indicators = [\n            \"config/application.rb\",\n            \"config/environment.rb\",\n            \"app/controllers/application_controller.rb\",\n            \"Rakefile\",\n        ]\n\n        for indicator in rails_indicators:\n            if os.path.exists(os.path.join(repository_root_path, indicator)):\n                return True\n\n        # Check for Rails in Gemfile\n        gemfile_path = os.path.join(repository_root_path, \"Gemfile\")\n        if os.path.exists(gemfile_path):\n            try:\n                with open(gemfile_path) as f:\n                    content = f.read().lower()\n                    if \"gem 'rails'\" in content or 'gem \"rails\"' in content:\n                        return True\n            except Exception:\n                pass\n\n        return False\n\n    @staticmethod\n    def _get_ruby_exclude_patterns(repository_root_path: str) -> list[str]:\n        \"\"\"\n        Get Ruby and Rails-specific exclude patterns for better performance.\n        \"\"\"\n        base_patterns = [\n            \"**/vendor/**\",  # Ruby vendor directory\n            \"**/.bundle/**\",  # Bundler cache\n            \"**/tmp/**\",  # Temporary files\n            \"**/log/**\",  # Log files\n            \"**/coverage/**\",  # Test coverage reports\n            \"**/.yardoc/**\",  # YARD documentation cache\n            \"**/doc/**\",  # Generated documentation\n            \"**/.git/**\",  # Git directory\n            \"**/node_modules/**\",  # Node modules (for Rails with JS)\n            \"**/public/assets/**\",  # Rails compiled assets\n        ]\n\n        # Add Rails-specific patterns if this is a Rails project\n        if RubyLsp._detect_rails_project(repository_root_path):\n            base_patterns.extend(\n                [\n                    \"**/app/assets/builds/**\",  # Rails 7+ CSS builds\n                    \"**/storage/**\",  # Active Storage\n                    \"**/public/packs/**\",  # Webpacker\n                    \"**/public/webpack/**\",  # Webpack\n                ]\n            )\n\n        return base_patterns\n\n    def _get_initialize_params(self) -> InitializeParams:\n        \"\"\"\n        Returns ruby-lsp specific initialization parameters.\n        \"\"\"\n        exclude_patterns = self._get_ruby_exclude_patterns(self.repository_root_path)\n\n        initialize_params = {\n            \"processId\": os.getpid(),\n            \"rootPath\": self.repository_root_path,\n            \"rootUri\": pathlib.Path(self.repository_root_path).as_uri(),\n            \"capabilities\": {\n                \"workspace\": {\n                    \"workspaceEdit\": {\"documentChanges\": True},\n                    \"configuration\": True,\n                },\n                \"window\": {\n                    \"workDoneProgress\": True,\n                },\n                \"textDocument\": {\n                    \"documentSymbol\": {\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"completion\": {\n                        \"completionItem\": {\n                            \"snippetSupport\": True,\n                            \"commitCharactersSupport\": True,\n                        }\n                    },\n                },\n            },\n            \"initializationOptions\": {\n                # ruby-lsp enables all features by default, so we don't need to specify enabledFeatures\n                \"experimentalFeaturesEnabled\": False,\n                \"featuresConfiguration\": {},\n                \"indexing\": {\n                    \"includedPatterns\": [\"**/*.rb\", \"**/*.rake\", \"**/*.ru\", \"**/*.erb\"],\n                    \"excludedPatterns\": exclude_patterns,\n                },\n            },\n        }\n\n        return initialize_params  # type: ignore\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the ruby-lsp Language Server for Ruby\n        \"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            assert \"registrations\" in params\n            for registration in params[\"registrations\"]:\n                log.info(f\"Registered capability: {registration['method']}\")\n            return\n\n        def lang_status_handler(params: dict) -> None:\n            log.info(f\"LSP: language/status: {params}\")\n            if params.get(\"type\") == \"ready\":\n                log.info(\"ruby-lsp service is ready.\")\n                self.analysis_complete.set()\n\n        def execute_client_command_handler(params: dict) -> list:\n            return []\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def progress_handler(params: dict) -> None:\n            # ruby-lsp sends progress notifications during indexing\n            log.debug(f\"LSP: $/progress: {params}\")\n            if \"value\" in params:\n                value = params[\"value\"]\n                # Check for completion indicators\n                if value.get(\"kind\") == \"end\":\n                    log.info(\"ruby-lsp indexing complete ($/progress end)\")\n                    self.analysis_complete.set()\n                elif value.get(\"kind\") == \"begin\":\n                    log.info(\"ruby-lsp indexing started ($/progress begin)\")\n                elif \"percentage\" in value:\n                    percentage = value.get(\"percentage\", 0)\n                    log.debug(f\"ruby-lsp indexing progress: {percentage}%\")\n            # Handle direct progress format (fallback)\n            elif \"token\" in params and \"value\" in params:\n                token = params.get(\"token\")\n                if isinstance(token, str) and \"indexing\" in token.lower():\n                    value = params.get(\"value\", {})\n                    if value.get(\"kind\") == \"end\" or value.get(\"percentage\") == 100:\n                        log.info(\"ruby-lsp indexing complete (token progress)\")\n                        self.analysis_complete.set()\n\n        def window_work_done_progress_create(params: dict) -> dict:\n            \"\"\"Handle workDoneProgress/create requests from ruby-lsp\"\"\"\n            log.debug(f\"LSP: window/workDoneProgress/create: {params}\")\n            return {}\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"language/status\", lang_status_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_request(\"workspace/executeClientCommand\", execute_client_command_handler)\n        self.server.on_notification(\"$/progress\", progress_handler)\n        self.server.on_request(\"window/workDoneProgress/create\", window_work_done_progress_create)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting ruby-lsp server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params()\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        log.info(f\"Sending init params: {json.dumps(initialize_params, indent=4)}\")\n        init_response = self.server.send.initialize(initialize_params)\n        log.info(f\"Received init response: {init_response}\")\n\n        # Verify expected capabilities\n        # Note: ruby-lsp may return textDocumentSync in different formats (number or object)\n        text_document_sync = init_response[\"capabilities\"].get(\"textDocumentSync\")\n        if isinstance(text_document_sync, int):\n            assert text_document_sync in [1, 2], f\"Unexpected textDocumentSync value: {text_document_sync}\"\n        elif isinstance(text_document_sync, dict):\n            # ruby-lsp returns an object with change property\n            assert \"change\" in text_document_sync, \"textDocumentSync object should have 'change' property\"\n\n        assert \"completionProvider\" in init_response[\"capabilities\"]\n\n        self.server.notify.initialized({})\n        # Wait for ruby-lsp to complete its initial indexing\n        # ruby-lsp has fast indexing\n        log.info(\"Waiting for ruby-lsp to complete initial indexing...\")\n        if self.analysis_complete.wait(timeout=30.0):\n            log.info(\"ruby-lsp initial indexing complete, server ready\")\n        else:\n            log.warning(\"Timeout waiting for ruby-lsp indexing completion, proceeding anyway\")\n            # Fallback: assume indexing is complete after timeout\n            self.analysis_complete.set()\n\n    def _handle_initialization_response(self, init_response: InitializeResult) -> None:\n        \"\"\"\n        Handle the initialization response from ruby-lsp and validate capabilities.\n        \"\"\"\n        if \"capabilities\" in init_response:\n            capabilities = init_response[\"capabilities\"]\n\n            # Validate textDocumentSync (ruby-lsp may return different formats)\n            text_document_sync = capabilities.get(\"textDocumentSync\")\n            if isinstance(text_document_sync, int):\n                assert text_document_sync in [1, 2], f\"Unexpected textDocumentSync value: {text_document_sync}\"\n            elif isinstance(text_document_sync, dict):\n                # ruby-lsp returns an object with change property\n                assert \"change\" in text_document_sync, \"textDocumentSync object should have 'change' property\"\n\n            # Log important capabilities\n            important_capabilities = [\n                \"completionProvider\",\n                \"hoverProvider\",\n                \"definitionProvider\",\n                \"referencesProvider\",\n                \"documentSymbolProvider\",\n                \"codeActionProvider\",\n                \"documentFormattingProvider\",\n                \"semanticTokensProvider\",\n            ]\n\n            for cap in important_capabilities:\n                if cap in capabilities:\n                    log.debug(f\"ruby-lsp {cap}: available\")\n\n        # Signal that the service is ready\n        self.service_ready_event.set()\n"
  },
  {
    "path": "src/solidlsp/language_servers/rust_analyzer.py",
    "content": "\"\"\"\nProvides Rust specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Rust.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport platform\nimport shutil\nimport subprocess\nimport threading\nfrom typing import cast\n\nfrom overrides import override\n\nfrom solidlsp.ls import LanguageServerDependencyProvider, LanguageServerDependencyProviderSinglePath, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass RustAnalyzer(SolidLanguageServer):\n    \"\"\"\n    Provides Rust specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Rust.\n    \"\"\"\n\n    @staticmethod\n    def _determine_log_level(line: str) -> int:\n        \"\"\"Classify rust-analyzer stderr output to avoid false-positive errors.\"\"\"\n        line_lower = line.lower()\n\n        # Known informational/warning messages from rust-analyzer that aren't critical errors\n        if any(\n            [\n                \"failed to find any projects in\" in line_lower,\n                \"fetchworkspaceerror\" in line_lower,\n            ]\n        ):\n            return logging.DEBUG\n\n        return SolidLanguageServer._determine_log_level(line)\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        @staticmethod\n        def _get_rustup_version() -> str | None:\n            \"\"\"Get installed rustup version or None if not found.\"\"\"\n            try:\n                result = subprocess.run([\"rustup\", \"--version\"], capture_output=True, text=True, check=False)\n                if result.returncode == 0:\n                    return result.stdout.strip()\n            except FileNotFoundError:\n                return None\n            return None\n\n        @staticmethod\n        def _get_rust_analyzer_via_rustup() -> str | None:\n            \"\"\"Get rust-analyzer path via rustup. Returns None if not found.\"\"\"\n            try:\n                result = subprocess.run([\"rustup\", \"which\", \"rust-analyzer\"], capture_output=True, text=True, check=False)\n                if result.returncode == 0:\n                    return result.stdout.strip()\n            except FileNotFoundError:\n                pass\n            return None\n\n        @staticmethod\n        def _ensure_rust_analyzer_installed() -> str:\n            \"\"\"\n            Ensure rust-analyzer is available.\n\n            Priority order:\n            1. Rustup existing installation (preferred - matches toolchain version)\n            2. Rustup auto-install if rustup is available (ensures correct version)\n            3. Common installation locations as fallback (only if rustup not available)\n            4. System PATH last (can pick up incompatible versions)\n\n            :return: path to rust-analyzer executable\n            \"\"\"\n            # Try rustup FIRST (preferred - avoids picking up incompatible versions from PATH)\n            rustup_path = RustAnalyzer.DependencyProvider._get_rust_analyzer_via_rustup()\n            if rustup_path:\n                return rustup_path\n\n            # If rustup is available but rust-analyzer not installed, auto-install it BEFORE\n            # checking common paths. This ensures we get the correct version matching the toolchain.\n            if RustAnalyzer.DependencyProvider._get_rustup_version():\n                result = subprocess.run([\"rustup\", \"component\", \"add\", \"rust-analyzer\"], check=False, capture_output=True, text=True)\n                if result.returncode == 0:\n                    # Verify installation worked\n                    rustup_path = RustAnalyzer.DependencyProvider._get_rust_analyzer_via_rustup()\n                    if rustup_path:\n                        return rustup_path\n                # If auto-install failed, fall through to common paths as last resort\n\n            # Determine platform-specific binary name and paths\n            is_windows = platform.system() == \"Windows\"\n            binary_name = \"rust-analyzer.exe\" if is_windows else \"rust-analyzer\"\n\n            # Fallback to common installation locations (only used if rustup not available)\n            common_paths: list[str | None] = []\n\n            if is_windows:\n                # Windows-specific paths\n                home = pathlib.Path.home()\n                common_paths.extend(\n                    [\n                        str(home / \".cargo\" / \"bin\" / binary_name),  # cargo install / rustup\n                        str(home / \"scoop\" / \"shims\" / binary_name),  # Scoop package manager\n                        str(home / \"scoop\" / \"apps\" / \"rust-analyzer\" / \"current\" / binary_name),  # Scoop direct\n                        str(\n                            pathlib.Path(os.environ.get(\"LOCALAPPDATA\", \"\")) / \"Programs\" / \"rust-analyzer\" / binary_name\n                        ),  # Standalone install\n                    ]\n                )\n            else:\n                # Unix-like paths (macOS, Linux)\n                common_paths.extend(\n                    [\n                        \"/opt/homebrew/bin/rust-analyzer\",  # macOS Homebrew (Apple Silicon)\n                        \"/usr/local/bin/rust-analyzer\",  # macOS Homebrew (Intel) / Linux system\n                        os.path.expanduser(\"~/.cargo/bin/rust-analyzer\"),  # cargo install\n                        os.path.expanduser(\"~/.local/bin/rust-analyzer\"),  # User local bin\n                    ]\n                )\n\n            for path in common_paths:\n                if path and os.path.isfile(path) and os.access(path, os.X_OK):\n                    return path\n\n            # Last resort: check system PATH (can pick up incorrect aliases, hence checked last)\n            path_result = shutil.which(\"rust-analyzer\")\n            if path_result and os.path.isfile(path_result) and os.access(path_result, os.X_OK):\n                return path_result\n\n            # Provide helpful error message with all searched locations\n            searched = [p for p in common_paths if p]\n            install_instructions = [\n                \"  - Rustup: rustup component add rust-analyzer\",\n                \"  - Cargo: cargo install rust-analyzer\",\n            ]\n            if is_windows:\n                install_instructions.extend(\n                    [\n                        \"  - Scoop: scoop install rust-analyzer\",\n                        \"  - Chocolatey: choco install rust-analyzer\",\n                        \"  - Standalone: Download from https://github.com/rust-lang/rust-analyzer/releases\",\n                    ]\n                )\n            else:\n                install_instructions.extend(\n                    [\n                        \"  - Homebrew (macOS): brew install rust-analyzer\",\n                        \"  - System package manager (Linux): apt/dnf/pacman install rust-analyzer\",\n                    ]\n                )\n\n            raise RuntimeError(\n                \"rust-analyzer is not installed or not in PATH.\\n\"\n                \"Searched locations:\\n\" + \"\\n\".join(f\"  - {p}\" for p in searched) + \"\\n\"\n                \"Please install rust-analyzer via:\\n\" + \"\\n\".join(install_instructions)\n            )\n\n        def _get_or_install_core_dependency(self) -> str:\n            return self._ensure_rust_analyzer_installed()\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [core_path]\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a RustAnalyzer instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(\n            config,\n            repository_root_path,\n            None,\n            \"rust\",\n            solidlsp_settings,\n        )\n        self.server_ready = threading.Event()\n        self.service_ready_event = threading.Event()\n        self.initialize_searcher_command_available = threading.Event()\n        self.resolve_main_method_available = threading.Event()\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\"target\"]\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Rust Analyzer Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"clientInfo\": {\"name\": \"Visual Studio Code - Insiders\", \"version\": \"1.82.0-insider\"},\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"workspace\": {\n                    \"applyEdit\": True,\n                    \"workspaceEdit\": {\n                        \"documentChanges\": True,\n                        \"resourceOperations\": [\"create\", \"rename\", \"delete\"],\n                        \"failureHandling\": \"textOnlyTransactional\",\n                        \"normalizesLineEndings\": True,\n                        \"changeAnnotationSupport\": {\"groupsOnLabel\": True},\n                    },\n                    \"configuration\": True,\n                    \"didChangeWatchedFiles\": {\"dynamicRegistration\": True, \"relativePatternSupport\": True},\n                    \"symbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                        \"tagSupport\": {\"valueSet\": [1]},\n                        \"resolveSupport\": {\"properties\": [\"location.range\"]},\n                    },\n                    \"codeLens\": {\"refreshSupport\": True},\n                    \"executeCommand\": {\"dynamicRegistration\": True},\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"workspaceFolders\": True,\n                    \"semanticTokens\": {\"refreshSupport\": True},\n                    \"fileOperations\": {\n                        \"dynamicRegistration\": True,\n                        \"didCreate\": True,\n                        \"didRename\": True,\n                        \"didDelete\": True,\n                        \"willCreate\": True,\n                        \"willRename\": True,\n                        \"willDelete\": True,\n                    },\n                    \"inlineValue\": {\"refreshSupport\": True},\n                    \"inlayHint\": {\"refreshSupport\": True},\n                    \"diagnostics\": {\"refreshSupport\": True},\n                },\n                \"textDocument\": {\n                    \"publishDiagnostics\": {\n                        \"relatedInformation\": True,\n                        \"versionSupport\": False,\n                        \"tagSupport\": {\"valueSet\": [1, 2]},\n                        \"codeDescriptionSupport\": True,\n                        \"dataSupport\": True,\n                    },\n                    \"synchronization\": {\"dynamicRegistration\": True, \"willSave\": True, \"willSaveWaitUntil\": True, \"didSave\": True},\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"contextSupport\": True,\n                        \"completionItem\": {\n                            \"snippetSupport\": True,\n                            \"commitCharactersSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"deprecatedSupport\": True,\n                            \"preselectSupport\": True,\n                            \"tagSupport\": {\"valueSet\": [1]},\n                            \"insertReplaceSupport\": True,\n                            \"resolveSupport\": {\"properties\": [\"documentation\", \"detail\", \"additionalTextEdits\"]},\n                            \"insertTextModeSupport\": {\"valueSet\": [1, 2]},\n                            \"labelDetailsSupport\": True,\n                        },\n                        \"insertTextMode\": 2,\n                        \"completionItemKind\": {\n                            \"valueSet\": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]\n                        },\n                        \"completionList\": {\"itemDefaults\": [\"commitCharacters\", \"editRange\", \"insertTextFormat\", \"insertTextMode\"]},\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"signatureHelp\": {\n                        \"dynamicRegistration\": True,\n                        \"signatureInformation\": {\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"parameterInformation\": {\"labelOffsetSupport\": True},\n                            \"activeParameterSupport\": True,\n                        },\n                        \"contextSupport\": True,\n                    },\n                    \"definition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentHighlight\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"tagSupport\": {\"valueSet\": [1]},\n                        \"labelSupport\": True,\n                    },\n                    \"codeAction\": {\n                        \"dynamicRegistration\": True,\n                        \"isPreferredSupport\": True,\n                        \"disabledSupport\": True,\n                        \"dataSupport\": True,\n                        \"resolveSupport\": {\"properties\": [\"edit\"]},\n                        \"codeActionLiteralSupport\": {\n                            \"codeActionKind\": {\n                                \"valueSet\": [\n                                    \"\",\n                                    \"quickfix\",\n                                    \"refactor\",\n                                    \"refactor.extract\",\n                                    \"refactor.inline\",\n                                    \"refactor.rewrite\",\n                                    \"source\",\n                                    \"source.organizeImports\",\n                                ]\n                            }\n                        },\n                        \"honorsChangeAnnotations\": False,\n                    },\n                    \"codeLens\": {\"dynamicRegistration\": True},\n                    \"formatting\": {\"dynamicRegistration\": True},\n                    \"rangeFormatting\": {\"dynamicRegistration\": True},\n                    \"onTypeFormatting\": {\"dynamicRegistration\": True},\n                    \"rename\": {\n                        \"dynamicRegistration\": True,\n                        \"prepareSupport\": True,\n                        \"prepareSupportDefaultBehavior\": 1,\n                        \"honorsChangeAnnotations\": True,\n                    },\n                    \"documentLink\": {\"dynamicRegistration\": True, \"tooltipSupport\": True},\n                    \"typeDefinition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"implementation\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"colorProvider\": {\"dynamicRegistration\": True},\n                    \"foldingRange\": {\n                        \"dynamicRegistration\": True,\n                        \"rangeLimit\": 5000,\n                        \"lineFoldingOnly\": True,\n                        \"foldingRangeKind\": {\"valueSet\": [\"comment\", \"imports\", \"region\"]},\n                        \"foldingRange\": {\"collapsedText\": False},\n                    },\n                    \"declaration\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"selectionRange\": {\"dynamicRegistration\": True},\n                    \"callHierarchy\": {\"dynamicRegistration\": True},\n                    \"semanticTokens\": {\n                        \"dynamicRegistration\": True,\n                        \"tokenTypes\": [\n                            \"namespace\",\n                            \"type\",\n                            \"class\",\n                            \"enum\",\n                            \"interface\",\n                            \"struct\",\n                            \"typeParameter\",\n                            \"parameter\",\n                            \"variable\",\n                            \"property\",\n                            \"enumMember\",\n                            \"event\",\n                            \"function\",\n                            \"method\",\n                            \"macro\",\n                            \"keyword\",\n                            \"modifier\",\n                            \"comment\",\n                            \"string\",\n                            \"number\",\n                            \"regexp\",\n                            \"operator\",\n                            \"decorator\",\n                        ],\n                        \"tokenModifiers\": [\n                            \"declaration\",\n                            \"definition\",\n                            \"readonly\",\n                            \"static\",\n                            \"deprecated\",\n                            \"abstract\",\n                            \"async\",\n                            \"modification\",\n                            \"documentation\",\n                            \"defaultLibrary\",\n                        ],\n                        \"formats\": [\"relative\"],\n                        \"requests\": {\"range\": True, \"full\": {\"delta\": True}},\n                        \"multilineTokenSupport\": False,\n                        \"overlappingTokenSupport\": False,\n                        \"serverCancelSupport\": True,\n                        \"augmentsSyntaxTokens\": False,\n                    },\n                    \"linkedEditingRange\": {\"dynamicRegistration\": True},\n                    \"typeHierarchy\": {\"dynamicRegistration\": True},\n                    \"inlineValue\": {\"dynamicRegistration\": True},\n                    \"inlayHint\": {\n                        \"dynamicRegistration\": True,\n                        \"resolveSupport\": {\"properties\": [\"tooltip\", \"textEdits\", \"label.tooltip\", \"label.location\", \"label.command\"]},\n                    },\n                    \"diagnostic\": {\"dynamicRegistration\": True, \"relatedDocumentSupport\": False},\n                },\n                \"window\": {\n                    \"showMessage\": {\"messageActionItem\": {\"additionalPropertiesSupport\": True}},\n                    \"showDocument\": {\"support\": True},\n                    \"workDoneProgress\": True,\n                },\n                \"general\": {\n                    \"staleRequestSupport\": {\n                        \"cancel\": True,\n                        \"retryOnContentModified\": [\n                            \"textDocument/semanticTokens/full\",\n                            \"textDocument/semanticTokens/range\",\n                            \"textDocument/semanticTokens/full/delta\",\n                        ],\n                    },\n                    \"regularExpressions\": {\"engine\": \"ECMAScript\", \"version\": \"ES2020\"},\n                    \"markdown\": {\n                        \"parser\": \"marked\",\n                        \"version\": \"1.1.0\",\n                        \"allowedTags\": [\n                            \"ul\",\n                            \"li\",\n                            \"p\",\n                            \"code\",\n                            \"blockquote\",\n                            \"ol\",\n                            \"h1\",\n                            \"h2\",\n                            \"h3\",\n                            \"h4\",\n                            \"h5\",\n                            \"h6\",\n                            \"hr\",\n                            \"em\",\n                            \"pre\",\n                            \"table\",\n                            \"thead\",\n                            \"tbody\",\n                            \"tr\",\n                            \"th\",\n                            \"td\",\n                            \"div\",\n                            \"del\",\n                            \"a\",\n                            \"strong\",\n                            \"br\",\n                            \"img\",\n                            \"span\",\n                        ],\n                    },\n                    \"positionEncodings\": [\"utf-16\"],\n                },\n                \"notebookDocument\": {\"synchronization\": {\"dynamicRegistration\": True, \"executionSummarySupport\": True}},\n                \"experimental\": {\n                    \"snippetTextEdit\": True,\n                    \"codeActionGroup\": True,\n                    \"hoverActions\": True,\n                    \"serverStatusNotification\": True,\n                    \"colorDiagnosticOutput\": True,\n                    \"openServerLogs\": True,\n                    \"localDocs\": True,\n                    \"commands\": {\n                        \"commands\": [\n                            \"rust-analyzer.runSingle\",\n                            \"rust-analyzer.debugSingle\",\n                            \"rust-analyzer.showReferences\",\n                            \"rust-analyzer.gotoLocation\",\n                            \"editor.action.triggerParameterHints\",\n                        ]\n                    },\n                },\n            },\n            \"initializationOptions\": {\n                \"cargoRunner\": None,\n                \"runnables\": {\"extraEnv\": None, \"problemMatcher\": [\"$rustc\"], \"command\": None, \"extraArgs\": []},\n                \"statusBar\": {\"clickAction\": \"openLogs\"},\n                \"server\": {\"path\": None, \"extraEnv\": None},\n                \"trace\": {\"server\": \"verbose\", \"extension\": False},\n                \"debug\": {\n                    \"engine\": \"auto\",\n                    \"sourceFileMap\": {\"/rustc/<id>\": \"${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust\"},\n                    \"openDebugPane\": False,\n                    \"engineSettings\": {},\n                },\n                \"restartServerOnConfigChange\": False,\n                \"typing\": {\"continueCommentsOnNewline\": True, \"autoClosingAngleBrackets\": {\"enable\": False}},\n                \"diagnostics\": {\n                    \"previewRustcOutput\": False,\n                    \"useRustcErrorCode\": False,\n                    \"disabled\": [],\n                    \"enable\": True,\n                    \"experimental\": {\"enable\": False},\n                    \"remapPrefix\": {},\n                    \"warningsAsHint\": [],\n                    \"warningsAsInfo\": [],\n                },\n                \"discoverProjectRunner\": None,\n                \"showUnlinkedFileNotification\": True,\n                \"showDependenciesExplorer\": True,\n                \"assist\": {\"emitMustUse\": False, \"expressionFillDefault\": \"todo\"},\n                \"cachePriming\": {\"enable\": True, \"numThreads\": 0},\n                \"cargo\": {\n                    \"autoreload\": True,\n                    \"buildScripts\": {\n                        \"enable\": True,\n                        \"invocationLocation\": \"workspace\",\n                        \"invocationStrategy\": \"per_workspace\",\n                        \"overrideCommand\": None,\n                        \"useRustcWrapper\": True,\n                    },\n                    \"cfgs\": [],\n                    \"extraArgs\": [],\n                    \"extraEnv\": {},\n                    \"features\": [],\n                    \"noDefaultFeatures\": False,\n                    \"sysroot\": \"discover\",\n                    \"sysrootSrc\": None,\n                    \"target\": None,\n                    \"unsetTest\": [\"core\"],\n                },\n                \"checkOnSave\": True,\n                \"check\": {\n                    \"allTargets\": True,\n                    \"command\": \"check\",\n                    \"extraArgs\": [],\n                    \"extraEnv\": {},\n                    \"features\": None,\n                    \"ignore\": [],\n                    \"invocationLocation\": \"workspace\",\n                    \"invocationStrategy\": \"per_workspace\",\n                    \"noDefaultFeatures\": None,\n                    \"overrideCommand\": None,\n                    \"targets\": None,\n                },\n                \"completion\": {\n                    \"autoimport\": {\"enable\": True},\n                    \"autoself\": {\"enable\": True},\n                    \"callable\": {\"snippets\": \"fill_arguments\"},\n                    \"fullFunctionSignatures\": {\"enable\": False},\n                    \"limit\": None,\n                    \"postfix\": {\"enable\": True},\n                    \"privateEditable\": {\"enable\": False},\n                    \"snippets\": {\n                        \"custom\": {\n                            \"Arc::new\": {\n                                \"postfix\": \"arc\",\n                                \"body\": \"Arc::new(${receiver})\",\n                                \"requires\": \"std::sync::Arc\",\n                                \"description\": \"Put the expression into an `Arc`\",\n                                \"scope\": \"expr\",\n                            },\n                            \"Rc::new\": {\n                                \"postfix\": \"rc\",\n                                \"body\": \"Rc::new(${receiver})\",\n                                \"requires\": \"std::rc::Rc\",\n                                \"description\": \"Put the expression into an `Rc`\",\n                                \"scope\": \"expr\",\n                            },\n                            \"Box::pin\": {\n                                \"postfix\": \"pinbox\",\n                                \"body\": \"Box::pin(${receiver})\",\n                                \"requires\": \"std::boxed::Box\",\n                                \"description\": \"Put the expression into a pinned `Box`\",\n                                \"scope\": \"expr\",\n                            },\n                            \"Ok\": {\n                                \"postfix\": \"ok\",\n                                \"body\": \"Ok(${receiver})\",\n                                \"description\": \"Wrap the expression in a `Result::Ok`\",\n                                \"scope\": \"expr\",\n                            },\n                            \"Err\": {\n                                \"postfix\": \"err\",\n                                \"body\": \"Err(${receiver})\",\n                                \"description\": \"Wrap the expression in a `Result::Err`\",\n                                \"scope\": \"expr\",\n                            },\n                            \"Some\": {\n                                \"postfix\": \"some\",\n                                \"body\": \"Some(${receiver})\",\n                                \"description\": \"Wrap the expression in an `Option::Some`\",\n                                \"scope\": \"expr\",\n                            },\n                        }\n                    },\n                },\n                \"files\": {\"excludeDirs\": [], \"watcher\": \"client\"},\n                \"highlightRelated\": {\n                    \"breakPoints\": {\"enable\": True},\n                    \"closureCaptures\": {\"enable\": True},\n                    \"exitPoints\": {\"enable\": True},\n                    \"references\": {\"enable\": True},\n                    \"yieldPoints\": {\"enable\": True},\n                },\n                \"hover\": {\n                    \"actions\": {\n                        \"debug\": {\"enable\": True},\n                        \"enable\": True,\n                        \"gotoTypeDef\": {\"enable\": True},\n                        \"implementations\": {\"enable\": True},\n                        \"references\": {\"enable\": False},\n                        \"run\": {\"enable\": True},\n                    },\n                    \"documentation\": {\"enable\": True, \"keywords\": {\"enable\": True}},\n                    \"links\": {\"enable\": True},\n                    \"memoryLayout\": {\"alignment\": \"hexadecimal\", \"enable\": True, \"niches\": False, \"offset\": \"hexadecimal\", \"size\": \"both\"},\n                },\n                \"imports\": {\n                    \"granularity\": {\"enforce\": False, \"group\": \"crate\"},\n                    \"group\": {\"enable\": True},\n                    \"merge\": {\"glob\": True},\n                    \"preferNoStd\": False,\n                    \"preferPrelude\": False,\n                    \"prefix\": \"plain\",\n                },\n                \"inlayHints\": {\n                    \"bindingModeHints\": {\"enable\": False},\n                    \"chainingHints\": {\"enable\": True},\n                    \"closingBraceHints\": {\"enable\": True, \"minLines\": 25},\n                    \"closureCaptureHints\": {\"enable\": False},\n                    \"closureReturnTypeHints\": {\"enable\": \"never\"},\n                    \"closureStyle\": \"impl_fn\",\n                    \"discriminantHints\": {\"enable\": \"never\"},\n                    \"expressionAdjustmentHints\": {\"enable\": \"never\", \"hideOutsideUnsafe\": False, \"mode\": \"prefix\"},\n                    \"lifetimeElisionHints\": {\"enable\": \"never\", \"useParameterNames\": False},\n                    \"maxLength\": 25,\n                    \"parameterHints\": {\"enable\": True},\n                    \"reborrowHints\": {\"enable\": \"never\"},\n                    \"renderColons\": True,\n                    \"typeHints\": {\"enable\": True, \"hideClosureInitialization\": False, \"hideNamedConstructor\": False},\n                },\n                \"interpret\": {\"tests\": False},\n                \"joinLines\": {\"joinAssignments\": True, \"joinElseIf\": True, \"removeTrailingComma\": True, \"unwrapTrivialBlock\": True},\n                \"lens\": {\n                    \"debug\": {\"enable\": True},\n                    \"enable\": True,\n                    \"forceCustomCommands\": True,\n                    \"implementations\": {\"enable\": True},\n                    \"location\": \"above_name\",\n                    \"references\": {\n                        \"adt\": {\"enable\": False},\n                        \"enumVariant\": {\"enable\": False},\n                        \"method\": {\"enable\": False},\n                        \"trait\": {\"enable\": False},\n                    },\n                    \"run\": {\"enable\": True},\n                },\n                \"linkedProjects\": [],\n                \"lru\": {\"capacity\": None, \"query\": {\"capacities\": {}}},\n                \"notifications\": {\"cargoTomlNotFound\": True},\n                \"numThreads\": None,\n                \"procMacro\": {\"attributes\": {\"enable\": True}, \"enable\": True, \"ignored\": {}, \"server\": None},\n                \"references\": {\"excludeImports\": False},\n                \"rust\": {\"analyzerTargetDir\": None},\n                \"rustc\": {\"source\": None},\n                \"rustfmt\": {\"extraArgs\": [], \"overrideCommand\": None, \"rangeFormatting\": {\"enable\": False}},\n                \"semanticHighlighting\": {\n                    \"doc\": {\"comment\": {\"inject\": {\"enable\": True}}},\n                    \"nonStandardTokens\": True,\n                    \"operator\": {\"enable\": True, \"specialization\": {\"enable\": False}},\n                    \"punctuation\": {\"enable\": False, \"separate\": {\"macro\": {\"bang\": False}}, \"specialization\": {\"enable\": False}},\n                    \"strings\": {\"enable\": True},\n                },\n                \"signatureInfo\": {\"detail\": \"full\", \"documentation\": {\"enable\": True}},\n                \"workspace\": {\"symbol\": {\"search\": {\"kind\": \"only_types\", \"limit\": 128, \"scope\": \"workspace\"}}},\n            },\n            \"trace\": \"verbose\",\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return cast(InitializeParams, initialize_params)\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the Rust Analyzer Language Server\n        \"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            assert \"registrations\" in params\n            for registration in params[\"registrations\"]:\n                if registration[\"method\"] == \"workspace/executeCommand\":\n                    self.initialize_searcher_command_available.set()\n                    self.resolve_main_method_available.set()\n            return\n\n        def lang_status_handler(params: dict) -> None:\n            # TODO: Should we wait for\n            # server -> client: {'jsonrpc': '2.0', 'method': 'language/status', 'params': {'type': 'ProjectStatus', 'message': 'OK'}}\n            # Before proceeding?\n            if params[\"type\"] == \"ServiceReady\" and params[\"message\"] == \"ServiceReady\":\n                self.service_ready_event.set()\n\n        def execute_client_command_handler(params: dict) -> list:\n            return []\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def check_experimental_status(params: dict) -> None:\n            if params[\"quiescent\"] == True:\n                self.server_ready.set()\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"language/status\", lang_status_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_request(\"workspace/executeClientCommand\", execute_client_command_handler)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"language/actionableNotification\", do_nothing)\n        self.server.on_notification(\"experimental/serverStatus\", check_experimental_status)\n\n        log.info(\"Starting RustAnalyzer server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        assert init_response[\"capabilities\"][\"textDocumentSync\"][\"change\"] == 2  # type: ignore\n        assert \"completionProvider\" in init_response[\"capabilities\"]\n        assert init_response[\"capabilities\"][\"completionProvider\"] == {\n            \"resolveProvider\": True,\n            \"triggerCharacters\": [\":\", \".\", \"'\", \"(\"],\n            \"completionItem\": {\"labelDetailsSupport\": True},\n        }\n        self.server.notify.initialized({})\n\n        self.server_ready.wait()\n"
  },
  {
    "path": "src/solidlsp/language_servers/scala_language_server.py",
    "content": "\"\"\"\nProvides Scala specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Scala.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport shutil\nimport subprocess\nfrom enum import Enum\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.ls_utils import PlatformUtils\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nif not PlatformUtils.get_platform_id().value.startswith(\"win\"):\n    pass\n\n\nlog = logging.getLogger(__name__)\n\n# Default configuration constants\nDEFAULT_METALS_VERSION = \"1.6.4\"\nDEFAULT_CLIENT_NAME = \"Serena\"\nDEFAULT_ON_STALE_LOCK = \"auto-clean\"\nDEFAULT_LOG_MULTI_INSTANCE_NOTICE = True\n\n\nclass StaleLockMode(Enum):\n    \"\"\"Mode for handling stale Metals H2 database locks.\"\"\"\n\n    AUTO_CLEAN = \"auto-clean\"\n    \"\"\"Automatically remove stale lock files (default, recommended).\"\"\"\n\n    WARN = \"warn\"\n    \"\"\"Log a warning but proceed; may result in degraded experience.\"\"\"\n\n    FAIL = \"fail\"\n    \"\"\"Raise an error and refuse to start.\"\"\"\n\n\ndef _get_scala_settings(solidlsp_settings: SolidLSPSettings) -> dict[str, object]:\n    \"\"\"\n    Extract Scala-specific settings with defaults applied.\n\n    Returns a dictionary with keys:\n        - metals_version: str\n        - client_name: str\n        - on_stale_lock: StaleLockMode\n        - log_multi_instance_notice: bool\n    \"\"\"\n    from solidlsp.ls_config import Language\n\n    defaults: dict[str, object] = {\n        \"metals_version\": DEFAULT_METALS_VERSION,\n        \"client_name\": DEFAULT_CLIENT_NAME,\n        \"on_stale_lock\": StaleLockMode.AUTO_CLEAN,\n        \"log_multi_instance_notice\": DEFAULT_LOG_MULTI_INSTANCE_NOTICE,\n    }\n\n    if not solidlsp_settings.ls_specific_settings:\n        return defaults\n\n    scala_settings = solidlsp_settings.get_ls_specific_settings(Language.SCALA)\n\n    # Parse stale lock mode with validation\n    on_stale_lock_str = scala_settings.get(\"on_stale_lock\", DEFAULT_ON_STALE_LOCK)\n    try:\n        on_stale_lock = StaleLockMode(on_stale_lock_str)\n    except ValueError:\n        log.warning(f\"Invalid on_stale_lock value '{on_stale_lock_str}', using '{DEFAULT_ON_STALE_LOCK}'\")\n        on_stale_lock = StaleLockMode.AUTO_CLEAN\n\n    return {\n        \"metals_version\": scala_settings.get(\"metals_version\", DEFAULT_METALS_VERSION),\n        \"client_name\": scala_settings.get(\"client_name\", DEFAULT_CLIENT_NAME),\n        \"on_stale_lock\": on_stale_lock,\n        \"log_multi_instance_notice\": scala_settings.get(\"log_multi_instance_notice\", DEFAULT_LOG_MULTI_INSTANCE_NOTICE),\n    }\n\n\nclass ScalaLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides Scala specific instantiation of the LanguageServer class.\n    Contains various configurations and settings specific to Scala.\n\n    Configurable options in ls_specific_settings (in serena_config.yml):\n\n        ls_specific_settings:\n          scala:\n            # Stale lock handling: auto-clean | warn | fail\n            on_stale_lock: 'auto-clean'\n            # Log notice when another Metals instance is detected\n            log_multi_instance_notice: true\n            # Metals version to bootstrap (default: DEFAULT_METALS_VERSION)\n            metals_version: '1.6.4'\n            # Client identifier sent to Metals (default: DEFAULT_CLIENT_NAME)\n            client_name: 'Serena'\n\n    Multi-instance support:\n        Metals uses H2 AUTO_SERVER mode (enabled by default) to support multiple\n        concurrent instances sharing the same database. Running Serena's Metals\n        alongside VS Code's Metals is designed to work. The only issue is stale\n        locks from crashed processes, which this class can detect and clean up.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a ScalaLanguageServer instance. This class is not meant to be instantiated directly.\n        Use LanguageServer.create() instead.\n        \"\"\"\n        # Check for stale locks before setting up dependencies (fail-fast)\n        self._check_metals_db_status(repository_root_path, solidlsp_settings)\n\n        scala_lsp_executable_path = self._setup_runtime_dependencies(config, solidlsp_settings)\n        super().__init__(\n            config,\n            repository_root_path,\n            ProcessLaunchInfo(cmd=scala_lsp_executable_path, cwd=repository_root_path),\n            config.code_language.value,\n            solidlsp_settings,\n        )\n\n    def _check_metals_db_status(self, repository_root_path: str, solidlsp_settings: SolidLSPSettings) -> None:\n        \"\"\"\n        Check the Metals H2 database status and handle stale locks.\n\n        This method is called before setting up runtime dependencies to fail-fast\n        if there's a stale lock that the user has configured to fail on.\n        \"\"\"\n        from pathlib import Path\n\n        from solidlsp.ls_exceptions import MetalsStaleLockError\n        from solidlsp.util.metals_db_utils import (\n            MetalsDbStatus,\n            check_metals_db_status,\n            cleanup_stale_lock,\n        )\n\n        project_path = Path(repository_root_path)\n        status, lock_info = check_metals_db_status(project_path)\n\n        # Get settings using the shared helper function\n        settings = _get_scala_settings(solidlsp_settings)\n        on_stale_lock: StaleLockMode = settings[\"on_stale_lock\"]  # type: ignore[assignment]\n        log_multi_instance_notice: bool = settings[\"log_multi_instance_notice\"]  # type: ignore[assignment]\n\n        if status == MetalsDbStatus.ACTIVE_INSTANCE:\n            if log_multi_instance_notice and lock_info:\n                log.info(\n                    f\"Another Metals instance detected (PID: {lock_info.pid}). \"\n                    \"This is fine - Metals supports multiple instances via H2 AUTO_SERVER. \"\n                    \"Both instances will share the database and Bloop build server.\"\n                )\n\n        elif status == MetalsDbStatus.STALE_LOCK:\n            lock_path = lock_info.lock_path if lock_info else project_path / \".metals\" / \"metals.mv.db.lock.db\"\n            lock_path_str = str(lock_path)\n\n            if on_stale_lock == StaleLockMode.AUTO_CLEAN:\n                log.info(f\"Stale Metals lock detected, cleaning up: {lock_path_str}\")\n                cleanup_success = cleanup_stale_lock(lock_path)\n                if not cleanup_success:\n                    log.warning(\n                        f\"Failed to clean up stale lock at {lock_path_str}. \"\n                        \"Metals may fall back to in-memory database (degraded experience).\"\n                    )\n\n            elif on_stale_lock == StaleLockMode.WARN:\n                log.warning(\n                    f\"Stale Metals lock detected at {lock_path_str}. \"\n                    \"A previous Metals process may have crashed. \"\n                    \"Metals will fall back to in-memory database (degraded experience). \"\n                    \"Consider removing the lock file manually or setting on_stale_lock='auto-clean'.\"\n                )\n\n            elif on_stale_lock == StaleLockMode.FAIL:\n                raise MetalsStaleLockError(lock_path_str)\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\n            \".bloop\",\n            \".metals\",\n            \"target\",\n        ]\n\n    @classmethod\n    def _setup_runtime_dependencies(cls, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings) -> list[str]:\n        \"\"\"\n        Setup runtime dependencies for Scala Language Server and return the command to start the server.\n        \"\"\"\n        assert shutil.which(\"java\") is not None, \"JDK is not installed or not in PATH.\"\n\n        # Check if metals is available globally in PATH\n        global_metals = shutil.which(\"metals\")\n        if global_metals:\n            log.info(f\"Found metals in PATH: {global_metals}\")\n            return [global_metals]\n\n        # Get settings using the shared helper function\n        settings = _get_scala_settings(solidlsp_settings)\n        metals_version: str = settings[\"metals_version\"]  # type: ignore[assignment]\n        client_name: str = settings[\"client_name\"]  # type: ignore[assignment]\n\n        metals_home = os.path.join(cls.ls_resources_dir(solidlsp_settings), \"metals-lsp\")\n        os.makedirs(metals_home, exist_ok=True)\n        metals_executable = os.path.join(metals_home, metals_version, \"metals\")\n\n        if not os.path.exists(metals_executable):\n            coursier_command_path = shutil.which(\"coursier\")\n            cs_command_path = shutil.which(\"cs\")\n            assert cs_command_path is not None or coursier_command_path is not None, \"coursier is not installed or not in PATH.\"\n\n            if not cs_command_path:\n                assert coursier_command_path is not None\n                log.info(\"'cs' command not found. Trying to install it using 'coursier'.\")\n                try:\n                    log.info(\"Running 'coursier setup --yes' to install 'cs'...\")\n                    subprocess.run([coursier_command_path, \"setup\", \"--yes\"], check=True, capture_output=True, text=True)\n                except subprocess.CalledProcessError as e:\n                    raise RuntimeError(f\"Failed to set up 'cs' command with 'coursier setup'. Stderr: {e.stderr}\")\n\n                cs_command_path = shutil.which(\"cs\")\n                if not cs_command_path:\n                    raise RuntimeError(\n                        \"'cs' command not found after running 'coursier setup'. Please check your PATH or install it manually.\"\n                    )\n                log.info(\"'cs' command installed successfully.\")\n\n            log.info(f\"metals executable not found at {metals_executable}, bootstrapping...\")\n            subprocess.run([\"mkdir\", \"-p\", os.path.join(metals_home, metals_version)], check=True)\n            artifact = f\"org.scalameta:metals_2.13:{metals_version}\"\n            cmd = [\n                cs_command_path,\n                \"bootstrap\",\n                \"--java-opt\",\n                \"-XX:+UseG1GC\",\n                \"--java-opt\",\n                \"-XX:+UseStringDeduplication\",\n                \"--java-opt\",\n                \"-Xss4m\",\n                \"--java-opt\",\n                \"-Xms100m\",\n                \"--java-opt\",\n                f\"-Dmetals.client={client_name}\",\n                artifact,\n                \"-o\",\n                metals_executable,\n                \"-f\",\n            ]\n            log.info(\"Bootstrapping metals...\")\n            subprocess.run(cmd, cwd=metals_home, check=True)\n            log.info(\"Bootstrapping metals finished.\")\n        return [metals_executable]\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Scala Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"initializationOptions\": {\n                \"compilerOptions\": {\n                    \"completionCommand\": None,\n                    \"isCompletionItemDetailEnabled\": True,\n                    \"isCompletionItemDocumentationEnabled\": True,\n                    \"isCompletionItemResolve\": True,\n                    \"isHoverDocumentationEnabled\": True,\n                    \"isSignatureHelpDocumentationEnabled\": True,\n                    \"overrideDefFormat\": \"ascli\",\n                    \"snippetAutoIndent\": False,\n                },\n                \"debuggingProvider\": True,\n                \"decorationProvider\": False,\n                \"didFocusProvider\": False,\n                \"doctorProvider\": False,\n                \"executeClientCommandProvider\": False,\n                \"globSyntax\": \"uri\",\n                \"icons\": \"unicode\",\n                \"inputBoxProvider\": False,\n                \"isVirtualDocumentSupported\": False,\n                \"isExitOnShutdown\": True,\n                \"isHttpEnabled\": True,\n                \"openFilesOnRenameProvider\": False,\n                \"quickPickProvider\": False,\n                \"renameFileThreshold\": 200,\n                \"statusBarProvider\": \"false\",\n                \"treeViewProvider\": False,\n                \"testExplorerProvider\": False,\n                \"openNewWindowProvider\": False,\n                \"copyWorksheetOutputProvider\": False,\n                \"doctorVisibilityProvider\": False,\n            },\n            \"capabilities\": {\"textDocument\": {\"documentSymbol\": {\"hierarchicalDocumentSymbolSupport\": True}}},\n        }\n        return initialize_params  # type: ignore\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the Scala Language Server\n        \"\"\"\n        log.info(\"Starting Scala server process\")\n        self.server.start()\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n        self.server.send.initialize(initialize_params)\n        self.server.notify.initialized({})\n\n    @override\n    def _get_wait_time_for_cross_file_referencing(self) -> float:\n        return 5\n"
  },
  {
    "path": "src/solidlsp/language_servers/solargraph.py",
    "content": "\"\"\"\nProvides Ruby specific instantiation of the LanguageServer class using Solargraph.\nContains various configurations and settings specific to Ruby.\n\"\"\"\n\nimport json\nimport logging\nimport os\nimport pathlib\nimport re\nimport shutil\nimport subprocess\nimport threading\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass Solargraph(SolidLanguageServer):\n    \"\"\"\n    Provides Ruby specific instantiation of the LanguageServer class using Solargraph.\n    Contains various configurations and settings specific to Ruby.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a Solargraph instance. This class is not meant to be instantiated directly.\n        Use LanguageServer.create() instead.\n        \"\"\"\n        solargraph_executable_path = self._setup_runtime_dependencies(config, repository_root_path)\n        super().__init__(\n            config,\n            repository_root_path,\n            ProcessLaunchInfo(cmd=f\"{solargraph_executable_path} stdio\", cwd=repository_root_path),\n            \"ruby\",\n            solidlsp_settings,\n        )\n        # Override internal language enum for file matching (excludes .erb files)\n        # while keeping LSP languageId as \"ruby\" for protocol compliance\n        from solidlsp.ls_config import Language\n\n        self.language = Language.RUBY_SOLARGRAPH\n        self.analysis_complete = threading.Event()\n        self.service_ready_event = threading.Event()\n        self.initialize_searcher_command_available = threading.Event()\n        self.resolve_main_method_available = threading.Event()\n\n        # Set timeout for Solargraph requests - Bundler environments may need more time\n        self.set_request_timeout(120.0)  # 120 seconds for initialization and requests\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        ruby_ignored_dirs = [\n            \"vendor\",  # Ruby vendor directory\n            \".bundle\",  # Bundler cache\n            \"tmp\",  # Temporary files\n            \"log\",  # Log files\n            \"coverage\",  # Test coverage reports\n            \".yardoc\",  # YARD documentation cache\n            \"doc\",  # Generated documentation\n            \"node_modules\",  # Node modules (for Rails with JS)\n            \"storage\",  # Active Storage files (Rails)\n        ]\n        return super().is_ignored_dirname(dirname) or dirname in ruby_ignored_dirs\n\n    @staticmethod\n    def _setup_runtime_dependencies(config: LanguageServerConfig, repository_root_path: str) -> str:\n        \"\"\"\n        Setup runtime dependencies for Solargraph and return the command to start the server.\n        \"\"\"\n        # Check if Ruby is installed\n        try:\n            result = subprocess.run([\"ruby\", \"--version\"], check=True, capture_output=True, cwd=repository_root_path, text=True)\n            ruby_version = result.stdout.strip()\n            log.info(f\"Ruby version: {ruby_version}\")\n\n            # Extract version number for compatibility checks\n            version_match = re.search(r\"ruby (\\d+)\\.(\\d+)\\.(\\d+)\", ruby_version)\n            if version_match:\n                major, minor, patch = map(int, version_match.groups())\n                if major < 2 or (major == 2 and minor < 6):\n                    log.warning(f\"Warning: Ruby {major}.{minor}.{patch} detected. Solargraph works best with Ruby 2.6+\")\n\n        except subprocess.CalledProcessError as e:\n            error_msg = e.stderr.decode() if e.stderr else \"Unknown error\"\n            raise RuntimeError(\n                f\"Error checking Ruby installation: {error_msg}. Please ensure Ruby is properly installed and in PATH.\"\n            ) from e\n        except FileNotFoundError as e:\n            raise RuntimeError(\n                \"Ruby is not installed or not found in PATH. Please install Ruby using one of these methods:\\n\"\n                \"  - Using rbenv: rbenv install 3.0.0 && rbenv global 3.0.0\\n\"\n                \"  - Using RVM: rvm install 3.0.0 && rvm use 3.0.0 --default\\n\"\n                \"  - Using asdf: asdf install ruby 3.0.0 && asdf global ruby 3.0.0\\n\"\n                \"  - System package manager (brew install ruby, apt install ruby, etc.)\"\n            ) from e\n\n        # Helper function for Windows-compatible executable search\n        def find_executable_with_extensions(executable_name: str) -> str | None:\n            \"\"\"Find executable with Windows-specific extensions if on Windows.\"\"\"\n            import platform\n\n            if platform.system() == \"Windows\":\n                for ext in [\".bat\", \".cmd\", \".exe\"]:\n                    path = shutil.which(f\"{executable_name}{ext}\")\n                    if path:\n                        return path\n                return shutil.which(executable_name)\n            else:\n                return shutil.which(executable_name)\n\n        # Check for Bundler project (Gemfile exists)\n        gemfile_path = os.path.join(repository_root_path, \"Gemfile\")\n        gemfile_lock_path = os.path.join(repository_root_path, \"Gemfile.lock\")\n        is_bundler_project = os.path.exists(gemfile_path)\n\n        if is_bundler_project:\n            log.info(\"Detected Bundler project (Gemfile found)\")\n\n            # Check if bundle command is available\n            bundle_path = find_executable_with_extensions(\"bundle\")\n            if not bundle_path:\n                # Try common bundle executables\n                for bundle_cmd in [\"bin/bundle\", \"bundle\"]:\n                    if bundle_cmd.startswith(\"bin/\"):\n                        bundle_full_path = os.path.join(repository_root_path, bundle_cmd)\n                    else:\n                        bundle_full_path = find_executable_with_extensions(bundle_cmd)  # type: ignore[assignment]\n                    if bundle_full_path and os.path.exists(bundle_full_path):\n                        bundle_path = bundle_full_path if bundle_cmd.startswith(\"bin/\") else bundle_cmd\n                        break\n\n            if not bundle_path:\n                raise RuntimeError(\n                    \"Bundler project detected but 'bundle' command not found. Please install Bundler:\\n\"\n                    \"  - gem install bundler\\n\"\n                    \"  - Or use your Ruby version manager's bundler installation\\n\"\n                    \"  - Ensure the bundle command is in your PATH\"\n                )\n\n            # Check if solargraph is in Gemfile.lock\n            solargraph_in_bundle = False\n            if os.path.exists(gemfile_lock_path):\n                try:\n                    with open(gemfile_lock_path) as f:\n                        content = f.read()\n                        solargraph_in_bundle = \"solargraph\" in content.lower()\n                except Exception as e:\n                    log.warning(f\"Warning: Could not read Gemfile.lock: {e}\")\n\n            if solargraph_in_bundle:\n                log.info(\"Found solargraph in Gemfile.lock\")\n                return f\"{bundle_path} exec solargraph\"\n            else:\n                log.warning(\n                    \"solargraph not found in Gemfile.lock. Please add 'gem \\\"solargraph\\\"' to your Gemfile and run 'bundle install'\",\n                )\n                # Fall through to global installation check\n\n        # Check if solargraph is installed globally\n        # First, try to find solargraph in PATH (includes asdf shims) with Windows support\n        solargraph_path = find_executable_with_extensions(\"solargraph\")\n        if solargraph_path:\n            log.info(f\"Found solargraph at: {solargraph_path}\")\n            return solargraph_path\n\n        # Fallback to gem exec (for non-Bundler projects or when global solargraph not found)\n        if not is_bundler_project:\n            runtime_dependencies = [\n                {\n                    \"url\": \"https://rubygems.org/downloads/solargraph-0.51.1.gem\",\n                    \"installCommand\": \"gem install solargraph -v 0.51.1\",\n                    \"binaryName\": \"solargraph\",\n                    \"archiveType\": \"gem\",\n                }\n            ]\n\n            dependency = runtime_dependencies[0]\n            try:\n                result = subprocess.run(\n                    [\"gem\", \"list\", \"^solargraph$\", \"-i\"], check=False, capture_output=True, text=True, cwd=repository_root_path\n                )\n                if result.stdout.strip() == \"false\":\n                    log.info(\"Installing Solargraph...\")\n                    subprocess.run(dependency[\"installCommand\"].split(), check=True, capture_output=True, cwd=repository_root_path)\n\n                return \"gem exec solargraph\"\n            except subprocess.CalledProcessError as e:\n                error_msg = e.stderr.decode() if e.stderr else str(e)\n                raise RuntimeError(\n                    f\"Failed to check or install Solargraph: {error_msg}\\nPlease try installing manually: gem install solargraph\"\n                ) from e\n        else:\n            raise RuntimeError(\n                \"This appears to be a Bundler project, but solargraph is not available. \"\n                \"Please add 'gem \\\"solargraph\\\"' to your Gemfile and run 'bundle install'.\"\n            )\n\n    @staticmethod\n    def _detect_rails_project(repository_root_path: str) -> bool:\n        \"\"\"\n        Detect if this is a Rails project by checking for Rails-specific files.\n        \"\"\"\n        rails_indicators = [\n            \"config/application.rb\",\n            \"config/environment.rb\",\n            \"app/controllers/application_controller.rb\",\n            \"Rakefile\",\n        ]\n\n        for indicator in rails_indicators:\n            if os.path.exists(os.path.join(repository_root_path, indicator)):\n                return True\n\n        # Check for Rails in Gemfile\n        gemfile_path = os.path.join(repository_root_path, \"Gemfile\")\n        if os.path.exists(gemfile_path):\n            try:\n                with open(gemfile_path) as f:\n                    content = f.read().lower()\n                    if \"gem 'rails'\" in content or 'gem \"rails\"' in content:\n                        return True\n            except Exception:\n                pass\n\n        return False\n\n    @staticmethod\n    def _get_ruby_exclude_patterns(repository_root_path: str) -> list[str]:\n        \"\"\"\n        Get Ruby and Rails-specific exclude patterns for better performance.\n        \"\"\"\n        base_patterns = [\n            \"**/vendor/**\",  # Ruby vendor directory (similar to node_modules)\n            \"**/.bundle/**\",  # Bundler cache\n            \"**/tmp/**\",  # Temporary files\n            \"**/log/**\",  # Log files\n            \"**/coverage/**\",  # Test coverage reports\n            \"**/.yardoc/**\",  # YARD documentation cache\n            \"**/doc/**\",  # Generated documentation\n            \"**/.git/**\",  # Git directory\n            \"**/node_modules/**\",  # Node modules (for Rails with JS)\n            \"**/public/assets/**\",  # Rails compiled assets\n        ]\n\n        # Add Rails-specific patterns if this is a Rails project\n        if Solargraph._detect_rails_project(repository_root_path):\n            rails_patterns = [\n                \"**/public/packs/**\",  # Webpacker output\n                \"**/public/webpack/**\",  # Webpack output\n                \"**/storage/**\",  # Active Storage files\n                \"**/tmp/cache/**\",  # Rails cache\n                \"**/tmp/pids/**\",  # Process IDs\n                \"**/tmp/sessions/**\",  # Session files\n                \"**/tmp/sockets/**\",  # Socket files\n                \"**/db/*.sqlite3\",  # SQLite databases\n            ]\n            base_patterns.extend(rails_patterns)\n\n        return base_patterns\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Solargraph Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        exclude_patterns = Solargraph._get_ruby_exclude_patterns(repository_absolute_path)\n\n        initialize_params: InitializeParams = {  # type: ignore\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"initializationOptions\": {\n                \"exclude\": exclude_patterns,  # type: ignore[dict-item]\n            },\n            \"capabilities\": {\n                \"workspace\": {\n                    \"workspaceEdit\": {\"documentChanges\": True},\n                },\n                \"textDocument\": {\n                    \"documentSymbol\": {\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},  # type: ignore[arg-type]\n                    },\n                },\n            },\n            \"trace\": \"verbose\",  # type: ignore[typeddict-item]\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return initialize_params  # type: ignore[return-value]\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the Solargraph Language Server for Ruby\n        \"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            assert \"registrations\" in params\n            for registration in params[\"registrations\"]:\n                if registration[\"method\"] == \"workspace/executeCommand\":\n                    self.initialize_searcher_command_available.set()\n                    self.resolve_main_method_available.set()\n            return\n\n        def lang_status_handler(params: dict) -> None:\n            log.info(f\"LSP: language/status: {params}\")\n            if params.get(\"type\") == \"ServiceReady\" and params.get(\"message\") == \"Service is ready.\":\n                log.info(\"Solargraph service is ready.\")\n                self.analysis_complete.set()\n\n        def execute_client_command_handler(params: dict) -> list:\n            return []\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"language/status\", lang_status_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_request(\"workspace/executeClientCommand\", execute_client_command_handler)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"language/actionableNotification\", do_nothing)\n\n        log.info(\"Starting solargraph server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        log.info(f\"Sending init params: {json.dumps(initialize_params, indent=4)}\")\n        init_response = self.server.send.initialize(initialize_params)\n        log.info(f\"Received init response: {init_response}\")\n        assert init_response[\"capabilities\"][\"textDocumentSync\"] == 2\n        assert \"completionProvider\" in init_response[\"capabilities\"]\n        assert init_response[\"capabilities\"][\"completionProvider\"] == {\n            \"resolveProvider\": True,\n            \"triggerCharacters\": [\".\", \":\", \"@\"],\n        }\n        self.server.notify.initialized({})\n\n        # Wait for Solargraph to complete its initial workspace analysis\n        # This prevents issues by ensuring background tasks finish\n        log.info(\"Waiting for Solargraph to complete initial workspace analysis...\")\n        if self.analysis_complete.wait(timeout=60.0):\n            log.info(\"Solargraph initial analysis complete, server ready\")\n        else:\n            log.warning(\"Timeout waiting for Solargraph analysis completion, proceeding anyway\")\n            # Fallback: assume analysis is complete after timeout\n            self.analysis_complete.set()\n"
  },
  {
    "path": "src/solidlsp/language_servers/solidity_language_server.py",
    "content": "\"\"\"\nProvides Solidity-specific instantiation of the LanguageServer class using\nthe Nomic Foundation Solidity Language Server (@nomicfoundation/solidity-language-server).\n\"\"\"\n\nimport glob\nimport logging\nimport os\nimport pathlib\nimport shutil\nimport threading\nfrom time import sleep\nfrom typing import Any\n\nfrom solidlsp.language_servers.common import RuntimeDependency, RuntimeDependencyCollection\nfrom solidlsp.ls import LanguageServerDependencyProvider, LanguageServerDependencyProviderSinglePath, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass SolidityLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides Solidity-specific instantiation of the LanguageServer class using\n    the Nomic Foundation Solidity Language Server (@nomicfoundation/solidity-language-server).\n    Supports go-to-definition, find references, document symbols, hover, and diagnostics.\n    Requires Node.js and npm to be installed.\n    \"\"\"\n\n    @staticmethod\n    def _determine_log_level(line: str) -> int:\n        \"\"\"Suppress known non-critical stderr output from the Solidity language server.\"\"\"\n        line_lower = line.lower()\n        if any(\n            [\n                \"telemetry\" in line_lower,\n                \"could not find\" in line_lower and \"hardhat\" in line_lower,\n                \"no workspaceroot\" in line_lower,\n            ]\n        ):\n            return logging.DEBUG\n        return SolidLanguageServer._determine_log_level(line)\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a SolidityLanguageServer instance. Not meant to be instantiated directly.\n        Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(\n            config,\n            repository_root_path,\n            None,\n            \"solidity\",\n            solidlsp_settings,\n        )\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def _get_or_install_core_dependency(self) -> str:\n            \"\"\"\n            Install @nomicfoundation/solidity-language-server via npm and return the\n            path to the solidity-language-server executable.\n            \"\"\"\n            is_node_installed = shutil.which(\"node\") is not None\n            assert is_node_installed, \"node is not installed or isn't in PATH. Please install Node.js and try again.\"\n            is_npm_installed = shutil.which(\"npm\") is not None\n            assert is_npm_installed, \"npm is not installed or isn't in PATH. Please install npm and try again.\"\n\n            deps = RuntimeDependencyCollection(\n                [\n                    RuntimeDependency(\n                        id=\"solidity-language-server\",\n                        description=\"Nomic Foundation Solidity Language Server\",\n                        command=\"npm install --prefix ./ @nomicfoundation/solidity-language-server@0.8.4\",\n                        platform_id=\"any\",\n                    ),\n                ]\n            )\n\n            solidity_ls_dir = os.path.join(self._ls_resources_dir, \"solidity-lsp\")\n            solidity_executable_path = os.path.join(solidity_ls_dir, \"node_modules\", \".bin\", \"nomicfoundation-solidity-language-server\")\n\n            if os.name == \"nt\":\n                solidity_executable_path += \".cmd\"\n\n            if not os.path.exists(solidity_executable_path):\n                log.info(f\"Solidity Language Server executable not found at {solidity_executable_path}. Installing...\")\n                deps.install(solidity_ls_dir)\n                log.info(\"Solidity language server dependencies installed successfully.\")\n\n            if not os.path.exists(solidity_executable_path):\n                raise FileNotFoundError(\n                    f\"nomicfoundation-solidity-language-server executable not found at {solidity_executable_path}. \"\n                    \"Something went wrong with the installation.\"\n                )\n\n            return solidity_executable_path\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [core_path, \"--stdio\"]\n\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in {\"artifacts\", \"cache\", \"typechain-types\"}\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"Return LSP InitializeParams for the Solidity language server.\"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        return {  # type: ignore\n            \"locale\": \"en\",\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\n                        \"dynamicRegistration\": True,\n                        \"didSave\": True,\n                    },\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"completionItem\": {\"snippetSupport\": True},\n                    },\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},  # type: ignore[arg-type]\n                    },\n                    \"hover\": {\n                        \"dynamicRegistration\": True,\n                        \"contentFormat\": [\"markdown\", \"plaintext\"],  # type: ignore[list-item]\n                    },\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True},\n                },\n            },\n            \"initializationOptions\": {},\n        }\n\n    def _get_wait_time_for_cross_file_referencing(self) -> float:\n        # Small buffer for any post-indexing analysis the LSP performs after file-indexed events.\n        return 3.0\n\n    def _start_server(self) -> None:\n        \"\"\"Start the Solidity language server and wait for project indexing to finish.\"\"\"\n\n        def do_nothing(params: Any) -> None:\n            return\n\n        def register_capability_handler(params: Any) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        # Count .sol files in the project to know when indexing is complete.\n        sol_files = glob.glob(os.path.join(self.repository_root_path, \"**\", \"*.sol\"), recursive=True)\n        expected_count = len(sol_files)\n        indexed_count = [0]\n        all_indexed = threading.Event()\n\n        def on_file_indexed(params: Any) -> None:\n            indexed_count[0] += 1\n            uri = (params or {}).get(\"uri\", \"\")\n            log.debug(f\"Solidity LSP: file indexed ({indexed_count[0]}/{expected_count}): {uri}\")\n            if indexed_count[0] >= expected_count:\n                all_indexed.set()\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"custom/file-indexed\", on_file_indexed)\n\n        log.info(\"Starting Solidity language server process\")\n        self.server.start()\n\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n        log.debug(\"Sending initialize request to Solidity language server\")\n        init_response = self.server.send.initialize(initialize_params)\n        log.debug(f\"Received initialize response from Solidity server: {init_response}\")\n\n        if \"documentSymbolProvider\" in init_response.get(\"capabilities\", {}):\n            log.debug(\"Solidity server supports document symbols\")\n        else:\n            log.warning(\"Solidity server does not report document symbol support\")\n\n        self.server.notify.initialized({})\n\n        if expected_count > 0:\n            log.info(f\"Waiting for Solidity LSP to index {expected_count} .sol file(s)…\")\n            completed = all_indexed.wait(timeout=60)\n            if completed:\n                log.info(f\"Solidity LSP indexing complete ({indexed_count[0]}/{expected_count} files indexed)\")\n            else:\n                log.warning(\n                    f\"Solidity LSP indexing timed out ({indexed_count[0]}/{expected_count} files indexed). \"\n                    \"Waiting additional 30s for slow environments (e.g., CI).\"\n                )\n                sleep(30)\n                log.info(f\"Additional wait complete ({indexed_count[0]}/{expected_count} files indexed)\")\n        else:\n            log.info(\"No .sol files found; skipping indexing wait\")\n\n        log.info(\"Solidity language server initialization complete\")\n"
  },
  {
    "path": "src/solidlsp/language_servers/sourcekit_lsp.py",
    "content": "import logging\nimport os\nimport pathlib\nimport subprocess\nimport time\n\nfrom overrides import override\n\nfrom solidlsp import ls_types\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass SourceKitLSP(SolidLanguageServer):\n    \"\"\"\n    Provides Swift specific instantiation of the LanguageServer class using sourcekit-lsp.\n    \"\"\"\n\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    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Swift Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n\n        initialize_params = {\n            \"capabilities\": {\n                \"general\": {\n                    \"markdown\": {\"parser\": \"marked\", \"version\": \"1.1.0\"},\n                    \"positionEncodings\": [\"utf-16\"],\n                    \"regularExpressions\": {\"engine\": \"ECMAScript\", \"version\": \"ES2020\"},\n                    \"staleRequestSupport\": {\n                        \"cancel\": True,\n                        \"retryOnContentModified\": [\n                            \"textDocument/semanticTokens/full\",\n                            \"textDocument/semanticTokens/range\",\n                            \"textDocument/semanticTokens/full/delta\",\n                        ],\n                    },\n                },\n                \"notebookDocument\": {\"synchronization\": {\"dynamicRegistration\": True, \"executionSummarySupport\": True}},\n                \"textDocument\": {\n                    \"callHierarchy\": {\"dynamicRegistration\": True},\n                    \"codeAction\": {\n                        \"codeActionLiteralSupport\": {\n                            \"codeActionKind\": {\n                                \"valueSet\": [\n                                    \"\",\n                                    \"quickfix\",\n                                    \"refactor\",\n                                    \"refactor.extract\",\n                                    \"refactor.inline\",\n                                    \"refactor.rewrite\",\n                                    \"source\",\n                                    \"source.organizeImports\",\n                                ]\n                            }\n                        },\n                        \"dataSupport\": True,\n                        \"disabledSupport\": True,\n                        \"dynamicRegistration\": True,\n                        \"honorsChangeAnnotations\": True,\n                        \"isPreferredSupport\": True,\n                        \"resolveSupport\": {\"properties\": [\"edit\"]},\n                    },\n                    \"codeLens\": {\"dynamicRegistration\": True},\n                    \"colorProvider\": {\"dynamicRegistration\": True},\n                    \"completion\": {\n                        \"completionItem\": {\n                            \"commitCharactersSupport\": True,\n                            \"deprecatedSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"insertReplaceSupport\": True,\n                            \"insertTextModeSupport\": {\"valueSet\": [1, 2]},\n                            \"labelDetailsSupport\": True,\n                            \"preselectSupport\": True,\n                            \"resolveSupport\": {\"properties\": [\"documentation\", \"detail\", \"additionalTextEdits\"]},\n                            \"snippetSupport\": True,\n                            \"tagSupport\": {\"valueSet\": [1]},\n                        },\n                        \"completionItemKind\": {\n                            \"valueSet\": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]\n                        },\n                        \"completionList\": {\"itemDefaults\": [\"commitCharacters\", \"editRange\", \"insertTextFormat\", \"insertTextMode\", \"data\"]},\n                        \"contextSupport\": True,\n                        \"dynamicRegistration\": True,\n                        \"insertTextMode\": 2,\n                    },\n                    \"declaration\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"definition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"diagnostic\": {\"dynamicRegistration\": True, \"relatedDocumentSupport\": False},\n                    \"documentHighlight\": {\"dynamicRegistration\": True},\n                    \"documentLink\": {\"dynamicRegistration\": True, \"tooltipSupport\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"labelSupport\": True,\n                        \"symbolKind\": {\n                            \"valueSet\": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]\n                        },\n                        \"tagSupport\": {\"valueSet\": [1]},\n                    },\n                    \"foldingRange\": {\n                        \"dynamicRegistration\": True,\n                        \"foldingRange\": {\"collapsedText\": False},\n                        \"foldingRangeKind\": {\"valueSet\": [\"comment\", \"imports\", \"region\"]},\n                        \"lineFoldingOnly\": True,\n                        \"rangeLimit\": 5000,\n                    },\n                    \"formatting\": {\"dynamicRegistration\": True},\n                    \"hover\": {\"contentFormat\": [\"markdown\", \"plaintext\"], \"dynamicRegistration\": True},\n                    \"implementation\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"inlayHint\": {\n                        \"dynamicRegistration\": True,\n                        \"resolveSupport\": {\"properties\": [\"tooltip\", \"textEdits\", \"label.tooltip\", \"label.location\", \"label.command\"]},\n                    },\n                    \"inlineValue\": {\"dynamicRegistration\": True},\n                    \"linkedEditingRange\": {\"dynamicRegistration\": True},\n                    \"onTypeFormatting\": {\"dynamicRegistration\": True},\n                    \"publishDiagnostics\": {\n                        \"codeDescriptionSupport\": True,\n                        \"dataSupport\": True,\n                        \"relatedInformation\": True,\n                        \"tagSupport\": {\"valueSet\": [1, 2]},\n                        \"versionSupport\": False,\n                    },\n                    \"rangeFormatting\": {\"dynamicRegistration\": True, \"rangesSupport\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"rename\": {\n                        \"dynamicRegistration\": True,\n                        \"honorsChangeAnnotations\": True,\n                        \"prepareSupport\": True,\n                        \"prepareSupportDefaultBehavior\": 1,\n                    },\n                    \"selectionRange\": {\"dynamicRegistration\": True},\n                    \"semanticTokens\": {\n                        \"augmentsSyntaxTokens\": True,\n                        \"dynamicRegistration\": True,\n                        \"formats\": [\"relative\"],\n                        \"multilineTokenSupport\": False,\n                        \"overlappingTokenSupport\": False,\n                        \"requests\": {\"full\": {\"delta\": True}, \"range\": True},\n                        \"serverCancelSupport\": True,\n                        \"tokenModifiers\": [\n                            \"declaration\",\n                            \"definition\",\n                            \"readonly\",\n                            \"static\",\n                            \"deprecated\",\n                            \"abstract\",\n                            \"async\",\n                            \"modification\",\n                            \"documentation\",\n                            \"defaultLibrary\",\n                        ],\n                        \"tokenTypes\": [\n                            \"namespace\",\n                            \"type\",\n                            \"class\",\n                            \"enum\",\n                            \"interface\",\n                            \"struct\",\n                            \"typeParameter\",\n                            \"parameter\",\n                            \"variable\",\n                            \"property\",\n                            \"enumMember\",\n                            \"event\",\n                            \"function\",\n                            \"method\",\n                            \"macro\",\n                            \"keyword\",\n                            \"modifier\",\n                            \"comment\",\n                            \"string\",\n                            \"number\",\n                            \"regexp\",\n                            \"operator\",\n                            \"decorator\",\n                        ],\n                    },\n                    \"signatureHelp\": {\n                        \"contextSupport\": True,\n                        \"dynamicRegistration\": True,\n                        \"signatureInformation\": {\n                            \"activeParameterSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"parameterInformation\": {\"labelOffsetSupport\": True},\n                        },\n                    },\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True, \"willSave\": True, \"willSaveWaitUntil\": True},\n                    \"typeDefinition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"typeHierarchy\": {\"dynamicRegistration\": True},\n                },\n                \"window\": {\n                    \"showDocument\": {\"support\": True},\n                    \"showMessage\": {\"messageActionItem\": {\"additionalPropertiesSupport\": True}},\n                    \"workDoneProgress\": True,\n                },\n                \"workspace\": {\n                    \"applyEdit\": True,\n                    \"codeLens\": {\"refreshSupport\": True},\n                    \"configuration\": True,\n                    \"diagnostics\": {\"refreshSupport\": True},\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"didChangeWatchedFiles\": {\"dynamicRegistration\": True, \"relativePatternSupport\": True},\n                    \"executeCommand\": {\"dynamicRegistration\": True},\n                    \"fileOperations\": {\n                        \"didCreate\": True,\n                        \"didDelete\": True,\n                        \"didRename\": True,\n                        \"dynamicRegistration\": True,\n                        \"willCreate\": True,\n                        \"willDelete\": True,\n                        \"willRename\": True,\n                    },\n                    \"foldingRange\": {\"refreshSupport\": True},\n                    \"inlayHint\": {\"refreshSupport\": True},\n                    \"inlineValue\": {\"refreshSupport\": True},\n                    \"semanticTokens\": {\"refreshSupport\": False},\n                    \"symbol\": {\n                        \"dynamicRegistration\": True,\n                        \"resolveSupport\": {\"properties\": [\"location.range\"]},\n                        \"symbolKind\": {\n                            \"valueSet\": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]\n                        },\n                        \"tagSupport\": {\"valueSet\": [1]},\n                    },\n                    \"workspaceEdit\": {\n                        \"changeAnnotationSupport\": {\"groupsOnLabel\": True},\n                        \"documentChanges\": True,\n                        \"failureHandling\": \"textOnlyTransactional\",\n                        \"normalizesLineEndings\": True,\n                        \"resourceOperations\": [\"create\", \"rename\", \"delete\"],\n                    },\n                    \"workspaceFolders\": True,\n                },\n            },\n            \"clientInfo\": {\"name\": \"Visual Studio Code\", \"version\": \"1.102.2\"},\n            \"initializationOptions\": {\n                \"backgroundIndexing\": True,\n                \"backgroundPreparationMode\": \"enabled\",\n                \"textDocument/codeLens\": {\"supportedCommands\": {\"swift.debug\": \"swift.debug\", \"swift.run\": \"swift.run\"}},\n                \"window/didChangeActiveDocument\": True,\n                \"workspace/getReferenceDocument\": True,\n                \"workspace/peekDocuments\": True,\n            },\n            \"locale\": \"en\",\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n\n        return initialize_params  # type: ignore[return-value]\n\n    def _start_server(self) -> None:\n        \"\"\"Start sourcekit-lsp server process\"\"\"\n\n        def register_capability_handler(_params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def do_nothing(_params: dict) -> None:\n            return\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting sourcekit-lsp server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        capabilities = init_response[\"capabilities\"]\n        log.info(f\"SourceKit LSP capabilities: {list(capabilities.keys())}\")\n\n        assert \"textDocumentSync\" in capabilities, \"textDocumentSync capability missing\"\n        assert \"definitionProvider\" in capabilities, \"definitionProvider capability missing\"\n\n        self.server.notify.initialized({})\n\n        # Mark initialization timestamp for smarter delay calculation\n        self._initialization_timestamp = time.time()\n\n    @override\n    def request_references(self, relative_file_path: str, line: int, column: int) -> list[ls_types.Location]:\n        # SourceKit LSP needs initialization + indexing time after startup\n        # before it can provide accurate reference information. This sleep\n        # prevents race conditions where references might not be available yet.\n        # CI environments need extra time for project indexing and cross-file analysis\n        if not self._did_sleep_before_requesting_references:\n            # Calculate minimum delay based on how much time has passed since initialization\n            if self._initialization_timestamp:\n                elapsed = time.time() - self._initialization_timestamp\n                # Increased CI delay for project indexing: 15s CI, 5s local\n                base_delay = 15 if os.getenv(\"CI\") else 5\n                remaining_delay = max(2, base_delay - elapsed)\n            else:\n                # Fallback if initialization timestamp is missing\n                remaining_delay = 15 if os.getenv(\"CI\") else 5\n\n            log.info(f\"Sleeping {remaining_delay:.1f}s before requesting references for the first time (CI needs extra indexing time)\")\n            time.sleep(remaining_delay)\n            self._did_sleep_before_requesting_references = True\n\n        # Get references with retry logic for CI stability\n        references = super().request_references(relative_file_path, line, column)\n\n        # In CI, if no references found, retry once after additional delay\n        if os.getenv(\"CI\") and not references:\n            log.info(\"No references found in CI - retrying after additional 5s delay\")\n            time.sleep(5)\n            references = super().request_references(relative_file_path, line, column)\n\n        return references\n"
  },
  {
    "path": "src/solidlsp/language_servers/systemverilog_server.py",
    "content": "\"\"\"\nSystemVerilog language server using verible-verilog-ls.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport shutil\nimport subprocess\nfrom typing import Any, cast\n\nfrom solidlsp.ls import LanguageServerDependencyProvider, LanguageServerDependencyProviderSinglePath, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nfrom .common import RuntimeDependency, RuntimeDependencyCollection\n\nlog = logging.getLogger(__name__)\n\n\nclass SystemVerilogLanguageServer(SolidLanguageServer):\n    \"\"\"\n    SystemVerilog language server using verible-verilog-ls.\n    Supports .sv, .svh, .v, .vh files.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings) -> None:\n        super().__init__(config, repository_root_path, None, \"systemverilog\", solidlsp_settings)\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def _get_or_install_core_dependency(self) -> str:\n            # 1. Check PATH first for system-installed verible\n            system_verible = shutil.which(\"verible-verilog-ls\")\n            if system_verible:\n                # Log version information\n                try:\n                    result = subprocess.run(\n                        [system_verible, \"--version\"],\n                        capture_output=True,\n                        text=True,\n                        check=False,\n                        timeout=5,\n                    )\n                    if result.returncode == 0:\n                        version_info = result.stdout.strip().split(\"\\n\")[0]\n                        log.info(f\"Using system-installed verible-verilog-ls: {version_info}\")\n                    else:\n                        log.info(f\"Using system-installed verible-verilog-ls at {system_verible}\")\n                except Exception:\n                    log.info(f\"Using system-installed verible-verilog-ls at {system_verible}\")\n                return system_verible\n\n            # 2. Not found in PATH, try to download\n            verible_version = self._custom_settings.get(\"verible_version\", \"v0.0-4051-g9fdb4057\")\n            base_url = f\"https://github.com/chipsalliance/verible/releases/download/{verible_version}\"\n\n            deps = RuntimeDependencyCollection(\n                [\n                    RuntimeDependency(\n                        id=\"verible-ls\",\n                        description=\"verible-verilog-ls for Linux (x64)\",\n                        url=f\"{base_url}/verible-{verible_version}-linux-static-x86_64.tar.gz\",\n                        platform_id=\"linux-x64\",\n                        archive_type=\"gztar\",\n                        binary_name=f\"verible-{verible_version}/bin/verible-verilog-ls\",\n                    ),\n                    RuntimeDependency(\n                        id=\"verible-ls\",\n                        description=\"verible-verilog-ls for Linux (arm64)\",\n                        url=f\"{base_url}/verible-{verible_version}-linux-static-arm64.tar.gz\",\n                        platform_id=\"linux-arm64\",\n                        archive_type=\"gztar\",\n                        binary_name=f\"verible-{verible_version}/bin/verible-verilog-ls\",\n                    ),\n                    RuntimeDependency(\n                        id=\"verible-ls\",\n                        description=\"verible-verilog-ls for macOS\",\n                        url=f\"{base_url}/verible-{verible_version}-macOS.tar.gz\",\n                        platform_id=\"osx-x64\",\n                        archive_type=\"gztar\",\n                        binary_name=f\"verible-{verible_version}/bin/verible-verilog-ls\",\n                    ),\n                    RuntimeDependency(\n                        id=\"verible-ls\",\n                        description=\"verible-verilog-ls for macOS\",\n                        url=f\"{base_url}/verible-{verible_version}-macOS.tar.gz\",\n                        platform_id=\"osx-arm64\",\n                        archive_type=\"gztar\",\n                        binary_name=f\"verible-{verible_version}/bin/verible-verilog-ls\",\n                    ),\n                    RuntimeDependency(\n                        id=\"verible-ls\",\n                        description=\"verible-verilog-ls for Windows (x64)\",\n                        url=f\"{base_url}/verible-{verible_version}-win64.zip\",\n                        platform_id=\"win-x64\",\n                        archive_type=\"zip\",\n                        binary_name=f\"verible-{verible_version}/bin/verible-verilog-ls.exe\",\n                    ),\n                ]\n            )\n\n            try:\n                dep = deps.get_single_dep_for_current_platform()\n            except RuntimeError:\n                dep = None\n\n            if dep is None:\n                raise FileNotFoundError(\n                    \"verible-verilog-ls is not installed on your system.\\n\"\n                    + \"Please install verible using one of the following methods:\\n\"\n                    + \"  conda:      conda install -c conda-forge verible\\n\"\n                    + \"  Homebrew:   brew install verible\\n\"\n                    + \"  GitHub:     Download from https://github.com/chipsalliance/verible/releases\\n\"\n                    + \"See https://github.com/chipsalliance/verible for more details.\"\n                )\n\n            verible_ls_dir = os.path.join(self._ls_resources_dir, \"verible-ls\")\n            executable_path = deps.binary_path(verible_ls_dir)\n\n            if not os.path.exists(executable_path):\n                log.info(f\"verible-verilog-ls not found. Downloading from {dep.url}\")\n                _ = deps.install(verible_ls_dir)\n\n            if not os.path.exists(executable_path):\n                raise FileNotFoundError(f\"verible-verilog-ls not found at {executable_path}\")\n\n            os.chmod(executable_path, 0o755)\n            return executable_path\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [core_path]\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"completionItem\": {\"snippetSupport\": True},\n                    },\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"hover\": {\n                        \"dynamicRegistration\": True,\n                        \"contentFormat\": [\"markdown\", \"plaintext\"],\n                    },\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"codeAction\": {\"dynamicRegistration\": True},\n                    \"formatting\": {\"dynamicRegistration\": True},\n                    \"documentHighlight\": {\"dynamicRegistration\": True},\n                    \"publishDiagnostics\": {\"relatedInformation\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                },\n            },\n            \"workspaceFolders\": [{\"uri\": root_uri, \"name\": os.path.basename(repository_absolute_path)}],\n        }\n        return cast(InitializeParams, initialize_params)\n\n    def _start_server(self) -> None:\n        def do_nothing(params: Any) -> None:\n            return\n\n        def on_log_message(params: Any) -> None:\n            message = params.get(\"message\", \"\") if isinstance(params, dict) else str(params)\n            log.info(f\"verible-verilog-ls: {message}\")\n\n        self.server.on_request(\"client/registerCapability\", do_nothing)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"window/logMessage\", on_log_message)\n\n        log.info(\"Starting verible-verilog-ls process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        # Validate server capabilities (follows Gopls/Bash pattern)\n        capabilities = init_response.get(\"capabilities\", {})\n        log.info(f\"Initialize response capabilities: {list(capabilities.keys())}\")\n        assert \"textDocumentSync\" in capabilities, \"verible-verilog-ls must support textDocumentSync\"\n        if \"documentSymbolProvider\" not in capabilities:\n            log.warning(\"verible-verilog-ls does not advertise documentSymbolProvider\")\n        if \"definitionProvider\" not in capabilities:\n            log.warning(\"verible-verilog-ls does not advertise definitionProvider\")\n\n        self.server.notify.initialized({})\n"
  },
  {
    "path": "src/solidlsp/language_servers/taplo_server.py",
    "content": "\"\"\"\nProvides TOML specific instantiation of the LanguageServer class using Taplo.\nContains various configurations and settings specific to TOML files.\n\"\"\"\n\nimport gzip\nimport hashlib\nimport logging\nimport os\nimport platform\nimport shutil\nimport socket\nimport stat\nimport urllib.request\nfrom typing import Any\n\n# Download timeout in seconds (prevents indefinite hangs)\nDOWNLOAD_TIMEOUT_SECONDS = 120\n\nfrom solidlsp.ls import LanguageServerDependencyProvider, LanguageServerDependencyProviderSinglePath, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.ls_utils import PathUtils\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n# Taplo release version and download URLs\nTAPLO_VERSION = \"0.10.0\"\nTAPLO_DOWNLOAD_BASE = f\"https://github.com/tamasfe/taplo/releases/download/{TAPLO_VERSION}\"\n\n# SHA256 checksums for Taplo releases (verified from official GitHub releases)\n# Source: https://github.com/tamasfe/taplo/releases/tag/0.10.0\n# To update: download each release file and run: sha256sum <filename>\nTAPLO_SHA256_CHECKSUMS: dict[str, str] = {\n    \"taplo-windows-x86_64.zip\": \"1615eed140039bd58e7089109883b1c434de5d6de8f64a993e6e8c80ca57bdf9\",\n    \"taplo-windows-x86.zip\": \"b825701daab10dcfc0251e6d668cd1a9c0e351e7f6762dd20844c3f3f3553aa0\",\n    \"taplo-darwin-x86_64.gz\": \"898122cde3a0b1cd1cbc2d52d3624f23338218c91b5ddb71518236a4c2c10ef2\",\n    \"taplo-darwin-aarch64.gz\": \"713734314c3e71894b9e77513c5349835eefbd52908445a0d73b0c7dc469347d\",\n    \"taplo-linux-x86_64.gz\": \"8fe196b894ccf9072f98d4e1013a180306e17d244830b03986ee5e8eabeb6156\",\n    \"taplo-linux-aarch64.gz\": \"033681d01eec8376c3fd38fa3703c79316f5e14bb013d859943b60a07bccdcc3\",\n    \"taplo-linux-armv7.gz\": \"6b728896afe2573522f38b8e668b1ff40eb5928fd9d6d0c253ecae508274d417\",\n}\n\n\ndef _verify_sha256(file_path: str, expected_hash: str) -> bool:\n    \"\"\"Verify SHA256 checksum of a downloaded file.\"\"\"\n    sha256_hash = hashlib.sha256()\n    with open(file_path, \"rb\") as f:\n        for chunk in iter(lambda: f.read(8192), b\"\"):\n            sha256_hash.update(chunk)\n    actual_hash = sha256_hash.hexdigest()\n    return actual_hash.lower() == expected_hash.lower()\n\n\ndef _get_taplo_download_url() -> tuple[str, str]:\n    \"\"\"\n    Get the appropriate Taplo download URL for the current platform.\n\n    Returns:\n        Tuple of (download_url, executable_name)\n\n    \"\"\"\n    system = platform.system().lower()\n    machine = platform.machine().lower()\n\n    # Map machine architecture to Taplo naming convention\n    arch_map = {\n        \"x86_64\": \"x86_64\",\n        \"amd64\": \"x86_64\",\n        \"x86\": \"x86\",\n        \"i386\": \"x86\",\n        \"i686\": \"x86\",\n        \"aarch64\": \"aarch64\",\n        \"arm64\": \"aarch64\",\n        \"armv7l\": \"armv7\",\n    }\n\n    arch = arch_map.get(machine, \"x86_64\")  # Default to x86_64\n\n    if system == \"windows\":\n        filename = f\"taplo-windows-{arch}.zip\"\n        executable = \"taplo.exe\"\n    elif system == \"darwin\":\n        filename = f\"taplo-darwin-{arch}.gz\"\n        executable = \"taplo\"\n    else:  # Linux and others\n        filename = f\"taplo-linux-{arch}.gz\"\n        executable = \"taplo\"\n\n    return f\"{TAPLO_DOWNLOAD_BASE}/{filename}\", executable\n\n\nclass TaploServer(SolidLanguageServer):\n    \"\"\"\n    Provides TOML specific instantiation of the LanguageServer class using Taplo.\n    Taplo is a TOML toolkit with LSP support for validation, formatting, and schema support.\n    \"\"\"\n\n    @staticmethod\n    def _determine_log_level(line: str) -> int:\n        \"\"\"Classify Taplo stderr output to avoid false-positive errors.\"\"\"\n        line_lower = line.lower()\n\n        # Known informational messages from Taplo\n        if any(\n            [\n                \"schema\" in line_lower and \"not found\" in line_lower,\n                \"warning\" in line_lower,\n            ]\n        ):\n            return logging.DEBUG\n\n        return SolidLanguageServer._determine_log_level(line)\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a TaploServer instance. This class is not meant to be instantiated directly.\n        Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(\n            config,\n            repository_root_path,\n            None,\n            \"toml\",\n            solidlsp_settings,\n        )\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def _get_or_install_core_dependency(self) -> str:\n            \"\"\"\n            Setup runtime dependencies for Taplo and return the command to start the server.\n            \"\"\"\n            # First check if taplo is already installed system-wide\n            system_taplo = shutil.which(\"taplo\")\n            if system_taplo:\n                log.info(f\"Using system-installed Taplo at: {system_taplo}\")\n                return system_taplo\n\n            # Setup local installation directory\n            taplo_dir = os.path.join(self._ls_resources_dir, \"taplo\")\n            os.makedirs(taplo_dir, exist_ok=True)\n\n            _, executable_name = _get_taplo_download_url()\n            taplo_executable = os.path.join(taplo_dir, executable_name)\n\n            if os.path.exists(taplo_executable) and os.access(taplo_executable, os.X_OK):\n                log.info(f\"Using cached Taplo at: {taplo_executable}\")\n                return taplo_executable\n\n            # Download and install Taplo\n            log.info(f\"Taplo not found. Downloading version {TAPLO_VERSION}...\")\n            self._download_taplo(taplo_dir, taplo_executable)\n\n            if not os.path.exists(taplo_executable):\n                raise FileNotFoundError(\n                    f\"Taplo executable not found at {taplo_executable}. \"\n                    \"Installation may have failed. Try installing manually: cargo install taplo-cli --locked\"\n                )\n\n            return taplo_executable\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [core_path, \"lsp\", \"stdio\"]\n\n        @classmethod\n        def _download_taplo(cls, install_dir: str, executable_path: str) -> None:\n            \"\"\"Download and extract Taplo binary with SHA256 verification.\"\"\"\n            # TODO: consider using existing download utilities in SolidLSP instead of the custom logic here\n            download_url, _ = _get_taplo_download_url()\n            archive_filename = os.path.basename(download_url)\n\n            try:\n                log.info(f\"Downloading Taplo from: {download_url}\")\n                archive_path = os.path.join(install_dir, archive_filename)\n\n                # Download the archive with timeout to prevent indefinite hangs\n                old_timeout = socket.getdefaulttimeout()\n                try:\n                    socket.setdefaulttimeout(DOWNLOAD_TIMEOUT_SECONDS)\n                    urllib.request.urlretrieve(download_url, archive_path)\n                finally:\n                    socket.setdefaulttimeout(old_timeout)\n\n                # Verify SHA256 checksum\n                expected_hash = TAPLO_SHA256_CHECKSUMS.get(archive_filename)\n                if expected_hash:\n                    if not _verify_sha256(archive_path, expected_hash):\n                        os.remove(archive_path)\n                        raise RuntimeError(\n                            f\"SHA256 checksum verification failed for {archive_filename}. \"\n                            \"The downloaded file may be corrupted or tampered with. \"\n                            \"Try installing manually: cargo install taplo-cli --locked\"\n                        )\n                    log.info(f\"SHA256 checksum verified for {archive_filename}\")\n                else:\n                    log.warning(\n                        f\"No SHA256 checksum available for {archive_filename}. \"\n                        \"Skipping verification - consider installing manually: cargo install taplo-cli --locked\"\n                    )\n\n                # Extract based on format\n                if archive_path.endswith(\".gz\") and not archive_path.endswith(\".tar.gz\"):\n                    # Single file gzip\n                    with gzip.open(archive_path, \"rb\") as f_in:\n                        with open(executable_path, \"wb\") as f_out:\n                            f_out.write(f_in.read())\n                elif archive_path.endswith(\".zip\"):\n                    import zipfile\n\n                    with zipfile.ZipFile(archive_path, \"r\") as zip_ref:\n                        # Security: Validate paths to prevent zip slip vulnerability\n                        for member in zip_ref.namelist():\n                            member_path = os.path.normpath(os.path.join(install_dir, member))\n                            if not member_path.startswith(os.path.normpath(install_dir)):\n                                raise RuntimeError(f\"Zip slip detected: {member} attempts to escape install directory\")\n                        zip_ref.extractall(install_dir)\n\n                # Make executable on Unix systems\n                if os.name != \"nt\":\n                    os.chmod(executable_path, os.stat(executable_path).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)\n\n                # Clean up archive\n                os.remove(archive_path)\n                log.info(f\"Taplo installed successfully at: {executable_path}\")\n\n            except Exception as e:\n                log.error(f\"Failed to download Taplo: {e}\")\n                raise RuntimeError(\n                    f\"Failed to download Taplo from {download_url}. Try installing manually: cargo install taplo-cli --locked\"\n                ) from e\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Taplo Language Server.\n        \"\"\"\n        root_uri = PathUtils.path_to_uri(repository_absolute_path)\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\"dynamicRegistration\": True, \"completionItem\": {\"snippetSupport\": True}},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"codeAction\": {\"dynamicRegistration\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True},\n                },\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return initialize_params  # type: ignore\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the Taplo Language Server and initializes it.\n        \"\"\"\n\n        def register_capability_handler(params: Any) -> None:\n            return\n\n        def do_nothing(params: Any) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting Taplo server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request to Taplo server\")\n        init_response = self.server.send.initialize(initialize_params)\n        log.debug(f\"Received initialize response from Taplo: {init_response}\")\n\n        # Verify document symbol support\n        capabilities = init_response.get(\"capabilities\", {})\n        if capabilities.get(\"documentSymbolProvider\"):\n            log.info(\"Taplo server supports document symbols\")\n        else:\n            log.warning(\"Taplo server may have limited document symbol support\")\n\n        self.server.notify.initialized({})\n\n        log.info(\"Taplo server initialization complete\")\n\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        \"\"\"Define TOML-specific directories to ignore.\"\"\"\n        return super().is_ignored_dirname(dirname) or dirname in [\"target\", \".cargo\", \"node_modules\"]\n"
  },
  {
    "path": "src/solidlsp/language_servers/terraform_ls.py",
    "content": "import logging\nimport os\nimport shutil\nfrom typing import cast\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.ls_utils import PathUtils, PlatformUtils\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nfrom .common import RuntimeDependency, RuntimeDependencyCollection\n\nlog = logging.getLogger(__name__)\n\n\nclass TerraformLS(SolidLanguageServer):\n    \"\"\"\n    Provides Terraform specific instantiation of the LanguageServer class using terraform-ls.\n    \"\"\"\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\".terraform\", \"terraform.tfstate.d\"]\n\n    @staticmethod\n    def _determine_log_level(line: str) -> int:\n        \"\"\"Classify terraform-ls stderr output to avoid false-positive errors.\"\"\"\n        line_lower = line.lower()\n\n        # File discovery messages that are not actual errors\n        if any(\n            [\n                \"discover.go:\" in line_lower,\n                \"walker.go:\" in line_lower,\n                \"walking of {file://\" in line_lower,\n                \"bus: -> discover\" in line_lower,\n            ]\n        ):\n            return logging.DEBUG\n\n        # Known informational messages from terraform-ls that contain \"error\" but aren't errors\n        # Note: pattern match is flexible to handle file paths between keywords\n        if any(\n            [\n                \"loading module metadata returned error:\" in line_lower and \"state not changed\" in line_lower,\n                \"incoming notification for\" in line_lower,\n            ]\n        ):\n            return logging.DEBUG\n\n        return SolidLanguageServer._determine_log_level(line)\n\n    @staticmethod\n    def _ensure_tf_command_available() -> None:\n        log.debug(\"Starting terraform version detection...\")\n\n        # 1. Try to find terraform using shutil.which\n        terraform_cmd = shutil.which(\"terraform\")\n        if terraform_cmd is not None:\n            log.debug(f\"Found terraform via shutil.which: {terraform_cmd}\")\n            return\n\n        # TODO: is this needed?\n        # 2. Fallback to TERRAFORM_CLI_PATH (set by hashicorp/setup-terraform action)\n        if not terraform_cmd:\n            terraform_cli_path = os.environ.get(\"TERRAFORM_CLI_PATH\")\n            if terraform_cli_path:\n                log.debug(f\"Trying TERRAFORM_CLI_PATH: {terraform_cli_path}\")\n                # TODO: use binary name from runtime dependencies if we keep this code\n                if os.name == \"nt\":\n                    terraform_binary = os.path.join(terraform_cli_path, \"terraform.exe\")\n                else:\n                    terraform_binary = os.path.join(terraform_cli_path, \"terraform\")\n                if os.path.exists(terraform_binary):\n                    terraform_cmd = terraform_binary\n                    log.debug(f\"Found terraform via TERRAFORM_CLI_PATH: {terraform_cmd}\")\n                    return\n\n        raise RuntimeError(\n            \"Terraform executable not found, please ensure Terraform is installed.\"\n            \"See https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli for instructions.\"\n        )\n\n    @classmethod\n    def _setup_runtime_dependencies(cls, solidlsp_settings: SolidLSPSettings) -> str:\n        \"\"\"\n        Setup runtime dependencies for terraform-ls.\n        Downloads and installs terraform-ls if not already present.\n        \"\"\"\n        cls._ensure_tf_command_available()\n        platform_id = PlatformUtils.get_platform_id()\n        deps = RuntimeDependencyCollection(\n            [\n                RuntimeDependency(\n                    id=\"TerraformLS\",\n                    description=\"terraform-ls for macOS (ARM64)\",\n                    url=\"https://releases.hashicorp.com/terraform-ls/0.36.5/terraform-ls_0.36.5_darwin_arm64.zip\",\n                    platform_id=\"osx-arm64\",\n                    archive_type=\"zip\",\n                    binary_name=\"terraform-ls\",\n                ),\n                RuntimeDependency(\n                    id=\"TerraformLS\",\n                    description=\"terraform-ls for macOS (x64)\",\n                    url=\"https://releases.hashicorp.com/terraform-ls/0.36.5/terraform-ls_0.36.5_darwin_amd64.zip\",\n                    platform_id=\"osx-x64\",\n                    archive_type=\"zip\",\n                    binary_name=\"terraform-ls\",\n                ),\n                RuntimeDependency(\n                    id=\"TerraformLS\",\n                    description=\"terraform-ls for Linux (ARM64)\",\n                    url=\"https://releases.hashicorp.com/terraform-ls/0.36.5/terraform-ls_0.36.5_linux_arm64.zip\",\n                    platform_id=\"linux-arm64\",\n                    archive_type=\"zip\",\n                    binary_name=\"terraform-ls\",\n                ),\n                RuntimeDependency(\n                    id=\"TerraformLS\",\n                    description=\"terraform-ls for Linux (x64)\",\n                    url=\"https://releases.hashicorp.com/terraform-ls/0.36.5/terraform-ls_0.36.5_linux_amd64.zip\",\n                    platform_id=\"linux-x64\",\n                    archive_type=\"zip\",\n                    binary_name=\"terraform-ls\",\n                ),\n                RuntimeDependency(\n                    id=\"TerraformLS\",\n                    description=\"terraform-ls for Windows (x64)\",\n                    url=\"https://releases.hashicorp.com/terraform-ls/0.36.5/terraform-ls_0.36.5_windows_amd64.zip\",\n                    platform_id=\"win-x64\",\n                    archive_type=\"zip\",\n                    binary_name=\"terraform-ls.exe\",\n                ),\n            ]\n        )\n        dependency = deps.get_single_dep_for_current_platform()\n\n        terraform_ls_executable_path = deps.binary_path(cls.ls_resources_dir(solidlsp_settings))\n        if not os.path.exists(terraform_ls_executable_path):\n            log.info(f\"Downloading terraform-ls from {dependency.url}\")\n            deps.install(cls.ls_resources_dir(solidlsp_settings))\n\n        assert os.path.exists(terraform_ls_executable_path), f\"terraform-ls executable not found at {terraform_ls_executable_path}\"\n\n        # Make the executable file executable on Unix-like systems\n        if platform_id.value != \"win-x64\":\n            os.chmod(terraform_ls_executable_path, 0o755)\n\n        return terraform_ls_executable_path\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a TerraformLS instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.\n        \"\"\"\n        terraform_ls_executable_path = self._setup_runtime_dependencies(solidlsp_settings)\n\n        super().__init__(\n            config,\n            repository_root_path,\n            ProcessLaunchInfo(cmd=f\"{terraform_ls_executable_path} serve\", cwd=repository_root_path),\n            \"terraform\",\n            solidlsp_settings,\n        )\n        self.request_id = 0\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Terraform Language Server.\n        \"\"\"\n        root_uri = PathUtils.path_to_uri(repository_absolute_path)\n        result = {\n            \"processId\": os.getpid(),\n            \"locale\": \"en\",\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\"dynamicRegistration\": True, \"completionItem\": {\"snippetSupport\": True}},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                },\n                \"workspace\": {\"workspaceFolders\": True, \"didChangeConfiguration\": {\"dynamicRegistration\": True}},\n            },\n            \"workspaceFolders\": [\n                {\n                    \"name\": os.path.basename(repository_absolute_path),\n                    \"uri\": root_uri,\n                }\n            ],\n        }\n        return cast(InitializeParams, result)\n\n    def _start_server(self) -> None:\n        \"\"\"Start terraform-ls server process\"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting terraform-ls server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        # Verify server capabilities\n        assert \"textDocumentSync\" in init_response[\"capabilities\"]\n        assert \"completionProvider\" in init_response[\"capabilities\"]\n        assert \"definitionProvider\" in init_response[\"capabilities\"]\n\n        self.server.notify.initialized({})\n\n        # terraform-ls server is typically ready immediately after initialization\n"
  },
  {
    "path": "src/solidlsp/language_servers/typescript_language_server.py",
    "content": "\"\"\"\nProvides TypeScript specific instantiation of the LanguageServer class. Contains various configurations and settings specific to TypeScript.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport shutil\nimport threading\nfrom typing import Any, cast\n\nfrom overrides import override\nfrom sensai.util.logging import LogTime\n\nfrom solidlsp import ls_types\nfrom solidlsp.ls import LanguageServerDependencyProvider, LanguageServerDependencyProviderSinglePath, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.ls_utils import PlatformId, PlatformUtils\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nfrom .common import RuntimeDependency, RuntimeDependencyCollection\n\nlog = logging.getLogger(__name__)\n\n# Platform-specific imports\nif os.name != \"nt\":  # Unix-like systems\n    import pwd\nelse:\n    # Dummy pwd module for Windows\n    class pwd:  # type: ignore\n        @staticmethod\n        def getpwuid(uid: Any) -> Any:\n            return type(\"obj\", (), {\"pw_name\": os.environ.get(\"USERNAME\", \"unknown\")})()\n\n\n# Conditionally import pwd module (Unix-only)\nif not PlatformUtils.get_platform_id().value.startswith(\"win\"):\n    pass\n\n\ndef prefer_non_node_modules_definition(definitions: list[ls_types.Location]) -> ls_types.Location:\n    \"\"\"\n    Select the preferred definition, preferring source files over type definitions.\n\n    TypeScript language servers often return both type definitions (.d.ts files\n    in node_modules) and source definitions. This function prefers:\n    1. Files not in node_modules\n    2. Falls back to first definition if all are in node_modules\n\n    :param definitions: A non-empty list of definition locations.\n    :return: The preferred definition location.\n    \"\"\"\n    for d in definitions:\n        rel_path = d.get(\"relativePath\", \"\")\n        if rel_path and \"node_modules\" not in rel_path:\n            return d\n    return definitions[0]\n\n\nclass TypeScriptLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides TypeScript specific instantiation of the LanguageServer class. Contains various configurations and settings specific to TypeScript.\n\n    You can pass the following entries in ls_specific_settings[\"typescript\"]:\n        - typescript_version: Version of TypeScript to install (default: \"5.9.3\")\n        - typescript_language_server_version: Version of typescript-language-server to install (default: \"5.1.3\")\n    \"\"\"\n\n    # Safety timeout for $/progress-based indexing wait. Normally the event fires\n    # well within this window; the timeout is only hit if the server never sends progress.\n    INDEXING_PROGRESS_TIMEOUT = 15.0 if os.name == \"nt\" else 10.0\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a TypeScriptLanguageServer instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(\n            config,\n            repository_root_path,\n            None,\n            \"typescript\",\n            solidlsp_settings,\n        )\n        self.server_ready = threading.Event()\n        self.initialize_searcher_command_available = threading.Event()\n\n        # Progress tracking for $/progress notifications (project indexing, etc.)\n        self._progress_lock = threading.Lock()\n        self._active_progress_tokens: set[str] = set()\n        self._indexing_complete = threading.Event()\n        self._indexing_complete.set()  # Initially set (no active work)\n\n    def wait_for_indexing(self, timeout: float) -> bool:\n        \"\"\"Block until all $/progress tokens complete.\n\n        :param timeout: Maximum seconds to wait.\n        :return: True if indexing completed, False on timeout.\n        \"\"\"\n        return self._indexing_complete.wait(timeout=timeout)\n\n    def expect_indexing(self) -> None:\n        \"\"\"Signal that new files are about to be opened and async indexing should be awaited.\n\n        Clears the internal indexing-complete event so that a subsequent\n        :meth:`wait_for_indexing` call blocks until all $/progress tokens\n        complete (or the timeout expires).\n        \"\"\"\n        self._indexing_complete.clear()\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\n            \"node_modules\",\n            \"dist\",\n            \"build\",\n            \"coverage\",\n        ]\n\n    @staticmethod\n    def _determine_log_level(line: str) -> int:\n        \"\"\"Classify typescript-language-server stderr output to avoid false-positive errors.\"\"\"\n        return SolidLanguageServer._determine_log_level(line)\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def _get_or_install_core_dependency(self) -> str:\n            \"\"\"\n            Setup runtime dependencies for TypeScript Language Server and return the path to the executable.\n            \"\"\"\n            platform_id = PlatformUtils.get_platform_id()\n\n            valid_platforms = [\n                PlatformId.LINUX_x64,\n                PlatformId.LINUX_arm64,\n                PlatformId.OSX,\n                PlatformId.OSX_x64,\n                PlatformId.OSX_arm64,\n                PlatformId.WIN_x64,\n                PlatformId.WIN_arm64,\n            ]\n            assert (\n                platform_id in valid_platforms\n            ), f\"Platform {platform_id} is not supported for multilspy javascript/typescript at the moment\"\n\n            # Get version settings from ls_specific_settings or use defaults\n            language_specific_config = self._custom_settings\n            typescript_version = language_specific_config.get(\"typescript_version\", \"5.9.3\")\n            typescript_language_server_version = language_specific_config.get(\"typescript_language_server_version\", \"5.1.3\")\n\n            deps = RuntimeDependencyCollection(\n                [\n                    RuntimeDependency(\n                        id=\"typescript\",\n                        description=\"typescript package\",\n                        command=[\"npm\", \"install\", \"--prefix\", \"./\", f\"typescript@{typescript_version}\"],\n                        platform_id=\"any\",\n                    ),\n                    RuntimeDependency(\n                        id=\"typescript-language-server\",\n                        description=\"typescript-language-server package\",\n                        command=[\"npm\", \"install\", \"--prefix\", \"./\", f\"typescript-language-server@{typescript_language_server_version}\"],\n                        platform_id=\"any\",\n                    ),\n                ]\n            )\n\n            # Verify both node and npm are installed\n            is_node_installed = shutil.which(\"node\") is not None\n            assert is_node_installed, \"node is not installed or isn't in PATH. Please install NodeJS and try again.\"\n            is_npm_installed = shutil.which(\"npm\") is not None\n            assert is_npm_installed, \"npm is not installed or isn't in PATH. Please install npm and try again.\"\n\n            # Install typescript and typescript-language-server if not already installed or version mismatch\n            tsserver_ls_dir = os.path.join(self._ls_resources_dir, \"ts-lsp\")\n            tsserver_executable_path = os.path.join(tsserver_ls_dir, \"node_modules\", \".bin\", \"typescript-language-server\")\n\n            # Check if installation is needed based on executable AND version\n            version_file = os.path.join(tsserver_ls_dir, \".installed_version\")\n            expected_version = f\"{typescript_version}_{typescript_language_server_version}\"\n\n            needs_install = False\n            if not os.path.exists(tsserver_executable_path):\n                log.info(f\"Typescript Language Server executable not found at {tsserver_executable_path}.\")\n                needs_install = True\n            elif os.path.exists(version_file):\n                with open(version_file) as f:\n                    installed_version = f.read().strip()\n                if installed_version != expected_version:\n                    log.info(\n                        f\"TypeScript Language Server version mismatch: installed={installed_version}, expected={expected_version}. Reinstalling...\"\n                    )\n                    needs_install = True\n            else:\n                # No version file exists, assume old installation needs refresh\n                log.info(\"TypeScript Language Server version file not found. Reinstalling to ensure correct version...\")\n                needs_install = True\n\n            if needs_install:\n                log.info(\"Installing TypeScript Language Server dependencies...\")\n                with LogTime(\"Installation of TypeScript language server dependencies\", logger=log):\n                    deps.install(tsserver_ls_dir)\n                # Write version marker file\n                with open(version_file, \"w\") as f:\n                    f.write(expected_version)\n                log.info(\"TypeScript language server dependencies installed successfully\")\n\n            if not os.path.exists(tsserver_executable_path):\n                raise FileNotFoundError(\n                    f\"typescript-language-server executable not found at {tsserver_executable_path}, something went wrong with the installation.\"\n                )\n            return tsserver_executable_path\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [core_path, \"--stdio\"]\n\n    def _get_initialize_params(self, repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the TypeScript Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\"dynamicRegistration\": True, \"completionItem\": {\"snippetSupport\": True}},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"signatureHelp\": {\"dynamicRegistration\": True},\n                    \"codeAction\": {\"dynamicRegistration\": True},\n                    \"rename\": {\"dynamicRegistration\": True, \"prepareSupport\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True},\n                },\n                \"window\": {\n                    \"workDoneProgress\": True,  # Enables $/progress notifications for project loading\n                },\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return cast(InitializeParams, initialize_params)\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the TypeScript Language Server, waits for the server to be ready and yields the LanguageServer instance.\n\n        Usage:\n        ```\n        async with lsp.start_server():\n            # LanguageServer has been initialized and ready to serve requests\n            await lsp.request_definition(...)\n            await lsp.request_references(...)\n            # Shutdown the LanguageServer on exit from scope\n        # LanguageServer has been shutdown\n        \"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            assert \"registrations\" in params\n            for registration in params[\"registrations\"]:\n                if registration[\"method\"] == \"workspace/executeCommand\":\n                    self.initialize_searcher_command_available.set()\n                    # TypeScript doesn't have a direct equivalent to resolve_main_method\n                    # You might want to set a different flag or remove this line\n                    # self.resolve_main_method_available.set()\n            return\n\n        def execute_client_command_handler(params: dict) -> list:\n            return []\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def handle_typescript_version(params: dict) -> None:\n            \"\"\"\n            The $/typescriptVersion notification is sent by typescript-language-server\n            once tsserver has loaded and reported its version. This is a reliable\n            signal that tsserver is running and responsive.\n            \"\"\"\n            log.info(f\"TypeScript server version notification received: {params}\")\n            self.server_ready.set()\n\n        def work_done_progress_create(params: dict) -> dict:\n            \"\"\"Handle window/workDoneProgress/create: the server is about to report async progress.\n\n            Clear the indexing-complete event so callers waiting on it will block until\n            all progress tokens finish. This is sent by typescript-language-server when\n            tsserver starts processing files (e.g. \"Initializing JS/TS language features...\").\n            \"\"\"\n            token = str(params.get(\"token\", \"\"))\n            log.debug(f\"TypeScript LSP workDoneProgress/create: token={token!r}\")\n            with self._progress_lock:\n                self._active_progress_tokens.add(token)\n                self._indexing_complete.clear()\n            return {}\n\n        def progress_handler(params: dict) -> None:\n            \"\"\"Track $/progress begin/end to detect when all async work finishes.\n\n            typescript-language-server sends $/progress for project loading operations\n            like \"Initializing JS/TS language features...\". When all progress tokens\n            complete (kind='end'), _indexing_complete is set.\n            \"\"\"\n            token = str(params.get(\"token\", \"\"))\n            value = params.get(\"value\", {})\n            kind = value.get(\"kind\")\n            if kind == \"begin\":\n                title = value.get(\"title\", \"\")\n                log.info(f\"TypeScript LSP progress [{token}]: started - {title}\")\n                with self._progress_lock:\n                    self._active_progress_tokens.add(token)\n                    self._indexing_complete.clear()\n            elif kind == \"report\":\n                pct = value.get(\"percentage\")\n                msg = value.get(\"message\", \"\")\n                pct_str = f\" ({pct}%)\" if pct is not None else \"\"\n                log.debug(f\"TypeScript LSP progress [{token}]: {msg}{pct_str}\")\n            elif kind == \"end\":\n                msg = value.get(\"message\", \"\")\n                log.info(f\"TypeScript LSP progress [{token}]: ended - {msg}\")\n                with self._progress_lock:\n                    self._active_progress_tokens.discard(token)\n                    if not self._active_progress_tokens:\n                        self._indexing_complete.set()\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_request(\"workspace/executeClientCommand\", execute_client_command_handler)\n        self.server.on_request(\"window/workDoneProgress/create\", work_done_progress_create)\n        self.server.on_notification(\"$/progress\", progress_handler)\n        self.server.on_notification(\"$/typescriptVersion\", handle_typescript_version)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting TypeScript server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\n            \"Sending initialize request from LSP client to LSP server and awaiting response\",\n        )\n        init_response = self.server.send.initialize(initialize_params)\n\n        # TypeScript-specific capability checks\n        assert init_response[\"capabilities\"][\"textDocumentSync\"] == 2\n        assert \"completionProvider\" in init_response[\"capabilities\"]\n        assert init_response[\"capabilities\"][\"completionProvider\"] == {\n            \"triggerCharacters\": [\".\", '\"', \"'\", \"/\", \"@\", \"<\"],\n            \"resolveProvider\": True,\n        }\n\n        self.server.notify.initialized({})\n        if self.server_ready.wait(timeout=10.0):\n            log.info(\"TypeScript server is ready\")\n        else:\n            log.info(\"Timeout waiting for TypeScript server to become ready, proceeding anyway\")\n            # Fallback: assume server is ready after timeout\n            self.server_ready.set()\n\n        # Wait for any async project loading to complete.\n        # typescript-language-server may send $/progress for \"Initializing JS/TS\n        # language features…\" after initialized. If no progress is sent,\n        # _indexing_complete stays SET and wait() returns immediately.\n        log.info(\"Waiting for TypeScript project indexing to complete (if async)...\")\n        if self.wait_for_indexing(timeout=self.INDEXING_PROGRESS_TIMEOUT):\n            log.info(\"TypeScript project indexing complete\")\n        else:\n            log.warning(\n                \"TypeScript project indexing did not complete within %.0fs; proceeding anyway\",\n                self.INDEXING_PROGRESS_TIMEOUT,\n            )\n\n    @override\n    def _get_wait_time_for_cross_file_referencing(self) -> float:\n        return 2\n\n    @override\n    def _get_preferred_definition(self, definitions: list[ls_types.Location]) -> ls_types.Location:\n        return prefer_non_node_modules_definition(definitions)\n"
  },
  {
    "path": "src/solidlsp/language_servers/vts_language_server.py",
    "content": "\"\"\"\nLanguage Server implementation for TypeScript/JavaScript using https://github.com/yioneko/vtsls,\nwhich provides TypeScript language server functionality via VSCode's TypeScript extension\n(contrary to typescript-language-server, which uses the TypeScript compiler directly).\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport shutil\nimport threading\nfrom typing import cast\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.ls_utils import PlatformId, PlatformUtils\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nfrom .common import RuntimeDependency, RuntimeDependencyCollection\n\nlog = logging.getLogger(__name__)\n\n\nclass VtsLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides TypeScript specific instantiation of the LanguageServer class using vtsls.\n    Contains various configurations and settings specific to TypeScript via vtsls wrapper.\n    \"\"\"\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a VtsLanguageServer instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.\n        \"\"\"\n        vts_lsp_executable_path = self._setup_runtime_dependencies(config, solidlsp_settings)\n        super().__init__(\n            config,\n            repository_root_path,\n            ProcessLaunchInfo(cmd=vts_lsp_executable_path, cwd=repository_root_path),\n            \"typescript\",\n            solidlsp_settings,\n        )\n        self.server_ready = threading.Event()\n        self.initialize_searcher_command_available = threading.Event()\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\n            \"node_modules\",\n            \"dist\",\n            \"build\",\n            \"coverage\",\n        ]\n\n    @classmethod\n    def _setup_runtime_dependencies(cls, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings) -> str:\n        \"\"\"\n        Setup runtime dependencies for VTS Language Server and return the command to start the server.\n        \"\"\"\n        platform_id = PlatformUtils.get_platform_id()\n\n        valid_platforms = [\n            PlatformId.LINUX_x64,\n            PlatformId.LINUX_arm64,\n            PlatformId.OSX,\n            PlatformId.OSX_x64,\n            PlatformId.OSX_arm64,\n            PlatformId.WIN_x64,\n            PlatformId.WIN_arm64,\n        ]\n        assert platform_id in valid_platforms, f\"Platform {platform_id} is not supported for vtsls at the moment\"\n\n        deps = RuntimeDependencyCollection(\n            [\n                RuntimeDependency(\n                    id=\"vtsls\",\n                    description=\"vtsls language server package\",\n                    command=\"npm install --prefix ./ @vtsls/language-server@0.2.9\",\n                    platform_id=\"any\",\n                ),\n            ]\n        )\n        vts_ls_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), \"vts-lsp\")\n        vts_executable_path = os.path.join(vts_ls_dir, \"vtsls\")\n\n        # Verify both node and npm are installed\n        is_node_installed = shutil.which(\"node\") is not None\n        assert is_node_installed, \"node is not installed or isn't in PATH. Please install NodeJS and try again.\"\n        is_npm_installed = shutil.which(\"npm\") is not None\n        assert is_npm_installed, \"npm is not installed or isn't in PATH. Please install npm and try again.\"\n\n        # Install vtsls if not already installed\n        if not os.path.exists(vts_ls_dir):\n            os.makedirs(vts_ls_dir, exist_ok=True)\n            deps.install(vts_ls_dir)\n\n        vts_executable_path = os.path.join(vts_ls_dir, \"node_modules\", \".bin\", \"vtsls\")\n\n        assert os.path.exists(vts_executable_path), \"vtsls executable not found. Please install @vtsls/language-server and try again.\"\n        return f\"{vts_executable_path} --stdio\"\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the VTS Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"signatureHelp\": {\"dynamicRegistration\": True},\n                    \"codeAction\": {\"dynamicRegistration\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True},\n                    \"configuration\": True,  # This might be needed for vtsls\n                },\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n        }\n        return cast(InitializeParams, initialize_params)\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the VTS Language Server, waits for the server to be ready and yields the LanguageServer instance.\n\n        Usage:\n        ```\n        async with lsp.start_server():\n            # LanguageServer has been initialized and ready to serve requests\n            await lsp.request_definition(...)\n            await lsp.request_references(...)\n            # Shutdown the LanguageServer on exit from scope\n        # LanguageServer has been shutdown\n        \"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            assert \"registrations\" in params\n            for registration in params[\"registrations\"]:\n                if registration[\"method\"] == \"workspace/executeCommand\":\n                    self.initialize_searcher_command_available.set()\n            return\n\n        def execute_client_command_handler(params: dict) -> list:\n            return []\n\n        def workspace_configuration_handler(params: dict) -> list[dict] | dict:\n            # VTS may request workspace configuration\n            # Return empty configuration for each requested item\n            if \"items\" in params:\n                return [{}] * len(params[\"items\"])\n            return {}\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def check_experimental_status(params: dict) -> None:\n            \"\"\"\n            Also listen for experimental/serverStatus as a backup signal\n            \"\"\"\n            if params.get(\"quiescent\") is True:\n                self.server_ready.set()\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_request(\"workspace/executeClientCommand\", execute_client_command_handler)\n        self.server.on_request(\"workspace/configuration\", workspace_configuration_handler)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n        self.server.on_notification(\"experimental/serverStatus\", check_experimental_status)\n\n        log.info(\"Starting VTS server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        # VTS-specific capability checks\n        # Be more flexible with capabilities since vtsls might have different structure\n        log.debug(f\"VTS init response capabilities: {init_response['capabilities']}\")\n\n        # Basic checks to ensure essential capabilities are present\n        assert \"textDocumentSync\" in init_response[\"capabilities\"]\n        assert \"completionProvider\" in init_response[\"capabilities\"]\n\n        # Log the actual values for debugging\n        log.debug(f\"textDocumentSync: {init_response['capabilities']['textDocumentSync']}\")\n        log.debug(f\"completionProvider: {init_response['capabilities']['completionProvider']}\")\n\n        self.server.notify.initialized({})\n        if self.server_ready.wait(timeout=1.0):\n            log.info(\"VTS server is ready\")\n        else:\n            log.info(\"Timeout waiting for VTS server to become ready, proceeding anyway\")\n            # Fallback: assume server is ready after timeout\n            self.server_ready.set()\n\n    @override\n    def _get_wait_time_for_cross_file_referencing(self) -> float:\n        return 1\n"
  },
  {
    "path": "src/solidlsp/language_servers/vue_language_server.py",
    "content": "\"\"\"\nVue Language Server implementation using @vue/language-server (Volar) with companion TypeScript LS.\nOperates in hybrid mode: Vue LS handles .vue files, TypeScript LS handles .ts/.js files.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport shutil\nimport threading\nfrom pathlib import Path\nfrom time import sleep\nfrom typing import Any\n\nfrom overrides import override\n\nfrom solidlsp import ls_types\nfrom solidlsp.language_servers.common import RuntimeDependency, RuntimeDependencyCollection\nfrom solidlsp.language_servers.typescript_language_server import (\n    TypeScriptLanguageServer,\n    prefer_non_node_modules_definition,\n)\nfrom solidlsp.ls import LSPFileBuffer, SolidLanguageServer\nfrom solidlsp.ls_config import Language, LanguageServerConfig\nfrom solidlsp.ls_exceptions import SolidLSPException\nfrom solidlsp.ls_types import Location\nfrom solidlsp.ls_utils import PathUtils\nfrom solidlsp.lsp_protocol_handler import lsp_types\nfrom solidlsp.lsp_protocol_handler.lsp_types import DocumentSymbol, ExecuteCommandParams, InitializeParams, SymbolInformation\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass VueTypeScriptServer(TypeScriptLanguageServer):\n    \"\"\"TypeScript LS configured with @vue/typescript-plugin for Vue file support.\"\"\"\n\n    @classmethod\n    @override\n    def get_language_enum_instance(cls) -> Language:\n        \"\"\"Return TYPESCRIPT since this is a TypeScript language server variant.\n\n        Note: VueTypeScriptServer is a companion server that uses TypeScript's language server\n        with the Vue TypeScript plugin. It reports as TYPESCRIPT to maintain compatibility\n        with the TypeScript language server infrastructure.\n        \"\"\"\n        return Language.TYPESCRIPT\n\n    class DependencyProvider(TypeScriptLanguageServer.DependencyProvider):\n        override_ts_ls_executable: str | None = None\n\n        def _get_or_install_core_dependency(self) -> str:\n            if self.override_ts_ls_executable is not None:\n                return self.override_ts_ls_executable\n            return super()._get_or_install_core_dependency()\n\n    @override\n    def _get_language_id_for_file(self, relative_file_path: str) -> str:\n        \"\"\"Return the correct language ID for files.\n\n        Vue files must be opened with language ID \"vue\" for the @vue/typescript-plugin\n        to process them correctly. The plugin is configured with \"languages\": [\"vue\"]\n        in the initialization options.\n        \"\"\"\n        ext = os.path.splitext(relative_file_path)[1].lower()\n        if ext == \".vue\":\n            return \"vue\"\n        elif ext in (\".ts\", \".tsx\", \".mts\", \".cts\"):\n            return \"typescript\"\n        elif ext in (\".js\", \".jsx\", \".mjs\", \".cjs\"):\n            return \"javascript\"\n        else:\n            return \"typescript\"\n\n    def __init__(\n        self,\n        config: LanguageServerConfig,\n        repository_root_path: str,\n        solidlsp_settings: SolidLSPSettings,\n        vue_plugin_path: str,\n        tsdk_path: str,\n        ts_ls_executable_path: str,\n    ):\n        self._vue_plugin_path = vue_plugin_path\n        self._custom_tsdk_path = tsdk_path\n        VueTypeScriptServer.DependencyProvider.override_ts_ls_executable = ts_ls_executable_path\n        super().__init__(config, repository_root_path, solidlsp_settings)\n        VueTypeScriptServer.DependencyProvider.override_ts_ls_executable = None\n\n    @override\n    def _get_initialize_params(self, repository_absolute_path: str) -> InitializeParams:\n        params = super()._get_initialize_params(repository_absolute_path)\n\n        params[\"initializationOptions\"] = {\n            \"plugins\": [\n                {\n                    \"name\": \"@vue/typescript-plugin\",\n                    \"location\": self._vue_plugin_path,\n                    \"languages\": [\"vue\"],\n                }\n            ],\n            \"tsserver\": {\n                \"path\": self._custom_tsdk_path,\n            },\n        }\n\n        if \"workspace\" in params[\"capabilities\"]:\n            params[\"capabilities\"][\"workspace\"][\"executeCommand\"] = {\"dynamicRegistration\": True}\n\n        return params\n\n    @override\n    def _start_server(self) -> None:\n        def workspace_configuration_handler(params: dict) -> list:\n            items = params.get(\"items\", [])\n            return [{} for _ in items]\n\n        self.server.on_request(\"workspace/configuration\", workspace_configuration_handler)\n        super()._start_server()\n\n\nclass VueLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Language server for Vue Single File Components using @vue/language-server (Volar) with companion TypeScript LS.\n\n    You can pass the following entries in ls_specific_settings[\"vue\"]:\n        - vue_language_server_version: Version of @vue/language-server to install (default: \"3.1.5\")\n\n    Note: TypeScript versions are configured via ls_specific_settings[\"typescript\"]:\n        - typescript_version: Version of TypeScript to install (default: \"5.9.3\")\n        - typescript_language_server_version: Version of typescript-language-server to install (default: \"5.1.3\")\n    \"\"\"\n\n    TS_SERVER_READY_TIMEOUT = 5.0\n    VUE_SERVER_READY_TIMEOUT = 3.0\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        vue_lsp_executable_path, self.tsdk_path, self._ts_ls_cmd = self._setup_runtime_dependencies(config, solidlsp_settings)\n        self._vue_ls_dir = os.path.join(self.ls_resources_dir(solidlsp_settings), \"vue-lsp\")\n        super().__init__(\n            config,\n            repository_root_path,\n            ProcessLaunchInfo(cmd=vue_lsp_executable_path, cwd=repository_root_path),\n            \"vue\",\n            solidlsp_settings,\n        )\n        self.server_ready = threading.Event()\n        self.initialize_searcher_command_available = threading.Event()\n        self._ts_server: VueTypeScriptServer | None = None\n        self._ts_server_started = False\n        self._vue_files_indexed = False\n        self._indexed_vue_file_uris: list[str] = []\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        return super().is_ignored_dirname(dirname) or dirname in [\n            \"node_modules\",\n            \"dist\",\n            \"build\",\n            \"coverage\",\n            \".nuxt\",\n            \".output\",\n        ]\n\n    @override\n    def _get_language_id_for_file(self, relative_file_path: str) -> str:\n        ext = os.path.splitext(relative_file_path)[1].lower()\n        if ext == \".vue\":\n            return \"vue\"\n        elif ext in (\".ts\", \".tsx\", \".mts\", \".cts\"):\n            return \"typescript\"\n        elif ext in (\".js\", \".jsx\", \".mjs\", \".cjs\"):\n            return \"javascript\"\n        else:\n            return \"vue\"\n\n    def _is_typescript_file(self, file_path: str) -> bool:\n        ext = os.path.splitext(file_path)[1].lower()\n        return ext in (\".ts\", \".tsx\", \".mts\", \".cts\", \".js\", \".jsx\", \".mjs\", \".cjs\")\n\n    def _find_all_vue_files(self) -> list[str]:\n        vue_files = []\n        repo_path = Path(self.repository_root_path)\n\n        for vue_file in repo_path.rglob(\"*.vue\"):\n            try:\n                relative_path = str(vue_file.relative_to(repo_path))\n                if \"node_modules\" not in relative_path and not relative_path.startswith(\".\"):\n                    vue_files.append(relative_path)\n            except Exception as e:\n                log.debug(f\"Error processing Vue file {vue_file}: {e}\")\n\n        return vue_files\n\n    def _ensure_vue_files_indexed_on_ts_server(self) -> None:\n        if self._vue_files_indexed:\n            return\n\n        assert self._ts_server is not None\n        log.info(\"Indexing .vue files on TypeScript server for cross-file references\")\n        vue_files = self._find_all_vue_files()\n        log.debug(f\"Found {len(vue_files)} .vue files to index\")\n\n        # Prepare the TS server to track new $/progress notifications triggered\n        # by the didOpen calls below. Must happen BEFORE opening files to avoid\n        # a race where progress begins and ends before we start waiting.\n        self._ts_server.expect_indexing()\n\n        for vue_file in vue_files:\n            try:\n                with self._ts_server.open_file(vue_file) as file_buffer:\n                    file_buffer.ref_count += 1\n                    self._indexed_vue_file_uris.append(file_buffer.uri)\n            except Exception as e:\n                log.debug(f\"Failed to open {vue_file} on TS server: {e}\")\n\n        self._vue_files_indexed = True\n        log.info(\"Vue file indexing on TypeScript server complete, waiting for TS server to finish processing\")\n\n        self._wait_for_ts_indexing_complete()\n\n    def _wait_for_ts_indexing_complete(self) -> None:\n        \"\"\"Wait for the companion TypeScript server to finish processing opened Vue files.\n\n        Uses the $/progress tracking in TypeScriptLanguageServer: after Vue files are\n        opened, tsserver sends \"Initializing JS/TS language features…\" progress.\n        We wait for all progress tokens to complete, with a timeout fallback.\n        \"\"\"\n        assert self._ts_server is not None\n        timeout = TypeScriptLanguageServer.INDEXING_PROGRESS_TIMEOUT\n        if self._ts_server.wait_for_indexing(timeout=timeout):\n            log.info(\"TypeScript server finished indexing Vue files (signaled via $/progress)\")\n        else:\n            log.warning(f\"Timeout ({timeout}s) waiting for TypeScript server to finish indexing Vue files, proceeding anyway\")\n\n    def _send_references_request(self, relative_file_path: str, line: int, column: int) -> list[lsp_types.Location] | None:\n        uri = PathUtils.path_to_uri(os.path.join(self.repository_root_path, relative_file_path))\n        request_params = {\n            \"textDocument\": {\"uri\": uri},\n            \"position\": {\"line\": line, \"character\": column},\n            \"context\": {\"includeDeclaration\": False},\n        }\n\n        return self.server.send.references(request_params)  # type: ignore[arg-type]\n\n    def _send_ts_references_request(self, relative_file_path: str, line: int, column: int) -> list[ls_types.Location]:\n        assert self._ts_server is not None\n        uri = PathUtils.path_to_uri(os.path.join(self.repository_root_path, relative_file_path))\n        request_params = {\n            \"textDocument\": {\"uri\": uri},\n            \"position\": {\"line\": line, \"character\": column},\n            \"context\": {\"includeDeclaration\": True},\n        }\n\n        with self._ts_server.open_file(relative_file_path):\n            response = self._ts_server.handler.send.references(request_params)  # type: ignore[arg-type]\n\n        result: list[ls_types.Location] = []\n        if response is not None:\n            for item in response:\n                abs_path = PathUtils.uri_to_path(item[\"uri\"])\n                if not Path(abs_path).is_relative_to(self.repository_root_path):\n                    log.debug(f\"Found reference outside repository: {abs_path}, skipping\")\n                    continue\n\n                rel_path = Path(abs_path).relative_to(self.repository_root_path)\n                if self.is_ignored_path(str(rel_path)):\n                    log.debug(f\"Ignoring reference in {rel_path}\")\n                    continue\n\n                new_item: dict = {}\n                new_item.update(item)  # type: ignore[arg-type]\n                new_item[\"absolutePath\"] = str(abs_path)\n                new_item[\"relativePath\"] = str(rel_path)\n                result.append(ls_types.Location(**new_item))  # type: ignore\n\n        return result\n\n    def request_file_references(self, relative_file_path: str) -> list:\n        if not self.server_started:\n            log.error(\"request_file_references called before Language Server started\")\n            raise SolidLSPException(\"Language Server not started\")\n\n        absolute_file_path = os.path.join(self.repository_root_path, relative_file_path)\n        uri = PathUtils.path_to_uri(absolute_file_path)\n\n        request_params = {\"textDocument\": {\"uri\": uri}}\n\n        log.info(f\"Sending volar/client/findFileReference request for {relative_file_path}\")\n        log.info(f\"Request URI: {uri}\")\n        log.info(f\"Request params: {request_params}\")\n\n        try:\n            with self.open_file(relative_file_path):\n                log.debug(f\"Sending volar/client/findFileReference for {relative_file_path}\")\n                log.debug(f\"Request params: {request_params}\")\n\n                response = self.server.send_request(\"volar/client/findFileReference\", request_params)\n\n                log.debug(f\"Received response type: {type(response)}\")\n\n            log.info(f\"Received file references response: {response}\")\n            log.info(f\"Response type: {type(response)}\")\n\n            if response is None:\n                log.debug(f\"No file references found for {relative_file_path}\")\n                return []\n\n            # Response should be an array of Location objects\n            if not isinstance(response, list):\n                log.warning(f\"Unexpected response format from volar/client/findFileReference: {type(response)}\")\n                return []\n\n            ret: list[Location] = []\n            for item in response:\n                if not isinstance(item, dict) or \"uri\" not in item:\n                    log.debug(f\"Skipping invalid location item: {item}\")\n                    continue\n\n                abs_path = PathUtils.uri_to_path(item[\"uri\"])  # type: ignore[arg-type]\n                if not Path(abs_path).is_relative_to(self.repository_root_path):\n                    log.warning(f\"Found file reference outside repository: {abs_path}, skipping\")\n                    continue\n\n                rel_path = Path(abs_path).relative_to(self.repository_root_path)\n                if self.is_ignored_path(str(rel_path)):\n                    log.debug(f\"Ignoring file reference in {rel_path}\")\n                    continue\n\n                new_item: dict = {}\n                new_item.update(item)  # type: ignore[arg-type]\n                new_item[\"absolutePath\"] = str(abs_path)\n                new_item[\"relativePath\"] = str(rel_path)\n                ret.append(Location(**new_item))  # type: ignore\n\n            log.debug(f\"Found {len(ret)} file references for {relative_file_path}\")\n            return ret\n\n        except Exception as e:\n            log.warning(f\"Error requesting file references for {relative_file_path}: {e}\")\n            return []\n\n    @override\n    def request_references(self, relative_file_path: str, line: int, column: int) -> list[ls_types.Location]:\n        if not self.server_started:\n            log.error(\"request_references called before Language Server started\")\n            raise SolidLSPException(\"Language Server not started\")\n\n        if not self._has_waited_for_cross_file_references:\n            sleep(self._get_wait_time_for_cross_file_referencing())\n            self._has_waited_for_cross_file_references = True\n\n        self._ensure_vue_files_indexed_on_ts_server()\n        symbol_refs = self._send_ts_references_request(relative_file_path, line=line, column=column)\n\n        if relative_file_path.endswith(\".vue\"):\n            log.info(f\"Attempting to find file-level references for Vue component {relative_file_path}\")\n            file_refs = self.request_file_references(relative_file_path)\n            log.info(f\"file_refs result: {len(file_refs)} references found\")\n\n            seen = set()\n            for ref in symbol_refs:\n                key = (ref[\"uri\"], ref[\"range\"][\"start\"][\"line\"], ref[\"range\"][\"start\"][\"character\"])\n                seen.add(key)\n\n            for file_ref in file_refs:\n                key = (file_ref[\"uri\"], file_ref[\"range\"][\"start\"][\"line\"], file_ref[\"range\"][\"start\"][\"character\"])\n                if key not in seen:\n                    symbol_refs.append(file_ref)\n                    seen.add(key)\n\n            log.info(f\"Total references for {relative_file_path}: {len(symbol_refs)} (symbol refs + file refs, deduplicated)\")\n\n        return symbol_refs\n\n    @override\n    def request_definition(self, relative_file_path: str, line: int, column: int) -> list[ls_types.Location]:\n        if not self.server_started:\n            log.error(\"request_definition called before Language Server started\")\n            raise SolidLSPException(\"Language Server not started\")\n\n        assert self._ts_server is not None\n        with self._ts_server.open_file(relative_file_path):\n            return self._ts_server.request_definition(relative_file_path, line, column)\n\n    @override\n    def request_rename_symbol_edit(self, relative_file_path: str, line: int, column: int, new_name: str) -> ls_types.WorkspaceEdit | None:\n        if not self.server_started:\n            log.error(\"request_rename_symbol_edit called before Language Server started\")\n            raise SolidLSPException(\"Language Server not started\")\n\n        assert self._ts_server is not None\n        with self._ts_server.open_file(relative_file_path):\n            return self._ts_server.request_rename_symbol_edit(relative_file_path, line, column, new_name)\n\n    @classmethod\n    def _setup_runtime_dependencies(cls, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings) -> tuple[list[str], str, str]:\n        is_node_installed = shutil.which(\"node\") is not None\n        assert is_node_installed, \"node is not installed or isn't in PATH. Please install NodeJS and try again.\"\n        is_npm_installed = shutil.which(\"npm\") is not None\n        assert is_npm_installed, \"npm is not installed or isn't in PATH. Please install npm and try again.\"\n\n        # Get TypeScript version settings from TypeScript language server settings\n        typescript_config = solidlsp_settings.get_ls_specific_settings(Language.TYPESCRIPT)\n        typescript_version = typescript_config.get(\"typescript_version\", \"5.9.3\")\n        typescript_language_server_version = typescript_config.get(\"typescript_language_server_version\", \"5.1.3\")\n        vue_config = solidlsp_settings.get_ls_specific_settings(Language.VUE)\n        vue_language_server_version = vue_config.get(\"vue_language_server_version\", \"3.1.5\")\n\n        deps = RuntimeDependencyCollection(\n            [\n                RuntimeDependency(\n                    id=\"vue-language-server\",\n                    description=\"Vue language server package (Volar)\",\n                    command=[\"npm\", \"install\", \"--prefix\", \"./\", f\"@vue/language-server@{vue_language_server_version}\"],\n                    platform_id=\"any\",\n                ),\n                RuntimeDependency(\n                    id=\"typescript\",\n                    description=\"TypeScript (required for tsdk)\",\n                    command=[\"npm\", \"install\", \"--prefix\", \"./\", f\"typescript@{typescript_version}\"],\n                    platform_id=\"any\",\n                ),\n                RuntimeDependency(\n                    id=\"typescript-language-server\",\n                    description=\"TypeScript language server (for Vue LS 3.x tsserver forwarding)\",\n                    command=[\n                        \"npm\",\n                        \"install\",\n                        \"--prefix\",\n                        \"./\",\n                        f\"typescript-language-server@{typescript_language_server_version}\",\n                    ],\n                    platform_id=\"any\",\n                ),\n            ]\n        )\n\n        vue_ls_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), \"vue-lsp\")\n        vue_executable_path = os.path.join(vue_ls_dir, \"node_modules\", \".bin\", \"vue-language-server\")\n        ts_ls_executable_path = os.path.join(vue_ls_dir, \"node_modules\", \".bin\", \"typescript-language-server\")\n\n        if os.name == \"nt\":\n            vue_executable_path += \".cmd\"\n            ts_ls_executable_path += \".cmd\"\n\n        tsdk_path = os.path.join(vue_ls_dir, \"node_modules\", \"typescript\", \"lib\")\n\n        # Check if installation is needed based on executables AND version\n        version_file = os.path.join(vue_ls_dir, \".installed_version\")\n        expected_version = f\"{vue_language_server_version}_{typescript_version}_{typescript_language_server_version}\"\n\n        needs_install = False\n        if not os.path.exists(vue_executable_path) or not os.path.exists(ts_ls_executable_path):\n            log.info(\"Vue/TypeScript Language Server executables not found.\")\n            needs_install = True\n        elif os.path.exists(version_file):\n            with open(version_file) as f:\n                installed_version = f.read().strip()\n            if installed_version != expected_version:\n                log.info(\n                    f\"Vue Language Server version mismatch: installed={installed_version}, expected={expected_version}. Reinstalling...\"\n                )\n                needs_install = True\n        else:\n            # No version file exists, assume old installation needs refresh\n            log.info(\"Vue Language Server version file not found. Reinstalling to ensure correct version...\")\n            needs_install = True\n\n        if needs_install:\n            log.info(\"Installing Vue/TypeScript Language Server dependencies...\")\n            deps.install(vue_ls_dir)\n            # Write version marker file\n            with open(version_file, \"w\") as f:\n                f.write(expected_version)\n            log.info(\"Vue language server dependencies installed successfully\")\n\n        if not os.path.exists(vue_executable_path):\n            raise FileNotFoundError(\n                f\"vue-language-server executable not found at {vue_executable_path}, something went wrong with the installation.\"\n            )\n\n        if not os.path.exists(ts_ls_executable_path):\n            raise FileNotFoundError(\n                f\"typescript-language-server executable not found at {ts_ls_executable_path}, something went wrong with the installation.\"\n            )\n\n        return [vue_executable_path, \"--stdio\"], tsdk_path, ts_ls_executable_path\n\n    def _get_initialize_params(self, repository_absolute_path: str) -> InitializeParams:\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\"dynamicRegistration\": True, \"completionItem\": {\"snippetSupport\": True}},\n                    \"definition\": {\"dynamicRegistration\": True, \"linkSupport\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"signatureHelp\": {\"dynamicRegistration\": True},\n                    \"codeAction\": {\"dynamicRegistration\": True},\n                    \"rename\": {\"dynamicRegistration\": True, \"prepareSupport\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True},\n                },\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n            \"initializationOptions\": {\n                \"vue\": {\n                    \"hybridMode\": True,\n                },\n                \"typescript\": {\n                    \"tsdk\": self.tsdk_path,\n                },\n            },\n        }\n        return initialize_params  # type: ignore\n\n    def _start_typescript_server(self) -> None:\n        try:\n            vue_ts_plugin_path = os.path.join(self._vue_ls_dir, \"node_modules\", \"@vue\", \"typescript-plugin\")\n\n            ts_config = LanguageServerConfig(\n                code_language=Language.TYPESCRIPT,\n                trace_lsp_communication=False,\n            )\n\n            log.info(\"Creating companion VueTypeScriptServer\")\n            self._ts_server = VueTypeScriptServer(\n                config=ts_config,\n                repository_root_path=self.repository_root_path,\n                solidlsp_settings=self._solidlsp_settings,\n                vue_plugin_path=vue_ts_plugin_path,\n                tsdk_path=self.tsdk_path,\n                ts_ls_executable_path=self._ts_ls_cmd,\n            )\n\n            log.info(\"Starting companion TypeScript server\")\n            self._ts_server.start()\n\n            log.info(\"Waiting for companion TypeScript server to be ready...\")\n            if not self._ts_server.server_ready.wait(timeout=self.TS_SERVER_READY_TIMEOUT):\n                log.warning(\n                    f\"Timeout waiting for companion TypeScript server to be ready after {self.TS_SERVER_READY_TIMEOUT} seconds, proceeding anyway\"\n                )\n                self._ts_server.server_ready.set()\n\n            self._ts_server_started = True\n            log.info(\"Companion TypeScript server ready\")\n        except Exception as e:\n            log.error(f\"Error starting TypeScript server: {e}\")\n            self._ts_server = None\n            self._ts_server_started = False\n            raise\n\n    def _forward_tsserver_request(self, method: str, params: dict) -> Any:\n        if self._ts_server is None:\n            log.error(\"Cannot forward tsserver request - TypeScript server not started\")\n            return None\n\n        try:\n            execute_params: ExecuteCommandParams = {\n                \"command\": \"typescript.tsserverRequest\",\n                \"arguments\": [method, params, {\"isAsync\": True, \"lowPriority\": True}],\n            }\n            result = self._ts_server.handler.send.execute_command(execute_params)\n            log.debug(f\"TypeScript server raw response for {method}: {result}\")\n\n            if isinstance(result, dict) and \"body\" in result:\n                return result[\"body\"]\n            return result\n        except Exception as e:\n            log.error(f\"Error forwarding tsserver request {method}: {e}\")\n            return None\n\n    def _cleanup_indexed_vue_files(self) -> None:\n        if not self._indexed_vue_file_uris or self._ts_server is None:\n            return\n\n        log.debug(f\"Cleaning up {len(self._indexed_vue_file_uris)} indexed Vue files\")\n        for uri in self._indexed_vue_file_uris:\n            try:\n                if uri in self._ts_server.open_file_buffers:\n                    file_buffer = self._ts_server.open_file_buffers[uri]\n                    file_buffer.ref_count -= 1\n\n                    if file_buffer.ref_count == 0:\n                        self._ts_server.server.notify.did_close_text_document({\"textDocument\": {\"uri\": uri}})\n                        del self._ts_server.open_file_buffers[uri]\n                        log.debug(f\"Closed indexed Vue file: {uri}\")\n            except Exception as e:\n                log.debug(f\"Error closing indexed Vue file {uri}: {e}\")\n\n        self._indexed_vue_file_uris.clear()\n\n    def _stop_typescript_server(self) -> None:\n        if self._ts_server is not None:\n            try:\n                log.info(\"Stopping companion TypeScript server\")\n                self._ts_server.stop()\n            except Exception as e:\n                log.warning(f\"Error stopping TypeScript server: {e}\")\n            finally:\n                self._ts_server = None\n                self._ts_server_started = False\n\n    @override\n    def _start_server(self) -> None:\n        self._start_typescript_server()\n\n        def register_capability_handler(params: dict) -> None:\n            assert \"registrations\" in params\n            for registration in params[\"registrations\"]:\n                if registration[\"method\"] == \"workspace/executeCommand\":\n                    self.initialize_searcher_command_available.set()\n            return\n\n        def configuration_handler(params: dict) -> list:\n            items = params.get(\"items\", [])\n            return [{} for _ in items]\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n            message_text = msg.get(\"message\", \"\")\n            if \"initialized\" in message_text.lower() or \"ready\" in message_text.lower():\n                log.info(\"Vue language server ready signal detected\")\n                self.server_ready.set()\n\n        def tsserver_request_notification_handler(params: list) -> None:\n            try:\n                if params and len(params) > 0 and len(params[0]) >= 2:\n                    request_id = params[0][0]\n                    method = params[0][1]\n                    method_params = params[0][2] if len(params[0]) > 2 else {}\n                    log.debug(f\"Received tsserver/request: id={request_id}, method={method}\")\n\n                    if method == \"_vue:projectInfo\":\n                        file_path = method_params.get(\"file\", \"\")\n                        tsconfig_path = self._find_tsconfig_for_file(file_path)\n                        result = {\"configFileName\": tsconfig_path} if tsconfig_path else None\n                        response = [[request_id, result]]\n                        self.server.notify.send_notification(\"tsserver/response\", response)\n                        log.debug(f\"Sent tsserver/response for projectInfo: {tsconfig_path}\")\n                    else:\n                        result = self._forward_tsserver_request(method, method_params)\n                        response = [[request_id, result]]\n                        self.server.notify.send_notification(\"tsserver/response\", response)\n                        log.debug(f\"Forwarded tsserver/response for {method}: {result}\")\n                else:\n                    log.warning(f\"Unexpected tsserver/request params format: {params}\")\n            except Exception as e:\n                log.error(f\"Error handling tsserver/request: {e}\")\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_request(\"workspace/configuration\", configuration_handler)\n        self.server.on_notification(\"tsserver/request\", tsserver_request_notification_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting Vue server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        log.debug(f\"Received initialize response from Vue server: {init_response}\")\n\n        assert init_response[\"capabilities\"][\"textDocumentSync\"] in [1, 2]\n\n        self.server.notify.initialized({})\n\n        log.info(\"Waiting for Vue language server to be ready...\")\n        if not self.server_ready.wait(timeout=self.VUE_SERVER_READY_TIMEOUT):\n            log.info(\"Timeout waiting for Vue server ready signal, proceeding anyway\")\n            self.server_ready.set()\n        else:\n            log.info(\"Vue server initialization complete\")\n\n    def _find_tsconfig_for_file(self, file_path: str) -> str | None:\n        if not file_path:\n            tsconfig_path = os.path.join(self.repository_root_path, \"tsconfig.json\")\n            return tsconfig_path if os.path.exists(tsconfig_path) else None\n\n        current_dir = os.path.dirname(file_path)\n        repo_root = os.path.abspath(self.repository_root_path)\n\n        while current_dir and current_dir.startswith(repo_root):\n            tsconfig_path = os.path.join(current_dir, \"tsconfig.json\")\n            if os.path.exists(tsconfig_path):\n                return tsconfig_path\n            parent = os.path.dirname(current_dir)\n            if parent == current_dir:\n                break\n            current_dir = parent\n\n        tsconfig_path = os.path.join(repo_root, \"tsconfig.json\")\n        return tsconfig_path if os.path.exists(tsconfig_path) else None\n\n    @override\n    def _get_wait_time_for_cross_file_referencing(self) -> float:\n        return 5.0\n\n    @override\n    def stop(self, shutdown_timeout: float = 5.0) -> None:\n        self._cleanup_indexed_vue_files()\n        self._stop_typescript_server()\n        super().stop(shutdown_timeout)\n\n    @override\n    def _get_preferred_definition(self, definitions: list[ls_types.Location]) -> ls_types.Location:\n        return prefer_non_node_modules_definition(definitions)\n\n    @override\n    def _request_document_symbols(\n        self, relative_file_path: str, file_data: LSPFileBuffer | None\n    ) -> list[SymbolInformation] | list[DocumentSymbol] | None:\n        \"\"\"\n        Override to filter out shorthand property references in Vue files.\n\n        In Vue, when using shorthand syntax in defineExpose like `defineExpose({ pressCount })`,\n        the Vue LSP returns both:\n        - The Variable definition (e.g., `const pressCount = ref(0)`)\n        - A Property symbol for the shorthand reference (e.g., `pressCount` in defineExpose)\n\n        This causes duplicate symbols with the same name, which breaks symbol lookup.\n        We filter out Property symbols that have a matching Variable with the same name\n        at a different location (the definition), keeping only the definition.\n        \"\"\"\n        symbols = super()._request_document_symbols(relative_file_path, file_data)\n\n        if symbols is None or len(symbols) == 0:\n            return symbols\n\n        # Only process DocumentSymbol format (hierarchical symbols with children)\n        # SymbolInformation format doesn't have the same issue\n        if not isinstance(symbols[0], dict) or \"range\" not in symbols[0]:\n            return symbols\n\n        return self._filter_shorthand_property_duplicates(symbols)\n\n    def _filter_shorthand_property_duplicates(\n        self, symbols: list[DocumentSymbol] | list[SymbolInformation]\n    ) -> list[DocumentSymbol] | list[SymbolInformation]:\n        \"\"\"\n        Filter out Property symbols that have a matching Variable symbol with the same name.\n\n        This handles Vue's shorthand property syntax in defineExpose, where the same\n        identifier appears as both a Variable definition and a Property reference.\n        \"\"\"\n        VARIABLE_KIND = 13  # SymbolKind.Variable\n        PROPERTY_KIND = 7  # SymbolKind.Property\n\n        def filter_symbols(syms: list[dict]) -> list[dict]:\n            # Collect all Variable symbol names with their line numbers\n            variable_names: dict[str, set[int]] = {}\n            for sym in syms:\n                if sym.get(\"kind\") == VARIABLE_KIND:\n                    name = sym.get(\"name\", \"\")\n                    line = sym.get(\"range\", {}).get(\"start\", {}).get(\"line\", -1)\n                    if name not in variable_names:\n                        variable_names[name] = set()\n                    variable_names[name].add(line)\n\n            # Filter: keep symbols that are either:\n            # 1. Not a Property, or\n            # 2. A Property without a matching Variable name at a different location\n            filtered = []\n            for sym in syms:\n                name = sym.get(\"name\", \"\")\n                kind = sym.get(\"kind\")\n                line = sym.get(\"range\", {}).get(\"start\", {}).get(\"line\", -1)\n\n                # If it's a Property with a matching Variable name at a DIFFERENT line, skip it\n                if kind == PROPERTY_KIND and name in variable_names:\n                    # Check if there's a Variable definition at a different line\n                    var_lines = variable_names[name]\n                    if any(var_line != line for var_line in var_lines):\n                        # This is a shorthand reference, skip it\n                        log.debug(\n                            f\"Filtering shorthand property reference '{name}' at line {line} \"\n                            f\"(Variable definition exists at line(s) {var_lines})\"\n                        )\n                        continue\n\n                # Recursively filter children\n                children = sym.get(\"children\", [])\n                if children:\n                    sym = dict(sym)  # Create a copy to avoid mutating the original\n                    sym[\"children\"] = filter_symbols(children)\n\n                filtered.append(sym)\n\n            return filtered\n\n        return filter_symbols(list(symbols))  # type: ignore\n"
  },
  {
    "path": "src/solidlsp/language_servers/yaml_language_server.py",
    "content": "\"\"\"\nProvides YAML specific instantiation of the LanguageServer class using yaml-language-server.\nContains various configurations and settings specific to YAML files.\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport shutil\nfrom typing import Any\n\nfrom solidlsp.language_servers.common import RuntimeDependency, RuntimeDependencyCollection\nfrom solidlsp.ls import LanguageServerDependencyProvider, LanguageServerDependencyProviderSinglePath, SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass YamlLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides YAML specific instantiation of the LanguageServer class using yaml-language-server.\n    Contains various configurations and settings specific to YAML files.\n    \"\"\"\n\n    @staticmethod\n    def _determine_log_level(line: str) -> int:\n        \"\"\"Classify yaml-language-server stderr output to avoid false-positive errors.\"\"\"\n        line_lower = line.lower()\n\n        # Known informational messages from yaml-language-server that aren't critical errors\n        if any(\n            [\n                \"cannot find module\" in line_lower and \"package.json\" in line_lower,  # Schema resolution - not critical\n                \"no parser\" in line_lower,  # Parser messages - informational\n            ]\n        ):\n            return logging.DEBUG\n\n        return SolidLanguageServer._determine_log_level(line)\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        \"\"\"\n        Creates a YamlLanguageServer instance. This class is not meant to be instantiated directly.\n        Use LanguageServer.create() instead.\n        \"\"\"\n        super().__init__(\n            config,\n            repository_root_path,\n            None,\n            \"yaml\",\n            solidlsp_settings,\n        )\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        return self.DependencyProvider(self._custom_settings, self._ls_resources_dir)\n\n    class DependencyProvider(LanguageServerDependencyProviderSinglePath):\n        def _get_or_install_core_dependency(self) -> str:\n            \"\"\"\n            Setup runtime dependencies for YAML Language Server and return the command to start the server.\n            \"\"\"\n            # Verify both node and npm are installed\n            is_node_installed = shutil.which(\"node\") is not None\n            assert is_node_installed, \"node is not installed or isn't in PATH. Please install NodeJS and try again.\"\n            is_npm_installed = shutil.which(\"npm\") is not None\n            assert is_npm_installed, \"npm is not installed or isn't in PATH. Please install npm and try again.\"\n\n            deps = RuntimeDependencyCollection(\n                [\n                    RuntimeDependency(\n                        id=\"yaml-language-server\",\n                        description=\"yaml-language-server package (Red Hat)\",\n                        command=\"npm install --prefix ./ yaml-language-server@1.19.2\",\n                        platform_id=\"any\",\n                    ),\n                ]\n            )\n\n            # Install yaml-language-server if not already installed\n            yaml_ls_dir = os.path.join(self._ls_resources_dir, \"yaml-lsp\")\n            yaml_executable_path = os.path.join(yaml_ls_dir, \"node_modules\", \".bin\", \"yaml-language-server\")\n\n            # Handle Windows executable extension\n            if os.name == \"nt\":\n                yaml_executable_path += \".cmd\"\n\n            if not os.path.exists(yaml_executable_path):\n                log.info(f\"YAML Language Server executable not found at {yaml_executable_path}. Installing...\")\n                deps.install(yaml_ls_dir)\n                log.info(\"YAML language server dependencies installed successfully\")\n\n            if not os.path.exists(yaml_executable_path):\n                raise FileNotFoundError(\n                    f\"yaml-language-server executable not found at {yaml_executable_path}, something went wrong with the installation.\"\n                )\n\n            return yaml_executable_path\n\n        def _create_launch_command(self, core_path: str) -> list[str]:\n            return [core_path, \"--stdio\"]\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the YAML Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"completion\": {\"dynamicRegistration\": True, \"completionItem\": {\"snippetSupport\": True}},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"hover\": {\"dynamicRegistration\": True, \"contentFormat\": [\"markdown\", \"plaintext\"]},\n                    \"codeAction\": {\"dynamicRegistration\": True},\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"symbol\": {\"dynamicRegistration\": True},\n                },\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n            \"initializationOptions\": {\n                \"yaml\": {\n                    \"schemaStore\": {\"enable\": True, \"url\": \"https://www.schemastore.org/api/json/catalog.json\"},\n                    \"format\": {\"enable\": True},\n                    \"validate\": True,\n                    \"hover\": True,\n                    \"completion\": True,\n                }\n            },\n        }\n        return initialize_params  # type: ignore\n\n    def _start_server(self) -> None:\n        \"\"\"\n        Starts the YAML Language Server, waits for the server to be ready and yields the LanguageServer instance.\n        \"\"\"\n\n        def register_capability_handler(params: Any) -> None:\n            return\n\n        def do_nothing(params: Any) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting YAML server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n        log.debug(f\"Received initialize response from YAML server: {init_response}\")\n\n        # Verify document symbol support is available\n        if \"documentSymbolProvider\" in init_response[\"capabilities\"]:\n            log.info(\"YAML server supports document symbols\")\n        else:\n            log.warning(\"Warning: YAML server does not report document symbol support\")\n\n        self.server.notify.initialized({})\n\n        # YAML language server is ready immediately after initialization\n        log.info(\"YAML server initialization complete\")\n"
  },
  {
    "path": "src/solidlsp/language_servers/zls.py",
    "content": "\"\"\"\nProvides Zig specific instantiation of the LanguageServer class using ZLS (Zig Language Server).\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nimport platform\nimport shutil\nimport subprocess\n\nfrom overrides import override\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import LanguageServerConfig\nfrom solidlsp.lsp_protocol_handler.lsp_types import InitializeParams\nfrom solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo\nfrom solidlsp.settings import SolidLSPSettings\n\nlog = logging.getLogger(__name__)\n\n\nclass ZigLanguageServer(SolidLanguageServer):\n    \"\"\"\n    Provides Zig specific instantiation of the LanguageServer class using ZLS.\n    \"\"\"\n\n    @override\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        # For Zig projects, we should ignore:\n        # - zig-cache: build cache directory\n        # - zig-out: default build output directory\n        # - .zig-cache: alternative cache location\n        # - node_modules: if the project has JavaScript components\n        return super().is_ignored_dirname(dirname) or dirname in [\"zig-cache\", \"zig-out\", \".zig-cache\", \"node_modules\", \"build\", \"dist\"]\n\n    @staticmethod\n    def _get_zig_version() -> str | None:\n        \"\"\"Get the installed Zig version or None if not found.\"\"\"\n        try:\n            result = subprocess.run([\"zig\", \"version\"], capture_output=True, text=True, check=False)\n            if result.returncode == 0:\n                return result.stdout.strip()\n        except FileNotFoundError:\n            return None\n        return None\n\n    @staticmethod\n    def _get_zls_version() -> str | None:\n        \"\"\"Get the installed ZLS version or None if not found.\"\"\"\n        try:\n            result = subprocess.run([\"zls\", \"--version\"], capture_output=True, text=True, check=False)\n            if result.returncode == 0:\n                return result.stdout.strip()\n        except FileNotFoundError:\n            return None\n        return None\n\n    @staticmethod\n    def _check_zls_installed() -> bool:\n        \"\"\"Check if ZLS is installed in the system.\"\"\"\n        return shutil.which(\"zls\") is not None\n\n    @staticmethod\n    def _setup_runtime_dependency() -> bool:\n        \"\"\"\n        Check if required Zig runtime dependencies are available.\n        Raises RuntimeError with helpful message if dependencies are missing.\n        \"\"\"\n        # Check for Windows and provide error message\n        if platform.system() == \"Windows\":\n            raise RuntimeError(\n                \"Windows is not supported by ZLS in this integration. \"\n                \"Cross-file references don't work reliably on Windows. Reason unknown.\"\n            )\n\n        zig_version = ZigLanguageServer._get_zig_version()\n        if not zig_version:\n            raise RuntimeError(\n                \"Zig is not installed. Please install Zig from https://ziglang.org/download/ and make sure it is added to your PATH.\"\n            )\n\n        if not ZigLanguageServer._check_zls_installed():\n            zls_version = ZigLanguageServer._get_zls_version()\n            if not zls_version:\n                raise RuntimeError(\n                    \"Found Zig but ZLS (Zig Language Server) is not installed.\\n\"\n                    \"Please install ZLS from https://github.com/zigtools/zls\\n\"\n                    \"You can install it via:\\n\"\n                    \"  - Package managers (brew install zls, scoop install zls, etc.)\\n\"\n                    \"  - Download pre-built binaries from GitHub releases\\n\"\n                    \"  - Build from source with: zig build -Doptimize=ReleaseSafe\\n\\n\"\n                    \"After installation, make sure 'zls' is added to your PATH.\"\n                )\n\n        return True\n\n    def __init__(self, config: LanguageServerConfig, repository_root_path: str, solidlsp_settings: SolidLSPSettings):\n        self._setup_runtime_dependency()\n\n        super().__init__(config, repository_root_path, ProcessLaunchInfo(cmd=\"zls\", cwd=repository_root_path), \"zig\", solidlsp_settings)\n        self.request_id = 0\n\n    @staticmethod\n    def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:\n        \"\"\"\n        Returns the initialize params for the Zig Language Server.\n        \"\"\"\n        root_uri = pathlib.Path(repository_absolute_path).as_uri()\n        initialize_params = {\n            \"locale\": \"en\",\n            \"capabilities\": {\n                \"textDocument\": {\n                    \"synchronization\": {\"didSave\": True, \"dynamicRegistration\": True},\n                    \"definition\": {\"dynamicRegistration\": True},\n                    \"references\": {\"dynamicRegistration\": True},\n                    \"documentSymbol\": {\n                        \"dynamicRegistration\": True,\n                        \"hierarchicalDocumentSymbolSupport\": True,\n                        \"symbolKind\": {\"valueSet\": list(range(1, 27))},\n                    },\n                    \"completion\": {\n                        \"dynamicRegistration\": True,\n                        \"completionItem\": {\n                            \"snippetSupport\": True,\n                            \"commitCharactersSupport\": True,\n                            \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                            \"deprecatedSupport\": True,\n                            \"preselectSupport\": True,\n                        },\n                    },\n                    \"hover\": {\n                        \"dynamicRegistration\": True,\n                        \"contentFormat\": [\"markdown\", \"plaintext\"],\n                    },\n                },\n                \"workspace\": {\n                    \"workspaceFolders\": True,\n                    \"didChangeConfiguration\": {\"dynamicRegistration\": True},\n                    \"configuration\": True,\n                },\n            },\n            \"processId\": os.getpid(),\n            \"rootPath\": repository_absolute_path,\n            \"rootUri\": root_uri,\n            \"workspaceFolders\": [\n                {\n                    \"uri\": root_uri,\n                    \"name\": os.path.basename(repository_absolute_path),\n                }\n            ],\n            \"initializationOptions\": {\n                # ZLS specific options based on schema.json\n                # Critical paths for ZLS to understand the project\n                \"zig_exe_path\": shutil.which(\"zig\"),  # Path to zig executable\n                \"zig_lib_path\": None,  # Let ZLS auto-detect\n                \"build_runner_path\": None,  # Let ZLS use its built-in runner\n                \"global_cache_path\": None,  # Let ZLS use default cache\n                # Build configuration\n                \"enable_build_on_save\": True,  # Enable to analyze project structure\n                \"build_on_save_args\": [\"build\"],\n                # Features\n                \"enable_snippets\": True,\n                \"enable_argument_placeholders\": True,\n                \"semantic_tokens\": \"full\",\n                \"warn_style\": False,\n                \"highlight_global_var_declarations\": False,\n                \"skip_std_references\": False,\n                \"prefer_ast_check_as_child_process\": True,\n                \"completion_label_details\": True,\n                # Inlay hints configuration\n                \"inlay_hints_show_variable_type_hints\": True,\n                \"inlay_hints_show_struct_literal_field_type\": True,\n                \"inlay_hints_show_parameter_name\": True,\n                \"inlay_hints_show_builtin\": True,\n                \"inlay_hints_exclude_single_argument\": True,\n                \"inlay_hints_hide_redundant_param_names\": False,\n                \"inlay_hints_hide_redundant_param_names_last_token\": False,\n            },\n        }\n        return initialize_params  # type: ignore[return-value]\n\n    def _start_server(self) -> None:\n        \"\"\"Start ZLS server process\"\"\"\n\n        def register_capability_handler(params: dict) -> None:\n            return\n\n        def window_log_message(msg: dict) -> None:\n            log.info(f\"LSP: window/logMessage: {msg}\")\n\n        def do_nothing(params: dict) -> None:\n            return\n\n        self.server.on_request(\"client/registerCapability\", register_capability_handler)\n        self.server.on_notification(\"window/logMessage\", window_log_message)\n        self.server.on_notification(\"$/progress\", do_nothing)\n        self.server.on_notification(\"textDocument/publishDiagnostics\", do_nothing)\n\n        log.info(\"Starting ZLS server process\")\n        self.server.start()\n        initialize_params = self._get_initialize_params(self.repository_root_path)\n\n        log.info(\"Sending initialize request from LSP client to LSP server and awaiting response\")\n        init_response = self.server.send.initialize(initialize_params)\n\n        # Verify server capabilities\n        assert \"textDocumentSync\" in init_response[\"capabilities\"]\n        assert \"definitionProvider\" in init_response[\"capabilities\"]\n        assert \"documentSymbolProvider\" in init_response[\"capabilities\"]\n        assert \"referencesProvider\" in init_response[\"capabilities\"]\n\n        self.server.notify.initialized({})\n\n        # ZLS server is ready after initialization\n        # (no need to wait for an event)\n\n        # Open build.zig if it exists to help ZLS understand project structure\n        build_zig_path = os.path.join(self.repository_root_path, \"build.zig\")\n        if os.path.exists(build_zig_path):\n            try:\n                with open(build_zig_path, encoding=\"utf-8\") as f:\n                    content = f.read()\n                    uri = pathlib.Path(build_zig_path).as_uri()\n                    self.server.notify.did_open_text_document(\n                        {\n                            \"textDocument\": {\n                                \"uri\": uri,\n                                \"languageId\": \"zig\",\n                                \"version\": 1,\n                                \"text\": content,\n                            }\n                        }\n                    )\n                    log.info(\"Opened build.zig to provide project context to ZLS\")\n            except Exception as e:\n                log.warning(f\"Failed to open build.zig: {e}\")\n"
  },
  {
    "path": "src/solidlsp/ls.py",
    "content": "import dataclasses\nimport hashlib\nimport json\nimport logging\nimport os\nimport pathlib\nimport shutil\nimport subprocess\nimport threading\nfrom abc import ABC, abstractmethod\nfrom collections import defaultdict\nfrom collections.abc import Hashable, Iterator\nfrom contextlib import contextmanager\nfrom copy import copy\nfrom pathlib import Path, PurePath\nfrom time import perf_counter, sleep\nfrom typing import Self, Union, cast\n\nimport pathspec\nfrom sensai.util.pickle import getstate, load_pickle\nfrom sensai.util.string import ToStringMixin\n\nfrom serena.util.file_system import match_path\nfrom serena.util.text_utils import MatchedConsecutiveLines\nfrom solidlsp import ls_types\nfrom solidlsp.ls_config import Language, LanguageServerConfig\nfrom solidlsp.ls_exceptions import SolidLSPException\nfrom solidlsp.ls_process import LanguageServerProcess\nfrom solidlsp.ls_types import UnifiedSymbolInformation\nfrom solidlsp.ls_utils import FileUtils, PathUtils, TextUtils\nfrom solidlsp.lsp_protocol_handler import lsp_types\nfrom solidlsp.lsp_protocol_handler import lsp_types as LSPTypes\nfrom solidlsp.lsp_protocol_handler.lsp_constants import LSPConstants\nfrom solidlsp.lsp_protocol_handler.lsp_types import (\n    Definition,\n    DefinitionParams,\n    DocumentSymbol,\n    LocationLink,\n    RenameParams,\n    SymbolInformation,\n)\nfrom solidlsp.lsp_protocol_handler.server import (\n    LSPError,\n    ProcessLaunchInfo,\n    StringDict,\n)\nfrom solidlsp.settings import SolidLSPSettings\nfrom solidlsp.util.cache import load_cache, save_cache\n\nGenericDocumentSymbol = Union[LSPTypes.DocumentSymbol, LSPTypes.SymbolInformation, ls_types.UnifiedSymbolInformation]\nlog = logging.getLogger(__name__)\n\n_debug_enabled = log.isEnabledFor(logging.DEBUG)\n\"\"\"Serves as a flag that triggers additional computation when debug logging is enabled.\"\"\"\n\n\n@dataclasses.dataclass(kw_only=True)\nclass ReferenceInSymbol:\n    \"\"\"A symbol retrieved when requesting reference to a symbol, together with the location of the reference\"\"\"\n\n    symbol: ls_types.UnifiedSymbolInformation\n    line: int\n    character: int\n\n\nclass LSPFileBuffer:\n    \"\"\"\n    This class is used to store the contents of an open LSP file in memory.\n    \"\"\"\n\n    def __init__(\n        self,\n        abs_path: Path,\n        uri: str,\n        encoding: str,\n        version: int,\n        language_id: str,\n        ref_count: int,\n        language_server: \"SolidLanguageServer\",\n        open_in_ls: bool = True,\n    ) -> None:\n        self.abs_path = abs_path\n        self.language_server = language_server\n        self.uri = uri\n        self._read_file_modified_date: float | None = None\n        self._contents: str | None = None\n        self.version = version\n        self.language_id = language_id\n        self.ref_count = ref_count\n        self.encoding = encoding\n        self._content_hash: str | None = None\n        self._is_open_in_ls = False\n        if open_in_ls:\n            self._open_in_ls()\n\n    def _open_in_ls(self) -> None:\n        \"\"\"\n        Open the file in the language server if it is not already open.\n        \"\"\"\n        if self._is_open_in_ls:\n            return\n        self._is_open_in_ls = True\n        self.language_server.server.notify.did_open_text_document(\n            {\n                LSPConstants.TEXT_DOCUMENT: {  # type: ignore\n                    LSPConstants.URI: self.uri,\n                    LSPConstants.LANGUAGE_ID: self.language_id,\n                    LSPConstants.VERSION: 0,\n                    LSPConstants.TEXT: self.contents,\n                }\n            }\n        )\n\n    def close(self) -> None:\n        if self._is_open_in_ls:\n            self.language_server.server.notify.did_close_text_document(\n                {\n                    LSPConstants.TEXT_DOCUMENT: {  # type: ignore\n                        LSPConstants.URI: self.uri,\n                    }\n                }\n            )\n\n    def ensure_open_in_ls(self) -> None:\n        \"\"\"Ensure that the file is opened in the language server.\"\"\"\n        self._open_in_ls()\n\n    @property\n    def contents(self) -> str:\n        file_modified_date = self.abs_path.stat().st_mtime\n\n        # if contents are cached, check if they are stale (file modification since last read) and invalidate if so\n        if self._contents is not None:\n            assert self._read_file_modified_date is not None\n            if file_modified_date > self._read_file_modified_date:\n                self._contents = None\n\n        if self._contents is None:\n            self._read_file_modified_date = file_modified_date\n            self._contents = FileUtils.read_file(str(self.abs_path), self.encoding)\n            self._content_hash = None\n\n        return self._contents\n\n    @contents.setter\n    def contents(self, new_contents: str) -> None:\n        \"\"\"\n        Sets new contents for the file buffer (in-memory change only).\n        Persistence of the change to disk must be handled separately.\n\n        :param new_contents: the new contents to set\n        \"\"\"\n        self._contents = new_contents\n        self._content_hash = None\n\n    @property\n    def content_hash(self) -> str:\n        if self._content_hash is None:\n            self._content_hash = hashlib.md5(self.contents.encode(self.encoding)).hexdigest()\n        return self._content_hash\n\n    def split_lines(self) -> list[str]:\n        \"\"\"Splits the contents of the file into lines.\"\"\"\n        return self.contents.split(\"\\n\")\n\n\nclass SymbolBody(ToStringMixin):\n    \"\"\"\n    Representation of the body of a symbol, which allows the extraction of the symbol's text\n    from the lines of the file it is defined in.\n\n    Instances that share the same lines buffer are memory-efficient,\n    using only 4 integers and a reference to the lines buffer from which the text can be extracted,\n    i.e. a core representation of only about 40 bytes per body.\n    \"\"\"\n\n    def __init__(self, lines: list[str], start_line: int, start_col: int, end_line: int, end_col: int) -> None:\n        self._lines = lines\n        self._start_line = start_line\n        self._start_col = start_col\n        self._end_line = end_line\n        self._end_col = end_col\n\n    def _tostring_excludes(self) -> list[str]:\n        return [\"_lines\"]\n\n    def get_text(self) -> str:\n        # extract relevant lines\n        symbol_body = \"\\n\".join(self._lines[self._start_line : self._end_line + 1])\n\n        # remove leading content from the first line\n        symbol_body = symbol_body[self._start_col :]\n\n        # remove trailing content from the last line\n        last_line = self._lines[self._end_line]\n        trailing_length = len(last_line) - self._end_col\n        if trailing_length > 0:\n            symbol_body = symbol_body[: -(len(last_line) - self._end_col)]\n\n        return symbol_body\n\n\nclass SymbolBodyFactory:\n    \"\"\"\n    A factory for the creation of SymbolBody instances from symbols dictionaries.\n    Instances created from the same factory instance are memory-efficient, as they share\n    the same lines buffer.\n    \"\"\"\n\n    def __init__(self, file_buffer: LSPFileBuffer):\n        self._lines = file_buffer.split_lines()\n\n    def create_symbol_body(self, symbol: GenericDocumentSymbol) -> SymbolBody:\n        existing_body = symbol.get(\"body\", None)\n        if existing_body and isinstance(existing_body, SymbolBody):\n            return existing_body\n\n        assert \"location\" in symbol\n        start_line = symbol[\"location\"][\"range\"][\"start\"][\"line\"]  # type: ignore\n        end_line = symbol[\"location\"][\"range\"][\"end\"][\"line\"]  # type: ignore\n        start_col = symbol[\"location\"][\"range\"][\"start\"][\"character\"]  # type: ignore\n        end_col = symbol[\"location\"][\"range\"][\"end\"][\"character\"]  # type: ignore\n        return SymbolBody(self._lines, start_line, start_col, end_line, end_col)\n\n\nclass DocumentSymbols:\n    # IMPORTANT: Instances of this class are persisted in the high-level document symbol cache\n\n    def __init__(self, root_symbols: list[ls_types.UnifiedSymbolInformation]):\n        self.root_symbols = root_symbols\n        self._all_symbols: list[ls_types.UnifiedSymbolInformation] | None = None\n\n    def __getstate__(self) -> dict:\n        return getstate(DocumentSymbols, self, transient_properties=[\"_all_symbols\"])\n\n    def iter_symbols(self) -> Iterator[ls_types.UnifiedSymbolInformation]:\n        \"\"\"\n        Iterate over all symbols in the document symbol tree.\n        Yields symbols in a depth-first manner.\n        \"\"\"\n        if self._all_symbols is not None:\n            yield from self._all_symbols\n            return\n\n        def traverse(s: ls_types.UnifiedSymbolInformation) -> Iterator[ls_types.UnifiedSymbolInformation]:\n            yield s\n            for child in s.get(\"children\", []):\n                yield from traverse(child)\n\n        for root_symbol in self.root_symbols:\n            yield from traverse(root_symbol)\n\n    def get_all_symbols_and_roots(self) -> tuple[list[ls_types.UnifiedSymbolInformation], list[ls_types.UnifiedSymbolInformation]]:\n        \"\"\"\n        This function returns all symbols in the document as a flat list and the root symbols.\n        It exists to facilitate migration from previous versions, where this was the return interface of\n        the LS method that obtained document symbols.\n\n        :return: A tuple containing a list of all symbols in the document and a list of root symbols.\n        \"\"\"\n        if self._all_symbols is None:\n            self._all_symbols = list(self.iter_symbols())\n        return self._all_symbols, self.root_symbols\n\n\nclass LanguageServerDependencyProvider(ABC):\n    \"\"\"\n    Prepares dependencies for a language server (if any), ultimately enabling the launch command to be constructed\n    and optionally providing environment variables that are necessary for the execution.\n    \"\"\"\n\n    def __init__(self, custom_settings: SolidLSPSettings.CustomLSSettings, ls_resources_dir: str):\n        self._custom_settings = custom_settings\n        self._ls_resources_dir = ls_resources_dir\n\n    @abstractmethod\n    def create_launch_command(self) -> list[str]:\n        \"\"\"\n        Creates the launch command for this language server, potentially downloading and installing dependencies\n        beforehand.\n\n        :return: the launch command as a list containing the executable and its arguments\n        \"\"\"\n\n    def create_launch_command_env(self) -> dict[str, str]:\n        \"\"\"\n        Provides environment variables to be set when executing the launch command.\n\n        This method is intended to be overridden by subclasses that need to set variables.\n\n        :return: a mapping for variable names to values\n        \"\"\"\n        return {}\n\n\nclass LanguageServerDependencyProviderSinglePath(LanguageServerDependencyProvider, ABC):\n    \"\"\"\n    Special case of a dependency provider, where there is a single core dependency which provides\n    the basis for the launch command.\n\n    The core dependency's path can be overridden by the user in LS-specific settings (SerenaConfig)\n    via the key \"ls_path\". If the user provides the key, the specified path is used directly.\n    Otherwise, the provider implementation is called to get or install the core dependency.\n    \"\"\"\n\n    @abstractmethod\n    def _get_or_install_core_dependency(self) -> str:\n        \"\"\"\n        Gets the language server's core path, potentially installing dependencies beforehand.\n\n        :return: the core dependency's path (e.g. executable, jar, etc.)\n        \"\"\"\n\n    def create_launch_command(self) -> list[str]:\n        path = self._custom_settings.get(\"ls_path\", None)\n        if path is not None:\n            core_path = path\n        else:\n            core_path = self._get_or_install_core_dependency()\n        return self._create_launch_command(core_path)\n\n    @abstractmethod\n    def _create_launch_command(self, core_path: str) -> list[str]:\n        \"\"\"\n        :param core_path: path to the core dependency\n        :return: the launch command as a list containing the executable and its arguments\n        \"\"\"\n\n\nclass SolidLanguageServer(ABC):\n    \"\"\"\n    The LanguageServer class provides a language agnostic interface to the Language Server Protocol.\n    It is used to communicate with Language Servers of different programming languages.\n    \"\"\"\n\n    CACHE_FOLDER_NAME = \"cache\"\n    RAW_DOCUMENT_SYMBOLS_CACHE_VERSION = 1\n    \"\"\"\n    global version identifier for raw symbol caches; an LS-specific version is defined separately and combined with this.\n    This should be incremented whenever there is a change in the way raw document symbols are stored.\n    If the result of a language server changes in a way that affects the raw document symbols,\n    the LS-specific version should be incremented instead.\n    \"\"\"\n    RAW_DOCUMENT_SYMBOL_CACHE_FILENAME = \"raw_document_symbols.pkl\"\n    RAW_DOCUMENT_SYMBOL_CACHE_FILENAME_LEGACY_FALLBACK = \"document_symbols_cache_v23-06-25.pkl\"\n    DOCUMENT_SYMBOL_CACHE_VERSION = 4\n    DOCUMENT_SYMBOL_CACHE_FILENAME = \"document_symbols.pkl\"\n\n    # To be overridden and extended by subclasses\n    def is_ignored_dirname(self, dirname: str) -> bool:\n        \"\"\"\n        A language-specific condition for directories that should always be ignored. For example, venv\n        in Python and node_modules in JS/TS should be ignored always.\n        \"\"\"\n        return dirname.startswith(\".\")\n\n    @staticmethod\n    def _determine_log_level(line: str) -> int:\n        \"\"\"\n        Classify a stderr line from the language server to determine appropriate logging level.\n\n        Language servers may emit informational messages to stderr that contain words like \"error\"\n        but are not actual errors. Subclasses can override this method to filter out known\n        false-positive patterns specific to their language server.\n\n        :param line: The stderr line to classify\n        :return: A logging level (logging.DEBUG, logging.INFO, logging.WARNING, or logging.ERROR)\n        \"\"\"\n        line_lower = line.lower()\n\n        # Default classification: treat lines with \"error\" or \"exception\" as ERROR level\n        if \"error\" in line_lower or \"exception\" in line_lower or line.startswith(\"E[\"):\n            return logging.ERROR\n        else:\n            return logging.INFO\n\n    @classmethod\n    def get_language_enum_instance(cls) -> Language:\n        return Language.from_ls_class(cls)\n\n    @classmethod\n    def ls_resources_dir(cls, solidlsp_settings: SolidLSPSettings, mkdir: bool = True) -> str:\n        \"\"\"\n        Returns the directory where the language server resources are downloaded.\n        This is used to store language server binaries, configuration files, etc.\n        \"\"\"\n        result = os.path.join(solidlsp_settings.ls_resources_dir, cls.__name__)\n\n        # Migration of previously downloaded LS resources that were downloaded to a subdir of solidlsp instead of to the user's home\n        pre_migration_ls_resources_dir = os.path.join(os.path.dirname(__file__), \"language_servers\", \"static\", cls.__name__)\n        if os.path.exists(pre_migration_ls_resources_dir):\n            if os.path.exists(result):\n                # if the directory already exists, we just remove the old resources\n                shutil.rmtree(result, ignore_errors=True)\n            else:\n                # move old resources to the new location\n                shutil.move(pre_migration_ls_resources_dir, result)\n        if mkdir:\n            os.makedirs(result, exist_ok=True)\n        return result\n\n    @classmethod\n    def create(\n        cls,\n        config: LanguageServerConfig,\n        repository_root_path: str,\n        timeout: float | None = None,\n        solidlsp_settings: SolidLSPSettings | None = None,\n    ) -> \"SolidLanguageServer\":\n        \"\"\"\n        Creates a language specific LanguageServer instance based on the given configuration, and appropriate settings for the programming language.\n\n        If language is Java, then ensure that jdk-17.0.6 or higher is installed, `java` is in PATH, and JAVA_HOME is set to the installation directory.\n        If language is JS/TS, then ensure that node (v18.16.0 or higher) is installed and in PATH.\n\n        :param repository_root_path: The root path of the repository.\n        :param config: language server configuration.\n        :param logger: The logger to use.\n        :param timeout: the timeout for requests to the language server. If None, no timeout will be used.\n        :param solidlsp_settings: additional settings\n        :return LanguageServer: A language specific LanguageServer instance.\n        \"\"\"\n        ls: SolidLanguageServer\n        if solidlsp_settings is None:\n            solidlsp_settings = SolidLSPSettings()\n\n        # Ensure repository_root_path is absolute to avoid issues with file URIs\n        repository_root_path = os.path.abspath(repository_root_path)\n\n        ls_class = config.code_language.get_ls_class()\n        # For now, we assume that all language server implementations have the same signature of the constructor\n        # (which, unfortunately, differs from the signature of the base class).\n        # If this assumption is ever violated, we need branching logic here.\n        ls = ls_class(config, repository_root_path, solidlsp_settings)  # type: ignore\n        ls.set_request_timeout(timeout)\n        return ls\n\n    def __init__(\n        self,\n        config: LanguageServerConfig,\n        repository_root_path: str,\n        process_launch_info: ProcessLaunchInfo | None,\n        language_id: str,\n        solidlsp_settings: SolidLSPSettings,\n        cache_version_raw_document_symbols: Hashable = 1,\n    ):\n        \"\"\"\n        Initializes a LanguageServer instance.\n\n        Do not instantiate this class directly. Use `LanguageServer.create` method instead.\n\n        :param config: the global SolidLSP configuration.\n        :param repository_root_path: the root path of the repository.\n        :param process_launch_info: (DEPRECATED - implement _create_dependency_provider instead)\n            the command used to start the actual language server.\n            The command must pass appropriate flags to the binary, so that it runs in the stdio mode,\n            as opposed to HTTP, TCP modes supported by some language servers.\n        :param cache_version_raw_document_symbols: the version, for caching, of the raw document symbols coming\n            from this specific language server. This should be incremented by subclasses calling this constructor\n            whenever the format of the raw document symbols changes (typically because the language server\n            improves/fixes its output).\n        \"\"\"\n        self._solidlsp_settings = solidlsp_settings\n        lang = self.get_language_enum_instance()\n        self._custom_settings = solidlsp_settings.get_ls_specific_settings(lang)\n        self._ls_resources_dir = self.ls_resources_dir(solidlsp_settings)\n        log.debug(f\"Custom config (LS-specific settings) for {lang}: {self._custom_settings}\")\n        self._encoding = config.encoding\n        self.repository_root_path: str = repository_root_path\n\n        log.debug(\n            f\"Creating language server instance for {repository_root_path=} with {language_id=} and process launch info: {process_launch_info}\"\n        )\n\n        self.language_id = language_id\n        self.open_file_buffers: dict[str, LSPFileBuffer] = {}\n        self.language = Language(language_id)\n\n        # initialise symbol caches\n        self.cache_dir = Path(self._solidlsp_settings.project_data_path) / self.CACHE_FOLDER_NAME / self.language_id\n        self.cache_dir.mkdir(parents=True, exist_ok=True)\n        # * raw document symbols cache\n        self._ls_specific_raw_document_symbols_cache_version = cache_version_raw_document_symbols\n        self._raw_document_symbols_cache: dict[str, tuple[str, list[DocumentSymbol] | list[SymbolInformation] | None]] = {}\n        \"\"\"maps relative file paths to a tuple of (file_content_hash, raw_root_symbols)\"\"\"\n        self._raw_document_symbols_cache_is_modified: bool = False\n        self._load_raw_document_symbols_cache()\n        # * high-level document symbols cache\n        self._document_symbols_cache: dict[str, tuple[str, DocumentSymbols]] = {}\n        \"\"\"maps relative file paths to a tuple of (file_content_hash, document_symbols)\"\"\"\n        self._document_symbols_cache_is_modified: bool = False\n        self._load_document_symbols_cache()\n\n        self.server_started = False\n        if config.trace_lsp_communication:\n\n            def logging_fn(source: str, target: str, msg: StringDict | str) -> None:\n                log.debug(f\"LSP: {source} -> {target}: {msg!s}\")\n\n        else:\n            logging_fn = None  # type: ignore\n\n        # create the LanguageServerHandler, which provides the functionality to start the language server and communicate with it,\n        # preparing the launch command beforehand\n        self._dependency_provider: LanguageServerDependencyProvider | None = None\n        if process_launch_info is None:\n            self._dependency_provider = self._create_dependency_provider()\n            process_launch_info = self._create_process_launch_info()\n        log.debug(f\"Creating language server instance with {language_id=} and process launch info: {process_launch_info}\")\n        self.server = LanguageServerProcess(\n            process_launch_info,\n            language=self.language,\n            determine_log_level=self._determine_log_level,\n            logger=logging_fn,\n            start_independent_lsp_process=config.start_independent_lsp_process,\n        )\n\n        # Set up the pathspec matcher for the ignored paths\n        # for all absolute paths in ignored_paths, convert them to relative paths\n        processed_patterns = []\n        for pattern in set(config.ignored_paths):\n            # Normalize separators (pathspec expects forward slashes)\n            pattern = pattern.replace(os.path.sep, \"/\")\n            processed_patterns.append(pattern)\n        log.debug(f\"Processing {len(processed_patterns)} ignored paths from the config\")\n\n        # Create a pathspec matcher from the processed patterns\n        self._ignore_spec = pathspec.PathSpec.from_lines(pathspec.patterns.GitWildMatchPattern, processed_patterns)\n\n        self._request_timeout: float | None = None\n\n        self._has_waited_for_cross_file_references = False\n\n    def _create_dependency_provider(self) -> LanguageServerDependencyProvider:\n        \"\"\"\n        Creates the dependency provider for this language server.\n\n        Subclasses should override this method to provide their specific dependency provider.\n        This method is only called if process_launch_info is not passed to __init__.\n        \"\"\"\n        raise NotImplementedError(\n            f\"{self.__class__.__name__} must implement _create_dependency_provider() or pass process_launch_info to __init__()\"\n        )\n\n    def _create_process_launch_info(self) -> ProcessLaunchInfo:\n        assert self._dependency_provider is not None\n        cmd = self._dependency_provider.create_launch_command()\n        env = self._dependency_provider.create_launch_command_env()\n        return ProcessLaunchInfo(cmd=cmd, cwd=self.repository_root_path, env=env)\n\n    def _get_wait_time_for_cross_file_referencing(self) -> float:\n        \"\"\"Meant to be overridden by subclasses for LS that don't have a reliable \"finished initializing\" signal.\n\n        LS may return incomplete results on calls to `request_references` (only references found in the same file),\n        if the LS is not fully initialized yet.\n        \"\"\"\n        return 2\n\n    def set_request_timeout(self, timeout: float | None) -> None:\n        \"\"\"\n        :param timeout: the timeout, in seconds, for requests to the language server.\n        \"\"\"\n        self.server.set_request_timeout(timeout)\n\n    def get_ignore_spec(self) -> pathspec.PathSpec:\n        \"\"\"\n        Returns the pathspec matcher for the paths that were configured to be ignored through\n        the language server configuration.\n\n        This is a subset of the full language-specific ignore spec that determines\n        which files are relevant for the language server.\n\n        This matcher is useful for operations outside of the language server,\n        such as when searching for relevant non-language files in the project.\n        \"\"\"\n        return self._ignore_spec\n\n    def is_ignored_path(self, relative_path: str, ignore_unsupported_files: bool = True) -> bool:\n        \"\"\"\n        Determine if a path should be ignored based on file type\n        and ignore patterns.\n\n        :param relative_path: Relative path to check\n        :param ignore_unsupported_files: whether files that are not supported source files should be ignored\n\n        :return: True if the path should be ignored, False otherwise\n        \"\"\"\n        abs_path = os.path.join(self.repository_root_path, relative_path)\n        if not os.path.exists(abs_path):\n            raise FileNotFoundError(f\"File {abs_path} not found, the ignore check cannot be performed\")\n\n        # Check file extension if it's a file\n        is_file = os.path.isfile(abs_path)\n        if is_file and ignore_unsupported_files:\n            fn_matcher = self.language.get_source_fn_matcher()\n            if not fn_matcher.is_relevant_filename(abs_path):\n                return True\n\n        # Create normalized path for consistent handling\n        rel_path = Path(relative_path)\n\n        # Check each part of the path against always fulfilled ignore conditions\n        dir_parts = rel_path.parts\n        if is_file:\n            dir_parts = dir_parts[:-1]\n        for part in dir_parts:\n            if not part:  # Skip empty parts (e.g., from leading '/')\n                continue\n            if self.is_ignored_dirname(part):\n                return True\n\n        return match_path(relative_path, self.get_ignore_spec(), root_path=self.repository_root_path)\n\n    def _shutdown(self, timeout: float = 5.0) -> None:\n        \"\"\"\n        A robust shutdown process designed to terminate cleanly on all platforms, including Windows,\n        by explicitly closing all I/O pipes.\n        \"\"\"\n        if not self.server.is_running():\n            log.debug(\"Server process not running, skipping shutdown.\")\n            return\n\n        log.info(f\"Initiating final robust shutdown with a {timeout}s timeout...\")\n        process = self.server.process\n        if process is None:\n            log.debug(\"Server process is None, cannot shutdown.\")\n            return\n\n        # --- Main Shutdown Logic ---\n        # Stage 1: Graceful Termination Request\n        # Send LSP shutdown and close stdin to signal no more input.\n        try:\n            log.debug(\"Sending LSP shutdown request...\")\n            # Use a thread to timeout the LSP shutdown call since it can hang\n            shutdown_thread = threading.Thread(target=self.server.shutdown)\n            shutdown_thread.daemon = True\n            shutdown_thread.start()\n            shutdown_thread.join(timeout=2.0)  # 2 second timeout for LSP shutdown\n\n            if shutdown_thread.is_alive():\n                log.debug(\"LSP shutdown request timed out, proceeding to terminate...\")\n            else:\n                log.debug(\"LSP shutdown request completed.\")\n\n            if process.stdin and not process.stdin.closed:\n                process.stdin.close()\n            log.debug(\"Stage 1 shutdown complete.\")\n        except Exception as e:\n            log.debug(f\"Exception during graceful shutdown: {e}\")\n            # Ignore errors here, we are proceeding to terminate anyway.\n\n        # Stage 2: Terminate and Wait for Process to Exit\n        log.debug(f\"Terminating process {process.pid}, current status: {process.poll()}\")\n        process.terminate()\n\n        # Stage 3: Wait for process termination with timeout\n        try:\n            log.debug(f\"Waiting for process {process.pid} to terminate...\")\n            exit_code = process.wait(timeout=timeout)\n            log.info(f\"Language server process terminated successfully with exit code {exit_code}.\")\n        except subprocess.TimeoutExpired:\n            # If termination failed, forcefully kill the process\n            log.warning(f\"Process {process.pid} termination timed out, killing process forcefully...\")\n            process.kill()\n            try:\n                exit_code = process.wait(timeout=2.0)\n                log.info(f\"Language server process killed successfully with exit code {exit_code}.\")\n            except subprocess.TimeoutExpired:\n                log.error(f\"Process {process.pid} could not be killed within timeout.\")\n        except Exception as e:\n            log.error(f\"Error during process shutdown: {e}\")\n\n    @contextmanager\n    def start_server(self) -> Iterator[\"SolidLanguageServer\"]:\n        self.start()\n        yield self\n        self.stop()\n\n    def _start_server_process(self) -> None:\n        self.server_started = True\n        self._start_server()\n\n    @abstractmethod\n    def _start_server(self) -> None:\n        pass\n\n    def _get_language_id_for_file(self, relative_file_path: str) -> str:\n        \"\"\"Return the language ID for a file.\n\n        Override in subclasses to return file-specific language IDs.\n        Default implementation returns self.language_id.\n        \"\"\"\n        return self.language_id\n\n    @contextmanager\n    def open_file(self, relative_file_path: str, open_in_ls: bool = True) -> Iterator[LSPFileBuffer]:\n        \"\"\"\n        Open a file in the Language Server. This is required before making any requests to the Language Server.\n\n        :param relative_file_path: The relative path of the file to open.\n        :param open_in_ls: whether to open the file in the language server, sending the didOpen notification.\n            Set this to False to read the local file buffer without notifying the LS; the file can\n            be opened in the LS later by calling the `ensure_open_in_ls` method on the returned LSPFileBuffer.\n        \"\"\"\n        if not self.server_started:\n            log.error(\"open_file called before Language Server started\")\n            raise SolidLSPException(\"Language Server not started\")\n\n        absolute_file_path = Path(self.repository_root_path, relative_file_path)\n        uri = absolute_file_path.as_uri()\n\n        if uri in self.open_file_buffers:\n            fb = self.open_file_buffers[uri]\n            assert fb.uri == uri\n            assert fb.ref_count >= 1\n\n            fb.ref_count += 1\n            if open_in_ls:\n                fb.ensure_open_in_ls()\n            yield fb\n            fb.ref_count -= 1\n        else:\n            version = 0\n            language_id = self._get_language_id_for_file(relative_file_path)\n            fb = LSPFileBuffer(\n                abs_path=absolute_file_path,\n                uri=uri,\n                encoding=self._encoding,\n                version=version,\n                language_id=language_id,\n                ref_count=1,\n                language_server=self,\n                open_in_ls=open_in_ls,\n            )\n            self.open_file_buffers[uri] = fb\n            yield fb\n            fb.ref_count -= 1\n\n        if self.open_file_buffers[uri].ref_count == 0:\n            self.open_file_buffers[uri].close()\n            del self.open_file_buffers[uri]\n\n    @contextmanager\n    def _open_file_context(\n        self, relative_file_path: str, file_buffer: LSPFileBuffer | None = None, open_in_ls: bool = True\n    ) -> Iterator[LSPFileBuffer]:\n        \"\"\"\n        Internal context manager to open a file, optionally reusing an existing file buffer.\n\n        :param relative_file_path: the relative path of the file to open.\n        :param file_buffer: an optional existing file buffer to reuse.\n        :param open_in_ls: whether to open the file in the language server, sending the didOpen notification.\n            Set this to False to read the local file buffer without notifying the LS; the file can\n            be opened in the LS later by calling the `ensure_open_in_ls` method on the returned LSPFileBuffer.\n        \"\"\"\n        if file_buffer is not None:\n            expected_uri = pathlib.Path(os.path.join(self.repository_root_path, relative_file_path)).as_uri()\n            assert file_buffer.uri == expected_uri, f\"Inconsistency between provided {file_buffer.uri=} and {expected_uri=}\"\n            if open_in_ls:\n                file_buffer.ensure_open_in_ls()\n            yield file_buffer\n        else:\n            with self.open_file(relative_file_path, open_in_ls=open_in_ls) as fb:\n                yield fb\n\n    def insert_text_at_position(self, relative_file_path: str, line: int, column: int, text_to_be_inserted: str) -> ls_types.Position:\n        \"\"\"\n        Insert text at the given line and column in the given file and return\n        the updated cursor position after inserting the text.\n\n        :param relative_file_path: The relative path of the file to open.\n        :param line: The line number at which text should be inserted.\n        :param column: The column number at which text should be inserted.\n        :param text_to_be_inserted: The text to insert.\n        \"\"\"\n        if not self.server_started:\n            log.error(\"insert_text_at_position called before Language Server started\")\n            raise SolidLSPException(\"Language Server not started\")\n\n        absolute_file_path = str(PurePath(self.repository_root_path, relative_file_path))\n        uri = pathlib.Path(absolute_file_path).as_uri()\n\n        # Ensure the file is open\n        assert uri in self.open_file_buffers\n\n        file_buffer = self.open_file_buffers[uri]\n        file_buffer.version += 1\n\n        new_contents, new_l, new_c = TextUtils.insert_text_at_position(file_buffer.contents, line, column, text_to_be_inserted)\n        file_buffer.contents = new_contents\n        self.server.notify.did_change_text_document(\n            {\n                LSPConstants.TEXT_DOCUMENT: {  # type: ignore\n                    LSPConstants.VERSION: file_buffer.version,\n                    LSPConstants.URI: file_buffer.uri,\n                },\n                LSPConstants.CONTENT_CHANGES: [\n                    {\n                        LSPConstants.RANGE: {\n                            \"start\": {\"line\": line, \"character\": column},\n                            \"end\": {\"line\": line, \"character\": column},\n                        },\n                        \"text\": text_to_be_inserted,\n                    }\n                ],\n            }\n        )\n        return ls_types.Position(line=new_l, character=new_c)\n\n    def delete_text_between_positions(\n        self,\n        relative_file_path: str,\n        start: ls_types.Position,\n        end: ls_types.Position,\n    ) -> str:\n        \"\"\"\n        Delete text between the given start and end positions in the given file and return the deleted text.\n        \"\"\"\n        if not self.server_started:\n            log.error(\"insert_text_at_position called before Language Server started\")\n            raise SolidLSPException(\"Language Server not started\")\n\n        absolute_file_path = str(PurePath(self.repository_root_path, relative_file_path))\n        uri = pathlib.Path(absolute_file_path).as_uri()\n\n        # Ensure the file is open\n        assert uri in self.open_file_buffers\n\n        file_buffer = self.open_file_buffers[uri]\n        file_buffer.version += 1\n        new_contents, deleted_text = TextUtils.delete_text_between_positions(\n            file_buffer.contents, start_line=start[\"line\"], start_col=start[\"character\"], end_line=end[\"line\"], end_col=end[\"character\"]\n        )\n        file_buffer.contents = new_contents\n        self.server.notify.did_change_text_document(\n            {\n                LSPConstants.TEXT_DOCUMENT: {  # type: ignore\n                    LSPConstants.VERSION: file_buffer.version,\n                    LSPConstants.URI: file_buffer.uri,\n                },\n                LSPConstants.CONTENT_CHANGES: [{LSPConstants.RANGE: {\"start\": start, \"end\": end}, \"text\": \"\"}],\n            }\n        )\n        return deleted_text\n\n    def _send_definition_request(self, definition_params: DefinitionParams) -> Definition | list[LocationLink] | None:\n        return self.server.send.definition(definition_params)\n\n    def request_definition(self, relative_file_path: str, line: int, column: int) -> list[ls_types.Location]:\n        \"\"\"\n        Raise a [textDocument/definition](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_definition) request to the Language Server\n        for the symbol at the given line and column in the given file. Wait for the response and return the result.\n\n        :param relative_file_path: The relative path of the file that has the symbol for which definition should be looked up\n        :param line: The line number of the symbol\n        :param column: The column number of the symbol\n\n        :return: the list of locations where the symbol is defined\n        \"\"\"\n        if not self.server_started:\n            log.error(\"request_definition called before language server started\")\n            raise SolidLSPException(\"Language Server not started\")\n\n        if not self._has_waited_for_cross_file_references:\n            # Some LS require waiting for a while before they can return cross-file definitions.\n            # This is a workaround for such LS that don't have a reliable \"finished initializing\" signal.\n            sleep(self._get_wait_time_for_cross_file_referencing())\n            self._has_waited_for_cross_file_references = True\n\n        with self.open_file(relative_file_path):\n            # sending request to the language server and waiting for response\n            definition_params = cast(\n                DefinitionParams,\n                {\n                    LSPConstants.TEXT_DOCUMENT: {\n                        LSPConstants.URI: pathlib.Path(str(PurePath(self.repository_root_path, relative_file_path))).as_uri()\n                    },\n                    LSPConstants.POSITION: {\n                        LSPConstants.LINE: line,\n                        LSPConstants.CHARACTER: column,\n                    },\n                },\n            )\n            response = self._send_definition_request(definition_params)\n\n        ret: list[ls_types.Location] = []\n        if isinstance(response, list):\n            # response is either of type Location[] or LocationLink[]\n            for item in response:\n                assert isinstance(item, dict)\n                if LSPConstants.URI in item and LSPConstants.RANGE in item:\n                    new_item: dict = {}\n                    new_item.update(item)\n                    new_item[\"absolutePath\"] = PathUtils.uri_to_path(new_item[\"uri\"])\n                    new_item[\"relativePath\"] = PathUtils.get_relative_path(new_item[\"absolutePath\"], self.repository_root_path)\n                    ret.append(ls_types.Location(**new_item))  # type: ignore\n                elif LSPConstants.TARGET_URI in item and LSPConstants.TARGET_RANGE in item and LSPConstants.TARGET_SELECTION_RANGE in item:\n                    new_item: dict = {}  # type: ignore\n                    new_item[\"uri\"] = item[LSPConstants.TARGET_URI]  # type: ignore\n                    new_item[\"absolutePath\"] = PathUtils.uri_to_path(new_item[\"uri\"])\n                    new_item[\"relativePath\"] = PathUtils.get_relative_path(new_item[\"absolutePath\"], self.repository_root_path)\n                    new_item[\"range\"] = item[LSPConstants.TARGET_SELECTION_RANGE]  # type: ignore\n                    ret.append(ls_types.Location(**new_item))  # type: ignore\n                else:\n                    assert False, f\"Unexpected response from Language Server: {item}\"\n        elif isinstance(response, dict):\n            # response is of type Location\n            assert LSPConstants.URI in response\n            assert LSPConstants.RANGE in response\n\n            new_item: dict = {}  # type: ignore\n            new_item.update(response)\n            new_item[\"absolutePath\"] = PathUtils.uri_to_path(new_item[\"uri\"])\n            new_item[\"relativePath\"] = PathUtils.get_relative_path(new_item[\"absolutePath\"], self.repository_root_path)\n            ret.append(ls_types.Location(**new_item))  # type: ignore\n        elif response is None:\n            # Some language servers return None when they cannot find a definition\n            # This is expected for certain symbol types like generics or types with incomplete information\n            log.warning(f\"Language server returned None for definition request at {relative_file_path}:{line}:{column}\")\n        else:\n            assert False, f\"Unexpected response from Language Server: {response}\"\n\n        return ret\n\n    # Some LS cause problems with this, so the call is isolated from the rest to allow overriding in subclasses\n    def _send_references_request(self, relative_file_path: str, line: int, column: int) -> list[lsp_types.Location] | None:\n        return self.server.send.references(\n            {\n                \"textDocument\": {\"uri\": PathUtils.path_to_uri(os.path.join(self.repository_root_path, relative_file_path))},\n                \"position\": {\"line\": line, \"character\": column},\n                \"context\": {\"includeDeclaration\": False},\n            }\n        )\n\n    def request_references(self, relative_file_path: str, line: int, column: int) -> list[ls_types.Location]:\n        \"\"\"\n        Raise a [textDocument/references](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_references) request to the Language Server\n        to find references to the symbol at the given line and column in the given file. Wait for the response and return the result.\n        Filters out references located in ignored directories.\n\n        :param relative_file_path: The relative path of the file that has the symbol for which references should be looked up\n        :param line: The line number of the symbol\n        :param column: The column number of the symbol\n\n        :return: A list of locations where the symbol is referenced (excluding ignored directories)\n        \"\"\"\n        if not self.server_started:\n            log.error(\"request_references called before Language Server started\")\n            raise SolidLSPException(\"Language Server not started\")\n\n        with self.open_file(relative_file_path):\n            if not self._has_waited_for_cross_file_references:\n                # Some LS require waiting for a while before they can return cross-file references.\n                # This is a workaround for such LS that don't have a reliable \"finished initializing\" signal.\n                # The waiting has to happen after at least one file was opened in the ls\n                sleep(self._get_wait_time_for_cross_file_referencing())\n                self._has_waited_for_cross_file_references = True\n            t0 = perf_counter() if _debug_enabled else 0.0\n            try:\n                response = self._send_references_request(relative_file_path, line=line, column=column)\n            except Exception as e:\n                # Catch LSP internal error (-32603) and raise a more informative exception\n                if isinstance(e, LSPError) and getattr(e, \"code\", None) == -32603:\n                    raise RuntimeError(\n                        f\"LSP internal error (-32603) when requesting references for {relative_file_path}:{line}:{column}. \"\n                        \"This often occurs when requesting references for a symbol not referenced in the expected way. \"\n                    ) from e\n                raise\n        if response is None:\n            if _debug_enabled:\n                elapsed_ms = (perf_counter() - t0) * 1000\n                log.debug(\"perf: request_references path=%s elapsed_ms=%.2f count=0\", relative_file_path, elapsed_ms)\n            return []\n\n        ret: list[ls_types.Location] = []\n        assert isinstance(response, list), f\"Unexpected response from Language Server (expected list, got {type(response)}): {response}\"\n        for item in response:\n            assert isinstance(item, dict), f\"Unexpected response from Language Server (expected dict, got {type(item)}): {item}\"\n            assert LSPConstants.URI in item\n            assert LSPConstants.RANGE in item\n\n            abs_path = PathUtils.uri_to_path(item[LSPConstants.URI])  # type: ignore\n            if not Path(abs_path).is_relative_to(self.repository_root_path):\n                log.warning(\n                    \"Found a reference in a path outside the repository, probably the LS is parsing things in installed packages or in the standardlib! \"\n                    f\"Path: {abs_path}. This is a bug but we currently simply skip these references.\"\n                )\n                continue\n\n            rel_path = Path(abs_path).relative_to(self.repository_root_path)\n            if self.is_ignored_path(str(rel_path)):\n                log.debug(\"Ignoring reference in %s since it should be ignored\", rel_path)\n                continue\n\n            new_item: dict = {}\n            new_item.update(item)\n            new_item[\"absolutePath\"] = str(abs_path)\n            new_item[\"relativePath\"] = str(rel_path)\n            ret.append(ls_types.Location(**new_item))  # type: ignore\n\n        if _debug_enabled:\n            elapsed_ms = (perf_counter() - t0) * 1000\n            unique_files = len({r[\"relativePath\"] for r in ret})\n            log.debug(\n                \"perf: request_references path=%s elapsed_ms=%.2f count=%d unique_files=%d\",\n                relative_file_path,\n                elapsed_ms,\n                len(ret),\n                unique_files,\n            )\n\n        return ret\n\n    def request_text_document_diagnostics(self, relative_file_path: str) -> list[ls_types.Diagnostic]:\n        \"\"\"\n        Raise a [textDocument/diagnostic](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_diagnostic) request to the Language Server\n        to find diagnostics for the given file. Wait for the response and return the result.\n\n        :param relative_file_path: The relative path of the file to retrieve diagnostics for\n\n        :return: A list of diagnostics for the file\n        \"\"\"\n        if not self.server_started:\n            log.error(\"request_text_document_diagnostics called before Language Server started\")\n            raise SolidLSPException(\"Language Server not started\")\n\n        with self.open_file(relative_file_path):\n            response = self.server.send.text_document_diagnostic(\n                {\n                    LSPConstants.TEXT_DOCUMENT: {  # type: ignore\n                        LSPConstants.URI: pathlib.Path(str(PurePath(self.repository_root_path, relative_file_path))).as_uri()\n                    }\n                }\n            )\n\n        if response is None:\n            return []  # type: ignore\n\n        assert isinstance(response, dict), f\"Unexpected response from Language Server (expected list, got {type(response)}): {response}\"\n        ret: list[ls_types.Diagnostic] = []\n        for item in response[\"items\"]:  # type: ignore\n            new_item: ls_types.Diagnostic = {\n                \"uri\": pathlib.Path(str(PurePath(self.repository_root_path, relative_file_path))).as_uri(),\n                \"severity\": item[\"severity\"],\n                \"message\": item[\"message\"],\n                \"range\": item[\"range\"],\n                \"code\": item[\"code\"],  # type: ignore\n            }\n            ret.append(ls_types.Diagnostic(**new_item))\n\n        return ret\n\n    def retrieve_full_file_content(self, file_path: str) -> str:\n        \"\"\"\n        Retrieve the full content of the given file.\n        \"\"\"\n        if os.path.isabs(file_path):\n            file_path = os.path.relpath(file_path, self.repository_root_path)\n        with self.open_file(file_path) as file_data:\n            return file_data.contents\n\n    def retrieve_content_around_line(\n        self, relative_file_path: str, line: int, context_lines_before: int = 0, context_lines_after: int = 0\n    ) -> MatchedConsecutiveLines:\n        \"\"\"\n        Retrieve the content of the given file around the given line.\n\n        :param relative_file_path: The relative path of the file to retrieve the content from\n        :param line: The line number to retrieve the content around\n        :param context_lines_before: The number of lines to retrieve before the given line\n        :param context_lines_after: The number of lines to retrieve after the given line\n\n        :return MatchedConsecutiveLines: A container with the desired lines.\n        \"\"\"\n        with self.open_file(relative_file_path) as file_data:\n            file_contents = file_data.contents\n        return MatchedConsecutiveLines.from_file_contents(\n            file_contents,\n            line=line,\n            context_lines_before=context_lines_before,\n            context_lines_after=context_lines_after,\n            source_file_path=relative_file_path,\n        )\n\n    def request_completions(\n        self, relative_file_path: str, line: int, column: int, allow_incomplete: bool = False\n    ) -> list[ls_types.CompletionItem]:\n        \"\"\"\n        Raise a [textDocument/completion](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_completion) request to the Language Server\n        to find completions at the given line and column in the given file. Wait for the response and return the result.\n\n        :param relative_file_path: The relative path of the file that has the symbol for which completions should be looked up\n        :param line: The line number of the symbol\n        :param column: The column number of the symbol\n\n        :return: A list of completions\n        \"\"\"\n        with self.open_file(relative_file_path):\n            open_file_buffer = self.open_file_buffers[pathlib.Path(os.path.join(self.repository_root_path, relative_file_path)).as_uri()]\n            completion_params: LSPTypes.CompletionParams = {\n                \"position\": {\"line\": line, \"character\": column},\n                \"textDocument\": {\"uri\": open_file_buffer.uri},\n                \"context\": {\"triggerKind\": LSPTypes.CompletionTriggerKind.Invoked},\n            }\n            response: list[LSPTypes.CompletionItem] | LSPTypes.CompletionList | None = None\n\n            for _ in range(30):\n                response = self.server.send.completion(completion_params)\n                if isinstance(response, list):\n                    response = {\"items\": response, \"isIncomplete\": False}\n                if response is None or not response[\"isIncomplete\"]:  # type: ignore\n                    break\n\n            # TODO: Understand how to appropriately handle `isIncomplete`\n            if response is None or (response[\"isIncomplete\"] and not allow_incomplete):  # type: ignore\n                return []\n\n            if \"items\" in response:\n                response = response[\"items\"]  # type: ignore\n\n            response = cast(list[LSPTypes.CompletionItem], response)\n\n            # TODO: Handle the case when the completion is a keyword\n            items = [item for item in response if item[\"kind\"] != LSPTypes.CompletionItemKind.Keyword]\n\n            completions_list: list[ls_types.CompletionItem] = []\n\n            for item in items:\n                assert \"insertText\" in item or \"textEdit\" in item\n                assert \"kind\" in item\n                completion_item = {}\n                if \"detail\" in item:\n                    completion_item[\"detail\"] = item[\"detail\"]\n\n                if \"label\" in item:\n                    completion_item[\"completionText\"] = item[\"label\"]\n                    completion_item[\"kind\"] = item[\"kind\"]  # type: ignore\n                elif \"insertText\" in item:  # type: ignore\n                    completion_item[\"completionText\"] = item[\"insertText\"]\n                    completion_item[\"kind\"] = item[\"kind\"]\n                elif \"textEdit\" in item and \"newText\" in item[\"textEdit\"]:\n                    completion_item[\"completionText\"] = item[\"textEdit\"][\"newText\"]\n                    completion_item[\"kind\"] = item[\"kind\"]\n                elif \"textEdit\" in item and \"range\" in item[\"textEdit\"]:\n                    new_dot_lineno, new_dot_colno = (\n                        completion_params[\"position\"][\"line\"],\n                        completion_params[\"position\"][\"character\"],\n                    )\n                    assert all(\n                        (\n                            item[\"textEdit\"][\"range\"][\"start\"][\"line\"] == new_dot_lineno,\n                            item[\"textEdit\"][\"range\"][\"start\"][\"character\"] == new_dot_colno,\n                            item[\"textEdit\"][\"range\"][\"start\"][\"line\"] == item[\"textEdit\"][\"range\"][\"end\"][\"line\"],\n                            item[\"textEdit\"][\"range\"][\"start\"][\"character\"] == item[\"textEdit\"][\"range\"][\"end\"][\"character\"],\n                        )\n                    )\n\n                    completion_item[\"completionText\"] = item[\"textEdit\"][\"newText\"]\n                    completion_item[\"kind\"] = item[\"kind\"]\n                elif \"textEdit\" in item and \"insert\" in item[\"textEdit\"]:\n                    assert False\n                else:\n                    assert False\n\n                completion_item = ls_types.CompletionItem(**completion_item)  # type: ignore\n                completions_list.append(completion_item)\n\n            return [json.loads(json_repr) for json_repr in set(json.dumps(item, sort_keys=True) for item in completions_list)]\n\n    def _request_document_symbols(\n        self, relative_file_path: str, file_data: LSPFileBuffer | None\n    ) -> list[SymbolInformation] | list[DocumentSymbol] | None:\n        \"\"\"\n        Sends a [documentSymbol](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_documentSymbol)\n        request to the language server to find symbols in the given file - or returns a cached result if available.\n\n        :param relative_file_path: the relative path of the file that has the symbols.\n        :param file_data: the file data buffer, if already opened. If None, the file will be opened in this method.\n        :return: the list of root symbols in the file.\n        \"\"\"\n\n        def get_cached_raw_document_symbols(cache_key: str, fd: LSPFileBuffer) -> list[SymbolInformation] | list[DocumentSymbol] | None:\n            file_hash_and_result = self._raw_document_symbols_cache.get(cache_key)\n            if file_hash_and_result is None:\n                log.debug(\"No cache hit for raw document symbols in %s\", relative_file_path)\n                log.debug(\"perf: raw_document_symbols_cache MISS path=%s\", relative_file_path)\n                return None\n\n            file_hash, result = file_hash_and_result\n            if file_hash == fd.content_hash:\n                log.debug(\"Returning cached raw document symbols for %s\", relative_file_path)\n                log.debug(\"perf: raw_document_symbols_cache HIT path=%s\", relative_file_path)\n                return result\n\n            log.debug(\"Document content for %s has changed (raw symbol cache is not up-to-date)\", relative_file_path)\n            log.debug(\"perf: raw_document_symbols_cache STALE path=%s\", relative_file_path)\n            return None\n\n        def get_raw_document_symbols(fd: LSPFileBuffer) -> list[SymbolInformation] | list[DocumentSymbol] | None:\n            # check for cached result\n            cache_key = relative_file_path\n            response = get_cached_raw_document_symbols(cache_key, fd)\n            if response is not None:\n                return response\n\n            # no cached result, query language server\n            log.debug(f\"Requesting document symbols for {relative_file_path} from the Language Server\")\n            response = self.server.send.document_symbol(\n                {\"textDocument\": {\"uri\": pathlib.Path(os.path.join(self.repository_root_path, relative_file_path)).as_uri()}}\n            )\n\n            # update cache\n            self._raw_document_symbols_cache[cache_key] = (fd.content_hash, response)\n            self._raw_document_symbols_cache_is_modified = True\n\n            return response\n\n        with self._open_file_context(relative_file_path, file_buffer=file_data) as fd:\n            return get_raw_document_symbols(fd)\n\n    def request_document_symbols(self, relative_file_path: str, file_buffer: LSPFileBuffer | None = None) -> DocumentSymbols:\n        \"\"\"\n        Retrieves the collection of symbols in the given file\n\n        :param relative_file_path: The relative path of the file that has the symbols\n        :param file_buffer: an optional file buffer if the file is already opened.\n        :return: the collection of symbols in the file.\n            All contained symbols will have a location, children, and a parent attribute,\n            where the parent attribute is None for root symbols.\n            Note that this is slightly different from the call to request_full_symbol_tree,\n            where the parent attribute will be the file symbol which in turn may have a package symbol as parent.\n            If you need a symbol tree that contains file symbols as well, you should use `request_full_symbol_tree` instead.\n        \"\"\"\n        with self._open_file_context(relative_file_path, file_buffer, open_in_ls=False) as file_data:\n            # check if the desired result is cached\n            cache_key = relative_file_path\n            file_hash_and_result = self._document_symbols_cache.get(cache_key)\n            if file_hash_and_result is None:\n                log.debug(\"No cache hit for document symbols in %s\", relative_file_path)\n                log.debug(\"perf: document_symbols_cache MISS path=%s\", relative_file_path)\n            else:\n                file_hash, document_symbols = file_hash_and_result\n                if file_hash == file_data.content_hash:\n                    log.debug(\"Returning cached document symbols for %s\", relative_file_path)\n                    log.debug(\"perf: document_symbols_cache HIT path=%s\", relative_file_path)\n                    return document_symbols\n\n                log.debug(\"Cached document symbol content for %s has changed\", relative_file_path)\n                log.debug(\"perf: document_symbols_cache STALE path=%s\", relative_file_path)\n\n            # no cached result: request the root symbols from the language server\n            root_symbols = self._request_document_symbols(relative_file_path, file_data)\n\n            if root_symbols is None:\n                log.warning(\n                    f\"Received None response from the Language Server for document symbols in {relative_file_path}. \"\n                    f\"This means the language server can't understand this file (possibly due to syntax errors). It may also be due to a bug or misconfiguration of the LS. \"\n                    f\"Returning empty list\",\n                )\n                return DocumentSymbols([])\n\n            assert isinstance(root_symbols, list), f\"Unexpected response from Language Server: {root_symbols}\"\n            log.debug(\"Received %d root symbols for %s from the language server\", len(root_symbols), relative_file_path)\n\n            body_factory = SymbolBodyFactory(file_data)\n\n            def convert_to_unified_symbol(original_symbol_dict: GenericDocumentSymbol) -> ls_types.UnifiedSymbolInformation:\n                \"\"\"\n                Converts the given symbol dictionary to the unified representation, ensuring\n                that all required fields are present (except 'children' which is handled separately).\n\n                :param original_symbol_dict: the item to augment\n                :return: the augmented item (new object)\n                \"\"\"\n                # noinspection PyInvalidCast\n                item = cast(ls_types.UnifiedSymbolInformation, dict(original_symbol_dict))\n                absolute_path = os.path.join(self.repository_root_path, relative_file_path)\n\n                # handle missing location and path entries\n                if \"location\" not in item:\n                    uri = pathlib.Path(absolute_path).as_uri()\n                    assert \"range\" in item\n                    tree_location = ls_types.Location(\n                        uri=uri,\n                        range=item[\"range\"],\n                        absolutePath=absolute_path,\n                        relativePath=relative_file_path,\n                    )\n                    item[\"location\"] = tree_location\n                location = item[\"location\"]\n                if \"absolutePath\" not in location:\n                    location[\"absolutePath\"] = absolute_path  # type: ignore\n                if \"relativePath\" not in location:\n                    location[\"relativePath\"] = relative_file_path  # type: ignore\n\n                item[\"body\"] = self.create_symbol_body(item, factory=body_factory)\n\n                # handle missing selectionRange\n                if \"selectionRange\" not in item:\n                    if \"range\" in item:\n                        item[\"selectionRange\"] = item[\"range\"]\n                    else:\n                        item[\"selectionRange\"] = item[\"location\"][\"range\"]\n\n                return item\n\n            def convert_symbols_with_common_parent(\n                symbols: list[DocumentSymbol] | list[SymbolInformation] | list[UnifiedSymbolInformation],\n                parent: ls_types.UnifiedSymbolInformation | None,\n            ) -> list[ls_types.UnifiedSymbolInformation]:\n                \"\"\"\n                Converts the given symbols into UnifiedSymbolInformation with proper parent-child relationships,\n                adding overload indices for symbols with the same name under the same parent.\n                \"\"\"\n                total_name_counts: dict[str, int] = defaultdict(lambda: 0)\n                for symbol in symbols:\n                    total_name_counts[symbol[\"name\"]] += 1\n                name_counts: dict[str, int] = defaultdict(lambda: 0)\n                unified_symbols = []\n                for symbol in symbols:\n                    usymbol = convert_to_unified_symbol(symbol)\n                    if total_name_counts[usymbol[\"name\"]] > 1:\n                        usymbol[\"overload_idx\"] = name_counts[usymbol[\"name\"]]\n                    name_counts[usymbol[\"name\"]] += 1\n                    usymbol[\"parent\"] = parent\n                    if \"children\" in usymbol:\n                        usymbol[\"children\"] = convert_symbols_with_common_parent(usymbol[\"children\"], usymbol)  # type: ignore\n                    else:\n                        usymbol[\"children\"] = []  # type: ignore\n                    unified_symbols.append(usymbol)\n                return unified_symbols\n\n            unified_root_symbols = convert_symbols_with_common_parent(root_symbols, None)\n            document_symbols = DocumentSymbols(unified_root_symbols)\n\n            # update cache\n            log.debug(\"Updating cached document symbols for %s\", relative_file_path)\n            self._document_symbols_cache[cache_key] = (file_data.content_hash, document_symbols)\n            self._document_symbols_cache_is_modified = True\n\n            return document_symbols\n\n    def request_full_symbol_tree(self, within_relative_path: str | None = None) -> list[ls_types.UnifiedSymbolInformation]:\n        \"\"\"\n        Will go through all files in the project or within a relative path and build a tree of symbols.\n        Note: this may be slow the first time it is called, especially if `within_relative_path` is not used to restrict the search.\n\n        For each file, a symbol of kind File (2) will be created. For directories, a symbol of kind Package (4) will be created.\n        All symbols will have a children attribute, thereby representing the tree structure of all symbols in the project\n        that are within the repository.\n        All symbols except the root packages will have a parent attribute.\n        Will ignore directories starting with '.', language-specific defaults\n        and user-configured directories (e.g. from .gitignore).\n\n        :param within_relative_path: pass a relative path to only consider symbols within this path.\n            If a file is passed, only the symbols within this file will be considered.\n            If a directory is passed, all files within this directory will be considered.\n        :return: A list of root symbols representing the top-level packages/modules in the project.\n        \"\"\"\n        if within_relative_path is not None:\n            within_abs_path = os.path.join(self.repository_root_path, within_relative_path)\n            if not os.path.exists(within_abs_path):\n                raise FileNotFoundError(f\"File or directory not found: {within_abs_path}\")\n            if os.path.isfile(within_abs_path):\n                if self.is_ignored_path(within_relative_path):\n                    log.error(\"You passed a file explicitly, but it is ignored. This is probably an error. File: %s\", within_relative_path)\n                    return []\n                else:\n                    root_nodes = self.request_document_symbols(within_relative_path).root_symbols\n                    return root_nodes\n\n        # Helper function to recursively process directories\n        def process_directory(rel_dir_path: str) -> list[ls_types.UnifiedSymbolInformation]:\n            abs_dir_path = self.repository_root_path if rel_dir_path == \".\" else os.path.join(self.repository_root_path, rel_dir_path)\n            abs_dir_path = os.path.realpath(abs_dir_path)\n\n            if self.is_ignored_path(str(Path(abs_dir_path).relative_to(self.repository_root_path))):\n                log.debug(\"Skipping directory: %s (because it should be ignored)\", rel_dir_path)\n                return []\n\n            result = []\n            try:\n                contained_dir_or_file_names = os.listdir(abs_dir_path)\n            except OSError:\n                return []\n\n            # Create package symbol for directory\n            package_symbol = ls_types.UnifiedSymbolInformation(  # type: ignore\n                name=os.path.basename(abs_dir_path),\n                kind=ls_types.SymbolKind.Package,\n                location=ls_types.Location(\n                    uri=str(pathlib.Path(abs_dir_path).as_uri()),\n                    range={\"start\": {\"line\": 0, \"character\": 0}, \"end\": {\"line\": 0, \"character\": 0}},\n                    absolutePath=str(abs_dir_path),\n                    relativePath=str(Path(abs_dir_path).resolve().relative_to(self.repository_root_path)),\n                ),\n                children=[],\n            )\n            result.append(package_symbol)\n\n            for contained_dir_or_file_name in contained_dir_or_file_names:\n                contained_dir_or_file_abs_path = os.path.join(abs_dir_path, contained_dir_or_file_name)\n\n                # obtain relative path\n                try:\n                    contained_dir_or_file_rel_path = str(\n                        Path(contained_dir_or_file_abs_path).resolve().relative_to(self.repository_root_path)\n                    )\n                except ValueError as e:\n                    # Typically happens when the path is not under the repository root (e.g., symlink pointing outside)\n                    log.warning(\n                        \"Skipping path %s; likely outside of the repository root %s [cause: %s]\",\n                        contained_dir_or_file_abs_path,\n                        self.repository_root_path,\n                        e,\n                    )\n                    continue\n\n                if self.is_ignored_path(contained_dir_or_file_rel_path):\n                    log.debug(\"Skipping item: %s (because it should be ignored)\", contained_dir_or_file_rel_path)\n                    continue\n\n                if os.path.isdir(contained_dir_or_file_abs_path):\n                    child_symbols = process_directory(contained_dir_or_file_rel_path)\n                    package_symbol[\"children\"].extend(child_symbols)\n                    for child in child_symbols:\n                        child[\"parent\"] = package_symbol\n\n                elif os.path.isfile(contained_dir_or_file_abs_path):\n                    with self._open_file_context(contained_dir_or_file_rel_path, open_in_ls=False) as file_data:\n                        document_symbols = self.request_document_symbols(contained_dir_or_file_rel_path, file_data)\n                        file_root_nodes = document_symbols.root_symbols\n\n                        # Create file symbol, link with children\n                        file_range = self._get_range_from_file_content(file_data.contents)\n                        file_symbol = ls_types.UnifiedSymbolInformation(  # type: ignore\n                            name=os.path.splitext(contained_dir_or_file_name)[0],\n                            kind=ls_types.SymbolKind.File,\n                            range=file_range,\n                            selectionRange=file_range,\n                            location=ls_types.Location(\n                                uri=str(pathlib.Path(contained_dir_or_file_abs_path).as_uri()),\n                                range=file_range,\n                                absolutePath=str(contained_dir_or_file_abs_path),\n                                relativePath=str(Path(contained_dir_or_file_abs_path).resolve().relative_to(self.repository_root_path)),\n                            ),\n                            children=file_root_nodes,\n                            parent=package_symbol,\n                        )\n                        for child in file_root_nodes:\n                            child[\"parent\"] = file_symbol\n\n                    # Link file symbol with package\n                    package_symbol[\"children\"].append(file_symbol)\n\n                    # TODO: Not sure if this is actually still needed given recent changes to relative path handling\n                    def fix_relative_path(nodes: list[ls_types.UnifiedSymbolInformation]) -> None:\n                        for node in nodes:\n                            if \"location\" in node and \"relativePath\" in node[\"location\"]:\n                                path = Path(node[\"location\"][\"relativePath\"])  # type: ignore\n                                if path.is_absolute():\n                                    try:\n                                        path = path.relative_to(self.repository_root_path)\n                                        node[\"location\"][\"relativePath\"] = str(path)\n                                    except Exception:\n                                        pass\n                            if \"children\" in node:\n                                fix_relative_path(node[\"children\"])\n\n                    fix_relative_path(file_root_nodes)\n\n            return result\n\n        # Start from the root or the specified directory\n        start_rel_path = within_relative_path or \".\"\n        return process_directory(start_rel_path)\n\n    @staticmethod\n    def _get_range_from_file_content(file_content: str) -> ls_types.Range:\n        \"\"\"\n        Get the range for the given file.\n        \"\"\"\n        lines = file_content.split(\"\\n\")\n        end_line = len(lines)\n        end_column = len(lines[-1])\n        return ls_types.Range(start=ls_types.Position(line=0, character=0), end=ls_types.Position(line=end_line, character=end_column))\n\n    def request_dir_overview(self, relative_dir_path: str) -> dict[str, list[UnifiedSymbolInformation]]:\n        \"\"\"\n        :return: A mapping of all relative paths analyzed to lists of top-level symbols in the corresponding file.\n        \"\"\"\n        symbol_tree = self.request_full_symbol_tree(relative_dir_path)\n        # Initialize result dictionary\n        result: dict[str, list[UnifiedSymbolInformation]] = defaultdict(list)\n\n        # Helper function to process a symbol and its children\n        def process_symbol(symbol: ls_types.UnifiedSymbolInformation) -> None:\n            if symbol[\"kind\"] == ls_types.SymbolKind.File:\n                # For file symbols, process their children (top-level symbols)\n                for child in symbol[\"children\"]:\n                    # Handle cross-platform path resolution (fixes Docker/macOS path issues)\n                    absolute_path = Path(child[\"location\"][\"absolutePath\"]).resolve()\n                    repository_root = Path(self.repository_root_path).resolve()\n\n                    # Try pathlib first, fallback to alternative approach if paths are incompatible\n                    try:\n                        path = absolute_path.relative_to(repository_root)\n                    except ValueError:\n                        # If paths are from different roots (e.g., /workspaces vs /Users),\n                        # use the relativePath from location if available, or extract from absolutePath\n                        if \"relativePath\" in child[\"location\"] and child[\"location\"][\"relativePath\"]:\n                            path = Path(child[\"location\"][\"relativePath\"])\n                        else:\n                            # Extract relative path by finding common structure\n                            # Example: /workspaces/.../test_repo/file.py -> test_repo/file.py\n                            path_parts = absolute_path.parts\n\n                            # Find the last common part or use a fallback\n                            if \"test_repo\" in path_parts:\n                                test_repo_idx = path_parts.index(\"test_repo\")\n                                path = Path(*path_parts[test_repo_idx:])\n                            else:\n                                # Last resort: use filename only\n                                path = Path(absolute_path.name)\n                    result[str(path)].append(child)\n            # For package/directory symbols, process their children\n            for child in symbol[\"children\"]:\n                process_symbol(child)\n\n        # Process each root symbol\n        for root in symbol_tree:\n            process_symbol(root)\n        return result\n\n    def request_document_overview(self, relative_file_path: str) -> list[UnifiedSymbolInformation]:\n        \"\"\"\n        :return: the top-level symbols in the given file.\n        \"\"\"\n        return self.request_document_symbols(relative_file_path).root_symbols\n\n    def request_overview(self, within_relative_path: str) -> dict[str, list[UnifiedSymbolInformation]]:\n        \"\"\"\n        An overview of all symbols in the given file or directory.\n\n        :param within_relative_path: the relative path to the file or directory to get the overview of.\n        :return: A mapping of all relative paths analyzed to lists of top-level symbols in the corresponding file.\n        \"\"\"\n        abs_path = (Path(self.repository_root_path) / within_relative_path).resolve()\n        if not abs_path.exists():\n            raise FileNotFoundError(f\"File or directory not found: {abs_path}\")\n\n        if abs_path.is_file():\n            symbols_overview = self.request_document_overview(within_relative_path)\n            return {within_relative_path: symbols_overview}\n        else:\n            return self.request_dir_overview(within_relative_path)\n\n    def request_hover(\n        self, relative_file_path: str, line: int, column: int, file_buffer: LSPFileBuffer | None = None\n    ) -> ls_types.Hover | None:\n        \"\"\"\n        Raise a [textDocument/hover](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_hover) request to the Language Server\n        to find the hover information at the given line and column in the given file. Wait for the response and return the result.\n\n        :param relative_file_path: The relative path of the file that has the hover information\n        :param line: The line number of the symbol\n        :param column: The column number of the symbol\n        :param file_buffer: The file buffer to use for the request. If not provided, the file will be read from disk.\n            Can be used for optimizing number of file reads in downstream code\n        \"\"\"\n        with self._open_file_context(relative_file_path, file_buffer=file_buffer) as fb:\n            return self._request_hover(fb, line, column)\n\n    def _request_hover(self, file_buffer: LSPFileBuffer, line: int, column: int) -> ls_types.Hover | None:\n        \"\"\"\n        Performs the actual hover request.\n        \"\"\"\n        response = self.server.send.hover(\n            {\n                \"textDocument\": {\"uri\": file_buffer.uri},\n                \"position\": {\n                    \"line\": line,\n                    \"character\": column,\n                },\n            }\n        )\n\n        if response is None:\n            return None\n\n        assert isinstance(response, dict)\n        contents = response.get(\"contents\")\n        if not contents:\n            return None\n        if isinstance(contents, dict) and not contents.get(\"value\"):\n            return None\n        return ls_types.Hover(**response)  # type: ignore\n\n    def request_signature_help(self, relative_file_path: str, line: int, column: int) -> ls_types.SignatureHelp | None:\n        \"\"\"\n        Raise a [textDocument/signatureHelp](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_signatureHelp)\n        request to the Language Server to find the signature help at the given line and column in the given file.\n        Note: contrary to `hover`, this only returns something on the position of a *call* and not on a symbol definition.\n        This means for Serena's purposes, this method is not particularly useful. The result is also fairly verbose (but well structured).\n\n        :param relative_file_path: The relative path of the file that has the signature help\n        :param line: The line number of the symbol\n        :param column: The column number of the symbol\n\n        :return None\n        \"\"\"\n        with self.open_file(relative_file_path):\n            response = self.server.send.signature_help(\n                {\n                    \"textDocument\": {\"uri\": pathlib.Path(os.path.join(self.repository_root_path, relative_file_path)).as_uri()},\n                    \"position\": {\n                        \"line\": line,\n                        \"character\": column,\n                    },\n                }\n            )\n\n        if response is None:\n            return None\n\n        assert isinstance(response, dict)\n\n        return ls_types.SignatureHelp(**response)  # type: ignore\n\n    def create_symbol_body(\n        self,\n        symbol: ls_types.UnifiedSymbolInformation | LSPTypes.SymbolInformation,\n        factory: SymbolBodyFactory | None = None,\n    ) -> SymbolBody:\n        if factory is None:\n            assert \"relativePath\" in symbol[\"location\"]\n            with self._open_file_context(symbol[\"location\"][\"relativePath\"]) as f:  # type: ignore\n                factory = SymbolBodyFactory(f)\n\n        return factory.create_symbol_body(symbol)\n\n    def request_referencing_symbols(\n        self,\n        relative_file_path: str,\n        line: int,\n        column: int,\n        include_imports: bool = True,\n        include_self: bool = False,\n        include_body: bool = False,\n        include_file_symbols: bool = False,\n    ) -> list[ReferenceInSymbol]:\n        \"\"\"\n        Finds all symbols that reference the symbol at the given location.\n        This is similar to request_references but filters to only include symbols\n        (functions, methods, classes, etc.) that reference the target symbol.\n\n        :param relative_file_path: The relative path to the file.\n        :param line: The 0-indexed line number.\n        :param column: The 0-indexed column number.\n        :param include_imports: whether to also include imports as references.\n            Unfortunately, the LSP does not have an import type, so the references corresponding to imports\n            will not be easily distinguishable from definitions.\n        :param include_self: whether to include the references that is the \"input symbol\" itself.\n            Only has an effect if the relative_file_path, line and column point to a symbol, for example a definition.\n        :param include_body: whether to include the body of the symbols in the result.\n        :param include_file_symbols: whether to include references that are file symbols. This\n            is often a fallback mechanism for when the reference cannot be resolved to a symbol.\n        :return: List of objects containing the symbol and the location of the reference.\n        \"\"\"\n        if not self.server_started:\n            log.error(\"request_referencing_symbols called before Language Server started\")\n            raise SolidLSPException(\"Language Server not started\")\n\n        # First, get all references to the symbol\n        references = self.request_references(relative_file_path, line, column)\n        if not references:\n            return []\n\n        debug_enabled = log.isEnabledFor(logging.DEBUG)\n        t0_loop = perf_counter() if debug_enabled else 0.0\n        # For each reference, find the containing symbol\n        result = []\n        incoming_symbol = None\n        for ref in references:\n            ref_path = ref[\"relativePath\"]\n            assert ref_path is not None\n            ref_line = ref[\"range\"][\"start\"][\"line\"]\n            ref_col = ref[\"range\"][\"start\"][\"character\"]\n\n            with self.open_file(ref_path) as file_data:\n                body_factory = SymbolBodyFactory(file_data)\n\n                # Get the containing symbol for this reference\n                containing_symbol = self.request_containing_symbol(\n                    ref_path, ref_line, ref_col, include_body=include_body, body_factory=body_factory\n                )\n                if containing_symbol is None:\n                    # TODO: HORRIBLE HACK! I don't know how to do it better for now...\n                    # THIS IS BOUND TO BREAK IN MANY CASES! IT IS ALSO SPECIFIC TO PYTHON!\n                    # Background:\n                    # When a variable is used to change something, like\n                    #\n                    # instance = MyClass()\n                    # instance.status = \"new status\"\n                    #\n                    # we can't find the containing symbol for the reference to `status`\n                    # since there is no container on the line of the reference\n                    # The hack is to try to find a variable symbol in the containing module\n                    # by using the text of the reference to find the variable name (In a very heuristic way)\n                    # and then look for a symbol with that name and kind Variable\n                    ref_text = file_data.contents.split(\"\\n\")[ref_line]\n                    if \".\" in ref_text:\n                        containing_symbol_name = ref_text.split(\".\")[0]\n                        document_symbols = self.request_document_symbols(ref_path)\n                        for symbol in document_symbols.iter_symbols():\n                            if symbol[\"name\"] == containing_symbol_name and symbol[\"kind\"] == ls_types.SymbolKind.Variable:\n                                containing_symbol = copy(symbol)\n                                containing_symbol[\"location\"] = ref\n                                containing_symbol[\"range\"] = ref[\"range\"]\n                                break\n\n                # We failed retrieving the symbol, falling back to creating a file symbol\n                if containing_symbol is None and include_file_symbols:\n                    log.warning(f\"Could not find containing symbol for {ref_path}:{ref_line}:{ref_col}. Returning file symbol instead\")\n                    fileRange = self._get_range_from_file_content(file_data.contents)\n                    location = ls_types.Location(\n                        uri=str(pathlib.Path(os.path.join(self.repository_root_path, ref_path)).as_uri()),\n                        range=fileRange,\n                        absolutePath=str(os.path.join(self.repository_root_path, ref_path)),\n                        relativePath=ref_path,\n                    )\n                    name = os.path.splitext(os.path.basename(ref_path))[0]\n\n                    containing_symbol = ls_types.UnifiedSymbolInformation(\n                        kind=ls_types.SymbolKind.File,\n                        range=fileRange,\n                        selectionRange=fileRange,\n                        location=location,\n                        name=name,\n                        children=[],\n                    )\n\n                    if include_body:\n                        containing_symbol[\"body\"] = self.create_symbol_body(containing_symbol, factory=body_factory)\n\n                if containing_symbol is None or (not include_file_symbols and containing_symbol[\"kind\"] == ls_types.SymbolKind.File):\n                    continue\n\n                assert \"location\" in containing_symbol\n                assert \"selectionRange\" in containing_symbol\n\n                # Checking for self-reference\n                if (\n                    containing_symbol[\"location\"][\"relativePath\"] == relative_file_path\n                    and containing_symbol[\"selectionRange\"][\"start\"][\"line\"] == ref_line\n                    and containing_symbol[\"selectionRange\"][\"start\"][\"character\"] == ref_col\n                ):\n                    incoming_symbol = containing_symbol\n                    if include_self:\n                        result.append(ReferenceInSymbol(symbol=containing_symbol, line=ref_line, character=ref_col))\n                        continue\n                    log.debug(f\"Found self-reference for {incoming_symbol['name']}, skipping it since {include_self=}\")\n                    continue\n\n                # checking whether reference is an import\n                # This is neither really safe nor elegant, but if we don't do it,\n                # there is no way to distinguish between definitions and imports as import is not a symbol-type\n                # and we get the type referenced symbol resulting from imports...\n                if (\n                    not include_imports\n                    and incoming_symbol is not None\n                    and containing_symbol[\"name\"] == incoming_symbol[\"name\"]\n                    and containing_symbol[\"kind\"] == incoming_symbol[\"kind\"]\n                ):\n                    log.debug(\n                        f\"Found import of referenced symbol {incoming_symbol['name']}\"\n                        f\"in {containing_symbol['location']['relativePath']}, skipping\"\n                    )\n                    continue\n\n                result.append(ReferenceInSymbol(symbol=containing_symbol, line=ref_line, character=ref_col))\n\n        if debug_enabled:\n            loop_elapsed_ms = (perf_counter() - t0_loop) * 1000\n            unique_files = len({r.symbol[\"location\"][\"relativePath\"] for r in result})\n            log.debug(\n                \"perf: request_referencing_symbols path=%s loop_elapsed_ms=%.2f ref_count=%d result_count=%d unique_files=%d\",\n                relative_file_path,\n                loop_elapsed_ms,\n                len(references),\n                len(result),\n                unique_files,\n            )\n\n        return result\n\n    def request_containing_symbol(\n        self,\n        relative_file_path: str,\n        line: int,\n        column: int | None = None,\n        strict: bool = False,\n        include_body: bool = False,\n        body_factory: SymbolBodyFactory | None = None,\n    ) -> ls_types.UnifiedSymbolInformation | None:\n        \"\"\"\n        Finds the first symbol containing the position for the given file.\n        For Python, container symbols are considered to be those with kinds corresponding to\n        functions, methods, or classes (typically: Function (12), Method (6), Class (5)).\n\n        The method operates as follows:\n          - Request the document symbols for the file.\n          - Filter symbols to those that start at or before the given line.\n          - From these, first look for symbols whose range contains the (line, column).\n          - If one or more symbols contain the position, return the one with the greatest starting position\n            (i.e. the innermost container).\n          - If none (strictly) contain the position, return the symbol with the greatest starting position\n            among those above the given line.\n          - If no container candidates are found, return None.\n\n        :param relative_file_path: The relative path to the Python file.\n        :param line: The 0-indexed line number.\n        :param column: The 0-indexed column (also called character). If not passed, the lookup will be based\n            only on the line.\n        :param strict: If True, the position must be strictly within the range of the symbol.\n            Setting to True is useful for example for finding the parent of a symbol, as with strict=False,\n            and the line pointing to a symbol itself, the containing symbol will be the symbol itself\n            (and not the parent).\n        :param include_body: Whether to include the body of the symbol in the result.\n        :return: The container symbol (if found) or None.\n        \"\"\"\n        # checking if the line is empty, unfortunately ugly and duplicating code, but I don't want to refactor\n        with self.open_file(relative_file_path):\n            absolute_file_path = str(PurePath(self.repository_root_path, relative_file_path))\n            content = FileUtils.read_file(absolute_file_path, self._encoding)\n            if content.split(\"\\n\")[line].strip() == \"\":\n                log.error(f\"Passing empty lines to request_container_symbol is currently not supported, {relative_file_path=}, {line=}\")\n                return None\n\n        document_symbols = self.request_document_symbols(relative_file_path)\n\n        # make jedi and pyright api compatible\n        # the former has no location, the later has no range\n        # we will just always add location of the desired format to all symbols\n        for symbol in document_symbols.iter_symbols():\n            if \"location\" not in symbol:\n                range = symbol[\"range\"]\n                location = ls_types.Location(\n                    uri=f\"file:/{absolute_file_path}\",\n                    range=range,\n                    absolutePath=absolute_file_path,\n                    relativePath=relative_file_path,\n                )\n                symbol[\"location\"] = location\n            else:\n                location = symbol[\"location\"]\n                assert \"range\" in location\n                location[\"absolutePath\"] = absolute_file_path\n                location[\"relativePath\"] = relative_file_path\n                location[\"uri\"] = Path(absolute_file_path).as_uri()\n\n        # Allowed container kinds, currently only for Python\n        container_symbol_kinds = {ls_types.SymbolKind.Method, ls_types.SymbolKind.Function, ls_types.SymbolKind.Class}\n\n        def is_position_in_range(line: int, range_d: ls_types.Range) -> bool:\n            start = range_d[\"start\"]\n            end = range_d[\"end\"]\n\n            column_condition = True\n            if strict:\n                line_condition = end[\"line\"] >= line > start[\"line\"]\n                if column is not None and line == start[\"line\"]:\n                    column_condition = column > start[\"character\"]\n            else:\n                line_condition = end[\"line\"] >= line >= start[\"line\"]\n                if column is not None and line == start[\"line\"]:\n                    column_condition = column >= start[\"character\"]\n            return line_condition and column_condition\n\n        # Only consider containers that are not one-liners (otherwise we may get imports)\n        candidate_containers = [\n            s\n            for s in document_symbols.iter_symbols()\n            if s[\"kind\"] in container_symbol_kinds and s[\"location\"][\"range\"][\"start\"][\"line\"] != s[\"location\"][\"range\"][\"end\"][\"line\"]\n        ]\n        var_containers = [s for s in document_symbols.iter_symbols() if s[\"kind\"] == ls_types.SymbolKind.Variable]\n        candidate_containers.extend(var_containers)\n\n        if not candidate_containers:\n            return None\n\n        # From the candidates, find those whose range contains the given position.\n        containing_symbols = []\n        for symbol in candidate_containers:\n            s_range = symbol[\"location\"][\"range\"]\n            if not is_position_in_range(line, s_range):\n                continue\n            containing_symbols.append(symbol)\n\n        if containing_symbols:\n            # Return the one with the greatest starting position (i.e. the innermost container).\n            containing_symbol = max(containing_symbols, key=lambda s: s[\"location\"][\"range\"][\"start\"][\"line\"])\n            if include_body:\n                containing_symbol[\"body\"] = self.create_symbol_body(containing_symbol, factory=body_factory)\n            return containing_symbol\n        else:\n            return None\n\n    def request_container_of_symbol(\n        self, symbol: ls_types.UnifiedSymbolInformation, include_body: bool = False\n    ) -> ls_types.UnifiedSymbolInformation | None:\n        \"\"\"\n        Finds the container of the given symbol if there is one. If the parent attribute is present, the parent is returned\n        without further searching.\n\n        :param symbol: The symbol to find the container of.\n        :param include_body: whether to include the body of the symbol in the result.\n        :return: The container of the given symbol or None if no container is found.\n        \"\"\"\n        if \"parent\" in symbol:\n            return symbol[\"parent\"]\n        assert \"location\" in symbol, f\"Symbol {symbol} has no location and no parent attribute\"\n        return self.request_containing_symbol(\n            symbol[\"location\"][\"relativePath\"],  # type: ignore\n            symbol[\"location\"][\"range\"][\"start\"][\"line\"],\n            symbol[\"location\"][\"range\"][\"start\"][\"character\"],\n            strict=True,\n            include_body=include_body,\n        )\n\n    def _get_preferred_definition(self, definitions: list[ls_types.Location]) -> ls_types.Location:\n        \"\"\"\n        Select the preferred definition from a list of definitions.\n\n        When multiple definitions are returned (e.g., both source and type definitions),\n        this method determines which one to use. The base implementation simply returns\n        the first definition.\n\n        Subclasses can override this method to implement language-specific preferences.\n        For example, TypeScript/Vue servers may prefer source files over .d.ts type\n        definition files.\n\n        :param definitions: A non-empty list of definition locations.\n        :return: The preferred definition location.\n        \"\"\"\n        return definitions[0]\n\n    def request_defining_symbol(\n        self,\n        relative_file_path: str,\n        line: int,\n        column: int,\n        include_body: bool = False,\n    ) -> ls_types.UnifiedSymbolInformation | None:\n        \"\"\"\n        Finds the symbol that defines the symbol at the given location.\n\n        This method first finds the definition of the symbol at the given position,\n        then retrieves the full symbol information for that definition.\n\n        :param relative_file_path: The relative path to the file.\n        :param line: The 0-indexed line number.\n        :param column: The 0-indexed column number.\n        :param include_body: whether to include the body of the symbol in the result.\n        :return: The symbol information for the definition, or None if not found.\n        \"\"\"\n        if not self.server_started:\n            log.error(\"request_defining_symbol called before language server started\")\n            raise SolidLSPException(\"Language Server not started\")\n\n        # Get the definition location(s)\n        definitions = self.request_definition(relative_file_path, line, column)\n        if not definitions:\n            return None\n\n        # Select the preferred definition (subclasses can override _get_preferred_definition)\n        definition = self._get_preferred_definition(definitions)\n        def_path = definition[\"relativePath\"]\n        assert def_path is not None\n        def_line = definition[\"range\"][\"start\"][\"line\"]\n        def_col = definition[\"range\"][\"start\"][\"character\"]\n\n        # Find the symbol at or containing this location\n        defining_symbol = self.request_containing_symbol(def_path, def_line, def_col, strict=False, include_body=include_body)\n\n        return defining_symbol\n\n    def _document_symbols_cache_fingerprint(self) -> Hashable | None:\n        \"\"\"\n        Returns a fingerprint of any language server-specific aspects that result in changes\n        to the high-level document symbol information.\n\n        Language servers must implement this method/change the return value\n          * whenever they change the `request_document_symbols` implementation to modify the returned content\n          * are reconfigured in a way that affects the returned contents (e.g. context-specific configuration\n            such as build flags or environment variables); configuration options can, in such cases, be\n            hashed together to produce a single fingerprint value.\n\n        Whenever the value changes, the document symbols cache will be invalidated and re-populated.\n\n        The value must be hashable and safe for inclusion in cache version tuples.\n        E.g. use an integer, a string or a tuple of integers/strings.\n\n        Returns None if no context-specific fingerprint is needed.\n        \"\"\"\n        return None\n\n    def _document_symbols_cache_version(self) -> Hashable:\n        \"\"\"\n        Return the version for the document symbols cache.\n\n        Incorporates cache context fingerprint if provided by the language server.\n        \"\"\"\n        fingerprint = self._document_symbols_cache_fingerprint()\n        if fingerprint is not None:\n            return (self.DOCUMENT_SYMBOL_CACHE_VERSION, fingerprint)\n        return self.DOCUMENT_SYMBOL_CACHE_VERSION\n\n    def _save_raw_document_symbols_cache(self) -> None:\n        cache_file = self.cache_dir / self.RAW_DOCUMENT_SYMBOL_CACHE_FILENAME\n\n        if not self._raw_document_symbols_cache_is_modified:\n            log.debug(\"No changes to raw document symbols cache, skipping save\")\n            return\n\n        log.info(\"Saving updated raw document symbols cache to %s\", cache_file)\n        try:\n            save_cache(str(cache_file), self._raw_document_symbols_cache_version(), self._raw_document_symbols_cache)\n            self._raw_document_symbols_cache_is_modified = False\n        except Exception as e:\n            log.error(\n                \"Failed to save raw document symbols cache to %s: %s. Note: this may have resulted in a corrupted cache file.\",\n                cache_file,\n                e,\n            )\n\n    def _raw_document_symbols_cache_version(self) -> tuple[Hashable, ...]:\n        base_version: tuple[Hashable, ...] = (self.RAW_DOCUMENT_SYMBOLS_CACHE_VERSION, self._ls_specific_raw_document_symbols_cache_version)\n        fingerprint = self._document_symbols_cache_fingerprint()\n        if fingerprint is not None:\n            return (*base_version, fingerprint)\n        return base_version\n\n    def _load_raw_document_symbols_cache(self) -> None:\n        cache_file = self.cache_dir / self.RAW_DOCUMENT_SYMBOL_CACHE_FILENAME\n\n        if not cache_file.exists():\n            # check for legacy cache to load to migrate\n            legacy_cache_file = self.cache_dir / self.RAW_DOCUMENT_SYMBOL_CACHE_FILENAME_LEGACY_FALLBACK\n            if legacy_cache_file.exists():\n                try:\n                    legacy_cache: dict[\n                        str, tuple[str, tuple[list[ls_types.UnifiedSymbolInformation], list[ls_types.UnifiedSymbolInformation]]]\n                    ] = load_pickle(legacy_cache_file)\n                    log.info(\"Migrating legacy document symbols cache with %d entries\", len(legacy_cache))\n                    num_symbols_migrated = 0\n                    migrated_cache = {}\n                    for cache_key, (file_hash, (all_symbols, root_symbols)) in legacy_cache.items():\n                        if cache_key.endswith(\"-True\"):  # include_body=True\n                            new_cache_key = cache_key[:-5]\n                            migrated_cache[new_cache_key] = (file_hash, root_symbols)\n                            num_symbols_migrated += len(all_symbols)\n                    log.info(\"Migrated %d document symbols from legacy cache\", num_symbols_migrated)\n                    self._raw_document_symbols_cache = migrated_cache  # type: ignore\n                    self._raw_document_symbols_cache_is_modified = True\n                    self._save_raw_document_symbols_cache()\n                    legacy_cache_file.unlink()\n                    return\n                except Exception as e:\n                    log.error(\"Error during cache migration: %s\", e)\n                    return\n\n        # load existing cache (if any)\n        if cache_file.exists():\n            log.info(\"Loading document symbols cache from %s\", cache_file)\n            try:\n                saved_cache = load_cache(str(cache_file), self._raw_document_symbols_cache_version())\n                if saved_cache is not None:\n                    self._raw_document_symbols_cache = saved_cache\n                    log.info(f\"Loaded {len(self._raw_document_symbols_cache)} entries from raw document symbols cache.\")\n            except Exception as e:\n                # cache can become corrupt, so just skip loading it\n                log.warning(\n                    \"Failed to load raw document symbols cache from %s (%s); Ignoring cache.\",\n                    cache_file,\n                    e,\n                )\n\n    def _save_document_symbols_cache(self) -> None:\n        cache_file = self.cache_dir / self.DOCUMENT_SYMBOL_CACHE_FILENAME\n\n        if not self._document_symbols_cache_is_modified:\n            log.debug(\"No changes to document symbols cache, skipping save\")\n            return\n\n        log.info(\"Saving updated document symbols cache to %s\", cache_file)\n        try:\n            save_cache(str(cache_file), self._document_symbols_cache_version(), self._document_symbols_cache)\n            self._document_symbols_cache_is_modified = False\n        except Exception as e:\n            log.error(\n                \"Failed to save document symbols cache to %s: %s. Note: this may have resulted in a corrupted cache file.\",\n                cache_file,\n                e,\n            )\n\n    def _load_document_symbols_cache(self) -> None:\n        cache_file = self.cache_dir / self.DOCUMENT_SYMBOL_CACHE_FILENAME\n        if cache_file.exists():\n            log.info(\"Loading document symbols cache from %s\", cache_file)\n            try:\n                saved_cache = load_cache(str(cache_file), self._document_symbols_cache_version())\n                if saved_cache is not None:\n                    self._document_symbols_cache = saved_cache\n                    log.info(f\"Loaded {len(self._document_symbols_cache)} entries from document symbols cache.\")\n            except Exception as e:\n                # cache can become corrupt, so just skip loading it\n                log.warning(\n                    \"Failed to load document symbols cache from %s (%s); Ignoring cache.\",\n                    cache_file,\n                    e,\n                )\n\n    def save_cache(self) -> None:\n        self._save_raw_document_symbols_cache()\n        self._save_document_symbols_cache()\n\n    def request_workspace_symbol(self, query: str) -> list[ls_types.UnifiedSymbolInformation] | None:\n        \"\"\"\n        Raise a [workspace/symbol](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_symbol) request to the Language Server\n        to find symbols across the whole workspace. Wait for the response and return the result.\n\n        :param query: The query string to filter symbols by\n\n        :return: A list of matching symbols\n        \"\"\"\n        response = self.server.send.workspace_symbol({\"query\": query})\n        if response is None:\n            return None\n\n        assert isinstance(response, list)\n\n        ret: list[ls_types.UnifiedSymbolInformation] = []\n        for item in response:\n            assert isinstance(item, dict)\n\n            assert LSPConstants.NAME in item\n            assert LSPConstants.KIND in item\n            assert LSPConstants.LOCATION in item\n\n            ret.append(ls_types.UnifiedSymbolInformation(**item))  # type: ignore\n\n        return ret\n\n    def request_rename_symbol_edit(\n        self,\n        relative_file_path: str,\n        line: int,\n        column: int,\n        new_name: str,\n    ) -> ls_types.WorkspaceEdit | None:\n        \"\"\"\n        Retrieve a WorkspaceEdit for renaming the symbol at the given location to the new name.\n        Does not apply the edit, just retrieves it. In order to actually rename the symbol, call apply_workspace_edit.\n\n        :param relative_file_path: The relative path to the file containing the symbol\n        :param line: The 0-indexed line number of the symbol\n        :param column: The 0-indexed column number of the symbol\n        :param new_name: The new name for the symbol\n        :return: A WorkspaceEdit containing the changes needed to rename the symbol, or None if rename is not supported\n        \"\"\"\n        params = RenameParams(\n            textDocument=ls_types.TextDocumentIdentifier(\n                uri=pathlib.Path(os.path.join(self.repository_root_path, relative_file_path)).as_uri()\n            ),\n            position=ls_types.Position(line=line, character=column),\n            newName=new_name,\n        )\n\n        with self.open_file(relative_file_path):\n            return self.server.send.rename(params)\n\n    def apply_text_edits_to_file(self, relative_path: str, edits: list[ls_types.TextEdit]) -> None:\n        \"\"\"\n        Apply a list of text edits to a file.\n\n        :param relative_path: The relative path of the file to edit\n        :param edits: List of TextEdit dictionaries to apply\n        \"\"\"\n        with self.open_file(relative_path):\n            # Sort edits by position (latest first) to avoid position shifts\n            sorted_edits = sorted(edits, key=lambda e: (e[\"range\"][\"start\"][\"line\"], e[\"range\"][\"start\"][\"character\"]), reverse=True)\n\n            for edit in sorted_edits:\n                start_pos = ls_types.Position(line=edit[\"range\"][\"start\"][\"line\"], character=edit[\"range\"][\"start\"][\"character\"])\n                end_pos = ls_types.Position(line=edit[\"range\"][\"end\"][\"line\"], character=edit[\"range\"][\"end\"][\"character\"])\n\n                # Delete the old text and insert the new text\n                self.delete_text_between_positions(relative_path, start_pos, end_pos)\n                self.insert_text_at_position(relative_path, start_pos[\"line\"], start_pos[\"character\"], edit[\"newText\"])\n\n    def start(self) -> \"SolidLanguageServer\":\n        \"\"\"\n        Starts the language server process and connects to it. Call shutdown when ready.\n\n        :return: self for method chaining\n        \"\"\"\n        log.info(f\"Starting language server with language {self.language_server.language} for {self.language_server.repository_root_path}\")\n        self._start_server_process()\n        return self\n\n    def stop(self, shutdown_timeout: float = 2.0) -> None:\n        \"\"\"\n        Stops the language server process.\n        This function never raises an exception (any exceptions during shutdown are logged).\n\n        :param shutdown_timeout: time, in seconds, to wait for the server to shutdown gracefully before killing it\n        \"\"\"\n        try:\n            self._shutdown(timeout=shutdown_timeout)\n        except Exception as e:\n            log.warning(f\"Exception while shutting down language server: {e}\")\n\n    @property\n    def language_server(self) -> Self:\n        return self\n\n    @property\n    def handler(self) -> LanguageServerProcess:\n        \"\"\"Access the underlying language server handler.\n\n        Useful for advanced operations like sending custom commands\n        or registering notification handlers.\n        \"\"\"\n        return self.server\n\n    def is_running(self) -> bool:\n        return self.server.is_running()\n"
  },
  {
    "path": "src/solidlsp/ls_config.py",
    "content": "\"\"\"\nConfiguration objects for language servers\n\"\"\"\n\nimport fnmatch\nfrom collections.abc import Iterable\nfrom dataclasses import dataclass, field\nfrom enum import Enum\nfrom typing import TYPE_CHECKING, Self\n\nif TYPE_CHECKING:\n    from solidlsp import SolidLanguageServer\n\n\nclass FilenameMatcher:\n    def __init__(self, *patterns: str) -> None:\n        \"\"\"\n        :param patterns: fnmatch-compatible patterns\n        \"\"\"\n        self.patterns = patterns\n\n    def is_relevant_filename(self, fn: str) -> bool:\n        for pattern in self.patterns:\n            if fnmatch.fnmatch(fn, pattern):\n                return True\n        return False\n\n\nclass Language(str, Enum):\n    \"\"\"\n    Enumeration of language servers supported by SolidLSP.\n    \"\"\"\n\n    CSHARP = \"csharp\"\n    PYTHON = \"python\"\n    RUST = \"rust\"\n    JAVA = \"java\"\n    KOTLIN = \"kotlin\"\n    TYPESCRIPT = \"typescript\"\n    GO = \"go\"\n    RUBY = \"ruby\"\n    DART = \"dart\"\n    CPP = \"cpp\"\n    CPP_CCLS = \"cpp_ccls\"\n    PHP = \"php\"\n    R = \"r\"\n    PERL = \"perl\"\n    CLOJURE = \"clojure\"\n    ELIXIR = \"elixir\"\n    ELM = \"elm\"\n    TERRAFORM = \"terraform\"\n    SWIFT = \"swift\"\n    BASH = \"bash\"\n    ZIG = \"zig\"\n    LUA = \"lua\"\n    LUAU = \"luau\"\n    \"\"\"Luau Language Server for Roblox's Luau language (typed Lua 5.1 superset).\n    Uses luau-lsp by JohnnyMorganz. Automatically downloads the binary if not found.\n    Supports .luau files. Configure via .luaurc in the project root.\n    \"\"\"\n    NIX = \"nix\"\n    ERLANG = \"erlang\"\n    OCAML = \"ocaml\"\n    AL = \"al\"\n    FSHARP = \"fsharp\"\n    REGO = \"rego\"\n    SCALA = \"scala\"\n    JULIA = \"julia\"\n    FORTRAN = \"fortran\"\n    HASKELL = \"haskell\"\n    LEAN4 = \"lean4\"\n    GROOVY = \"groovy\"\n    VUE = \"vue\"\n    POWERSHELL = \"powershell\"\n    PASCAL = \"pascal\"\n    \"\"\"Pascal Language Server (pasls) for Free Pascal and Lazarus projects.\n    Automatically downloads pasls binary. Requires FPC for full functionality.\n    Set PP and FPCDIR environment variables for source navigation.\n    \"\"\"\n    MATLAB = \"matlab\"\n    \"\"\"MATLAB language server using the official MathWorks MATLAB Language Server.\n    Requires MATLAB R2021b or later and Node.js.\n    Set MATLAB_PATH environment variable or configure matlab_path in ls_specific_settings.\n    \"\"\"\n    # Experimental or deprecated Language Servers\n    TYPESCRIPT_VTS = \"typescript_vts\"\n    \"\"\"Use the typescript language server through the natively bundled vscode extension via https://github.com/yioneko/vtsls\"\"\"\n    PYTHON_JEDI = \"python_jedi\"\n    \"\"\"Jedi language server for Python (instead of pyright, which is the default)\"\"\"\n    CSHARP_OMNISHARP = \"csharp_omnisharp\"\n    \"\"\"OmniSharp language server for C# (instead of the default csharp-ls by microsoft).\n    Currently has problems with finding references, and generally seems less stable and performant.\n    \"\"\"\n    RUBY_SOLARGRAPH = \"ruby_solargraph\"\n    \"\"\"Solargraph language server for Ruby (legacy, experimental).\n    Use Language.RUBY (ruby-lsp) for better performance and modern LSP features.\n    \"\"\"\n    PHP_PHPACTOR = \"php_phpactor\"\n    \"\"\"Phpactor language server for PHP (instead of Intelephense, which is the default).\n    Requires PHP 8.1+ on the system. Fully open-source (MIT license).\n    \"\"\"\n    MARKDOWN = \"markdown\"\n    \"\"\"Marksman language server for Markdown (experimental).\n    Must be explicitly specified as the main language, not auto-detected.\n    This is an edge case primarily useful when working on documentation-heavy projects.\n    \"\"\"\n    YAML = \"yaml\"\n    \"\"\"YAML language server (experimental).\n    Must be explicitly specified as the main language, not auto-detected.\n    \"\"\"\n    TOML = \"toml\"\n    \"\"\"TOML language server using Taplo.\n    Supports TOML validation, formatting, and schema support.\n    \"\"\"\n    HLSL = \"hlsl\"\n    \"\"\"Shader language server using shader-language-server (antaalt/shader-sense).\n    Supports .hlsl, .hlsli, .fx, .fxh, .cginc, .compute, .shader, .glsl, .vert, .frag, .geom, .tesc, .tese, .comp, .wgsl files.\n    Automatically downloads shader-language-server binary.\n    \"\"\"\n    SYSTEMVERILOG = \"systemverilog\"\n    \"\"\"SystemVerilog language server using verible-verilog-ls.\n    Supports .sv, .svh, .v, .vh files.\n    Automatically downloads verible binary.\n    \"\"\"\n    SOLIDITY = \"solidity\"\n    \"\"\"Solidity language server using the Nomic Foundation Solidity Language Server\n    (@nomicfoundation/solidity-language-server).\n    Supports .sol files. Provides go-to-definition, find references, document symbols,\n    hover, and diagnostics. Requires Node.js and npm.\n    Works best with a foundry.toml or hardhat.config.js in the project root.\n    \"\"\"\n    ANSIBLE = \"ansible\"\n    \"\"\"Ansible language server (experimental) using @ansible/ansible-language-server.\n    Supports *.yaml and *.yml files (same extensions as YAML, hence experimental).\n    Must be explicitly specified in project.yml. Requires Node.js and npm.\n    Requires ``ansible`` in PATH for full functionality.\n    \"\"\"\n\n    @classmethod\n    def iter_all(cls, include_experimental: bool = False) -> Iterable[Self]:\n        for lang in cls:\n            if include_experimental or not lang.is_experimental():\n                yield lang\n\n    def is_experimental(self) -> bool:\n        \"\"\"\n        Check if the language server is experimental or deprecated.\n\n        Note for serena users/developers:\n        Experimental languages are not autodetected and must be explicitly specified\n        in the project.yml configuration.\n        \"\"\"\n        return self in {\n            self.ANSIBLE,\n            self.TYPESCRIPT_VTS,\n            self.PYTHON_JEDI,\n            self.CSHARP_OMNISHARP,\n            self.RUBY_SOLARGRAPH,\n            self.PHP_PHPACTOR,\n            self.MARKDOWN,\n            self.YAML,\n            self.TOML,\n            self.GROOVY,\n            self.CPP_CCLS,\n            self.SOLIDITY,\n        }\n\n    def __str__(self) -> str:\n        return self.value\n\n    def get_priority(self) -> int:\n        \"\"\"\n        :return: priority of the language for breaking ties between languages; higher is more important.\n        \"\"\"\n        # experimental languages have the lowest priority\n        if self.is_experimental():\n            return 0\n        # We assign lower priority to languages that are supersets of others, such that\n        # the \"larger\" language is only chosen when it matches more strongly\n        match self:\n            # languages that are supersets of others (Vue is superset of TypeScript/JavaScript)\n            case self.VUE:\n                return 1\n            # regular languages\n            case _:\n                return 2\n\n    def get_source_fn_matcher(self) -> FilenameMatcher:\n        match self:\n            case self.PYTHON | self.PYTHON_JEDI:\n                return FilenameMatcher(\"*.py\", \"*.pyi\")\n            case self.JAVA:\n                return FilenameMatcher(\"*.java\")\n            case self.TYPESCRIPT | self.TYPESCRIPT_VTS:\n                # see https://github.com/oraios/serena/issues/204\n                path_patterns = []\n                for prefix in [\"c\", \"m\", \"\"]:\n                    for postfix in [\"x\", \"\"]:\n                        for base_pattern in [\"ts\", \"js\"]:\n                            path_patterns.append(f\"*.{prefix}{base_pattern}{postfix}\")\n                return FilenameMatcher(*path_patterns)\n            case self.CSHARP | self.CSHARP_OMNISHARP:\n                return FilenameMatcher(\"*.cs\")\n            case self.RUST:\n                return FilenameMatcher(\"*.rs\")\n            case self.GO:\n                return FilenameMatcher(\"*.go\")\n            case self.RUBY:\n                return FilenameMatcher(\"*.rb\", \"*.erb\")\n            case self.RUBY_SOLARGRAPH:\n                return FilenameMatcher(\"*.rb\")\n            case self.CPP | self.CPP_CCLS:\n                return FilenameMatcher(\"*.cpp\", \"*.h\", \"*.hpp\", \"*.c\", \"*.hxx\", \"*.cc\", \"*.cxx\")\n            case self.KOTLIN:\n                return FilenameMatcher(\"*.kt\", \"*.kts\")\n            case self.DART:\n                return FilenameMatcher(\"*.dart\")\n            case self.PHP | self.PHP_PHPACTOR:\n                return FilenameMatcher(\"*.php\")\n            case self.R:\n                return FilenameMatcher(\"*.R\", \"*.r\", \"*.Rmd\", \"*.Rnw\")\n            case self.PERL:\n                return FilenameMatcher(\"*.pl\", \"*.pm\", \"*.t\")\n            case self.CLOJURE:\n                return FilenameMatcher(\"*.clj\", \"*.cljs\", \"*.cljc\", \"*.edn\")  # codespell:ignore edn\n            case self.ELIXIR:\n                return FilenameMatcher(\"*.ex\", \"*.exs\")\n            case self.ELM:\n                return FilenameMatcher(\"*.elm\")\n            case self.TERRAFORM:\n                return FilenameMatcher(\"*.tf\", \"*.tfvars\", \"*.tfstate\")\n            case self.SWIFT:\n                return FilenameMatcher(\"*.swift\")\n            case self.BASH:\n                return FilenameMatcher(\"*.sh\", \"*.bash\")\n            case self.YAML:\n                return FilenameMatcher(\"*.yaml\", \"*.yml\")\n            case self.TOML:\n                return FilenameMatcher(\"*.toml\")\n            case self.ZIG:\n                return FilenameMatcher(\"*.zig\", \"*.zon\")\n            case self.LUA:\n                return FilenameMatcher(\"*.lua\")\n            case self.LUAU:\n                return FilenameMatcher(\"*.luau\")\n            case self.NIX:\n                return FilenameMatcher(\"*.nix\")\n            case self.ERLANG:\n                return FilenameMatcher(\"*.erl\", \"*.hrl\", \"*.escript\", \"*.config\", \"*.app\", \"*.app.src\")\n            case self.OCAML:\n                return FilenameMatcher(\"*.ml\", \"*.mli\", \"*.re\", \"*.rei\")\n            case self.AL:\n                return FilenameMatcher(\"*.al\", \"*.dal\")\n            case self.FSHARP:\n                return FilenameMatcher(\"*.fs\", \"*.fsx\", \"*.fsi\")\n            case self.REGO:\n                return FilenameMatcher(\"*.rego\")\n            case self.MARKDOWN:\n                return FilenameMatcher(\"*.md\", \"*.markdown\")\n            case self.SCALA:\n                return FilenameMatcher(\"*.scala\", \"*.sbt\")\n            case self.JULIA:\n                return FilenameMatcher(\"*.jl\")\n            case self.FORTRAN:\n                return FilenameMatcher(\n                    \"*.f90\", \"*.F90\", \"*.f95\", \"*.F95\", \"*.f03\", \"*.F03\", \"*.f08\", \"*.F08\", \"*.f\", \"*.F\", \"*.for\", \"*.FOR\", \"*.fpp\", \"*.FPP\"\n                )\n            case self.HASKELL:\n                return FilenameMatcher(\"*.hs\", \"*.lhs\")\n            case self.LEAN4:\n                return FilenameMatcher(\"*.lean\")\n            case self.VUE:\n                path_patterns = [\"*.vue\"]\n                for prefix in [\"c\", \"m\", \"\"]:\n                    for postfix in [\"x\", \"\"]:\n                        for base_pattern in [\"ts\", \"js\"]:\n                            path_patterns.append(f\"*.{prefix}{base_pattern}{postfix}\")\n                return FilenameMatcher(*path_patterns)\n            case self.POWERSHELL:\n                return FilenameMatcher(\"*.ps1\", \"*.psm1\", \"*.psd1\")\n            case self.PASCAL:\n                return FilenameMatcher(\"*.pas\", \"*.pp\", \"*.lpr\", \"*.dpr\", \"*.dpk\", \"*.inc\")\n            case self.GROOVY:\n                return FilenameMatcher(\"*.groovy\", \"*.gvy\")\n            case self.MATLAB:\n                return FilenameMatcher(\"*.m\", \"*.mlx\", \"*.mlapp\")\n            case self.HLSL:\n                return FilenameMatcher(\n                    \"*.hlsl\",\n                    \"*.hlsli\",\n                    \"*.fx\",\n                    \"*.fxh\",\n                    \"*.cginc\",\n                    \"*.compute\",\n                    \"*.shader\",\n                    \"*.glsl\",\n                    \"*.vert\",\n                    \"*.frag\",\n                    \"*.geom\",\n                    \"*.tesc\",\n                    \"*.tese\",\n                    \"*.comp\",\n                    \"*.wgsl\",\n                )\n            case self.SYSTEMVERILOG:\n                return FilenameMatcher(\"*.sv\", \"*.svh\", \"*.v\", \"*.vh\")\n            case self.SOLIDITY:\n                return FilenameMatcher(\"*.sol\")\n            case self.ANSIBLE:\n                return FilenameMatcher(\"*.yaml\", \"*.yml\")\n            case _:\n                raise ValueError(f\"Unhandled language: {self}\")\n\n    def get_ls_class(self) -> type[\"SolidLanguageServer\"]:\n        match self:\n            case self.PYTHON:\n                from solidlsp.language_servers.pyright_server import PyrightServer\n\n                return PyrightServer\n            case self.PYTHON_JEDI:\n                from solidlsp.language_servers.jedi_server import JediServer\n\n                return JediServer\n            case self.JAVA:\n                from solidlsp.language_servers.eclipse_jdtls import EclipseJDTLS\n\n                return EclipseJDTLS\n            case self.KOTLIN:\n                from solidlsp.language_servers.kotlin_language_server import KotlinLanguageServer\n\n                return KotlinLanguageServer\n            case self.RUST:\n                from solidlsp.language_servers.rust_analyzer import RustAnalyzer\n\n                return RustAnalyzer\n            case self.CSHARP:\n                from solidlsp.language_servers.csharp_language_server import CSharpLanguageServer\n\n                return CSharpLanguageServer\n            case self.CSHARP_OMNISHARP:\n                from solidlsp.language_servers.omnisharp import OmniSharp\n\n                return OmniSharp\n            case self.TYPESCRIPT:\n                from solidlsp.language_servers.typescript_language_server import TypeScriptLanguageServer\n\n                return TypeScriptLanguageServer\n            case self.TYPESCRIPT_VTS:\n                from solidlsp.language_servers.vts_language_server import VtsLanguageServer\n\n                return VtsLanguageServer\n            case self.VUE:\n                from solidlsp.language_servers.vue_language_server import VueLanguageServer\n\n                return VueLanguageServer\n            case self.GO:\n                from solidlsp.language_servers.gopls import Gopls\n\n                return Gopls\n            case self.RUBY:\n                from solidlsp.language_servers.ruby_lsp import RubyLsp\n\n                return RubyLsp\n            case self.RUBY_SOLARGRAPH:\n                from solidlsp.language_servers.solargraph import Solargraph\n\n                return Solargraph\n            case self.DART:\n                from solidlsp.language_servers.dart_language_server import DartLanguageServer\n\n                return DartLanguageServer\n            case self.CPP:\n                from solidlsp.language_servers.clangd_language_server import ClangdLanguageServer\n\n                return ClangdLanguageServer\n            case self.CPP_CCLS:\n                from solidlsp.language_servers.ccls_language_server import CCLS\n\n                return CCLS\n            case self.PHP:\n                from solidlsp.language_servers.intelephense import Intelephense\n\n                return Intelephense\n            case self.PHP_PHPACTOR:\n                from solidlsp.language_servers.phpactor import PhpactorServer\n\n                return PhpactorServer\n            case self.PERL:\n                from solidlsp.language_servers.perl_language_server import PerlLanguageServer\n\n                return PerlLanguageServer\n            case self.CLOJURE:\n                from solidlsp.language_servers.clojure_lsp import ClojureLSP\n\n                return ClojureLSP\n            case self.ELIXIR:\n                from solidlsp.language_servers.elixir_tools.elixir_tools import ElixirTools\n\n                return ElixirTools\n            case self.ELM:\n                from solidlsp.language_servers.elm_language_server import ElmLanguageServer\n\n                return ElmLanguageServer\n            case self.TERRAFORM:\n                from solidlsp.language_servers.terraform_ls import TerraformLS\n\n                return TerraformLS\n            case self.SWIFT:\n                from solidlsp.language_servers.sourcekit_lsp import SourceKitLSP\n\n                return SourceKitLSP\n            case self.BASH:\n                from solidlsp.language_servers.bash_language_server import BashLanguageServer\n\n                return BashLanguageServer\n            case self.YAML:\n                from solidlsp.language_servers.yaml_language_server import YamlLanguageServer\n\n                return YamlLanguageServer\n            case self.TOML:\n                from solidlsp.language_servers.taplo_server import TaploServer\n\n                return TaploServer\n            case self.ZIG:\n                from solidlsp.language_servers.zls import ZigLanguageServer\n\n                return ZigLanguageServer\n            case self.NIX:\n                from solidlsp.language_servers.nixd_ls import NixLanguageServer  # type: ignore\n\n                return NixLanguageServer\n            case self.LUA:\n                from solidlsp.language_servers.lua_ls import LuaLanguageServer\n\n                return LuaLanguageServer\n\n            case self.LUAU:\n                from solidlsp.language_servers.luau_lsp import LuauLanguageServer\n\n                return LuauLanguageServer\n\n            case self.ERLANG:\n                from solidlsp.language_servers.erlang_language_server import ErlangLanguageServer\n\n                return ErlangLanguageServer\n            case self.OCAML:\n                from solidlsp.language_servers.ocaml_lsp_server import OcamlLanguageServer\n\n                return OcamlLanguageServer\n            case self.AL:\n                from solidlsp.language_servers.al_language_server import ALLanguageServer\n\n                return ALLanguageServer\n            case self.REGO:\n                from solidlsp.language_servers.regal_server import RegalLanguageServer\n\n                return RegalLanguageServer\n            case self.MARKDOWN:\n                from solidlsp.language_servers.marksman import Marksman\n\n                return Marksman\n            case self.R:\n                from solidlsp.language_servers.r_language_server import RLanguageServer\n\n                return RLanguageServer\n            case self.SCALA:\n                from solidlsp.language_servers.scala_language_server import ScalaLanguageServer\n\n                return ScalaLanguageServer\n            case self.JULIA:\n                from solidlsp.language_servers.julia_server import JuliaLanguageServer\n\n                return JuliaLanguageServer\n            case self.FORTRAN:\n                from solidlsp.language_servers.fortran_language_server import FortranLanguageServer\n\n                return FortranLanguageServer\n            case self.HASKELL:\n                from solidlsp.language_servers.haskell_language_server import HaskellLanguageServer\n\n                return HaskellLanguageServer\n            case self.LEAN4:\n                from solidlsp.language_servers.lean4_language_server import Lean4LanguageServer\n\n                return Lean4LanguageServer\n            case self.FSHARP:\n                from solidlsp.language_servers.fsharp_language_server import FSharpLanguageServer\n\n                return FSharpLanguageServer\n            case self.POWERSHELL:\n                from solidlsp.language_servers.powershell_language_server import PowerShellLanguageServer\n\n                return PowerShellLanguageServer\n            case self.PASCAL:\n                from solidlsp.language_servers.pascal_server import PascalLanguageServer\n\n                return PascalLanguageServer\n            case self.GROOVY:\n                from solidlsp.language_servers.groovy_language_server import GroovyLanguageServer\n\n                return GroovyLanguageServer\n            case self.MATLAB:\n                from solidlsp.language_servers.matlab_language_server import MatlabLanguageServer\n\n                return MatlabLanguageServer\n            case self.HLSL:\n                from solidlsp.language_servers.hlsl_language_server import HlslLanguageServer\n\n                return HlslLanguageServer\n            case self.SYSTEMVERILOG:\n                from solidlsp.language_servers.systemverilog_server import SystemVerilogLanguageServer\n\n                return SystemVerilogLanguageServer\n            case self.SOLIDITY:\n                from solidlsp.language_servers.solidity_language_server import SolidityLanguageServer\n\n                return SolidityLanguageServer\n            case self.ANSIBLE:\n                from solidlsp.language_servers.ansible_language_server import AnsibleLanguageServer\n\n                return AnsibleLanguageServer\n            case _:\n                raise ValueError(f\"Unhandled language: {self}\")\n\n    @classmethod\n    def from_ls_class(cls, ls_class: type[\"SolidLanguageServer\"]) -> Self:\n        \"\"\"\n        Get the Language enum value from a SolidLanguageServer class.\n\n        :param ls_class: The SolidLanguageServer class to find the corresponding Language for\n        :return: The Language enum value\n        :raises ValueError: If the language server class is not supported\n        \"\"\"\n        for enum_instance in cls:\n            if enum_instance.get_ls_class() == ls_class:\n                return enum_instance\n        raise ValueError(f\"Unhandled language server class: {ls_class}\")\n\n\n@dataclass\nclass LanguageServerConfig:\n    \"\"\"\n    Configuration parameters\n    \"\"\"\n\n    code_language: Language\n    trace_lsp_communication: bool = False\n    start_independent_lsp_process: bool = True\n    ignored_paths: list[str] = field(default_factory=list)\n    \"\"\"Paths, dirs or glob-like patterns. The matching will follow the same logic as for .gitignore entries\"\"\"\n    encoding: str = \"utf-8\"\n    \"\"\"File encoding to use when reading source files\"\"\"\n\n    @classmethod\n    def from_dict(cls, env: dict) -> Self:\n        import inspect\n\n        return cls(**{k: v for k, v in env.items() if k in inspect.signature(cls).parameters})\n"
  },
  {
    "path": "src/solidlsp/ls_exceptions.py",
    "content": "\"\"\"\nThis module contains the exceptions raised by the framework.\n\"\"\"\n\nfrom solidlsp.ls_config import Language\n\n\nclass SolidLSPException(Exception):\n    def __init__(self, message: str, cause: Exception | None = None) -> None:\n        \"\"\"\n        Initializes the exception with the given message.\n\n        :param message: the message describing the exception\n        :param cause: the original exception that caused this exception, if any.\n            For exceptions raised during request handling, this is typically\n                * an LSPError for errors returned by the LSP server\n                * LanguageServerTerminatedException for errors due to the language server having terminated.\n        \"\"\"\n        self.cause = cause\n        super().__init__(message)\n\n    def is_language_server_terminated(self) -> bool:\n        \"\"\"\n        :return: True if the exception is caused by the language server having terminated as indicated\n            by the causing exception being an instance of LanguageServerTerminatedException.\n        \"\"\"\n        from .ls_process import LanguageServerTerminatedException\n\n        return isinstance(self.cause, LanguageServerTerminatedException)\n\n    def get_affected_language(self) -> Language | None:\n        \"\"\"\n        :return: the affected language for the case where the exception is caused by the language server having terminated\n        \"\"\"\n        from .ls_process import LanguageServerTerminatedException\n\n        if isinstance(self.cause, LanguageServerTerminatedException):\n            return self.cause.language\n        return None\n\n    def __str__(self) -> str:\n        \"\"\"\n        Returns a string representation of the exception.\n        \"\"\"\n        s = super().__str__()\n        if self.cause:\n            if \"\\n\" in s:\n                s += \"\\n\"\n            else:\n                s += \" \"\n            s += f\"(caused by {self.cause})\"\n        return s\n\n\nclass MetalsStaleLockError(SolidLSPException):\n    \"\"\"\n    Raised when a stale Metals H2 database lock is detected and the user\n    has configured fail-on-stale-lock behavior.\n\n    A stale lock occurs when a previous Metals process crashed without\n    cleaning up its lock file, which can prevent proper AUTO_SERVER\n    coordination with new instances.\n    \"\"\"\n\n    def __init__(self, lock_path: str, message: str | None = None) -> None:\n        self.lock_path = lock_path\n        if message is None:\n            message = (\n                f\"Stale Metals lock file detected at {lock_path}. \"\n                \"A previous Metals process may have crashed. \"\n                \"To resolve: remove the lock file manually, or set \"\n                \"on_stale_lock='auto-clean' in ls_specific_settings.scala.\"\n            )\n        super().__init__(message)\n"
  },
  {
    "path": "src/solidlsp/ls_process.py",
    "content": "import asyncio\nimport json\nimport logging\nimport os\nimport platform\nimport subprocess\nimport threading\nimport time\nfrom collections.abc import Callable\nfrom dataclasses import dataclass\nfrom queue import Empty, Queue\nfrom typing import Any\n\nimport psutil\nfrom sensai.util.string import ToStringMixin\n\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_exceptions import SolidLSPException\nfrom solidlsp.ls_request import LanguageServerRequest\nfrom solidlsp.lsp_protocol_handler.lsp_requests import LspNotification\nfrom solidlsp.lsp_protocol_handler.lsp_types import ErrorCodes\nfrom solidlsp.lsp_protocol_handler.server import (\n    ENCODING,\n    LSPError,\n    PayloadLike,\n    ProcessLaunchInfo,\n    StringDict,\n    content_length,\n    create_message,\n    make_error_response,\n    make_notification,\n    make_request,\n    make_response,\n)\nfrom solidlsp.util.subprocess_util import quote_arg, subprocess_kwargs\n\nlog = logging.getLogger(__name__)\n\n\nclass LanguageServerTerminatedException(Exception):\n    \"\"\"\n    Exception raised when the language server process has terminated unexpectedly.\n    \"\"\"\n\n    def __init__(self, message: str, language: Language, cause: Exception | None = None) -> None:\n        super().__init__(message)\n        self.message = message\n        self.language = language\n        self.cause = cause\n\n    def __str__(self) -> str:\n        return f\"LanguageServerTerminatedException: {self.message}\" + (f\"; Cause: {self.cause}\" if self.cause else \"\")\n\n\nclass Request(ToStringMixin):\n    @dataclass\n    class Result:\n        payload: PayloadLike | None = None\n        error: Exception | None = None\n\n        def is_error(self) -> bool:\n            return self.error is not None\n\n    def __init__(self, request_id: int, method: str) -> None:\n        self._request_id = request_id\n        self._method = method\n        self._status = \"pending\"\n        self._result_queue: Queue[Request.Result] = Queue()\n\n    def _tostring_includes(self) -> list[str]:\n        return [\"_request_id\", \"_status\", \"_method\"]\n\n    def on_result(self, params: PayloadLike) -> None:\n        self._status = \"completed\"\n        self._result_queue.put(Request.Result(payload=params))\n\n    def on_error(self, err: Exception) -> None:\n        \"\"\"\n        :param err: the error that occurred while processing the request (typically an LSPError\n            for errors returned by the LS or LanguageServerTerminatedException if the error\n            is due to the language server process terminating unexpectedly).\n        \"\"\"\n        self._status = \"error\"\n        self._result_queue.put(Request.Result(error=err))\n\n    def get_result(self, timeout: float | None = None) -> Result:\n        try:\n            return self._result_queue.get(timeout=timeout)\n        except Empty as e:\n            if timeout is not None:\n                raise TimeoutError(f\"Request timed out ({timeout=})\") from e\n            raise e\n\n\nclass LanguageServerProcess:\n    \"\"\"\n    Represents a language server process and provides methods for communicating with it using the\n    Language Server Protocol (LSP).\n\n    It provides methods for sending requests, responses, and notifications to the server\n    and for registering handlers for requests and notifications from the server.\n\n    Uses JSON-RPC 2.0 for communication with the server over stdin/stdout.\n\n    Attributes:\n        send: A LspRequest object that can be used to send requests to the server and\n            await for the responses.\n        notify: A LspNotification object that can be used to send notifications to the server.\n        cmd: A string that represents the command to launch the language server process.\n        process: A subprocess.Popen object that represents the language server process.\n        request_id: An integer that represents the next available request id for the client.\n        _pending_requests: A dictionary that maps request ids to Request objects that\n            store the results or errors of the requests.\n        on_request_handlers: A dictionary that maps method names to callback functions\n            that handle requests from the server.\n        on_notification_handlers: A dictionary that maps method names to callback functions\n            that handle notifications from the server.\n        _trace_log_fn: An optional function that takes two strings (source and destination) and\n            a payload dictionary, and logs the communication between the client and the server.\n        tasks: A dictionary that maps task ids to asyncio.Task objects that represent\n            the asynchronous tasks created by the handler.\n        task_counter: An integer that represents the next available task id for the handler.\n        loop: An asyncio.AbstractEventLoop object that represents the event loop used by the handler.\n        start_independent_lsp_process: An optional boolean flag that indicates whether to start the\n        language server process in an independent process group. Default is `True`. Setting it to\n        `False` means that the language server process will be in the same process group as the\n        the current process, and any SIGINT and SIGTERM signals will be sent to both processes.\n\n    \"\"\"\n\n    def __init__(\n        self,\n        process_launch_info: ProcessLaunchInfo,\n        language: Language,\n        determine_log_level: Callable[[str], int],\n        logger: Callable[[str, str, StringDict | str], None] | None = None,\n        start_independent_lsp_process: bool = True,\n        request_timeout: float | None = None,\n    ) -> None:\n        self.language = language\n        self._determine_log_level = determine_log_level\n        self.send = LanguageServerRequest(self)\n        self.notify = LspNotification(self.send_notification)\n\n        self.process_launch_info = process_launch_info\n        self.process: subprocess.Popen[bytes] | None = None\n        self._is_shutting_down = False\n\n        self.request_id = 1\n        self._pending_requests: dict[Any, Request] = {}\n        self.on_request_handlers: dict[str, Callable[[Any], Any]] = {}\n        self.on_notification_handlers: dict[str, Callable[[Any], None]] = {}\n        self._trace_log_fn = logger\n        self.tasks: dict[int, Any] = {}\n        self.task_counter = 0\n        self.loop = None\n        self.start_independent_lsp_process = start_independent_lsp_process\n        self._request_timeout = request_timeout\n\n        # Add thread locks for shared resources to prevent race conditions\n        self._stdin_lock = threading.Lock()\n        self._request_id_lock = threading.Lock()\n        self._response_handlers_lock = threading.Lock()\n        self._tasks_lock = threading.Lock()\n\n    def set_request_timeout(self, timeout: float | None) -> None:\n        \"\"\"\n        :param timeout: the timeout, in seconds, for all requests sent to the language server.\n        \"\"\"\n        self._request_timeout = timeout\n\n    def is_running(self) -> bool:\n        \"\"\"\n        Checks if the language server process is currently running.\n        \"\"\"\n        return self.process is not None and self.process.returncode is None\n\n    def start(self) -> None:\n        \"\"\"\n        Starts the language server process and creates a task to continuously read from its stdout to handle communications\n        from the server to the client\n        \"\"\"\n        child_proc_env = os.environ.copy()\n        child_proc_env.update(self.process_launch_info.env)\n\n        cmd = self.process_launch_info.cmd\n        is_windows = platform.system() == \"Windows\"\n        if not isinstance(cmd, str) and not is_windows:\n            # Since we are using the shell, we need to convert the command list to a single string\n            # on Linux/macOS\n            cmd = \" \".join(map(quote_arg, cmd))\n        log.info(\"Starting language server process via command: %s\", self.process_launch_info.cmd)\n        kwargs = subprocess_kwargs()\n        kwargs[\"start_new_session\"] = self.start_independent_lsp_process\n        self.process = subprocess.Popen(\n            cmd,\n            stdout=subprocess.PIPE,\n            stdin=subprocess.PIPE,\n            stderr=subprocess.PIPE,\n            env=child_proc_env,\n            cwd=self.process_launch_info.cwd,\n            shell=True,\n            **kwargs,\n        )\n\n        # Check if process terminated immediately\n        if self.process.returncode is not None:\n            log.error(\"Language server has already terminated/could not be started\")\n            # Process has already terminated\n            stderr_data = self.process.stderr.read() if self.process.stderr else b\"\"\n            error_message = stderr_data.decode(\"utf-8\", errors=\"replace\")\n            raise RuntimeError(f\"Process terminated immediately with code {self.process.returncode}. Error: {error_message}\")\n\n        # start threads to read stdout and stderr of the process\n        threading.Thread(\n            target=self._read_ls_process_stdout,\n            name=f\"LSP-stdout-reader:{self.language.value}\",\n            daemon=True,\n        ).start()\n        threading.Thread(\n            target=self._read_ls_process_stderr,\n            name=f\"LSP-stderr-reader:{self.language.value}\",\n            daemon=True,\n        ).start()\n\n    def stop(self) -> None:\n        \"\"\"\n        Sends the terminate signal to the language server process and waits for it to exit, with a timeout, killing it if necessary\n        \"\"\"\n        process = self.process\n        self.process = None\n        if process:\n            self._cleanup_process(process)\n\n    def _cleanup_process(self, process: subprocess.Popen[bytes]) -> None:\n        \"\"\"Clean up a process: close stdin, terminate/kill process, close stdout/stderr.\"\"\"\n        # Close stdin first to prevent deadlocks\n        # See: https://bugs.python.org/issue35539\n        self._safely_close_pipe(process.stdin)\n\n        # Terminate/kill the process if it's still running\n        if process.returncode is None:\n            self._terminate_or_kill_process(process)\n\n        # Close stdout and stderr pipes after process has exited\n        # This is essential to prevent \"I/O operation on closed pipe\" errors and\n        # \"Event loop is closed\" errors during garbage collection\n        # See: https://bugs.python.org/issue41320 and https://github.com/python/cpython/issues/88050\n        self._safely_close_pipe(process.stdout)\n        self._safely_close_pipe(process.stderr)\n\n    def _safely_close_pipe(self, pipe: Any) -> None:\n        \"\"\"Safely close a pipe, ignoring any exceptions.\"\"\"\n        if pipe:\n            try:\n                pipe.close()\n            except Exception:\n                pass\n\n    def _terminate_or_kill_process(self, process: subprocess.Popen[bytes]) -> None:\n        \"\"\"Try to terminate the process gracefully, then forcefully if necessary.\"\"\"\n        # First try to terminate the process tree gracefully\n        self._signal_process_tree(process, terminate=True)\n\n    def _signal_process_tree(self, process: subprocess.Popen[bytes], terminate: bool = True) -> None:\n        \"\"\"Send signal (terminate or kill) to the process and all its children.\"\"\"\n        signal_method = \"terminate\" if terminate else \"kill\"\n\n        # Try to get the parent process\n        parent = None\n        try:\n            parent = psutil.Process(process.pid)\n        except (psutil.NoSuchProcess, psutil.AccessDenied, Exception):\n            pass\n\n        # If we have the parent process and it's running, signal the entire tree\n        if parent and parent.is_running():\n            # Signal children first\n            for child in parent.children(recursive=True):\n                try:\n                    getattr(child, signal_method)()\n                except (psutil.NoSuchProcess, psutil.AccessDenied, Exception):\n                    pass\n\n            # Then signal the parent\n            try:\n                getattr(parent, signal_method)()\n            except (psutil.NoSuchProcess, psutil.AccessDenied, Exception):\n                pass\n        else:\n            # Fall back to direct process signaling\n            try:\n                getattr(process, signal_method)()\n            except Exception:\n                pass\n\n    def shutdown(self) -> None:\n        \"\"\"\n        Perform the shutdown sequence for the client, including sending the shutdown request to the server and notifying it of exit\n        \"\"\"\n        self._is_shutting_down = True\n        log.info(\"Sending shutdown request to server\")\n        self.send.shutdown()\n        log.info(\"Received shutdown response from server\")\n        log.info(\"Sending exit notification to server\")\n        self.notify.exit()\n        log.info(\"Sent exit notification to server\")\n\n    def _trace(self, src: str, dest: str, message: str | StringDict) -> None:\n        \"\"\"\n        Traces LS communication by logging the message with the source and destination of the message\n        \"\"\"\n        if self._trace_log_fn is not None:\n            self._trace_log_fn(src, dest, message)\n\n    def _read_bytes_from_process(self, process, stream, num_bytes) -> bytes:  # type: ignore\n        \"\"\"Read exactly num_bytes from process stdout\"\"\"\n        data = b\"\"\n        while len(data) < num_bytes:\n            chunk = stream.read(num_bytes - len(data))\n            if not chunk:\n                if process.poll() is not None:\n                    raise LanguageServerTerminatedException(\n                        f\"Process terminated while trying to read response (read {num_bytes} of {len(data)} bytes before termination)\",\n                        language=self.language,\n                    )\n                # Process still running but no data available yet, retry after a short delay\n                time.sleep(0.01)\n                continue\n            data += chunk\n        return data\n\n    def _read_ls_process_stdout(self) -> None:\n        \"\"\"\n        Continuously read from the language server process stdout and handle the messages\n        invoking the registered response and notification handlers\n        \"\"\"\n        exception: Exception | None = None\n        try:\n            while self.process and self.process.stdout:\n                if self.process.poll() is not None:  # process has terminated\n                    break\n                line = self.process.stdout.readline()\n                if not line:\n                    continue\n                try:\n                    num_bytes = content_length(line)\n                except ValueError:\n                    continue\n                if num_bytes is None:\n                    continue\n                while line and line.strip():\n                    line = self.process.stdout.readline()\n                if not line:\n                    continue\n                body = self._read_bytes_from_process(self.process, self.process.stdout, num_bytes)\n\n                self._handle_body(body)\n        except LanguageServerTerminatedException as e:\n            exception = e\n        except (BrokenPipeError, ConnectionResetError) as e:\n            exception = LanguageServerTerminatedException(\"Language server process terminated while reading stdout\", self.language, cause=e)\n        except Exception as e:\n            exception = LanguageServerTerminatedException(\n                \"Unexpected error while reading stdout from language server process\", self.language, cause=e\n            )\n        log.info(\"Language server stdout reader thread has terminated\")\n        if not self._is_shutting_down:\n            if exception is None:\n                exception = LanguageServerTerminatedException(\"Language server stdout read process terminated unexpectedly\", self.language)\n            log.error(str(exception))\n            self._cancel_pending_requests(exception)\n\n    def _read_ls_process_stderr(self) -> None:\n        \"\"\"\n        Continuously read from the language server process stderr and log the messages\n        \"\"\"\n        try:\n            while self.process and self.process.stderr:\n                if self.process.poll() is not None:\n                    # process has terminated\n                    break\n                line = self.process.stderr.readline()\n                if not line:\n                    continue\n                line_str = line.decode(ENCODING, errors=\"replace\")\n                level = self._determine_log_level(line_str)\n                log.log(level, line_str)\n        except Exception as e:\n            log.error(\"Error while reading stderr from language server process: %s\", e, exc_info=e)\n        if not self._is_shutting_down:\n            log.error(\"Language server stderr reader thread terminated unexpectedly\")\n        else:\n            log.info(\"Language server stderr reader thread has terminated\")\n\n    def _handle_body(self, body: bytes) -> None:\n        \"\"\"\n        Parse the body text received from the language server process and invoke the appropriate handler\n        \"\"\"\n        try:\n            self._receive_payload(json.loads(body))\n        except OSError as ex:\n            log.error(f\"Error processing payload: {ex}\", exc_info=ex)\n        except UnicodeDecodeError as ex:\n            log.error(f\"Decoding error for encoding={ENCODING}: {ex}\")\n        except json.JSONDecodeError as ex:\n            log.error(f\"JSON decoding error: {ex}\")\n\n    def _receive_payload(self, payload: StringDict) -> None:\n        \"\"\"\n        Determine if the payload received from server is for a request, response, or notification and invoke the appropriate handler\n        \"\"\"\n        self._trace(\"ls\", \"solidlsp\", payload)\n        try:\n            if \"method\" in payload:\n                if \"id\" in payload:\n                    self._request_handler(payload)\n                else:\n                    self._notification_handler(payload)\n            elif \"id\" in payload:\n                self._response_handler(payload)\n            else:\n                log.error(f\"Unknown payload type: {payload}\")\n        except Exception as err:\n            log.error(f\"Error handling server payload: {err}\")\n\n    def send_notification(self, method: str, params: dict | None = None) -> None:\n        \"\"\"\n        Send notification pertaining to the given method to the server with the given parameters\n        \"\"\"\n        self._send_payload(make_notification(method, params))\n\n    def send_response(self, request_id: Any, params: PayloadLike) -> None:\n        \"\"\"\n        Send response to the given request id to the server with the given parameters\n        \"\"\"\n        self._send_payload(make_response(request_id, params))\n\n    def send_error_response(self, request_id: Any, err: LSPError) -> None:\n        \"\"\"\n        Send error response to the given request id to the server with the given error\n        \"\"\"\n        self._send_payload(make_error_response(request_id, err))\n\n    def _cancel_pending_requests(self, exception: Exception) -> None:\n        \"\"\"\n        Cancel all pending requests by setting their results to an error\n        \"\"\"\n        with self._response_handlers_lock:\n            log.info(\"Cancelling %d pending language server requests\", len(self._pending_requests))\n            for request in self._pending_requests.values():\n                log.info(\"Cancelling %s\", request)\n                request.on_error(exception)\n            self._pending_requests.clear()\n\n    def send_request(self, method: str, params: dict | None = None) -> PayloadLike:\n        \"\"\"\n        Send request to the server, register the request id, and wait for the response\n        \"\"\"\n        with self._request_id_lock:\n            request_id = self.request_id\n            self.request_id += 1\n\n        request = Request(request_id=request_id, method=method)\n        log.debug(\"Starting: %s\", request)\n\n        with self._response_handlers_lock:\n            self._pending_requests[request_id] = request\n\n        self._send_payload(make_request(method, request_id, params))\n\n        log.debug(\"Waiting for response to request %s with params:\\n%s\", method, params)\n        result = request.get_result(timeout=self._request_timeout)\n        log.debug(\"Completed: %s\", request)\n\n        if result.is_error():\n            raise SolidLSPException(f\"Error processing request {method} with params:\\n{params}\", cause=result.error) from result.error\n\n        log.debug(\"Returning result:\\n%s\", result.payload)\n        return result.payload\n\n    def _send_payload(self, payload: StringDict) -> None:\n        \"\"\"\n        Send the payload to the server by writing to its stdin asynchronously.\n        \"\"\"\n        if not self.process or not self.process.stdin:\n            return\n        self._trace(\"solidlsp\", \"ls\", payload)\n        msg = create_message(payload)\n\n        # Use lock to prevent concurrent writes to stdin that cause buffer corruption\n        with self._stdin_lock:\n            try:\n                self.process.stdin.writelines(msg)\n                self.process.stdin.flush()\n            except (BrokenPipeError, ConnectionResetError, OSError) as e:\n                # Log the error but don't raise to prevent cascading failures\n                log.error(f\"Failed to write to stdin: {e}\")\n                return\n\n    def on_request(self, method: str, cb: Callable[[Any], Any]) -> None:\n        \"\"\"\n        Register the callback function to handle requests from the server to the client for the given method\n        \"\"\"\n        self.on_request_handlers[method] = cb\n\n    def on_notification(self, method: str, cb: Callable[[Any], None]) -> None:\n        \"\"\"\n        Register the callback function to handle notifications from the server to the client for the given method\n        \"\"\"\n        self.on_notification_handlers[method] = cb\n\n    def _response_handler(self, response: StringDict) -> None:\n        \"\"\"\n        Handle the response received from the server for a request, using the id to determine the request\n        \"\"\"\n        response_id = response[\"id\"]\n        with self._response_handlers_lock:\n            request = self._pending_requests.pop(response_id, None)\n            if request is None and isinstance(response_id, str) and response_id.isdigit():\n                request = self._pending_requests.pop(int(response_id), None)\n\n            if request is None:  # need to convert response_id to the right type\n                log.debug(\"Request interrupted by user or not found for ID %s\", response_id)\n                return\n\n        if \"result\" in response and \"error\" not in response:\n            request.on_result(response[\"result\"])\n        elif \"result\" not in response and \"error\" in response:\n            request.on_error(LSPError.from_lsp(response[\"error\"]))\n        else:\n            request.on_error(LSPError(ErrorCodes.InvalidRequest, \"\"))\n\n    def _request_handler(self, response: StringDict) -> None:\n        \"\"\"\n        Handle the request received from the server: call the appropriate callback function and return the result\n        \"\"\"\n        method = response.get(\"method\", \"\")\n        params = response.get(\"params\")\n        request_id = response.get(\"id\")\n        handler = self.on_request_handlers.get(method)\n        if not handler:\n            self.send_error_response(\n                request_id,\n                LSPError(\n                    ErrorCodes.MethodNotFound,\n                    f\"method '{method}' not handled on client.\",\n                ),\n            )\n            return\n        try:\n            self.send_response(request_id, handler(params))\n        except LSPError as ex:\n            self.send_error_response(request_id, ex)\n        except Exception as ex:\n            self.send_error_response(request_id, LSPError(ErrorCodes.InternalError, str(ex)))\n\n    def _notification_handler(self, response: StringDict) -> None:\n        \"\"\"\n        Handle the notification received from the server: call the appropriate callback function\n        \"\"\"\n        method = response.get(\"method\", \"\")\n        params = response.get(\"params\")\n        handler = self.on_notification_handlers.get(method)\n        if not handler:\n            log.warning(\"Unhandled method '%s'\", method)\n            return\n        try:\n            handler(params)\n        except asyncio.CancelledError:\n            return\n        except Exception as ex:\n            if not self._is_shutting_down:\n                log.error(\"Error handling notification for method '%s': %s\", method, ex, exc_info=ex)\n"
  },
  {
    "path": "src/solidlsp/ls_request.py",
    "content": "from typing import TYPE_CHECKING, Any, Union\n\nfrom solidlsp.lsp_protocol_handler import lsp_types\n\nif TYPE_CHECKING:\n    from .ls_process import LanguageServerProcess\n\n\nclass LanguageServerRequest:\n    def __init__(self, handler: \"LanguageServerProcess\"):\n        self.handler = handler\n\n    def _send_request(self, method: str, params: Any | None = None) -> Any:\n        return self.handler.send_request(method, params)\n\n    def implementation(self, params: lsp_types.ImplementationParams) -> Union[\"lsp_types.Definition\", list[\"lsp_types.LocationLink\"], None]:\n        \"\"\"A request to resolve the implementation locations of a symbol at a given text\n        document position. The request's parameter is of type [TextDocumentPositionParams]\n        (#TextDocumentPositionParams) the response is of type {@link Definition} or a\n        Thenable that resolves to such.\n        \"\"\"\n        return self._send_request(\"textDocument/implementation\", params)\n\n    def type_definition(\n        self, params: lsp_types.TypeDefinitionParams\n    ) -> Union[\"lsp_types.Definition\", list[\"lsp_types.LocationLink\"], None]:\n        \"\"\"A request to resolve the type definition locations of a symbol at a given text\n        document position. The request's parameter is of type [TextDocumentPositionParams]\n        (#TextDocumentPositionParams) the response is of type {@link Definition} or a\n        Thenable that resolves to such.\n        \"\"\"\n        return self._send_request(\"textDocument/typeDefinition\", params)\n\n    def document_color(self, params: lsp_types.DocumentColorParams) -> list[\"lsp_types.ColorInformation\"]:\n        \"\"\"A request to list all color symbols found in a given text document. The request's\n        parameter is of type {@link DocumentColorParams} the\n        response is of type {@link ColorInformation ColorInformation[]} or a Thenable\n        that resolves to such.\n        \"\"\"\n        return self._send_request(\"textDocument/documentColor\", params)\n\n    def color_presentation(self, params: lsp_types.ColorPresentationParams) -> list[\"lsp_types.ColorPresentation\"]:\n        \"\"\"A request to list all presentation for a color. The request's\n        parameter is of type {@link ColorPresentationParams} the\n        response is of type {@link ColorInformation ColorInformation[]} or a Thenable\n        that resolves to such.\n        \"\"\"\n        return self._send_request(\"textDocument/colorPresentation\", params)\n\n    def folding_range(self, params: lsp_types.FoldingRangeParams) -> list[\"lsp_types.FoldingRange\"] | None:\n        \"\"\"A request to provide folding ranges in a document. The request's\n        parameter is of type {@link FoldingRangeParams}, the\n        response is of type {@link FoldingRangeList} or a Thenable\n        that resolves to such.\n        \"\"\"\n        return self._send_request(\"textDocument/foldingRange\", params)\n\n    def declaration(self, params: lsp_types.DeclarationParams) -> Union[\"lsp_types.Declaration\", list[\"lsp_types.LocationLink\"], None]:\n        \"\"\"A request to resolve the type definition locations of a symbol at a given text\n        document position. The request's parameter is of type [TextDocumentPositionParams]\n        (#TextDocumentPositionParams) the response is of type {@link Declaration}\n        or a typed array of {@link DeclarationLink} or a Thenable that resolves\n        to such.\n        \"\"\"\n        return self._send_request(\"textDocument/declaration\", params)\n\n    def selection_range(self, params: lsp_types.SelectionRangeParams) -> list[\"lsp_types.SelectionRange\"] | None:\n        \"\"\"A request to provide selection ranges in a document. The request's\n        parameter is of type {@link SelectionRangeParams}, the\n        response is of type {@link SelectionRange SelectionRange[]} or a Thenable\n        that resolves to such.\n        \"\"\"\n        return self._send_request(\"textDocument/selectionRange\", params)\n\n    def prepare_call_hierarchy(self, params: lsp_types.CallHierarchyPrepareParams) -> list[\"lsp_types.CallHierarchyItem\"] | None:\n        \"\"\"A request to result a `CallHierarchyItem` in a document at a given position.\n        Can be used as an input to an incoming or outgoing call hierarchy.\n\n        @since 3.16.0\n        \"\"\"\n        return self._send_request(\"textDocument/prepareCallHierarchy\", params)\n\n    def incoming_calls(self, params: lsp_types.CallHierarchyIncomingCallsParams) -> list[\"lsp_types.CallHierarchyIncomingCall\"] | None:\n        \"\"\"A request to resolve the incoming calls for a given `CallHierarchyItem`.\n\n        @since 3.16.0\n        \"\"\"\n        return self._send_request(\"callHierarchy/incomingCalls\", params)\n\n    def outgoing_calls(self, params: lsp_types.CallHierarchyOutgoingCallsParams) -> list[\"lsp_types.CallHierarchyOutgoingCall\"] | None:\n        \"\"\"A request to resolve the outgoing calls for a given `CallHierarchyItem`.\n\n        @since 3.16.0\n        \"\"\"\n        return self._send_request(\"callHierarchy/outgoingCalls\", params)\n\n    def semantic_tokens_full(self, params: lsp_types.SemanticTokensParams) -> Union[\"lsp_types.SemanticTokens\", None]:\n        \"\"\"@since 3.16.0\"\"\"\n        return self._send_request(\"textDocument/semanticTokens/full\", params)\n\n    def semantic_tokens_delta(\n        self, params: lsp_types.SemanticTokensDeltaParams\n    ) -> Union[\"lsp_types.SemanticTokens\", \"lsp_types.SemanticTokensDelta\", None]:\n        \"\"\"@since 3.16.0\"\"\"\n        return self._send_request(\"textDocument/semanticTokens/full/delta\", params)\n\n    def semantic_tokens_range(self, params: lsp_types.SemanticTokensRangeParams) -> Union[\"lsp_types.SemanticTokens\", None]:\n        \"\"\"@since 3.16.0\"\"\"\n        return self._send_request(\"textDocument/semanticTokens/range\", params)\n\n    def linked_editing_range(self, params: lsp_types.LinkedEditingRangeParams) -> Union[\"lsp_types.LinkedEditingRanges\", None]:\n        \"\"\"A request to provide ranges that can be edited together.\n\n        @since 3.16.0\n        \"\"\"\n        return self._send_request(\"textDocument/linkedEditingRange\", params)\n\n    def will_create_files(self, params: lsp_types.CreateFilesParams) -> Union[\"lsp_types.WorkspaceEdit\", None]:\n        \"\"\"The will create files request is sent from the client to the server before files are actually\n        created as long as the creation is triggered from within the client.\n\n        @since 3.16.0\n        \"\"\"\n        return self._send_request(\"workspace/willCreateFiles\", params)\n\n    def will_rename_files(self, params: lsp_types.RenameFilesParams) -> Union[\"lsp_types.WorkspaceEdit\", None]:\n        \"\"\"The will rename files request is sent from the client to the server before files are actually\n        renamed as long as the rename is triggered from within the client.\n\n        @since 3.16.0\n        \"\"\"\n        return self._send_request(\"workspace/willRenameFiles\", params)\n\n    def will_delete_files(self, params: lsp_types.DeleteFilesParams) -> Union[\"lsp_types.WorkspaceEdit\", None]:\n        \"\"\"The did delete files notification is sent from the client to the server when\n        files were deleted from within the client.\n\n        @since 3.16.0\n        \"\"\"\n        return self._send_request(\"workspace/willDeleteFiles\", params)\n\n    def moniker(self, params: lsp_types.MonikerParams) -> list[\"lsp_types.Moniker\"] | None:\n        \"\"\"A request to get the moniker of a symbol at a given text document position.\n        The request parameter is of type {@link TextDocumentPositionParams}.\n        The response is of type {@link Moniker Moniker[]} or `null`.\n        \"\"\"\n        return self._send_request(\"textDocument/moniker\", params)\n\n    def prepare_type_hierarchy(self, params: lsp_types.TypeHierarchyPrepareParams) -> list[\"lsp_types.TypeHierarchyItem\"] | None:\n        \"\"\"A request to result a `TypeHierarchyItem` in a document at a given position.\n        Can be used as an input to a subtypes or supertypes type hierarchy.\n\n        @since 3.17.0\n        \"\"\"\n        return self._send_request(\"textDocument/prepareTypeHierarchy\", params)\n\n    def type_hierarchy_supertypes(self, params: lsp_types.TypeHierarchySupertypesParams) -> list[\"lsp_types.TypeHierarchyItem\"] | None:\n        \"\"\"A request to resolve the supertypes for a given `TypeHierarchyItem`.\n\n        @since 3.17.0\n        \"\"\"\n        return self._send_request(\"typeHierarchy/supertypes\", params)\n\n    def type_hierarchy_subtypes(self, params: lsp_types.TypeHierarchySubtypesParams) -> list[\"lsp_types.TypeHierarchyItem\"] | None:\n        \"\"\"A request to resolve the subtypes for a given `TypeHierarchyItem`.\n\n        @since 3.17.0\n        \"\"\"\n        return self._send_request(\"typeHierarchy/subtypes\", params)\n\n    def inline_value(self, params: lsp_types.InlineValueParams) -> list[\"lsp_types.InlineValue\"] | None:\n        \"\"\"A request to provide inline values in a document. The request's parameter is of\n        type {@link InlineValueParams}, the response is of type\n        {@link InlineValue InlineValue[]} or a Thenable that resolves to such.\n\n        @since 3.17.0\n        \"\"\"\n        return self._send_request(\"textDocument/inlineValue\", params)\n\n    def inlay_hint(self, params: lsp_types.InlayHintParams) -> list[\"lsp_types.InlayHint\"] | None:\n        \"\"\"A request to provide inlay hints in a document. The request's parameter is of\n        type {@link InlayHintsParams}, the response is of type\n        {@link InlayHint InlayHint[]} or a Thenable that resolves to such.\n\n        @since 3.17.0\n        \"\"\"\n        return self._send_request(\"textDocument/inlayHint\", params)\n\n    def resolve_inlay_hint(self, params: lsp_types.InlayHint) -> \"lsp_types.InlayHint\":\n        \"\"\"A request to resolve additional properties for an inlay hint.\n        The request's parameter is of type {@link InlayHint}, the response is\n        of type {@link InlayHint} or a Thenable that resolves to such.\n\n        @since 3.17.0\n        \"\"\"\n        return self._send_request(\"inlayHint/resolve\", params)\n\n    def text_document_diagnostic(self, params: lsp_types.DocumentDiagnosticParams) -> \"lsp_types.DocumentDiagnosticReport\":\n        \"\"\"The document diagnostic request definition.\n\n        @since 3.17.0\n        \"\"\"\n        return self._send_request(\"textDocument/diagnostic\", params)\n\n    def workspace_diagnostic(self, params: lsp_types.WorkspaceDiagnosticParams) -> \"lsp_types.WorkspaceDiagnosticReport\":\n        \"\"\"The workspace diagnostic request definition.\n\n        @since 3.17.0\n        \"\"\"\n        return self._send_request(\"workspace/diagnostic\", params)\n\n    def initialize(self, params: lsp_types.InitializeParams) -> \"lsp_types.InitializeResult\":\n        \"\"\"The initialize request is sent from the client to the server.\n        It is sent once as the request after starting up the server.\n        The requests parameter is of type {@link InitializeParams}\n        the response if of type {@link InitializeResult} of a Thenable that\n        resolves to such.\n        \"\"\"\n        return self._send_request(\"initialize\", params)\n\n    def shutdown(self) -> None:\n        \"\"\"A shutdown request is sent from the client to the server.\n        It is sent once when the client decides to shutdown the\n        server. The only notification that is sent after a shutdown request\n        is the exit event.\n        \"\"\"\n        return self._send_request(\"shutdown\")\n\n    def will_save_wait_until(self, params: lsp_types.WillSaveTextDocumentParams) -> list[\"lsp_types.TextEdit\"] | None:\n        \"\"\"A document will save request is sent from the client to the server before\n        the document is actually saved. The request can return an array of TextEdits\n        which will be applied to the text document before it is saved. Please note that\n        clients might drop results if computing the text edits took too long or if a\n        server constantly fails on this request. This is done to keep the save fast and\n        reliable.\n        \"\"\"\n        return self._send_request(\"textDocument/willSaveWaitUntil\", params)\n\n    def completion(self, params: lsp_types.CompletionParams) -> Union[list[\"lsp_types.CompletionItem\"], \"lsp_types.CompletionList\", None]:\n        \"\"\"Request to request completion at a given text document position. The request's\n        parameter is of type {@link TextDocumentPosition} the response\n        is of type {@link CompletionItem CompletionItem[]} or {@link CompletionList}\n        or a Thenable that resolves to such.\n\n        The request can delay the computation of the {@link CompletionItem.detail `detail`}\n        and {@link CompletionItem.documentation `documentation`} properties to the `completionItem/resolve`\n        request. However, properties that are needed for the initial sorting and filtering, like `sortText`,\n        `filterText`, `insertText`, and `textEdit`, must not be changed during resolve.\n        \"\"\"\n        return self._send_request(\"textDocument/completion\", params)\n\n    def resolve_completion_item(self, params: lsp_types.CompletionItem) -> \"lsp_types.CompletionItem\":\n        \"\"\"Request to resolve additional information for a given completion item.The request's\n        parameter is of type {@link CompletionItem} the response\n        is of type {@link CompletionItem} or a Thenable that resolves to such.\n        \"\"\"\n        return self._send_request(\"completionItem/resolve\", params)\n\n    def hover(self, params: lsp_types.HoverParams) -> Union[\"lsp_types.Hover\", None]:\n        \"\"\"Request to request hover information at a given text document position. The request's\n        parameter is of type {@link TextDocumentPosition} the response is of\n        type {@link Hover} or a Thenable that resolves to such.\n        \"\"\"\n        return self._send_request(\"textDocument/hover\", params)\n\n    def signature_help(self, params: lsp_types.SignatureHelpParams) -> Union[\"lsp_types.SignatureHelp\", None]:\n        return self._send_request(\"textDocument/signatureHelp\", params)\n\n    def definition(self, params: lsp_types.DefinitionParams) -> Union[\"lsp_types.Definition\", list[\"lsp_types.LocationLink\"], None]:\n        \"\"\"A request to resolve the definition location of a symbol at a given text\n        document position. The request's parameter is of type [TextDocumentPosition]\n        (#TextDocumentPosition) the response is of either type {@link Definition}\n        or a typed array of {@link DefinitionLink} or a Thenable that resolves\n        to such.\n        \"\"\"\n        return self._send_request(\"textDocument/definition\", params)\n\n    def references(self, params: lsp_types.ReferenceParams) -> list[\"lsp_types.Location\"] | None:\n        \"\"\"A request to resolve project-wide references for the symbol denoted\n        by the given text document position. The request's parameter is of\n        type {@link ReferenceParams} the response is of type\n        {@link Location Location[]} or a Thenable that resolves to such.\n        \"\"\"\n        return self._send_request(\"textDocument/references\", params)\n\n    def document_highlight(self, params: lsp_types.DocumentHighlightParams) -> list[\"lsp_types.DocumentHighlight\"] | None:\n        \"\"\"Request to resolve a {@link DocumentHighlight} for a given\n        text document position. The request's parameter is of type [TextDocumentPosition]\n        (#TextDocumentPosition) the request response is of type [DocumentHighlight[]]\n        (#DocumentHighlight) or a Thenable that resolves to such.\n        \"\"\"\n        return self._send_request(\"textDocument/documentHighlight\", params)\n\n    def document_symbol(\n        self, params: lsp_types.DocumentSymbolParams\n    ) -> list[\"lsp_types.SymbolInformation\"] | list[\"lsp_types.DocumentSymbol\"] | None:\n        \"\"\"A request to list all symbols found in a given text document. The request's\n        parameter is of type {@link TextDocumentIdentifier} the\n        response is of type {@link SymbolInformation SymbolInformation[]} or a Thenable\n        that resolves to such.\n        \"\"\"\n        return self._send_request(\"textDocument/documentSymbol\", params)\n\n    def code_action(self, params: lsp_types.CodeActionParams) -> list[Union[\"lsp_types.Command\", \"lsp_types.CodeAction\"]] | None:\n        \"\"\"A request to provide commands for the given text document and range.\"\"\"\n        return self._send_request(\"textDocument/codeAction\", params)\n\n    def resolve_code_action(self, params: lsp_types.CodeAction) -> \"lsp_types.CodeAction\":\n        \"\"\"Request to resolve additional information for a given code action.The request's\n        parameter is of type {@link CodeAction} the response\n        is of type {@link CodeAction} or a Thenable that resolves to such.\n        \"\"\"\n        return self._send_request(\"codeAction/resolve\", params)\n\n    def workspace_symbol(\n        self, params: lsp_types.WorkspaceSymbolParams\n    ) -> list[\"lsp_types.SymbolInformation\"] | list[\"lsp_types.WorkspaceSymbol\"] | None:\n        \"\"\"A request to list project-wide symbols matching the query string given\n        by the {@link WorkspaceSymbolParams}. The response is\n        of type {@link SymbolInformation SymbolInformation[]} or a Thenable that\n        resolves to such.\n\n        @since 3.17.0 - support for WorkspaceSymbol in the returned data. Clients\n         need to advertise support for WorkspaceSymbols via the client capability\n         `workspace.symbol.resolveSupport`.\n        \"\"\"\n        return self._send_request(\"workspace/symbol\", params)\n\n    def resolve_workspace_symbol(self, params: lsp_types.WorkspaceSymbol) -> \"lsp_types.WorkspaceSymbol\":\n        \"\"\"A request to resolve the range inside the workspace\n        symbol's location.\n\n        @since 3.17.0\n        \"\"\"\n        return self._send_request(\"workspaceSymbol/resolve\", params)\n\n    def code_lens(self, params: lsp_types.CodeLensParams) -> list[\"lsp_types.CodeLens\"] | None:\n        \"\"\"A request to provide code lens for the given text document.\"\"\"\n        return self._send_request(\"textDocument/codeLens\", params)\n\n    def resolve_code_lens(self, params: lsp_types.CodeLens) -> \"lsp_types.CodeLens\":\n        \"\"\"A request to resolve a command for a given code lens.\"\"\"\n        return self._send_request(\"codeLens/resolve\", params)\n\n    def document_link(self, params: lsp_types.DocumentLinkParams) -> list[\"lsp_types.DocumentLink\"] | None:\n        \"\"\"A request to provide document links\"\"\"\n        return self._send_request(\"textDocument/documentLink\", params)\n\n    def resolve_document_link(self, params: lsp_types.DocumentLink) -> \"lsp_types.DocumentLink\":\n        \"\"\"Request to resolve additional information for a given document link. The request's\n        parameter is of type {@link DocumentLink} the response\n        is of type {@link DocumentLink} or a Thenable that resolves to such.\n        \"\"\"\n        return self._send_request(\"documentLink/resolve\", params)\n\n    def formatting(self, params: lsp_types.DocumentFormattingParams) -> list[\"lsp_types.TextEdit\"] | None:\n        \"\"\"A request to to format a whole document.\"\"\"\n        return self._send_request(\"textDocument/formatting\", params)\n\n    def range_formatting(self, params: lsp_types.DocumentRangeFormattingParams) -> list[\"lsp_types.TextEdit\"] | None:\n        \"\"\"A request to to format a range in a document.\"\"\"\n        return self._send_request(\"textDocument/rangeFormatting\", params)\n\n    def on_type_formatting(self, params: lsp_types.DocumentOnTypeFormattingParams) -> list[\"lsp_types.TextEdit\"] | None:\n        \"\"\"A request to format a document on type.\"\"\"\n        return self._send_request(\"textDocument/onTypeFormatting\", params)\n\n    def rename(self, params: lsp_types.RenameParams) -> Union[\"lsp_types.WorkspaceEdit\", None]:\n        \"\"\"A request to rename a symbol.\"\"\"\n        return self._send_request(\"textDocument/rename\", params)\n\n    def prepare_rename(self, params: lsp_types.PrepareRenameParams) -> Union[\"lsp_types.PrepareRenameResult\", None]:\n        \"\"\"A request to test and perform the setup necessary for a rename.\n\n        @since 3.16 - support for default behavior\n        \"\"\"\n        return self._send_request(\"textDocument/prepareRename\", params)\n\n    def execute_command(self, params: lsp_types.ExecuteCommandParams) -> Union[\"lsp_types.LSPAny\", None]:\n        \"\"\"A request send from the client to the server to execute a command. The request might return\n        a workspace edit which the client will apply to the workspace.\n        \"\"\"\n        return self._send_request(\"workspace/executeCommand\", params)\n"
  },
  {
    "path": "src/solidlsp/ls_types.py",
    "content": "\"\"\"\nDefines wrapper objects around the types returned by LSP to ensure decoupling between LSP versions and SolidLSP\n\"\"\"\n\nfrom __future__ import annotations\n\nfrom enum import Enum, IntEnum\nfrom typing import TYPE_CHECKING, NotRequired, Union\n\nfrom typing_extensions import TypedDict\n\nfrom solidlsp.lsp_protocol_handler.lsp_types import DiagnosticSeverity\n\nif TYPE_CHECKING:\n    from .ls import SymbolBody\n\n\nURI = str\nDocumentUri = str\nUint = int\nRegExp = str\n\n\nclass Position(TypedDict):\n    r\"\"\"Position in a text document expressed as zero-based line and character\n    offset. Prior to 3.17 the offsets were always based on a UTF-16 string\n    representation. So a string of the form `a𐐀b` the character offset of the\n    character `a` is 0, the character offset of `𐐀` is 1 and the character\n    offset of b is 3 since `𐐀` is represented using two code units in UTF-16.\n    Since 3.17 clients and servers can agree on a different string encoding\n    representation (e.g. UTF-8). The client announces it's supported encoding\n    via the client capability [`general.positionEncodings`](#clientCapabilities).\n    The value is an array of position encodings the client supports, with\n    decreasing preference (e.g. the encoding at index `0` is the most preferred\n    one). To stay backwards compatible the only mandatory encoding is UTF-16\n    represented via the string `utf-16`. The server can pick one of the\n    encodings offered by the client and signals that encoding back to the\n    client via the initialize result's property\n    [`capabilities.positionEncoding`](#serverCapabilities). If the string value\n    `utf-16` is missing from the client's capability `general.positionEncodings`\n    servers can safely assume that the client supports UTF-16. If the server\n    omits the position encoding in its initialize result the encoding defaults\n    to the string value `utf-16`. Implementation considerations: since the\n    conversion from one encoding into another requires the content of the\n    file / line the conversion is best done where the file is read which is\n    usually on the server side.\n\n    Positions are line end character agnostic. So you can not specify a position\n    that denotes `\\r|\\n` or `\\n|` where `|` represents the character offset.\n\n    @since 3.17.0 - support for negotiated position encoding.\n    \"\"\"\n\n    line: Uint\n    \"\"\" Line position in a document (zero-based).\n\n    If a line number is greater than the number of lines in a document, it defaults back to the number of lines in the document.\n    If a line number is negative, it defaults to 0. \"\"\"\n    character: Uint\n    \"\"\" Character offset on a line in a document (zero-based).\n\n    The meaning of this offset is determined by the negotiated\n    `PositionEncodingKind`.\n\n    If the character value is greater than the line length it defaults back to the\n    line length. \"\"\"\n\n\nclass Range(TypedDict):\n    \"\"\"A range in a text document expressed as (zero-based) start and end positions.\n\n    If you want to specify a range that contains a line including the line ending\n    character(s) then use an end position denoting the start of the next line.\n    For example:\n    ```ts\n    {\n        start: { line: 5, character: 23 }\n        end : { line 6, character : 0 }\n    }\n    ```\n    \"\"\"\n\n    start: Position\n    \"\"\" The range's start position. \"\"\"\n    end: Position\n    \"\"\" The range's end position. \"\"\"\n\n\nclass Location(TypedDict):\n    \"\"\"Represents a location inside a resource, such as a line\n    inside a text file.\n    \"\"\"\n\n    uri: DocumentUri\n    range: Range\n    absolutePath: str\n    relativePath: str | None\n\n\nclass CompletionItemKind(IntEnum):\n    \"\"\"The kind of a completion entry.\"\"\"\n\n    Text = 1\n    Method = 2\n    Function = 3\n    Constructor = 4\n    Field = 5\n    Variable = 6\n    Class = 7\n    Interface = 8\n    Module = 9\n    Property = 10\n    Unit = 11\n    Value = 12\n    Enum = 13\n    Keyword = 14\n    Snippet = 15\n    Color = 16\n    File = 17\n    Reference = 18\n    Folder = 19\n    EnumMember = 20\n    Constant = 21\n    Struct = 22\n    Event = 23\n    Operator = 24\n    TypeParameter = 25\n\n\nclass CompletionItem(TypedDict):\n    \"\"\"A completion item represents a text snippet that is\n    proposed to complete text that is being typed.\n    \"\"\"\n\n    completionText: str\n    \"\"\" The completionText of this completion item.\n\n    The completionText property is also by default the text that\n    is inserted when selecting this completion.\"\"\"\n\n    kind: CompletionItemKind\n    \"\"\" The kind of this completion item. Based of the kind\n    an icon is chosen by the editor. \"\"\"\n\n    detail: NotRequired[str]\n    \"\"\" A human-readable string with additional information\n    about this item, like type or symbol information. \"\"\"\n\n\nclass SymbolKind(IntEnum):\n    \"\"\"A symbol kind.\"\"\"\n\n    # TODO: This is a duplicate of SymbolKind in lsp_types.\n\n    File = 1\n    Module = 2\n    Namespace = 3\n    Package = 4\n    Class = 5\n    Method = 6\n    Property = 7\n    Field = 8\n    Constructor = 9\n    Enum = 10\n    Interface = 11\n    Function = 12\n    Variable = 13\n    Constant = 14\n    String = 15\n    Number = 16\n    Boolean = 17\n    Array = 18\n    Object = 19\n    Key = 20\n    Null = 21\n    EnumMember = 22\n    Struct = 23\n    Event = 24\n    Operator = 25\n    TypeParameter = 26\n\n\nclass SymbolTag(IntEnum):\n    \"\"\"Symbol tags are extra annotations that tweak the rendering of a symbol.\n\n    @since 3.16\n    \"\"\"\n\n    Deprecated = 1\n    \"\"\" Render a symbol as obsolete, usually using a strike-out. \"\"\"\n\n\nclass UnifiedSymbolInformation(TypedDict):\n    \"\"\"\n    Represents information about programming constructs like variables, classes,\n    interfaces etc.\n\n    This is a unifying extension of `lsp_types.SymbolInformation` and `lsp_types.DocumentSymbol`,\n    with added fields for SolidLSP/Serena use.\n    \"\"\"\n\n    deprecated: NotRequired[bool]\n    \"\"\" Indicates if this symbol is deprecated.\n\n    @deprecated Use tags instead \"\"\"\n    location: NotRequired[Location]\n    \"\"\" The location of this symbol. The location's range is used by a tool\n    to reveal the location in the editor. If the symbol is selected in the\n    tool the range's start information is used to position the cursor. So\n    the range usually spans more than the actual symbol's name and does\n    normally include things like visibility modifiers.\n\n    The range doesn't have to denote a node range in the sense of an abstract\n    syntax tree. It can therefore not be used to re-construct a hierarchy of\n    the symbols. \"\"\"\n    name: str\n    \"\"\" The name of this symbol. \"\"\"\n    kind: SymbolKind\n    \"\"\" The kind of this symbol. \"\"\"\n    tags: NotRequired[list[SymbolTag]]\n    \"\"\" Tags for this symbol.\n\n    @since 3.16.0 \"\"\"\n    containerName: NotRequired[str]\n    \"\"\" The name of the symbol containing this symbol. This information is for\n    user interface purposes (e.g. to render a qualifier in the user interface\n    if necessary). It can't be used to re-infer a hierarchy for the document\n    symbols. \n    \n    Note: within Serena, the parent attribute was added and should be used instead. \n    Most LS don't provide containerName.\n    \"\"\"\n\n    detail: NotRequired[str]\n    \"\"\" More detail for this symbol, e.g the signature of a function. \"\"\"\n\n    range: NotRequired[Range]\n    \"\"\" The range enclosing this symbol not including leading/trailing whitespace but everything else\n    like comments. This information is typically used to determine if the clients cursor is\n    inside the symbol to reveal in the symbol in the UI. \"\"\"\n    selectionRange: NotRequired[Range]\n    \"\"\" The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.\n    Must be contained by the `range`. \"\"\"\n\n    body: NotRequired[\"SymbolBody\"]\n    \"\"\" The body of the symbol. \"\"\"\n\n    children: list[UnifiedSymbolInformation]\n    \"\"\" The children of the symbol. \n    Added to be compatible with `lsp_types.DocumentSymbol`, \n    since it is sometimes useful to have the children of the symbol as a user-facing feature.\"\"\"\n\n    parent: NotRequired[UnifiedSymbolInformation | None]\n    \"\"\"The parent of the symbol, if there is any. Added with Serena, not part of the LSP.\n    All symbols except the root packages will have a parent.\n    \"\"\"\n\n    overload_idx: NotRequired[int]\n    \"\"\"\n    The overload index of the symbol, if applicable. If a symbol does not have overloads, this field is omitted.\n    If the symbol is an overloaded function or method (same symbol name with the same parent), \n    this index indicates which overload it is. The index is 0-based.\n    Added for Serena, not part of the LSP.\n    \"\"\"\n\n\nclass MarkupKind(Enum):\n    \"\"\"Describes the content type that a client supports in various\n    result literals like `Hover`, `ParameterInfo` or `CompletionItem`.\n\n    Please note that `MarkupKinds` must not start with a `$`. This kinds\n    are reserved for internal usage.\n    \"\"\"\n\n    PlainText = \"plaintext\"\n    \"\"\" Plain text is supported as a content format \"\"\"\n    Markdown = \"markdown\"\n    \"\"\" Markdown is supported as a content format \"\"\"\n\n\nclass __MarkedString_Type_1(TypedDict):\n    language: str\n    value: str\n\n\nMarkedString = Union[str, \"__MarkedString_Type_1\"]\n\"\"\" MarkedString can be used to render human readable text. It is either a markdown string\nor a code-block that provides a language and a code snippet. The language identifier\nis semantically equal to the optional language identifier in fenced code blocks in GitHub\nissues. See https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting\n\nThe pair of a language and a value is an equivalent to markdown:\n```${language}\n${value}\n```\n\nNote that markdown strings will be sanitized - that means html will be escaped.\n@deprecated use MarkupContent instead. \"\"\"\n\n\nclass MarkupContent(TypedDict):\n    r\"\"\"A `MarkupContent` literal represents a string value which content is interpreted base on its\n    kind flag. Currently the protocol supports `plaintext` and `markdown` as markup kinds.\n\n    If the kind is `markdown` then the value can contain fenced code blocks like in GitHub issues.\n    See https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting\n\n    Here is an example how such a string can be constructed using JavaScript / TypeScript:\n    ```ts\n    let markdown: MarkdownContent = {\n     kind: MarkupKind.Markdown,\n     value: [\n       '# Header',\n       'Some text',\n       '```typescript',\n       'someCode();',\n       '```'\n     ].join('\\n')\n    };\n    ```\n\n    *Please Note* that clients might sanitize the return markdown. A client could decide to\n    remove HTML from the markdown to avoid script execution.\n    \"\"\"\n\n    kind: MarkupKind\n    \"\"\" The type of the Markup \"\"\"\n    value: str\n    \"\"\" The content itself \"\"\"\n\n\nclass Hover(TypedDict):\n    \"\"\"The result of a hover request.\"\"\"\n\n    contents: MarkupContent | MarkedString | list[MarkedString]\n    \"\"\" The hover's content \"\"\"\n    range: NotRequired[Range]\n    \"\"\" An optional range inside the text document that is used to\n    visualize the hover, e.g. by changing the background color. \"\"\"\n\n\nclass TextDocumentIdentifier(TypedDict):\n    \"\"\"A literal to identify a text document in the client.\"\"\"\n\n    uri: DocumentUri\n    \"\"\" The text document's uri. \"\"\"\n\n\nclass TextEdit(TypedDict):\n    \"\"\"A textual edit applicable to a text document.\"\"\"\n\n    range: Range\n    \"\"\" The range of the text document to be manipulated. \"\"\"\n    newText: str\n    \"\"\" The string to be inserted. For delete operations use an empty string. \"\"\"\n\n\nclass WorkspaceEdit(TypedDict):\n    \"\"\"A workspace edit represents changes to many resources managed in the workspace.\"\"\"\n\n    changes: NotRequired[dict[DocumentUri, list[TextEdit]]]\n    \"\"\" Holds changes to existing resources. \"\"\"\n    documentChanges: NotRequired[list]\n    \"\"\" Document changes array for versioned edits. \"\"\"\n\n\nclass Diagnostic(TypedDict):\n    \"\"\"Diagnostic information for a text document.\"\"\"\n\n    uri: DocumentUri\n    \"\"\" The URI of the text document to which the diagnostics apply. \"\"\"\n    range: Range\n    \"\"\" The range of the text document to which the diagnostics apply. \"\"\"\n    severity: NotRequired[DiagnosticSeverity]\n    \"\"\" The severity of the diagnostic. \"\"\"\n    message: str\n    \"\"\" The diagnostic message. \"\"\"\n    code: str\n    \"\"\" The code of the diagnostic. \"\"\"\n    source: NotRequired[str]\n    \"\"\" The source of the diagnostic, e.g. the name of the tool that produced it. \"\"\"\n\n\nclass SignatureHelp(TypedDict):\n    \"\"\"\n    Signature help represents the signature of something\n    callable. There can be multiple signature but only one\n    active and only one active parameter.\n\n    See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#signatureHelp\n    \"\"\"\n\n    signatures: list[SignatureInformation]\n    \"\"\" One or more signatures. \"\"\"\n    activeSignature: NotRequired[int]\n    \"\"\" The active signature. If omitted or the value lies outside the\n    range of `signatures` the value defaults to zero or is ignored if\n    the `SignatureHelp` has no signatures.\n\n    Whenever possible implementers should make an active decision about\n    the active signature and shouldn't rely on a default value.\n\n    In future version of the protocol this property might become\n    mandatory to better express this. \"\"\"\n    activeParameter: NotRequired[int]\n    \"\"\" The active parameter of the active signature. If omitted or the value\n    lies outside the range of `signatures[activeSignature].parameters`\n    defaults to 0 if the active signature has parameters. If\n    the active signature has no parameters it is ignored.\n    In future version of the protocol this property might become\n    mandatory to better express the active parameter if the\n    active signature does have any. \"\"\"\n\n\nclass SignatureInformation(TypedDict):\n    \"\"\"Represents the signature of something callable. A signature\n    can have a label, like a function-name, a doc-comment, and\n    a set of parameters.\n    \"\"\"\n\n    label: str\n    \"\"\" The label of this signature. Will be shown in\n    the UI. \"\"\"\n    documentation: NotRequired[MarkupContent | str]\n    \"\"\" The human-readable doc-comment of this signature. Will be shown\n    in the UI but can be omitted. \"\"\"\n    parameters: NotRequired[list[ParameterInformation]]\n    \"\"\" The parameters of this signature. \"\"\"\n    activeParameter: NotRequired[int]\n    \"\"\" The index of the active parameter.\n\n    If provided, this is used in place of `SignatureHelp.activeParameter`.\n\n    @since 3.16.0 \"\"\"\n\n\nclass ParameterInformation(TypedDict):\n    \"\"\"Represents a parameter of a callable-signature. A parameter can\n    have a label and a doc-comment.\n    \"\"\"\n\n    label: str | list[int]\n    \"\"\" The label of this parameter information.\n\n    Either a string or an inclusive start and exclusive end offsets within its containing\n    signature label. (see SignatureInformation.label). The offsets are based on a UTF-16\n    string representation as `Position` and `Range` does.\n\n    *Note*: a label of type string should be a substring of its containing signature label.\n    Its intended use case is to highlight the parameter label part in the `SignatureInformation.label`. \"\"\"\n    documentation: NotRequired[MarkupContent | str]\n    \"\"\" The human-readable doc-comment of this parameter. Will be shown\n    in the UI but can be omitted. \"\"\"\n"
  },
  {
    "path": "src/solidlsp/ls_utils.py",
    "content": "\"\"\"\nThis file contains various utility functions like I/O operations, handling paths, etc.\n\"\"\"\n\nimport gzip\nimport logging\nimport os\nimport platform\nimport shutil\nimport subprocess\nimport uuid\nimport zipfile\nfrom enum import Enum\nfrom pathlib import Path, PurePath\n\nimport charset_normalizer\nimport requests\n\nfrom solidlsp.ls_exceptions import SolidLSPException\nfrom solidlsp.ls_types import UnifiedSymbolInformation\n\nlog = logging.getLogger(__name__)\n\n\nclass InvalidTextLocationError(Exception):\n    pass\n\n\nclass TextUtils:\n    \"\"\"\n    Utilities for text operations.\n    \"\"\"\n\n    @staticmethod\n    def get_line_col_from_index(text: str, index: int) -> tuple[int, int]:\n        \"\"\"\n        Returns the zero-indexed line and column number of the given index in the given text\n        \"\"\"\n        l = 0\n        c = 0\n        idx = 0\n        while idx < index:\n            if text[idx] == \"\\n\":\n                l += 1\n                c = 0\n            else:\n                c += 1\n            idx += 1\n\n        return l, c\n\n    @staticmethod\n    def get_index_from_line_col(text: str, line: int, col: int) -> int:\n        \"\"\"\n        Returns the index of the given zero-indexed line and column number in the given text\n        \"\"\"\n        idx = 0\n        while line > 0:\n            if idx >= len(text):\n                raise InvalidTextLocationError\n            if text[idx] == \"\\n\":\n                line -= 1\n            idx += 1\n        idx += col\n        return idx\n\n    @staticmethod\n    def _get_updated_position_from_line_and_column_and_edit(l: int, c: int, text_to_be_inserted: str) -> tuple[int, int]:\n        \"\"\"\n        Utility function to get the position of the cursor after inserting text at a given line and column.\n        \"\"\"\n        num_newlines_in_gen_text = text_to_be_inserted.count(\"\\n\")\n        if num_newlines_in_gen_text > 0:\n            l += num_newlines_in_gen_text\n            c = len(text_to_be_inserted.split(\"\\n\")[-1])\n        else:\n            c += len(text_to_be_inserted)\n        return (l, c)\n\n    @staticmethod\n    def delete_text_between_positions(text: str, start_line: int, start_col: int, end_line: int, end_col: int) -> tuple[str, str]:\n        \"\"\"\n        Deletes the text between the given start and end positions.\n        Returns the modified text and the deleted text.\n        \"\"\"\n        del_start_idx = TextUtils.get_index_from_line_col(text, start_line, start_col)\n        del_end_idx = TextUtils.get_index_from_line_col(text, end_line, end_col)\n\n        deleted_text = text[del_start_idx:del_end_idx]\n        new_text = text[:del_start_idx] + text[del_end_idx:]\n        return new_text, deleted_text\n\n    @staticmethod\n    def insert_text_at_position(text: str, line: int, col: int, text_to_be_inserted: str) -> tuple[str, int, int]:\n        \"\"\"\n        Inserts the given text at the given line and column.\n        Returns the modified text and the new line and column.\n        \"\"\"\n        try:\n            change_index = TextUtils.get_index_from_line_col(text, line, col)\n        except InvalidTextLocationError:\n            num_lines_in_text = text.count(\"\\n\") + 1\n            max_line = num_lines_in_text - 1\n            if line == max_line + 1 and col == 0:  # trying to insert at new line after full text\n                # insert at end, adding missing newline\n                change_index = len(text)\n                text_to_be_inserted = \"\\n\" + text_to_be_inserted\n            else:\n                raise\n        new_text = text[:change_index] + text_to_be_inserted + text[change_index:]\n        new_l, new_c = TextUtils._get_updated_position_from_line_and_column_and_edit(line, col, text_to_be_inserted)\n        return new_text, new_l, new_c\n\n\nclass PathUtils:\n    \"\"\"\n    Utilities for platform-agnostic path operations.\n    \"\"\"\n\n    @staticmethod\n    def uri_to_path(uri: str) -> str:\n        \"\"\"\n        Converts a URI to a file path. Works on both Linux and Windows.\n\n        This method was obtained from https://stackoverflow.com/a/61922504\n        \"\"\"\n        try:\n            from urllib.parse import unquote, urlparse\n            from urllib.request import url2pathname\n        except ImportError:\n            # backwards compatibility (Python 2)\n            from urllib.parse import unquote as unquote_py2\n            from urllib.request import url2pathname as url2pathname_py2\n\n            from urlparse import urlparse as urlparse_py2\n\n            unquote = unquote_py2\n            url2pathname = url2pathname_py2\n            urlparse = urlparse_py2\n        parsed = urlparse(uri)\n        host = f\"{os.path.sep}{os.path.sep}{parsed.netloc}{os.path.sep}\"\n        path = os.path.normpath(os.path.join(host, url2pathname(unquote(parsed.path))))\n        return path\n\n    @staticmethod\n    def path_to_uri(path: str) -> str:\n        \"\"\"\n        Converts a file path to a file URI (file:///...).\n        \"\"\"\n        return str(Path(path).absolute().as_uri())\n\n    @staticmethod\n    def is_glob_pattern(pattern: str) -> bool:\n        \"\"\"Check if a pattern contains glob-specific characters.\"\"\"\n        return any(c in pattern for c in \"*?[]!\")\n\n    @staticmethod\n    def get_relative_path(path: str, base_path: str) -> str | None:\n        \"\"\"\n        Gets relative path if it's possible (paths should be on the same drive),\n        returns `None` otherwise.\n        \"\"\"\n        if PurePath(path).drive == PurePath(base_path).drive:\n            rel_path = str(PurePath(os.path.relpath(path, base_path)))\n            return rel_path\n        return None\n\n\nclass FileUtils:\n    \"\"\"\n    Utility functions for file operations.\n    \"\"\"\n\n    @staticmethod\n    def read_file(file_path: str, encoding: str) -> str:\n        \"\"\"\n        Reads the file at the given path using the given encoding and returns the contents as a string.\n        If decoding fails, tries to detect the encoding using charset_normalizer.\n\n        Raises FileNotFoundError if the file does not exist.\n        \"\"\"\n        if not os.path.exists(file_path):\n            log.error(f\"Failed to read '{file_path}': File does not exist.\")\n            raise FileNotFoundError(f\"File read '{file_path}' failed: File does not exist.\")\n        try:\n            try:\n                with open(file_path, encoding=encoding) as inp_file:\n                    return inp_file.read()\n            except UnicodeDecodeError as ude:\n                results = charset_normalizer.from_path(file_path)\n                match = results.best()\n                if match:\n                    log.warning(\n                        f\"Could not decode {file_path} with encoding='{encoding}'; using best match '{match.encoding}' instead\",\n                    )\n                    return match.raw.decode(match.encoding)\n                raise ude\n        except Exception as exc:\n            log.error(f\"Failed to read '{file_path}' with encoding '{encoding}': {exc}\")\n            raise exc\n\n    @staticmethod\n    def download_file(url: str, target_path: str) -> None:\n        \"\"\"\n        Downloads the file from the given URL to the given {target_path}\n        \"\"\"\n        os.makedirs(os.path.dirname(target_path), exist_ok=True)\n        try:\n            response = requests.get(url, stream=True, timeout=60)\n            if response.status_code != 200:\n                log.error(f\"Error downloading file '{url}': {response.status_code} {response.text}\")\n                raise SolidLSPException(\"Error downloading file.\")\n            with open(target_path, \"wb\") as f:\n                shutil.copyfileobj(response.raw, f)\n        except Exception as exc:\n            log.error(f\"Error downloading file '{url}': {exc}\")\n            raise SolidLSPException(\"Error downloading file.\") from None\n\n    @staticmethod\n    def download_and_extract_archive(url: str, target_path: str, archive_type: str) -> None:\n        \"\"\"\n        Downloads the archive from the given URL having format {archive_type} and extracts it to the given {target_path}\n        \"\"\"\n        try:\n            tmp_files = []\n            tmp_file_name = str(PurePath(os.path.expanduser(\"~\"), \"solidlsp_tmp\", uuid.uuid4().hex))\n            tmp_files.append(tmp_file_name)\n            os.makedirs(os.path.dirname(tmp_file_name), exist_ok=True)\n            FileUtils.download_file(url, tmp_file_name)\n            if archive_type in [\"tar\", \"gztar\", \"bztar\", \"xztar\"]:\n                os.makedirs(target_path, exist_ok=True)\n                shutil.unpack_archive(tmp_file_name, target_path, archive_type)\n            elif archive_type == \"zip\":\n                os.makedirs(target_path, exist_ok=True)\n                with zipfile.ZipFile(tmp_file_name, \"r\") as zip_ref:\n                    for zip_info in zip_ref.infolist():\n                        extracted_path = zip_ref.extract(zip_info, target_path)\n                        ZIP_SYSTEM_UNIX = 3  # zip file created on Unix system\n                        if zip_info.create_system != ZIP_SYSTEM_UNIX:\n                            continue\n                        # extractall() does not preserve permissions\n                        # see. https://github.com/python/cpython/issues/59999\n                        attrs = (zip_info.external_attr >> 16) & 0o777\n                        if attrs:\n                            os.chmod(extracted_path, attrs)\n            elif archive_type == \"zip.gz\":\n                os.makedirs(target_path, exist_ok=True)\n                tmp_file_name_ungzipped = tmp_file_name + \".zip\"\n                tmp_files.append(tmp_file_name_ungzipped)\n                with gzip.open(tmp_file_name, \"rb\") as f_in, open(tmp_file_name_ungzipped, \"wb\") as f_out:\n                    shutil.copyfileobj(f_in, f_out)\n                shutil.unpack_archive(tmp_file_name_ungzipped, target_path, \"zip\")\n            elif archive_type == \"gz\":\n                with gzip.open(tmp_file_name, \"rb\") as f_in, open(target_path, \"wb\") as f_out:\n                    shutil.copyfileobj(f_in, f_out)\n            elif archive_type == \"binary\":\n                # For single binary files, just move to target without extraction\n                shutil.move(tmp_file_name, target_path)\n            else:\n                log.error(f\"Unknown archive type '{archive_type}' for extraction\")\n                raise SolidLSPException(f\"Unknown archive type '{archive_type}'\")\n        except Exception as exc:\n            log.error(f\"Error extracting archive '{tmp_file_name}' obtained from '{url}': {exc}\")\n            raise SolidLSPException(\"Error extracting archive.\") from exc\n        finally:\n            for tmp_file_name in tmp_files:\n                if os.path.exists(tmp_file_name):\n                    Path.unlink(Path(tmp_file_name))\n\n\nclass PlatformId(str, Enum):\n    WIN_x86 = \"win-x86\"\n    WIN_x64 = \"win-x64\"\n    WIN_arm64 = \"win-arm64\"\n    OSX = \"osx\"\n    OSX_x64 = \"osx-x64\"\n    OSX_arm64 = \"osx-arm64\"\n    LINUX_x86 = \"linux-x86\"\n    LINUX_x64 = \"linux-x64\"\n    LINUX_arm64 = \"linux-arm64\"\n    LINUX_MUSL_x64 = \"linux-musl-x64\"\n    LINUX_MUSL_arm64 = \"linux-musl-arm64\"\n\n    def is_windows(self) -> bool:\n        return self.value.startswith(\"win\")\n\n\nclass DotnetVersion(str, Enum):\n    V4 = \"4\"\n    V6 = \"6\"\n    V7 = \"7\"\n    V8 = \"8\"\n    V9 = \"9\"\n    VMONO = \"mono\"\n\n\nclass PlatformUtils:\n    \"\"\"\n    This class provides utilities for platform detection and identification.\n    \"\"\"\n\n    @classmethod\n    def get_platform_id(cls) -> PlatformId:\n        \"\"\"\n        Returns the platform id for the current system\n        \"\"\"\n        system = platform.system()\n        machine = platform.machine()\n        bitness = platform.architecture()[0]\n        if system == \"Windows\" and machine == \"\":\n            machine = cls._determine_windows_machine_type()\n        system_map = {\"Windows\": \"win\", \"Darwin\": \"osx\", \"Linux\": \"linux\"}\n        machine_map = {\n            \"AMD64\": \"x64\",\n            \"x86_64\": \"x64\",\n            \"i386\": \"x86\",\n            \"i686\": \"x86\",\n            \"aarch64\": \"arm64\",\n            \"arm64\": \"arm64\",\n            \"ARM64\": \"arm64\",\n        }\n        if system in system_map and machine in machine_map:\n            platform_id = system_map[system] + \"-\" + machine_map[machine]\n            if system == \"Linux\" and bitness == \"64bit\":\n                libc = platform.libc_ver()[0]\n                if libc != \"glibc\":\n                    # Format: linux-musl-arch (e.g., linux-musl-arm64)\n                    platform_id = f\"{system_map[system]}-{libc}-{machine_map[machine]}\"\n            return PlatformId(platform_id)\n        else:\n            raise SolidLSPException(f\"Unknown platform: {system=}, {machine=}, {bitness=}\")\n\n    @staticmethod\n    def _determine_windows_machine_type() -> str:\n        import ctypes\n        from ctypes import wintypes\n\n        class SYSTEM_INFO(ctypes.Structure):\n            class _U(ctypes.Union):\n                class _S(ctypes.Structure):\n                    _fields_ = [(\"wProcessorArchitecture\", wintypes.WORD), (\"wReserved\", wintypes.WORD)]\n\n                _fields_ = [(\"dwOemId\", wintypes.DWORD), (\"s\", _S)]\n                _anonymous_ = (\"s\",)\n\n            _fields_ = [\n                (\"u\", _U),\n                (\"dwPageSize\", wintypes.DWORD),\n                (\"lpMinimumApplicationAddress\", wintypes.LPVOID),\n                (\"lpMaximumApplicationAddress\", wintypes.LPVOID),\n                (\"dwActiveProcessorMask\", wintypes.LPVOID),\n                (\"dwNumberOfProcessors\", wintypes.DWORD),\n                (\"dwProcessorType\", wintypes.DWORD),\n                (\"dwAllocationGranularity\", wintypes.DWORD),\n                (\"wProcessorLevel\", wintypes.WORD),\n                (\"wProcessorRevision\", wintypes.WORD),\n            ]\n            _anonymous_ = (\"u\",)\n\n        sys_info = SYSTEM_INFO()\n        ctypes.windll.kernel32.GetNativeSystemInfo(ctypes.byref(sys_info))  # type: ignore\n\n        arch_map = {\n            9: \"AMD64\",\n            5: \"ARM\",\n            12: \"arm64\",\n            6: \"Intel Itanium-based\",\n            0: \"i386\",\n        }\n\n        return arch_map.get(sys_info.wProcessorArchitecture, f\"Unknown ({sys_info.wProcessorArchitecture})\")\n\n    @staticmethod\n    def get_dotnet_version() -> DotnetVersion:\n        \"\"\"\n        Returns the dotnet version for the current system\n        \"\"\"\n        try:\n            result = subprocess.run([\"dotnet\", \"--list-runtimes\"], capture_output=True, check=True)\n            available_version_cmd_output = []\n            for line in result.stdout.decode(\"utf-8\").split(\"\\n\"):\n                if line.startswith(\"Microsoft.NETCore.App\"):\n                    version_cmd_output = line.split(\" \")[1]\n                    available_version_cmd_output.append(version_cmd_output)\n\n            if not available_version_cmd_output:\n                raise SolidLSPException(\"dotnet not found on the system\")\n\n            # Check for supported versions in order of preference (latest first)\n            for version_cmd_output in available_version_cmd_output:\n                if version_cmd_output.startswith(\"9\"):\n                    return DotnetVersion.V9\n                if version_cmd_output.startswith(\"8\"):\n                    return DotnetVersion.V8\n                if version_cmd_output.startswith(\"7\"):\n                    return DotnetVersion.V7\n                if version_cmd_output.startswith(\"6\"):\n                    return DotnetVersion.V6\n                if version_cmd_output.startswith(\"4\"):\n                    return DotnetVersion.V4\n\n            # If no supported version found, raise exception with all available versions\n            raise SolidLSPException(\n                f\"No supported dotnet version found. Available versions: {', '.join(available_version_cmd_output)}. Supported versions: 4, 6, 7, 8\"\n            )\n        except (FileNotFoundError, subprocess.CalledProcessError):\n            try:\n                result = subprocess.run([\"mono\", \"--version\"], capture_output=True, check=True)\n                return DotnetVersion.VMONO\n            except (FileNotFoundError, subprocess.CalledProcessError):\n                raise SolidLSPException(\"dotnet or mono not found on the system\")\n\n\nclass SymbolUtils:\n    @staticmethod\n    def symbol_tree_contains_name(roots: list[UnifiedSymbolInformation], name: str) -> bool:\n        \"\"\"\n        Check if any symbol in the tree has a name matching the given name.\n        \"\"\"\n        for symbol in roots:\n            if symbol[\"name\"] == name:\n                return True\n            if SymbolUtils.symbol_tree_contains_name(symbol[\"children\"], name):\n                return True\n        return False\n"
  },
  {
    "path": "src/solidlsp/lsp_protocol_handler/lsp_constants.py",
    "content": "\"\"\"\nThis module contains constants used in the LSP protocol.\n\"\"\"\n\n\nclass LSPConstants:\n    \"\"\"\n    This class contains constants used in the LSP protocol.\n    \"\"\"\n\n    # the key for uri used to represent paths\n    URI = \"uri\"\n\n    # the key for range, which is a from and to position within a text document\n    RANGE = \"range\"\n\n    # A key used in LocationLink type, used as the span of the origin link\n    ORIGIN_SELECTION_RANGE = \"originSelectionRange\"\n\n    # A key used in LocationLink type, used as the target uri of the link\n    TARGET_URI = \"targetUri\"\n\n    # A key used in LocationLink type, used as the target range of the link\n    TARGET_RANGE = \"targetRange\"\n\n    # A key used in LocationLink type, used as the target selection range of the link\n    TARGET_SELECTION_RANGE = \"targetSelectionRange\"\n\n    # key for the textDocument field in the request\n    TEXT_DOCUMENT = \"textDocument\"\n\n    # key used to represent the language a document is in - \"java\", \"csharp\", etc.\n    LANGUAGE_ID = \"languageId\"\n\n    # key used to represent the version of a document (a shared value between the client and server)\n    VERSION = \"version\"\n\n    # key used to represent the text of a document being sent from the client to the server on open\n    TEXT = \"text\"\n\n    # key used to represent a position (line and colnum) within a text document\n    POSITION = \"position\"\n\n    # key used to represent the line number of a position\n    LINE = \"line\"\n\n    # key used to represent the column number of a position\n    CHARACTER = \"character\"\n\n    # key used to represent the changes made to a document\n    CONTENT_CHANGES = \"contentChanges\"\n\n    # key used to represent name of symbols\n    NAME = \"name\"\n\n    # key used to represent the kind of symbols\n    KIND = \"kind\"\n\n    # key used to represent children in document symbols\n    CHILDREN = \"children\"\n\n    # key used to represent the location in symbols\n    LOCATION = \"location\"\n\n    # Severity level of the diagnostic\n    SEVERITY = \"severity\"\n\n    # The message of the diagnostic\n    MESSAGE = \"message\"\n"
  },
  {
    "path": "src/solidlsp/lsp_protocol_handler/lsp_requests.py",
    "content": "# Code generated. DO NOT EDIT.\n# LSP v3.17.0\n# TODO: Look into use of https://pypi.org/project/ts2python/ to generate the types for https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/\n\n\"\"\"\nThis file provides the python interface corresponding to the requests and notifications defined in Typescript in the language server protocol.\nThis file is obtained from https://github.com/predragnikolic/OLSP under the MIT License with the following terms:\n\nMIT License\n\nCopyright (c) 2023 Предраг Николић\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\"\"\"\n\nfrom typing import Any, Union\n\nfrom solidlsp.lsp_protocol_handler import lsp_types\n\n\nclass LspRequest:\n    def __init__(self, send_request: Any) -> None:\n        self.send_request = send_request\n\n    async def implementation(\n        self, params: lsp_types.ImplementationParams\n    ) -> Union[\"lsp_types.Definition\", list[\"lsp_types.LocationLink\"], None]:\n        \"\"\"A request to resolve the implementation locations of a symbol at a given text\n        document position. The request's parameter is of type [TextDocumentPositionParams]\n        (#TextDocumentPositionParams) the response is of type {@link Definition} or a\n        Thenable that resolves to such.\n        \"\"\"\n        return await self.send_request(\"textDocument/implementation\", params)\n\n    async def type_definition(\n        self, params: lsp_types.TypeDefinitionParams\n    ) -> Union[\"lsp_types.Definition\", list[\"lsp_types.LocationLink\"], None]:\n        \"\"\"A request to resolve the type definition locations of a symbol at a given text\n        document position. The request's parameter is of type [TextDocumentPositionParams]\n        (#TextDocumentPositionParams) the response is of type {@link Definition} or a\n        Thenable that resolves to such.\n        \"\"\"\n        return await self.send_request(\"textDocument/typeDefinition\", params)\n\n    async def document_color(self, params: lsp_types.DocumentColorParams) -> list[\"lsp_types.ColorInformation\"]:\n        \"\"\"A request to list all color symbols found in a given text document. The request's\n        parameter is of type {@link DocumentColorParams} the\n        response is of type {@link ColorInformation ColorInformation[]} or a Thenable\n        that resolves to such.\n        \"\"\"\n        return await self.send_request(\"textDocument/documentColor\", params)\n\n    async def color_presentation(self, params: lsp_types.ColorPresentationParams) -> list[\"lsp_types.ColorPresentation\"]:\n        \"\"\"A request to list all presentation for a color. The request's\n        parameter is of type {@link ColorPresentationParams} the\n        response is of type {@link ColorInformation ColorInformation[]} or a Thenable\n        that resolves to such.\n        \"\"\"\n        return await self.send_request(\"textDocument/colorPresentation\", params)\n\n    async def folding_range(self, params: lsp_types.FoldingRangeParams) -> list[\"lsp_types.FoldingRange\"] | None:\n        \"\"\"A request to provide folding ranges in a document. The request's\n        parameter is of type {@link FoldingRangeParams}, the\n        response is of type {@link FoldingRangeList} or a Thenable\n        that resolves to such.\n        \"\"\"\n        return await self.send_request(\"textDocument/foldingRange\", params)\n\n    async def declaration(\n        self, params: lsp_types.DeclarationParams\n    ) -> Union[\"lsp_types.Declaration\", list[\"lsp_types.LocationLink\"], None]:\n        \"\"\"A request to resolve the type definition locations of a symbol at a given text\n        document position. The request's parameter is of type [TextDocumentPositionParams]\n        (#TextDocumentPositionParams) the response is of type {@link Declaration}\n        or a typed array of {@link DeclarationLink} or a Thenable that resolves\n        to such.\n        \"\"\"\n        return await self.send_request(\"textDocument/declaration\", params)\n\n    async def selection_range(self, params: lsp_types.SelectionRangeParams) -> list[\"lsp_types.SelectionRange\"] | None:\n        \"\"\"A request to provide selection ranges in a document. The request's\n        parameter is of type {@link SelectionRangeParams}, the\n        response is of type {@link SelectionRange SelectionRange[]} or a Thenable\n        that resolves to such.\n        \"\"\"\n        return await self.send_request(\"textDocument/selectionRange\", params)\n\n    async def prepare_call_hierarchy(self, params: lsp_types.CallHierarchyPrepareParams) -> list[\"lsp_types.CallHierarchyItem\"] | None:\n        \"\"\"A request to result a `CallHierarchyItem` in a document at a given position.\n        Can be used as an input to an incoming or outgoing call hierarchy.\n\n        @since 3.16.0\n        \"\"\"\n        return await self.send_request(\"textDocument/prepareCallHierarchy\", params)\n\n    async def incoming_calls(\n        self, params: lsp_types.CallHierarchyIncomingCallsParams\n    ) -> list[\"lsp_types.CallHierarchyIncomingCall\"] | None:\n        \"\"\"A request to resolve the incoming calls for a given `CallHierarchyItem`.\n\n        @since 3.16.0\n        \"\"\"\n        return await self.send_request(\"callHierarchy/incomingCalls\", params)\n\n    async def outgoing_calls(\n        self, params: lsp_types.CallHierarchyOutgoingCallsParams\n    ) -> list[\"lsp_types.CallHierarchyOutgoingCall\"] | None:\n        \"\"\"A request to resolve the outgoing calls for a given `CallHierarchyItem`.\n\n        @since 3.16.0\n        \"\"\"\n        return await self.send_request(\"callHierarchy/outgoingCalls\", params)\n\n    async def semantic_tokens_full(self, params: lsp_types.SemanticTokensParams) -> Union[\"lsp_types.SemanticTokens\", None]:\n        \"\"\"@since 3.16.0\"\"\"\n        return await self.send_request(\"textDocument/semanticTokens/full\", params)\n\n    async def semantic_tokens_delta(\n        self, params: lsp_types.SemanticTokensDeltaParams\n    ) -> Union[\"lsp_types.SemanticTokens\", \"lsp_types.SemanticTokensDelta\", None]:\n        \"\"\"@since 3.16.0\"\"\"\n        return await self.send_request(\"textDocument/semanticTokens/full/delta\", params)\n\n    async def semantic_tokens_range(self, params: lsp_types.SemanticTokensRangeParams) -> Union[\"lsp_types.SemanticTokens\", None]:\n        \"\"\"@since 3.16.0\"\"\"\n        return await self.send_request(\"textDocument/semanticTokens/range\", params)\n\n    async def linked_editing_range(self, params: lsp_types.LinkedEditingRangeParams) -> Union[\"lsp_types.LinkedEditingRanges\", None]:\n        \"\"\"A request to provide ranges that can be edited together.\n\n        @since 3.16.0\n        \"\"\"\n        return await self.send_request(\"textDocument/linkedEditingRange\", params)\n\n    async def will_create_files(self, params: lsp_types.CreateFilesParams) -> Union[\"lsp_types.WorkspaceEdit\", None]:\n        \"\"\"The will create files request is sent from the client to the server before files are actually\n        created as long as the creation is triggered from within the client.\n\n        @since 3.16.0\n        \"\"\"\n        return await self.send_request(\"workspace/willCreateFiles\", params)\n\n    async def will_rename_files(self, params: lsp_types.RenameFilesParams) -> Union[\"lsp_types.WorkspaceEdit\", None]:\n        \"\"\"The will rename files request is sent from the client to the server before files are actually\n        renamed as long as the rename is triggered from within the client.\n\n        @since 3.16.0\n        \"\"\"\n        return await self.send_request(\"workspace/willRenameFiles\", params)\n\n    async def will_delete_files(self, params: lsp_types.DeleteFilesParams) -> Union[\"lsp_types.WorkspaceEdit\", None]:\n        \"\"\"The did delete files notification is sent from the client to the server when\n        files were deleted from within the client.\n\n        @since 3.16.0\n        \"\"\"\n        return await self.send_request(\"workspace/willDeleteFiles\", params)\n\n    async def moniker(self, params: lsp_types.MonikerParams) -> list[\"lsp_types.Moniker\"] | None:\n        \"\"\"A request to get the moniker of a symbol at a given text document position.\n        The request parameter is of type {@link TextDocumentPositionParams}.\n        The response is of type {@link Moniker Moniker[]} or `null`.\n        \"\"\"\n        return await self.send_request(\"textDocument/moniker\", params)\n\n    async def prepare_type_hierarchy(self, params: lsp_types.TypeHierarchyPrepareParams) -> list[\"lsp_types.TypeHierarchyItem\"] | None:\n        \"\"\"A request to result a `TypeHierarchyItem` in a document at a given position.\n        Can be used as an input to a subtypes or supertypes type hierarchy.\n\n        @since 3.17.0\n        \"\"\"\n        return await self.send_request(\"textDocument/prepareTypeHierarchy\", params)\n\n    async def type_hierarchy_supertypes(\n        self, params: lsp_types.TypeHierarchySupertypesParams\n    ) -> list[\"lsp_types.TypeHierarchyItem\"] | None:\n        \"\"\"A request to resolve the supertypes for a given `TypeHierarchyItem`.\n\n        @since 3.17.0\n        \"\"\"\n        return await self.send_request(\"typeHierarchy/supertypes\", params)\n\n    async def type_hierarchy_subtypes(self, params: lsp_types.TypeHierarchySubtypesParams) -> list[\"lsp_types.TypeHierarchyItem\"] | None:\n        \"\"\"A request to resolve the subtypes for a given `TypeHierarchyItem`.\n\n        @since 3.17.0\n        \"\"\"\n        return await self.send_request(\"typeHierarchy/subtypes\", params)\n\n    async def inline_value(self, params: lsp_types.InlineValueParams) -> list[\"lsp_types.InlineValue\"] | None:\n        \"\"\"A request to provide inline values in a document. The request's parameter is of\n        type {@link InlineValueParams}, the response is of type\n        {@link InlineValue InlineValue[]} or a Thenable that resolves to such.\n\n        @since 3.17.0\n        \"\"\"\n        return await self.send_request(\"textDocument/inlineValue\", params)\n\n    async def inlay_hint(self, params: lsp_types.InlayHintParams) -> list[\"lsp_types.InlayHint\"] | None:\n        \"\"\"A request to provide inlay hints in a document. The request's parameter is of\n        type {@link InlayHintsParams}, the response is of type\n        {@link InlayHint InlayHint[]} or a Thenable that resolves to such.\n\n        @since 3.17.0\n        \"\"\"\n        return await self.send_request(\"textDocument/inlayHint\", params)\n\n    async def resolve_inlay_hint(self, params: lsp_types.InlayHint) -> \"lsp_types.InlayHint\":\n        \"\"\"A request to resolve additional properties for an inlay hint.\n        The request's parameter is of type {@link InlayHint}, the response is\n        of type {@link InlayHint} or a Thenable that resolves to such.\n\n        @since 3.17.0\n        \"\"\"\n        return await self.send_request(\"inlayHint/resolve\", params)\n\n    async def text_document_diagnostic(self, params: lsp_types.DocumentDiagnosticParams) -> \"lsp_types.DocumentDiagnosticReport\":\n        \"\"\"The document diagnostic request definition.\n\n        @since 3.17.0\n        \"\"\"\n        return await self.send_request(\"textDocument/diagnostic\", params)\n\n    async def workspace_diagnostic(self, params: lsp_types.WorkspaceDiagnosticParams) -> \"lsp_types.WorkspaceDiagnosticReport\":\n        \"\"\"The workspace diagnostic request definition.\n\n        @since 3.17.0\n        \"\"\"\n        return await self.send_request(\"workspace/diagnostic\", params)\n\n    async def initialize(self, params: lsp_types.InitializeParams) -> \"lsp_types.InitializeResult\":\n        \"\"\"The initialize request is sent from the client to the server.\n        It is sent once as the request after starting up the server.\n        The requests parameter is of type {@link InitializeParams}\n        the response if of type {@link InitializeResult} of a Thenable that\n        resolves to such.\n        \"\"\"\n        return await self.send_request(\"initialize\", params)\n\n    async def shutdown(self) -> None:\n        \"\"\"A shutdown request is sent from the client to the server.\n        It is sent once when the client decides to shutdown the\n        server. The only notification that is sent after a shutdown request\n        is the exit event.\n        \"\"\"\n        return await self.send_request(\"shutdown\")\n\n    async def will_save_wait_until(self, params: lsp_types.WillSaveTextDocumentParams) -> list[\"lsp_types.TextEdit\"] | None:\n        \"\"\"A document will save request is sent from the client to the server before\n        the document is actually saved. The request can return an array of TextEdits\n        which will be applied to the text document before it is saved. Please note that\n        clients might drop results if computing the text edits took too long or if a\n        server constantly fails on this request. This is done to keep the save fast and\n        reliable.\n        \"\"\"\n        return await self.send_request(\"textDocument/willSaveWaitUntil\", params)\n\n    async def completion(\n        self, params: lsp_types.CompletionParams\n    ) -> Union[list[\"lsp_types.CompletionItem\"], \"lsp_types.CompletionList\", None]:\n        \"\"\"Request to request completion at a given text document position. The request's\n        parameter is of type {@link TextDocumentPosition} the response\n        is of type {@link CompletionItem CompletionItem[]} or {@link CompletionList}\n        or a Thenable that resolves to such.\n\n        The request can delay the computation of the {@link CompletionItem.detail `detail`}\n        and {@link CompletionItem.documentation `documentation`} properties to the `completionItem/resolve`\n        request. However, properties that are needed for the initial sorting and filtering, like `sortText`,\n        `filterText`, `insertText`, and `textEdit`, must not be changed during resolve.\n        \"\"\"\n        return await self.send_request(\"textDocument/completion\", params)\n\n    async def resolve_completion_item(self, params: lsp_types.CompletionItem) -> \"lsp_types.CompletionItem\":\n        \"\"\"Request to resolve additional information for a given completion item.The request's\n        parameter is of type {@link CompletionItem} the response\n        is of type {@link CompletionItem} or a Thenable that resolves to such.\n        \"\"\"\n        return await self.send_request(\"completionItem/resolve\", params)\n\n    async def hover(self, params: lsp_types.HoverParams) -> Union[\"lsp_types.Hover\", None]:\n        \"\"\"Request to request hover information at a given text document position. The request's\n        parameter is of type {@link TextDocumentPosition} the response is of\n        type {@link Hover} or a Thenable that resolves to such.\n        \"\"\"\n        return await self.send_request(\"textDocument/hover\", params)\n\n    async def signature_help(self, params: lsp_types.SignatureHelpParams) -> Union[\"lsp_types.SignatureHelp\", None]:\n        return await self.send_request(\"textDocument/signatureHelp\", params)\n\n    async def definition(self, params: lsp_types.DefinitionParams) -> Union[\"lsp_types.Definition\", list[\"lsp_types.LocationLink\"], None]:\n        \"\"\"A request to resolve the definition location of a symbol at a given text\n        document position. The request's parameter is of type [TextDocumentPosition]\n        (#TextDocumentPosition) the response is of either type {@link Definition}\n        or a typed array of {@link DefinitionLink} or a Thenable that resolves\n        to such.\n        \"\"\"\n        return await self.send_request(\"textDocument/definition\", params)\n\n    async def references(self, params: lsp_types.ReferenceParams) -> list[\"lsp_types.Location\"] | None:\n        \"\"\"A request to resolve project-wide references for the symbol denoted\n        by the given text document position. The request's parameter is of\n        type {@link ReferenceParams} the response is of type\n        {@link Location Location[]} or a Thenable that resolves to such.\n        \"\"\"\n        return await self.send_request(\"textDocument/references\", params)\n\n    async def document_highlight(self, params: lsp_types.DocumentHighlightParams) -> list[\"lsp_types.DocumentHighlight\"] | None:\n        \"\"\"Request to resolve a {@link DocumentHighlight} for a given\n        text document position. The request's parameter is of type [TextDocumentPosition]\n        (#TextDocumentPosition) the request response is of type [DocumentHighlight[]]\n        (#DocumentHighlight) or a Thenable that resolves to such.\n        \"\"\"\n        return await self.send_request(\"textDocument/documentHighlight\", params)\n\n    async def document_symbol(\n        self, params: lsp_types.DocumentSymbolParams\n    ) -> list[\"lsp_types.SymbolInformation\"] | list[\"lsp_types.DocumentSymbol\"] | None:\n        \"\"\"A request to list all symbols found in a given text document. The request's\n        parameter is of type {@link TextDocumentIdentifier} the\n        response is of type {@link SymbolInformation SymbolInformation[]} or a Thenable\n        that resolves to such.\n        \"\"\"\n        return await self.send_request(\"textDocument/documentSymbol\", params)\n\n    async def code_action(self, params: lsp_types.CodeActionParams) -> list[Union[\"lsp_types.Command\", \"lsp_types.CodeAction\"]] | None:\n        \"\"\"A request to provide commands for the given text document and range.\"\"\"\n        return await self.send_request(\"textDocument/codeAction\", params)\n\n    async def resolve_code_action(self, params: lsp_types.CodeAction) -> \"lsp_types.CodeAction\":\n        \"\"\"Request to resolve additional information for a given code action.The request's\n        parameter is of type {@link CodeAction} the response\n        is of type {@link CodeAction} or a Thenable that resolves to such.\n        \"\"\"\n        return await self.send_request(\"codeAction/resolve\", params)\n\n    async def workspace_symbol(\n        self, params: lsp_types.WorkspaceSymbolParams\n    ) -> list[\"lsp_types.SymbolInformation\"] | list[\"lsp_types.WorkspaceSymbol\"] | None:\n        \"\"\"A request to list project-wide symbols matching the query string given\n        by the {@link WorkspaceSymbolParams}. The response is\n        of type {@link SymbolInformation SymbolInformation[]} or a Thenable that\n        resolves to such.\n\n        @since 3.17.0 - support for WorkspaceSymbol in the returned data. Clients\n         need to advertise support for WorkspaceSymbols via the client capability\n         `workspace.symbol.resolveSupport`.\n        \"\"\"\n        return await self.send_request(\"workspace/symbol\", params)\n\n    async def resolve_workspace_symbol(self, params: lsp_types.WorkspaceSymbol) -> \"lsp_types.WorkspaceSymbol\":\n        \"\"\"A request to resolve the range inside the workspace\n        symbol's location.\n\n        @since 3.17.0\n        \"\"\"\n        return await self.send_request(\"workspaceSymbol/resolve\", params)\n\n    async def code_lens(self, params: lsp_types.CodeLensParams) -> list[\"lsp_types.CodeLens\"] | None:\n        \"\"\"A request to provide code lens for the given text document.\"\"\"\n        return await self.send_request(\"textDocument/codeLens\", params)\n\n    async def resolve_code_lens(self, params: lsp_types.CodeLens) -> \"lsp_types.CodeLens\":\n        \"\"\"A request to resolve a command for a given code lens.\"\"\"\n        return await self.send_request(\"codeLens/resolve\", params)\n\n    async def document_link(self, params: lsp_types.DocumentLinkParams) -> list[\"lsp_types.DocumentLink\"] | None:\n        \"\"\"A request to provide document links\"\"\"\n        return await self.send_request(\"textDocument/documentLink\", params)\n\n    async def resolve_document_link(self, params: lsp_types.DocumentLink) -> \"lsp_types.DocumentLink\":\n        \"\"\"Request to resolve additional information for a given document link. The request's\n        parameter is of type {@link DocumentLink} the response\n        is of type {@link DocumentLink} or a Thenable that resolves to such.\n        \"\"\"\n        return await self.send_request(\"documentLink/resolve\", params)\n\n    async def formatting(self, params: lsp_types.DocumentFormattingParams) -> list[\"lsp_types.TextEdit\"] | None:\n        \"\"\"A request to to format a whole document.\"\"\"\n        return await self.send_request(\"textDocument/formatting\", params)\n\n    async def range_formatting(self, params: lsp_types.DocumentRangeFormattingParams) -> list[\"lsp_types.TextEdit\"] | None:\n        \"\"\"A request to to format a range in a document.\"\"\"\n        return await self.send_request(\"textDocument/rangeFormatting\", params)\n\n    async def on_type_formatting(self, params: lsp_types.DocumentOnTypeFormattingParams) -> list[\"lsp_types.TextEdit\"] | None:\n        \"\"\"A request to format a document on type.\"\"\"\n        return await self.send_request(\"textDocument/onTypeFormatting\", params)\n\n    async def rename(self, params: lsp_types.RenameParams) -> Union[\"lsp_types.WorkspaceEdit\", None]:\n        \"\"\"A request to rename a symbol.\"\"\"\n        return await self.send_request(\"textDocument/rename\", params)\n\n    async def prepare_rename(self, params: lsp_types.PrepareRenameParams) -> Union[\"lsp_types.PrepareRenameResult\", None]:\n        \"\"\"A request to test and perform the setup necessary for a rename.\n\n        @since 3.16 - support for default behavior\n        \"\"\"\n        return await self.send_request(\"textDocument/prepareRename\", params)\n\n    async def execute_command(self, params: lsp_types.ExecuteCommandParams) -> Union[\"lsp_types.LSPAny\", None]:\n        \"\"\"A request send from the client to the server to execute a command. The request might return\n        a workspace edit which the client will apply to the workspace.\n        \"\"\"\n        return await self.send_request(\"workspace/executeCommand\", params)\n\n\nclass LspNotification:\n    def __init__(self, send_notification: Any) -> None:\n        self.send_notification = send_notification\n\n    def did_change_workspace_folders(self, params: lsp_types.DidChangeWorkspaceFoldersParams) -> None:\n        \"\"\"The `workspace/didChangeWorkspaceFolders` notification is sent from the client to the server when the workspace\n        folder configuration changes.\n        \"\"\"\n        return self.send_notification(\"workspace/didChangeWorkspaceFolders\", params)\n\n    def cancel_work_done_progress(self, params: lsp_types.WorkDoneProgressCancelParams) -> None:\n        \"\"\"The `window/workDoneProgress/cancel` notification is sent from  the client to the server to cancel a progress\n        initiated on the server side.\n        \"\"\"\n        return self.send_notification(\"window/workDoneProgress/cancel\", params)\n\n    def did_create_files(self, params: lsp_types.CreateFilesParams) -> None:\n        \"\"\"The did create files notification is sent from the client to the server when\n        files were created from within the client.\n\n        @since 3.16.0\n        \"\"\"\n        return self.send_notification(\"workspace/didCreateFiles\", params)\n\n    def did_rename_files(self, params: lsp_types.RenameFilesParams) -> None:\n        \"\"\"The did rename files notification is sent from the client to the server when\n        files were renamed from within the client.\n\n        @since 3.16.0\n        \"\"\"\n        return self.send_notification(\"workspace/didRenameFiles\", params)\n\n    def did_delete_files(self, params: lsp_types.DeleteFilesParams) -> None:\n        \"\"\"The will delete files request is sent from the client to the server before files are actually\n        deleted as long as the deletion is triggered from within the client.\n\n        @since 3.16.0\n        \"\"\"\n        return self.send_notification(\"workspace/didDeleteFiles\", params)\n\n    def did_open_notebook_document(self, params: lsp_types.DidOpenNotebookDocumentParams) -> None:\n        \"\"\"A notification sent when a notebook opens.\n\n        @since 3.17.0\n        \"\"\"\n        return self.send_notification(\"notebookDocument/didOpen\", params)\n\n    def did_change_notebook_document(self, params: lsp_types.DidChangeNotebookDocumentParams) -> None:\n        return self.send_notification(\"notebookDocument/didChange\", params)\n\n    def did_save_notebook_document(self, params: lsp_types.DidSaveNotebookDocumentParams) -> None:\n        \"\"\"A notification sent when a notebook document is saved.\n\n        @since 3.17.0\n        \"\"\"\n        return self.send_notification(\"notebookDocument/didSave\", params)\n\n    def did_close_notebook_document(self, params: lsp_types.DidCloseNotebookDocumentParams) -> None:\n        \"\"\"A notification sent when a notebook closes.\n\n        @since 3.17.0\n        \"\"\"\n        return self.send_notification(\"notebookDocument/didClose\", params)\n\n    def initialized(self, params: lsp_types.InitializedParams) -> None:\n        \"\"\"The initialized notification is sent from the client to the\n        server after the client is fully initialized and the server\n        is allowed to send requests from the server to the client.\n        \"\"\"\n        return self.send_notification(\"initialized\", params)\n\n    def exit(self) -> None:\n        \"\"\"The exit event is sent from the client to the server to\n        ask the server to exit its process.\n        \"\"\"\n        return self.send_notification(\"exit\")\n\n    def workspace_did_change_configuration(self, params: lsp_types.DidChangeConfigurationParams) -> None:\n        \"\"\"The configuration change notification is sent from the client to the server\n        when the client's configuration has changed. The notification contains\n        the changed configuration as defined by the language client.\n        \"\"\"\n        return self.send_notification(\"workspace/didChangeConfiguration\", params)\n\n    def did_open_text_document(self, params: lsp_types.DidOpenTextDocumentParams) -> None:\n        \"\"\"The document open notification is sent from the client to the server to signal\n        newly opened text documents. The document's truth is now managed by the client\n        and the server must not try to read the document's truth using the document's\n        uri. Open in this sense means it is managed by the client. It doesn't necessarily\n        mean that its content is presented in an editor. An open notification must not\n        be sent more than once without a corresponding close notification send before.\n        This means open and close notification must be balanced and the max open count\n        is one.\n        \"\"\"\n        return self.send_notification(\"textDocument/didOpen\", params)\n\n    def did_change_text_document(self, params: lsp_types.DidChangeTextDocumentParams) -> None:\n        \"\"\"The document change notification is sent from the client to the server to signal\n        changes to a text document.\n        \"\"\"\n        return self.send_notification(\"textDocument/didChange\", params)\n\n    def did_close_text_document(self, params: lsp_types.DidCloseTextDocumentParams) -> None:\n        \"\"\"The document close notification is sent from the client to the server when\n        the document got closed in the client. The document's truth now exists where\n        the document's uri points to (e.g. if the document's uri is a file uri the\n        truth now exists on disk). As with the open notification the close notification\n        is about managing the document's content. Receiving a close notification\n        doesn't mean that the document was open in an editor before. A close\n        notification requires a previous open notification to be sent.\n        \"\"\"\n        return self.send_notification(\"textDocument/didClose\", params)\n\n    def did_save_text_document(self, params: lsp_types.DidSaveTextDocumentParams) -> None:\n        \"\"\"The document save notification is sent from the client to the server when\n        the document got saved in the client.\n        \"\"\"\n        return self.send_notification(\"textDocument/didSave\", params)\n\n    def will_save_text_document(self, params: lsp_types.WillSaveTextDocumentParams) -> None:\n        \"\"\"A document will save notification is sent from the client to the server before\n        the document is actually saved.\n        \"\"\"\n        return self.send_notification(\"textDocument/willSave\", params)\n\n    def did_change_watched_files(self, params: lsp_types.DidChangeWatchedFilesParams) -> None:\n        \"\"\"The watched files notification is sent from the client to the server when\n        the client detects changes to file watched by the language client.\n        \"\"\"\n        return self.send_notification(\"workspace/didChangeWatchedFiles\", params)\n\n    def set_trace(self, params: lsp_types.SetTraceParams) -> None:\n        return self.send_notification(\"$/setTrace\", params)\n\n    def cancel_request(self, params: lsp_types.CancelParams) -> None:\n        return self.send_notification(\"$/cancelRequest\", params)\n\n    def progress(self, params: lsp_types.ProgressParams) -> None:\n        return self.send_notification(\"$/progress\", params)\n"
  },
  {
    "path": "src/solidlsp/lsp_protocol_handler/lsp_types.py",
    "content": "# Code generated. DO NOT EDIT.\n# LSP v3.17.0\n# TODO: Look into use of https://pypi.org/project/ts2python/ to generate the types for https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/\n\n\"\"\"\nThis file provides the Python types corresponding to the Typescript types defined in the language server protocol.\nThis file is obtained from https://github.com/predragnikolic/OLSP under the MIT License with the following terms:\n\nMIT License\n\nCopyright (c) 2023 Предраг Николић\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\"\"\"\n\nfrom enum import Enum, IntEnum, IntFlag\nfrom typing import Literal, NotRequired, Union\n\nfrom typing_extensions import TypedDict\n\nURI = str\nDocumentUri = str\nUint = int\nRegExp = str\n\n\nclass SemanticTokenTypes(Enum):\n    \"\"\"A set of predefined token types. This set is not fixed\n    an clients can specify additional token types via the\n    corresponding client capabilities.\n\n    @since 3.16.0\n    \"\"\"\n\n    Namespace = \"namespace\"\n    Type = \"type\"\n    \"\"\" Represents a generic type. Acts as a fallback for types which can't be mapped to\n    a specific type like class or enum. \"\"\"\n    Class = \"class\"\n    Enum = \"enum\"\n    Interface = \"interface\"\n    Struct = \"struct\"\n    TypeParameter = \"typeParameter\"\n    Parameter = \"parameter\"\n    Variable = \"variable\"\n    Property = \"property\"\n    EnumMember = \"enumMember\"\n    Event = \"event\"\n    Function = \"function\"\n    Method = \"method\"\n    Macro = \"macro\"\n    Keyword = \"keyword\"\n    Modifier = \"modifier\"\n    Comment = \"comment\"\n    String = \"string\"\n    Number = \"number\"\n    Regexp = \"regexp\"\n    Operator = \"operator\"\n    Decorator = \"decorator\"\n    \"\"\" @since 3.17.0 \"\"\"\n\n\nclass SemanticTokenModifiers(Enum):\n    \"\"\"A set of predefined token modifiers. This set is not fixed\n    an clients can specify additional token types via the\n    corresponding client capabilities.\n\n    @since 3.16.0\n    \"\"\"\n\n    Declaration = \"declaration\"\n    Definition = \"definition\"\n    Readonly = \"readonly\"\n    Static = \"static\"\n    Deprecated = \"deprecated\"\n    Abstract = \"abstract\"\n    Async = \"async\"\n    Modification = \"modification\"\n    Documentation = \"documentation\"\n    DefaultLibrary = \"defaultLibrary\"\n\n\nclass DocumentDiagnosticReportKind(Enum):\n    \"\"\"The document diagnostic report kinds.\n\n    @since 3.17.0\n    \"\"\"\n\n    Full = \"full\"\n    \"\"\" A diagnostic report with a full\n    set of problems. \"\"\"\n    Unchanged = \"unchanged\"\n    \"\"\" A report indicating that the last\n    returned report is still accurate. \"\"\"\n\n\nclass ErrorCodes(IntEnum):\n    \"\"\"Predefined error codes.\"\"\"\n\n    ParseError = -32700\n    InvalidRequest = -32600\n    MethodNotFound = -32601\n    InvalidParams = -32602\n    InternalError = -32603\n    ServerNotInitialized = -32002\n    \"\"\" Error code indicating that a server received a notification or\n    request before the server has received the `initialize` request. \"\"\"\n    UnknownErrorCode = -32001\n\n\nclass LSPErrorCodes(IntEnum):\n    RequestFailed = -32803\n    \"\"\" A request failed but it was syntactically correct, e.g the\n    method name was known and the parameters were valid. The error\n    message should contain human readable information about why\n    the request failed.\n\n    @since 3.17.0 \"\"\"\n    ServerCancelled = -32802\n    \"\"\" The server cancelled the request. This error code should\n    only be used for requests that explicitly support being\n    server cancellable.\n\n    @since 3.17.0 \"\"\"\n    ContentModified = -32801\n    \"\"\" The server detected that the content of a document got\n    modified outside normal conditions. A server should\n    NOT send this error code if it detects a content change\n    in it unprocessed messages. The result even computed\n    on an older state might still be useful for the client.\n\n    If a client decides that a result is not of any use anymore\n    the client should cancel the request. \"\"\"\n    RequestCancelled = -32800\n    \"\"\" The client has canceled a request and a server as detected\n    the cancel. \"\"\"\n\n\nclass FoldingRangeKind(Enum):\n    \"\"\"A set of predefined range kinds.\"\"\"\n\n    Comment = \"comment\"\n    \"\"\" Folding range for a comment \"\"\"\n    Imports = \"imports\"\n    \"\"\" Folding range for an import or include \"\"\"\n    Region = \"region\"\n    \"\"\" Folding range for a region (e.g. `#region`) \"\"\"\n\n\nclass SymbolKind(IntEnum):\n    \"\"\"A symbol kind.\"\"\"\n\n    File = 1\n    Module = 2\n    Namespace = 3\n    Package = 4\n    \"\"\"\n    Represents a package or simply a directory in the filesystem\n    \"\"\"\n    Class = 5\n    Method = 6\n    Property = 7\n    Field = 8\n    Constructor = 9\n    Enum = 10\n    Interface = 11\n    Function = 12\n    Variable = 13\n    Constant = 14\n    String = 15\n    Number = 16\n    Boolean = 17\n    Array = 18\n    Object = 19\n    Key = 20\n    Null = 21\n    EnumMember = 22\n    Struct = 23\n    Event = 24\n    Operator = 25\n    TypeParameter = 26\n\n    @classmethod\n    def from_int(cls, value: int) -> \"SymbolKind\":\n        for symbol_kind in cls:\n            if symbol_kind.value == value:\n                return symbol_kind\n        raise ValueError(f\"Invalid symbol kind: {value}\")\n\n\nclass SymbolTag(IntEnum):\n    \"\"\"Symbol tags are extra annotations that tweak the rendering of a symbol.\n\n    @since 3.16\n    \"\"\"\n\n    Deprecated = 1\n    \"\"\" Render a symbol as obsolete, usually using a strike-out. \"\"\"\n\n\nclass UniquenessLevel(Enum):\n    \"\"\"Moniker uniqueness level to define scope of the moniker.\n\n    @since 3.16.0\n    \"\"\"\n\n    Document = \"document\"\n    \"\"\" The moniker is only unique inside a document \"\"\"\n    Project = \"project\"\n    \"\"\" The moniker is unique inside a project for which a dump got created \"\"\"\n    Group = \"group\"\n    \"\"\" The moniker is unique inside the group to which a project belongs \"\"\"\n    Scheme = \"scheme\"\n    \"\"\" The moniker is unique inside the moniker scheme. \"\"\"\n    Global = \"global\"\n    \"\"\" The moniker is globally unique \"\"\"\n\n\nclass MonikerKind(Enum):\n    \"\"\"The moniker kind.\n\n    @since 3.16.0\n    \"\"\"\n\n    Import = \"import\"\n    \"\"\" The moniker represent a symbol that is imported into a project \"\"\"\n    Export = \"export\"\n    \"\"\" The moniker represents a symbol that is exported from a project \"\"\"\n    Local = \"local\"\n    \"\"\" The moniker represents a symbol that is local to a project (e.g. a local\n    variable of a function, a class not visible outside the project, ...) \"\"\"\n\n\nclass InlayHintKind(IntEnum):\n    \"\"\"Inlay hint kinds.\n\n    @since 3.17.0\n    \"\"\"\n\n    Type = 1\n    \"\"\" An inlay hint that for a type annotation. \"\"\"\n    Parameter = 2\n    \"\"\" An inlay hint that is for a parameter. \"\"\"\n\n\nclass MessageType(IntEnum):\n    \"\"\"The message type\"\"\"\n\n    Error = 1\n    \"\"\" An error message. \"\"\"\n    Warning = 2\n    \"\"\" A warning message. \"\"\"\n    Info = 3\n    \"\"\" An information message. \"\"\"\n    Log = 4\n    \"\"\" A log message. \"\"\"\n\n\nclass TextDocumentSyncKind(IntEnum):\n    \"\"\"Defines how the host (editor) should sync\n    document changes to the language server.\n    \"\"\"\n\n    None_ = 0\n    \"\"\" Documents should not be synced at all. \"\"\"\n    Full = 1\n    \"\"\" Documents are synced by always sending the full content\n    of the document. \"\"\"\n    Incremental = 2\n    \"\"\" Documents are synced by sending the full content on open.\n    After that only incremental updates to the document are\n    send. \"\"\"\n\n\nclass TextDocumentSaveReason(IntEnum):\n    \"\"\"Represents reasons why a text document is saved.\"\"\"\n\n    Manual = 1\n    \"\"\" Manually triggered, e.g. by the user pressing save, by starting debugging,\n    or by an API call. \"\"\"\n    AfterDelay = 2\n    \"\"\" Automatic after a delay. \"\"\"\n    FocusOut = 3\n    \"\"\" When the editor lost focus. \"\"\"\n\n\nclass CompletionItemKind(IntEnum):\n    \"\"\"The kind of a completion entry.\"\"\"\n\n    Text = 1\n    Method = 2\n    Function = 3\n    Constructor = 4\n    Field = 5\n    Variable = 6\n    Class = 7\n    Interface = 8\n    Module = 9\n    Property = 10\n    Unit = 11\n    Value = 12\n    Enum = 13\n    Keyword = 14\n    Snippet = 15\n    Color = 16\n    File = 17\n    Reference = 18\n    Folder = 19\n    EnumMember = 20\n    Constant = 21\n    Struct = 22\n    Event = 23\n    Operator = 24\n    TypeParameter = 25\n\n\nclass CompletionItemTag(IntEnum):\n    \"\"\"Completion item tags are extra annotations that tweak the rendering of a completion\n    item.\n\n    @since 3.15.0\n    \"\"\"\n\n    Deprecated = 1\n    \"\"\" Render a completion as obsolete, usually using a strike-out. \"\"\"\n\n\nclass InsertTextFormat(IntEnum):\n    \"\"\"Defines whether the insert text in a completion item should be interpreted as\n    plain text or a snippet.\n    \"\"\"\n\n    PlainText = 1\n    \"\"\" The primary text to be inserted is treated as a plain string. \"\"\"\n    Snippet = 2\n    \"\"\" The primary text to be inserted is treated as a snippet.\n\n    A snippet can define tab stops and placeholders with `$1`, `$2`\n    and `${3:foo}`. `$0` defines the final tab stop, it defaults to\n    the end of the snippet. Placeholders with equal identifiers are linked,\n    that is typing in one will update others too.\n\n    See also: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#snippet_syntax \"\"\"\n\n\nclass InsertTextMode(IntEnum):\n    \"\"\"How whitespace and indentation is handled during completion\n    item insertion.\n\n    @since 3.16.0\n    \"\"\"\n\n    AsIs = 1\n    \"\"\" The insertion or replace strings is taken as it is. If the\n    value is multi line the lines below the cursor will be\n    inserted using the indentation defined in the string value.\n    The client will not apply any kind of adjustments to the\n    string. \"\"\"\n    AdjustIndentation = 2\n    \"\"\" The editor adjusts leading whitespace of new lines so that\n    they match the indentation up to the cursor of the line for\n    which the item is accepted.\n\n    Consider a line like this: <2tabs><cursor><3tabs>foo. Accepting a\n    multi line completion item is indented using 2 tabs and all\n    following lines inserted will be indented using 2 tabs as well. \"\"\"\n\n\nclass DocumentHighlightKind(IntEnum):\n    \"\"\"A document highlight kind.\"\"\"\n\n    Text = 1\n    \"\"\" A textual occurrence. \"\"\"\n    Read = 2\n    \"\"\" Read-access of a symbol, like reading a variable. \"\"\"\n    Write = 3\n    \"\"\" Write-access of a symbol, like writing to a variable. \"\"\"\n\n\nclass CodeActionKind(Enum):\n    \"\"\"A set of predefined code action kinds\"\"\"\n\n    Empty = \"\"\n    \"\"\" Empty kind. \"\"\"\n    QuickFix = \"quickfix\"\n    \"\"\" Base kind for quickfix actions: 'quickfix' \"\"\"\n    Refactor = \"refactor\"\n    \"\"\" Base kind for refactoring actions: 'refactor' \"\"\"\n    RefactorExtract = \"refactor.extract\"\n    \"\"\" Base kind for refactoring extraction actions: 'refactor.extract'\n\n    Example extract actions:\n\n    - Extract method\n    - Extract function\n    - Extract variable\n    - Extract interface from class\n    - ... \"\"\"\n    RefactorInline = \"refactor.inline\"\n    \"\"\" Base kind for refactoring inline actions: 'refactor.inline'\n\n    Example inline actions:\n\n    - Inline function\n    - Inline variable\n    - Inline constant\n    - ... \"\"\"\n    RefactorRewrite = \"refactor.rewrite\"\n    \"\"\" Base kind for refactoring rewrite actions: 'refactor.rewrite'\n\n    Example rewrite actions:\n\n    - Convert JavaScript function to class\n    - Add or remove parameter\n    - Encapsulate field\n    - Make method static\n    - Move method to base class\n    - ... \"\"\"\n    Source = \"source\"\n    \"\"\" Base kind for source actions: `source`\n\n    Source code actions apply to the entire file. \"\"\"\n    SourceOrganizeImports = \"source.organizeImports\"\n    \"\"\" Base kind for an organize imports source action: `source.organizeImports` \"\"\"\n    SourceFixAll = \"source.fixAll\"\n    \"\"\" Base kind for auto-fix source actions: `source.fixAll`.\n\n    Fix all actions automatically fix errors that have a clear fix that do not require user input.\n    They should not suppress errors or perform unsafe fixes such as generating new types or classes.\n\n    @since 3.15.0 \"\"\"\n\n\nclass TraceValues(Enum):\n    Off = \"off\"\n    \"\"\" Turn tracing off. \"\"\"\n    Messages = \"messages\"\n    \"\"\" Trace messages only. \"\"\"\n    Verbose = \"verbose\"\n    \"\"\" Verbose message tracing. \"\"\"\n\n\nclass MarkupKind(Enum):\n    \"\"\"Describes the content type that a client supports in various\n    result literals like `Hover`, `ParameterInfo` or `CompletionItem`.\n\n    Please note that `MarkupKinds` must not start with a `$`. This kinds\n    are reserved for internal usage.\n    \"\"\"\n\n    PlainText = \"plaintext\"\n    \"\"\" Plain text is supported as a content format \"\"\"\n    Markdown = \"markdown\"\n    \"\"\" Markdown is supported as a content format \"\"\"\n\n\nclass PositionEncodingKind(Enum):\n    \"\"\"A set of predefined position encoding kinds.\n\n    @since 3.17.0\n    \"\"\"\n\n    UTF8 = \"utf-8\"\n    \"\"\" Character offsets count UTF-8 code units. \"\"\"\n    UTF16 = \"utf-16\"\n    \"\"\" Character offsets count UTF-16 code units.\n\n    This is the default and must always be supported\n    by servers \"\"\"\n    UTF32 = \"utf-32\"\n    \"\"\" Character offsets count UTF-32 code units.\n\n    Implementation note: these are the same as Unicode code points,\n    so this `PositionEncodingKind` may also be used for an\n    encoding-agnostic representation of character offsets. \"\"\"\n\n\nclass FileChangeType(IntEnum):\n    \"\"\"The file event type\"\"\"\n\n    Created = 1\n    \"\"\" The file got created. \"\"\"\n    Changed = 2\n    \"\"\" The file got changed. \"\"\"\n    Deleted = 3\n    \"\"\" The file got deleted. \"\"\"\n\n\nclass WatchKind(IntFlag):\n    Create = 1\n    \"\"\" Interested in create events. \"\"\"\n    Change = 2\n    \"\"\" Interested in change events \"\"\"\n    Delete = 4\n    \"\"\" Interested in delete events \"\"\"\n\n\nclass DiagnosticSeverity(IntEnum):\n    \"\"\"The diagnostic's severity.\"\"\"\n\n    Error = 1\n    \"\"\" Reports an error. \"\"\"\n    Warning = 2\n    \"\"\" Reports a warning. \"\"\"\n    Information = 3\n    \"\"\" Reports an information. \"\"\"\n    Hint = 4\n    \"\"\" Reports a hint. \"\"\"\n\n\nclass DiagnosticTag(IntEnum):\n    \"\"\"The diagnostic tags.\n\n    @since 3.15.0\n    \"\"\"\n\n    Unnecessary = 1\n    \"\"\" Unused or unnecessary code.\n\n    Clients are allowed to render diagnostics with this tag faded out instead of having\n    an error squiggle. \"\"\"\n    Deprecated = 2\n    \"\"\" Deprecated or obsolete code.\n\n    Clients are allowed to rendered diagnostics with this tag strike through. \"\"\"\n\n\nclass CompletionTriggerKind(IntEnum):\n    \"\"\"How a completion was triggered\"\"\"\n\n    Invoked = 1\n    \"\"\" Completion was triggered by typing an identifier (24x7 code\n    complete), manual invocation (e.g Ctrl+Space) or via API. \"\"\"\n    TriggerCharacter = 2\n    \"\"\" Completion was triggered by a trigger character specified by\n    the `triggerCharacters` properties of the `CompletionRegistrationOptions`. \"\"\"\n    TriggerForIncompleteCompletions = 3\n    \"\"\" Completion was re-triggered as current completion list is incomplete \"\"\"\n\n\nclass SignatureHelpTriggerKind(IntEnum):\n    \"\"\"How a signature help was triggered.\n\n    @since 3.15.0\n    \"\"\"\n\n    Invoked = 1\n    \"\"\" Signature help was invoked manually by the user or by a command. \"\"\"\n    TriggerCharacter = 2\n    \"\"\" Signature help was triggered by a trigger character. \"\"\"\n    ContentChange = 3\n    \"\"\" Signature help was triggered by the cursor moving or by the document content changing. \"\"\"\n\n\nclass CodeActionTriggerKind(IntEnum):\n    \"\"\"The reason why code actions were requested.\n\n    @since 3.17.0\n    \"\"\"\n\n    Invoked = 1\n    \"\"\" Code actions were explicitly requested by the user or by an extension. \"\"\"\n    Automatic = 2\n    \"\"\" Code actions were requested automatically.\n\n    This typically happens when current selection in a file changes, but can\n    also be triggered when file content changes. \"\"\"\n\n\nclass FileOperationPatternKind(Enum):\n    \"\"\"A pattern kind describing if a glob pattern matches a file a folder or\n    both.\n\n    @since 3.16.0\n    \"\"\"\n\n    File = \"file\"\n    \"\"\" The pattern matches a file only. \"\"\"\n    Folder = \"folder\"\n    \"\"\" The pattern matches a folder only. \"\"\"\n\n\nclass NotebookCellKind(IntEnum):\n    \"\"\"A notebook cell kind.\n\n    @since 3.17.0\n    \"\"\"\n\n    Markup = 1\n    \"\"\" A markup-cell is formatted source that is used for display. \"\"\"\n    Code = 2\n    \"\"\" A code-cell is source code. \"\"\"\n\n\nclass ResourceOperationKind(Enum):\n    Create = \"create\"\n    \"\"\" Supports creating new files and folders. \"\"\"\n    Rename = \"rename\"\n    \"\"\" Supports renaming existing files and folders. \"\"\"\n    Delete = \"delete\"\n    \"\"\" Supports deleting existing files and folders. \"\"\"\n\n\nclass FailureHandlingKind(Enum):\n    Abort = \"abort\"\n    \"\"\" Applying the workspace change is simply aborted if one of the changes provided\n    fails. All operations executed before the failing operation stay executed. \"\"\"\n    Transactional = \"transactional\"\n    \"\"\" All operations are executed transactional. That means they either all\n    succeed or no changes at all are applied to the workspace. \"\"\"\n    TextOnlyTransactional = \"textOnlyTransactional\"\n    \"\"\" If the workspace edit contains only textual file changes they are executed transactional.\n    If resource changes (create, rename or delete file) are part of the change the failure\n    handling strategy is abort. \"\"\"\n    Undo = \"undo\"\n    \"\"\" The client tries to undo the operations already executed. But there is no\n    guarantee that this is succeeding. \"\"\"\n\n\nclass PrepareSupportDefaultBehavior(IntEnum):\n    Identifier = 1\n    \"\"\" The client's default behavior is to select the identifier\n    according the to language's syntax rule. \"\"\"\n\n\nclass TokenFormat(Enum):\n    Relative = \"relative\"\n\n\nDefinition = Union[\"Location\", list[\"Location\"]]\n\"\"\" The definition of a symbol represented as one or many {@link Location locations}.\nFor most programming languages there is only one location at which a symbol is\ndefined.\n\nServers should prefer returning `DefinitionLink` over `Definition` if supported\nby the client. \"\"\"\n\nDefinitionLink = \"LocationLink\"\n\"\"\" Information about where a symbol is defined.\n\nProvides additional metadata over normal {@link Location location} definitions, including the range of\nthe defining symbol \"\"\"\n\nLSPArray = list[\"LSPAny\"]\n\"\"\" LSP arrays.\n@since 3.17.0 \"\"\"\n\nLSPAny = Union[\"LSPObject\", \"LSPArray\", str, int, Uint, float, bool, None]\n\"\"\" The LSP any type.\nPlease note that strictly speaking a property with the value `undefined`\ncan't be converted into JSON preserving the property name. However for\nconvenience it is allowed and assumed that all these properties are\noptional as well.\n@since 3.17.0 \"\"\"\n\nDeclaration = Union[\"Location\", list[\"Location\"]]\n\"\"\" The declaration of a symbol representation as one or many {@link Location locations}. \"\"\"\n\nDeclarationLink = \"LocationLink\"\n\"\"\" Information about where a symbol is declared.\n\nProvides additional metadata over normal {@link Location location} declarations, including the range of\nthe declaring symbol.\n\nServers should prefer returning `DeclarationLink` over `Declaration` if supported\nby the client. \"\"\"\n\nInlineValue = Union[\"InlineValueText\", \"InlineValueVariableLookup\", \"InlineValueEvaluatableExpression\"]\n\"\"\" Inline value information can be provided by different means:\n- directly as a text value (class InlineValueText).\n- as a name to use for a variable lookup (class InlineValueVariableLookup)\n- as an evaluatable expression (class InlineValueEvaluatableExpression)\nThe InlineValue types combines all inline value types into one type.\n\n@since 3.17.0 \"\"\"\n\nDocumentDiagnosticReport = Union[\"RelatedFullDocumentDiagnosticReport\", \"RelatedUnchangedDocumentDiagnosticReport\"]\n\"\"\" The result of a document diagnostic pull request. A report can\neither be a full report containing all diagnostics for the\nrequested document or an unchanged report indicating that nothing\nhas changed in terms of diagnostics in comparison to the last\npull request.\n\n@since 3.17.0 \"\"\"\n\nPrepareRenameResult = Union[\"Range\", \"__PrepareRenameResult_Type_1\", \"__PrepareRenameResult_Type_2\"]\n\nDocumentSelector = list[\"DocumentFilter\"]\n\"\"\" A document selector is the combination of one or many document filters.\n\n@sample `let sel:DocumentSelector = [{ language: 'typescript' }, { language: 'json', pattern: '**/tsconfig.json' }]`;\n\nThe use of a string as a document filter is deprecated @since 3.16.0. \"\"\"\n\nProgressToken = Union[int, str]\n\nChangeAnnotationIdentifier = str\n\"\"\" An identifier to refer to a change annotation stored with a workspace edit. \"\"\"\n\nWorkspaceDocumentDiagnosticReport = Union[\n    \"WorkspaceFullDocumentDiagnosticReport\",\n    \"WorkspaceUnchangedDocumentDiagnosticReport\",\n]\n\"\"\" A workspace diagnostic document report.\n\n@since 3.17.0 \"\"\"\n\nTextDocumentContentChangeEvent = Union[\"__TextDocumentContentChangeEvent_Type_1\", \"__TextDocumentContentChangeEvent_Type_2\"]\n\"\"\" An event describing a change to a text document. If only a text is provided\nit is considered to be the full content of the document. \"\"\"\n\nMarkedString = Union[str, \"__MarkedString_Type_1\"]\n\"\"\" MarkedString can be used to render human readable text. It is either a markdown string\nor a code-block that provides a language and a code snippet. The language identifier\nis semantically equal to the optional language identifier in fenced code blocks in GitHub\nissues. See https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting\n\nThe pair of a language and a value is an equivalent to markdown:\n```${language}\n${value}\n```\n\nNote that markdown strings will be sanitized - that means html will be escaped.\n@deprecated use MarkupContent instead. \"\"\"\n\nDocumentFilter = Union[\"TextDocumentFilter\", \"NotebookCellTextDocumentFilter\"]\n\"\"\" A document filter describes a top level text document or\na notebook cell document.\n\n@since 3.17.0 - proposed support for NotebookCellTextDocumentFilter. \"\"\"\n\nLSPObject = dict[str, \"LSPAny\"]\n\"\"\" LSP object definition.\n@since 3.17.0 \"\"\"\n\nGlobPattern = Union[\"Pattern\", \"RelativePattern\"]\n\"\"\" The glob pattern. Either a string pattern or a relative pattern.\n\n@since 3.17.0 \"\"\"\n\nTextDocumentFilter = Union[\n    \"__TextDocumentFilter_Type_1\",\n    \"__TextDocumentFilter_Type_2\",\n    \"__TextDocumentFilter_Type_3\",\n]\n\"\"\" A document filter denotes a document by different properties like\nthe {@link TextDocument.languageId language}, the {@link Uri.scheme scheme} of\nits resource, or a glob-pattern that is applied to the {@link TextDocument.fileName path}.\n\nGlob patterns can have the following syntax:\n- `*` to match one or more characters in a path segment\n- `?` to match on one character in a path segment\n- `**` to match any number of path segments, including none\n- `{}` to group sub patterns into an OR expression. (e.g. `**\\u200b/*.{ts,js}` matches all TypeScript and JavaScript files)\n- `[]` to declare a range of characters to match in a path segment (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …)\n- `[!...]` to negate a range of characters to match in a path segment (e.g., `example.[!0-9]` to match on `example.a`, `example.b`, but not `example.0`)\n\n@sample A language filter that applies to typescript files on disk: `{ language: 'typescript', scheme: 'file' }`\n@sample A language filter that applies to all package.json paths: `{ language: 'json', pattern: '**package.json' }`\n\n@since 3.17.0 \"\"\"\n\nNotebookDocumentFilter = Union[\n    \"__NotebookDocumentFilter_Type_1\",\n    \"__NotebookDocumentFilter_Type_2\",\n    \"__NotebookDocumentFilter_Type_3\",\n]\n\"\"\" A notebook document filter denotes a notebook document by\ndifferent properties. The properties will be match\nagainst the notebook's URI (same as with documents)\n\n@since 3.17.0 \"\"\"\n\nPattern = str\n\"\"\" The glob pattern to watch relative to the base path. Glob patterns can have the following syntax:\n- `*` to match one or more characters in a path segment\n- `?` to match on one character in a path segment\n- `**` to match any number of path segments, including none\n- `{}` to group conditions (e.g. `**\\u200b/*.{ts,js}` matches all TypeScript and JavaScript files)\n- `[]` to declare a range of characters to match in a path segment (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …)\n- `[!...]` to negate a range of characters to match in a path segment (e.g., `example.[!0-9]` to match on `example.a`, `example.b`, but not `example.0`)\n\n@since 3.17.0 \"\"\"\n\n\nclass ImplementationParams(TypedDict):\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    position: \"Position\"\n    \"\"\" The position inside the text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass Location(TypedDict):\n    \"\"\"Represents a location inside a resource, such as a line\n    inside a text file.\n    \"\"\"\n\n    uri: \"DocumentUri\"\n    range: \"Range\"\n\n\nclass ImplementationRegistrationOptions(TypedDict):\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    id: NotRequired[str]\n    \"\"\" The id used to register the request. The id can be used to deregister\n    the request again. See also Registration#id. \"\"\"\n\n\nclass TypeDefinitionParams(TypedDict):\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    position: \"Position\"\n    \"\"\" The position inside the text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass TypeDefinitionRegistrationOptions(TypedDict):\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    id: NotRequired[str]\n    \"\"\" The id used to register the request. The id can be used to deregister\n    the request again. See also Registration#id. \"\"\"\n\n\nclass WorkspaceFolder(TypedDict):\n    \"\"\"A workspace folder inside a client.\"\"\"\n\n    uri: \"URI\"\n    \"\"\" The associated URI for this workspace folder. \"\"\"\n    name: str\n    \"\"\" The name of the workspace folder. Used to refer to this\n    workspace folder in the user interface. \"\"\"\n\n\nclass DidChangeWorkspaceFoldersParams(TypedDict):\n    \"\"\"The parameters of a `workspace/didChangeWorkspaceFolders` notification.\"\"\"\n\n    event: \"WorkspaceFoldersChangeEvent\"\n    \"\"\" The actual workspace folder change event. \"\"\"\n\n\nclass ConfigurationParams(TypedDict):\n    \"\"\"The parameters of a configuration request.\"\"\"\n\n    items: list[\"ConfigurationItem\"]\n\n\nclass DocumentColorParams(TypedDict):\n    \"\"\"Parameters for a {@link DocumentColorRequest}.\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass ColorInformation(TypedDict):\n    \"\"\"Represents a color range from a document.\"\"\"\n\n    range: \"Range\"\n    \"\"\" The range in the document where this color appears. \"\"\"\n    color: \"Color\"\n    \"\"\" The actual color value for this color range. \"\"\"\n\n\nclass DocumentColorRegistrationOptions(TypedDict):\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    id: NotRequired[str]\n    \"\"\" The id used to register the request. The id can be used to deregister\n    the request again. See also Registration#id. \"\"\"\n\n\nclass ColorPresentationParams(TypedDict):\n    \"\"\"Parameters for a {@link ColorPresentationRequest}.\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    color: \"Color\"\n    \"\"\" The color to request presentations for. \"\"\"\n    range: \"Range\"\n    \"\"\" The range where the color would be inserted. Serves as a context. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass ColorPresentation(TypedDict):\n    label: str\n    \"\"\" The label of this color presentation. It will be shown on the color\n    picker header. By default this is also the text that is inserted when selecting\n    this color presentation. \"\"\"\n    textEdit: NotRequired[\"TextEdit\"]\n    \"\"\" An {@link TextEdit edit} which is applied to a document when selecting\n    this presentation for the color.  When `falsy` the {@link ColorPresentation.label label}\n    is used. \"\"\"\n    additionalTextEdits: NotRequired[list[\"TextEdit\"]]\n    \"\"\" An optional array of additional {@link TextEdit text edits} that are applied when\n    selecting this color presentation. Edits must not overlap with the main {@link ColorPresentation.textEdit edit} nor with themselves. \"\"\"\n\n\nclass WorkDoneProgressOptions(TypedDict):\n    workDoneProgress: NotRequired[bool]\n\n\nclass TextDocumentRegistrationOptions(TypedDict):\n    \"\"\"General text document registration options.\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n\n\nclass FoldingRangeParams(TypedDict):\n    \"\"\"Parameters for a {@link FoldingRangeRequest}.\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass FoldingRange(TypedDict):\n    \"\"\"Represents a folding range. To be valid, start and end line must be bigger than zero and smaller\n    than the number of lines in the document. Clients are free to ignore invalid ranges.\n    \"\"\"\n\n    startLine: Uint\n    \"\"\" The zero-based start line of the range to fold. The folded area starts after the line's last character.\n    To be valid, the end must be zero or larger and smaller than the number of lines in the document. \"\"\"\n    startCharacter: NotRequired[Uint]\n    \"\"\" The zero-based character offset from where the folded range starts. If not defined, defaults to the length of the start line. \"\"\"\n    endLine: Uint\n    \"\"\" The zero-based end line of the range to fold. The folded area ends with the line's last character.\n    To be valid, the end must be zero or larger and smaller than the number of lines in the document. \"\"\"\n    endCharacter: NotRequired[Uint]\n    \"\"\" The zero-based character offset before the folded range ends. If not defined, defaults to the length of the end line. \"\"\"\n    kind: NotRequired[\"FoldingRangeKind\"]\n    \"\"\" Describes the kind of the folding range such as `comment' or 'region'. The kind\n    is used to categorize folding ranges and used by commands like 'Fold all comments'.\n    See {@link FoldingRangeKind} for an enumeration of standardized kinds. \"\"\"\n    collapsedText: NotRequired[str]\n    \"\"\" The text that the client should show when the specified range is\n    collapsed. If not defined or not supported by the client, a default\n    will be chosen by the client.\n\n    @since 3.17.0 \"\"\"\n\n\nclass FoldingRangeRegistrationOptions(TypedDict):\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    id: NotRequired[str]\n    \"\"\" The id used to register the request. The id can be used to deregister\n    the request again. See also Registration#id. \"\"\"\n\n\nclass DeclarationParams(TypedDict):\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    position: \"Position\"\n    \"\"\" The position inside the text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass DeclarationRegistrationOptions(TypedDict):\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    id: NotRequired[str]\n    \"\"\" The id used to register the request. The id can be used to deregister\n    the request again. See also Registration#id. \"\"\"\n\n\nclass SelectionRangeParams(TypedDict):\n    \"\"\"A parameter literal used in selection range requests.\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    positions: list[\"Position\"]\n    \"\"\" The positions inside the text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass SelectionRange(TypedDict):\n    \"\"\"A selection range represents a part of a selection hierarchy. A selection range\n    may have a parent selection range that contains it.\n    \"\"\"\n\n    range: \"Range\"\n    \"\"\" The {@link Range range} of this selection range. \"\"\"\n    parent: NotRequired[\"SelectionRange\"]\n    \"\"\" The parent selection range containing this range. Therefore `parent.range` must contain `this.range`. \"\"\"\n\n\nclass SelectionRangeRegistrationOptions(TypedDict):\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    id: NotRequired[str]\n    \"\"\" The id used to register the request. The id can be used to deregister\n    the request again. See also Registration#id. \"\"\"\n\n\nclass WorkDoneProgressCreateParams(TypedDict):\n    token: \"ProgressToken\"\n    \"\"\" The token to be used to report progress. \"\"\"\n\n\nclass WorkDoneProgressCancelParams(TypedDict):\n    token: \"ProgressToken\"\n    \"\"\" The token to be used to report progress. \"\"\"\n\n\nclass CallHierarchyPrepareParams(TypedDict):\n    \"\"\"The parameter of a `textDocument/prepareCallHierarchy` request.\n\n    @since 3.16.0\n    \"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    position: \"Position\"\n    \"\"\" The position inside the text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n\n\nclass CallHierarchyItem(TypedDict):\n    \"\"\"Represents programming constructs like functions or constructors in the context\n    of call hierarchy.\n\n    @since 3.16.0\n    \"\"\"\n\n    name: str\n    \"\"\" The name of this item. \"\"\"\n    kind: \"SymbolKind\"\n    \"\"\" The kind of this item. \"\"\"\n    tags: NotRequired[list[\"SymbolTag\"]]\n    \"\"\" Tags for this item. \"\"\"\n    detail: NotRequired[str]\n    \"\"\" More detail for this item, e.g. the signature of a function. \"\"\"\n    uri: \"DocumentUri\"\n    \"\"\" The resource identifier of this item. \"\"\"\n    range: \"Range\"\n    \"\"\" The range enclosing this symbol not including leading/trailing whitespace but everything else, e.g. comments and code. \"\"\"\n    selectionRange: \"Range\"\n    \"\"\" The range that should be selected and revealed when this symbol is being picked, e.g. the name of a function.\n    Must be contained by the {@link CallHierarchyItem.range `range`}. \"\"\"\n    data: NotRequired[\"LSPAny\"]\n    \"\"\" A data entry field that is preserved between a call hierarchy prepare and\n    incoming calls or outgoing calls requests. \"\"\"\n\n\nclass CallHierarchyRegistrationOptions(TypedDict):\n    \"\"\"Call hierarchy options used during static or dynamic registration.\n\n    @since 3.16.0\n    \"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    id: NotRequired[str]\n    \"\"\" The id used to register the request. The id can be used to deregister\n    the request again. See also Registration#id. \"\"\"\n\n\nclass CallHierarchyIncomingCallsParams(TypedDict):\n    \"\"\"The parameter of a `callHierarchy/incomingCalls` request.\n\n    @since 3.16.0\n    \"\"\"\n\n    item: \"CallHierarchyItem\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nCallHierarchyIncomingCall = TypedDict(\n    \"CallHierarchyIncomingCall\",\n    {\n        # The item that makes the call.\n        \"from\": \"CallHierarchyItem\",\n        # The ranges at which the calls appear. This is relative to the caller\n        # denoted by {@link CallHierarchyIncomingCall.from `this.from`}.\n        \"fromRanges\": list[\"Range\"],\n    },\n)\n\"\"\" Represents an incoming call, e.g. a caller of a method or constructor.\n\n@since 3.16.0 \"\"\"\n\n\nclass CallHierarchyOutgoingCallsParams(TypedDict):\n    \"\"\"The parameter of a `callHierarchy/outgoingCalls` request.\n\n    @since 3.16.0\n    \"\"\"\n\n    item: \"CallHierarchyItem\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass CallHierarchyOutgoingCall(TypedDict):\n    \"\"\"Represents an outgoing call, e.g. calling a getter from a method or a method from a constructor etc.\n\n    @since 3.16.0\n    \"\"\"\n\n    to: \"CallHierarchyItem\"\n    \"\"\" The item that is called. \"\"\"\n    fromRanges: list[\"Range\"]\n    \"\"\" The range at which this item is called. This is the range relative to the caller, e.g the item\n    passed to {@link CallHierarchyItemProvider.provideCallHierarchyOutgoingCalls `provideCallHierarchyOutgoingCalls`}\n    and not {@link CallHierarchyOutgoingCall.to `this.to`}. \"\"\"\n\n\nclass SemanticTokensParams(TypedDict):\n    \"\"\"@since 3.16.0\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass SemanticTokens(TypedDict):\n    \"\"\"@since 3.16.0\"\"\"\n\n    resultId: NotRequired[str]\n    \"\"\" An optional result id. If provided and clients support delta updating\n    the client will include the result id in the next semantic token request.\n    A server can then instead of computing all semantic tokens again simply\n    send a delta. \"\"\"\n    data: list[Uint]\n    \"\"\" The actual tokens. \"\"\"\n\n\nclass SemanticTokensPartialResult(TypedDict):\n    \"\"\"@since 3.16.0\"\"\"\n\n    data: list[Uint]\n\n\nclass SemanticTokensRegistrationOptions(TypedDict):\n    \"\"\"@since 3.16.0\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    legend: \"SemanticTokensLegend\"\n    \"\"\" The legend used by the server \"\"\"\n    range: NotRequired[bool | dict]\n    \"\"\" Server supports providing semantic tokens for a specific range\n    of a document. \"\"\"\n    full: NotRequired[Union[bool, \"__SemanticTokensOptions_full_Type_1\"]]\n    \"\"\" Server supports providing semantic tokens for a full document. \"\"\"\n    id: NotRequired[str]\n    \"\"\" The id used to register the request. The id can be used to deregister\n    the request again. See also Registration#id. \"\"\"\n\n\nclass SemanticTokensDeltaParams(TypedDict):\n    \"\"\"@since 3.16.0\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    previousResultId: str\n    \"\"\" The result id of a previous response. The result Id can either point to a full response\n    or a delta response depending on what was received last. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass SemanticTokensDelta(TypedDict):\n    \"\"\"@since 3.16.0\"\"\"\n\n    resultId: NotRequired[str]\n    edits: list[\"SemanticTokensEdit\"]\n    \"\"\" The semantic token edits to transform a previous result into a new result. \"\"\"\n\n\nclass SemanticTokensDeltaPartialResult(TypedDict):\n    \"\"\"@since 3.16.0\"\"\"\n\n    edits: list[\"SemanticTokensEdit\"]\n\n\nclass SemanticTokensRangeParams(TypedDict):\n    \"\"\"@since 3.16.0\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    range: \"Range\"\n    \"\"\" The range the semantic tokens are requested for. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass ShowDocumentParams(TypedDict):\n    \"\"\"Params to show a document.\n\n    @since 3.16.0\n    \"\"\"\n\n    uri: \"URI\"\n    \"\"\" The document uri to show. \"\"\"\n    external: NotRequired[bool]\n    \"\"\" Indicates to show the resource in an external program.\n    To show for example `https://code.visualstudio.com/`\n    in the default WEB browser set `external` to `true`. \"\"\"\n    takeFocus: NotRequired[bool]\n    \"\"\" An optional property to indicate whether the editor\n    showing the document should take focus or not.\n    Clients might ignore this property if an external\n    program is started. \"\"\"\n    selection: NotRequired[\"Range\"]\n    \"\"\" An optional selection range if the document is a text\n    document. Clients might ignore the property if an\n    external program is started or the file is not a text\n    file. \"\"\"\n\n\nclass ShowDocumentResult(TypedDict):\n    \"\"\"The result of a showDocument request.\n\n    @since 3.16.0\n    \"\"\"\n\n    success: bool\n    \"\"\" A boolean indicating if the show was successful. \"\"\"\n\n\nclass LinkedEditingRangeParams(TypedDict):\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    position: \"Position\"\n    \"\"\" The position inside the text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n\n\nclass LinkedEditingRanges(TypedDict):\n    \"\"\"The result of a linked editing range request.\n\n    @since 3.16.0\n    \"\"\"\n\n    ranges: list[\"Range\"]\n    \"\"\" A list of ranges that can be edited together. The ranges must have\n    identical length and contain identical text content. The ranges cannot overlap. \"\"\"\n    wordPattern: NotRequired[str]\n    \"\"\" An optional word pattern (regular expression) that describes valid contents for\n    the given ranges. If no pattern is provided, the client configuration's word\n    pattern will be used. \"\"\"\n\n\nclass LinkedEditingRangeRegistrationOptions(TypedDict):\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    id: NotRequired[str]\n    \"\"\" The id used to register the request. The id can be used to deregister\n    the request again. See also Registration#id. \"\"\"\n\n\nclass CreateFilesParams(TypedDict):\n    \"\"\"The parameters sent in notifications/requests for user-initiated creation of\n    files.\n\n    @since 3.16.0\n    \"\"\"\n\n    files: list[\"FileCreate\"]\n    \"\"\" An array of all files/folders created in this operation. \"\"\"\n\n\nclass WorkspaceEdit(TypedDict):\n    \"\"\"A workspace edit represents changes to many resources managed in the workspace. The edit\n    should either provide `changes` or `documentChanges`. If documentChanges are present\n    they are preferred over `changes` if the client can handle versioned document edits.\n\n    Since version 3.13.0 a workspace edit can contain resource operations as well. If resource\n    operations are present clients need to execute the operations in the order in which they\n    are provided. So a workspace edit for example can consist of the following two changes:\n    (1) a create file a.txt and (2) a text document edit which insert text into file a.txt.\n\n    An invalid sequence (e.g. (1) delete file a.txt and (2) insert text into file a.txt) will\n    cause failure of the operation. How the client recovers from the failure is described by\n    the client capability: `workspace.workspaceEdit.failureHandling`\n    \"\"\"\n\n    changes: NotRequired[dict[\"DocumentUri\", list[\"TextEdit\"]]]\n    \"\"\" Holds changes to existing resources. \"\"\"\n    documentChanges: NotRequired[list[Union[\"TextDocumentEdit\", \"CreateFile\", \"RenameFile\", \"DeleteFile\"]]]\n    \"\"\" Depending on the client capability `workspace.workspaceEdit.resourceOperations` document changes\n    are either an array of `TextDocumentEdit`s to express changes to n different text documents\n    where each text document edit addresses a specific version of a text document. Or it can contain\n    above `TextDocumentEdit`s mixed with create, rename and delete file / folder operations.\n\n    Whether a client supports versioned document edits is expressed via\n    `workspace.workspaceEdit.documentChanges` client capability.\n\n    If a client neither supports `documentChanges` nor `workspace.workspaceEdit.resourceOperations` then\n    only plain `TextEdit`s using the `changes` property are supported. \"\"\"\n    changeAnnotations: NotRequired[dict[\"ChangeAnnotationIdentifier\", \"ChangeAnnotation\"]]\n    \"\"\" A map of change annotations that can be referenced in `AnnotatedTextEdit`s or create, rename and\n    delete file / folder operations.\n\n    Whether clients honor this property depends on the client capability `workspace.changeAnnotationSupport`.\n\n    @since 3.16.0 \"\"\"\n\n\nclass FileOperationRegistrationOptions(TypedDict):\n    \"\"\"The options to register for file operations.\n\n    @since 3.16.0\n    \"\"\"\n\n    filters: list[\"FileOperationFilter\"]\n    \"\"\" The actual filters. \"\"\"\n\n\nclass RenameFilesParams(TypedDict):\n    \"\"\"The parameters sent in notifications/requests for user-initiated renames of\n    files.\n\n    @since 3.16.0\n    \"\"\"\n\n    files: list[\"FileRename\"]\n    \"\"\" An array of all files/folders renamed in this operation. When a folder is renamed, only\n    the folder will be included, and not its children. \"\"\"\n\n\nclass DeleteFilesParams(TypedDict):\n    \"\"\"The parameters sent in notifications/requests for user-initiated deletes of\n    files.\n\n    @since 3.16.0\n    \"\"\"\n\n    files: list[\"FileDelete\"]\n    \"\"\" An array of all files/folders deleted in this operation. \"\"\"\n\n\nclass MonikerParams(TypedDict):\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    position: \"Position\"\n    \"\"\" The position inside the text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass Moniker(TypedDict):\n    \"\"\"Moniker definition to match LSIF 0.5 moniker definition.\n\n    @since 3.16.0\n    \"\"\"\n\n    scheme: str\n    \"\"\" The scheme of the moniker. For example tsc or .Net \"\"\"\n    identifier: str\n    \"\"\" The identifier of the moniker. The value is opaque in LSIF however\n    schema owners are allowed to define the structure if they want. \"\"\"\n    unique: \"UniquenessLevel\"\n    \"\"\" The scope in which the moniker is unique \"\"\"\n    kind: NotRequired[\"MonikerKind\"]\n    \"\"\" The moniker kind if known. \"\"\"\n\n\nclass MonikerRegistrationOptions(TypedDict):\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n\n\nclass TypeHierarchyPrepareParams(TypedDict):\n    \"\"\"The parameter of a `textDocument/prepareTypeHierarchy` request.\n\n    @since 3.17.0\n    \"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    position: \"Position\"\n    \"\"\" The position inside the text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n\n\nclass TypeHierarchyItem(TypedDict):\n    \"\"\"@since 3.17.0\"\"\"\n\n    name: str\n    \"\"\" The name of this item. \"\"\"\n    kind: \"SymbolKind\"\n    \"\"\" The kind of this item. \"\"\"\n    tags: NotRequired[list[\"SymbolTag\"]]\n    \"\"\" Tags for this item. \"\"\"\n    detail: NotRequired[str]\n    \"\"\" More detail for this item, e.g. the signature of a function. \"\"\"\n    uri: \"DocumentUri\"\n    \"\"\" The resource identifier of this item. \"\"\"\n    range: \"Range\"\n    \"\"\" The range enclosing this symbol not including leading/trailing whitespace\n    but everything else, e.g. comments and code. \"\"\"\n    selectionRange: \"Range\"\n    \"\"\" The range that should be selected and revealed when this symbol is being\n    picked, e.g. the name of a function. Must be contained by the\n    {@link TypeHierarchyItem.range `range`}. \"\"\"\n    data: NotRequired[\"LSPAny\"]\n    \"\"\" A data entry field that is preserved between a type hierarchy prepare and\n    supertypes or subtypes requests. It could also be used to identify the\n    type hierarchy in the server, helping improve the performance on\n    resolving supertypes and subtypes. \"\"\"\n\n\nclass TypeHierarchyRegistrationOptions(TypedDict):\n    \"\"\"Type hierarchy options used during static or dynamic registration.\n\n    @since 3.17.0\n    \"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    id: NotRequired[str]\n    \"\"\" The id used to register the request. The id can be used to deregister\n    the request again. See also Registration#id. \"\"\"\n\n\nclass TypeHierarchySupertypesParams(TypedDict):\n    \"\"\"The parameter of a `typeHierarchy/supertypes` request.\n\n    @since 3.17.0\n    \"\"\"\n\n    item: \"TypeHierarchyItem\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass TypeHierarchySubtypesParams(TypedDict):\n    \"\"\"The parameter of a `typeHierarchy/subtypes` request.\n\n    @since 3.17.0\n    \"\"\"\n\n    item: \"TypeHierarchyItem\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass InlineValueParams(TypedDict):\n    \"\"\"A parameter literal used in inline value requests.\n\n    @since 3.17.0\n    \"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    range: \"Range\"\n    \"\"\" The document range for which inline values should be computed. \"\"\"\n    context: \"InlineValueContext\"\n    \"\"\" Additional information about the context in which inline values were\n    requested. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n\n\nclass InlineValueRegistrationOptions(TypedDict):\n    \"\"\"Inline value options used during static or dynamic registration.\n\n    @since 3.17.0\n    \"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    id: NotRequired[str]\n    \"\"\" The id used to register the request. The id can be used to deregister\n    the request again. See also Registration#id. \"\"\"\n\n\nclass InlayHintParams(TypedDict):\n    \"\"\"A parameter literal used in inlay hint requests.\n\n    @since 3.17.0\n    \"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    range: \"Range\"\n    \"\"\" The document range for which inlay hints should be computed. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n\n\nclass InlayHint(TypedDict):\n    \"\"\"Inlay hint information.\n\n    @since 3.17.0\n    \"\"\"\n\n    position: \"Position\"\n    \"\"\" The position of this hint. \"\"\"\n    label: str | list[\"InlayHintLabelPart\"]\n    \"\"\" The label of this hint. A human readable string or an array of\n    InlayHintLabelPart label parts.\n\n    *Note* that neither the string nor the label part can be empty. \"\"\"\n    kind: NotRequired[\"InlayHintKind\"]\n    \"\"\" The kind of this hint. Can be omitted in which case the client\n    should fall back to a reasonable default. \"\"\"\n    textEdits: NotRequired[list[\"TextEdit\"]]\n    \"\"\" Optional text edits that are performed when accepting this inlay hint.\n\n    *Note* that edits are expected to change the document so that the inlay\n    hint (or its nearest variant) is now part of the document and the inlay\n    hint itself is now obsolete. \"\"\"\n    tooltip: NotRequired[Union[str, \"MarkupContent\"]]\n    \"\"\" The tooltip text when you hover over this item. \"\"\"\n    paddingLeft: NotRequired[bool]\n    \"\"\" Render padding before the hint.\n\n    Note: Padding should use the editor's background color, not the\n    background color of the hint itself. That means padding can be used\n    to visually align/separate an inlay hint. \"\"\"\n    paddingRight: NotRequired[bool]\n    \"\"\" Render padding after the hint.\n\n    Note: Padding should use the editor's background color, not the\n    background color of the hint itself. That means padding can be used\n    to visually align/separate an inlay hint. \"\"\"\n    data: NotRequired[\"LSPAny\"]\n    \"\"\" A data entry field that is preserved on an inlay hint between\n    a `textDocument/inlayHint` and a `inlayHint/resolve` request. \"\"\"\n\n\nclass InlayHintRegistrationOptions(TypedDict):\n    \"\"\"Inlay hint options used during static or dynamic registration.\n\n    @since 3.17.0\n    \"\"\"\n\n    resolveProvider: NotRequired[bool]\n    \"\"\" The server provides support to resolve additional\n    information for an inlay hint item. \"\"\"\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    id: NotRequired[str]\n    \"\"\" The id used to register the request. The id can be used to deregister\n    the request again. See also Registration#id. \"\"\"\n\n\nclass DocumentDiagnosticParams(TypedDict):\n    \"\"\"Parameters of the document diagnostic request.\n\n    @since 3.17.0\n    \"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    identifier: NotRequired[str]\n    \"\"\" The additional identifier  provided during registration. \"\"\"\n    previousResultId: NotRequired[str]\n    \"\"\" The result id of a previous response if provided. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass DocumentDiagnosticReportPartialResult(TypedDict):\n    \"\"\"A partial result for a document diagnostic report.\n\n    @since 3.17.0\n    \"\"\"\n\n    relatedDocuments: dict[\n        \"DocumentUri\",\n        Union[\"FullDocumentDiagnosticReport\", \"UnchangedDocumentDiagnosticReport\"],\n    ]\n\n\nclass DiagnosticServerCancellationData(TypedDict):\n    \"\"\"Cancellation data returned from a diagnostic request.\n\n    @since 3.17.0\n    \"\"\"\n\n    retriggerRequest: bool\n\n\nclass DiagnosticRegistrationOptions(TypedDict):\n    \"\"\"Diagnostic registration options.\n\n    @since 3.17.0\n    \"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    identifier: NotRequired[str]\n    \"\"\" An optional identifier under which the diagnostics are\n    managed by the client. \"\"\"\n    interFileDependencies: bool\n    \"\"\" Whether the language has inter file dependencies meaning that\n    editing code in one file can result in a different diagnostic\n    set in another file. Inter file dependencies are common for\n    most programming languages and typically uncommon for linters. \"\"\"\n    workspaceDiagnostics: bool\n    \"\"\" The server provides support for workspace diagnostics as well. \"\"\"\n    id: NotRequired[str]\n    \"\"\" The id used to register the request. The id can be used to deregister\n    the request again. See also Registration#id. \"\"\"\n\n\nclass WorkspaceDiagnosticParams(TypedDict):\n    \"\"\"Parameters of the workspace diagnostic request.\n\n    @since 3.17.0\n    \"\"\"\n\n    identifier: NotRequired[str]\n    \"\"\" The additional identifier provided during registration. \"\"\"\n    previousResultIds: list[\"PreviousResultId\"]\n    \"\"\" The currently known diagnostic reports with their\n    previous result ids. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass WorkspaceDiagnosticReport(TypedDict):\n    \"\"\"A workspace diagnostic report.\n\n    @since 3.17.0\n    \"\"\"\n\n    items: list[\"WorkspaceDocumentDiagnosticReport\"]\n\n\nclass WorkspaceDiagnosticReportPartialResult(TypedDict):\n    \"\"\"A partial result for a workspace diagnostic report.\n\n    @since 3.17.0\n    \"\"\"\n\n    items: list[\"WorkspaceDocumentDiagnosticReport\"]\n\n\nclass DidOpenNotebookDocumentParams(TypedDict):\n    \"\"\"The params sent in an open notebook document notification.\n\n    @since 3.17.0\n    \"\"\"\n\n    notebookDocument: \"NotebookDocument\"\n    \"\"\" The notebook document that got opened. \"\"\"\n    cellTextDocuments: list[\"TextDocumentItem\"]\n    \"\"\" The text documents that represent the content\n    of a notebook cell. \"\"\"\n\n\nclass DidChangeNotebookDocumentParams(TypedDict):\n    \"\"\"The params sent in a change notebook document notification.\n\n    @since 3.17.0\n    \"\"\"\n\n    notebookDocument: \"VersionedNotebookDocumentIdentifier\"\n    \"\"\" The notebook document that did change. The version number points\n    to the version after all provided changes have been applied. If\n    only the text document content of a cell changes the notebook version\n    doesn't necessarily have to change. \"\"\"\n    change: \"NotebookDocumentChangeEvent\"\n    \"\"\" The actual changes to the notebook document.\n\n    The changes describe single state changes to the notebook document.\n    So if there are two changes c1 (at array index 0) and c2 (at array\n    index 1) for a notebook in state S then c1 moves the notebook from\n    S to S' and c2 from S' to S''. So c1 is computed on the state S and\n    c2 is computed on the state S'.\n\n    To mirror the content of a notebook using change events use the following approach:\n    - start with the same initial content\n    - apply the 'notebookDocument/didChange' notifications in the order you receive them.\n    - apply the `NotebookChangeEvent`s in a single notification in the order\n      you receive them. \"\"\"\n\n\nclass DidSaveNotebookDocumentParams(TypedDict):\n    \"\"\"The params sent in a save notebook document notification.\n\n    @since 3.17.0\n    \"\"\"\n\n    notebookDocument: \"NotebookDocumentIdentifier\"\n    \"\"\" The notebook document that got saved. \"\"\"\n\n\nclass DidCloseNotebookDocumentParams(TypedDict):\n    \"\"\"The params sent in a close notebook document notification.\n\n    @since 3.17.0\n    \"\"\"\n\n    notebookDocument: \"NotebookDocumentIdentifier\"\n    \"\"\" The notebook document that got closed. \"\"\"\n    cellTextDocuments: list[\"TextDocumentIdentifier\"]\n    \"\"\" The text documents that represent the content\n    of a notebook cell that got closed. \"\"\"\n\n\nclass RegistrationParams(TypedDict):\n    registrations: list[\"Registration\"]\n\n\nclass UnregistrationParams(TypedDict):\n    unregisterations: list[\"Unregistration\"]\n\n\nclass InitializeParams(TypedDict):\n    processId: int | None\n    \"\"\" The process Id of the parent process that started\n    the server.\n\n    Is `null` if the process has not been started by another process.\n    If the parent process is not alive then the server should exit. \"\"\"\n    clientInfo: NotRequired[\"___InitializeParams_clientInfo_Type_1\"]\n    \"\"\" Information about the client\n\n    @since 3.15.0 \"\"\"\n    locale: NotRequired[str]\n    \"\"\" The locale the client is currently showing the user interface\n    in. This must not necessarily be the locale of the operating\n    system.\n\n    Uses IETF language tags as the value's syntax\n    (See https://en.wikipedia.org/wiki/IETF_language_tag)\n\n    @since 3.16.0 \"\"\"\n    rootPath: NotRequired[str | None]\n    \"\"\" The rootPath of the workspace. Is null\n    if no folder is open.\n\n    @deprecated in favour of rootUri. \"\"\"\n    rootUri: Union[\"DocumentUri\", None]\n    \"\"\" The rootUri of the workspace. Is null if no\n    folder is open. If both `rootPath` and `rootUri` are set\n    `rootUri` wins.\n\n    @deprecated in favour of workspaceFolders. \"\"\"\n    capabilities: \"ClientCapabilities\"\n    \"\"\" The capabilities provided by the client (editor or tool) \"\"\"\n    initializationOptions: NotRequired[\"LSPAny\"]\n    \"\"\" User provided initialization options. \"\"\"\n    trace: NotRequired[\"TraceValues\"]\n    \"\"\" The initial trace setting. If omitted trace is disabled ('off'). \"\"\"\n    workspaceFolders: NotRequired[list[\"WorkspaceFolder\"] | None]\n    \"\"\" The workspace folders configured in the client when the server starts.\n\n    This property is only available if the client supports workspace folders.\n    It can be `null` if the client supports workspace folders but none are\n    configured.\n\n    @since 3.6.0 \"\"\"\n\n\nclass InitializeResult(TypedDict):\n    \"\"\"The result returned from an initialize request.\"\"\"\n\n    capabilities: \"ServerCapabilities\"\n    \"\"\" The capabilities the language server provides. \"\"\"\n    serverInfo: NotRequired[\"__InitializeResult_serverInfo_Type_1\"]\n    \"\"\" Information about the server.\n\n    @since 3.15.0 \"\"\"\n\n\nclass InitializeError(TypedDict):\n    \"\"\"The data type of the ResponseError if the\n    initialize request fails.\n    \"\"\"\n\n    retry: bool\n    \"\"\" Indicates whether the client execute the following retry logic:\n    (1) show the message provided by the ResponseError to the user\n    (2) user selects retry or cancel\n    (3) if user selected retry the initialize method is sent again. \"\"\"\n\n\nclass InitializedParams(TypedDict):\n    pass\n\n\nclass DidChangeConfigurationParams(TypedDict):\n    \"\"\"The parameters of a change configuration notification.\"\"\"\n\n    settings: \"LSPAny\"\n    \"\"\" The actual changed settings \"\"\"\n\n\nclass DidChangeConfigurationRegistrationOptions(TypedDict):\n    section: NotRequired[str | list[str]]\n\n\nclass ShowMessageParams(TypedDict):\n    \"\"\"The parameters of a notification message.\"\"\"\n\n    type: \"MessageType\"\n    \"\"\" The message type. See {@link MessageType} \"\"\"\n    message: str\n    \"\"\" The actual message. \"\"\"\n\n\nclass ShowMessageRequestParams(TypedDict):\n    type: \"MessageType\"\n    \"\"\" The message type. See {@link MessageType} \"\"\"\n    message: str\n    \"\"\" The actual message. \"\"\"\n    actions: NotRequired[list[\"MessageActionItem\"]]\n    \"\"\" The message action items to present. \"\"\"\n\n\nclass MessageActionItem(TypedDict):\n    title: str\n    \"\"\" A short title like 'Retry', 'Open Log' etc. \"\"\"\n\n\nclass LogMessageParams(TypedDict):\n    \"\"\"The log message parameters.\"\"\"\n\n    type: \"MessageType\"\n    \"\"\" The message type. See {@link MessageType} \"\"\"\n    message: str\n    \"\"\" The actual message. \"\"\"\n\n\nclass DidOpenTextDocumentParams(TypedDict):\n    \"\"\"The parameters sent in an open text document notification\"\"\"\n\n    textDocument: \"TextDocumentItem\"\n    \"\"\" The document that was opened. \"\"\"\n\n\nclass DidChangeTextDocumentParams(TypedDict):\n    \"\"\"The change text document notification's parameters.\"\"\"\n\n    textDocument: \"VersionedTextDocumentIdentifier\"\n    \"\"\" The document that did change. The version number points\n    to the version after all provided content changes have\n    been applied. \"\"\"\n    contentChanges: list[\"TextDocumentContentChangeEvent\"]\n    \"\"\" The actual content changes. The content changes describe single state changes\n    to the document. So if there are two content changes c1 (at array index 0) and\n    c2 (at array index 1) for a document in state S then c1 moves the document from\n    S to S' and c2 from S' to S''. So c1 is computed on the state S and c2 is computed\n    on the state S'.\n\n    To mirror the content of a document using change events use the following approach:\n    - start with the same initial content\n    - apply the 'textDocument/didChange' notifications in the order you receive them.\n    - apply the `TextDocumentContentChangeEvent`s in a single notification in the order\n      you receive them. \"\"\"\n\n\nclass TextDocumentChangeRegistrationOptions(TypedDict):\n    \"\"\"Describe options to be used when registered for text document change events.\"\"\"\n\n    syncKind: \"TextDocumentSyncKind\"\n    \"\"\" How documents are synced to the server. \"\"\"\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n\n\nclass DidCloseTextDocumentParams(TypedDict):\n    \"\"\"The parameters sent in a close text document notification\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The document that was closed. \"\"\"\n\n\nclass DidSaveTextDocumentParams(TypedDict):\n    \"\"\"The parameters sent in a save text document notification\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The document that was saved. \"\"\"\n    text: NotRequired[str]\n    \"\"\" Optional the content when saved. Depends on the includeText value\n    when the save notification was requested. \"\"\"\n\n\nclass TextDocumentSaveRegistrationOptions(TypedDict):\n    \"\"\"Save registration options.\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    includeText: NotRequired[bool]\n    \"\"\" The client is supposed to include the content on save. \"\"\"\n\n\nclass WillSaveTextDocumentParams(TypedDict):\n    \"\"\"The parameters sent in a will save text document notification.\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The document that will be saved. \"\"\"\n    reason: \"TextDocumentSaveReason\"\n    \"\"\" The 'TextDocumentSaveReason'. \"\"\"\n\n\nclass TextEdit(TypedDict):\n    \"\"\"A text edit applicable to a text document.\"\"\"\n\n    range: \"Range\"\n    \"\"\" The range of the text document to be manipulated. To insert\n    text into a document create a range where start === end. \"\"\"\n    newText: str\n    \"\"\" The string to be inserted. For delete operations use an\n    empty string. \"\"\"\n\n\nclass DidChangeWatchedFilesParams(TypedDict):\n    \"\"\"The watched files change notification's parameters.\"\"\"\n\n    changes: list[\"FileEvent\"]\n    \"\"\" The actual file events. \"\"\"\n\n\nclass DidChangeWatchedFilesRegistrationOptions(TypedDict):\n    \"\"\"Describe options to be used when registered for text document change events.\"\"\"\n\n    watchers: list[\"FileSystemWatcher\"]\n    \"\"\" The watchers to register. \"\"\"\n\n\nclass PublishDiagnosticsParams(TypedDict):\n    \"\"\"The publish diagnostic notification's parameters.\"\"\"\n\n    uri: \"DocumentUri\"\n    \"\"\" The URI for which diagnostic information is reported. \"\"\"\n    version: NotRequired[int]\n    \"\"\" Optional the version number of the document the diagnostics are published for.\n\n    @since 3.15.0 \"\"\"\n    diagnostics: list[\"Diagnostic\"]\n    \"\"\" An array of diagnostic information items. \"\"\"\n\n\nclass CompletionParams(TypedDict):\n    \"\"\"Completion parameters\"\"\"\n\n    context: NotRequired[\"CompletionContext\"]\n    \"\"\" The completion context. This is only available it the client specifies\n    to send this using the client capability `textDocument.completion.contextSupport === true` \"\"\"\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    position: \"Position\"\n    \"\"\" The position inside the text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass CompletionItem(TypedDict):\n    \"\"\"A completion item represents a text snippet that is\n    proposed to complete text that is being typed.\n    \"\"\"\n\n    label: str\n    \"\"\" The label of this completion item.\n\n    The label property is also by default the text that\n    is inserted when selecting this completion.\n\n    If label details are provided the label itself should\n    be an unqualified name of the completion item. \"\"\"\n    labelDetails: NotRequired[\"CompletionItemLabelDetails\"]\n    \"\"\" Additional details for the label\n\n    @since 3.17.0 \"\"\"\n    kind: NotRequired[\"CompletionItemKind\"]\n    \"\"\" The kind of this completion item. Based of the kind\n    an icon is chosen by the editor. \"\"\"\n    tags: NotRequired[list[\"CompletionItemTag\"]]\n    \"\"\" Tags for this completion item.\n\n    @since 3.15.0 \"\"\"\n    detail: NotRequired[str]\n    \"\"\" A human-readable string with additional information\n    about this item, like type or symbol information. \"\"\"\n    documentation: NotRequired[Union[str, \"MarkupContent\"]]\n    \"\"\" A human-readable string that represents a doc-comment. \"\"\"\n    deprecated: NotRequired[bool]\n    \"\"\" Indicates if this item is deprecated.\n    @deprecated Use `tags` instead. \"\"\"\n    preselect: NotRequired[bool]\n    \"\"\" Select this item when showing.\n\n    *Note* that only one completion item can be selected and that the\n    tool / client decides which item that is. The rule is that the *first*\n    item of those that match best is selected. \"\"\"\n    sortText: NotRequired[str]\n    \"\"\" A string that should be used when comparing this item\n    with other items. When `falsy` the {@link CompletionItem.label label}\n    is used. \"\"\"\n    filterText: NotRequired[str]\n    \"\"\" A string that should be used when filtering a set of\n    completion items. When `falsy` the {@link CompletionItem.label label}\n    is used. \"\"\"\n    insertText: NotRequired[str]\n    \"\"\" A string that should be inserted into a document when selecting\n    this completion. When `falsy` the {@link CompletionItem.label label}\n    is used.\n\n    The `insertText` is subject to interpretation by the client side.\n    Some tools might not take the string literally. For example\n    VS Code when code complete is requested in this example\n    `con<cursor position>` and a completion item with an `insertText` of\n    `console` is provided it will only insert `sole`. Therefore it is\n    recommended to use `textEdit` instead since it avoids additional client\n    side interpretation. \"\"\"\n    insertTextFormat: NotRequired[\"InsertTextFormat\"]\n    \"\"\" The format of the insert text. The format applies to both the\n    `insertText` property and the `newText` property of a provided\n    `textEdit`. If omitted defaults to `InsertTextFormat.PlainText`.\n\n    Please note that the insertTextFormat doesn't apply to\n    `additionalTextEdits`. \"\"\"\n    insertTextMode: NotRequired[\"InsertTextMode\"]\n    \"\"\" How whitespace and indentation is handled during completion\n    item insertion. If not provided the clients default value depends on\n    the `textDocument.completion.insertTextMode` client capability.\n\n    @since 3.16.0 \"\"\"\n    textEdit: NotRequired[Union[\"TextEdit\", \"InsertReplaceEdit\"]]\n    \"\"\" An {@link TextEdit edit} which is applied to a document when selecting\n    this completion. When an edit is provided the value of\n    {@link CompletionItem.insertText insertText} is ignored.\n\n    Most editors support two different operations when accepting a completion\n    item. One is to insert a completion text and the other is to replace an\n    existing text with a completion text. Since this can usually not be\n    predetermined by a server it can report both ranges. Clients need to\n    signal support for `InsertReplaceEdits` via the\n    `textDocument.completion.insertReplaceSupport` client capability\n    property.\n\n    *Note 1:* The text edit's range as well as both ranges from an insert\n    replace edit must be a [single line] and they must contain the position\n    at which completion has been requested.\n    *Note 2:* If an `InsertReplaceEdit` is returned the edit's insert range\n    must be a prefix of the edit's replace range, that means it must be\n    contained and starting at the same position.\n\n    @since 3.16.0 additional type `InsertReplaceEdit` \"\"\"\n    textEditText: NotRequired[str]\n    \"\"\" The edit text used if the completion item is part of a CompletionList and\n    CompletionList defines an item default for the text edit range.\n\n    Clients will only honor this property if they opt into completion list\n    item defaults using the capability `completionList.itemDefaults`.\n\n    If not provided and a list's default range is provided the label\n    property is used as a text.\n\n    @since 3.17.0 \"\"\"\n    additionalTextEdits: NotRequired[list[\"TextEdit\"]]\n    \"\"\" An optional array of additional {@link TextEdit text edits} that are applied when\n    selecting this completion. Edits must not overlap (including the same insert position)\n    with the main {@link CompletionItem.textEdit edit} nor with themselves.\n\n    Additional text edits should be used to change text unrelated to the current cursor position\n    (for example adding an import statement at the top of the file if the completion item will\n    insert an unqualified type). \"\"\"\n    commitCharacters: NotRequired[list[str]]\n    \"\"\" An optional set of characters that when pressed while this completion is active will accept it first and\n    then type that character. *Note* that all commit characters should have `length=1` and that superfluous\n    characters will be ignored. \"\"\"\n    command: NotRequired[\"Command\"]\n    \"\"\" An optional {@link Command command} that is executed *after* inserting this completion. *Note* that\n    additional modifications to the current document should be described with the\n    {@link CompletionItem.additionalTextEdits additionalTextEdits}-property. \"\"\"\n    data: NotRequired[\"LSPAny\"]\n    \"\"\" A data entry field that is preserved on a completion item between a\n    {@link CompletionRequest} and a {@link CompletionResolveRequest}. \"\"\"\n\n\nclass CompletionList(TypedDict):\n    \"\"\"Represents a collection of {@link CompletionItem completion items} to be presented\n    in the editor.\n    \"\"\"\n\n    isIncomplete: bool\n    \"\"\" This list it not complete. Further typing results in recomputing this list.\n\n    Recomputed lists have all their items replaced (not appended) in the\n    incomplete completion sessions. \"\"\"\n    itemDefaults: NotRequired[\"__CompletionList_itemDefaults_Type_1\"]\n    \"\"\" In many cases the items of an actual completion result share the same\n    value for properties like `commitCharacters` or the range of a text\n    edit. A completion list can therefore define item defaults which will\n    be used if a completion item itself doesn't specify the value.\n\n    If a completion list specifies a default value and a completion item\n    also specifies a corresponding value the one from the item is used.\n\n    Servers are only allowed to return default values if the client\n    signals support for this via the `completionList.itemDefaults`\n    capability.\n\n    @since 3.17.0 \"\"\"\n    items: list[\"CompletionItem\"]\n    \"\"\" The completion items. \"\"\"\n\n\nclass CompletionRegistrationOptions(TypedDict):\n    \"\"\"Registration options for a {@link CompletionRequest}.\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    triggerCharacters: NotRequired[list[str]]\n    \"\"\" Most tools trigger completion request automatically without explicitly requesting\n    it using a keyboard shortcut (e.g. Ctrl+Space). Typically they do so when the user\n    starts to type an identifier. For example if the user types `c` in a JavaScript file\n    code complete will automatically pop up present `console` besides others as a\n    completion item. Characters that make up identifiers don't need to be listed here.\n\n    If code complete should automatically be trigger on characters not being valid inside\n    an identifier (for example `.` in JavaScript) list them in `triggerCharacters`. \"\"\"\n    allCommitCharacters: NotRequired[list[str]]\n    \"\"\" The list of all possible characters that commit a completion. This field can be used\n    if clients don't support individual commit characters per completion item. See\n    `ClientCapabilities.textDocument.completion.completionItem.commitCharactersSupport`\n\n    If a server provides both `allCommitCharacters` and commit characters on an individual\n    completion item the ones on the completion item win.\n\n    @since 3.2.0 \"\"\"\n    resolveProvider: NotRequired[bool]\n    \"\"\" The server provides support to resolve additional\n    information for a completion item. \"\"\"\n    completionItem: NotRequired[\"__CompletionOptions_completionItem_Type_1\"]\n    \"\"\" The server supports the following `CompletionItem` specific\n    capabilities.\n\n    @since 3.17.0 \"\"\"\n\n\nclass HoverParams(TypedDict):\n    \"\"\"Parameters for a {@link HoverRequest}.\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    position: \"Position\"\n    \"\"\" The position inside the text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n\n\nclass Hover(TypedDict):\n    \"\"\"The result of a hover request.\"\"\"\n\n    contents: Union[\"MarkupContent\", \"MarkedString\", list[\"MarkedString\"]]\n    \"\"\" The hover's content \"\"\"\n    range: NotRequired[\"Range\"]\n    \"\"\" An optional range inside the text document that is used to\n    visualize the hover, e.g. by changing the background color. \"\"\"\n\n\nclass HoverRegistrationOptions(TypedDict):\n    \"\"\"Registration options for a {@link HoverRequest}.\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n\n\nclass SignatureHelpParams(TypedDict):\n    \"\"\"Parameters for a {@link SignatureHelpRequest}.\"\"\"\n\n    context: NotRequired[\"SignatureHelpContext\"]\n    \"\"\" The signature help context. This is only available if the client specifies\n    to send this using the client capability `textDocument.signatureHelp.contextSupport === true`\n\n    @since 3.15.0 \"\"\"\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    position: \"Position\"\n    \"\"\" The position inside the text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n\n\nclass SignatureHelp(TypedDict):\n    \"\"\"Signature help represents the signature of something\n    callable. There can be multiple signature but only one\n    active and only one active parameter.\n    \"\"\"\n\n    signatures: list[\"SignatureInformation\"]\n    \"\"\" One or more signatures. \"\"\"\n    activeSignature: NotRequired[Uint]\n    \"\"\" The active signature. If omitted or the value lies outside the\n    range of `signatures` the value defaults to zero or is ignored if\n    the `SignatureHelp` has no signatures.\n\n    Whenever possible implementers should make an active decision about\n    the active signature and shouldn't rely on a default value.\n\n    In future version of the protocol this property might become\n    mandatory to better express this. \"\"\"\n    activeParameter: NotRequired[Uint]\n    \"\"\" The active parameter of the active signature. If omitted or the value\n    lies outside the range of `signatures[activeSignature].parameters`\n    defaults to 0 if the active signature has parameters. If\n    the active signature has no parameters it is ignored.\n    In future version of the protocol this property might become\n    mandatory to better express the active parameter if the\n    active signature does have any. \"\"\"\n\n\nclass SignatureHelpRegistrationOptions(TypedDict):\n    \"\"\"Registration options for a {@link SignatureHelpRequest}.\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    triggerCharacters: NotRequired[list[str]]\n    \"\"\" List of characters that trigger signature help automatically. \"\"\"\n    retriggerCharacters: NotRequired[list[str]]\n    \"\"\" List of characters that re-trigger signature help.\n\n    These trigger characters are only active when signature help is already showing. All trigger characters\n    are also counted as re-trigger characters.\n\n    @since 3.15.0 \"\"\"\n\n\nclass DefinitionParams(TypedDict):\n    \"\"\"Parameters for a {@link DefinitionRequest}.\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    position: \"Position\"\n    \"\"\" The position inside the text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass DefinitionRegistrationOptions(TypedDict):\n    \"\"\"Registration options for a {@link DefinitionRequest}.\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n\n\nclass ReferenceParams(TypedDict):\n    \"\"\"Parameters for a {@link ReferencesRequest}.\"\"\"\n\n    context: \"ReferenceContext\"\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    position: \"Position\"\n    \"\"\" The position inside the text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass ReferenceRegistrationOptions(TypedDict):\n    \"\"\"Registration options for a {@link ReferencesRequest}.\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n\n\nclass DocumentHighlightParams(TypedDict):\n    \"\"\"Parameters for a {@link DocumentHighlightRequest}.\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    position: \"Position\"\n    \"\"\" The position inside the text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass DocumentHighlight(TypedDict):\n    \"\"\"A document highlight is a range inside a text document which deserves\n    special attention. Usually a document highlight is visualized by changing\n    the background color of its range.\n    \"\"\"\n\n    range: \"Range\"\n    \"\"\" The range this highlight applies to. \"\"\"\n    kind: NotRequired[\"DocumentHighlightKind\"]\n    \"\"\" The highlight kind, default is {@link DocumentHighlightKind.Text text}. \"\"\"\n\n\nclass DocumentHighlightRegistrationOptions(TypedDict):\n    \"\"\"Registration options for a {@link DocumentHighlightRequest}.\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n\n\nclass DocumentSymbolParams(TypedDict):\n    \"\"\"Parameters for a {@link DocumentSymbolRequest}.\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass SymbolInformation(TypedDict):\n    \"\"\"Represents information about programming constructs like variables, classes,\n    interfaces etc.\n    \"\"\"\n\n    deprecated: NotRequired[bool]\n    \"\"\" Indicates if this symbol is deprecated.\n\n    @deprecated Use tags instead \"\"\"\n    location: \"Location\"\n    \"\"\" The location of this symbol. The location's range is used by a tool\n    to reveal the location in the editor. If the symbol is selected in the\n    tool the range's start information is used to position the cursor. So\n    the range usually spans more than the actual symbol's name and does\n    normally include things like visibility modifiers.\n\n    The range doesn't have to denote a node range in the sense of an abstract\n    syntax tree. It can therefore not be used to re-construct a hierarchy of\n    the symbols. \"\"\"\n    name: str\n    \"\"\" The name of this symbol. \"\"\"\n    kind: \"SymbolKind\"\n    \"\"\" The kind of this symbol. \"\"\"\n    tags: NotRequired[list[\"SymbolTag\"]]\n    \"\"\" Tags for this symbol.\n\n    @since 3.16.0 \"\"\"\n    containerName: NotRequired[str]\n    \"\"\" The name of the symbol containing this symbol. This information is for\n    user interface purposes (e.g. to render a qualifier in the user interface\n    if necessary). It can't be used to re-infer a hierarchy for the document\n    symbols. \"\"\"\n\n\nclass DocumentSymbol(TypedDict):\n    \"\"\"Represents programming constructs like variables, classes, interfaces etc.\n    that appear in a document. Document symbols can be hierarchical and they\n    have two ranges: one that encloses its definition and one that points to\n    its most interesting range, e.g. the range of an identifier.\n    \"\"\"\n\n    name: str\n    \"\"\" The name of this symbol. Will be displayed in the user interface and therefore must not be\n    an empty string or a string only consisting of white spaces. \"\"\"\n    detail: NotRequired[str]\n    \"\"\" More detail for this symbol, e.g the signature of a function. \"\"\"\n    kind: \"SymbolKind\"\n    \"\"\" The kind of this symbol. \"\"\"\n    tags: NotRequired[list[\"SymbolTag\"]]\n    \"\"\" Tags for this document symbol.\n\n    @since 3.16.0 \"\"\"\n    deprecated: NotRequired[bool]\n    \"\"\" Indicates if this symbol is deprecated.\n\n    @deprecated Use tags instead \"\"\"\n    range: \"Range\"\n    \"\"\" The range enclosing this symbol not including leading/trailing whitespace but everything else\n    like comments. This information is typically used to determine if the clients cursor is\n    inside the symbol to reveal in the symbol in the UI. \"\"\"\n    selectionRange: \"Range\"\n    \"\"\" The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.\n    Must be contained by the `range`. \"\"\"\n\n    # TODO: I think this type is missing the 'children' field - DJ\n\n\nclass DocumentSymbolRegistrationOptions(TypedDict):\n    \"\"\"Registration options for a {@link DocumentSymbolRequest}.\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    label: NotRequired[str]\n    \"\"\" A human-readable string that is shown when multiple outlines trees\n    are shown for the same document.\n\n    @since 3.16.0 \"\"\"\n\n\nclass CodeActionParams(TypedDict):\n    \"\"\"The parameters of a {@link CodeActionRequest}.\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The document in which the command was invoked. \"\"\"\n    range: \"Range\"\n    \"\"\" The range for which the command was invoked. \"\"\"\n    context: \"CodeActionContext\"\n    \"\"\" Context carrying additional information. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass Command(TypedDict):\n    \"\"\"Represents a reference to a command. Provides a title which\n    will be used to represent a command in the UI and, optionally,\n    an array of arguments which will be passed to the command handler\n    function when invoked.\n    \"\"\"\n\n    title: str\n    \"\"\" Title of the command, like `save`. \"\"\"\n    command: str\n    \"\"\" The identifier of the actual command handler. \"\"\"\n    arguments: NotRequired[list[\"LSPAny\"]]\n    \"\"\" Arguments that the command handler should be\n    invoked with. \"\"\"\n\n\nclass CodeAction(TypedDict):\n    \"\"\"A code action represents a change that can be performed in code, e.g. to fix a problem or\n    to refactor code.\n\n    A CodeAction must set either `edit` and/or a `command`. If both are supplied, the `edit` is applied first, then the `command` is executed.\n    \"\"\"\n\n    title: str\n    \"\"\" A short, human-readable, title for this code action. \"\"\"\n    kind: NotRequired[\"CodeActionKind\"]\n    \"\"\" The kind of the code action.\n\n    Used to filter code actions. \"\"\"\n    diagnostics: NotRequired[list[\"Diagnostic\"]]\n    \"\"\" The diagnostics that this code action resolves. \"\"\"\n    isPreferred: NotRequired[bool]\n    \"\"\" Marks this as a preferred action. Preferred actions are used by the `auto fix` command and can be targeted\n    by keybindings.\n\n    A quick fix should be marked preferred if it properly addresses the underlying error.\n    A refactoring should be marked preferred if it is the most reasonable choice of actions to take.\n\n    @since 3.15.0 \"\"\"\n    disabled: NotRequired[\"__CodeAction_disabled_Type_1\"]\n    \"\"\" Marks that the code action cannot currently be applied.\n\n    Clients should follow the following guidelines regarding disabled code actions:\n\n      - Disabled code actions are not shown in automatic [lightbulbs](https://code.visualstudio.com/docs/editor/editingevolved#_code-action)\n        code action menus.\n\n      - Disabled actions are shown as faded out in the code action menu when the user requests a more specific type\n        of code action, such as refactorings.\n\n      - If the user has a [keybinding](https://code.visualstudio.com/docs/editor/refactoring#_keybindings-for-code-actions)\n        that auto applies a code action and only disabled code actions are returned, the client should show the user an\n        error message with `reason` in the editor.\n\n    @since 3.16.0 \"\"\"\n    edit: NotRequired[\"WorkspaceEdit\"]\n    \"\"\" The workspace edit this code action performs. \"\"\"\n    command: NotRequired[\"Command\"]\n    \"\"\" A command this code action executes. If a code action\n    provides an edit and a command, first the edit is\n    executed and then the command. \"\"\"\n    data: NotRequired[\"LSPAny\"]\n    \"\"\" A data entry field that is preserved on a code action between\n    a `textDocument/codeAction` and a `codeAction/resolve` request.\n\n    @since 3.16.0 \"\"\"\n\n\nclass CodeActionRegistrationOptions(TypedDict):\n    \"\"\"Registration options for a {@link CodeActionRequest}.\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    codeActionKinds: NotRequired[list[\"CodeActionKind\"]]\n    \"\"\" CodeActionKinds that this server may return.\n\n    The list of kinds may be generic, such as `CodeActionKind.Refactor`, or the server\n    may list out every specific kind they provide. \"\"\"\n    resolveProvider: NotRequired[bool]\n    \"\"\" The server provides support to resolve additional\n    information for a code action.\n\n    @since 3.16.0 \"\"\"\n\n\nclass WorkspaceSymbolParams(TypedDict):\n    \"\"\"The parameters of a {@link WorkspaceSymbolRequest}.\"\"\"\n\n    query: str\n    \"\"\" A query string to filter symbols by. Clients may send an empty\n    string here to request all symbols. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass WorkspaceSymbol(TypedDict):\n    \"\"\"A special workspace symbol that supports locations without a range.\n\n    See also SymbolInformation.\n\n    @since 3.17.0\n    \"\"\"\n\n    location: Union[\"Location\", \"__WorkspaceSymbol_location_Type_1\"]\n    \"\"\" The location of the symbol. Whether a server is allowed to\n    return a location without a range depends on the client\n    capability `workspace.symbol.resolveSupport`.\n\n    See SymbolInformation#location for more details. \"\"\"\n    data: NotRequired[\"LSPAny\"]\n    \"\"\" A data entry field that is preserved on a workspace symbol between a\n    workspace symbol request and a workspace symbol resolve request. \"\"\"\n    name: str\n    \"\"\" The name of this symbol. \"\"\"\n    kind: \"SymbolKind\"\n    \"\"\" The kind of this symbol. \"\"\"\n    tags: NotRequired[list[\"SymbolTag\"]]\n    \"\"\" Tags for this symbol.\n\n    @since 3.16.0 \"\"\"\n    containerName: NotRequired[str]\n    \"\"\" The name of the symbol containing this symbol. This information is for\n    user interface purposes (e.g. to render a qualifier in the user interface\n    if necessary). It can't be used to re-infer a hierarchy for the document\n    symbols. \"\"\"\n\n\nclass WorkspaceSymbolRegistrationOptions(TypedDict):\n    \"\"\"Registration options for a {@link WorkspaceSymbolRequest}.\"\"\"\n\n    resolveProvider: NotRequired[bool]\n    \"\"\" The server provides support to resolve additional\n    information for a workspace symbol.\n\n    @since 3.17.0 \"\"\"\n\n\nclass CodeLensParams(TypedDict):\n    \"\"\"The parameters of a {@link CodeLensRequest}.\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The document to request code lens for. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass CodeLens(TypedDict):\n    \"\"\"A code lens represents a {@link Command command} that should be shown along with\n    source text, like the number of references, a way to run tests, etc.\n\n    A code lens is _unresolved_ when no command is associated to it. For performance\n    reasons the creation of a code lens and resolving should be done in two stages.\n    \"\"\"\n\n    range: \"Range\"\n    \"\"\" The range in which this code lens is valid. Should only span a single line. \"\"\"\n    command: NotRequired[\"Command\"]\n    \"\"\" The command this code lens represents. \"\"\"\n    data: NotRequired[\"LSPAny\"]\n    \"\"\" A data entry field that is preserved on a code lens item between\n    a {@link CodeLensRequest} and a [CodeLensResolveRequest]\n    (#CodeLensResolveRequest) \"\"\"\n\n\nclass CodeLensRegistrationOptions(TypedDict):\n    \"\"\"Registration options for a {@link CodeLensRequest}.\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    resolveProvider: NotRequired[bool]\n    \"\"\" Code lens has a resolve provider as well. \"\"\"\n\n\nclass DocumentLinkParams(TypedDict):\n    \"\"\"The parameters of a {@link DocumentLinkRequest}.\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The document to provide document links for. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass DocumentLink(TypedDict):\n    \"\"\"A document link is a range in a text document that links to an internal or external resource, like another\n    text document or a web site.\n    \"\"\"\n\n    range: \"Range\"\n    \"\"\" The range this link applies to. \"\"\"\n    target: NotRequired[str]\n    \"\"\" The uri this link points to. If missing a resolve request is sent later. \"\"\"\n    tooltip: NotRequired[str]\n    \"\"\" The tooltip text when you hover over this link.\n\n    If a tooltip is provided, is will be displayed in a string that includes instructions on how to\n    trigger the link, such as `{0} (ctrl + click)`. The specific instructions vary depending on OS,\n    user settings, and localization.\n\n    @since 3.15.0 \"\"\"\n    data: NotRequired[\"LSPAny\"]\n    \"\"\" A data entry field that is preserved on a document link between a\n    DocumentLinkRequest and a DocumentLinkResolveRequest. \"\"\"\n\n\nclass DocumentLinkRegistrationOptions(TypedDict):\n    \"\"\"Registration options for a {@link DocumentLinkRequest}.\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    resolveProvider: NotRequired[bool]\n    \"\"\" Document links have a resolve provider as well. \"\"\"\n\n\nclass DocumentFormattingParams(TypedDict):\n    \"\"\"The parameters of a {@link DocumentFormattingRequest}.\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The document to format. \"\"\"\n    options: \"FormattingOptions\"\n    \"\"\" The format options. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n\n\nclass DocumentFormattingRegistrationOptions(TypedDict):\n    \"\"\"Registration options for a {@link DocumentFormattingRequest}.\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n\n\nclass DocumentRangeFormattingParams(TypedDict):\n    \"\"\"The parameters of a {@link DocumentRangeFormattingRequest}.\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The document to format. \"\"\"\n    range: \"Range\"\n    \"\"\" The range to format \"\"\"\n    options: \"FormattingOptions\"\n    \"\"\" The format options \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n\n\nclass DocumentRangeFormattingRegistrationOptions(TypedDict):\n    \"\"\"Registration options for a {@link DocumentRangeFormattingRequest}.\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n\n\nclass DocumentOnTypeFormattingParams(TypedDict):\n    \"\"\"The parameters of a {@link DocumentOnTypeFormattingRequest}.\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The document to format. \"\"\"\n    position: \"Position\"\n    \"\"\" The position around which the on type formatting should happen.\n    This is not necessarily the exact position where the character denoted\n    by the property `ch` got typed. \"\"\"\n    ch: str\n    \"\"\" The character that has been typed that triggered the formatting\n    on type request. That is not necessarily the last character that\n    got inserted into the document since the client could auto insert\n    characters as well (e.g. like automatic brace completion). \"\"\"\n    options: \"FormattingOptions\"\n    \"\"\" The formatting options. \"\"\"\n\n\nclass DocumentOnTypeFormattingRegistrationOptions(TypedDict):\n    \"\"\"Registration options for a {@link DocumentOnTypeFormattingRequest}.\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    firstTriggerCharacter: str\n    \"\"\" A character on which formatting should be triggered, like `{`. \"\"\"\n    moreTriggerCharacter: NotRequired[list[str]]\n    \"\"\" More trigger characters. \"\"\"\n\n\nclass RenameParams(TypedDict):\n    \"\"\"The parameters of a {@link RenameRequest}.\"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The document to rename. \"\"\"\n    position: \"Position\"\n    \"\"\" The position at which this request was sent. \"\"\"\n    newName: str\n    \"\"\" The new name of the symbol. If the given name is not valid the\n    request must return a {@link ResponseError} with an\n    appropriate message set. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n\n\nclass RenameRegistrationOptions(TypedDict):\n    \"\"\"Registration options for a {@link RenameRequest}.\"\"\"\n\n    documentSelector: Union[\"DocumentSelector\", None]\n    \"\"\" A document selector to identify the scope of the registration. If set to null\n    the document selector provided on the client side will be used. \"\"\"\n    prepareProvider: NotRequired[bool]\n    \"\"\" Renames should be checked and tested before being executed.\n\n    @since version 3.12.0 \"\"\"\n\n\nclass PrepareRenameParams(TypedDict):\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    position: \"Position\"\n    \"\"\" The position inside the text document. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n\n\nclass ExecuteCommandParams(TypedDict):\n    \"\"\"The parameters of a {@link ExecuteCommandRequest}.\"\"\"\n\n    command: str\n    \"\"\" The identifier of the actual command handler. \"\"\"\n    arguments: NotRequired[list[\"LSPAny\"]]\n    \"\"\" Arguments that the command should be invoked with. \"\"\"\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n\n\nclass ExecuteCommandRegistrationOptions(TypedDict):\n    \"\"\"Registration options for a {@link ExecuteCommandRequest}.\"\"\"\n\n    commands: list[str]\n    \"\"\" The commands to be executed on the server \"\"\"\n\n\nclass ApplyWorkspaceEditParams(TypedDict):\n    \"\"\"The parameters passed via a apply workspace edit request.\"\"\"\n\n    label: NotRequired[str]\n    \"\"\" An optional label of the workspace edit. This label is\n    presented in the user interface for example on an undo\n    stack to undo the workspace edit. \"\"\"\n    edit: \"WorkspaceEdit\"\n    \"\"\" The edits to apply. \"\"\"\n\n\nclass ApplyWorkspaceEditResult(TypedDict):\n    \"\"\"The result returned from the apply workspace edit request.\n\n    @since 3.17 renamed from ApplyWorkspaceEditResponse\n    \"\"\"\n\n    applied: bool\n    \"\"\" Indicates whether the edit was applied or not. \"\"\"\n    failureReason: NotRequired[str]\n    \"\"\" An optional textual description for why the edit was not applied.\n    This may be used by the server for diagnostic logging or to provide\n    a suitable error for a request that triggered the edit. \"\"\"\n    failedChange: NotRequired[Uint]\n    \"\"\" Depending on the client's failure handling strategy `failedChange` might\n    contain the index of the change that failed. This property is only available\n    if the client signals a `failureHandlingStrategy` in its client capabilities. \"\"\"\n\n\nclass WorkDoneProgressBegin(TypedDict):\n    kind: Literal[\"begin\"]\n    title: str\n    \"\"\" Mandatory title of the progress operation. Used to briefly inform about\n    the kind of operation being performed.\n\n    Examples: \"Indexing\" or \"Linking dependencies\". \"\"\"\n    cancellable: NotRequired[bool]\n    \"\"\" Controls if a cancel button should show to allow the user to cancel the\n    long running operation. Clients that don't support cancellation are allowed\n    to ignore the setting. \"\"\"\n    message: NotRequired[str]\n    \"\"\" Optional, more detailed associated progress message. Contains\n    complementary information to the `title`.\n\n    Examples: \"3/25 files\", \"project/src/module2\", \"node_modules/some_dep\".\n    If unset, the previous progress message (if any) is still valid. \"\"\"\n    percentage: NotRequired[Uint]\n    \"\"\" Optional progress percentage to display (value 100 is considered 100%).\n    If not provided infinite progress is assumed and clients are allowed\n    to ignore the `percentage` value in subsequent in report notifications.\n\n    The value should be steadily rising. Clients are free to ignore values\n    that are not following this rule. The value range is [0, 100]. \"\"\"\n\n\nclass WorkDoneProgressReport(TypedDict):\n    kind: Literal[\"report\"]\n    cancellable: NotRequired[bool]\n    \"\"\" Controls enablement state of a cancel button.\n\n    Clients that don't support cancellation or don't support controlling the button's\n    enablement state are allowed to ignore the property. \"\"\"\n    message: NotRequired[str]\n    \"\"\" Optional, more detailed associated progress message. Contains\n    complementary information to the `title`.\n\n    Examples: \"3/25 files\", \"project/src/module2\", \"node_modules/some_dep\".\n    If unset, the previous progress message (if any) is still valid. \"\"\"\n    percentage: NotRequired[Uint]\n    \"\"\" Optional progress percentage to display (value 100 is considered 100%).\n    If not provided infinite progress is assumed and clients are allowed\n    to ignore the `percentage` value in subsequent in report notifications.\n\n    The value should be steadily rising. Clients are free to ignore values\n    that are not following this rule. The value range is [0, 100] \"\"\"\n\n\nclass WorkDoneProgressEnd(TypedDict):\n    kind: Literal[\"end\"]\n    message: NotRequired[str]\n    \"\"\" Optional, a final message indicating to for example indicate the outcome\n    of the operation. \"\"\"\n\n\nclass SetTraceParams(TypedDict):\n    value: \"TraceValues\"\n\n\nclass LogTraceParams(TypedDict):\n    message: str\n    verbose: NotRequired[str]\n\n\nclass CancelParams(TypedDict):\n    id: int | str\n    \"\"\" The request id to cancel. \"\"\"\n\n\nclass ProgressParams(TypedDict):\n    token: \"ProgressToken\"\n    \"\"\" The progress token provided by the client or server. \"\"\"\n    value: \"LSPAny\"\n    \"\"\" The progress data. \"\"\"\n\n\nclass TextDocumentPositionParams(TypedDict):\n    \"\"\"A parameter literal used in requests to pass a text document and a position inside that\n    document.\n    \"\"\"\n\n    textDocument: \"TextDocumentIdentifier\"\n    \"\"\" The text document. \"\"\"\n    position: \"Position\"\n    \"\"\" The position inside the text document. \"\"\"\n\n\nclass WorkDoneProgressParams(TypedDict):\n    workDoneToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report work done progress. \"\"\"\n\n\nclass PartialResultParams(TypedDict):\n    partialResultToken: NotRequired[\"ProgressToken\"]\n    \"\"\" An optional token that a server can use to report partial results (e.g. streaming) to\n    the client. \"\"\"\n\n\nclass LocationLink(TypedDict):\n    \"\"\"Represents the connection of two locations. Provides additional metadata over normal {@link Location locations},\n    including an origin range.\n    \"\"\"\n\n    originSelectionRange: NotRequired[\"Range\"]\n    \"\"\" Span of the origin of this link.\n\n    Used as the underlined span for mouse interaction. Defaults to the word range at\n    the definition position. \"\"\"\n    targetUri: \"DocumentUri\"\n    \"\"\" The target resource identifier of this link. \"\"\"\n    targetRange: \"Range\"\n    \"\"\" The full target range of this link. If the target for example is a symbol then target range is the\n    range enclosing this symbol not including leading/trailing whitespace but everything else\n    like comments. This information is typically used to highlight the range in the editor. \"\"\"\n    targetSelectionRange: \"Range\"\n    \"\"\" The range that should be selected and revealed when this link is being followed, e.g the name of a function.\n    Must be contained by the `targetRange`. See also `DocumentSymbol#range` \"\"\"\n\n\nclass Range(TypedDict):\n    \"\"\"A range in a text document expressed as (zero-based) start and end positions.\n\n    If you want to specify a range that contains a line including the line ending\n    character(s) then use an end position denoting the start of the next line.\n    For example:\n    ```ts\n    {\n        start: { line: 5, character: 23 }\n        end : { line 6, character : 0 }\n    }\n    ```\n    \"\"\"\n\n    start: \"Position\"\n    \"\"\" The range's start position. \"\"\"\n    end: \"Position\"\n    \"\"\" The range's end position. \"\"\"\n\n\nclass ImplementationOptions(TypedDict):\n    workDoneProgress: NotRequired[bool]\n\n\nclass StaticRegistrationOptions(TypedDict):\n    \"\"\"Static registration options to be returned in the initialize\n    request.\n    \"\"\"\n\n    id: NotRequired[str]\n    \"\"\" The id used to register the request. The id can be used to deregister\n    the request again. See also Registration#id. \"\"\"\n\n\nclass TypeDefinitionOptions(TypedDict):\n    workDoneProgress: NotRequired[bool]\n\n\nclass WorkspaceFoldersChangeEvent(TypedDict):\n    \"\"\"The workspace folder change event.\"\"\"\n\n    added: list[\"WorkspaceFolder\"]\n    \"\"\" The array of added workspace folders \"\"\"\n    removed: list[\"WorkspaceFolder\"]\n    \"\"\" The array of the removed workspace folders \"\"\"\n\n\nclass ConfigurationItem(TypedDict):\n    scopeUri: NotRequired[str]\n    \"\"\" The scope to get the configuration section for. \"\"\"\n    section: NotRequired[str]\n    \"\"\" The configuration section asked for. \"\"\"\n\n\nclass TextDocumentIdentifier(TypedDict):\n    \"\"\"A literal to identify a text document in the client.\"\"\"\n\n    uri: \"DocumentUri\"\n    \"\"\" The text document's uri. \"\"\"\n\n\nclass Color(TypedDict):\n    \"\"\"Represents a color in RGBA space.\"\"\"\n\n    red: float\n    \"\"\" The red component of this color in the range [0-1]. \"\"\"\n    green: float\n    \"\"\" The green component of this color in the range [0-1]. \"\"\"\n    blue: float\n    \"\"\" The blue component of this color in the range [0-1]. \"\"\"\n    alpha: float\n    \"\"\" The alpha component of this color in the range [0-1]. \"\"\"\n\n\nclass DocumentColorOptions(TypedDict):\n    workDoneProgress: NotRequired[bool]\n\n\nclass FoldingRangeOptions(TypedDict):\n    workDoneProgress: NotRequired[bool]\n\n\nclass DeclarationOptions(TypedDict):\n    workDoneProgress: NotRequired[bool]\n\n\nclass Position(TypedDict):\n    r\"\"\"Position in a text document expressed as zero-based line and character\n    offset. Prior to 3.17 the offsets were always based on a UTF-16 string\n    representation. So a string of the form `a𐐀b` the character offset of the\n    character `a` is 0, the character offset of `𐐀` is 1 and the character\n    offset of b is 3 since `𐐀` is represented using two code units in UTF-16.\n    Since 3.17 clients and servers can agree on a different string encoding\n    representation (e.g. UTF-8). The client announces it's supported encoding\n    via the client capability [`general.positionEncodings`](#clientCapabilities).\n    The value is an array of position encodings the client supports, with\n    decreasing preference (e.g. the encoding at index `0` is the most preferred\n    one). To stay backwards compatible the only mandatory encoding is UTF-16\n    represented via the string `utf-16`. The server can pick one of the\n    encodings offered by the client and signals that encoding back to the\n    client via the initialize result's property\n    [`capabilities.positionEncoding`](#serverCapabilities). If the string value\n    `utf-16` is missing from the client's capability `general.positionEncodings`\n    servers can safely assume that the client supports UTF-16. If the server\n    omits the position encoding in its initialize result the encoding defaults\n    to the string value `utf-16`. Implementation considerations: since the\n    conversion from one encoding into another requires the content of the\n    file / line the conversion is best done where the file is read which is\n    usually on the server side.\n\n    Positions are line end character agnostic. So you can not specify a position\n    that denotes `\\r|\\n` or `\\n|` where `|` represents the character offset.\n\n    @since 3.17.0 - support for negotiated position encoding.\n    \"\"\"\n\n    line: Uint\n    \"\"\" Line position in a document (zero-based).\n\n    If a line number is greater than the number of lines in a document, it defaults back to the number of lines in the document.\n    If a line number is negative, it defaults to 0. \"\"\"\n    character: Uint\n    \"\"\" Character offset on a line in a document (zero-based).\n\n    The meaning of this offset is determined by the negotiated\n    `PositionEncodingKind`.\n\n    If the character value is greater than the line length it defaults back to the\n    line length. \"\"\"\n\n\nclass SelectionRangeOptions(TypedDict):\n    workDoneProgress: NotRequired[bool]\n\n\nclass CallHierarchyOptions(TypedDict):\n    \"\"\"Call hierarchy options used during static registration.\n\n    @since 3.16.0\n    \"\"\"\n\n    workDoneProgress: NotRequired[bool]\n\n\nclass SemanticTokensOptions(TypedDict):\n    \"\"\"@since 3.16.0\"\"\"\n\n    legend: \"SemanticTokensLegend\"\n    \"\"\" The legend used by the server \"\"\"\n    range: NotRequired[bool | dict]\n    \"\"\" Server supports providing semantic tokens for a specific range\n    of a document. \"\"\"\n    full: NotRequired[Union[bool, \"__SemanticTokensOptions_full_Type_2\"]]\n    \"\"\" Server supports providing semantic tokens for a full document. \"\"\"\n    workDoneProgress: NotRequired[bool]\n\n\nclass SemanticTokensEdit(TypedDict):\n    \"\"\"@since 3.16.0\"\"\"\n\n    start: Uint\n    \"\"\" The start offset of the edit. \"\"\"\n    deleteCount: Uint\n    \"\"\" The count of elements to remove. \"\"\"\n    data: NotRequired[list[Uint]]\n    \"\"\" The elements to insert. \"\"\"\n\n\nclass LinkedEditingRangeOptions(TypedDict):\n    workDoneProgress: NotRequired[bool]\n\n\nclass FileCreate(TypedDict):\n    \"\"\"Represents information on a file/folder create.\n\n    @since 3.16.0\n    \"\"\"\n\n    uri: str\n    \"\"\" A file:// URI for the location of the file/folder being created. \"\"\"\n\n\nclass TextDocumentEdit(TypedDict):\n    \"\"\"Describes textual changes on a text document. A TextDocumentEdit describes all changes\n    on a document version Si and after they are applied move the document to version Si+1.\n    So the creator of a TextDocumentEdit doesn't need to sort the array of edits or do any\n    kind of ordering. However the edits must be non overlapping.\n    \"\"\"\n\n    textDocument: \"OptionalVersionedTextDocumentIdentifier\"\n    \"\"\" The text document to change. \"\"\"\n    edits: list[Union[\"TextEdit\", \"AnnotatedTextEdit\"]]\n    \"\"\" The edits to be applied.\n\n    @since 3.16.0 - support for AnnotatedTextEdit. This is guarded using a\n    client capability. \"\"\"\n\n\nclass CreateFile(TypedDict):\n    \"\"\"Create file operation.\"\"\"\n\n    kind: Literal[\"create\"]\n    \"\"\" A create \"\"\"\n    uri: \"DocumentUri\"\n    \"\"\" The resource to create. \"\"\"\n    options: NotRequired[\"CreateFileOptions\"]\n    \"\"\" Additional options \"\"\"\n    annotationId: NotRequired[\"ChangeAnnotationIdentifier\"]\n    \"\"\" An optional annotation identifier describing the operation.\n\n    @since 3.16.0 \"\"\"\n\n\nclass RenameFile(TypedDict):\n    \"\"\"Rename file operation\"\"\"\n\n    kind: Literal[\"rename\"]\n    \"\"\" A rename \"\"\"\n    oldUri: \"DocumentUri\"\n    \"\"\" The old (existing) location. \"\"\"\n    newUri: \"DocumentUri\"\n    \"\"\" The new location. \"\"\"\n    options: NotRequired[\"RenameFileOptions\"]\n    \"\"\" Rename options. \"\"\"\n    annotationId: NotRequired[\"ChangeAnnotationIdentifier\"]\n    \"\"\" An optional annotation identifier describing the operation.\n\n    @since 3.16.0 \"\"\"\n\n\nclass DeleteFile(TypedDict):\n    \"\"\"Delete file operation\"\"\"\n\n    kind: Literal[\"delete\"]\n    \"\"\" A delete \"\"\"\n    uri: \"DocumentUri\"\n    \"\"\" The file to delete. \"\"\"\n    options: NotRequired[\"DeleteFileOptions\"]\n    \"\"\" Delete options. \"\"\"\n    annotationId: NotRequired[\"ChangeAnnotationIdentifier\"]\n    \"\"\" An optional annotation identifier describing the operation.\n\n    @since 3.16.0 \"\"\"\n\n\nclass ChangeAnnotation(TypedDict):\n    \"\"\"Additional information that describes document changes.\n\n    @since 3.16.0\n    \"\"\"\n\n    label: str\n    \"\"\" A human-readable string describing the actual change. The string\n    is rendered prominent in the user interface. \"\"\"\n    needsConfirmation: NotRequired[bool]\n    \"\"\" A flag which indicates that user confirmation is needed\n    before applying the change. \"\"\"\n    description: NotRequired[str]\n    \"\"\" A human-readable string which is rendered less prominent in\n    the user interface. \"\"\"\n\n\nclass FileOperationFilter(TypedDict):\n    \"\"\"A filter to describe in which file operation requests or notifications\n    the server is interested in receiving.\n\n    @since 3.16.0\n    \"\"\"\n\n    scheme: NotRequired[str]\n    \"\"\" A Uri scheme like `file` or `untitled`. \"\"\"\n    pattern: \"FileOperationPattern\"\n    \"\"\" The actual file operation pattern. \"\"\"\n\n\nclass FileRename(TypedDict):\n    \"\"\"Represents information on a file/folder rename.\n\n    @since 3.16.0\n    \"\"\"\n\n    oldUri: str\n    \"\"\" A file:// URI for the original location of the file/folder being renamed. \"\"\"\n    newUri: str\n    \"\"\" A file:// URI for the new location of the file/folder being renamed. \"\"\"\n\n\nclass FileDelete(TypedDict):\n    \"\"\"Represents information on a file/folder delete.\n\n    @since 3.16.0\n    \"\"\"\n\n    uri: str\n    \"\"\" A file:// URI for the location of the file/folder being deleted. \"\"\"\n\n\nclass MonikerOptions(TypedDict):\n    workDoneProgress: NotRequired[bool]\n\n\nclass TypeHierarchyOptions(TypedDict):\n    \"\"\"Type hierarchy options used during static registration.\n\n    @since 3.17.0\n    \"\"\"\n\n    workDoneProgress: NotRequired[bool]\n\n\nclass InlineValueContext(TypedDict):\n    \"\"\"@since 3.17.0\"\"\"\n\n    frameId: int\n    \"\"\" The stack frame (as a DAP Id) where the execution has stopped. \"\"\"\n    stoppedLocation: \"Range\"\n    \"\"\" The document range where execution has stopped.\n    Typically the end position of the range denotes the line where the inline values are shown. \"\"\"\n\n\nclass InlineValueText(TypedDict):\n    \"\"\"Provide inline value as text.\n\n    @since 3.17.0\n    \"\"\"\n\n    range: \"Range\"\n    \"\"\" The document range for which the inline value applies. \"\"\"\n    text: str\n    \"\"\" The text of the inline value. \"\"\"\n\n\nclass InlineValueVariableLookup(TypedDict):\n    \"\"\"Provide inline value through a variable lookup.\n    If only a range is specified, the variable name will be extracted from the underlying document.\n    An optional variable name can be used to override the extracted name.\n\n    @since 3.17.0\n    \"\"\"\n\n    range: \"Range\"\n    \"\"\" The document range for which the inline value applies.\n    The range is used to extract the variable name from the underlying document. \"\"\"\n    variableName: NotRequired[str]\n    \"\"\" If specified the name of the variable to look up. \"\"\"\n    caseSensitiveLookup: bool\n    \"\"\" How to perform the lookup. \"\"\"\n\n\nclass InlineValueEvaluatableExpression(TypedDict):\n    \"\"\"Provide an inline value through an expression evaluation.\n    If only a range is specified, the expression will be extracted from the underlying document.\n    An optional expression can be used to override the extracted expression.\n\n    @since 3.17.0\n    \"\"\"\n\n    range: \"Range\"\n    \"\"\" The document range for which the inline value applies.\n    The range is used to extract the evaluatable expression from the underlying document. \"\"\"\n    expression: NotRequired[str]\n    \"\"\" If specified the expression overrides the extracted expression. \"\"\"\n\n\nclass InlineValueOptions(TypedDict):\n    \"\"\"Inline value options used during static registration.\n\n    @since 3.17.0\n    \"\"\"\n\n    workDoneProgress: NotRequired[bool]\n\n\nclass InlayHintLabelPart(TypedDict):\n    \"\"\"An inlay hint label part allows for interactive and composite labels\n    of inlay hints.\n\n    @since 3.17.0\n    \"\"\"\n\n    value: str\n    \"\"\" The value of this label part. \"\"\"\n    tooltip: NotRequired[Union[str, \"MarkupContent\"]]\n    \"\"\" The tooltip text when you hover over this label part. Depending on\n    the client capability `inlayHint.resolveSupport` clients might resolve\n    this property late using the resolve request. \"\"\"\n    location: NotRequired[\"Location\"]\n    \"\"\" An optional source code location that represents this\n    label part.\n\n    The editor will use this location for the hover and for code navigation\n    features: This part will become a clickable link that resolves to the\n    definition of the symbol at the given location (not necessarily the\n    location itself), it shows the hover that shows at the given location,\n    and it shows a context menu with further code navigation commands.\n\n    Depending on the client capability `inlayHint.resolveSupport` clients\n    might resolve this property late using the resolve request. \"\"\"\n    command: NotRequired[\"Command\"]\n    \"\"\" An optional command for this label part.\n\n    Depending on the client capability `inlayHint.resolveSupport` clients\n    might resolve this property late using the resolve request. \"\"\"\n\n\nclass MarkupContent(TypedDict):\n    r\"\"\"A `MarkupContent` literal represents a string value which content is interpreted base on its\n    kind flag. Currently the protocol supports `plaintext` and `markdown` as markup kinds.\n\n    If the kind is `markdown` then the value can contain fenced code blocks like in GitHub issues.\n    See https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting\n\n    Here is an example how such a string can be constructed using JavaScript / TypeScript:\n    ```ts\n    let markdown: MarkdownContent = {\n     kind: MarkupKind.Markdown,\n     value: [\n       '# Header',\n       'Some text',\n       '```typescript',\n       'someCode();',\n       '```'\n     ].join('\\n')\n    };\n    ```\n\n    *Please Note* that clients might sanitize the return markdown. A client could decide to\n    remove HTML from the markdown to avoid script execution.\n    \"\"\"\n\n    kind: \"MarkupKind\"\n    \"\"\" The type of the Markup \"\"\"\n    value: str\n    \"\"\" The content itself \"\"\"\n\n\nclass InlayHintOptions(TypedDict):\n    \"\"\"Inlay hint options used during static registration.\n\n    @since 3.17.0\n    \"\"\"\n\n    resolveProvider: NotRequired[bool]\n    \"\"\" The server provides support to resolve additional\n    information for an inlay hint item. \"\"\"\n    workDoneProgress: NotRequired[bool]\n\n\nclass RelatedFullDocumentDiagnosticReport(TypedDict):\n    \"\"\"A full diagnostic report with a set of related documents.\n\n    @since 3.17.0\n    \"\"\"\n\n    relatedDocuments: NotRequired[\n        dict[\n            \"DocumentUri\",\n            Union[\"FullDocumentDiagnosticReport\", \"UnchangedDocumentDiagnosticReport\"],\n        ]\n    ]\n    \"\"\" Diagnostics of related documents. This information is useful\n    in programming languages where code in a file A can generate\n    diagnostics in a file B which A depends on. An example of\n    such a language is C/C++ where marco definitions in a file\n    a.cpp and result in errors in a header file b.hpp.\n\n    @since 3.17.0 \"\"\"\n    kind: Literal[\"full\"]\n    \"\"\" A full document diagnostic report. \"\"\"\n    resultId: NotRequired[str]\n    \"\"\" An optional result id. If provided it will\n    be sent on the next diagnostic request for the\n    same document. \"\"\"\n    items: list[\"Diagnostic\"]\n    \"\"\" The actual items. \"\"\"\n\n\nclass RelatedUnchangedDocumentDiagnosticReport(TypedDict):\n    \"\"\"An unchanged diagnostic report with a set of related documents.\n\n    @since 3.17.0\n    \"\"\"\n\n    relatedDocuments: NotRequired[\n        dict[\n            \"DocumentUri\",\n            Union[\"FullDocumentDiagnosticReport\", \"UnchangedDocumentDiagnosticReport\"],\n        ]\n    ]\n    \"\"\" Diagnostics of related documents. This information is useful\n    in programming languages where code in a file A can generate\n    diagnostics in a file B which A depends on. An example of\n    such a language is C/C++ where marco definitions in a file\n    a.cpp and result in errors in a header file b.hpp.\n\n    @since 3.17.0 \"\"\"\n    kind: Literal[\"unchanged\"]\n    \"\"\" A document diagnostic report indicating\n    no changes to the last result. A server can\n    only return `unchanged` if result ids are\n    provided. \"\"\"\n    resultId: str\n    \"\"\" A result id which will be sent on the next\n    diagnostic request for the same document. \"\"\"\n\n\nclass FullDocumentDiagnosticReport(TypedDict):\n    \"\"\"A diagnostic report with a full set of problems.\n\n    @since 3.17.0\n    \"\"\"\n\n    kind: Literal[\"full\"]\n    \"\"\" A full document diagnostic report. \"\"\"\n    resultId: NotRequired[str]\n    \"\"\" An optional result id. If provided it will\n    be sent on the next diagnostic request for the\n    same document. \"\"\"\n    items: list[\"Diagnostic\"]\n    \"\"\" The actual items. \"\"\"\n\n\nclass UnchangedDocumentDiagnosticReport(TypedDict):\n    \"\"\"A diagnostic report indicating that the last returned\n    report is still accurate.\n\n    @since 3.17.0\n    \"\"\"\n\n    kind: Literal[\"unchanged\"]\n    \"\"\" A document diagnostic report indicating\n    no changes to the last result. A server can\n    only return `unchanged` if result ids are\n    provided. \"\"\"\n    resultId: str\n    \"\"\" A result id which will be sent on the next\n    diagnostic request for the same document. \"\"\"\n\n\nclass DiagnosticOptions(TypedDict):\n    \"\"\"Diagnostic options.\n\n    @since 3.17.0\n    \"\"\"\n\n    identifier: NotRequired[str]\n    \"\"\" An optional identifier under which the diagnostics are\n    managed by the client. \"\"\"\n    interFileDependencies: bool\n    \"\"\" Whether the language has inter file dependencies meaning that\n    editing code in one file can result in a different diagnostic\n    set in another file. Inter file dependencies are common for\n    most programming languages and typically uncommon for linters. \"\"\"\n    workspaceDiagnostics: bool\n    \"\"\" The server provides support for workspace diagnostics as well. \"\"\"\n    workDoneProgress: NotRequired[bool]\n\n\nclass PreviousResultId(TypedDict):\n    \"\"\"A previous result id in a workspace pull request.\n\n    @since 3.17.0\n    \"\"\"\n\n    uri: \"DocumentUri\"\n    \"\"\" The URI for which the client knowns a\n    result id. \"\"\"\n    value: str\n    \"\"\" The value of the previous result id. \"\"\"\n\n\nclass NotebookDocument(TypedDict):\n    \"\"\"A notebook document.\n\n    @since 3.17.0\n    \"\"\"\n\n    uri: \"URI\"\n    \"\"\" The notebook document's uri. \"\"\"\n    notebookType: str\n    \"\"\" The type of the notebook. \"\"\"\n    version: int\n    \"\"\" The version number of this document (it will increase after each\n    change, including undo/redo). \"\"\"\n    metadata: NotRequired[\"LSPObject\"]\n    \"\"\" Additional metadata stored with the notebook\n    document.\n\n    Note: should always be an object literal (e.g. LSPObject) \"\"\"\n    cells: list[\"NotebookCell\"]\n    \"\"\" The cells of a notebook. \"\"\"\n\n\nclass TextDocumentItem(TypedDict):\n    \"\"\"An item to transfer a text document from the client to the\n    server.\n    \"\"\"\n\n    uri: \"DocumentUri\"\n    \"\"\" The text document's uri. \"\"\"\n    languageId: str\n    \"\"\" The text document's language identifier. \"\"\"\n    version: int\n    \"\"\" The version number of this document (it will increase after each\n    change, including undo/redo). \"\"\"\n    text: str\n    \"\"\" The content of the opened text document. \"\"\"\n\n\nclass VersionedNotebookDocumentIdentifier(TypedDict):\n    \"\"\"A versioned notebook document identifier.\n\n    @since 3.17.0\n    \"\"\"\n\n    version: int\n    \"\"\" The version number of this notebook document. \"\"\"\n    uri: \"URI\"\n    \"\"\" The notebook document's uri. \"\"\"\n\n\nclass NotebookDocumentChangeEvent(TypedDict):\n    \"\"\"A change event for a notebook document.\n\n    @since 3.17.0\n    \"\"\"\n\n    metadata: NotRequired[\"LSPObject\"]\n    \"\"\" The changed meta data if any.\n\n    Note: should always be an object literal (e.g. LSPObject) \"\"\"\n    cells: NotRequired[\"__NotebookDocumentChangeEvent_cells_Type_1\"]\n    \"\"\" Changes to cells \"\"\"\n\n\nclass NotebookDocumentIdentifier(TypedDict):\n    \"\"\"A literal to identify a notebook document in the client.\n\n    @since 3.17.0\n    \"\"\"\n\n    uri: \"URI\"\n    \"\"\" The notebook document's uri. \"\"\"\n\n\nclass Registration(TypedDict):\n    \"\"\"General parameters to to register for an notification or to register a provider.\"\"\"\n\n    id: str\n    \"\"\" The id used to register the request. The id can be used to deregister\n    the request again. \"\"\"\n    method: str\n    \"\"\" The method / capability to register for. \"\"\"\n    registerOptions: NotRequired[\"LSPAny\"]\n    \"\"\" Options necessary for the registration. \"\"\"\n\n\nclass Unregistration(TypedDict):\n    \"\"\"General parameters to unregister a request or notification.\"\"\"\n\n    id: str\n    \"\"\" The id used to unregister the request or notification. Usually an id\n    provided during the register request. \"\"\"\n    method: str\n    \"\"\" The method to unregister for. \"\"\"\n\n\nclass WorkspaceFoldersInitializeParams(TypedDict):\n    workspaceFolders: NotRequired[list[\"WorkspaceFolder\"] | None]\n    \"\"\" The workspace folders configured in the client when the server starts.\n\n    This property is only available if the client supports workspace folders.\n    It can be `null` if the client supports workspace folders but none are\n    configured.\n\n    @since 3.6.0 \"\"\"\n\n\nclass ServerCapabilities(TypedDict):\n    \"\"\"Defines the capabilities provided by a language\n    server.\n    \"\"\"\n\n    positionEncoding: NotRequired[\"PositionEncodingKind\"]\n    \"\"\" The position encoding the server picked from the encodings offered\n    by the client via the client capability `general.positionEncodings`.\n\n    If the client didn't provide any position encodings the only valid\n    value that a server can return is 'utf-16'.\n\n    If omitted it defaults to 'utf-16'.\n\n    @since 3.17.0 \"\"\"\n    textDocumentSync: NotRequired[Union[\"TextDocumentSyncOptions\", \"TextDocumentSyncKind\"]]\n    \"\"\" Defines how text documents are synced. Is either a detailed structure\n    defining each notification or for backwards compatibility the\n    TextDocumentSyncKind number. \"\"\"\n    notebookDocumentSync: NotRequired[Union[\"NotebookDocumentSyncOptions\", \"NotebookDocumentSyncRegistrationOptions\"]]\n    \"\"\" Defines how notebook documents are synced.\n\n    @since 3.17.0 \"\"\"\n    completionProvider: NotRequired[\"CompletionOptions\"]\n    \"\"\" The server provides completion support. \"\"\"\n    hoverProvider: NotRequired[Union[bool, \"HoverOptions\"]]\n    \"\"\" The server provides hover support. \"\"\"\n    signatureHelpProvider: NotRequired[\"SignatureHelpOptions\"]\n    \"\"\" The server provides signature help support. \"\"\"\n    declarationProvider: NotRequired[Union[bool, \"DeclarationOptions\", \"DeclarationRegistrationOptions\"]]\n    \"\"\" The server provides Goto Declaration support. \"\"\"\n    definitionProvider: NotRequired[Union[bool, \"DefinitionOptions\"]]\n    \"\"\" The server provides goto definition support. \"\"\"\n    typeDefinitionProvider: NotRequired[Union[bool, \"TypeDefinitionOptions\", \"TypeDefinitionRegistrationOptions\"]]\n    \"\"\" The server provides Goto Type Definition support. \"\"\"\n    implementationProvider: NotRequired[Union[bool, \"ImplementationOptions\", \"ImplementationRegistrationOptions\"]]\n    \"\"\" The server provides Goto Implementation support. \"\"\"\n    referencesProvider: NotRequired[Union[bool, \"ReferenceOptions\"]]\n    \"\"\" The server provides find references support. \"\"\"\n    documentHighlightProvider: NotRequired[Union[bool, \"DocumentHighlightOptions\"]]\n    \"\"\" The server provides document highlight support. \"\"\"\n    documentSymbolProvider: NotRequired[Union[bool, \"DocumentSymbolOptions\"]]\n    \"\"\" The server provides document symbol support. \"\"\"\n    codeActionProvider: NotRequired[Union[bool, \"CodeActionOptions\"]]\n    \"\"\" The server provides code actions. CodeActionOptions may only be\n    specified if the client states that it supports\n    `codeActionLiteralSupport` in its initial `initialize` request. \"\"\"\n    codeLensProvider: NotRequired[\"CodeLensOptions\"]\n    \"\"\" The server provides code lens. \"\"\"\n    documentLinkProvider: NotRequired[\"DocumentLinkOptions\"]\n    \"\"\" The server provides document link support. \"\"\"\n    colorProvider: NotRequired[Union[bool, \"DocumentColorOptions\", \"DocumentColorRegistrationOptions\"]]\n    \"\"\" The server provides color provider support. \"\"\"\n    workspaceSymbolProvider: NotRequired[Union[bool, \"WorkspaceSymbolOptions\"]]\n    \"\"\" The server provides workspace symbol support. \"\"\"\n    documentFormattingProvider: NotRequired[Union[bool, \"DocumentFormattingOptions\"]]\n    \"\"\" The server provides document formatting. \"\"\"\n    documentRangeFormattingProvider: NotRequired[Union[bool, \"DocumentRangeFormattingOptions\"]]\n    \"\"\" The server provides document range formatting. \"\"\"\n    documentOnTypeFormattingProvider: NotRequired[\"DocumentOnTypeFormattingOptions\"]\n    \"\"\" The server provides document formatting on typing. \"\"\"\n    renameProvider: NotRequired[Union[bool, \"RenameOptions\"]]\n    \"\"\" The server provides rename support. RenameOptions may only be\n    specified if the client states that it supports\n    `prepareSupport` in its initial `initialize` request. \"\"\"\n    foldingRangeProvider: NotRequired[Union[bool, \"FoldingRangeOptions\", \"FoldingRangeRegistrationOptions\"]]\n    \"\"\" The server provides folding provider support. \"\"\"\n    selectionRangeProvider: NotRequired[Union[bool, \"SelectionRangeOptions\", \"SelectionRangeRegistrationOptions\"]]\n    \"\"\" The server provides selection range support. \"\"\"\n    executeCommandProvider: NotRequired[\"ExecuteCommandOptions\"]\n    \"\"\" The server provides execute command support. \"\"\"\n    callHierarchyProvider: NotRequired[Union[bool, \"CallHierarchyOptions\", \"CallHierarchyRegistrationOptions\"]]\n    \"\"\" The server provides call hierarchy support.\n\n    @since 3.16.0 \"\"\"\n    linkedEditingRangeProvider: NotRequired[Union[bool, \"LinkedEditingRangeOptions\", \"LinkedEditingRangeRegistrationOptions\"]]\n    \"\"\" The server provides linked editing range support.\n\n    @since 3.16.0 \"\"\"\n    semanticTokensProvider: NotRequired[Union[\"SemanticTokensOptions\", \"SemanticTokensRegistrationOptions\"]]\n    \"\"\" The server provides semantic tokens support.\n\n    @since 3.16.0 \"\"\"\n    monikerProvider: NotRequired[Union[bool, \"MonikerOptions\", \"MonikerRegistrationOptions\"]]\n    \"\"\" The server provides moniker support.\n\n    @since 3.16.0 \"\"\"\n    typeHierarchyProvider: NotRequired[Union[bool, \"TypeHierarchyOptions\", \"TypeHierarchyRegistrationOptions\"]]\n    \"\"\" The server provides type hierarchy support.\n\n    @since 3.17.0 \"\"\"\n    inlineValueProvider: NotRequired[Union[bool, \"InlineValueOptions\", \"InlineValueRegistrationOptions\"]]\n    \"\"\" The server provides inline values.\n\n    @since 3.17.0 \"\"\"\n    inlayHintProvider: NotRequired[Union[bool, \"InlayHintOptions\", \"InlayHintRegistrationOptions\"]]\n    \"\"\" The server provides inlay hints.\n\n    @since 3.17.0 \"\"\"\n    diagnosticProvider: NotRequired[Union[\"DiagnosticOptions\", \"DiagnosticRegistrationOptions\"]]\n    \"\"\" The server has support for pull model diagnostics.\n\n    @since 3.17.0 \"\"\"\n    workspace: NotRequired[\"__ServerCapabilities_workspace_Type_1\"]\n    \"\"\" Workspace specific server capabilities. \"\"\"\n    experimental: NotRequired[\"LSPAny\"]\n    \"\"\" Experimental server capabilities. \"\"\"\n\n\nclass VersionedTextDocumentIdentifier(TypedDict):\n    \"\"\"A text document identifier to denote a specific version of a text document.\"\"\"\n\n    version: int\n    \"\"\" The version number of this document. \"\"\"\n    uri: \"DocumentUri\"\n    \"\"\" The text document's uri. \"\"\"\n\n\nclass SaveOptions(TypedDict):\n    \"\"\"Save options.\"\"\"\n\n    includeText: NotRequired[bool]\n    \"\"\" The client is supposed to include the content on save. \"\"\"\n\n\nclass FileEvent(TypedDict):\n    \"\"\"An event describing a file change.\"\"\"\n\n    uri: \"DocumentUri\"\n    \"\"\" The file's uri. \"\"\"\n    type: \"FileChangeType\"\n    \"\"\" The change type. \"\"\"\n\n\nclass FileSystemWatcher(TypedDict):\n    globPattern: \"GlobPattern\"\n    \"\"\" The glob pattern to watch. See {@link GlobPattern glob pattern} for more detail.\n\n    @since 3.17.0 support for relative patterns. \"\"\"\n    kind: NotRequired[\"WatchKind\"]\n    \"\"\" The kind of events of interest. If omitted it defaults\n    to WatchKind.Create | WatchKind.Change | WatchKind.Delete\n    which is 7. \"\"\"\n\n\nclass Diagnostic(TypedDict):\n    \"\"\"Represents a diagnostic, such as a compiler error or warning. Diagnostic objects\n    are only valid in the scope of a resource.\n    \"\"\"\n\n    range: \"Range\"\n    \"\"\" The range at which the message applies \"\"\"\n    severity: NotRequired[\"DiagnosticSeverity\"]\n    \"\"\" The diagnostic's severity. Can be omitted. If omitted it is up to the\n    client to interpret diagnostics as error, warning, info or hint. \"\"\"\n    code: NotRequired[int | str]\n    \"\"\" The diagnostic's code, which usually appear in the user interface. \"\"\"\n    codeDescription: NotRequired[\"CodeDescription\"]\n    \"\"\" An optional property to describe the error code.\n    Requires the code field (above) to be present/not null.\n\n    @since 3.16.0 \"\"\"\n    source: NotRequired[str]\n    \"\"\" A human-readable string describing the source of this\n    diagnostic, e.g. 'typescript' or 'super lint'. It usually\n    appears in the user interface. \"\"\"\n    message: str\n    \"\"\" The diagnostic's message. It usually appears in the user interface \"\"\"\n    tags: NotRequired[list[\"DiagnosticTag\"]]\n    \"\"\" Additional metadata about the diagnostic.\n\n    @since 3.15.0 \"\"\"\n    relatedInformation: NotRequired[list[\"DiagnosticRelatedInformation\"]]\n    \"\"\" An array of related diagnostic information, e.g. when symbol-names within\n    a scope collide all definitions can be marked via this property. \"\"\"\n    data: NotRequired[\"LSPAny\"]\n    \"\"\" A data entry field that is preserved between a `textDocument/publishDiagnostics`\n    notification and `textDocument/codeAction` request.\n\n    @since 3.16.0 \"\"\"\n\n\nclass CompletionContext(TypedDict):\n    \"\"\"Contains additional information about the context in which a completion request is triggered.\"\"\"\n\n    triggerKind: \"CompletionTriggerKind\"\n    \"\"\" How the completion was triggered. \"\"\"\n    triggerCharacter: NotRequired[str]\n    \"\"\" The trigger character (a single character) that has trigger code complete.\n    Is undefined if `triggerKind !== CompletionTriggerKind.TriggerCharacter` \"\"\"\n\n\nclass CompletionItemLabelDetails(TypedDict):\n    \"\"\"Additional details for a completion item label.\n\n    @since 3.17.0\n    \"\"\"\n\n    detail: NotRequired[str]\n    \"\"\" An optional string which is rendered less prominently directly after {@link CompletionItem.label label},\n    without any spacing. Should be used for function signatures and type annotations. \"\"\"\n    description: NotRequired[str]\n    \"\"\" An optional string which is rendered less prominently after {@link CompletionItem.detail}. Should be used\n    for fully qualified names and file paths. \"\"\"\n\n\nclass InsertReplaceEdit(TypedDict):\n    \"\"\"A special text edit to provide an insert and a replace operation.\n\n    @since 3.16.0\n    \"\"\"\n\n    newText: str\n    \"\"\" The string to be inserted. \"\"\"\n    insert: \"Range\"\n    \"\"\" The range if the insert is requested \"\"\"\n    replace: \"Range\"\n    \"\"\" The range if the replace is requested. \"\"\"\n\n\nclass CompletionOptions(TypedDict):\n    \"\"\"Completion options.\"\"\"\n\n    triggerCharacters: NotRequired[list[str]]\n    \"\"\" Most tools trigger completion request automatically without explicitly requesting\n    it using a keyboard shortcut (e.g. Ctrl+Space). Typically they do so when the user\n    starts to type an identifier. For example if the user types `c` in a JavaScript file\n    code complete will automatically pop up present `console` besides others as a\n    completion item. Characters that make up identifiers don't need to be listed here.\n\n    If code complete should automatically be trigger on characters not being valid inside\n    an identifier (for example `.` in JavaScript) list them in `triggerCharacters`. \"\"\"\n    allCommitCharacters: NotRequired[list[str]]\n    \"\"\" The list of all possible characters that commit a completion. This field can be used\n    if clients don't support individual commit characters per completion item. See\n    `ClientCapabilities.textDocument.completion.completionItem.commitCharactersSupport`\n\n    If a server provides both `allCommitCharacters` and commit characters on an individual\n    completion item the ones on the completion item win.\n\n    @since 3.2.0 \"\"\"\n    resolveProvider: NotRequired[bool]\n    \"\"\" The server provides support to resolve additional\n    information for a completion item. \"\"\"\n    completionItem: NotRequired[\"__CompletionOptions_completionItem_Type_2\"]\n    \"\"\" The server supports the following `CompletionItem` specific\n    capabilities.\n\n    @since 3.17.0 \"\"\"\n    workDoneProgress: NotRequired[bool]\n\n\nclass HoverOptions(TypedDict):\n    \"\"\"Hover options.\"\"\"\n\n    workDoneProgress: NotRequired[bool]\n\n\nclass SignatureHelpContext(TypedDict):\n    \"\"\"Additional information about the context in which a signature help request was triggered.\n\n    @since 3.15.0\n    \"\"\"\n\n    triggerKind: \"SignatureHelpTriggerKind\"\n    \"\"\" Action that caused signature help to be triggered. \"\"\"\n    triggerCharacter: NotRequired[str]\n    \"\"\" Character that caused signature help to be triggered.\n\n    This is undefined when `triggerKind !== SignatureHelpTriggerKind.TriggerCharacter` \"\"\"\n    isRetrigger: bool\n    \"\"\" `true` if signature help was already showing when it was triggered.\n\n    Retriggers occurs when the signature help is already active and can be caused by actions such as\n    typing a trigger character, a cursor move, or document content changes. \"\"\"\n    activeSignatureHelp: NotRequired[\"SignatureHelp\"]\n    \"\"\" The currently active `SignatureHelp`.\n\n    The `activeSignatureHelp` has its `SignatureHelp.activeSignature` field updated based on\n    the user navigating through available signatures. \"\"\"\n\n\nclass SignatureInformation(TypedDict):\n    \"\"\"Represents the signature of something callable. A signature\n    can have a label, like a function-name, a doc-comment, and\n    a set of parameters.\n    \"\"\"\n\n    label: str\n    \"\"\" The label of this signature. Will be shown in\n    the UI. \"\"\"\n    documentation: NotRequired[Union[str, \"MarkupContent\"]]\n    \"\"\" The human-readable doc-comment of this signature. Will be shown\n    in the UI but can be omitted. \"\"\"\n    parameters: NotRequired[list[\"ParameterInformation\"]]\n    \"\"\" The parameters of this signature. \"\"\"\n    activeParameter: NotRequired[Uint]\n    \"\"\" The index of the active parameter.\n\n    If provided, this is used in place of `SignatureHelp.activeParameter`.\n\n    @since 3.16.0 \"\"\"\n\n\nclass SignatureHelpOptions(TypedDict):\n    \"\"\"Server Capabilities for a {@link SignatureHelpRequest}.\"\"\"\n\n    triggerCharacters: NotRequired[list[str]]\n    \"\"\" List of characters that trigger signature help automatically. \"\"\"\n    retriggerCharacters: NotRequired[list[str]]\n    \"\"\" List of characters that re-trigger signature help.\n\n    These trigger characters are only active when signature help is already showing. All trigger characters\n    are also counted as re-trigger characters.\n\n    @since 3.15.0 \"\"\"\n    workDoneProgress: NotRequired[bool]\n\n\nclass DefinitionOptions(TypedDict):\n    \"\"\"Server Capabilities for a {@link DefinitionRequest}.\"\"\"\n\n    workDoneProgress: NotRequired[bool]\n\n\nclass ReferenceContext(TypedDict):\n    \"\"\"Value-object that contains additional information when\n    requesting references.\n    \"\"\"\n\n    includeDeclaration: bool\n    \"\"\" Include the declaration of the current symbol. \"\"\"\n\n\nclass ReferenceOptions(TypedDict):\n    \"\"\"Reference options.\"\"\"\n\n    workDoneProgress: NotRequired[bool]\n\n\nclass DocumentHighlightOptions(TypedDict):\n    \"\"\"Provider options for a {@link DocumentHighlightRequest}.\"\"\"\n\n    workDoneProgress: NotRequired[bool]\n\n\nclass BaseSymbolInformation(TypedDict):\n    \"\"\"A base for all symbol information.\"\"\"\n\n    name: str\n    \"\"\" The name of this symbol. \"\"\"\n    kind: \"SymbolKind\"\n    \"\"\" The kind of this symbol. \"\"\"\n    tags: NotRequired[list[\"SymbolTag\"]]\n    \"\"\" Tags for this symbol.\n\n    @since 3.16.0 \"\"\"\n    containerName: NotRequired[str]\n    \"\"\" The name of the symbol containing this symbol. This information is for\n    user interface purposes (e.g. to render a qualifier in the user interface\n    if necessary). It can't be used to re-infer a hierarchy for the document\n    symbols. \"\"\"\n\n\nclass DocumentSymbolOptions(TypedDict):\n    \"\"\"Provider options for a {@link DocumentSymbolRequest}.\"\"\"\n\n    label: NotRequired[str]\n    \"\"\" A human-readable string that is shown when multiple outlines trees\n    are shown for the same document.\n\n    @since 3.16.0 \"\"\"\n    workDoneProgress: NotRequired[bool]\n\n\nclass CodeActionContext(TypedDict):\n    \"\"\"Contains additional diagnostic information about the context in which\n    a {@link CodeActionProvider.provideCodeActions code action} is run.\n    \"\"\"\n\n    diagnostics: list[\"Diagnostic\"]\n    \"\"\" An array of diagnostics known on the client side overlapping the range provided to the\n    `textDocument/codeAction` request. They are provided so that the server knows which\n    errors are currently presented to the user for the given range. There is no guarantee\n    that these accurately reflect the error state of the resource. The primary parameter\n    to compute code actions is the provided range. \"\"\"\n    only: NotRequired[list[\"CodeActionKind\"]]\n    \"\"\" Requested kind of actions to return.\n\n    Actions not of this kind are filtered out by the client before being shown. So servers\n    can omit computing them. \"\"\"\n    triggerKind: NotRequired[\"CodeActionTriggerKind\"]\n    \"\"\" The reason why code actions were requested.\n\n    @since 3.17.0 \"\"\"\n\n\nclass CodeActionOptions(TypedDict):\n    \"\"\"Provider options for a {@link CodeActionRequest}.\"\"\"\n\n    codeActionKinds: NotRequired[list[\"CodeActionKind\"]]\n    \"\"\" CodeActionKinds that this server may return.\n\n    The list of kinds may be generic, such as `CodeActionKind.Refactor`, or the server\n    may list out every specific kind they provide. \"\"\"\n    resolveProvider: NotRequired[bool]\n    \"\"\" The server provides support to resolve additional\n    information for a code action.\n\n    @since 3.16.0 \"\"\"\n    workDoneProgress: NotRequired[bool]\n\n\nclass WorkspaceSymbolOptions(TypedDict):\n    \"\"\"Server capabilities for a {@link WorkspaceSymbolRequest}.\"\"\"\n\n    resolveProvider: NotRequired[bool]\n    \"\"\" The server provides support to resolve additional\n    information for a workspace symbol.\n\n    @since 3.17.0 \"\"\"\n    workDoneProgress: NotRequired[bool]\n\n\nclass CodeLensOptions(TypedDict):\n    \"\"\"Code Lens provider options of a {@link CodeLensRequest}.\"\"\"\n\n    resolveProvider: NotRequired[bool]\n    \"\"\" Code lens has a resolve provider as well. \"\"\"\n    workDoneProgress: NotRequired[bool]\n\n\nclass DocumentLinkOptions(TypedDict):\n    \"\"\"Provider options for a {@link DocumentLinkRequest}.\"\"\"\n\n    resolveProvider: NotRequired[bool]\n    \"\"\" Document links have a resolve provider as well. \"\"\"\n    workDoneProgress: NotRequired[bool]\n\n\nclass FormattingOptions(TypedDict):\n    \"\"\"Value-object describing what options formatting should use.\"\"\"\n\n    tabSize: Uint\n    \"\"\" Size of a tab in spaces. \"\"\"\n    insertSpaces: bool\n    \"\"\" Prefer spaces over tabs. \"\"\"\n    trimTrailingWhitespace: NotRequired[bool]\n    \"\"\" Trim trailing whitespace on a line.\n\n    @since 3.15.0 \"\"\"\n    insertFinalNewline: NotRequired[bool]\n    \"\"\" Insert a newline character at the end of the file if one does not exist.\n\n    @since 3.15.0 \"\"\"\n    trimFinalNewlines: NotRequired[bool]\n    \"\"\" Trim all newlines after the final newline at the end of the file.\n\n    @since 3.15.0 \"\"\"\n\n\nclass DocumentFormattingOptions(TypedDict):\n    \"\"\"Provider options for a {@link DocumentFormattingRequest}.\"\"\"\n\n    workDoneProgress: NotRequired[bool]\n\n\nclass DocumentRangeFormattingOptions(TypedDict):\n    \"\"\"Provider options for a {@link DocumentRangeFormattingRequest}.\"\"\"\n\n    workDoneProgress: NotRequired[bool]\n\n\nclass DocumentOnTypeFormattingOptions(TypedDict):\n    \"\"\"Provider options for a {@link DocumentOnTypeFormattingRequest}.\"\"\"\n\n    firstTriggerCharacter: str\n    \"\"\" A character on which formatting should be triggered, like `{`. \"\"\"\n    moreTriggerCharacter: NotRequired[list[str]]\n    \"\"\" More trigger characters. \"\"\"\n\n\nclass RenameOptions(TypedDict):\n    \"\"\"Provider options for a {@link RenameRequest}.\"\"\"\n\n    prepareProvider: NotRequired[bool]\n    \"\"\" Renames should be checked and tested before being executed.\n\n    @since version 3.12.0 \"\"\"\n    workDoneProgress: NotRequired[bool]\n\n\nclass ExecuteCommandOptions(TypedDict):\n    \"\"\"The server capabilities of a {@link ExecuteCommandRequest}.\"\"\"\n\n    commands: list[str]\n    \"\"\" The commands to be executed on the server \"\"\"\n    workDoneProgress: NotRequired[bool]\n\n\nclass SemanticTokensLegend(TypedDict):\n    \"\"\"@since 3.16.0\"\"\"\n\n    tokenTypes: list[str]\n    \"\"\" The token types a server uses. \"\"\"\n    tokenModifiers: list[str]\n    \"\"\" The token modifiers a server uses. \"\"\"\n\n\nclass OptionalVersionedTextDocumentIdentifier(TypedDict):\n    \"\"\"A text document identifier to optionally denote a specific version of a text document.\"\"\"\n\n    version: int | None\n    \"\"\" The version number of this document. If a versioned text document identifier\n    is sent from the server to the client and the file is not open in the editor\n    (the server has not received an open notification before) the server can send\n    `null` to indicate that the version is unknown and the content on disk is the\n    truth (as specified with document content ownership). \"\"\"\n    uri: \"DocumentUri\"\n    \"\"\" The text document's uri. \"\"\"\n\n\nclass AnnotatedTextEdit(TypedDict):\n    \"\"\"A special text edit with an additional change annotation.\n\n    @since 3.16.0.\n    \"\"\"\n\n    annotationId: \"ChangeAnnotationIdentifier\"\n    \"\"\" The actual identifier of the change annotation \"\"\"\n    range: \"Range\"\n    \"\"\" The range of the text document to be manipulated. To insert\n    text into a document create a range where start === end. \"\"\"\n    newText: str\n    \"\"\" The string to be inserted. For delete operations use an\n    empty string. \"\"\"\n\n\nclass ResourceOperation(TypedDict):\n    \"\"\"A generic resource operation.\"\"\"\n\n    kind: str\n    \"\"\" The resource operation kind. \"\"\"\n    annotationId: NotRequired[\"ChangeAnnotationIdentifier\"]\n    \"\"\" An optional annotation identifier describing the operation.\n\n    @since 3.16.0 \"\"\"\n\n\nclass CreateFileOptions(TypedDict):\n    \"\"\"Options to create a file.\"\"\"\n\n    overwrite: NotRequired[bool]\n    \"\"\" Overwrite existing file. Overwrite wins over `ignoreIfExists` \"\"\"\n    ignoreIfExists: NotRequired[bool]\n    \"\"\" Ignore if exists. \"\"\"\n\n\nclass RenameFileOptions(TypedDict):\n    \"\"\"Rename file options\"\"\"\n\n    overwrite: NotRequired[bool]\n    \"\"\" Overwrite target if existing. Overwrite wins over `ignoreIfExists` \"\"\"\n    ignoreIfExists: NotRequired[bool]\n    \"\"\" Ignores if target exists. \"\"\"\n\n\nclass DeleteFileOptions(TypedDict):\n    \"\"\"Delete file options\"\"\"\n\n    recursive: NotRequired[bool]\n    \"\"\" Delete the content recursively if a folder is denoted. \"\"\"\n    ignoreIfNotExists: NotRequired[bool]\n    \"\"\" Ignore the operation if the file doesn't exist. \"\"\"\n\n\nclass FileOperationPattern(TypedDict):\n    \"\"\"A pattern to describe in which file operation requests or notifications\n    the server is interested in receiving.\n\n    @since 3.16.0\n    \"\"\"\n\n    glob: str\n    \"\"\" The glob pattern to match. Glob patterns can have the following syntax:\n    - `*` to match one or more characters in a path segment\n    - `?` to match on one character in a path segment\n    - `**` to match any number of path segments, including none\n    - `{}` to group sub patterns into an OR expression. (e.g. `**\\u200b/*.{ts,js}` matches all TypeScript and JavaScript files)\n    - `[]` to declare a range of characters to match in a path segment (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …)\n    - `[!...]` to negate a range of characters to match in a path segment (e.g., `example.[!0-9]` to match on `example.a`, `example.b`, but not `example.0`) \"\"\"\n    matches: NotRequired[\"FileOperationPatternKind\"]\n    \"\"\" Whether to match files or folders with this pattern.\n\n    Matches both if undefined. \"\"\"\n    options: NotRequired[\"FileOperationPatternOptions\"]\n    \"\"\" Additional options used during matching. \"\"\"\n\n\nclass WorkspaceFullDocumentDiagnosticReport(TypedDict):\n    \"\"\"A full document diagnostic report for a workspace diagnostic result.\n\n    @since 3.17.0\n    \"\"\"\n\n    uri: \"DocumentUri\"\n    \"\"\" The URI for which diagnostic information is reported. \"\"\"\n    version: int | None\n    \"\"\" The version number for which the diagnostics are reported.\n    If the document is not marked as open `null` can be provided. \"\"\"\n    kind: Literal[\"full\"]\n    \"\"\" A full document diagnostic report. \"\"\"\n    resultId: NotRequired[str]\n    \"\"\" An optional result id. If provided it will\n    be sent on the next diagnostic request for the\n    same document. \"\"\"\n    items: list[\"Diagnostic\"]\n    \"\"\" The actual items. \"\"\"\n\n\nclass WorkspaceUnchangedDocumentDiagnosticReport(TypedDict):\n    \"\"\"An unchanged document diagnostic report for a workspace diagnostic result.\n\n    @since 3.17.0\n    \"\"\"\n\n    uri: \"DocumentUri\"\n    \"\"\" The URI for which diagnostic information is reported. \"\"\"\n    version: int | None\n    \"\"\" The version number for which the diagnostics are reported.\n    If the document is not marked as open `null` can be provided. \"\"\"\n    kind: Literal[\"unchanged\"]\n    \"\"\" A document diagnostic report indicating\n    no changes to the last result. A server can\n    only return `unchanged` if result ids are\n    provided. \"\"\"\n    resultId: str\n    \"\"\" A result id which will be sent on the next\n    diagnostic request for the same document. \"\"\"\n\n\nclass NotebookCell(TypedDict):\n    \"\"\"A notebook cell.\n\n    A cell's document URI must be unique across ALL notebook\n    cells and can therefore be used to uniquely identify a\n    notebook cell or the cell's text document.\n\n    @since 3.17.0\n    \"\"\"\n\n    kind: \"NotebookCellKind\"\n    \"\"\" The cell's kind \"\"\"\n    document: \"DocumentUri\"\n    \"\"\" The URI of the cell's text document\n    content. \"\"\"\n    metadata: NotRequired[\"LSPObject\"]\n    \"\"\" Additional metadata stored with the cell.\n\n    Note: should always be an object literal (e.g. LSPObject) \"\"\"\n    executionSummary: NotRequired[\"ExecutionSummary\"]\n    \"\"\" Additional execution summary information\n    if supported by the client. \"\"\"\n\n\nclass NotebookCellArrayChange(TypedDict):\n    \"\"\"A change describing how to move a `NotebookCell`\n    array from state S to S'.\n\n    @since 3.17.0\n    \"\"\"\n\n    start: Uint\n    \"\"\" The start oftest of the cell that changed. \"\"\"\n    deleteCount: Uint\n    \"\"\" The deleted cells \"\"\"\n    cells: NotRequired[list[\"NotebookCell\"]]\n    \"\"\" The new cells, if any \"\"\"\n\n\nclass ClientCapabilities(TypedDict):\n    \"\"\"Defines the capabilities provided by the client.\"\"\"\n\n    workspace: NotRequired[\"WorkspaceClientCapabilities\"]\n    \"\"\" Workspace specific client capabilities. \"\"\"\n    textDocument: NotRequired[\"TextDocumentClientCapabilities\"]\n    \"\"\" Text document specific client capabilities. \"\"\"\n    notebookDocument: NotRequired[\"NotebookDocumentClientCapabilities\"]\n    \"\"\" Capabilities specific to the notebook document support.\n\n    @since 3.17.0 \"\"\"\n    window: NotRequired[\"WindowClientCapabilities\"]\n    \"\"\" Window specific client capabilities. \"\"\"\n    general: NotRequired[\"GeneralClientCapabilities\"]\n    \"\"\" General client capabilities.\n\n    @since 3.16.0 \"\"\"\n    experimental: NotRequired[\"LSPAny\"]\n    \"\"\" Experimental client capabilities. \"\"\"\n\n\nclass TextDocumentSyncOptions(TypedDict):\n    openClose: NotRequired[bool]\n    \"\"\" Open and close notifications are sent to the server. If omitted open close notification should not\n    be sent. \"\"\"\n    change: NotRequired[\"TextDocumentSyncKind\"]\n    \"\"\" Change notifications are sent to the server. See TextDocumentSyncKind.None, TextDocumentSyncKind.Full\n    and TextDocumentSyncKind.Incremental. If omitted it defaults to TextDocumentSyncKind.None. \"\"\"\n    willSave: NotRequired[bool]\n    \"\"\" If present will save notifications are sent to the server. If omitted the notification should not be\n    sent. \"\"\"\n    willSaveWaitUntil: NotRequired[bool]\n    \"\"\" If present will save wait until requests are sent to the server. If omitted the request should not be\n    sent. \"\"\"\n    save: NotRequired[Union[bool, \"SaveOptions\"]]\n    \"\"\" If present save notifications are sent to the server. If omitted the notification should not be\n    sent. \"\"\"\n\n\nclass NotebookDocumentSyncOptions(TypedDict):\n    \"\"\"Options specific to a notebook plus its cells\n    to be synced to the server.\n\n    If a selector provides a notebook document\n    filter but no cell selector all cells of a\n    matching notebook document will be synced.\n\n    If a selector provides no notebook document\n    filter but only a cell selector all notebook\n    document that contain at least one matching\n    cell will be synced.\n\n    @since 3.17.0\n    \"\"\"\n\n    notebookSelector: list[\n        Union[\n            \"__NotebookDocumentSyncOptions_notebookSelector_Type_1\",\n            \"__NotebookDocumentSyncOptions_notebookSelector_Type_2\",\n        ]\n    ]\n    \"\"\" The notebooks to be synced \"\"\"\n    save: NotRequired[bool]\n    \"\"\" Whether save notification should be forwarded to\n    the server. Will only be honored if mode === `notebook`. \"\"\"\n\n\nclass NotebookDocumentSyncRegistrationOptions(TypedDict):\n    \"\"\"Registration options specific to a notebook.\n\n    @since 3.17.0\n    \"\"\"\n\n    notebookSelector: list[\n        Union[\n            \"__NotebookDocumentSyncOptions_notebookSelector_Type_3\",\n            \"__NotebookDocumentSyncOptions_notebookSelector_Type_4\",\n        ]\n    ]\n    \"\"\" The notebooks to be synced \"\"\"\n    save: NotRequired[bool]\n    \"\"\" Whether save notification should be forwarded to\n    the server. Will only be honored if mode === `notebook`. \"\"\"\n    id: NotRequired[str]\n    \"\"\" The id used to register the request. The id can be used to deregister\n    the request again. See also Registration#id. \"\"\"\n\n\nclass WorkspaceFoldersServerCapabilities(TypedDict):\n    supported: NotRequired[bool]\n    \"\"\" The server has support for workspace folders \"\"\"\n    changeNotifications: NotRequired[str | bool]\n    \"\"\" Whether the server wants to receive workspace folder\n    change notifications.\n\n    If a string is provided the string is treated as an ID\n    under which the notification is registered on the client\n    side. The ID can be used to unregister for these events\n    using the `client/unregisterCapability` request. \"\"\"\n\n\nclass FileOperationOptions(TypedDict):\n    \"\"\"Options for notifications/requests for user operations on files.\n\n    @since 3.16.0\n    \"\"\"\n\n    didCreate: NotRequired[\"FileOperationRegistrationOptions\"]\n    \"\"\" The server is interested in receiving didCreateFiles notifications. \"\"\"\n    willCreate: NotRequired[\"FileOperationRegistrationOptions\"]\n    \"\"\" The server is interested in receiving willCreateFiles requests. \"\"\"\n    didRename: NotRequired[\"FileOperationRegistrationOptions\"]\n    \"\"\" The server is interested in receiving didRenameFiles notifications. \"\"\"\n    willRename: NotRequired[\"FileOperationRegistrationOptions\"]\n    \"\"\" The server is interested in receiving willRenameFiles requests. \"\"\"\n    didDelete: NotRequired[\"FileOperationRegistrationOptions\"]\n    \"\"\" The server is interested in receiving didDeleteFiles file notifications. \"\"\"\n    willDelete: NotRequired[\"FileOperationRegistrationOptions\"]\n    \"\"\" The server is interested in receiving willDeleteFiles file requests. \"\"\"\n\n\nclass CodeDescription(TypedDict):\n    \"\"\"Structure to capture a description for an error code.\n\n    @since 3.16.0\n    \"\"\"\n\n    href: \"URI\"\n    \"\"\" An URI to open with more information about the diagnostic error. \"\"\"\n\n\nclass DiagnosticRelatedInformation(TypedDict):\n    \"\"\"Represents a related message and source code location for a diagnostic. This should be\n    used to point to code locations that cause or related to a diagnostics, e.g when duplicating\n    a symbol in a scope.\n    \"\"\"\n\n    location: \"Location\"\n    \"\"\" The location of this related diagnostic information. \"\"\"\n    message: str\n    \"\"\" The message of this related diagnostic information. \"\"\"\n\n\nclass ParameterInformation(TypedDict):\n    \"\"\"Represents a parameter of a callable-signature. A parameter can\n    have a label and a doc-comment.\n    \"\"\"\n\n    label: str | list[Uint | Uint]\n    \"\"\" The label of this parameter information.\n\n    Either a string or an inclusive start and exclusive end offsets within its containing\n    signature label. (see SignatureInformation.label). The offsets are based on a UTF-16\n    string representation as `Position` and `Range` does.\n\n    *Note*: a label of type string should be a substring of its containing signature label.\n    Its intended use case is to highlight the parameter label part in the `SignatureInformation.label`. \"\"\"\n    documentation: NotRequired[Union[str, \"MarkupContent\"]]\n    \"\"\" The human-readable doc-comment of this parameter. Will be shown\n    in the UI but can be omitted. \"\"\"\n\n\nclass NotebookCellTextDocumentFilter(TypedDict):\n    \"\"\"A notebook cell text document filter denotes a cell text\n    document by different properties.\n\n    @since 3.17.0\n    \"\"\"\n\n    notebook: Union[str, \"NotebookDocumentFilter\"]\n    \"\"\" A filter that matches against the notebook\n    containing the notebook cell. If a string\n    value is provided it matches against the\n    notebook type. '*' matches every notebook. \"\"\"\n    language: NotRequired[str]\n    \"\"\" A language id like `python`.\n\n    Will be matched against the language id of the\n    notebook cell document. '*' matches every language. \"\"\"\n\n\nclass FileOperationPatternOptions(TypedDict):\n    \"\"\"Matching options for the file operation pattern.\n\n    @since 3.16.0\n    \"\"\"\n\n    ignoreCase: NotRequired[bool]\n    \"\"\" The pattern should be matched ignoring casing. \"\"\"\n\n\nclass ExecutionSummary(TypedDict):\n    executionOrder: Uint\n    \"\"\" A strict monotonically increasing value\n    indicating the execution order of a cell\n    inside a notebook. \"\"\"\n    success: NotRequired[bool]\n    \"\"\" Whether the execution was successful or\n    not if known by the client. \"\"\"\n\n\nclass WorkspaceClientCapabilities(TypedDict):\n    \"\"\"Workspace specific client capabilities.\"\"\"\n\n    applyEdit: NotRequired[bool]\n    \"\"\" The client supports applying batch edits\n    to the workspace by supporting the request\n    'workspace/applyEdit' \"\"\"\n    workspaceEdit: NotRequired[\"WorkspaceEditClientCapabilities\"]\n    \"\"\" Capabilities specific to `WorkspaceEdit`s. \"\"\"\n    didChangeConfiguration: NotRequired[\"DidChangeConfigurationClientCapabilities\"]\n    \"\"\" Capabilities specific to the `workspace/didChangeConfiguration` notification. \"\"\"\n    didChangeWatchedFiles: NotRequired[\"DidChangeWatchedFilesClientCapabilities\"]\n    \"\"\" Capabilities specific to the `workspace/didChangeWatchedFiles` notification. \"\"\"\n    symbol: NotRequired[\"WorkspaceSymbolClientCapabilities\"]\n    \"\"\" Capabilities specific to the `workspace/symbol` request. \"\"\"\n    executeCommand: NotRequired[\"ExecuteCommandClientCapabilities\"]\n    \"\"\" Capabilities specific to the `workspace/executeCommand` request. \"\"\"\n    workspaceFolders: NotRequired[bool]\n    \"\"\" The client has support for workspace folders.\n\n    @since 3.6.0 \"\"\"\n    configuration: NotRequired[bool]\n    \"\"\" The client supports `workspace/configuration` requests.\n\n    @since 3.6.0 \"\"\"\n    semanticTokens: NotRequired[\"SemanticTokensWorkspaceClientCapabilities\"]\n    \"\"\" Capabilities specific to the semantic token requests scoped to the\n    workspace.\n\n    @since 3.16.0. \"\"\"\n    codeLens: NotRequired[\"CodeLensWorkspaceClientCapabilities\"]\n    \"\"\" Capabilities specific to the code lens requests scoped to the\n    workspace.\n\n    @since 3.16.0. \"\"\"\n    fileOperations: NotRequired[\"FileOperationClientCapabilities\"]\n    \"\"\" The client has support for file notifications/requests for user operations on files.\n\n    Since 3.16.0 \"\"\"\n    inlineValue: NotRequired[\"InlineValueWorkspaceClientCapabilities\"]\n    \"\"\" Capabilities specific to the inline values requests scoped to the\n    workspace.\n\n    @since 3.17.0. \"\"\"\n    inlayHint: NotRequired[\"InlayHintWorkspaceClientCapabilities\"]\n    \"\"\" Capabilities specific to the inlay hint requests scoped to the\n    workspace.\n\n    @since 3.17.0. \"\"\"\n    diagnostics: NotRequired[\"DiagnosticWorkspaceClientCapabilities\"]\n    \"\"\" Capabilities specific to the diagnostic requests scoped to the\n    workspace.\n\n    @since 3.17.0. \"\"\"\n\n\nclass TextDocumentClientCapabilities(TypedDict):\n    \"\"\"Text document specific client capabilities.\"\"\"\n\n    synchronization: NotRequired[\"TextDocumentSyncClientCapabilities\"]\n    \"\"\" Defines which synchronization capabilities the client supports. \"\"\"\n    completion: NotRequired[\"CompletionClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/completion` request. \"\"\"\n    hover: NotRequired[\"HoverClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/hover` request. \"\"\"\n    signatureHelp: NotRequired[\"SignatureHelpClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/signatureHelp` request. \"\"\"\n    declaration: NotRequired[\"DeclarationClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/declaration` request.\n\n    @since 3.14.0 \"\"\"\n    definition: NotRequired[\"DefinitionClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/definition` request. \"\"\"\n    typeDefinition: NotRequired[\"TypeDefinitionClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/typeDefinition` request.\n\n    @since 3.6.0 \"\"\"\n    implementation: NotRequired[\"ImplementationClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/implementation` request.\n\n    @since 3.6.0 \"\"\"\n    references: NotRequired[\"ReferenceClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/references` request. \"\"\"\n    documentHighlight: NotRequired[\"DocumentHighlightClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/documentHighlight` request. \"\"\"\n    documentSymbol: NotRequired[\"DocumentSymbolClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/documentSymbol` request. \"\"\"\n    codeAction: NotRequired[\"CodeActionClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/codeAction` request. \"\"\"\n    codeLens: NotRequired[\"CodeLensClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/codeLens` request. \"\"\"\n    documentLink: NotRequired[\"DocumentLinkClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/documentLink` request. \"\"\"\n    colorProvider: NotRequired[\"DocumentColorClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/documentColor` and the\n    `textDocument/colorPresentation` request.\n\n    @since 3.6.0 \"\"\"\n    formatting: NotRequired[\"DocumentFormattingClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/formatting` request. \"\"\"\n    rangeFormatting: NotRequired[\"DocumentRangeFormattingClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/rangeFormatting` request. \"\"\"\n    onTypeFormatting: NotRequired[\"DocumentOnTypeFormattingClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/onTypeFormatting` request. \"\"\"\n    rename: NotRequired[\"RenameClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/rename` request. \"\"\"\n    foldingRange: NotRequired[\"FoldingRangeClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/foldingRange` request.\n\n    @since 3.10.0 \"\"\"\n    selectionRange: NotRequired[\"SelectionRangeClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/selectionRange` request.\n\n    @since 3.15.0 \"\"\"\n    publishDiagnostics: NotRequired[\"PublishDiagnosticsClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/publishDiagnostics` notification. \"\"\"\n    callHierarchy: NotRequired[\"CallHierarchyClientCapabilities\"]\n    \"\"\" Capabilities specific to the various call hierarchy requests.\n\n    @since 3.16.0 \"\"\"\n    semanticTokens: NotRequired[\"SemanticTokensClientCapabilities\"]\n    \"\"\" Capabilities specific to the various semantic token request.\n\n    @since 3.16.0 \"\"\"\n    linkedEditingRange: NotRequired[\"LinkedEditingRangeClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/linkedEditingRange` request.\n\n    @since 3.16.0 \"\"\"\n    moniker: NotRequired[\"MonikerClientCapabilities\"]\n    \"\"\" Client capabilities specific to the `textDocument/moniker` request.\n\n    @since 3.16.0 \"\"\"\n    typeHierarchy: NotRequired[\"TypeHierarchyClientCapabilities\"]\n    \"\"\" Capabilities specific to the various type hierarchy requests.\n\n    @since 3.17.0 \"\"\"\n    inlineValue: NotRequired[\"InlineValueClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/inlineValue` request.\n\n    @since 3.17.0 \"\"\"\n    inlayHint: NotRequired[\"InlayHintClientCapabilities\"]\n    \"\"\" Capabilities specific to the `textDocument/inlayHint` request.\n\n    @since 3.17.0 \"\"\"\n    diagnostic: NotRequired[\"DiagnosticClientCapabilities\"]\n    \"\"\" Capabilities specific to the diagnostic pull model.\n\n    @since 3.17.0 \"\"\"\n\n\nclass NotebookDocumentClientCapabilities(TypedDict):\n    \"\"\"Capabilities specific to the notebook document support.\n\n    @since 3.17.0\n    \"\"\"\n\n    synchronization: \"NotebookDocumentSyncClientCapabilities\"\n    \"\"\" Capabilities specific to notebook document synchronization\n\n    @since 3.17.0 \"\"\"\n\n\nclass WindowClientCapabilities(TypedDict):\n    workDoneProgress: NotRequired[bool]\n    \"\"\" It indicates whether the client supports server initiated\n    progress using the `window/workDoneProgress/create` request.\n\n    The capability also controls Whether client supports handling\n    of progress notifications. If set servers are allowed to report a\n    `workDoneProgress` property in the request specific server\n    capabilities.\n\n    @since 3.15.0 \"\"\"\n    showMessage: NotRequired[\"ShowMessageRequestClientCapabilities\"]\n    \"\"\" Capabilities specific to the showMessage request.\n\n    @since 3.16.0 \"\"\"\n    showDocument: NotRequired[\"ShowDocumentClientCapabilities\"]\n    \"\"\" Capabilities specific to the showDocument request.\n\n    @since 3.16.0 \"\"\"\n\n\nclass GeneralClientCapabilities(TypedDict):\n    \"\"\"General client capabilities.\n\n    @since 3.16.0\n    \"\"\"\n\n    staleRequestSupport: NotRequired[\"__GeneralClientCapabilities_staleRequestSupport_Type_1\"]\n    \"\"\" Client capability that signals how the client\n    handles stale requests (e.g. a request\n    for which the client will not process the response\n    anymore since the information is outdated).\n\n    @since 3.17.0 \"\"\"\n    regularExpressions: NotRequired[\"RegularExpressionsClientCapabilities\"]\n    \"\"\" Client capabilities specific to regular expressions.\n\n    @since 3.16.0 \"\"\"\n    markdown: NotRequired[\"MarkdownClientCapabilities\"]\n    \"\"\" Client capabilities specific to the client's markdown parser.\n\n    @since 3.16.0 \"\"\"\n    positionEncodings: NotRequired[list[\"PositionEncodingKind\"]]\n    \"\"\" The position encodings supported by the client. Client and server\n    have to agree on the same position encoding to ensure that offsets\n    (e.g. character position in a line) are interpreted the same on both\n    sides.\n\n    To keep the protocol backwards compatible the following applies: if\n    the value 'utf-16' is missing from the array of position encodings\n    servers can assume that the client supports UTF-16. UTF-16 is\n    therefore a mandatory encoding.\n\n    If omitted it defaults to ['utf-16'].\n\n    Implementation considerations: since the conversion from one encoding\n    into another requires the content of the file / line the conversion\n    is best done where the file is read which is usually on the server\n    side.\n\n    @since 3.17.0 \"\"\"\n\n\nclass RelativePattern(TypedDict):\n    \"\"\"A relative pattern is a helper to construct glob patterns that are matched\n    relatively to a base URI. The common value for a `baseUri` is a workspace\n    folder root, but it can be another absolute URI as well.\n\n    @since 3.17.0\n    \"\"\"\n\n    baseUri: Union[\"WorkspaceFolder\", \"URI\"]\n    \"\"\" A workspace folder or a base URI to which this pattern will be matched\n    against relatively. \"\"\"\n    pattern: \"Pattern\"\n    \"\"\" The actual glob pattern; \"\"\"\n\n\nclass WorkspaceEditClientCapabilities(TypedDict):\n    documentChanges: NotRequired[bool]\n    \"\"\" The client supports versioned document changes in `WorkspaceEdit`s \"\"\"\n    resourceOperations: NotRequired[list[\"ResourceOperationKind\"]]\n    \"\"\" The resource operations the client supports. Clients should at least\n    support 'create', 'rename' and 'delete' files and folders.\n\n    @since 3.13.0 \"\"\"\n    failureHandling: NotRequired[\"FailureHandlingKind\"]\n    \"\"\" The failure handling strategy of a client if applying the workspace edit\n    fails.\n\n    @since 3.13.0 \"\"\"\n    normalizesLineEndings: NotRequired[bool]\n    \"\"\" Whether the client normalizes line endings to the client specific\n    setting.\n    If set to `true` the client will normalize line ending characters\n    in a workspace edit to the client-specified new line\n    character.\n\n    @since 3.16.0 \"\"\"\n    changeAnnotationSupport: NotRequired[\"__WorkspaceEditClientCapabilities_changeAnnotationSupport_Type_1\"]\n    \"\"\" Whether the client in general supports change annotations on text edits,\n    create file, rename file and delete file changes.\n\n    @since 3.16.0 \"\"\"\n\n\nclass DidChangeConfigurationClientCapabilities(TypedDict):\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Did change configuration notification supports dynamic registration. \"\"\"\n\n\nclass DidChangeWatchedFilesClientCapabilities(TypedDict):\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Did change watched files notification supports dynamic registration. Please note\n    that the current protocol doesn't support static configuration for file changes\n    from the server side. \"\"\"\n    relativePatternSupport: NotRequired[bool]\n    \"\"\" Whether the client has support for {@link  RelativePattern relative pattern}\n    or not.\n\n    @since 3.17.0 \"\"\"\n\n\nclass WorkspaceSymbolClientCapabilities(TypedDict):\n    \"\"\"Client capabilities for a {@link WorkspaceSymbolRequest}.\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Symbol request supports dynamic registration. \"\"\"\n    symbolKind: NotRequired[\"__WorkspaceSymbolClientCapabilities_symbolKind_Type_1\"]\n    \"\"\" Specific capabilities for the `SymbolKind` in the `workspace/symbol` request. \"\"\"\n    tagSupport: NotRequired[\"__WorkspaceSymbolClientCapabilities_tagSupport_Type_1\"]\n    \"\"\" The client supports tags on `SymbolInformation`.\n    Clients supporting tags have to handle unknown tags gracefully.\n\n    @since 3.16.0 \"\"\"\n    resolveSupport: NotRequired[\"__WorkspaceSymbolClientCapabilities_resolveSupport_Type_1\"]\n    \"\"\" The client support partial workspace symbols. The client will send the\n    request `workspaceSymbol/resolve` to the server to resolve additional\n    properties.\n\n    @since 3.17.0 \"\"\"\n\n\nclass ExecuteCommandClientCapabilities(TypedDict):\n    \"\"\"The client capabilities of a {@link ExecuteCommandRequest}.\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Execute command supports dynamic registration. \"\"\"\n\n\nclass SemanticTokensWorkspaceClientCapabilities(TypedDict):\n    \"\"\"@since 3.16.0\"\"\"\n\n    refreshSupport: NotRequired[bool]\n    \"\"\" Whether the client implementation supports a refresh request sent from\n    the server to the client.\n\n    Note that this event is global and will force the client to refresh all\n    semantic tokens currently shown. It should be used with absolute care\n    and is useful for situation where a server for example detects a project\n    wide change that requires such a calculation. \"\"\"\n\n\nclass CodeLensWorkspaceClientCapabilities(TypedDict):\n    \"\"\"@since 3.16.0\"\"\"\n\n    refreshSupport: NotRequired[bool]\n    \"\"\" Whether the client implementation supports a refresh request sent from the\n    server to the client.\n\n    Note that this event is global and will force the client to refresh all\n    code lenses currently shown. It should be used with absolute care and is\n    useful for situation where a server for example detect a project wide\n    change that requires such a calculation. \"\"\"\n\n\nclass FileOperationClientCapabilities(TypedDict):\n    \"\"\"Capabilities relating to events from file operations by the user in the client.\n\n    These events do not come from the file system, they come from user operations\n    like renaming a file in the UI.\n\n    @since 3.16.0\n    \"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether the client supports dynamic registration for file requests/notifications. \"\"\"\n    didCreate: NotRequired[bool]\n    \"\"\" The client has support for sending didCreateFiles notifications. \"\"\"\n    willCreate: NotRequired[bool]\n    \"\"\" The client has support for sending willCreateFiles requests. \"\"\"\n    didRename: NotRequired[bool]\n    \"\"\" The client has support for sending didRenameFiles notifications. \"\"\"\n    willRename: NotRequired[bool]\n    \"\"\" The client has support for sending willRenameFiles requests. \"\"\"\n    didDelete: NotRequired[bool]\n    \"\"\" The client has support for sending didDeleteFiles notifications. \"\"\"\n    willDelete: NotRequired[bool]\n    \"\"\" The client has support for sending willDeleteFiles requests. \"\"\"\n\n\nclass InlineValueWorkspaceClientCapabilities(TypedDict):\n    \"\"\"Client workspace capabilities specific to inline values.\n\n    @since 3.17.0\n    \"\"\"\n\n    refreshSupport: NotRequired[bool]\n    \"\"\" Whether the client implementation supports a refresh request sent from the\n    server to the client.\n\n    Note that this event is global and will force the client to refresh all\n    inline values currently shown. It should be used with absolute care and is\n    useful for situation where a server for example detects a project wide\n    change that requires such a calculation. \"\"\"\n\n\nclass InlayHintWorkspaceClientCapabilities(TypedDict):\n    \"\"\"Client workspace capabilities specific to inlay hints.\n\n    @since 3.17.0\n    \"\"\"\n\n    refreshSupport: NotRequired[bool]\n    \"\"\" Whether the client implementation supports a refresh request sent from\n    the server to the client.\n\n    Note that this event is global and will force the client to refresh all\n    inlay hints currently shown. It should be used with absolute care and\n    is useful for situation where a server for example detects a project wide\n    change that requires such a calculation. \"\"\"\n\n\nclass DiagnosticWorkspaceClientCapabilities(TypedDict):\n    \"\"\"Workspace client capabilities specific to diagnostic pull requests.\n\n    @since 3.17.0\n    \"\"\"\n\n    refreshSupport: NotRequired[bool]\n    \"\"\" Whether the client implementation supports a refresh request sent from\n    the server to the client.\n\n    Note that this event is global and will force the client to refresh all\n    pulled diagnostics currently shown. It should be used with absolute care and\n    is useful for situation where a server for example detects a project wide\n    change that requires such a calculation. \"\"\"\n\n\nclass TextDocumentSyncClientCapabilities(TypedDict):\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether text document synchronization supports dynamic registration. \"\"\"\n    willSave: NotRequired[bool]\n    \"\"\" The client supports sending will save notifications. \"\"\"\n    willSaveWaitUntil: NotRequired[bool]\n    \"\"\" The client supports sending a will save request and\n    waits for a response providing text edits which will\n    be applied to the document before it is saved. \"\"\"\n    didSave: NotRequired[bool]\n    \"\"\" The client supports did save notifications. \"\"\"\n\n\nclass CompletionClientCapabilities(TypedDict):\n    \"\"\"Completion client capabilities\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether completion supports dynamic registration. \"\"\"\n    completionItem: NotRequired[\"__CompletionClientCapabilities_completionItem_Type_1\"]\n    \"\"\" The client supports the following `CompletionItem` specific\n    capabilities. \"\"\"\n    completionItemKind: NotRequired[\"__CompletionClientCapabilities_completionItemKind_Type_1\"]\n    insertTextMode: NotRequired[\"InsertTextMode\"]\n    \"\"\" Defines how the client handles whitespace and indentation\n    when accepting a completion item that uses multi line\n    text in either `insertText` or `textEdit`.\n\n    @since 3.17.0 \"\"\"\n    contextSupport: NotRequired[bool]\n    \"\"\" The client supports to send additional context information for a\n    `textDocument/completion` request. \"\"\"\n    completionList: NotRequired[\"__CompletionClientCapabilities_completionList_Type_1\"]\n    \"\"\" The client supports the following `CompletionList` specific\n    capabilities.\n\n    @since 3.17.0 \"\"\"\n\n\nclass HoverClientCapabilities(TypedDict):\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether hover supports dynamic registration. \"\"\"\n    contentFormat: NotRequired[list[\"MarkupKind\"]]\n    \"\"\" Client supports the following content formats for the content\n    property. The order describes the preferred format of the client. \"\"\"\n\n\nclass SignatureHelpClientCapabilities(TypedDict):\n    \"\"\"Client Capabilities for a {@link SignatureHelpRequest}.\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether signature help supports dynamic registration. \"\"\"\n    signatureInformation: NotRequired[\"__SignatureHelpClientCapabilities_signatureInformation_Type_1\"]\n    \"\"\" The client supports the following `SignatureInformation`\n    specific properties. \"\"\"\n    contextSupport: NotRequired[bool]\n    \"\"\" The client supports to send additional context information for a\n    `textDocument/signatureHelp` request. A client that opts into\n    contextSupport will also support the `retriggerCharacters` on\n    `SignatureHelpOptions`.\n\n    @since 3.15.0 \"\"\"\n\n\nclass DeclarationClientCapabilities(TypedDict):\n    \"\"\"@since 3.14.0\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether declaration supports dynamic registration. If this is set to `true`\n    the client supports the new `DeclarationRegistrationOptions` return value\n    for the corresponding server capability as well. \"\"\"\n    linkSupport: NotRequired[bool]\n    \"\"\" The client supports additional metadata in the form of declaration links. \"\"\"\n\n\nclass DefinitionClientCapabilities(TypedDict):\n    \"\"\"Client Capabilities for a {@link DefinitionRequest}.\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether definition supports dynamic registration. \"\"\"\n    linkSupport: NotRequired[bool]\n    \"\"\" The client supports additional metadata in the form of definition links.\n\n    @since 3.14.0 \"\"\"\n\n\nclass TypeDefinitionClientCapabilities(TypedDict):\n    \"\"\"Since 3.6.0\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether implementation supports dynamic registration. If this is set to `true`\n    the client supports the new `TypeDefinitionRegistrationOptions` return value\n    for the corresponding server capability as well. \"\"\"\n    linkSupport: NotRequired[bool]\n    \"\"\" The client supports additional metadata in the form of definition links.\n\n    Since 3.14.0 \"\"\"\n\n\nclass ImplementationClientCapabilities(TypedDict):\n    \"\"\"@since 3.6.0\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether implementation supports dynamic registration. If this is set to `true`\n    the client supports the new `ImplementationRegistrationOptions` return value\n    for the corresponding server capability as well. \"\"\"\n    linkSupport: NotRequired[bool]\n    \"\"\" The client supports additional metadata in the form of definition links.\n\n    @since 3.14.0 \"\"\"\n\n\nclass ReferenceClientCapabilities(TypedDict):\n    \"\"\"Client Capabilities for a {@link ReferencesRequest}.\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether references supports dynamic registration. \"\"\"\n\n\nclass DocumentHighlightClientCapabilities(TypedDict):\n    \"\"\"Client Capabilities for a {@link DocumentHighlightRequest}.\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether document highlight supports dynamic registration. \"\"\"\n\n\nclass DocumentSymbolClientCapabilities(TypedDict):\n    \"\"\"Client Capabilities for a {@link DocumentSymbolRequest}.\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether document symbol supports dynamic registration. \"\"\"\n    symbolKind: NotRequired[\"__DocumentSymbolClientCapabilities_symbolKind_Type_1\"]\n    \"\"\" Specific capabilities for the `SymbolKind` in the\n    `textDocument/documentSymbol` request. \"\"\"\n    hierarchicalDocumentSymbolSupport: NotRequired[bool]\n    \"\"\" The client supports hierarchical document symbols. \"\"\"\n    tagSupport: NotRequired[\"__DocumentSymbolClientCapabilities_tagSupport_Type_1\"]\n    \"\"\" The client supports tags on `SymbolInformation`. Tags are supported on\n    `DocumentSymbol` if `hierarchicalDocumentSymbolSupport` is set to true.\n    Clients supporting tags have to handle unknown tags gracefully.\n\n    @since 3.16.0 \"\"\"\n    labelSupport: NotRequired[bool]\n    \"\"\" The client supports an additional label presented in the UI when\n    registering a document symbol provider.\n\n    @since 3.16.0 \"\"\"\n\n\nclass CodeActionClientCapabilities(TypedDict):\n    \"\"\"The Client Capabilities of a {@link CodeActionRequest}.\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether code action supports dynamic registration. \"\"\"\n    codeActionLiteralSupport: NotRequired[\"__CodeActionClientCapabilities_codeActionLiteralSupport_Type_1\"]\n    \"\"\" The client support code action literals of type `CodeAction` as a valid\n    response of the `textDocument/codeAction` request. If the property is not\n    set the request can only return `Command` literals.\n\n    @since 3.8.0 \"\"\"\n    isPreferredSupport: NotRequired[bool]\n    \"\"\" Whether code action supports the `isPreferred` property.\n\n    @since 3.15.0 \"\"\"\n    disabledSupport: NotRequired[bool]\n    \"\"\" Whether code action supports the `disabled` property.\n\n    @since 3.16.0 \"\"\"\n    dataSupport: NotRequired[bool]\n    \"\"\" Whether code action supports the `data` property which is\n    preserved between a `textDocument/codeAction` and a\n    `codeAction/resolve` request.\n\n    @since 3.16.0 \"\"\"\n    resolveSupport: NotRequired[\"__CodeActionClientCapabilities_resolveSupport_Type_1\"]\n    \"\"\" Whether the client supports resolving additional code action\n    properties via a separate `codeAction/resolve` request.\n\n    @since 3.16.0 \"\"\"\n    honorsChangeAnnotations: NotRequired[bool]\n    \"\"\" Whether the client honors the change annotations in\n    text edits and resource operations returned via the\n    `CodeAction#edit` property by for example presenting\n    the workspace edit in the user interface and asking\n    for confirmation.\n\n    @since 3.16.0 \"\"\"\n\n\nclass CodeLensClientCapabilities(TypedDict):\n    \"\"\"The client capabilities  of a {@link CodeLensRequest}.\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether code lens supports dynamic registration. \"\"\"\n\n\nclass DocumentLinkClientCapabilities(TypedDict):\n    \"\"\"The client capabilities of a {@link DocumentLinkRequest}.\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether document link supports dynamic registration. \"\"\"\n    tooltipSupport: NotRequired[bool]\n    \"\"\" Whether the client supports the `tooltip` property on `DocumentLink`.\n\n    @since 3.15.0 \"\"\"\n\n\nclass DocumentColorClientCapabilities(TypedDict):\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether implementation supports dynamic registration. If this is set to `true`\n    the client supports the new `DocumentColorRegistrationOptions` return value\n    for the corresponding server capability as well. \"\"\"\n\n\nclass DocumentFormattingClientCapabilities(TypedDict):\n    \"\"\"Client capabilities of a {@link DocumentFormattingRequest}.\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether formatting supports dynamic registration. \"\"\"\n\n\nclass DocumentRangeFormattingClientCapabilities(TypedDict):\n    \"\"\"Client capabilities of a {@link DocumentRangeFormattingRequest}.\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether range formatting supports dynamic registration. \"\"\"\n\n\nclass DocumentOnTypeFormattingClientCapabilities(TypedDict):\n    \"\"\"Client capabilities of a {@link DocumentOnTypeFormattingRequest}.\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether on type formatting supports dynamic registration. \"\"\"\n\n\nclass RenameClientCapabilities(TypedDict):\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether rename supports dynamic registration. \"\"\"\n    prepareSupport: NotRequired[bool]\n    \"\"\" Client supports testing for validity of rename operations\n    before execution.\n\n    @since 3.12.0 \"\"\"\n    prepareSupportDefaultBehavior: NotRequired[\"PrepareSupportDefaultBehavior\"]\n    \"\"\" Client supports the default behavior result.\n\n    The value indicates the default behavior used by the\n    client.\n\n    @since 3.16.0 \"\"\"\n    honorsChangeAnnotations: NotRequired[bool]\n    \"\"\" Whether the client honors the change annotations in\n    text edits and resource operations returned via the\n    rename request's workspace edit by for example presenting\n    the workspace edit in the user interface and asking\n    for confirmation.\n\n    @since 3.16.0 \"\"\"\n\n\nclass FoldingRangeClientCapabilities(TypedDict):\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether implementation supports dynamic registration for folding range\n    providers. If this is set to `true` the client supports the new\n    `FoldingRangeRegistrationOptions` return value for the corresponding\n    server capability as well. \"\"\"\n    rangeLimit: NotRequired[Uint]\n    \"\"\" The maximum number of folding ranges that the client prefers to receive\n    per document. The value serves as a hint, servers are free to follow the\n    limit. \"\"\"\n    lineFoldingOnly: NotRequired[bool]\n    \"\"\" If set, the client signals that it only supports folding complete lines.\n    If set, client will ignore specified `startCharacter` and `endCharacter`\n    properties in a FoldingRange. \"\"\"\n    foldingRangeKind: NotRequired[\"__FoldingRangeClientCapabilities_foldingRangeKind_Type_1\"]\n    \"\"\" Specific options for the folding range kind.\n\n    @since 3.17.0 \"\"\"\n    foldingRange: NotRequired[\"__FoldingRangeClientCapabilities_foldingRange_Type_1\"]\n    \"\"\" Specific options for the folding range.\n\n    @since 3.17.0 \"\"\"\n\n\nclass SelectionRangeClientCapabilities(TypedDict):\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether implementation supports dynamic registration for selection range providers. If this is set to `true`\n    the client supports the new `SelectionRangeRegistrationOptions` return value for the corresponding server\n    capability as well. \"\"\"\n\n\nclass PublishDiagnosticsClientCapabilities(TypedDict):\n    \"\"\"The publish diagnostic client capabilities.\"\"\"\n\n    relatedInformation: NotRequired[bool]\n    \"\"\" Whether the clients accepts diagnostics with related information. \"\"\"\n    tagSupport: NotRequired[\"__PublishDiagnosticsClientCapabilities_tagSupport_Type_1\"]\n    \"\"\" Client supports the tag property to provide meta data about a diagnostic.\n    Clients supporting tags have to handle unknown tags gracefully.\n\n    @since 3.15.0 \"\"\"\n    versionSupport: NotRequired[bool]\n    \"\"\" Whether the client interprets the version property of the\n    `textDocument/publishDiagnostics` notification's parameter.\n\n    @since 3.15.0 \"\"\"\n    codeDescriptionSupport: NotRequired[bool]\n    \"\"\" Client supports a codeDescription property\n\n    @since 3.16.0 \"\"\"\n    dataSupport: NotRequired[bool]\n    \"\"\" Whether code action supports the `data` property which is\n    preserved between a `textDocument/publishDiagnostics` and\n    `textDocument/codeAction` request.\n\n    @since 3.16.0 \"\"\"\n\n\nclass CallHierarchyClientCapabilities(TypedDict):\n    \"\"\"@since 3.16.0\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether implementation supports dynamic registration. If this is set to `true`\n    the client supports the new `(TextDocumentRegistrationOptions & StaticRegistrationOptions)`\n    return value for the corresponding server capability as well. \"\"\"\n\n\nclass SemanticTokensClientCapabilities(TypedDict):\n    \"\"\"@since 3.16.0\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether implementation supports dynamic registration. If this is set to `true`\n    the client supports the new `(TextDocumentRegistrationOptions & StaticRegistrationOptions)`\n    return value for the corresponding server capability as well. \"\"\"\n    requests: \"__SemanticTokensClientCapabilities_requests_Type_1\"\n    \"\"\" Which requests the client supports and might send to the server\n    depending on the server's capability. Please note that clients might not\n    show semantic tokens or degrade some of the user experience if a range\n    or full request is advertised by the client but not provided by the\n    server. If for example the client capability `requests.full` and\n    `request.range` are both set to true but the server only provides a\n    range provider the client might not render a minimap correctly or might\n    even decide to not show any semantic tokens at all. \"\"\"\n    tokenTypes: list[str]\n    \"\"\" The token types that the client supports. \"\"\"\n    tokenModifiers: list[str]\n    \"\"\" The token modifiers that the client supports. \"\"\"\n    formats: list[\"TokenFormat\"]\n    \"\"\" The token formats the clients supports. \"\"\"\n    overlappingTokenSupport: NotRequired[bool]\n    \"\"\" Whether the client supports tokens that can overlap each other. \"\"\"\n    multilineTokenSupport: NotRequired[bool]\n    \"\"\" Whether the client supports tokens that can span multiple lines. \"\"\"\n    serverCancelSupport: NotRequired[bool]\n    \"\"\" Whether the client allows the server to actively cancel a\n    semantic token request, e.g. supports returning\n    LSPErrorCodes.ServerCancelled. If a server does the client\n    needs to retrigger the request.\n\n    @since 3.17.0 \"\"\"\n    augmentsSyntaxTokens: NotRequired[bool]\n    \"\"\" Whether the client uses semantic tokens to augment existing\n    syntax tokens. If set to `true` client side created syntax\n    tokens and semantic tokens are both used for colorization. If\n    set to `false` the client only uses the returned semantic tokens\n    for colorization.\n\n    If the value is `undefined` then the client behavior is not\n    specified.\n\n    @since 3.17.0 \"\"\"\n\n\nclass LinkedEditingRangeClientCapabilities(TypedDict):\n    \"\"\"Client capabilities for the linked editing range request.\n\n    @since 3.16.0\n    \"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether implementation supports dynamic registration. If this is set to `true`\n    the client supports the new `(TextDocumentRegistrationOptions & StaticRegistrationOptions)`\n    return value for the corresponding server capability as well. \"\"\"\n\n\nclass MonikerClientCapabilities(TypedDict):\n    \"\"\"Client capabilities specific to the moniker request.\n\n    @since 3.16.0\n    \"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether moniker supports dynamic registration. If this is set to `true`\n    the client supports the new `MonikerRegistrationOptions` return value\n    for the corresponding server capability as well. \"\"\"\n\n\nclass TypeHierarchyClientCapabilities(TypedDict):\n    \"\"\"@since 3.17.0\"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether implementation supports dynamic registration. If this is set to `true`\n    the client supports the new `(TextDocumentRegistrationOptions & StaticRegistrationOptions)`\n    return value for the corresponding server capability as well. \"\"\"\n\n\nclass InlineValueClientCapabilities(TypedDict):\n    \"\"\"Client capabilities specific to inline values.\n\n    @since 3.17.0\n    \"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether implementation supports dynamic registration for inline value providers. \"\"\"\n\n\nclass InlayHintClientCapabilities(TypedDict):\n    \"\"\"Inlay hint client capabilities.\n\n    @since 3.17.0\n    \"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether inlay hints support dynamic registration. \"\"\"\n    resolveSupport: NotRequired[\"__InlayHintClientCapabilities_resolveSupport_Type_1\"]\n    \"\"\" Indicates which properties a client can resolve lazily on an inlay\n    hint. \"\"\"\n\n\nclass DiagnosticClientCapabilities(TypedDict):\n    \"\"\"Client capabilities specific to diagnostic pull requests.\n\n    @since 3.17.0\n    \"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether implementation supports dynamic registration. If this is set to `true`\n    the client supports the new `(TextDocumentRegistrationOptions & StaticRegistrationOptions)`\n    return value for the corresponding server capability as well. \"\"\"\n    relatedDocumentSupport: NotRequired[bool]\n    \"\"\" Whether the clients supports related documents for document diagnostic pulls. \"\"\"\n\n\nclass NotebookDocumentSyncClientCapabilities(TypedDict):\n    \"\"\"Notebook specific client capabilities.\n\n    @since 3.17.0\n    \"\"\"\n\n    dynamicRegistration: NotRequired[bool]\n    \"\"\" Whether implementation supports dynamic registration. If this is\n    set to `true` the client supports the new\n    `(TextDocumentRegistrationOptions & StaticRegistrationOptions)`\n    return value for the corresponding server capability as well. \"\"\"\n    executionSummarySupport: NotRequired[bool]\n    \"\"\" The client supports sending execution summary data per cell. \"\"\"\n\n\nclass ShowMessageRequestClientCapabilities(TypedDict):\n    \"\"\"Show message request client capabilities\"\"\"\n\n    messageActionItem: NotRequired[\"__ShowMessageRequestClientCapabilities_messageActionItem_Type_1\"]\n    \"\"\" Capabilities specific to the `MessageActionItem` type. \"\"\"\n\n\nclass ShowDocumentClientCapabilities(TypedDict):\n    \"\"\"Client capabilities for the showDocument request.\n\n    @since 3.16.0\n    \"\"\"\n\n    support: bool\n    \"\"\" The client has support for the showDocument\n    request. \"\"\"\n\n\nclass RegularExpressionsClientCapabilities(TypedDict):\n    \"\"\"Client capabilities specific to regular expressions.\n\n    @since 3.16.0\n    \"\"\"\n\n    engine: str\n    \"\"\" The engine's name. \"\"\"\n    version: NotRequired[str]\n    \"\"\" The engine's version. \"\"\"\n\n\nclass MarkdownClientCapabilities(TypedDict):\n    \"\"\"Client capabilities specific to the used markdown parser.\n\n    @since 3.16.0\n    \"\"\"\n\n    parser: str\n    \"\"\" The name of the parser. \"\"\"\n    version: NotRequired[str]\n    \"\"\" The version of the parser. \"\"\"\n    allowedTags: NotRequired[list[str]]\n    \"\"\" A list of HTML tags that the client allows / supports in\n    Markdown.\n\n    @since 3.17.0 \"\"\"\n\n\nclass __CodeActionClientCapabilities_codeActionLiteralSupport_Type_1(TypedDict):\n    codeActionKind: \"__CodeActionClientCapabilities_codeActionLiteralSupport_codeActionKind_Type_1\"\n    \"\"\" The code action kind is support with the following value\n    set. \"\"\"\n\n\nclass __CodeActionClientCapabilities_codeActionLiteralSupport_codeActionKind_Type_1(TypedDict):\n    valueSet: list[\"CodeActionKind\"]\n    \"\"\" The code action kind values the client supports. When this\n    property exists the client also guarantees that it will\n    handle values outside its set gracefully and falls back\n    to a default value when unknown. \"\"\"\n\n\nclass __CodeActionClientCapabilities_resolveSupport_Type_1(TypedDict):\n    properties: list[str]\n    \"\"\" The properties that a client can resolve lazily. \"\"\"\n\n\nclass __CodeAction_disabled_Type_1(TypedDict):\n    reason: str\n    \"\"\" Human readable description of why the code action is currently disabled.\n\n    This is displayed in the code actions UI. \"\"\"\n\n\nclass __CompletionClientCapabilities_completionItemKind_Type_1(TypedDict):\n    valueSet: NotRequired[list[\"CompletionItemKind\"]]\n    \"\"\" The completion item kind values the client supports. When this\n    property exists the client also guarantees that it will\n    handle values outside its set gracefully and falls back\n    to a default value when unknown.\n\n    If this property is not present the client only supports\n    the completion items kinds from `Text` to `Reference` as defined in\n    the initial version of the protocol. \"\"\"\n\n\nclass __CompletionClientCapabilities_completionItem_Type_1(TypedDict):\n    snippetSupport: NotRequired[bool]\n    \"\"\" Client supports snippets as insert text.\n\n    A snippet can define tab stops and placeholders with `$1`, `$2`\n    and `${3:foo}`. `$0` defines the final tab stop, it defaults to\n    the end of the snippet. Placeholders with equal identifiers are linked,\n    that is typing in one will update others too. \"\"\"\n    commitCharactersSupport: NotRequired[bool]\n    \"\"\" Client supports commit characters on a completion item. \"\"\"\n    documentationFormat: NotRequired[list[\"MarkupKind\"]]\n    \"\"\" Client supports the following content formats for the documentation\n    property. The order describes the preferred format of the client. \"\"\"\n    deprecatedSupport: NotRequired[bool]\n    \"\"\" Client supports the deprecated property on a completion item. \"\"\"\n    preselectSupport: NotRequired[bool]\n    \"\"\" Client supports the preselect property on a completion item. \"\"\"\n    tagSupport: NotRequired[\"__CompletionClientCapabilities_completionItem_tagSupport_Type_1\"]\n    \"\"\" Client supports the tag property on a completion item. Clients supporting\n    tags have to handle unknown tags gracefully. Clients especially need to\n    preserve unknown tags when sending a completion item back to the server in\n    a resolve call.\n\n    @since 3.15.0 \"\"\"\n    insertReplaceSupport: NotRequired[bool]\n    \"\"\" Client support insert replace edit to control different behavior if a\n    completion item is inserted in the text or should replace text.\n\n    @since 3.16.0 \"\"\"\n    resolveSupport: NotRequired[\"__CompletionClientCapabilities_completionItem_resolveSupport_Type_1\"]\n    \"\"\" Indicates which properties a client can resolve lazily on a completion\n    item. Before version 3.16.0 only the predefined properties `documentation`\n    and `details` could be resolved lazily.\n\n    @since 3.16.0 \"\"\"\n    insertTextModeSupport: NotRequired[\"__CompletionClientCapabilities_completionItem_insertTextModeSupport_Type_1\"]\n    \"\"\" The client supports the `insertTextMode` property on\n    a completion item to override the whitespace handling mode\n    as defined by the client (see `insertTextMode`).\n\n    @since 3.16.0 \"\"\"\n    labelDetailsSupport: NotRequired[bool]\n    \"\"\" The client has support for completion item label\n    details (see also `CompletionItemLabelDetails`).\n\n    @since 3.17.0 \"\"\"\n\n\nclass __CompletionClientCapabilities_completionItem_insertTextModeSupport_Type_1(TypedDict):\n    valueSet: list[\"InsertTextMode\"]\n\n\nclass __CompletionClientCapabilities_completionItem_resolveSupport_Type_1(TypedDict):\n    properties: list[str]\n    \"\"\" The properties that a client can resolve lazily. \"\"\"\n\n\nclass __CompletionClientCapabilities_completionItem_tagSupport_Type_1(TypedDict):\n    valueSet: list[\"CompletionItemTag\"]\n    \"\"\" The tags supported by the client. \"\"\"\n\n\nclass __CompletionClientCapabilities_completionList_Type_1(TypedDict):\n    itemDefaults: NotRequired[list[str]]\n    \"\"\" The client supports the following itemDefaults on\n    a completion list.\n\n    The value lists the supported property names of the\n    `CompletionList.itemDefaults` object. If omitted\n    no properties are supported.\n\n    @since 3.17.0 \"\"\"\n\n\nclass __CompletionList_itemDefaults_Type_1(TypedDict):\n    commitCharacters: NotRequired[list[str]]\n    \"\"\" A default commit character set.\n\n    @since 3.17.0 \"\"\"\n    editRange: NotRequired[Union[\"Range\", \"__CompletionList_itemDefaults_editRange_Type_1\"]]\n    \"\"\" A default edit range.\n\n    @since 3.17.0 \"\"\"\n    insertTextFormat: NotRequired[\"InsertTextFormat\"]\n    \"\"\" A default insert text format.\n\n    @since 3.17.0 \"\"\"\n    insertTextMode: NotRequired[\"InsertTextMode\"]\n    \"\"\" A default insert text mode.\n\n    @since 3.17.0 \"\"\"\n    data: NotRequired[\"LSPAny\"]\n    \"\"\" A default data value.\n\n    @since 3.17.0 \"\"\"\n\n\nclass __CompletionList_itemDefaults_editRange_Type_1(TypedDict):\n    insert: \"Range\"\n    replace: \"Range\"\n\n\nclass __CompletionOptions_completionItem_Type_1(TypedDict):\n    labelDetailsSupport: NotRequired[bool]\n    \"\"\" The server has support for completion item label\n    details (see also `CompletionItemLabelDetails`) when\n    receiving a completion item in a resolve call.\n\n    @since 3.17.0 \"\"\"\n\n\nclass __CompletionOptions_completionItem_Type_2(TypedDict):\n    labelDetailsSupport: NotRequired[bool]\n    \"\"\" The server has support for completion item label\n    details (see also `CompletionItemLabelDetails`) when\n    receiving a completion item in a resolve call.\n\n    @since 3.17.0 \"\"\"\n\n\nclass __DocumentSymbolClientCapabilities_symbolKind_Type_1(TypedDict):\n    valueSet: NotRequired[list[\"SymbolKind\"]]\n    \"\"\" The symbol kind values the client supports. When this\n    property exists the client also guarantees that it will\n    handle values outside its set gracefully and falls back\n    to a default value when unknown.\n\n    If this property is not present the client only supports\n    the symbol kinds from `File` to `Array` as defined in\n    the initial version of the protocol. \"\"\"\n\n\nclass __DocumentSymbolClientCapabilities_tagSupport_Type_1(TypedDict):\n    valueSet: list[\"SymbolTag\"]\n    \"\"\" The tags supported by the client. \"\"\"\n\n\nclass __FoldingRangeClientCapabilities_foldingRangeKind_Type_1(TypedDict):\n    valueSet: NotRequired[list[\"FoldingRangeKind\"]]\n    \"\"\" The folding range kind values the client supports. When this\n    property exists the client also guarantees that it will\n    handle values outside its set gracefully and falls back\n    to a default value when unknown. \"\"\"\n\n\nclass __FoldingRangeClientCapabilities_foldingRange_Type_1(TypedDict):\n    collapsedText: NotRequired[bool]\n    \"\"\" If set, the client signals that it supports setting collapsedText on\n    folding ranges to display custom labels instead of the default text.\n\n    @since 3.17.0 \"\"\"\n\n\nclass __GeneralClientCapabilities_staleRequestSupport_Type_1(TypedDict):\n    cancel: bool\n    \"\"\" The client will actively cancel the request. \"\"\"\n    retryOnContentModified: list[str]\n    \"\"\" The list of requests for which the client\n    will retry the request if it receives a\n    response with error code `ContentModified` \"\"\"\n\n\nclass __InitializeResult_serverInfo_Type_1(TypedDict):\n    name: str\n    \"\"\" The name of the server as defined by the server. \"\"\"\n    version: NotRequired[str]\n    \"\"\" The server's version as defined by the server. \"\"\"\n\n\nclass __InlayHintClientCapabilities_resolveSupport_Type_1(TypedDict):\n    properties: list[str]\n    \"\"\" The properties that a client can resolve lazily. \"\"\"\n\n\nclass __MarkedString_Type_1(TypedDict):\n    language: str\n    value: str\n\n\nclass __NotebookDocumentChangeEvent_cells_Type_1(TypedDict):\n    structure: NotRequired[\"__NotebookDocumentChangeEvent_cells_structure_Type_1\"]\n    \"\"\" Changes to the cell structure to add or\n    remove cells. \"\"\"\n    data: NotRequired[list[\"NotebookCell\"]]\n    \"\"\" Changes to notebook cells properties like its\n    kind, execution summary or metadata. \"\"\"\n    textContent: NotRequired[list[\"__NotebookDocumentChangeEvent_cells_textContent_Type_1\"]]\n    \"\"\" Changes to the text content of notebook cells. \"\"\"\n\n\nclass __NotebookDocumentChangeEvent_cells_structure_Type_1(TypedDict):\n    array: \"NotebookCellArrayChange\"\n    \"\"\" The change to the cell array. \"\"\"\n    didOpen: NotRequired[list[\"TextDocumentItem\"]]\n    \"\"\" Additional opened cell text documents. \"\"\"\n    didClose: NotRequired[list[\"TextDocumentIdentifier\"]]\n    \"\"\" Additional closed cell text documents. \"\"\"\n\n\nclass __NotebookDocumentChangeEvent_cells_textContent_Type_1(TypedDict):\n    document: \"VersionedTextDocumentIdentifier\"\n    changes: list[\"TextDocumentContentChangeEvent\"]\n\n\nclass __NotebookDocumentFilter_Type_1(TypedDict):\n    notebookType: str\n    \"\"\" The type of the enclosing notebook. \"\"\"\n    scheme: NotRequired[str]\n    \"\"\" A Uri {@link Uri.scheme scheme}, like `file` or `untitled`. \"\"\"\n    pattern: NotRequired[str]\n    \"\"\" A glob pattern. \"\"\"\n\n\nclass __NotebookDocumentFilter_Type_2(TypedDict):\n    notebookType: NotRequired[str]\n    \"\"\" The type of the enclosing notebook. \"\"\"\n    scheme: str\n    \"\"\" A Uri {@link Uri.scheme scheme}, like `file` or `untitled`. \"\"\"\n    pattern: NotRequired[str]\n    \"\"\" A glob pattern. \"\"\"\n\n\nclass __NotebookDocumentFilter_Type_3(TypedDict):\n    notebookType: NotRequired[str]\n    \"\"\" The type of the enclosing notebook. \"\"\"\n    scheme: NotRequired[str]\n    \"\"\" A Uri {@link Uri.scheme scheme}, like `file` or `untitled`. \"\"\"\n    pattern: str\n    \"\"\" A glob pattern. \"\"\"\n\n\nclass __NotebookDocumentSyncOptions_notebookSelector_Type_1(TypedDict):\n    notebook: Union[str, \"NotebookDocumentFilter\"]\n    \"\"\" The notebook to be synced If a string\n    value is provided it matches against the\n    notebook type. '*' matches every notebook. \"\"\"\n    cells: NotRequired[list[\"__NotebookDocumentSyncOptions_notebookSelector_cells_Type_1\"]]\n    \"\"\" The cells of the matching notebook to be synced. \"\"\"\n\n\nclass __NotebookDocumentSyncOptions_notebookSelector_Type_2(TypedDict):\n    notebook: NotRequired[Union[str, \"NotebookDocumentFilter\"]]\n    \"\"\" The notebook to be synced If a string\n    value is provided it matches against the\n    notebook type. '*' matches every notebook. \"\"\"\n    cells: list[\"__NotebookDocumentSyncOptions_notebookSelector_cells_Type_2\"]\n    \"\"\" The cells of the matching notebook to be synced. \"\"\"\n\n\nclass __NotebookDocumentSyncOptions_notebookSelector_Type_3(TypedDict):\n    notebook: Union[str, \"NotebookDocumentFilter\"]\n    \"\"\" The notebook to be synced If a string\n    value is provided it matches against the\n    notebook type. '*' matches every notebook. \"\"\"\n    cells: NotRequired[list[\"__NotebookDocumentSyncOptions_notebookSelector_cells_Type_3\"]]\n    \"\"\" The cells of the matching notebook to be synced. \"\"\"\n\n\nclass __NotebookDocumentSyncOptions_notebookSelector_Type_4(TypedDict):\n    notebook: NotRequired[Union[str, \"NotebookDocumentFilter\"]]\n    \"\"\" The notebook to be synced If a string\n    value is provided it matches against the\n    notebook type. '*' matches every notebook. \"\"\"\n    cells: list[\"__NotebookDocumentSyncOptions_notebookSelector_cells_Type_4\"]\n    \"\"\" The cells of the matching notebook to be synced. \"\"\"\n\n\nclass __NotebookDocumentSyncOptions_notebookSelector_cells_Type_1(TypedDict):\n    language: str\n\n\nclass __NotebookDocumentSyncOptions_notebookSelector_cells_Type_2(TypedDict):\n    language: str\n\n\nclass __NotebookDocumentSyncOptions_notebookSelector_cells_Type_3(TypedDict):\n    language: str\n\n\nclass __NotebookDocumentSyncOptions_notebookSelector_cells_Type_4(TypedDict):\n    language: str\n\n\nclass __PrepareRenameResult_Type_1(TypedDict):\n    range: \"Range\"\n    placeholder: str\n\n\nclass __PrepareRenameResult_Type_2(TypedDict):\n    defaultBehavior: bool\n\n\nclass __PublishDiagnosticsClientCapabilities_tagSupport_Type_1(TypedDict):\n    valueSet: list[\"DiagnosticTag\"]\n    \"\"\" The tags supported by the client. \"\"\"\n\n\nclass __SemanticTokensClientCapabilities_requests_Type_1(TypedDict):\n    range: NotRequired[bool | dict]\n    \"\"\" The client will send the `textDocument/semanticTokens/range` request if\n    the server provides a corresponding handler. \"\"\"\n    full: NotRequired[Union[bool, \"__SemanticTokensClientCapabilities_requests_full_Type_1\"]]\n    \"\"\" The client will send the `textDocument/semanticTokens/full` request if\n    the server provides a corresponding handler. \"\"\"\n\n\nclass __SemanticTokensClientCapabilities_requests_full_Type_1(TypedDict):\n    delta: NotRequired[bool]\n    \"\"\" The client will send the `textDocument/semanticTokens/full/delta` request if\n    the server provides a corresponding handler. \"\"\"\n\n\nclass __SemanticTokensOptions_full_Type_1(TypedDict):\n    delta: NotRequired[bool]\n    \"\"\" The server supports deltas for full documents. \"\"\"\n\n\nclass __SemanticTokensOptions_full_Type_2(TypedDict):\n    delta: NotRequired[bool]\n    \"\"\" The server supports deltas for full documents. \"\"\"\n\n\nclass __ServerCapabilities_workspace_Type_1(TypedDict):\n    workspaceFolders: NotRequired[\"WorkspaceFoldersServerCapabilities\"]\n    \"\"\" The server supports workspace folder.\n\n    @since 3.6.0 \"\"\"\n    fileOperations: NotRequired[\"FileOperationOptions\"]\n    \"\"\" The server is interested in notifications/requests for operations on files.\n\n    @since 3.16.0 \"\"\"\n\n\nclass __ShowMessageRequestClientCapabilities_messageActionItem_Type_1(TypedDict):\n    additionalPropertiesSupport: NotRequired[bool]\n    \"\"\" Whether the client supports additional attributes which\n    are preserved and send back to the server in the\n    request's response. \"\"\"\n\n\nclass __SignatureHelpClientCapabilities_signatureInformation_Type_1(TypedDict):\n    documentationFormat: NotRequired[list[\"MarkupKind\"]]\n    \"\"\" Client supports the following content formats for the documentation\n    property. The order describes the preferred format of the client. \"\"\"\n    parameterInformation: NotRequired[\"__SignatureHelpClientCapabilities_signatureInformation_parameterInformation_Type_1\"]\n    \"\"\" Client capabilities specific to parameter information. \"\"\"\n    activeParameterSupport: NotRequired[bool]\n    \"\"\" The client supports the `activeParameter` property on `SignatureInformation`\n    literal.\n\n    @since 3.16.0 \"\"\"\n\n\nclass __SignatureHelpClientCapabilities_signatureInformation_parameterInformation_Type_1(TypedDict):\n    labelOffsetSupport: NotRequired[bool]\n    \"\"\" The client supports processing label offsets instead of a\n    simple label string.\n\n    @since 3.14.0 \"\"\"\n\n\nclass __TextDocumentContentChangeEvent_Type_1(TypedDict):\n    range: \"Range\"\n    \"\"\" The range of the document that changed. \"\"\"\n    rangeLength: NotRequired[Uint]\n    \"\"\" The optional length of the range that got replaced.\n\n    @deprecated use range instead. \"\"\"\n    text: str\n    \"\"\" The new text for the provided range. \"\"\"\n\n\nclass __TextDocumentContentChangeEvent_Type_2(TypedDict):\n    text: str\n    \"\"\" The new text of the whole document. \"\"\"\n\n\nclass __TextDocumentFilter_Type_1(TypedDict):\n    language: str\n    \"\"\" A language id, like `typescript`. \"\"\"\n    scheme: NotRequired[str]\n    \"\"\" A Uri {@link Uri.scheme scheme}, like `file` or `untitled`. \"\"\"\n    pattern: NotRequired[str]\n    \"\"\" A glob pattern, like `*.{ts,js}`. \"\"\"\n\n\nclass __TextDocumentFilter_Type_2(TypedDict):\n    language: NotRequired[str]\n    \"\"\" A language id, like `typescript`. \"\"\"\n    scheme: str\n    \"\"\" A Uri {@link Uri.scheme scheme}, like `file` or `untitled`. \"\"\"\n    pattern: NotRequired[str]\n    \"\"\" A glob pattern, like `*.{ts,js}`. \"\"\"\n\n\nclass __TextDocumentFilter_Type_3(TypedDict):\n    language: NotRequired[str]\n    \"\"\" A language id, like `typescript`. \"\"\"\n    scheme: NotRequired[str]\n    \"\"\" A Uri {@link Uri.scheme scheme}, like `file` or `untitled`. \"\"\"\n    pattern: str\n    \"\"\" A glob pattern, like `*.{ts,js}`. \"\"\"\n\n\nclass __WorkspaceEditClientCapabilities_changeAnnotationSupport_Type_1(TypedDict):\n    groupsOnLabel: NotRequired[bool]\n    \"\"\" Whether the client groups edits with equal labels into tree nodes,\n    for instance all edits labelled with \"Changes in Strings\" would\n    be a tree node. \"\"\"\n\n\nclass __WorkspaceSymbolClientCapabilities_resolveSupport_Type_1(TypedDict):\n    properties: list[str]\n    \"\"\" The properties that a client can resolve lazily. Usually\n    `location.range` \"\"\"\n\n\nclass __WorkspaceSymbolClientCapabilities_symbolKind_Type_1(TypedDict):\n    valueSet: NotRequired[list[\"SymbolKind\"]]\n    \"\"\" The symbol kind values the client supports. When this\n    property exists the client also guarantees that it will\n    handle values outside its set gracefully and falls back\n    to a default value when unknown.\n\n    If this property is not present the client only supports\n    the symbol kinds from `File` to `Array` as defined in\n    the initial version of the protocol. \"\"\"\n\n\nclass __WorkspaceSymbolClientCapabilities_tagSupport_Type_1(TypedDict):\n    valueSet: list[\"SymbolTag\"]\n    \"\"\" The tags supported by the client. \"\"\"\n\n\nclass __WorkspaceSymbol_location_Type_1(TypedDict):\n    uri: \"DocumentUri\"\n\n\nclass ___InitializeParams_clientInfo_Type_1(TypedDict):\n    name: str\n    \"\"\" The name of the client as defined by the client. \"\"\"\n    version: NotRequired[str]\n    \"\"\" The client's version as defined by the client. \"\"\"\n"
  },
  {
    "path": "src/solidlsp/lsp_protocol_handler/server.py",
    "content": "\"\"\"\nThis file provides the implementation of the JSON-RPC client, that launches and\ncommunicates with the language server.\n\nThe initial implementation of this file was obtained from\nhttps://github.com/predragnikolic/OLSP under the MIT License with the following terms:\n\nMIT License\n\nCopyright (c) 2023 Предраг Николић\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\"\"\"\n\nimport dataclasses\nimport json\nimport logging\nimport os\nfrom typing import Any, Union\n\nfrom .lsp_types import ErrorCodes\n\nStringDict = dict[str, Any]\nPayloadLike = Union[list[StringDict], StringDict, None, bool]\nCONTENT_LENGTH = \"Content-Length: \"\nENCODING = \"utf-8\"\nlog = logging.getLogger(__name__)\n\n\n@dataclasses.dataclass\nclass ProcessLaunchInfo:\n    \"\"\"\n    This class is used to store the information required to launch a (language server) process.\n    \"\"\"\n\n    cmd: str | list[str]\n    \"\"\"\n    the command used to launch the process.\n    Specification as a list is preferred (as it is more robust and avoids incorrect quoting of arguments);\n    the string variant is supported for backward compatibility only\n    \"\"\"\n\n    env: dict[str, str] = dataclasses.field(default_factory=dict)\n    \"\"\"\n    the environment variables to set for the process\n    \"\"\"\n\n    cwd: str = os.getcwd()\n    \"\"\"\n    the working directory for the process\n    \"\"\"\n\n\nclass LSPError(Exception):\n    def __init__(self, code: ErrorCodes, message: str) -> None:\n        super().__init__(message)\n        self.code = code\n\n    def to_lsp(self) -> StringDict:\n        return {\"code\": self.code, \"message\": super().__str__()}\n\n    @classmethod\n    def from_lsp(cls, d: StringDict) -> \"LSPError\":\n        return LSPError(d[\"code\"], d[\"message\"])\n\n    def __str__(self) -> str:\n        return f\"{super().__str__()} ({self.code})\"\n\n\ndef make_response(request_id: Any, params: PayloadLike) -> StringDict:\n    return {\"jsonrpc\": \"2.0\", \"id\": request_id, \"result\": params}\n\n\ndef make_error_response(request_id: Any, err: LSPError) -> StringDict:\n    return {\"jsonrpc\": \"2.0\", \"id\": request_id, \"error\": err.to_lsp()}\n\n\n# LSP methods that expect NO params field at all (not even empty object).\n# These methods use Void/unit type in their protocol definition.\n# - shutdown: HLS uses Haskell's Void type, rust-analyzer expects unit\n# - exit: Similar - notification with no params\n# Sending params:{} to these methods causes parse errors like \"Cannot parse Void\"\n# See: https://www.jsonrpc.org/specification (\"params MAY be omitted\")\n_NO_PARAMS_METHODS = frozenset({\"shutdown\", \"exit\"})\n\n\ndef _build_params_field(method: str, params: PayloadLike) -> StringDict:\n    \"\"\"Build the params portion of a JSON-RPC message based on LSP method requirements.\n\n    LSP methods with Void/unit type (shutdown, exit) must omit params field entirely\n    to satisfy HLS and rust-analyzer. Other methods send empty {} for None params\n    to maintain Delphi/FPC LSP compatibility (PR #851).\n\n    Returns a dict that can be merged into the message using ** unpacking.\n    \"\"\"\n    if method in _NO_PARAMS_METHODS:\n        return {}  # Omit params entirely for Void-type methods\n    elif params is not None:\n        return {\"params\": params}\n    else:\n        return {\"params\": {}}  # Keep {} for Delphi/FPC compatibility\n\n\ndef make_notification(method: str, params: PayloadLike) -> StringDict:\n    \"\"\"Create a JSON-RPC 2.0 notification message.\"\"\"\n    return {\"jsonrpc\": \"2.0\", \"method\": method, **_build_params_field(method, params)}\n\n\ndef make_request(method: str, request_id: Any, params: PayloadLike) -> StringDict:\n    \"\"\"Create a JSON-RPC 2.0 request message.\"\"\"\n    return {\"jsonrpc\": \"2.0\", \"method\": method, \"id\": request_id, **_build_params_field(method, params)}\n\n\nclass StopLoopException(Exception):\n    pass\n\n\ndef create_message(payload: PayloadLike) -> tuple[bytes, bytes, bytes]:\n    body = json.dumps(payload, check_circular=False, ensure_ascii=False, separators=(\",\", \":\")).encode(ENCODING)\n    return (\n        f\"Content-Length: {len(body)}\\r\\n\".encode(ENCODING),\n        \"Content-Type: application/vscode-jsonrpc; charset=utf-8\\r\\n\\r\\n\".encode(ENCODING),\n        body,\n    )\n\n\nclass MessageType:\n    error = 1\n    warning = 2\n    info = 3\n    log = 4\n\n\ndef content_length(line: bytes) -> int | None:\n    if line.startswith(b\"Content-Length: \"):\n        _, value = line.split(b\"Content-Length: \")\n        value = value.strip()\n        try:\n            return int(value)\n        except ValueError:\n            raise ValueError(f\"Invalid Content-Length header: {value!r}\")\n    return None\n"
  },
  {
    "path": "src/solidlsp/settings.py",
    "content": "\"\"\"\nDefines settings for Solid-LSP\n\"\"\"\n\nimport logging\nimport os\nimport pathlib\nfrom dataclasses import dataclass, field\nfrom typing import TYPE_CHECKING, Any\n\nfrom sensai.util.string import ToStringMixin\n\nif TYPE_CHECKING:\n    from solidlsp.ls_config import Language\n\nlog = logging.getLogger(__name__)\n\n\n@dataclass\nclass SolidLSPSettings:\n    solidlsp_dir: str = str(pathlib.Path.home() / \".solidlsp\")\n    \"\"\"\n    Path to the directory in which to store global Solid-LSP data (which is not project-specific)\n    \"\"\"\n    project_data_path: str = \"\"\n    \"\"\"\n    Absolute path to a directory where Solid-LSP can store project-specific data, e.g. cache files.\n    For instance, if this is \"/home/user/myproject/.solidlsp\",\n    then Solid-LSP will store project-specific data (e.g. caches) in that directory.\n    \"\"\"\n    ls_specific_settings: dict[\"Language\", dict[str, Any]] = field(default_factory=dict)\n    \"\"\"\n    Advanced configuration option allowing to configure language server implementation specific options.\n    Have a look at the docstring of the constructors of the corresponding LS implementations within solidlsp to see which options are available.\n    No documentation on options means no options are available.\n    \"\"\"\n\n    def __post_init__(self) -> None:\n        os.makedirs(str(self.solidlsp_dir), exist_ok=True)\n        os.makedirs(str(self.ls_resources_dir), exist_ok=True)\n\n    @property\n    def ls_resources_dir(self) -> str:\n        return os.path.join(str(self.solidlsp_dir), \"language_servers\", \"static\")\n\n    class CustomLSSettings(ToStringMixin):\n        def __init__(self, settings: dict[str, Any] | None) -> None:\n            self.settings = settings or {}\n\n        def get(self, key: str, default_value: Any = None) -> Any:\n            \"\"\"\n            Returns the custom setting for the given key or the default value if not set.\n            If a custom value is set for the given key, the retrieval is logged.\n\n            :param key: the key\n            :param default_value: the default value to use if no custom value is set\n            :return: the value\n            \"\"\"\n            if key in self.settings:\n                value = self.settings[key]\n                log.info(\"Using custom LS setting %s for key '%s'\", value, key)\n            else:\n                value = default_value\n            return value\n\n    def get_ls_specific_settings(self, language: \"Language\") -> CustomLSSettings:\n        \"\"\"\n        Get the language server specific settings for the given language.\n\n        :param language: The programming language.\n        :return: A dictionary of settings for the language server.\n        \"\"\"\n        return self.CustomLSSettings(self.ls_specific_settings.get(language))\n"
  },
  {
    "path": "src/solidlsp/util/cache.py",
    "content": "import logging\nfrom typing import Any, Optional\n\nfrom sensai.util.pickle import dump_pickle, load_pickle\n\nlog = logging.getLogger(__name__)\n\n\ndef load_cache(path: str, version: Any) -> Optional[Any]:\n    data = load_pickle(path)\n    if not isinstance(data, dict) or \"__cache_version\" not in data:\n        log.info(\"Cache is outdated (expected version %s). Ignoring cache at %s\", version, path)\n        return None\n    saved_version = data[\"__cache_version\"]\n    if saved_version != version:\n        log.info(\"Cache is outdated (expected version %s, got %s). Ignoring cache at %s\", version, saved_version, path)\n        return None\n    return data[\"obj\"]\n\n\ndef save_cache(path: str, version: Any, obj: Any) -> None:\n    data = {\"__cache_version\": version, \"obj\": obj}\n    dump_pickle(data, path)\n"
  },
  {
    "path": "src/solidlsp/util/metals_db_utils.py",
    "content": "\"\"\"\nUtilities for detecting and managing Scala Metals H2 database state.\n\nThis module provides functions to detect existing Metals LSP instances by checking\nthe H2 database lock file, and to clean up stale locks from crashed processes.\n\nMetals uses H2 AUTO_SERVER mode (enabled by default) to support multiple concurrent\ninstances sharing the same database. However, if a Metals process crashes without\nproper cleanup, it can leave a stale lock file that prevents proper AUTO_SERVER\ncoordination, causing new instances to fall back to in-memory database mode.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport logging\nimport re\nfrom dataclasses import dataclass\nfrom enum import Enum\nfrom pathlib import Path\nfrom typing import TYPE_CHECKING\n\nif TYPE_CHECKING:\n    pass\n\nlog = logging.getLogger(__name__)\n\n\nclass MetalsDbStatus(Enum):\n    \"\"\"Status of the Metals H2 database for a project.\"\"\"\n\n    NO_DATABASE = \"no_database\"\n    \"\"\"No .metals directory or database exists (fresh project).\"\"\"\n\n    NO_LOCK = \"no_lock\"\n    \"\"\"Database exists but no lock file (safe to start).\"\"\"\n\n    ACTIVE_INSTANCE = \"active_instance\"\n    \"\"\"Lock held by a running process (will share via AUTO_SERVER).\"\"\"\n\n    STALE_LOCK = \"stale_lock\"\n    \"\"\"Lock held by a dead process (needs cleanup).\"\"\"\n\n\n@dataclass\nclass MetalsLockInfo:\n    \"\"\"Information extracted from an H2 database lock file.\"\"\"\n\n    pid: int | None\n    \"\"\"Process ID that holds the lock, if parseable.\"\"\"\n\n    port: int | None\n    \"\"\"TCP port for AUTO_SERVER connection, if parseable.\"\"\"\n\n    lock_path: Path\n    \"\"\"Path to the lock file.\"\"\"\n\n    is_stale: bool\n    \"\"\"True if the owning process is no longer running.\"\"\"\n\n    raw_content: str\n    \"\"\"Raw content of the lock file for debugging.\"\"\"\n\n\ndef parse_h2_lock_file(lock_path: Path) -> MetalsLockInfo | None:\n    \"\"\"\n    Parse an H2 database lock file to extract connection information.\n\n    The H2 lock file format varies by version but typically contains\n    server connection information. Common formats include:\n    - Text format: \"server:localhost:9092\" or similar\n    - Binary format with embedded PID\n\n    Args:\n        lock_path: Path to the .lock.db file\n\n    Returns:\n        MetalsLockInfo if the file can be parsed, None if file doesn't exist\n        or is completely unparsable.\n\n    \"\"\"\n    if not lock_path.exists():\n        return None\n\n    try:\n        # Try reading as text first (most common for H2 AUTO_SERVER)\n        content = lock_path.read_text(encoding=\"utf-8\", errors=\"replace\")\n    except OSError as e:\n        log.debug(f\"Could not read lock file {lock_path}: {e}\")\n        return None\n\n    pid: int | None = None\n    port: int | None = None\n\n    # Try to extract port from common H2 lock file formats\n    # Format 1: \"server:localhost:PORT\"\n    server_match = re.search(r\"server:[\\w.]+:(\\d+)\", content, re.IGNORECASE)\n    if server_match:\n        port = int(server_match.group(1))\n\n    # Format 2: Look for standalone port numbers (H2 uses ports in 9000+ range typically)\n    if port is None:\n        port_match = re.search(r\"\\b(9\\d{3})\\b\", content)\n        if port_match:\n            port = int(port_match.group(1))\n\n    # Try to extract PID - H2 may embed this in various formats\n    pid_match = re.search(r\"pid[=:]?\\s*(\\d+)\", content, re.IGNORECASE)\n    if pid_match:\n        pid = int(pid_match.group(1))\n\n    # Check if the process is still alive\n    is_stale = False\n    if pid is not None:\n        is_stale = not is_metals_process_alive(pid)\n    elif port is not None:\n        # If we have a port but no PID, try to find a Metals process using that port\n        is_stale = not _is_port_in_use_by_metals(port)\n    else:\n        # Can't determine - assume stale if lock exists but we can't parse it\n        # and no Metals processes are running for this project\n        log.debug(f\"Could not parse PID or port from lock file: {lock_path}\")\n        is_stale = True  # Conservative: treat unparsable as stale\n\n    return MetalsLockInfo(\n        pid=pid,\n        port=port,\n        lock_path=lock_path,\n        is_stale=is_stale,\n        raw_content=content[:200],  # Truncate for logging\n    )\n\n\ndef is_metals_process_alive(pid: int) -> bool:\n    \"\"\"\n    Check if a process with the given PID is alive and is a Metals process.\n\n    Args:\n        pid: Process ID to check\n\n    Returns:\n        True if the process exists and appears to be a Metals LSP server.\n\n    \"\"\"\n    try:\n        import psutil\n\n        proc = psutil.Process(pid)\n        if not proc.is_running():\n            return False\n\n        # Check if this is actually a Metals process\n        cmdline = \" \".join(proc.cmdline()).lower()\n        return _is_metals_cmdline(cmdline)\n\n    except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):\n        return False\n    except Exception as e:\n        log.debug(f\"Error checking process {pid}: {e}\")\n        return False\n\n\ndef _is_metals_cmdline(cmdline: str) -> bool:\n    \"\"\"Check if a command line string appears to be a Metals LSP server.\"\"\"\n    cmdline_lower = cmdline.lower()\n    # Metals is a Scala/Java application\n    if \"java\" not in cmdline_lower:\n        return False\n    # Look for Metals-specific identifiers\n    return any(\n        marker in cmdline_lower\n        for marker in [\n            \"metals\",\n            \"org.scalameta\",\n            \"-dmetals.client\",\n        ]\n    )\n\n\ndef _is_port_in_use_by_metals(port: int) -> bool:\n    \"\"\"Check if the given port is in use by a Metals process.\"\"\"\n    try:\n        import psutil\n\n        for conn in psutil.net_connections(kind=\"tcp\"):\n            if conn.laddr.port == port and conn.status == \"LISTEN\":\n                try:\n                    proc = psutil.Process(conn.pid)\n                    cmdline = \" \".join(proc.cmdline()).lower()\n                    if _is_metals_cmdline(cmdline):\n                        return True\n                except (psutil.NoSuchProcess, psutil.AccessDenied):\n                    pass\n        return False\n    except (psutil.AccessDenied, OSError) as e:\n        # On some systems, net_connections requires elevated privileges\n        log.debug(f\"Could not check port {port}: {e}\")\n        return False\n\n\ndef check_metals_db_status(project_path: Path) -> tuple[MetalsDbStatus, MetalsLockInfo | None]:\n    \"\"\"\n    Check the status of the Metals H2 database for a project.\n\n    This function determines whether it's safe to start a new Metals instance\n    and whether any cleanup is needed.\n\n    Args:\n        project_path: Path to the project root directory\n\n    Returns:\n        A tuple of (status, lock_info) where lock_info is populated for\n        ACTIVE_INSTANCE and STALE_LOCK statuses.\n\n    \"\"\"\n    metals_dir = project_path / \".metals\"\n    db_path = metals_dir / \"metals.mv.db\"\n    lock_path = metals_dir / \"metals.mv.db.lock.db\"\n\n    if not metals_dir.exists():\n        log.debug(f\"No .metals directory found at {metals_dir}\")\n        return MetalsDbStatus.NO_DATABASE, None\n\n    if not db_path.exists():\n        log.debug(f\"No Metals database found at {db_path}\")\n        return MetalsDbStatus.NO_DATABASE, None\n\n    if not lock_path.exists():\n        log.debug(f\"Metals database exists but no lock file at {lock_path}\")\n        return MetalsDbStatus.NO_LOCK, None\n\n    # Lock file exists - parse it to determine status\n    lock_info = parse_h2_lock_file(lock_path)\n\n    if lock_info is None:\n        # Lock file exists but couldn't be read - treat as stale\n        log.warning(f\"Could not read lock file at {lock_path}, treating as stale\")\n        return MetalsDbStatus.STALE_LOCK, MetalsLockInfo(\n            pid=None,\n            port=None,\n            lock_path=lock_path,\n            is_stale=True,\n            raw_content=\"<unreadable>\",\n        )\n\n    if lock_info.is_stale:\n        log.debug(f\"Stale Metals lock detected: {lock_info}\")\n        return MetalsDbStatus.STALE_LOCK, lock_info\n    else:\n        log.debug(f\"Active Metals instance detected: {lock_info}\")\n        return MetalsDbStatus.ACTIVE_INSTANCE, lock_info\n\n\ndef cleanup_stale_lock(lock_path: Path) -> bool:\n    \"\"\"\n    Remove a stale H2 database lock file.\n\n    This should only be called when we've verified the owning process is dead.\n    Removing a lock file from a running process could cause database corruption.\n\n    Args:\n        lock_path: Path to the .lock.db file to remove\n\n    Returns:\n        True if cleanup succeeded, False otherwise.\n\n    \"\"\"\n    if not lock_path.exists():\n        log.debug(f\"Lock file already removed: {lock_path}\")\n        return True\n\n    try:\n        lock_path.unlink()\n        log.info(f\"Cleaned up stale Metals lock file: {lock_path}\")\n        return True\n    except PermissionError as e:\n        log.warning(f\"Permission denied removing stale lock file {lock_path}: {e}\")\n        return False\n    except OSError as e:\n        log.warning(f\"Could not remove stale lock file {lock_path}: {e}\")\n        return False\n"
  },
  {
    "path": "src/solidlsp/util/subprocess_util.py",
    "content": "import platform\nimport subprocess\n\n\ndef subprocess_kwargs() -> dict:\n    \"\"\"\n    Returns a dictionary of keyword arguments for subprocess calls, adding platform-specific\n    flags that we want to use consistently.\n    \"\"\"\n    kwargs = {}\n    if platform.system() == \"Windows\":\n        kwargs[\"creationflags\"] = subprocess.CREATE_NO_WINDOW  # type: ignore\n    return kwargs\n\n\ndef quote_arg(arg: str) -> str:\n    \"\"\"\n    Adds quotes around an argument if it contains spaces.\n    \"\"\"\n    if \" \" not in arg:\n        return arg\n    return f'\"{arg}\"'\n"
  },
  {
    "path": "src/solidlsp/util/zip.py",
    "content": "import fnmatch\nimport logging\nimport os\nimport sys\nimport zipfile\nfrom pathlib import Path\nfrom typing import Optional\n\nlog = logging.getLogger(__name__)\n\n\nclass SafeZipExtractor:\n    \"\"\"\n    A utility class for extracting ZIP archives safely.\n\n    Features:\n    - Handles long file paths on Windows\n    - Skips files that fail to extract, continuing with the rest\n    - Creates necessary directories automatically\n    - Optional include/exclude pattern filters\n    \"\"\"\n\n    def __init__(\n        self,\n        archive_path: Path,\n        extract_dir: Path,\n        verbose: bool = True,\n        include_patterns: Optional[list[str]] = None,\n        exclude_patterns: Optional[list[str]] = None,\n    ) -> None:\n        \"\"\"\n        Initialize the SafeZipExtractor.\n\n        :param archive_path: Path to the ZIP archive file\n        :param extract_dir: Directory where files will be extracted\n        :param verbose: Whether to log status messages\n        :param include_patterns: List of glob patterns for files to extract (None = all files)\n        :param exclude_patterns: List of glob patterns for files to skip\n        \"\"\"\n        self.archive_path = Path(archive_path)\n        self.extract_dir = Path(extract_dir)\n        self.verbose = verbose\n        self.include_patterns = include_patterns or []\n        self.exclude_patterns = exclude_patterns or []\n\n    def extract_all(self) -> None:\n        \"\"\"\n        Extract all files from the archive, skipping any that fail.\n        \"\"\"\n        if not self.archive_path.exists():\n            raise FileNotFoundError(f\"Archive not found: {self.archive_path}\")\n\n        if self.verbose:\n            log.info(f\"Extracting from: {self.archive_path} to {self.extract_dir}\")\n\n        with zipfile.ZipFile(self.archive_path, \"r\") as zip_ref:\n            for member in zip_ref.infolist():\n                if self._should_extract(member.filename):\n                    self._extract_member(zip_ref, member)\n                elif self.verbose:\n                    log.info(f\"Skipped: {member.filename}\")\n\n    def _should_extract(self, filename: str) -> bool:\n        \"\"\"\n        Determine whether a file should be extracted based on include/exclude patterns.\n\n        :param filename: The file name from the archive\n        :return: True if the file should be extracted\n        \"\"\"\n        # If include_patterns is set, only extract if it matches at least one pattern\n        if self.include_patterns:\n            if not any(fnmatch.fnmatch(filename, pattern) for pattern in self.include_patterns):\n                return False\n\n        # If exclude_patterns is set, skip if it matches any pattern\n        if self.exclude_patterns:\n            if any(fnmatch.fnmatch(filename, pattern) for pattern in self.exclude_patterns):\n                return False\n\n        return True\n\n    def _extract_member(self, zip_ref: zipfile.ZipFile, member: zipfile.ZipInfo) -> None:\n        \"\"\"\n        Extract a single member from the archive with error handling.\n\n        :param zip_ref: Open ZipFile object\n        :param member: ZipInfo object representing the file\n        \"\"\"\n        try:\n            target_path = self.extract_dir / member.filename\n\n            # Ensure directory structure exists\n            target_path.parent.mkdir(parents=True, exist_ok=True)\n\n            # Handle long paths on Windows\n            final_path = self._normalize_path(target_path)\n\n            # Extract file\n            with zip_ref.open(member) as source, open(final_path, \"wb\") as target:\n                target.write(source.read())\n\n            if self.verbose:\n                log.info(f\"Extracted: {member.filename}\")\n\n        except Exception as e:\n            log.error(f\"Failed to extract {member.filename}: {e}\")\n\n    @staticmethod\n    def _normalize_path(path: Path) -> Path:\n        \"\"\"\n        Adjust path to handle long paths on Windows.\n\n        :param path: Original path\n        :return: Normalized path\n        \"\"\"\n        if sys.platform.startswith(\"win\"):\n            return Path(rf\"\\\\?\\{os.path.abspath(path)}\")\n        return path  # type: ignore\n\n\n# Example usage:\n# extractor = SafeZipExtractor(\n#     archive_path=Path(\"file.nupkg\"),\n#     extract_dir=Path(\"extract_dir\"),\n#     include_patterns=[\"*.dll\", \"*.xml\"],\n#     exclude_patterns=[\"*.pdb\"]\n# )\n# extractor.extract_all()\n"
  },
  {
    "path": "sync.py",
    "content": "import os\nfrom repo_dir_sync import LibRepo, OtherRepo\n\nr = LibRepo(name=\"serena\", libDirectory=\"src\")\nr.add(OtherRepo(name=\"mux\", branch=\"mux\", pathToLib=os.path.join(\"..\", \"serena-multiplexer\", \"src-serena\")))\nr.runMain()\n"
  },
  {
    "path": "test/__init__.py",
    "content": "\n"
  },
  {
    "path": "test/conftest.py",
    "content": "import logging\nimport os\nimport platform\nimport shutil as _sh\nfrom collections.abc import Iterator\nfrom contextlib import contextmanager\nfrom pathlib import Path\nfrom typing import Any\n\nimport pytest\nfrom sensai.util.logging import configure\n\nfrom serena.config.serena_config import SerenaConfig, SerenaPaths\nfrom serena.constants import SERENA_MANAGED_DIR_NAME\nfrom serena.project import Project\nfrom serena.util.file_system import GitignoreParser\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import Language, LanguageServerConfig\nfrom solidlsp.settings import SolidLSPSettings\n\nfrom .solidlsp.clojure import is_clojure_cli_available\n\nconfigure(level=logging.INFO)\n\nlog = logging.getLogger(__name__)\n\n\n@pytest.fixture(scope=\"session\")\ndef resources_dir() -> Path:\n    \"\"\"Path to the test resources directory.\"\"\"\n    current_dir = Path(__file__).parent\n    return current_dir / \"resources\"\n\n\nclass LanguageParamRequest:\n    param: Language\n\n\n_LANGUAGE_REPO_ALIASES: dict[Language, Language] = {\n    Language.CPP_CCLS: Language.CPP,\n    Language.PHP_PHPACTOR: Language.PHP,\n    Language.PYTHON_JEDI: Language.PYTHON,\n    Language.RUBY_SOLARGRAPH: Language.RUBY,\n}\n\n\ndef get_repo_path(language: Language) -> Path:\n    repo_language = _LANGUAGE_REPO_ALIASES.get(language, language)\n    return Path(__file__).parent / \"resources\" / \"repos\" / repo_language / \"test_repo\"\n\n\ndef _create_ls(\n    language: Language,\n    repo_path: str | None = None,\n    ignored_paths: list[str] | None = None,\n    trace_lsp_communication: bool = False,\n    ls_specific_settings: dict[Language, dict[str, Any]] | None = None,\n    solidlsp_dir: Path | None = None,\n) -> SolidLanguageServer:\n    ignored_paths = ignored_paths or []\n    if repo_path is None:\n        repo_path = str(get_repo_path(language))\n    gitignore_parser = GitignoreParser(str(repo_path))\n    for spec in gitignore_parser.get_ignore_specs():\n        ignored_paths.extend(spec.patterns)\n    config = LanguageServerConfig(\n        code_language=language,\n        ignored_paths=ignored_paths,\n        trace_lsp_communication=trace_lsp_communication,\n    )\n    effective_solidlsp_dir = solidlsp_dir if solidlsp_dir is not None else SerenaPaths().serena_user_home_dir\n    project_data_path = os.path.join(repo_path, SERENA_MANAGED_DIR_NAME)\n    return SolidLanguageServer.create(\n        config,\n        repo_path,\n        solidlsp_settings=SolidLSPSettings(\n            solidlsp_dir=effective_solidlsp_dir,\n            project_data_path=project_data_path,\n            ls_specific_settings=ls_specific_settings or {},\n        ),\n    )\n\n\n@contextmanager\ndef start_ls_context(\n    language: Language,\n    repo_path: str | None = None,\n    ignored_paths: list[str] | None = None,\n    trace_lsp_communication: bool = False,\n    ls_specific_settings: dict[Language, dict[str, Any]] | None = None,\n    solidlsp_dir: Path | None = None,\n) -> Iterator[SolidLanguageServer]:\n    ls = _create_ls(language, repo_path, ignored_paths, trace_lsp_communication, ls_specific_settings, solidlsp_dir)\n    log.info(f\"Starting language server for {language} {repo_path}\")\n    ls.start()\n    try:\n        log.info(f\"Language server started for {language} {repo_path}\")\n        yield ls\n    finally:\n        log.info(f\"Stopping language server for {language} {repo_path}\")\n        try:\n            ls.stop(shutdown_timeout=5)\n        except Exception as e:\n            log.warning(f\"Warning: Error stopping language server: {e}\")\n            # try to force cleanup\n            if hasattr(ls, \"server\") and hasattr(ls.server, \"process\"):\n                try:\n                    ls.server.process.terminate()\n                except:\n                    pass\n\n\n@contextmanager\ndef start_default_ls_context(language: Language) -> Iterator[SolidLanguageServer]:\n    with start_ls_context(language) as ls:\n        yield ls\n\n\ndef create_default_serena_config():\n    return SerenaConfig(gui_log_window=False, web_dashboard=False)\n\n\ndef _create_default_project(language: Language, repo_root_override: str | None = None) -> Project:\n    repo_path = str(get_repo_path(language)) if repo_root_override is None else repo_root_override\n    return Project.load(repo_path, serena_config=create_default_serena_config())\n\n\n@pytest.fixture(scope=\"session\")\ndef repo_path(request: LanguageParamRequest) -> Path:\n    \"\"\"Get the repository path for a specific language.\n\n    This fixture requires a language parameter via pytest.mark.parametrize:\n\n    Example:\n    ```\n    @pytest.mark.parametrize(\"repo_path\", [Language.PYTHON], indirect=True)\n    def test_python_repo(repo_path):\n        assert (repo_path / \"src\").exists()\n    ```\n\n    \"\"\"\n    if not hasattr(request, \"param\"):\n        raise ValueError(\"Language parameter must be provided via pytest.mark.parametrize\")\n\n    language = request.param\n    return get_repo_path(language)\n\n\n# Note: using module scope here to avoid restarting LS for each test function but still terminate between test modules\n@pytest.fixture(scope=\"module\")\ndef language_server(request: LanguageParamRequest):\n    \"\"\"Create a language server instance configured for the specified language.\n\n    This fixture requires a language parameter via pytest.mark.parametrize:\n\n    Example:\n    ```\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_python_server(language_server: SyncLanguageServer) -> None:\n        # Use the Python language server\n        pass\n    ```\n\n    You can also test multiple languages in a single test:\n    ```\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON, Language.TYPESCRIPT], indirect=True)\n    def test_multiple_languages(language_server: SyncLanguageServer) -> None:\n        # This test will run once for each language\n        pass\n    ```\n\n    \"\"\"\n    if not hasattr(request, \"param\"):\n        raise ValueError(\"Language parameter must be provided via pytest.mark.parametrize\")\n\n    language = request.param\n    with start_default_ls_context(language) as ls:\n        yield ls\n\n\n@contextmanager\ndef project_context(language: Language, repo_root_override: str | None = None) -> Iterator[Project]:\n    \"\"\"Context manager that creates a Project for the specified language and ensures proper cleanup.\"\"\"\n    project = _create_default_project(language, repo_root_override)\n    try:\n        yield project\n    finally:\n        project.shutdown(timeout=5)\n\n\n@pytest.fixture(scope=\"module\")\ndef project(request: LanguageParamRequest, repo_root_override: str | None = None) -> Iterator[Project]:\n    \"\"\"Create a Project for the specified language.\n\n    This fixture requires a language parameter via pytest.mark.parametrize:\n\n    Example:\n    ```\n    @pytest.mark.parametrize(\"project\", [Language.PYTHON], indirect=True)\n    def test_python_project(project: Project) -> None:\n        # Use the Python project to test something\n        pass\n    ```\n\n    You can also test multiple languages in a single test:\n    ```\n    @pytest.mark.parametrize(\"project\", [Language.PYTHON, Language.TYPESCRIPT], indirect=True)\n    def test_multiple_languages(project: SyncLanguageServer) -> None:\n        # This test will run once for each language\n        pass\n    ```\n\n    \"\"\"\n    if not hasattr(request, \"param\"):\n        raise ValueError(\"Language parameter must be provided via pytest.mark.parametrize\")\n    language = request.param\n    with project_context(language, repo_root_override) as project:\n        yield project\n\n\n@contextmanager\ndef project_with_ls_context(language: Language, repo_root_override: str | None = None) -> Iterator[Project]:\n    \"\"\"Context manager that creates a Project with an active language server for the specified language.\"\"\"\n    with project_context(language, repo_root_override) as project:\n        project.create_language_server_manager()\n        yield project\n\n\n@pytest.fixture(scope=\"module\")\ndef project_with_ls(request: LanguageParamRequest) -> Iterator[Project]:\n    if not hasattr(request, \"param\"):\n        raise ValueError(\"Language parameter must be provided via pytest.mark.parametrize\")\n    language = request.param\n    with project_with_ls_context(language) as project:\n        yield project\n\n\nis_ci = os.getenv(\"CI\") == \"true\" or os.getenv(\"GITHUB_ACTIONS\") == \"true\"\n\"\"\"\nFlag indicating whether the tests are running in the GitHub CI environment.\n\"\"\"\n\nis_windows = platform.system() == \"Windows\"\n\n\ndef _determine_disabled_languages() -> list[Language]:\n    \"\"\"\n    Determine which language tests should be disabled (based on the environment)\n\n    :return: the list of disabled languages\n    \"\"\"\n    result: list[Language] = []\n\n    java_tests_enabled = True\n    if not java_tests_enabled:\n        result.append(Language.JAVA)\n\n    clojure_tests_enabled = is_clojure_cli_available()\n    if not clojure_tests_enabled:\n        result.append(Language.CLOJURE)\n\n    # Disable CPP_CCLS tests if ccls is not available\n    ccls_tests_enabled = _sh.which(\"ccls\") is not None\n    if not ccls_tests_enabled:\n        result.append(Language.CPP_CCLS)\n\n    # Disable CPP (clangd) tests if clangd is not available\n    clangd_tests_enabled = _sh.which(\"clangd\") is not None\n    if not clangd_tests_enabled:\n        result.append(Language.CPP)\n\n    # Disable PHP_PHPACTOR tests if php is not available\n    php_tests_enabled = _sh.which(\"php\") is not None\n    if not php_tests_enabled:\n        result.append(Language.PHP_PHPACTOR)\n\n    al_tests_enabled = True\n    if not al_tests_enabled:\n        result.append(Language.AL)\n\n    return result\n\n\n_disabled_languages = _determine_disabled_languages()\n\n\ndef language_tests_enabled(language: Language) -> bool:\n    \"\"\"\n    Check if tests for the given language are enabled in the current environment.\n\n    :param language: the language to check\n    :return: True if tests for the language are enabled, False otherwise\n    \"\"\"\n    return language not in _disabled_languages\n"
  },
  {
    "path": "test/resources/repos/al/test_repo/app.json",
    "content": "{\n  \"id\": \"00000001-0000-0000-0000-000000000001\",\n  \"name\": \"Test AL Project\",\n  \"publisher\": \"Serena Test Publisher\",\n  \"version\": \"1.0.0.0\",\n  \"brief\": \"Test project for AL Language Server in Serena\",\n  \"description\": \"This project contains AL code samples for testing language server features\",\n  \"privacyStatement\": \"\",\n  \"EULA\": \"\",\n  \"help\": \"\",\n  \"url\": \"https://github.com/oraios/serena\",\n  \"logo\": \"\",\n  \"dependencies\": [],\n  \"screenshots\": [],\n  \"platform\": \"1.0.0.0\",\n  \"application\": \"26.0.0.0\",\n  \"idRanges\": [\n    {\n      \"from\": 50000,\n      \"to\": 50100\n    }\n  ],\n  \"resourceExposurePolicy\": {\n    \"allowDebugging\": true,\n    \"allowDownloadingSource\": true,\n    \"includeSourceInSymbolFile\": true\n  },\n  \"runtime\": \"15.0\",\n  \"features\": [\"NoImplicitWith\"],\n  \"target\": \"Cloud\"\n}"
  },
  {
    "path": "test/resources/repos/al/test_repo/src/Codeunits/CustomerMgt.Codeunit.al",
    "content": "codeunit 50000 CustomerMgt\n{\n    Permissions = tabledata \"TEST Customer\" = rimd;\n\n    trigger OnRun()\n    begin\n        Message('Customer Management Codeunit');\n    end;\n\n    procedure CreateNewCustomer()\n    var\n        Customer: Record \"TEST Customer\";\n        CustomerCard: Page \"TEST Customer Card\";\n    begin\n        Customer.Init();\n        Customer.Insert(true);\n\n        CustomerCard.SetRecord(Customer);\n        CustomerCard.Run();\n    end;\n\n    procedure CreateCustomer(CustomerNo: Code[20]; CustomerName: Text[100]; CustomerType: Enum CustomerType): Boolean\n    var\n        Customer: Record \"TEST Customer\";\n    begin\n        if Customer.Get(CustomerNo) then\n            exit(false);\n\n        Customer.Init();\n        Customer.\"No.\" := CustomerNo;\n        Customer.Name := CustomerName;\n        Customer.\"Customer Type\" := CustomerType;\n        Customer.UpdateSearchName();\n        Customer.Insert(true);\n\n        exit(true);\n    end;\n\n    procedure AssistEdit(var Customer: Record \"TEST Customer\"): Boolean\n    var\n        NoSeriesMgt: Codeunit NoSeriesManagement;\n    begin\n        with Customer do begin\n            if NoSeriesMgt.SelectSeries(GetNoSeriesCode(), '', \"No. Series\") then begin\n                NoSeriesMgt.SetSeries(\"No.\");\n                exit(true);\n            end;\n        end;\n        exit(false);\n    end;\n\n    procedure TestNoSeries()\n    var\n        SalesSetup: Record \"Sales & Receivables Setup\";\n    begin\n        SalesSetup.Get();\n        SalesSetup.TestField(\"Customer Nos.\");\n    end;\n\n    procedure InitNo(var Customer: Record \"TEST Customer\")\n    var\n        NoSeriesMgt: Codeunit NoSeriesManagement;\n    begin\n        TestNoSeries();\n        NoSeriesMgt.InitSeries(GetNoSeriesCode(), Customer.\"No. Series\", 0D, Customer.\"No.\", Customer.\"No. Series\");\n    end;\n\n    procedure GetNoSeriesCode(): Code[20]\n    var\n        SalesSetup: Record \"Sales & Receivables Setup\";\n    begin\n        SalesSetup.Get();\n        exit(SalesSetup.\"Customer Nos.\");\n    end;\n\n    procedure CalculateTotalBalance(): Decimal\n    var\n        Customer: Record \"TEST Customer\";\n        TotalBalance: Decimal;\n    begin\n        TotalBalance := 0;\n\n        if Customer.FindSet() then\n            repeat\n                Customer.CalcFields(Balance);\n                TotalBalance += Customer.Balance;\n            until Customer.Next() = 0;\n\n        exit(TotalBalance);\n    end;\n\n    procedure GetCustomerCount(CustomerType: Enum CustomerType): Integer\n    var\n        Customer: Record \"TEST Customer\";\n    begin\n        Customer.SetRange(\"Customer Type\", CustomerType);\n        exit(Customer.Count());\n    end;\n\n    procedure BlockCustomersOverCreditLimit()\n    var\n        Customer: Record \"TEST Customer\";\n        BlockedCount: Integer;\n    begin\n        BlockedCount := 0;\n\n        if Customer.FindSet() then\n            repeat\n                Customer.CalcFields(Balance);\n                if (Customer.\"Credit Limit\" > 0) and (Customer.Balance > Customer.\"Credit Limit\") then begin\n                    Customer.Blocked := true;\n                    Customer.Modify(true);\n                    BlockedCount += 1;\n                end;\n            until Customer.Next() = 0;\n\n        if BlockedCount > 0 then\n            Message('%1 customers blocked due to credit limit exceeded', BlockedCount);\n    end;\n\n    procedure GetPaymentProcessor(): Interface IPaymentProcessor\n    var\n        PaymentProcessorImpl: Codeunit PaymentProcessorImpl;\n    begin\n        exit(PaymentProcessorImpl);\n    end;\n\n    procedure SendCustomerStatement(CustomerNo: Code[20])\n    var\n        Customer: Record \"TEST Customer\";\n        ReportSelections: Record \"Report Selections\";\n    begin\n        if not Customer.Get(CustomerNo) then\n            Error('Customer %1 not found', CustomerNo);\n\n        Customer.SetRecFilter();\n        ReportSelections.SetRange(Usage, ReportSelections.Usage::\"C.Statement\");\n        ReportSelections.PrintForCust(ReportSelections.Usage::\"C.Statement\", Customer, 1);\n    end;\n\n    procedure ValidateEmail(Email: Text[80]): Boolean\n    var\n        MailMgt: Codeunit \"Mail Management\";\n    begin\n        exit(MailMgt.CheckValidEmailAddress(Email));\n    end;\n\n    procedure MergeCustomers(FromCustomerNo: Code[20]; ToCustomerNo: Code[20])\n    var\n        FromCustomer: Record \"TEST Customer\";\n        ToCustomer: Record \"TEST Customer\";\n        CustomerLedgerEntry: Record \"Cust. Ledger Entry\";\n    begin\n        if not FromCustomer.Get(FromCustomerNo) then\n            Error('Source customer %1 not found', FromCustomerNo);\n\n        if not ToCustomer.Get(ToCustomerNo) then\n            Error('Target customer %1 not found', ToCustomerNo);\n\n        // Transfer ledger entries\n        CustomerLedgerEntry.SetRange(\"Customer No.\", FromCustomerNo);\n        if CustomerLedgerEntry.FindSet() then\n            repeat\n                CustomerLedgerEntry.\"Customer No.\" := ToCustomerNo;\n                CustomerLedgerEntry.Modify();\n            until CustomerLedgerEntry.Next() = 0;\n\n        // Delete source customer\n        FromCustomer.Delete(true);\n\n        Message('Customer %1 merged into %2', FromCustomerNo, ToCustomerNo);\n    end;\n\n    [EventSubscriber(ObjectType::Table, Database::\"TEST Customer\", OnAfterInsertEvent, '', true, true)]\n    local procedure OnAfterInsertCustomer(var Rec: Record \"TEST Customer\")\n    begin\n        LogCustomerChange(Rec, 'INSERT');\n    end;\n\n    [EventSubscriber(ObjectType::Table, Database::\"TEST Customer\", OnAfterModifyEvent, '', true, true)]\n    local procedure OnAfterModifyCustomer(var Rec: Record \"TEST Customer\")\n    begin\n        LogCustomerChange(Rec, 'MODIFY');\n    end;\n\n    local procedure LogCustomerChange(Customer: Record \"TEST Customer\"; ChangeType: Text[10])\n    var\n        ChangeLogEntry: Record \"Change Log Entry\";\n    begin\n        // Log customer changes for audit purposes\n        ChangeLogEntry.Init();\n        ChangeLogEntry.\"Table No.\" := Database::\"TEST Customer\";\n        ChangeLogEntry.\"Primary Key Field 1 Value\" := Customer.\"No.\";\n        ChangeLogEntry.\"Type of Change\" := ChangeLogEntry.\"Type of Change\"::Modification;\n        ChangeLogEntry.\"User ID\" := UserId;\n        ChangeLogEntry.\"Date and Time\" := CurrentDateTime;\n        if ChangeLogEntry.Insert() then;\n    end;\n}"
  },
  {
    "path": "test/resources/repos/al/test_repo/src/Codeunits/PaymentProcessorImpl.Codeunit.al",
    "content": "codeunit 50001 PaymentProcessorImpl implements IPaymentProcessor\n{\n    procedure ProcessPayment(Customer: Record \"TEST Customer\"): Boolean\n    var\n    //PaymentEntry: Record \"Payment Entry\";\n    begin\n        // Implementation of payment processing\n        Customer.CalcFields(Balance);\n\n        if Customer.Balance <= 0 then\n            exit(false);\n\n        // PaymentEntry.Init();\n        // PaymentEntry.\"Customer No.\" := Customer.\"No.\";\n        // PaymentEntry.Amount := Customer.Balance;\n        // PaymentEntry.\"Payment Date\" := Today();\n        // PaymentEntry.Status := PaymentEntry.Status::Processed;\n\n        // if PaymentEntry.Insert(true) then begin\n        //     Message('Payment processed for customer %1', Customer.Name);\n        //     exit(true);\n        // end;\n\n        exit(false);\n    end;\n\n    procedure ValidatePaymentMethod(PaymentMethodCode: Code[10]): Boolean\n    var\n        PaymentMethod: Record \"Payment Method\";\n    begin\n        if PaymentMethodCode = '' then\n            exit(false);\n\n        exit(PaymentMethod.Get(PaymentMethodCode));\n    end;\n\n    procedure GetTransactionFee(Amount: Decimal): Decimal\n    var\n        FeePercentage: Decimal;\n        MinimumFee: Decimal;\n    begin\n        FeePercentage := 2.9; // 2.9% transaction fee\n        MinimumFee := 0.30; // Minimum fee\n\n        exit(Maximum(Amount * FeePercentage / 100, MinimumFee));\n    end;\n\n    procedure RefundPayment(TransactionID: Text[50]): Boolean\n    var\n    // PaymentEntry: Record \"Payment Entry\";\n    begin\n        // PaymentEntry.SetRange(\"Transaction ID\", TransactionID);\n\n        // if PaymentEntry.FindFirst() then begin\n        //     PaymentEntry.Status := PaymentEntry.Status::Refunded;\n        //     PaymentEntry.\"Refund Date\" := Today();\n        //     PaymentEntry.Modify(true);\n\n        //     Message('Payment refunded for transaction %1', TransactionID);\n        //     exit(true);\n        // end;\n\n        Error('Transaction %1 not found', TransactionID);\n    end;\n\n    local procedure Maximum(Value1: Decimal; Value2: Decimal): Decimal\n    begin\n        if Value1 > Value2 then\n            exit(Value1)\n        else\n            exit(Value2);\n    end;\n}"
  },
  {
    "path": "test/resources/repos/al/test_repo/src/Enums/CustomerType.Enum.al",
    "content": "enum 50000 CustomerType\n{\n    Extensible = true;\n    Caption = 'Customer Type';\n    \n    value(0; \"\")\n    {\n        Caption = '';\n    }\n    \n    value(1; Regular)\n    {\n        Caption = 'Regular';\n    }\n    \n    value(2; Premium)\n    {\n        Caption = 'Premium';\n    }\n    \n    value(3; VIP)\n    {\n        Caption = 'VIP';\n    }\n    \n    value(4; Corporate)\n    {\n        Caption = 'Corporate';\n    }\n    \n    value(5; Government)\n    {\n        Caption = 'Government';\n    }\n}"
  },
  {
    "path": "test/resources/repos/al/test_repo/src/Interfaces/IPaymentProcessor.Interface.al",
    "content": "interface IPaymentProcessor\n{\n    procedure ProcessPayment(Customer: Record \"TEST Customer\"): Boolean;\n    procedure ValidatePaymentMethod(PaymentMethodCode: Code[10]): Boolean;\n    procedure GetTransactionFee(Amount: Decimal): Decimal;\n    procedure RefundPayment(TransactionID: Text[50]): Boolean;\n}"
  },
  {
    "path": "test/resources/repos/al/test_repo/src/Pages/CustomerCard.Page.al",
    "content": "page 50001 \"TEST Customer Card\"\n{\n    Caption = 'Customer Card';\n    PageType = Card;\n    SourceTable = \"TEST Customer\";\n    RefreshOnActivate = true;\n\n    layout\n    {\n        area(Content)\n        {\n            group(General)\n            {\n                Caption = 'General';\n\n                field(\"No.\"; Rec.\"No.\")\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the customer number.';\n\n                    trigger OnAssistEdit()\n                    begin\n                        if CustomerMgt.AssistEdit(Rec) then\n                            CurrPage.Update();\n                    end;\n                }\n\n                field(Name; Rec.Name)\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the customer name.';\n                    ShowMandatory = true;\n                }\n\n                field(\"Search Name\"; Rec.\"Search Name\")\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the search name.';\n                    Visible = false;\n                }\n\n                field(\"Customer Type\"; Rec.\"Customer Type\")\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the type of customer.';\n                }\n\n                field(Blocked; Rec.Blocked)\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies if the customer is blocked.';\n                }\n\n                field(\"Last Date Modified\"; Rec.\"Last Date Modified\")\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies when the customer was last modified.';\n                    Editable = false;\n                }\n            }\n\n            group(AddressAndContact)\n            {\n                Caption = 'Address & Contact';\n\n                field(Address; Rec.Address)\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the customer address.';\n                }\n\n                field(\"Address 2\"; Rec.\"Address 2\")\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies additional address information.';\n                }\n\n                field(City; Rec.City)\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the city.';\n                }\n\n                field(\"Phone No.\"; Rec.\"Phone No.\")\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the phone number.';\n                }\n\n                field(\"E-Mail\"; Rec.\"E-Mail\")\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the email address.';\n                    ExtendedDatatype = EMail;\n                }\n            }\n\n            group(Invoicing)\n            {\n                Caption = 'Invoicing';\n\n                field(\"Credit Limit\"; Rec.\"Credit Limit\")\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the credit limit.';\n                }\n\n                field(Balance; Rec.Balance)\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the customer balance.';\n                    DrillDownPageId = \"Customer Ledger Entries\";\n                }\n\n                field(\"Payment Terms Code\"; Rec.\"Payment Terms Code\")\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the payment terms.';\n                }\n\n                field(\"Currency Code\"; Rec.\"Currency Code\")\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the currency code.';\n                }\n            }\n        }\n\n        area(FactBoxes)\n        {\n            part(CustomerPicture; \"Customer Picture\")\n            {\n                ApplicationArea = All;\n                SubPageLink = \"No.\" = field(\"No.\");\n            }\n\n            systempart(Links; Links)\n            {\n                ApplicationArea = RecordLinks;\n            }\n\n            systempart(Notes; Notes)\n            {\n                ApplicationArea = Notes;\n            }\n        }\n    }\n\n    actions\n    {\n        area(Navigation)\n        {\n            group(Customer)\n            {\n                Caption = '&Customer';\n\n                action(LedgerEntries)\n                {\n                    ApplicationArea = All;\n                    Caption = 'Ledger E&ntries';\n                    Image = CustomerLedger;\n                    RunObject = page \"Customer Ledger Entries\";\n                    RunPageLink = \"Customer No.\" = field(\"No.\");\n                    RunPageView = sorting(\"Customer No.\");\n                    ShortcutKey = 'Ctrl+F7';\n                    ToolTip = 'View the history of transactions for the customer.';\n                }\n\n                action(Statistics)\n                {\n                    ApplicationArea = All;\n                    Caption = 'Statistics';\n                    Image = Statistics;\n                    RunObject = page \"Customer Statistics\";\n                    RunPageLink = \"No.\" = field(\"No.\");\n                    ShortcutKey = 'F7';\n                    ToolTip = 'View statistical information about the customer.';\n                }\n            }\n        }\n\n        area(Processing)\n        {\n            group(Functions)\n            {\n                Caption = 'F&unctions';\n\n                action(CheckCreditLimit)\n                {\n                    ApplicationArea = All;\n                    Caption = 'Check Credit Limit';\n                    Image = Check;\n                    ToolTip = 'Check if the customer has exceeded their credit limit.';\n\n                    trigger OnAction()\n                    begin\n                        Rec.CheckCreditLimit();\n                    end;\n                }\n\n                action(ProcessPayment)\n                {\n                    ApplicationArea = All;\n                    Caption = 'Process Payment';\n                    Image = Payment;\n                    ToolTip = 'Process a payment for this customer.';\n\n                    trigger OnAction()\n                    var\n                        PaymentProcessor: Interface IPaymentProcessor;\n                    begin\n                        PaymentProcessor := CustomerMgt.GetPaymentProcessor();\n                        PaymentProcessor.ProcessPayment(Rec);\n                    end;\n                }\n            }\n        }\n\n        area(Promoted)\n        {\n            group(Category_Process)\n            {\n                Caption = 'Process';\n\n                actionref(CheckCreditLimit_Promoted; CheckCreditLimit)\n                {\n                }\n\n                actionref(ProcessPayment_Promoted; ProcessPayment)\n                {\n                }\n            }\n\n            group(Category_Customer)\n            {\n                Caption = 'Customer';\n\n                actionref(Statistics_Promoted; Statistics)\n                {\n                }\n\n                actionref(LedgerEntries_Promoted; LedgerEntries)\n                {\n                }\n            }\n        }\n    }\n\n    var\n        CustomerMgt: Codeunit CustomerMgt;\n\n    trigger OnOpenPage()\n    begin\n        Rec.SetRange(\"Customer Type\");\n    end;\n\n    trigger OnAfterGetRecord()\n    begin\n        CheckCreditStatus();\n    end;\n\n    local procedure CheckCreditStatus()\n    begin\n        if Rec.\"Credit Limit\" = 0 then\n            exit;\n\n        Rec.CalcFields(Balance);\n        if Rec.Balance > Rec.\"Credit Limit\" then\n            Message('Warning: Customer has exceeded credit limit');\n    end;\n}"
  },
  {
    "path": "test/resources/repos/al/test_repo/src/Pages/CustomerList.Page.al",
    "content": "page 50002 \"TEST Customer List\"\n{\n    Caption = 'Customer List';\n    PageType = List;\n    ApplicationArea = All;\n    UsageCategory = Lists;\n    SourceTable = \"TEST Customer\";\n    CardPageId = \"TEST Customer Card\";\n    Editable = false;\n\n    layout\n    {\n        area(Content)\n        {\n            repeater(Group)\n            {\n                field(\"No.\"; Rec.\"No.\")\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the customer number.';\n                }\n\n                field(Name; Rec.Name)\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the customer name.';\n                }\n\n                field(City; Rec.City)\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the city.';\n                }\n\n                field(\"Customer Type\"; Rec.\"Customer Type\")\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the type of customer.';\n                }\n\n                field(\"Phone No.\"; Rec.\"Phone No.\")\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the phone number.';\n                }\n\n                field(\"E-Mail\"; Rec.\"E-Mail\")\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the email address.';\n                }\n\n                field(Balance; Rec.Balance)\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the customer balance.';\n                    StyleExpr = BalanceStyleExpr;\n                }\n\n                field(\"Credit Limit\"; Rec.\"Credit Limit\")\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies the credit limit.';\n                }\n\n                field(Blocked; Rec.Blocked)\n                {\n                    ApplicationArea = All;\n                    ToolTip = 'Specifies if the customer is blocked.';\n                }\n            }\n        }\n\n        area(FactBoxes)\n        {\n            systempart(Links; Links)\n            {\n                ApplicationArea = RecordLinks;\n            }\n\n            systempart(Notes; Notes)\n            {\n                ApplicationArea = Notes;\n            }\n        }\n    }\n\n    actions\n    {\n        area(Processing)\n        {\n            action(NewCustomer)\n            {\n                ApplicationArea = All;\n                Caption = 'New';\n                Image = NewCustomer;\n                ToolTip = 'Create a new customer.';\n\n                trigger OnAction()\n                begin\n                    CustomerMgt.CreateNewCustomer();\n                end;\n            }\n\n            action(ExportToExcel)\n            {\n                ApplicationArea = All;\n                Caption = 'Export to Excel';\n                Image = ExportToExcel;\n                ToolTip = 'Export the customer list to Excel.';\n\n                trigger OnAction()\n                begin\n                    ExportCustomersToExcel();\n                end;\n            }\n        }\n\n        area(Navigation)\n        {\n            action(ViewStatistics)\n            {\n                ApplicationArea = All;\n                Caption = 'Statistics';\n                Image = Statistics;\n                RunObject = page \"Customer Statistics\";\n                RunPageLink = \"No.\" = field(\"No.\");\n                ToolTip = 'View customer statistics.';\n            }\n        }\n\n        area(Promoted)\n        {\n            group(Category_New)\n            {\n                Caption = 'New';\n\n                actionref(NewCustomer_Promoted; NewCustomer)\n                {\n                }\n            }\n\n            group(Category_Process)\n            {\n                Caption = 'Process';\n\n                actionref(ExportToExcel_Promoted; ExportToExcel)\n                {\n                }\n            }\n        }\n    }\n\n    trigger OnAfterGetRecord()\n    begin\n        SetBalanceStyle();\n    end;\n\n    var\n        CustomerMgt: Codeunit CustomerMgt;\n        BalanceStyleExpr: Text;\n\n    local procedure SetBalanceStyle()\n    begin\n        BalanceStyleExpr := '';\n\n        Rec.CalcFields(Balance);\n        if (Rec.\"Credit Limit\" <> 0) and (Rec.Balance > Rec.\"Credit Limit\") then\n            BalanceStyleExpr := 'Unfavorable';\n    end;\n\n    local procedure ExportCustomersToExcel()\n    var\n        ExcelBuffer: Record \"Excel Buffer\" temporary;\n        RowNo: Integer;\n    begin\n        ExcelBuffer.Reset();\n        ExcelBuffer.DeleteAll();\n\n        // Add headers\n        RowNo := 1;\n        ExcelBuffer.AddColumn('Customer No.', false, '', false, false, false, '', ExcelBuffer.\"Cell Type\"::Text);\n        ExcelBuffer.AddColumn('Name', false, '', false, false, false, '', ExcelBuffer.\"Cell Type\"::Text);\n        ExcelBuffer.AddColumn('City', false, '', false, false, false, '', ExcelBuffer.\"Cell Type\"::Text);\n        ExcelBuffer.AddColumn('Balance', false, '', false, false, false, '', ExcelBuffer.\"Cell Type\"::Number);\n        ExcelBuffer.NewRow();\n\n        // Add data\n        if rec.FindSet() then\n            repeat\n                RowNo += 1;\n                rec.CalcFields(Balance);\n                ExcelBuffer.AddColumn(rec.\"No.\", false, '', false, false, false, '', ExcelBuffer.\"Cell Type\"::Text);\n                ExcelBuffer.AddColumn(rec.Name, false, '', false, false, false, '', ExcelBuffer.\"Cell Type\"::Text);\n                ExcelBuffer.AddColumn(rec.City, false, '', false, false, false, '', ExcelBuffer.\"Cell Type\"::Text);\n                ExcelBuffer.AddColumn(rec.Balance, false, '', false, false, false, '', ExcelBuffer.\"Cell Type\"::Number);\n                ExcelBuffer.NewRow();\n            until rec.Next() = 0;\n\n        ExcelBuffer.CreateNewBook('Customers');\n        ExcelBuffer.WriteSheet('Customer List', CompanyName, UserId);\n        ExcelBuffer.CloseBook();\n        ExcelBuffer.OpenExcel();\n    end;\n}"
  },
  {
    "path": "test/resources/repos/al/test_repo/src/TableExtensions/Item.TableExt.al",
    "content": "tableextension 50000 ItemExt extends Item\n{\n    fields\n    {\n        field(50000; \"Customer No.\"; Code[20])\n        {\n            Caption = 'Preferred Customer No.';\n            DataClassification = CustomerContent;\n            TableRelation = \"TEST Customer\";\n\n            trigger OnValidate()\n            var\n                Customer: Record \"TEST Customer\";\n            begin\n                if \"Customer No.\" <> '' then begin\n                    Customer.Get(\"Customer No.\");\n                    \"Customer Name\" := Customer.Name;\n                end else\n                    \"Customer Name\" := '';\n            end;\n        }\n\n        field(50001; \"Customer Name\"; Text[100])\n        {\n            Caption = 'Preferred Customer Name';\n            DataClassification = CustomerContent;\n            Editable = false;\n        }\n\n        field(50002; \"Special Discount %\"; Decimal)\n        {\n            Caption = 'Special Discount %';\n            DataClassification = CustomerContent;\n            MinValue = 0;\n            MaxValue = 100;\n        }\n\n        field(50003; \"Last Sale Date\"; Date)\n        {\n            Caption = 'Last Sale Date';\n            DataClassification = CustomerContent;\n            Editable = false;\n        }\n\n        field(50004; \"Total Sales Qty\"; Decimal)\n        {\n            Caption = 'Total Sales Quantity';\n            FieldClass = FlowField;\n            CalcFormula = sum(\"Sales Line\".Quantity where(\"No.\" = field(\"No.\"),\n                                                           Type = const(Item)));\n            Editable = false;\n        }\n    }\n\n    keys\n    {\n        key(CustomerKey; \"Customer No.\")\n        {\n        }\n    }\n\n    procedure UpdateLastSaleDate()\n    begin\n        \"Last Sale Date\" := Today();\n        Modify();\n    end;\n\n    procedure GetSpecialPrice(Customer: Record \"TEST Customer\"): Decimal\n    var\n        BasePrice: Decimal;\n    begin\n        BasePrice := \"Unit Price\";\n\n        if \"Customer No.\" = Customer.\"No.\" then\n            BasePrice := BasePrice * (1 - \"Special Discount %\" / 100);\n\n        exit(BasePrice);\n    end;\n}"
  },
  {
    "path": "test/resources/repos/al/test_repo/src/Tables/Customer.Table.al",
    "content": "table 50000 \"TEST Customer\"\n{\n    Caption = 'Customer';\n    DataClassification = CustomerContent;\n\n    fields\n    {\n        field(1; \"No.\"; Code[20])\n        {\n            Caption = 'No.';\n            DataClassification = CustomerContent;\n\n            trigger OnValidate()\n            begin\n                if \"No.\" <> xRec.\"No.\" then begin\n                    CustomerMgt.TestNoSeries();\n                    \"No. Series\" := '';\n                end;\n            end;\n        }\n\n        field(2; Name; Text[100])\n        {\n            Caption = 'Name';\n            DataClassification = CustomerContent;\n\n            trigger OnValidate()\n            begin\n                if Name <> xRec.Name then\n                    UpdateSearchName();\n            end;\n        }\n\n        field(3; \"Search Name\"; Code[100])\n        {\n            Caption = 'Search Name';\n            DataClassification = CustomerContent;\n        }\n\n        field(4; Address; Text[100])\n        {\n            Caption = 'Address';\n            DataClassification = CustomerContent;\n        }\n\n        field(5; \"Address 2\"; Text[50])\n        {\n            Caption = 'Address 2';\n            DataClassification = CustomerContent;\n        }\n\n        field(6; City; Text[30])\n        {\n            Caption = 'City';\n            DataClassification = CustomerContent;\n        }\n\n        field(7; \"Phone No.\"; Text[30])\n        {\n            Caption = 'Phone No.';\n            DataClassification = CustomerContent;\n        }\n\n        field(8; \"E-Mail\"; Text[80])\n        {\n            Caption = 'E-Mail';\n            DataClassification = CustomerContent;\n\n            trigger OnValidate()\n            var\n                MailMgt: Codeunit \"Mail Management\";\n            begin\n                MailMgt.CheckValidEmailAddresses(\"E-Mail\");\n            end;\n        }\n\n        field(10; \"Customer Type\"; Enum CustomerType)\n        {\n            Caption = 'Customer Type';\n            DataClassification = CustomerContent;\n        }\n\n        field(11; Balance; Decimal)\n        {\n            Caption = 'Balance';\n            Editable = false;\n            FieldClass = FlowField;\n            CalcFormula = sum(\"Cust. Ledger Entry\".Amount where(\"Customer No.\" = field(\"No.\")));\n        }\n\n        field(12; \"Credit Limit\"; Decimal)\n        {\n            Caption = 'Credit Limit';\n            DataClassification = CustomerContent;\n        }\n\n        field(13; Blocked; Boolean)\n        {\n            Caption = 'Blocked';\n            DataClassification = CustomerContent;\n        }\n\n        field(14; \"Last Date Modified\"; Date)\n        {\n            Caption = 'Last Date Modified';\n            DataClassification = CustomerContent;\n            Editable = false;\n        }\n\n        field(15; \"No. Series\"; Code[20])\n        {\n            Caption = 'No. Series';\n            DataClassification = CustomerContent;\n        }\n\n        field(20; \"Payment Terms Code\"; Code[10])\n        {\n            Caption = 'Payment Terms Code';\n            DataClassification = CustomerContent;\n            TableRelation = \"Payment Terms\";\n        }\n\n        field(21; \"Currency Code\"; Code[10])\n        {\n            Caption = 'Currency Code';\n            DataClassification = CustomerContent;\n            TableRelation = Currency;\n        }\n    }\n\n    keys\n    {\n        key(PK; \"No.\")\n        {\n            Clustered = true;\n        }\n\n        key(SearchName; \"Search Name\")\n        {\n        }\n\n        key(CustomerType; \"Customer Type\", City)\n        {\n        }\n    }\n\n    fieldgroups\n    {\n        fieldgroup(DropDown; \"No.\", Name, City)\n        {\n        }\n\n        fieldgroup(Brick; \"No.\", Name, Balance)\n        {\n        }\n    }\n\n    trigger OnInsert()\n    begin\n        if \"No.\" = '' then begin\n            CustomerMgt.TestNoSeries();\n            CustomerMgt.InitNo(Rec);\n        end;\n\n        \"Last Date Modified\" := Today();\n    end;\n\n    trigger OnModify()\n    begin\n        \"Last Date Modified\" := Today();\n    end;\n\n    trigger OnDelete()\n    var\n        CustomerLedgerEntry: Record \"Cust. Ledger Entry\";\n    begin\n        CustomerLedgerEntry.SetRange(\"Customer No.\", \"No.\");\n        if not CustomerLedgerEntry.IsEmpty() then\n            Error('Cannot delete customer %1 with ledger entries', \"No.\");\n    end;\n\n    trigger OnRename()\n    begin\n        \"Last Date Modified\" := Today();\n    end;\n\n    var\n        CustomerMgt: Codeunit CustomerMgt;\n\n    procedure UpdateSearchName()\n    begin\n        \"Search Name\" := UpperCase(Name);\n    end;\n\n    procedure CheckCreditLimit()\n    var\n        CreditLimitExceeded: Boolean;\n    begin\n        CalcFields(Balance);\n        CreditLimitExceeded := (Balance > \"Credit Limit\") and (\"Credit Limit\" <> 0);\n\n        if CreditLimitExceeded then\n            Message('Credit limit exceeded for customer %1', \"No.\");\n    end;\n\n    procedure GetDisplayName(): Text\n    begin\n        exit(Name + ' (' + \"No.\" + ')');\n    end;\n}"
  },
  {
    "path": "test/resources/repos/ansible/test_repo/inventory/hosts.yml",
    "content": "---\nall:\n  children:\n    webservers:\n      hosts:\n        web1.example.com:\n          ansible_host: 192.168.1.10\n        web2.example.com:\n          ansible_host: 192.168.1.11\n    dbservers:\n      hosts:\n        db1.example.com:\n          ansible_host: 192.168.1.20\n"
  },
  {
    "path": "test/resources/repos/ansible/test_repo/playbook.yml",
    "content": "---\n- name: Configure web servers\n  hosts: webservers\n  become: true\n  vars:\n    http_port: 80\n    max_connections: 100\n\n  tasks:\n    - name: Install nginx\n      ansible.builtin.package:\n        name: nginx\n        state: present\n\n    - name: Start nginx service\n      ansible.builtin.service:\n        name: nginx\n        state: started\n        enabled: true\n\n    - name: Copy config file\n      ansible.builtin.template:\n        src: nginx.conf.j2\n        dest: /etc/nginx/nginx.conf\n      notify: Restart nginx\n\n  handlers:\n    - name: Restart nginx\n      ansible.builtin.service:\n        name: nginx\n        state: restarted\n"
  },
  {
    "path": "test/resources/repos/ansible/test_repo/roles/common/defaults/main.yml",
    "content": "---\nnginx_listen_port: 80\ndeploy_user: deploy\n"
  },
  {
    "path": "test/resources/repos/ansible/test_repo/roles/common/handlers/main.yml",
    "content": "---\n- name: Restart common services\n  ansible.builtin.debug:\n    msg: \"Restarting common services\"\n"
  },
  {
    "path": "test/resources/repos/ansible/test_repo/roles/common/tasks/main.yml",
    "content": "---\n- name: Update package cache\n  ansible.builtin.package:\n    update_cache: true\n\n- name: Install common packages\n  ansible.builtin.package:\n    name: \"{{ item }}\"\n    state: present\n  loop:\n    - curl\n    - git\n    - vim\n\n- name: Create deploy user\n  ansible.builtin.user:\n    name: deploy\n    state: present\n    shell: /bin/bash\n"
  },
  {
    "path": "test/resources/repos/bash/test_repo/config.sh",
    "content": "#!/bin/bash\n\n# Configuration script for project setup\n\n# Environment variables\nexport PROJECT_NAME=\"bash-test-project\"\nexport PROJECT_VERSION=\"1.0.0\"\nexport LOG_LEVEL=\"INFO\"\nexport CONFIG_DIR=\"./config\"\n\n# Default settings\nDEFAULT_TIMEOUT=30\nDEFAULT_RETRIES=3\nDEFAULT_PORT=8080\n\n# Configuration arrays\ndeclare -A ENVIRONMENTS=(\n    [\"dev\"]=\"development\"\n    [\"prod\"]=\"production\"\n    [\"test\"]=\"testing\"\n)\n\ndeclare -A DATABASE_CONFIGS=(\n    [\"host\"]=\"localhost\"\n    [\"port\"]=\"5432\"\n    [\"name\"]=\"myapp_db\"\n    [\"user\"]=\"dbuser\"\n)\n\n# Function to load configuration\nload_config() {\n    local env=\"${1:-dev}\"\n    local config_file=\"${CONFIG_DIR}/${env}.conf\"\n    \n    if [[ -f \"$config_file\" ]]; then\n        echo \"Loading configuration from $config_file\"\n        source \"$config_file\"\n    else\n        echo \"Warning: Configuration file $config_file not found, using defaults\"\n    fi\n}\n\n# Function to validate configuration\nvalidate_config() {\n    local errors=0\n    \n    if [[ -z \"$PROJECT_NAME\" ]]; then\n        echo \"Error: PROJECT_NAME is not set\" >&2\n        ((errors++))\n    fi\n    \n    if [[ -z \"$PROJECT_VERSION\" ]]; then\n        echo \"Error: PROJECT_VERSION is not set\" >&2\n        ((errors++))\n    fi\n    \n    if [[ $DEFAULT_PORT -lt 1024 || $DEFAULT_PORT -gt 65535 ]]; then\n        echo \"Error: Invalid port number $DEFAULT_PORT\" >&2\n        ((errors++))\n    fi\n    \n    return $errors\n}\n\n# Function to print configuration\nprint_config() {\n    echo \"=== Current Configuration ===\"\n    echo \"Project Name: $PROJECT_NAME\"\n    echo \"Version: $PROJECT_VERSION\"\n    echo \"Log Level: $LOG_LEVEL\"\n    echo \"Default Port: $DEFAULT_PORT\"\n    echo \"Default Timeout: $DEFAULT_TIMEOUT\"\n    echo \"Default Retries: $DEFAULT_RETRIES\"\n    \n    echo \"\\n=== Environments ===\"\n    for env in \"${!ENVIRONMENTS[@]}\"; do\n        echo \"  $env: ${ENVIRONMENTS[$env]}\"\n    done\n    \n    echo \"\\n=== Database Configuration ===\"\n    for key in \"${!DATABASE_CONFIGS[@]}\"; do\n        echo \"  $key: ${DATABASE_CONFIGS[$key]}\"\n    done\n}\n\n# Initialize configuration if this script is run directly\nif [[ \"${BASH_SOURCE[0]}\" == \"${0}\" ]]; then\n    load_config \"$1\"\n    validate_config\n    print_config\nfi\n"
  },
  {
    "path": "test/resources/repos/bash/test_repo/main.sh",
    "content": "#!/bin/bash\n\n# Main script demonstrating various bash features\n\n# Global variables\nreadonly SCRIPT_NAME=\"Main Script\"\nCOUNTER=0\ndeclare -a ITEMS=(\"item1\" \"item2\" \"item3\")\n\n# Function definitions\nfunction greet_user() {\n    local username=\"$1\"\n    local greeting_type=\"${2:-default}\"\n    \n    case \"$greeting_type\" in\n        \"formal\")\n            echo \"Good day, ${username}!\"\n            ;;\n        \"casual\")\n            echo \"Hey ${username}!\"\n            ;;\n        *)\n            echo \"Hello, ${username}!\"\n            ;;\n    esac\n}\n\nfunction process_items() {\n    local -n items_ref=$1\n    local operation=\"$2\"\n    \n    for item in \"${items_ref[@]}\"; do\n        case \"$operation\" in\n            \"count\")\n                ((COUNTER++))\n                echo \"Processing item $COUNTER: $item\"\n                ;;\n            \"uppercase\")\n                echo \"${item^^}\"\n                ;;\n            *)\n                echo \"Unknown operation: $operation\"\n                return 1\n                ;;\n        esac\n    done\n}\n\n# Main execution\nmain() {\n    echo \"Starting $SCRIPT_NAME\"\n    \n    if [[ $# -eq 0 ]]; then\n        echo \"Usage: $0 <username> [greeting_type]\"\n        exit 1\n    fi\n    \n    local user=\"$1\"\n    local greeting=\"${2:-default}\"\n    \n    greet_user \"$user\" \"$greeting\"\n    \n    echo \"Processing items...\"\n    process_items ITEMS \"count\"\n    \n    echo \"Script completed successfully\"\n}\n\n# Run main function with all arguments\nmain \"$@\"\n"
  },
  {
    "path": "test/resources/repos/bash/test_repo/utils.sh",
    "content": "#!/bin/bash\n\n# Utility functions for bash scripting\n\n# String manipulation functions\nfunction to_uppercase() {\n    echo \"${1^^}\"\n}\n\nfunction to_lowercase() {\n    echo \"${1,,}\"\n}\n\nfunction trim_whitespace() {\n    local var=\"$1\"\n    var=\"${var#\"${var%%[![:space:]]*}\"}\"\n    var=\"${var%\"${var##*[![:space:]]}\"}\"   \n    echo \"$var\"\n}\n\n# File operations\nfunction backup_file() {\n    local file=\"$1\"\n    local backup_dir=\"${2:-./backups}\"\n    \n    if [[ ! -f \"$file\" ]]; then\n        echo \"Error: File '$file' does not exist\" >&2\n        return 1\n    fi\n    \n    mkdir -p \"$backup_dir\"\n    cp \"$file\" \"${backup_dir}/$(basename \"$file\").$(date +%Y%m%d_%H%M%S).bak\"\n    echo \"Backup created for $file\"\n}\n\n# Array operations\nfunction contains_element() {\n    local element=\"$1\"\n    shift\n    local array=(\"$@\")\n    \n    for item in \"${array[@]}\"; do\n        if [[ \"$item\" == \"$element\" ]]; then\n            return 0\n        fi\n    done\n    return 1\n}\n\n# Logging functions\nfunction log_message() {\n    local level=\"$1\"\n    local message=\"$2\"\n    local timestamp=$(date '+%Y-%m-%d %H:%M:%S')\n    \n    case \"$level\" in\n        \"ERROR\")\n            echo \"[$timestamp] ERROR: $message\" >&2\n            ;;\n        \"WARN\")\n            echo \"[$timestamp] WARN: $message\" >&2\n            ;;\n        \"INFO\")\n            echo \"[$timestamp] INFO: $message\"\n            ;;\n        \"DEBUG\")\n            [[ \"${DEBUG:-false}\" == \"true\" ]] && echo \"[$timestamp] DEBUG: $message\"\n            ;;\n        *)\n            echo \"[$timestamp] $message\"\n            ;;\n    esac\n}\n\n# Validation functions\nfunction is_valid_email() {\n    local email=\"$1\"\n    [[ \"$email\" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$ ]]\n}\n\nfunction is_number() {\n    [[ $1 =~ ^[0-9]+$ ]]\n}\n"
  },
  {
    "path": "test/resources/repos/clojure/test_repo/deps.edn",
    "content": "{:paths [\"src\"]\n :deps {org.clojure/clojure {:mvn/version \"1.11.1\"}}\n :aliases\n {:test {:extra-paths [\"test\"]\n         :extra-deps {org.clojure/test.check {:mvn/version \"1.1.1\"}}}}}\n"
  },
  {
    "path": "test/resources/repos/clojure/test_repo/src/test_app/core.clj",
    "content": "(ns test-app.core)\n\n(defn greet\n  \"A simple greeting function\"\n  [name]\n  (str \"Hello, \" name \"!\"))\n\n(defn add\n  \"Adds two numbers\"\n  [a b]\n  (+ a b))\n\n(defn multiply\n  \"Multiplies two numbers\"\n  [a b]\n  (* a b))\n\n(defn -main\n  \"Main entry point\"\n  [& args]\n  (println (greet \"World\"))\n  (println \"2 + 3 =\" (add 2 3))\n  (println \"4 * 5 =\" (multiply 4 5)))\n"
  },
  {
    "path": "test/resources/repos/clojure/test_repo/src/test_app/utils.clj",
    "content": "(ns test-app.utils\n  (:require [test-app.core :as core]))\n\n(defn calculate-area\n  \"Calculates the area of a rectangle\"\n  [width height]\n  (core/multiply width height))\n\n(defn format-greeting\n  \"Formats a greeting message\"\n  [name]\n  (str \"Welcome, \" (core/greet name)))\n\n(defn sum-list\n  \"Sums a list of numbers\"\n  [numbers]\n  (reduce core/add 0 numbers))\n"
  },
  {
    "path": "test/resources/repos/cpp/test_repo/a.cpp",
    "content": "#include \"b.hpp\"\n\nint main() {\n    int x = add(3, 4);\n    return x;\n}\n"
  },
  {
    "path": "test/resources/repos/cpp/test_repo/b.cpp",
    "content": "#include \"b.hpp\"\n\nint add(int a, int b) {\n    return a + b;\n}\n"
  },
  {
    "path": "test/resources/repos/cpp/test_repo/b.hpp",
    "content": "#pragma once\n\nint add(int a, int b);\n"
  },
  {
    "path": "test/resources/repos/cpp/test_repo/compile_commands.json",
    "content": "[\n  {\n    \"directory\": \".\",\n    \"command\": \"g++ -std=c++17 -I . -c a.cpp\",\n    \"file\": \"a.cpp\"\n  },\n  {\n    \"directory\": \".\",\n    \"command\": \"g++ -std=c++17 -I . -c b.cpp\",\n    \"file\": \"b.cpp\"\n  }\n]"
  },
  {
    "path": "test/resources/repos/csharp/test_repo/.gitignore",
    "content": "# Build results\n[Dd]ebug/\n[Dd]ebugPublic/\n[Rr]elease/\n[Rr]eleases/\nx64/\nx86/\n[Aa][Rr][Mm]/\n[Aa][Rr][Mm]64/\nbld/\n[Bb]in/\n[Oo]bj/\n[Ll]og/\n[Ll]ogs/\n\n# Visual Studio temporary files\n.vs/\n\n# .NET Core\nproject.lock.json\nproject.fragment.lock.json\nartifacts/\n\n# Files built by Visual Studio\n*.user\n*.userosscache\n*.sln.docstates\n\n# Build results\n*.dll\n*.exe\n*.pdb\n\n# NuGet\n*.nupkg\n*.snupkg\npackages/"
  },
  {
    "path": "test/resources/repos/csharp/test_repo/Models/Person.cs",
    "content": "using TestProject;\n\nnamespace TestProject.Models\n{\n    public class Person\n    {\n        public string Name { get; set; }\n        public int Age { get; set; }\n        public string Email { get; set; }\n        \n        public Person(string name, int age, string email)\n        {\n            Name = name;\n            Age = age;\n            Email = email;\n        }\n        \n        public override string ToString()\n        {\n            return $\"{Name} ({Age}) - {Email}\";\n        }\n        \n        public bool IsAdult()\n        {\n            return Age >= 18;\n        }\n        \n        public int CalculateYearsUntilRetirement()\n        {\n            var calculator = new Calculator();\n            return calculator.Subtract(65, Age);\n        }\n    }\n}"
  },
  {
    "path": "test/resources/repos/csharp/test_repo/Program.cs",
    "content": "using System;\n\nnamespace TestProject\n{\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            Console.WriteLine(\"Hello, World!\");\n            \n            var calculator = new Calculator();\n            int result = calculator.Add(5, 3);\n            Console.WriteLine($\"5 + 3 = {result}\");\n        }\n    }\n    \n    public class Calculator\n    {\n        public int Add(int a, int b)\n        {\n            return a + b;\n        }\n        \n        public int Subtract(int a, int b)\n        {\n            return a - b;\n        }\n        \n        public int Multiply(int a, int b)\n        {\n            return a * b;\n        }\n        \n        public double Divide(int a, int b)\n        {\n            if (b == 0)\n            {\n                throw new DivideByZeroException(\"Cannot divide by zero\");\n            }\n            return (double)a / b;\n        }\n    }\n}"
  },
  {
    "path": "test/resources/repos/csharp/test_repo/TestProject.csproj",
    "content": "<Project Sdk=\"Microsoft.NET.Sdk\">\n\n  <PropertyGroup>\n    <OutputType>Exe</OutputType>\n    <TargetFramework>net8.0</TargetFramework>\n    <ImplicitUsings>enable</ImplicitUsings>\n    <Nullable>enable</Nullable>\n  </PropertyGroup>\n\n</Project>"
  },
  {
    "path": "test/resources/repos/csharp/test_repo/serena.sln",
    "content": "Microsoft Visual Studio Solution File, Format Version 12.00\n# Visual Studio Version 17\nVisualStudioVersion = 17.5.2.0\nMinimumVisualStudioVersion = 10.0.40219.1\nProject(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\") = \"test\", \"test\", \"{0C88DD14-F956-CE84-757C-A364CCF449FC}\"\nEndProject\nProject(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\") = \"resources\", \"resources\", \"{EF7103B4-4C75-1E6D-A485-A154A88D107A}\"\nEndProject\nProject(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\") = \"repos\", \"repos\", \"{E2326EEF-E677-6A44-0935-7677816F09E7}\"\nEndProject\nProject(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\") = \"csharp\", \"csharp\", \"{C21E6CE7-177A-86D9-040F-A317F18B6DBF}\"\nEndProject\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"TestProject\", \"test\\resources\\repos\\csharp\\test_repo\\TestProject.csproj\", \"{A4D04E18-760A-73F9-3303-0542F6298C84}\"\nEndProject\nGlobal\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n\t\tDebug|Any CPU = Debug|Any CPU\n\t\tRelease|Any CPU = Release|Any CPU\n\tEndGlobalSection\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n\t\t{A4D04E18-760A-73F9-3303-0542F6298C84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\n\t\t{A4D04E18-760A-73F9-3303-0542F6298C84}.Debug|Any CPU.Build.0 = Debug|Any CPU\n\t\t{A4D04E18-760A-73F9-3303-0542F6298C84}.Release|Any CPU.ActiveCfg = Release|Any CPU\n\t\t{A4D04E18-760A-73F9-3303-0542F6298C84}.Release|Any CPU.Build.0 = Release|Any CPU\n\tEndGlobalSection\n\tGlobalSection(SolutionProperties) = preSolution\n\t\tHideSolutionNode = FALSE\n\tEndGlobalSection\n\tGlobalSection(NestedProjects) = preSolution\n\t\t{EF7103B4-4C75-1E6D-A485-A154A88D107A} = {0C88DD14-F956-CE84-757C-A364CCF449FC}\n\t\t{E2326EEF-E677-6A44-0935-7677816F09E7} = {EF7103B4-4C75-1E6D-A485-A154A88D107A}\n\t\t{C21E6CE7-177A-86D9-040F-A317F18B6DBF} = {E2326EEF-E677-6A44-0935-7677816F09E7}\n\t\t{A4D04E18-760A-73F9-3303-0542F6298C84} = {C21E6CE7-177A-86D9-040F-A317F18B6DBF}\n\tEndGlobalSection\n\tGlobalSection(ExtensibilityGlobals) = postSolution\n\t\tSolutionGuid = {BDCA748E-D888-4BAF-BF24-DAC683113BFC}\n\tEndGlobalSection\nEndGlobal\n"
  },
  {
    "path": "test/resources/repos/dart/test_repo/.gitignore",
    "content": "# Files and directories created by pub\n.dart_tool/\n.packages\npubspec.lock\nbuild/\n\n# If you're building an application, you may want to check-in your pubspec.lock\n# pubspec.lock\n\n# Directory created by dartdoc\ndoc/api/\n\n# dotenv environment variables file\n.env*\n\n# Avoid committing generated Javascript files\n*.dart.js\n*.info.json      # Produced by the --dump-info flag.\n*.js             # When generated by dart2js. Don't specify *.js if your\n                 # project includes source files written in JavaScript.\n*.js_\n*.js.deps\n*.js.map"
  },
  {
    "path": "test/resources/repos/dart/test_repo/pubspec.yaml",
    "content": "name: test_repo\ndescription: A test repository for Serena Dart language server testing\nversion: 1.0.0\n\nenvironment:\n  sdk: '>=3.0.0 <4.0.0'\n\ndependencies:\n  \ndev_dependencies:\n  lints: ^3.0.0"
  },
  {
    "path": "test/resources/repos/elixir/test_repo/.gitignore",
    "content": ""
  },
  {
    "path": "test/resources/repos/elixir/test_repo/lib/examples.ex",
    "content": "defmodule TestRepo.Examples do\n  @moduledoc \"\"\"\n  Examples module demonstrating usage of models and services.\n  Similar to Python's examples directory, this shows how different modules work together.\n  \"\"\"\n\n  alias TestRepo.Models.{User, Item}\n  alias TestRepo.Services.{UserService, ItemService, OrderService}\n\n  defmodule UserManagement do\n    @doc \"\"\"\n    Creates a complete user workflow example.\n    \"\"\"\n    def run_user_example do\n      # Start user service\n      {:ok, user_service} = UserService.start_link()\n\n      # Create users\n      {:ok, alice} = UserService.create_user(user_service, \"1\", \"Alice\", \"alice@example.com\", [\"admin\"])\n      {:ok, bob} = UserService.create_user(user_service, \"2\", \"Bob\", \"bob@example.com\", [\"user\"])\n\n      # Get users\n      {:ok, retrieved_alice} = UserService.get_user(user_service, \"1\")\n\n      # List all users\n      all_users = UserService.list_users(user_service)\n\n      # Clean up\n      GenServer.stop(user_service)\n\n      %{\n        created_alice: alice,\n        created_bob: bob,\n        retrieved_alice: retrieved_alice,\n        all_users: all_users\n      }\n    end\n\n    @doc \"\"\"\n    Demonstrates user role management.\n    \"\"\"\n    def manage_user_roles do\n      user = User.new(\"role_user\", \"Role User\", \"role@example.com\")\n\n      # Add roles\n      user_with_admin = User.add_role(user, \"admin\")\n      user_with_multiple = User.add_role(user_with_admin, \"moderator\")\n\n      # Check roles\n      has_admin = User.has_role?(user_with_multiple, \"admin\")\n      has_guest = User.has_role?(user_with_multiple, \"guest\")\n\n      %{\n        original_user: user,\n        user_with_roles: user_with_multiple,\n        has_admin: has_admin,\n        has_guest: has_guest\n      }\n    end\n  end\n\n  defmodule ShoppingExample do\n    @doc \"\"\"\n    Creates a complete shopping workflow.\n    \"\"\"\n    def run_shopping_example do\n      # Create user and items\n      user = User.new(\"customer1\", \"Customer One\", \"customer@example.com\")\n      item1 = Item.new(\"widget1\", \"Super Widget\", 19.99, \"electronics\")\n      item2 = Item.new(\"gadget1\", \"Cool Gadget\", 29.99, \"electronics\")\n\n      # Create order\n      order = OrderService.create_order(\"order1\", user)\n\n      # Add items to order\n      order_with_item1 = OrderService.add_item_to_order(order, item1)\n      order_with_items = OrderService.add_item_to_order(order_with_item1, item2)\n\n      # Process the order\n      processed_order = OrderService.process_order(order_with_items)\n      completed_order = OrderService.complete_order(processed_order)\n\n      %{\n        user: user,\n        items: [item1, item2],\n        final_order: completed_order,\n        total_cost: completed_order.total\n      }\n    end\n\n    @doc \"\"\"\n    Demonstrates item filtering and searching.\n    \"\"\"\n    def item_filtering_example do\n      # Start item service\n      {:ok, item_service} = ItemService.start_link()\n\n      # Create various items\n      ItemService.create_item(item_service, \"laptop\", \"Gaming Laptop\", 1299.99, \"electronics\")\n      ItemService.create_item(item_service, \"book\", \"Elixir Guide\", 39.99, \"books\")\n      ItemService.create_item(item_service, \"phone\", \"Smartphone\", 699.99, \"electronics\")\n      ItemService.create_item(item_service, \"novel\", \"Great Novel\", 19.99, \"books\")\n\n      # Get all items\n      all_items = ItemService.list_items(item_service)\n\n      # Filter by category\n      electronics = ItemService.list_items(item_service, \"electronics\")\n      books = ItemService.list_items(item_service, \"books\")\n\n      # Clean up\n      Agent.stop(item_service)\n\n      %{\n        all_items: all_items,\n        electronics: electronics,\n        books: books,\n        total_items: length(all_items),\n        electronics_count: length(electronics),\n        books_count: length(books)\n      }\n    end\n  end\n\n  defmodule IntegrationExample do\n    @doc \"\"\"\n    Runs a complete e-commerce scenario.\n    \"\"\"\n    def run_full_scenario do\n      # Setup services\n      container = TestRepo.Services.create_service_container()\n      TestRepo.Services.setup_sample_data(container)\n\n      # Get sample data\n      {:ok, sample_user} = UserService.get_user(container.user_service, TestRepo.Services.sample_user_id())\n      {:ok, sample_item} = ItemService.get_item(container.item_service, TestRepo.Services.sample_item_id())\n\n      # Create additional items\n      {:ok, premium_item} = ItemService.create_item(\n        container.item_service,\n        \"premium\",\n        \"Premium Product\",\n        99.99,\n        \"premium\"\n      )\n\n      # Create order with multiple items\n      order = OrderService.create_order(\"big_order\", sample_user, [sample_item])\n      order_with_premium = OrderService.add_item_to_order(order, premium_item)\n\n      # Process through order lifecycle\n      processing_order = OrderService.process_order(order_with_premium)\n      final_order = OrderService.complete_order(processing_order)\n\n      # Serialize everything for output\n      serialized_user = TestRepo.Services.serialize_model(sample_user)\n      serialized_order = TestRepo.Services.serialize_model(final_order)\n\n      # Clean up\n      GenServer.stop(container.user_service)\n      Agent.stop(container.item_service)\n\n      %{\n        scenario: \"full_ecommerce\",\n        user: serialized_user,\n        order: serialized_order,\n        total_revenue: final_order.total,\n        items_sold: length(final_order.items)\n      }\n    end\n\n    @doc \"\"\"\n    Demonstrates error handling scenarios.\n    \"\"\"\n    def error_handling_example do\n      {:ok, user_service} = UserService.start_link()\n\n      # Try to create duplicate user\n      {:ok, _user1} = UserService.create_user(user_service, \"dup\", \"User\", \"user@example.com\")\n      duplicate_result = UserService.create_user(user_service, \"dup\", \"Another User\", \"another@example.com\")\n\n      # Try to get non-existent user\n      missing_user_result = UserService.get_user(user_service, \"nonexistent\")\n\n      # Try to delete non-existent user\n      delete_result = UserService.delete_user(user_service, \"nonexistent\")\n\n      GenServer.stop(user_service)\n\n      %{\n        duplicate_user_error: duplicate_result,\n        missing_user_error: missing_user_result,\n        delete_missing_error: delete_result\n      }\n    end\n  end\n\n  @doc \"\"\"\n  Main function to run all examples.\n  \"\"\"\n  def run_all_examples do\n    %{\n      user_management: UserManagement.run_user_example(),\n      role_management: UserManagement.manage_user_roles(),\n      shopping: ShoppingExample.run_shopping_example(),\n      item_filtering: ShoppingExample.item_filtering_example(),\n      integration: IntegrationExample.run_full_scenario(),\n      error_handling: IntegrationExample.error_handling_example()\n    }\n  end\nend "
  },
  {
    "path": "test/resources/repos/elixir/test_repo/lib/ignored_dir/ignored_module.ex",
    "content": "defmodule TestRepo.IgnoredDir.IgnoredModule do\n  @moduledoc \"\"\"\n  This module is in a directory that should be ignored by the language server.\n  It's used for testing directory filtering functionality.\n  \"\"\"\n\n  alias TestRepo.Models.User\n\n  @doc \"\"\"\n  This function references the User model to test that ignored directories\n  don't show up in symbol references.\n  \"\"\"\n  def create_ignored_user do\n    User.new(\"ignored\", \"Ignored User\", \"ignored@example.com\")\n  end\n\n  @doc \"\"\"\n  Another function that uses models.\n  \"\"\"\n  def process_ignored_user(user) do\n    User.add_role(user, \"ignored_role\")\n  end\nend "
  },
  {
    "path": "test/resources/repos/elixir/test_repo/lib/models.ex",
    "content": "defmodule TestRepo.Models do\n  @moduledoc \"\"\"\n  Models module demonstrating various Elixir patterns including structs, protocols, and behaviours.\n  \"\"\"\n\n  defprotocol Serializable do\n    @doc \"Convert model to map representation\"\n    def to_map(model)\n  end\n\n  defmodule User do\n    @type t :: %__MODULE__{\n            id: String.t(),\n            name: String.t() | nil,\n            email: String.t(),\n            roles: list(String.t())\n          }\n\n    defstruct [:id, :name, :email, roles: []]\n\n    @doc \"\"\"\n    Creates a new user.\n\n    ## Examples\n\n        iex> TestRepo.Models.User.new(\"1\", \"Alice\", \"alice@example.com\")\n        %TestRepo.Models.User{id: \"1\", name: \"Alice\", email: \"alice@example.com\", roles: []}\n\n    \"\"\"\n    def new(id, name, email, roles \\\\ []) do\n      %__MODULE__{id: id, name: name, email: email, roles: roles}\n    end\n\n    @doc \"\"\"\n    Checks if user has a specific role.\n    \"\"\"\n    def has_role?(%__MODULE__{roles: roles}, role) do\n      role in roles\n    end\n\n    @doc \"\"\"\n    Adds a role to the user.\n    \"\"\"\n    def add_role(%__MODULE__{roles: roles} = user, role) do\n      %{user | roles: [role | roles]}\n    end\n  end\n\n  defmodule Item do\n    @type t :: %__MODULE__{\n            id: String.t(),\n            name: String.t(),\n            price: float(),\n            category: String.t()\n          }\n\n    defstruct [:id, :name, :price, :category]\n\n    @doc \"\"\"\n    Creates a new item.\n\n    ## Examples\n\n        iex> TestRepo.Models.Item.new(\"1\", \"Widget\", 19.99, \"electronics\")\n        %TestRepo.Models.Item{id: \"1\", name: \"Widget\", price: 19.99, category: \"electronics\"}\n\n    \"\"\"\n    def new(id, name, price, category) do\n      %__MODULE__{id: id, name: name, price: price, category: category}\n    end\n\n    @doc \"\"\"\n    Formats price for display.\n    \"\"\"\n    def display_price(%__MODULE__{price: price}) do\n      \"$#{:erlang.float_to_binary(price, decimals: 2)}\"\n    end\n\n    @doc \"\"\"\n    Checks if item is in a specific category.\n    \"\"\"\n    def in_category?(%__MODULE__{category: category}, target_category) do\n      category == target_category\n    end\n  end\n\n  defmodule Order do\n    alias TestRepo.Models.{User, Item}\n\n    @type t :: %__MODULE__{\n            id: String.t(),\n            user: User.t(),\n            items: list(Item.t()),\n            total: float(),\n            status: atom()\n          }\n\n    defstruct [:id, :user, items: [], total: 0.0, status: :pending]\n\n    @doc \"\"\"\n    Creates a new order.\n    \"\"\"\n    def new(id, user, items \\\\ []) do\n      total = calculate_total(items)\n      %__MODULE__{id: id, user: user, items: items, total: total}\n    end\n\n    @doc \"\"\"\n    Adds an item to the order.\n    \"\"\"\n    def add_item(%__MODULE__{items: items} = order, item) do\n      new_items = [item | items]\n      %{order | items: new_items, total: calculate_total(new_items)}\n    end\n\n    @doc \"\"\"\n    Updates order status.\n    \"\"\"\n    def update_status(%__MODULE__{} = order, status) do\n      %{order | status: status}\n    end\n\n    defp calculate_total(items) do\n      Enum.reduce(items, 0.0, fn item, acc -> acc + item.price end)\n    end\n  end\n\n  # Protocol implementations\n  defimpl Serializable, for: User do\n    def to_map(%User{id: id, name: name, email: email, roles: roles}) do\n      %{id: id, name: name, email: email, roles: roles}\n    end\n  end\n\n  defimpl Serializable, for: Item do\n    def to_map(%Item{id: id, name: name, price: price, category: category}) do\n      %{id: id, name: name, price: price, category: category}\n    end\n  end\n\n  defimpl Serializable, for: Order do\n    def to_map(%Order{id: id, user: user, items: items, total: total, status: status}) do\n      %{\n        id: id,\n        user: Serializable.to_map(user),\n        items: Enum.map(items, &Serializable.to_map/1),\n        total: total,\n        status: status\n      }\n    end\n  end\n\n  @doc \"\"\"\n  Factory function to create a sample user.\n  \"\"\"\n  def create_sample_user do\n    User.new(\"sample\", \"Sample User\", \"sample@example.com\", [\"user\"])\n  end\n\n  @doc \"\"\"\n  Factory function to create a sample item.\n  \"\"\"\n  def create_sample_item do\n    Item.new(\"sample\", \"Sample Item\", 9.99, \"sample\")\n  end\nend "
  },
  {
    "path": "test/resources/repos/elixir/test_repo/lib/services.ex",
    "content": "defmodule TestRepo.Services do\n  @moduledoc \"\"\"\n  Services module demonstrating function usage and dependencies.\n  Similar to Python's services.py, this module uses the models defined in TestRepo.Models.\n  \"\"\"\n\n  alias TestRepo.Models.{User, Item, Order, Serializable}\n\n  defmodule UserService do\n    use GenServer\n\n    # Client API\n\n    @doc \"\"\"\n    Starts the UserService GenServer.\n    \"\"\"\n    def start_link(opts \\\\ []) do\n      GenServer.start_link(__MODULE__, %{}, opts)\n    end\n\n    @doc \"\"\"\n    Creates a new user and stores it.\n    \"\"\"\n    def create_user(pid, id, name, email, roles \\\\ []) do\n      GenServer.call(pid, {:create_user, id, name, email, roles})\n    end\n\n    @doc \"\"\"\n    Gets a user by ID.\n    \"\"\"\n    def get_user(pid, id) do\n      GenServer.call(pid, {:get_user, id})\n    end\n\n    @doc \"\"\"\n    Lists all users.\n    \"\"\"\n    def list_users(pid) do\n      GenServer.call(pid, :list_users)\n    end\n\n    @doc \"\"\"\n    Deletes a user by ID.\n    \"\"\"\n    def delete_user(pid, id) do\n      GenServer.call(pid, {:delete_user, id})\n    end\n\n    # Server callbacks\n\n    @impl true\n    def init(_) do\n      {:ok, %{}}\n    end\n\n    @impl true\n    def handle_call({:create_user, id, name, email, roles}, _from, users) do\n      if Map.has_key?(users, id) do\n        {:reply, {:error, \"User with ID #{id} already exists\"}, users}\n      else\n        user = User.new(id, name, email, roles)\n        new_users = Map.put(users, id, user)\n        {:reply, {:ok, user}, new_users}\n      end\n    end\n\n    @impl true\n    def handle_call({:get_user, id}, _from, users) do\n      case Map.get(users, id) do\n        nil -> {:reply, {:error, :not_found}, users}\n        user -> {:reply, {:ok, user}, users}\n      end\n    end\n\n    @impl true\n    def handle_call(:list_users, _from, users) do\n      user_list = Map.values(users)\n      {:reply, user_list, users}\n    end\n\n    @impl true\n    def handle_call({:delete_user, id}, _from, users) do\n      if Map.has_key?(users, id) do\n        new_users = Map.delete(users, id)\n        {:reply, :ok, new_users}\n      else\n        {:reply, {:error, :not_found}, users}\n      end\n    end\n  end\n\n  defmodule ItemService do\n    use Agent\n\n    @doc \"\"\"\n    Starts the ItemService Agent.\n    \"\"\"\n    def start_link(opts \\\\ []) do\n      Agent.start_link(fn -> %{} end, opts)\n    end\n\n    @doc \"\"\"\n    Creates a new item and stores it.\n    \"\"\"\n    def create_item(pid, id, name, price, category) do\n      Agent.get_and_update(pid, fn items ->\n        if Map.has_key?(items, id) do\n          {{:error, \"Item with ID #{id} already exists\"}, items}\n        else\n          item = Item.new(id, name, price, category)\n          new_items = Map.put(items, id, item)\n          {{:ok, item}, new_items}\n        end\n      end)\n    end\n\n    @doc \"\"\"\n    Gets an item by ID.\n    \"\"\"\n    def get_item(pid, id) do\n      Agent.get(pid, fn items ->\n        case Map.get(items, id) do\n          nil -> {:error, :not_found}\n          item -> {:ok, item}\n        end\n      end)\n    end\n\n    @doc \"\"\"\n    Lists all items, optionally filtered by category.\n    \"\"\"\n    def list_items(pid, category \\\\ nil) do\n      Agent.get(pid, fn items ->\n        item_list = Map.values(items)\n\n        case category do\n          nil -> item_list\n          cat -> Enum.filter(item_list, &Item.in_category?(&1, cat))\n        end\n      end)\n    end\n\n    @doc \"\"\"\n    Deletes an item by ID.\n    \"\"\"\n    def delete_item(pid, id) do\n      Agent.get_and_update(pid, fn items ->\n        if Map.has_key?(items, id) do\n          new_items = Map.delete(items, id)\n          {:ok, new_items}\n        else\n          {{:error, :not_found}, items}\n        end\n      end)\n    end\n  end\n\n  defmodule OrderService do\n    @doc \"\"\"\n    Creates a new order.\n    \"\"\"\n    def create_order(id, user, items \\\\ []) do\n      Order.new(id, user, items)\n    end\n\n    @doc \"\"\"\n    Adds an item to an existing order.\n    \"\"\"\n    def add_item_to_order(order, item) do\n      Order.add_item(order, item)\n    end\n\n    @doc \"\"\"\n    Updates the status of an order.\n    \"\"\"\n    def update_order_status(order, status) do\n      Order.update_status(order, status)\n    end\n\n    @doc \"\"\"\n    Processes an order (changes status to :processing).\n    \"\"\"\n    def process_order(order) do\n      update_order_status(order, :processing)\n    end\n\n    @doc \"\"\"\n    Completes an order (changes status to :completed).\n    \"\"\"\n    def complete_order(order) do\n      update_order_status(order, :completed)\n    end\n\n    @doc \"\"\"\n    Cancels an order (changes status to :cancelled).\n    \"\"\"\n    def cancel_order(order) do\n      update_order_status(order, :cancelled)\n    end\n  end\n\n  @doc \"\"\"\n  Factory function to create a service container.\n  \"\"\"\n  def create_service_container do\n    {:ok, user_service} = UserService.start_link()\n    {:ok, item_service} = ItemService.start_link()\n\n    %{\n      user_service: user_service,\n      item_service: item_service,\n      order_service: OrderService\n    }\n  end\n\n  @doc \"\"\"\n  Helper function to serialize any model that implements the Serializable protocol.\n  \"\"\"\n  def serialize_model(model) do\n    Serializable.to_map(model)\n  end\n\n  # Module-level variables for testing\n  @sample_user_id \"sample_user\"\n  @sample_item_id \"sample_item\"\n\n  @doc \"\"\"\n  Gets the sample user ID.\n  \"\"\"\n  def sample_user_id, do: @sample_user_id\n\n  @doc \"\"\"\n  Gets the sample item ID.\n  \"\"\"\n  def sample_item_id, do: @sample_item_id\n\n  # Create some sample data at module load time\n  def setup_sample_data(container) do\n    # Create sample user\n    UserService.create_user(\n      container.user_service,\n      @sample_user_id,\n      \"Sample User\",\n      \"sample@example.com\",\n      [\"user\", \"customer\"]\n    )\n\n    # Create sample item\n    ItemService.create_item(\n      container.item_service,\n      @sample_item_id,\n      \"Sample Widget\",\n      29.99,\n      \"electronics\"\n    )\n  end\nend "
  },
  {
    "path": "test/resources/repos/elixir/test_repo/lib/test_repo.ex",
    "content": "defmodule TestRepo do\n  @moduledoc \"\"\"\n  Documentation for `TestRepo`.\n  \"\"\"\n\n  @doc \"\"\"\n  Hello world.\n\n  ## Examples\n\n      iex> TestRepo.hello()\n      :world\n\n  \"\"\"\n  def hello do\n    :world\n  end\n\n  @doc \"\"\"\n  Adds two numbers together.\n\n  ## Examples\n\n      iex> TestRepo.add(2, 3)\n      5\n\n  \"\"\"\n  def add(a, b) do\n    a + b\n  end\nend "
  },
  {
    "path": "test/resources/repos/elixir/test_repo/lib/utils.ex",
    "content": "defmodule TestRepo.Utils do\n  @moduledoc \"\"\"\n  Utility functions for TestRepo.\n  \"\"\"\n\n  @doc \"\"\"\n  Converts a string to uppercase.\n\n  ## Examples\n\n      iex> TestRepo.Utils.upcase(\"hello\")\n      \"HELLO\"\n\n  \"\"\"\n  def upcase(string) when is_binary(string) do\n    String.upcase(string)\n  end\n\n  @doc \"\"\"\n  Calculates the factorial of a number.\n\n  ## Examples\n\n      iex> TestRepo.Utils.factorial(5)\n      120\n\n  \"\"\"\n  def factorial(0), do: 1\n  def factorial(n) when n > 0 do\n    n * factorial(n - 1)\n  end\n\n  @doc \"\"\"\n  Checks if a number is even.\n\n  ## Examples\n\n      iex> TestRepo.Utils.even?(4)\n      true\n\n      iex> TestRepo.Utils.even?(3)\n      false\n\n  \"\"\"\n  def even?(n) when is_integer(n) do\n    rem(n, 2) == 0\n  end\nend "
  },
  {
    "path": "test/resources/repos/elixir/test_repo/mix.exs",
    "content": "defmodule TestRepo.MixProject do\n  use Mix.Project\n\n  def project do\n    [\n      app: :test_repo,\n      version: \"0.1.0\",\n      elixir: \"~> 1.14\",\n      start_permanent: Mix.env() == :prod,\n      deps: deps()\n    ]\n  end\n\n  def application do\n    [\n      extra_applications: [:logger]\n    ]\n  end\n\n  defp deps do\n    [\n      {:credo, \"~> 1.7\", only: [:dev, :test], runtime: false}\n    ]\n  end\nend "
  },
  {
    "path": "test/resources/repos/elixir/test_repo/scripts/build_script.ex",
    "content": "defmodule TestRepo.Scripts.BuildScript do\n  @moduledoc \"\"\"\n  Build script that references models.\n  This is in the scripts directory which should be ignored in some tests.\n  \"\"\"\n\n  alias TestRepo.Models.{User, Item}\n\n  @doc \"\"\"\n  Script function that creates test data.\n  \"\"\"\n  def create_test_data do\n    user = User.new(\"script_user\", \"Script User\", \"script@example.com\")\n    item = Item.new(\"script_item\", \"Script Item\", 1.0, \"script\")\n\n    {user, item}\n  end\n\n  @doc \"\"\"\n  Another script function referencing User.\n  \"\"\"\n  def cleanup_users do\n    # This would reference User in a real scenario\n    IO.puts(\"Cleaning up users...\")\n  end\nend "
  },
  {
    "path": "test/resources/repos/elixir/test_repo/test/models_test.exs",
    "content": "defmodule TestRepo.ModelsTest do\n  use ExUnit.Case\n  doctest TestRepo.Models\n\n  alias TestRepo.Models.{User, Item, Order, Serializable}\n\n  describe \"User\" do\n    test \"creates a new user with default roles\" do\n      user = User.new(\"1\", \"Alice\", \"alice@example.com\")\n      \n      assert user.id == \"1\"\n      assert user.name == \"Alice\"\n      assert user.email == \"alice@example.com\"\n      assert user.roles == []\n    end\n\n    test \"creates a user with specified roles\" do\n      user = User.new(\"2\", \"Bob\", \"bob@example.com\", [\"admin\", \"user\"])\n      \n      assert user.roles == [\"admin\", \"user\"]\n    end\n\n    test \"checks if user has role\" do\n      user = User.new(\"3\", \"Charlie\", \"charlie@example.com\", [\"admin\"])\n      \n      assert User.has_role?(user, \"admin\")\n      refute User.has_role?(user, \"guest\")\n    end\n\n    test \"adds role to user\" do\n      user = User.new(\"4\", \"David\", \"david@example.com\")\n      user_with_role = User.add_role(user, \"moderator\")\n      \n      assert User.has_role?(user_with_role, \"moderator\")\n      assert length(user_with_role.roles) == 1\n    end\n  end\n\n  describe \"Item\" do\n    test \"creates a new item\" do\n      item = Item.new(\"widget1\", \"Super Widget\", 19.99, \"electronics\")\n      \n      assert item.id == \"widget1\"\n      assert item.name == \"Super Widget\"\n      assert item.price == 19.99\n      assert item.category == \"electronics\"\n    end\n\n    test \"formats price for display\" do\n      item = Item.new(\"item1\", \"Test Item\", 29.99, \"test\")\n      \n      assert Item.display_price(item) == \"$29.99\"\n    end\n\n    test \"checks if item is in category\" do\n      item = Item.new(\"book1\", \"Elixir Book\", 39.99, \"books\")\n      \n      assert Item.in_category?(item, \"books\")\n      refute Item.in_category?(item, \"electronics\")\n    end\n  end\n\n  describe \"Order\" do\n    setup do\n      user = User.new(\"customer1\", \"Customer\", \"customer@example.com\")\n      item1 = Item.new(\"item1\", \"Item 1\", 10.00, \"category1\")\n      item2 = Item.new(\"item2\", \"Item 2\", 20.00, \"category2\")\n      \n      %{user: user, item1: item1, item2: item2}\n    end\n\n    test \"creates a new order\", %{user: user} do\n      order = Order.new(\"order1\", user)\n      \n      assert order.id == \"order1\"\n      assert order.user == user\n      assert order.items == []\n      assert order.total == 0.0\n      assert order.status == :pending\n    end\n\n    test \"creates order with items\", %{user: user, item1: item1, item2: item2} do\n      order = Order.new(\"order2\", user, [item1, item2])\n      \n      assert length(order.items) == 2\n      assert order.total == 30.0\n    end\n\n    test \"adds item to order\", %{user: user, item1: item1, item2: item2} do\n      order = Order.new(\"order3\", user, [item1])\n      order_with_item = Order.add_item(order, item2)\n      \n      assert length(order_with_item.items) == 2\n      assert order_with_item.total == 30.0\n    end\n\n    test \"updates order status\", %{user: user} do\n      order = Order.new(\"order4\", user)\n      processed_order = Order.update_status(order, :processing)\n      \n      assert processed_order.status == :processing\n    end\n  end\n\n  describe \"Serializable protocol\" do\n    test \"serializes User\" do\n      user = User.new(\"1\", \"Alice\", \"alice@example.com\", [\"admin\"])\n      serialized = Serializable.to_map(user)\n      \n      expected = %{\n        id: \"1\",\n        name: \"Alice\",\n        email: \"alice@example.com\",\n        roles: [\"admin\"]\n      }\n      \n      assert serialized == expected\n    end\n\n    test \"serializes Item\" do\n      item = Item.new(\"widget1\", \"Widget\", 19.99, \"electronics\")\n      serialized = Serializable.to_map(item)\n      \n      expected = %{\n        id: \"widget1\",\n        name: \"Widget\",\n        price: 19.99,\n        category: \"electronics\"\n      }\n      \n      assert serialized == expected\n    end\n\n    test \"serializes Order\" do\n      user = User.new(\"1\", \"Alice\", \"alice@example.com\")\n      item = Item.new(\"widget1\", \"Widget\", 19.99, \"electronics\")\n      order = Order.new(\"order1\", user, [item])\n      \n      serialized = Serializable.to_map(order)\n      \n      assert serialized.id == \"order1\"\n      assert serialized.total == 19.99\n      assert serialized.status == :pending\n      assert is_map(serialized.user)\n      assert is_list(serialized.items)\n      assert length(serialized.items) == 1\n    end\n  end\n\n  describe \"factory functions\" do\n    test \"creates sample user\" do\n      user = TestRepo.Models.create_sample_user()\n      \n      assert user.id == \"sample\"\n      assert user.name == \"Sample User\"\n      assert user.email == \"sample@example.com\"\n      assert \"user\" in user.roles\n    end\n\n    test \"creates sample item\" do\n      item = TestRepo.Models.create_sample_item()\n      \n      assert item.id == \"sample\"\n      assert item.name == \"Sample Item\"\n      assert item.price == 9.99\n      assert item.category == \"sample\"\n    end\n  end\nend "
  },
  {
    "path": "test/resources/repos/elixir/test_repo/test/test_repo_test.exs",
    "content": "defmodule TestRepoTest do\n  use ExUnit.Case\n  doctest TestRepo\n\n  test \"greets the world\" do\n    assert TestRepo.hello() == :world\n  end\n\n  test \"adds numbers correctly\" do\n    assert TestRepo.add(2, 3) == 5\n    assert TestRepo.add(-1, 1) == 0\n    assert TestRepo.add(0, 0) == 0\n  end\nend "
  },
  {
    "path": "test/resources/repos/elm/test_repo/Main.elm",
    "content": "module Main exposing (main, greet, calculateSum)\n\n{-| Main module for testing Elm language server functionality.\n\nThis module contains basic functions to test:\n\n  - Symbol discovery\n  - Reference finding\n  - Cross-file imports\n\n-}\n\nimport Browser\nimport Html exposing (Html, div, h1, p, text)\nimport Utils exposing (formatMessage, addNumbers)\n\n\n{-| The main entry point for the application\n-}\nmain : Program () Model Msg\nmain =\n    Browser.sandbox\n        { init = init\n        , view = view\n        , update = update\n        }\n\n\ntype alias Model =\n    { message : String\n    , count : Int\n    }\n\n\ninit : Model\ninit =\n    { message = greet \"World\"\n    , count = calculateSum 5 10\n    }\n\n\ntype Msg\n    = NoOp\n\n\nupdate : Msg -> Model -> Model\nupdate msg model =\n    case msg of\n        NoOp ->\n            model\n\n\nview : Model -> Html Msg\nview model =\n    div []\n        [ h1 [] [ text (formatMessage model.message) ]\n        , p [] [ text (\"Count: \" ++ String.fromInt model.count) ]\n        ]\n\n\n{-| Greet someone by name\n-}\ngreet : String -> String\ngreet name =\n    \"Hello, \" ++ name ++ \"!\"\n\n\n{-| Calculate the sum of two numbers\n-}\ncalculateSum : Int -> Int -> Int\ncalculateSum a b =\n    addNumbers a b\n"
  },
  {
    "path": "test/resources/repos/elm/test_repo/Utils.elm",
    "content": "module Utils exposing (formatMessage, addNumbers, multiplyNumbers)\n\n{-| Utility functions for the Elm test application.\n\nThis module provides helper functions used by other modules.\n\n-}\n\n\n{-| Format a message by adding brackets around it\n-}\nformatMessage : String -> String\nformatMessage msg =\n    \"[ \" ++ msg ++ \" ]\"\n\n\n{-| Add two numbers together\n-}\naddNumbers : Int -> Int -> Int\naddNumbers x y =\n    x + y\n\n\n{-| Multiply two numbers\n-}\nmultiplyNumbers : Int -> Int -> Int\nmultiplyNumbers x y =\n    x * y\n"
  },
  {
    "path": "test/resources/repos/elm/test_repo/elm.json",
    "content": "{\n    \"type\": \"application\",\n    \"source-directories\": [\n        \".\"\n    ],\n    \"elm-version\": \"0.19.1\",\n    \"dependencies\": {\n        \"direct\": {\n            \"elm/browser\": \"1.0.2\",\n            \"elm/core\": \"1.0.5\",\n            \"elm/html\": \"1.0.0\"\n        },\n        \"indirect\": {\n            \"elm/json\": \"1.1.3\",\n            \"elm/time\": \"1.0.0\",\n            \"elm/url\": \"1.0.0\",\n            \"elm/virtual-dom\": \"1.0.3\"\n        }\n    },\n    \"test-dependencies\": {\n        \"direct\": {},\n        \"indirect\": {}\n    }\n}\n"
  },
  {
    "path": "test/resources/repos/erlang/test_repo/hello.erl",
    "content": "-module(hello).\n-export([hello_world/0, greet/1, calculate_sum/2]).\n\n%% Simple hello world function\nhello_world() ->\n    io:format(\"Hello, World!~n\").\n\n%% Greet a person by name\ngreet(Name) ->\n    io:format(\"Hello, ~s!~n\", [Name]).\n\n%% Calculate sum of two numbers\ncalculate_sum(A, B) ->\n    A + B."
  },
  {
    "path": "test/resources/repos/erlang/test_repo/ignored_dir/ignored_module.erl",
    "content": "%% This module should be ignored by tests\n-module(ignored_module).\n\n%% This is in the ignored directory and should not be processed\n-export([ignored_function/0]).\n\nignored_function() ->\n    \"This should not appear in symbol searches\"."
  },
  {
    "path": "test/resources/repos/erlang/test_repo/include/records.hrl",
    "content": "%% Common record definitions for the test repository\n-ifndef(RECORDS_HRL).\n-define(RECORDS_HRL, true).\n\n%% User record definition\n-record(user, {\n    id :: integer(),\n    name :: string(),\n    email :: string(),\n    age :: integer(),\n    active = true :: boolean()\n}).\n\n%% Order record definition\n-record(order, {\n    id :: integer(),\n    user_id :: integer(),\n    items = [] :: list(),\n    total :: float(),\n    status = pending :: pending | processing | completed | cancelled\n}).\n\n%% Item record definition\n-record(item, {\n    id :: integer(),\n    name :: string(),\n    price :: float(),\n    category :: string()\n}).\n\n%% Configuration record\n-record(config, {\n    database_url :: string(),\n    port :: integer(),\n    debug = false :: boolean()\n}).\n\n-endif."
  },
  {
    "path": "test/resources/repos/erlang/test_repo/include/types.hrl",
    "content": "%% Type definitions for the test repository\n-ifndef(TYPES_HRL).\n-define(TYPES_HRL, true).\n\n%% Custom types\n-type user_id() :: pos_integer().\n-type email() :: string().\n-type status() :: active | inactive | suspended.\n-type price() :: float().\n-type quantity() :: non_neg_integer().\n\n%% Complex types\n-type order_line() :: {item_id :: pos_integer(), quantity :: quantity(), price :: price()}.\n-type search_result() :: {ok, list()} | {error, term()}.\n\n%% Callback types for behaviors\n-type init_result() :: {ok, term()} | {stop, term()}.\n-type handle_call_result() :: {reply, term(), term()} | {stop, term(), term()}.\n\n-endif."
  },
  {
    "path": "test/resources/repos/erlang/test_repo/math_utils.erl",
    "content": "-module(math_utils).\n-export([add/2, multiply/2, factorial/1]).\n\n%% Add two numbers\nadd(X, Y) ->\n    X + Y.\n\n%% Multiply two numbers\nmultiply(X, Y) ->\n    X * Y.\n\n%% Calculate factorial\nfactorial(0) ->\n    1;\nfactorial(N) when N > 0 ->\n    N * factorial(N - 1)."
  },
  {
    "path": "test/resources/repos/erlang/test_repo/rebar.config",
    "content": "%% Rebar3 configuration for test repository\n{erl_opts, [\n    debug_info,\n    warnings_as_errors,\n    warn_export_all,\n    warn_unused_import,\n    {i, \"include\"}\n]}.\n\n{deps, [\n    {eunit, \".*\", {git, \"https://github.com/richcarl/eunit.git\", {tag, \"2.3.6\"}}}\n]}.\n\n{profiles, [\n    {test, [\n        {erl_opts, [debug_info]},\n        {deps, [\n            {proper, \"1.3.0\"}\n        ]}\n    ]}\n]}.\n\n{cover_enabled, true}.\n{cover_print_enabled, true}.\n\n{dialyzer, [\n    {warnings, [\n        unmatched_returns,\n        error_handling,\n        race_conditions,\n        underspecs\n    ]}\n]}."
  },
  {
    "path": "test/resources/repos/erlang/test_repo/src/app.erl",
    "content": "%% Main application module\n-module(app).\n-behaviour(application).\n-include(\"../include/records.hrl\").\n\n%% Application callbacks\n-export([\n    start/2,\n    stop/1\n]).\n\n%% API exports\n-export([\n    start_services/0,\n    stop_services/0,\n    get_config/0,\n    health_check/0\n]).\n\n%%%===================================================================\n%%% Application callbacks\n%%%===================================================================\n\n-spec start(application:start_type(), term()) -> {ok, pid()} | {error, term()}.\nstart(_StartType, _StartArgs) ->\n    io:format(\"Starting test application~n\"),\n    case start_services() of\n        ok ->\n            supervisor:start_link({local, app_sup}, ?MODULE, []);\n        {error, Reason} ->\n            {error, Reason}\n    end.\n\n-spec stop(term()) -> ok.\nstop(_State) ->\n    io:format(\"Stopping test application~n\"),\n    stop_services(),\n    ok.\n\n%%%===================================================================\n%%% API functions\n%%%===================================================================\n\n-spec start_services() -> ok | {error, term()}.\nstart_services() ->\n    try\n        {ok, _Pid} = services:start_link(),\n        io:format(\"Services started successfully~n\"),\n        ok\n    catch\n        error:Reason ->\n            io:format(\"Failed to start services: ~p~n\", [Reason]),\n            {error, Reason}\n    end.\n\n-spec stop_services() -> ok.\nstop_services() ->\n    try\n        services:stop(),\n        io:format(\"Services stopped successfully~n\"),\n        ok\n    catch\n        error:Reason ->\n            io:format(\"Error stopping services: ~p~n\", [Reason]),\n            ok\n    end.\n\n-spec get_config() -> #config{}.\nget_config() ->\n    #config{\n        database_url = \"postgresql://localhost:5432/testdb\",\n        port = 8080,\n        debug = true\n    }.\n\n-spec health_check() -> {ok, #{atom() => term()}} | {error, term()}.\nhealth_check() ->\n    try\n        Stats = services:get_statistics(),\n        Config = get_config(),\n        HealthInfo = #{\n            status => healthy,\n            timestamp => utils:timestamp(),\n            config => Config,\n            statistics => Stats,\n            uptime => erlang:statistics(wall_clock)\n        },\n        {ok, HealthInfo}\n    catch\n        error:Reason ->\n            {error, {health_check_failed, Reason}}\n    end.\n\n%%%===================================================================\n%%% Supervisor callbacks (simple implementation)\n%%%===================================================================\n\ninit([]) ->\n    %% Simple supervisor strategy\n    SupFlags = #{\n        strategy => one_for_one,\n        intensity => 5,\n        period => 10\n    },\n    \n    ChildSpecs = [\n        #{\n            id => services,\n            start => {services, start_link, []},\n            restart => permanent,\n            shutdown => 5000,\n            type => worker,\n            modules => [services]\n        }\n    ],\n    \n    {ok, {SupFlags, ChildSpecs}}."
  },
  {
    "path": "test/resources/repos/erlang/test_repo/src/models.erl",
    "content": "%% Models module with record operations and business logic\n-module(models).\n-include(\"../include/records.hrl\").\n-include(\"../include/types.hrl\").\n\n%% Export functions\n-export([\n    create_user/4,\n    update_user/2,\n    get_user_by_id/1,\n    create_order/3,\n    add_item_to_order/3,\n    calculate_order_total/1,\n    validate_email/1,\n    format_user_info/1\n]).\n\n%% User operations\n-spec create_user(integer(), string(), email(), integer()) -> #user{}.\ncreate_user(Id, Name, Email, Age) ->\n    #user{\n        id = Id,\n        name = Name,\n        email = Email,\n        age = Age,\n        active = true\n    }.\n\n-spec update_user(#user{}, [{atom(), term()}]) -> #user{}.\nupdate_user(User, Updates) ->\n    lists:foldl(fun update_user_field/2, User, Updates).\n\n-spec get_user_by_id(user_id()) -> {ok, #user{}} | {error, not_found}.\nget_user_by_id(Id) ->\n    %% Simulate database lookup\n    case Id of\n        1 -> {ok, create_user(1, \"John Doe\", \"john@example.com\", 30)};\n        2 -> {ok, create_user(2, \"Jane Smith\", \"jane@example.com\", 25)};\n        _ -> {error, not_found}\n    end.\n\n%% Order operations\n-spec create_order(integer(), user_id(), list()) -> #order{}.\ncreate_order(Id, UserId, Items) ->\n    #order{\n        id = Id,\n        user_id = UserId,\n        items = Items,\n        total = 0.0,\n        status = pending\n    }.\n\n-spec add_item_to_order(#order{}, #item{}, quantity()) -> #order{}.\nadd_item_to_order(Order, Item, Quantity) ->\n    NewItem = Item#item{id = Quantity}, % Store quantity in id field for simplicity\n    Order#order{items = [NewItem | Order#order.items]}.\n\n-spec calculate_order_total(#order{}) -> float().\ncalculate_order_total(#order{items = Items}) ->\n    lists:foldl(fun(#item{price = Price, id = Qty}, Acc) -> \n        Acc + (Price * Qty) \n    end, 0.0, Items).\n\n%% Helper functions\n-spec update_user_field({atom(), term()}, #user{}) -> #user{}.\nupdate_user_field({name, Name}, User) -> User#user{name = Name};\nupdate_user_field({email, Email}, User) -> User#user{email = Email};\nupdate_user_field({age, Age}, User) -> User#user{age = Age};\nupdate_user_field({active, Active}, User) -> User#user{active = Active};\nupdate_user_field(_, User) -> User.\n\n-spec validate_email(string()) -> boolean().\nvalidate_email(Email) ->\n    string:str(Email, \"@\") > 0 andalso string:str(Email, \".\") > 0.\n\n-spec format_user_info(#user{}) -> string().\nformat_user_info(#user{name = Name, email = Email, age = Age, active = Active}) ->\n    Status = case Active of\n        true -> \"active\";\n        false -> \"inactive\"\n    end,\n    lists:flatten(io_lib:format(\"~s (~s) - Age: ~w - Status: ~s\", \n        [Name, Email, Age, Status]))."
  },
  {
    "path": "test/resources/repos/erlang/test_repo/src/services.erl",
    "content": "%% Services module implementing gen_server behavior\n-module(services).\n-behaviour(gen_server).\n-include(\"../include/records.hrl\").\n-include(\"../include/types.hrl\").\n\n%% API exports\n-export([\n    start_link/0,\n    stop/0,\n    register_user/4,\n    get_user/1,\n    create_order/2,\n    update_order_status/2,\n    get_statistics/0\n]).\n\n%% gen_server callbacks\n-export([\n    init/1,\n    handle_call/3,\n    handle_cast/2,\n    handle_info/2,\n    terminate/2,\n    code_change/3\n]).\n\n%% State record\n-record(state, {\n    users = #{} :: map(),\n    orders = #{} :: map(),\n    next_user_id = 1 :: integer(),\n    next_order_id = 1 :: integer()\n}).\n\n%%%===================================================================\n%%% API\n%%%===================================================================\n\n-spec start_link() -> {ok, pid()} | ignore | {error, term()}.\nstart_link() ->\n    gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).\n\n-spec stop() -> ok.\nstop() ->\n    gen_server:stop(?MODULE).\n\n-spec register_user(string(), email(), integer(), boolean()) -> {ok, user_id()} | {error, term()}.\nregister_user(Name, Email, Age, Active) ->\n    gen_server:call(?MODULE, {register_user, Name, Email, Age, Active}).\n\n-spec get_user(user_id()) -> {ok, #user{}} | {error, not_found}.\nget_user(UserId) ->\n    gen_server:call(?MODULE, {get_user, UserId}).\n\n-spec create_order(user_id(), list()) -> {ok, integer()} | {error, term()}.\ncreate_order(UserId, Items) ->\n    gen_server:call(?MODULE, {create_order, UserId, Items}).\n\n-spec update_order_status(integer(), atom()) -> ok | {error, term()}.\nupdate_order_status(OrderId, Status) ->\n    gen_server:call(?MODULE, {update_order_status, OrderId, Status}).\n\n-spec get_statistics() -> #{atom() => integer()}.\nget_statistics() ->\n    gen_server:call(?MODULE, get_statistics).\n\n%%%===================================================================\n%%% gen_server callbacks\n%%%===================================================================\n\n-spec init([]) -> {ok, #state{}}.\ninit([]) ->\n    {ok, #state{}}.\n\n-spec handle_call(term(), {pid(), term()}, #state{}) -> handle_call_result().\nhandle_call({register_user, Name, Email, Age, Active}, _From, State) ->\n    UserId = State#state.next_user_id,\n    User = models:create_user(UserId, Name, Email, Age),\n    UpdatedUser = models:update_user(User, [{active, Active}]),\n    NewUsers = maps:put(UserId, UpdatedUser, State#state.users),\n    NewState = State#state{\n        users = NewUsers,\n        next_user_id = UserId + 1\n    },\n    {reply, {ok, UserId}, NewState};\n\nhandle_call({get_user, UserId}, _From, State) ->\n    case maps:get(UserId, State#state.users, not_found) of\n        not_found -> {reply, {error, not_found}, State};\n        User -> {reply, {ok, User}, State}\n    end;\n\nhandle_call({create_order, UserId, Items}, _From, State) ->\n    case maps:get(UserId, State#state.users, not_found) of\n        not_found ->\n            {reply, {error, user_not_found}, State};\n        _User ->\n            OrderId = State#state.next_order_id,\n            Order = models:create_order(OrderId, UserId, Items),\n            NewOrders = maps:put(OrderId, Order, State#state.orders),\n            NewState = State#state{\n                orders = NewOrders,\n                next_order_id = OrderId + 1\n            },\n            {reply, {ok, OrderId}, NewState}\n    end;\n\nhandle_call({update_order_status, OrderId, Status}, _From, State) ->\n    case maps:get(OrderId, State#state.orders, not_found) of\n        not_found ->\n            {reply, {error, order_not_found}, State};\n        Order ->\n            UpdatedOrder = Order#order{status = Status},\n            NewOrders = maps:put(OrderId, UpdatedOrder, State#state.orders),\n            NewState = State#state{orders = NewOrders},\n            {reply, ok, NewState}\n    end;\n\nhandle_call(get_statistics, _From, State) ->\n    Stats = #{\n        total_users => maps:size(State#state.users),\n        total_orders => maps:size(State#state.orders),\n        next_user_id => State#state.next_user_id,\n        next_order_id => State#state.next_order_id\n    },\n    {reply, Stats, State};\n\nhandle_call(_Request, _From, State) ->\n    {reply, {error, unknown_request}, State}.\n\n-spec handle_cast(term(), #state{}) -> {noreply, #state{}}.\nhandle_cast(_Msg, State) ->\n    {noreply, State}.\n\n-spec handle_info(term(), #state{}) -> {noreply, #state{}}.\nhandle_info(_Info, State) ->\n    {noreply, State}.\n\n-spec terminate(term(), #state{}) -> ok.\nterminate(_Reason, _State) ->\n    ok.\n\n-spec code_change(term() | {down, term()}, #state{}, term()) -> {ok, #state{}}.\ncode_change(_OldVsn, State, _Extra) ->\n    {ok, State}."
  },
  {
    "path": "test/resources/repos/erlang/test_repo/src/utils.erl",
    "content": "%% Utility functions module\n-module(utils).\n-include(\"../include/types.hrl\").\n\n%% String utilities\n-export([\n    capitalize/1,\n    trim/1,\n    split_string/2,\n    format_currency/1,\n    validate_input/2\n]).\n\n%% List utilities\n-export([\n    find_by_id/2,\n    group_by/2,\n    partition_by/2,\n    safe_nth/2\n]).\n\n%% Math utilities\n-export([\n    calculate_discount/2,\n    round_to_decimal/2,\n    percentage/2\n]).\n\n%% Date/Time utilities\n-export([\n    timestamp/0,\n    format_datetime/1,\n    days_between/2\n]).\n\n%%%===================================================================\n%%% String utilities\n%%%===================================================================\n\n-spec capitalize(string()) -> string().\ncapitalize([]) -> [];\ncapitalize([H|T]) -> [string:to_upper(H) | T].\n\n-spec trim(string()) -> string().\ntrim(String) ->\n    string:strip(string:strip(String, right), left).\n\n-spec split_string(string(), string()) -> [string()].\nsplit_string(String, Delimiter) ->\n    string:tokens(String, Delimiter).\n\n-spec format_currency(float()) -> string().\nformat_currency(Amount) ->\n    lists:flatten(io_lib:format(\"$~.2f\", [Amount])).\n\n-spec validate_input(atom(), term()) -> boolean().\nvalidate_input(email, Email) when is_list(Email) ->\n    models:validate_email(Email);\nvalidate_input(age, Age) when is_integer(Age) ->\n    Age >= 0 andalso Age =< 150;\nvalidate_input(name, Name) when is_list(Name) ->\n    length(Name) > 0 andalso length(Name) =< 100;\nvalidate_input(_, _) ->\n    false.\n\n%%%===================================================================\n%%% List utilities\n%%%===================================================================\n\n-spec find_by_id(integer(), [tuple()]) -> {ok, tuple()} | {error, not_found}.\nfind_by_id(_Id, []) -> {error, not_found};\nfind_by_id(Id, [H|T]) when element(2, H) =:= Id -> {ok, H};\nfind_by_id(Id, [_|T]) -> find_by_id(Id, T).\n\n-spec group_by(fun((term()) -> term()), [term()]) -> [{term(), [term()]}].\ngroup_by(Fun, List) ->\n    Dict = lists:foldl(fun(Item, Acc) ->\n        Key = Fun(Item),\n        case lists:keyfind(Key, 1, Acc) of\n            {Key, Values} ->\n                lists:keyreplace(Key, 1, Acc, {Key, [Item|Values]});\n            false ->\n                [{Key, [Item]}|Acc]\n        end\n    end, [], List),\n    [{K, lists:reverse(V)} || {K, V} <- Dict].\n\n-spec partition_by(fun((term()) -> boolean()), [term()]) -> {[term()], [term()]}.\npartition_by(Predicate, List) ->\n    lists:partition(Predicate, List).\n\n-spec safe_nth(integer(), [term()]) -> {ok, term()} | {error, out_of_bounds}.\nsafe_nth(N, List) when N > 0 andalso N =< length(List) ->\n    {ok, lists:nth(N, List)};\nsafe_nth(_, _) ->\n    {error, out_of_bounds}.\n\n%%%===================================================================\n%%% Math utilities\n%%%===================================================================\n\n-spec calculate_discount(float(), float()) -> float().\ncalculate_discount(Price, DiscountPercent) when DiscountPercent >= 0 andalso DiscountPercent =< 100 ->\n    Price * (100 - DiscountPercent) / 100.\n\n-spec round_to_decimal(float(), integer()) -> float().\nround_to_decimal(Number, Decimals) ->\n    Factor = math:pow(10, Decimals),\n    round(Number * Factor) / Factor.\n\n-spec percentage(number(), number()) -> float().\npercentage(Part, Total) when Total =/= 0 ->\n    (Part / Total) * 100;\npercentage(_, 0) ->\n    0.0.\n\n%%%===================================================================\n%%% Date/Time utilities\n%%%===================================================================\n\n-spec timestamp() -> integer().\ntimestamp() ->\n    {MegaSecs, Secs, _MicroSecs} = os:timestamp(),\n    MegaSecs * 1000000 + Secs.\n\n-spec format_datetime(integer()) -> string().\nformat_datetime(Timestamp) ->\n    {{Year, Month, Day}, {Hour, Minute, Second}} = \n        calendar:gregorian_seconds_to_datetime(Timestamp + 62167219200),\n    lists:flatten(io_lib:format(\"~4..0w-~2..0w-~2..0w ~2..0w:~2..0w:~2..0w\", \n        [Year, Month, Day, Hour, Minute, Second])).\n\n-spec days_between(integer(), integer()) -> integer().\ndays_between(Timestamp1, Timestamp2) ->\n    abs(Timestamp2 - Timestamp1) div (24 * 3600)."
  },
  {
    "path": "test/resources/repos/erlang/test_repo/test/models_tests.erl",
    "content": "%% Unit tests for models module\n-module(models_tests).\n-include_lib(\"eunit/include/eunit.hrl\").\n-include(\"../include/records.hrl\").\n\n%%%===================================================================\n%%% Test fixtures\n%%%===================================================================\n\nsample_user() ->\n    models:create_user(1, \"John Doe\", \"john@example.com\", 30).\n\nsample_order() ->\n    Items = [\n        #item{id = 1, name = \"Widget\", price = 10.99, category = \"tools\"},\n        #item{id = 2, name = \"Gadget\", price = 25.50, category = \"electronics\"}\n    ],\n    models:create_order(1, 1, Items).\n\n%%%===================================================================\n%%% User tests\n%%%===================================================================\n\ncreate_user_test() ->\n    User = models:create_user(1, \"John Doe\", \"john@example.com\", 30),\n    ?assertEqual(1, User#user.id),\n    ?assertEqual(\"John Doe\", User#user.name),\n    ?assertEqual(\"john@example.com\", User#user.email),\n    ?assertEqual(30, User#user.age),\n    ?assertEqual(true, User#user.active).\n\nupdate_user_test() ->\n    User = sample_user(),\n    UpdatedUser = models:update_user(User, [{name, \"Jane Doe\"}, {age, 25}]),\n    ?assertEqual(\"Jane Doe\", UpdatedUser#user.name),\n    ?assertEqual(25, UpdatedUser#user.age),\n    ?assertEqual(\"john@example.com\", UpdatedUser#user.email). % unchanged\n\nget_user_by_id_test() ->\n    ?assertEqual({ok, #user{id = 1, name = \"John Doe\"}}, \n                 models:get_user_by_id(1)),\n    ?assertEqual({error, not_found}, models:get_user_by_id(999)).\n\n%%%===================================================================\n%%% Order tests\n%%%===================================================================\n\ncreate_order_test() ->\n    Order = models:create_order(1, 1, []),\n    ?assertEqual(1, Order#order.id),\n    ?assertEqual(1, Order#order.user_id),\n    ?assertEqual([], Order#order.items),\n    ?assertEqual(pending, Order#order.status).\n\ncalculate_order_total_test() ->\n    Order = sample_order(),\n    Total = models:calculate_order_total(Order),\n    ?assertEqual(36.49, Total). % 10.99 * 1 + 25.50 * 2\n\n%%%===================================================================\n%%% Validation tests\n%%%===================================================================\n\nvalidate_email_test() ->\n    ?assertEqual(true, models:validate_email(\"user@example.com\")),\n    ?assertEqual(true, models:validate_email(\"test.email@domain.co.uk\")),\n    ?assertEqual(false, models:validate_email(\"invalid-email\")),\n    ?assertEqual(false, models:validate_email(\"@domain.com\")),\n    ?assertEqual(false, models:validate_email(\"user@\")).\n\nformat_user_info_test() ->\n    User = sample_user(),\n    Info = models:format_user_info(User),\n    ?assert(string:str(Info, \"John Doe\") > 0),\n    ?assert(string:str(Info, \"john@example.com\") > 0),\n    ?assert(string:str(Info, \"30\") > 0),\n    ?assert(string:str(Info, \"active\") > 0)."
  },
  {
    "path": "test/resources/repos/erlang/test_repo/test/utils_tests.erl",
    "content": "%% Unit tests for utils module\n-module(utils_tests).\n-include_lib(\"eunit/include/eunit.hrl\").\n\n%%%===================================================================\n%%% String utility tests\n%%%===================================================================\n\ncapitalize_test() ->\n    ?assertEqual(\"Hello\", utils:capitalize(\"hello\")),\n    ?assertEqual(\"Test\", utils:capitalize(\"test\")),\n    ?assertEqual(\"\", utils:capitalize(\"\")).\n\ntrim_test() ->\n    ?assertEqual(\"hello\", utils:trim(\"  hello  \")),\n    ?assertEqual(\"test\", utils:trim(\"test\")),\n    ?assertEqual(\"\", utils:trim(\"   \")).\n\nformat_currency_test() ->\n    ?assertEqual(\"$10.50\", utils:format_currency(10.5)),\n    ?assertEqual(\"$0.99\", utils:format_currency(0.99)),\n    ?assertEqual(\"$100.00\", utils:format_currency(100.0)).\n\nvalidate_input_test() ->\n    ?assertEqual(true, utils:validate_input(email, \"test@example.com\")),\n    ?assertEqual(false, utils:validate_input(email, \"invalid\")),\n    ?assertEqual(true, utils:validate_input(age, 25)),\n    ?assertEqual(false, utils:validate_input(age, -5)),\n    ?assertEqual(true, utils:validate_input(name, \"John\")),\n    ?assertEqual(false, utils:validate_input(name, \"\")).\n\n%%%===================================================================\n%%% List utility tests\n%%%===================================================================\n\nfind_by_id_test() ->\n    Items = [{item, 1, \"first\"}, {item, 2, \"second\"}, {item, 3, \"third\"}],\n    ?assertEqual({ok, {item, 2, \"second\"}}, utils:find_by_id(2, Items)),\n    ?assertEqual({error, not_found}, utils:find_by_id(999, Items)).\n\nsafe_nth_test() ->\n    List = [a, b, c, d, e],\n    ?assertEqual({ok, c}, utils:safe_nth(3, List)),\n    ?assertEqual({error, out_of_bounds}, utils:safe_nth(10, List)),\n    ?assertEqual({error, out_of_bounds}, utils:safe_nth(0, List)).\n\n%%%===================================================================\n%%% Math utility tests\n%%%===================================================================\n\ncalculate_discount_test() ->\n    ?assertEqual(90.0, utils:calculate_discount(100.0, 10.0)),\n    ?assertEqual(75.0, utils:calculate_discount(100.0, 25.0)),\n    ?assertEqual(100.0, utils:calculate_discount(100.0, 0.0)).\n\nround_to_decimal_test() ->\n    ?assertEqual(10.99, utils:round_to_decimal(10.9876, 2)),\n    ?assertEqual(15.0, utils:round_to_decimal(15.0001, 2)),\n    ?assertEqual(0.33, utils:round_to_decimal(1/3, 2)).\n\npercentage_test() ->\n    ?assertEqual(50.0, utils:percentage(50, 100)),\n    ?assertEqual(25.0, utils:percentage(1, 4)),\n    ?assertEqual(0.0, utils:percentage(10, 0)).\n\n%%%===================================================================\n%%% Date/Time utility tests\n%%%===================================================================\n\ntimestamp_test() ->\n    Timestamp = utils:timestamp(),\n    ?assert(is_integer(Timestamp)),\n    ?assert(Timestamp > 0).\n\nformat_datetime_test() ->\n    % Test with a known timestamp\n    Formatted = utils:format_datetime(1234567890),\n    ?assert(is_list(Formatted)),\n    ?assert(length(Formatted) > 0).\n\ndays_between_test() ->\n    Day1 = 1000000,\n    Day2 = 1000000 + (3 * 24 * 3600), % 3 days later\n    ?assertEqual(3, utils:days_between(Day1, Day2)),\n    ?assertEqual(3, utils:days_between(Day2, Day1))."
  },
  {
    "path": "test/resources/repos/fortran/test_repo/main.f90",
    "content": "program test_program\n    use math_utils\n    implicit none\n    real :: result\n    \n    ! Test addition\n    result = add_numbers(5.0, 3.0)\n    call print_result(result)\n    \n    ! Test multiplication\n    result = multiply_numbers(4.0, 2.0)\n    call print_result(result)\n    \n    print *, \"All tests completed\"\nend program test_program\n\n"
  },
  {
    "path": "test/resources/repos/fortran/test_repo/modules/geometry.f90",
    "content": "module geometry_types\n    implicit none\n\n    ! Simple type definition\n    type Point2D\n        real :: x, y\n    end type Point2D\n\n    ! Type with double colon syntax\n    type :: Circle\n        real :: radius\n        type(Point2D) :: center\n    end type Circle\n\n    ! Type with extends (inheritance)\n    type, extends(Point2D) :: Point3D\n        real :: z\n    end type Point3D\n\n    ! Named interface\n    interface distance\n        module procedure distance_2d, distance_3d\n    end interface distance\n\ncontains\n\n    function distance_2d(p1, p2) result(dist)\n        type(Point2D), intent(in) :: p1, p2\n        real :: dist\n        dist = sqrt((p2%x - p1%x)**2 + (p2%y - p1%y)**2)\n    end function distance_2d\n\n    function distance_3d(p1, p2) result(dist)\n        type(Point3D), intent(in) :: p1, p2\n        real :: dist\n        dist = sqrt((p2%x - p1%x)**2 + (p2%y - p1%y)**2 + (p2%z - p1%z)**2)\n    end function distance_3d\n\n    function circle_area(c) result(area)\n        type(Circle), intent(in) :: c\n        real :: area\n        real, parameter :: pi = 3.14159265359\n        area = pi * c%radius**2\n    end function circle_area\n\nend module geometry_types\n"
  },
  {
    "path": "test/resources/repos/fortran/test_repo/modules/math_utils.f90",
    "content": "module math_utils\n    implicit none\n    contains\n    \n    function add_numbers(a, b) result(sum)\n        real, intent(in) :: a, b\n        real :: sum\n        sum = a + b\n    end function add_numbers\n    \n    function multiply_numbers(x, y) result(product)\n        real, intent(in) :: x, y\n        real :: product\n        product = x * y\n    end function multiply_numbers\n    \n    subroutine print_result(value)\n        real, intent(in) :: value\n        print *, \"Result is:\", value\n    end subroutine print_result\nend module math_utils\n\n"
  },
  {
    "path": "test/resources/repos/fsharp/test_repo/.gitignore",
    "content": "bin/\nobj/\n*.user\n.vscode/\n.ionide/"
  },
  {
    "path": "test/resources/repos/fsharp/test_repo/Calculator.fs",
    "content": "module Calculator\n\n/// Simple calculator functions\nlet add a b = a + b\n\nlet subtract a b = a - b\n\nlet multiply a b = a * b\n\nlet divide a b =\n    if b = 0 then\n        failwith \"Cannot divide by zero\"\n    else\n        (float a) / (float b)\n\n/// More complex operations\nlet square x = x * x\n\nlet factorial n =\n    if n <= 0 then 1\n    else\n        let rec factorialHelper acc n =\n            if n <= 1 then acc\n            else factorialHelper (acc * n) (n - 1)\n        factorialHelper 1 n\n\n/// Calculator type with instance methods\ntype CalculatorClass() =\n    member this.Add(a, b) = add a b\n    member this.Subtract(a, b) = subtract a b\n    member this.Multiply(a, b) = multiply a b\n    member this.Divide(a, b) = divide a b"
  },
  {
    "path": "test/resources/repos/fsharp/test_repo/Models/Person.fs",
    "content": "namespace Models\n\n/// Person record type\ntype Person = {\n    Name: string\n    Age: int\n    Email: string option\n}\n\nmodule PersonModule =\n    /// Create a new person\n    let createPerson name age email =\n        { Name = name; Age = age; Email = email }\n    \n    /// Check if person is an adult\n    let isAdult person =\n        person.Age >= 18\n    \n    /// Get display name\n    let getDisplayName person =\n        match person.Email with\n        | Some email -> $\"{person.Name} ({email})\"\n        | None -> person.Name\n    \n    /// Update person age\n    let updateAge newAge person =\n        { person with Age = newAge }\n\n/// Address type\ntype Address = {\n    Street: string\n    City: string\n    ZipCode: string\n    Country: string\n}\n\n/// Employee type that extends Person concept\ntype Employee = {\n    Person: Person\n    EmployeeId: int\n    Department: string\n    Salary: decimal\n    Address: Address option\n}"
  },
  {
    "path": "test/resources/repos/fsharp/test_repo/Program.fs",
    "content": "module Program\n\nopen Calculator\nopen Models\n\n[<EntryPoint>]\nlet main argv =\n    printfn \"Hello, F# World!\"\n    \n    // Test calculator functions\n    let result1 = add 5 3\n    printfn \"5 + 3 = %d\" result1\n    \n    let result2 = subtract 10 4\n    printfn \"10 - 4 = %d\" result2\n    \n    let result3 = multiply 6 7\n    printfn \"6 * 7 = %d\" result3\n    \n    let result4 = divide 15 3\n    printfn \"15 / 3 = %.2f\" result4\n    \n    // Test calculator class\n    let calc = CalculatorClass()\n    let classResult = calc.Add(20, 5)\n    printfn \"Calculator class: 20 + 5 = %d\" classResult\n    \n    // Test person module\n    let person = PersonModule.createPerson \"Alice Smith\" 25 (Some \"alice@example.com\")\n    printfn \"Person: %s\" (PersonModule.getDisplayName person)\n    printfn \"Is adult: %b\" (PersonModule.isAdult person)\n    \n    // Test factorial\n    let fact5 = factorial 5\n    printfn \"5! = %d\" fact5\n    \n    0 // return success"
  },
  {
    "path": "test/resources/repos/fsharp/test_repo/README.md",
    "content": "# F# Test Project\n\nThis is a test F# project for testing Serena's F# language support.\n\n## Project Structure\n\n- `Program.fs` - Main program entry point\n- `Calculator.fs` - Calculator functions and types\n- `Models/Person.fs` - Person and Employee data models\n\n## Build\n\n```bash\ndotnet build\n```\n\n## Run\n\n```bash\ndotnet run\n```"
  },
  {
    "path": "test/resources/repos/fsharp/test_repo/TestProject.fsproj",
    "content": "<Project Sdk=\"Microsoft.NET.Sdk\">\n\n  <PropertyGroup>\n    <OutputType>Exe</OutputType>\n    <TargetFramework>net8.0</TargetFramework>\n  </PropertyGroup>\n\n  <ItemGroup>\n    <Compile Include=\"Calculator.fs\" />\n    <Compile Include=\"Models/Person.fs\" />\n    <Compile Include=\"Program.fs\" />\n  </ItemGroup>\n\n</Project>"
  },
  {
    "path": "test/resources/repos/go/test_repo/buildtags/foo.go",
    "content": "//go:build foo\n// +build foo\n\npackage buildtags\n\ntype XFoo struct {\n\tValue int\n}\n"
  },
  {
    "path": "test/resources/repos/go/test_repo/buildtags/notfoo.go",
    "content": "//go:build !foo\n// +build !foo\n\npackage buildtags\n\ntype XNotFoo struct {\n\tValue int\n}\n"
  },
  {
    "path": "test/resources/repos/go/test_repo/go.mod",
    "content": "module test_repo\n\ngo 1.21\n"
  },
  {
    "path": "test/resources/repos/go/test_repo/main.go",
    "content": "package main\n\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"Hello, Go!\")\n    Helper()\n}\n\nfunc Helper() {\n    fmt.Println(\"Helper function called\")\n}\n\ntype DemoStruct struct {\n    Field int\n}\n\nfunc UsingHelper() {\n    Helper()\n}\n"
  },
  {
    "path": "test/resources/repos/groovy/test_repo/.gitignore",
    "content": ".gradle/\n"
  },
  {
    "path": "test/resources/repos/groovy/test_repo/build.gradle",
    "content": "plugins {\n    id 'groovy'\n}\n\nrepositories {\n    mavenCentral()\n}\n"
  },
  {
    "path": "test/resources/repos/groovy/test_repo/src/main/groovy/com/example/Main.groovy",
    "content": "package com.example\n\nclass Main {\n    static void main(String[] args) {\n        Utils.printHello()\n        Model model = new Model(\"Cascade\")\n        println(model.name)\n    }\n}\n"
  },
  {
    "path": "test/resources/repos/groovy/test_repo/src/main/groovy/com/example/Model.groovy",
    "content": "package com.example\n\nclass Model {\n    String name\n\n    Model(String name) {\n        this.name = name\n    }\n}\n"
  },
  {
    "path": "test/resources/repos/groovy/test_repo/src/main/groovy/com/example/ModelUser.groovy",
    "content": "package com.example\n\nclass ModelUser {\n    static void main(String[] args) {\n        Model model = new Model(\"Cascade\")\n        println(model.name)\n    }\n}\n"
  },
  {
    "path": "test/resources/repos/groovy/test_repo/src/main/groovy/com/example/Utils.groovy",
    "content": "package com.example\n\nclass Utils {\n    static void printHello() {\n        println(\"Hello from Utils!\")\n    }\n}\n"
  },
  {
    "path": "test/resources/repos/haskell/test_repo/app/Main.hs",
    "content": "module Main (main) where\n\nimport Calculator\nimport Helper\n\nmain :: IO ()\nmain = do\n    let calc = Calculator \"TestCalc\" 1\n    putStrLn $ \"Using \" ++ calcName calc ++ \" version \" ++ show (calcVersion calc)\n\n    -- Test add function (cross-file reference)\n    let result1 = add 5 3\n    putStrLn $ \"5 + 3 = \" ++ show result1\n\n    -- Test subtract (uses validateNumber from Helper)\n    let result2 = Calculator.subtract 10 4\n    putStrLn $ \"10 - 4 = \" ++ show result2\n\n    -- Test calculate function\n    case calculate calc \"multiply\" 6 7 of\n        Just result -> putStrLn $ \"6 * 7 = \" ++ show result\n        Nothing -> putStrLn \"Calculation failed\"\n\n    -- Test helper functions directly\n    putStrLn $ \"Is 5 positive? \" ++ show (isPositive 5)\n    putStrLn $ \"Absolute of -10: \" ++ show (absolute (-10))\n"
  },
  {
    "path": "test/resources/repos/haskell/test_repo/package.yaml",
    "content": "name: haskell-test-repo\nversion: 0.1.0.0\ngithub: \"test/haskell-test-repo\"\nlicense: BSD3\nauthor: \"Test Author\"\nmaintainer: \"test@example.com\"\n\ndependencies:\n  - base >= 4.7 && < 5\n\nlibrary:\n  source-dirs: src\n  exposed-modules:\n    - Calculator\n    - Helper\n\nexecutables:\n  haskell-test-repo-exe:\n    main: Main.hs\n    source-dirs: app\n    dependencies:\n      - haskell-test-repo\n\ndefault-extensions:\n  - OverloadedStrings\n"
  },
  {
    "path": "test/resources/repos/haskell/test_repo/src/Calculator.hs",
    "content": "module Calculator\n    ( Calculator(..)\n    , add\n    , subtract\n    , multiply\n    , divide\n    , calculate\n    ) where\n\nimport Prelude hiding (subtract)\nimport Helper (validateNumber)\n\n-- | A simple calculator data type\ndata Calculator = Calculator\n    { calcName :: String\n    , calcVersion :: Int\n    } deriving (Show, Eq)\n\n-- | Add two numbers\nadd :: Int -> Int -> Int\nadd x y = validateNumber x + validateNumber y\n\n-- | Subtract two numbers\nsubtract :: Int -> Int -> Int\nsubtract x y = validateNumber x - validateNumber y\n\n-- | Multiply two numbers\nmultiply :: Int -> Int -> Int\nmultiply x y = x * y\n\n-- | Divide two numbers (returns Maybe to handle division by zero)\ndivide :: Int -> Int -> Maybe Int\ndivide _ 0 = Nothing\ndivide x y = Just (x `div` y)\n\n-- | Perform a calculation based on operator\ncalculate :: Calculator -> String -> Int -> Int -> Maybe Int\ncalculate calc op x y = case op of\n    \"add\"      -> Just (add x y)\n    \"subtract\" -> Just (subtract x y)\n    \"multiply\" -> Just (multiply x y)\n    \"divide\"   -> divide x y\n    _          -> Nothing\n"
  },
  {
    "path": "test/resources/repos/haskell/test_repo/src/Helper.hs",
    "content": "module Helper\n    ( validateNumber\n    , isPositive\n    , isNegative\n    , absolute\n    ) where\n\n-- | Validate that a number is not zero (for demonstration)\nvalidateNumber :: Int -> Int\nvalidateNumber x = if x == 0 then error \"Zero not allowed\" else x\n\n-- | Check if a number is positive\nisPositive :: Int -> Bool\nisPositive x = x > 0\n\n-- | Check if a number is negative\nisNegative :: Int -> Bool\nisNegative x = x < 0\n\n-- | Get absolute value\nabsolute :: Int -> Int\nabsolute x = if isNegative x then negate x else x\n"
  },
  {
    "path": "test/resources/repos/haskell/test_repo/stack.yaml",
    "content": "resolver: ghc-9.8.4\nsystem-ghc: true\ninstall-ghc: false\npackages:\n  - .\n"
  },
  {
    "path": "test/resources/repos/hlsl/test_repo/common.hlsl",
    "content": "#ifndef COMMON_HLSL\n#define COMMON_HLSL\n\nstruct VertexInput\n{\n    float3 position : POSITION;\n    float3 normal : NORMAL;\n    float2 uv : TEXCOORD0;\n};\n\nstruct VertexOutput\n{\n    float4 clipPos : SV_POSITION;\n    float3 worldNormal : TEXCOORD0;\n    float2 uv : TEXCOORD1;\n};\n\nfloat3 SafeNormalize(float3 v)\n{\n    float len = length(v);\n    return len > 0.0001 ? v / len : float3(0, 0, 0);\n}\n\nfloat Remap(float value, float fromMin, float fromMax, float toMin, float toMax)\n{\n    return toMin + (value - fromMin) * (toMax - toMin) / (fromMax - fromMin);\n}\n\n#endif // COMMON_HLSL\n"
  },
  {
    "path": "test/resources/repos/hlsl/test_repo/compute_test.hlsl",
    "content": "#include \"common.hlsl\"\n\nRWTexture2D<float4> OutputTexture : register(u0);\nTexture2D<float4> InputTexture : register(t0);\n\ncbuffer ComputeParams : register(b0)\n{\n    uint2 TextureSize;\n    float BlurRadius;\n    float _Pad;\n};\n\n[numthreads(8, 8, 1)]\nvoid CSMain(uint3 id : SV_DispatchThreadID)\n{\n    if (id.x >= TextureSize.x || id.y >= TextureSize.y)\n        return;\n\n    float4 color = InputTexture[id.xy];\n    float3 remapped = float3(\n        Remap(color.r, 0.0, 1.0, 0.2, 0.8),\n        Remap(color.g, 0.0, 1.0, 0.2, 0.8),\n        Remap(color.b, 0.0, 1.0, 0.2, 0.8)\n    );\n    OutputTexture[id.xy] = float4(remapped, color.a);\n}\n"
  },
  {
    "path": "test/resources/repos/hlsl/test_repo/lighting.hlsl",
    "content": "#ifndef LIGHTING_HLSL\n#define LIGHTING_HLSL\n\n#include \"common.hlsl\"\n\ncbuffer LightingConstants : register(b0)\n{\n    float4x4 ViewProjection;\n    float3 LightDirection;\n    float LightIntensity;\n    float3 AmbientColor;\n    float _Padding;\n};\n\nfloat3 CalculateDiffuse(float3 normal, float3 lightDir, float3 albedo)\n{\n    float ndotl = max(dot(normal, -lightDir), 0.0);\n    return albedo * ndotl;\n}\n\nfloat3 CalculateSpecular(float3 normal, float3 lightDir, float3 viewDir, float shininess)\n{\n    float3 halfVec = SafeNormalize(-lightDir + viewDir);\n    float ndoth = max(dot(normal, halfVec), 0.0);\n    return pow(ndoth, shininess);\n}\n\nVertexOutput TransformVertex(VertexInput input)\n{\n    VertexOutput output;\n    output.clipPos = mul(ViewProjection, float4(input.position, 1.0));\n    output.worldNormal = input.normal;\n    output.uv = input.uv;\n    return output;\n}\n\n#endif // LIGHTING_HLSL\n"
  },
  {
    "path": "test/resources/repos/hlsl/test_repo/terrain/terrain_sdf.hlsl",
    "content": "#ifndef TERRAIN_SDF_HLSL\n#define TERRAIN_SDF_HLSL\n\n#include \"../common.hlsl\"\n\nstruct SDFBrickData\n{\n    float3 center;\n    float halfExtent;\n    int resolution;\n    float maxDistance;\n};\n\nfloat3 WorldOffset;\n\nfloat SampleSDF(float3 worldPos, SDFBrickData brick)\n{\n    float3 localPos = worldPos - brick.center;\n    float dist = length(localPos) - brick.halfExtent;\n    return dist;\n}\n\nfloat3 CalculateGradient(float3 worldPos, SDFBrickData brick)\n{\n    float eps = 0.01;\n    float3 gradient;\n    gradient.x = SampleSDF(worldPos + float3(eps, 0, 0), brick) - SampleSDF(worldPos - float3(eps, 0, 0), brick);\n    gradient.y = SampleSDF(worldPos + float3(0, eps, 0), brick) - SampleSDF(worldPos - float3(0, eps, 0), brick);\n    gradient.z = SampleSDF(worldPos + float3(0, 0, eps), brick) - SampleSDF(worldPos - float3(0, 0, eps), brick);\n    return SafeNormalize(gradient);\n}\n\n#endif // TERRAIN_SDF_HLSL\n"
  },
  {
    "path": "test/resources/repos/java/test_repo/pom.xml",
    "content": "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n         xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n    <modelVersion>4.0.0</modelVersion>\n    <groupId>org.example</groupId>\n    <artifactId>test_repo</artifactId>\n    <version>1.0-SNAPSHOT</version>\n    <packaging>jar</packaging>\n    <name>Java Test Repo</name>\n    <properties>\n        <maven.compiler.source>21</maven.compiler.source>\n        <maven.compiler.target>21</maven.compiler.target>\n        <maven.compiler.plugin.version>3.13.0</maven.compiler.plugin.version>\n    </properties>\n    \n    <build>\n        <plugins>\n            <plugin>\n                <groupId>org.apache.maven.plugins</groupId>\n                <artifactId>maven-compiler-plugin</artifactId>\n                <version>${maven.compiler.plugin.version}</version>\n                <configuration>\n                    <source>21</source>\n                    <target>21</target>\n                </configuration>\n            </plugin>\n        </plugins>\n    </build>\n</project>\n"
  },
  {
    "path": "test/resources/repos/java/test_repo/src/main/java/test_repo/Main.java",
    "content": "package test_repo;\n\npublic class Main {\n    public static void main(String[] args) {\n        Utils.printHello();\n        Model model = new Model(\"Cascade\");\n        System.out.println(model.getName());\n        acceptModel(model);\n    }\n    public static void acceptModel(Model m) {\n        // Do nothing, just for LSP reference\n    }\n}\n"
  },
  {
    "path": "test/resources/repos/java/test_repo/src/main/java/test_repo/Model.java",
    "content": "package test_repo;\n\n/**\n * A simple model class that holds a name and provides methods to retrieve it.\n */\npublic class Model {\n    private String name;\n\n    public Model(String name) {\n        this.name = name;\n    }\n\n    public String getName() {\n        return name;\n    }\n\n    public String getName(int maxChars) {\n        if (name.length() <= maxChars) {\n            return name;\n        } else {\n            return name.substring(0, maxChars) + \"...\";\n        }\n    }\n}\n"
  },
  {
    "path": "test/resources/repos/java/test_repo/src/main/java/test_repo/ModelUser.java",
    "content": "package test_repo;\n\npublic class ModelUser {\n    public static void main(String[] args) {\n        Model model = new Model(\"Cascade\");\n        System.out.println(model.getName());\n    }\n}\n"
  },
  {
    "path": "test/resources/repos/java/test_repo/src/main/java/test_repo/Utils.java",
    "content": "package test_repo;\n\npublic class Utils {\n    public static void printHello() {\n        System.out.println(\"Hello from Utils!\");\n    }\n}\n"
  },
  {
    "path": "test/resources/repos/julia/test_repo/lib/helper.jl",
    "content": "module Helper\n    function say_hello()\n        println(\"Hello from the helper module!\")\n    end\nend\n"
  },
  {
    "path": "test/resources/repos/julia/test_repo/main.jl",
    "content": "include(\"lib/helper.jl\")\n\nfunction calculate_sum(a, b)\n    return a + b\nend\n\nfunction main()\n    result = calculate_sum(5, 3)  # A within-file reference\n    println(result)\n    Helper.say_hello()            # A cross-file reference\nend\n\nmain()\n"
  },
  {
    "path": "test/resources/repos/kotlin/test_repo/.gitignore",
    "content": ".gradle/\n"
  },
  {
    "path": "test/resources/repos/kotlin/test_repo/build.gradle.kts",
    "content": "plugins {\n    kotlin(\"jvm\") version \"1.9.21\"\n    application\n}\n\ngroup = \"test.serena\"\nversion = \"1.0-SNAPSHOT\"\n\nrepositories {\n    mavenCentral()\n}"
  },
  {
    "path": "test/resources/repos/kotlin/test_repo/src/main/kotlin/test_repo/Main.kt",
    "content": "package test_repo\n\nobject Main {\n    @JvmStatic\n    fun main(args: Array<String>) {\n        Utils.printHello()\n        val model = Model(\"Cascade\")\n        println(model.name)\n        acceptModel(model)\n    }\n\n    fun acceptModel(m: Model?) {\n        // Do nothing, just for LSP reference\n    }\n}"
  },
  {
    "path": "test/resources/repos/kotlin/test_repo/src/main/kotlin/test_repo/Model.kt",
    "content": "package test_repo\n\ndata class Model(val name: String)"
  },
  {
    "path": "test/resources/repos/kotlin/test_repo/src/main/kotlin/test_repo/ModelUser.kt",
    "content": "package test_repo\n\nobject ModelUser {\n    @JvmStatic\n    fun main(args: Array<String>) {\n        val model = Model(\"Cascade\")\n        println(model.name)\n    }\n}"
  },
  {
    "path": "test/resources/repos/kotlin/test_repo/src/main/kotlin/test_repo/Utils.kt",
    "content": "package test_repo\n\nobject Utils {\n    fun printHello() {\n        println(\"Hello from Utils!\")\n    }\n}"
  },
  {
    "path": "test/resources/repos/lean4/test_repo/Helper.lean",
    "content": "structure Calculator where\n  name : String\n  version : Nat\n  deriving Repr\n\ndef add (x y : Nat) : Nat :=\n  x + y\n\ndef subtract (x y : Nat) : Int :=\n  Int.ofNat x - Int.ofNat y\n\ndef isPositive (x : Int) : Bool :=\n  x > 0\n\ndef absolute (x : Int) : Int :=\n  if isPositive x then x else -x\n"
  },
  {
    "path": "test/resources/repos/lean4/test_repo/Main.lean",
    "content": "import Helper\n\ndef multiply (x y : Nat) : Nat :=\n  x * y\n\ndef calculate (c : Calculator) (op : String) (x y : Nat) : Option Int :=\n  match op with\n  | \"add\" => some (Int.ofNat (add x y))\n  | \"subtract\" => some (subtract x y)\n  | \"multiply\" => some (Int.ofNat (multiply x y))\n  | _ => none\n\ndef main : IO Unit := do\n  let c : Calculator := { name := \"TestCalc\", version := 1 }\n  IO.println s!\"Using {c.name} version {c.version}\"\n  let result1 := add 5 3\n  IO.println s!\"5 + 3 = {result1}\"\n  let result2 := subtract 10 4\n  IO.println s!\"10 - 4 = {result2}\"\n  match calculate c \"multiply\" 6 7 with\n  | some result => IO.println s!\"6 * 7 = {result}\"\n  | none => IO.println \"Calculation failed\"\n  IO.println s!\"Is 5 positive? {isPositive 5}\"\n  IO.println s!\"Absolute of -10: {absolute (-10)}\"\n"
  },
  {
    "path": "test/resources/repos/lean4/test_repo/lake-manifest.json",
    "content": "{\"version\": \"1.1.0\",\n \"packagesDir\": \".lake/packages\",\n \"packages\": [],\n \"name\": \"test_repo\",\n \"lakeDir\": \".lake\"}\n"
  },
  {
    "path": "test/resources/repos/lean4/test_repo/lakefile.lean",
    "content": "import Lake\nopen Lake DSL\n\npackage «test_repo» where\n  leanOptions := #[⟨`autoImplicit, false⟩]\n\n@[default_target]\nlean_lib «Main» where\n  roots := #[`Main, `Helper]\n"
  },
  {
    "path": "test/resources/repos/lean4/test_repo/lean-toolchain",
    "content": "leanprover/lean4:stable\n"
  },
  {
    "path": "test/resources/repos/lua/test_repo/.gitignore",
    "content": "# Lua specific\n*.luac\n.luarocks/\nlua_modules/\nluarocks/\n\n# Build artifacts\nbuild/\ndist/\n\n# IDE\n.vscode/\n.idea/"
  },
  {
    "path": "test/resources/repos/lua/test_repo/main.lua",
    "content": "#!/usr/bin/env lua\n\n-- main.lua: Entry point for the test application\n\nlocal calculator = require(\"src.calculator\")\nlocal utils = require(\"src.utils\")\n\nlocal function print_banner()\n    print(\"=\" .. string.rep(\"=\", 40))\n    print(\"       Lua Test Repository\")\n    print(\"=\" .. string.rep(\"=\", 40))\nend\n\nlocal function test_calculator()\n    print(\"\\nTesting Calculator Module:\")\n    print(\"5 + 3 =\", calculator.add(5, 3))\n    print(\"10 - 4 =\", calculator.subtract(10, 4))\n    print(\"6 * 7 =\", calculator.multiply(6, 7))\n    print(\"15 / 3 =\", calculator.divide(15, 3))\n    print(\"2^8 =\", calculator.power(2, 8))\n    print(\"5! =\", calculator.factorial(5))\n    \n    local numbers = {5, 2, 8, 3, 9, 1, 7}\n    print(\"Mean of\", table.concat(numbers, \", \"), \"=\", calculator.mean(numbers))\n    print(\"Median of\", table.concat(numbers, \", \"), \"=\", calculator.median(numbers))\nend\n\nlocal function test_utils()\n    print(\"\\nTesting Utils Module:\")\n    \n    -- String utilities\n    print(\"Trimmed '  hello  ' =\", \"'\" .. utils.trim(\"  hello  \") .. \"'\")\n    local parts = utils.split(\"apple,banana,orange\", \",\")\n    print(\"Split 'apple,banana,orange' by ',' =\", table.concat(parts, \" | \"))\n    print(\"'hello' starts with 'he' =\", utils.starts_with(\"hello\", \"he\"))\n    print(\"'world' ends with 'ld' =\", utils.ends_with(\"world\", \"ld\"))\n    \n    -- Table utilities\n    local t1 = {a = 1, b = 2}\n    local t2 = {b = 3, c = 4}\n    local merged = utils.table_merge(t1, t2)\n    print(\"Merged tables: a=\" .. (merged.a or \"nil\") .. \n          \", b=\" .. (merged.b or \"nil\") .. \n          \", c=\" .. (merged.c or \"nil\"))\n    \n    -- Logger\n    local logger = utils.Logger:new(\"TestApp\")\n    logger:info(\"Application started\")\n    logger:debug(\"Debug information\")\n    logger:warn(\"This is a warning\")\nend\n\nlocal function interactive_calculator()\n    print(\"\\nInteractive Calculator (type 'quit' to exit):\")\n    while true do\n        io.write(\"Enter operation (e.g., '5 + 3'): \")\n        local input = io.read()\n        \n        if input == \"quit\" then\n            break\n        end\n        \n        -- Simple parser for basic operations\n        local a, op, b = input:match(\"(%d+)%s*([%+%-%*/])%s*(%d+)\")\n        if a and op and b then\n            a = tonumber(a)\n            b = tonumber(b)\n            local result\n            \n            if op == \"+\" then\n                result = calculator.add(a, b)\n            elseif op == \"-\" then\n                result = calculator.subtract(a, b)\n            elseif op == \"*\" then\n                result = calculator.multiply(a, b)\n            elseif op == \"/\" then\n                local success, res = pcall(calculator.divide, a, b)\n                if success then\n                    result = res\n                else\n                    print(\"Error: \" .. res)\n                    goto continue\n                end\n            end\n            \n            print(\"Result: \" .. result)\n        else\n            print(\"Invalid input. Please use format: number operator number\")\n        end\n        \n        ::continue::\n    end\nend\n\n-- Main execution\nlocal function main(args)\n    print_banner()\n    \n    if #args == 0 then\n        test_calculator()\n        test_utils()\n    elseif args[1] == \"interactive\" then\n        interactive_calculator()\n    elseif args[1] == \"test\" then\n        test_calculator()\n        test_utils()\n        print(\"\\nAll tests completed!\")\n    else\n        print(\"Usage: lua main.lua [interactive|test]\")\n    end\nend\n\n-- Run main function\nmain(arg or {})"
  },
  {
    "path": "test/resources/repos/lua/test_repo/src/calculator.lua",
    "content": "-- calculator.lua: A simple calculator module for testing LSP features\n\nlocal calculator = {}\n\n-- Basic arithmetic operations\nfunction calculator.add(a, b)\n    return a + b\nend\n\nfunction calculator.subtract(a, b)\n    return a - b\nend\n\nfunction calculator.multiply(a, b)\n    return a * b\nend\n\nfunction calculator.divide(a, b)\n    if b == 0 then\n        error(\"Division by zero\")\n    end\n    return a / b\nend\n\n-- Advanced operations\nfunction calculator.power(base, exponent)\n    return base ^ exponent\nend\n\nfunction calculator.factorial(n)\n    if n < 0 then\n        error(\"Factorial is not defined for negative numbers\")\n    elseif n == 0 or n == 1 then\n        return 1\n    else\n        local result = 1\n        for i = 2, n do\n            result = result * i\n        end\n        return result\n    end\nend\n\n-- Statistics functions\nfunction calculator.mean(numbers)\n    if #numbers == 0 then\n        return nil\n    end\n    \n    local sum = 0\n    for _, num in ipairs(numbers) do\n        sum = sum + num\n    end\n    return sum / #numbers\nend\n\nfunction calculator.median(numbers)\n    if #numbers == 0 then\n        return nil\n    end\n    \n    local sorted = {}\n    for i, v in ipairs(numbers) do\n        sorted[i] = v\n    end\n    table.sort(sorted)\n    \n    local mid = math.floor(#sorted / 2)\n    if #sorted % 2 == 0 then\n        return (sorted[mid] + sorted[mid + 1]) / 2\n    else\n        return sorted[mid + 1]\n    end\nend\n\nreturn calculator"
  },
  {
    "path": "test/resources/repos/lua/test_repo/src/utils.lua",
    "content": "-- utils.lua: Utility functions for the test repository\n\nlocal utils = {}\n\n-- String utilities\nfunction utils.trim(s)\n    return s:match(\"^%s*(.-)%s*$\")\nend\n\nfunction utils.split(str, delimiter)\n    local result = {}\n    local pattern = string.format(\"([^%s]+)\", delimiter)\n    for match in string.gmatch(str, pattern) do\n        table.insert(result, match)\n    end\n    return result\nend\n\nfunction utils.starts_with(str, prefix)\n    return str:sub(1, #prefix) == prefix\nend\n\nfunction utils.ends_with(str, suffix)\n    return str:sub(-#suffix) == suffix\nend\n\n-- Table utilities\nfunction utils.deep_copy(orig)\n    local orig_type = type(orig)\n    local copy\n    if orig_type == 'table' then\n        copy = {}\n        for orig_key, orig_value in next, orig, nil do\n            copy[utils.deep_copy(orig_key)] = utils.deep_copy(orig_value)\n        end\n        setmetatable(copy, utils.deep_copy(getmetatable(orig)))\n    else\n        copy = orig\n    end\n    return copy\nend\n\nfunction utils.table_contains(tbl, value)\n    for _, v in ipairs(tbl) do\n        if v == value then\n            return true\n        end\n    end\n    return false\nend\n\nfunction utils.table_merge(t1, t2)\n    local result = {}\n    for k, v in pairs(t1) do\n        result[k] = v\n    end\n    for k, v in pairs(t2) do\n        result[k] = v\n    end\n    return result\nend\n\n-- File utilities\nfunction utils.read_file(path)\n    local file = io.open(path, \"r\")\n    if not file then\n        return nil, \"Could not open file: \" .. path\n    end\n    local content = file:read(\"*all\")\n    file:close()\n    return content\nend\n\nfunction utils.write_file(path, content)\n    local file = io.open(path, \"w\")\n    if not file then\n        return false, \"Could not open file for writing: \" .. path\n    end\n    file:write(content)\n    file:close()\n    return true\nend\n\n-- Class-like structure\nutils.Logger = {}\nutils.Logger.__index = utils.Logger\n\nfunction utils.Logger:new(name)\n    local self = setmetatable({}, utils.Logger)\n    self.name = name or \"default\"\n    self.level = \"info\"\n    return self\nend\n\nfunction utils.Logger:set_level(level)\n    self.level = level\nend\n\nfunction utils.Logger:log(message, level)\n    level = level or self.level\n    print(string.format(\"[%s] %s: %s\", self.name, level:upper(), message))\nend\n\nfunction utils.Logger:debug(message)\n    self:log(message, \"debug\")\nend\n\nfunction utils.Logger:info(message)\n    self:log(message, \"info\")\nend\n\nfunction utils.Logger:warn(message)\n    self:log(message, \"warn\")\nend\n\nfunction utils.Logger:error(message)\n    self:log(message, \"error\")\nend\n\nreturn utils"
  },
  {
    "path": "test/resources/repos/lua/test_repo/tests/test_calculator.lua",
    "content": "-- test_calculator.lua: Unit tests for calculator module\n\nlocal calculator = require(\"src.calculator\")\n\nlocal function assert_equals(actual, expected, message)\n    if actual ~= expected then\n        error(string.format(\"%s: expected %s, got %s\", \n            message or \"Assertion failed\", tostring(expected), tostring(actual)))\n    end\nend\n\nlocal function assert_error(func, message)\n    local success = pcall(func)\n    if success then\n        error(string.format(\"%s: expected error but none was thrown\", \n            message or \"Assertion failed\"))\n    end\nend\n\nlocal function test_basic_operations()\n    print(\"Testing basic operations...\")\n    assert_equals(calculator.add(2, 3), 5, \"Addition test\")\n    assert_equals(calculator.add(-5, 5), 0, \"Addition with negative\")\n    assert_equals(calculator.add(0, 0), 0, \"Addition with zeros\")\n    \n    assert_equals(calculator.subtract(10, 3), 7, \"Subtraction test\")\n    assert_equals(calculator.subtract(5, 10), -5, \"Subtraction negative result\")\n    \n    assert_equals(calculator.multiply(4, 5), 20, \"Multiplication test\")\n    assert_equals(calculator.multiply(-3, 4), -12, \"Multiplication with negative\")\n    assert_equals(calculator.multiply(0, 100), 0, \"Multiplication with zero\")\n    \n    assert_equals(calculator.divide(10, 2), 5, \"Division test\")\n    assert_equals(calculator.divide(7, 2), 3.5, \"Division with decimal result\")\n    assert_error(function() calculator.divide(5, 0) end, \"Division by zero\")\n    \n    print(\"✓ Basic operations tests passed\")\nend\n\nlocal function test_advanced_operations()\n    print(\"Testing advanced operations...\")\n    assert_equals(calculator.power(2, 3), 8, \"Power test\")\n    assert_equals(calculator.power(5, 0), 1, \"Power of zero\")\n    assert_equals(calculator.power(10, -1), 0.1, \"Negative exponent\")\n    \n    assert_equals(calculator.factorial(0), 1, \"Factorial of 0\")\n    assert_equals(calculator.factorial(1), 1, \"Factorial of 1\")\n    assert_equals(calculator.factorial(5), 120, \"Factorial of 5\")\n    assert_equals(calculator.factorial(10), 3628800, \"Factorial of 10\")\n    assert_error(function() calculator.factorial(-1) end, \"Factorial of negative\")\n    \n    print(\"✓ Advanced operations tests passed\")\nend\n\nlocal function test_statistics()\n    print(\"Testing statistics functions...\")\n    \n    -- Mean tests\n    assert_equals(calculator.mean({1, 2, 3, 4, 5}), 3, \"Mean of sequential numbers\")\n    assert_equals(calculator.mean({10}), 10, \"Mean of single number\")\n    assert_equals(calculator.mean({-5, 5}), 0, \"Mean with negatives\")\n    assert_equals(calculator.mean({}), nil, \"Mean of empty array\")\n    \n    -- Median tests\n    assert_equals(calculator.median({1, 2, 3, 4, 5}), 3, \"Median of odd count\")\n    assert_equals(calculator.median({1, 2, 3, 4}), 2.5, \"Median of even count\")\n    assert_equals(calculator.median({5, 1, 3, 2, 4}), 3, \"Median of unsorted\")\n    assert_equals(calculator.median({7}), 7, \"Median of single number\")\n    assert_equals(calculator.median({}), nil, \"Median of empty array\")\n    \n    print(\"✓ Statistics tests passed\")\nend\n\n-- Run all tests\nlocal function run_all_tests()\n    print(\"Running calculator tests...\\n\")\n    test_basic_operations()\n    test_advanced_operations()\n    test_statistics()\n    print(\"\\n✅ All calculator tests passed!\")\nend\n\n-- Execute tests if run directly\nif arg and arg[0] and arg[0]:match(\"test_calculator%.lua$\") then\n    run_all_tests()\nend\n\nreturn {\n    run_all_tests = run_all_tests,\n    test_basic_operations = test_basic_operations,\n    test_advanced_operations = test_advanced_operations,\n    test_statistics = test_statistics\n}"
  },
  {
    "path": "test/resources/repos/luau/test_repo/.luaurc",
    "content": "{\n    \"languageMode\": \"strict\",\n    \"lint\": {\n        \"*\": true\n    },\n    \"aliases\": {\n        \"Packages\": \"Packages/\"\n    }\n}"
  },
  {
    "path": "test/resources/repos/luau/test_repo/src/init.luau",
    "content": "local module = require(\"./module\")\n\nexport type Config = {\n    name: string,\n    value: number,\n    enabled: boolean,\n}\n\nlocal function createConfig(name: string, value: number): Config\n    return {\n        name = name,\n        value = value,\n        enabled = true,\n    }\nend\n\nlocal function main()\n    local config = createConfig(\"test\", 42)\n    local result = module.process(config)\n    print(result)\nend\n\nreturn {\n    createConfig = createConfig,\n    main = main,\n}"
  },
  {
    "path": "test/resources/repos/luau/test_repo/src/module.luau",
    "content": "local function process(data: { name: string, value: number }): string\n    return `Processing {data.name} with value {data.value}`\nend\n\nlocal function helper(x: number, y: number): number\n    return x + y\nend\n\nreturn {\n    process = process,\n    helper = helper,\n}"
  },
  {
    "path": "test/resources/repos/markdown/test_repo/CONTRIBUTING.md",
    "content": "# Contributing Guidelines\n\nThank you for considering contributing to this project!\n\n## Table of Contents\n\n- [Code of Conduct](#code-of-conduct)\n- [Getting Started](#getting-started)\n- [Development Setup](#development-setup)\n- [Submitting Changes](#submitting-changes)\n\n## Code of Conduct\n\nPlease be respectful and considerate in all interactions.\n\n## Getting Started\n\nTo contribute:\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Submit a pull request\n\n## Development Setup\n\n### Prerequisites\n\n- Git\n- Node.js (v16+)\n- npm or yarn\n\n### Installation Steps\n\n```bash\ngit clone https://github.com/example/repo.git\ncd repo\nnpm install\n```\n\n## Submitting Changes\n\n### Pull Request Process\n\n1. Update documentation\n2. Add tests for new features\n3. Ensure all tests pass\n4. Update the [README](README.md)\n\n### Commit Messages\n\nUse clear and descriptive commit messages:\n\n- feat: Add new feature\n- fix: Bug fix\n- docs: Documentation changes\n- test: Add or update tests\n\n## Testing\n\nRun the test suite before submitting:\n\n```bash\nnpm test\n```\n\nFor more information, see:\n\n- [User Guide](guide.md)\n- [API Reference](api.md)\n\n## Questions?\n\nContact the maintainers or open an issue.\n"
  },
  {
    "path": "test/resources/repos/markdown/test_repo/README.md",
    "content": "# Test Repository\n\nThis is a test repository for markdown language server testing.\n\n## Overview\n\nThis repository contains sample markdown files for testing LSP features.\n\n## Features\n\n- Document symbol detection\n- Link navigation\n- Reference finding\n- Code completion\n\n### Installation\n\nTo use this test repository:\n\n1. Clone the repository\n2. Install dependencies\n3. Run tests\n\n### Usage\n\nSee [guide.md](guide.md) for detailed usage instructions.\n\n## Code Examples\n\nHere's a simple example:\n\n```python\ndef hello_world():\n    print(\"Hello, World!\")\n```\n\n### JavaScript Example\n\n```javascript\nfunction greet(name) {\n    console.log(`Hello, ${name}!`);\n}\n```\n\n## References\n\n- [Official Documentation](https://example.com/docs)\n- [API Reference](api.md)\n- [Contributing Guide](CONTRIBUTING.md)\n\n## License\n\nMIT License\n"
  },
  {
    "path": "test/resources/repos/markdown/test_repo/api.md",
    "content": "# API Reference\n\nComplete API documentation for the test repository.\n\n## Classes\n\n### Client\n\nThe main client class for interacting with the API.\n\n#### Methods\n\n##### `connect()`\n\nEstablishes a connection to the server.\n\n**Parameters:**\n- `host`: Server hostname\n- `port`: Server port number\n\n**Returns:** Connection object\n\n##### `disconnect()`\n\nCloses the connection to the server.\n\n**Returns:** None\n\n### Server\n\nServer-side implementation.\n\n#### Configuration\n\n```json\n{\n  \"host\": \"localhost\",\n  \"port\": 8080,\n  \"timeout\": 30\n}\n```\n\n## Functions\n\n### `initialize(config)`\n\nInitializes the system with the provided configuration.\n\n**Parameters:**\n- `config`: Configuration dictionary\n\n**Example:**\n\n```python\nconfig = {\n    \"host\": \"localhost\",\n    \"port\": 8080\n}\ninitialize(config)\n```\n\n### `shutdown()`\n\nGracefully shuts down the system.\n\n## Error Handling\n\nCommon errors and their solutions:\n\n- `ConnectionError`: Check network connectivity\n- `TimeoutError`: Increase timeout value\n- `ConfigError`: Validate configuration file\n\n## See Also\n\n- [User Guide](guide.md)\n- [README](README.md)\n- [Contributing](CONTRIBUTING.md)\n"
  },
  {
    "path": "test/resources/repos/markdown/test_repo/guide.md",
    "content": "# User Guide\n\nThis guide provides detailed instructions for using the test repository.\n\n## Getting Started\n\nWelcome to the user guide. This document covers:\n\n- Basic concepts\n- Advanced features\n- Troubleshooting\n\n### Basic Concepts\n\nThe fundamental concepts you need to understand:\n\n#### Headers and Structure\n\nMarkdown documents use headers to create structure. Headers are created using `#` symbols.\n\n#### Links and References\n\nInternal links can reference other documents:\n\n- [Back to README](README.md)\n- [See API documentation](api.md)\n\n### Advanced Features\n\nFor advanced users, we provide:\n\n1. Custom extensions\n2. Plugin support\n3. Theme customization\n\n## Configuration\n\nConfiguration options are stored in `config.yaml`:\n\n```yaml\nserver:\n  port: 8080\n  host: localhost\n```\n\n## Troubleshooting\n\nIf you encounter issues:\n\n1. Check the [README](README.md) first\n2. Review [common issues](CONTRIBUTING.md)\n3. Contact support\n\n## Next Steps\n\nAfter reading this guide, check out:\n\n- [API Reference](api.md)\n- [Contributing Guidelines](CONTRIBUTING.md)\n"
  },
  {
    "path": "test/resources/repos/matlab/test_repo/Calculator.m",
    "content": "classdef Calculator < handle\n    % Calculator A simple calculator class for testing MATLAB LSP\n    %\n    % This class provides basic arithmetic operations and demonstrates\n    % MATLAB class structure for LSP testing purposes.\n\n    properties\n        LastResult double = 0\n        History cell = {}\n    end\n\n    properties (Access = private)\n        OperationCount uint32 = 0\n    end\n\n    methods\n        function obj = Calculator()\n            % Constructor for Calculator class\n            obj.LastResult = 0;\n            obj.History = {};\n            obj.OperationCount = 0;\n        end\n\n        function result = add(obj, a, b)\n            % ADD Add two numbers\n            %   result = add(obj, a, b) returns the sum of a and b\n            result = a + b;\n            obj.updateState(result, 'add');\n        end\n\n        function result = subtract(obj, a, b)\n            % SUBTRACT Subtract b from a\n            %   result = subtract(obj, a, b) returns a - b\n            result = a - b;\n            obj.updateState(result, 'subtract');\n        end\n\n        function result = multiply(obj, a, b)\n            % MULTIPLY Multiply two numbers\n            %   result = multiply(obj, a, b) returns a * b\n            result = a * b;\n            obj.updateState(result, 'multiply');\n        end\n\n        function result = divide(obj, a, b)\n            % DIVIDE Divide a by b\n            %   result = divide(obj, a, b) returns a / b\n            %   Throws error if b is zero\n            if b == 0\n                error('Calculator:DivisionByZero', 'Cannot divide by zero');\n            end\n            result = a / b;\n            obj.updateState(result, 'divide');\n        end\n\n        function displayHistory(obj)\n            % DISPLAYHISTORY Display the calculation history\n            fprintf('Calculation History:\\n');\n            for i = 1:length(obj.History)\n                fprintf('  %d: %s = %.4f\\n', i, obj.History{i}.operation, obj.History{i}.result);\n            end\n        end\n    end\n\n    methods (Access = private)\n        function updateState(obj, result, operation)\n            % Update internal state after an operation\n            obj.LastResult = result;\n            obj.OperationCount = obj.OperationCount + 1;\n            obj.History{end+1} = struct('operation', operation, 'result', result);\n        end\n    end\n\n    methods (Static)\n        function result = power(base, exponent)\n            % POWER Compute base raised to exponent\n            %   result = Calculator.power(base, exponent) returns base^exponent\n            result = base ^ exponent;\n        end\n    end\nend\n"
  },
  {
    "path": "test/resources/repos/matlab/test_repo/main.m",
    "content": "% MAIN Main script demonstrating Calculator and mathUtils usage\n%\n% This script shows how to use the Calculator class and mathUtils\n% functions together for various mathematical operations.\n\n% Add lib folder to path\naddpath('lib');\n\n%% Section 1: Basic Calculator Operations\n% Create a calculator instance and perform basic operations\n\ncalc = Calculator();\n\n% Perform some calculations\nsum_result = calc.add(10, 5);\nfprintf('10 + 5 = %d\\n', sum_result);\n\ndiff_result = calc.subtract(10, 3);\nfprintf('10 - 3 = %d\\n', diff_result);\n\nprod_result = calc.multiply(4, 7);\nfprintf('4 * 7 = %d\\n', prod_result);\n\nquot_result = calc.divide(20, 4);\nfprintf('20 / 4 = %d\\n', quot_result);\n\n%% Section 2: Static Method Usage\n% Use the static power method\n\npower_result = Calculator.power(2, 10);\nfprintf('2^10 = %d\\n', power_result);\n\n%% Section 3: Math Utilities\n% Test the mathUtils functions\n\n% Factorial\nfact5 = mathUtils('factorial', 5);\nfprintf('5! = %d\\n', fact5);\n\n% Fibonacci\nfib10 = mathUtils('fibonacci', 10);\nfprintf('Fibonacci(10) = %d\\n', fib10);\n\n% Prime check\nis17prime = mathUtils('isPrime', 17);\nfprintf('Is 17 prime? %s\\n', mat2str(is17prime));\n\n% Statistics\ndata = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n[dataMean, dataStd] = mathUtils('stats', data);\nfprintf('Mean: %.2f, Std: %.2f\\n', dataMean, dataStd);\n\n%% Section 4: Display History\n% Show all calculations performed by the calculator\n\ncalc.displayHistory();\n\n%% Section 5: Error Handling\n% Demonstrate error handling with division by zero\n\ntry\n    calc.divide(10, 0);\ncatch ME\n    fprintf('Caught expected error: %s\\n', ME.message);\nend\n\nfprintf('\\nAll tests completed successfully!\\n');\n"
  },
  {
    "path": "test/resources/repos/nix/test_repo/.gitignore",
    "content": "# Nix specific\nresult\nresult-*\n.direnv/\n\n# Build artifacts\n*.drv\n\n# IDE\n.vscode/\n.idea/"
  },
  {
    "path": "test/resources/repos/nix/test_repo/default.nix",
    "content": "# default.nix - Traditional Nix expression for backwards compatibility\n{ pkgs ? import <nixpkgs> { } }:\n\nlet\n  # Import library functions\n  lib = pkgs.lib;\n  stdenv = pkgs.stdenv;\n\n  # Import our custom utilities\n  utils = import ./lib/utils.nix { inherit lib; };\n\n  # Custom function to create a greeting\n  makeGreeting = name: \"Hello, ${name}!\";\n\n  # List manipulation functions (using imported utils)\n  listUtils = {\n    double = list: map (x: x * 2) list;\n    sum = list: lib.foldl' (acc: x: acc + x) 0 list;\n    average = list:\n      if list == [ ]\n      then 0\n      else (listUtils.sum list) / (builtins.length list);\n    # Use function from imported utils\n    unique = utils.lists.unique;\n  };\n\n  # String utilities\n  stringUtils = rec {\n    capitalize = str:\n      let\n        first = lib.substring 0 1 str;\n        rest = lib.substring 1 (-1) str;\n      in\n      (lib.toUpper first) + rest;\n\n    repeat = n: str: lib.concatStrings (lib.genList (_: str) n);\n\n    padLeft = width: char: str:\n      let\n        len = lib.stringLength str;\n        padding = if len >= width then 0 else width - len;\n      in\n      (repeat padding char) + str;\n  };\n\n  # Package builder helper\n  buildSimplePackage = { name, version, script }:\n    stdenv.mkDerivation {\n      pname = name;\n      inherit version;\n\n      phases = [ \"installPhase\" ];\n\n      installPhase = ''\n        mkdir -p $out/bin\n        cat > $out/bin/${name} << EOF\n        #!/usr/bin/env bash\n        ${script}\n        EOF\n        chmod +x $out/bin/${name}\n      '';\n    };\n\nin\nrec {\n  # Export utilities\n  inherit listUtils stringUtils makeGreeting;\n\n  # Export imported utilities directly\n  inherit (utils) math strings;\n\n  # Example packages\n  hello = buildSimplePackage {\n    name = \"hello\";\n    version = \"1.0\";\n    script = ''\n      echo \"${makeGreeting \"World\"}\"\n    '';\n  };\n\n  calculator = buildSimplePackage {\n    name = \"calculator\";\n    version = \"0.1\";\n    script = ''\n      if [ $# -ne 3 ]; then\n        echo \"Usage: calculator <num1> <op> <num2>\"\n        exit 1\n      fi\n      \n      case $2 in\n        +) echo $(($1 + $3)) ;;\n        -) echo $(($1 - $3)) ;;\n        x) echo $(($1 * $3)) ;;\n        /) echo $(($1 / $3)) ;;\n        *) echo \"Unknown operator: $2\" ;;\n      esac\n    '';\n  };\n\n  # Environment with multiple packages\n  devEnv = pkgs.buildEnv {\n    name = \"dev-environment\";\n    paths = with pkgs; [\n      git\n      vim\n      bash\n      hello\n      calculator\n    ];\n  };\n\n  # Shell derivation\n  shell = pkgs.mkShell {\n    buildInputs = with pkgs; [\n      bash\n      coreutils\n      findutils\n      gnugrep\n      gnused\n    ];\n\n    shellHook = ''\n      echo \"Entering Nix shell environment\"\n      echo \"Available custom functions: makeGreeting, listUtils, stringUtils\"\n    '';\n  };\n\n  # Configuration example\n  config = {\n    system = {\n      stateVersion = \"23.11\";\n      enable = true;\n    };\n\n    services = {\n      nginx = {\n        enable = false;\n        virtualHosts = {\n          \"example.com\" = {\n            root = \"/var/www/example\";\n            locations.\"/\" = {\n              index = \"index.html\";\n            };\n          };\n        };\n      };\n    };\n\n    users = {\n      testUser = {\n        name = \"test\";\n        group = \"users\";\n        home = \"/home/test\";\n        shell = \"${pkgs.bash}/bin/bash\";\n      };\n    };\n  };\n\n  # Recursive attribute set example\n  tree = {\n    root = {\n      value = 1;\n      left = {\n        value = 2;\n        left = { value = 4; };\n        right = { value = 5; };\n      };\n      right = {\n        value = 3;\n        left = { value = 6; };\n        right = { value = 7; };\n      };\n    };\n\n    # Tree traversal function\n    traverse = node:\n      if node ? left && node ? right\n      then [ node.value ] ++ (tree.traverse node.left) ++ (tree.traverse node.right)\n      else if node ? value\n      then [ node.value ]\n      else [ ];\n  };\n}\n"
  },
  {
    "path": "test/resources/repos/nix/test_repo/flake.nix",
    "content": "{\n  description = \"Test Nix flake for language server testing\";\n\n  inputs = {\n    nixpkgs.url = \"github:NixOS/nixpkgs/nixos-unstable\";\n    flake-utils.url = \"github:numtide/flake-utils\";\n  };\n\n  outputs = { self, nixpkgs, flake-utils }:\n    flake-utils.lib.eachDefaultSystem (system:\n      let\n        pkgs = nixpkgs.legacyPackages.${system};\n        \n        # Import our default.nix for shared logic\n        defaultNix = import ./default.nix { inherit pkgs; };\n        \n        # Custom derivation for testing\n        hello-custom = pkgs.stdenv.mkDerivation {\n          pname = \"hello-custom\";\n          version = \"1.0.0\";\n          \n          src = ./.;\n          \n          buildInputs = with pkgs; [\n            bash\n            coreutils\n          ];\n          \n          installPhase = ''\n            mkdir -p $out/bin\n            cp ${./scripts/hello.sh} $out/bin/hello-custom\n            chmod +x $out/bin/hello-custom\n          '';\n          \n          meta = with pkgs.lib; {\n            description = \"A custom hello world script\";\n            license = licenses.mit;\n            platforms = platforms.all;\n          };\n        };\n        \n        # Development shell configuration\n        devShell = pkgs.mkShell {\n          buildInputs = with pkgs; [\n            # Development tools\n            git\n            gnumake\n            gcc\n            \n            # Nix tools\n            nix-prefetch-git\n            nixpkgs-fmt\n            nil\n            \n            # Languages\n            python3\n            nodejs\n            rustc\n            cargo\n          ];\n          \n          shellHook = ''\n            echo \"Welcome to the Nix development shell!\"\n            echo \"Available tools: git, make, gcc, python3, nodejs, rustc\"\n          '';\n        };\n        \n      in\n      {\n        # Packages\n        packages = {\n          default = hello-custom;\n          inherit hello-custom;\n          \n          # Another package for testing\n          utils = pkgs.stdenv.mkDerivation {\n            pname = \"test-utils\";\n            version = \"0.1.0\";\n            src = ./.;\n            \n            installPhase = ''\n              mkdir -p $out/share\n              echo \"Utility functions\" > $out/share/utils.txt\n            '';\n          };\n        };\n        \n        # Apps\n        apps = {\n          default = {\n            type = \"app\";\n            program = \"${hello-custom}/bin/hello-custom\";\n          };\n          \n          hello = {\n            type = \"app\";\n            program = \"${hello-custom}/bin/hello-custom\";\n          };\n        };\n        \n        # Development shells\n        devShells = {\n          default = devShell;\n          \n          # Minimal shell for testing\n          minimal = pkgs.mkShell {\n            buildInputs = with pkgs; [\n              bash\n              coreutils\n            ];\n          };\n        };\n        \n        # Overlay\n        overlays.default = final: prev: {\n          inherit hello-custom;\n        };\n        \n        # NixOS module\n        nixosModules.default = { config, lib, pkgs, ... }:\n          with lib;\n          {\n            options.services.hello-custom = {\n              enable = mkEnableOption \"hello-custom service\";\n              \n              message = mkOption {\n                type = types.str;\n                default = \"Hello from NixOS!\";\n                description = \"Message to display\";\n              };\n            };\n            \n            config = mkIf config.services.hello-custom.enable {\n              systemd.services.hello-custom = {\n                description = \"Hello Custom Service\";\n                wantedBy = [ \"multi-user.target\" ];\n                serviceConfig = {\n                  ExecStart = \"${hello-custom}/bin/hello-custom\";\n                  Type = \"oneshot\";\n                };\n              };\n            };\n          };\n      }\n    );\n}"
  },
  {
    "path": "test/resources/repos/nix/test_repo/lib/utils.nix",
    "content": "# Utility functions library\n{ lib }:\n\nrec {\n  # Math utilities\n  math = {\n    # Calculate factorial\n    factorial = n:\n      if n == 0\n      then 1\n      else n * factorial (n - 1);\n    \n    # Calculate fibonacci number\n    fibonacci = n:\n      if n <= 1\n      then n\n      else (fibonacci (n - 1)) + (fibonacci (n - 2));\n    \n    # Check if number is prime\n    isPrime = n:\n      let\n        checkDivisible = i:\n          if i * i > n then true\n          else if lib.mod n i == 0 then false\n          else checkDivisible (i + 1);\n      in\n        if n <= 1 then false\n        else if n <= 3 then true\n        else checkDivisible 2;\n    \n    # Greatest common divisor\n    gcd = a: b:\n      if b == 0\n      then a\n      else gcd b (lib.mod a b);\n  };\n  \n  # String manipulation\n  strings = {\n    # Reverse a string\n    reverse = str:\n      let\n        len = lib.stringLength str;\n        chars = lib.genList (i: lib.substring (len - i - 1) 1 str) len;\n      in\n        lib.concatStrings chars;\n    \n    # Check if string is palindrome\n    isPalindrome = str:\n      str == strings.reverse str;\n    \n    # Convert to camelCase\n    toCamelCase = str:\n      let\n        words = lib.splitString \"-\" str;\n        capitalize = w: \n          if w == \"\" then \"\"\n          else (lib.toUpper (lib.substring 0 1 w)) + (lib.substring 1 (-1) w);\n        capitalizedWords = lib.tail (map capitalize words);\n      in\n        (lib.head words) + (lib.concatStrings capitalizedWords);\n    \n    # Convert to snake_case\n    toSnakeCase = str:\n      lib.replaceStrings [\"-\"] [\"_\"] (lib.toLower str);\n  };\n  \n  # List operations\n  lists = {\n    # Get unique elements\n    unique = list:\n      lib.foldl' (acc: x:\n        if lib.elem x acc\n        then acc\n        else acc ++ [x]\n      ) [] list;\n    \n    # Zip two lists\n    zip = list1: list2:\n      let\n        len1 = lib.length list1;\n        len2 = lib.length list2;\n        minLen = if len1 < len2 then len1 else len2;\n      in\n        lib.genList (i: {\n          fst = lib.elemAt list1 i;\n          snd = lib.elemAt list2 i;\n        }) minLen;\n    \n    # Flatten nested list\n    flatten = list:\n      lib.foldl' (acc: x:\n        if builtins.isList x\n        then acc ++ (flatten x)\n        else acc ++ [x]\n      ) [] list;\n    \n    # Partition list by predicate\n    partition = pred: list:\n      lib.foldl' (acc: x:\n        if pred x\n        then { yes = acc.yes ++ [x]; no = acc.no; }\n        else { yes = acc.yes; no = acc.no ++ [x]; }\n      ) { yes = []; no = []; } list;\n  };\n  \n  # Attribute set operations\n  attrs = {\n    # Deep merge two attribute sets\n    deepMerge = attr1: attr2:\n      lib.recursiveUpdate attr1 attr2;\n    \n    # Filter attributes by predicate\n    filterAttrs = pred: attrs:\n      lib.filterAttrs pred attrs;\n    \n    # Map over attribute values\n    mapValues = f: attrs:\n      lib.mapAttrs (name: value: f value) attrs;\n    \n    # Get nested attribute safely\n    getAttrPath = path: default: attrs:\n      lib.attrByPath path default attrs;\n  };\n  \n  # File system utilities\n  files = {\n    # Read JSON file\n    readJSON = path:\n      builtins.fromJSON (builtins.readFile path);\n    \n    # Read TOML file\n    readTOML = path:\n      builtins.fromTOML (builtins.readFile path);\n    \n    # Check if path exists\n    pathExists = path:\n      builtins.pathExists path;\n    \n    # Get file type\n    getFileType = path:\n      let\n        type = builtins.readFileType path;\n      in\n        if type == \"directory\" then \"dir\"\n        else if type == \"regular\" then \"file\"\n        else if type == \"symlink\" then \"link\"\n        else \"unknown\";\n  };\n  \n  # Validation utilities\n  validate = {\n    # Check if value is email\n    isEmail = str:\n      builtins.match \"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,}$\" str != null;\n    \n    # Check if value is URL\n    isURL = str:\n      builtins.match \"^https?://[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,}\" str != null;\n    \n    # Check if value is valid version\n    isVersion = str:\n      builtins.match \"^[0-9]+\\\\.[0-9]+\\\\.[0-9]+$\" str != null;\n  };\n}"
  },
  {
    "path": "test/resources/repos/nix/test_repo/modules/example.nix",
    "content": "# Example NixOS module\n{ config, lib, pkgs, ... }:\n\nwith lib;\n\nlet\n  cfg = config.services.example;\n  \n  # Helper function to generate config file\n  generateConfig = settings: ''\n    # Generated configuration\n    ${lib.concatStringsSep \"\\n\" (lib.mapAttrsToList (k: v: \"${k} = ${toString v}\") settings)}\n  '';\n  \nin {\n  # Module options\n  options = {\n    services.example = {\n      enable = mkEnableOption \"example service\";\n      \n      package = mkOption {\n        type = types.package;\n        default = pkgs.hello;\n        description = \"Package to use for the service\";\n      };\n      \n      port = mkOption {\n        type = types.port;\n        default = 8080;\n        description = \"Port to listen on\";\n      };\n      \n      host = mkOption {\n        type = types.str;\n        default = \"localhost\";\n        description = \"Host to bind to\";\n      };\n      \n      workers = mkOption {\n        type = types.int;\n        default = 4;\n        description = \"Number of worker processes\";\n      };\n      \n      settings = mkOption {\n        type = types.attrsOf types.anything;\n        default = {};\n        description = \"Additional settings\";\n      };\n      \n      users = mkOption {\n        type = types.listOf types.str;\n        default = [];\n        description = \"List of users with access\";\n      };\n      \n      database = {\n        enable = mkOption {\n          type = types.bool;\n          default = false;\n          description = \"Enable database support\";\n        };\n        \n        type = mkOption {\n          type = types.enum [ \"postgresql\" \"mysql\" \"sqlite\" ];\n          default = \"sqlite\";\n          description = \"Database type\";\n        };\n        \n        host = mkOption {\n          type = types.str;\n          default = \"localhost\";\n          description = \"Database host\";\n        };\n        \n        name = mkOption {\n          type = types.str;\n          default = \"example\";\n          description = \"Database name\";\n        };\n      };\n    };\n  };\n  \n  # Module configuration\n  config = mkIf cfg.enable {\n    # System packages\n    environment.systemPackages = [ cfg.package ];\n    \n    # Systemd service\n    systemd.services.example = {\n      description = \"Example Service\";\n      after = [ \"network.target\" ] ++ (optional cfg.database.enable \"postgresql.service\");\n      wantedBy = [ \"multi-user.target\" ];\n      \n      serviceConfig = {\n        Type = \"simple\";\n        User = \"example\";\n        Group = \"example\";\n        ExecStart = \"${cfg.package}/bin/example --port ${toString cfg.port} --host ${cfg.host}\";\n        Restart = \"on-failure\";\n        RestartSec = 5;\n        \n        # Security hardening\n        PrivateTmp = true;\n        ProtectSystem = \"strict\";\n        ProtectHome = true;\n        NoNewPrivileges = true;\n      };\n      \n      environment = {\n        EXAMPLE_WORKERS = toString cfg.workers;\n        EXAMPLE_CONFIG = generateConfig cfg.settings;\n      } // optionalAttrs cfg.database.enable {\n        DATABASE_TYPE = cfg.database.type;\n        DATABASE_HOST = cfg.database.host;\n        DATABASE_NAME = cfg.database.name;\n      };\n    };\n    \n    # User and group\n    users.users.example = {\n      isSystemUser = true;\n      group = \"example\";\n      description = \"Example service user\";\n    };\n    \n    users.groups.example = {};\n    \n    # Firewall rules\n    networking.firewall = mkIf (cfg.host == \"0.0.0.0\") {\n      allowedTCPPorts = [ cfg.port ];\n    };\n    \n    # Database setup\n    services.postgresql = mkIf (cfg.database.enable && cfg.database.type == \"postgresql\") {\n      enable = true;\n      ensureDatabases = [ cfg.database.name ];\n      ensureUsers = [{\n        name = \"example\";\n        ensureDBOwnership = true;\n      }];\n    };\n  };\n}"
  },
  {
    "path": "test/resources/repos/nix/test_repo/scripts/hello.sh",
    "content": "#!/usr/bin/env bash\n# Simple hello script for testing\necho \"Hello from Nix!\""
  },
  {
    "path": "test/resources/repos/ocaml/test_repo/bin/dune",
    "content": "(executable\n (public_name test_repo)\n (name main)\n (libraries test_repo))\n"
  },
  {
    "path": "test/resources/repos/ocaml/test_repo/bin/main.ml",
    "content": "open Test_repo\n\nlet n = 20\n\nlet () =\n  let res = fib n in\n  Printf.printf \"fib(%d) = %d\\n\" n res;\n  let greeting = DemoModule.someFunction \"Hello\" in\n  Printf.printf \"%s\\n\" greeting"
  },
  {
    "path": "test/resources/repos/ocaml/test_repo/dune-project",
    "content": "(lang dune 3.18)\n\n(name test_repo)\n\n(generate_opam_files true)\n\n(source\n (github username/reponame))\n\n(authors \"Author Name <author@example.com>\")\n\n(maintainers \"Maintainer Name <maintainer@example.com>\")\n\n(license LICENSE)\n\n(documentation https://url/to/documentation)\n\n(package\n (name test_repo)\n (synopsis \"A short synopsis\")\n (description \"A longer description\")\n (depends ocaml)\n (tags\n  (\"add topics\" \"to describe\" your project)))\n\n; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html\n"
  },
  {
    "path": "test/resources/repos/ocaml/test_repo/lib/dune",
    "content": "(library\n (public_name test_repo)\n (name test_repo))"
  },
  {
    "path": "test/resources/repos/ocaml/test_repo/lib/test_repo.ml",
    "content": "module DemoModule = struct\n  type value = string\n\n  let someFunction s =\n    s ^ \" More String\"\nend\n\nlet rec fib n =\n  if n < 2 then 1\n  else fib (n-1) + fib (n-2)\n\nlet num_domains = 2"
  },
  {
    "path": "test/resources/repos/ocaml/test_repo/lib/test_repo.mli",
    "content": "module DemoModule : sig\n  type value = string\n  val someFunction : string -> string\nend\n\nval fib : int -> int\nval num_domains : int"
  },
  {
    "path": "test/resources/repos/ocaml/test_repo/test/dune",
    "content": "(test\n (name test_test_repo)\n (libraries test_repo))"
  },
  {
    "path": "test/resources/repos/ocaml/test_repo/test/test_test_repo.ml",
    "content": "open Test_repo\n\nlet test_fib () =\n  assert (fib 0 = 1);\n  assert (fib 1 = 1);\n  assert (fib 2 = 2);\n  assert (fib 5 = 8);\n  Printf.printf \"fib tests passed\\n\"\n\nlet test_demo_module () =\n  let result = DemoModule.someFunction \"Test\" in\n  assert (result = \"Test More String\");\n  Printf.printf \"DemoModule tests passed\\n\"\n\nlet () =\n  test_fib ();\n  test_demo_module ();\n  Printf.printf \"All tests passed!\\n\""
  },
  {
    "path": "test/resources/repos/ocaml/test_repo/test_repo.opam",
    "content": "# This file is generated by dune, edit dune-project instead\nopam-version: \"2.0\"\nsynopsis: \"A short synopsis\"\ndescription: \"A longer description\"\nmaintainer: [\"Maintainer Name <maintainer@example.com>\"]\nauthors: [\"Author Name <author@example.com>\"]\nlicense: \"LICENSE\"\ntags: [\"add topics\" \"to describe\" \"your\" \"project\"]\nhomepage: \"https://github.com/username/reponame\"\ndoc: \"https://url/to/documentation\"\nbug-reports: \"https://github.com/username/reponame/issues\"\ndepends: [\n  \"dune\" {>= \"3.18\"}\n  \"ocaml\"\n  \"odoc\" {with-doc}\n]\nbuild: [\n  [\"dune\" \"subst\"] {dev}\n  [\n    \"dune\"\n    \"build\"\n    \"-p\"\n    name\n    \"-j\"\n    jobs\n    \"@install\"\n    \"@runtest\" {with-test}\n    \"@doc\" {with-doc}\n  ]\n]\ndev-repo: \"git+https://github.com/username/reponame.git\"\nx-maintenance-intent: [\"(latest)\"]\n"
  },
  {
    "path": "test/resources/repos/pascal/test_repo/.gitignore",
    "content": "backup/\n*.o\n*.ppu\n*.exe\n*.lps\n*.compiled\n__history/\n__recovery/\n"
  },
  {
    "path": "test/resources/repos/pascal/test_repo/main.pas",
    "content": "unit Main;\n\n{$mode objfpc}{$H+}\n\ninterface\n\nuses\n  Classes, SysUtils, Helper;\n\ntype\n  { TUser - A simple user class }\n  TUser = class\n  private\n    FName: string;\n    FAge: Integer;\n  public\n    constructor Create(const AName: string; AAge: Integer);\n    destructor Destroy; override;\n\n    function GetInfo: string;\n    procedure UpdateAge(NewAge: Integer);\n\n    property Name: string read FName write FName;\n    property Age: Integer read FAge write FAge;\n  end;\n\n  { TUserManager - Manages multiple users }\n  TUserManager = class\n  private\n    FUsers: TList;\n  public\n    constructor Create;\n    destructor Destroy; override;\n\n    procedure AddUser(User: TUser);\n    function GetUserCount: Integer;\n    function FindUserByName(const AName: string): TUser;\n  end;\n\n{ Helper functions }\n\n/// Calculates the sum of two integers.\n/// @param A First integer value\n/// @param B Second integer value\n/// @returns The sum of A and B\nfunction CalculateSum(A, B: Integer): Integer;\nprocedure PrintMessage(const Msg: string);\n\nimplementation\n\n{ TUser implementation }\n\nconstructor TUser.Create(const AName: string; AAge: Integer);\nbegin\n  inherited Create;\n  FName := AName;\n  FAge := AAge;\nend;\n\ndestructor TUser.Destroy;\nbegin\n  inherited Destroy;\nend;\n\nfunction TUser.GetInfo: string;\nbegin\n  Result := Format('Name: %s, Age: %d', [FName, FAge]);\nend;\n\nprocedure TUser.UpdateAge(NewAge: Integer);\nbegin\n  FAge := NewAge;\nend;\n\n{ TUserManager implementation }\n\nconstructor TUserManager.Create;\nbegin\n  inherited Create;\n  FUsers := TList.Create;\nend;\n\ndestructor TUserManager.Destroy;\nvar\n  i: Integer;\nbegin\n  for i := 0 to FUsers.Count - 1 do\n    TUser(FUsers[i]).Free;\n  FUsers.Free;\n  inherited Destroy;\nend;\n\nprocedure TUserManager.AddUser(User: TUser);\nbegin\n  FUsers.Add(User);\nend;\n\nfunction TUserManager.GetUserCount: Integer;\nbegin\n  Result := FUsers.Count;\nend;\n\nfunction TUserManager.FindUserByName(const AName: string): TUser;\nvar\n  i: Integer;\nbegin\n  Result := nil;\n  for i := 0 to FUsers.Count - 1 do\n  begin\n    if TUser(FUsers[i]).Name = AName then\n    begin\n      Result := TUser(FUsers[i]);\n      Exit;\n    end;\n  end;\nend;\n\n{ Helper functions }\n\nfunction CalculateSum(A, B: Integer): Integer;\nbegin\n  Result := A + B;\nend;\n\nprocedure PrintMessage(const Msg: string);\nbegin\n  WriteLn(Msg);\nend;\n\nend.\n"
  },
  {
    "path": "test/resources/repos/perl/test_repo/helper.pl",
    "content": "#!/usr/bin/env perl\nuse strict;\nuse warnings;\n\nsub helper_function {\n    print \"Helper function was called.\\n\";\n}\n\n1;\n"
  },
  {
    "path": "test/resources/repos/perl/test_repo/main.pl",
    "content": "#!/usr/bin/env perl\nuse strict;\nuse warnings;\nuse lib '.';\n\nrequire helper;\n\nsub greet {\n    my ($name) = @_;\n    return \"Hello, $name!\";\n}\n\nmy $user_name = \"Perl User\";\nmy $greeting = greet($user_name);\n\nprint \"$greeting\\n\";\n\nhelper_function();\n\nsub use_helper_function {\n    helper_function();\n}\n"
  },
  {
    "path": "test/resources/repos/php/test_repo/helper.php",
    "content": "<?php\n\nfunction helperFunction(): void {\n    echo \"Helper function was called.\";\n}\n\n?> "
  },
  {
    "path": "test/resources/repos/php/test_repo/index.php",
    "content": "<?php\n\nrequire_once 'helper.php';\n\nfunction greet(string $name): string {\n    return \"Hello, \" . $name . \"!\";\n}\n\n$userName = \"PHP User\";\n$greeting = greet($userName);\n\necho $greeting;\n\nhelperFunction();\n\nfunction useHelperFunction() {\n    helperFunction();\n}\n\n?> "
  },
  {
    "path": "test/resources/repos/php/test_repo/sample.php",
    "content": "<?php\n\nnamespace SerenaTest;\n\n/**\n * Interface for objects that can greet.\n */\ninterface GreeterInterface\n{\n    public function greet(string $name): string;\n}\n\n/**\n * Abstract base class for animals.\n */\nabstract class Animal\n{\n    protected string $name;\n    protected int $age;\n\n    public function __construct(string $name, int $age)\n    {\n        $this->name = $name;\n        $this->age  = $age;\n    }\n\n    public function getName(): string\n    {\n        return $this->name;\n    }\n\n    public function getAge(): int\n    {\n        return $this->age;\n    }\n\n    abstract public function describe(): string;\n}\n\n/**\n * A concrete animal that can greet visitors.\n */\nclass Dog extends Animal implements GreeterInterface\n{\n    private string $breed;\n\n    public function __construct(string $name, int $age, string $breed)\n    {\n        parent::__construct($name, $age);\n        $this->breed = $breed;\n    }\n\n    public function greet(string $visitorName): string\n    {\n        return \"Woof! I'm {$this->name}. Hello, {$visitorName}!\";\n    }\n\n    public function getBreed(): string\n    {\n        return $this->breed;\n    }\n\n    public function describe(): string\n    {\n        return \"Dog: {$this->name} ({$this->breed}), age {$this->age}\";\n    }\n\n    public function fetch(string $item): string\n    {\n        return \"{$this->name} fetches the {$item}!\";\n    }\n}\n\n/**\n * Another concrete animal.\n */\nclass Cat extends Animal\n{\n    private bool $indoor;\n\n    public function __construct(string $name, int $age, bool $indoor = true)\n    {\n        parent::__construct($name, $age);\n        $this->indoor = $indoor;\n    }\n\n    public function isIndoor(): bool\n    {\n        return $this->indoor;\n    }\n\n    public function describe(): string\n    {\n        $type = $this->indoor ? 'indoor' : 'outdoor';\n        return \"Cat: {$this->name} ({$type}), age {$this->age}\";\n    }\n}\n\nconst MAX_ANIMALS = 100;\nconst DEFAULT_BREED = 'Mixed';\n\n/**\n * Factory function to create an animal by type name.\n */\nfunction createAnimal(string $type, string $name, int $age): Animal\n{\n    return match ($type) {\n        'dog' => new Dog($name, $age, DEFAULT_BREED),\n        'cat' => new Cat($name, $age),\n        default => throw new \\InvalidArgumentException(\"Unknown animal type: {$type}\"),\n    };\n}\n\n/**\n * Returns a summary string for a list of animals.\n *\n * @param Animal[] $animals\n */\nfunction summarizeAnimals(array $animals): string\n{\n    return implode(', ', array_map(fn(Animal $a) => $a->describe(), $animals));\n}\n"
  },
  {
    "path": "test/resources/repos/php/test_repo/simple_var.php",
    "content": "<?php\n$localVar = \"test\";\necho $localVar;\n?> "
  },
  {
    "path": "test/resources/repos/powershell/test_repo/PowerShellEditorServices.json",
    "content": "{\"status\":\"started\",\"languageServiceTransport\":\"Stdio\",\"powerShellVersion\":\"7.5.3\"}"
  },
  {
    "path": "test/resources/repos/powershell/test_repo/main.ps1",
    "content": "# Main script demonstrating various PowerShell features\n\n# Import utility functions\n. \"$PSScriptRoot\\utils.ps1\"\n\n# Global variables\n$Script:ScriptName = \"Main Script\"\n$Script:Counter = 0\n\n<#\n.SYNOPSIS\n    Greets a user with various greeting styles.\n.PARAMETER Username\n    The name of the user to greet.\n.PARAMETER GreetingType\n    The type of greeting (formal, casual, or default).\n#>\nfunction Greet-User {\n    [CmdletBinding()]\n    param(\n        [Parameter(Mandatory = $true)]\n        [string]$Username,\n\n        [Parameter(Mandatory = $false)]\n        [ValidateSet(\"formal\", \"casual\", \"default\")]\n        [string]$GreetingType = \"default\"\n    )\n\n    switch ($GreetingType) {\n        \"formal\" {\n            Write-Output \"Good day, $Username!\"\n        }\n        \"casual\" {\n            Write-Output \"Hey $Username!\"\n        }\n        default {\n            Write-Output \"Hello, $Username!\"\n        }\n    }\n}\n\n<#\n.SYNOPSIS\n    Processes an array of items with the specified operation.\n.PARAMETER Items\n    The array of items to process.\n.PARAMETER Operation\n    The operation to perform (count, uppercase).\n#>\nfunction Process-Items {\n    [CmdletBinding()]\n    param(\n        [Parameter(Mandatory = $true)]\n        [string[]]$Items,\n\n        [Parameter(Mandatory = $true)]\n        [ValidateSet(\"count\", \"uppercase\")]\n        [string]$Operation\n    )\n\n    foreach ($item in $Items) {\n        switch ($Operation) {\n            \"count\" {\n                $Script:Counter++\n                Write-Output \"Processing item $($Script:Counter): $item\"\n            }\n            \"uppercase\" {\n                Write-Output $item.ToUpper()\n            }\n        }\n    }\n}\n\n<#\n.SYNOPSIS\n    Main entry point for the script.\n#>\nfunction Main {\n    [CmdletBinding()]\n    param(\n        [Parameter(Mandatory = $false)]\n        [string]$User = \"World\",\n\n        [Parameter(Mandatory = $false)]\n        [string]$Greeting = \"default\"\n    )\n\n    Write-Output \"Starting $Script:ScriptName\"\n\n    # Use the Greet-User function\n    Greet-User -Username $User -GreetingType $Greeting\n\n    # Process some items\n    $items = @(\"item1\", \"item2\", \"item3\")\n    Write-Output \"Processing items...\"\n    Process-Items -Items $items -Operation \"count\"\n\n    # Use utility functions from utils.ps1\n    $upperName = Convert-ToUpperCase -InputString $User\n    Write-Output \"Uppercase name: $upperName\"\n\n    $trimmed = Remove-Whitespace -InputString \"  Hello World  \"\n    Write-Output \"Trimmed: '$trimmed'\"\n\n    Write-Output \"Script completed successfully\"\n}\n\n# Run main function\nMain @args\n"
  },
  {
    "path": "test/resources/repos/powershell/test_repo/utils.ps1",
    "content": "# Utility functions for PowerShell operations\n\n<#\n.SYNOPSIS\n    Converts a string to uppercase.\n.PARAMETER InputString\n    The string to convert.\n.OUTPUTS\n    System.String - The uppercase string.\n#>\nfunction Convert-ToUpperCase {\n    [CmdletBinding()]\n    [OutputType([string])]\n    param(\n        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]\n        [string]$InputString\n    )\n\n    return $InputString.ToUpper()\n}\n\n<#\n.SYNOPSIS\n    Converts a string to lowercase.\n.PARAMETER InputString\n    The string to convert.\n.OUTPUTS\n    System.String - The lowercase string.\n#>\nfunction Convert-ToLowerCase {\n    [CmdletBinding()]\n    [OutputType([string])]\n    param(\n        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]\n        [string]$InputString\n    )\n\n    return $InputString.ToLower()\n}\n\n<#\n.SYNOPSIS\n    Removes leading and trailing whitespace from a string.\n.PARAMETER InputString\n    The string to trim.\n.OUTPUTS\n    System.String - The trimmed string.\n#>\nfunction Remove-Whitespace {\n    [CmdletBinding()]\n    [OutputType([string])]\n    param(\n        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]\n        [string]$InputString\n    )\n\n    return $InputString.Trim()\n}\n\n<#\n.SYNOPSIS\n    Creates a backup of a file.\n.PARAMETER FilePath\n    The path to the file to backup.\n.PARAMETER BackupDirectory\n    The directory where the backup will be created.\n.OUTPUTS\n    System.String - The path to the backup file.\n#>\nfunction Backup-File {\n    [CmdletBinding()]\n    [OutputType([string])]\n    param(\n        [Parameter(Mandatory = $true)]\n        [string]$FilePath,\n\n        [Parameter(Mandatory = $false)]\n        [string]$BackupDirectory = \".\"\n    )\n\n    if (-not (Test-Path $FilePath)) {\n        throw \"File not found: $FilePath\"\n    }\n\n    $fileName = Split-Path $FilePath -Leaf\n    $timestamp = Get-Date -Format \"yyyyMMdd_HHmmss\"\n    $backupName = \"$fileName.$timestamp.bak\"\n    $backupPath = Join-Path $BackupDirectory $backupName\n\n    Copy-Item -Path $FilePath -Destination $backupPath\n    return $backupPath\n}\n\n<#\n.SYNOPSIS\n    Checks if an array contains a specific element.\n.PARAMETER Array\n    The array to search.\n.PARAMETER Element\n    The element to find.\n.OUTPUTS\n    System.Boolean - True if the element is found, false otherwise.\n#>\nfunction Test-ArrayContains {\n    [CmdletBinding()]\n    [OutputType([bool])]\n    param(\n        [Parameter(Mandatory = $true)]\n        [array]$Array,\n\n        [Parameter(Mandatory = $true)]\n        $Element\n    )\n\n    return $Array -contains $Element\n}\n\n<#\n.SYNOPSIS\n    Writes a log message with timestamp.\n.PARAMETER Message\n    The message to log.\n.PARAMETER Level\n    The log level (Info, Warning, Error).\n#>\nfunction Write-LogMessage {\n    [CmdletBinding()]\n    param(\n        [Parameter(Mandatory = $true)]\n        [string]$Message,\n\n        [Parameter(Mandatory = $false)]\n        [ValidateSet(\"Info\", \"Warning\", \"Error\")]\n        [string]$Level = \"Info\"\n    )\n\n    $timestamp = Get-Date -Format \"yyyy-MM-dd HH:mm:ss\"\n    $logEntry = \"[$timestamp] [$Level] $Message\"\n\n    switch ($Level) {\n        \"Info\" { Write-Host $logEntry -ForegroundColor White }\n        \"Warning\" { Write-Host $logEntry -ForegroundColor Yellow }\n        \"Error\" { Write-Host $logEntry -ForegroundColor Red }\n    }\n}\n\n<#\n.SYNOPSIS\n    Validates if a string is a valid email address.\n.PARAMETER Email\n    The email address to validate.\n.OUTPUTS\n    System.Boolean - True if the email is valid, false otherwise.\n#>\nfunction Test-ValidEmail {\n    [CmdletBinding()]\n    [OutputType([bool])]\n    param(\n        [Parameter(Mandatory = $true)]\n        [string]$Email\n    )\n\n    $emailRegex = \"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$\"\n    return $Email -match $emailRegex\n}\n\n<#\n.SYNOPSIS\n    Checks if a string is a valid number.\n.PARAMETER Value\n    The string to check.\n.OUTPUTS\n    System.Boolean - True if the string is a valid number, false otherwise.\n#>\nfunction Test-IsNumber {\n    [CmdletBinding()]\n    [OutputType([bool])]\n    param(\n        [Parameter(Mandatory = $true)]\n        [string]$Value\n    )\n\n    $number = 0\n    return [double]::TryParse($Value, [ref]$number)\n}\n"
  },
  {
    "path": "test/resources/repos/python/test_repo/.gitignore",
    "content": "ignore_this_dir*/"
  },
  {
    "path": "test/resources/repos/python/test_repo/custom_test/__init__.py",
    "content": "\"\"\"\nCustom test package for testing code parsing capabilities.\n\"\"\"\n"
  },
  {
    "path": "test/resources/repos/python/test_repo/custom_test/advanced_features.py",
    "content": "\"\"\"\nAdvanced Python features for testing code parsing capabilities.\n\nThis module contains various advanced Python code patterns to ensure\nthat the code parser can correctly handle them.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport asyncio\nimport os\nfrom abc import ABC, abstractmethod\nfrom collections.abc import Callable, Iterable\nfrom contextlib import contextmanager\nfrom dataclasses import dataclass, field\nfrom enum import Enum, Flag, IntEnum, auto\nfrom functools import wraps\nfrom typing import (\n    Annotated,\n    Any,\n    ClassVar,\n    Final,\n    Generic,\n    Literal,\n    NewType,\n    Protocol,\n    TypedDict,\n    TypeVar,\n)\n\n# Type variables for generics\nT = TypeVar(\"T\")\nK = TypeVar(\"K\")\nV = TypeVar(\"V\")\n\n# Custom types using NewType\nUserId = NewType(\"UserId\", str)\nItemId = NewType(\"ItemId\", int)\n\n# Type aliases\nPathLike = str | os.PathLike\nJsonDict = dict[str, Any]\n\n\n# TypedDict\nclass UserDict(TypedDict):\n    \"\"\"TypedDict representing user data.\"\"\"\n\n    id: str\n    name: str\n    email: str\n    age: int\n    roles: list[str]\n\n\n# Enums\nclass Status(Enum):\n    \"\"\"Status enum for process states.\"\"\"\n\n    PENDING = \"pending\"\n    RUNNING = \"running\"\n    COMPLETED = \"completed\"\n    FAILED = \"failed\"\n\n\nclass Priority(IntEnum):\n    \"\"\"Priority levels for tasks.\"\"\"\n\n    LOW = 0\n    MEDIUM = 5\n    HIGH = 10\n    CRITICAL = auto()\n\n\nclass Permissions(Flag):\n    \"\"\"Permission flags for access control.\"\"\"\n\n    NONE = 0\n    READ = 1\n    WRITE = 2\n    EXECUTE = 4\n    ALL = READ | WRITE | EXECUTE\n\n\n# Abstract class with various method types\nclass BaseProcessor(ABC):\n    \"\"\"Abstract base class for processors with various method patterns.\"\"\"\n\n    # Class variable with type annotation\n    DEFAULT_TIMEOUT: ClassVar[int] = 30\n    MAX_RETRIES: Final[int] = 3\n\n    def __init__(self, name: str, config: dict[str, Any] | None = None):\n        self.name = name\n        self.config = config or {}\n        self._status = Status.PENDING\n\n    @property\n    def status(self) -> Status:\n        \"\"\"Status property getter.\"\"\"\n        return self._status\n\n    @status.setter\n    def status(self, value: Status) -> None:\n        \"\"\"Status property setter.\"\"\"\n        if not isinstance(value, Status):\n            raise TypeError(f\"Expected Status enum, got {type(value)}\")\n        self._status = value\n\n    @abstractmethod\n    def process(self, data: Any) -> Any:\n        \"\"\"Process the input data.\"\"\"\n\n    @classmethod\n    def create_from_config(cls, config: dict[str, Any]) -> BaseProcessor:\n        \"\"\"Factory classmethod.\"\"\"\n        name = config.get(\"name\", \"default\")\n        return cls(name=name, config=config)\n\n    @staticmethod\n    def validate_config(config: dict[str, Any]) -> bool:\n        \"\"\"Static method for config validation.\"\"\"\n        return \"name\" in config\n\n    def __str__(self) -> str:\n        return f\"{self.__class__.__name__}(name={self.name})\"\n\n\n# Concrete implementation of abstract class\nclass DataProcessor(BaseProcessor):\n    \"\"\"Concrete implementation of BaseProcessor.\"\"\"\n\n    def __init__(self, name: str, config: dict[str, Any] | None = None, priority: Priority = Priority.MEDIUM):\n        super().__init__(name, config)\n        self.priority = priority\n        self.processed_count = 0\n\n    def process(self, data: Any) -> Any:\n        \"\"\"Process the data.\"\"\"\n\n        # Nested function definition\n        def transform(item: Any) -> Any:\n            # Nested function within a nested function\n            def apply_rules(x: Any) -> Any:\n                return x\n\n            return apply_rules(item)\n\n        # Lambda function\n        normalize = lambda x: x / max(x) if hasattr(x, \"__iter__\") and len(x) > 0 else x  # noqa: F841\n\n        result = transform(data)\n        self.processed_count += 1\n        return result\n\n    # Method with complex type hints\n    def batch_process(self, items: list[str | dict[str, Any] | tuple[Any, ...]]) -> dict[str, list[Any]]:\n        \"\"\"Process multiple items in a batch.\"\"\"\n        results: dict[str, list[Any]] = {\"success\": [], \"error\": []}\n\n        for item in items:\n            try:\n                result = self.process(item)\n                results[\"success\"].append(result)\n            except Exception as e:\n                results[\"error\"].append((item, str(e)))\n\n        return results\n\n    # Generator method\n    def process_stream(self, data_stream: Iterable[T]) -> Iterable[T]:\n        \"\"\"Process a stream of data, yielding results as they're processed.\"\"\"\n        for item in data_stream:\n            yield self.process(item)\n\n    # Async method\n    async def async_process(self, data: Any) -> Any:\n        \"\"\"Process data asynchronously.\"\"\"\n        await asyncio.sleep(0.1)\n        return self.process(data)\n\n    # Method with function parameters\n    def apply_transform(self, data: Any, transform_func: Callable[[Any], Any]) -> Any:\n        \"\"\"Apply a custom transform function to the data.\"\"\"\n        return transform_func(data)\n\n\n# Dataclass\n@dataclass\nclass Task:\n    \"\"\"Task dataclass for tracking work items.\"\"\"\n\n    id: str\n    name: str\n    status: Status = Status.PENDING\n    priority: Priority = Priority.MEDIUM\n    metadata: dict[str, Any] = field(default_factory=dict)\n    dependencies: list[str] = field(default_factory=list)\n    created_at: float | None = None\n\n    def __post_init__(self):\n        if self.created_at is None:\n            import time\n\n            self.created_at = time.time()\n\n    def has_dependencies(self) -> bool:\n        \"\"\"Check if task has dependencies.\"\"\"\n        return len(self.dependencies) > 0\n\n\n# Generic class\nclass Repository(Generic[T]):\n    \"\"\"Generic repository for managing collections of items.\"\"\"\n\n    def __init__(self):\n        self.items: dict[str, T] = {}\n\n    def add(self, id: str, item: T) -> None:\n        \"\"\"Add an item to the repository.\"\"\"\n        self.items[id] = item\n\n    def get(self, id: str) -> T | None:\n        \"\"\"Get an item by id.\"\"\"\n        return self.items.get(id)\n\n    def remove(self, id: str) -> bool:\n        \"\"\"Remove an item by id.\"\"\"\n        if id in self.items:\n            del self.items[id]\n            return True\n        return False\n\n    def list_all(self) -> list[T]:\n        \"\"\"List all items.\"\"\"\n        return list(self.items.values())\n\n\n# Type with Protocol (structural subtyping)\nclass Serializable(Protocol):\n    \"\"\"Protocol for objects that can be serialized to dict.\"\"\"\n\n    def to_dict(self) -> dict[str, Any]: ...\n\n\n#\n# Decorator function\ndef log_execution(func: Callable) -> Callable:\n    \"\"\"Decorator to log function execution.\"\"\"\n\n    @wraps(func)\n    def wrapper(*args, **kwargs):\n        print(f\"Executing {func.__name__}\")\n        result = func(*args, **kwargs)\n        print(f\"Finished {func.__name__}\")\n        return result\n\n    return wrapper\n\n\n# Context manager\n@contextmanager\ndef transaction_context(name: str = \"default\"):\n    \"\"\"Context manager for transaction-like operations.\"\"\"\n    print(f\"Starting transaction: {name}\")\n    try:\n        yield name\n        print(f\"Committing transaction: {name}\")\n    except Exception as e:\n        print(f\"Rolling back transaction: {name}, error: {e}\")\n        raise\n\n\n# Function with complex parameter annotations\ndef advanced_search(\n    query: str,\n    filters: dict[str, Any] | None = None,\n    sort_by: str | None = None,\n    sort_order: Literal[\"asc\", \"desc\"] = \"asc\",\n    page: int = 1,\n    page_size: int = 10,\n    include_metadata: bool = False,\n) -> tuple[list[dict[str, Any]], int]:\n    \"\"\"\n    Advanced search function with many parameters.\n\n    Returns search results and total count.\n    \"\"\"\n    results = []\n    total = 0\n    # Simulating search functionality\n    return results, total\n\n\n# Class with nested classes\nclass OuterClass:\n    \"\"\"Outer class with nested classes and methods.\"\"\"\n\n    class NestedClass:\n        \"\"\"Nested class inside OuterClass.\"\"\"\n\n        def __init__(self, value: Any):\n            self.value = value\n\n        def get_value(self) -> Any:\n            \"\"\"Get the stored value.\"\"\"\n            return self.value\n\n        class DeeplyNestedClass:\n            \"\"\"Deeply nested class for testing parser depth capabilities.\"\"\"\n\n            def deep_method(self) -> str:\n                \"\"\"Method in deeply nested class.\"\"\"\n                return \"deep\"\n\n    def __init__(self, name: str):\n        self.name = name\n        self.nested = self.NestedClass(name)\n\n    def get_nested(self) -> NestedClass:\n        \"\"\"Get the nested class instance.\"\"\"\n        return self.nested\n\n    # Method with nested functions\n    def process_with_nested(self, data: Any) -> Any:\n        \"\"\"Method demonstrating deeply nested function definitions.\"\"\"\n\n        def level1(x: Any) -> Any:\n            \"\"\"First level nested function.\"\"\"\n\n            def level2(y: Any) -> Any:\n                \"\"\"Second level nested function.\"\"\"\n\n                def level3(z: Any) -> Any:\n                    \"\"\"Third level nested function.\"\"\"\n                    return z\n\n                return level3(y)\n\n            return level2(x)\n\n        return level1(data)\n\n\n# Metaclass example\nclass Meta(type):\n    \"\"\"Metaclass example for testing advanced class handling.\"\"\"\n\n    def __new__(mcs, name, bases, attrs):\n        print(f\"Creating class: {name}\")\n        return super().__new__(mcs, name, bases, attrs)\n\n    def __init__(cls, name, bases, attrs):\n        print(f\"Initializing class: {name}\")\n        super().__init__(name, bases, attrs)\n\n\nclass WithMeta(metaclass=Meta):\n    \"\"\"Class that uses a metaclass.\"\"\"\n\n    def __init__(self, value: str):\n        self.value = value\n\n\n# Factory function that creates and returns instances\ndef create_processor(processor_type: str, name: str, config: dict[str, Any] | None = None) -> BaseProcessor:\n    \"\"\"Factory function that creates and returns processor instances.\"\"\"\n    if processor_type == \"data\":\n        return DataProcessor(name, config)\n    else:\n        raise ValueError(f\"Unknown processor type: {processor_type}\")\n\n\n# Nested decorator example\ndef with_retry(max_retries: int = 3):\n    \"\"\"Decorator factory that creates a retry decorator.\"\"\"\n\n    def decorator(func):\n        @wraps(func)\n        def wrapper(*args, **kwargs):\n            for attempt in range(max_retries):\n                try:\n                    return func(*args, **kwargs)\n                except Exception as e:\n                    if attempt == max_retries - 1:\n                        raise\n                    print(f\"Retrying {func.__name__} after error: {e}\")\n            return None\n\n        return wrapper\n\n    return decorator\n\n\n@with_retry(max_retries=5)\ndef unreliable_operation(data: Any) -> Any:\n    \"\"\"Function that might fail and uses the retry decorator.\"\"\"\n    import random\n\n    if random.random() < 0.5:\n        raise RuntimeError(\"Random failure\")\n    return data\n\n\n# Complex type annotation with Annotated\nValidatedString = Annotated[str, \"A string that has been validated\"]\nPositiveInt = Annotated[int, lambda x: x > 0]\n\n\ndef process_validated_data(data: ValidatedString, count: PositiveInt) -> list[str]:\n    \"\"\"Process data with Annotated type hints.\"\"\"\n    return [data] * count\n\n\n# Example of forward references and string literals in type annotations\nclass TreeNode:\n    \"\"\"Tree node with forward reference to itself in annotations.\"\"\"\n\n    def __init__(self, value: Any):\n        self.value = value\n        self.children: list[TreeNode] = []\n\n    def add_child(self, child: TreeNode) -> None:\n        \"\"\"Add a child node.\"\"\"\n        self.children.append(child)\n\n    def traverse(self) -> list[Any]:\n        \"\"\"Traverse the tree and return all values.\"\"\"\n        result = [self.value]\n        for child in self.children:\n            result.extend(child.traverse())\n        return result\n\n\n# Main entry point for demonstration\ndef main() -> None:\n    \"\"\"Main function demonstrating the use of various features.\"\"\"\n    # Create processor\n    processor = DataProcessor(\"test-processor\", {\"debug\": True})\n\n    # Create tasks\n    task1 = Task(id=\"task1\", name=\"First Task\")\n    task2 = Task(id=\"task2\", name=\"Second Task\", dependencies=[\"task1\"])\n\n    # Create repository\n    repo: Repository[Task] = Repository()\n    repo.add(task1.id, task1)\n    repo.add(task2.id, task2)\n\n    # Process some data\n    data = [1, 2, 3, 4, 5]\n    result = processor.process(data)  # noqa: F841\n\n    # Use context manager\n    with transaction_context(\"main\"):\n        # Process more data\n        for task in repo.list_all():\n            processor.process(task.name)\n\n    # Use advanced search\n    _results, _total = advanced_search(query=\"test\", filters={\"status\": Status.PENDING}, sort_by=\"priority\", page=1, include_metadata=True)\n\n    # Create a tree\n    root = TreeNode(\"root\")\n    child1 = TreeNode(\"child1\")\n    child2 = TreeNode(\"child2\")\n    root.add_child(child1)\n    root.add_child(child2)\n    child1.add_child(TreeNode(\"grandchild1\"))\n\n    print(\"Done!\")\n\n\nif __name__ == \"__main__\":\n    main()\n"
  },
  {
    "path": "test/resources/repos/python/test_repo/examples/__init__.py",
    "content": "\"\"\"\nExamples package for demonstrating test_repo module usage.\n\"\"\"\n"
  },
  {
    "path": "test/resources/repos/python/test_repo/examples/user_management.py",
    "content": "\"\"\"\nExample demonstrating user management with the test_repo module.\n\nThis example showcases:\n- Creating and managing users\n- Using various object types and relationships\n- Type annotations and complex Python patterns\n\"\"\"\n\nimport logging\nfrom dataclasses import dataclass\nfrom typing import Any\n\nfrom test_repo.models import User, create_user_object\nfrom test_repo.services import UserService\n\n# Set up logging\nlogging.basicConfig(level=logging.INFO)\nlogger = logging.getLogger(__name__)\n\n\n@dataclass\nclass UserStats:\n    \"\"\"Statistics about user activity.\"\"\"\n\n    user_id: str\n    login_count: int = 0\n    last_active_days: int = 0\n    engagement_score: float = 0.0\n\n    def is_active(self) -> bool:\n        \"\"\"Check if the user is considered active.\"\"\"\n        return self.last_active_days < 30\n\n\nclass UserManager:\n    \"\"\"Example class demonstrating complex user management.\"\"\"\n\n    def __init__(self, service: UserService):\n        self.service = service\n        self.active_users: dict[str, User] = {}\n        self.user_stats: dict[str, UserStats] = {}\n\n    def register_user(self, name: str, email: str, roles: list[str] | None = None) -> User:\n        \"\"\"Register a new user.\"\"\"\n        logger.info(f\"Registering new user: {name} ({email})\")\n        user = self.service.create_user(name=name, email=email, roles=roles)\n        self.active_users[user.id] = user\n        self.user_stats[user.id] = UserStats(user_id=user.id)\n        return user\n\n    def get_user(self, user_id: str) -> User | None:\n        \"\"\"Get a user by ID.\"\"\"\n        if user_id in self.active_users:\n            return self.active_users[user_id]\n\n        # Try to fetch from service\n        user = self.service.get_user(user_id)\n        if user:\n            self.active_users[user.id] = user\n        return user\n\n    def update_user_stats(self, user_id: str, login_count: int, days_since_active: int) -> None:\n        \"\"\"Update statistics for a user.\"\"\"\n        if user_id not in self.user_stats:\n            self.user_stats[user_id] = UserStats(user_id=user_id)\n\n        stats = self.user_stats[user_id]\n        stats.login_count = login_count\n        stats.last_active_days = days_since_active\n\n        # Calculate engagement score based on activity\n        engagement = (100 - min(days_since_active, 100)) * 0.8\n        engagement += min(login_count, 20) * 0.2\n        stats.engagement_score = engagement\n\n    def get_active_users(self) -> list[User]:\n        \"\"\"Get all active users.\"\"\"\n        active_user_ids = [user_id for user_id, stats in self.user_stats.items() if stats.is_active()]\n        return [self.active_users[user_id] for user_id in active_user_ids if user_id in self.active_users]\n\n    def get_user_by_email(self, email: str) -> User | None:\n        \"\"\"Find a user by their email address.\"\"\"\n        for user in self.active_users.values():\n            if user.email == email:\n                return user\n        return None\n\n\n# Example function demonstrating type annotations\ndef process_user_data(users: list[User], include_inactive: bool = False, transform_func: callable | None = None) -> dict[str, Any]:\n    \"\"\"Process user data with optional transformations.\"\"\"\n    result: dict[str, Any] = {\"users\": [], \"total\": 0, \"admin_count\": 0}\n\n    for user in users:\n        if transform_func:\n            user_data = transform_func(user.to_dict())\n        else:\n            user_data = user.to_dict()\n\n        result[\"users\"].append(user_data)\n        result[\"total\"] += 1\n\n        if \"admin\" in user.roles:\n            result[\"admin_count\"] += 1\n\n    return result\n\n\ndef main():\n    \"\"\"Main function demonstrating the usage of UserManager.\"\"\"\n    # Initialize service and manager\n    service = UserService()\n    manager = UserManager(service)\n\n    # Register some users\n    admin = manager.register_user(\"Admin User\", \"admin@example.com\", [\"admin\"])\n    user1 = manager.register_user(\"Regular User\", \"user@example.com\", [\"user\"])\n    user2 = manager.register_user(\"Another User\", \"another@example.com\", [\"user\"])\n\n    # Update some stats\n    manager.update_user_stats(admin.id, 100, 5)\n    manager.update_user_stats(user1.id, 50, 10)\n    manager.update_user_stats(user2.id, 10, 45)  # Inactive user\n\n    # Get active users\n    active_users = manager.get_active_users()\n    logger.info(f\"Active users: {len(active_users)}\")\n\n    # Process user data\n    user_data = process_user_data(active_users, transform_func=lambda u: {**u, \"full_name\": u.get(\"name\", \"\")})\n\n    logger.info(f\"Processed {user_data['total']} users, {user_data['admin_count']} admins\")\n\n    # Example of calling create_user directly\n    external_user = create_user_object(id=\"ext123\", name=\"External User\", email=\"external@example.org\", roles=[\"external\"])\n    logger.info(f\"Created external user: {external_user.name}\")\n\n\nif __name__ == \"__main__\":\n    main()\n"
  },
  {
    "path": "test/resources/repos/python/test_repo/scripts/__init__.py",
    "content": "\"\"\"\nScripts package containing entry point scripts for the application.\n\"\"\"\n"
  },
  {
    "path": "test/resources/repos/python/test_repo/scripts/run_app.py",
    "content": "#!/usr/bin/env python\n\"\"\"\nMain entry point script for the test_repo application.\n\nThis script demonstrates how a typical application entry point would be structured,\nwith command-line arguments, configuration loading, and service initialization.\n\"\"\"\n\nimport argparse\nimport json\nimport logging\nimport os\nimport sys\nfrom typing import Any\n\n# Add parent directory to path to make imports work\nsys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), \"..\")))\n\nfrom test_repo.models import Item, User\nfrom test_repo.services import ItemService, UserService\n\n# Configure logging\nlogging.basicConfig(level=logging.INFO, format=\"%(asctime)s - %(name)s - %(levelname)s - %(message)s\")\nlogger = logging.getLogger(__name__)\n\n\ndef parse_args():\n    \"\"\"Parse command line arguments.\"\"\"\n    parser = argparse.ArgumentParser(description=\"Test Repo Application\")\n\n    parser.add_argument(\"--config\", type=str, default=\"config.json\", help=\"Path to configuration file\")\n\n    parser.add_argument(\"--mode\", choices=[\"user\", \"item\", \"both\"], default=\"both\", help=\"Operation mode\")\n\n    parser.add_argument(\"--verbose\", action=\"store_true\", help=\"Enable verbose logging\")\n\n    return parser.parse_args()\n\n\ndef load_config(config_path: str) -> dict[str, Any]:\n    \"\"\"Load configuration from a JSON file.\"\"\"\n    if not os.path.exists(config_path):\n        logger.warning(f\"Configuration file not found: {config_path}\")\n        return {}\n\n    try:\n        with open(config_path, encoding=\"utf-8\") as f:\n            return json.load(f)\n    except json.JSONDecodeError:\n        logger.error(f\"Invalid JSON in configuration file: {config_path}\")\n        return {}\n    except Exception as e:\n        logger.error(f\"Error loading configuration: {e}\")\n        return {}\n\n\ndef create_sample_users(service: UserService, count: int = 3) -> list[User]:\n    \"\"\"Create sample users for demonstration.\"\"\"\n    users = []\n\n    # Create admin user\n    admin = service.create_user(name=\"Admin User\", email=\"admin@example.com\", roles=[\"admin\"])\n    users.append(admin)\n\n    # Create regular users\n    for i in range(count - 1):\n        user = service.create_user(name=f\"User {i + 1}\", email=f\"user{i + 1}@example.com\", roles=[\"user\"])\n        users.append(user)\n\n    return users\n\n\ndef create_sample_items(service: ItemService, count: int = 5) -> list[Item]:\n    \"\"\"Create sample items for demonstration.\"\"\"\n    categories = [\"Electronics\", \"Books\", \"Clothing\", \"Food\", \"Other\"]\n    items = []\n\n    for i in range(count):\n        category = categories[i % len(categories)]\n        item = service.create_item(name=f\"Item {i + 1}\", price=10.0 * (i + 1), category=category)\n        items.append(item)\n\n    return items\n\n\ndef run_user_operations(service: UserService, config: dict[str, Any]) -> None:\n    \"\"\"Run operations related to users.\"\"\"\n    logger.info(\"Running user operations\")\n\n    # Get configuration\n    user_count = config.get(\"user_count\", 3)\n\n    # Create users\n    users = create_sample_users(service, user_count)\n    logger.info(f\"Created {len(users)} users\")\n\n    # Demonstrate some operations\n    for user in users:\n        logger.info(f\"User: {user.name} (ID: {user.id})\")\n\n        # Access a method to demonstrate method calls\n        if user.has_role(\"admin\"):\n            logger.info(f\"{user.name} is an admin\")\n\n    # Lookup a user\n    found_user = service.get_user(users[0].id)\n    if found_user:\n        logger.info(f\"Found user: {found_user.name}\")\n\n\ndef run_item_operations(service: ItemService, config: dict[str, Any]) -> None:\n    \"\"\"Run operations related to items.\"\"\"\n    logger.info(\"Running item operations\")\n\n    # Get configuration\n    item_count = config.get(\"item_count\", 5)\n\n    # Create items\n    items = create_sample_items(service, item_count)\n    logger.info(f\"Created {len(items)} items\")\n\n    # Demonstrate some operations\n    total_price = 0.0\n    for item in items:\n        price_display = item.get_display_price()\n        logger.info(f\"Item: {item.name}, Price: {price_display}\")\n        total_price += item.price\n\n    logger.info(f\"Total price of all items: ${total_price:.2f}\")\n\n\ndef main():\n    \"\"\"Main entry point for the application.\"\"\"\n    # Parse command line arguments\n    args = parse_args()\n\n    # Configure logging level\n    if args.verbose:\n        logging.getLogger().setLevel(logging.DEBUG)\n\n    logger.info(\"Starting Test Repo Application\")\n\n    # Load configuration\n    config = load_config(args.config)\n    logger.debug(f\"Loaded configuration: {config}\")\n\n    # Initialize services\n    user_service = UserService()\n    item_service = ItemService()\n\n    # Run operations based on mode\n    if args.mode in (\"user\", \"both\"):\n        run_user_operations(user_service, config)\n\n    if args.mode in (\"item\", \"both\"):\n        run_item_operations(item_service, config)\n\n    logger.info(\"Application completed successfully\")\n\n\nitem_reference = Item(id=\"1\", name=\"Item 1\", price=10.0, category=\"Electronics\")\n\nif __name__ == \"__main__\":\n    main()\n"
  },
  {
    "path": "test/resources/repos/python/test_repo/test_repo/__init__.py",
    "content": ""
  },
  {
    "path": "test/resources/repos/python/test_repo/test_repo/complex_types.py",
    "content": "from typing import TypedDict\n\na: list[int] = [1]\n\n\nclass CustomListInt(list[int]):\n    def some_method(self):\n        pass\n\n\nclass CustomTypedDict(TypedDict):\n    a: int\n    b: str\n\n\nclass Outer2:\n    class InnerTypedDict(TypedDict):\n        a: int\n        b: str\n\n\nclass ComplexExtension(Outer2.InnerTypedDict, total=False):\n    c: bool\n"
  },
  {
    "path": "test/resources/repos/python/test_repo/test_repo/models.py",
    "content": "\"\"\"\nModels module that demonstrates various Python class patterns.\n\"\"\"\n\nfrom abc import ABC, abstractmethod\nfrom typing import Any, Generic, TypeVar\n\nT = TypeVar(\"T\")\n\n\nclass BaseModel(ABC):\n    \"\"\"\n    Abstract base class for all models.\n    \"\"\"\n\n    def __init__(self, id: str, name: str | None = None):\n        self.id = id\n        self.name = name or id\n\n    @abstractmethod\n    def to_dict(self) -> dict[str, Any]:\n        \"\"\"Convert model to dictionary representation\"\"\"\n\n    @classmethod\n    def from_dict(cls, data: dict[str, Any]) -> \"BaseModel\":\n        \"\"\"Create a model instance from dictionary data\"\"\"\n        id = data.get(\"id\", \"\")\n        name = data.get(\"name\")\n        return cls(id=id, name=name)\n\n\nclass User(BaseModel):\n    \"\"\"\n    User model representing a system user.\n    \"\"\"\n\n    def __init__(self, id: str, name: str | None = None, email: str = \"\", roles: list[str] | None = None):\n        super().__init__(id, name)\n        self.email = email\n        self.roles = roles or []\n\n    def to_dict(self) -> dict[str, Any]:\n        return {\"id\": self.id, \"name\": self.name, \"email\": self.email, \"roles\": self.roles}\n\n    @classmethod\n    def from_dict(cls, data: dict[str, Any]) -> \"User\":\n        instance = super().from_dict(data)\n        instance.email = data.get(\"email\", \"\")\n        instance.roles = data.get(\"roles\", [])\n        return instance\n\n    def has_role(self, role: str) -> bool:\n        \"\"\"Check if user has a specific role\"\"\"\n        return role in self.roles\n\n\nclass Item(BaseModel):\n    \"\"\"\n    Item model representing a product or service.\n    \"\"\"\n\n    def __init__(self, id: str, name: str | None = None, price: float = 0.0, category: str = \"\"):\n        super().__init__(id, name)\n        self.price = price\n        self.category = category\n\n    def to_dict(self) -> dict[str, Any]:\n        return {\"id\": self.id, \"name\": self.name, \"price\": self.price, \"category\": self.category}\n\n    def get_display_price(self) -> str:\n        \"\"\"Format price for display\"\"\"\n        return f\"${self.price:.2f}\"\n\n\n# Generic type example\nclass Collection(Generic[T]):\n    def __init__(self, items: list[T] | None = None):\n        self.items = items or []\n\n    def add(self, item: T) -> None:\n        self.items.append(item)\n\n    def get_all(self) -> list[T]:\n        return self.items\n\n\n# Factory function\ndef create_user_object(id: str, name: str, email: str, roles: list[str] | None = None) -> User:\n    \"\"\"Factory function to create a user\"\"\"\n    return User(id=id, name=name, email=email, roles=roles)\n\n\n# Multiple inheritance examples\n\n\nclass Loggable:\n    \"\"\"\n    Mixin class that provides logging functionality.\n    Example of a common mixin pattern used with multiple inheritance.\n    \"\"\"\n\n    def __init__(self, **kwargs):\n        super().__init__(**kwargs)\n        self.log_entries: list[str] = []\n\n    def log(self, message: str) -> None:\n        \"\"\"Add a log entry\"\"\"\n        self.log_entries.append(message)\n\n    def get_logs(self) -> list[str]:\n        \"\"\"Get all log entries\"\"\"\n        return self.log_entries\n\n\nclass Serializable:\n    \"\"\"\n    Mixin class that provides JSON serialization capabilities.\n    Another example of a mixin for multiple inheritance.\n    \"\"\"\n\n    def __init__(self, **kwargs):\n        super().__init__(**kwargs)\n\n    def to_json(self) -> dict[str, Any]:\n        \"\"\"Convert to JSON-serializable dictionary\"\"\"\n        return self.to_dict() if hasattr(self, \"to_dict\") else {}\n\n    @classmethod\n    def from_json(cls, data: dict[str, Any]) -> Any:\n        \"\"\"Create instance from JSON data\"\"\"\n        return cls.from_dict(data) if hasattr(cls, \"from_dict\") else cls(**data)\n\n\nclass Auditable:\n    \"\"\"\n    Mixin for tracking creation and modification timestamps.\n    \"\"\"\n\n    def __init__(self, **kwargs):\n        super().__init__(**kwargs)\n        self.created_at: str = kwargs.get(\"created_at\", \"\")\n        self.updated_at: str = kwargs.get(\"updated_at\", \"\")\n\n    def update_timestamp(self, timestamp: str) -> None:\n        \"\"\"Update the last modified timestamp\"\"\"\n        self.updated_at = timestamp\n\n\n# Diamond inheritance pattern\nclass BaseService(ABC):\n    \"\"\"\n    Base class for service objects - demonstrates diamond inheritance pattern.\n    \"\"\"\n\n    def __init__(self, name: str = \"base\"):\n        self.service_name = name\n\n    @abstractmethod\n    def get_service_info(self) -> dict[str, str]:\n        \"\"\"Get service information\"\"\"\n\n\nclass DataService(BaseService):\n    \"\"\"\n    Data handling service.\n    \"\"\"\n\n    def __init__(self, **kwargs):\n        name = kwargs.pop(\"name\", \"data\")\n        super().__init__(name=name)\n        self.data_source = kwargs.get(\"data_source\", \"default\")\n\n    def get_service_info(self) -> dict[str, str]:\n        return {\"service_type\": \"data\", \"service_name\": self.service_name, \"data_source\": self.data_source}\n\n\nclass NetworkService(BaseService):\n    \"\"\"\n    Network connectivity service.\n    \"\"\"\n\n    def __init__(self, **kwargs):\n        name = kwargs.pop(\"name\", \"network\")\n        super().__init__(name=name)\n        self.endpoint = kwargs.get(\"endpoint\", \"localhost\")\n\n    def get_service_info(self) -> dict[str, str]:\n        return {\"service_type\": \"network\", \"service_name\": self.service_name, \"endpoint\": self.endpoint}\n\n\nclass DataSyncService(DataService, NetworkService):\n    \"\"\"\n    Service that syncs data over network - example of diamond inheritance.\n    Inherits from both DataService and NetworkService, which both inherit from BaseService.\n    \"\"\"\n\n    def __init__(self, **kwargs):\n        super().__init__(**kwargs)\n        self.sync_interval = kwargs.get(\"sync_interval\", 60)\n\n    def get_service_info(self) -> dict[str, str]:\n        info = super().get_service_info()\n        info.update({\"service_type\": \"data_sync\", \"sync_interval\": str(self.sync_interval)})\n        return info\n\n\n# Multiple inheritance with mixins\n\n\nclass LoggableUser(User, Loggable):\n    \"\"\"\n    User class with logging capabilities.\n    Example of extending a concrete class with a mixin.\n    \"\"\"\n\n    def __init__(self, id: str, name: str | None = None, email: str = \"\", roles: list[str] | None = None):\n        super().__init__(id=id, name=name, email=email, roles=roles)\n\n    def add_role(self, role: str) -> None:\n        \"\"\"Add a role to the user and log the action\"\"\"\n        if role not in self.roles:\n            self.roles.append(role)\n            self.log(f\"Added role '{role}' to user {self.id}\")\n\n\nclass TrackedItem(Item, Serializable, Auditable):\n    \"\"\"\n    Item with serialization and auditing capabilities.\n    Example of a class inheriting from a concrete class and multiple mixins.\n    \"\"\"\n\n    def __init__(\n        self, id: str, name: str | None = None, price: float = 0.0, category: str = \"\", created_at: str = \"\", updated_at: str = \"\"\n    ):\n        super().__init__(id=id, name=name, price=price, category=category, created_at=created_at, updated_at=updated_at)\n        self.stock_level = 0\n\n    def update_stock(self, quantity: int) -> None:\n        \"\"\"Update stock level and timestamp\"\"\"\n        self.stock_level = quantity\n        self.update_timestamp(f\"stock_update_{quantity}\")\n\n    def to_dict(self) -> dict[str, Any]:\n        result = super().to_dict()\n        result.update({\"stock_level\": self.stock_level, \"created_at\": self.created_at, \"updated_at\": self.updated_at})\n        return result\n"
  },
  {
    "path": "test/resources/repos/python/test_repo/test_repo/name_collisions.py",
    "content": "# ruff: noqa\nvar_will_be_overwritten = 1\n\nvar_will_be_overwritten = 2\n\n\ndef func_using_overwritten_var():\n    print(var_will_be_overwritten)\n\n\nclass ClassWillBeOverwritten:\n    def method1(self):\n        pass\n\n\nclass ClassWillBeOverwritten:\n    def method2(self):\n        pass\n\n\ndef func_will_be_overwritten():\n    pass\n\n\ndef func_will_be_overwritten():\n    pass\n\n\ndef func_calling_overwritten_func():\n    func_will_be_overwritten()\n\n\ndef func_calling_overwritten_class():\n    ClassWillBeOverwritten()\n"
  },
  {
    "path": "test/resources/repos/python/test_repo/test_repo/nested.py",
    "content": "class OuterClass:\n    class NestedClass:\n        def find_me(self):\n            pass\n\n    def nested_test(self):\n        class WithinMethod:\n            pass\n\n        def func_within_func():\n            pass\n\n        a = self.NestedClass()  # noqa: F841\n\n\nb = OuterClass().NestedClass().find_me()\n"
  },
  {
    "path": "test/resources/repos/python/test_repo/test_repo/nested_base.py",
    "content": "\"\"\"\nModule to test parsing of classes with nested module paths in base classes.\n\"\"\"\n\nfrom typing import Generic, TypeVar\n\nT = TypeVar(\"T\")\n\n\nclass BaseModule:\n    \"\"\"Base module class for nested module tests.\"\"\"\n\n\nclass SubModule:\n    \"\"\"Sub-module class for nested paths.\"\"\"\n\n    class NestedBase:\n        \"\"\"Nested base class.\"\"\"\n\n        def base_method(self):\n            \"\"\"Base method.\"\"\"\n            return \"base\"\n\n        class NestedLevel2:\n            \"\"\"Nested level 2.\"\"\"\n\n            def nested_level_2_method(self):\n                \"\"\"Nested level 2 method.\"\"\"\n                return \"nested_level_2\"\n\n    class GenericBase(Generic[T]):\n        \"\"\"Generic nested base class.\"\"\"\n\n        def generic_method(self, value: T) -> T:\n            \"\"\"Generic method.\"\"\"\n            return value\n\n\n# Classes extending base classes with single-level nesting\nclass FirstLevel(SubModule):\n    \"\"\"Class extending a class from a nested module path.\"\"\"\n\n    def first_level_method(self):\n        \"\"\"First level method.\"\"\"\n        return \"first\"\n\n\n# Classes extending base classes with multi-level nesting\nclass TwoLevel(SubModule.NestedBase):\n    \"\"\"Class extending a doubly-nested base class.\"\"\"\n\n    def multi_level_method(self):\n        \"\"\"Multi-level method.\"\"\"\n        return \"multi\"\n\n    def base_method(self):\n        \"\"\"Override of base method.\"\"\"\n        return \"overridden\"\n\n\nclass ThreeLevel(SubModule.NestedBase.NestedLevel2):\n    \"\"\"Class extending a triply-nested base class.\"\"\"\n\n    def three_level_method(self):\n        \"\"\"Three-level method.\"\"\"\n        return \"three\"\n\n\n# Class extending a generic base class with nesting\nclass GenericExtension(SubModule.GenericBase[str]):\n    \"\"\"Class extending a generic nested base class.\"\"\"\n\n    def generic_extension_method(self, text: str) -> str:\n        \"\"\"Extension method.\"\"\"\n        return f\"Extended: {text}\"\n"
  },
  {
    "path": "test/resources/repos/python/test_repo/test_repo/overloaded.py",
    "content": "\"\"\"\nModule demonstrating function and method overloading with typing.overload\n\"\"\"\n\nfrom typing import Any, overload\n\n\n# Example of function overloading\n@overload\ndef process_data(data: str) -> dict[str, str]: ...\n\n\n@overload\ndef process_data(data: int) -> dict[str, int]: ...\n\n\n@overload\ndef process_data(data: list[str | int]) -> dict[str, list[str | int]]: ...\n\n\ndef process_data(data: str | int | list[str | int]) -> dict[str, Any]:\n    \"\"\"\n    Process data based on its type.\n\n    - If string: returns a dict with 'value': <string>\n    - If int: returns a dict with 'value': <int>\n    - If list: returns a dict with 'value': <list>\n    \"\"\"\n    return {\"value\": data}\n\n\n# Class with overloaded methods\nclass DataProcessor:\n    \"\"\"\n    A class demonstrating method overloading.\n    \"\"\"\n\n    @overload\n    def transform(self, input_value: str) -> str: ...\n\n    @overload\n    def transform(self, input_value: int) -> int: ...\n\n    @overload\n    def transform(self, input_value: list[Any]) -> list[Any]: ...\n\n    def transform(self, input_value: str | int | list[Any]) -> str | int | list[Any]:\n        \"\"\"\n        Transform input based on its type.\n\n        - If string: returns the string in uppercase\n        - If int: returns the int multiplied by 2\n        - If list: returns the list sorted\n        \"\"\"\n        if isinstance(input_value, str):\n            return input_value.upper()\n        elif isinstance(input_value, int):\n            return input_value * 2\n        elif isinstance(input_value, list):\n            try:\n                return sorted(input_value)\n            except TypeError:\n                return input_value\n        return input_value\n\n    @overload\n    def fetch(self, id: int) -> dict[str, Any]: ...\n\n    @overload\n    def fetch(self, id: str, cache: bool = False) -> dict[str, Any] | None: ...\n\n    def fetch(self, id: int | str, cache: bool = False) -> dict[str, Any] | None:\n        \"\"\"\n        Fetch data for a given ID.\n\n        Args:\n            id: The ID to fetch, either numeric or string\n            cache: Whether to use cache for string IDs\n\n        Returns:\n            Data dictionary or None if not found\n\n        \"\"\"\n        # Implementation would actually fetch data\n        if isinstance(id, int):\n            return {\"id\": id, \"type\": \"numeric\"}\n        else:\n            return {\"id\": id, \"type\": \"string\", \"cached\": cache}\n"
  },
  {
    "path": "test/resources/repos/python/test_repo/test_repo/services.py",
    "content": "\"\"\"\nServices module demonstrating function usage and dependencies.\n\"\"\"\n\nfrom typing import Any\n\nfrom .models import Item, User\n\n\nclass UserService:\n    \"\"\"Service for user-related operations\"\"\"\n\n    def __init__(self, user_db: dict[str, User] | None = None):\n        self.users = user_db or {}\n\n    def create_user(self, id: str, name: str, email: str) -> User:\n        \"\"\"Create a new user and store it\"\"\"\n        if id in self.users:\n            raise ValueError(f\"User with ID {id} already exists\")\n\n        user = User(id=id, name=name, email=email)\n        self.users[id] = user\n        return user\n\n    def get_user(self, id: str) -> User | None:\n        \"\"\"Get a user by ID\"\"\"\n        return self.users.get(id)\n\n    def list_users(self) -> list[User]:\n        \"\"\"Get a list of all users\"\"\"\n        return list(self.users.values())\n\n    def delete_user(self, id: str) -> bool:\n        \"\"\"Delete a user by ID\"\"\"\n        if id in self.users:\n            del self.users[id]\n            return True\n        return False\n\n\nclass ItemService:\n    \"\"\"Service for item-related operations\"\"\"\n\n    def __init__(self, item_db: dict[str, Item] | None = None):\n        self.items = item_db or {}\n\n    def create_item(self, id: str, name: str, price: float, category: str) -> Item:\n        \"\"\"Create a new item and store it\"\"\"\n        if id in self.items:\n            raise ValueError(f\"Item with ID {id} already exists\")\n\n        item = Item(id=id, name=name, price=price, category=category)\n        self.items[id] = item\n        return item\n\n    def get_item(self, id: str) -> Item | None:\n        \"\"\"Get an item by ID\"\"\"\n        return self.items.get(id)\n\n    def list_items(self, category: str | None = None) -> list[Item]:\n        \"\"\"List all items, optionally filtered by category\"\"\"\n        if category:\n            return [item for item in self.items.values() if item.category == category]\n        return list(self.items.values())\n\n\n# Factory function for services\ndef create_service_container() -> dict[str, Any]:\n    \"\"\"Create a container with all services\"\"\"\n    container = {\"user_service\": UserService(), \"item_service\": ItemService()}\n    return container\n\n\nuser_var_str = \"user_var\"\n\n\nuser_service = UserService()\nuser_service.create_user(\"1\", \"Alice\", \"alice@example.com\")\n"
  },
  {
    "path": "test/resources/repos/python/test_repo/test_repo/utils.py",
    "content": "\"\"\"\nUtility functions and classes demonstrating various Python features.\n\"\"\"\n\nimport logging\nfrom collections.abc import Callable\nfrom typing import Any, TypeVar\n\n# Type variables for generic functions\nT = TypeVar(\"T\")\nU = TypeVar(\"U\")\n\n\ndef setup_logging(level: str = \"INFO\") -> logging.Logger:\n    \"\"\"Set up and return a configured logger\"\"\"\n    levels = {\n        \"DEBUG\": logging.DEBUG,\n        \"INFO\": logging.INFO,\n        \"WARNING\": logging.WARNING,\n        \"ERROR\": logging.ERROR,\n        \"CRITICAL\": logging.CRITICAL,\n    }\n\n    logger = logging.getLogger(\"test_repo\")\n    logger.setLevel(levels.get(level.upper(), logging.INFO))\n\n    handler = logging.StreamHandler()\n    formatter = logging.Formatter(\"%(asctime)s - %(name)s - %(levelname)s - %(message)s\")\n    handler.setFormatter(formatter)\n    logger.addHandler(handler)\n\n    return logger\n\n\n# Decorator example\ndef log_execution(func: Callable) -> Callable:\n    \"\"\"Decorator to log function execution\"\"\"\n\n    def wrapper(*args, **kwargs):\n        logger = logging.getLogger(\"test_repo\")\n        logger.info(f\"Executing function: {func.__name__}\")\n        result = func(*args, **kwargs)\n        logger.info(f\"Completed function: {func.__name__}\")\n        return result\n\n    return wrapper\n\n\n# Higher-order function\ndef map_list(items: list[T], mapper: Callable[[T], U]) -> list[U]:\n    \"\"\"Map a function over a list of items\"\"\"\n    return [mapper(item) for item in items]\n\n\n# Class with various Python features\nclass ConfigManager:\n    \"\"\"Manages configuration with various access patterns\"\"\"\n\n    _instance = None\n\n    # Singleton pattern\n    def __new__(cls, *args, **kwargs):\n        if not cls._instance:\n            cls._instance = super().__new__(cls)\n        return cls._instance\n\n    def __init__(self, initial_config: dict[str, Any] | None = None):\n        if not hasattr(self, \"initialized\"):\n            self.config = initial_config or {}\n            self.initialized = True\n\n    def __getitem__(self, key: str) -> Any:\n        \"\"\"Allow dictionary-like access\"\"\"\n        return self.config.get(key)\n\n    def __setitem__(self, key: str, value: Any) -> None:\n        \"\"\"Allow dictionary-like setting\"\"\"\n        self.config[key] = value\n\n    @property\n    def debug_mode(self) -> bool:\n        \"\"\"Property example\"\"\"\n        return self.config.get(\"debug\", False)\n\n    @debug_mode.setter\n    def debug_mode(self, value: bool) -> None:\n        self.config[\"debug\"] = value\n\n\n# Context manager example\nclass Timer:\n    \"\"\"Context manager for timing code execution\"\"\"\n\n    def __init__(self, name: str = \"Timer\"):\n        self.name = name\n        self.start_time = None\n        self.end_time = None\n\n    def __enter__(self):\n        import time\n\n        self.start_time = time.time()\n        return self\n\n    def __exit__(self, exc_type, exc_val, exc_tb):\n        import time\n\n        self.end_time = time.time()\n        print(f\"{self.name} took {self.end_time - self.start_time:.6f} seconds\")\n\n\n# Functions with default arguments\ndef retry(func: Callable, max_attempts: int = 3, delay: float = 1.0) -> Any:\n    \"\"\"Retry a function with backoff\"\"\"\n    import time\n\n    for attempt in range(max_attempts):\n        try:\n            return func()\n        except Exception as e:\n            if attempt == max_attempts - 1:\n                raise e\n            time.sleep(delay * (2**attempt))\n"
  },
  {
    "path": "test/resources/repos/python/test_repo/test_repo/variables.py",
    "content": "\"\"\"\nTest module for variable declarations and usage.\n\nThis module tests various types of variable declarations and usages including:\n- Module-level variables\n- Class-level variables\n- Instance variables\n- Variable reassignments\n\"\"\"\n\nfrom dataclasses import dataclass, field\n\n# Module-level variables\nmodule_var = \"Initial module value\"\n\nreassignable_module_var = 10\nreassignable_module_var = 20  # Reassigned\n\n# Module-level variable with type annotation\ntyped_module_var: int = 42\n\n\n# Regular class with class and instance variables\nclass VariableContainer:\n    \"\"\"Class that contains various variables.\"\"\"\n\n    # Class-level variables\n    class_var = \"Initial class value\"\n\n    reassignable_class_var = True\n    reassignable_class_var = False  # Reassigned #noqa: PIE794\n\n    # Class-level variable with type annotation\n    typed_class_var: str = \"typed value\"\n\n    def __init__(self):\n        # Instance variables\n        self.instance_var = \"Initial instance value\"\n        self.reassignable_instance_var = 100\n\n        # Instance variable with type annotation\n        self.typed_instance_var: list[str] = [\"item1\", \"item2\"]\n\n    def modify_instance_var(self):\n        # Reassign instance variable\n        self.instance_var = \"Modified instance value\"\n        self.reassignable_instance_var = 200  # Reassigned\n\n    def use_module_var(self):\n        # Use module-level variables\n        result = module_var + \" used in method\"\n        other_result = reassignable_module_var + 5\n        return result, other_result\n\n    def use_class_var(self):\n        # Use class-level variables\n        result = VariableContainer.class_var + \" used in method\"\n        other_result = VariableContainer.reassignable_class_var\n        return result, other_result\n\n\n# Dataclass with variables\n@dataclass\nclass VariableDataclass:\n    \"\"\"Dataclass that contains various fields.\"\"\"\n\n    # Field variables with type annotations\n    id: int\n    name: str\n    items: list[str] = field(default_factory=list)\n    metadata: dict[str, str] = field(default_factory=dict)\n    optional_value: float | None = None\n\n    # This will be reassigned in various places\n    status: str = \"pending\"\n\n\n# Function that uses the module variables\ndef use_module_variables():\n    \"\"\"Function that uses module-level variables.\"\"\"\n    result = module_var + \" used in function\"\n    other_result = reassignable_module_var * 2\n    return result, other_result\n\n\n# Create instances and use variables\ndataclass_instance = VariableDataclass(id=1, name=\"Test\")\ndataclass_instance.status = \"active\"  # Reassign dataclass field\n\n# Use variables at module level\nmodule_result = module_var + \" used at module level\"\nother_module_result = reassignable_module_var + 30\n\n# Create a second dataclass instance with different status\nsecond_dataclass = VariableDataclass(id=2, name=\"Another Test\")\nsecond_dataclass.status = \"completed\"  # Another reassignment of status\n"
  },
  {
    "path": "test/resources/repos/r/test_repo/.Rbuildignore",
    "content": "^.*\\.Rproj$\n^\\.Rproj\\.user$\n^\\.serena$"
  },
  {
    "path": "test/resources/repos/r/test_repo/DESCRIPTION",
    "content": "Package: testpackage\nType: Package\nTitle: Test Package for R Language Server\nVersion: 1.0.0\nAuthor: Serena Test\nMaintainer: Serena Test <test@example.com>\nDescription: A minimal test package for testing R language server functionality.\n    This package contains sample R functions for testing symbol extraction,\n    completion, and other language server features.\nLicense: MIT + file LICENSE\nEncoding: UTF-8\nLazyData: true\nRoxygenNote: 7.2.0"
  },
  {
    "path": "test/resources/repos/r/test_repo/NAMESPACE",
    "content": "# Generated by roxygen2: do not edit by hand\n\nexport(calculate_mean)\nexport(create_data_frame)\nexport(fit_linear_model)\nexport(plot_data)\nexport(process_data)"
  },
  {
    "path": "test/resources/repos/r/test_repo/R/models.R",
    "content": "#' Fit a linear model\n#'\n#' @param formula A formula for the model\n#' @param data A data frame containing the variables\n#' @return A fitted lm object\n#' @export\nfit_linear_model <- function(formula, data) {\n    if (missing(formula) || missing(data)) {\n        stop(\"Both formula and data are required\")\n    }\n    \n    model <- lm(formula, data = data)\n    \n    # Add some custom attributes\n    attr(model, \"created_by\") <- \"fit_linear_model\"\n    attr(model, \"creation_time\") <- Sys.time()\n    \n    return(model)\n}\n\n#' Plot data using ggplot2-style syntax\n#'\n#' @param data A data frame\n#' @param x_var Column name for x-axis\n#' @param y_var Column name for y-axis\n#' @return A plot object\n#' @export\nplot_data <- function(data, x_var, y_var) {\n    if (!is.data.frame(data)) {\n        stop(\"data must be a data frame\")\n    }\n    \n    if (!(x_var %in% names(data))) {\n        stop(paste(\"Column\", x_var, \"not found in data\"))\n    }\n    \n    if (!(y_var %in% names(data))) {\n        stop(paste(\"Column\", y_var, \"not found in data\"))\n    }\n    \n    # Create a simple base R plot\n    plot(data[[x_var]], data[[y_var]], \n         xlab = x_var, ylab = y_var,\n         main = paste(y_var, \"vs\", x_var))\n    \n    # Add a trend line\n    abline(lm(data[[y_var]] ~ data[[x_var]]), col = \"red\")\n}"
  },
  {
    "path": "test/resources/repos/r/test_repo/R/utils.R",
    "content": "#' Calculate mean of numeric vector\n#'\n#' @param x A numeric vector\n#' @return The mean of the vector\n#' @export\ncalculate_mean <- function(x) {\n    if (!is.numeric(x)) {\n        stop(\"Input must be numeric\")\n    }\n    mean(x, na.rm = TRUE)\n}\n\n#' Process data by removing missing values\n#'\n#' @param data A data frame\n#' @return A cleaned data frame\n#' @export\nprocess_data <- function(data) {\n    if (!is.data.frame(data)) {\n        stop(\"Input must be a data frame\")\n    }\n    \n    # Remove rows with any missing values\n    clean_data <- na.omit(data)\n    \n    # Add a processed flag\n    clean_data$processed <- TRUE\n    \n    return(clean_data)\n}\n\n#' Create a sample data frame\n#'\n#' @param n Number of rows to create\n#' @return A data frame with sample data\n#' @export\ncreate_data_frame <- function(n = 100) {\n    data.frame(\n        id = 1:n,\n        value = rnorm(n),\n        category = sample(c(\"A\", \"B\", \"C\"), n, replace = TRUE),\n        stringsAsFactors = FALSE\n    )\n}"
  },
  {
    "path": "test/resources/repos/r/test_repo/examples/analysis.R",
    "content": "# Example R script demonstrating package usage\n\n# Load required libraries\nlibrary(testpackage)\n\n# Create sample data\nsample_data <- create_data_frame(n = 50)\n\n# Process the data\nclean_data <- process_data(sample_data)\n\n# Calculate some statistics\nmean_value <- calculate_mean(clean_data$value)\ncat(\"Mean value:\", mean_value, \"\\n\")\n\n# Fit a simple model\nmodel <- fit_linear_model(value ~ id, data = clean_data)\nsummary(model)\n\n# Create a plot\nplot_data(clean_data, \"id\", \"value\")\n\n# Additional analysis function (not exported)\nanalyze_categories <- function(data) {\n    table(data$category)\n}\n\n# Run the analysis\ncategory_summary <- analyze_categories(clean_data)\nprint(category_summary)"
  },
  {
    "path": "test/resources/repos/rego/test_repo/policies/authz.rego",
    "content": "package policies\n\nimport data.utils\n\n# Default deny\ndefault allow := false\n\n# Admin access rule\nallow if {\n\tinput.user.role == \"admin\"\n\tutils.is_valid_user(input.user)\n}\n\n# Read access for authenticated users\nallow_read if {\n\tinput.action == \"read\"\n\tinput.user.authenticated\n}\n\n# User roles list\nadmin_roles := [\"admin\", \"superuser\"]\n\n# Helper function to check if user is admin\nis_admin(user) if {\n\tadmin_roles[_] == user.role\n}\n\n# Check if action is allowed for user\ncheck_permission(user, action) if {\n\tuser.role == \"admin\"\n\tallowed_actions := [\"read\", \"write\", \"delete\"]\n\tallowed_actions[_] == action\n}\n"
  },
  {
    "path": "test/resources/repos/rego/test_repo/policies/validation.rego",
    "content": "package policies\n\nimport data.policies\nimport data.utils\n\n# Validate user input\nvalidate_user_input if {\n\tutils.is_valid_user(input.user)\n\tutils.is_valid_email(input.user.email)\n}\n\n# Check if user has valid credentials\nhas_valid_credentials(user) if {\n\tuser.username != \"\"\n\tuser.password != \"\"\n\tutils.is_valid_email(user.email)\n}\n\n# Validate request\nvalidate_request if {\n\tinput.user.authenticated\n\tpolicies.allow\n}\n"
  },
  {
    "path": "test/resources/repos/rego/test_repo/utils/helpers.rego",
    "content": "package utils\n\n# User validation\nis_valid_user(user) if {\n\tuser.id != \"\"\n\tuser.email != \"\"\n}\n\n# Email validation\nis_valid_email(email) if {\n\tcontains(email, \"@\")\n\tcontains(email, \".\")\n}\n\n# Username validation\nis_valid_username(username) if {\n\tcount(username) >= 3\n\tcount(username) <= 32\n}\n\n# Check if string is empty\nis_empty(str) if {\n\tstr == \"\"\n}\n\n# Check if array contains element\narray_contains(arr, elem) if {\n\tarr[_] == elem\n}\n"
  },
  {
    "path": "test/resources/repos/ruby/test_repo/.solargraph.yml",
    "content": "---\ninclude:\n  - \"main.rb\"\n  - \"lib.rb\"\n"
  },
  {
    "path": "test/resources/repos/ruby/test_repo/examples/user_management.rb",
    "content": "require '../services.rb'\nrequire '../models.rb'\n\nclass UserStats\n  attr_reader :user_count, :active_users, :last_updated\n\n  def initialize\n    @user_count = 0\n    @active_users = 0\n    @last_updated = Time.now\n  end\n\n  def update_stats(total, active)\n    @user_count = total\n    @active_users = active\n    @last_updated = Time.now\n  end\n\n  def activity_ratio\n    return 0.0 if @user_count == 0\n    (@active_users.to_f / @user_count * 100).round(2)\n  end\n\n  def formatted_stats\n    \"Users: #{@user_count}, Active: #{@active_users} (#{activity_ratio}%)\"\n  end\nend\n\nclass UserManager\n  def initialize\n    @service = Services::UserService.new\n    @stats = UserStats.new\n  end\n\n  def create_user_with_tracking(id, name, email = nil)\n    user = @service.create_user(id, name)\n    user.email = email if email\n    \n    update_statistics\n    notify_user_created(user)\n    \n    user\n  end\n\n  def get_user_details(id)\n    user = @service.get_user(id)\n    return nil unless user\n    \n    {\n      user_info: user.full_info,\n      created_at: Time.now,\n      stats: @stats.formatted_stats\n    }\n  end\n\n  def bulk_create_users(user_data_list)\n    created_users = []\n    \n    user_data_list.each do |data|\n      user = create_user_with_tracking(data[:id], data[:name], data[:email])\n      created_users << user\n    end\n    \n    created_users\n  end\n\n  private\n\n  def update_statistics\n    total_users = @service.users.length\n    # For demo purposes, assume all users are active\n    @stats.update_stats(total_users, total_users)\n  end\n\n  def notify_user_created(user)\n    puts \"User created: #{user.name} (ID: #{user.id})\"\n  end\nend\n\ndef process_user_data(raw_data)\n  processed = raw_data.map do |entry|\n    {\n      id: entry[\"id\"] || entry[:id],\n      name: entry[\"name\"] || entry[:name],\n      email: entry[\"email\"] || entry[:email]\n    }\n  end\n  \n  processed.reject { |entry| entry[:name].nil? || entry[:name].empty? }\nend\n\ndef main\n  # Example usage\n  manager = UserManager.new\n  \n  sample_data = [\n    { id: 1, name: \"Alice Johnson\", email: \"alice@example.com\" },\n    { id: 2, name: \"Bob Smith\", email: \"bob@example.com\" },\n    { id: 3, name: \"Charlie Brown\" }\n  ]\n  \n  users = manager.bulk_create_users(sample_data)\n  \n  users.each do |user|\n    details = manager.get_user_details(user.id)\n    puts details[:user_info]\n  end\n  \n  puts \"\\nFinal statistics:\"\n  stats = UserStats.new\n  stats.update_stats(users.length, users.length)\n  puts stats.formatted_stats\nend\n\n# Execute if this file is run directly\nmain if __FILE__ == $0"
  },
  {
    "path": "test/resources/repos/ruby/test_repo/lib.rb",
    "content": "class Calculator\n  def add(a, b)\n    a + b\n  end\n\n  def subtract(a, b)\n    a - b\n  end\nend\n"
  },
  {
    "path": "test/resources/repos/ruby/test_repo/main.rb",
    "content": "require './lib.rb'\n\nclass DemoClass\n  attr_accessor :value\n\n  def initialize(value)\n    @value = value\n  end\n\n  def print_value\n    puts @value\n  end\nend\n\ndef helper_function(number = 42)\n  demo = DemoClass.new(number)\n  Calculator.new.add(demo.value, 10)\n  demo.print_value\nend\n\nhelper_function\n"
  },
  {
    "path": "test/resources/repos/ruby/test_repo/models.rb",
    "content": "class User\n  attr_accessor :id, :name, :email\n\n  def initialize(id, name, email = nil)\n    @id = id\n    @name = name\n    @email = email\n  end\n\n  def full_info\n    info = \"User: #{@name} (ID: #{@id})\"\n    info += \", Email: #{@email}\" if @email\n    info\n  end\n\n  def to_hash\n    {\n      id: @id,\n      name: @name,\n      email: @email\n    }\n  end\n\n  def self.from_hash(hash)\n    new(hash[:id], hash[:name], hash[:email])\n  end\n\n  class << self\n    def default_user\n      new(0, \"Guest\")\n    end\n  end\nend\n\nclass Item\n  attr_reader :id, :name, :price\n\n  def initialize(id, name, price)\n    @id = id\n    @name = name\n    @price = price\n  end\n\n  def discounted_price(discount_percent)\n    @price * (1 - discount_percent / 100.0)\n  end\n\n  def description\n    \"#{@name}: $#{@price}\"\n  end\nend\n\nmodule ItemHelpers\n  def format_price(price)\n    \"$#{sprintf('%.2f', price)}\"\n  end\n\n  def calculate_tax(price, tax_rate = 0.08)\n    price * tax_rate\n  end\nend\n\nclass Order\n  include ItemHelpers\n\n  def initialize\n    @items = []\n    @total = 0\n  end\n\n  def add_item(item, quantity = 1)\n    @items << { item: item, quantity: quantity }\n    calculate_total\n  end\n\n  def total_with_tax\n    tax = calculate_tax(@total)\n    @total + tax\n  end\n\n  private\n\n  def calculate_total\n    @total = @items.sum { |entry| entry[:item].price * entry[:quantity] }\n  end\nend"
  },
  {
    "path": "test/resources/repos/ruby/test_repo/nested.rb",
    "content": "class OuterClass\n  def initialize\n    @value = \"outer\"\n  end\n\n  def outer_method\n    inner_function = lambda do |x|\n      x * 2\n    end\n    \n    result = inner_function.call(5)\n    puts \"Result: #{result}\"\n  end\n\n  class NestedClass\n    def initialize(name)\n      @name = name\n    end\n\n    def find_me\n      \"Found in NestedClass: #{@name}\"\n    end\n\n    def nested_method\n      puts \"Nested method called\"\n    end\n\n    class DeeplyNested\n      def deep_method\n        \"Deep inside\"\n      end\n    end\n  end\n\n  module NestedModule\n    def module_method\n      \"Module method\"\n    end\n\n    class ModuleClass\n      def module_class_method\n        \"Module class method\"\n      end\n    end\n  end\nend\n\n# Test usage of nested classes\nouter = OuterClass.new\nnested = OuterClass::NestedClass.new(\"test\")\nresult = nested.find_me"
  },
  {
    "path": "test/resources/repos/ruby/test_repo/services.rb",
    "content": "require './lib.rb'\nrequire './models.rb'\n\nmodule Services\n  class UserService\n    attr_reader :users\n\n    def initialize\n      @users = {}\n    end\n\n    def create_user(id, name)\n      user = User.new(id, name)\n      @users[id] = user\n      user\n    end\n\n    def get_user(id)\n      @users[id]\n    end\n\n    def delete_user(id)\n      @users.delete(id)\n    end\n\n    private\n\n    def validate_user_data(id, name)\n      return false if id.nil? || name.nil?\n      return false if name.empty?\n      true\n    end\n  end\n\n  class ItemService\n    def initialize\n      @items = []\n    end\n\n    def add_item(item)\n      @items << item\n    end\n\n    def find_item(id)\n      @items.find { |item| item.id == id }\n    end\n  end\nend\n\n# Module-level function\ndef create_service_container\n  {\n    user_service: Services::UserService.new,\n    item_service: Services::ItemService.new\n  }\nend\n\n# Variables for testing\nuser_service_instance = Services::UserService.new\nitem_service_instance = Services::ItemService.new"
  },
  {
    "path": "test/resources/repos/ruby/test_repo/variables.rb",
    "content": "require './models.rb'\n\n# Global variables for testing references\n$global_counter = 0\n$global_config = {\n  debug: true,\n  timeout: 30\n}\n\nclass DataContainer\n  attr_accessor :status, :data, :metadata\n\n  def initialize\n    @status = \"pending\"\n    @data = {}\n    @metadata = {\n      created_at: Time.now,\n      version: \"1.0\"\n    }\n  end\n\n  def update_status(new_status)\n    old_status = @status\n    @status = new_status\n    log_status_change(old_status, new_status)\n  end\n\n  def process_data(input_data)\n    @data = input_data\n    @status = \"processing\"\n    \n    # Process the data\n    result = @data.transform_values { |v| v.to_s.upcase }\n    @status = \"completed\"\n    \n    result\n  end\n\n  def get_metadata_info\n    info = \"Status: #{@status}, Version: #{@metadata[:version]}\"\n    info += \", Created: #{@metadata[:created_at]}\"\n    info\n  end\n\n  private\n\n  def log_status_change(old_status, new_status)\n    puts \"Status changed from #{old_status} to #{new_status}\"\n  end\nend\n\nclass StatusTracker\n  def initialize\n    @tracked_items = []\n  end\n\n  def add_item(item)\n    @tracked_items << item\n    item.status = \"tracked\" if item.respond_to?(:status=)\n  end\n\n  def find_by_status(target_status)\n    @tracked_items.select { |item| item.status == target_status }\n  end\n\n  def update_all_status(new_status)\n    @tracked_items.each do |item|\n      item.status = new_status if item.respond_to?(:status=)\n    end\n  end\nend\n\n# Module level variables and functions\nmodule ProcessingHelper\n  PROCESSING_MODES = [\"sync\", \"async\", \"batch\"].freeze\n  \n  @@instance_count = 0\n  \n  def self.create_processor(mode = \"sync\")\n    @@instance_count += 1\n    {\n      id: @@instance_count,\n      mode: mode,\n      created_at: Time.now\n    }\n  end\n  \n  def self.get_instance_count\n    @@instance_count\n  end\nend\n\n# Test instances for reference testing\ndataclass_instance = DataContainer.new\ndataclass_instance.status = \"initialized\"\n\nsecond_dataclass = DataContainer.new  \nsecond_dataclass.update_status(\"ready\")\n\ntracker = StatusTracker.new\ntracker.add_item(dataclass_instance)\ntracker.add_item(second_dataclass)\n\n# Function that uses the variables\ndef demonstrate_variable_usage\n  puts \"Global counter: #{$global_counter}\"\n  \n  container = DataContainer.new\n  container.status = \"demo\"\n  \n  processor = ProcessingHelper.create_processor(\"async\")\n  puts \"Created processor #{processor[:id]} in #{processor[:mode]} mode\"\n  \n  container\nend\n\n# More complex variable interactions\nclass VariableInteractionTest\n  def initialize\n    @internal_status = \"created\"\n    @data_containers = []\n  end\n  \n  def add_container(container)\n    @data_containers << container\n    container.status = \"added_to_collection\"\n    @internal_status = \"modified\"\n  end\n  \n  def process_all_containers\n    @data_containers.each do |container|\n      container.status = \"batch_processed\"\n    end\n    @internal_status = \"processing_complete\"\n  end\n  \n  def get_status_summary\n    statuses = @data_containers.map(&:status)\n    {\n      internal: @internal_status,\n      containers: statuses,\n      count: @data_containers.length\n    }\n  end\nend\n\n# Create instances for testing\ninteraction_test = VariableInteractionTest.new\ninteraction_test.add_container(dataclass_instance)\ninteraction_test.add_container(second_dataclass)"
  },
  {
    "path": "test/resources/repos/rust/test_repo/Cargo.toml",
    "content": "[package]\nname = \"rsandbox\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\n"
  },
  {
    "path": "test/resources/repos/rust/test_repo/src/lib.rs",
    "content": "// This function returns the sum of 2 + 2\npub fn add() -> i32 {\n    let res = 2 + 2;\n    res\n}\npub fn multiply() -> i32 {\n    2 * 3\n}\n\n"
  },
  {
    "path": "test/resources/repos/rust/test_repo/src/main.rs",
    "content": "use rsandbox::add;\n\nfn main() {\n    println!(\"Hello, World!\");\n    println!(\"Good morning!\");\n    println!(\"add result: {}\", add());\n    println!(\"inserted line\");\n}\n"
  },
  {
    "path": "test/resources/repos/rust/test_repo_2024/Cargo.toml",
    "content": "[package]\nname = \"rsandbox_2024\"\nversion = \"0.1.0\"\nedition = \"2024\"\n\n[dependencies]"
  },
  {
    "path": "test/resources/repos/rust/test_repo_2024/src/lib.rs",
    "content": "pub fn multiply(a: i32, b: i32) -> i32 {\n    a * b\n}\n\npub struct Calculator {\n    pub result: i32,\n}\n\nimpl Calculator {\n    pub fn new() -> Self {\n        Calculator { result: 0 }\n    }\n\n    pub fn add(&mut self, value: i32) {\n        self.result += value;\n    }\n\n    pub fn get_result(&self) -> i32 {\n        self.result\n    }\n}"
  },
  {
    "path": "test/resources/repos/rust/test_repo_2024/src/main.rs",
    "content": "fn main() {\n    println!(\"Hello, Rust 2024 edition!\");\n    let result = add(2, 3);\n    println!(\"2 + 3 = {}\", result);\n}\n\npub fn add(a: i32, b: i32) -> i32 {\n    a + b\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn test_add() {\n        assert_eq!(add(2, 3), 5);\n    }\n}"
  },
  {
    "path": "test/resources/repos/scala/build.sbt",
    "content": "scalaVersion := \"2.13.16\"\n"
  },
  {
    "path": "test/resources/repos/scala/project/build.properties",
    "content": "sbt.version=1.10.1\n"
  },
  {
    "path": "test/resources/repos/scala/project/metals.sbt",
    "content": "// format: off\n// DO NOT EDIT! This file is auto-generated.\n\n// This file enables sbt-bloop to create bloop config files.\n\naddSbtPlugin(\"ch.epfl.scala\" % \"sbt-bloop\" % \"2.0.13\")\n\n// format: on\n"
  },
  {
    "path": "test/resources/repos/scala/project/plugins.sbt",
    "content": "addSbtPlugin(\"ch.epfl.scala\" % \"sbt-bloop\" % \"v2.0.14\")"
  },
  {
    "path": "test/resources/repos/scala/src/main/scala/com/example/Main.scala",
    "content": "package com.example\n\nobject Main {\n  def main(args: Array[String]): Unit = {\n    println(\"Hello, Scala!\")\n    \n    // Use Utils from another file\n    Utils.printHello()\n    val result = Utils.multiply(3, 4)\n    println(s\"3 * 4 = $result\")\n\n    // Call local methods\n    val sum = add(5, 3)\n    println(s\"5 + 3 = $sum\")\n  }\n\n  def add(a: Int, b: Int): Int = {\n    a + b\n  }\n\n  // https://github.com/oraios/serena/issues/688\n  def someMethod(config: Config): Unit = {\n    val str = config.field1\n\n    println(str)\n  }\n  \n  case class Config(field1:String)\n}\n"
  },
  {
    "path": "test/resources/repos/scala/src/main/scala/com/example/Utils.scala",
    "content": "package com.example\n\nobject Utils {\n  def printHello(): Unit = {\n    println(\"Hello from Utils!\")\n  }\n  \n  def multiply(x: Int, y: Int): Int = {\n    x * y\n  }\n}\n"
  },
  {
    "path": "test/resources/repos/solidity/test_repo/.gitignore",
    "content": "out/\ncache/\nartifacts/\nnode_modules/\n"
  },
  {
    "path": "test/resources/repos/solidity/test_repo/contracts/Token.sol",
    "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nimport \"./interfaces/IERC20.sol\";\nimport \"./lib/SafeMath.sol\";\n\n/// @title Token\n/// @notice A simple ERC-20 token implementation used as a test fixture.\ncontract Token is IERC20 {\n    using SafeMath for uint256;\n\n    // -------------------------------------------------------------------------\n    // State variables\n    // -------------------------------------------------------------------------\n\n    string public name;\n    string public symbol;\n    uint8 public decimals;\n    uint256 private _totalSupply;\n\n    mapping(address => uint256) private _balances;\n    mapping(address => mapping(address => uint256)) private _allowances;\n\n    // -------------------------------------------------------------------------\n    // Errors\n    // -------------------------------------------------------------------------\n\n    /// @notice Thrown when transferring to the zero address.\n    error ZeroAddress();\n\n    /// @notice Thrown when the caller's balance is insufficient.\n    error InsufficientBalance(address account, uint256 required, uint256 available);\n\n    /// @notice Thrown when the allowance is insufficient.\n    error InsufficientAllowance(address spender, uint256 required, uint256 available);\n\n    // -------------------------------------------------------------------------\n    // Constructor\n    // -------------------------------------------------------------------------\n\n    /// @param _name   Human-readable token name.\n    /// @param _symbol Token ticker symbol.\n    /// @param supply  Initial supply minted to `msg.sender` (in whole tokens).\n    constructor(string memory _name, string memory _symbol, uint256 supply) {\n        name = _name;\n        symbol = _symbol;\n        decimals = 18;\n        _mint(msg.sender, supply * 10 ** decimals);\n    }\n\n    // -------------------------------------------------------------------------\n    // IERC20 view functions\n    // -------------------------------------------------------------------------\n\n    /// @inheritdoc IERC20\n    function totalSupply() external view override returns (uint256) {\n        return _totalSupply;\n    }\n\n    /// @inheritdoc IERC20\n    function balanceOf(address account) external view override returns (uint256) {\n        return _balances[account];\n    }\n\n    /// @inheritdoc IERC20\n    function allowance(address owner, address spender) external view override returns (uint256) {\n        return _allowances[owner][spender];\n    }\n\n    // -------------------------------------------------------------------------\n    // IERC20 mutating functions\n    // -------------------------------------------------------------------------\n\n    /// @inheritdoc IERC20\n    function transfer(address to, uint256 amount) external override returns (bool) {\n        _transfer(msg.sender, to, amount);\n        return true;\n    }\n\n    /// @inheritdoc IERC20\n    function approve(address spender, uint256 amount) external override returns (bool) {\n        _approve(msg.sender, spender, amount);\n        return true;\n    }\n\n    /// @inheritdoc IERC20\n    function transferFrom(address from, address to, uint256 amount) external override returns (bool) {\n        uint256 currentAllowance = _allowances[from][msg.sender];\n        if (currentAllowance < amount) {\n            revert InsufficientAllowance(msg.sender, amount, currentAllowance);\n        }\n        _approve(from, msg.sender, currentAllowance.sub(amount));\n        _transfer(from, to, amount);\n        return true;\n    }\n\n    // -------------------------------------------------------------------------\n    // Internal helpers\n    // -------------------------------------------------------------------------\n\n    function _transfer(address from, address to, uint256 amount) internal {\n        if (to == address(0)) revert ZeroAddress();\n        uint256 fromBalance = _balances[from];\n        if (fromBalance < amount) {\n            revert InsufficientBalance(from, amount, fromBalance);\n        }\n        _balances[from] = fromBalance.sub(amount);\n        _balances[to] = _balances[to].add(amount);\n        emit Transfer(from, to, amount);\n    }\n\n    function _approve(address owner, address spender, uint256 amount) internal {\n        if (owner == address(0) || spender == address(0)) revert ZeroAddress();\n        _allowances[owner][spender] = amount;\n        emit Approval(owner, spender, amount);\n    }\n\n    function _mint(address account, uint256 amount) internal {\n        if (account == address(0)) revert ZeroAddress();\n        _totalSupply = _totalSupply.add(amount);\n        _balances[account] = _balances[account].add(amount);\n        emit Transfer(address(0), account, amount);\n    }\n}\n"
  },
  {
    "path": "test/resources/repos/solidity/test_repo/contracts/interfaces/IERC20.sol",
    "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\n/// @title IERC20\n/// @notice Minimal ERC-20 interface used by the test token.\ninterface IERC20 {\n    /// @notice Emitted when tokens are transferred between accounts.\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /// @notice Emitted when an allowance is set via `approve`.\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /// @notice Returns the total token supply.\n    function totalSupply() external view returns (uint256);\n\n    /// @notice Returns the token balance of `account`.\n    function balanceOf(address account) external view returns (uint256);\n\n    /// @notice Transfers `amount` tokens to `to`.\n    function transfer(address to, uint256 amount) external returns (bool);\n\n    /// @notice Returns the remaining allowance that `spender` has over `owner`'s tokens.\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /// @notice Sets `amount` as the allowance of `spender` over the caller's tokens.\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /// @notice Moves `amount` tokens from `from` to `to` using the allowance mechanism.\n    function transferFrom(address from, address to, uint256 amount) external returns (bool);\n}\n"
  },
  {
    "path": "test/resources/repos/solidity/test_repo/contracts/lib/SafeMath.sol",
    "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\n/// @title SafeMath\n/// @notice Arithmetic helpers with overflow checks (illustrative — 0.8+ reverts natively).\nlibrary SafeMath {\n    /// @notice Returns the sum of `a` and `b`, reverting on overflow.\n    function add(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a + b;\n    }\n\n    /// @notice Returns `a` minus `b`, reverting on underflow.\n    function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n        require(b <= a, \"SafeMath: subtraction underflow\");\n        return a - b;\n    }\n\n    /// @notice Returns the product of `a` and `b`, reverting on overflow.\n    function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n        if (a == 0) return 0;\n        return a * b;\n    }\n\n    /// @notice Returns the integer division of `a` by `b`, reverting on division by zero.\n    function div(uint256 a, uint256 b) internal pure returns (uint256) {\n        require(b > 0, \"SafeMath: division by zero\");\n        return a / b;\n    }\n}\n"
  },
  {
    "path": "test/resources/repos/solidity/test_repo/foundry.toml",
    "content": "[profile.default]\nsrc = \"contracts\"\nout = \"out\"\nlibs = []\nsolc = \"0.8.20\"\n"
  },
  {
    "path": "test/resources/repos/swift/test_repo/Package.swift",
    "content": "// swift-tools-version: 5.9\nimport PackageDescription\n\nlet package = Package(\n    name: \"test_repo\",\n    products: [\n        .library(\n            name: \"test_repo\",\n            targets: [\"test_repo\"]),\n    ],\n    targets: [\n        .target(\n            name: \"test_repo\",\n            dependencies: []),\n    ]\n)"
  },
  {
    "path": "test/resources/repos/swift/test_repo/src/main.swift",
    "content": "import Foundation\n\n// Main entry point\nfunc main() {\n    let calculator = Calculator()\n    let result = calculator.add(5, 3)\n    print(\"Result: \\(result)\")\n    \n    let user = User(name: \"Alice\", age: 30)\n    user.greet()\n    \n    let area = Utils.calculateArea(radius: 5.0)\n    print(\"Circle area: \\(area)\")\n}\n\nclass Calculator {\n    func add(_ a: Int, _ b: Int) -> Int {\n        return a + b\n    }\n    \n    func multiply(_ a: Int, _ b: Int) -> Int {\n        return a * b\n    }\n}\n\nstruct User {\n    let name: String\n    let age: Int\n    \n    func greet() {\n        print(\"Hello, my name is \\(name) and I am \\(age) years old.\")\n    }\n    \n    func isAdult() -> Bool {\n        return age >= 18\n    }\n}\n\nenum Status {\n    case active\n    case inactive\n    case pending\n}\n\nprotocol Drawable {\n    func draw()\n}\n\nclass Circle: Drawable {\n    let radius: Double\n    \n    init(radius: Double) {\n        self.radius = radius\n    }\n    \n    func draw() {\n        print(\"Drawing a circle with radius \\(radius)\")\n    }\n}\n\n// Call main\nmain()"
  },
  {
    "path": "test/resources/repos/swift/test_repo/src/utils.swift",
    "content": "import Foundation\n\npublic struct Utils {\n    public static func formatDate(_ date: Date) -> String {\n        let formatter = DateFormatter()\n        formatter.dateStyle = .medium\n        return formatter.string(from: date)\n    }\n    \n    public static func calculateArea(radius: Double) -> Double {\n        return Double.pi * radius * radius\n    }\n}\n\npublic extension String {\n    func isValidEmail() -> Bool {\n        let emailRegex = \"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\\\.[A-Za-z]{2,}\"\n        return NSPredicate(format: \"SELF MATCHES %@\", emailRegex).evaluate(with: self)\n    }\n}"
  },
  {
    "path": "test/resources/repos/systemverilog/test_repo/alu.sv",
    "content": "// ALU module for testing SystemVerilog LSP\nmodule alu #(\n    parameter DATA_WIDTH = 32\n) (\n    input  logic [DATA_WIDTH-1:0] a,\n    input  logic [DATA_WIDTH-1:0] b,\n    input  logic [2:0] op,\n    output logic [DATA_WIDTH-1:0] result,\n    output logic zero\n);\n\n    typedef enum logic [2:0] {\n        ALU_ADD = 3'b000,\n        ALU_SUB = 3'b001,\n        ALU_AND = 3'b010,\n        ALU_OR  = 3'b011,\n        ALU_XOR = 3'b100,\n        ALU_SLL = 3'b101,\n        ALU_SRL = 3'b110,\n        ALU_SRA = 3'b111\n    } alu_op_t;\n\n    always_comb begin\n        case (op)\n            ALU_ADD: result = a + b;\n            ALU_SUB: result = a - b;\n            ALU_AND: result = a & b;\n            ALU_OR:  result = a | b;\n            ALU_XOR: result = a ^ b;\n            ALU_SLL: result = a << b[4:0];\n            ALU_SRL: result = a >> b[4:0];\n            ALU_SRA: result = $signed(a) >>> b[4:0];\n            default: result = '0;\n        endcase\n    end\n\n    assign zero = (result == '0);\n\nendmodule\n"
  },
  {
    "path": "test/resources/repos/systemverilog/test_repo/counter.sv",
    "content": "// Simple counter module for testing SystemVerilog LSP\nmodule counter #(\n    parameter WIDTH = 8\n) (\n    input  logic clk,\n    input  logic rst_n,\n    input  logic enable,\n    output logic [WIDTH-1:0] count\n);\n\n    // Counter logic\n    always_ff @(posedge clk or negedge rst_n) begin\n        if (!rst_n)\n            count <= '0;\n        else if (enable)\n            count <= count + 1'b1;\n    end\n\nendmodule\n"
  },
  {
    "path": "test/resources/repos/systemverilog/test_repo/top.sv",
    "content": "// Top module that instantiates counter and alu for cross-file testing\n`include \"types.svh\"\n\nmodule top (\n    input  logic        clk,\n    input  logic        rst_n,\n    input  logic        enable,\n    input  word_t       a,\n    input  word_t       b,\n    input  logic [2:0]  op,\n    output byte_t       count,\n    output word_t       alu_result,\n    output logic        alu_zero\n);\n\n    // Instantiate counter module\n    counter #(.WIDTH(8)) u_counter (\n        .clk(clk),\n        .rst_n(rst_n),\n        .enable(enable),\n        .count(count)\n    );\n\n    // Instantiate ALU module\n    alu #(.DATA_WIDTH(32)) u_alu (\n        .a(a),\n        .b(b),\n        .op(op),\n        .result(alu_result),\n        .zero(alu_zero)\n    );\n\nendmodule\n"
  },
  {
    "path": "test/resources/repos/systemverilog/test_repo/types.svh",
    "content": "// Common types header for testing SystemVerilog LSP\n`ifndef TYPES_SVH\n`define TYPES_SVH\n\ntypedef logic [7:0] byte_t;\ntypedef logic [15:0] halfword_t;\ntypedef logic [31:0] word_t;\ntypedef logic [63:0] doubleword_t;\n\ntypedef struct packed {\n    logic valid;\n    logic [31:0] data;\n    logic [3:0] tag;\n} tagged_data_t;\n\n`endif // TYPES_SVH\n"
  },
  {
    "path": "test/resources/repos/terraform/test_repo/data.tf",
    "content": "# Data sources for the Terraform configuration\n\n# Get the latest Ubuntu AMI\ndata \"aws_ami\" \"ubuntu\" {\n  most_recent = true\n  owners      = [\"099720109477\"] # Canonical\n  \n  filter {\n    name   = \"name\"\n    values = [\"ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*\"]\n  }\n  \n  filter {\n    name   = \"virtualization-type\"\n    values = [\"hvm\"]\n  }\n}\n\n# Get available availability zones\ndata \"aws_availability_zones\" \"available\" {\n  state = \"available\"\n}\n\n# Get current AWS caller identity\ndata \"aws_caller_identity\" \"current\" {}\n\n# Get current AWS region\ndata \"aws_region\" \"current\" {}\n"
  },
  {
    "path": "test/resources/repos/terraform/test_repo/main.tf",
    "content": "# Main Terraform configuration\nterraform {\n  required_version = \">= 1.0\"\n  required_providers {\n    aws = {\n      source  = \"hashicorp/aws\"\n      version = \"~> 5.0\"\n    }\n  }\n}\n\nprovider \"aws\" {\n  region = var.aws_region\n}\n\n# EC2 Instance\nresource \"aws_instance\" \"web_server\" {\n  ami           = data.aws_ami.ubuntu.id\n  instance_type = var.instance_type\n  \n  vpc_security_group_ids = [aws_security_group.web_sg.id]\n  subnet_id              = aws_subnet.public.id\n  \n  user_data = <<-EOF\n    #!/bin/bash\n    apt-get update\n    apt-get install -y nginx\n    systemctl start nginx\n    systemctl enable nginx\n  EOF\n  \n  tags = {\n    Name        = \"${var.project_name}-web-server\"\n    Environment = var.environment\n    Project     = var.project_name\n  }\n}\n\n# S3 Bucket\nresource \"aws_s3_bucket\" \"app_bucket\" {\n  bucket = \"${var.project_name}-${var.environment}-bucket\"\n  \n  tags = {\n    Name        = \"${var.project_name}-bucket\"\n    Environment = var.environment\n    Project     = var.project_name\n  }\n}\n\nresource \"aws_s3_bucket_versioning\" \"app_bucket_versioning\" {\n  bucket = aws_s3_bucket.app_bucket.id\n  versioning_configuration {\n    status = \"Enabled\"\n  }\n}\n\n# VPC\nresource \"aws_vpc\" \"main\" {\n  cidr_block           = \"10.0.0.0/16\"\n  enable_dns_hostnames = true\n  enable_dns_support   = true\n  \n  tags = {\n    Name        = \"${var.project_name}-vpc\"\n    Environment = var.environment\n    Project     = var.project_name\n  }\n}\n\n# Internet Gateway\nresource \"aws_internet_gateway\" \"main\" {\n  vpc_id = aws_vpc.main.id\n  \n  tags = {\n    Name        = \"${var.project_name}-igw\"\n    Environment = var.environment\n    Project     = var.project_name\n  }\n}\n\n# Public Subnet\nresource \"aws_subnet\" \"public\" {\n  vpc_id                  = aws_vpc.main.id\n  cidr_block              = \"10.0.1.0/24\"\n  availability_zone       = data.aws_availability_zones.available.names[0]\n  map_public_ip_on_launch = true\n  \n  tags = {\n    Name        = \"${var.project_name}-public-subnet\"\n    Environment = var.environment\n    Project     = var.project_name\n  }\n}\n\n# Security Group\nresource \"aws_security_group\" \"web_sg\" {\n  name_prefix = \"${var.project_name}-web-\"\n  vpc_id      = aws_vpc.main.id\n  \n  ingress {\n    from_port   = 80\n    to_port     = 80\n    protocol    = \"tcp\"\n    cidr_blocks = [\"0.0.0.0/0\"]\n  }\n  \n  ingress {\n    from_port   = 443\n    to_port     = 443\n    protocol    = \"tcp\"\n    cidr_blocks = [\"0.0.0.0/0\"]\n  }\n  \n  egress {\n    from_port   = 0\n    to_port     = 0\n    protocol    = \"-1\"\n    cidr_blocks = [\"0.0.0.0/0\"]\n  }\n  \n  tags = {\n    Name        = \"${var.project_name}-web-sg\"\n    Environment = var.environment\n    Project     = var.project_name\n  }\n}\n"
  },
  {
    "path": "test/resources/repos/terraform/test_repo/outputs.tf",
    "content": "# Output values for the Terraform configuration\n\noutput \"instance_id\" {\n  description = \"ID of the EC2 instance\"\n  value       = aws_instance.web_server.id\n}\n\noutput \"instance_public_ip\" {\n  description = \"Public IP address of the EC2 instance\"\n  value       = aws_instance.web_server.public_ip\n}\n\noutput \"instance_public_dns\" {\n  description = \"Public DNS name of the EC2 instance\"\n  value       = aws_instance.web_server.public_dns\n}\n\noutput \"s3_bucket_name\" {\n  description = \"Name of the S3 bucket\"\n  value       = aws_s3_bucket.app_bucket.bucket\n}\n\noutput \"s3_bucket_arn\" {\n  description = \"ARN of the S3 bucket\"\n  value       = aws_s3_bucket.app_bucket.arn\n}\n\noutput \"vpc_id\" {\n  description = \"ID of the VPC\"\n  value       = aws_vpc.main.id\n}\n\noutput \"subnet_id\" {\n  description = \"ID of the public subnet\"\n  value       = aws_subnet.public.id\n}\n\noutput \"security_group_id\" {\n  description = \"ID of the security group\"\n  value       = aws_security_group.web_sg.id\n}\n\noutput \"application_url\" {\n  description = \"URL to access the application\"\n  value       = \"http://${aws_instance.web_server.public_dns}\"\n}\n"
  },
  {
    "path": "test/resources/repos/terraform/test_repo/variables.tf",
    "content": "# Input variables for the Terraform configuration\n\nvariable \"aws_region\" {\n  description = \"AWS region for resources\"\n  type        = string\n  default     = \"us-west-2\"\n}\n\nvariable \"instance_type\" {\n  description = \"EC2 instance type\"\n  type        = string\n  default     = \"t3.micro\"\n  \n  validation {\n    condition = contains([\n      \"t3.micro\", \"t3.small\", \"t3.medium\",\n      \"t2.micro\", \"t2.small\", \"t2.medium\"\n    ], var.instance_type)\n    error_message = \"Instance type must be a valid t2 or t3 instance type.\"\n  }\n}\n\nvariable \"environment\" {\n  description = \"Environment name (dev, staging, prod)\"\n  type        = string\n  default     = \"dev\"\n  \n  validation {\n    condition     = contains([\"dev\", \"staging\", \"prod\"], var.environment)\n    error_message = \"Environment must be dev, staging, or prod.\"\n  }\n}\n\nvariable \"project_name\" {\n  description = \"Name of the project\"\n  type        = string\n  default     = \"terraform-test\"\n  \n  validation {\n    condition     = can(regex(\"^[a-z0-9-]+$\", var.project_name))\n    error_message = \"Project name must contain only lowercase letters, numbers, and hyphens.\"\n  }\n}\n\nvariable \"enable_monitoring\" {\n  description = \"Enable CloudWatch monitoring\"\n  type        = bool\n  default     = false\n}\n\nvariable \"allowed_cidr_blocks\" {\n  description = \"List of CIDR blocks allowed to access the application\"\n  type        = list(string)\n  default     = [\"0.0.0.0/0\"]\n}\n\nvariable \"tags\" {\n  description = \"Additional tags to apply to resources\"\n  type        = map(string)\n  default     = {}\n}\n"
  },
  {
    "path": "test/resources/repos/toml/test_repo/Cargo.toml",
    "content": "[package]\nname = \"test_project\"\nversion = \"0.1.0\"\nedition = \"2021\"\ndescription = \"A test TOML file for Serena TOML language support\"\nauthors = [\"Test Author <test@example.com>\"]\nlicense = \"MIT\"\n\n[dependencies]\nserde = { version = \"1.0\", features = [\"derive\"] }\ntokio = { version = \"1.0\", features = [\"full\"] }\n\n[dev-dependencies]\nproptest = \"1.0\"\n\n[features]\ndefault = [\"feature1\"]\nfeature1 = []\nfeature2 = [\"feature1\"]\n\n[profile.release]\nlto = true\nopt-level = 3\n\n[[bin]]\nname = \"main\"\npath = \"src/main.rs\"\n\n[workspace]\nmembers = [\"crates/*\"]\n"
  },
  {
    "path": "test/resources/repos/toml/test_repo/config.toml",
    "content": "# Configuration file with various TOML features for testing\n\n[server]\nhost = \"localhost\"\nport = 8080\ndebug = false\ntimeout = 30.5\n\n# Inline table example\nendpoint = { url = \"https://api.example.com\", version = \"v1\" }\n\n[server.ssl]\nenabled = true\ncert_path = \"/etc/ssl/cert.pem\"\nkey_path = \"/etc/ssl/key.pem\"\n\n[database]\nconnection_string = \"\"\"\n    postgresql://user:password@localhost:5432/mydb?\n    sslmode=require&\n    pool_size=10\n\"\"\"\n\n[database.pool]\nmin_connections = 5\nmax_connections = 20\nidle_timeout = 300\n\n[logging]\nlevel = \"info\"\nformat = \"json\"\noutputs = [\"stdout\", \"file\"]\n\n[logging.file]\npath = \"/var/log/app.log\"\nmax_size = 10485760  # 10MB\nmax_backups = 5\ncompress = true\n\n# Array of inline tables\n[[endpoints]]\nname = \"users\"\npath = \"/api/users\"\nmethods = [\"GET\", \"POST\", \"PUT\", \"DELETE\"]\nauth_required = true\n\n[[endpoints]]\nname = \"health\"\npath = \"/health\"\nmethods = [\"GET\"]\nauth_required = false\n\n# Datetime values\n[metadata]\ncreated = 1979-05-27T07:32:00Z\nupdated = 2024-01-15T10:30:00-05:00\n\n# Special characters in strings\n[messages]\nwelcome = \"Hello, World!\"\nmultiline = '''\nThis is a\nmultiline literal\nstring.\n'''\nwith_escapes = \"Line1\\nLine2\\tTabbed\"\n"
  },
  {
    "path": "test/resources/repos/toml/test_repo/pyproject.toml",
    "content": "[project]\nname = \"test-project\"\nversion = \"0.1.0\"\ndescription = \"A test Python project for TOML support\"\nreadme = \"README.md\"\nrequires-python = \">=3.11\"\nlicense = {text = \"MIT\"}\nauthors = [\n    {name = \"Test Author\", email = \"test@example.com\"}\n]\ndependencies = [\n    \"pydantic>=2.0\",\n    \"httpx>=0.24\",\n]\n\n[project.optional-dependencies]\ndev = [\n    \"pytest>=7.0\",\n    \"ruff>=0.1\",\n    \"mypy>=1.0\",\n]\n\n[build-system]\nrequires = [\"hatchling\"]\nbuild-backend = \"hatchling.build\"\n\n[tool.ruff]\nline-length = 88\ntarget-version = \"py311\"\n\n[tool.ruff.lint]\nselect = [\"E\", \"F\", \"I\", \"N\", \"W\", \"B\", \"S\"]\n\n[tool.ruff.lint.isort]\nknown-first-party = [\"test_project\"]\n\n[tool.mypy]\npython_version = \"3.11\"\nstrict = true\nwarn_unreachable = true\n\n[tool.pytest.ini_options]\ntestpaths = [\"tests\"]\npython_files = [\"test_*.py\"]\naddopts = \"-v --cov=src\"\n"
  },
  {
    "path": "test/resources/repos/typescript/test_repo/index.ts",
    "content": "export class DemoClass {\n    value: number;\n    constructor(value: number) {\n        this.value = value;\n    }\n    printValue() {\n        console.log(this.value);\n    }\n}\n\nexport function helperFunction() {\n    const demo = new DemoClass(42);\n    demo.printValue();\n}\n\nhelperFunction();\n"
  },
  {
    "path": "test/resources/repos/typescript/test_repo/tsconfig.json",
    "content": "{\n  \"compilerOptions\": {\n    \"target\": \"ES2017\",\n    \"module\": \"commonjs\",\n    \"strict\": true,\n    \"esModuleInterop\": true,\n    \"forceConsistentCasingInFileNames\": true,\n    \"skipLibCheck\": true\n  },\n  \"include\": [\"**/*.ts\"]\n}\n"
  },
  {
    "path": "test/resources/repos/typescript/test_repo/use_helper.ts",
    "content": "import {helperFunction} from \"./index\";\n\n\nexport function useHelper() {\n    helperFunction();\n}\n\nuseHelper();\n"
  },
  {
    "path": "test/resources/repos/typescript/test_repo/ws_manager.js",
    "content": "/**\n * Dummy WebSocket manager class for testing ambiguous regex matching.\n */\nclass WebSocketManager {\n    constructor() {\n        console.log(\"WebSocketManager initializing\\nStatus OK\");\n        this.ws = null;\n        this.statusElement = document.getElementById(\"status\");\n    }\n\n    /**\n     * Connects to the WebSocket server.\n     */\n    connectToServer() {\n        if (this.ws?.readyState === WebSocket.OPEN) {\n            this.updateConnectionStatus(\"Already connected\", true);\n            return;\n        }\n\n        try {\n            this.ws = new WebSocket(\"ws://localhost:4402\");\n            this.updateConnectionStatus(\"Connecting...\", false);\n\n            this.ws.onopen = () => {\n                console.log(\"Connected to server\");\n                this.updateConnectionStatus(\"Connected\", true);\n            };\n\n            this.ws.onmessage = (event) => {\n                console.log(\"Received message:\", event.data);\n                try {\n                    const data = JSON.parse(event.data);\n                    this.handleMessage(data);\n                } catch (error) {\n                    console.error(\"Failed to parse message:\", error);\n                    this.updateConnectionStatus(\"Parse error\", false);\n                }\n            };\n\n            this.ws.onclose = (event) => {\n                console.log(\"Connection closed\");\n                const message = event.reason || undefined;\n                this.updateConnectionStatus(\"Disconnected\", false, message);\n                this.ws = null;\n            };\n\n            this.ws.onerror = (error) => {\n                console.error(\"WebSocket error:\", error);\n                this.updateConnectionStatus(\"Connection error\", false);\n            };\n        } catch (error) {\n            console.error(\"Failed to connect to server:\", error);\n            this.updateConnectionStatus(\"Connection failed\", false);\n        }\n    }\n\n    /**\n     * Updates the connection status display.\n     */\n    updateConnectionStatus(status, isConnected, message) {\n        if (this.statusElement) {\n            const text = message ? `${status}: ${message}` : status;\n            this.statusElement.textContent = text;\n            this.statusElement.style.color = isConnected ? \"green\" : \"red\";\n        }\n    }\n\n    /**\n     * Handles incoming messages.\n     */\n    handleMessage(data) {\n        console.log(\"Handling:\", data);\n    }\n}"
  },
  {
    "path": "test/resources/repos/vue/test_repo/.gitignore",
    "content": "# Logs\nlogs\n*.log\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\npnpm-debug.log*\nlerna-debug.log*\n\nnode_modules\ndist\ndist-ssr\n*.local\n\n# Editor directories and files\n.vscode/*\n!.vscode/extensions.json\n.idea\n.DS_Store\n*.suo\n*.ntvs*\n*.njsproj\n*.sln\n*.sw?\n"
  },
  {
    "path": "test/resources/repos/vue/test_repo/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"UTF-8\">\n    <link rel=\"icon\" type=\"image/svg+xml\" href=\"/vite.svg\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Vue Calculator</title>\n  </head>\n  <body>\n    <div id=\"app\"></div>\n    <script type=\"module\" src=\"/src/main.ts\"></script>\n  </body>\n</html>\n"
  },
  {
    "path": "test/resources/repos/vue/test_repo/package.json",
    "content": "{\n  \"name\": \"vue-calculator-test-fixture\",\n  \"version\": \"1.0.0\",\n  \"type\": \"module\",\n  \"description\": \"Vue 3 + Pinia + TypeScript test fixtures for Serena LSP testing\",\n  \"dependencies\": {\n    \"vue\": \"^3.4.0\",\n    \"pinia\": \"^2.1.0\"\n  },\n  \"devDependencies\": {\n    \"@vue/language-server\": \"^2.0.0\",\n    \"typescript\": \"~5.5.4\"\n  }\n}\n"
  },
  {
    "path": "test/resources/repos/vue/test_repo/src/App.vue",
    "content": "<script setup lang=\"ts\">\nimport { ref, computed, watch, watchEffect, onMounted } from 'vue'\nimport { useCalculatorStore } from '@/stores/calculator'\nimport { useThemeProvider } from '@/composables/useTheme'\nimport { useTimeFormatter } from '@/composables/useFormatter'\nimport CalculatorInput from '@/components/CalculatorInput.vue'\nimport CalculatorDisplay from '@/components/CalculatorDisplay.vue'\n\n// Get the calculator store\nconst store = useCalculatorStore()\n\n// Use theme composable with provide/inject - provides theme to all child components\nconst themeManager = useThemeProvider()\n\n// Use time formatter composable\nconst timeFormatter = useTimeFormatter()\n\n// Local ref for app title\nconst appTitle = ref('Vue Calculator')\n\n// Computed property for app version\nconst appVersion = computed((): string => {\n  return '1.0.0'\n})\n\n// Computed property for greeting message\nconst greetingMessage = computed((): string => {\n  const hour = new Date().getHours()\n  if (hour < 12) return 'Good morning'\n  if (hour < 18) return 'Good afternoon'\n  return 'Good evening'\n})\n\n// Get statistics from store\nconst totalCalculations = computed((): number => {\n  return store.history.length\n})\n\n// Check if calculator is active\nconst isCalculatorActive = computed((): boolean => {\n  return store.currentValue !== 0 || store.previousValue !== null\n})\n\n// Get last calculation time\nconst lastCalculationTime = computed((): string => {\n  if (store.history.length === 0) return 'No calculations yet'\n  const lastEntry = store.history[store.history.length - 1]\n  return timeFormatter.getRelativeTime(lastEntry.timestamp)\n})\n\n// Watch for calculation count changes - demonstrates watchEffect\nwatchEffect(() => {\n  document.title = `Calculator (${totalCalculations.value} calculations)`\n})\n\n// Watch for theme changes - demonstrates watch\nwatch(\n  () => themeManager.isDarkMode.value,\n  (isDark) => {\n    console.log(`Theme changed to ${isDark ? 'dark' : 'light'} mode`)\n  }\n)\n\n// Lifecycle hook\nonMounted(() => {\n  console.log('App component mounted')\n  console.log(`Initial calculations: ${totalCalculations.value}`)\n})\n\n// Toggle theme method\nconst toggleTheme = () => {\n  themeManager.toggleDarkMode()\n}\n\n<template>\n  <div :class=\"['app', { 'dark-mode': themeManager.isDarkMode }]\">\n    <header class=\"app-header\">\n      <h1>{{ appTitle }}</h1>\n      <div class=\"header-info\">\n        <span class=\"greeting\">{{ greetingMessage }}!</span>\n        <span class=\"version\">v{{ appVersion }}</span>\n        <button @click=\"toggleTheme\" class=\"btn-theme\">\n          {{ themeManager.isDarkMode ? '☀️' : '🌙' }}\n        </button>\n      </div>\n    </header>\n\n    <main class=\"app-main\">\n      <div class=\"calculator-container\">\n        <div class=\"stats-bar\">\n          <span>Total Calculations: {{ totalCalculations }}</span>\n          <span :class=\"{ 'active-indicator': isCalculatorActive }\">\n            {{ isCalculatorActive ? 'Active' : 'Idle' }}\n          </span>\n          <span class=\"last-calc-time\">{{ lastCalculationTime }}</span>\n        </div>\n\n        <div class=\"calculator-grid\">\n          <CalculatorInput />\n          <CalculatorDisplay />\n        </div>\n      </div>\n    </main>\n\n    <footer class=\"app-footer\">\n      <p>Built with Vue 3 + Pinia + TypeScript</p>\n    </footer>\n  </div>\n</template>\n\n<style scoped>\n.app {\n  min-height: 100vh;\n  display: flex;\n  flex-direction: column;\n  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n  transition: background 0.3s ease;\n}\n\n.app.dark-mode {\n  background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);\n}\n\n.app-header {\n  padding: 2rem;\n  color: white;\n  text-align: center;\n}\n\n.app-header h1 {\n  margin: 0 0 1rem 0;\n  font-size: 2.5rem;\n}\n\n.header-info {\n  display: flex;\n  justify-content: center;\n  align-items: center;\n  gap: 1rem;\n}\n\n.greeting {\n  font-size: 1.1rem;\n}\n\n.version {\n  font-size: 0.9rem;\n  opacity: 0.8;\n}\n\n.btn-theme {\n  background: rgba(255, 255, 255, 0.2);\n  border: none;\n  border-radius: 50%;\n  width: 40px;\n  height: 40px;\n  font-size: 1.2rem;\n  cursor: pointer;\n  transition: background 0.2s;\n}\n\n.btn-theme:hover {\n  background: rgba(255, 255, 255, 0.3);\n}\n\n.app-main {\n  flex: 1;\n  display: flex;\n  justify-content: center;\n  align-items: center;\n  padding: 2rem;\n}\n\n.calculator-container {\n  width: 100%;\n  max-width: 1200px;\n  display: flex;\n  flex-direction: column;\n  gap: 1rem;\n}\n\n.stats-bar {\n  display: flex;\n  justify-content: space-between;\n  align-items: center;\n  gap: 1rem;\n  padding: 1rem;\n  background: rgba(255, 255, 255, 0.9);\n  border-radius: 8px;\n  font-weight: 500;\n}\n\n.last-calc-time {\n  font-size: 0.9rem;\n  color: #666;\n  font-style: italic;\n}\n\n.active-indicator {\n  color: #4caf50;\n  font-weight: bold;\n}\n\n.active-indicator:not(.active-indicator) {\n  color: #999;\n}\n\n.calculator-grid {\n  display: grid;\n  grid-template-columns: 1fr 1fr;\n  gap: 2rem;\n}\n\n@media (max-width: 768px) {\n  .calculator-grid {\n    grid-template-columns: 1fr;\n  }\n}\n\n.app-footer {\n  padding: 1rem;\n  text-align: center;\n  color: white;\n  opacity: 0.8;\n}\n\n.app-footer p {\n  margin: 0;\n}\n</style>\n"
  },
  {
    "path": "test/resources/repos/vue/test_repo/src/components/CalculatorButton.vue",
    "content": "<script setup lang=\"ts\">\nimport { computed, ref } from 'vue'\n\n/**\n * Props interface for CalculatorButton.\n * Demonstrates: defineProps with TypeScript interface\n */\ninterface Props {\n  label: string | number\n  variant?: 'digit' | 'operation' | 'equals' | 'clear'\n  disabled?: boolean\n  active?: boolean\n  size?: 'small' | 'medium' | 'large'\n}\n\n/**\n * Emits interface for CalculatorButton.\n * Demonstrates: defineEmits with TypeScript\n */\ninterface Emits {\n  click: [value: string | number]\n  hover: [isHovering: boolean]\n  focus: []\n  blur: []\n}\n\n// Define props with defaults\nconst props = withDefaults(defineProps<Props>(), {\n  variant: 'digit',\n  disabled: false,\n  active: false,\n  size: 'medium'\n})\n\n// Define emits\nconst emit = defineEmits<Emits>()\n\n// Local state\nconst isHovered = ref(false)\nconst isFocused = ref(false)\nconst pressCount = ref(0)\n\n// Computed classes based on props and state\nconst buttonClass = computed(() => {\n  const classes = ['calc-button', `calc-button--${props.variant}`, `calc-button--${props.size}`]\n\n  if (props.active) classes.push('calc-button--active')\n  if (props.disabled) classes.push('calc-button--disabled')\n  if (isHovered.value) classes.push('calc-button--hovered')\n  if (isFocused.value) classes.push('calc-button--focused')\n\n  return classes.join(' ')\n})\n\n// Computed aria label for accessibility\nconst ariaLabel = computed(() => {\n  const variantText = {\n    digit: 'Number',\n    operation: 'Operation',\n    equals: 'Equals',\n    clear: 'Clear'\n  }[props.variant]\n\n  return `${variantText}: ${props.label}`\n})\n\n// Event handlers that emit events\nconst handleClick = () => {\n  if (!props.disabled) {\n    pressCount.value++\n    emit('click', props.label)\n  }\n}\n\nconst handleMouseEnter = () => {\n  isHovered.value = true\n  emit('hover', true)\n}\n\nconst handleMouseLeave = () => {\n  isHovered.value = false\n  emit('hover', false)\n}\n\nconst handleFocus = () => {\n  isFocused.value = true\n  emit('focus')\n}\n\nconst handleBlur = () => {\n  isFocused.value = false\n  emit('blur')\n}\n\n// Expose internal state for parent access via template refs\n// Demonstrates: defineExpose\ndefineExpose({\n  pressCount,\n  isHovered,\n  isFocused,\n  simulateClick: handleClick\n})\n</script>\n\n<template>\n  <button\n    :class=\"buttonClass\"\n    :disabled=\"disabled\"\n    :aria-label=\"ariaLabel\"\n    @click=\"handleClick\"\n    @mouseenter=\"handleMouseEnter\"\n    @mouseleave=\"handleMouseLeave\"\n    @focus=\"handleFocus\"\n    @blur=\"handleBlur\"\n  >\n    <span class=\"calc-button__label\">{{ label }}</span>\n    <span v-if=\"pressCount > 0\" class=\"calc-button__badge\">{{ pressCount }}</span>\n  </button>\n</template>\n\n<style scoped>\n.calc-button {\n  position: relative;\n  padding: 1rem;\n  font-size: 1.2rem;\n  border: none;\n  border-radius: 4px;\n  cursor: pointer;\n  transition: all 0.2s;\n  font-weight: 500;\n}\n\n.calc-button--small {\n  padding: 0.5rem;\n  font-size: 1rem;\n}\n\n.calc-button--medium {\n  padding: 1rem;\n  font-size: 1.2rem;\n}\n\n.calc-button--large {\n  padding: 1.5rem;\n  font-size: 1.5rem;\n}\n\n.calc-button--digit {\n  background: white;\n  color: #333;\n}\n\n.calc-button--digit:hover:not(:disabled) {\n  background: #e0e0e0;\n}\n\n.calc-button--operation {\n  background: #2196f3;\n  color: white;\n}\n\n.calc-button--operation:hover:not(:disabled) {\n  background: #1976d2;\n}\n\n.calc-button--operation.calc-button--active {\n  background: #1565c0;\n}\n\n.calc-button--equals {\n  background: #4caf50;\n  color: white;\n}\n\n.calc-button--equals:hover:not(:disabled) {\n  background: #45a049;\n}\n\n.calc-button--clear {\n  background: #f44336;\n  color: white;\n}\n\n.calc-button--clear:hover:not(:disabled) {\n  background: #da190b;\n}\n\n.calc-button--disabled {\n  opacity: 0.5;\n  cursor: not-allowed;\n}\n\n.calc-button--hovered {\n  transform: translateY(-2px);\n  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);\n}\n\n.calc-button--focused {\n  outline: 2px solid #2196f3;\n  outline-offset: 2px;\n}\n\n.calc-button__label {\n  display: block;\n}\n\n.calc-button__badge {\n  position: absolute;\n  top: -5px;\n  right: -5px;\n  background: #ff5722;\n  color: white;\n  border-radius: 50%;\n  width: 20px;\n  height: 20px;\n  font-size: 0.7rem;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n}\n</style>\n"
  },
  {
    "path": "test/resources/repos/vue/test_repo/src/components/CalculatorDisplay.vue",
    "content": "<script setup lang=\"ts\">\nimport { computed, ref } from 'vue'\nimport { storeToRefs } from 'pinia'\nimport { useCalculatorStore } from '@/stores/calculator'\nimport type { HistoryEntry } from '@/types'\n\n// Get the calculator store\nconst store = useCalculatorStore()\n\n// Use storeToRefs to get reactive references to store state\nconst { recentHistory, hasHistory, currentValue, operation } = storeToRefs(store)\n\n// Local ref for display options\nconst showFullHistory = ref(false)\nconst maxHistoryItems = ref(5)\n\n// Computed property for filtered history\nconst displayedHistory = computed((): HistoryEntry[] => {\n  if (showFullHistory.value) {\n    return recentHistory.value\n  }\n  return recentHistory.value.slice(0, maxHistoryItems.value)\n})\n\n// Format date for display\nconst formatDate = (date: Date): string => {\n  return new Date(date).toLocaleTimeString()\n}\n\n// Format the current calculation status\nconst currentCalculation = computed((): string => {\n  if (operation.value && store.previousValue !== null) {\n    const opSymbol = {\n      add: '+',\n      subtract: '-',\n      multiply: '×',\n      divide: '÷'\n    }[operation.value]\n    return `${store.previousValue} ${opSymbol} ${currentValue.value}`\n  }\n  return currentValue.value.toString()\n})\n\n// Toggle history view\nconst toggleHistoryView = () => {\n  showFullHistory.value = !showFullHistory.value\n}\n\n// Clear history handler\nconst clearHistory = () => {\n  store.clearHistory()\n}\n\n// Check if history is empty\nconst isHistoryEmpty = computed((): boolean => {\n  return !hasHistory.value\n})\n</script>\n\n<template>\n  <div class=\"calculator-display\">\n    <div class=\"current-calculation\">\n      <h3>Current Calculation</h3>\n      <div class=\"calculation-value\">\n        {{ currentCalculation }}\n      </div>\n    </div>\n\n    <div class=\"history-section\">\n      <div class=\"history-header\">\n        <h3>History</h3>\n        <button\n          v-if=\"hasHistory\"\n          @click=\"toggleHistoryView\"\n          class=\"btn-toggle\"\n        >\n          {{ showFullHistory ? 'Show Less' : 'Show All' }}\n        </button>\n        <button\n          v-if=\"hasHistory\"\n          @click=\"clearHistory\"\n          class=\"btn-clear-history\"\n        >\n          Clear History\n        </button>\n      </div>\n\n      <div v-if=\"isHistoryEmpty\" class=\"empty-history\">\n        No calculations yet\n      </div>\n\n      <div v-else class=\"history-list\">\n        <div\n          v-for=\"(entry, index) in displayedHistory\"\n          :key=\"`${entry.timestamp}-${index}`\"\n          class=\"history-item\"\n        >\n          <span class=\"expression\">{{ entry.expression }}</span>\n          <span class=\"result\">= {{ entry.result }}</span>\n          <span class=\"timestamp\">{{ formatDate(entry.timestamp) }}</span>\n        </div>\n      </div>\n\n      <div v-if=\"!showFullHistory && recentHistory.length > maxHistoryItems\" class=\"history-count\">\n        Showing {{ maxHistoryItems }} of {{ recentHistory.length }} entries\n      </div>\n    </div>\n  </div>\n</template>\n\n<style scoped>\n.calculator-display {\n  display: flex;\n  flex-direction: column;\n  gap: 1.5rem;\n  padding: 1rem;\n  background: white;\n  border-radius: 8px;\n  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);\n}\n\n.current-calculation {\n  padding: 1rem;\n  background: #e3f2fd;\n  border-radius: 4px;\n}\n\n.current-calculation h3 {\n  margin: 0 0 0.5rem 0;\n  font-size: 1rem;\n  color: #1976d2;\n}\n\n.calculation-value {\n  font-size: 1.5rem;\n  font-weight: bold;\n  color: #333;\n}\n\n.history-section {\n  display: flex;\n  flex-direction: column;\n  gap: 1rem;\n}\n\n.history-header {\n  display: flex;\n  align-items: center;\n  gap: 1rem;\n}\n\n.history-header h3 {\n  margin: 0;\n  flex: 1;\n}\n\n.btn-toggle,\n.btn-clear-history {\n  padding: 0.5rem 1rem;\n  border: none;\n  border-radius: 4px;\n  cursor: pointer;\n  font-size: 0.9rem;\n}\n\n.btn-toggle {\n  background: #2196f3;\n  color: white;\n}\n\n.btn-toggle:hover {\n  background: #1976d2;\n}\n\n.btn-clear-history {\n  background: #f44336;\n  color: white;\n}\n\n.btn-clear-history:hover {\n  background: #da190b;\n}\n\n.empty-history {\n  padding: 2rem;\n  text-align: center;\n  color: #999;\n  font-style: italic;\n}\n\n.history-list {\n  display: flex;\n  flex-direction: column;\n  gap: 0.5rem;\n}\n\n.history-item {\n  display: grid;\n  grid-template-columns: 2fr 1fr 1fr;\n  gap: 1rem;\n  padding: 0.75rem;\n  background: #f5f5f5;\n  border-radius: 4px;\n  align-items: center;\n}\n\n.expression {\n  font-weight: 500;\n}\n\n.result {\n  font-weight: bold;\n  color: #4caf50;\n}\n\n.timestamp {\n  font-size: 0.8rem;\n  color: #666;\n  text-align: right;\n}\n\n.history-count {\n  text-align: center;\n  font-size: 0.9rem;\n  color: #666;\n  padding: 0.5rem;\n}\n</style>\n"
  },
  {
    "path": "test/resources/repos/vue/test_repo/src/components/CalculatorInput.vue",
    "content": "<script setup lang=\"ts\">\nimport { ref, computed, watch, onMounted, onBeforeUnmount } from 'vue'\nimport { useCalculatorStore } from '@/stores/calculator'\nimport { useFormatter } from '@/composables/useFormatter'\nimport CalculatorButton from './CalculatorButton.vue'\nimport type { Operation } from '@/types'\n\n// Get the calculator store\nconst store = useCalculatorStore()\n\n// Use composable for formatting\nconst formatter = useFormatter(2)\n\n// Local refs for component state\nconst isOperationPending = ref(false)\nconst lastOperation = ref<Operation>(null)\nconst keyboardEnabled = ref(true)\nconst operationHistory = ref<string[]>([])\n\n// Template refs - demonstrates template ref pattern\nconst displayRef = ref<HTMLDivElement | null>(null)\nconst equalsButtonRef = ref<InstanceType<typeof CalculatorButton> | null>(null)\n\n// Computed property for button styling\nconst getOperationClass = computed(() => (op: Operation) => {\n  return lastOperation.value === op ? 'active' : ''\n})\n\n// Computed formatted display value using composable\nconst formattedDisplay = computed(() => {\n  const value = parseFloat(store.display)\n  return isNaN(value) ? store.display : formatter.formatNumber(value)\n})\n\n// Watch for operation changes - demonstrates watch\nwatch(lastOperation, (newOp, oldOp) => {\n  if (newOp !== oldOp && newOp) {\n    operationHistory.value.push(newOp)\n    // Keep only last 10 operations\n    if (operationHistory.value.length > 10) {\n      operationHistory.value.shift()\n    }\n  }\n})\n\n// Watch store display changes - demonstrates watch with callback\nwatch(\n  () => store.display,\n  (newDisplay) => {\n    if (displayRef.value) {\n      // Trigger animation on display change\n      displayRef.value.classList.add('display-updated')\n      setTimeout(() => {\n        displayRef.value?.classList.remove('display-updated')\n      }, 300)\n    }\n  }\n)\n\n// Lifecycle hook - demonstrates onMounted\nonMounted(() => {\n  console.log('CalculatorInput mounted')\n  // Add keyboard event listener\n  window.addEventListener('keydown', handleKeyboard)\n\n  // Focus on the display element\n  if (displayRef.value) {\n    displayRef.value.focus()\n  }\n})\n\n// Lifecycle hook - demonstrates onBeforeUnmount\nonBeforeUnmount(() => {\n  console.log('CalculatorInput unmounting')\n  // Clean up keyboard event listener\n  window.removeEventListener('keydown', handleKeyboard)\n})\n\n// Handle number button clicks\nconst handleDigit = (digit: number) => {\n  store.appendDigit(digit)\n  isOperationPending.value = false\n}\n\n// Handle operation button clicks\nconst handleOperation = (operation: Operation) => {\n  isOperationPending.value = true\n  lastOperation.value = operation\n\n  switch (operation) {\n    case 'add':\n      store.add()\n      break\n    case 'subtract':\n      store.subtract()\n      break\n    case 'multiply':\n      store.multiply()\n      break\n    case 'divide':\n      store.divide()\n      break\n  }\n}\n\n// Handle equals button\nconst handleEquals = () => {\n  store.equals()\n  isOperationPending.value = false\n  lastOperation.value = null\n\n  // Access exposed method from child component\n  if (equalsButtonRef.value) {\n    console.log('Equals button press count:', equalsButtonRef.value.pressCount)\n  }\n}\n\n// Handle clear button\nconst handleClear = () => {\n  store.clear()\n  isOperationPending.value = false\n  lastOperation.value = null\n  operationHistory.value = []\n}\n\n// Keyboard handler - demonstrates event handling\nconst handleKeyboard = (event: KeyboardEvent) => {\n  if (!keyboardEnabled.value) return\n\n  const key = event.key\n\n  if (key >= '0' && key <= '9') {\n    handleDigit(parseInt(key))\n  } else if (key === '+') {\n    handleOperation('add')\n  } else if (key === '-') {\n    handleOperation('subtract')\n  } else if (key === '*') {\n    handleOperation('multiply')\n  } else if (key === '/') {\n    event.preventDefault()\n    handleOperation('divide')\n  } else if (key === 'Enter' || key === '=') {\n    handleEquals()\n  } else if (key === 'Escape' || key === 'c' || key === 'C') {\n    handleClear()\n  }\n}\n\n// Toggle keyboard input\nconst toggleKeyboard = () => {\n  keyboardEnabled.value = !keyboardEnabled.value\n}\n\n// Array of digits for rendering\nconst digits = [7, 8, 9, 4, 5, 6, 1, 2, 3, 0]\n</script>\n\n<template>\n  <div class=\"calculator-input\">\n    <div ref=\"displayRef\" class=\"display\" tabindex=\"0\">\n      {{ formattedDisplay }}\n    </div>\n\n    <div class=\"keyboard-toggle\">\n      <label>\n        <input type=\"checkbox\" v-model=\"keyboardEnabled\" @change=\"toggleKeyboard\" />\n        Enable Keyboard Input\n      </label>\n    </div>\n\n    <div class=\"buttons\">\n      <CalculatorButton\n        v-for=\"digit in digits\"\n        :key=\"digit\"\n        :label=\"digit\"\n        variant=\"digit\"\n        @click=\"handleDigit\"\n      />\n\n      <CalculatorButton\n        label=\"+\"\n        variant=\"operation\"\n        :active=\"lastOperation === 'add'\"\n        @click=\"() => handleOperation('add')\"\n      />\n\n      <CalculatorButton\n        label=\"-\"\n        variant=\"operation\"\n        :active=\"lastOperation === 'subtract'\"\n        @click=\"() => handleOperation('subtract')\"\n      />\n\n      <CalculatorButton\n        label=\"×\"\n        variant=\"operation\"\n        :active=\"lastOperation === 'multiply'\"\n        @click=\"() => handleOperation('multiply')\"\n      />\n\n      <CalculatorButton\n        label=\"÷\"\n        variant=\"operation\"\n        :active=\"lastOperation === 'divide'\"\n        @click=\"() => handleOperation('divide')\"\n      />\n\n      <CalculatorButton\n        ref=\"equalsButtonRef\"\n        label=\"=\"\n        variant=\"equals\"\n        size=\"large\"\n        @click=\"handleEquals\"\n      />\n\n      <CalculatorButton\n        label=\"C\"\n        variant=\"clear\"\n        @click=\"handleClear\"\n      />\n    </div>\n\n    <div v-if=\"isOperationPending\" class=\"pending-indicator\">\n      Operation pending: {{ lastOperation }}\n    </div>\n\n    <div v-if=\"operationHistory.length > 0\" class=\"operation-history\">\n      Recent operations: {{ operationHistory.join(', ') }}\n    </div>\n  </div>\n</template>\n\n<style scoped>\n.calculator-input {\n  display: flex;\n  flex-direction: column;\n  gap: 1rem;\n  padding: 1rem;\n  background: #f5f5f5;\n  border-radius: 8px;\n}\n\n.display {\n  font-size: 2rem;\n  text-align: right;\n  padding: 1rem;\n  background: white;\n  border-radius: 4px;\n  min-height: 3rem;\n  transition: background-color 0.3s;\n  outline: none;\n}\n\n.display:focus {\n  box-shadow: 0 0 0 2px #2196f3;\n}\n\n.display.display-updated {\n  background-color: #e3f2fd;\n}\n\n.keyboard-toggle {\n  display: flex;\n  justify-content: center;\n  padding: 0.5rem;\n}\n\n.keyboard-toggle label {\n  display: flex;\n  align-items: center;\n  gap: 0.5rem;\n  cursor: pointer;\n  font-size: 0.9rem;\n}\n\n.buttons {\n  display: grid;\n  grid-template-columns: repeat(4, 1fr);\n  gap: 0.5rem;\n}\n\n.pending-indicator {\n  font-size: 0.9rem;\n  color: #666;\n  text-align: center;\n  font-style: italic;\n}\n\n.operation-history {\n  font-size: 0.8rem;\n  color: #999;\n  text-align: center;\n  padding: 0.5rem;\n  background: white;\n  border-radius: 4px;\n  max-height: 3rem;\n  overflow: auto;\n}\n</style>\n"
  },
  {
    "path": "test/resources/repos/vue/test_repo/src/composables/useFormatter.ts",
    "content": "import { ref, computed } from 'vue'\nimport type { Ref, ComputedRef } from 'vue'\nimport type { FormatOptions } from '@/types'\n\n/**\n * Composable for formatting numbers with various options.\n * Demonstrates: composable pattern, refs, computed, type imports\n */\nexport function useFormatter(initialPrecision: number = 2) {\n  // State\n  const precision = ref<number>(initialPrecision)\n  const useGrouping = ref<boolean>(true)\n  const locale = ref<string>('en-US')\n\n  // Computed properties\n  const formatOptions = computed((): FormatOptions => ({\n    maxDecimals: precision.value,\n    useGrouping: useGrouping.value\n  }))\n\n  // Methods\n  const formatNumber = (value: number): string => {\n    return value.toLocaleString(locale.value, {\n      minimumFractionDigits: precision.value,\n      maximumFractionDigits: precision.value,\n      useGrouping: useGrouping.value\n    })\n  }\n\n  const formatCurrency = (value: number, currency: string = 'USD'): string => {\n    return value.toLocaleString(locale.value, {\n      style: 'currency',\n      currency,\n      minimumFractionDigits: precision.value,\n      maximumFractionDigits: precision.value\n    })\n  }\n\n  const formatPercentage = (value: number): string => {\n    return `${(value * 100).toFixed(precision.value)}%`\n  }\n\n  const setPrecision = (newPrecision: number): void => {\n    if (newPrecision >= 0 && newPrecision <= 10) {\n      precision.value = newPrecision\n    }\n  }\n\n  const toggleGrouping = (): void => {\n    useGrouping.value = !useGrouping.value\n  }\n\n  const setLocale = (newLocale: string): void => {\n    locale.value = newLocale\n  }\n\n  // Return composable API\n  return {\n    // State (readonly)\n    precision: computed(() => precision.value),\n    useGrouping: computed(() => useGrouping.value),\n    locale: computed(() => locale.value),\n    formatOptions,\n\n    // Methods\n    formatNumber,\n    formatCurrency,\n    formatPercentage,\n    setPrecision,\n    toggleGrouping,\n    setLocale\n  }\n}\n\n/**\n * Composable for time formatting.\n * Demonstrates: simpler composable, pure functions\n */\nexport function useTimeFormatter() {\n  const formatTime = (date: Date): string => {\n    return date.toLocaleTimeString('en-US', {\n      hour: '2-digit',\n      minute: '2-digit',\n      second: '2-digit'\n    })\n  }\n\n  const formatDate = (date: Date): string => {\n    return date.toLocaleDateString('en-US', {\n      year: 'numeric',\n      month: 'long',\n      day: 'numeric'\n    })\n  }\n\n  const formatDateTime = (date: Date): string => {\n    return `${formatDate(date)} ${formatTime(date)}`\n  }\n\n  const getRelativeTime = (date: Date): string => {\n    const now = new Date()\n    const diffMs = now.getTime() - date.getTime()\n    const diffSecs = Math.floor(diffMs / 1000)\n    const diffMins = Math.floor(diffSecs / 60)\n    const diffHours = Math.floor(diffMins / 60)\n    const diffDays = Math.floor(diffHours / 24)\n\n    if (diffSecs < 60) return 'just now'\n    if (diffMins < 60) return `${diffMins} minute${diffMins > 1 ? 's' : ''} ago`\n    if (diffHours < 24) return `${diffHours} hour${diffHours > 1 ? 's' : ''} ago`\n    return `${diffDays} day${diffDays > 1 ? 's' : ''} ago`\n  }\n\n  return {\n    formatTime,\n    formatDate,\n    formatDateTime,\n    getRelativeTime\n  }\n}\n\n/**\n * Type definitions for return types\n */\nexport type UseFormatterReturn = ReturnType<typeof useFormatter>\nexport type UseTimeFormatterReturn = ReturnType<typeof useTimeFormatter>\n"
  },
  {
    "path": "test/resources/repos/vue/test_repo/src/composables/useTheme.ts",
    "content": "import { ref, computed, watch, inject, provide, type InjectionKey, type Ref } from 'vue'\n\n/**\n * Theme configuration type\n */\nexport interface ThemeConfig {\n  isDark: boolean\n  primaryColor: string\n  fontSize: number\n}\n\n/**\n * Injection key for theme - demonstrates provide/inject pattern\n */\nexport const ThemeKey: InjectionKey<Ref<ThemeConfig>> = Symbol('theme')\n\n/**\n * Composable for theme management with watchers.\n * Demonstrates: watch, provide/inject, localStorage interaction\n */\nexport function useThemeProvider() {\n  // Initialize theme from localStorage or defaults\n  const loadThemeFromStorage = (): ThemeConfig => {\n    const stored = localStorage.getItem('app-theme')\n    if (stored) {\n      try {\n        return JSON.parse(stored)\n      } catch {\n        // Fall through to defaults\n      }\n    }\n    return {\n      isDark: false,\n      primaryColor: '#667eea',\n      fontSize: 16\n    }\n  }\n\n  const theme = ref<ThemeConfig>(loadThemeFromStorage())\n\n  // Computed properties\n  const isDarkMode = computed(() => theme.value.isDark)\n  const themeClass = computed(() => theme.value.isDark ? 'dark-theme' : 'light-theme')\n\n  // Watch for theme changes and persist to localStorage\n  watch(\n    theme,\n    (newTheme) => {\n      localStorage.setItem('app-theme', JSON.stringify(newTheme))\n      document.documentElement.className = newTheme.isDark ? 'dark' : 'light'\n    },\n    { deep: true }\n  )\n\n  // Methods\n  const toggleDarkMode = (): void => {\n    theme.value.isDark = !theme.value.isDark\n  }\n\n  const setPrimaryColor = (color: string): void => {\n    theme.value.primaryColor = color\n  }\n\n  const setFontSize = (size: number): void => {\n    if (size >= 12 && size <= 24) {\n      theme.value.fontSize = size\n    }\n  }\n\n  const resetTheme = (): void => {\n    theme.value = {\n      isDark: false,\n      primaryColor: '#667eea',\n      fontSize: 16\n    }\n  }\n\n  // Provide theme to child components\n  provide(ThemeKey, theme)\n\n  return {\n    theme,\n    isDarkMode,\n    themeClass,\n    toggleDarkMode,\n    setPrimaryColor,\n    setFontSize,\n    resetTheme\n  }\n}\n\n/**\n * Composable for consuming theme in child components.\n * Demonstrates: inject pattern\n */\nexport function useTheme() {\n  const theme = inject(ThemeKey)\n\n  if (!theme) {\n    throw new Error('useTheme must be used within a component that provides ThemeKey')\n  }\n\n  const isDark = computed(() => theme.value.isDark)\n  const primaryColor = computed(() => theme.value.primaryColor)\n  const fontSize = computed(() => theme.value.fontSize)\n\n  return {\n    theme,\n    isDark,\n    primaryColor,\n    fontSize\n  }\n}\n"
  },
  {
    "path": "test/resources/repos/vue/test_repo/src/main.ts",
    "content": "import { createApp } from 'vue'\nimport { createPinia } from 'pinia'\nimport App from './App.vue'\n\nconst app = createApp(App)\nconst pinia = createPinia()\n\napp.use(pinia)\napp.mount('#app')\n"
  },
  {
    "path": "test/resources/repos/vue/test_repo/src/stores/calculator.ts",
    "content": "import { defineStore } from 'pinia'\nimport type { HistoryEntry, Operation, CalculatorState } from '@/types'\n\nexport const useCalculatorStore = defineStore('calculator', {\n  state: (): CalculatorState => ({\n    currentValue: 0,\n    previousValue: null,\n    operation: null,\n    history: [],\n    displayValue: '0'\n  }),\n\n  getters: {\n    /**\n     * Get the most recent history entries (last 10)\n     */\n    recentHistory: (state): HistoryEntry[] => {\n      return state.history.slice(-10).reverse()\n    },\n\n    /**\n     * Check if calculator has any history\n     */\n    hasHistory: (state): boolean => {\n      return state.history.length > 0\n    },\n\n    /**\n     * Get the current display text\n     */\n    display: (state): string => {\n      return state.displayValue\n    }\n  },\n\n  actions: {\n    /**\n     * Set a number value\n     */\n    setNumber(value: number) {\n      this.currentValue = value\n      this.displayValue = value.toString()\n    },\n\n    /**\n     * Append a digit to the current value\n     */\n    appendDigit(digit: number) {\n      if (this.displayValue === '0') {\n        this.displayValue = digit.toString()\n      } else {\n        this.displayValue += digit.toString()\n      }\n      this.currentValue = parseFloat(this.displayValue)\n    },\n\n    /**\n     * Add two numbers\n     */\n    add() {\n      if (this.previousValue !== null && this.operation) {\n        this.executeOperation()\n      }\n      this.previousValue = this.currentValue\n      this.operation = 'add'\n      this.displayValue = '0'\n    },\n\n    /**\n     * Subtract two numbers\n     */\n    subtract() {\n      if (this.previousValue !== null && this.operation) {\n        this.executeOperation()\n      }\n      this.previousValue = this.currentValue\n      this.operation = 'subtract'\n      this.displayValue = '0'\n    },\n\n    /**\n     * Multiply two numbers\n     */\n    multiply() {\n      if (this.previousValue !== null && this.operation) {\n        this.executeOperation()\n      }\n      this.previousValue = this.currentValue\n      this.operation = 'multiply'\n      this.displayValue = '0'\n    },\n\n    /**\n     * Divide two numbers\n     */\n    divide() {\n      if (this.previousValue !== null && this.operation) {\n        this.executeOperation()\n      }\n      this.previousValue = this.currentValue\n      this.operation = 'divide'\n      this.displayValue = '0'\n    },\n\n    /**\n     * Execute the pending operation\n     */\n    executeOperation() {\n      if (this.previousValue === null || this.operation === null) {\n        return\n      }\n\n      let result = 0\n      const prev = this.previousValue\n      const current = this.currentValue\n      let expression = ''\n\n      switch (this.operation) {\n        case 'add':\n          result = prev + current\n          expression = `${prev} + ${current}`\n          break\n        case 'subtract':\n          result = prev - current\n          expression = `${prev} - ${current}`\n          break\n        case 'multiply':\n          result = prev * current\n          expression = `${prev} × ${current}`\n          break\n        case 'divide':\n          if (current === 0) {\n            this.displayValue = 'Error'\n            this.clear()\n            return\n          }\n          result = prev / current\n          expression = `${prev} ÷ ${current}`\n          break\n      }\n\n      // Add to history\n      this.history.push({\n        expression,\n        result,\n        timestamp: new Date()\n      })\n\n      this.currentValue = result\n      this.displayValue = result.toString()\n      this.previousValue = null\n      this.operation = null\n    },\n\n    /**\n     * Calculate the equals operation\n     */\n    equals() {\n      this.executeOperation()\n    },\n\n    /**\n     * Clear the calculator state\n     */\n    clear() {\n      this.currentValue = 0\n      this.previousValue = null\n      this.operation = null\n      this.displayValue = '0'\n    },\n\n    /**\n     * Clear all history\n     */\n    clearHistory() {\n      this.history = []\n    }\n  }\n})\n"
  },
  {
    "path": "test/resources/repos/vue/test_repo/src/types/index.ts",
    "content": "/**\n * Represents a single calculation in the history\n */\nexport interface HistoryEntry {\n  expression: string\n  result: number\n  timestamp: Date\n}\n\n/**\n * Valid calculator operations\n */\nexport type Operation = 'add' | 'subtract' | 'multiply' | 'divide' | null\n\n/**\n * The complete state of the calculator\n */\nexport interface CalculatorState {\n  currentValue: number\n  previousValue: number | null\n  operation: Operation\n  history: HistoryEntry[]\n  displayValue: string\n}\n\n/**\n * Format options for displaying numbers\n */\nexport interface FormatOptions {\n  maxDecimals?: number\n  useGrouping?: boolean\n}\n"
  },
  {
    "path": "test/resources/repos/vue/test_repo/tsconfig.json",
    "content": "{\n  \"compilerOptions\": {\n    \"target\": \"ES2020\",\n    \"useDefineForClassFields\": true,\n    \"module\": \"ESNext\",\n    \"lib\": [\"ES2020\", \"DOM\", \"DOM.Iterable\"],\n    \"skipLibCheck\": true,\n    \"moduleResolution\": \"bundler\",\n    \"allowImportingTsExtensions\": true,\n    \"resolveJsonModule\": true,\n    \"isolatedModules\": true,\n    \"noEmit\": true,\n    \"jsx\": \"preserve\",\n    \"strict\": true,\n    \"noUnusedLocals\": true,\n    \"noUnusedParameters\": true,\n    \"noFallthroughCasesInSwitch\": true,\n    \"baseUrl\": \".\",\n    \"paths\": {\n      \"@/*\": [\"./src/*\"]\n    }\n  },\n  \"plugins\": [\n    {\n      \"name\": \"@vue/typescript-plugin\"\n    }\n  ],\n  \"include\": [\"src/**/*.ts\", \"src/**/*.vue\"],\n  \"references\": [{ \"path\": \"./tsconfig.node.json\" }]\n}\n"
  },
  {
    "path": "test/resources/repos/vue/test_repo/tsconfig.node.json",
    "content": "{\n  \"compilerOptions\": {\n    \"composite\": true,\n    \"skipLibCheck\": true,\n    \"module\": \"ESNext\",\n    \"moduleResolution\": \"bundler\",\n    \"allowSyntheticDefaultImports\": true,\n    \"strict\": true\n  },\n  \"include\": [\"vite.config.ts\"]\n}\n"
  },
  {
    "path": "test/resources/repos/vue/test_repo/vite.config.ts",
    "content": "import { defineConfig } from 'vite'\nimport vue from '@vitejs/plugin-vue'\nimport { fileURLToPath, URL } from 'node:url'\n\nexport default defineConfig({\n  plugins: [vue()],\n  resolve: {\n    alias: {\n      '@': fileURLToPath(new URL('./src', import.meta.url))\n    }\n  }\n})\n"
  },
  {
    "path": "test/resources/repos/yaml/test_repo/config.yaml",
    "content": "# Application configuration\napp:\n  name: test-application\n  version: 1.0.0\n  port: 8080\n  debug: true\n\ndatabase:\n  host: localhost\n  port: 5432\n  name: testdb\n  username: admin\n  password: secret123\n\nlogging:\n  level: info\n  format: json\n  outputs:\n    - console\n    - file\n\nfeatures:\n  authentication: true\n  caching: false\n  monitoring: true\n"
  },
  {
    "path": "test/resources/repos/yaml/test_repo/data.yaml",
    "content": "# Sample data structure\nusers:\n  - id: 1\n    name: John Doe\n    email: john@example.com\n    roles:\n      - admin\n      - developer\n    active: true\n\n  - id: 2\n    name: Jane Smith\n    email: jane@example.com\n    roles:\n      - developer\n    active: true\n\n  - id: 3\n    name: Bob Johnson\n    email: bob@example.com\n    roles:\n      - viewer\n    active: false\n\nprojects:\n  - name: project-alpha\n    status: active\n    team:\n      - John Doe\n      - Jane Smith\n    tags:\n      - backend\n      - api\n\n  - name: project-beta\n    status: planning\n    team:\n      - Jane Smith\n    tags:\n      - frontend\n      - ui\n"
  },
  {
    "path": "test/resources/repos/yaml/test_repo/services.yml",
    "content": "# Docker compose services definition\nversion: '3.8'\n\nservices:\n  web:\n    image: nginx:latest\n    ports:\n      - \"80:80\"\n      - \"443:443\"\n    volumes:\n      - ./html:/usr/share/nginx/html\n    environment:\n      - NGINX_HOST=localhost\n      - NGINX_PORT=80\n    networks:\n      - frontend\n\n  api:\n    image: node:18\n    ports:\n      - \"3000:3000\"\n    depends_on:\n      - database\n    environment:\n      - NODE_ENV=production\n      - DB_HOST=database\n    networks:\n      - frontend\n      - backend\n\n  database:\n    image: postgres:15\n    ports:\n      - \"5432:5432\"\n    environment:\n      - POSTGRES_DB=mydb\n      - POSTGRES_USER=admin\n      - POSTGRES_PASSWORD=password\n    volumes:\n      - db-data:/var/lib/postgresql/data\n    networks:\n      - backend\n\nnetworks:\n  frontend:\n    driver: bridge\n  backend:\n    driver: bridge\n\nvolumes:\n  db-data:\n"
  },
  {
    "path": "test/resources/repos/zig/test_repo/.gitignore",
    "content": "zig-cache/\nzig-out/\n.zig-cache/\nbuild/\ndist/"
  },
  {
    "path": "test/resources/repos/zig/test_repo/build.zig",
    "content": "const std = @import(\"std\");\n\npub fn build(b: *std.Build) void {\n    const target = b.standardTargetOptions(.{});\n    const optimize = b.standardOptimizeOption(.{});\n\n    const exe = b.addExecutable(.{\n        .name = \"test_repo\",\n        .root_source_file = b.path(\"src/main.zig\"),\n        .target = target,\n        .optimize = optimize,\n    });\n\n    b.installArtifact(exe);\n\n    const run_cmd = b.addRunArtifact(exe);\n    run_cmd.step.dependOn(b.getInstallStep());\n\n    const run_step = b.step(\"run\", \"Run the app\");\n    run_step.dependOn(&run_cmd.step);\n\n    const lib_tests = b.addTest(.{\n        .root_source_file = b.path(\"src/calculator.zig\"),\n        .target = target,\n        .optimize = optimize,\n    });\n\n    const run_lib_tests = b.addRunArtifact(lib_tests);\n    const test_step = b.step(\"test\", \"Run unit tests\");\n    test_step.dependOn(&run_lib_tests.step);\n}"
  },
  {
    "path": "test/resources/repos/zig/test_repo/src/calculator.zig",
    "content": "const std = @import(\"std\");\n\npub const CalculatorError = error{\n    DivisionByZero,\n    Overflow,\n};\n\npub const Calculator = struct {\n    const Self = @This();\n\n    pub fn init() Self {\n        return .{};\n    }\n\n    pub fn add(self: Self, a: i32, b: i32) i32 {\n        _ = self;\n        return a + b;\n    }\n\n    pub fn subtract(self: Self, a: i32, b: i32) i32 {\n        _ = self;\n        return a - b;\n    }\n\n    pub fn multiply(self: Self, a: i32, b: i32) i32 {\n        _ = self;\n        return a * b;\n    }\n\n    pub fn divide(self: Self, a: i32, b: i32) !f64 {\n        _ = self;\n        if (b == 0) {\n            return CalculatorError.DivisionByZero;\n        }\n        return @as(f64, @floatFromInt(a)) / @as(f64, @floatFromInt(b));\n    }\n\n    pub fn power(self: Self, base: i32, exponent: u32) i64 {\n        _ = self;\n        return std.math.pow(i64, base, exponent);\n    }\n};\n\ntest \"Calculator add\" {\n    const calc = Calculator.init();\n    try std.testing.expectEqual(@as(i32, 7), calc.add(3, 4));\n    try std.testing.expectEqual(@as(i32, 0), calc.add(-5, 5));\n}\n\ntest \"Calculator subtract\" {\n    const calc = Calculator.init();\n    try std.testing.expectEqual(@as(i32, -1), calc.subtract(3, 4));\n    try std.testing.expectEqual(@as(i32, 10), calc.subtract(15, 5));\n}\n\ntest \"Calculator multiply\" {\n    const calc = Calculator.init();\n    try std.testing.expectEqual(@as(i32, 12), calc.multiply(3, 4));\n    try std.testing.expectEqual(@as(i32, -25), calc.multiply(-5, 5));\n}\n\ntest \"Calculator divide\" {\n    const calc = Calculator.init();\n    try std.testing.expectEqual(@as(f64, 2.0), try calc.divide(10, 5));\n    try std.testing.expectError(CalculatorError.DivisionByZero, calc.divide(10, 0));\n}"
  },
  {
    "path": "test/resources/repos/zig/test_repo/src/main.zig",
    "content": "const std = @import(\"std\");\nconst calculator = @import(\"calculator.zig\");\nconst math_utils = @import(\"math_utils.zig\");\n\npub fn main() !void {\n    const stdout = std.io.getStdOut().writer();\n\n    const calc = calculator.Calculator.init();\n    \n    const sum = calc.add(10, 5);\n    const diff = calc.subtract(10, 5);\n    const prod = calc.multiply(10, 5);\n    const quot = calc.divide(10, 5) catch |err| {\n        try stdout.print(\"Division error: {}\\n\", .{err});\n        return;\n    };\n\n    try stdout.print(\"10 + 5 = {}\\n\", .{sum});\n    try stdout.print(\"10 - 5 = {}\\n\", .{diff});\n    try stdout.print(\"10 * 5 = {}\\n\", .{prod});\n    try stdout.print(\"10 / 5 = {}\\n\", .{quot});\n\n    const factorial_result = math_utils.factorial(5);\n    try stdout.print(\"5! = {}\\n\", .{factorial_result});\n\n    const is_prime = math_utils.isPrime(17);\n    try stdout.print(\"Is 17 prime? {}\\n\", .{is_prime});\n}\n\npub fn greeting(name: []const u8) []const u8 {\n    return std.fmt.allocPrint(std.heap.page_allocator, \"Hello, {s}!\", .{name}) catch \"Hello!\";\n}"
  },
  {
    "path": "test/resources/repos/zig/test_repo/src/math_utils.zig",
    "content": "const std = @import(\"std\");\n\npub fn factorial(n: u32) u64 {\n    if (n == 0 or n == 1) {\n        return 1;\n    }\n    var result: u64 = 1;\n    var i: u32 = 2;\n    while (i <= n) : (i += 1) {\n        result *= i;\n    }\n    return result;\n}\n\npub fn isPrime(n: u32) bool {\n    if (n <= 1) return false;\n    if (n <= 3) return true;\n    if (n % 2 == 0 or n % 3 == 0) return false;\n    \n    var i: u32 = 5;\n    while (i * i <= n) : (i += 6) {\n        if (n % i == 0 or n % (i + 2) == 0) {\n            return false;\n        }\n    }\n    return true;\n}\n\npub fn gcd(a: u32, b: u32) u32 {\n    var x = a;\n    var y = b;\n    while (y != 0) {\n        const temp = y;\n        y = x % y;\n        x = temp;\n    }\n    return x;\n}\n\npub fn lcm(a: u32, b: u32) u32 {\n    return (a * b) / gcd(a, b);\n}\n\ntest \"factorial\" {\n    try std.testing.expectEqual(@as(u64, 1), factorial(0));\n    try std.testing.expectEqual(@as(u64, 1), factorial(1));\n    try std.testing.expectEqual(@as(u64, 120), factorial(5));\n    try std.testing.expectEqual(@as(u64, 3628800), factorial(10));\n}\n\ntest \"isPrime\" {\n    try std.testing.expect(!isPrime(0));\n    try std.testing.expect(!isPrime(1));\n    try std.testing.expect(isPrime(2));\n    try std.testing.expect(isPrime(3));\n    try std.testing.expect(!isPrime(4));\n    try std.testing.expect(isPrime(17));\n    try std.testing.expect(!isPrime(100));\n}\n\ntest \"gcd and lcm\" {\n    try std.testing.expectEqual(@as(u32, 6), gcd(12, 18));\n    try std.testing.expectEqual(@as(u32, 1), gcd(17, 19));\n    try std.testing.expectEqual(@as(u32, 36), lcm(12, 18));\n}"
  },
  {
    "path": "test/resources/repos/zig/test_repo/zls.json",
    "content": "{\n    \"enable_build_on_save\": true,\n    \"build_on_save_args\": [\"build\"],\n    \"enable_autofix\": false,\n    \"semantic_tokens\": \"full\",\n    \"enable_inlay_hints\": true,\n    \"inlay_hints_show_builtin\": true,\n    \"inlay_hints_exclude_single_argument\": true,\n    \"inlay_hints_show_parameter_name\": true,\n    \"skip_std_references\": false,\n    \"max_detail_length\": 1048576\n}\n"
  },
  {
    "path": "test/serena/__init__.py",
    "content": "\n"
  },
  {
    "path": "test/serena/__snapshots__/test_symbol_editing.ambr",
    "content": "# serializer version: 1\n# name: test_delete_symbol[test_case0]\n  '''\n  \"\"\"\n  Test module for variable declarations and usage.\n  \n  This module tests various types of variable declarations and usages including:\n  - Module-level variables\n  - Class-level variables\n  - Instance variables\n  - Variable reassignments\n  \"\"\"\n  \n  from dataclasses import dataclass, field\n  \n  # Module-level variables\n  module_var = \"Initial module value\"\n  \n  reassignable_module_var = 10\n  reassignable_module_var = 20  # Reassigned\n  \n  # Module-level variable with type annotation\n  typed_module_var: int = 42\n  \n  \n  # Regular class with class and instance variables\n  \n  \n  \n  # Dataclass with variables\n  @dataclass\n  class VariableDataclass:\n      \"\"\"Dataclass that contains various fields.\"\"\"\n  \n      # Field variables with type annotations\n      id: int\n      name: str\n      items: list[str] = field(default_factory=list)\n      metadata: dict[str, str] = field(default_factory=dict)\n      optional_value: float | None = None\n  \n      # This will be reassigned in various places\n      status: str = \"pending\"\n  \n  \n  # Function that uses the module variables\n  def use_module_variables():\n      \"\"\"Function that uses module-level variables.\"\"\"\n      result = module_var + \" used in function\"\n      other_result = reassignable_module_var * 2\n      return result, other_result\n  \n  \n  # Create instances and use variables\n  dataclass_instance = VariableDataclass(id=1, name=\"Test\")\n  dataclass_instance.status = \"active\"  # Reassign dataclass field\n  \n  # Use variables at module level\n  module_result = module_var + \" used at module level\"\n  other_module_result = reassignable_module_var + 30\n  \n  # Create a second dataclass instance with different status\n  second_dataclass = VariableDataclass(id=2, name=\"Another Test\")\n  second_dataclass.status = \"completed\"  # Another reassignment of status\n  \n  '''\n# ---\n# name: test_delete_symbol[test_case1]\n  '''\n  \n  \n  export function helperFunction() {\n      const demo = new DemoClass(42);\n      demo.printValue();\n  }\n  \n  helperFunction();\n  \n  '''\n# ---\n# name: test_delete_symbol_vue[test_case0]\n  '''\n  <script setup lang=\"ts\">\n  import { computed, ref } from 'vue'\n  \n  /**\n   * Props interface for CalculatorButton.\n   * Demonstrates: defineProps with TypeScript interface\n   */\n  interface Props {\n    label: string | number\n    variant?: 'digit' | 'operation' | 'equals' | 'clear'\n    disabled?: boolean\n    active?: boolean\n    size?: 'small' | 'medium' | 'large'\n  }\n  \n  /**\n   * Emits interface for CalculatorButton.\n   * Demonstrates: defineEmits with TypeScript\n   */\n  interface Emits {\n    click: [value: string | number]\n    hover: [isHovering: boolean]\n    focus: []\n    blur: []\n  }\n  \n  // Define props with defaults\n  const props = withDefaults(defineProps<Props>(), {\n    variant: 'digit',\n    disabled: false,\n    active: false,\n    size: 'medium'\n  })\n  \n  // Define emits\n  const emit = defineEmits<Emits>()\n  \n  // Local state\n  const isHovered = ref(false)\n  const isFocused = ref(false)\n  const pressCount = ref(0)\n  \n  // Computed classes based on props and state\n  const buttonClass = computed(() => {\n    const classes = ['calc-button', `calc-button--${props.variant}`, `calc-button--${props.size}`]\n  \n    if (props.active) classes.push('calc-button--active')\n    if (props.disabled) classes.push('calc-button--disabled')\n    if (isHovered.value) classes.push('calc-button--hovered')\n    if (isFocused.value) classes.push('calc-button--focused')\n  \n    return classes.join(' ')\n  })\n  \n  // Computed aria label for accessibility\n  const ariaLabel = computed(() => {\n    const variantText = {\n      digit: 'Number',\n      operation: 'Operation',\n      equals: 'Equals',\n      clear: 'Clear'\n    }[props.variant]\n  \n    return `${variantText}: ${props.label}`\n  })\n  \n  // Event handlers that emit events\n  const handleClick = () => {\n    if (!props.disabled) {\n      pressCount.value++\n      emit('click', props.label)\n    }\n  }\n  \n  const \n  \n  const handleMouseLeave = () => {\n    isHovered.value = false\n    emit('hover', false)\n  }\n  \n  const handleFocus = () => {\n    isFocused.value = true\n    emit('focus')\n  }\n  \n  const handleBlur = () => {\n    isFocused.value = false\n    emit('blur')\n  }\n  \n  // Expose internal state for parent access via template refs\n  // Demonstrates: defineExpose\n  defineExpose({\n    pressCount,\n    isHovered,\n    isFocused,\n    simulateClick: handleClick\n  })\n  </script>\n  \n  <template>\n    <button\n      :class=\"buttonClass\"\n      :disabled=\"disabled\"\n      :aria-label=\"ariaLabel\"\n      @click=\"handleClick\"\n      @mouseenter=\"handleMouseEnter\"\n      @mouseleave=\"handleMouseLeave\"\n      @focus=\"handleFocus\"\n      @blur=\"handleBlur\"\n    >\n      <span class=\"calc-button__label\">{{ label }}</span>\n      <span v-if=\"pressCount > 0\" class=\"calc-button__badge\">{{ pressCount }}</span>\n    </button>\n  </template>\n  \n  <style scoped>\n  .calc-button {\n    position: relative;\n    padding: 1rem;\n    font-size: 1.2rem;\n    border: none;\n    border-radius: 4px;\n    cursor: pointer;\n    transition: all 0.2s;\n    font-weight: 500;\n  }\n  \n  .calc-button--small {\n    padding: 0.5rem;\n    font-size: 1rem;\n  }\n  \n  .calc-button--medium {\n    padding: 1rem;\n    font-size: 1.2rem;\n  }\n  \n  .calc-button--large {\n    padding: 1.5rem;\n    font-size: 1.5rem;\n  }\n  \n  .calc-button--digit {\n    background: white;\n    color: #333;\n  }\n  \n  .calc-button--digit:hover:not(:disabled) {\n    background: #e0e0e0;\n  }\n  \n  .calc-button--operation {\n    background: #2196f3;\n    color: white;\n  }\n  \n  .calc-button--operation:hover:not(:disabled) {\n    background: #1976d2;\n  }\n  \n  .calc-button--operation.calc-button--active {\n    background: #1565c0;\n  }\n  \n  .calc-button--equals {\n    background: #4caf50;\n    color: white;\n  }\n  \n  .calc-button--equals:hover:not(:disabled) {\n    background: #45a049;\n  }\n  \n  .calc-button--clear {\n    background: #f44336;\n    color: white;\n  }\n  \n  .calc-button--clear:hover:not(:disabled) {\n    background: #da190b;\n  }\n  \n  .calc-button--disabled {\n    opacity: 0.5;\n    cursor: not-allowed;\n  }\n  \n  .calc-button--hovered {\n    transform: translateY(-2px);\n    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);\n  }\n  \n  .calc-button--focused {\n    outline: 2px solid #2196f3;\n    outline-offset: 2px;\n  }\n  \n  .calc-button__label {\n    display: block;\n  }\n  \n  .calc-button__badge {\n    position: absolute;\n    top: -5px;\n    right: -5px;\n    background: #ff5722;\n    color: white;\n    border-radius: 50%;\n    width: 20px;\n    height: 20px;\n    font-size: 0.7rem;\n    display: flex;\n    align-items: center;\n    justify-content: center;\n  }\n  </style>\n  \n  '''\n# ---\n# name: test_insert_in_rel_to_symbol[test_case0-after]\n  '''\n  \"\"\"\n  Test module for variable declarations and usage.\n  \n  This module tests various types of variable declarations and usages including:\n  - Module-level variables\n  - Class-level variables\n  - Instance variables\n  - Variable reassignments\n  \"\"\"\n  \n  from dataclasses import dataclass, field\n  \n  # Module-level variables\n  module_var = \"Initial module value\"\n  \n  reassignable_module_var = 10\n  reassignable_module_var = 20  # Reassigned\n  \n  # Module-level variable with type annotation\n  typed_module_var: int = 42\n  new_module_var = \"Inserted after typed_module_var\"\n  \n  \n  # Regular class with class and instance variables\n  class VariableContainer:\n      \"\"\"Class that contains various variables.\"\"\"\n  \n      # Class-level variables\n      class_var = \"Initial class value\"\n  \n      reassignable_class_var = True\n      reassignable_class_var = False  # Reassigned #noqa: PIE794\n  \n      # Class-level variable with type annotation\n      typed_class_var: str = \"typed value\"\n  \n      def __init__(self):\n          # Instance variables\n          self.instance_var = \"Initial instance value\"\n          self.reassignable_instance_var = 100\n  \n          # Instance variable with type annotation\n          self.typed_instance_var: list[str] = [\"item1\", \"item2\"]\n  \n      def modify_instance_var(self):\n          # Reassign instance variable\n          self.instance_var = \"Modified instance value\"\n          self.reassignable_instance_var = 200  # Reassigned\n  \n      def use_module_var(self):\n          # Use module-level variables\n          result = module_var + \" used in method\"\n          other_result = reassignable_module_var + 5\n          return result, other_result\n  \n      def use_class_var(self):\n          # Use class-level variables\n          result = VariableContainer.class_var + \" used in method\"\n          other_result = VariableContainer.reassignable_class_var\n          return result, other_result\n  \n  \n  # Dataclass with variables\n  @dataclass\n  class VariableDataclass:\n      \"\"\"Dataclass that contains various fields.\"\"\"\n  \n      # Field variables with type annotations\n      id: int\n      name: str\n      items: list[str] = field(default_factory=list)\n      metadata: dict[str, str] = field(default_factory=dict)\n      optional_value: float | None = None\n  \n      # This will be reassigned in various places\n      status: str = \"pending\"\n  \n  \n  # Function that uses the module variables\n  def use_module_variables():\n      \"\"\"Function that uses module-level variables.\"\"\"\n      result = module_var + \" used in function\"\n      other_result = reassignable_module_var * 2\n      return result, other_result\n  \n  \n  # Create instances and use variables\n  dataclass_instance = VariableDataclass(id=1, name=\"Test\")\n  dataclass_instance.status = \"active\"  # Reassign dataclass field\n  \n  # Use variables at module level\n  module_result = module_var + \" used at module level\"\n  other_module_result = reassignable_module_var + 30\n  \n  # Create a second dataclass instance with different status\n  second_dataclass = VariableDataclass(id=2, name=\"Another Test\")\n  second_dataclass.status = \"completed\"  # Another reassignment of status\n  \n  '''\n# ---\n# name: test_insert_in_rel_to_symbol[test_case0-before]\n  '''\n  \"\"\"\n  Test module for variable declarations and usage.\n  \n  This module tests various types of variable declarations and usages including:\n  - Module-level variables\n  - Class-level variables\n  - Instance variables\n  - Variable reassignments\n  \"\"\"\n  \n  from dataclasses import dataclass, field\n  \n  # Module-level variables\n  module_var = \"Initial module value\"\n  \n  reassignable_module_var = 10\n  reassignable_module_var = 20  # Reassigned\n  \n  # Module-level variable with type annotation\n  new_module_var = \"Inserted after typed_module_var\"\n  typed_module_var: int = 42\n  \n  \n  # Regular class with class and instance variables\n  class VariableContainer:\n      \"\"\"Class that contains various variables.\"\"\"\n  \n      # Class-level variables\n      class_var = \"Initial class value\"\n  \n      reassignable_class_var = True\n      reassignable_class_var = False  # Reassigned #noqa: PIE794\n  \n      # Class-level variable with type annotation\n      typed_class_var: str = \"typed value\"\n  \n      def __init__(self):\n          # Instance variables\n          self.instance_var = \"Initial instance value\"\n          self.reassignable_instance_var = 100\n  \n          # Instance variable with type annotation\n          self.typed_instance_var: list[str] = [\"item1\", \"item2\"]\n  \n      def modify_instance_var(self):\n          # Reassign instance variable\n          self.instance_var = \"Modified instance value\"\n          self.reassignable_instance_var = 200  # Reassigned\n  \n      def use_module_var(self):\n          # Use module-level variables\n          result = module_var + \" used in method\"\n          other_result = reassignable_module_var + 5\n          return result, other_result\n  \n      def use_class_var(self):\n          # Use class-level variables\n          result = VariableContainer.class_var + \" used in method\"\n          other_result = VariableContainer.reassignable_class_var\n          return result, other_result\n  \n  \n  # Dataclass with variables\n  @dataclass\n  class VariableDataclass:\n      \"\"\"Dataclass that contains various fields.\"\"\"\n  \n      # Field variables with type annotations\n      id: int\n      name: str\n      items: list[str] = field(default_factory=list)\n      metadata: dict[str, str] = field(default_factory=dict)\n      optional_value: float | None = None\n  \n      # This will be reassigned in various places\n      status: str = \"pending\"\n  \n  \n  # Function that uses the module variables\n  def use_module_variables():\n      \"\"\"Function that uses module-level variables.\"\"\"\n      result = module_var + \" used in function\"\n      other_result = reassignable_module_var * 2\n      return result, other_result\n  \n  \n  # Create instances and use variables\n  dataclass_instance = VariableDataclass(id=1, name=\"Test\")\n  dataclass_instance.status = \"active\"  # Reassign dataclass field\n  \n  # Use variables at module level\n  module_result = module_var + \" used at module level\"\n  other_module_result = reassignable_module_var + 30\n  \n  # Create a second dataclass instance with different status\n  second_dataclass = VariableDataclass(id=2, name=\"Another Test\")\n  second_dataclass.status = \"completed\"  # Another reassignment of status\n  \n  '''\n# ---\n# name: test_insert_in_rel_to_symbol[test_case1-after]\n  '''\n  \"\"\"\n  Test module for variable declarations and usage.\n  \n  This module tests various types of variable declarations and usages including:\n  - Module-level variables\n  - Class-level variables\n  - Instance variables\n  - Variable reassignments\n  \"\"\"\n  \n  from dataclasses import dataclass, field\n  \n  # Module-level variables\n  module_var = \"Initial module value\"\n  \n  reassignable_module_var = 10\n  reassignable_module_var = 20  # Reassigned\n  \n  # Module-level variable with type annotation\n  typed_module_var: int = 42\n  \n  \n  # Regular class with class and instance variables\n  class VariableContainer:\n      \"\"\"Class that contains various variables.\"\"\"\n  \n      # Class-level variables\n      class_var = \"Initial class value\"\n  \n      reassignable_class_var = True\n      reassignable_class_var = False  # Reassigned #noqa: PIE794\n  \n      # Class-level variable with type annotation\n      typed_class_var: str = \"typed value\"\n  \n      def __init__(self):\n          # Instance variables\n          self.instance_var = \"Initial instance value\"\n          self.reassignable_instance_var = 100\n  \n          # Instance variable with type annotation\n          self.typed_instance_var: list[str] = [\"item1\", \"item2\"]\n  \n      def modify_instance_var(self):\n          # Reassign instance variable\n          self.instance_var = \"Modified instance value\"\n          self.reassignable_instance_var = 200  # Reassigned\n  \n      def use_module_var(self):\n          # Use module-level variables\n          result = module_var + \" used in method\"\n          other_result = reassignable_module_var + 5\n          return result, other_result\n  \n      def use_class_var(self):\n          # Use class-level variables\n          result = VariableContainer.class_var + \" used in method\"\n          other_result = VariableContainer.reassignable_class_var\n          return result, other_result\n  \n  \n  # Dataclass with variables\n  @dataclass\n  class VariableDataclass:\n      \"\"\"Dataclass that contains various fields.\"\"\"\n  \n      # Field variables with type annotations\n      id: int\n      name: str\n      items: list[str] = field(default_factory=list)\n      metadata: dict[str, str] = field(default_factory=dict)\n      optional_value: float | None = None\n  \n      # This will be reassigned in various places\n      status: str = \"pending\"\n  \n  \n  # Function that uses the module variables\n  def use_module_variables():\n      \"\"\"Function that uses module-level variables.\"\"\"\n      result = module_var + \" used in function\"\n      other_result = reassignable_module_var * 2\n      return result, other_result\n  \n  def new_inserted_function():\n      print(\"This is a new function inserted before another.\")\n  \n  \n  # Create instances and use variables\n  dataclass_instance = VariableDataclass(id=1, name=\"Test\")\n  dataclass_instance.status = \"active\"  # Reassign dataclass field\n  \n  # Use variables at module level\n  module_result = module_var + \" used at module level\"\n  other_module_result = reassignable_module_var + 30\n  \n  # Create a second dataclass instance with different status\n  second_dataclass = VariableDataclass(id=2, name=\"Another Test\")\n  second_dataclass.status = \"completed\"  # Another reassignment of status\n  \n  '''\n# ---\n# name: test_insert_in_rel_to_symbol[test_case1-before]\n  '''\n  \"\"\"\n  Test module for variable declarations and usage.\n  \n  This module tests various types of variable declarations and usages including:\n  - Module-level variables\n  - Class-level variables\n  - Instance variables\n  - Variable reassignments\n  \"\"\"\n  \n  from dataclasses import dataclass, field\n  \n  # Module-level variables\n  module_var = \"Initial module value\"\n  \n  reassignable_module_var = 10\n  reassignable_module_var = 20  # Reassigned\n  \n  # Module-level variable with type annotation\n  typed_module_var: int = 42\n  \n  \n  # Regular class with class and instance variables\n  class VariableContainer:\n      \"\"\"Class that contains various variables.\"\"\"\n  \n      # Class-level variables\n      class_var = \"Initial class value\"\n  \n      reassignable_class_var = True\n      reassignable_class_var = False  # Reassigned #noqa: PIE794\n  \n      # Class-level variable with type annotation\n      typed_class_var: str = \"typed value\"\n  \n      def __init__(self):\n          # Instance variables\n          self.instance_var = \"Initial instance value\"\n          self.reassignable_instance_var = 100\n  \n          # Instance variable with type annotation\n          self.typed_instance_var: list[str] = [\"item1\", \"item2\"]\n  \n      def modify_instance_var(self):\n          # Reassign instance variable\n          self.instance_var = \"Modified instance value\"\n          self.reassignable_instance_var = 200  # Reassigned\n  \n      def use_module_var(self):\n          # Use module-level variables\n          result = module_var + \" used in method\"\n          other_result = reassignable_module_var + 5\n          return result, other_result\n  \n      def use_class_var(self):\n          # Use class-level variables\n          result = VariableContainer.class_var + \" used in method\"\n          other_result = VariableContainer.reassignable_class_var\n          return result, other_result\n  \n  \n  # Dataclass with variables\n  @dataclass\n  class VariableDataclass:\n      \"\"\"Dataclass that contains various fields.\"\"\"\n  \n      # Field variables with type annotations\n      id: int\n      name: str\n      items: list[str] = field(default_factory=list)\n      metadata: dict[str, str] = field(default_factory=dict)\n      optional_value: float | None = None\n  \n      # This will be reassigned in various places\n      status: str = \"pending\"\n  \n  \n  # Function that uses the module variables\n  def new_inserted_function():\n      print(\"This is a new function inserted before another.\")\n  \n  def use_module_variables():\n      \"\"\"Function that uses module-level variables.\"\"\"\n      result = module_var + \" used in function\"\n      other_result = reassignable_module_var * 2\n      return result, other_result\n  \n  \n  # Create instances and use variables\n  dataclass_instance = VariableDataclass(id=1, name=\"Test\")\n  dataclass_instance.status = \"active\"  # Reassign dataclass field\n  \n  # Use variables at module level\n  module_result = module_var + \" used at module level\"\n  other_module_result = reassignable_module_var + 30\n  \n  # Create a second dataclass instance with different status\n  second_dataclass = VariableDataclass(id=2, name=\"Another Test\")\n  second_dataclass.status = \"completed\"  # Another reassignment of status\n  \n  '''\n# ---\n# name: test_insert_in_rel_to_symbol[test_case2-after]\n  '''\n  export class DemoClass {\n      value: number;\n      constructor(value: number) {\n          this.value = value;\n      }\n      printValue() {\n          console.log(this.value);\n      }\n  }\n  \n  function newFunctionAfterClass(): void {\n      console.log(\"This function is after DemoClass.\");\n  }\n  \n  export function helperFunction() {\n      const demo = new DemoClass(42);\n      demo.printValue();\n  }\n  \n  helperFunction();\n  \n  '''\n# ---\n# name: test_insert_in_rel_to_symbol[test_case2-before]\n  '''\n  function newFunctionAfterClass(): void {\n      console.log(\"This function is after DemoClass.\");\n  }\n  \n  export class DemoClass {\n      value: number;\n      constructor(value: number) {\n          this.value = value;\n      }\n      printValue() {\n          console.log(this.value);\n      }\n  }\n  \n  export function helperFunction() {\n      const demo = new DemoClass(42);\n      demo.printValue();\n  }\n  \n  helperFunction();\n  \n  '''\n# ---\n# name: test_insert_in_rel_to_symbol[test_case3-after]\n  '''\n  export class DemoClass {\n      value: number;\n      constructor(value: number) {\n          this.value = value;\n      }\n      printValue() {\n          console.log(this.value);\n      }\n  }\n  \n  export function helperFunction() {\n      const demo = new DemoClass(42);\n      demo.printValue();\n  }\n  \n  function newInsertedFunction(): void {\n      console.log(\"This is a new function inserted before another.\");\n  }\n  \n  helperFunction();\n  \n  '''\n# ---\n# name: test_insert_in_rel_to_symbol[test_case3-before]\n  '''\n  export class DemoClass {\n      value: number;\n      constructor(value: number) {\n          this.value = value;\n      }\n      printValue() {\n          console.log(this.value);\n      }\n  }\n  \n  function newInsertedFunction(): void {\n      console.log(\"This is a new function inserted before another.\");\n  }\n  \n  export function helperFunction() {\n      const demo = new DemoClass(42);\n      demo.printValue();\n  }\n  \n  helperFunction();\n  \n  '''\n# ---\n# name: test_insert_in_rel_to_symbol_vue[test_case0-after]\n  '''\n  <script setup lang=\"ts\">\n  import { computed, ref } from 'vue'\n  \n  /**\n   * Props interface for CalculatorButton.\n   * Demonstrates: defineProps with TypeScript interface\n   */\n  interface Props {\n    label: string | number\n    variant?: 'digit' | 'operation' | 'equals' | 'clear'\n    disabled?: boolean\n    active?: boolean\n    size?: 'small' | 'medium' | 'large'\n  }\n  \n  /**\n   * Emits interface for CalculatorButton.\n   * Demonstrates: defineEmits with TypeScript\n   */\n  interface Emits {\n    click: [value: string | number]\n    hover: [isHovering: boolean]\n    focus: []\n    blur: []\n  }\n  \n  // Define props with defaults\n  const props = withDefaults(defineProps<Props>(), {\n    variant: 'digit',\n    disabled: false,\n    active: false,\n    size: 'medium'\n  })\n  \n  // Define emits\n  const emit = defineEmits<Emits>()\n  \n  // Local state\n  const isHovered = ref(false)\n  const isFocused = ref(false)\n  const pressCount = ref(0)\n  \n  // Computed classes based on props and state\n  const buttonClass = computed(() => {\n    const classes = ['calc-button', `calc-button--${props.variant}`, `calc-button--${props.size}`]\n  \n    if (props.active) classes.push('calc-button--active')\n    if (props.disabled) classes.push('calc-button--disabled')\n    if (isHovered.value) classes.push('calc-button--hovered')\n    if (isFocused.value) classes.push('calc-button--focused')\n  \n    return classes.join(' ')\n  })\n  \n  // Computed aria label for accessibility\n  const ariaLabel = computed(() => {\n    const variantText = {\n      digit: 'Number',\n      operation: 'Operation',\n      equals: 'Equals',\n      clear: 'Clear'\n    }[props.variant]\n  \n    return `${variantText}: ${props.label}`\n  })\n  \n  // Event handlers that emit events\n  const handleClick = () => {\n    if (!props.disabled) {\n      pressCount.value++\n      emit('click', props.label)\n    }\n  }\n  const handleDoubleClick = () => {\n      pressCount.value++;\n      emit('click', props.label);\n  }\n  \n  const handleMouseEnter = () => {\n    isHovered.value = true\n    emit('hover', true)\n  }\n  \n  const handleMouseLeave = () => {\n    isHovered.value = false\n    emit('hover', false)\n  }\n  \n  const handleFocus = () => {\n    isFocused.value = true\n    emit('focus')\n  }\n  \n  const handleBlur = () => {\n    isFocused.value = false\n    emit('blur')\n  }\n  \n  // Expose internal state for parent access via template refs\n  // Demonstrates: defineExpose\n  defineExpose({\n    pressCount,\n    isHovered,\n    isFocused,\n    simulateClick: handleClick\n  })\n  </script>\n  \n  <template>\n    <button\n      :class=\"buttonClass\"\n      :disabled=\"disabled\"\n      :aria-label=\"ariaLabel\"\n      @click=\"handleClick\"\n      @mouseenter=\"handleMouseEnter\"\n      @mouseleave=\"handleMouseLeave\"\n      @focus=\"handleFocus\"\n      @blur=\"handleBlur\"\n    >\n      <span class=\"calc-button__label\">{{ label }}</span>\n      <span v-if=\"pressCount > 0\" class=\"calc-button__badge\">{{ pressCount }}</span>\n    </button>\n  </template>\n  \n  <style scoped>\n  .calc-button {\n    position: relative;\n    padding: 1rem;\n    font-size: 1.2rem;\n    border: none;\n    border-radius: 4px;\n    cursor: pointer;\n    transition: all 0.2s;\n    font-weight: 500;\n  }\n  \n  .calc-button--small {\n    padding: 0.5rem;\n    font-size: 1rem;\n  }\n  \n  .calc-button--medium {\n    padding: 1rem;\n    font-size: 1.2rem;\n  }\n  \n  .calc-button--large {\n    padding: 1.5rem;\n    font-size: 1.5rem;\n  }\n  \n  .calc-button--digit {\n    background: white;\n    color: #333;\n  }\n  \n  .calc-button--digit:hover:not(:disabled) {\n    background: #e0e0e0;\n  }\n  \n  .calc-button--operation {\n    background: #2196f3;\n    color: white;\n  }\n  \n  .calc-button--operation:hover:not(:disabled) {\n    background: #1976d2;\n  }\n  \n  .calc-button--operation.calc-button--active {\n    background: #1565c0;\n  }\n  \n  .calc-button--equals {\n    background: #4caf50;\n    color: white;\n  }\n  \n  .calc-button--equals:hover:not(:disabled) {\n    background: #45a049;\n  }\n  \n  .calc-button--clear {\n    background: #f44336;\n    color: white;\n  }\n  \n  .calc-button--clear:hover:not(:disabled) {\n    background: #da190b;\n  }\n  \n  .calc-button--disabled {\n    opacity: 0.5;\n    cursor: not-allowed;\n  }\n  \n  .calc-button--hovered {\n    transform: translateY(-2px);\n    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);\n  }\n  \n  .calc-button--focused {\n    outline: 2px solid #2196f3;\n    outline-offset: 2px;\n  }\n  \n  .calc-button__label {\n    display: block;\n  }\n  \n  .calc-button__badge {\n    position: absolute;\n    top: -5px;\n    right: -5px;\n    background: #ff5722;\n    color: white;\n    border-radius: 50%;\n    width: 20px;\n    height: 20px;\n    font-size: 0.7rem;\n    display: flex;\n    align-items: center;\n    justify-content: center;\n  }\n  </style>\n  \n  '''\n# ---\n# name: test_insert_in_rel_to_symbol_vue[test_case0-before]\n  '''\n  <script setup lang=\"ts\">\n  import { computed, ref } from 'vue'\n  \n  /**\n   * Props interface for CalculatorButton.\n   * Demonstrates: defineProps with TypeScript interface\n   */\n  interface Props {\n    label: string | number\n    variant?: 'digit' | 'operation' | 'equals' | 'clear'\n    disabled?: boolean\n    active?: boolean\n    size?: 'small' | 'medium' | 'large'\n  }\n  \n  /**\n   * Emits interface for CalculatorButton.\n   * Demonstrates: defineEmits with TypeScript\n   */\n  interface Emits {\n    click: [value: string | number]\n    hover: [isHovering: boolean]\n    focus: []\n    blur: []\n  }\n  \n  // Define props with defaults\n  const props = withDefaults(defineProps<Props>(), {\n    variant: 'digit',\n    disabled: false,\n    active: false,\n    size: 'medium'\n  })\n  \n  // Define emits\n  const emit = defineEmits<Emits>()\n  \n  // Local state\n  const isHovered = ref(false)\n  const isFocused = ref(false)\n  const pressCount = ref(0)\n  \n  // Computed classes based on props and state\n  const buttonClass = computed(() => {\n    const classes = ['calc-button', `calc-button--${props.variant}`, `calc-button--${props.size}`]\n  \n    if (props.active) classes.push('calc-button--active')\n    if (props.disabled) classes.push('calc-button--disabled')\n    if (isHovered.value) classes.push('calc-button--hovered')\n    if (isFocused.value) classes.push('calc-button--focused')\n  \n    return classes.join(' ')\n  })\n  \n  // Computed aria label for accessibility\n  const ariaLabel = computed(() => {\n    const variantText = {\n      digit: 'Number',\n      operation: 'Operation',\n      equals: 'Equals',\n      clear: 'Clear'\n    }[props.variant]\n  \n    return `${variantText}: ${props.label}`\n  })\n  \n  // Event handlers that emit events\n  const handleDoubleClick = () => {\n      pressCount.value++;\n      emit('click', props.label);\n  }\n  const handleClick = () => {\n    if (!props.disabled) {\n      pressCount.value++\n      emit('click', props.label)\n    }\n  }\n  \n  const handleMouseEnter = () => {\n    isHovered.value = true\n    emit('hover', true)\n  }\n  \n  const handleMouseLeave = () => {\n    isHovered.value = false\n    emit('hover', false)\n  }\n  \n  const handleFocus = () => {\n    isFocused.value = true\n    emit('focus')\n  }\n  \n  const handleBlur = () => {\n    isFocused.value = false\n    emit('blur')\n  }\n  \n  // Expose internal state for parent access via template refs\n  // Demonstrates: defineExpose\n  defineExpose({\n    pressCount,\n    isHovered,\n    isFocused,\n    simulateClick: handleClick\n  })\n  </script>\n  \n  <template>\n    <button\n      :class=\"buttonClass\"\n      :disabled=\"disabled\"\n      :aria-label=\"ariaLabel\"\n      @click=\"handleClick\"\n      @mouseenter=\"handleMouseEnter\"\n      @mouseleave=\"handleMouseLeave\"\n      @focus=\"handleFocus\"\n      @blur=\"handleBlur\"\n    >\n      <span class=\"calc-button__label\">{{ label }}</span>\n      <span v-if=\"pressCount > 0\" class=\"calc-button__badge\">{{ pressCount }}</span>\n    </button>\n  </template>\n  \n  <style scoped>\n  .calc-button {\n    position: relative;\n    padding: 1rem;\n    font-size: 1.2rem;\n    border: none;\n    border-radius: 4px;\n    cursor: pointer;\n    transition: all 0.2s;\n    font-weight: 500;\n  }\n  \n  .calc-button--small {\n    padding: 0.5rem;\n    font-size: 1rem;\n  }\n  \n  .calc-button--medium {\n    padding: 1rem;\n    font-size: 1.2rem;\n  }\n  \n  .calc-button--large {\n    padding: 1.5rem;\n    font-size: 1.5rem;\n  }\n  \n  .calc-button--digit {\n    background: white;\n    color: #333;\n  }\n  \n  .calc-button--digit:hover:not(:disabled) {\n    background: #e0e0e0;\n  }\n  \n  .calc-button--operation {\n    background: #2196f3;\n    color: white;\n  }\n  \n  .calc-button--operation:hover:not(:disabled) {\n    background: #1976d2;\n  }\n  \n  .calc-button--operation.calc-button--active {\n    background: #1565c0;\n  }\n  \n  .calc-button--equals {\n    background: #4caf50;\n    color: white;\n  }\n  \n  .calc-button--equals:hover:not(:disabled) {\n    background: #45a049;\n  }\n  \n  .calc-button--clear {\n    background: #f44336;\n    color: white;\n  }\n  \n  .calc-button--clear:hover:not(:disabled) {\n    background: #da190b;\n  }\n  \n  .calc-button--disabled {\n    opacity: 0.5;\n    cursor: not-allowed;\n  }\n  \n  .calc-button--hovered {\n    transform: translateY(-2px);\n    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);\n  }\n  \n  .calc-button--focused {\n    outline: 2px solid #2196f3;\n    outline-offset: 2px;\n  }\n  \n  .calc-button__label {\n    display: block;\n  }\n  \n  .calc-button__badge {\n    position: absolute;\n    top: -5px;\n    right: -5px;\n    background: #ff5722;\n    color: white;\n    border-radius: 50%;\n    width: 20px;\n    height: 20px;\n    font-size: 0.7rem;\n    display: flex;\n    align-items: center;\n    justify-content: center;\n  }\n  </style>\n  \n  '''\n# ---\n# name: test_insert_python_class_after\n  '''\n  \"\"\"\n  Test module for variable declarations and usage.\n  \n  This module tests various types of variable declarations and usages including:\n  - Module-level variables\n  - Class-level variables\n  - Instance variables\n  - Variable reassignments\n  \"\"\"\n  \n  from dataclasses import dataclass, field\n  \n  # Module-level variables\n  module_var = \"Initial module value\"\n  \n  reassignable_module_var = 10\n  reassignable_module_var = 20  # Reassigned\n  \n  # Module-level variable with type annotation\n  typed_module_var: int = 42\n  \n  \n  # Regular class with class and instance variables\n  class VariableContainer:\n      \"\"\"Class that contains various variables.\"\"\"\n  \n      # Class-level variables\n      class_var = \"Initial class value\"\n  \n      reassignable_class_var = True\n      reassignable_class_var = False  # Reassigned #noqa: PIE794\n  \n      # Class-level variable with type annotation\n      typed_class_var: str = \"typed value\"\n  \n      def __init__(self):\n          # Instance variables\n          self.instance_var = \"Initial instance value\"\n          self.reassignable_instance_var = 100\n  \n          # Instance variable with type annotation\n          self.typed_instance_var: list[str] = [\"item1\", \"item2\"]\n  \n      def modify_instance_var(self):\n          # Reassign instance variable\n          self.instance_var = \"Modified instance value\"\n          self.reassignable_instance_var = 200  # Reassigned\n  \n      def use_module_var(self):\n          # Use module-level variables\n          result = module_var + \" used in method\"\n          other_result = reassignable_module_var + 5\n          return result, other_result\n  \n      def use_class_var(self):\n          # Use class-level variables\n          result = VariableContainer.class_var + \" used in method\"\n          other_result = VariableContainer.reassignable_class_var\n          return result, other_result\n  \n  \n  # Dataclass with variables\n  @dataclass\n  class VariableDataclass:\n      \"\"\"Dataclass that contains various fields.\"\"\"\n  \n      # Field variables with type annotations\n      id: int\n      name: str\n      items: list[str] = field(default_factory=list)\n      metadata: dict[str, str] = field(default_factory=dict)\n      optional_value: float | None = None\n  \n      # This will be reassigned in various places\n      status: str = \"pending\"\n  \n  \n  class NewInsertedClass:\n      pass\n  \n  \n  # Function that uses the module variables\n  def use_module_variables():\n      \"\"\"Function that uses module-level variables.\"\"\"\n      result = module_var + \" used in function\"\n      other_result = reassignable_module_var * 2\n      return result, other_result\n  \n  \n  # Create instances and use variables\n  dataclass_instance = VariableDataclass(id=1, name=\"Test\")\n  dataclass_instance.status = \"active\"  # Reassign dataclass field\n  \n  # Use variables at module level\n  module_result = module_var + \" used at module level\"\n  other_module_result = reassignable_module_var + 30\n  \n  # Create a second dataclass instance with different status\n  second_dataclass = VariableDataclass(id=2, name=\"Another Test\")\n  second_dataclass.status = \"completed\"  # Another reassignment of status\n  \n  '''\n# ---\n# name: test_insert_python_class_before\n  '''\n  \"\"\"\n  Test module for variable declarations and usage.\n  \n  This module tests various types of variable declarations and usages including:\n  - Module-level variables\n  - Class-level variables\n  - Instance variables\n  - Variable reassignments\n  \"\"\"\n  \n  from dataclasses import dataclass, field\n  \n  # Module-level variables\n  module_var = \"Initial module value\"\n  \n  reassignable_module_var = 10\n  reassignable_module_var = 20  # Reassigned\n  \n  # Module-level variable with type annotation\n  typed_module_var: int = 42\n  \n  \n  # Regular class with class and instance variables\n  class VariableContainer:\n      \"\"\"Class that contains various variables.\"\"\"\n  \n      # Class-level variables\n      class_var = \"Initial class value\"\n  \n      reassignable_class_var = True\n      reassignable_class_var = False  # Reassigned #noqa: PIE794\n  \n      # Class-level variable with type annotation\n      typed_class_var: str = \"typed value\"\n  \n      def __init__(self):\n          # Instance variables\n          self.instance_var = \"Initial instance value\"\n          self.reassignable_instance_var = 100\n  \n          # Instance variable with type annotation\n          self.typed_instance_var: list[str] = [\"item1\", \"item2\"]\n  \n      def modify_instance_var(self):\n          # Reassign instance variable\n          self.instance_var = \"Modified instance value\"\n          self.reassignable_instance_var = 200  # Reassigned\n  \n      def use_module_var(self):\n          # Use module-level variables\n          result = module_var + \" used in method\"\n          other_result = reassignable_module_var + 5\n          return result, other_result\n  \n      def use_class_var(self):\n          # Use class-level variables\n          result = VariableContainer.class_var + \" used in method\"\n          other_result = VariableContainer.reassignable_class_var\n          return result, other_result\n  \n  \n  # Dataclass with variables\n  class NewInsertedClass:\n      pass\n  \n  \n  @dataclass\n  class VariableDataclass:\n      \"\"\"Dataclass that contains various fields.\"\"\"\n  \n      # Field variables with type annotations\n      id: int\n      name: str\n      items: list[str] = field(default_factory=list)\n      metadata: dict[str, str] = field(default_factory=dict)\n      optional_value: float | None = None\n  \n      # This will be reassigned in various places\n      status: str = \"pending\"\n  \n  \n  # Function that uses the module variables\n  def use_module_variables():\n      \"\"\"Function that uses module-level variables.\"\"\"\n      result = module_var + \" used in function\"\n      other_result = reassignable_module_var * 2\n      return result, other_result\n  \n  \n  # Create instances and use variables\n  dataclass_instance = VariableDataclass(id=1, name=\"Test\")\n  dataclass_instance.status = \"active\"  # Reassign dataclass field\n  \n  # Use variables at module level\n  module_result = module_var + \" used at module level\"\n  other_module_result = reassignable_module_var + 30\n  \n  # Create a second dataclass instance with different status\n  second_dataclass = VariableDataclass(id=2, name=\"Another Test\")\n  second_dataclass.status = \"completed\"  # Another reassignment of status\n  \n  '''\n# ---\n# name: test_nix_symbol_replacement_no_double_semicolon\n  '''\n  # default.nix - Traditional Nix expression for backwards compatibility\n  { pkgs ? import <nixpkgs> { } }:\n  \n  let\n    # Import library functions\n    lib = pkgs.lib;\n    stdenv = pkgs.stdenv;\n  \n    # Import our custom utilities\n    utils = import ./lib/utils.nix { inherit lib; };\n  \n    # Custom function to create a greeting\n    makeGreeting = name: \"Hello, ${name}!\";\n  \n    # List manipulation functions (using imported utils)\n    listUtils = {\n      double = list: map (x: x * 2) list;\n      sum = list: lib.foldl' (acc: x: acc + x) 0 list;\n      average = list:\n        if list == [ ]\n        then 0\n        else (listUtils.sum list) / (builtins.length list);\n      # Use function from imported utils\n      unique = utils.lists.unique;\n    };\n  \n    # String utilities\n    stringUtils = rec {\n      capitalize = str:\n        let\n          first = lib.substring 0 1 str;\n          rest = lib.substring 1 (-1) str;\n        in\n        (lib.toUpper first) + rest;\n  \n      repeat = n: str: lib.concatStrings (lib.genList (_: str) n);\n  \n      padLeft = width: char: str:\n        let\n          len = lib.stringLength str;\n          padding = if len >= width then 0 else width - len;\n        in\n        (repeat padding char) + str;\n    };\n  \n    # Package builder helper\n    buildSimplePackage = { name, version, script }:\n      stdenv.mkDerivation {\n        pname = name;\n        inherit version;\n  \n        phases = [ \"installPhase\" ];\n  \n        installPhase = ''\n          mkdir -p $out/bin\n          cat > $out/bin/${name} << EOF\n          #!/usr/bin/env bash\n          ${script}\n          EOF\n          chmod +x $out/bin/${name}\n        '';\n      };\n  \n  in\n  rec {\n    # Export utilities\n    inherit listUtils stringUtils makeGreeting;\n  \n    # Export imported utilities directly\n    inherit (utils) math strings;\n  \n    # Example packages\n    hello = buildSimplePackage {\n      name = \"hello\";\n      version = \"1.0\";\n      script = ''\n        echo \"${makeGreeting \"World\"}\"\n      '';\n    };\n  \n    calculator = buildSimplePackage {\n      name = \"calculator\";\n      version = \"0.1\";\n      script = ''\n        if [ $# -ne 3 ]; then\n          echo \"Usage: calculator <num1> <op> <num2>\"\n          exit 1\n        fi\n        \n        case $2 in\n          +) echo $(($1 + $3)) ;;\n          -) echo $(($1 - $3)) ;;\n          x) echo $(($1 * $3)) ;;\n          /) echo $(($1 / $3)) ;;\n          *) echo \"Unknown operator: $2\" ;;\n        esac\n      '';\n    };\n  \n    # Environment with multiple packages\n    devEnv = pkgs.buildEnv {\n      name = \"dev-environment\";\n      paths = with pkgs; [\n        git\n        vim\n        bash\n        hello\n        calculator\n      ];\n    };\n  \n    # Shell derivation\n    shell = pkgs.mkShell {\n      buildInputs = with pkgs; [\n        bash\n        coreutils\n        findutils\n        gnugrep\n        gnused\n      ];\n  \n      shellHook = ''\n        echo \"Entering Nix shell environment\"\n        echo \"Available custom functions: makeGreeting, listUtils, stringUtils\"\n      '';\n    };\n  \n    # Configuration example\n    config = {\n      system = {\n        stateVersion = \"23.11\";\n        enable = true;\n      };\n  \n      services = {\n        nginx = {\n          enable = false;\n          virtualHosts = {\n            \"example.com\" = {\n              root = \"/var/www/example\";\n              locations.\"/\" = {\n                index = \"index.html\";\n              };\n            };\n          };\n        };\n      };\n  \n      users = {\n        c = 3;\n      };\n    };\n  \n    # Recursive attribute set example\n    tree = {\n      root = {\n        value = 1;\n        left = {\n          value = 2;\n          left = { value = 4; };\n          right = { value = 5; };\n        };\n        right = {\n          value = 3;\n          left = { value = 6; };\n          right = { value = 7; };\n        };\n      };\n  \n      # Tree traversal function\n      traverse = node:\n        if node ? left && node ? right\n        then [ node.value ] ++ (tree.traverse node.left) ++ (tree.traverse node.right)\n        else if node ? value\n        then [ node.value ]\n        else [ ];\n    };\n  }\n  \n  '''\n# ---\n# name: test_rename_symbol\n  '''\n  \"\"\"\n  Test module for variable declarations and usage.\n  \n  This module tests various types of variable declarations and usages including:\n  - Module-level variables\n  - Class-level variables\n  - Instance variables\n  - Variable reassignments\n  \"\"\"\n  \n  from dataclasses import dataclass, field\n  \n  # Module-level variables\n  module_var = \"Initial module value\"\n  \n  reassignable_module_var = 10\n  reassignable_module_var = 20  # Reassigned\n  \n  # Module-level variable with type annotation\n  renamed_typed_module_var: int = 42\n  \n  \n  # Regular class with class and instance variables\n  class VariableContainer:\n      \"\"\"Class that contains various variables.\"\"\"\n  \n      # Class-level variables\n      class_var = \"Initial class value\"\n  \n      reassignable_class_var = True\n      reassignable_class_var = False  # Reassigned #noqa: PIE794\n  \n      # Class-level variable with type annotation\n      typed_class_var: str = \"typed value\"\n  \n      def __init__(self):\n          # Instance variables\n          self.instance_var = \"Initial instance value\"\n          self.reassignable_instance_var = 100\n  \n          # Instance variable with type annotation\n          self.typed_instance_var: list[str] = [\"item1\", \"item2\"]\n  \n      def modify_instance_var(self):\n          # Reassign instance variable\n          self.instance_var = \"Modified instance value\"\n          self.reassignable_instance_var = 200  # Reassigned\n  \n      def use_module_var(self):\n          # Use module-level variables\n          result = module_var + \" used in method\"\n          other_result = reassignable_module_var + 5\n          return result, other_result\n  \n      def use_class_var(self):\n          # Use class-level variables\n          result = VariableContainer.class_var + \" used in method\"\n          other_result = VariableContainer.reassignable_class_var\n          return result, other_result\n  \n  \n  # Dataclass with variables\n  @dataclass\n  class VariableDataclass:\n      \"\"\"Dataclass that contains various fields.\"\"\"\n  \n      # Field variables with type annotations\n      id: int\n      name: str\n      items: list[str] = field(default_factory=list)\n      metadata: dict[str, str] = field(default_factory=dict)\n      optional_value: float | None = None\n  \n      # This will be reassigned in various places\n      status: str = \"pending\"\n  \n  \n  # Function that uses the module variables\n  def use_module_variables():\n      \"\"\"Function that uses module-level variables.\"\"\"\n      result = module_var + \" used in function\"\n      other_result = reassignable_module_var * 2\n      return result, other_result\n  \n  \n  # Create instances and use variables\n  dataclass_instance = VariableDataclass(id=1, name=\"Test\")\n  dataclass_instance.status = \"active\"  # Reassign dataclass field\n  \n  # Use variables at module level\n  module_result = module_var + \" used at module level\"\n  other_module_result = reassignable_module_var + 30\n  \n  # Create a second dataclass instance with different status\n  second_dataclass = VariableDataclass(id=2, name=\"Another Test\")\n  second_dataclass.status = \"completed\"  # Another reassignment of status\n  \n  '''\n# ---\n# name: test_replace_body[test_case0]\n  '''\n  \"\"\"\n  Test module for variable declarations and usage.\n  \n  This module tests various types of variable declarations and usages including:\n  - Module-level variables\n  - Class-level variables\n  - Instance variables\n  - Variable reassignments\n  \"\"\"\n  \n  from dataclasses import dataclass, field\n  \n  # Module-level variables\n  module_var = \"Initial module value\"\n  \n  reassignable_module_var = 10\n  reassignable_module_var = 20  # Reassigned\n  \n  # Module-level variable with type annotation\n  typed_module_var: int = 42\n  \n  \n  # Regular class with class and instance variables\n  class VariableContainer:\n      \"\"\"Class that contains various variables.\"\"\"\n  \n      # Class-level variables\n      class_var = \"Initial class value\"\n  \n      reassignable_class_var = True\n      reassignable_class_var = False  # Reassigned #noqa: PIE794\n  \n      # Class-level variable with type annotation\n      typed_class_var: str = \"typed value\"\n  \n      def __init__(self):\n          # Instance variables\n          self.instance_var = \"Initial instance value\"\n          self.reassignable_instance_var = 100\n  \n          # Instance variable with type annotation\n          self.typed_instance_var: list[str] = [\"item1\", \"item2\"]\n  \n      def modify_instance_var(self):\n          # This body has been replaced\n          self.instance_var = \"Replaced!\"\n          self.reassignable_instance_var = 999  # Reassigned\n  \n      def use_module_var(self):\n          # Use module-level variables\n          result = module_var + \" used in method\"\n          other_result = reassignable_module_var + 5\n          return result, other_result\n  \n      def use_class_var(self):\n          # Use class-level variables\n          result = VariableContainer.class_var + \" used in method\"\n          other_result = VariableContainer.reassignable_class_var\n          return result, other_result\n  \n  \n  # Dataclass with variables\n  @dataclass\n  class VariableDataclass:\n      \"\"\"Dataclass that contains various fields.\"\"\"\n  \n      # Field variables with type annotations\n      id: int\n      name: str\n      items: list[str] = field(default_factory=list)\n      metadata: dict[str, str] = field(default_factory=dict)\n      optional_value: float | None = None\n  \n      # This will be reassigned in various places\n      status: str = \"pending\"\n  \n  \n  # Function that uses the module variables\n  def use_module_variables():\n      \"\"\"Function that uses module-level variables.\"\"\"\n      result = module_var + \" used in function\"\n      other_result = reassignable_module_var * 2\n      return result, other_result\n  \n  \n  # Create instances and use variables\n  dataclass_instance = VariableDataclass(id=1, name=\"Test\")\n  dataclass_instance.status = \"active\"  # Reassign dataclass field\n  \n  # Use variables at module level\n  module_result = module_var + \" used at module level\"\n  other_module_result = reassignable_module_var + 30\n  \n  # Create a second dataclass instance with different status\n  second_dataclass = VariableDataclass(id=2, name=\"Another Test\")\n  second_dataclass.status = \"completed\"  # Another reassignment of status\n  \n  '''\n# ---\n# name: test_replace_body[test_case1]\n  '''\n  export class DemoClass {\n      value: number;\n      constructor(value: number) {\n          this.value = value;\n      }\n      function printValue() {\n          // This body has been replaced\n          console.warn(\"New value: \" + this.value);\n      }\n  }\n  \n  export function helperFunction() {\n      const demo = new DemoClass(42);\n      demo.printValue();\n  }\n  \n  helperFunction();\n  \n  '''\n# ---\n# name: test_replace_body_vue[test_case0]\n  '''\n  <script setup lang=\"ts\">\n  import { computed, ref } from 'vue'\n  \n  /**\n   * Props interface for CalculatorButton.\n   * Demonstrates: defineProps with TypeScript interface\n   */\n  interface Props {\n    label: string | number\n    variant?: 'digit' | 'operation' | 'equals' | 'clear'\n    disabled?: boolean\n    active?: boolean\n    size?: 'small' | 'medium' | 'large'\n  }\n  \n  /**\n   * Emits interface for CalculatorButton.\n   * Demonstrates: defineEmits with TypeScript\n   */\n  interface Emits {\n    click: [value: string | number]\n    hover: [isHovering: boolean]\n    focus: []\n    blur: []\n  }\n  \n  // Define props with defaults\n  const props = withDefaults(defineProps<Props>(), {\n    variant: 'digit',\n    disabled: false,\n    active: false,\n    size: 'medium'\n  })\n  \n  // Define emits\n  const emit = defineEmits<Emits>()\n  \n  // Local state\n  const isHovered = ref(false)\n  const isFocused = ref(false)\n  const pressCount = ref(0)\n  \n  // Computed classes based on props and state\n  const buttonClass = computed(() => {\n    const classes = ['calc-button', `calc-button--${props.variant}`, `calc-button--${props.size}`]\n  \n    if (props.active) classes.push('calc-button--active')\n    if (props.disabled) classes.push('calc-button--disabled')\n    if (isHovered.value) classes.push('calc-button--hovered')\n    if (isFocused.value) classes.push('calc-button--focused')\n  \n    return classes.join(' ')\n  })\n  \n  // Computed aria label for accessibility\n  const ariaLabel = computed(() => {\n    const variantText = {\n      digit: 'Number',\n      operation: 'Operation',\n      equals: 'Equals',\n      clear: 'Clear'\n    }[props.variant]\n  \n    return `${variantText}: ${props.label}`\n  })\n  \n  // Event handlers that emit events\n  const const handleClick = () => {\n      if (!props.disabled) {\n          pressCount.value = 0;  // Reset instead of incrementing\n          emit('click', props.label);\n      }\n  }\n  \n  const handleMouseEnter = () => {\n    isHovered.value = true\n    emit('hover', true)\n  }\n  \n  const handleMouseLeave = () => {\n    isHovered.value = false\n    emit('hover', false)\n  }\n  \n  const handleFocus = () => {\n    isFocused.value = true\n    emit('focus')\n  }\n  \n  const handleBlur = () => {\n    isFocused.value = false\n    emit('blur')\n  }\n  \n  // Expose internal state for parent access via template refs\n  // Demonstrates: defineExpose\n  defineExpose({\n    pressCount,\n    isHovered,\n    isFocused,\n    simulateClick: handleClick\n  })\n  </script>\n  \n  <template>\n    <button\n      :class=\"buttonClass\"\n      :disabled=\"disabled\"\n      :aria-label=\"ariaLabel\"\n      @click=\"handleClick\"\n      @mouseenter=\"handleMouseEnter\"\n      @mouseleave=\"handleMouseLeave\"\n      @focus=\"handleFocus\"\n      @blur=\"handleBlur\"\n    >\n      <span class=\"calc-button__label\">{{ label }}</span>\n      <span v-if=\"pressCount > 0\" class=\"calc-button__badge\">{{ pressCount }}</span>\n    </button>\n  </template>\n  \n  <style scoped>\n  .calc-button {\n    position: relative;\n    padding: 1rem;\n    font-size: 1.2rem;\n    border: none;\n    border-radius: 4px;\n    cursor: pointer;\n    transition: all 0.2s;\n    font-weight: 500;\n  }\n  \n  .calc-button--small {\n    padding: 0.5rem;\n    font-size: 1rem;\n  }\n  \n  .calc-button--medium {\n    padding: 1rem;\n    font-size: 1.2rem;\n  }\n  \n  .calc-button--large {\n    padding: 1.5rem;\n    font-size: 1.5rem;\n  }\n  \n  .calc-button--digit {\n    background: white;\n    color: #333;\n  }\n  \n  .calc-button--digit:hover:not(:disabled) {\n    background: #e0e0e0;\n  }\n  \n  .calc-button--operation {\n    background: #2196f3;\n    color: white;\n  }\n  \n  .calc-button--operation:hover:not(:disabled) {\n    background: #1976d2;\n  }\n  \n  .calc-button--operation.calc-button--active {\n    background: #1565c0;\n  }\n  \n  .calc-button--equals {\n    background: #4caf50;\n    color: white;\n  }\n  \n  .calc-button--equals:hover:not(:disabled) {\n    background: #45a049;\n  }\n  \n  .calc-button--clear {\n    background: #f44336;\n    color: white;\n  }\n  \n  .calc-button--clear:hover:not(:disabled) {\n    background: #da190b;\n  }\n  \n  .calc-button--disabled {\n    opacity: 0.5;\n    cursor: not-allowed;\n  }\n  \n  .calc-button--hovered {\n    transform: translateY(-2px);\n    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);\n  }\n  \n  .calc-button--focused {\n    outline: 2px solid #2196f3;\n    outline-offset: 2px;\n  }\n  \n  .calc-button__label {\n    display: block;\n  }\n  \n  .calc-button__badge {\n    position: absolute;\n    top: -5px;\n    right: -5px;\n    background: #ff5722;\n    color: white;\n    border-radius: 50%;\n    width: 20px;\n    height: 20px;\n    font-size: 0.7rem;\n    display: flex;\n    align-items: center;\n    justify-content: center;\n  }\n  </style>\n  \n  '''\n# ---\n# name: test_replace_body_vue_ts_file[test_case0]\n  '''\n  import { defineStore } from 'pinia'\n  import type { HistoryEntry, Operation, CalculatorState } from '@/types'\n  \n  export const useCalculatorStore = defineStore('calculator', {\n    state: (): CalculatorState => ({\n      currentValue: 0,\n      previousValue: null,\n      operation: null,\n      history: [],\n      displayValue: '0'\n    }),\n  \n    getters: {\n      /**\n       * Get the most recent history entries (last 10)\n       */\n      recentHistory: (state): HistoryEntry[] => {\n        return state.history.slice(-10).reverse()\n      },\n  \n      /**\n       * Check if calculator has any history\n       */\n      hasHistory: (state): boolean => {\n        return state.history.length > 0\n      },\n  \n      /**\n       * Get the current display text\n       */\n      display: (state): string => {\n        return state.displayValue\n      }\n    },\n  \n    actions: {\n      /**\n       * Set a number value\n       */\n      setNumber(value: number) {\n        this.currentValue = value\n        this.displayValue = value.toString()\n      },\n  \n      /**\n       * Append a digit to the current value\n       */\n      appendDigit(digit: number) {\n        if (this.displayValue === '0') {\n          this.displayValue = digit.toString()\n        } else {\n          this.displayValue += digit.toString()\n        }\n        this.currentValue = parseFloat(this.displayValue)\n      },\n  \n      /**\n       * Add two numbers\n       */\n      add() {\n        if (this.previousValue !== null && this.operation) {\n          this.executeOperation()\n        }\n        this.previousValue = this.currentValue\n        this.operation = 'add'\n        this.displayValue = '0'\n      },\n  \n      /**\n       * Subtract two numbers\n       */\n      subtract() {\n        if (this.previousValue !== null && this.operation) {\n          this.executeOperation()\n        }\n        this.previousValue = this.currentValue\n        this.operation = 'subtract'\n        this.displayValue = '0'\n      },\n  \n      /**\n       * Multiply two numbers\n       */\n      multiply() {\n        if (this.previousValue !== null && this.operation) {\n          this.executeOperation()\n        }\n        this.previousValue = this.currentValue\n        this.operation = 'multiply'\n        this.displayValue = '0'\n      },\n  \n      /**\n       * Divide two numbers\n       */\n      divide() {\n        if (this.previousValue !== null && this.operation) {\n          this.executeOperation()\n        }\n        this.previousValue = this.currentValue\n        this.operation = 'divide'\n        this.displayValue = '0'\n      },\n  \n      /**\n       * Execute the pending operation\n       */\n      executeOperation() {\n        if (this.previousValue === null || this.operation === null) {\n          return\n        }\n  \n        let result = 0\n        const prev = this.previousValue\n        const current = this.currentValue\n        let expression = ''\n  \n        switch (this.operation) {\n          case 'add':\n            result = prev + current\n            expression = `${prev} + ${current}`\n            break\n          case 'subtract':\n            result = prev - current\n            expression = `${prev} - ${current}`\n            break\n          case 'multiply':\n            result = prev * current\n            expression = `${prev} × ${current}`\n            break\n          case 'divide':\n            if (current === 0) {\n              this.displayValue = 'Error'\n              this.clear()\n              return\n            }\n            result = prev / current\n            expression = `${prev} ÷ ${current}`\n            break\n        }\n  \n        // Add to history\n        this.history.push({\n          expression,\n          result,\n          timestamp: new Date()\n        })\n  \n        this.currentValue = result\n        this.displayValue = result.toString()\n        this.previousValue = null\n        this.operation = null\n      },\n  \n      /**\n       * Calculate the equals operation\n       */\n      equals() {\n        this.executeOperation()\n      },\n  \n      /**\n       * Clear the calculator state\n       */\n      function clear() {\n      // Modified: Reset to initial state with a log\n      console.log('Clearing calculator state');\n      displayValue.value = '0';\n      expression.value = '';\n      operationHistory.value = [];\n      lastResult.value = undefined;\n  },\n  \n      /**\n       * Clear all history\n       */\n      clearHistory() {\n        this.history = []\n      }\n    }\n  })\n  \n  '''\n# ---\n# name: test_replace_body_vue_with_disambiguation[test_case0]\n  '''\n  <script setup lang=\"ts\">\n  import { computed, ref } from 'vue'\n  \n  /**\n   * Props interface for CalculatorButton.\n   * Demonstrates: defineProps with TypeScript interface\n   */\n  interface Props {\n    label: string | number\n    variant?: 'digit' | 'operation' | 'equals' | 'clear'\n    disabled?: boolean\n    active?: boolean\n    size?: 'small' | 'medium' | 'large'\n  }\n  \n  /**\n   * Emits interface for CalculatorButton.\n   * Demonstrates: defineEmits with TypeScript\n   */\n  interface Emits {\n    click: [value: string | number]\n    hover: [isHovering: boolean]\n    focus: []\n    blur: []\n  }\n  \n  // Define props with defaults\n  const props = withDefaults(defineProps<Props>(), {\n    variant: 'digit',\n    disabled: false,\n    active: false,\n    size: 'medium'\n  })\n  \n  // Define emits\n  const emit = defineEmits<Emits>()\n  \n  // Local state\n  const isHovered = ref(false)\n  const isFocused = ref(false)\n  const const pressCount = ref(100)\n  \n  // Computed classes based on props and state\n  const buttonClass = computed(() => {\n    const classes = ['calc-button', `calc-button--${props.variant}`, `calc-button--${props.size}`]\n  \n    if (props.active) classes.push('calc-button--active')\n    if (props.disabled) classes.push('calc-button--disabled')\n    if (isHovered.value) classes.push('calc-button--hovered')\n    if (isFocused.value) classes.push('calc-button--focused')\n  \n    return classes.join(' ')\n  })\n  \n  // Computed aria label for accessibility\n  const ariaLabel = computed(() => {\n    const variantText = {\n      digit: 'Number',\n      operation: 'Operation',\n      equals: 'Equals',\n      clear: 'Clear'\n    }[props.variant]\n  \n    return `${variantText}: ${props.label}`\n  })\n  \n  // Event handlers that emit events\n  const handleClick = () => {\n    if (!props.disabled) {\n      pressCount.value++\n      emit('click', props.label)\n    }\n  }\n  \n  const handleMouseEnter = () => {\n    isHovered.value = true\n    emit('hover', true)\n  }\n  \n  const handleMouseLeave = () => {\n    isHovered.value = false\n    emit('hover', false)\n  }\n  \n  const handleFocus = () => {\n    isFocused.value = true\n    emit('focus')\n  }\n  \n  const handleBlur = () => {\n    isFocused.value = false\n    emit('blur')\n  }\n  \n  // Expose internal state for parent access via template refs\n  // Demonstrates: defineExpose\n  defineExpose({\n    pressCount,\n    isHovered,\n    isFocused,\n    simulateClick: handleClick\n  })\n  </script>\n  \n  <template>\n    <button\n      :class=\"buttonClass\"\n      :disabled=\"disabled\"\n      :aria-label=\"ariaLabel\"\n      @click=\"handleClick\"\n      @mouseenter=\"handleMouseEnter\"\n      @mouseleave=\"handleMouseLeave\"\n      @focus=\"handleFocus\"\n      @blur=\"handleBlur\"\n    >\n      <span class=\"calc-button__label\">{{ label }}</span>\n      <span v-if=\"pressCount > 0\" class=\"calc-button__badge\">{{ pressCount }}</span>\n    </button>\n  </template>\n  \n  <style scoped>\n  .calc-button {\n    position: relative;\n    padding: 1rem;\n    font-size: 1.2rem;\n    border: none;\n    border-radius: 4px;\n    cursor: pointer;\n    transition: all 0.2s;\n    font-weight: 500;\n  }\n  \n  .calc-button--small {\n    padding: 0.5rem;\n    font-size: 1rem;\n  }\n  \n  .calc-button--medium {\n    padding: 1rem;\n    font-size: 1.2rem;\n  }\n  \n  .calc-button--large {\n    padding: 1.5rem;\n    font-size: 1.5rem;\n  }\n  \n  .calc-button--digit {\n    background: white;\n    color: #333;\n  }\n  \n  .calc-button--digit:hover:not(:disabled) {\n    background: #e0e0e0;\n  }\n  \n  .calc-button--operation {\n    background: #2196f3;\n    color: white;\n  }\n  \n  .calc-button--operation:hover:not(:disabled) {\n    background: #1976d2;\n  }\n  \n  .calc-button--operation.calc-button--active {\n    background: #1565c0;\n  }\n  \n  .calc-button--equals {\n    background: #4caf50;\n    color: white;\n  }\n  \n  .calc-button--equals:hover:not(:disabled) {\n    background: #45a049;\n  }\n  \n  .calc-button--clear {\n    background: #f44336;\n    color: white;\n  }\n  \n  .calc-button--clear:hover:not(:disabled) {\n    background: #da190b;\n  }\n  \n  .calc-button--disabled {\n    opacity: 0.5;\n    cursor: not-allowed;\n  }\n  \n  .calc-button--hovered {\n    transform: translateY(-2px);\n    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);\n  }\n  \n  .calc-button--focused {\n    outline: 2px solid #2196f3;\n    outline-offset: 2px;\n  }\n  \n  .calc-button__label {\n    display: block;\n  }\n  \n  .calc-button__badge {\n    position: absolute;\n    top: -5px;\n    right: -5px;\n    background: #ff5722;\n    color: white;\n    border-radius: 50%;\n    width: 20px;\n    height: 20px;\n    font-size: 0.7rem;\n    display: flex;\n    align-items: center;\n    justify-content: center;\n  }\n  </style>\n  \n  '''\n# ---\n"
  },
  {
    "path": "test/serena/config/__init__.py",
    "content": "# Empty init file for test package\n"
  },
  {
    "path": "test/serena/config/test_global_ignored_paths.py",
    "content": "import os\nimport shutil\nimport tempfile\nfrom pathlib import Path\n\nfrom serena.config.serena_config import ProjectConfig, RegisteredProject, SerenaConfig\nfrom serena.project import Project\nfrom solidlsp.ls_config import Language\n\n\ndef _create_test_project(\n    project_root: Path,\n    project_ignored_paths: list[str] | None = None,\n    global_ignored_paths: list[str] | None = None,\n) -> Project:\n    \"\"\"Helper to create a Project with the given ignored paths configuration.\"\"\"\n    config = ProjectConfig(\n        project_name=\"test_project\",\n        languages=[Language.PYTHON],\n        ignored_paths=project_ignored_paths or [],\n        ignore_all_files_in_gitignore=False,\n    )\n    serena_config = SerenaConfig(gui_log_window=False, web_dashboard=False, ignored_paths=global_ignored_paths)\n    return Project(\n        project_root=str(project_root),\n        project_config=config,\n        serena_config=serena_config,\n    )\n\n\nclass TestGlobalIgnoredPaths:\n    \"\"\"Tests for system-global ignored_paths feature.\"\"\"\n\n    def setup_method(self) -> None:\n        self.test_dir = tempfile.mkdtemp()\n        self.project_path = Path(self.test_dir)\n        # Create some test files and directories\n        (self.project_path / \"main.py\").write_text(\"print('hello')\")\n        os.makedirs(self.project_path / \"node_modules\" / \"pkg\", exist_ok=True)\n        (self.project_path / \"node_modules\" / \"pkg\" / \"index.js\").write_text(\"module.exports = {}\")\n        os.makedirs(self.project_path / \"build\", exist_ok=True)\n        (self.project_path / \"build\" / \"output.js\").write_text(\"compiled\")\n        os.makedirs(self.project_path / \"src\", exist_ok=True)\n        (self.project_path / \"src\" / \"app.py\").write_text(\"def app(): pass\")\n        (self.project_path / \"debug.log\").write_text(\"log data\")\n\n    def teardown_method(self) -> None:\n        shutil.rmtree(self.test_dir)\n\n    def test_global_ignored_paths_are_applied(self) -> None:\n        \"\"\"Global ignored_paths from SerenaConfig are respected by Project.is_ignored_path().\"\"\"\n        project = _create_test_project(\n            self.project_path,\n            global_ignored_paths=[\"node_modules\"],\n        )\n        assert project.is_ignored_path(str(self.project_path / \"node_modules\" / \"pkg\" / \"index.js\"))\n        assert not project.is_ignored_path(str(self.project_path / \"src\" / \"app.py\"))\n\n    def test_additive_merge_of_global_and_project_patterns(self) -> None:\n        \"\"\"Global + project patterns are merged additively (both applied).\"\"\"\n        project = _create_test_project(\n            self.project_path,\n            project_ignored_paths=[\"build\"],\n            global_ignored_paths=[\"node_modules\"],\n        )\n        # Global pattern should be applied\n        assert project.is_ignored_path(str(self.project_path / \"node_modules\" / \"pkg\" / \"index.js\"))\n        # Project pattern should also be applied\n        assert project.is_ignored_path(str(self.project_path / \"build\" / \"output.js\"))\n        # Non-ignored files should not be affected\n        assert not project.is_ignored_path(str(self.project_path / \"src\" / \"app.py\"))\n\n    def test_empty_global_ignored_paths_has_no_effect(self) -> None:\n        \"\"\"Empty global ignored_paths (default) has no effect on existing behavior.\"\"\"\n        project = _create_test_project(\n            self.project_path,\n            project_ignored_paths=[\"build\"],\n            global_ignored_paths=[],\n        )\n        # Project pattern still works\n        assert project.is_ignored_path(str(self.project_path / \"build\" / \"output.js\"))\n        # Non-ignored files still accessible\n        assert not project.is_ignored_path(str(self.project_path / \"node_modules\" / \"pkg\" / \"index.js\"))\n\n    def test_duplicate_patterns_across_global_and_project(self) -> None:\n        \"\"\"Duplicate patterns across global and project do not cause errors.\"\"\"\n        project = _create_test_project(\n            self.project_path,\n            project_ignored_paths=[\"node_modules\", \"build\"],\n            global_ignored_paths=[\"node_modules\", \"build\"],\n        )\n        assert project.is_ignored_path(str(self.project_path / \"node_modules\" / \"pkg\" / \"index.js\"))\n        assert project.is_ignored_path(str(self.project_path / \"build\" / \"output.js\"))\n        assert not project.is_ignored_path(str(self.project_path / \"src\" / \"app.py\"))\n\n    def test_glob_patterns_in_global_ignored_paths(self) -> None:\n        \"\"\"Global ignored_paths support gitignore-style glob patterns.\"\"\"\n        project = _create_test_project(\n            self.project_path,\n            global_ignored_paths=[\"*.log\"],\n        )\n        assert project.is_ignored_path(str(self.project_path / \"debug.log\"))\n        assert not project.is_ignored_path(str(self.project_path / \"main.py\"))\n\n\nclass TestRegisteredProjectGlobalIgnoredPaths:\n    \"\"\"RegisteredProject.get_project_instance() correctly passes global patterns to Project.\"\"\"\n\n    def setup_method(self) -> None:\n        self.test_dir = tempfile.mkdtemp()\n        self.project_path = Path(self.test_dir).resolve()\n        (self.project_path / \"main.py\").write_text(\"print('hello')\")\n        os.makedirs(self.project_path / \"node_modules\", exist_ok=True)\n        (self.project_path / \"node_modules\" / \"pkg.js\").write_text(\"module\")\n\n    def teardown_method(self) -> None:\n        shutil.rmtree(self.test_dir)\n\n    def test_get_project_instance_passes_global_ignored_paths(self) -> None:\n        \"\"\"RegisteredProject.get_project_instance() passes global_ignored_paths to Project.\"\"\"\n        config = ProjectConfig(\n            project_name=\"test_project\",\n            languages=[Language.PYTHON],\n            ignored_paths=[],\n            ignore_all_files_in_gitignore=False,\n        )\n        serena_config = SerenaConfig(gui_log_window=False, web_dashboard=False, ignored_paths=[\"node_modules\"])\n        registered = RegisteredProject(\n            project_root=str(self.project_path),\n            project_config=config,\n        )\n        project = registered.get_project_instance(serena_config=serena_config)\n        assert project.is_ignored_path(str(self.project_path / \"node_modules\" / \"pkg.js\"))\n\n    def test_get_project_instance_without_global_ignored_paths(self) -> None:\n        \"\"\"RegisteredProject without global_ignored_paths defaults to empty.\"\"\"\n        config = ProjectConfig(\n            project_name=\"test_project\",\n            languages=[Language.PYTHON],\n            ignored_paths=[],\n            ignore_all_files_in_gitignore=False,\n        )\n        registered = RegisteredProject(\n            project_root=str(self.project_path),\n            project_config=config,\n        )\n        serena_config = SerenaConfig(gui_log_window=False, web_dashboard=False, ignored_paths=[])\n        project = registered.get_project_instance(serena_config=serena_config)\n        assert not project.is_ignored_path(str(self.project_path / \"node_modules\" / \"pkg.js\"))\n\n    def test_from_project_root_passes_global_ignored_paths(self) -> None:\n        \"\"\"RegisteredProject.from_project_root() threads global_ignored_paths to Project.\"\"\"\n        # Create a minimal project.yml so from_project_root can load config\n        serena_dir = self.project_path / \".serena\"\n        serena_dir.mkdir(exist_ok=True)\n        (serena_dir / \"project.yml\").write_text(\n            'project_name: \"test_project\"\\nlanguages: [\"python\"]\\nignored_paths: []\\nignore_all_files_in_gitignore: false\\n'\n        )\n        serena_config = SerenaConfig(gui_log_window=False, web_dashboard=False, ignored_paths=[\"node_modules\"])\n        registered = RegisteredProject.from_project_root(\n            str(self.project_path),\n            serena_config=serena_config,\n        )\n        project = registered.get_project_instance(serena_config=serena_config)\n        assert project.is_ignored_path(str(self.project_path / \"node_modules\" / \"pkg.js\"))\n\n    def test_from_project_instance_passes_global_ignored_paths(self) -> None:\n        \"\"\"RegisteredProject.from_project_instance() threads global_ignored_paths to Project.\"\"\"\n        config = ProjectConfig(\n            project_name=\"test_project\",\n            languages=[Language.PYTHON],\n            ignored_paths=[],\n            ignore_all_files_in_gitignore=False,\n        )\n        serena_config = SerenaConfig(gui_log_window=False, web_dashboard=False, ignored_paths=[\"node_modules\"])\n        project = Project(\n            project_root=str(self.project_path),\n            project_config=config,\n            serena_config=serena_config,\n        )\n        registered = RegisteredProject.from_project_instance(project)\n        # The registered project already has a project_instance, so get_project_instance() returns it directly\n        retrieved = registered.get_project_instance(serena_config=serena_config)\n        assert retrieved.is_ignored_path(str(self.project_path / \"node_modules\" / \"pkg.js\"))\n\n\nclass TestGlobalIgnoredPathsWithGitignore:\n    \"\"\"Global ignored_paths combined with ignore_all_files_in_gitignore produces correct three-way merge.\"\"\"\n\n    def setup_method(self) -> None:\n        self.test_dir = tempfile.mkdtemp()\n        self.project_path = Path(self.test_dir).resolve()\n        # Create test files\n        (self.project_path / \"main.py\").write_text(\"print('hello')\")\n        os.makedirs(self.project_path / \"node_modules\", exist_ok=True)\n        (self.project_path / \"node_modules\" / \"pkg.js\").write_text(\"module\")\n        os.makedirs(self.project_path / \"dist\", exist_ok=True)\n        (self.project_path / \"dist\" / \"bundle.js\").write_text(\"bundled\")\n        os.makedirs(self.project_path / \"build\", exist_ok=True)\n        (self.project_path / \"build\" / \"output.js\").write_text(\"compiled\")\n        # Create .gitignore that ignores dist/\n        (self.project_path / \".gitignore\").write_text(\"dist/\\n\")\n\n    def teardown_method(self) -> None:\n        shutil.rmtree(self.test_dir)\n\n    def test_three_way_merge_global_project_and_gitignore(self) -> None:\n        \"\"\"Global patterns, project patterns, and .gitignore patterns are all applied together.\"\"\"\n        config = ProjectConfig(\n            project_name=\"test_project\",\n            languages=[Language.PYTHON],\n            ignored_paths=[\"build\"],\n            ignore_all_files_in_gitignore=True,\n        )\n        serena_config = SerenaConfig(gui_log_window=False, web_dashboard=False, ignored_paths=[\"node_modules\"])\n        project = Project(\n            project_root=str(self.project_path),\n            project_config=config,\n            serena_config=serena_config,\n        )\n        # Global pattern: node_modules\n        assert project.is_ignored_path(str(self.project_path / \"node_modules\" / \"pkg.js\"))\n        # Project pattern: build\n        assert project.is_ignored_path(str(self.project_path / \"build\" / \"output.js\"))\n        # Gitignore pattern: dist/\n        assert project.is_ignored_path(str(self.project_path / \"dist\" / \"bundle.js\"))\n        # Non-ignored file\n        assert not project.is_ignored_path(str(self.project_path / \"main.py\"))\n\n\nclass TestSerenaConfigIgnoredPaths:\n    \"\"\"Config loading with ignored_paths in serena_config.yml works correctly.\"\"\"\n\n    def test_serena_config_default_ignored_paths(self) -> None:\n        \"\"\"SerenaConfig defaults to empty ignored_paths.\"\"\"\n        config = SerenaConfig(gui_log_window=False, web_dashboard=False)\n        assert config.ignored_paths == []\n\n    def test_serena_config_with_ignored_paths(self) -> None:\n        \"\"\"SerenaConfig can be created with explicit ignored_paths.\"\"\"\n        config = SerenaConfig(\n            gui_log_window=False,\n            web_dashboard=False,\n            ignored_paths=[\"node_modules\", \"*.log\", \"build\"],\n        )\n        assert config.ignored_paths == [\"node_modules\", \"*.log\", \"build\"]\n"
  },
  {
    "path": "test/serena/config/test_serena_config.py",
    "content": "import logging\nimport os\nimport shutil\nimport tempfile\nfrom pathlib import Path\n\nimport pytest\n\nfrom serena.agent import SerenaAgent\nfrom serena.config.serena_config import (\n    DEFAULT_PROJECT_SERENA_FOLDER_LOCATION,\n    LanguageBackend,\n    ProjectConfig,\n    RegisteredProject,\n    SerenaConfig,\n    SerenaConfigError,\n)\nfrom serena.constants import PROJECT_TEMPLATE_FILE, SERENA_MANAGED_DIR_NAME\nfrom serena.project import MemoriesManager, Project\nfrom solidlsp.ls_config import Language\nfrom test.conftest import create_default_serena_config\n\n\nclass TestProjectConfigAutogenerate:\n    \"\"\"Test class for ProjectConfig autogeneration functionality.\"\"\"\n\n    def setup_method(self):\n        \"\"\"Set up test environment before each test method.\"\"\"\n        # Create a temporary directory for testing\n        self.test_dir = tempfile.mkdtemp()\n        self.serena_config = create_default_serena_config()\n        self.project_path = Path(self.test_dir)\n\n    def teardown_method(self):\n        \"\"\"Clean up test environment after each test method.\"\"\"\n        # Remove the temporary directory\n        shutil.rmtree(self.test_dir)\n\n    def test_autogenerate_empty_directory(self):\n        \"\"\"Test that autogenerate succeeds with empty languages list for an empty directory.\"\"\"\n        config = ProjectConfig.autogenerate(self.project_path, self.serena_config, save_to_disk=False)\n\n        assert config.project_name == self.project_path.name\n        assert config.languages == []\n\n    def test_autogenerate_empty_directory_logs_warning(self, caplog):\n        \"\"\"Test that autogenerate logs a warning when no language files are found.\"\"\"\n        with caplog.at_level(logging.WARNING):\n            ProjectConfig.autogenerate(self.project_path, self.serena_config, save_to_disk=False)\n\n        assert any(\"No source files for supported language servers were found\" in msg for msg in caplog.messages)\n\n    def test_autogenerate_with_python_files(self):\n        \"\"\"Test successful autogeneration with Python source files.\"\"\"\n        # Create a Python file\n        python_file = self.project_path / \"main.py\"\n        python_file.write_text(\"def hello():\\n    print('Hello, world!')\\n\")\n\n        # Run autogenerate\n        config = ProjectConfig.autogenerate(self.project_path, self.serena_config, save_to_disk=False)\n\n        # Verify the configuration\n        assert config.project_name == self.project_path.name\n        assert config.languages == [Language.PYTHON]\n\n    def test_autogenerate_with_js_files(self):\n        \"\"\"Test successful autogeneration with JavaScript source files.\"\"\"\n        # Create files for multiple languages\n        (self.project_path / \"small.js\").write_text(\"console.log('JS');\")\n\n        # Run autogenerate - should pick Python as dominant\n        config = ProjectConfig.autogenerate(self.project_path, self.serena_config, save_to_disk=False)\n\n        assert config.languages == [Language.TYPESCRIPT]\n\n    def test_autogenerate_with_multiple_languages(self):\n        \"\"\"Test autogeneration picks dominant language when multiple are present.\"\"\"\n        # Create files for multiple languages\n        (self.project_path / \"main.py\").write_text(\"print('Python')\")\n        (self.project_path / \"util.py\").write_text(\"def util(): pass\")\n        (self.project_path / \"small.js\").write_text(\"console.log('JS');\")\n\n        # Run autogenerate - should pick Python as dominant\n        config = ProjectConfig.autogenerate(self.project_path, self.serena_config, save_to_disk=False)\n\n        assert config.languages == [Language.PYTHON]\n\n    def test_autogenerate_saves_to_disk(self):\n        \"\"\"Test that autogenerate can save the configuration to disk.\"\"\"\n        # Create a Go file\n        go_file = self.project_path / \"main.go\"\n        go_file.write_text(\"package main\\n\\nfunc main() {}\\n\")\n\n        # Run autogenerate with save_to_disk=True\n        config = ProjectConfig.autogenerate(self.project_path, self.serena_config, save_to_disk=True)\n\n        # Verify the configuration file was created\n        config_path = self.project_path / \".serena\" / \"project.yml\"\n        assert config_path.exists()\n\n        # Verify the content\n        assert config.languages == [Language.GO]\n\n    def test_autogenerate_nonexistent_path(self):\n        \"\"\"Test that autogenerate raises FileNotFoundError for non-existent path.\"\"\"\n        non_existent = self.project_path / \"does_not_exist\"\n\n        with pytest.raises(FileNotFoundError) as exc_info:\n            ProjectConfig.autogenerate(non_existent, self.serena_config, save_to_disk=False)\n\n        assert \"Project root not found\" in str(exc_info.value)\n\n    def test_autogenerate_with_gitignored_files_only(self):\n        \"\"\"Test autogenerate creates a project with empty languages when only gitignored files exist.\"\"\"\n        # Create a .gitignore that ignores all Python files\n        gitignore = self.project_path / \".gitignore\"\n        gitignore.write_text(\"*.py\\n\")\n\n        # Create Python files that will be ignored\n        (self.project_path / \"ignored.py\").write_text(\"print('ignored')\")\n\n        # Should succeed with empty languages (gitignored files are not counted)\n        config = ProjectConfig.autogenerate(self.project_path, self.serena_config, save_to_disk=False)\n\n        assert config.project_name == self.project_path.name\n        assert config.languages == []\n\n    def test_autogenerate_custom_project_name(self):\n        \"\"\"Test autogenerate with custom project name.\"\"\"\n        # Create a TypeScript file\n        ts_file = self.project_path / \"index.ts\"\n        ts_file.write_text(\"const greeting: string = 'Hello';\\n\")\n\n        # Run autogenerate with custom name\n        custom_name = \"my-custom-project\"\n        config = ProjectConfig.autogenerate(self.project_path, self.serena_config, project_name=custom_name, save_to_disk=False)\n\n        assert config.project_name == custom_name\n        assert config.languages == [Language.TYPESCRIPT]\n\n\nclass TestProjectConfig:\n    def test_template_is_complete(self):\n        _, is_complete = ProjectConfig._load_yaml_dict(PROJECT_TEMPLATE_FILE)\n        assert is_complete, \"Project template YAML is incomplete; all fields must be present (with descriptions).\"\n\n\nclass TestProjectConfigLanguageBackend:\n    \"\"\"Tests for the per-project language_backend field.\"\"\"\n\n    def test_language_backend_defaults_to_none(self):\n        config = ProjectConfig(\n            project_name=\"test\",\n            languages=[Language.PYTHON],\n        )\n        assert config.language_backend is None\n\n    def test_language_backend_can_be_set(self):\n        config = ProjectConfig(\n            project_name=\"test\",\n            languages=[Language.PYTHON],\n            language_backend=LanguageBackend.JETBRAINS,\n        )\n        assert config.language_backend == LanguageBackend.JETBRAINS\n\n    def test_language_backend_roundtrips_through_yaml(self):\n        config = ProjectConfig(\n            project_name=\"test\",\n            languages=[Language.PYTHON],\n            language_backend=LanguageBackend.JETBRAINS,\n        )\n        d = config._to_yaml_dict()\n        assert d[\"language_backend\"] == \"JetBrains\"\n\n    def test_language_backend_none_roundtrips_through_yaml(self):\n        config = ProjectConfig(\n            project_name=\"test\",\n            languages=[Language.PYTHON],\n        )\n        d = config._to_yaml_dict()\n        assert d[\"language_backend\"] is None\n\n    def test_language_backend_parsed_from_dict(self):\n        \"\"\"Test that _from_dict parses language_backend correctly.\"\"\"\n        template_path = PROJECT_TEMPLATE_FILE\n        data, _ = ProjectConfig._load_yaml_dict(template_path)\n        data[\"project_name\"] = \"test\"\n        data[\"languages\"] = [\"python\"]\n        data[\"language_backend\"] = \"JetBrains\"\n        config = ProjectConfig._from_dict(data, local_override_keys=[])\n        assert config.language_backend == LanguageBackend.JETBRAINS\n\n    def test_language_backend_none_when_missing_from_dict(self):\n        \"\"\"Test that _from_dict handles missing language_backend gracefully.\"\"\"\n        template_path = PROJECT_TEMPLATE_FILE\n        data, _ = ProjectConfig._load_yaml_dict(template_path)\n        data[\"project_name\"] = \"test\"\n        data[\"languages\"] = [\"python\"]\n        data.pop(\"language_backend\", None)\n        config = ProjectConfig._from_dict(data, local_override_keys=[])\n        assert config.language_backend is None\n\n\ndef _make_config_with_project(\n    project_name: str,\n    language_backend: LanguageBackend | None = None,\n    global_backend: LanguageBackend = LanguageBackend.LSP,\n) -> tuple[SerenaConfig, str]:\n    \"\"\"Create a SerenaConfig with a single registered project and return (config, project_name).\"\"\"\n    config = SerenaConfig(\n        gui_log_window=False,\n        web_dashboard=False,\n        log_level=logging.ERROR,\n        language_backend=global_backend,\n    )\n    project = Project(\n        project_root=str(Path(__file__).parent.parent / \"resources\" / \"repos\" / \"python\" / \"test_repo\"),\n        project_config=ProjectConfig(\n            project_name=project_name,\n            languages=[Language.PYTHON],\n            language_backend=language_backend,\n        ),\n        serena_config=config,\n    )\n    config.projects = [RegisteredProject.from_project_instance(project)]\n    return config, project_name\n\n\nclass TestEffectiveLanguageBackend:\n    \"\"\"Tests for per-project language_backend override logic in SerenaAgent.\"\"\"\n\n    def test_default_backend_is_global(self):\n        \"\"\"When no project override, effective backend matches global config.\"\"\"\n        config, name = _make_config_with_project(\"test_proj\", language_backend=None, global_backend=LanguageBackend.LSP)\n        agent = SerenaAgent(project=name, serena_config=config)\n        try:\n            assert agent.get_language_backend().is_lsp()\n        finally:\n            agent.shutdown(timeout=5)\n\n    def test_project_overrides_global_backend(self):\n        \"\"\"When startup project has language_backend set, it overrides the global.\"\"\"\n        config, name = _make_config_with_project(\n            \"test_jetbrains\", language_backend=LanguageBackend.JETBRAINS, global_backend=LanguageBackend.LSP\n        )\n        agent = SerenaAgent(project=name, serena_config=config)\n        try:\n            assert agent.get_language_backend().is_jetbrains()\n        finally:\n            agent.shutdown(timeout=5)\n\n    def test_no_project_uses_global_backend(self):\n        \"\"\"When no startup project is provided, effective backend is the global one.\"\"\"\n        config = SerenaConfig(\n            gui_log_window=False,\n            web_dashboard=False,\n            log_level=logging.ERROR,\n            language_backend=LanguageBackend.LSP,\n        )\n        agent = SerenaAgent(project=None, serena_config=config)\n        try:\n            assert agent.get_language_backend() == LanguageBackend.LSP\n        finally:\n            agent.shutdown(timeout=5)\n\n    def test_activate_project_rejects_backend_mismatch(self):\n        \"\"\"Post-init activation of a project with mismatched backend raises ValueError.\"\"\"\n        # Start with LSP backend\n        config, name = _make_config_with_project(\"lsp_proj\", language_backend=None, global_backend=LanguageBackend.LSP)\n\n        # Add a second project that requires JetBrains\n        jb_project = Project(\n            project_root=str(Path(__file__).parent.parent / \"resources\" / \"repos\" / \"python\" / \"test_repo\"),\n            project_config=ProjectConfig(\n                project_name=\"jb_proj\",\n                languages=[Language.PYTHON],\n                language_backend=LanguageBackend.JETBRAINS,\n            ),\n            serena_config=config,\n        )\n        config.projects.append(RegisteredProject.from_project_instance(jb_project))\n\n        agent = SerenaAgent(project=name, serena_config=config)\n        try:\n            with pytest.raises(ValueError, match=\"Cannot activate project\"):\n                agent.activate_project_from_path_or_name(\"jb_proj\")\n        finally:\n            agent.shutdown(timeout=5)\n\n    def test_activate_project_allows_matching_backend(self):\n        \"\"\"Post-init activation of a project with matching backend succeeds.\"\"\"\n        config, name = _make_config_with_project(\"lsp_proj\", language_backend=None, global_backend=LanguageBackend.LSP)\n\n        # Add a second project that also uses LSP\n        lsp_project2 = Project(\n            project_root=str(Path(__file__).parent.parent / \"resources\" / \"repos\" / \"python\" / \"test_repo\"),\n            project_config=ProjectConfig(\n                project_name=\"lsp_proj2\",\n                languages=[Language.PYTHON],\n                language_backend=LanguageBackend.LSP,\n            ),\n            serena_config=config,\n        )\n        config.projects.append(RegisteredProject.from_project_instance(lsp_project2))\n\n        agent = SerenaAgent(project=name, serena_config=config)\n        try:\n            # Should not raise\n            agent.activate_project_from_path_or_name(\"lsp_proj2\")\n        finally:\n            agent.shutdown(timeout=5)\n\n    def test_activate_project_allows_none_backend(self):\n        \"\"\"Post-init activation of a project with no backend override succeeds.\"\"\"\n        config, name = _make_config_with_project(\"lsp_proj\", language_backend=None, global_backend=LanguageBackend.LSP)\n\n        # Add a second project with no backend override\n        proj2 = Project(\n            project_root=str(Path(__file__).parent.parent / \"resources\" / \"repos\" / \"python\" / \"test_repo\"),\n            project_config=ProjectConfig(\n                project_name=\"proj2\",\n                languages=[Language.PYTHON],\n                language_backend=None,\n            ),\n            serena_config=config,\n        )\n        config.projects.append(RegisteredProject.from_project_instance(proj2))\n\n        agent = SerenaAgent(project=name, serena_config=config)\n        try:\n            # Should not raise — None means \"inherit session backend\"\n            agent.activate_project_from_path_or_name(\"proj2\")\n        finally:\n            agent.shutdown(timeout=5)\n\n\nclass TestGetConfiguredProjectSerenaFolder:\n    \"\"\"Tests for SerenaConfig.get_configured_project_serena_folder (pure template resolution).\"\"\"\n\n    def test_default_location(self):\n        config = SerenaConfig(\n            gui_log_window=False,\n            web_dashboard=False,\n        )\n        result = config.get_configured_project_serena_folder(\"/home/user/myproject\")\n        assert result == os.path.abspath(\"/home/user/myproject/.serena\")\n\n    def test_custom_location_with_project_folder_name(self):\n        config = SerenaConfig(\n            gui_log_window=False,\n            web_dashboard=False,\n            project_serena_folder_location=\"/projects-metadata/$projectFolderName/.serena\",\n        )\n        result = config.get_configured_project_serena_folder(\"/home/user/myproject\")\n        assert result == os.path.abspath(\"/projects-metadata/myproject/.serena\")\n\n    def test_custom_location_with_project_dir(self):\n        config = SerenaConfig(\n            gui_log_window=False,\n            web_dashboard=False,\n            project_serena_folder_location=\"$projectDir/.custom-serena\",\n        )\n        result = config.get_configured_project_serena_folder(\"/home/user/myproject\")\n        assert result == os.path.abspath(\"/home/user/myproject/.custom-serena\")\n\n    def test_custom_location_with_both_placeholders(self):\n        config = SerenaConfig(\n            gui_log_window=False,\n            web_dashboard=False,\n            project_serena_folder_location=\"/data/$projectFolderName/$projectDir/.serena\",\n        )\n        result = config.get_configured_project_serena_folder(\"/home/user/proj\")\n        assert result == os.path.abspath(\"/data/proj/home/user/proj/.serena\")\n\n    def test_default_field_value(self):\n        config = SerenaConfig(\n            gui_log_window=False,\n            web_dashboard=False,\n        )\n        assert config.project_serena_folder_location == DEFAULT_PROJECT_SERENA_FOLDER_LOCATION\n\n    def test_rejects_unknown_placeholder(self):\n        config = SerenaConfig(\n            gui_log_window=False,\n            web_dashboard=False,\n            project_serena_folder_location=\"$projectDir/$unknownVar/.serena\",\n        )\n        with pytest.raises(SerenaConfigError, match=r\"Unknown placeholder '\\$unknownVar'\"):\n            config.get_configured_project_serena_folder(\"/home/user/myproject\")\n\n    def test_rejects_typo_projectDirs(self):\n        \"\"\"$projectDirs should not be silently treated as $projectDir + 's'.\"\"\"\n        config = SerenaConfig(\n            gui_log_window=False,\n            web_dashboard=False,\n            project_serena_folder_location=\"$projectDirs/.serena\",\n        )\n        with pytest.raises(SerenaConfigError, match=r\"Unknown placeholder '\\$projectDirs'\"):\n            config.get_configured_project_serena_folder(\"/home/user/myproject\")\n\n    def test_rejects_typo_projectfoldername_lowercase(self):\n        config = SerenaConfig(\n            gui_log_window=False,\n            web_dashboard=False,\n            project_serena_folder_location=\"/data/$projectfoldername/.serena\",\n        )\n        with pytest.raises(SerenaConfigError, match=r\"Unknown placeholder '\\$projectfoldername'\"):\n            config.get_configured_project_serena_folder(\"/home/user/myproject\")\n\n    def test_no_placeholders_is_valid(self):\n        config = SerenaConfig(\n            gui_log_window=False,\n            web_dashboard=False,\n            project_serena_folder_location=\"/fixed/path/.serena\",\n        )\n        result = config.get_configured_project_serena_folder(\"/home/user/myproject\")\n        assert result == os.path.abspath(\"/fixed/path/.serena\")\n\n    def test_error_message_lists_supported_placeholders(self):\n        config = SerenaConfig(\n            gui_log_window=False,\n            web_dashboard=False,\n            project_serena_folder_location=\"$bogus/.serena\",\n        )\n        with pytest.raises(SerenaConfigError, match=r\"\\$projectDir.*\\$projectFolderName|\\$projectFolderName.*\\$projectDir\"):\n            config.get_configured_project_serena_folder(\"/home/user/myproject\")\n\n\nclass TestProjectSerenaDataFolder:\n    \"\"\"Tests for SerenaConfig.get_project_serena_folder fallback logic (via Project).\"\"\"\n\n    def setup_method(self):\n        self.test_dir = tempfile.mkdtemp()\n        self.project_path = Path(self.test_dir) / \"myproject\"\n        self.project_path.mkdir()\n        (self.project_path / \"main.py\").write_text(\"print('hello')\\n\")\n\n    def teardown_method(self):\n        shutil.rmtree(self.test_dir)\n\n    def _make_project(self, serena_config: \"SerenaConfig | None\" = None) -> Project:\n        project_config = ProjectConfig(\n            project_name=\"myproject\",\n            languages=[Language.PYTHON],\n        )\n        project = Project(\n            project_root=str(self.project_path),\n            project_config=project_config,\n            serena_config=serena_config,\n        )\n        project._ignore_spec_available.wait()\n        return project\n\n    def test_default_config_creates_in_project_dir(self):\n        config = SerenaConfig(gui_log_window=False, web_dashboard=False)\n        project = self._make_project(config)\n        expected = os.path.abspath(str(self.project_path / SERENA_MANAGED_DIR_NAME))\n        assert project.path_to_serena_data_folder() == expected\n\n    def test_custom_location_creates_outside_project(self):\n        custom_base = Path(self.test_dir) / \"metadata\"\n        custom_base.mkdir()\n        config = SerenaConfig(\n            gui_log_window=False,\n            web_dashboard=False,\n            project_serena_folder_location=str(custom_base) + \"/$projectFolderName/.serena\",\n        )\n        project = self._make_project(config)\n        expected = os.path.abspath(str(custom_base / \"myproject\" / \".serena\"))\n        assert project.path_to_serena_data_folder() == expected\n\n    def test_fallback_to_existing_project_dir(self):\n        \"\"\"If config points to a non-existent path but .serena exists in the project root, use the existing one.\"\"\"\n        existing_serena = self.project_path / SERENA_MANAGED_DIR_NAME\n        existing_serena.mkdir()\n        config = SerenaConfig(\n            gui_log_window=False,\n            web_dashboard=False,\n            project_serena_folder_location=\"/nonexistent/path/$projectFolderName/.serena\",\n        )\n        project = self._make_project(config)\n        assert project.path_to_serena_data_folder() == str(existing_serena)\n\n    def test_configured_path_takes_precedence_when_exists(self):\n        \"\"\"If both config path and project root path exist, use the config path.\"\"\"\n        existing_serena = self.project_path / SERENA_MANAGED_DIR_NAME\n        existing_serena.mkdir()\n\n        custom_base = Path(self.test_dir) / \"metadata\"\n        custom_serena = custom_base / \"myproject\" / \".serena\"\n        custom_serena.mkdir(parents=True)\n\n        config = SerenaConfig(\n            gui_log_window=False,\n            web_dashboard=False,\n            project_serena_folder_location=str(custom_base) + \"/$projectFolderName/.serena\",\n        )\n        project = self._make_project(config)\n        assert project.path_to_serena_data_folder() == str(custom_serena)\n\n\nclass TestMemoriesManagerCustomPath:\n    \"\"\"Tests for MemoriesManager with a custom serena data folder.\"\"\"\n\n    def setup_method(self):\n        self.test_dir = tempfile.mkdtemp()\n        self.data_folder = Path(self.test_dir) / \"custom_serena\"\n\n    def teardown_method(self):\n        shutil.rmtree(self.test_dir)\n\n    def test_memories_subdir_is_created(self):\n        assert not self.data_folder.exists()\n        MemoriesManager(str(self.data_folder))\n        assert (self.data_folder / \"memories\").exists()\n\n    def test_save_and_load_memory(self):\n        manager = MemoriesManager(str(self.data_folder))\n        manager.save_memory(\"test_topic\", \"test content\", is_tool_context=False)\n        content = manager.load_memory(\"test_topic\")\n        assert content == \"test content\"\n\n    def test_list_memories(self):\n        manager = MemoriesManager(str(self.data_folder))\n        manager.save_memory(\"topic_a\", \"content a\", is_tool_context=False)\n        manager.save_memory(\"topic_b\", \"content b\", is_tool_context=False)\n        memories = manager.list_project_memories()\n        assert sorted(memories.get_full_list()) == [\"topic_a\", \"topic_b\"]\n"
  },
  {
    "path": "test/serena/test_cli_project_commands.py",
    "content": "\"\"\"Tests for CLI project commands (create, index).\"\"\"\n\nimport os\nimport shutil\nimport tempfile\nimport time\nfrom pathlib import Path\n\nimport pytest\nfrom click.testing import CliRunner\n\nfrom serena.cli import ProjectCommands, TopLevelCommands, find_project_root\nfrom serena.config.serena_config import ProjectConfig\n\npytestmark = pytest.mark.filterwarnings(\"ignore::UserWarning\")\n\n\n@pytest.fixture\ndef temp_project_dir():\n    \"\"\"Create a temporary directory for testing.\"\"\"\n    tmpdir = tempfile.mkdtemp()\n    try:\n        yield tmpdir\n    finally:\n        # if windows, wait a bit to avoid PermissionError on cleanup\n        if os.name == \"nt\":\n            time.sleep(0.2)\n        shutil.rmtree(tmpdir, ignore_errors=True)\n\n\n@pytest.fixture\ndef temp_project_dir_with_python_file():\n    \"\"\"Create a temporary directory with a Python file for testing.\"\"\"\n    tmpdir = tempfile.mkdtemp()\n    try:\n        # Create a simple Python file so language detection works\n        py_file = os.path.join(tmpdir, \"test.py\")\n        with open(py_file, \"w\") as f:\n            f.write(\"def hello():\\n    pass\\n\")\n        yield tmpdir\n    finally:\n        # if windows, wait a bit to avoid PermissionError on cleanup\n        if os.name == \"nt\":\n            time.sleep(0.2)\n        shutil.rmtree(tmpdir, ignore_errors=True)\n\n\n@pytest.fixture\ndef cli_runner():\n    \"\"\"Create a CliRunner for testing Click commands.\"\"\"\n    return CliRunner()\n\n\nclass TestProjectCreate:\n    \"\"\"Tests for 'project create' command.\"\"\"\n\n    def test_create_basic_with_language(self, cli_runner, temp_project_dir):\n        \"\"\"Test basic project creation with explicit language.\"\"\"\n        result = cli_runner.invoke(ProjectCommands.create, [temp_project_dir, \"--language\", \"python\"])\n        assert result.exit_code == 0, f\"Command failed: {result.output}\"\n        assert \"Generated project\" in result.output\n        assert \"python\" in result.output.lower()\n\n        # Verify project.yml was created\n        yml_path = os.path.join(temp_project_dir, \".serena\", \"project.yml\")\n        assert os.path.exists(yml_path), f\"project.yml not found at {yml_path}\"\n\n    def test_create_auto_detect_language(self, cli_runner, temp_project_dir_with_python_file):\n        \"\"\"Test project creation with auto-detected language.\"\"\"\n        result = cli_runner.invoke(ProjectCommands.create, [temp_project_dir_with_python_file])\n        assert result.exit_code == 0, f\"Command failed: {result.output}\"\n        assert \"Generated project\" in result.output\n        assert \"python\" in result.output.lower()\n\n        # Verify project.yml was created\n        yml_path = os.path.join(temp_project_dir_with_python_file, \".serena\", \"project.yml\")\n        assert os.path.exists(yml_path)\n\n    def test_create_with_name(self, cli_runner, temp_project_dir):\n        \"\"\"Test project creation with custom name and explicit language.\"\"\"\n        result = cli_runner.invoke(ProjectCommands.create, [temp_project_dir, \"--name\", \"my-custom-project\", \"--language\", \"python\"])\n        assert result.exit_code == 0, f\"Command failed: {result.output}\"\n        assert \"Generated project\" in result.output\n\n        # Verify project.yml was created\n        yml_path = os.path.join(temp_project_dir, \".serena\", \"project.yml\")\n        assert os.path.exists(yml_path)\n\n    def test_create_with_language(self, cli_runner, temp_project_dir):\n        \"\"\"Test project creation with specified language.\"\"\"\n        result = cli_runner.invoke(ProjectCommands.create, [temp_project_dir, \"--language\", \"python\"])\n        assert result.exit_code == 0, f\"Command failed: {result.output}\"\n        assert \"Generated project\" in result.output\n        assert \"python\" in result.output.lower()\n\n    def test_create_with_multiple_languages(self, cli_runner, temp_project_dir):\n        \"\"\"Test project creation with multiple languages.\"\"\"\n        result = cli_runner.invoke(\n            ProjectCommands.create,\n            [temp_project_dir, \"--language\", \"python\", \"--language\", \"typescript\"],\n        )\n        assert result.exit_code == 0, f\"Command failed: {result.output}\"\n        assert \"Generated project\" in result.output\n\n    def test_create_with_invalid_language(self, cli_runner, temp_project_dir):\n        \"\"\"Test project creation with invalid language raises error.\"\"\"\n        result = cli_runner.invoke(\n            ProjectCommands.create,\n            [temp_project_dir, \"--language\", \"invalid-lang\"],\n        )\n        assert result.exit_code != 0, \"Should fail with invalid language\"\n        assert \"Unknown language\" in result.output or \"invalid-lang\" in result.output\n\n    def test_create_already_exists(self, cli_runner, temp_project_dir):\n        \"\"\"Test that creating a project twice fails gracefully.\"\"\"\n        # Create once with explicit language\n        result1 = cli_runner.invoke(ProjectCommands.create, [temp_project_dir, \"--language\", \"python\"])\n        assert result1.exit_code == 0\n\n        # Try to create again - should fail gracefully\n        result2 = cli_runner.invoke(ProjectCommands.create, [temp_project_dir, \"--language\", \"python\"])\n        assert result2.exit_code != 0, \"Should fail when project.yml already exists\"\n        assert \"already exists\" in result2.output.lower()\n        assert \"Error:\" in result2.output  # Should be user-friendly error\n\n    def test_create_with_index_flag(self, cli_runner, temp_project_dir_with_python_file):\n        \"\"\"Test project creation with --index flag performs indexing.\"\"\"\n        result = cli_runner.invoke(\n            ProjectCommands.create,\n            [temp_project_dir_with_python_file, \"--language\", \"python\", \"--index\", \"--log-level\", \"ERROR\", \"--timeout\", \"5\"],\n        )\n        assert result.exit_code == 0, f\"Command failed: {result.output}\"\n        assert \"Generated project\" in result.output\n        assert \"Indexing project\" in result.output\n\n        # Verify project.yml was created\n        yml_path = os.path.join(temp_project_dir_with_python_file, \".serena\", \"project.yml\")\n        assert os.path.exists(yml_path)\n\n        # Verify cache directory was created (proof of indexing)\n        cache_dir = os.path.join(temp_project_dir_with_python_file, \".serena\", \"cache\")\n        assert os.path.exists(cache_dir), \"Cache directory should exist after indexing\"\n\n    def test_create_without_index_flag(self, cli_runner, temp_project_dir):\n        \"\"\"Test that project creation without --index does NOT perform indexing.\"\"\"\n        result = cli_runner.invoke(ProjectCommands.create, [temp_project_dir, \"--language\", \"python\"])\n        assert result.exit_code == 0\n        assert \"Generated project\" in result.output\n        assert \"Indexing\" not in result.output\n\n        # Verify cache directory was NOT created\n        cache_dir = os.path.join(temp_project_dir, \".serena\", \"cache\")\n        assert not os.path.exists(cache_dir), \"Cache directory should not exist without --index\"\n\n\nclass TestProjectIndex:\n    \"\"\"Tests for 'project index' command.\"\"\"\n\n    def test_index_auto_creates_project_with_files(self, cli_runner, temp_project_dir_with_python_file):\n        \"\"\"Test that index command auto-creates project.yml if it doesn't exist (with source files).\"\"\"\n        result = cli_runner.invoke(ProjectCommands.index, [temp_project_dir_with_python_file, \"--log-level\", \"ERROR\", \"--timeout\", \"5\"])\n        # Should succeed and perform indexing\n        assert result.exit_code == 0, f\"Command failed: {result.output}\"\n        assert \"Auto-creating\" in result.output or \"Indexing\" in result.output\n\n        # Verify project.yml was auto-created\n        yml_path = os.path.join(temp_project_dir_with_python_file, \".serena\", \"project.yml\")\n        assert os.path.exists(yml_path), \"project.yml should be auto-created\"\n\n    def test_index_with_explicit_language(self, cli_runner, temp_project_dir):\n        \"\"\"Test index with explicit --language for empty directory.\"\"\"\n        result = cli_runner.invoke(\n            ProjectCommands.index,\n            [temp_project_dir, \"--language\", \"python\", \"--log-level\", \"ERROR\", \"--timeout\", \"5\"],\n        )\n        # Should succeed even without source files if language is explicit\n        assert result.exit_code == 0, f\"Command failed: {result.output}\"\n\n        yml_path = os.path.join(temp_project_dir, \".serena\", \"project.yml\")\n        assert os.path.exists(yml_path)\n\n    def test_index_with_language_auto_creates(self, cli_runner, temp_project_dir):\n        \"\"\"Test index with --language option for auto-creation.\"\"\"\n        result = cli_runner.invoke(\n            ProjectCommands.index,\n            [temp_project_dir, \"--language\", \"python\", \"--log-level\", \"ERROR\"],\n        )\n        assert result.exit_code == 0 or \"Indexing\" in result.output\n\n        yml_path = os.path.join(temp_project_dir, \".serena\", \"project.yml\")\n        assert os.path.exists(yml_path)\n\n    def test_index_is_equivalent_to_create_with_index(self, cli_runner, temp_project_dir_with_python_file):\n        \"\"\"Test that 'index' behaves like 'create --index' for new projects.\"\"\"\n        # Use manual temp directory creation with Windows-safe cleanup\n        # to avoid PermissionError on Windows CI when language servers hold file locks\n        dir1 = tempfile.mkdtemp()\n        dir2 = tempfile.mkdtemp()\n\n        try:\n            # Setup both directories with same file\n            for d in [dir1, dir2]:\n                with open(os.path.join(d, \"test.py\"), \"w\") as f:\n                    f.write(\"def hello():\\n    pass\\n\")\n\n            # Run 'create --index' on dir1\n            result1 = cli_runner.invoke(\n                ProjectCommands.create, [dir1, \"--language\", \"python\", \"--index\", \"--log-level\", \"ERROR\", \"--timeout\", \"5\"]\n            )\n\n            # Run 'index' on dir2\n            result2 = cli_runner.invoke(ProjectCommands.index, [dir2, \"--language\", \"python\", \"--log-level\", \"ERROR\", \"--timeout\", \"5\"])\n\n            # Both should succeed\n            assert result1.exit_code == 0, f\"create --index failed: {result1.output}\"\n            assert result2.exit_code == 0, f\"index failed: {result2.output}\"\n\n            # Both should create project.yml\n            assert os.path.exists(os.path.join(dir1, \".serena\", \"project.yml\"))\n            assert os.path.exists(os.path.join(dir2, \".serena\", \"project.yml\"))\n\n            # Both should create cache (proof of indexing)\n            assert os.path.exists(os.path.join(dir1, \".serena\", \"cache\"))\n            assert os.path.exists(os.path.join(dir2, \".serena\", \"cache\"))\n        finally:\n            # Windows-safe cleanup: wait for file handles to be released\n            if os.name == \"nt\":\n                time.sleep(0.2)\n            # Use ignore_errors to handle lingering file locks on Windows\n            shutil.rmtree(dir1, ignore_errors=True)\n            shutil.rmtree(dir2, ignore_errors=True)\n\n\nclass TestProjectCreateHelper:\n    \"\"\"Tests for _create_project helper method.\"\"\"\n\n    def test_create_project_helper_returns_config(self, temp_project_dir):\n        \"\"\"Test that _create_project returns a ProjectConfig with explicit language.\"\"\"\n        config = ProjectCommands._create_project(temp_project_dir, \"test-project\", (\"python\",)).project_config\n        assert isinstance(config, ProjectConfig)\n        assert config.project_name == \"test-project\"\n\n    def test_create_project_helper_with_auto_detect(self, temp_project_dir_with_python_file):\n        \"\"\"Test _create_project with auto-detected language.\"\"\"\n        config = ProjectCommands._create_project(temp_project_dir_with_python_file, \"my-project\", ()).project_config\n        assert isinstance(config, ProjectConfig)\n        assert config.project_name == \"my-project\"\n        assert len(config.languages) >= 1\n\n    def test_create_project_helper_with_languages(self, temp_project_dir):\n        \"\"\"Test _create_project with language specification.\"\"\"\n        config = ProjectCommands._create_project(temp_project_dir, None, (\"python\", \"typescript\")).project_config\n        assert isinstance(config, ProjectConfig)\n        assert len(config.languages) >= 1\n\n    def test_create_project_helper_file_exists_error(self, temp_project_dir):\n        \"\"\"Test _create_project raises error if project.yml exists.\"\"\"\n        # Create project first with explicit language\n        ProjectCommands._create_project(temp_project_dir, None, (\"python\",))\n\n        # Try to create again - should raise FileExistsError\n        with pytest.raises(FileExistsError):\n            ProjectCommands._create_project(temp_project_dir, None, (\"python\",))\n\n\nclass TestFindProjectRoot:\n    \"\"\"Tests for find_project_root helper with virtual chroot boundary.\"\"\"\n\n    def test_finds_serena_from_subdirectory(self, temp_project_dir):\n        \"\"\"Test that .serena/project.yml is found when searching from a subdirectory.\"\"\"\n        serena_dir = os.path.join(temp_project_dir, \".serena\")\n        os.makedirs(serena_dir)\n        Path(os.path.join(serena_dir, \"project.yml\")).touch()\n        subdir = os.path.join(temp_project_dir, \"src\", \"nested\")\n        os.makedirs(subdir)\n\n        original_cwd = os.getcwd()\n        try:\n            os.chdir(subdir)\n            result = find_project_root(root=temp_project_dir)\n            assert result is not None\n            assert os.path.samefile(result, temp_project_dir)\n        finally:\n            os.chdir(original_cwd)\n\n    def test_serena_preferred_over_git(self, temp_project_dir):\n        \"\"\"Test that .serena/project.yml takes priority over .git at the same level.\"\"\"\n        serena_dir = os.path.join(temp_project_dir, \".serena\")\n        os.makedirs(serena_dir)\n        Path(os.path.join(serena_dir, \"project.yml\")).touch()\n        os.makedirs(os.path.join(temp_project_dir, \".git\"))\n\n        original_cwd = os.getcwd()\n        try:\n            os.chdir(temp_project_dir)\n            result = find_project_root(root=temp_project_dir)\n            assert result is not None\n            assert os.path.isdir(os.path.join(result, \".serena\"))\n            assert os.path.samefile(result, temp_project_dir)\n        finally:\n            os.chdir(original_cwd)\n\n    def test_git_used_as_fallback(self, temp_project_dir):\n        \"\"\"Test that .git is found when no .serena exists.\"\"\"\n        os.makedirs(os.path.join(temp_project_dir, \".git\"))\n        subdir = os.path.join(temp_project_dir, \"src\")\n        os.makedirs(subdir)\n\n        original_cwd = os.getcwd()\n        try:\n            os.chdir(subdir)\n            result = find_project_root(root=temp_project_dir)\n            assert result is not None\n            assert os.path.samefile(result, temp_project_dir)\n        finally:\n            os.chdir(original_cwd)\n\n    def test_falls_back_to_none_when_no_markers(self, temp_project_dir):\n        \"\"\"Test falls back to None when no markers exist within boundary.\"\"\"\n        subdir = os.path.join(temp_project_dir, \"src\")\n        os.makedirs(subdir)\n\n        original_cwd = os.getcwd()\n        try:\n            os.chdir(subdir)\n            result = find_project_root(root=temp_project_dir)\n            assert result is None\n        finally:\n            os.chdir(original_cwd)\n\n\nclass TestProjectFromCwdMutualExclusivity:\n    \"\"\"Tests for --project-from-cwd mutual exclusivity.\"\"\"\n\n    def test_project_from_cwd_with_project_flag_fails(self, cli_runner):\n        \"\"\"Test that --project-from-cwd with --project raises error.\"\"\"\n        result = cli_runner.invoke(\n            TopLevelCommands.start_mcp_server,\n            [\"--project-from-cwd\", \"--project\", \"/some/path\"],\n        )\n        assert result.exit_code != 0\n        assert \"cannot be used with\" in result.output\n\n\nif __name__ == \"__main__\":\n    # For manual testing, you can run this file directly:\n    # uv run pytest test/serena/test_cli_project_commands.py -v\n    pytest.main([__file__, \"-v\"])\n"
  },
  {
    "path": "test/serena/test_edit_marker.py",
    "content": "from serena.tools import CreateTextFileTool, ReadFileTool, Tool\n\n\nclass TestEditMarker:\n    def test_tool_can_edit_method(self):\n        \"\"\"Test that Tool.can_edit() method works correctly\"\"\"\n        # Non-editing tool should return False\n        assert issubclass(ReadFileTool, Tool)\n        assert not ReadFileTool.can_edit()\n\n        # Editing tool should return True\n        assert issubclass(CreateTextFileTool, Tool)\n        assert CreateTextFileTool.can_edit()\n"
  },
  {
    "path": "test/serena/test_jetbrains_plugin_client.py",
    "content": "import pytest\n\nfrom serena.constants import REPO_ROOT\nfrom serena.jetbrains.jetbrains_plugin_client import JetBrainsPluginClient\n\n\nclass TestSerenaJetBrainsPluginClient:\n    @pytest.mark.parametrize(\n        \"serena_path, plugin_path\",\n        [\n            (REPO_ROOT, REPO_ROOT),\n            (\"/home/user/project\", \"/home/user/project\"),\n            (\"/home/user/project\", \"//wsl.localhost/Ubuntu-24.04/home/user/project\"),\n            (\"/home/user/project\", \"//wsl$/Ubuntu/home/user/project\"),\n            (\"/home/user/project\", \"//wsl$/Ubuntu/home/user/project\"),\n            (\"/mnt/c/Users/user/projects/my-app\", \"/workspaces/serena/C:/Users/user/projects/my-app\"),\n        ],\n    )\n    def test_path_matching(self, serena_path, plugin_path) -> None:\n        assert JetBrainsPluginClient._paths_match(serena_path, plugin_path)\n"
  },
  {
    "path": "test/serena/test_mcp.py",
    "content": "\"\"\"Tests for the mcp.py module in serena.\"\"\"\n\nimport pytest\nfrom mcp.server.fastmcp.tools.base import Tool as MCPTool\n\nfrom serena.agent import Tool, ToolRegistry\nfrom serena.config.context_mode import SerenaAgentContext\nfrom serena.mcp import SerenaMCPFactory\n\nmake_tool = SerenaMCPFactory.make_mcp_tool\n\n\n# Create a mock agent for tool initialization\nclass MockAgent:\n    def __init__(self):\n        self.project_config = None\n        self.serena_config = None\n\n    @staticmethod\n    def get_context() -> SerenaAgentContext:\n        return SerenaAgentContext.load_default()\n\n\nclass BaseMockTool(Tool):\n    \"\"\"A mock Tool class for testing.\"\"\"\n\n    def __init__(self):\n        super().__init__(MockAgent())  # type: ignore\n\n\nclass BasicTool(BaseMockTool):\n    \"\"\"A mock Tool class for testing.\"\"\"\n\n    def apply(self, name: str, age: int = 0) -> str:\n        \"\"\"This is a test function.\n\n        :param name: The person's name\n        :param age: The person's age\n        :return: A greeting message\n        \"\"\"\n        return f\"Hello {name}, you are {age} years old!\"\n\n    def apply_ex(\n        self,\n        log_call: bool = True,\n        catch_exceptions: bool = True,\n        **kwargs,\n    ) -> str:\n        \"\"\"Mock implementation of apply_ex.\"\"\"\n        return self.apply(**kwargs)\n\n\ndef test_make_tool_basic() -> None:\n    \"\"\"Test that make_tool correctly creates an MCP tool from a Tool object.\"\"\"\n    mock_tool = BasicTool()\n\n    mcp_tool = make_tool(mock_tool)\n\n    # Test that the MCP tool has the correct properties\n    assert isinstance(mcp_tool, MCPTool)\n    assert mcp_tool.name == \"basic\"\n    assert \"This is a test function. Returns A greeting message.\" in mcp_tool.description\n\n    # Test that the parameters were correctly processed\n    parameters = mcp_tool.parameters\n    assert \"properties\" in parameters\n    assert \"name\" in parameters[\"properties\"]\n    assert \"age\" in parameters[\"properties\"]\n    assert parameters[\"properties\"][\"name\"][\"description\"] == \"The person's name.\"\n    assert parameters[\"properties\"][\"age\"][\"description\"] == \"The person's age.\"\n\n\ndef test_make_tool_execution() -> None:\n    \"\"\"Test that the execution function created by make_tool works correctly.\"\"\"\n    mock_tool = BasicTool()\n    mcp_tool = make_tool(mock_tool)\n\n    # Execute the MCP tool function\n    result = mcp_tool.fn(name=\"Alice\", age=30)\n\n    assert result == \"Hello Alice, you are 30 years old!\"\n\n\ndef test_make_tool_no_params() -> None:\n    \"\"\"Test make_tool with a function that has no parameters.\"\"\"\n\n    class NoParamsTool(BaseMockTool):\n        def apply(self) -> str:\n            \"\"\"This is a test function with no parameters.\n\n            :return: A simple result\n            \"\"\"\n            return \"Simple result\"\n\n        def apply_ex(self, *args, **kwargs) -> str:\n            return self.apply()\n\n    tool = NoParamsTool()\n    mcp_tool = make_tool(tool)\n\n    assert mcp_tool.name == \"no_params\"\n    assert \"This is a test function with no parameters. Returns A simple result.\" in mcp_tool.description\n    assert mcp_tool.parameters[\"properties\"] == {}\n\n\ndef test_make_tool_no_return_description() -> None:\n    \"\"\"Test make_tool with a function that has no return description.\"\"\"\n\n    class NoReturnTool(BaseMockTool):\n        def apply(self, param: str) -> str:\n            \"\"\"This is a test function.\n\n            :param param: The parameter\n            \"\"\"\n            return f\"Processed: {param}\"\n\n        def apply_ex(self, *args, **kwargs) -> str:\n            return self.apply(**kwargs)\n\n    tool = NoReturnTool()\n    mcp_tool = make_tool(tool)\n\n    assert mcp_tool.name == \"no_return\"\n    assert mcp_tool.description == \"This is a test function.\"\n    assert mcp_tool.parameters[\"properties\"][\"param\"][\"description\"] == \"The parameter.\"\n\n\ndef test_make_tool_parameter_not_in_docstring() -> None:\n    \"\"\"Test make_tool when a parameter in properties is not in the docstring.\"\"\"\n\n    class MissingParamTool(BaseMockTool):\n        def apply(self, name: str, missing_param: str = \"\") -> str:\n            \"\"\"This is a test function.\n\n            :param name: The person's name\n            \"\"\"\n            return f\"Hello {name}! Missing param: {missing_param}\"\n\n        def apply_ex(self, *args, **kwargs) -> str:\n            return self.apply(**kwargs)\n\n    tool = MissingParamTool()\n    mcp_tool = make_tool(tool)\n\n    assert \"name\" in mcp_tool.parameters[\"properties\"]\n    assert \"missing_param\" in mcp_tool.parameters[\"properties\"]\n    assert mcp_tool.parameters[\"properties\"][\"name\"][\"description\"] == \"The person's name.\"\n    assert \"description\" not in mcp_tool.parameters[\"properties\"][\"missing_param\"]\n\n\ndef test_make_tool_multiline_docstring() -> None:\n    \"\"\"Test make_tool with a complex multi-line docstring.\"\"\"\n\n    class ComplexDocTool(BaseMockTool):\n        def apply(self, project_file_path: str, host: str, port: int) -> str:\n            \"\"\"Create an MCP server.\n\n            This function creates and configures a Model Context Protocol server\n            with the specified settings.\n\n            :param project_file_path: The path to the project file, or None\n            :param host: The host to bind to\n            :param port: The port to bind to\n            :return: A configured FastMCP server instance\n            \"\"\"\n            return f\"Server config: {project_file_path}, {host}:{port}\"\n\n        def apply_ex(self, *args, **kwargs) -> str:\n            return self.apply(**kwargs)\n\n    tool = ComplexDocTool()\n    mcp_tool = make_tool(tool)\n\n    assert \"Create an MCP server\" in mcp_tool.description\n    assert \"Returns A configured FastMCP server instance\" in mcp_tool.description\n    assert mcp_tool.parameters[\"properties\"][\"project_file_path\"][\"description\"] == \"The path to the project file, or None.\"\n    assert mcp_tool.parameters[\"properties\"][\"host\"][\"description\"] == \"The host to bind to.\"\n    assert mcp_tool.parameters[\"properties\"][\"port\"][\"description\"] == \"The port to bind to.\"\n\n\ndef test_make_tool_capitalization_and_periods() -> None:\n    \"\"\"Test that make_tool properly handles capitalization and periods in descriptions.\"\"\"\n\n    class FormatTool(BaseMockTool):\n        def apply(self, param1: str, param2: str, param3: str) -> str:\n            \"\"\"Test function.\n\n            :param param1: lowercase description\n            :param param2: description with period.\n            :param param3: description with Capitalized word.\n            \"\"\"\n            return f\"Formatted: {param1}, {param2}, {param3}\"\n\n        def apply_ex(self, *args, **kwargs) -> str:\n            return self.apply(**kwargs)\n\n    tool = FormatTool()\n    mcp_tool = make_tool(tool)\n\n    assert mcp_tool.parameters[\"properties\"][\"param1\"][\"description\"] == \"Lowercase description.\"\n    assert mcp_tool.parameters[\"properties\"][\"param2\"][\"description\"] == \"Description with period.\"\n    assert mcp_tool.parameters[\"properties\"][\"param3\"][\"description\"] == \"Description with Capitalized word.\"\n\n\ndef test_make_tool_missing_apply() -> None:\n    \"\"\"Test make_tool with a tool that doesn't have an apply method.\"\"\"\n\n    class BadTool(BaseMockTool):\n        pass\n\n    tool = BadTool()\n\n    with pytest.raises(AttributeError):\n        make_tool(tool)\n\n\n@pytest.mark.parametrize(\n    \"docstring, expected_description\",\n    [\n        (\n            \"\"\"This is a test function.\n\n            :param param: The parameter\n            :return: A result\n            \"\"\",\n            \"This is a test function. Returns A result.\",\n        ),\n        (\n            \"\"\"\n            :param param: The parameter\n            :return: A result\n            \"\"\",\n            \"Returns A result.\",\n        ),\n        (\n            \"\"\"\n            :param param: The parameter\n            \"\"\",\n            \"\",\n        ),\n        (\"Description without params.\", \"Description without params.\"),\n    ],\n)\ndef test_make_tool_descriptions(docstring, expected_description) -> None:\n    \"\"\"Test make_tool with various docstring formats.\"\"\"\n\n    class TestTool(BaseMockTool):\n        def apply(self, param: str) -> str:\n            return f\"Result: {param}\"\n\n        def apply_ex(self, *args, **kwargs) -> str:\n            return self.apply(**kwargs)\n\n    # Dynamically set the docstring\n    TestTool.apply.__doc__ = docstring\n\n    tool = TestTool()\n    mcp_tool = make_tool(tool)\n\n    assert mcp_tool.name == \"test\"\n    assert mcp_tool.description == expected_description\n\n\ndef is_test_mock_class(tool_class: type) -> bool:\n    \"\"\"Check if a class is a test mock class.\"\"\"\n    # Check if the class is defined in a test module\n    module_name = tool_class.__module__\n    return (\n        module_name.startswith((\"test.\", \"tests.\"))\n        or \"test_\" in module_name\n        or tool_class.__name__\n        in [\n            \"BaseMockTool\",\n            \"BasicTool\",\n            \"BadTool\",\n            \"NoParamsTool\",\n            \"NoReturnTool\",\n            \"MissingParamTool\",\n            \"ComplexDocTool\",\n            \"FormatTool\",\n            \"NoDescriptionTool\",\n        ]\n    )\n\n\n@pytest.mark.parametrize(\"tool_class\", ToolRegistry().get_all_tool_classes())\ndef test_make_tool_all_tools(tool_class) -> None:\n    \"\"\"Test that make_tool works for all tools in the codebase.\"\"\"\n    # Create an instance of the tool\n    tool_instance = tool_class(MockAgent())\n\n    # Try to create an MCP tool from it\n    mcp_tool = make_tool(tool_instance)\n\n    # Basic validation\n    assert isinstance(mcp_tool, MCPTool)\n    assert mcp_tool.name == tool_class.get_name_from_cls()\n\n    # The description should be a string (either from docstring or default)\n    assert isinstance(mcp_tool.description, str)\n"
  },
  {
    "path": "test/serena/test_serena_agent.py",
    "content": "import json\nimport logging\nimport os\nimport re\nimport time\nfrom collections.abc import Iterator\nfrom contextlib import contextmanager\nfrom typing import Literal\n\nimport pytest\n\nfrom serena.agent import SerenaAgent\nfrom serena.config.serena_config import ProjectConfig, RegisteredProject, SerenaConfig\nfrom serena.project import Project\nfrom serena.tools import SUCCESS_RESULT, FindReferencingSymbolsTool, FindSymbolTool, ReplaceContentTool, ReplaceSymbolBodyTool\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_types import SymbolKind\nfrom test.conftest import get_repo_path, is_ci, language_tests_enabled\nfrom test.solidlsp import clojure as clj\n\n\n@pytest.fixture\ndef serena_config():\n    config = SerenaConfig(gui_log_window=False, web_dashboard=False, log_level=logging.ERROR)\n\n    # Create test projects for all supported languages\n    test_projects = []\n    for language in [\n        Language.PYTHON,\n        Language.GO,\n        Language.JAVA,\n        Language.KOTLIN,\n        Language.RUST,\n        Language.TYPESCRIPT,\n        Language.PHP,\n        Language.CSHARP,\n        Language.CLOJURE,\n        Language.FSHARP,\n        Language.POWERSHELL,\n        Language.CPP_CCLS,\n        Language.LEAN4,\n    ]:\n        repo_path = get_repo_path(language)\n        if repo_path.exists():\n            project_name = f\"test_repo_{language}\"\n            project = Project(\n                project_root=str(repo_path),\n                project_config=ProjectConfig(\n                    project_name=project_name,\n                    languages=[language],\n                    ignored_paths=[],\n                    excluded_tools=[],\n                    read_only=False,\n                    ignore_all_files_in_gitignore=True,\n                    initial_prompt=\"\",\n                    encoding=\"utf-8\",\n                ),\n                serena_config=config,\n            )\n            test_projects.append(RegisteredProject.from_project_instance(project))\n\n    config.projects = test_projects\n    return config\n\n\ndef read_project_file(project: Project, relative_path: str) -> str:\n    \"\"\"Utility function to read a file from the project.\"\"\"\n    file_path = os.path.join(project.project_root, relative_path)\n    with open(file_path, encoding=project.project_config.encoding) as f:\n        return f.read()\n\n\n@contextmanager\ndef project_file_modification_context(serena_agent: SerenaAgent, relative_path: str) -> Iterator[None]:\n    \"\"\"Context manager to modify a project file and revert the changes after use.\"\"\"\n    project = serena_agent.get_active_project()\n    file_path = os.path.join(project.project_root, relative_path)\n\n    # Read the original content\n    original_content = read_project_file(project, relative_path)\n\n    try:\n        yield\n    finally:\n        # Revert to the original content\n        with open(file_path, \"w\", encoding=project.project_config.encoding) as f:\n            f.write(original_content)\n\n\n@pytest.fixture\ndef serena_agent(request: pytest.FixtureRequest, serena_config) -> Iterator[SerenaAgent]:\n    language = Language(request.param)\n    if not language_tests_enabled(language):\n        pytest.skip(f\"Tests for language {language} are not enabled.\")\n\n    project_name = f\"test_repo_{language}\"\n\n    agent = SerenaAgent(project=project_name, serena_config=serena_config)\n\n    # wait for agent to be ready\n    agent.execute_task(lambda: None)\n\n    yield agent\n\n    # explicitly shut down to free resources\n    agent.shutdown(timeout=5)\n\n\nclass TestSerenaAgent:\n    @pytest.mark.parametrize(\"project\", [None, str(get_repo_path(Language.PYTHON)), \"non_existent_path\"])\n    def test_agent_instantiation(self, project: str | None):\n        \"\"\"\n        Tests agent instantiation for cases where\n          * no project is specified at startup\n          * a valid project path is specified at startup\n          * an invalid project path is specified at startup\n        All cases must not raise an exception.\n        \"\"\"\n        serena_config = SerenaConfig(gui_log_window=False, web_dashboard=False)\n        SerenaAgent(project=project, serena_config=serena_config)\n\n    def _assert_find_symbol(self, serena_agent: SerenaAgent, symbol_name: str, expected_kind: str, expected_file: str) -> None:\n        agent = serena_agent\n        find_symbol_tool = agent.get_tool(FindSymbolTool)\n        result = find_symbol_tool.apply(name_path_pattern=symbol_name, include_info=True)\n\n        symbols = json.loads(result)\n        assert any(\n            symbol_name in s[\"name_path\"] and expected_kind.lower() in s[\"kind\"].lower() and expected_file in s[\"relative_path\"]\n            for s in symbols\n        ), f\"Expected to find {symbol_name} ({expected_kind}) in {expected_file}\"\n        # testing retrieval of symbol info\n        if serena_agent.get_active_lsp_languages() == [Language.KOTLIN]:\n            # kotlin LS doesn't seem to provide hover info right now, at least for the struct we test this on\n            return\n        for s in symbols:\n            if s[\"kind\"] in (SymbolKind.File.name, SymbolKind.Module.name):\n                # we ignore file and module symbols for the info test\n                continue\n            symbol_info = s.get(\"info\")\n            assert symbol_info, f\"Expected symbol info to be present for symbol: {s}\"\n            assert (\n                symbol_name in s[\"info\"]\n            ), f\"[{serena_agent.get_active_lsp_languages()[0]}] Expected symbol info to contain symbol name {symbol_name}. Info: {s['info']}\"\n            # special additional test for Java, since Eclipse returns hover in a complex format and we want to make sure to get it right\n            if s[\"kind\"] == SymbolKind.Class.name and serena_agent.get_active_lsp_languages() == [Language.JAVA]:\n                assert \"A simple model class\" in symbol_info, f\"Java class docstring not found in symbol info: {s}\"\n\n    @pytest.mark.php\n    @pytest.mark.parametrize(\"serena_agent\", [Language.PHP], indirect=True)\n    def test_find_symbol_within_php_file(self, serena_agent: SerenaAgent) -> None:\n        \"\"\"Verify find_symbol with a PHP file path routes to the PHP language server.\n\n        This validates the fix in symbol.py (LanguageServerSymbolRetriever.find_symbols):\n        when within_relative_path points to a PHP file, the retriever must use\n        get_language_server() rather than iterating all language servers. Without this\n        fix, non-PHP servers reject the PHP file and no symbols are returned.\n        \"\"\"\n        find_symbol_tool = serena_agent.get_tool(FindSymbolTool)\n        sample_php = \"sample.php\"\n\n        result = find_symbol_tool.apply(name_path_pattern=\"Dog/greet\", relative_path=sample_php)\n        symbols = json.loads(result)\n\n        assert len(symbols) > 0, (\n            f\"Expected to find Dog/greet in {sample_php} but got empty result. \"\n            \"This may indicate that find_symbol is not routing to the PHP language server for PHP files.\"\n        )\n        assert any(\n            \"greet\" in s[\"name_path\"] and sample_php in s[\"relative_path\"] for s in symbols\n        ), f\"Dog/greet not found in {sample_php}. Symbols: {symbols}\"\n\n    @pytest.mark.parametrize(\n        \"serena_agent,symbol_name,expected_kind,expected_file\",\n        [\n            pytest.param(Language.PYTHON, \"User\", \"Class\", \"models.py\", marks=pytest.mark.python),\n            pytest.param(Language.GO, \"Helper\", \"Function\", \"main.go\", marks=pytest.mark.go),\n            pytest.param(Language.JAVA, \"Model\", \"Class\", \"Model.java\", marks=pytest.mark.java),\n            pytest.param(\n                Language.KOTLIN,\n                \"Model\",\n                \"Struct\",\n                \"Model.kt\",\n                marks=[pytest.mark.kotlin] + ([pytest.mark.skip(reason=\"Kotlin LSP JVM crashes on restart in CI\")] if is_ci else []),\n            ),\n            pytest.param(Language.TYPESCRIPT, \"DemoClass\", \"Class\", \"index.ts\", marks=pytest.mark.typescript),\n            pytest.param(Language.PHP, \"helperFunction\", \"Function\", \"helper.php\", marks=pytest.mark.php),\n            pytest.param(Language.CLOJURE, \"greet\", \"Function\", clj.CORE_PATH, marks=pytest.mark.clojure),\n            pytest.param(Language.CSHARP, \"Calculator\", \"Class\", \"Program.cs\", marks=pytest.mark.csharp),\n            pytest.param(Language.POWERSHELL, \"function Greet-User ()\", \"Function\", \"main.ps1\", marks=pytest.mark.powershell),\n            pytest.param(Language.CPP_CCLS, \"add\", \"Function\", \"b.cpp\", marks=pytest.mark.cpp),\n            pytest.param(Language.LEAN4, \"add\", \"Method\", \"Helper.lean\", marks=pytest.mark.lean4),\n        ],\n        indirect=[\"serena_agent\"],\n    )\n    def test_find_symbol_stable(self, serena_agent: SerenaAgent, symbol_name: str, expected_kind: str, expected_file: str) -> None:\n        self._assert_find_symbol(serena_agent, symbol_name, expected_kind, expected_file)\n\n    @pytest.mark.parametrize(\n        \"serena_agent,symbol_name,expected_kind,expected_file\",\n        [\n            pytest.param(Language.FSHARP, \"Calculator\", \"Module\", \"Calculator.fs\", marks=pytest.mark.fsharp),\n        ],\n        indirect=[\"serena_agent\"],\n    )\n    @pytest.mark.xfail(reason=\"F# language server is unreliable\")  # See issue #1040\n    def test_find_symbol_fsharp(self, serena_agent: SerenaAgent, symbol_name: str, expected_kind: str, expected_file: str) -> None:\n        self._assert_find_symbol(serena_agent, symbol_name, expected_kind, expected_file)\n\n    @pytest.mark.parametrize(\n        \"serena_agent,symbol_name,expected_kind,expected_file\",\n        [\n            pytest.param(Language.RUST, \"add\", \"Function\", \"lib.rs\", marks=pytest.mark.rust),\n        ],\n        indirect=[\"serena_agent\"],\n    )\n    @pytest.mark.xfail(reason=\"Rust language server is unreliable\")  # See issue #1040\n    def test_find_symbol_rust(self, serena_agent: SerenaAgent, symbol_name: str, expected_kind: str, expected_file: str) -> None:\n        self._assert_find_symbol(serena_agent, symbol_name, expected_kind, expected_file)\n\n    def _assert_find_symbol_references(self, serena_agent: SerenaAgent, symbol_name: str, def_file: str, ref_file: str) -> None:\n        agent = serena_agent\n\n        # Find the symbol location first\n        find_symbol_tool = agent.get_tool(FindSymbolTool)\n        result = find_symbol_tool.apply(name_path_pattern=symbol_name, relative_path=def_file)\n\n        time.sleep(1)\n        symbols = json.loads(result)\n        # Find the definition\n        def_symbol = symbols[0]\n\n        # Now find references\n        find_refs_tool = agent.get_tool(FindReferencingSymbolsTool)\n        result = find_refs_tool.apply(name_path=def_symbol[\"name_path\"], relative_path=def_symbol[\"relative_path\"])\n\n        def contains_ref_with_relative_path(refs, relative_path):\n            \"\"\"\n            Checks for reference to relative path, regardless of output format (grouped an ungrouped)\n            \"\"\"\n            if isinstance(refs, list):\n                for ref in refs:\n                    if contains_ref_with_relative_path(ref, relative_path):\n                        return True\n            elif isinstance(refs, dict):\n                if relative_path in refs:\n                    return True\n                for value in refs.values():\n                    if contains_ref_with_relative_path(value, relative_path):\n                        return True\n            return False\n\n        refs = json.loads(result)\n        assert contains_ref_with_relative_path(refs, ref_file), f\"Expected to find reference to {symbol_name} in {ref_file}. refs={refs}\"\n\n    @pytest.mark.parametrize(\n        \"serena_agent,symbol_name,def_file,ref_file\",\n        [\n            pytest.param(\n                Language.PYTHON,\n                \"User\",\n                os.path.join(\"test_repo\", \"models.py\"),\n                os.path.join(\"test_repo\", \"services.py\"),\n                marks=pytest.mark.python,\n            ),\n            pytest.param(Language.GO, \"Helper\", \"main.go\", \"main.go\", marks=pytest.mark.go),\n            pytest.param(\n                Language.JAVA,\n                \"Model\",\n                os.path.join(\"src\", \"main\", \"java\", \"test_repo\", \"Model.java\"),\n                os.path.join(\"src\", \"main\", \"java\", \"test_repo\", \"Main.java\"),\n                marks=pytest.mark.java,\n            ),\n            pytest.param(\n                Language.KOTLIN,\n                \"Model\",\n                os.path.join(\"src\", \"main\", \"kotlin\", \"test_repo\", \"Model.kt\"),\n                os.path.join(\"src\", \"main\", \"kotlin\", \"test_repo\", \"Main.kt\"),\n                marks=[pytest.mark.kotlin] + ([pytest.mark.skip(reason=\"Kotlin LSP JVM crashes on restart in CI\")] if is_ci else []),\n            ),\n            pytest.param(Language.RUST, \"add\", os.path.join(\"src\", \"lib.rs\"), os.path.join(\"src\", \"main.rs\"), marks=pytest.mark.rust),\n            pytest.param(Language.PHP, \"helperFunction\", \"helper.php\", \"index.php\", marks=pytest.mark.php),\n            pytest.param(\n                Language.CLOJURE,\n                \"multiply\",\n                clj.CORE_PATH,\n                clj.UTILS_PATH,\n                marks=pytest.mark.clojure,\n            ),\n            pytest.param(Language.CSHARP, \"Calculator\", \"Program.cs\", \"Program.cs\", marks=pytest.mark.csharp),\n            pytest.param(Language.POWERSHELL, \"function Greet-User ()\", \"main.ps1\", \"main.ps1\", marks=pytest.mark.powershell),\n            pytest.param(Language.CPP_CCLS, \"add\", \"b.cpp\", \"a.cpp\", marks=pytest.mark.cpp),\n            pytest.param(Language.LEAN4, \"add\", \"Helper.lean\", \"Main.lean\", marks=pytest.mark.lean4),\n        ],\n        indirect=[\"serena_agent\"],\n    )\n    def test_find_symbol_references_stable(self, serena_agent: SerenaAgent, symbol_name: str, def_file: str, ref_file: str) -> None:\n        self._assert_find_symbol_references(serena_agent, symbol_name, def_file, ref_file)\n\n    @pytest.mark.parametrize(\n        \"serena_agent,symbol_name,def_file,ref_file\",\n        [\n            pytest.param(Language.TYPESCRIPT, \"helperFunction\", \"index.ts\", \"use_helper.ts\", marks=pytest.mark.typescript),\n        ],\n        indirect=[\"serena_agent\"],\n    )\n    @pytest.mark.xfail(False, reason=\"TypeScript language server is unreliable\")  # NOTE: Testing; may be resolved by #1120; See issue #1040\n    def test_find_symbol_references_typescript(self, serena_agent: SerenaAgent, symbol_name: str, def_file: str, ref_file: str) -> None:\n        self._assert_find_symbol_references(serena_agent, symbol_name, def_file, ref_file)\n\n    @pytest.mark.parametrize(\n        \"serena_agent,symbol_name,def_file,ref_file\",\n        [\n            pytest.param(Language.FSHARP, \"add\", \"Calculator.fs\", \"Program.fs\", marks=pytest.mark.fsharp),\n        ],\n        indirect=[\"serena_agent\"],\n    )\n    @pytest.mark.xfail(reason=\"F# language server is unreliable\")  # See issue #1040\n    def test_find_symbol_references_fsharp(self, serena_agent: SerenaAgent, symbol_name: str, def_file: str, ref_file: str) -> None:\n        self._assert_find_symbol_references(serena_agent, symbol_name, def_file, ref_file)\n\n    @pytest.mark.parametrize(\n        \"serena_agent,name_path,substring_matching,expected_symbol_name,expected_kind,expected_file\",\n        [\n            pytest.param(\n                Language.PYTHON,\n                \"OuterClass/NestedClass\",\n                False,\n                \"NestedClass\",\n                \"Class\",\n                os.path.join(\"test_repo\", \"nested.py\"),\n                id=\"exact_qualname_class\",\n                marks=pytest.mark.python,\n            ),\n            pytest.param(\n                Language.PYTHON,\n                \"OuterClass/NestedClass/find_me\",\n                False,\n                \"find_me\",\n                \"Method\",\n                os.path.join(\"test_repo\", \"nested.py\"),\n                id=\"exact_qualname_method\",\n                marks=pytest.mark.python,\n            ),\n            pytest.param(\n                Language.PYTHON,\n                \"OuterClass/NestedCl\",  # Substring for NestedClass\n                True,\n                \"NestedClass\",\n                \"Class\",\n                os.path.join(\"test_repo\", \"nested.py\"),\n                id=\"substring_qualname_class\",\n                marks=pytest.mark.python,\n            ),\n            pytest.param(\n                Language.PYTHON,\n                \"OuterClass/NestedClass/find_m\",  # Substring for find_me\n                True,\n                \"find_me\",\n                \"Method\",\n                os.path.join(\"test_repo\", \"nested.py\"),\n                id=\"substring_qualname_method\",\n                marks=pytest.mark.python,\n            ),\n            pytest.param(\n                Language.PYTHON,\n                \"/OuterClass\",  # Absolute path\n                False,\n                \"OuterClass\",\n                \"Class\",\n                os.path.join(\"test_repo\", \"nested.py\"),\n                id=\"absolute_qualname_class\",\n                marks=pytest.mark.python,\n            ),\n            pytest.param(\n                Language.PYTHON,\n                \"/OuterClass/NestedClass/find_m\",  # Absolute path with substring\n                True,\n                \"find_me\",\n                \"Method\",\n                os.path.join(\"test_repo\", \"nested.py\"),\n                id=\"absolute_substring_qualname_method\",\n                marks=pytest.mark.python,\n            ),\n        ],\n        indirect=[\"serena_agent\"],\n    )\n    def test_find_symbol_name_path(\n        self,\n        serena_agent,\n        name_path: str,\n        substring_matching: bool,\n        expected_symbol_name: str,\n        expected_kind: str,\n        expected_file: str,\n    ):\n        agent = serena_agent\n\n        find_symbol_tool = agent.get_tool(FindSymbolTool)\n        result = find_symbol_tool.apply_ex(\n            name_path_pattern=name_path,\n            depth=0,\n            relative_path=None,\n            include_body=False,\n            include_kinds=None,\n            exclude_kinds=None,\n            substring_matching=substring_matching,\n        )\n\n        symbols = json.loads(result)\n        assert any(\n            expected_symbol_name == s[\"name_path\"].split(\"/\")[-1]\n            and expected_kind.lower() in s[\"kind\"].lower()\n            and expected_file in s[\"relative_path\"]\n            for s in symbols\n        ), f\"Expected to find {name_path} ({expected_kind}) in {expected_file}. Symbols: {symbols}\"\n\n    @pytest.mark.parametrize(\n        \"serena_agent,name_path\",\n        [\n            pytest.param(\n                Language.PYTHON,\n                \"/NestedClass\",  # Absolute path, NestedClass is not top-level\n                id=\"absolute_path_non_top_level_no_match\",\n                marks=pytest.mark.python,\n            ),\n            pytest.param(\n                Language.PYTHON,\n                \"/NoSuchParent/NestedClass\",  # Absolute path with non-existent parent\n                id=\"absolute_path_non_existent_parent_no_match\",\n                marks=pytest.mark.python,\n            ),\n        ],\n        indirect=[\"serena_agent\"],\n    )\n    def test_find_symbol_name_path_no_match(\n        self,\n        serena_agent,\n        name_path: str,\n    ):\n        agent = serena_agent\n\n        find_symbol_tool = agent.get_tool(FindSymbolTool)\n        result = find_symbol_tool.apply_ex(\n            name_path_pattern=name_path,\n            depth=0,\n            substring_matching=True,\n        )\n\n        symbols = json.loads(result)\n        assert not symbols, f\"Expected to find no symbols for {name_path}. Symbols found: {symbols}\"\n\n    @pytest.mark.parametrize(\n        \"serena_agent,name_path,num_expected\",\n        [\n            pytest.param(\n                Language.JAVA,\n                \"Model/getName\",\n                2,\n                id=\"overloaded_java_method\",\n                marks=pytest.mark.java,\n            ),\n        ],\n        indirect=[\"serena_agent\"],\n    )\n    def test_find_symbol_overloaded_function(self, serena_agent: SerenaAgent, name_path: str, num_expected: int):\n        \"\"\"\n        Tests whether the FindSymbolTool can find all overloads of a function/method\n        (provided that the overload id remains unspecified in the name path)\n        \"\"\"\n        agent = serena_agent\n\n        find_symbol_tool = agent.get_tool(FindSymbolTool)\n        result = find_symbol_tool.apply_ex(\n            name_path_pattern=name_path,\n            depth=0,\n            substring_matching=False,\n        )\n\n        symbols = json.loads(result)\n        assert (\n            len(symbols) == num_expected\n        ), f\"Expected to find {num_expected} symbols for overloaded function {name_path}. Symbols found: {symbols}\"\n\n    @pytest.mark.parametrize(\n        \"serena_agent,name_path,relative_path\",\n        [\n            pytest.param(\n                Language.JAVA,\n                \"Model/getName\",\n                os.path.join(\"src\", \"main\", \"java\", \"test_repo\", \"Model.java\"),\n                id=\"overloaded_java_method\",\n                marks=pytest.mark.java,\n            ),\n        ],\n        indirect=[\"serena_agent\"],\n    )\n    def test_non_unique_symbol_reference_error(self, serena_agent: SerenaAgent, name_path: str, relative_path: str):\n        \"\"\"\n        Tests whether the tools operating on a well-defined symbol raises an error when the symbol reference is non-unique.\n        We exemplarily test a retrieval tool (FindReferencingSymbolsTool) and an editing tool (ReplaceSymbolBodyTool).\n        \"\"\"\n        match_text = \"multiple\"\n\n        find_refs_tool = serena_agent.get_tool(FindReferencingSymbolsTool)\n        with pytest.raises(ValueError, match=match_text):\n            find_refs_tool.apply(name_path=name_path, relative_path=relative_path)\n\n        replace_symbol_body_tool = serena_agent.get_tool(ReplaceSymbolBodyTool)\n        with pytest.raises(ValueError, match=match_text):\n            replace_symbol_body_tool.apply(name_path=name_path, relative_path=relative_path, body=\"\")\n\n    @pytest.mark.parametrize(\n        \"serena_agent\",\n        [\n            pytest.param(\n                Language.TYPESCRIPT,\n                marks=pytest.mark.typescript,\n            ),\n        ],\n        indirect=[\"serena_agent\"],\n    )\n    def test_replace_content_regex_with_wildcard_ok(self, serena_agent: SerenaAgent):\n        \"\"\"\n        Tests a regex-based content replacement that has a unique match\n        \"\"\"\n        relative_path = \"ws_manager.js\"\n        with project_file_modification_context(serena_agent, relative_path):\n            replace_content_tool = serena_agent.get_tool(ReplaceContentTool)\n            result = replace_content_tool.apply(\n                needle=r'catch \\(error\\) \\{\\s*console.error\\(\"Failed to connect.*?\\}',\n                repl='catch(error) { console.log(\"Never mind\"); }',\n                relative_path=relative_path,\n                mode=\"regex\",\n            )\n            assert result == SUCCESS_RESULT\n\n    @pytest.mark.parametrize(\n        \"serena_agent\",\n        [\n            pytest.param(\n                Language.TYPESCRIPT,\n                marks=pytest.mark.typescript,\n            ),\n        ],\n        indirect=[\"serena_agent\"],\n    )\n    @pytest.mark.parametrize(\"mode\", [\"literal\", \"regex\"])\n    def test_replace_content_with_backslashes(self, serena_agent: SerenaAgent, mode: Literal[\"literal\", \"regex\"]):\n        \"\"\"\n        Tests a content replacement where the needle and replacement strings contain backslashes.\n        This is a regression test for escaping issues.\n        \"\"\"\n        relative_path = \"ws_manager.js\"\n        needle = r'console.log(\"WebSocketManager initializing\\nStatus OK\");'\n        repl = r'console.log(\"WebSocketManager initialized\\nAll systems go!\");'\n        replace_content_tool = serena_agent.get_tool(ReplaceContentTool)\n        with project_file_modification_context(serena_agent, relative_path):\n            result = replace_content_tool.apply(\n                needle=re.escape(needle) if mode == \"regex\" else needle,\n                repl=repl,\n                relative_path=relative_path,\n                mode=mode,\n            )\n            assert result == SUCCESS_RESULT\n            new_content = read_project_file(serena_agent.get_active_project(), relative_path)\n            assert repl in new_content\n\n    @pytest.mark.parametrize(\n        \"serena_agent\",\n        [\n            pytest.param(\n                Language.TYPESCRIPT,\n                marks=pytest.mark.typescript,\n            ),\n        ],\n        indirect=[\"serena_agent\"],\n    )\n    def test_replace_content_regex_with_wildcard_ambiguous(self, serena_agent: SerenaAgent):\n        \"\"\"\n        Tests that an ambiguous replacement where there is a larger match that internally contains\n        a smaller match triggers an exception\n        \"\"\"\n        replace_content_tool = serena_agent.get_tool(ReplaceContentTool)\n        with pytest.raises(ValueError, match=\"ambiguous\"):\n            replace_content_tool.apply(\n                needle=r'catch \\(error\\) \\{.*?this\\.updateConnectionStatus\\(\"Connection failed\", false\\);.*?\\}',\n                repl='catch(error) { console.log(\"Never mind\"); }',\n                relative_path=\"ws_manager.js\",\n                mode=\"regex\",\n            )\n"
  },
  {
    "path": "test/serena/test_set_modes.py",
    "content": "\"\"\"Tests for SerenaAgent.set_modes() to verify that mode switching works correctly.\"\"\"\n\nimport logging\n\nfrom serena.agent import SerenaAgent\nfrom serena.config.serena_config import ModeSelectionDefinition, SerenaConfig\n\n\nclass TestSetModes:\n    \"\"\"Test that set_modes correctly changes active modes.\"\"\"\n\n    def _create_agent(self, modes: ModeSelectionDefinition | None = None) -> SerenaAgent:\n        config = SerenaConfig(gui_log_window=False, web_dashboard=False, log_level=logging.ERROR)\n        return SerenaAgent(serena_config=config, modes=modes)\n\n    def test_set_modes_changes_active_modes(self) -> None:\n        \"\"\"Test that calling set_modes actually changes the active modes.\"\"\"\n        agent = self._create_agent(modes=ModeSelectionDefinition(default_modes=[\"editing\", \"interactive\"]))\n\n        initial_mode_names = sorted(m.name for m in agent.get_active_modes())\n        assert \"editing\" in initial_mode_names\n        assert \"interactive\" in initial_mode_names\n\n        # Switch to planning mode\n        agent.set_modes([\"planning\", \"interactive\"])\n\n        new_mode_names = sorted(m.name for m in agent.get_active_modes())\n        assert \"planning\" in new_mode_names\n        assert \"interactive\" in new_mode_names\n        assert \"editing\" not in new_mode_names\n\n    def test_set_modes_overrides_config_defaults(self) -> None:\n        \"\"\"Test that set_modes takes precedence over config defaults.\"\"\"\n        config = SerenaConfig(gui_log_window=False, web_dashboard=False, log_level=logging.ERROR)\n        config.default_modes = [\"editing\", \"interactive\"]\n        agent = SerenaAgent(serena_config=config)\n\n        # Verify config defaults are active\n        initial_mode_names = [m.name for m in agent.get_active_modes()]\n        assert \"editing\" in initial_mode_names\n\n        # Switch modes — should override config defaults\n        agent.set_modes([\"planning\", \"one-shot\"])\n\n        new_mode_names = [m.name for m in agent.get_active_modes()]\n        assert \"planning\" in new_mode_names\n        assert \"one-shot\" in new_mode_names\n        assert \"editing\" not in new_mode_names\n\n    def test_set_modes_persists_after_repeated_calls(self) -> None:\n        \"\"\"Test that set_modes result persists (modes don't revert).\"\"\"\n        agent = self._create_agent(modes=ModeSelectionDefinition(default_modes=[\"editing\"]))\n\n        agent.set_modes([\"planning\"])\n        mode_names_1 = [m.name for m in agent.get_active_modes()]\n        assert \"planning\" in mode_names_1\n\n        # Call get_active_modes again — should still be planning\n        mode_names_2 = [m.name for m in agent.get_active_modes()]\n        assert mode_names_1 == mode_names_2\n\n    def test_set_modes_can_switch_back(self) -> None:\n        \"\"\"Test that modes can be switched back to original after switching away.\"\"\"\n        agent = self._create_agent(modes=ModeSelectionDefinition(default_modes=[\"editing\", \"interactive\"]))\n\n        # Switch away\n        agent.set_modes([\"planning\", \"one-shot\"])\n        assert \"planning\" in [m.name for m in agent.get_active_modes()]\n\n        # Switch back\n        agent.set_modes([\"editing\", \"interactive\"])\n        mode_names = [m.name for m in agent.get_active_modes()]\n        assert \"editing\" in mode_names\n        assert \"interactive\" in mode_names\n        assert \"planning\" not in mode_names\n"
  },
  {
    "path": "test/serena/test_symbol.py",
    "content": "from unittest.mock import MagicMock\n\nimport pytest\n\nfrom serena.jetbrains.jetbrains_types import SymbolDTO, SymbolDTOKey\nfrom serena.project import Project\nfrom serena.symbol import LanguageServerSymbol, LanguageServerSymbolRetriever, NamePathComponent, NamePathMatcher\nfrom solidlsp.ls_config import Language\n\n\nclass TestSymbolNameMatching:\n    def _create_assertion_error_message(\n        self,\n        name_path_pattern: str,\n        name_path_components: list[NamePathComponent],\n        is_substring_match: bool,\n        expected_result: bool,\n        actual_result: bool,\n    ) -> str:\n        \"\"\"Helper to create a detailed error message for assertions.\"\"\"\n        qnp_repr = \"/\".join(map(str, name_path_components))\n\n        return (\n            f\"Pattern '{name_path_pattern}' (substring: {is_substring_match}) vs \"\n            f\"Name path components {name_path_components} (as '{qnp_repr}'). \"\n            f\"Expected: {expected_result}, Got: {actual_result}\"\n        )\n\n    @pytest.mark.parametrize(\n        \"name_path_pattern, symbol_name_path_parts, is_substring_match, expected\",\n        [\n            # Exact matches, anywhere in the name (is_substring_match=False)\n            pytest.param(\"foo\", [\"foo\"], False, True, id=\"'foo' matches 'foo' exactly (simple)\"),\n            pytest.param(\"foo/\", [\"foo\"], False, True, id=\"'foo/' matches 'foo' exactly (simple)\"),\n            pytest.param(\"foo\", [\"bar\", \"foo\"], False, True, id=\"'foo' matches ['bar', 'foo'] exactly (simple, last element)\"),\n            pytest.param(\"foo\", [\"foobar\"], False, False, id=\"'foo' does not match 'foobar' exactly (simple)\"),\n            pytest.param(\n                \"foo\", [\"bar\", \"foobar\"], False, False, id=\"'foo' does not match ['bar', 'foobar'] exactly (simple, last element)\"\n            ),\n            pytest.param(\n                \"foo\", [\"path\", \"to\", \"foo\"], False, True, id=\"'foo' matches ['path', 'to', 'foo'] exactly (simple, last element)\"\n            ),\n            # Exact matches, absolute patterns (is_substring_match=False)\n            pytest.param(\"/foo\", [\"foo\"], False, True, id=\"'/foo' matches ['foo'] exactly (absolute simple)\"),\n            pytest.param(\"/foo\", [\"foo\", \"bar\"], False, False, id=\"'/foo' does not match ['foo', 'bar'] (absolute simple, len mismatch)\"),\n            pytest.param(\"/foo\", [\"bar\"], False, False, id=\"'/foo' does not match ['bar'] (absolute simple, name mismatch)\"),\n            pytest.param(\n                \"/foo\", [\"bar\", \"foo\"], False, False, id=\"'/foo' does not match ['bar', 'foo'] (absolute simple, position mismatch)\"\n            ),\n            # Substring matches, anywhere in the name (is_substring_match=True)\n            pytest.param(\"foo\", [\"foobar\"], True, True, id=\"'foo' matches 'foobar' as substring (simple)\"),\n            pytest.param(\"foo\", [\"bar\", \"foobar\"], True, True, id=\"'foo' matches ['bar', 'foobar'] as substring (simple, last element)\"),\n            pytest.param(\n                \"foo\", [\"barfoo\"], True, True, id=\"'foo' matches 'barfoo' as substring (simple)\"\n            ),  # This was potentially ambiguous before\n            pytest.param(\"foo\", [\"baz\"], True, False, id=\"'foo' does not match 'baz' as substring (simple)\"),\n            pytest.param(\"foo\", [\"bar\", \"baz\"], True, False, id=\"'foo' does not match ['bar', 'baz'] as substring (simple, last element)\"),\n            pytest.param(\"foo\", [\"my_foobar_func\"], True, True, id=\"'foo' matches 'my_foobar_func' as substring (simple)\"),\n            pytest.param(\n                \"foo\",\n                [\"ClassA\", \"my_foobar_method\"],\n                True,\n                True,\n                id=\"'foo' matches ['ClassA', 'my_foobar_method'] as substring (simple, last element)\",\n            ),\n            pytest.param(\"foo\", [\"my_bar_func\"], True, False, id=\"'foo' does not match 'my_bar_func' as substring (simple)\"),\n            # Substring matches, absolute patterns (is_substring_match=True)\n            pytest.param(\"/foo\", [\"foobar\"], True, True, id=\"'/foo' matches ['foobar'] as substring (absolute simple)\"),\n            pytest.param(\"/foo/\", [\"foobar\"], True, True, id=\"'/foo/' matches ['foobar'] as substring (absolute simple, last element)\"),\n            pytest.param(\"/foo\", [\"barfoobaz\"], True, True, id=\"'/foo' matches ['barfoobaz'] as substring (absolute simple)\"),\n            pytest.param(\n                \"/foo\", [\"foo\", \"bar\"], True, False, id=\"'/foo' does not match ['foo', 'bar'] as substring (absolute simple, len mismatch)\"\n            ),\n            pytest.param(\"/foo\", [\"bar\"], True, False, id=\"'/foo' does not match ['bar'] (absolute simple, no substr)\"),\n            pytest.param(\n                \"/foo\", [\"bar\", \"foo\"], True, False, id=\"'/foo' does not match ['bar', 'foo'] (absolute simple, position mismatch)\"\n            ),\n            pytest.param(\n                \"/foo/\", [\"bar\", \"foo\"], True, False, id=\"'/foo/' does not match ['bar', 'foo'] (absolute simple, position mismatch)\"\n            ),\n        ],\n    )\n    def test_match_simple_name(self, name_path_pattern, symbol_name_path_parts, is_substring_match, expected):\n        \"\"\"Tests matching for simple names (no '/' in pattern).\"\"\"\n        symbol_name_path_components = [NamePathComponent(part) for part in symbol_name_path_parts]\n        result = NamePathMatcher(name_path_pattern, is_substring_match).matches_reversed_components(reversed(symbol_name_path_components))\n        error_msg = self._create_assertion_error_message(name_path_pattern, symbol_name_path_parts, is_substring_match, expected, result)\n        assert result == expected, error_msg\n\n    @pytest.mark.parametrize(\n        \"name_path_pattern, symbol_name_path_parts, is_substring_match, expected\",\n        [\n            # --- Relative patterns (suffix matching) ---\n            # Exact matches, relative patterns (is_substring_match=False)\n            pytest.param(\"bar/foo\", [\"bar\", \"foo\"], False, True, id=\"R: 'bar/foo' matches ['bar', 'foo'] exactly\"),\n            pytest.param(\"bar/foo\", [\"mod\", \"bar\", \"foo\"], False, True, id=\"R: 'bar/foo' matches ['mod', 'bar', 'foo'] exactly (suffix)\"),\n            pytest.param(\n                \"bar/foo\", [\"bar\", \"foo\", \"baz\"], False, False, id=\"R: 'bar/foo' does not match ['bar', 'foo', 'baz'] (pattern shorter)\"\n            ),\n            pytest.param(\"bar/foo\", [\"bar\"], False, False, id=\"R: 'bar/foo' does not match ['bar'] (pattern longer)\"),\n            pytest.param(\"bar/foo\", [\"baz\", \"foo\"], False, False, id=\"R: 'bar/foo' does not match ['baz', 'foo'] (first part mismatch)\"),\n            pytest.param(\"bar/foo\", [\"bar\", \"baz\"], False, False, id=\"R: 'bar/foo' does not match ['bar', 'baz'] (last part mismatch)\"),\n            pytest.param(\"bar/foo\", [\"foo\"], False, False, id=\"R: 'bar/foo' does not match ['foo'] (pattern longer)\"),\n            pytest.param(\n                \"bar/foo\", [\"other\", \"foo\"], False, False, id=\"R: 'bar/foo' does not match ['other', 'foo'] (first part mismatch)\"\n            ),\n            pytest.param(\n                \"bar/foo\", [\"bar\", \"otherfoo\"], False, False, id=\"R: 'bar/foo' does not match ['bar', 'otherfoo'] (last part mismatch)\"\n            ),\n            # Substring matches, relative patterns (is_substring_match=True)\n            pytest.param(\"bar/foo\", [\"bar\", \"foobar\"], True, True, id=\"R: 'bar/foo' matches ['bar', 'foobar'] as substring\"),\n            pytest.param(\n                \"bar/foo\", [\"mod\", \"bar\", \"foobar\"], True, True, id=\"R: 'bar/foo' matches ['mod', 'bar', 'foobar'] as substring (suffix)\"\n            ),\n            pytest.param(\"bar/foo\", [\"bar\", \"bazfoo\"], True, True, id=\"R: 'bar/foo' matches ['bar', 'bazfoo'] as substring\"),\n            pytest.param(\"bar/fo\", [\"bar\", \"foo\"], True, True, id=\"R: 'bar/fo' matches ['bar', 'foo'] as substring\"),  # codespell:ignore\n            pytest.param(\"bar/foo\", [\"bar\", \"baz\"], True, False, id=\"R: 'bar/foo' does not match ['bar', 'baz'] (last no substr)\"),\n            pytest.param(\n                \"bar/foo\", [\"baz\", \"foobar\"], True, False, id=\"R: 'bar/foo' does not match ['baz', 'foobar'] (first part mismatch)\"\n            ),\n            pytest.param(\n                \"bar/foo\", [\"bar\", \"my_foobar_method\"], True, True, id=\"R: 'bar/foo' matches ['bar', 'my_foobar_method'] as substring\"\n            ),\n            pytest.param(\n                \"bar/foo\",\n                [\"mod\", \"bar\", \"my_foobar_method\"],\n                True,\n                True,\n                id=\"R: 'bar/foo' matches ['mod', 'bar', 'my_foobar_method'] as substring (suffix)\",\n            ),\n            pytest.param(\n                \"bar/foo\",\n                [\"bar\", \"another_method\"],\n                True,\n                False,\n                id=\"R: 'bar/foo' does not match ['bar', 'another_method'] (last no substr)\",\n            ),\n            pytest.param(\n                \"bar/foo\",\n                [\"other\", \"my_foobar_method\"],\n                True,\n                False,\n                id=\"R: 'bar/foo' does not match ['other', 'my_foobar_method'] (first part mismatch)\",\n            ),\n            pytest.param(\"bar/f\", [\"bar\", \"foo\"], True, True, id=\"R: 'bar/f' matches ['bar', 'foo'] as substring\"),\n            # Exact matches, absolute patterns (is_substring_match=False)\n            pytest.param(\"/bar/foo\", [\"bar\", \"foo\"], False, True, id=\"A: '/bar/foo' matches ['bar', 'foo'] exactly\"),\n            pytest.param(\n                \"/bar/foo\", [\"bar\", \"foo\", \"baz\"], False, False, id=\"A: '/bar/foo' does not match ['bar', 'foo', 'baz'] (pattern shorter)\"\n            ),\n            pytest.param(\"/bar/foo\", [\"bar\"], False, False, id=\"A: '/bar/foo' does not match ['bar'] (pattern longer)\"),\n            pytest.param(\"/bar/foo\", [\"baz\", \"foo\"], False, False, id=\"A: '/bar/foo' does not match ['baz', 'foo'] (first part mismatch)\"),\n            pytest.param(\n                \"/bar/foo\",\n                [\"baz\", \"bar\", \"foo\"],\n                False,\n                False,\n                id=\"A: '/bar/foo' does not match ['baz', 'bar', 'foo'] (only suffix match for abs pattern)\",\n            ),\n            pytest.param(\"/bar/foo\", [\"bar\", \"baz\"], False, False, id=\"A: '/bar/foo' does not match ['bar', 'baz'] (last part mismatch)\"),\n            # Substring matches (is_substring_match=True)\n            pytest.param(\"/bar/foo\", [\"bar\", \"foobar\"], True, True, id=\"A: '/bar/foo' matches ['bar', 'foobar'] as substring\"),\n            pytest.param(\"/bar/foo\", [\"bar\", \"bazfoo\"], True, True, id=\"A: '/bar/foo' matches ['bar', 'bazfoo'] as substring\"),\n            pytest.param(\"/bar/fo\", [\"bar\", \"foo\"], True, True, id=\"A: '/bar/fo' matches ['bar', 'foo'] as substring\"),  # codespell:ignore\n            pytest.param(\"/bar/foo\", [\"bar\", \"baz\"], True, False, id=\"A: '/bar/foo' does not match ['bar', 'baz'] (last no substr)\"),\n            pytest.param(\n                \"/bar/foo\", [\"baz\", \"foobar\"], True, False, id=\"A: '/bar/foo' does not match ['baz', 'foobar'] (first part mismatch)\"\n            ),\n        ],\n    )\n    def test_match_name_path_pattern_path_len_2(self, name_path_pattern, symbol_name_path_parts, is_substring_match, expected):\n        \"\"\"Tests matching for qualified names (e.g. 'module/class/func').\"\"\"\n        symbol_name_path_components = [NamePathComponent(part) for part in symbol_name_path_parts]\n        result = NamePathMatcher(name_path_pattern, is_substring_match).matches_reversed_components(reversed(symbol_name_path_components))\n        error_msg = self._create_assertion_error_message(name_path_pattern, symbol_name_path_parts, is_substring_match, expected, result)\n        assert result == expected, error_msg\n\n    @pytest.mark.parametrize(\n        \"name_path_pattern, symbol_name_path_components, expected\",\n        [\n            pytest.param(\n                \"bar/foo\",\n                [NamePathComponent(\"bar\"), NamePathComponent(\"foo\", 0)],\n                True,\n                id=\"R: 'bar/foo' matches ['bar', 'foo'] with overload_index=0\",\n            ),\n            pytest.param(\n                \"bar/foo\",\n                [NamePathComponent(\"bar\"), NamePathComponent(\"foo\", 1)],\n                True,\n                id=\"R: 'bar/foo' matches ['bar', 'foo'] with overload_index=1\",\n            ),\n            pytest.param(\n                \"bar/foo[0]\",\n                [NamePathComponent(\"bar\"), NamePathComponent(\"foo\", 0)],\n                True,\n                id=\"R: 'bar/foo[0]' matches ['bar', 'foo'] with overload_index=0\",\n            ),\n            pytest.param(\n                \"bar/foo[1]\",\n                [NamePathComponent(\"bar\"), NamePathComponent(\"foo\", 0)],\n                False,\n                id=\"R: 'bar/foo[1]' does not match ['bar', 'foo'] with overload_index=0\",\n            ),\n            pytest.param(\n                \"bar/foo\", [NamePathComponent(\"bar\", 0), NamePathComponent(\"foo\")], True, id=\"R: 'bar/foo' matches ['bar[0]', 'foo']\"\n            ),\n            pytest.param(\n                \"bar/foo\", [NamePathComponent(\"bar\", 0), NamePathComponent(\"foo\", 1)], True, id=\"R: 'bar/foo' matches ['bar[0]', 'foo[1]']\"\n            ),\n            pytest.param(\n                \"bar[0]/foo\", [NamePathComponent(\"bar\", 0), NamePathComponent(\"foo\")], True, id=\"R: 'bar[0]/foo' matches ['bar[0]', 'foo']\"\n            ),\n            pytest.param(\n                \"bar[0]/foo[1]\",\n                [NamePathComponent(\"bar\", 0), NamePathComponent(\"foo\", 1)],\n                True,\n                id=\"R: 'bar[0]/foo[1]' matches ['bar[0]', 'foo[1]']\",\n            ),\n            pytest.param(\n                \"bar[0]/foo[1]\",\n                [NamePathComponent(\"bar\", 1), NamePathComponent(\"foo\", 0)],\n                False,\n                id=\"R: 'bar[0]/foo[1]' does not match ['bar[1]', 'foo[0]']\",\n            ),\n        ],\n    )\n    def test_match_name_path_pattern_with_overload_idx(self, name_path_pattern, symbol_name_path_components, expected):\n        \"\"\"Tests matching for qualified names (e.g. 'module/class/func').\"\"\"\n        matcher = NamePathMatcher(name_path_pattern, False)\n        result = matcher.matches_reversed_components(reversed(symbol_name_path_components))\n        error_msg = self._create_assertion_error_message(name_path_pattern, symbol_name_path_components, False, expected, result)\n        assert result == expected, error_msg\n\n\n@pytest.mark.python\nclass TestLanguageServerSymbolRetriever:\n    @pytest.mark.parametrize(\"project_with_ls\", [Language.PYTHON], indirect=True)\n    def test_request_info(self, project_with_ls: Project):\n        symbol_retriever = LanguageServerSymbolRetriever(project_with_ls)\n        create_user_method_symbol = symbol_retriever.find(\"UserService/create_user\", within_relative_path=\"test_repo/services.py\")[0]\n        create_user_method_symbol_info = symbol_retriever.request_info_for_symbol(create_user_method_symbol)\n        assert \"Create a new user and store it\" in create_user_method_symbol_info\n\n\nclass TestSymbolDictTypes:\n    @staticmethod\n    def check_key_type(dict_type: type, key_type: type):\n        \"\"\"\n        :param dict_type: a TypedDict type\n        :param key_type: the corresponding key type (Literal[...]) that the dict should have for keys\n        \"\"\"\n        dict_type_keys = dict_type.__annotations__.keys()\n        assert len(dict_type_keys) == len(\n            key_type.__args__  # type: ignore\n        ), f\"Expected {len(key_type.__args__)} keys in {dict_type}, but got {len(dict_type_keys)}\"  # type: ignore\n        for expected_key in key_type.__args__:  # type: ignore\n            assert expected_key in dict_type_keys, f\"Expected key '{expected_key}' not found in {dict_type}\"\n\n    def test_ls_symbol_dict_type(self):\n        self.check_key_type(LanguageServerSymbol.OutputDict, LanguageServerSymbol.OutputDictKey)\n\n    def test_jb_symbol_dict_type(self):\n        self.check_key_type(SymbolDTO, SymbolDTOKey)\n\n\ndef _make_mock_symbols(count: int, *, relative_path: str = \"test_repo/services.py\") -> list[MagicMock]:\n    symbols: list[MagicMock] = []\n    for i in range(count):\n        sym = MagicMock()\n        sym.relative_path = relative_path\n        sym.line = i + 1\n        sym.column = 0\n        sym.symbol_root = {}\n        symbols.append(sym)\n    return symbols\n\n\n@pytest.mark.python\nclass TestHoverBudget:\n    \"\"\"Tests for symbol_info_budget time budget behavior.\"\"\"\n\n    @pytest.mark.parametrize(\"project_with_ls\", [Language.PYTHON], indirect=True)\n    def test_budget_not_exceeded_all_lookups_performed(self, project_with_ls: Project, monkeypatch: pytest.MonkeyPatch):\n        \"\"\"With a large budget, all hover lookups are performed.\"\"\"\n        # Create symbol retriever with a mock agent that has large budget\n        project_with_ls.serena_config.symbol_info_budget = 10.0\n        project_with_ls.project_config.symbol_info_budget = 10.0\n\n        symbol_retriever = LanguageServerSymbolRetriever(project_with_ls)\n\n        # Track _request_info calls\n        call_count = 0\n\n        def counting_request_info(file_path, line, column, **kwargs):\n            nonlocal call_count\n            call_count += 1\n            return f\"info:{line}:{column}\"\n\n        monkeypatch.setattr(symbol_retriever, \"_request_info\", counting_request_info)\n\n        # Create mock symbols with unique (line, col) pairs\n        symbols = _make_mock_symbols(3)\n\n        result = symbol_retriever.request_info_for_symbol_batch(symbols)\n\n        # All 3 symbols should have info (no budget exceeded)\n        assert call_count == 3\n        assert all(info is not None for info in result.values())\n        assert len(result) == 3\n\n    @pytest.mark.parametrize(\"project_with_ls\", [Language.PYTHON], indirect=True)\n    def test_budget_exceeded_partial_info(self, project_with_ls: Project, monkeypatch: pytest.MonkeyPatch):\n        \"\"\"With a small budget, hover lookups stop and remaining symbols get None info.\"\"\"\n        project_with_ls.serena_config.symbol_info_budget = 0.1\n        project_with_ls.project_config.symbol_info_budget = 0.1\n\n        symbol_retriever = LanguageServerSymbolRetriever(project_with_ls)\n\n        # Track _request_info calls and simulate 0.05s per call\n        call_count = 0\n        simulated_time = [0.0]\n\n        def slow_request_info(file_path, line, column, **kwargs):\n            nonlocal call_count\n            call_count += 1\n            # Simulate each hover taking 0.05s\n            simulated_time[0] += 0.05\n            return f\"info:{line}:{column}\"\n\n        # Mock perf_counter to return simulated time for hover duration\n        def mock_perf_counter():\n            return simulated_time[0]\n\n        monkeypatch.setattr(symbol_retriever, \"_request_info\", slow_request_info)\n        monkeypatch.setattr(\"serena.symbol.perf_counter\", mock_perf_counter)\n\n        # Create 5 mock symbols with unique (line, col) pairs\n        symbols = _make_mock_symbols(5)\n\n        result = symbol_retriever.request_info_for_symbol_batch(symbols)\n\n        # Budget is 0.1s, each call takes 0.05s, so only 2 calls should succeed\n        # After 2 calls: 0.1s >= 0.1s budget, remaining 3 should be skipped\n        assert call_count == 2\n        assert len(result) == 5\n\n        # First 2 symbols should have info, last 3 should be None\n        result_list = list(result.values())\n        assert result_list[0] is not None\n        assert result_list[1] is not None\n        assert result_list[2] is None\n        assert result_list[3] is None\n        assert result_list[4] is None\n\n    @pytest.mark.parametrize(\"project_with_ls\", [Language.PYTHON], indirect=True)\n    def test_budget_zero_means_unlimited(self, project_with_ls: Project, monkeypatch: pytest.MonkeyPatch):\n        \"\"\"With budget=0, all hover lookups proceed (no early stopping).\"\"\"\n        project_with_ls.serena_config.symbol_info_budget = 0.0\n        project_with_ls.project_config.symbol_info_budget = 0.0\n\n        symbol_retriever = LanguageServerSymbolRetriever(project_with_ls)\n\n        # Track _request_info calls\n        call_count = 0\n\n        def counting_request_info(file_path, line, column, **kwargs):\n            nonlocal call_count\n            call_count += 1\n            return f\"info:{line}:{column}\"\n\n        monkeypatch.setattr(symbol_retriever, \"_request_info\", counting_request_info)\n\n        # Create mock symbols\n        symbols = _make_mock_symbols(5)\n\n        result = symbol_retriever.request_info_for_symbol_batch(symbols)\n\n        # All 5 symbols should be looked up (no budget limit)\n        assert call_count == 5\n        assert all(info is not None for info in result.values())\n\n    @pytest.mark.parametrize(\"project_with_ls\", [Language.PYTHON], indirect=True)\n    def test_project_budget_overrides_global(self, project_with_ls: Project, monkeypatch: pytest.MonkeyPatch):\n        \"\"\"Project-level budget overrides global budget.\"\"\"\n        # Create symbol retriever with global budget 10.0 but project budget 0.05\n        project_with_ls.project_config.symbol_info_budget = 0.05\n        project_with_ls.serena_config.symbol_info_budget = 10.0\n\n        symbol_retriever = LanguageServerSymbolRetriever(project_with_ls)\n\n        # Track _request_info calls and simulate time\n        call_count = 0\n        simulated_time = [0.0]\n\n        def slow_request_info(file_path, line, column, **kwargs):\n            nonlocal call_count\n            call_count += 1\n            simulated_time[0] += 0.03\n            return f\"info:{line}:{column}\"\n\n        def mock_perf_counter():\n            return simulated_time[0]\n\n        monkeypatch.setattr(symbol_retriever, \"_request_info\", slow_request_info)\n        monkeypatch.setattr(\"serena.symbol.perf_counter\", mock_perf_counter)\n\n        # Create 5 mock symbols\n        symbols = _make_mock_symbols(5)\n\n        symbol_retriever.request_info_for_symbol_batch(symbols)\n\n        # Project budget is 0.05s, each call takes 0.03s\n        # Budget check happens BEFORE starting a new call:\n        # - Before call 1: spent=0 < 0.05, proceed, spent becomes 0.03\n        # - Before call 2: spent=0.03 < 0.05, proceed, spent becomes 0.06\n        # - Before call 3: spent=0.06 >= 0.05, skip\n        # So 2 calls succeed (proving project budget 0.05 overrode global 10.0)\n        assert call_count == 2\n\n    @pytest.mark.parametrize(\"project_with_ls\", [Language.PYTHON], indirect=True)\n    def test_project_null_inherits_global(self, project_with_ls: Project, monkeypatch: pytest.MonkeyPatch):\n        \"\"\"When project budget is None, global budget is used.\"\"\"\n        # Create symbol retriever with project budget=None (inherit global)\n        project_with_ls.project_config.symbol_info_budget = None\n        project_with_ls.serena_config.symbol_info_budget = 10.0\n\n        symbol_retriever = LanguageServerSymbolRetriever(project_with_ls)\n\n        # Track _request_info calls\n        call_count = 0\n\n        def counting_request_info(file_path, line, column, **kwargs):\n            nonlocal call_count\n            call_count += 1\n            return f\"info:{line}:{column}\"\n\n        monkeypatch.setattr(symbol_retriever, \"_request_info\", counting_request_info)\n\n        # Create 3 mock symbols\n        symbols = _make_mock_symbols(3)\n\n        result = symbol_retriever.request_info_for_symbol_batch(symbols)\n\n        # Global budget is 10s, all 3 should succeed\n        assert call_count == 3\n        assert all(info is not None for info in result.values())\n"
  },
  {
    "path": "test/serena/test_symbol_editing.py",
    "content": "\"\"\"\nSnapshot tests using the (awesome) syrupy pytest plugin https://github.com/syrupy-project/syrupy.\nRecreate the snapshots with `pytest --snapshot-update`.\n\"\"\"\n\nimport logging\nimport os\nimport shutil\nimport sys\nimport tempfile\nimport time\nfrom abc import ABC, abstractmethod\nfrom collections.abc import Iterator\nfrom contextlib import contextmanager\nfrom dataclasses import dataclass, field\nfrom difflib import SequenceMatcher\nfrom pathlib import Path\nfrom typing import Literal, NamedTuple\n\nimport pytest\nfrom overrides import overrides\nfrom syrupy import SnapshotAssertion\n\nfrom serena.code_editor import CodeEditor, LanguageServerCodeEditor\nfrom solidlsp.ls_config import Language\nfrom src.serena.symbol import LanguageServerSymbolRetriever\nfrom test.conftest import get_repo_path, project_with_ls_context\n\npytestmark = pytest.mark.snapshot\n\nlog = logging.getLogger(__name__)\n\n\nclass LineChange(NamedTuple):\n    \"\"\"Represents a change to a specific line or range of lines.\"\"\"\n\n    operation: Literal[\"insert\", \"delete\", \"replace\"]\n    original_start: int\n    original_end: int\n    modified_start: int\n    modified_end: int\n    original_lines: list[str]\n    modified_lines: list[str]\n\n\n@dataclass\nclass CodeDiff:\n    \"\"\"\n    Represents the difference between original and modified code.\n    Provides object-oriented access to diff information including line numbers.\n    \"\"\"\n\n    relative_path: str\n    original_content: str\n    modified_content: str\n    _line_changes: list[LineChange] = field(init=False)\n\n    def __post_init__(self) -> None:\n        \"\"\"Compute the diff using difflib's SequenceMatcher.\"\"\"\n        original_lines = self.original_content.splitlines(keepends=True)\n        modified_lines = self.modified_content.splitlines(keepends=True)\n\n        matcher = SequenceMatcher(None, original_lines, modified_lines)\n        self._line_changes = []\n\n        for tag, orig_start, orig_end, mod_start, mod_end in matcher.get_opcodes():\n            if tag == \"equal\":\n                continue\n            if tag == \"insert\":\n                self._line_changes.append(\n                    LineChange(\n                        operation=\"insert\",\n                        original_start=orig_start,\n                        original_end=orig_start,\n                        modified_start=mod_start,\n                        modified_end=mod_end,\n                        original_lines=[],\n                        modified_lines=modified_lines[mod_start:mod_end],\n                    )\n                )\n            elif tag == \"delete\":\n                self._line_changes.append(\n                    LineChange(\n                        operation=\"delete\",\n                        original_start=orig_start,\n                        original_end=orig_end,\n                        modified_start=mod_start,\n                        modified_end=mod_start,\n                        original_lines=original_lines[orig_start:orig_end],\n                        modified_lines=[],\n                    )\n                )\n            elif tag == \"replace\":\n                self._line_changes.append(\n                    LineChange(\n                        operation=\"replace\",\n                        original_start=orig_start,\n                        original_end=orig_end,\n                        modified_start=mod_start,\n                        modified_end=mod_end,\n                        original_lines=original_lines[orig_start:orig_end],\n                        modified_lines=modified_lines[mod_start:mod_end],\n                    )\n                )\n\n    @property\n    def line_changes(self) -> list[LineChange]:\n        \"\"\"Get all line changes in the diff.\"\"\"\n        return self._line_changes\n\n    @property\n    def has_changes(self) -> bool:\n        \"\"\"Check if there are any changes.\"\"\"\n        return len(self._line_changes) > 0\n\n    @property\n    def added_lines(self) -> list[tuple[int, str]]:\n        \"\"\"Get all added lines with their line numbers (0-based) in the modified file.\"\"\"\n        result = []\n        for change in self._line_changes:\n            if change.operation in (\"insert\", \"replace\"):\n                for i, line in enumerate(change.modified_lines):\n                    result.append((change.modified_start + i, line))\n        return result\n\n    @property\n    def deleted_lines(self) -> list[tuple[int, str]]:\n        \"\"\"Get all deleted lines with their line numbers (0-based) in the original file.\"\"\"\n        result = []\n        for change in self._line_changes:\n            if change.operation in (\"delete\", \"replace\"):\n                for i, line in enumerate(change.original_lines):\n                    result.append((change.original_start + i, line))\n        return result\n\n    @property\n    def modified_line_numbers(self) -> list[int]:\n        \"\"\"Get all line numbers (0-based) that were modified in the modified file.\"\"\"\n        line_nums: set[int] = set()\n        for change in self._line_changes:\n            if change.operation in (\"insert\", \"replace\"):\n                line_nums.update(range(change.modified_start, change.modified_end))\n        return sorted(line_nums)\n\n    @property\n    def affected_original_line_numbers(self) -> list[int]:\n        \"\"\"Get all line numbers (0-based) that were affected in the original file.\"\"\"\n        line_nums: set[int] = set()\n        for change in self._line_changes:\n            if change.operation in (\"delete\", \"replace\"):\n                line_nums.update(range(change.original_start, change.original_end))\n        return sorted(line_nums)\n\n    def get_unified_diff(self, context_lines: int = 3) -> str:\n        \"\"\"Get the unified diff as a string.\"\"\"\n        import difflib\n\n        original_lines = self.original_content.splitlines(keepends=True)\n        modified_lines = self.modified_content.splitlines(keepends=True)\n\n        diff = difflib.unified_diff(\n            original_lines, modified_lines, fromfile=f\"a/{self.relative_path}\", tofile=f\"b/{self.relative_path}\", n=context_lines\n        )\n        return \"\".join(diff)\n\n    def get_context_diff(self, context_lines: int = 3) -> str:\n        \"\"\"Get the context diff as a string.\"\"\"\n        import difflib\n\n        original_lines = self.original_content.splitlines(keepends=True)\n        modified_lines = self.modified_content.splitlines(keepends=True)\n\n        diff = difflib.context_diff(\n            original_lines, modified_lines, fromfile=f\"a/{self.relative_path}\", tofile=f\"b/{self.relative_path}\", n=context_lines\n        )\n        return \"\".join(diff)\n\n\nclass EditingTest(ABC):\n    def __init__(self, language: Language, rel_path: str):\n        \"\"\"\n        :param language: the language\n        :param rel_path: the relative path of the edited file\n        \"\"\"\n        self.rel_path = rel_path\n        self.language = language\n        self.original_repo_path = get_repo_path(language)\n        self.repo_path: Path | None = None\n\n    @contextmanager\n    def _setup(self) -> Iterator[LanguageServerSymbolRetriever]:\n        \"\"\"Context manager for setup/teardown with a temporary directory, providing the symbol manager.\"\"\"\n        temp_dir = Path(tempfile.mkdtemp())\n        self.repo_path = temp_dir / self.original_repo_path.name\n        try:\n            print(f\"Copying repo from {self.original_repo_path} to {self.repo_path}\")\n            shutil.copytree(self.original_repo_path, self.repo_path)\n            # prevent deadlock on Windows due to file locks caused by antivirus or some other external software\n            # wait for a long time here\n            if os.name == \"nt\":\n                time.sleep(0.1)\n            log.info(f\"Creating language server for {self.language} {self.rel_path}\")\n            with project_with_ls_context(self.language, str(self.repo_path)) as project:\n                yield LanguageServerSymbolRetriever(project)\n        finally:\n            # prevent deadlock on Windows due to lingering file locks\n            if os.name == \"nt\":\n                time.sleep(0.1)\n            log.info(f\"Removing temp directory {temp_dir}\")\n            shutil.rmtree(temp_dir, ignore_errors=True)\n            log.info(f\"Temp directory {temp_dir} removed\")\n\n    def _read_file(self, rel_path: str) -> str:\n        \"\"\"Read the content of a file in the test repository.\"\"\"\n        assert self.repo_path is not None\n        file_path = self.repo_path / rel_path\n        with open(file_path, encoding=\"utf-8\") as f:\n            return f.read()\n\n    def run_test(self, content_after_ground_truth: SnapshotAssertion) -> None:\n        with self._setup() as symbol_retriever:\n            content_before = self._read_file(self.rel_path)\n            code_editor = LanguageServerCodeEditor(symbol_retriever)\n            self._apply_edit(code_editor)\n            content_after = self._read_file(self.rel_path)\n            code_diff = CodeDiff(self.rel_path, original_content=content_before, modified_content=content_after)\n            self._test_diff(code_diff, content_after_ground_truth)\n\n    @abstractmethod\n    def _apply_edit(self, code_editor: CodeEditor) -> None:\n        pass\n\n    def _test_diff(self, code_diff: CodeDiff, snapshot: SnapshotAssertion) -> None:\n        assert code_diff.has_changes, f\"Sanity check failed: No changes detected in {code_diff.relative_path}\"\n        assert code_diff.modified_content == snapshot\n\n\n# Python test file path\nPYTHON_TEST_REL_FILE_PATH = os.path.join(\"test_repo\", \"variables.py\")\n\n# TypeScript test file path\nTYPESCRIPT_TEST_FILE = \"index.ts\"\n\n\nclass DeleteSymbolTest(EditingTest):\n    def __init__(self, language: Language, rel_path: str, deleted_symbol: str):\n        super().__init__(language, rel_path)\n        self.deleted_symbol = deleted_symbol\n        self.rel_path = rel_path\n\n    def _apply_edit(self, code_editor: CodeEditor) -> None:\n        code_editor.delete_symbol(self.deleted_symbol, self.rel_path)\n\n\n@pytest.mark.parametrize(\n    \"test_case\",\n    [\n        pytest.param(\n            DeleteSymbolTest(\n                Language.PYTHON,\n                PYTHON_TEST_REL_FILE_PATH,\n                \"VariableContainer\",\n            ),\n            marks=pytest.mark.python,\n        ),\n        pytest.param(\n            DeleteSymbolTest(\n                Language.TYPESCRIPT,\n                TYPESCRIPT_TEST_FILE,\n                \"DemoClass\",\n            ),\n            marks=pytest.mark.typescript,\n        ),\n    ],\n)\ndef test_delete_symbol(test_case, snapshot: SnapshotAssertion):\n    test_case.run_test(content_after_ground_truth=snapshot)\n\n\nNEW_PYTHON_FUNCTION = \"\"\"def new_inserted_function():\n    print(\"This is a new function inserted before another.\")\"\"\"\n\nNEW_PYTHON_CLASS_WITH_LEADING_NEWLINES = \"\"\"\n\nclass NewInsertedClass:\n    pass\n\"\"\"\n\nNEW_PYTHON_CLASS_WITH_TRAILING_NEWLINES = \"\"\"class NewInsertedClass:\n    pass\n\n\n\"\"\"\n\nNEW_TYPESCRIPT_FUNCTION = \"\"\"function newInsertedFunction(): void {\n    console.log(\"This is a new function inserted before another.\");\n}\"\"\"\n\n\nNEW_PYTHON_VARIABLE = 'new_module_var = \"Inserted after typed_module_var\"'\n\nNEW_TYPESCRIPT_FUNCTION_AFTER = \"\"\"function newFunctionAfterClass(): void {\n    console.log(\"This function is after DemoClass.\");\n}\"\"\"\n\n\nclass InsertInRelToSymbolTest(EditingTest):\n    def __init__(\n        self, language: Language, rel_path: str, symbol_name: str, new_content: str, mode: Literal[\"before\", \"after\"] | None = None\n    ):\n        super().__init__(language, rel_path)\n        self.symbol_name = symbol_name\n        self.new_content = new_content\n        self.mode: Literal[\"before\", \"after\"] | None = mode\n\n    def set_mode(self, mode: Literal[\"before\", \"after\"]):\n        self.mode = mode\n\n    def _apply_edit(self, code_editor: CodeEditor) -> None:\n        assert self.mode is not None\n        if self.mode == \"before\":\n            code_editor.insert_before_symbol(self.symbol_name, self.rel_path, self.new_content)\n        elif self.mode == \"after\":\n            code_editor.insert_after_symbol(self.symbol_name, self.rel_path, self.new_content)\n\n\n@pytest.mark.parametrize(\"mode\", [\"before\", \"after\"])\n@pytest.mark.parametrize(\n    \"test_case\",\n    [\n        pytest.param(\n            InsertInRelToSymbolTest(\n                Language.PYTHON,\n                PYTHON_TEST_REL_FILE_PATH,\n                \"typed_module_var\",\n                NEW_PYTHON_VARIABLE,\n            ),\n            marks=pytest.mark.python,\n        ),\n        pytest.param(\n            InsertInRelToSymbolTest(\n                Language.PYTHON,\n                PYTHON_TEST_REL_FILE_PATH,\n                \"use_module_variables\",\n                NEW_PYTHON_FUNCTION,\n            ),\n            marks=pytest.mark.python,\n        ),\n        pytest.param(\n            InsertInRelToSymbolTest(\n                Language.TYPESCRIPT,\n                TYPESCRIPT_TEST_FILE,\n                \"DemoClass\",\n                NEW_TYPESCRIPT_FUNCTION_AFTER,\n            ),\n            marks=pytest.mark.typescript,\n        ),\n        pytest.param(\n            InsertInRelToSymbolTest(\n                Language.TYPESCRIPT,\n                TYPESCRIPT_TEST_FILE,\n                \"helperFunction\",\n                NEW_TYPESCRIPT_FUNCTION,\n            ),\n            marks=pytest.mark.typescript,\n        ),\n    ],\n)\ndef test_insert_in_rel_to_symbol(test_case: InsertInRelToSymbolTest, mode: Literal[\"before\", \"after\"], snapshot: SnapshotAssertion):\n    test_case.set_mode(mode)\n    test_case.run_test(content_after_ground_truth=snapshot)\n\n\n@pytest.mark.python\ndef test_insert_python_class_before(snapshot: SnapshotAssertion):\n    InsertInRelToSymbolTest(\n        Language.PYTHON,\n        PYTHON_TEST_REL_FILE_PATH,\n        \"VariableDataclass\",\n        NEW_PYTHON_CLASS_WITH_TRAILING_NEWLINES,\n        mode=\"before\",\n    ).run_test(snapshot)\n\n\n@pytest.mark.python\ndef test_insert_python_class_after(snapshot: SnapshotAssertion):\n    InsertInRelToSymbolTest(\n        Language.PYTHON,\n        PYTHON_TEST_REL_FILE_PATH,\n        \"VariableDataclass\",\n        NEW_PYTHON_CLASS_WITH_LEADING_NEWLINES,\n        mode=\"after\",\n    ).run_test(snapshot)\n\n\nPYTHON_REPLACED_BODY = \"\"\"def modify_instance_var(self):\n        # This body has been replaced\n        self.instance_var = \"Replaced!\"\n        self.reassignable_instance_var = 999\n\"\"\"\n\nTYPESCRIPT_REPLACED_BODY = \"\"\"function printValue() {\n        // This body has been replaced\n        console.warn(\"New value: \" + this.value);\n    }\n\"\"\"\n\n\nclass ReplaceBodyTest(EditingTest):\n    def __init__(self, language: Language, rel_path: str, symbol_name: str, new_body: str):\n        super().__init__(language, rel_path)\n        self.symbol_name = symbol_name\n        self.new_body = new_body\n\n    def _apply_edit(self, code_editor: CodeEditor) -> None:\n        code_editor.replace_body(self.symbol_name, self.rel_path, self.new_body)\n\n\n@pytest.mark.parametrize(\n    \"test_case\",\n    [\n        pytest.param(\n            ReplaceBodyTest(\n                Language.PYTHON,\n                PYTHON_TEST_REL_FILE_PATH,\n                \"VariableContainer/modify_instance_var\",\n                PYTHON_REPLACED_BODY,\n            ),\n            marks=pytest.mark.python,\n        ),\n        pytest.param(\n            ReplaceBodyTest(\n                Language.TYPESCRIPT,\n                TYPESCRIPT_TEST_FILE,\n                \"DemoClass/printValue\",\n                TYPESCRIPT_REPLACED_BODY,\n            ),\n            marks=pytest.mark.typescript,\n        ),\n    ],\n)\ndef test_replace_body(test_case: ReplaceBodyTest, snapshot: SnapshotAssertion):\n    # assert \"a\" in snapshot\n    test_case.run_test(content_after_ground_truth=snapshot)\n\n\nNIX_ATTR_REPLACEMENT = \"\"\"c = 3;\"\"\"\n\n\nclass NixAttrReplacementTest(EditingTest):\n    \"\"\"Test for replacing individual attributes in Nix that should NOT result in double semicolons.\"\"\"\n\n    def __init__(self, language: Language, rel_path: str, symbol_name: str, new_body: str):\n        super().__init__(language, rel_path)\n        self.symbol_name = symbol_name\n        self.new_body = new_body\n\n    def _apply_edit(self, code_editor: CodeEditor) -> None:\n        code_editor.replace_body(self.symbol_name, self.rel_path, self.new_body)\n\n\n@pytest.mark.nix\n@pytest.mark.skipif(sys.platform == \"win32\", reason=\"nixd language server doesn't run on Windows\")\ndef test_nix_symbol_replacement_no_double_semicolon(snapshot: SnapshotAssertion):\n    \"\"\"\n    Test that replacing a Nix attribute does not result in double semicolons.\n\n    This test exercises the bug where:\n    - Original: users.users.example = { isSystemUser = true; group = \"example\"; description = \"Example service user\"; };\n    - Replacement: c = 3;\n    - Bug result would be: c = 3;; (double semicolon)\n    - Correct result should be: c = 3; (single semicolon)\n\n    The replacement body includes a semicolon, but the language server's range extension\n    logic should prevent double semicolons.\n    \"\"\"\n    test_case = NixAttrReplacementTest(\n        Language.NIX,\n        \"default.nix\",\n        \"testUser\",  # Simple attrset with multiple key-value pairs\n        NIX_ATTR_REPLACEMENT,\n    )\n    test_case.run_test(content_after_ground_truth=snapshot)\n\n\nclass RenameSymbolTest(EditingTest):\n    def __init__(self, language: Language, rel_path: str, symbol_name: str, new_name: str):\n        super().__init__(language, rel_path)\n        self.symbol_name = symbol_name\n        self.new_name = new_name\n\n    def _apply_edit(self, code_editor: CodeEditor) -> None:\n        code_editor.rename_symbol(self.symbol_name, self.rel_path, self.new_name)\n\n    @overrides\n    def _test_diff(self, code_diff: CodeDiff, snapshot: SnapshotAssertion) -> None:\n        # sanity check (e.g., for newly generated snapshots) that the new name is actually in the modified content\n        assert self.new_name in code_diff.modified_content, f\"New name '{self.new_name}' not found in modified content.\"\n        return super()._test_diff(code_diff, snapshot)\n\n\n@pytest.mark.python\ndef test_rename_symbol(snapshot: SnapshotAssertion):\n    test_case = RenameSymbolTest(\n        Language.PYTHON,\n        PYTHON_TEST_REL_FILE_PATH,\n        \"typed_module_var\",\n        \"renamed_typed_module_var\",\n    )\n    test_case.run_test(content_after_ground_truth=snapshot)\n\n\n# ===== VUE WRITE OPERATIONS TESTS =====\n\nVUE_TEST_FILE = os.path.join(\"src\", \"components\", \"CalculatorButton.vue\")\nVUE_STORE_FILE = os.path.join(\"src\", \"stores\", \"calculator.ts\")\n\nNEW_VUE_HANDLER = \"\"\"const handleDoubleClick = () => {\n    pressCount.value++;\n    emit('click', props.label);\n}\"\"\"\n\n\n@pytest.mark.parametrize(\n    \"test_case\",\n    [\n        pytest.param(\n            DeleteSymbolTest(\n                Language.VUE,\n                VUE_TEST_FILE,\n                \"handleMouseEnter\",\n            ),\n            marks=pytest.mark.vue,\n        ),\n    ],\n)\ndef test_delete_symbol_vue(test_case: DeleteSymbolTest, snapshot: SnapshotAssertion) -> None:\n    test_case.run_test(content_after_ground_truth=snapshot)\n\n\n@pytest.mark.parametrize(\"mode\", [\"before\", \"after\"])\n@pytest.mark.parametrize(\n    \"test_case\",\n    [\n        pytest.param(\n            InsertInRelToSymbolTest(\n                Language.VUE,\n                VUE_TEST_FILE,\n                \"handleClick\",\n                NEW_VUE_HANDLER,\n            ),\n            marks=pytest.mark.vue,\n        ),\n    ],\n)\ndef test_insert_in_rel_to_symbol_vue(\n    test_case: InsertInRelToSymbolTest,\n    mode: Literal[\"before\", \"after\"],\n    snapshot: SnapshotAssertion,\n) -> None:\n    test_case.set_mode(mode)\n    test_case.run_test(content_after_ground_truth=snapshot)\n\n\nVUE_REPLACED_HANDLECLICK_BODY = \"\"\"const handleClick = () => {\n    if (!props.disabled) {\n        pressCount.value = 0;  // Reset instead of incrementing\n        emit('click', props.label);\n    }\n}\"\"\"\n\n\n@pytest.mark.parametrize(\n    \"test_case\",\n    [\n        pytest.param(\n            ReplaceBodyTest(\n                Language.VUE,\n                VUE_TEST_FILE,\n                \"handleClick\",\n                VUE_REPLACED_HANDLECLICK_BODY,\n            ),\n            marks=pytest.mark.vue,\n        ),\n    ],\n)\ndef test_replace_body_vue(test_case: ReplaceBodyTest, snapshot: SnapshotAssertion) -> None:\n    test_case.run_test(content_after_ground_truth=snapshot)\n\n\nVUE_REPLACED_PRESSCOUNT_BODY = \"\"\"const pressCount = ref(100)\"\"\"\n\n\n@pytest.mark.parametrize(\n    \"test_case\",\n    [\n        pytest.param(\n            ReplaceBodyTest(\n                Language.VUE,\n                VUE_TEST_FILE,\n                \"pressCount\",\n                VUE_REPLACED_PRESSCOUNT_BODY,\n            ),\n            marks=pytest.mark.vue,\n        ),\n    ],\n)\ndef test_replace_body_vue_with_disambiguation(test_case: ReplaceBodyTest, snapshot: SnapshotAssertion) -> None:\n    \"\"\"Test symbol disambiguation when replacing body in Vue files.\n\n    This test verifies the fix for the Vue LSP symbol duplication issue.\n    When the LSP returns two symbols with the same name (e.g., pressCount appears both as\n    a definition `const pressCount = ref(0)` and as a shorthand property in `defineExpose({ pressCount })`),\n    the _find_unique_symbol method should prefer the symbol with the larger range (the definition).\n\n    The test exercises this by calling replace_body on 'pressCount', which internally calls\n    _find_unique_symbol and should correctly select the definition (line 40, 19 chars) over\n    the reference (line 97, 10 chars).\n    \"\"\"\n    test_case.run_test(content_after_ground_truth=snapshot)\n\n\nVUE_STORE_REPLACED_CLEAR_BODY = \"\"\"function clear() {\n    // Modified: Reset to initial state with a log\n    console.log('Clearing calculator state');\n    displayValue.value = '0';\n    expression.value = '';\n    operationHistory.value = [];\n    lastResult.value = undefined;\n}\"\"\"\n\n\n@pytest.mark.parametrize(\n    \"test_case\",\n    [\n        pytest.param(\n            ReplaceBodyTest(\n                Language.VUE,\n                VUE_STORE_FILE,\n                \"clear\",\n                VUE_STORE_REPLACED_CLEAR_BODY,\n            ),\n            marks=pytest.mark.vue,\n        ),\n    ],\n)\ndef test_replace_body_vue_ts_file(test_case: ReplaceBodyTest, snapshot: SnapshotAssertion) -> None:\n    \"\"\"Test that TypeScript files within Vue projects can be edited.\"\"\"\n    test_case.run_test(content_after_ground_truth=snapshot)\n"
  },
  {
    "path": "test/serena/test_task_executor.py",
    "content": "import time\n\nimport pytest\n\nfrom serena.task_executor import TaskExecutor\n\n\n@pytest.fixture\ndef executor():\n    \"\"\"\n    Fixture for a basic SerenaAgent without a project\n    \"\"\"\n    return TaskExecutor(\"TestExecutor\")\n\n\nclass Task:\n    def __init__(self, delay: float, exception: bool = False):\n        self.delay = delay\n        self.exception = exception\n        self.did_run = False\n\n    def run(self):\n        self.did_run = True\n        time.sleep(self.delay)\n        if self.exception:\n            raise ValueError(\"Task failed\")\n        return True\n\n\ndef test_task_executor_sequence(executor):\n    \"\"\"\n    Tests that a sequence of tasks is executed correctly\n    \"\"\"\n    future1 = executor.issue_task(Task(1).run, name=\"task1\")\n    future2 = executor.issue_task(Task(1).run, name=\"task2\")\n    assert future1.result() is True\n    assert future2.result() is True\n\n\ndef test_task_executor_exception(executor):\n    \"\"\"\n    Tests that tasks that raise exceptions are handled correctly, i.e. that\n      * the exception is propagated,\n      * subsequent tasks are still executed.\n    \"\"\"\n    future1 = executor.issue_task(Task(1, exception=True).run, name=\"task1\")\n    future2 = executor.issue_task(Task(1).run, name=\"task2\")\n    have_exception = False\n    try:\n        assert future1.result()\n    except Exception as e:\n        assert isinstance(e, ValueError)\n        have_exception = True\n    assert have_exception\n    assert future2.result() is True\n\n\ndef test_task_executor_cancel_current(executor):\n    \"\"\"\n    Tests that tasks that are cancelled are handled correctly, i.e. that\n      * subsequent tasks are executed as soon as cancellation ensues.\n      * the cancelled task raises CancelledError when result() is called.\n    \"\"\"\n    start_time = time.time()\n    future1 = executor.issue_task(Task(10).run, name=\"task1\")\n    future2 = executor.issue_task(Task(1).run, name=\"task2\")\n    time.sleep(1)\n    future1.cancel()\n    assert future2.result() is True\n    end_time = time.time()\n    assert (end_time - start_time) < 9, \"Cancelled task did not stop in time\"\n    have_cancelled_error = False\n    try:\n        future1.result()\n    except Exception as e:\n        assert e.__class__.__name__ == \"CancelledError\"\n        have_cancelled_error = True\n    assert have_cancelled_error\n\n\ndef test_task_executor_cancel_future(executor):\n    \"\"\"\n    Tests that when a future task is cancelled, it is never run at all\n    \"\"\"\n    task1 = Task(10)\n    task2 = Task(1)\n    future1 = executor.issue_task(task1.run, name=\"task1\")\n    future2 = executor.issue_task(task2.run, name=\"task2\")\n    time.sleep(1)\n    future2.cancel()\n    future1.cancel()\n    try:\n        future2.result()\n    except:\n        pass\n    assert task1.did_run\n    assert not task2.did_run\n\n\ndef test_task_executor_cancellation_via_task_info(executor):\n    start_time = time.time()\n    executor.issue_task(Task(10).run, \"task1\")\n    executor.issue_task(Task(10).run, \"task2\")\n    task_infos = executor.get_current_tasks()\n    task_infos2 = executor.get_current_tasks()\n\n    # test expected tasks\n    assert len(task_infos) == 2\n    assert \"task1\" in task_infos[0].name\n    assert \"task2\" in task_infos[1].name\n\n    # test task identifiers being stable\n    assert task_infos2[0].task_id == task_infos[0].task_id\n\n    # test cancellation\n    task_infos[0].cancel()\n    time.sleep(0.5)\n    task_infos3 = executor.get_current_tasks()\n    assert len(task_infos3) == 1  # Cancelled task is gone from the queue\n    task_infos3[0].cancel()\n    try:\n        task_infos3[0].future.result()\n    except:\n        pass\n    end_time = time.time()\n    assert (end_time - start_time) < 9, \"Cancelled task did not stop in time\"\n"
  },
  {
    "path": "test/serena/test_text_utils.py",
    "content": "import re\n\nimport pytest\n\nfrom serena.util.text_utils import LineType, search_files, search_text\n\n\nclass TestSearchText:\n    def test_search_text_with_string_pattern(self):\n        \"\"\"Test searching with a simple string pattern.\"\"\"\n        content = \"\"\"\n        def hello_world():\n            print(\"Hello, World!\")\n            return 42\n        \"\"\"\n\n        # Search for a simple string pattern\n        matches = search_text(\"print\", content=content)\n\n        assert len(matches) == 1\n        assert matches[0].num_matched_lines == 1\n        assert matches[0].start_line == 3\n        assert matches[0].end_line == 3\n        assert matches[0].lines[0].line_content.strip() == 'print(\"Hello, World!\")'\n\n    def test_search_text_with_regex_pattern(self):\n        \"\"\"Test searching with a regex pattern.\"\"\"\n        content = \"\"\"\n        class DataProcessor:\n            def __init__(self, data):\n                self.data = data\n\n            def process(self):\n                return [x * 2 for x in self.data if x > 0]\n\n            def filter(self, predicate):\n                return [x for x in self.data if predicate(x)]\n        \"\"\"\n\n        # Search for a regex pattern matching method definitions\n        pattern = r\"def\\s+\\w+\\s*\\([^)]*\\):\"\n        matches = search_text(pattern, content=content)\n\n        assert len(matches) == 3\n        assert matches[0].lines[0].match_type == LineType.MATCH\n        assert \"def __init__\" in matches[0].lines[0].line_content\n        assert \"def process\" in matches[1].lines[0].line_content\n        assert \"def filter\" in matches[2].lines[0].line_content\n\n    def test_search_text_with_compiled_regex(self):\n        \"\"\"Test searching with a pre-compiled regex pattern.\"\"\"\n        content = \"\"\"\n        import os\n        import sys\n        from pathlib import Path\n\n        # Configuration variables\n        DEBUG = True\n        MAX_RETRIES = 3\n\n        def configure_logging():\n            log_level = \"DEBUG\" if DEBUG else \"INFO\"\n            print(f\"Setting log level to {log_level}\")\n        \"\"\"\n\n        # Search for variable assignments with a compiled regex\n        pattern = re.compile(r\"^\\s*[A-Z_]+ = .+$\")\n        matches = search_text(pattern, content=content)\n\n        assert len(matches) == 2\n        assert \"DEBUG = True\" in matches[0].lines[0].line_content\n        assert \"MAX_RETRIES = 3\" in matches[1].lines[0].line_content\n\n    def test_search_text_with_context_lines(self):\n        \"\"\"Test searching with context lines before and after the match.\"\"\"\n        content = \"\"\"\n        def complex_function(a, b, c):\n            # This is a complex function that does something.\n            if a > b:\n                return a * c\n            elif b > a:\n                return b * c\n            else:\n                return (a + b) * c\n        \"\"\"\n\n        # Search with context lines\n        matches = search_text(\"return\", content=content, context_lines_before=1, context_lines_after=1)\n\n        assert len(matches) == 3\n\n        # Check the first match with context\n        first_match = matches[0]\n        assert len(first_match.lines) == 3\n        assert first_match.lines[0].match_type == LineType.BEFORE_MATCH\n        assert first_match.lines[1].match_type == LineType.MATCH\n        assert first_match.lines[2].match_type == LineType.AFTER_MATCH\n\n        # Verify the content of lines\n        assert \"if a > b:\" in first_match.lines[0].line_content\n        assert \"return a * c\" in first_match.lines[1].line_content\n        assert \"elif b > a:\" in first_match.lines[2].line_content\n\n    def test_search_text_with_multiline_match(self):\n        \"\"\"Test searching with multiline pattern matching.\"\"\"\n        content = \"\"\"\n        def factorial(n):\n            if n <= 1:\n                return 1\n            else:\n                return n * factorial(n-1)\n\n        result = factorial(5)  # Should be 120\n        \"\"\"\n\n        # Search for a pattern that spans multiple lines (if-else block)\n        pattern = r\"if.*?else.*?return\"\n        matches = search_text(pattern, content=content, allow_multiline_match=True)\n\n        assert len(matches) == 1\n        multiline_match = matches[0]\n        assert multiline_match.num_matched_lines >= 3\n        assert \"if n <= 1:\" in multiline_match.lines[0].line_content\n\n        # All matched lines should have match_type == LineType.MATCH\n        match_lines = [line for line in multiline_match.lines if line.match_type == LineType.MATCH]\n        assert len(match_lines) >= 3\n\n    def test_search_text_with_glob_pattern(self):\n        \"\"\"Test searching with glob-like patterns.\"\"\"\n        content = \"\"\"\n        class UserService:\n            def get_user(self, user_id):\n                return {\"id\": user_id, \"name\": \"Test User\"}\n\n            def create_user(self, user_data):\n                print(f\"Creating user: {user_data}\")\n                return {\"id\": 123, **user_data}\n\n            def update_user(self, user_id, user_data):\n                print(f\"Updating user {user_id} with {user_data}\")\n                return True\n        \"\"\"\n\n        # Search with a glob pattern for all user methods\n        matches = search_text(\"*_user*\", content=content, is_glob=True)\n\n        assert len(matches) == 3\n        assert \"get_user\" in matches[0].lines[0].line_content\n        assert \"create_user\" in matches[1].lines[0].line_content\n        assert \"update_user\" in matches[2].lines[0].line_content\n\n    def test_search_text_with_complex_glob_pattern(self):\n        \"\"\"Test searching with more complex glob patterns.\"\"\"\n        content = \"\"\"\n        def process_data(data):\n            return [transform(item) for item in data]\n\n        def transform(item):\n            if isinstance(item, dict):\n                return {k: v.upper() if isinstance(v, str) else v for k, v in item.items()}\n            elif isinstance(item, list):\n                return [x * 2 for x in item if isinstance(x, (int, float))]\n            elif isinstance(item, str):\n                return item.upper()\n            else:\n                return item\n        \"\"\"\n\n        # Search with a simplified glob pattern to find all isinstance occurrences\n        matches = search_text(\"*isinstance*\", content=content, is_glob=True)\n\n        # Should match lines with isinstance(item, dict) and isinstance(item, list)\n        assert len(matches) >= 2\n        instance_matches = [\n            line.line_content\n            for match in matches\n            for line in match.lines\n            if line.match_type == LineType.MATCH and \"isinstance(item,\" in line.line_content\n        ]\n        assert len(instance_matches) >= 2\n        assert any(\"isinstance(item, dict)\" in line for line in instance_matches)\n        assert any(\"isinstance(item, list)\" in line for line in instance_matches)\n\n    def test_search_text_glob_with_special_chars(self):\n        \"\"\"Glob patterns containing regex special characters should match literally.\"\"\"\n        content = \"\"\"\n        def func_square():\n            print(\"value[42]\")\n\n        def func_curly():\n            print(\"value{bar}\")\n        \"\"\"\n\n        matches_square = search_text(r\"*\\[42\\]*\", content=content, is_glob=True)\n        assert len(matches_square) == 1\n        assert \"[42]\" in matches_square[0].lines[0].line_content\n\n        matches_curly = search_text(\"*{bar}*\", content=content, is_glob=True)\n        assert len(matches_curly) == 1\n        assert \"{bar}\" in matches_curly[0].lines[0].line_content\n\n    def test_search_text_no_matches(self):\n        \"\"\"Test searching with a pattern that doesn't match anything.\"\"\"\n        content = \"\"\"\n        def calculate_average(numbers):\n            if not numbers:\n                return 0\n            return sum(numbers) / len(numbers)\n        \"\"\"\n\n        # Search for a pattern that doesn't exist in the content\n        matches = search_text(\"missing_function\", content=content)\n\n        assert len(matches) == 0\n\n\n# Mock file reader that always returns matching content\ndef mock_reader_always_match(file_path: str) -> str:\n    \"\"\"Mock file reader that returns content guaranteed to match the simple pattern.\"\"\"\n    return \"This line contains a match.\"\n\n\nclass TestSearchFiles:\n    @pytest.mark.parametrize(\n        \"file_paths, pattern, paths_include_glob, paths_exclude_glob, expected_matched_files, description\",\n        [\n            # Basic cases\n            ([\"a.py\", \"b.txt\"], \"match\", None, None, [\"a.py\", \"b.txt\"], \"No filters\"),\n            ([\"a.py\", \"b.txt\"], \"match\", \"*.py\", None, [\"a.py\"], \"Include only .py files\"),\n            ([\"a.py\", \"b.txt\"], \"match\", None, \"*.txt\", [\"a.py\"], \"Exclude .txt files\"),\n            ([\"a.py\", \"b.txt\", \"c.py\"], \"match\", \"*.py\", \"c.*\", [\"a.py\"], \"Include .py, exclude c.*\"),\n            # Directory matching - Using pathspec patterns\n            ([\"main.c\", \"test/main.c\"], \"match\", \"test/*\", None, [\"test/main.c\"], \"Include files in test/ subdir\"),\n            ([\"data/a.csv\", \"data/b.log\"], \"match\", \"data/*\", \"*.log\", [\"data/a.csv\"], \"Include data/*, exclude *.log\"),\n            ([\"src/a.py\", \"tests/b.py\"], \"match\", \"src/**\", \"tests/**\", [\"src/a.py\"], \"Include src/**, exclude tests/**\"),\n            ([\"src/mod/a.py\", \"tests/b.py\"], \"match\", \"**/*.py\", \"tests/**\", [\"src/mod/a.py\"], \"Include **/*.py, exclude tests/**\"),\n            ([\"file.py\", \"dir/file.py\"], \"match\", \"dir/*.py\", None, [\"dir/file.py\"], \"Include files directly in dir\"),\n            ([\"file.py\", \"dir/sub/file.py\"], \"match\", \"dir/**/*.py\", None, [\"dir/sub/file.py\"], \"Include files recursively in dir\"),\n            # Overlap and edge cases\n            ([\"file.py\", \"dir/file.py\"], \"match\", \"*.py\", \"dir/*\", [\"file.py\"], \"Include *.py, exclude files directly in dir\"),\n            ([\"root.py\", \"adir/a.py\", \"bdir/b.py\"], \"match\", \"a*/*.py\", None, [\"adir/a.py\"], \"Include files in dirs starting with 'a'\"),\n            ([\"a.txt\", \"b.log\"], \"match\", \"*.py\", None, [], \"No files match include pattern\"),\n            ([\"a.py\", \"b.py\"], \"match\", None, \"*.py\", [], \"All files match exclude pattern\"),\n            ([\"a.py\", \"b.py\"], \"match\", \"a.*\", \"*.py\", [], \"Include a.* but exclude *.py -> empty\"),\n            ([\"a.py\", \"b.py\"], \"match\", \"*.py\", \"b.*\", [\"a.py\"], \"Include *.py but exclude b.* -> a.py\"),\n        ],\n        ids=lambda x: x if isinstance(x, str) else \"\",  # Use description as test ID\n    )\n    def test_search_files_include_exclude(\n        self, file_paths, pattern, paths_include_glob, paths_exclude_glob, expected_matched_files, description\n    ):\n        \"\"\"\n        Test the include/exclude glob filtering logic in search_files using PathSpec patterns.\n        \"\"\"\n        results = search_files(\n            relative_file_paths=file_paths,\n            pattern=pattern,\n            file_reader=mock_reader_always_match,\n            paths_include_glob=paths_include_glob,\n            paths_exclude_glob=paths_exclude_glob,\n            context_lines_before=0,  # No context needed for this test focus\n            context_lines_after=0,\n        )\n\n        # Extract the source file paths from the results\n        actual_matched_files = sorted([result.source_file_path for result in results if result.source_file_path])\n\n        # Assert that the matched files are exactly the ones expected\n        assert actual_matched_files == sorted(expected_matched_files)\n\n        # Basic check on results structure if files were expected\n        if expected_matched_files:\n            assert len(results) == len(expected_matched_files)\n            for result in results:\n                assert len(result.matched_lines) == 1  # Mock reader returns one matching line\n                assert result.matched_lines[0].line_content == \"This line contains a match.\"\n                assert result.matched_lines[0].match_type == LineType.MATCH\n\n    @pytest.mark.parametrize(\n        \"file_paths, pattern, paths_include_glob, paths_exclude_glob, expected_matched_files, description\",\n        [\n            # Glob patterns that were problematic with gitignore syntax\n            (\n                [\"src/serena/agent.py\", \"src/serena/process_isolated_agent.py\", \"test/agent.py\"],\n                \"match\",\n                \"src/**agent.py\",\n                None,\n                [\"src/serena/agent.py\", \"src/serena/process_isolated_agent.py\"],\n                \"Glob: src/**agent.py should match files ending with agent.py under src/\",\n            ),\n            (\n                [\"src/serena/agent.py\", \"src/serena/process_isolated_agent.py\", \"other/agent.py\"],\n                \"match\",\n                \"**agent.py\",\n                None,\n                [\"src/serena/agent.py\", \"src/serena/process_isolated_agent.py\", \"other/agent.py\"],\n                \"Glob: **agent.py should match files ending with agent.py anywhere\",\n            ),\n            (\n                [\"dir/subdir/file.py\", \"dir/other/file.py\", \"elsewhere/file.py\"],\n                \"match\",\n                \"dir/**file.py\",\n                None,\n                [\"dir/subdir/file.py\", \"dir/other/file.py\"],\n                \"Glob: dir/**file.py should match files ending with file.py under dir/\",\n            ),\n            (\n                [\"src/a/b/c/test.py\", \"src/x/test.py\", \"other/test.py\"],\n                \"match\",\n                \"src/**/test.py\",\n                None,\n                [\"src/a/b/c/test.py\", \"src/x/test.py\"],\n                \"Glob: src/**/test.py should match test.py files under src/ at any depth\",\n            ),\n            # Edge cases for ** patterns\n            (\n                [\"agent.py\", \"src/agent.py\", \"src/serena/agent.py\"],\n                \"match\",\n                \"**agent.py\",\n                None,\n                [\"agent.py\", \"src/agent.py\", \"src/serena/agent.py\"],\n                \"Glob: **agent.py should match at root and any depth\",\n            ),\n            ([\"file.txt\", \"src/file.txt\"], \"match\", \"src/**\", None, [\"src/file.txt\"], \"Glob: src/** should match everything under src/\"),\n        ],\n        ids=lambda x: x if isinstance(x, str) else \"\",  # Use description as test ID\n    )\n    def test_search_files_glob_patterns(\n        self, file_paths, pattern, paths_include_glob, paths_exclude_glob, expected_matched_files, description\n    ):\n        \"\"\"\n        Test glob patterns that were problematic with the previous gitignore-based implementation.\n        \"\"\"\n        results = search_files(\n            relative_file_paths=file_paths,\n            pattern=pattern,\n            file_reader=mock_reader_always_match,\n            paths_include_glob=paths_include_glob,\n            paths_exclude_glob=paths_exclude_glob,\n            context_lines_before=0,\n            context_lines_after=0,\n        )\n\n        # Extract the source file paths from the results\n        actual_matched_files = sorted([result.source_file_path for result in results if result.source_file_path])\n\n        # Assert that the matched files are exactly the ones expected\n        assert actual_matched_files == sorted(\n            expected_matched_files\n        ), f\"Pattern '{paths_include_glob}' failed: expected {sorted(expected_matched_files)}, got {actual_matched_files}\"\n\n        # Basic check on results structure if files were expected\n        if expected_matched_files:\n            assert len(results) == len(expected_matched_files)\n            for result in results:\n                assert len(result.matched_lines) == 1  # Mock reader returns one matching line\n                assert result.matched_lines[0].line_content == \"This line contains a match.\"\n                assert result.matched_lines[0].match_type == LineType.MATCH\n\n    @pytest.mark.parametrize(\n        \"file_paths, pattern, paths_include_glob, paths_exclude_glob, expected_matched_files, description\",\n        [\n            # Brace expansion in include glob\n            (\n                [\"a.py\", \"b.js\", \"c.txt\"],\n                \"match\",\n                \"*.{py,js}\",\n                None,\n                [\"a.py\", \"b.js\"],\n                \"Brace expansion in include glob\",\n            ),\n            # Brace expansion in exclude glob\n            (\n                [\"a.py\", \"b.log\", \"c.txt\"],\n                \"match\",\n                \"*.{py,log,txt}\",\n                \"*.{log,txt}\",\n                [\"a.py\"],\n                \"Brace expansion in exclude glob\",\n            ),\n            # Brace expansion in both include and exclude\n            (\n                [\"src/a.ts\", \"src/b.js\", \"test/a.ts\", \"test/b.js\"],\n                \"match\",\n                \"**/*.{ts,js}\",\n                \"test/**/*.{ts,js}\",\n                [\"src/a.ts\", \"src/b.js\"],\n                \"Brace expansion in both include and exclude\",\n            ),\n            # No matching files with brace expansion\n            (\n                [\"a.py\", \"b.js\"],\n                \"match\",\n                \"*.{c,h}\",\n                None,\n                [],\n                \"Brace expansion with no matching files\",\n            ),\n            # Multiple brace expansions\n            (\n                [\"src/a/a.py\", \"src/b/b.py\", \"lib/a/a.py\", \"lib/b/b.py\"],\n                \"match\",\n                \"{src,lib}/{a,b}/*.py\",\n                \"lib/b/*.py\",\n                [\"src/a/a.py\", \"src/b/b.py\", \"lib/a/a.py\"],\n                \"Multiple brace expansions in include/exclude\",\n            ),\n        ],\n        ids=lambda x: x if isinstance(x, str) else \"\",\n    )\n    def test_search_files_with_brace_expansion(\n        self, file_paths, pattern, paths_include_glob, paths_exclude_glob, expected_matched_files, description\n    ):\n        \"\"\"Test search_files with glob patterns containing brace expansions.\"\"\"\n        results = search_files(\n            relative_file_paths=file_paths,\n            pattern=pattern,\n            file_reader=mock_reader_always_match,\n            paths_include_glob=paths_include_glob,\n            paths_exclude_glob=paths_exclude_glob,\n        )\n\n        actual_matched_files = sorted([result.source_file_path for result in results if result.source_file_path])\n        assert actual_matched_files == sorted(expected_matched_files), f\"Test failed: {description}\"\n\n    def test_search_files_no_pattern_match_in_content(self):\n        \"\"\"Test that no results are returned if the pattern doesn't match the file content, even if files pass filters.\"\"\"\n        file_paths = [\"a.py\", \"b.txt\"]\n        pattern = \"non_existent_pattern_in_mock_content\"  # This won't match mock_reader_always_match content\n        results = search_files(\n            relative_file_paths=file_paths,\n            pattern=pattern,\n            file_reader=mock_reader_always_match,  # Content is \"This line contains a match.\"\n            paths_include_glob=None,  # Both files would pass filters\n            paths_exclude_glob=None,\n        )\n        assert len(results) == 0, \"Should not find matches if pattern doesn't match content\"\n\n    def test_search_files_regex_pattern_with_filters(self):\n        \"\"\"Test using a regex pattern works correctly along with include/exclude filters.\"\"\"\n\n        def specific_mock_reader(file_path: str) -> str:\n            # Provide different content for different files to test regex matching\n            if file_path == \"a.py\":  # noqa: SIM116\n                return \"File A: value=123\\nFile A: value=456\"\n            elif file_path == \"b.py\":\n                return \"File B: value=789\"\n            elif file_path == \"c.txt\":\n                return \"File C: value=000\"\n            return \"No values here.\"\n\n        file_paths = [\"a.py\", \"b.py\", \"c.txt\"]\n        pattern = r\"value=(\\d+)\"\n\n        results = search_files(\n            relative_file_paths=file_paths,\n            pattern=pattern,\n            file_reader=specific_mock_reader,\n            paths_include_glob=\"*.py\",  # Only include .py files\n            paths_exclude_glob=\"b.*\",  # Exclude files starting with b\n        )\n\n        # Expected: a.py included, b.py excluded by glob, c.txt excluded by glob\n        # a.py has two matches for the regex pattern\n        assert len(results) == 2, \"Expected 2 matches only from a.py\"\n        actual_matched_files = sorted([result.source_file_path for result in results if result.source_file_path])\n        assert actual_matched_files == [\"a.py\", \"a.py\"], \"Both matches should be from a.py\"\n        # Check the content of the matched lines\n        assert results[0].matched_lines[0].line_content == \"File A: value=123\"\n        assert results[1].matched_lines[0].line_content == \"File A: value=456\"\n\n    def test_search_files_context_lines_with_filters(self):\n        \"\"\"Test context lines are included correctly when filters are active.\"\"\"\n\n        def context_mock_reader(file_path: str) -> str:\n            if file_path == \"include_me.txt\":\n                return \"Line before 1\\nLine before 2\\nMATCH HERE\\nLine after 1\\nLine after 2\"\n            elif file_path == \"exclude_me.log\":\n                return \"Noise\\nMATCH HERE\\nNoise\"\n            return \"No match\"\n\n        file_paths = [\"include_me.txt\", \"exclude_me.log\"]\n        pattern = \"MATCH HERE\"\n\n        results = search_files(\n            relative_file_paths=file_paths,\n            pattern=pattern,\n            file_reader=context_mock_reader,\n            paths_include_glob=\"*.txt\",  # Only include .txt files\n            paths_exclude_glob=None,\n            context_lines_before=1,\n            context_lines_after=1,\n        )\n\n        # Expected: Only include_me.txt should be processed and matched\n        assert len(results) == 1, \"Expected only one result from the included file\"\n        result = results[0]\n        assert result.source_file_path == \"include_me.txt\"\n        assert len(result.lines) == 3, \"Expected 3 lines (1 before, 1 match, 1 after)\"\n        assert result.lines[0].line_content == \"Line before 2\", \"Incorrect 'before' context line\"\n        assert result.lines[0].match_type == LineType.BEFORE_MATCH\n        assert result.lines[1].line_content == \"MATCH HERE\", \"Incorrect 'match' line\"\n        assert result.lines[1].match_type == LineType.MATCH\n        assert result.lines[2].line_content == \"Line after 1\", \"Incorrect 'after' context line\"\n        assert result.lines[2].match_type == LineType.AFTER_MATCH\n\n\nclass TestGlobMatch:\n    \"\"\"Test the glob_match function directly.\"\"\"\n\n    @pytest.mark.parametrize(\n        \"pattern, path, expected\",\n        [\n            # Basic wildcard patterns\n            (\"*.py\", \"file.py\", True),\n            (\"*.py\", \"file.txt\", False),\n            (\"*agent.py\", \"agent.py\", True),\n            (\"*agent.py\", \"process_isolated_agent.py\", True),\n            (\"*agent.py\", \"agent_test.py\", False),\n            # Double asterisk patterns\n            (\"**agent.py\", \"agent.py\", True),\n            (\"**agent.py\", \"src/agent.py\", True),\n            (\"**agent.py\", \"src/serena/agent.py\", True),\n            (\"**agent.py\", \"src/serena/process_isolated_agent.py\", True),\n            (\"**agent.py\", \"agent_test.py\", False),\n            # Prefix with double asterisk\n            (\"src/**agent.py\", \"src/agent.py\", True),\n            (\"src/**agent.py\", \"src/serena/agent.py\", True),\n            (\"src/**agent.py\", \"src/serena/process_isolated_agent.py\", True),\n            (\"src/**agent.py\", \"other/agent.py\", False),\n            (\"src/**agent.py\", \"src/agent_test.py\", False),\n            # Directory patterns\n            (\"src/**\", \"src/file.py\", True),\n            (\"src/**\", \"src/dir/file.py\", True),\n            (\"src/**\", \"other/file.py\", False),\n            # Exact matches with double asterisk\n            (\"src/**/test.py\", \"src/test.py\", True),\n            (\"src/**/test.py\", \"src/a/b/test.py\", True),\n            (\"src/**/test.py\", \"src/test_file.py\", False),\n            # Simple patterns without asterisks\n            (\"src/file.py\", \"src/file.py\", True),\n            (\"src/file.py\", \"src/other.py\", False),\n        ],\n    )\n    def test_glob_match(self, pattern, path, expected):\n        \"\"\"Test glob_match function with various patterns.\"\"\"\n        from serena.util.text_utils import glob_match\n\n        assert glob_match(pattern, path) == expected\n\n\nclass TestExpandBraces:\n    \"\"\"Test the expand_braces function.\"\"\"\n\n    @pytest.mark.parametrize(\n        \"pattern, expected\",\n        [\n            # Basic case\n            (\"src/*.{js,ts}\", [\"src/*.js\", \"src/*.ts\"]),\n            # No braces\n            (\"src/*.py\", [\"src/*.py\"]),\n            # Multiple brace sets\n            (\"src/{a,b}/{c,d}.py\", [\"src/a/c.py\", \"src/a/d.py\", \"src/b/c.py\", \"src/b/d.py\"]),\n            # Empty string\n            (\"\", [\"\"]),\n            # Braces with empty elements\n            (\"src/{a,,b}.py\", [\"src/a.py\", \"src/.py\", \"src/b.py\"]),\n            # No commas\n            (\"src/{a}.py\", [\"src/a.py\"]),\n        ],\n    )\n    def test_expand_braces(self, pattern, expected):\n        \"\"\"Test brace expansion for glob patterns.\"\"\"\n        from serena.util.text_utils import expand_braces\n\n        assert sorted(expand_braces(pattern)) == sorted(expected)\n"
  },
  {
    "path": "test/serena/test_tool_parameter_types.py",
    "content": "import logging\n\nimport pytest\n\nfrom serena.config.serena_config import SerenaConfig\nfrom serena.mcp import SerenaMCPFactory\nfrom serena.tools.tools_base import ToolRegistry\n\n\n@pytest.mark.parametrize(\"context\", (\"chatgpt\", \"codex\", \"oaicompat-agent\"))\ndef test_all_tool_parameters_have_type(context):\n    \"\"\"\n    For every tool exposed by Serena, ensure that the generated\n    Open‑AI schema contains a ``type`` entry for each parameter.\n    \"\"\"\n    cfg = SerenaConfig(gui_log_window=False, web_dashboard=False, log_level=logging.ERROR)\n    registry = ToolRegistry()\n    cfg.included_optional_tools = tuple(registry.get_tool_names_optional())\n    factory = SerenaMCPFactory(context=context)\n    # Initialize the agent so that the tools are available\n    factory.agent = factory._create_serena_agent(cfg)\n    tools = list(factory._iter_tools())\n\n    for tool in tools:\n        mcp_tool = factory.make_mcp_tool(tool, openai_tool_compatible=True)\n        params = mcp_tool.parameters\n\n        # Collect any parameter that lacks a type\n        issues = []\n        print(f\"Checking tool {tool}\")\n\n        if \"properties\" not in params:\n            issues.append(f\"Tool {tool.get_name()!r} missing properties section\")\n        else:\n            for pname, prop in params[\"properties\"].items():\n                if \"type\" not in prop:\n                    issues.append(f\"Tool {tool.get_name()!r} parameter {pname!r} missing 'type'\")\n        if issues:\n            raise AssertionError(\"\\n\".join(issues))\n"
  },
  {
    "path": "test/serena/util/test_exception.py",
    "content": "import os\nfrom unittest.mock import MagicMock, Mock, patch\n\nimport pytest\n\nfrom serena.util.exception import is_headless_environment, show_fatal_exception_safe\n\n\nclass TestHeadlessEnvironmentDetection:\n    \"\"\"Test class for headless environment detection functionality.\"\"\"\n\n    def test_is_headless_no_display(self):\n        \"\"\"Test that environment without DISPLAY is detected as headless on Linux.\"\"\"\n        with patch(\"sys.platform\", \"linux\"):\n            with patch.dict(os.environ, {}, clear=True):\n                assert is_headless_environment() is True\n\n    def test_is_headless_ssh_connection(self):\n        \"\"\"Test that SSH sessions are detected as headless.\"\"\"\n        with patch(\"sys.platform\", \"linux\"):\n            with patch.dict(os.environ, {\"SSH_CONNECTION\": \"192.168.1.1 22 192.168.1.2 22\", \"DISPLAY\": \":0\"}):\n                assert is_headless_environment() is True\n\n            with patch.dict(os.environ, {\"SSH_CLIENT\": \"192.168.1.1 22 22\", \"DISPLAY\": \":0\"}):\n                assert is_headless_environment() is True\n\n    def test_is_headless_wsl(self):\n        \"\"\"Test that WSL environment is detected as headless.\"\"\"\n        # Skip this test on Windows since os.uname doesn't exist\n        if not hasattr(os, \"uname\"):\n            pytest.skip(\"os.uname not available on this platform\")\n\n        with patch(\"sys.platform\", \"linux\"):\n            with patch(\"os.uname\") as mock_uname:\n                mock_uname.return_value = Mock(release=\"5.15.153.1-microsoft-standard-WSL2\")\n                with patch.dict(os.environ, {\"DISPLAY\": \":0\"}):\n                    assert is_headless_environment() is True\n\n    def test_is_headless_docker(self):\n        \"\"\"Test that Docker containers are detected as headless.\"\"\"\n        with patch(\"sys.platform\", \"linux\"):\n            # Test with CI environment variable\n            with patch.dict(os.environ, {\"CI\": \"true\", \"DISPLAY\": \":0\"}):\n                assert is_headless_environment() is True\n\n            # Test with CONTAINER environment variable\n            with patch.dict(os.environ, {\"CONTAINER\": \"docker\", \"DISPLAY\": \":0\"}):\n                assert is_headless_environment() is True\n\n            # Test with .dockerenv file\n            with patch(\"os.path.exists\") as mock_exists:\n                mock_exists.return_value = True\n                with patch.dict(os.environ, {\"DISPLAY\": \":0\"}):\n                    assert is_headless_environment() is True\n\n    def test_is_not_headless_windows(self):\n        \"\"\"Test that Windows is never detected as headless.\"\"\"\n        with patch(\"sys.platform\", \"win32\"):\n            # Even without DISPLAY, Windows should not be headless\n            with patch.dict(os.environ, {}, clear=True):\n                assert is_headless_environment() is False\n\n\nclass TestShowFatalExceptionSafe:\n    \"\"\"Test class for safe fatal exception display functionality.\"\"\"\n\n    @patch(\"serena.util.exception.is_headless_environment\", return_value=True)\n    @patch(\"serena.util.exception.log\")\n    def test_show_fatal_exception_safe_headless(self, mock_log, mock_is_headless):\n        \"\"\"Test that GUI is not attempted in headless environment.\"\"\"\n        test_exception = ValueError(\"Test error\")\n\n        # The import should never happen in headless mode\n        with patch(\"serena.gui_log_viewer.show_fatal_exception\") as mock_show_gui:\n            show_fatal_exception_safe(test_exception)\n            mock_show_gui.assert_not_called()\n\n        # Verify debug log about skipping GUI\n        mock_log.debug.assert_called_once_with(\"Skipping GUI error display in headless environment\")\n\n    @patch(\"serena.util.exception.is_headless_environment\", return_value=False)\n    @patch(\"serena.util.exception.log\")\n    def test_show_fatal_exception_safe_with_gui(self, mock_log, mock_is_headless):\n        \"\"\"Test that GUI is attempted when not in headless environment.\"\"\"\n        test_exception = ValueError(\"Test error\")\n\n        # Mock the GUI function\n        with patch(\"serena.gui_log_viewer.show_fatal_exception\") as mock_show_gui:\n            show_fatal_exception_safe(test_exception)\n            mock_show_gui.assert_called_once_with(test_exception)\n\n    @patch(\"serena.util.exception.is_headless_environment\", return_value=False)\n    @patch(\"serena.util.exception.log\")\n    def test_show_fatal_exception_safe_gui_failure(self, mock_log, mock_is_headless):\n        \"\"\"Test graceful handling when GUI display fails.\"\"\"\n        test_exception = ValueError(\"Test error\")\n        gui_error = ImportError(\"No module named 'tkinter'\")\n\n        # Mock the GUI function to raise an exception\n        with patch(\"serena.gui_log_viewer.show_fatal_exception\", side_effect=gui_error):\n            show_fatal_exception_safe(test_exception)\n\n        # Verify debug log about GUI failure\n        mock_log.debug.assert_called_with(f\"Failed to show GUI error dialog: {gui_error}\")\n\n    def test_show_fatal_exception_safe_prints_to_stderr(self):\n        \"\"\"Test that exceptions are always printed to stderr.\"\"\"\n        test_exception = ValueError(\"Test error message\")\n\n        with patch(\"sys.stderr\", new_callable=MagicMock) as mock_stderr:\n            with patch(\"serena.util.exception.is_headless_environment\", return_value=True):\n                with patch(\"serena.util.exception.log\"):\n                    show_fatal_exception_safe(test_exception)\n\n        # Verify print was called with the correct arguments\n        mock_stderr.write.assert_any_call(\"Fatal exception: Test error message\")\n"
  },
  {
    "path": "test/serena/util/test_file_system.py",
    "content": "import os\nimport shutil\nimport tempfile\nfrom pathlib import Path\n\n# Assuming the gitignore parser code is in a module named 'gitignore_parser'\nfrom serena.util.file_system import GitignoreParser, GitignoreSpec\n\n\nclass TestGitignoreParser:\n    \"\"\"Test class for GitignoreParser functionality.\"\"\"\n\n    def setup_method(self):\n        \"\"\"Set up test environment before each test method.\"\"\"\n        # Create a temporary directory for testing\n        self.test_dir = tempfile.mkdtemp()\n        self.repo_path = Path(self.test_dir)\n\n        # Create test repository structure\n        self._create_repo_structure()\n\n    def teardown_method(self):\n        \"\"\"Clean up test environment after each test method.\"\"\"\n        # Remove the temporary directory\n        shutil.rmtree(self.test_dir)\n\n    def _create_repo_structure(self):\n        \"\"\"\n        Create a test repository structure with multiple gitignore files.\n\n        Structure:\n        repo/\n        ├── .gitignore\n        ├── file1.txt\n        ├── test.log\n        ├── src/\n        │   ├── .gitignore\n        │   ├── main.py\n        │   ├── test.log\n        │   ├── build/\n        │   │   └── output.o\n        │   └── lib/\n        │       ├── .gitignore\n        │       └── cache.tmp\n        └── docs/\n            ├── .gitignore\n            ├── api.md\n            └── temp/\n                └── draft.md\n        \"\"\"\n        # Create directories\n        (self.repo_path / \"src\").mkdir()\n        (self.repo_path / \"src\" / \"build\").mkdir()\n        (self.repo_path / \"src\" / \"lib\").mkdir()\n        (self.repo_path / \"docs\").mkdir()\n        (self.repo_path / \"docs\" / \"temp\").mkdir()\n\n        # Create files\n        (self.repo_path / \"file1.txt\").touch()\n        (self.repo_path / \"test.log\").touch()\n        (self.repo_path / \"src\" / \"main.py\").touch()\n        (self.repo_path / \"src\" / \"test.log\").touch()\n        (self.repo_path / \"src\" / \"build\" / \"output.o\").touch()\n        (self.repo_path / \"src\" / \"lib\" / \"cache.tmp\").touch()\n        (self.repo_path / \"docs\" / \"api.md\").touch()\n        (self.repo_path / \"docs\" / \"temp\" / \"draft.md\").touch()\n\n        # Create root .gitignore\n        root_gitignore = self.repo_path / \".gitignore\"\n        root_gitignore.write_text(\n            \"\"\"# Root gitignore\n*.log\n/build/\n\"\"\"\n        )\n\n        # Create src/.gitignore\n        src_gitignore = self.repo_path / \"src\" / \".gitignore\"\n        src_gitignore.write_text(\n            \"\"\"# Source gitignore\n*.o\nbuild/\n!important.log\n\"\"\"\n        )\n\n        # Create src/lib/.gitignore (deeply nested)\n        src_lib_gitignore = self.repo_path / \"src\" / \"lib\" / \".gitignore\"\n        src_lib_gitignore.write_text(\n            \"\"\"# Library gitignore\n*.tmp\n*.cache\n\"\"\"\n        )\n\n        # Create docs/.gitignore\n        docs_gitignore = self.repo_path / \"docs\" / \".gitignore\"\n        docs_gitignore.write_text(\n            \"\"\"# Docs gitignore\ntemp/\n*.tmp\n\"\"\"\n        )\n\n    def test_initialization(self):\n        \"\"\"Test GitignoreParser initialization.\"\"\"\n        parser = GitignoreParser(str(self.repo_path))\n\n        assert parser.repo_root == str(self.repo_path.absolute())\n        assert len(parser.get_ignore_specs()) == 4\n\n    def test_find_gitignore_files(self):\n        \"\"\"Test finding all gitignore files in repository, including deeply nested ones.\"\"\"\n        parser = GitignoreParser(str(self.repo_path))\n\n        # Get file paths from specs\n        gitignore_files = [spec.file_path for spec in parser.get_ignore_specs()]\n\n        # Convert to relative paths for easier testing\n        rel_paths = [os.path.relpath(f, self.repo_path) for f in gitignore_files]\n        rel_paths.sort()\n\n        assert len(rel_paths) == 4\n        assert \".gitignore\" in rel_paths\n        assert os.path.join(\"src\", \".gitignore\") in rel_paths\n        assert os.path.join(\"src\", \"lib\", \".gitignore\") in rel_paths  # Deeply nested\n        assert os.path.join(\"docs\", \".gitignore\") in rel_paths\n\n    def test_parse_patterns_root_directory(self):\n        \"\"\"Test parsing gitignore patterns in root directory.\"\"\"\n        # Create a simple test case with only root gitignore\n        test_dir = self.repo_path / \"test_root\"\n        test_dir.mkdir()\n\n        gitignore = test_dir / \".gitignore\"\n        gitignore.write_text(\n            \"\"\"*.log\nbuild/\n/temp.txt\n\"\"\"\n        )\n\n        parser = GitignoreParser(str(test_dir))\n        specs = parser.get_ignore_specs()\n\n        assert len(specs) == 1\n        patterns = specs[0].patterns\n\n        assert \"*.log\" in patterns\n        assert \"build/\" in patterns\n        assert \"/temp.txt\" in patterns\n\n    def test_parse_patterns_subdirectory(self):\n        \"\"\"Test parsing gitignore patterns in subdirectory.\"\"\"\n        # Create a test case with subdirectory gitignore\n        test_dir = self.repo_path / \"test_sub\"\n        test_dir.mkdir()\n        subdir = test_dir / \"src\"\n        subdir.mkdir()\n\n        gitignore = subdir / \".gitignore\"\n        gitignore.write_text(\n            \"\"\"*.o\n/build/\ntest.log\n\"\"\"\n        )\n\n        parser = GitignoreParser(str(test_dir))\n        specs = parser.get_ignore_specs()\n\n        assert len(specs) == 1\n        patterns = specs[0].patterns\n\n        # Non-anchored pattern should get ** prefix\n        assert \"src/**/*.o\" in patterns\n        # Anchored pattern should not get ** prefix\n        assert \"src/build/\" in patterns\n        # Non-anchored pattern without slash\n        assert \"src/**/test.log\" in patterns\n\n    def test_should_ignore_root_patterns(self):\n        \"\"\"Test ignoring files based on root .gitignore.\"\"\"\n        parser = GitignoreParser(str(self.repo_path))\n\n        # Files that should be ignored\n        assert parser.should_ignore(\"test.log\")\n        assert parser.should_ignore(str(self.repo_path / \"test.log\"))\n\n        # Files that should NOT be ignored\n        assert not parser.should_ignore(\"file1.txt\")\n        assert not parser.should_ignore(\"src/main.py\")\n\n    def test_should_ignore_subdirectory_patterns(self):\n        \"\"\"Test ignoring files based on subdirectory .gitignore files.\"\"\"\n        parser = GitignoreParser(str(self.repo_path))\n\n        # .o files in src should be ignored\n        assert parser.should_ignore(\"src/build/output.o\")\n\n        # build/ directory in src should be ignored\n        assert parser.should_ignore(\"src/build/\")\n\n        # temp/ directory in docs should be ignored\n        assert parser.should_ignore(\"docs/temp/draft.md\")\n\n        # But temp/ outside docs should not be ignored by docs/.gitignore\n        assert not parser.should_ignore(\"temp/file.txt\")\n\n        # Test deeply nested .gitignore in src/lib/\n        # .tmp files in src/lib should be ignored\n        assert parser.should_ignore(\"src/lib/cache.tmp\")\n\n        # .cache files in src/lib should also be ignored\n        assert parser.should_ignore(\"src/lib/data.cache\")\n\n        # But .tmp files outside src/lib should not be ignored by src/lib/.gitignore\n        assert not parser.should_ignore(\"src/other.tmp\")\n\n    def test_anchored_vs_non_anchored_patterns(self):\n        \"\"\"Test the difference between anchored and non-anchored patterns.\"\"\"\n        # Create new test structure\n        test_dir = self.repo_path / \"test_anchored\"\n        test_dir.mkdir()\n        (test_dir / \"src\").mkdir()\n        (test_dir / \"src\" / \"subdir\").mkdir()\n        (test_dir / \"src\" / \"subdir\" / \"deep\").mkdir()\n\n        # Create src/.gitignore with both anchored and non-anchored patterns\n        gitignore = test_dir / \"src\" / \".gitignore\"\n        gitignore.write_text(\n            \"\"\"/temp.txt\ndata.json\n\"\"\"\n        )\n\n        # Create test files\n        (test_dir / \"src\" / \"temp.txt\").touch()\n        (test_dir / \"src\" / \"data.json\").touch()\n        (test_dir / \"src\" / \"subdir\" / \"temp.txt\").touch()\n        (test_dir / \"src\" / \"subdir\" / \"data.json\").touch()\n        (test_dir / \"src\" / \"subdir\" / \"deep\" / \"data.json\").touch()\n\n        parser = GitignoreParser(str(test_dir))\n\n        # Anchored pattern /temp.txt should only match in src/\n        assert parser.should_ignore(\"src/temp.txt\")\n        assert not parser.should_ignore(\"src/subdir/temp.txt\")\n\n        # Non-anchored pattern data.json should match anywhere under src/\n        assert parser.should_ignore(\"src/data.json\")\n        assert parser.should_ignore(\"src/subdir/data.json\")\n        assert parser.should_ignore(\"src/subdir/deep/data.json\")\n\n    def test_root_anchored_patterns(self):\n        \"\"\"Test anchored patterns in root .gitignore only match root-level files.\"\"\"\n        # Create new test structure for root anchored patterns\n        test_dir = self.repo_path / \"test_root_anchored\"\n        test_dir.mkdir()\n        (test_dir / \"src\").mkdir()\n        (test_dir / \"docs\").mkdir()\n        (test_dir / \"src\" / \"nested\").mkdir()\n\n        # Create root .gitignore with anchored patterns\n        gitignore = test_dir / \".gitignore\"\n        gitignore.write_text(\n            \"\"\"/config.json\n/temp.log\n/build\n*.pyc\n\"\"\"\n        )\n\n        # Create test files at root level\n        (test_dir / \"config.json\").touch()\n        (test_dir / \"temp.log\").touch()\n        (test_dir / \"build\").mkdir()\n        (test_dir / \"file.pyc\").touch()\n\n        # Create same-named files in subdirectories\n        (test_dir / \"src\" / \"config.json\").touch()\n        (test_dir / \"src\" / \"temp.log\").touch()\n        (test_dir / \"src\" / \"build\").mkdir()\n        (test_dir / \"src\" / \"file.pyc\").touch()\n        (test_dir / \"docs\" / \"config.json\").touch()\n        (test_dir / \"docs\" / \"temp.log\").touch()\n        (test_dir / \"src\" / \"nested\" / \"config.json\").touch()\n        (test_dir / \"src\" / \"nested\" / \"temp.log\").touch()\n        (test_dir / \"src\" / \"nested\" / \"build\").mkdir()\n\n        parser = GitignoreParser(str(test_dir))\n\n        # Anchored patterns should only match root-level files\n        assert parser.should_ignore(\"config.json\")\n        assert not parser.should_ignore(\"src/config.json\")\n        assert not parser.should_ignore(\"docs/config.json\")\n        assert not parser.should_ignore(\"src/nested/config.json\")\n\n        assert parser.should_ignore(\"temp.log\")\n        assert not parser.should_ignore(\"src/temp.log\")\n        assert not parser.should_ignore(\"docs/temp.log\")\n        assert not parser.should_ignore(\"src/nested/temp.log\")\n\n        assert parser.should_ignore(\"build\")\n        assert not parser.should_ignore(\"src/build\")\n        assert not parser.should_ignore(\"src/nested/build\")\n\n        # Non-anchored patterns should match everywhere\n        assert parser.should_ignore(\"file.pyc\")\n        assert parser.should_ignore(\"src/file.pyc\")\n\n    def test_mixed_anchored_and_non_anchored_root_patterns(self):\n        \"\"\"Test mix of anchored and non-anchored patterns in root .gitignore.\"\"\"\n        test_dir = self.repo_path / \"test_mixed_patterns\"\n        test_dir.mkdir()\n        (test_dir / \"app\").mkdir()\n        (test_dir / \"tests\").mkdir()\n        (test_dir / \"app\" / \"modules\").mkdir()\n\n        # Create root .gitignore with mixed patterns\n        gitignore = test_dir / \".gitignore\"\n        gitignore.write_text(\n            \"\"\"/secrets.env\n/dist/\nnode_modules/\n*.tmp\n/app/local.config\ndebug.log\n\"\"\"\n        )\n\n        # Create test files and directories\n        (test_dir / \"secrets.env\").touch()\n        (test_dir / \"dist\").mkdir()\n        (test_dir / \"node_modules\").mkdir()\n        (test_dir / \"file.tmp\").touch()\n        (test_dir / \"app\" / \"local.config\").touch()\n        (test_dir / \"debug.log\").touch()\n\n        # Create same files in subdirectories\n        (test_dir / \"app\" / \"secrets.env\").touch()\n        (test_dir / \"app\" / \"dist\").mkdir()\n        (test_dir / \"app\" / \"node_modules\").mkdir()\n        (test_dir / \"app\" / \"file.tmp\").touch()\n        (test_dir / \"app\" / \"debug.log\").touch()\n        (test_dir / \"tests\" / \"secrets.env\").touch()\n        (test_dir / \"tests\" / \"node_modules\").mkdir()\n        (test_dir / \"tests\" / \"debug.log\").touch()\n        (test_dir / \"app\" / \"modules\" / \"local.config\").touch()\n\n        parser = GitignoreParser(str(test_dir))\n\n        # Anchored patterns should only match at root\n        assert parser.should_ignore(\"secrets.env\")\n        assert not parser.should_ignore(\"app/secrets.env\")\n        assert not parser.should_ignore(\"tests/secrets.env\")\n\n        assert parser.should_ignore(\"dist\")\n        assert not parser.should_ignore(\"app/dist\")\n\n        assert parser.should_ignore(\"app/local.config\")\n        assert not parser.should_ignore(\"app/modules/local.config\")\n\n        # Non-anchored patterns should match everywhere\n        assert parser.should_ignore(\"node_modules\")\n        assert parser.should_ignore(\"app/node_modules\")\n        assert parser.should_ignore(\"tests/node_modules\")\n\n        assert parser.should_ignore(\"file.tmp\")\n        assert parser.should_ignore(\"app/file.tmp\")\n\n        assert parser.should_ignore(\"debug.log\")\n        assert parser.should_ignore(\"app/debug.log\")\n        assert parser.should_ignore(\"tests/debug.log\")\n\n    def test_negation_patterns(self):\n        \"\"\"Test negation patterns are parsed correctly.\"\"\"\n        test_dir = self.repo_path / \"test_negation\"\n        test_dir.mkdir()\n\n        gitignore = test_dir / \".gitignore\"\n        gitignore.write_text(\n            \"\"\"*.log\n!important.log\n!src/keep.log\n\"\"\"\n        )\n\n        parser = GitignoreParser(str(test_dir))\n        specs = parser.get_ignore_specs()\n\n        assert len(specs) == 1\n        patterns = specs[0].patterns\n\n        assert \"*.log\" in patterns\n        assert \"!important.log\" in patterns\n        assert \"!src/keep.log\" in patterns\n\n    def test_comments_and_empty_lines(self):\n        \"\"\"Test that comments and empty lines are ignored.\"\"\"\n        test_dir = self.repo_path / \"test_comments\"\n        test_dir.mkdir()\n\n        gitignore = test_dir / \".gitignore\"\n        gitignore.write_text(\n            \"\"\"# This is a comment\n*.log\n\n# Another comment\n  # Indented comment\n\nbuild/\n\"\"\"\n        )\n\n        parser = GitignoreParser(str(test_dir))\n        specs = parser.get_ignore_specs()\n\n        assert len(specs) == 1\n        patterns = specs[0].patterns\n\n        assert len(patterns) == 2\n        assert \"*.log\" in patterns\n        assert \"build/\" in patterns\n\n    def test_escaped_characters(self):\n        \"\"\"Test escaped special characters.\"\"\"\n        test_dir = self.repo_path / \"test_escaped\"\n        test_dir.mkdir()\n\n        gitignore = test_dir / \".gitignore\"\n        gitignore.write_text(\n            \"\"\"\\\\#not-a-comment.txt\n\\\\!not-negation.txt\n\"\"\"\n        )\n\n        parser = GitignoreParser(str(test_dir))\n        specs = parser.get_ignore_specs()\n\n        assert len(specs) == 1\n        patterns = specs[0].patterns\n\n        assert \"#not-a-comment.txt\" in patterns\n        assert \"!not-negation.txt\" in patterns\n\n    def test_escaped_negation_patterns(self):\n        test_dir = self.repo_path / \"test_escaped_negation\"\n        test_dir.mkdir()\n\n        gitignore = test_dir / \".gitignore\"\n        gitignore.write_text(\n            \"\"\"*.log\n\\\\!not-negation.log\n!actual-negation.log\n\"\"\"\n        )\n\n        parser = GitignoreParser(str(test_dir))\n        specs = parser.get_ignore_specs()\n\n        assert len(specs) == 1\n        patterns = specs[0].patterns\n\n        # Key assertions: escaped exclamation becomes literal, real negation preserved\n        assert \"!not-negation.log\" in patterns  # escaped -> literal\n        assert \"!actual-negation.log\" in patterns  # real negation preserved\n\n        # Test the actual behavioral difference between escaped and real negation:\n        # *.log pattern should ignore test.log\n        assert parser.should_ignore(\"test.log\")\n\n        # Escaped negation file should still be ignored by *.log pattern\n        assert parser.should_ignore(\"!not-negation.log\")\n\n        # Actual negation should override the *.log pattern\n        assert not parser.should_ignore(\"actual-negation.log\")\n\n    def test_glob_patterns(self):\n        \"\"\"Test various glob patterns work correctly.\"\"\"\n        test_dir = self.repo_path / \"test_glob\"\n        test_dir.mkdir()\n\n        gitignore = test_dir / \".gitignore\"\n        gitignore.write_text(\n            \"\"\"*.pyc\n**/*.tmp\nsrc/*.o\n!src/important.o\n[Tt]est*\n\"\"\"\n        )\n\n        # Create test files\n        (test_dir / \"src\").mkdir()\n        (test_dir / \"src\" / \"nested\").mkdir()\n        (test_dir / \"file.pyc\").touch()\n        (test_dir / \"src\" / \"file.pyc\").touch()\n        (test_dir / \"file.tmp\").touch()\n        (test_dir / \"src\" / \"nested\" / \"file.tmp\").touch()\n        (test_dir / \"src\" / \"file.o\").touch()\n        (test_dir / \"src\" / \"important.o\").touch()\n        (test_dir / \"Test.txt\").touch()\n        (test_dir / \"test.log\").touch()\n\n        parser = GitignoreParser(str(test_dir))\n\n        # *.pyc should match everywhere\n        assert parser.should_ignore(\"file.pyc\")\n        assert parser.should_ignore(\"src/file.pyc\")\n\n        # **/*.tmp should match all .tmp files\n        assert parser.should_ignore(\"file.tmp\")\n        assert parser.should_ignore(\"src/nested/file.tmp\")\n\n        # src/*.o should only match .o files directly in src/\n        assert parser.should_ignore(\"src/file.o\")\n\n        # Character class patterns\n        assert parser.should_ignore(\"Test.txt\")\n        assert parser.should_ignore(\"test.log\")\n\n    def test_empty_gitignore(self):\n        \"\"\"Test handling of empty gitignore files.\"\"\"\n        test_dir = self.repo_path / \"test_empty\"\n        test_dir.mkdir()\n\n        gitignore = test_dir / \".gitignore\"\n        gitignore.write_text(\"\")\n\n        parser = GitignoreParser(str(test_dir))\n\n        # Should not crash and should return empty list\n        assert len(parser.get_ignore_specs()) == 0\n\n    def test_malformed_gitignore(self):\n        \"\"\"Test handling of malformed gitignore content.\"\"\"\n        test_dir = self.repo_path / \"test_malformed\"\n        test_dir.mkdir()\n\n        gitignore = test_dir / \".gitignore\"\n        gitignore.write_text(\n            \"\"\"# Only comments and empty lines\n    \n# More comments\n    \n    \"\"\"\n        )\n\n        parser = GitignoreParser(str(test_dir))\n\n        # Should handle gracefully\n        assert len(parser.get_ignore_specs()) == 0\n\n    def test_reload(self):\n        \"\"\"Test reloading gitignore files.\"\"\"\n        test_dir = self.repo_path / \"test_reload\"\n        test_dir.mkdir()\n\n        # Create initial gitignore\n        gitignore = test_dir / \".gitignore\"\n        gitignore.write_text(\"*.log\")\n\n        parser = GitignoreParser(str(test_dir))\n        assert len(parser.get_ignore_specs()) == 1\n        assert parser.should_ignore(\"test.log\")\n\n        # Modify gitignore\n        gitignore.write_text(\"*.tmp\")\n\n        # Without reload, should still use old patterns\n        assert parser.should_ignore(\"test.log\")\n        assert not parser.should_ignore(\"test.tmp\")\n\n        # After reload, should use new patterns\n        parser.reload()\n        assert not parser.should_ignore(\"test.log\")\n        assert parser.should_ignore(\"test.tmp\")\n\n    def test_gitignore_spec_matches(self):\n        \"\"\"Test GitignoreSpec.matches method.\"\"\"\n        spec = GitignoreSpec(\"/path/to/.gitignore\", [\"*.log\", \"build/\", \"!important.log\"])\n\n        assert spec.matches(\"test.log\")\n        assert spec.matches(\"build/output.o\")\n        assert spec.matches(\"src/test.log\")\n\n        # Note: Negation patterns in pathspec work differently than in git\n        # This is a limitation of the pathspec library\n\n    def test_subdirectory_gitignore_pattern_scoping(self):\n        \"\"\"Test that subdirectory .gitignore patterns are scoped correctly.\"\"\"\n        # Create test structure: foo/ with subdirectory bar/\n        test_dir = self.repo_path / \"test_subdir_scoping\"\n        test_dir.mkdir()\n        (test_dir / \"foo\").mkdir()\n        (test_dir / \"foo\" / \"bar\").mkdir()\n\n        # Create files in various locations\n        (test_dir / \"foo.txt\").touch()  # root level\n        (test_dir / \"foo\" / \"foo.txt\").touch()  # in foo/\n        (test_dir / \"foo\" / \"bar\" / \"foo.txt\").touch()  # in foo/bar/\n\n        # Test case 1: foo.txt in foo/.gitignore should only ignore in foo/ subtree\n        gitignore = test_dir / \"foo\" / \".gitignore\"\n        gitignore.write_text(\"foo.txt\\n\")\n\n        parser = GitignoreParser(str(test_dir))\n\n        # foo.txt at root should NOT be ignored by foo/.gitignore\n        assert not parser.should_ignore(\"foo.txt\"), \"Root foo.txt should not be ignored by foo/.gitignore\"\n\n        # foo.txt in foo/ should be ignored\n        assert parser.should_ignore(\"foo/foo.txt\"), \"foo/foo.txt should be ignored\"\n\n        # foo.txt in foo/bar/ should be ignored (within foo/ subtree)\n        assert parser.should_ignore(\"foo/bar/foo.txt\"), \"foo/bar/foo.txt should be ignored\"\n\n    def test_anchored_pattern_in_subdirectory(self):\n        \"\"\"Test that anchored patterns in subdirectory only match immediate children.\"\"\"\n        test_dir = self.repo_path / \"test_anchored_subdir\"\n        test_dir.mkdir()\n        (test_dir / \"foo\").mkdir()\n        (test_dir / \"foo\" / \"bar\").mkdir()\n\n        # Create files\n        (test_dir / \"foo.txt\").touch()  # root level\n        (test_dir / \"foo\" / \"foo.txt\").touch()  # in foo/\n        (test_dir / \"foo\" / \"bar\" / \"foo.txt\").touch()  # in foo/bar/\n\n        # Test case 2: /foo.txt in foo/.gitignore should only match foo/foo.txt\n        gitignore = test_dir / \"foo\" / \".gitignore\"\n        gitignore.write_text(\"/foo.txt\\n\")\n\n        parser = GitignoreParser(str(test_dir))\n\n        # foo.txt at root should NOT be ignored\n        assert not parser.should_ignore(\"foo.txt\"), \"Root foo.txt should not be ignored\"\n\n        # foo.txt directly in foo/ should be ignored\n        assert parser.should_ignore(\"foo/foo.txt\"), \"foo/foo.txt should be ignored by /foo.txt pattern\"\n\n        # foo.txt in foo/bar/ should NOT be ignored (anchored pattern only matches immediate children)\n        assert not parser.should_ignore(\"foo/bar/foo.txt\"), \"foo/bar/foo.txt should NOT be ignored by /foo.txt pattern\"\n\n    def test_double_star_pattern_scoping(self):\n        \"\"\"Test that **/pattern in subdirectory only applies within that subtree.\"\"\"\n        test_dir = self.repo_path / \"test_doublestar_scope\"\n        test_dir.mkdir()\n        (test_dir / \"foo\").mkdir()\n        (test_dir / \"foo\" / \"bar\").mkdir()\n        (test_dir / \"other\").mkdir()\n\n        # Create files\n        (test_dir / \"foo.txt\").touch()  # root level\n        (test_dir / \"foo\" / \"foo.txt\").touch()  # in foo/\n        (test_dir / \"foo\" / \"bar\" / \"foo.txt\").touch()  # in foo/bar/\n        (test_dir / \"other\" / \"foo.txt\").touch()  # in other/\n\n        # Test case 3: **/foo.txt in foo/.gitignore should only ignore within foo/ subtree\n        gitignore = test_dir / \"foo\" / \".gitignore\"\n        gitignore.write_text(\"**/foo.txt\\n\")\n\n        parser = GitignoreParser(str(test_dir))\n\n        # foo.txt at root should NOT be ignored\n        assert not parser.should_ignore(\"foo.txt\"), \"Root foo.txt should not be ignored by foo/.gitignore\"\n\n        # foo.txt in foo/ should be ignored\n        assert parser.should_ignore(\"foo/foo.txt\"), \"foo/foo.txt should be ignored\"\n\n        # foo.txt in foo/bar/ should be ignored (within foo/ subtree)\n        assert parser.should_ignore(\"foo/bar/foo.txt\"), \"foo/bar/foo.txt should be ignored\"\n\n        # foo.txt in other/ should NOT be ignored (outside foo/ subtree)\n        assert not parser.should_ignore(\"other/foo.txt\"), \"other/foo.txt should NOT be ignored by foo/.gitignore\"\n\n    def test_anchored_double_star_pattern(self):\n        \"\"\"Test that /**/pattern in subdirectory works correctly.\"\"\"\n        test_dir = self.repo_path / \"test_anchored_doublestar\"\n        test_dir.mkdir()\n        (test_dir / \"foo\").mkdir()\n        (test_dir / \"foo\" / \"bar\").mkdir()\n        (test_dir / \"other\").mkdir()\n\n        # Create files\n        (test_dir / \"foo.txt\").touch()  # root level\n        (test_dir / \"foo\" / \"foo.txt\").touch()  # in foo/\n        (test_dir / \"foo\" / \"bar\" / \"foo.txt\").touch()  # in foo/bar/\n        (test_dir / \"other\" / \"foo.txt\").touch()  # in other/\n\n        # Test case 4: /**/foo.txt in foo/.gitignore should correctly ignore only within foo/ subtree\n        gitignore = test_dir / \"foo\" / \".gitignore\"\n        gitignore.write_text(\"/**/foo.txt\\n\")\n\n        parser = GitignoreParser(str(test_dir))\n\n        # foo.txt at root should NOT be ignored\n        assert not parser.should_ignore(\"foo.txt\"), \"Root foo.txt should not be ignored\"\n\n        # foo.txt in foo/ should be ignored\n        assert parser.should_ignore(\"foo/foo.txt\"), \"foo/foo.txt should be ignored\"\n\n        # foo.txt in foo/bar/ should be ignored (within foo/ subtree)\n        assert parser.should_ignore(\"foo/bar/foo.txt\"), \"foo/bar/foo.txt should be ignored\"\n\n        # foo.txt in other/ should NOT be ignored (outside foo/ subtree)\n        assert not parser.should_ignore(\"other/foo.txt\"), \"other/foo.txt should NOT be ignored by foo/.gitignore\"\n"
  },
  {
    "path": "test/solidlsp/al/test_al_basic.py",
    "content": "import os\n\nimport pytest\n\nfrom serena.symbol import LanguageServerSymbol\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.language_servers.al_language_server import ALLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_utils import SymbolUtils\nfrom test.conftest import language_tests_enabled\n\npytestmark = [pytest.mark.al, pytest.mark.skipif(not language_tests_enabled(Language.AL), reason=\"AL tests are disabled\")]\n\n\nclass TestExtractALDisplayName:\n    \"\"\"Tests for the ALLanguageServer._extract_al_display_name method.\"\"\"\n\n    def test_table_with_quoted_name(self) -> None:\n        \"\"\"Test extraction from Table with quoted name.\"\"\"\n        assert ALLanguageServer._extract_al_display_name('Table 50000 \"TEST Customer\"') == \"TEST Customer\"\n\n    def test_page_with_quoted_name(self) -> None:\n        \"\"\"Test extraction from Page with quoted name.\"\"\"\n        assert ALLanguageServer._extract_al_display_name('Page 50001 \"TEST Customer Card\"') == \"TEST Customer Card\"\n\n    def test_codeunit_unquoted(self) -> None:\n        \"\"\"Test extraction from Codeunit with unquoted name.\"\"\"\n        assert ALLanguageServer._extract_al_display_name(\"Codeunit 50000 CustomerMgt\") == \"CustomerMgt\"\n\n    def test_enum_unquoted(self) -> None:\n        \"\"\"Test extraction from Enum with unquoted name.\"\"\"\n        assert ALLanguageServer._extract_al_display_name(\"Enum 50000 CustomerType\") == \"CustomerType\"\n\n    def test_interface_no_id(self) -> None:\n        \"\"\"Test extraction from Interface (no ID).\"\"\"\n        assert ALLanguageServer._extract_al_display_name(\"Interface IPaymentProcessor\") == \"IPaymentProcessor\"\n\n    def test_table_extension(self) -> None:\n        \"\"\"Test extraction from TableExtension.\"\"\"\n        assert ALLanguageServer._extract_al_display_name('TableExtension 50000 \"Ext Customer\"') == \"Ext Customer\"\n\n    def test_page_extension(self) -> None:\n        \"\"\"Test extraction from PageExtension.\"\"\"\n        assert ALLanguageServer._extract_al_display_name('PageExtension 50000 \"My Page Ext\"') == \"My Page Ext\"\n\n    def test_non_al_object_unchanged(self) -> None:\n        \"\"\"Test that non-AL-object names pass through unchanged.\"\"\"\n        assert ALLanguageServer._extract_al_display_name(\"fields\") == \"fields\"\n        assert ALLanguageServer._extract_al_display_name(\"CreateCustomer\") == \"CreateCustomer\"\n        assert ALLanguageServer._extract_al_display_name(\"Name\") == \"Name\"\n\n    def test_report_with_quoted_name(self) -> None:\n        \"\"\"Test extraction from Report.\"\"\"\n        assert ALLanguageServer._extract_al_display_name('Report 50000 \"Sales Invoice\"') == \"Sales Invoice\"\n\n    def test_query_unquoted(self) -> None:\n        \"\"\"Test extraction from Query.\"\"\"\n        assert ALLanguageServer._extract_al_display_name(\"Query 50000 CustomerQuery\") == \"CustomerQuery\"\n\n\n@pytest.mark.al\nclass TestALLanguageServer:\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_symbol_names_are_normalized(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that AL symbol names are normalized (metadata stripped).\"\"\"\n        file_path = os.path.join(\"src\", \"Tables\", \"Customer.Table.al\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        _all_symbols, root_symbols = symbols\n        customer_table = None\n        for sym in root_symbols:\n            if sym.get(\"name\") == \"TEST Customer\":\n                customer_table = sym\n                break\n\n        assert customer_table is not None, \"Could not find 'TEST Customer' table symbol (name should be normalized)\"\n        # Name should be just \"TEST Customer\", not \"Table 50000 'TEST Customer'\"\n        assert customer_table[\"name\"] == \"TEST Customer\", f\"Expected normalized name 'TEST Customer', got '{customer_table['name']}'\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_find_symbol_exact_match(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that find_symbol can match AL symbols by normalized name without substring_matching.\"\"\"\n        file_path = os.path.join(\"src\", \"Tables\", \"Customer.Table.al\")\n        symbols = language_server.request_document_symbols(file_path)\n\n        # Find symbols that match 'TEST Customer' using LanguageServerSymbol.find()\n        for root in symbols.root_symbols:\n            ls_symbol = LanguageServerSymbol(root)\n            matches = ls_symbol.find(\"TEST Customer\", substring_matching=False)\n            if matches:\n                assert len(matches) >= 1, \"Should find at least one match for 'TEST Customer'\"\n                assert matches[0].name == \"TEST Customer\", f\"Expected 'TEST Customer', got '{matches[0].name}'\"\n                return\n\n        pytest.fail(\"Could not find 'TEST Customer' symbol by exact name match\")\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_find_codeunit_exact_match(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding a codeunit by its normalized name.\"\"\"\n        file_path = os.path.join(\"src\", \"Codeunits\", \"CustomerMgt.Codeunit.al\")\n        symbols = language_server.request_document_symbols(file_path)\n\n        for root in symbols.root_symbols:\n            ls_symbol = LanguageServerSymbol(root)\n            matches = ls_symbol.find(\"CustomerMgt\", substring_matching=False)\n            if matches:\n                assert len(matches) >= 1\n                assert matches[0].name == \"CustomerMgt\"\n                return\n\n        pytest.fail(\"Could not find 'CustomerMgt' symbol by exact name match\")\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_find_symbol(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that AL Language Server can find symbols in the test repository with normalized names.\"\"\"\n        symbols = language_server.request_full_symbol_tree()\n\n        # Check for table symbols - names should be normalized (no \"Table 50000\" prefix)\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"TEST Customer\"), \"TEST Customer table not found in symbol tree\"\n\n        # Check for page symbols\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"TEST Customer Card\"), \"TEST Customer Card page not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"TEST Customer List\"), \"TEST Customer List page not found in symbol tree\"\n\n        # Check for codeunit symbols\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"CustomerMgt\"), \"CustomerMgt codeunit not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(\n            symbols, \"PaymentProcessorImpl\"\n        ), \"PaymentProcessorImpl codeunit not found in symbol tree\"\n\n        # Check for enum symbol\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"CustomerType\"), \"CustomerType enum not found in symbol tree\"\n\n        # Check for interface symbol\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"IPaymentProcessor\"), \"IPaymentProcessor interface not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_find_table_fields(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that AL Language Server can find fields within a table.\"\"\"\n        file_path = os.path.join(\"src\", \"Tables\", \"Customer.Table.al\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # AL tables should have their fields as child symbols\n        customer_table = None\n        _all_symbols, root_symbols = symbols\n        for sym in root_symbols:\n            if sym.get(\"name\") == \"TEST Customer\":\n                customer_table = sym\n                break\n\n        assert customer_table is not None, \"Could not find TEST Customer table symbol\"\n\n        # Check for field symbols (AL nests fields under a \"fields\" group)\n        if \"children\" in customer_table:\n            # Find the fields group\n            fields_group = None\n            for child in customer_table.get(\"children\", []):\n                if child.get(\"name\") == \"fields\":\n                    fields_group = child\n                    break\n\n            assert fields_group is not None, \"Fields group not found in Customer table\"\n\n            # Check actual field names\n            if \"children\" in fields_group:\n                field_names = [child.get(\"name\", \"\") for child in fields_group.get(\"children\", [])]\n                assert any(\"Name\" in name for name in field_names), f\"Name field not found. Fields: {field_names}\"\n                assert any(\"Balance\" in name for name in field_names), f\"Balance field not found. Fields: {field_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_find_procedures(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that AL Language Server can find procedures in codeunits.\"\"\"\n        file_path = os.path.join(\"src\", \"Codeunits\", \"CustomerMgt.Codeunit.al\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Find the codeunit symbol - name should be normalized to 'CustomerMgt'\n        codeunit_symbol = None\n        _all_symbols, root_symbols = symbols\n        for sym in root_symbols:\n            if sym.get(\"name\") == \"CustomerMgt\":\n                codeunit_symbol = sym\n                break\n\n        assert codeunit_symbol is not None, \"Could not find CustomerMgt codeunit symbol\"\n\n        # Check for procedure symbols (if hierarchical)\n        if \"children\" in codeunit_symbol:\n            procedure_names = [child.get(\"name\", \"\") for child in codeunit_symbol.get(\"children\", [])]\n            assert any(\"CreateCustomer\" in name for name in procedure_names), \"CreateCustomer procedure not found\"\n            assert any(\"TestNoSeries\" in name for name in procedure_names), \"TestNoSeries procedure not found\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that AL Language Server can find references to symbols.\"\"\"\n        # Find references to the Customer table from the CustomerMgt codeunit\n        table_file = os.path.join(\"src\", \"Tables\", \"Customer.Table.al\")\n        symbols = language_server.request_document_symbols(table_file).get_all_symbols_and_roots()\n\n        # Find the Customer table symbol (name is normalized)\n        customer_symbol = None\n        _all_symbols, root_symbols = symbols\n        for sym in root_symbols:\n            if sym.get(\"name\") == \"TEST Customer\":\n                customer_symbol = sym\n                break\n\n        if customer_symbol and \"selectionRange\" in customer_symbol:\n            sel_start = customer_symbol[\"selectionRange\"][\"start\"]\n            refs = language_server.request_references(table_file, sel_start[\"line\"], sel_start[\"character\"])\n\n            # The Customer table should be referenced in CustomerMgt.Codeunit.al\n            assert any(\n                \"CustomerMgt.Codeunit.al\" in ref.get(\"relativePath\", \"\") for ref in refs\n            ), \"Customer table should be referenced in CustomerMgt.Codeunit.al\"\n\n            # It should also be referenced in CustomerCard.Page.al\n            assert any(\n                \"CustomerCard.Page.al\" in ref.get(\"relativePath\", \"\") for ref in refs\n            ), \"Customer table should be referenced in CustomerCard.Page.al\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_cross_file_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that AL Language Server can handle cross-file symbol relationships.\"\"\"\n        # Get all symbols to verify cross-file visibility\n        symbols = language_server.request_full_symbol_tree()\n\n        # Count how many AL object symbols we found (names are now normalized)\n        al_object_names = []\n\n        def collect_symbols(syms: list) -> None:\n            for sym in syms:\n                if isinstance(sym, dict):\n                    name = sym.get(\"name\", \"\")\n                    # These are normalized names now, so just collect them\n                    al_object_names.append(name)\n                    if \"children\" in sym:\n                        collect_symbols(sym[\"children\"])\n\n        collect_symbols(symbols)\n\n        # We should find expected normalized names\n        assert \"TEST Customer\" in al_object_names, f\"TEST Customer not found in: {al_object_names}\"\n        assert \"CustomerMgt\" in al_object_names, f\"CustomerMgt not found in: {al_object_names}\"\n        assert \"CustomerType\" in al_object_names, f\"CustomerType not found in: {al_object_names}\"\n\n\n@pytest.mark.al\nclass TestALHoverInjection:\n    \"\"\"Tests for hover injection of original AL object names with type and ID.\"\"\"\n\n    def _get_symbol_hover(self, language_server: SolidLanguageServer, file_path: str, symbol_name: str) -> tuple[dict | None, str | None]:\n        \"\"\"Helper to get hover info for a symbol by name.\n\n        Returns (hover_info, hover_value) tuple.\n        \"\"\"\n        symbols = language_server.request_document_symbols(file_path)\n        for sym in symbols.root_symbols:\n            if sym.get(\"name\") == symbol_name:\n                sel_range = sym.get(\"selectionRange\", {})\n                start = sel_range.get(\"start\", {})\n                line = start.get(\"line\", 0)\n                char = start.get(\"character\", 0)\n                hover = language_server.request_hover(file_path, line, char)\n                if hover and \"contents\" in hover:\n                    return hover, hover[\"contents\"].get(\"value\", \"\")\n                return hover, None\n        return None, None\n\n    def _get_child_symbol_hover(\n        self, language_server: SolidLanguageServer, file_path: str, parent_name: str, child_name_contains: str\n    ) -> tuple[dict | None, str | None]:\n        \"\"\"Helper to get hover info for a child symbol.\n\n        Returns (hover_info, hover_value) tuple.\n        \"\"\"\n        symbols = language_server.request_document_symbols(file_path)\n        for sym in symbols.root_symbols:\n            if sym.get(\"name\") == parent_name:\n                for child in sym.get(\"children\", []):\n                    if child_name_contains in child.get(\"name\", \"\"):\n                        sel_range = child.get(\"selectionRange\", {})\n                        start = sel_range.get(\"start\", {})\n                        line = start.get(\"line\", 0)\n                        char = start.get(\"character\", 0)\n                        hover = language_server.request_hover(file_path, line, char)\n                        if hover and \"contents\" in hover:\n                            return hover, hover[\"contents\"].get(\"value\", \"\")\n                        return hover, None\n        return None, None\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_hover_table_injects_full_name(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that hovering over a Table symbol shows the full object name with ID.\"\"\"\n        file_path = os.path.join(\"src\", \"Tables\", \"Customer.Table.al\")\n        hover, value = self._get_symbol_hover(language_server, file_path, \"TEST Customer\")\n\n        assert hover is not None, \"Hover should return a result for Table symbol\"\n        assert value is not None, \"Hover should have content\"\n        assert '**Table 50000 \"TEST Customer\"**' in value, f\"Hover should contain full Table name with ID. Got: {value[:200]}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_hover_page_injects_full_name(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that hovering over a Page symbol shows the full object name with ID.\"\"\"\n        file_path = os.path.join(\"src\", \"Pages\", \"CustomerCard.Page.al\")\n        hover, value = self._get_symbol_hover(language_server, file_path, \"TEST Customer Card\")\n\n        assert hover is not None, \"Hover should return a result for Page symbol\"\n        assert value is not None, \"Hover should have content\"\n        assert '**Page 50001 \"TEST Customer Card\"**' in value, f\"Hover should contain full Page name with ID. Got: {value[:200]}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_hover_codeunit_injects_full_name(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that hovering over a Codeunit symbol shows the full object name with ID.\"\"\"\n        file_path = os.path.join(\"src\", \"Codeunits\", \"CustomerMgt.Codeunit.al\")\n        hover, value = self._get_symbol_hover(language_server, file_path, \"CustomerMgt\")\n\n        assert hover is not None, \"Hover should return a result for Codeunit symbol\"\n        assert value is not None, \"Hover should have content\"\n        assert \"**Codeunit 50000 CustomerMgt**\" in value, f\"Hover should contain full Codeunit name with ID. Got: {value[:200]}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_hover_enum_injects_full_name(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that hovering over an Enum symbol shows the full object name with ID.\"\"\"\n        file_path = os.path.join(\"src\", \"Enums\", \"CustomerType.Enum.al\")\n        hover, value = self._get_symbol_hover(language_server, file_path, \"CustomerType\")\n\n        assert hover is not None, \"Hover should return a result for Enum symbol\"\n        assert value is not None, \"Hover should have content\"\n        assert \"**Enum 50000 CustomerType**\" in value, f\"Hover should contain full Enum name with ID. Got: {value[:200]}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_hover_interface_injects_full_name(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that hovering over an Interface symbol shows the full object name (no ID for interfaces).\"\"\"\n        file_path = os.path.join(\"src\", \"Interfaces\", \"IPaymentProcessor.Interface.al\")\n        hover, value = self._get_symbol_hover(language_server, file_path, \"IPaymentProcessor\")\n\n        assert hover is not None, \"Hover should return a result for Interface symbol\"\n        assert value is not None, \"Hover should have content\"\n        assert \"**Interface IPaymentProcessor**\" in value, f\"Hover should contain full Interface name. Got: {value[:200]}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_hover_procedure_no_injection(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that hovering over a procedure does NOT inject object name (procedures are not normalized).\"\"\"\n        file_path = os.path.join(\"src\", \"Codeunits\", \"CustomerMgt.Codeunit.al\")\n        hover, value = self._get_child_symbol_hover(language_server, file_path, \"CustomerMgt\", \"CreateCustomer\")\n\n        assert hover is not None, \"Hover should return a result for procedure\"\n        assert value is not None, \"Hover should have content\"\n        # Procedure hover should NOT start with ** (no injection)\n        assert not value.startswith(\"**\"), f\"Procedure hover should not have injected name. Got: {value[:200]}\"\n        # But should contain procedure info\n        assert \"CreateCustomer\" in value, f\"Hover should contain procedure name. Got: {value[:200]}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_hover_field_no_injection(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that hovering over a field does NOT inject object name (fields are not normalized).\"\"\"\n        file_path = os.path.join(\"src\", \"Tables\", \"Customer.Table.al\")\n        symbols = language_server.request_document_symbols(file_path)\n\n        # Navigate to a field: Table -> fields -> specific field\n        for sym in symbols.root_symbols:\n            if sym.get(\"name\") == \"TEST Customer\":\n                for child in sym.get(\"children\", []):\n                    if child.get(\"name\") == \"fields\":\n                        for field in child.get(\"children\", []):\n                            if \"Name\" in field.get(\"name\", \"\"):\n                                sel_range = field.get(\"selectionRange\", {})\n                                start = sel_range.get(\"start\", {})\n                                line = start.get(\"line\", 0)\n                                char = start.get(\"character\", 0)\n                                hover = language_server.request_hover(file_path, line, char)\n\n                                assert hover is not None, \"Hover should return a result for field\"\n                                value = hover.get(\"contents\", {}).get(\"value\", \"\")\n                                # Field hover should NOT start with ** (no injection)\n                                assert not value.startswith(\"**\"), f\"Field hover should not have injected name. Got: {value[:200]}\"\n                                return\n\n        pytest.fail(\"Could not find a field to test hover on\")\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_hover_multiple_objects_correct_injection(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that multiple AL objects each get their correct full name injected.\"\"\"\n        test_cases = [\n            (os.path.join(\"src\", \"Tables\", \"Customer.Table.al\"), \"TEST Customer\", 'Table 50000 \"TEST Customer\"'),\n            (os.path.join(\"src\", \"Codeunits\", \"CustomerMgt.Codeunit.al\"), \"CustomerMgt\", \"Codeunit 50000 CustomerMgt\"),\n            (os.path.join(\"src\", \"Enums\", \"CustomerType.Enum.al\"), \"CustomerType\", \"Enum 50000 CustomerType\"),\n        ]\n\n        for file_path, symbol_name, expected_full_name in test_cases:\n            hover, value = self._get_symbol_hover(language_server, file_path, symbol_name)\n\n            assert hover is not None, f\"Hover should return a result for {symbol_name}\"\n            assert value is not None, f\"Hover should have content for {symbol_name}\"\n            assert (\n                f\"**{expected_full_name}**\" in value\n            ), f\"Hover for {symbol_name} should contain '{expected_full_name}'. Got: {value[:200]}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_hover_contains_separator_after_injection(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that injected hover has a separator between injected name and original content.\"\"\"\n        file_path = os.path.join(\"src\", \"Tables\", \"Customer.Table.al\")\n        hover, value = self._get_symbol_hover(language_server, file_path, \"TEST Customer\")\n\n        assert hover is not None, \"Hover should return a result\"\n        assert value is not None, \"Hover should have content\"\n        # Should have the separator after the bold name\n        assert \"---\" in value, f\"Hover should contain separator. Got: {value[:300]}\"\n        # The separator should come after the injected name\n        bold_end = value.find(\"**\", 2)  # Find closing **\n        separator_pos = value.find(\"---\")\n        assert separator_pos > bold_end, \"Separator should come after the injected name\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_hover_preserves_original_content(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that the original hover content is preserved after the injected name.\"\"\"\n        file_path = os.path.join(\"src\", \"Tables\", \"Customer.Table.al\")\n        hover, value = self._get_symbol_hover(language_server, file_path, \"TEST Customer\")\n\n        assert hover is not None, \"Hover should return a result\"\n        assert value is not None, \"Hover should have content\"\n        # Original AL hover content should still be present (the table structure)\n        assert \"```al\" in value, f\"Hover should contain original AL code block. Got: {value[:500]}\"\n        assert 'Table \"TEST Customer\"' in value, f\"Hover should contain original table definition. Got: {value[:500]}\"\n\n\n@pytest.mark.al\nclass TestALPathNormalization:\n    \"\"\"Tests for path normalization in hover injection cache.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_hover_with_forward_slash_path(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that hover injection works with forward slash paths.\"\"\"\n        file_path = \"src/Tables/Customer.Table.al\"\n        symbols = language_server.request_document_symbols(file_path)\n\n        for sym in symbols.root_symbols:\n            if sym.get(\"name\") == \"TEST Customer\":\n                sel_range = sym.get(\"selectionRange\", {})\n                start = sel_range.get(\"start\", {})\n                line = start.get(\"line\", 0)\n                char = start.get(\"character\", 0)\n\n                hover = language_server.request_hover(file_path, line, char)\n                assert hover is not None, \"Hover should return a result\"\n                value = hover.get(\"contents\", {}).get(\"value\", \"\")\n                assert '**Table 50000 \"TEST Customer\"**' in value, f\"Hover should have injection. Got: {value[:200]}\"\n                return\n\n        pytest.fail(\"Could not find TEST Customer symbol\")\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_hover_with_backslash_path(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that hover injection works with backslash paths (Windows style).\"\"\"\n        file_path = \"src\\\\Tables\\\\Customer.Table.al\"\n        symbols = language_server.request_document_symbols(file_path)\n\n        for sym in symbols.root_symbols:\n            if sym.get(\"name\") == \"TEST Customer\":\n                sel_range = sym.get(\"selectionRange\", {})\n                start = sel_range.get(\"start\", {})\n                line = start.get(\"line\", 0)\n                char = start.get(\"character\", 0)\n\n                hover = language_server.request_hover(file_path, line, char)\n                assert hover is not None, \"Hover should return a result\"\n                value = hover.get(\"contents\", {}).get(\"value\", \"\")\n                assert '**Table 50000 \"TEST Customer\"**' in value, f\"Hover should have injection. Got: {value[:200]}\"\n                return\n\n        pytest.fail(\"Could not find TEST Customer symbol\")\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_hover_with_mixed_path_formats_symbols_backslash_hover_forward(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test hover works when symbols requested with backslash but hover with forward slash.\"\"\"\n        file_path_backslash = \"src\\\\Tables\\\\Customer.Table.al\"\n        file_path_forward = \"src/Tables/Customer.Table.al\"\n\n        # Request symbols with backslash path\n        symbols = language_server.request_document_symbols(file_path_backslash)\n\n        for sym in symbols.root_symbols:\n            if sym.get(\"name\") == \"TEST Customer\":\n                sel_range = sym.get(\"selectionRange\", {})\n                start = sel_range.get(\"start\", {})\n                line = start.get(\"line\", 0)\n                char = start.get(\"character\", 0)\n\n                # Request hover with forward slash path (different format)\n                hover = language_server.request_hover(file_path_forward, line, char)\n                assert hover is not None, \"Hover should return a result\"\n                value = hover.get(\"contents\", {}).get(\"value\", \"\")\n                assert (\n                    '**Table 50000 \"TEST Customer\"**' in value\n                ), f\"Hover injection should work with mixed path formats. Got: {value[:200]}\"\n                return\n\n        pytest.fail(\"Could not find TEST Customer symbol\")\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_hover_with_mixed_path_formats_symbols_forward_hover_backslash(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test hover works when symbols requested with forward slash but hover with backslash.\"\"\"\n        file_path_forward = \"src/Tables/Customer.Table.al\"\n        file_path_backslash = \"src\\\\Tables\\\\Customer.Table.al\"\n\n        # Request symbols with forward slash path\n        symbols = language_server.request_document_symbols(file_path_forward)\n\n        for sym in symbols.root_symbols:\n            if sym.get(\"name\") == \"TEST Customer\":\n                sel_range = sym.get(\"selectionRange\", {})\n                start = sel_range.get(\"start\", {})\n                line = start.get(\"line\", 0)\n                char = start.get(\"character\", 0)\n\n                # Request hover with backslash path (different format)\n                hover = language_server.request_hover(file_path_backslash, line, char)\n                assert hover is not None, \"Hover should return a result\"\n                value = hover.get(\"contents\", {}).get(\"value\", \"\")\n                assert (\n                    '**Table 50000 \"TEST Customer\"**' in value\n                ), f\"Hover injection should work with mixed path formats. Got: {value[:200]}\"\n                return\n\n        pytest.fail(\"Could not find TEST Customer symbol\")\n\n    @pytest.mark.parametrize(\"language_server\", [Language.AL], indirect=True)\n    def test_hover_caching_multiple_files_different_path_formats(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that hover injection cache works correctly across multiple files with different path formats.\"\"\"\n        test_cases = [\n            (\"src/Tables/Customer.Table.al\", \"src\\\\Tables\\\\Customer.Table.al\", \"TEST Customer\", 'Table 50000 \"TEST Customer\"'),\n            (\n                \"src\\\\Codeunits\\\\CustomerMgt.Codeunit.al\",\n                \"src/Codeunits/CustomerMgt.Codeunit.al\",\n                \"CustomerMgt\",\n                \"Codeunit 50000 CustomerMgt\",\n            ),\n        ]\n\n        for symbols_path, hover_path, symbol_name, expected_injection in test_cases:\n            # Request symbols with one path format\n            symbols = language_server.request_document_symbols(symbols_path)\n\n            for sym in symbols.root_symbols:\n                if sym.get(\"name\") == symbol_name:\n                    sel_range = sym.get(\"selectionRange\", {})\n                    start = sel_range.get(\"start\", {})\n                    line = start.get(\"line\", 0)\n                    char = start.get(\"character\", 0)\n\n                    # Request hover with different path format\n                    hover = language_server.request_hover(hover_path, line, char)\n                    assert hover is not None, f\"Hover should return a result for {symbol_name}\"\n                    value = hover.get(\"contents\", {}).get(\"value\", \"\")\n                    assert (\n                        f\"**{expected_injection}**\" in value\n                    ), f\"Hover for {symbol_name} should have injection with mixed paths. Got: {value[:200]}\"\n                    break\n"
  },
  {
    "path": "test/solidlsp/ansible/__init__.py",
    "content": ""
  },
  {
    "path": "test/solidlsp/ansible/test_ansible_basic.py",
    "content": "\"\"\"\nBasic integration tests for the Ansible language server.\n\nThese tests validate initialization, hover, and completion capabilities\nusing the standard Ansible test repository. They work with the standard\n@ansible/ansible-language-server from npm.\n\"\"\"\n\nfrom pathlib import Path\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\n\n@pytest.mark.ansible\nclass TestAnsibleLanguageServerBasics:\n    \"\"\"Test basic Ansible language server functionality.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ANSIBLE], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.ANSIBLE], indirect=True)\n    def test_ls_is_running(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Language server starts and points to the correct repo.\"\"\"\n        assert language_server.is_running()\n        assert Path(language_server.language_server.repository_root_path).resolve() == repo_path.resolve()\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ANSIBLE], indirect=True)\n    def test_hover_on_module_contains_documentation(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Hover on ansible.builtin.package returns module documentation.\"\"\"\n        # playbook.yml line 10 (0-indexed): \"ansible.builtin.package:\"\n        result = language_server.request_hover(\"playbook.yml\", 10, 8)\n        assert result is not None, \"Expected hover info for ansible.builtin.package\"\n        hover_value = result[\"contents\"]\n        if isinstance(hover_value, dict):\n            hover_text = hover_value.get(\"value\", \"\")\n        elif isinstance(hover_value, list):\n            hover_text = \" \".join(str(v) for v in hover_value)\n        else:\n            hover_text = str(hover_value)\n        assert \"package\" in hover_text.lower(), f\"Hover should mention 'package', got: {hover_text[:300]}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ANSIBLE], indirect=True)\n    def test_completions_contain_module_names(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Completions at a task keyword position return Ansible module names.\"\"\"\n        # playbook.yml line 10 (0-indexed), col 6: inside a task block\n        result = language_server.request_completions(\"playbook.yml\", 10, 6)\n        assert result is not None, \"Expected completion results\"\n        assert len(result) > 0, \"Expected non-empty completion list\"\n        labels = [item[\"completionText\"] for item in result if \"completionText\" in item]\n        assert labels, f\"Expected completions with completionText, got: {result[:3]}\"\n"
  },
  {
    "path": "test/solidlsp/bash/__init__.py",
    "content": ""
  },
  {
    "path": "test/solidlsp/bash/test_bash_basic.py",
    "content": "\"\"\"\nBasic integration tests for the bash language server functionality.\n\nThese tests validate the functionality of the language server APIs\nlike request_document_symbols using the bash test repository.\n\"\"\"\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\n\n@pytest.mark.bash\nclass TestBashLanguageServerBasics:\n    \"\"\"Test basic functionality of the bash language server.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.BASH], indirect=True)\n    def test_bash_language_server_initialization(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that bash language server can be initialized successfully.\"\"\"\n        assert language_server is not None\n        assert language_server.language == Language.BASH\n\n    @pytest.mark.parametrize(\"language_server\", [Language.BASH], indirect=True)\n    def test_bash_request_document_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_document_symbols for bash files.\"\"\"\n        # Test getting symbols from main.sh\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"main.sh\").get_all_symbols_and_roots()\n\n        # Extract function symbols (LSP Symbol Kind 12)\n        function_symbols = [symbol for symbol in all_symbols if symbol.get(\"kind\") == 12]\n        function_names = [symbol[\"name\"] for symbol in function_symbols]\n\n        # Should detect all 3 functions from main.sh\n        assert \"greet_user\" in function_names, \"Should find greet_user function\"\n        assert \"process_items\" in function_names, \"Should find process_items function\"\n        assert \"main\" in function_names, \"Should find main function\"\n        assert len(function_symbols) >= 3, f\"Should find at least 3 functions, found {len(function_symbols)}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.BASH], indirect=True)\n    def test_bash_request_document_symbols_with_body(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_document_symbols with body extraction.\"\"\"\n        # Test with include_body=True\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"main.sh\").get_all_symbols_and_roots()\n\n        function_symbols = [symbol for symbol in all_symbols if symbol.get(\"kind\") == 12]\n\n        # Find greet_user function and check it has body\n        greet_user_symbol = next((sym for sym in function_symbols if sym[\"name\"] == \"greet_user\"), None)\n        assert greet_user_symbol is not None, \"Should find greet_user function\"\n\n        if \"body\" in greet_user_symbol:\n            body = greet_user_symbol[\"body\"].get_text()\n            assert \"function greet_user()\" in body, \"Function body should contain function definition\"\n            assert \"case\" in body.lower(), \"Function body should contain case statement\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.BASH], indirect=True)\n    def test_bash_utils_functions(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test function detection in utils.sh file.\"\"\"\n        # Test with utils.sh as well\n        utils_all_symbols, _utils_root_symbols = language_server.request_document_symbols(\"utils.sh\").get_all_symbols_and_roots()\n\n        utils_function_symbols = [symbol for symbol in utils_all_symbols if symbol.get(\"kind\") == 12]\n        utils_function_names = [symbol[\"name\"] for symbol in utils_function_symbols]\n\n        # Should detect functions from utils.sh\n        expected_utils_functions = [\n            \"to_uppercase\",\n            \"to_lowercase\",\n            \"trim_whitespace\",\n            \"backup_file\",\n            \"contains_element\",\n            \"log_message\",\n            \"is_valid_email\",\n            \"is_number\",\n        ]\n\n        for func_name in expected_utils_functions:\n            assert func_name in utils_function_names, f\"Should find {func_name} function in utils.sh\"\n\n        assert len(utils_function_symbols) >= 8, f\"Should find at least 8 functions in utils.sh, found {len(utils_function_symbols)}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.BASH], indirect=True)\n    def test_bash_function_syntax_patterns(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that LSP detects different bash function syntax patterns correctly.\"\"\"\n        # Test main.sh (has both 'function' keyword and traditional syntax)\n        main_all_symbols, _main_root_symbols = language_server.request_document_symbols(\"main.sh\").get_all_symbols_and_roots()\n        main_functions = [symbol for symbol in main_all_symbols if symbol.get(\"kind\") == 12]\n        main_function_names = [func[\"name\"] for func in main_functions]\n\n        # Test utils.sh (all use 'function' keyword)\n        utils_all_symbols, _utils_root_symbols = language_server.request_document_symbols(\"utils.sh\").get_all_symbols_and_roots()\n        utils_functions = [symbol for symbol in utils_all_symbols if symbol.get(\"kind\") == 12]\n        utils_function_names = [func[\"name\"] for func in utils_functions]\n\n        # Verify LSP detects both syntax patterns\n        # main() uses traditional syntax: main() {\n        assert \"main\" in main_function_names, \"LSP should detect traditional function syntax\"\n\n        # Functions with 'function' keyword: function name() {\n        assert \"greet_user\" in main_function_names, \"LSP should detect function keyword syntax\"\n        assert \"process_items\" in main_function_names, \"LSP should detect function keyword syntax\"\n\n        # Verify all expected utils functions are detected by LSP\n        expected_utils = [\n            \"to_uppercase\",\n            \"to_lowercase\",\n            \"trim_whitespace\",\n            \"backup_file\",\n            \"contains_element\",\n            \"log_message\",\n            \"is_valid_email\",\n            \"is_number\",\n        ]\n\n        for expected_func in expected_utils:\n            assert expected_func in utils_function_names, f\"LSP should detect {expected_func} function\"\n\n        # Verify total counts match expectations\n        assert len(main_functions) >= 3, f\"Should find at least 3 functions in main.sh, found {len(main_functions)}\"\n        assert len(utils_functions) >= 8, f\"Should find at least 8 functions in utils.sh, found {len(utils_functions)}\"\n"
  },
  {
    "path": "test/solidlsp/clojure/__init__.py",
    "content": "from pathlib import Path\n\nfrom solidlsp.language_servers.clojure_lsp import verify_clojure_cli\n\n\ndef _test_clojure_cli() -> bool:\n    try:\n        verify_clojure_cli()\n        return False\n    except (FileNotFoundError, RuntimeError):\n        return True\n\n\nCLI_FAIL = _test_clojure_cli()\nTEST_APP_PATH = Path(\"src\") / \"test_app\"\nCORE_PATH = str(TEST_APP_PATH / \"core.clj\")\nUTILS_PATH = str(TEST_APP_PATH / \"utils.clj\")\n\n\ndef is_clojure_cli_available() -> bool:\n    return not CLI_FAIL\n"
  },
  {
    "path": "test/solidlsp/clojure/test_clojure_basic.py",
    "content": "import pytest\n\nfrom serena.project import Project\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_types import UnifiedSymbolInformation\nfrom test.conftest import language_tests_enabled\n\nfrom . import CORE_PATH, UTILS_PATH\n\n\n@pytest.mark.skipif(not language_tests_enabled(Language.CLOJURE), reason=\"Clojure tests are disabled\")\n@pytest.mark.clojure\nclass TestLanguageServerBasics:\n    @pytest.mark.parametrize(\"language_server\", [Language.CLOJURE], indirect=True)\n    def test_basic_definition(self, language_server: SolidLanguageServer):\n        \"\"\"\n        Test finding definition of 'greet' function call in core.clj\n        \"\"\"\n        result = language_server.request_definition(CORE_PATH, 20, 12)  # Position of 'greet' in (greet \"World\")\n\n        assert isinstance(result, list)\n        assert len(result) >= 1\n\n        definition = result[0]\n        assert definition[\"relativePath\"] == CORE_PATH\n        assert definition[\"range\"][\"start\"][\"line\"] == 2, \"Should find the definition of greet function at line 2\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.CLOJURE], indirect=True)\n    def test_cross_file_references(self, language_server: SolidLanguageServer):\n        \"\"\"\n        Test finding references to 'multiply' function from core.clj\n        \"\"\"\n        result = language_server.request_references(CORE_PATH, 12, 6)\n\n        assert isinstance(result, list) and len(result) >= 2, \"Should find definition + usage in utils.clj\"\n\n        usage_found = any(\n            item[\"relativePath\"] == UTILS_PATH and item[\"range\"][\"start\"][\"line\"] == 6  # multiply usage in calculate-area\n            for item in result\n        )\n        assert usage_found, \"Should find multiply usage in utils.clj\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.CLOJURE], indirect=True)\n    def test_completions(self, language_server: SolidLanguageServer):\n        with language_server.open_file(UTILS_PATH):\n            # After \"core/\" in calculate-area\n            result = language_server.request_completions(UTILS_PATH, 6, 8)\n\n            assert isinstance(result, list) and len(result) > 0\n\n            completion_texts = [item[\"completionText\"] for item in result]\n            assert any(\"multiply\" in text for text in completion_texts), \"Should find 'multiply' function in completions after 'core/'\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.CLOJURE], indirect=True)\n    def test_document_symbols(self, language_server: SolidLanguageServer):\n        symbols, _ = language_server.request_document_symbols(CORE_PATH).get_all_symbols_and_roots()\n\n        assert isinstance(symbols, list) and len(symbols) >= 4, \"greet, add, multiply, -main functions\"\n\n        # Check that we find the expected function symbols\n        symbol_names = [symbol[\"name\"] for symbol in symbols]\n        expected_functions = [\"greet\", \"add\", \"multiply\", \"-main\"]\n\n        for func_name in expected_functions:\n            assert func_name in symbol_names, f\"Should find {func_name} function in symbols\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.CLOJURE], indirect=True)\n    def test_hover(self, language_server: SolidLanguageServer):\n        \"\"\"Test hover on greet function\"\"\"\n        result = language_server.request_hover(CORE_PATH, 2, 7)\n\n        assert result is not None, \"Hover should return information for greet function\"\n        assert \"contents\" in result\n        # Should contain function signature or documentation\n        contents = result[\"contents\"]\n        if isinstance(contents, str):\n            assert \"greet\" in contents.lower()\n        elif isinstance(contents, dict) and \"value\" in contents:\n            assert \"greet\" in contents[\"value\"].lower()\n        else:\n            assert False, f\"Unexpected contents format: {type(contents)}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.CLOJURE], indirect=True)\n    def test_workspace_symbols(self, language_server: SolidLanguageServer):\n        # Search for functions containing \"add\"\n        result = language_server.request_workspace_symbol(\"add\")\n\n        assert isinstance(result, list) and len(result) > 0, \"Should find at least one symbol containing 'add'\"\n\n        # Should find the 'add' function\n        symbol_names = [symbol[\"name\"] for symbol in result]\n        assert any(\"add\" in name.lower() for name in symbol_names), f\"Should find 'add' function in symbols: {symbol_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.CLOJURE], indirect=True)\n    def test_namespace_functions(self, language_server: SolidLanguageServer):\n        \"\"\"Test definition lookup for core/greet usage in utils.clj\"\"\"\n        # Position of 'greet' in core/greet call\n        result = language_server.request_definition(UTILS_PATH, 11, 25)\n\n        assert isinstance(result, list)\n        assert len(result) >= 1\n\n        definition = result[0]\n        assert definition[\"relativePath\"] == CORE_PATH, \"Should find the definition of greet in core.clj\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.CLOJURE], indirect=True)\n    def test_request_references_with_content(self, language_server: SolidLanguageServer):\n        \"\"\"Test references to multiply function with content\"\"\"\n        references = language_server.request_references(CORE_PATH, 12, 6)\n        result = [\n            language_server.retrieve_content_around_line(ref1[\"relativePath\"], ref1[\"range\"][\"start\"][\"line\"], 3, 0) for ref1 in references\n        ]\n\n        assert result is not None, \"Should find references with content\"\n        assert isinstance(result, list)\n        assert len(result) >= 2, \"Should find definition + usage in utils.clj\"\n\n        for ref in result:\n            assert ref.source_file_path is not None, \"Each reference should have a source file path\"\n            content_str = ref.to_display_string()\n            assert len(content_str) > 0, \"Content should not be empty\"\n\n        # Verify we find the reference in utils.clj with context\n        utils_refs = [ref for ref in result if ref.source_file_path and \"utils.clj\" in ref.source_file_path]\n        assert len(utils_refs) > 0, \"Should find reference in utils.clj\"\n\n        # The context should contain the calculate-area function\n        utils_content = utils_refs[0].to_display_string()\n        assert \"calculate-area\" in utils_content\n\n    @pytest.mark.parametrize(\"language_server\", [Language.CLOJURE], indirect=True)\n    def test_request_full_symbol_tree(self, language_server: SolidLanguageServer):\n        \"\"\"Test retrieving the full symbol tree for project overview\n        We just check that we find some expected symbols.\n        \"\"\"\n        result = language_server.request_full_symbol_tree()\n\n        assert result is not None, \"Should return symbol tree\"\n        assert isinstance(result, list), \"Symbol tree should be a list\"\n        assert len(result) > 0, \"Should find symbols in the project\"\n\n        def traverse_symbols(symbols, indent=0):\n            \"\"\"Recursively traverse symbols to print their structure\"\"\"\n            info = []\n            for s in symbols:\n                name = getattr(s, \"name\", \"NO_NAME\")\n                kind = getattr(s, \"kind\", \"NO_KIND\")\n                info.append(f\"{' ' * indent}Symbol: {name}, Kind: {kind}\")\n                if hasattr(s, \"children\") and s.children:\n                    info.append(\" \" * indent + \"Children:\")\n                    info.extend(traverse_symbols(s.children, indent + 2))\n            return info\n\n        def list_all_symbols(symbols: list[UnifiedSymbolInformation]):\n            found = []\n            for symbol in symbols:\n                found.append(symbol[\"name\"])\n                found.extend(list_all_symbols(symbol[\"children\"]))\n            return found\n\n        all_symbol_names = list_all_symbols(result)\n\n        expected_symbols = [\"greet\", \"add\", \"multiply\", \"-main\", \"calculate-area\", \"format-greeting\", \"sum-list\"]\n        found_expected = [name for name in expected_symbols if any(name in symbol_name for symbol_name in all_symbol_names)]\n\n        if len(found_expected) < 7:\n            pytest.fail(\n                f\"Expected to find at least 3 symbols from {expected_symbols}, but found: {found_expected}.\\n\"\n                f\"All symbol names: {all_symbol_names}\\n\"\n                f\"Symbol tree structure:\\n{traverse_symbols(result)}\"\n            )\n\n    @pytest.mark.parametrize(\"language_server\", [Language.CLOJURE], indirect=True)\n    def test_request_referencing_symbols(self, language_server: SolidLanguageServer):\n        \"\"\"Test finding symbols that reference a given symbol\n        Finds references to the 'multiply' function.\n        \"\"\"\n        result = language_server.request_referencing_symbols(CORE_PATH, 12, 6)\n        assert isinstance(result, list) and len(result) > 0, \"Should find at least one referencing symbol\"\n        found_relevant_references = False\n        for ref in result:\n            if hasattr(ref, \"symbol\") and \"calculate-area\" in ref.symbol[\"name\"]:\n                found_relevant_references = True\n                break\n\n        assert found_relevant_references, f\"Should have found calculate-area referencing multiply, but got: {result}\"\n\n\nclass TestProjectBasics:\n    @pytest.mark.parametrize(\"project\", [Language.CLOJURE], indirect=True)\n    def test_retrieve_content_around_line(self, project: Project):\n        \"\"\"Test retrieving content around specific lines\"\"\"\n        # Test retrieving content around the greet function definition (line 2)\n        result = project.retrieve_content_around_line(CORE_PATH, 2, 2)\n\n        assert result is not None, \"Should retrieve content around line 2\"\n        content_str = result.to_display_string()\n        assert \"greet\" in content_str, \"Should contain the greet function definition\"\n        assert \"defn\" in content_str, \"Should contain defn keyword\"\n\n        # Test retrieving content around multiply function (around line 13)\n        result = project.retrieve_content_around_line(CORE_PATH, 13, 1)\n\n        assert result is not None, \"Should retrieve content around line 13\"\n        content_str = result.to_display_string()\n        assert \"multiply\" in content_str, \"Should contain multiply function\"\n\n    @pytest.mark.parametrize(\"project\", [Language.CLOJURE], indirect=True)\n    def test_search_files_for_pattern(self, project: Project) -> None:\n        result = project.search_source_files_for_pattern(\"defn.*greet\")\n\n        assert result is not None, \"Pattern search should return results\"\n        assert len(result) > 0, \"Should find at least one match for 'defn.*greet'\"\n\n        core_matches = [match for match in result if match.source_file_path and \"core.clj\" in match.source_file_path]\n        assert len(core_matches) > 0, \"Should find greet function in core.clj\"\n\n        result = project.search_source_files_for_pattern(\":require\")\n\n        assert result is not None, \"Should find require statements\"\n        utils_matches = [match for match in result if match.source_file_path and \"utils.clj\" in match.source_file_path]\n        assert len(utils_matches) > 0, \"Should find require statement in utils.clj\"\n"
  },
  {
    "path": "test/solidlsp/cpp/__init__.py",
    "content": ""
  },
  {
    "path": "test/solidlsp/cpp/test_cpp_basic.py",
    "content": "\"\"\"\nBasic tests for C/C++ language server integration (clangd and ccls).\n\nThis module tests both Language.CPP (clangd) and Language.CPP_CCLS (ccls)\nusing the same test repository. Tests are skipped if the respective language\nserver is not available.\n\"\"\"\n\nimport os\nimport pathlib\nimport shutil\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_utils import SymbolUtils\n\n\ndef _ccls_available() -> bool:\n    return shutil.which(\"ccls\") is not None\n\n\n_cpp_servers: list[Language] = [Language.CPP]\nif _ccls_available():\n    _cpp_servers.append(Language.CPP_CCLS)\n\n\n@pytest.mark.cpp\n@pytest.mark.skipif(not _cpp_servers, reason=\"No C++ language server (clangd or ccls) available\")\nclass TestCppLanguageServer:\n    \"\"\"Tests for C/C++ language servers (clangd and ccls).\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", _cpp_servers, indirect=True)\n    def test_find_symbol(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that symbol tree contains expected functions.\"\"\"\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"add\"), \"Function 'add' not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"main\"), \"Function 'main' not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", _cpp_servers, indirect=True)\n    def test_get_document_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test document symbols for a.cpp.\"\"\"\n        file_path = os.path.join(\"a.cpp\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        # Flatten nested structure if needed\n        symbol_list = symbols[0] if symbols and isinstance(symbols[0], list) else symbols\n        names = [s.get(\"name\") for s in symbol_list]\n        assert \"main\" in names, f\"Expected 'main' in document symbols, got: {names}\"\n\n    @pytest.mark.parametrize(\"language_server\", _cpp_servers, indirect=True)\n    def test_find_referencing_symbols_across_files(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding references to 'add' function across files.\"\"\"\n        # Locate 'add' in b.cpp\n        file_path = os.path.join(\"b.cpp\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        symbol_list = symbols[0] if symbols and isinstance(symbols[0], list) else symbols\n        add_symbol = None\n        for sym in symbol_list:\n            if sym.get(\"name\") == \"add\":\n                add_symbol = sym\n                break\n        assert add_symbol is not None, \"Could not find 'add' function symbol in b.cpp\"\n\n        sel_start = add_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        ref_files = [ref.get(\"relativePath\", \"\") for ref in refs]\n        assert any(\"a.cpp\" in ref_file for ref_file in ref_files), f\"Should find reference in a.cpp, {refs=}\"\n\n        # Verify second call returns same results (stability check)\n        def _ref_key(ref: dict) -> tuple:\n            rp = ref.get(\"relativePath\", \"\")\n            rng = ref.get(\"range\") or {}\n            s = rng.get(\"start\") or {}\n            e = rng.get(\"end\") or {}\n            return (\n                rp,\n                s.get(\"line\", -1),\n                s.get(\"character\", -1),\n                e.get(\"line\", -1),\n                e.get(\"character\", -1),\n            )\n\n        refs2 = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        assert sorted(map(_ref_key, refs2)) == sorted(map(_ref_key, refs)), \"Reference results should be stable across calls\"\n\n    @pytest.mark.parametrize(\"language_server\", _cpp_servers, indirect=True)\n    @pytest.mark.xfail(\n        strict=True,\n        reason=(\"Both clangd and ccls do not support cross-file references for newly created files that were never opened by the LS.\"),\n    )\n    def test_find_references_in_newly_written_file(self, language_server: SolidLanguageServer) -> None:\n        # Create a new file that references the 'add' function from b.cpp\n        new_file_path = os.path.join(\"temp_new_file.cpp\")\n        new_file_abs_path = os.path.join(language_server.repository_root_path, new_file_path)\n\n        try:\n            # Write the new file with a reference to add()\n            with open(new_file_abs_path, \"w\", encoding=\"utf-8\") as f:\n                f.write(\n                    \"\"\"\n#include \"b.hpp\"\n\nint use_add() {\n    int result = add(5, 3);\n    return result;\n}\n\"\"\"\n                )\n\n            # Open the new file so clangd knows about it\n            with language_server.open_file(new_file_path):\n                # Request document symbols to ensure the file is fully loaded by clangd\n                new_file_symbols = language_server.request_document_symbols(new_file_path).get_all_symbols_and_roots()\n                assert new_file_symbols, \"New file should have symbols\"\n\n            # Verify the file stays in open_file_buffers after the context exits\n            uri = pathlib.Path(new_file_abs_path).as_uri()\n            assert uri in language_server.open_file_buffers, \"File should remain in open_file_buffers\"\n\n            # Find the 'add' symbol in b.cpp\n            b_file_path = os.path.join(\"b.cpp\")\n            symbols = language_server.request_document_symbols(b_file_path).get_all_symbols_and_roots()\n            symbol_list = symbols[0] if symbols and isinstance(symbols[0], list) else symbols\n            add_symbol = None\n            for sym in symbol_list:\n                if sym.get(\"name\") == \"add\":\n                    add_symbol = sym\n                    break\n            assert add_symbol is not None, \"Could not find 'add' function symbol in b.cpp\"\n\n            # Request references for 'add'\n            sel_start = add_symbol[\"selectionRange\"][\"start\"]\n            refs = language_server.request_references(b_file_path, sel_start[\"line\"], sel_start[\"character\"])\n            ref_files = [ref.get(\"relativePath\", \"\") for ref in refs]\n\n            # Should find reference in the newly written file\n            assert any(\n                \"temp_new_file.cpp\" in ref_file for ref_file in ref_files\n            ), f\"Should find reference in newly written temp_new_file.cpp, {ref_files=}\"\n        finally:\n            # Clean up the new file\n            if os.path.exists(new_file_abs_path):\n                os.remove(new_file_abs_path)\n"
  },
  {
    "path": "test/solidlsp/csharp/test_csharp_basic.py",
    "content": "import os\nimport tempfile\nfrom pathlib import Path\nfrom typing import cast\nfrom unittest.mock import Mock, patch\n\nimport pytest\nfrom sensai.util import logging\n\nfrom serena.util.logging import SuspendedLoggersContext\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.language_servers.csharp_language_server import (\n    CSharpLanguageServer,\n    breadth_first_file_scan,\n    find_solution_or_project_file,\n)\nfrom solidlsp.ls_config import Language, LanguageServerConfig\nfrom solidlsp.ls_utils import SymbolUtils\nfrom solidlsp.settings import SolidLSPSettings\n\n\n@pytest.mark.csharp\nclass TestCSharpLanguageServer:\n    @pytest.mark.parametrize(\"language_server\", [Language.CSHARP], indirect=True)\n    def test_find_symbol(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding symbols in the full symbol tree.\"\"\"\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Program\"), \"Program class not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Calculator\"), \"Calculator class not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Add\"), \"Add method not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.CSHARP], indirect=True)\n    def test_get_document_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test getting document symbols from a C# file.\"\"\"\n        file_path = os.path.join(\"Program.cs\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Check that we have symbols\n        assert len(symbols) > 0\n\n        # Flatten the symbols if they're nested\n        if isinstance(symbols[0], list):\n            symbols = symbols[0]\n\n        # Look for expected classes\n        class_names = [s.get(\"name\") for s in symbols if s.get(\"kind\") == 5]  # 5 is class\n        assert \"Program\" in class_names\n        assert \"Calculator\" in class_names\n\n    @pytest.mark.parametrize(\"language_server\", [Language.CSHARP], indirect=True)\n    def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding references using symbol selection range.\"\"\"\n        file_path = os.path.join(\"Program.cs\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        add_symbol = None\n        # Handle nested symbol structure\n        symbol_list = symbols[0] if symbols and isinstance(symbols[0], list) else symbols\n        for sym in symbol_list:\n            # Symbol names are normalized to base form (e.g., \"Add\" not \"Add(int, int) : int\")\n            if sym.get(\"name\") == \"Add\":\n                add_symbol = sym\n                break\n        assert add_symbol is not None, \"Could not find 'Add' method symbol in Program.cs\"\n        sel_start = add_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"] + 1)\n        assert any(\n            \"Program.cs\" in ref.get(\"relativePath\", \"\") for ref in refs\n        ), \"Program.cs should reference Add method (tried all positions in selectionRange)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.CSHARP], indirect=True)\n    def test_nested_namespace_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test getting symbols from nested namespace.\"\"\"\n        file_path = os.path.join(\"Models\", \"Person.cs\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Check that we have symbols\n        assert len(symbols) > 0\n\n        # Flatten the symbols if they're nested\n        if isinstance(symbols[0], list):\n            symbols = symbols[0]\n\n        # Check that we have the Person class\n        assert any(s.get(\"name\") == \"Person\" and s.get(\"kind\") == 5 for s in symbols)\n\n        # Check for properties and methods (names are normalized to base form)\n        symbol_names = [s.get(\"name\") for s in symbols]\n        assert \"Name\" in symbol_names, \"Name property not found\"\n        assert \"Age\" in symbol_names, \"Age property not found\"\n        assert \"Email\" in symbol_names, \"Email property not found\"\n        assert \"ToString\" in symbol_names, \"ToString method not found\"\n        assert \"IsAdult\" in symbol_names, \"IsAdult method not found\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.CSHARP], indirect=True)\n    def test_find_referencing_symbols_across_files(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding references to Calculator.Subtract method across files.\"\"\"\n        # First, find the Subtract method in Program.cs\n        file_path = os.path.join(\"Program.cs\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Flatten the symbols if they're nested\n        symbol_list = symbols[0] if symbols and isinstance(symbols[0], list) else symbols\n\n        subtract_symbol = None\n        for sym in symbol_list:\n            # Symbol names are normalized to base form (e.g., \"Subtract\" not \"Subtract(int, int) : int\")\n            if sym.get(\"name\") == \"Subtract\":\n                subtract_symbol = sym\n                break\n\n        assert subtract_symbol is not None, \"Could not find 'Subtract' method symbol in Program.cs\"\n\n        # Get references to the Subtract method\n        sel_start = subtract_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"] + 1)\n\n        # Should find references where the method is called\n        ref_files = cast(list[str], [ref.get(\"relativePath\", \"\") for ref in refs])\n        print(f\"Found references: {refs}\")\n        print(f\"Reference files: {ref_files}\")\n\n        # Check that we have reference in Models/Person.cs where Calculator.Subtract is called\n        # Note: New Roslyn version doesn't include the definition itself as a reference (more correct behavior)\n        assert any(\n            os.path.join(\"Models\", \"Person.cs\") in ref_file for ref_file in ref_files\n        ), \"Should find reference in Models/Person.cs where Calculator.Subtract is called\"\n        assert len(refs) > 0, \"Should find at least one reference\"\n\n        # check for a second time, since the first call may trigger initialization and change the state of the LS\n        refs_second_call = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"] + 1)\n        assert refs_second_call == refs, \"Second call to request_references should return the same results\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.CSHARP], indirect=True)\n    def test_hover_includes_type_information(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that hover information is available and includes type information.\"\"\"\n        file_path = os.path.join(\"Models\", \"Person.cs\")\n\n        # Open the file first\n        language_server.open_file(file_path)\n\n        # Test 1: Hover over the Name property (line 6, column 23 - on \"Name\")\n        # Source: public string Name { get; set; }\n        hover_info = language_server.request_hover(file_path, 6, 23)\n\n        # Verify hover returns content\n        assert hover_info is not None, \"Hover should return information for Name property\"\n        assert isinstance(hover_info, dict), \"Hover should be a dict\"\n        assert \"contents\" in hover_info, \"Hover should have contents\"\n\n        contents = hover_info[\"contents\"]\n        assert isinstance(contents, dict), \"Hover contents should be a dict\"\n        assert \"value\" in contents, \"Hover contents should have value\"\n        hover_text = contents[\"value\"]\n\n        # Verify the hover contains property signature with type\n        assert \"string\" in hover_text, f\"Hover should include 'string' type, got: {hover_text}\"\n        assert \"Name\" in hover_text, f\"Hover should include 'Name' property name, got: {hover_text}\"\n\n        # Test 2: Hover over the IsAdult method (line 22, column 21 - on \"IsAdult\")\n        # Source: public bool IsAdult()\n        hover_method = language_server.request_hover(file_path, 22, 21)\n\n        # Verify method hover returns content\n        assert hover_method is not None, \"Hover should return information for IsAdult method\"\n        assert isinstance(hover_method, dict), \"Hover should be a dict\"\n        assert \"contents\" in hover_method, \"Hover should have contents\"\n\n        contents = hover_method[\"contents\"]\n        assert isinstance(contents, dict), \"Hover contents should be a dict\"\n        assert \"value\" in contents, \"Hover contents should have value\"\n        method_hover_text = contents[\"value\"]\n\n        # Verify the hover contains method signature with return type\n        assert \"bool\" in method_hover_text, f\"Hover should include 'bool' return type, got: {method_hover_text}\"\n        assert \"IsAdult\" in method_hover_text, f\"Hover should include 'IsAdult' method name, got: {method_hover_text}\"\n\n\n@pytest.mark.csharp\nclass TestCSharpSolutionProjectOpening:\n    \"\"\"Test C# language server solution and project opening functionality.\"\"\"\n\n    def test_breadth_first_file_scan(self):\n        \"\"\"Test that breadth_first_file_scan finds files in breadth-first order.\"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            temp_path = Path(temp_dir)\n\n            # Create test directory structure\n            (temp_path / \"file1.txt\").touch()\n            (temp_path / \"subdir1\").mkdir()\n            (temp_path / \"subdir1\" / \"file2.txt\").touch()\n            (temp_path / \"subdir2\").mkdir()\n            (temp_path / \"subdir2\" / \"file3.txt\").touch()\n            (temp_path / \"subdir1\" / \"subdir3\").mkdir()\n            (temp_path / \"subdir1\" / \"subdir3\" / \"file4.txt\").touch()\n\n            # Scan files\n            files = list(breadth_first_file_scan(str(temp_path)))\n            filenames = [os.path.basename(f) for f in files]\n\n            # Should find all files\n            assert len(files) == 4\n            assert \"file1.txt\" in filenames\n            assert \"file2.txt\" in filenames\n            assert \"file3.txt\" in filenames\n            assert \"file4.txt\" in filenames\n\n            # file1.txt should be found first (breadth-first)\n            assert filenames[0] == \"file1.txt\"\n\n    def test_find_solution_or_project_file_with_solution(self):\n        \"\"\"Test that find_solution_or_project_file prefers .sln files.\"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            temp_path = Path(temp_dir)\n\n            # Create both .sln and .csproj files\n            solution_file = temp_path / \"MySolution.sln\"\n            project_file = temp_path / \"MyProject.csproj\"\n            solution_file.touch()\n            project_file.touch()\n\n            result = find_solution_or_project_file(str(temp_path))\n\n            # Should prefer .sln file\n            assert result == str(solution_file)\n\n    def test_find_solution_or_project_file_with_project_only(self):\n        \"\"\"Test that find_solution_or_project_file falls back to .csproj files.\"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            temp_path = Path(temp_dir)\n\n            # Create only .csproj file\n            project_file = temp_path / \"MyProject.csproj\"\n            project_file.touch()\n\n            result = find_solution_or_project_file(str(temp_path))\n\n            # Should return .csproj file\n            assert result == str(project_file)\n\n    def test_find_solution_or_project_file_with_nested_files(self):\n        \"\"\"Test that find_solution_or_project_file finds files in subdirectories.\"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            temp_path = Path(temp_dir)\n\n            # Create nested structure\n            (temp_path / \"src\").mkdir()\n            solution_file = temp_path / \"src\" / \"MySolution.sln\"\n            solution_file.touch()\n\n            result = find_solution_or_project_file(str(temp_path))\n\n            # Should find nested .sln file\n            assert result == str(solution_file)\n\n    def test_find_solution_or_project_file_returns_none_when_no_files(self):\n        \"\"\"Test that find_solution_or_project_file returns None when no .sln or .csproj files exist.\"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            temp_path = Path(temp_dir)\n\n            # Create some other files\n            (temp_path / \"readme.txt\").touch()\n            (temp_path / \"other.cs\").touch()\n\n            result = find_solution_or_project_file(str(temp_path))\n\n            # Should return None\n            assert result is None\n\n    def test_find_solution_or_project_file_prefers_solution_breadth_first(self):\n        \"\"\"Test that solution files are preferred even when deeper in the tree.\"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            temp_path = Path(temp_dir)\n\n            # Create .csproj at root and .sln in subdirectory\n            project_file = temp_path / \"MyProject.csproj\"\n            project_file.touch()\n\n            (temp_path / \"src\").mkdir()\n            solution_file = temp_path / \"src\" / \"MySolution.sln\"\n            solution_file.touch()\n\n            result = find_solution_or_project_file(str(temp_path))\n\n            # Should still prefer .sln file even though it's deeper\n            assert result == str(solution_file)\n\n    @patch(\"solidlsp.language_servers.csharp_language_server.CSharpLanguageServer.DependencyProvider._ensure_server_installed\")\n    @patch(\"solidlsp.language_servers.csharp_language_server.CSharpLanguageServer._start_server\")\n    def test_csharp_language_server_logs_solution_discovery(self, mock_start_server, mock_ensure_server_installed):\n        \"\"\"Test that CSharpLanguageServer logs solution/project discovery during initialization.\"\"\"\n        mock_ensure_server_installed.return_value = (\"/usr/bin/dotnet\", \"/path/to/server.dll\")\n\n        # Create test directory with solution file\n        with tempfile.TemporaryDirectory() as temp_dir:\n            temp_path = Path(temp_dir)\n            solution_file = temp_path / \"TestSolution.sln\"\n            solution_file.touch()\n\n            mock_config = Mock(spec=LanguageServerConfig)\n            mock_config.ignored_paths = []\n\n            # Create CSharpLanguageServer instance\n            mock_settings = Mock(spec=SolidLSPSettings)\n            mock_settings.ls_resources_dir = \"/tmp/test_ls_resources\"\n            mock_settings.project_data_path = str(temp_path / \"project_data\")\n\n            with SuspendedLoggersContext():\n                logging.getLogger().setLevel(logging.DEBUG)\n                with logging.MemoryLoggerContext() as mem_log:\n                    CSharpLanguageServer(mock_config, str(temp_path), mock_settings)\n\n                    # Verify that logger was called with solution file discovery\n                    expected_log_msg = f\"Found solution/project file: {solution_file}\"\n                    assert expected_log_msg in mem_log.get_log()\n\n    @patch(\"solidlsp.language_servers.csharp_language_server.CSharpLanguageServer.DependencyProvider._ensure_server_installed\")\n    @patch(\"solidlsp.language_servers.csharp_language_server.CSharpLanguageServer._start_server\")\n    def test_csharp_language_server_logs_no_solution_warning(self, mock_start_server, mock_ensure_server_installed):\n        \"\"\"Test that CSharpLanguageServer logs warning when no solution/project files are found.\"\"\"\n        # Mock the server installation\n        mock_ensure_server_installed.return_value = (\"/usr/bin/dotnet\", \"/path/to/server.dll\")\n\n        # Create empty test directory\n        with tempfile.TemporaryDirectory() as temp_dir:\n            temp_path = Path(temp_dir)\n\n            # Mock logger to capture log messages\n            mock_config = Mock(spec=LanguageServerConfig)\n            mock_config.ignored_paths = []\n\n            mock_settings = Mock(spec=SolidLSPSettings)\n            mock_settings.ls_resources_dir = \"/tmp/test_ls_resources\"\n            mock_settings.project_data_path = str(temp_path / \"project_data\")\n\n            # Create CSharpLanguageServer instance\n            with SuspendedLoggersContext():\n                logging.getLogger().setLevel(logging.DEBUG)\n                with logging.MemoryLoggerContext() as mem_log:\n                    CSharpLanguageServer(mock_config, str(temp_path), mock_settings)\n\n                    # Verify that logger was called with warning about no solution/project files\n                    expected_log_msg = \"No .sln/.slnx or .csproj file found, language server will attempt auto-discovery\"\n                    assert expected_log_msg in mem_log.get_log()\n\n    def test_solution_and_project_opening_with_real_test_repo(self):\n        \"\"\"Test solution and project opening with the actual C# test repository.\"\"\"\n        # Get the C# test repo path\n        test_repo_path = Path(__file__).parent.parent.parent / \"resources\" / \"repos\" / \"csharp\" / \"test_repo\"\n\n        if not test_repo_path.exists():\n            pytest.skip(\"C# test repository not found\")\n\n        # Test solution/project discovery in the real test repo\n        result = find_solution_or_project_file(str(test_repo_path))\n\n        # Should find either .sln or .csproj file\n        assert result is not None\n        assert result.endswith((\".sln\", \".csproj\"))\n\n        # Verify the file actually exists\n        assert os.path.exists(result)\n"
  },
  {
    "path": "test/solidlsp/csharp/test_csharp_nuget_download.py",
    "content": "\"\"\"Tests for C# language server NuGet package download from NuGet.org.\"\"\"\n\nimport tempfile\nfrom unittest.mock import patch\n\nimport pytest\n\nfrom solidlsp.language_servers.common import RuntimeDependency\nfrom solidlsp.language_servers.csharp_language_server import CSharpLanguageServer\nfrom solidlsp.settings import SolidLSPSettings\n\n\n@pytest.mark.csharp\nclass TestNuGetOrgDownload:\n    \"\"\"Test downloading Roslyn language server packages from NuGet.org.\"\"\"\n\n    def test_download_nuget_package_uses_direct_url(self):\n        \"\"\"Test that _download_nuget_package uses the URL from RuntimeDependency directly.\"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            # Create a RuntimeDependency with a NuGet.org URL\n            test_dependency = RuntimeDependency(\n                id=\"TestPackage\",\n                description=\"Test package from NuGet.org\",\n                package_name=\"roslyn-language-server.linux-x64\",\n                package_version=\"5.5.0-2.26078.4\",\n                url=\"https://www.nuget.org/api/v2/package/roslyn-language-server.linux-x64/5.5.0-2.26078.4\",\n                platform_id=\"linux-x64\",\n                archive_type=\"nupkg\",\n                binary_name=\"Microsoft.CodeAnalysis.LanguageServer.dll\",\n                extract_path=\"content/LanguageServer/linux-x64\",\n            )\n\n            # Mock the dependency provider\n            mock_settings = SolidLSPSettings()\n            custom_settings = SolidLSPSettings.CustomLSSettings({})\n\n            dependency_provider = CSharpLanguageServer.DependencyProvider(\n                custom_settings=custom_settings,\n                ls_resources_dir=temp_dir,\n                solidlsp_settings=mock_settings,\n                repository_root_path=\"/fake/repo\",\n            )\n\n            # Mock urllib.request.urlretrieve to capture the URL being used\n            with patch(\"solidlsp.language_servers.csharp_language_server.urllib.request.urlretrieve\") as mock_retrieve:\n                with patch(\"solidlsp.language_servers.csharp_language_server.SafeZipExtractor\"):\n                    try:\n                        dependency_provider._download_nuget_package(test_dependency)\n                    except Exception:\n                        # Expected to fail since we're mocking, but we want to check the URL\n                        pass\n\n                    # Verify that urlretrieve was called with the NuGet.org URL\n                    assert mock_retrieve.called, \"urlretrieve should be called\"\n                    called_url = mock_retrieve.call_args[0][0]\n                    assert called_url == test_dependency.url, f\"Should use URL from RuntimeDependency: {test_dependency.url}\"\n                    assert \"nuget.org\" in called_url, \"Should use NuGet.org URL\"\n                    assert \"azure\" not in called_url.lower(), \"Should not use Azure feed\"\n\n    def test_runtime_dependencies_use_nuget_org_urls(self):\n        \"\"\"Test that _RUNTIME_DEPENDENCIES are configured with NuGet.org URLs.\"\"\"\n        from solidlsp.language_servers.csharp_language_server import _RUNTIME_DEPENDENCIES\n\n        # Check language server dependencies\n        lang_server_deps = [dep for dep in _RUNTIME_DEPENDENCIES if dep.id == \"CSharpLanguageServer\"]\n\n        assert len(lang_server_deps) == 6, \"Should have 6 language server platform variants\"\n\n        for dep in lang_server_deps:\n            # Verify package name uses roslyn-language-server\n            assert dep.package_name is not None, f\"Package name should be set for {dep.platform_id}\"\n            assert dep.package_name.startswith(\n                \"roslyn-language-server.\"\n            ), f\"Package name should start with 'roslyn-language-server.' but got: {dep.package_name}\"\n\n            # Verify version is the newer NuGet.org version\n            assert dep.package_version == \"5.5.0-2.26078.4\", f\"Should use NuGet.org version 5.5.0-2.26078.4, got: {dep.package_version}\"\n\n            # Verify URL points to NuGet.org\n            assert dep.url is not None, f\"URL should be set for {dep.platform_id}\"\n            assert \"nuget.org\" in dep.url, f\"URL should point to nuget.org, got: {dep.url}\"\n            assert \"azure\" not in dep.url.lower(), f\"URL should not point to Azure feed, got: {dep.url}\"\n\n    def test_download_method_does_not_call_azure_feed(self):\n        \"\"\"Test that the new download method does not attempt to access Azure feed.\"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            test_dependency = RuntimeDependency(\n                id=\"TestPackage\",\n                description=\"Test package\",\n                package_name=\"roslyn-language-server.linux-x64\",\n                package_version=\"5.5.0-2.26078.4\",\n                url=\"https://www.nuget.org/api/v2/package/roslyn-language-server.linux-x64/5.5.0-2.26078.4\",\n                platform_id=\"linux-x64\",\n                archive_type=\"nupkg\",\n                binary_name=\"test.dll\",\n            )\n\n            mock_settings = SolidLSPSettings()\n            custom_settings = SolidLSPSettings.CustomLSSettings({})\n\n            dependency_provider = CSharpLanguageServer.DependencyProvider(\n                custom_settings=custom_settings,\n                ls_resources_dir=temp_dir,\n                solidlsp_settings=mock_settings,\n                repository_root_path=\"/fake/repo\",\n            )\n\n            # Mock urllib.request.urlopen to track if Azure feed is accessed\n            with patch(\"solidlsp.language_servers.csharp_language_server.urllib.request.urlopen\") as mock_urlopen:\n                with patch(\"solidlsp.language_servers.csharp_language_server.urllib.request.urlretrieve\"):\n                    with patch(\"solidlsp.language_servers.csharp_language_server.SafeZipExtractor\"):\n                        try:\n                            dependency_provider._download_nuget_package(test_dependency)\n                        except Exception:\n                            pass\n\n                        # Verify that urlopen was NOT called (no service index lookup)\n                        assert not mock_urlopen.called, \"Should not call urlopen for Azure service index lookup\"\n"
  },
  {
    "path": "test/solidlsp/dart/__init__.py",
    "content": ""
  },
  {
    "path": "test/solidlsp/dart/test_dart_basic.py",
    "content": "import os\nfrom pathlib import Path\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_types import SymbolKind\nfrom solidlsp.ls_utils import SymbolUtils\n\n\n@pytest.mark.dart\nclass TestDartLanguageServer:\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.DART], indirect=True)\n    def test_ls_is_running(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that the language server starts and stops successfully.\"\"\"\n        # The fixture already handles start and stop\n        assert language_server.is_running()\n        assert Path(language_server.language_server.repository_root_path).resolve() == repo_path.resolve()\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.DART], indirect=True)\n    def test_find_definition_within_file(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test finding definition of a method within the same file.\"\"\"\n        # In lib/main.dart:\n        # Line 105: final result1 = calc.add(5, 3); // Reference to add method\n        # Line 12: int add(int a, int b) {        // Definition of add method\n        # Find definition of 'add' method from its usage\n        main_dart_path = str(repo_path / \"lib\" / \"main.dart\")\n\n        # Position: calc.add(5, 3) - cursor on 'add'\n        # Line 105 (1-indexed) = line 104 (0-indexed), char position around 22\n        definition_location_list = language_server.request_definition(main_dart_path, 104, 22)\n\n        assert definition_location_list, f\"Expected non-empty definition_location_list but got {definition_location_list=}\"\n        assert len(definition_location_list) >= 1\n        definition_location = definition_location_list[0]\n        assert definition_location[\"uri\"].endswith(\"main.dart\")\n        # Definition of add method should be around line 11 (0-indexed)\n        # But language server may return different positions\n        assert definition_location[\"range\"][\"start\"][\"line\"] >= 0\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.DART], indirect=True)\n    def test_find_definition_across_files(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test finding definition across different files.\"\"\"\n        # Test finding definition of MathHelper class which is in helper.dart\n        # In lib/main.dart line 50: MathHelper.power(step1, 2)\n        main_dart_path = str(repo_path / \"lib\" / \"main.dart\")\n\n        # Position: MathHelper.power(step1, 2) - cursor on 'MathHelper'\n        # Line 50 (1-indexed) = line 49 (0-indexed), char position around 18\n        definition_location_list = language_server.request_definition(main_dart_path, 49, 18)\n\n        # Skip the test if language server doesn't find cross-file references\n        # This is acceptable for a basic test - the important thing is that LS is working\n        if not definition_location_list:\n            pytest.skip(\"Language server doesn't support cross-file definition lookup for this case\")\n\n        assert len(definition_location_list) >= 1\n        definition_location = definition_location_list[0]\n        assert definition_location[\"uri\"].endswith(\"helper.dart\")\n        assert definition_location[\"range\"][\"start\"][\"line\"] >= 0\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.DART], indirect=True)\n    def test_find_definition_class_method(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test finding definition of a class method.\"\"\"\n        # In lib/main.dart:\n        # Line 50: final step2 = MathHelper.power(step1, 2); // Reference to MathHelper.power method\n        # In lib/helper.dart:\n        # Line 14: static double power(double base, int exponent) { // Definition of power method\n        main_dart_path = str(repo_path / \"lib\" / \"main.dart\")\n\n        # Position: MathHelper.power(step1, 2) - cursor on 'power'\n        # Line 50 (1-indexed) = line 49 (0-indexed), char position around 30\n        definition_location_list = language_server.request_definition(main_dart_path, 49, 30)\n\n        assert definition_location_list, f\"Expected non-empty definition_location_list but got {definition_location_list=}\"\n        assert len(definition_location_list) >= 1\n        definition_location = definition_location_list[0]\n        assert definition_location[\"uri\"].endswith(\"helper.dart\")\n        # Definition of power method should be around line 13 (0-indexed)\n        assert 12 <= definition_location[\"range\"][\"start\"][\"line\"] <= 16\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.DART], indirect=True)\n    def test_find_references_within_file(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test finding references to a method within the same file.\"\"\"\n        main_dart_path = str(repo_path / \"lib\" / \"main.dart\")\n\n        # Find references to the 'add' method from its definition\n        # Line 12: int add(int a, int b) { // Definition of add method\n        # Line 105: final result1 = calc.add(5, 3); // Usage of add method\n        references = language_server.request_references(main_dart_path, 11, 6)  # cursor on 'add' in definition\n\n        assert references, f\"Expected non-empty references but got {references=}\"\n        # Should find at least the usage of add method\n        assert len(references) >= 1\n\n        # Check that we have a reference in main.dart\n        main_dart_references = [ref for ref in references if ref[\"uri\"].endswith(\"main.dart\")]\n        assert len(main_dart_references) >= 1\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.DART], indirect=True)\n    def test_find_references_across_files(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test finding references across different files.\"\"\"\n        helper_dart_path = str(repo_path / \"lib\" / \"helper.dart\")\n\n        # Find references to the 'subtract' function from its definition in helper.dart\n        # Definition is in helper.dart, usage is in main.dart\n        references = language_server.request_references(helper_dart_path, 4, 4)  # cursor on 'subtract' in definition\n\n        assert references, f\"Expected non-empty references for subtract function but got {references=}\"\n\n        # Should find references in main.dart\n        main_dart_references = [ref for ref in references if ref[\"uri\"].endswith(\"main.dart\")]\n        assert len(main_dart_references) >= 1\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.DART], indirect=True)\n    def test_find_definition_constructor(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test finding definition of a constructor call.\"\"\"\n        main_dart_path = str(repo_path / \"lib\" / \"main.dart\")\n\n        # In lib/main.dart:\n        # Line 104: final calc = Calculator(); // Reference to Calculator constructor\n        # Line 4: class Calculator {          // Definition of Calculator class\n        definition_location_list = language_server.request_definition(main_dart_path, 103, 18)  # cursor on 'Calculator'\n\n        assert definition_location_list, f\"Expected non-empty definition_location_list but got {definition_location_list=}\"\n        assert len(definition_location_list) >= 1\n        definition_location = definition_location_list[0]\n        assert definition_location[\"uri\"].endswith(\"main.dart\")\n        # Definition of Calculator class should be around line 3 (0-indexed)\n        assert 3 <= definition_location[\"range\"][\"start\"][\"line\"] <= 7\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.DART], indirect=True)\n    def test_find_definition_import(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test finding definition through imports.\"\"\"\n        models_dart_path = str(repo_path / \"lib\" / \"models.dart\")\n\n        # Test finding definition of User class name where it's used\n        # In lib/models.dart line 27 (constructor): User(this.id, this.name, this.email, this._age);\n        definition_location_list = language_server.request_definition(models_dart_path, 26, 2)  # cursor on 'User' in constructor\n\n        # Skip if language server doesn't find definition in this case\n        if not definition_location_list:\n            pytest.skip(\"Language server doesn't support definition lookup for this case\")\n\n        assert len(definition_location_list) >= 1\n        definition_location = definition_location_list[0]\n        # Language server might return SDK files instead of local files\n        # This is acceptable behavior - the important thing is that it found a definition\n        assert \"dart\" in definition_location[\"uri\"].lower()\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    def test_find_symbol(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding symbols in the full symbol tree.\"\"\"\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Calculator\"), \"Calculator class not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"add\"), \"add method not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"subtract\"), \"subtract function not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"MathHelper\"), \"MathHelper class not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"User\"), \"User class not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding references using symbol selection range.\"\"\"\n        file_path = os.path.join(\"lib\", \"main.dart\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Handle nested symbol structure - symbols can be nested in lists\n        symbol_list = symbols[0] if symbols and isinstance(symbols[0], list) else symbols\n\n        # Find the 'add' method symbol in Calculator class\n        add_symbol = None\n        for sym in symbol_list:\n            if sym.get(\"name\") == \"add\":\n                add_symbol = sym\n                break\n            # Check for nested symbols (methods inside classes)\n            if \"children\" in sym and sym.get(\"name\") == \"Calculator\":\n                for child in sym[\"children\"]:\n                    if child.get(\"name\") == \"add\":\n                        add_symbol = child\n                        break\n                if add_symbol:\n                    break\n\n        assert add_symbol is not None, \"Could not find 'add' method symbol in main.dart\"\n        sel_start = add_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n\n        # Check that we found references - at least one should be in main.dart\n        assert any(\n            \"main.dart\" in ref.get(\"relativePath\", \"\") or \"main.dart\" in ref.get(\"uri\", \"\") for ref in refs\n        ), \"main.dart should reference add method (tried all positions in selectionRange)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    def test_request_containing_symbol_method(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol for a method.\"\"\"\n        file_path = os.path.join(\"lib\", \"main.dart\")\n        # Line 14 is inside the add method body (around 'final result = a + b;')\n        containing_symbol = language_server.request_containing_symbol(file_path, 13, 10, include_body=True)\n\n        # Verify that we found the containing symbol\n        if containing_symbol is not None:\n            assert containing_symbol[\"name\"] == \"add\"\n            assert containing_symbol[\"kind\"] == SymbolKind.Method\n            if \"body\" in containing_symbol:\n                body = containing_symbol[\"body\"].get_text()\n                assert \"add\" in body or \"final result\" in body\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    def test_request_containing_symbol_class(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol for a class.\"\"\"\n        file_path = os.path.join(\"lib\", \"main.dart\")\n        # Line 4 is the Calculator class definition line\n        containing_symbol = language_server.request_containing_symbol(file_path, 4, 6)\n\n        # Verify that we found the containing symbol\n        if containing_symbol is not None:\n            assert containing_symbol[\"name\"] == \"Calculator\"\n            assert containing_symbol[\"kind\"] == SymbolKind.Class\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    def test_request_containing_symbol_nested(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol with nested scopes.\"\"\"\n        file_path = os.path.join(\"lib\", \"main.dart\")\n        # Line 14 is inside the add method inside Calculator class\n        containing_symbol = language_server.request_containing_symbol(file_path, 13, 20)\n\n        # Verify that we found the innermost containing symbol (the method)\n        if containing_symbol is not None:\n            assert containing_symbol[\"name\"] == \"add\"\n            assert containing_symbol[\"kind\"] == SymbolKind.Method\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    def test_request_defining_symbol_variable(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a variable usage.\"\"\"\n        file_path = os.path.join(\"lib\", \"main.dart\")\n        # Line 14 contains 'final result = a + b;' - test position on 'result'\n        defining_symbol = language_server.request_defining_symbol(file_path, 13, 10)\n\n        # The defining symbol might be the variable itself or the containing method\n        # This is acceptable behavior - different language servers handle this differently\n        if defining_symbol is not None:\n            assert defining_symbol.get(\"name\") in [\"result\", \"add\"]\n            if defining_symbol.get(\"name\") == \"add\":\n                assert defining_symbol.get(\"kind\") == SymbolKind.Method.value\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    def test_request_defining_symbol_imported_class(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for an imported class/function.\"\"\"\n        file_path = os.path.join(\"lib\", \"main.dart\")\n        # Line 20 references 'subtract' which was imported from helper.dart\n        defining_symbol = language_server.request_defining_symbol(file_path, 19, 18)\n\n        # Verify that we found the defining symbol - this should be the subtract function from helper.dart\n        if defining_symbol is not None:\n            assert defining_symbol.get(\"name\") == \"subtract\"\n            # Could be Function or Method depending on language server interpretation\n            assert defining_symbol.get(\"kind\") in [SymbolKind.Function.value, SymbolKind.Method.value]\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    def test_request_defining_symbol_class_method(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a static class method.\"\"\"\n        file_path = os.path.join(\"lib\", \"main.dart\")\n        # Line 50 references MathHelper.power - test position on 'power'\n        defining_symbol = language_server.request_defining_symbol(file_path, 49, 30)\n\n        # Verify that we found the defining symbol - should be the power method\n        if defining_symbol is not None:\n            assert defining_symbol.get(\"name\") == \"power\"\n            assert defining_symbol.get(\"kind\") == SymbolKind.Method.value\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    def test_request_document_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test getting document symbols from a Dart file.\"\"\"\n        file_path = os.path.join(\"lib\", \"main.dart\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Check that we have symbols\n        assert len(symbols) > 0\n\n        # Flatten the symbols if they're nested\n        symbol_list = symbols[0] if symbols and isinstance(symbols[0], list) else symbols\n\n        # Look for expected classes and methods\n        symbol_names = [s.get(\"name\") for s in symbol_list]\n        assert \"Calculator\" in symbol_names\n\n        # Check for nested symbols (methods inside classes) - optional\n        calculator_symbol = next((s for s in symbol_list if s.get(\"name\") == \"Calculator\"), None)\n        if calculator_symbol and \"children\" in calculator_symbol and calculator_symbol[\"children\"]:\n            method_names = [child.get(\"name\") for child in calculator_symbol[\"children\"]]\n            # If children are populated, we should find the add method\n            assert \"add\" in method_names\n        else:\n            # Some language servers may not populate children in document symbols\n            # This is acceptable behavior - the important thing is we found the class\n            pass\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    def test_request_referencing_symbols_comprehensive(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test comprehensive referencing symbols functionality.\"\"\"\n        file_path = os.path.join(\"lib\", \"main.dart\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Handle nested symbol structure\n        symbol_list = symbols[0] if symbols and isinstance(symbols[0], list) else symbols\n\n        # Find Calculator class and test its references\n        calculator_symbol = None\n        for sym in symbol_list:\n            if sym.get(\"name\") == \"Calculator\":\n                calculator_symbol = sym\n                break\n\n        if calculator_symbol and \"selectionRange\" in calculator_symbol:\n            sel_start = calculator_symbol[\"selectionRange\"][\"start\"]\n            refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n\n            # Should find references to Calculator (constructor calls, etc.)\n            if refs:\n                # Verify the structure of referencing symbols\n                for ref in refs:\n                    assert \"uri\" in ref or \"relativePath\" in ref\n                    if \"range\" in ref:\n                        assert \"start\" in ref[\"range\"]\n                        assert \"end\" in ref[\"range\"]\n\n    @pytest.mark.parametrize(\"language_server\", [Language.DART], indirect=True)\n    def test_cross_file_symbol_resolution(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test symbol resolution across multiple files.\"\"\"\n        helper_file_path = os.path.join(\"lib\", \"helper.dart\")\n\n        # Test finding references to subtract function from helper.dart in main.dart\n        helper_symbols = language_server.request_document_symbols(helper_file_path).get_all_symbols_and_roots()\n        symbol_list = helper_symbols[0] if helper_symbols and isinstance(helper_symbols[0], list) else helper_symbols\n\n        subtract_symbol = next((s for s in symbol_list if s.get(\"name\") == \"subtract\"), None)\n\n        if subtract_symbol and \"selectionRange\" in subtract_symbol:\n            sel_start = subtract_symbol[\"selectionRange\"][\"start\"]\n            refs = language_server.request_references(helper_file_path, sel_start[\"line\"], sel_start[\"character\"])\n\n            # Should find references in main.dart\n            main_dart_refs = [ref for ref in refs if \"main.dart\" in ref.get(\"uri\", \"\") or \"main.dart\" in ref.get(\"relativePath\", \"\")]\n            # Note: This may not always work depending on language server capabilities\n            # So we don't assert - just verify the structure if we get results\n            if main_dart_refs:\n                for ref in main_dart_refs:\n                    assert \"range\" in ref or \"location\" in ref\n"
  },
  {
    "path": "test/solidlsp/elixir/__init__.py",
    "content": "def _test_expert_available() -> str:\n    \"\"\"Test if Expert is available and return error reason if not.\"\"\"\n    # Try to import and check Elixir availability\n    try:\n        from solidlsp.language_servers.elixir_tools.elixir_tools import ElixirTools\n\n        # Check if Elixir is installed\n        elixir_version = ElixirTools._get_elixir_version()\n        if not elixir_version:\n            return \"Elixir is not installed or not in PATH\"\n\n        return \"\"  # No error, Expert should be available\n\n    except ImportError as e:\n        return f\"Failed to import ElixirTools: {e}\"\n    except Exception as e:\n        return f\"Error checking Expert availability: {e}\"\n\n\nEXPERT_UNAVAILABLE_REASON = _test_expert_available()\nEXPERT_UNAVAILABLE = bool(EXPERT_UNAVAILABLE_REASON)\n"
  },
  {
    "path": "test/solidlsp/elixir/conftest.py",
    "content": "\"\"\"\nElixir-specific test configuration and fixtures.\n\"\"\"\n\nimport os\nimport subprocess\nimport time\nfrom pathlib import Path\n\nimport pytest\n\n\ndef ensure_elixir_test_repo_compiled(repo_path: str) -> None:\n    \"\"\"Ensure the Elixir test repository dependencies are installed and project is compiled.\n\n    Next LS requires the project to be fully compiled and indexed before providing\n    complete references and symbol resolution. This function:\n    1. Installs dependencies via 'mix deps.get'\n    2. Compiles the project via 'mix compile'\n\n    This is essential in CI environments where dependencies aren't pre-installed.\n\n    Args:\n        repo_path: Path to the Elixir project root directory\n\n    \"\"\"\n    # Check if this looks like an Elixir project\n    mix_file = os.path.join(repo_path, \"mix.exs\")\n    if not os.path.exists(mix_file):\n        return\n\n    # Check if already compiled (optimization for repeated runs)\n    build_path = os.path.join(repo_path, \"_build\")\n    deps_path = os.path.join(repo_path, \"deps\")\n\n    if os.path.exists(build_path) and os.path.exists(deps_path):\n        print(f\"Elixir test repository already compiled in {repo_path}\")\n        return\n\n    try:\n        print(\"Installing dependencies and compiling Elixir test repository for optimal Next LS performance...\")\n\n        # First, install dependencies with increased timeout for CI\n        print(\"=\" * 60)\n        print(\"Step 1/2: Installing Elixir dependencies...\")\n        print(\"=\" * 60)\n        start_time = time.time()\n\n        deps_result = subprocess.run(\n            [\"mix\", \"deps.get\"],\n            cwd=repo_path,\n            capture_output=True,\n            text=True,\n            timeout=180,\n            check=False,  # 3 minutes for dependency installation (CI can be slow)\n        )\n\n        deps_duration = time.time() - start_time\n        print(f\"Dependencies installation completed in {deps_duration:.2f} seconds\")\n\n        # Always log the output for transparency\n        if deps_result.stdout.strip():\n            print(\"Dependencies stdout:\")\n            print(\"-\" * 40)\n            print(deps_result.stdout)\n            print(\"-\" * 40)\n\n        if deps_result.stderr.strip():\n            print(\"Dependencies stderr:\")\n            print(\"-\" * 40)\n            print(deps_result.stderr)\n            print(\"-\" * 40)\n\n        if deps_result.returncode != 0:\n            print(f\"⚠️  Warning: Dependencies installation failed with exit code {deps_result.returncode}\")\n            # Continue anyway - some projects might not have dependencies\n        else:\n            print(\"✓ Dependencies installed successfully\")\n\n        # Then compile the project with increased timeout for CI\n        print(\"=\" * 60)\n        print(\"Step 2/2: Compiling Elixir project...\")\n        print(\"=\" * 60)\n        start_time = time.time()\n\n        compile_result = subprocess.run(\n            [\"mix\", \"compile\"],\n            cwd=repo_path,\n            capture_output=True,\n            text=True,\n            timeout=300,\n            check=False,  # 5 minutes for compilation (Credo compilation can be slow in CI)\n        )\n\n        compile_duration = time.time() - start_time\n        print(f\"Compilation completed in {compile_duration:.2f} seconds\")\n\n        # Always log the output for transparency\n        if compile_result.stdout.strip():\n            print(\"Compilation stdout:\")\n            print(\"-\" * 40)\n            print(compile_result.stdout)\n            print(\"-\" * 40)\n\n        if compile_result.stderr.strip():\n            print(\"Compilation stderr:\")\n            print(\"-\" * 40)\n            print(compile_result.stderr)\n            print(\"-\" * 40)\n\n        if compile_result.returncode == 0:\n            print(f\"✓ Elixir test repository compiled successfully in {repo_path}\")\n        else:\n            print(f\"⚠️  Warning: Compilation completed with exit code {compile_result.returncode}\")\n            # Still continue - warnings are often non-fatal\n\n        print(\"=\" * 60)\n        print(f\"Total setup time: {time.time() - (start_time - compile_duration - deps_duration):.2f} seconds\")\n        print(\"=\" * 60)\n\n    except subprocess.TimeoutExpired as e:\n        print(\"=\" * 60)\n        print(f\"❌ TIMEOUT: Elixir setup timed out after {e.timeout} seconds\")\n        print(f\"Command: {' '.join(e.cmd)}\")\n        print(\"This may indicate slow CI environment - Next LS may still work but with reduced functionality\")\n\n        # Try to get partial output if available\n        if hasattr(e, \"stdout\") and e.stdout:\n            print(\"Partial stdout before timeout:\")\n            print(\"-\" * 40)\n            print(e.stdout)\n            print(\"-\" * 40)\n        if hasattr(e, \"stderr\") and e.stderr:\n            print(\"Partial stderr before timeout:\")\n            print(\"-\" * 40)\n            print(e.stderr)\n            print(\"-\" * 40)\n        print(\"=\" * 60)\n\n    except FileNotFoundError:\n        print(\"❌ ERROR: 'mix' command not found - Elixir test repository may not be compiled\")\n        print(\"Please ensure Elixir is installed and available in PATH\")\n    except Exception as e:\n        print(f\"❌ ERROR: Failed to prepare Elixir test repository: {e}\")\n\n\n@pytest.fixture(scope=\"session\", autouse=True)\ndef setup_elixir_test_environment():\n    \"\"\"Automatically prepare Elixir test environment for all Elixir tests.\n\n    This fixture runs once per test session and automatically:\n    1. Installs dependencies via 'mix deps.get'\n    2. Compiles the Elixir test repository via 'mix compile'\n\n    It uses autouse=True so it runs automatically without needing to be explicitly\n    requested by tests. This ensures Next LS has a fully prepared project to work with.\n\n    Uses generous timeouts (3-5 minutes) to accommodate slow CI environments.\n    All output is logged for transparency and debugging.\n    \"\"\"\n    # Get the test repo path relative to this conftest.py file\n    test_repo_path = Path(__file__).parent.parent.parent / \"resources\" / \"repos\" / \"elixir\" / \"test_repo\"\n    ensure_elixir_test_repo_compiled(str(test_repo_path))\n    return str(test_repo_path)\n\n\n@pytest.fixture(scope=\"session\")\ndef elixir_test_repo_path(setup_elixir_test_environment):\n    \"\"\"Get the path to the prepared Elixir test repository.\n\n    This fixture depends on setup_elixir_test_environment to ensure dependencies\n    are installed and compilation has completed before returning the path.\n    \"\"\"\n    return setup_elixir_test_environment\n"
  },
  {
    "path": "test/solidlsp/elixir/test_elixir_basic.py",
    "content": "\"\"\"\nBasic integration tests for the Elixir language server functionality.\n\nThese tests validate the functionality of the language server APIs\nlike request_references using the test repository.\n\"\"\"\n\nimport os\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\nfrom . import EXPERT_UNAVAILABLE, EXPERT_UNAVAILABLE_REASON\n\n# These marks will be applied to all tests in this module\npytestmark = [pytest.mark.elixir, pytest.mark.skipif(EXPERT_UNAVAILABLE, reason=f\"Next LS not available: {EXPERT_UNAVAILABLE_REASON}\")]\n\n\nclass TestElixirBasic:\n    \"\"\"Basic Elixir language server functionality tests.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_request_references_function_definition(self, language_server: SolidLanguageServer):\n        \"\"\"Test finding references to a function definition.\"\"\"\n        file_path = os.path.join(\"lib\", \"models.ex\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Find the User module's 'new' function\n        user_new_symbol = None\n        for symbol in symbols[0]:  # Top level symbols\n            if symbol.get(\"name\") == \"User\" and symbol.get(\"kind\") == 2:  # Module\n                for child in symbol.get(\"children\", []):\n                    if child.get(\"name\", \"\").startswith(\"def new(\") and child.get(\"kind\") == 12:  # Function\n                        user_new_symbol = child\n                        break\n                break\n\n        if not user_new_symbol or \"selectionRange\" not in user_new_symbol:\n            pytest.skip(\"User.new function or its selectionRange not found\")\n\n        sel_start = user_new_symbol[\"selectionRange\"][\"start\"]\n        references = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n\n        assert references is not None\n        assert len(references) > 0\n\n        # Should find at least one reference (the definition itself)\n        found_definition = any(ref[\"uri\"].endswith(\"models.ex\") for ref in references)\n        assert found_definition, \"Should find the function definition\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_request_references_create_user_function(self, language_server: SolidLanguageServer):\n        \"\"\"Test finding references to create_user function.\"\"\"\n        file_path = os.path.join(\"lib\", \"services.ex\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Find the UserService module's 'create_user' function\n        create_user_symbol = None\n        for symbol in symbols[0]:  # Top level symbols\n            if symbol.get(\"name\") == \"UserService\" and symbol.get(\"kind\") == 2:  # Module\n                for child in symbol.get(\"children\", []):\n                    if child.get(\"name\", \"\").startswith(\"def create_user(\") and child.get(\"kind\") == 12:  # Function\n                        create_user_symbol = child\n                        break\n                break\n\n        if not create_user_symbol or \"selectionRange\" not in create_user_symbol:\n            pytest.skip(\"UserService.create_user function or its selectionRange not found\")\n\n        sel_start = create_user_symbol[\"selectionRange\"][\"start\"]\n        references = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n\n        assert references is not None\n        assert len(references) > 0\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_request_referencing_symbols_function(self, language_server: SolidLanguageServer):\n        \"\"\"Test finding symbols that reference a specific function.\"\"\"\n        file_path = os.path.join(\"lib\", \"models.ex\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Find the User module's 'new' function\n        user_new_symbol = None\n        for symbol in symbols[0]:  # Top level symbols\n            if symbol.get(\"name\") == \"User\" and symbol.get(\"kind\") == 2:  # Module\n                for child in symbol.get(\"children\", []):\n                    if child.get(\"name\", \"\").startswith(\"def new(\") and child.get(\"kind\") == 12:  # Function\n                        user_new_symbol = child\n                        break\n                break\n\n        if not user_new_symbol or \"selectionRange\" not in user_new_symbol:\n            pytest.skip(\"User.new function or its selectionRange not found\")\n\n        sel_start = user_new_symbol[\"selectionRange\"][\"start\"]\n        referencing_symbols = language_server.request_referencing_symbols(file_path, sel_start[\"line\"], sel_start[\"character\"])\n\n        assert referencing_symbols is not None\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_timeout_enumeration_bug(self, language_server: SolidLanguageServer):\n        \"\"\"Test that enumeration doesn't timeout (regression test).\"\"\"\n        # This should complete without timing out\n        symbols = language_server.request_document_symbols(\"lib/models.ex\").get_all_symbols_and_roots()\n        assert symbols is not None\n\n        # Test multiple symbol requests in succession\n        for _ in range(3):\n            symbols = language_server.request_document_symbols(\"lib/services.ex\").get_all_symbols_and_roots()\n            assert symbols is not None\n"
  },
  {
    "path": "test/solidlsp/elixir/test_elixir_ignored_dirs.py",
    "content": "import os\nfrom collections.abc import Generator\nfrom pathlib import Path\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom test.conftest import start_ls_context\n\nfrom . import EXPERT_UNAVAILABLE, EXPERT_UNAVAILABLE_REASON\n\n# These marks will be applied to all tests in this module\npytestmark = [pytest.mark.elixir, pytest.mark.skipif(EXPERT_UNAVAILABLE, reason=f\"Expert not available: {EXPERT_UNAVAILABLE_REASON}\")]\n\n# Skip slow tests in CI - they require multiple Expert instances which is too slow\nIN_CI = bool(os.environ.get(\"CI\") or os.environ.get(\"GITHUB_ACTIONS\"))\nSKIP_SLOW_IN_CI = pytest.mark.skipif(\n    IN_CI,\n    reason=\"Slow tests skipped in CI - require multiple Expert instances (~60-90s each)\",\n)\n\n\n@pytest.fixture(scope=\"session\")\ndef ls_with_ignored_dirs() -> Generator[SolidLanguageServer, None, None]:\n    \"\"\"Fixture to set up an LS for the elixir test repo with the 'scripts' directory ignored.\n\n    Uses session scope to avoid restarting Expert for each test.\n    \"\"\"\n    ignored_paths = [\"scripts\", \"ignored_dir\"]\n    with start_ls_context(language=Language.ELIXIR, ignored_paths=ignored_paths) as ls:\n        yield ls\n\n\n@pytest.mark.slow\n@SKIP_SLOW_IN_CI\ndef test_symbol_tree_ignores_dir(ls_with_ignored_dirs: SolidLanguageServer):\n    \"\"\"Tests that request_full_symbol_tree ignores the configured directory.\n\n    Note: This test uses a separate Expert instance with custom ignored paths,\n    which adds ~60-90s startup time.\n    \"\"\"\n    root = ls_with_ignored_dirs.request_full_symbol_tree()[0]\n    root_children = root[\"children\"]\n    children_names = {child[\"name\"] for child in root_children}\n\n    # Should have lib and test directories, but not scripts or ignored_dir\n    expected_dirs = {\"lib\", \"test\"}\n    assert expected_dirs.issubset(children_names), f\"Expected {expected_dirs} to be in {children_names}\"\n    assert \"scripts\" not in children_names, f\"scripts should not be in {children_names}\"\n    assert \"ignored_dir\" not in children_names, f\"ignored_dir should not be in {children_names}\"\n\n\n@pytest.mark.slow\n@SKIP_SLOW_IN_CI\ndef test_find_references_ignores_dir(ls_with_ignored_dirs: SolidLanguageServer):\n    \"\"\"Tests that find_references ignores the configured directory.\n\n    Note: This test uses a separate Expert instance with custom ignored paths,\n    which adds ~60-90s startup time.\n    \"\"\"\n    # Location of User struct, which is referenced in scripts and ignored_dir\n    definition_file = \"lib/models.ex\"\n\n    # Find the User struct definition\n    symbols = ls_with_ignored_dirs.request_document_symbols(definition_file).get_all_symbols_and_roots()\n    user_symbol = None\n    for symbol_group in symbols:\n        user_symbol = next((s for s in symbol_group if \"User\" in s.get(\"name\", \"\")), None)\n        if user_symbol:\n            break\n\n    if not user_symbol or \"selectionRange\" not in user_symbol:\n        pytest.skip(\"User symbol not found for reference testing\")\n\n    sel_start = user_symbol[\"selectionRange\"][\"start\"]\n    references = ls_with_ignored_dirs.request_references(definition_file, sel_start[\"line\"], sel_start[\"character\"])\n\n    # Assert that scripts and ignored_dir do not appear in the references\n    assert not any(\"scripts\" in ref[\"relativePath\"] for ref in references), \"scripts should be ignored\"\n    assert not any(\"ignored_dir\" in ref[\"relativePath\"] for ref in references), \"ignored_dir should be ignored\"\n\n\n@pytest.mark.slow\n@SKIP_SLOW_IN_CI\n@pytest.mark.parametrize(\"repo_path\", [Language.ELIXIR], indirect=True)\ndef test_refs_and_symbols_with_glob_patterns(repo_path: Path) -> None:\n    \"\"\"Tests that refs and symbols with glob patterns are ignored.\n\n    Note: This test uses a separate Expert instance with custom ignored paths,\n    which adds ~60-90s startup time.\n    \"\"\"\n    ignored_paths = [\"*cripts\", \"ignored_*\"]  # codespell:ignore cripts\n    with start_ls_context(language=Language.ELIXIR, repo_path=str(repo_path), ignored_paths=ignored_paths) as ls:\n\n        # Same as in the above tests\n        root = ls.request_full_symbol_tree()[0]\n        root_children = root[\"children\"]\n        children_names = {child[\"name\"] for child in root_children}\n\n        # Should have lib and test directories, but not scripts or ignored_dir\n        expected_dirs = {\"lib\", \"test\"}\n        assert expected_dirs.issubset(children_names), f\"Expected {expected_dirs} to be in {children_names}\"\n        assert \"scripts\" not in children_names, f\"scripts should not be in {children_names} (glob pattern)\"\n        assert \"ignored_dir\" not in children_names, f\"ignored_dir should not be in {children_names} (glob pattern)\"\n\n        # Test that the refs and symbols with glob patterns are ignored\n        definition_file = \"lib/models.ex\"\n\n        # Find the User struct definition\n        symbols = ls.request_document_symbols(definition_file).get_all_symbols_and_roots()\n        user_symbol = None\n        for symbol_group in symbols:\n            user_symbol = next((s for s in symbol_group if \"User\" in s.get(\"name\", \"\")), None)\n            if user_symbol:\n                break\n\n        if user_symbol and \"selectionRange\" in user_symbol:\n            sel_start = user_symbol[\"selectionRange\"][\"start\"]\n            references = ls.request_references(definition_file, sel_start[\"line\"], sel_start[\"character\"])\n\n            # Assert that scripts and ignored_dir do not appear in references\n            assert not any(\"scripts\" in ref[\"relativePath\"] for ref in references), \"scripts should be ignored (glob)\"\n            assert not any(\"ignored_dir\" in ref[\"relativePath\"] for ref in references), \"ignored_dir should be ignored (glob)\"\n\n\n@pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\ndef test_default_ignored_directories(language_server: SolidLanguageServer):\n    \"\"\"Test that default Elixir directories are ignored.\"\"\"\n    # Test that Elixir-specific directories are ignored by default\n    assert language_server.is_ignored_dirname(\"_build\"), \"_build should be ignored\"\n    assert language_server.is_ignored_dirname(\"deps\"), \"deps should be ignored\"\n    assert language_server.is_ignored_dirname(\".elixir_ls\"), \".elixir_ls should be ignored\"\n    assert language_server.is_ignored_dirname(\"cover\"), \"cover should be ignored\"\n    assert language_server.is_ignored_dirname(\"node_modules\"), \"node_modules should be ignored\"\n\n    # Test that important directories are not ignored\n    assert not language_server.is_ignored_dirname(\"lib\"), \"lib should not be ignored\"\n    assert not language_server.is_ignored_dirname(\"test\"), \"test should not be ignored\"\n    assert not language_server.is_ignored_dirname(\"config\"), \"config should not be ignored\"\n    assert not language_server.is_ignored_dirname(\"priv\"), \"priv should not be ignored\"\n\n\n@pytest.mark.xfail(\n    reason=\"Expert 0.1.0 bug: document_symbols may return nil for some files (flaky)\",\n    raises=Exception,\n)\n@pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\ndef test_symbol_tree_excludes_build_dirs(language_server: SolidLanguageServer):\n    \"\"\"Test that symbol tree excludes build and dependency directories.\"\"\"\n    symbol_tree = language_server.request_full_symbol_tree()\n\n    if symbol_tree:\n        root = symbol_tree[0]\n        children_names = {child[\"name\"] for child in root.get(\"children\", [])}\n\n        # Build and dependency directories should not appear\n        ignored_dirs = {\"_build\", \"deps\", \".elixir_ls\", \"cover\", \"node_modules\"}\n        found_ignored = ignored_dirs.intersection(children_names)\n        assert len(found_ignored) == 0, f\"Found ignored directories in symbol tree: {found_ignored}\"\n\n        # Important directories should appear\n        important_dirs = {\"lib\", \"test\"}\n        found_important = important_dirs.intersection(children_names)\n        assert len(found_important) > 0, f\"Expected to find important directories: {important_dirs}, got: {children_names}\"\n"
  },
  {
    "path": "test/solidlsp/elixir/test_elixir_integration.py",
    "content": "\"\"\"\nIntegration tests for Elixir language server with test repository.\n\nThese tests verify that the language server works correctly with a real Elixir project\nand can perform advanced operations like cross-file symbol resolution.\n\"\"\"\n\nimport os\nfrom pathlib import Path\n\nimport pytest\n\nfrom serena.project import Project\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\nfrom . import EXPERT_UNAVAILABLE, EXPERT_UNAVAILABLE_REASON\n\n# These marks will be applied to all tests in this module\npytestmark = [pytest.mark.elixir, pytest.mark.skipif(EXPERT_UNAVAILABLE, reason=f\"Next LS not available: {EXPERT_UNAVAILABLE_REASON}\")]\n\n\nclass TestElixirIntegration:\n    \"\"\"Integration tests for Elixir language server with test repository.\"\"\"\n\n    @pytest.fixture\n    def elixir_test_repo_path(self):\n        \"\"\"Get the path to the Elixir test repository.\"\"\"\n        test_dir = Path(__file__).parent.parent.parent\n        return str(test_dir / \"resources\" / \"repos\" / \"elixir\" / \"test_repo\")\n\n    def test_elixir_repo_structure(self, elixir_test_repo_path):\n        \"\"\"Test that the Elixir test repository has the expected structure.\"\"\"\n        repo_path = Path(elixir_test_repo_path)\n\n        # Check that key files exist\n        assert (repo_path / \"mix.exs\").exists(), \"mix.exs should exist\"\n        assert (repo_path / \"lib\" / \"test_repo.ex\").exists(), \"main module should exist\"\n        assert (repo_path / \"lib\" / \"utils.ex\").exists(), \"utils module should exist\"\n        assert (repo_path / \"lib\" / \"models.ex\").exists(), \"models module should exist\"\n        assert (repo_path / \"lib\" / \"services.ex\").exists(), \"services module should exist\"\n        assert (repo_path / \"lib\" / \"examples.ex\").exists(), \"examples module should exist\"\n        assert (repo_path / \"test\" / \"test_repo_test.exs\").exists(), \"test file should exist\"\n        assert (repo_path / \"test\" / \"models_test.exs\").exists(), \"models test should exist\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_cross_file_symbol_resolution(self, language_server: SolidLanguageServer):\n        \"\"\"Test that symbols can be resolved across different files.\"\"\"\n        # Test that User struct from models.ex can be found when referenced in services.ex\n        services_file = os.path.join(\"lib\", \"services.ex\")\n\n        # Find where User is referenced in services.ex\n        content = language_server.retrieve_full_file_content(services_file)\n        lines = content.split(\"\\n\")\n        user_reference_line = None\n        for i, line in enumerate(lines):\n            if \"alias TestRepo.Models.{User\" in line:\n                user_reference_line = i\n                break\n\n        if user_reference_line is None:\n            pytest.skip(\"Could not find User reference in services.ex\")\n\n        # Try to find the definition\n        defining_symbol = language_server.request_defining_symbol(services_file, user_reference_line, 30)\n\n        if defining_symbol and \"location\" in defining_symbol:\n            # Should point to models.ex\n            assert \"models.ex\" in defining_symbol[\"location\"][\"uri\"]\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_module_hierarchy_understanding(self, language_server: SolidLanguageServer):\n        \"\"\"Test that the language server understands Elixir module hierarchy.\"\"\"\n        models_file = os.path.join(\"lib\", \"models.ex\")\n        symbols = language_server.request_document_symbols(models_file).get_all_symbols_and_roots()\n\n        if symbols:\n            # Flatten symbol structure\n            all_symbols = []\n            for symbol_group in symbols:\n                if isinstance(symbol_group, list):\n                    all_symbols.extend(symbol_group)\n                else:\n                    all_symbols.append(symbol_group)\n\n            symbol_names = [s.get(\"name\", \"\") for s in all_symbols]\n\n            # Should understand nested module structure\n            expected_modules = [\"TestRepo.Models\", \"User\", \"Item\", \"Order\"]\n            found_modules = [name for name in expected_modules if any(name in symbol_name for symbol_name in symbol_names)]\n            assert len(found_modules) > 0, f\"Expected modules {expected_modules}, found symbols {symbol_names}\"\n\n    def test_file_extension_matching(self):\n        \"\"\"Test that the Elixir language recognizes the correct file extensions.\"\"\"\n        language = Language.ELIXIR\n        matcher = language.get_source_fn_matcher()\n\n        # Test Elixir file extensions\n        assert matcher.is_relevant_filename(\"lib/test_repo.ex\")\n        assert matcher.is_relevant_filename(\"test/test_repo_test.exs\")\n        assert matcher.is_relevant_filename(\"config/config.exs\")\n        assert matcher.is_relevant_filename(\"mix.exs\")\n        assert matcher.is_relevant_filename(\"lib/models.ex\")\n        assert matcher.is_relevant_filename(\"lib/services.ex\")\n\n        # Test non-Elixir files\n        assert not matcher.is_relevant_filename(\"README.md\")\n        assert not matcher.is_relevant_filename(\"lib/test_repo.py\")\n        assert not matcher.is_relevant_filename(\"package.json\")\n        assert not matcher.is_relevant_filename(\"Cargo.toml\")\n\n\nclass TestElixirProject:\n    @pytest.mark.parametrize(\"project\", [Language.ELIXIR], indirect=True)\n    def test_comprehensive_symbol_search(self, project: Project):\n        \"\"\"Test comprehensive symbol search across the entire project.\"\"\"\n        # Search for all function definitions\n        function_pattern = r\"def\\s+\\w+\\s*[\\(\\s]\"\n        function_matches = project.search_source_files_for_pattern(function_pattern)\n\n        # Should find functions across multiple files\n        if function_matches:\n            files_with_functions = set()\n            for match in function_matches:\n                if match.source_file_path:\n                    files_with_functions.add(os.path.basename(match.source_file_path))\n\n            # Should find functions in multiple files\n            expected_files = {\"models.ex\", \"services.ex\", \"examples.ex\", \"utils.ex\", \"test_repo.ex\"}\n            found_files = expected_files.intersection(files_with_functions)\n            assert len(found_files) > 0, f\"Expected functions in {expected_files}, found in {files_with_functions}\"\n\n        # Search for struct definitions\n        struct_pattern = r\"defstruct\\s+\\[\"\n        struct_matches = project.search_source_files_for_pattern(struct_pattern)\n\n        if struct_matches:\n            # Should find structs primarily in models.ex\n            models_structs = [m for m in struct_matches if m.source_file_path and \"models.ex\" in m.source_file_path]\n            assert len(models_structs) > 0, \"Should find struct definitions in models.ex\"\n\n    @pytest.mark.parametrize(\"project\", [Language.ELIXIR], indirect=True)\n    def test_protocol_and_implementation_understanding(self, project: Project):\n        \"\"\"Test that the language server understands Elixir protocols and implementations.\"\"\"\n        # Search for protocol definitions\n        protocol_pattern = r\"defprotocol\\s+\\w+\"\n        protocol_matches = project.search_source_files_for_pattern(protocol_pattern, paths_include_glob=\"**/models.ex\")\n\n        if protocol_matches:\n            # Should find the Serializable protocol\n            serializable_matches = [m for m in protocol_matches if \"Serializable\" in str(m)]\n            assert len(serializable_matches) > 0, \"Should find Serializable protocol definition\"\n\n        # Search for protocol implementations\n        impl_pattern = r\"defimpl\\s+\\w+\"\n        impl_matches = project.search_source_files_for_pattern(impl_pattern, paths_include_glob=\"**/models.ex\")\n\n        if impl_matches:\n            # Should find multiple implementations\n            assert len(impl_matches) >= 3, f\"Should find at least 3 protocol implementations, found {len(impl_matches)}\"\n"
  },
  {
    "path": "test/solidlsp/elixir/test_elixir_symbol_retrieval.py",
    "content": "\"\"\"\nTests for the Elixir language server symbol-related functionality.\n\nThese tests focus on the following methods:\n- request_containing_symbol\n- request_referencing_symbols\n- request_defining_symbol\n\"\"\"\n\nimport os\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_types import SymbolKind\n\nfrom . import EXPERT_UNAVAILABLE, EXPERT_UNAVAILABLE_REASON\n\n# These marks will be applied to all tests in this module\npytestmark = [pytest.mark.elixir, pytest.mark.skipif(EXPERT_UNAVAILABLE, reason=f\"Next LS not available: {EXPERT_UNAVAILABLE_REASON}\")]\n\n\nclass TestElixirLanguageServerSymbols:\n    \"\"\"Test the Elixir language server's symbol-related functionality.\"\"\"\n\n    @pytest.mark.xfail(\n        reason=\"Expert 0.1.0 bug: document_symbols returns nil for some files (FunctionClauseError in XPExpert.EngineApi.document_symbols/2)\"\n    )\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_request_containing_symbol_function(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol for a function.\"\"\"\n        # Test for a position inside the create_user function\n        file_path = os.path.join(\"lib\", \"services.ex\")\n\n        # Find the create_user function in the file\n        content = language_server.retrieve_full_file_content(file_path)\n        lines = content.split(\"\\n\")\n        create_user_line = None\n        for i, line in enumerate(lines):\n            if \"def create_user(\" in line:\n                create_user_line = i + 2  # Go inside the function body\n                break\n\n        if create_user_line is None:\n            pytest.skip(\"Could not find create_user function\")\n\n        containing_symbol = language_server.request_containing_symbol(file_path, create_user_line, 10, include_body=True)\n\n        # Verify that we found the containing symbol\n        if containing_symbol:\n            # Next LS returns the full function signature instead of just the function name\n            assert containing_symbol[\"name\"] == \"def create_user(pid, id, name, email, roles \\\\\\\\ [])\"\n            assert containing_symbol[\"kind\"] == SymbolKind.Method or containing_symbol[\"kind\"] == SymbolKind.Function\n            if \"body\" in containing_symbol:\n                assert \"def create_user\" in containing_symbol[\"body\"].get_text()\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_request_containing_symbol_module(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol for a module.\"\"\"\n        # Test for a position inside the UserService module but outside any function\n        file_path = os.path.join(\"lib\", \"services.ex\")\n\n        # Find the UserService module definition\n        content = language_server.retrieve_full_file_content(file_path)\n        lines = content.split(\"\\n\")\n        user_service_line = None\n        for i, line in enumerate(lines):\n            if \"defmodule UserService do\" in line:\n                user_service_line = i + 1  # Go inside the module\n                break\n\n        if user_service_line is None:\n            pytest.skip(\"Could not find UserService module\")\n\n        containing_symbol = language_server.request_containing_symbol(file_path, user_service_line, 5)\n\n        # Verify that we found the containing symbol\n        if containing_symbol:\n            assert \"UserService\" in containing_symbol[\"name\"]\n            assert containing_symbol[\"kind\"] == SymbolKind.Module or containing_symbol[\"kind\"] == SymbolKind.Class\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_request_containing_symbol_nested(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol with nested scopes.\"\"\"\n        # Test for a position inside a function which is inside a module\n        file_path = os.path.join(\"lib\", \"services.ex\")\n\n        # Find a function inside UserService\n        content = language_server.retrieve_full_file_content(file_path)\n        lines = content.split(\"\\n\")\n        function_body_line = None\n        for i, line in enumerate(lines):\n            if \"def create_user(\" in line:\n                function_body_line = i + 3  # Go deeper into the function body\n                break\n\n        if function_body_line is None:\n            pytest.skip(\"Could not find function body\")\n\n        containing_symbol = language_server.request_containing_symbol(file_path, function_body_line, 15)\n\n        # Verify that we found the innermost containing symbol (the function)\n        if containing_symbol:\n            expected_names = [\"create_user\", \"UserService\"]\n            assert any(name in containing_symbol[\"name\"] for name in expected_names)\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_request_containing_symbol_none(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol for a position with no containing symbol.\"\"\"\n        # Test for a position outside any function/module (e.g., in module doc)\n        file_path = os.path.join(\"lib\", \"services.ex\")\n        # Line 1-3 are likely in module documentation or imports\n        containing_symbol = language_server.request_containing_symbol(file_path, 2, 10)\n\n        # Should return None or an empty dictionary, or the top-level module\n        # This is acceptable behavior for module-level positions\n        assert containing_symbol is None or containing_symbol == {} or \"TestRepo.Services\" in str(containing_symbol)\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_request_referencing_symbols_struct(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_referencing_symbols for a struct.\"\"\"\n        # Test referencing symbols for User struct\n        file_path = os.path.join(\"lib\", \"models.ex\")\n\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        user_symbol = None\n        for symbol_group in symbols:\n            user_symbol = next((s for s in symbol_group if \"User\" in s.get(\"name\", \"\")), None)\n            if user_symbol:\n                break\n\n        if not user_symbol or \"selectionRange\" not in user_symbol:\n            pytest.skip(\"User symbol or its selectionRange not found\")\n\n        sel_start = user_symbol[\"selectionRange\"][\"start\"]\n        ref_symbols = [\n            ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        ]\n\n        if ref_symbols:\n            services_references = [\n                symbol\n                for symbol in ref_symbols\n                if \"location\" in symbol and \"uri\" in symbol[\"location\"] and \"services.ex\" in symbol[\"location\"][\"uri\"]\n            ]\n            # We expect some references from services.ex\n            assert len(services_references) >= 0  # At least attempt to find references\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_request_referencing_symbols_none(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_referencing_symbols for a position with no symbol.\"\"\"\n        file_path = os.path.join(\"lib\", \"services.ex\")\n        # Line 3 is likely a blank line or comment\n        try:\n            ref_symbols = [ref.symbol for ref in language_server.request_referencing_symbols(file_path, 3, 0)]\n            # If we get here, make sure we got an empty result\n            assert ref_symbols == [] or ref_symbols is None\n        except Exception:\n            # The method might raise an exception for invalid positions\n            # which is acceptable behavior\n            pass\n\n    # Tests for request_defining_symbol\n    @pytest.mark.xfail(\n        reason=\"Expert 0.1.0 bug: definition request crashes (FunctionClauseError in XPExpert.Protocol.Conversions.to_elixir/2)\"\n    )\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_request_defining_symbol_function_call(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a function call.\"\"\"\n        # Find a place where User.new is called in services.ex\n        file_path = os.path.join(\"lib\", \"services.ex\")\n        content = language_server.retrieve_full_file_content(file_path)\n        lines = content.split(\"\\n\")\n        user_new_call_line = None\n        for i, line in enumerate(lines):\n            if \"User.new(\" in line:\n                user_new_call_line = i\n                break\n\n        if user_new_call_line is None:\n            pytest.skip(\"Could not find User.new call\")\n\n        # Try to find the definition of User.new\n        defining_symbol = language_server.request_defining_symbol(file_path, user_new_call_line, 15)\n\n        if defining_symbol:\n            assert defining_symbol.get(\"name\") == \"new\" or \"User\" in defining_symbol.get(\"name\", \"\")\n            if \"location\" in defining_symbol and \"uri\" in defining_symbol[\"location\"]:\n                assert \"models.ex\" in defining_symbol[\"location\"][\"uri\"]\n\n    @pytest.mark.xfail(\n        reason=\"Expert 0.1.0 bug: definition request crashes (FunctionClauseError in XPExpert.Protocol.Conversions.to_elixir/2)\"\n    )\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_request_defining_symbol_struct_usage(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a struct usage.\"\"\"\n        # Find a place where User struct is used in services.ex\n        file_path = os.path.join(\"lib\", \"services.ex\")\n        content = language_server.retrieve_full_file_content(file_path)\n        lines = content.split(\"\\n\")\n        user_usage_line = None\n        for i, line in enumerate(lines):\n            if \"alias TestRepo.Models.{User\" in line:\n                user_usage_line = i\n                break\n\n        if user_usage_line is None:\n            pytest.skip(\"Could not find User struct usage\")\n\n        defining_symbol = language_server.request_defining_symbol(file_path, user_usage_line, 30)\n\n        if defining_symbol:\n            assert \"User\" in defining_symbol.get(\"name\", \"\")\n\n    @pytest.mark.xfail(\n        reason=\"Expert 0.1.0 bug: definition request crashes (FunctionClauseError in XPExpert.Protocol.Conversions.to_elixir/2)\"\n    )\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_request_defining_symbol_none(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a position with no symbol.\"\"\"\n        # Test for a position with no symbol (e.g., whitespace or comment)\n        file_path = os.path.join(\"lib\", \"services.ex\")\n        # Line 3 is likely a blank line\n        defining_symbol = language_server.request_defining_symbol(file_path, 3, 0)\n\n        # Should return None or empty\n        assert defining_symbol is None or defining_symbol == {}\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_symbol_methods_integration(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test integration between different symbol methods.\"\"\"\n        file_path = os.path.join(\"lib\", \"models.ex\")\n\n        # Find User struct definition\n        content = language_server.retrieve_full_file_content(file_path)\n        lines = content.split(\"\\n\")\n        user_struct_line = None\n        for i, line in enumerate(lines):\n            if \"defmodule User do\" in line:\n                user_struct_line = i\n                break\n\n        if user_struct_line is None:\n            pytest.skip(\"Could not find User struct\")\n\n        # Test containing symbol\n        containing = language_server.request_containing_symbol(file_path, user_struct_line + 5, 10)\n\n        if containing:\n            # Test that we can find references to this symbol\n            if \"location\" in containing and \"range\" in containing[\"location\"]:\n                start_pos = containing[\"location\"][\"range\"][\"start\"]\n                refs = [\n                    ref.symbol for ref in language_server.request_referencing_symbols(file_path, start_pos[\"line\"], start_pos[\"character\"])\n                ]\n                # We should find some references or none (both are valid outcomes)\n                assert isinstance(refs, list)\n\n    @pytest.mark.xfail(reason=\"Flaky test, sometimes fails with an Expert-internal error\")\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_symbol_tree_structure(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that symbol tree structure is correctly built.\"\"\"\n        symbol_tree = language_server.request_full_symbol_tree()\n\n        # Should get a tree structure\n        assert len(symbol_tree) > 0\n\n        # Should have our test repository structure\n        root = symbol_tree[0]\n        assert \"children\" in root\n\n        # Look for lib directory\n        lib_dir = None\n        for child in root[\"children\"]:\n            if child[\"name\"] == \"lib\":\n                lib_dir = child\n                break\n\n        if lib_dir:\n            # Expert returns module names instead of file names (e.g., 'services' instead of 'services.ex')\n            file_names = [child[\"name\"] for child in lib_dir.get(\"children\", [])]\n            expected_modules = [\"models\", \"services\", \"examples\", \"utils\", \"test_repo\"]\n            found_modules = [name for name in expected_modules if name in file_names]\n            assert len(found_modules) > 0, f\"Expected to find some modules from {expected_modules}, but got {file_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_request_dir_overview(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_dir_overview functionality.\"\"\"\n        lib_overview = language_server.request_dir_overview(\"lib\")\n\n        # Should get an overview of the lib directory\n        assert lib_overview is not None\n        # Expert returns keys like 'lib/services.ex' instead of just 'lib'\n        overview_keys = list(lib_overview.keys()) if hasattr(lib_overview, \"keys\") else []\n        lib_files = [key for key in overview_keys if key.startswith(\"lib/\")]\n        assert len(lib_files) > 0, f\"Expected to find lib/ files in overview keys: {overview_keys}\"\n\n        # Should contain information about our modules\n        overview_text = str(lib_overview).lower()\n        expected_terms = [\"models\", \"services\", \"user\", \"item\"]\n        found_terms = [term for term in expected_terms if term in overview_text]\n        assert len(found_terms) > 0, f\"Expected to find some terms from {expected_terms} in overview\"\n\n    # @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    # def test_request_document_overview(self, language_server: SolidLanguageServer) -> None:\n    #     \"\"\"Test request_document_overview functionality.\"\"\"\n    #     # COMMENTED OUT: Expert document overview doesn't contain expected terms\n    #     # Expert return value: [('TestRepo.Models', 2, 0, 0)] - only module info, no detailed content\n    #     # Expected terms like 'user', 'item', 'order', 'struct', 'defmodule' are not present\n    #     # This appears to be a limitation of Expert document overview functionality\n    #     #\n    #     file_path = os.path.join(\"lib\", \"models.ex\")\n    #     doc_overview = language_server.request_document_overview(file_path)\n    #\n    #     # Should get an overview of the models.ex file\n    #     assert doc_overview is not None\n    #\n    #     # Should contain information about our structs and functions\n    #     overview_text = str(doc_overview).lower()\n    #     expected_terms = [\"user\", \"item\", \"order\", \"struct\", \"defmodule\"]\n    #     found_terms = [term for term in expected_terms if term in overview_text]\n    #     assert len(found_terms) > 0, f\"Expected to find some terms from {expected_terms} in overview\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ELIXIR], indirect=True)\n    def test_containing_symbol_of_module_attribute(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test containing symbol for module attributes.\"\"\"\n        file_path = os.path.join(\"lib\", \"models.ex\")\n\n        # Find a module attribute like @type or @doc\n        content = language_server.retrieve_full_file_content(file_path)\n        lines = content.split(\"\\n\")\n        attribute_line = None\n        for i, line in enumerate(lines):\n            if line.strip().startswith(\"@type\") or line.strip().startswith(\"@doc\"):\n                attribute_line = i\n                break\n\n        if attribute_line is None:\n            pytest.skip(\"Could not find module attribute\")\n\n        containing_symbol = language_server.request_containing_symbol(file_path, attribute_line, 5)\n\n        if containing_symbol:\n            # Should be contained within a module\n            assert \"name\" in containing_symbol\n            # The containing symbol should be a module\n            expected_names = [\"User\", \"Item\", \"Order\", \"TestRepo.Models\"]\n            assert any(name in containing_symbol[\"name\"] for name in expected_names)\n"
  },
  {
    "path": "test/solidlsp/elm/test_elm_basic.py",
    "content": "import os\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_utils import SymbolUtils\n\n\n@pytest.mark.elm\nclass TestElmLanguageServer:\n    @pytest.mark.parametrize(\"language_server\", [Language.ELM], indirect=True)\n    def test_find_symbol(self, language_server: SolidLanguageServer) -> None:\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"greet\"), \"greet function not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"calculateSum\"), \"calculateSum function not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"formatMessage\"), \"formatMessage function not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"addNumbers\"), \"addNumbers function not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ELM], indirect=True)\n    def test_find_references_within_file(self, language_server: SolidLanguageServer) -> None:\n        file_path = os.path.join(\"Main.elm\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        greet_symbol = None\n        for sym in symbols[0]:\n            if sym.get(\"name\") == \"greet\":\n                greet_symbol = sym\n                break\n        assert greet_symbol is not None, \"Could not find 'greet' symbol in Main.elm\"\n        sel_start = greet_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        assert any(\"Main.elm\" in ref.get(\"relativePath\", \"\") for ref in refs), \"Main.elm should reference greet function\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ELM], indirect=True)\n    def test_find_references_across_files(self, language_server: SolidLanguageServer) -> None:\n        # Test formatMessage function which is defined in Utils.elm and used in Main.elm\n        utils_path = os.path.join(\"Utils.elm\")\n        symbols = language_server.request_document_symbols(utils_path).get_all_symbols_and_roots()\n        formatMessage_symbol = None\n        for sym in symbols[0]:\n            if sym.get(\"name\") == \"formatMessage\":\n                formatMessage_symbol = sym\n                break\n        assert formatMessage_symbol is not None, \"Could not find 'formatMessage' symbol in Utils.elm\"\n\n        # Get references from the definition in Utils.elm\n        sel_start = formatMessage_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(utils_path, sel_start[\"line\"], sel_start[\"character\"])\n\n        # Verify that we found references\n        assert refs, \"Expected to find references for formatMessage\"\n\n        # Verify that at least one reference is in Main.elm (where formatMessage is used)\n        assert any(\"Main.elm\" in ref.get(\"relativePath\", \"\") for ref in refs), \"Expected to find usage of formatMessage in Main.elm\"\n"
  },
  {
    "path": "test/solidlsp/erlang/__init__.py",
    "content": "import platform\n\n\ndef _test_erlang_ls_available() -> str:\n    \"\"\"Test if Erlang LS is available and return error reason if not.\"\"\"\n    # Check if we're on Windows (Erlang LS doesn't support Windows)\n    if platform.system() == \"Windows\":\n        return \"Erlang LS does not support Windows\"\n\n    # Try to import and check Erlang availability\n    try:\n        from solidlsp.language_servers.erlang_language_server import ErlangLanguageServer\n\n        # Check if Erlang/OTP is installed\n        erlang_version = ErlangLanguageServer._get_erlang_version()\n        if not erlang_version:\n            return \"Erlang/OTP is not installed or not in PATH\"\n\n        # Check if rebar3 is available (commonly used build tool)\n        rebar3_available = ErlangLanguageServer._check_rebar3_available()\n        if not rebar3_available:\n            return \"rebar3 is not installed or not in PATH (required for project compilation)\"\n\n        return \"\"  # No error, Erlang LS should be available\n\n    except ImportError as e:\n        return f\"Failed to import ErlangLanguageServer: {e}\"\n    except Exception as e:\n        return f\"Error checking Erlang LS availability: {e}\"\n\n\nERLANG_LS_UNAVAILABLE_REASON = _test_erlang_ls_available()\nERLANG_LS_UNAVAILABLE = bool(ERLANG_LS_UNAVAILABLE_REASON)\n"
  },
  {
    "path": "test/solidlsp/erlang/conftest.py",
    "content": "\"\"\"\nErlang-specific test configuration and fixtures.\n\"\"\"\n\nimport os\nimport subprocess\nimport time\nfrom pathlib import Path\n\nimport pytest\n\n\ndef ensure_erlang_test_repo_compiled(repo_path: str) -> None:\n    \"\"\"Ensure the Erlang test repository dependencies are installed and project is compiled.\n\n    Erlang LS requires the project to be fully compiled and indexed before providing\n    complete references and symbol resolution. This function:\n    1. Installs dependencies via 'rebar3 deps'\n    2. Compiles the project via 'rebar3 compile'\n\n    This is essential in CI environments where dependencies aren't pre-installed.\n\n    Args:\n        repo_path: Path to the Erlang project root directory\n\n    \"\"\"\n    # Check if this looks like an Erlang project\n    rebar_config = os.path.join(repo_path, \"rebar.config\")\n    if not os.path.exists(rebar_config):\n        return\n\n    # Check if already compiled (optimization for repeated runs)\n    build_path = os.path.join(repo_path, \"_build\")\n    deps_path = os.path.join(repo_path, \"deps\")\n\n    if os.path.exists(build_path) and os.path.exists(deps_path):\n        print(f\"Erlang test repository already compiled in {repo_path}\")\n        return\n\n    try:\n        print(\"Installing dependencies and compiling Erlang test repository for optimal Erlang LS performance...\")\n\n        # First, install dependencies with increased timeout for CI\n        print(\"=\" * 60)\n        print(\"Step 1/2: Installing Erlang dependencies...\")\n        print(\"=\" * 60)\n        start_time = time.time()\n\n        deps_result = subprocess.run(\n            [\"rebar3\", \"deps\"],\n            cwd=repo_path,\n            capture_output=True,\n            text=True,\n            timeout=180,\n            check=False,  # 3 minutes for dependency installation (CI can be slow)\n        )\n\n        deps_duration = time.time() - start_time\n        print(f\"Dependencies installation completed in {deps_duration:.2f} seconds\")\n\n        # Always log the output for transparency\n        if deps_result.stdout.strip():\n            print(\"Dependencies stdout:\")\n            print(\"-\" * 40)\n            print(deps_result.stdout)\n            print(\"-\" * 40)\n\n        if deps_result.stderr.strip():\n            print(\"Dependencies stderr:\")\n            print(\"-\" * 40)\n            print(deps_result.stderr)\n            print(\"-\" * 40)\n\n        if deps_result.returncode != 0:\n            print(f\"⚠️  Warning: Dependencies installation failed with exit code {deps_result.returncode}\")\n            # Continue anyway - some projects might not have dependencies\n        else:\n            print(\"✓ Dependencies installed successfully\")\n\n        # Then compile the project with increased timeout for CI\n        print(\"=\" * 60)\n        print(\"Step 2/2: Compiling Erlang project...\")\n        print(\"=\" * 60)\n        start_time = time.time()\n\n        compile_result = subprocess.run(\n            [\"rebar3\", \"compile\"],\n            cwd=repo_path,\n            capture_output=True,\n            text=True,\n            timeout=300,\n            check=False,  # 5 minutes for compilation (Dialyzer can be slow in CI)\n        )\n\n        compile_duration = time.time() - start_time\n        print(f\"Compilation completed in {compile_duration:.2f} seconds\")\n\n        # Always log the output for transparency\n        if compile_result.stdout.strip():\n            print(\"Compilation stdout:\")\n            print(\"-\" * 40)\n            print(compile_result.stdout)\n            print(\"-\" * 40)\n\n        if compile_result.stderr.strip():\n            print(\"Compilation stderr:\")\n            print(\"-\" * 40)\n            print(compile_result.stderr)\n            print(\"-\" * 40)\n\n        if compile_result.returncode == 0:\n            print(f\"✓ Erlang test repository compiled successfully in {repo_path}\")\n        else:\n            print(f\"⚠️  Warning: Compilation completed with exit code {compile_result.returncode}\")\n            # Still continue - warnings are often non-fatal\n\n        print(\"=\" * 60)\n        print(f\"Total setup time: {time.time() - (start_time - compile_duration - deps_duration):.2f} seconds\")\n        print(\"=\" * 60)\n\n    except subprocess.TimeoutExpired as e:\n        print(\"=\" * 60)\n        print(f\"❌ TIMEOUT: Erlang setup timed out after {e.timeout} seconds\")\n        print(f\"Command: {' '.join(e.cmd)}\")\n        print(\"This may indicate slow CI environment - Erlang LS may still work but with reduced functionality\")\n\n        # Try to get partial output if available\n        if hasattr(e, \"stdout\") and e.stdout:\n            print(\"Partial stdout before timeout:\")\n            print(\"-\" * 40)\n            print(e.stdout)\n            print(\"-\" * 40)\n        if hasattr(e, \"stderr\") and e.stderr:\n            print(\"Partial stderr before timeout:\")\n            print(\"-\" * 40)\n            print(e.stderr)\n            print(\"-\" * 40)\n        print(\"=\" * 60)\n\n    except FileNotFoundError:\n        print(\"❌ ERROR: 'rebar3' command not found - Erlang test repository may not be compiled\")\n        print(\"Please ensure rebar3 is installed and available in PATH\")\n    except Exception as e:\n        print(f\"❌ ERROR: Failed to prepare Erlang test repository: {e}\")\n\n\n@pytest.fixture(scope=\"session\", autouse=True)\ndef setup_erlang_test_environment():\n    \"\"\"Automatically prepare Erlang test environment for all Erlang tests.\n\n    This fixture runs once per test session and automatically:\n    1. Installs dependencies via 'rebar3 deps'\n    2. Compiles the Erlang test repository via 'rebar3 compile'\n\n    It uses autouse=True so it runs automatically without needing to be explicitly\n    requested by tests. This ensures Erlang LS has a fully prepared project to work with.\n\n    Uses generous timeouts (3-5 minutes) to accommodate slow CI environments.\n    All output is logged for transparency and debugging.\n    \"\"\"\n    # Get the test repo path relative to this conftest.py file\n    test_repo_path = Path(__file__).parent.parent.parent / \"resources\" / \"repos\" / \"erlang\" / \"test_repo\"\n    ensure_erlang_test_repo_compiled(str(test_repo_path))\n    return str(test_repo_path)\n\n\n@pytest.fixture(scope=\"session\")\ndef erlang_test_repo_path(setup_erlang_test_environment):\n    \"\"\"Get the path to the prepared Erlang test repository.\n\n    This fixture depends on setup_erlang_test_environment to ensure dependencies\n    are installed and compilation has completed before returning the path.\n    \"\"\"\n    return setup_erlang_test_environment\n"
  },
  {
    "path": "test/solidlsp/erlang/test_erlang_basic.py",
    "content": "\"\"\"\nBasic integration tests for the Erlang language server functionality.\n\nThese tests validate the functionality of the language server APIs\nlike request_references using the test repository.\n\"\"\"\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\nfrom . import ERLANG_LS_UNAVAILABLE, ERLANG_LS_UNAVAILABLE_REASON\n\n\n@pytest.mark.erlang\n@pytest.mark.skipif(ERLANG_LS_UNAVAILABLE, reason=f\"Erlang LS not available: {ERLANG_LS_UNAVAILABLE_REASON}\")\nclass TestErlangLanguageServerBasics:\n    \"\"\"Test basic functionality of the Erlang language server.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_language_server_initialization(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that the Erlang language server initializes properly.\"\"\"\n        assert language_server is not None\n        assert language_server.language == Language.ERLANG\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_document_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test document symbols retrieval for Erlang files.\"\"\"\n        try:\n            file_path = \"hello.erl\"\n            symbols_tuple = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n            assert isinstance(symbols_tuple, tuple)\n            assert len(symbols_tuple) == 2\n\n            all_symbols, root_symbols = symbols_tuple\n            assert isinstance(all_symbols, list)\n            assert isinstance(root_symbols, list)\n        except Exception as e:\n            if \"not fully initialized\" in str(e):\n                pytest.skip(\"Erlang language server not fully initialized\")\n            else:\n                raise\n"
  },
  {
    "path": "test/solidlsp/erlang/test_erlang_ignored_dirs.py",
    "content": "from collections.abc import Generator\nfrom pathlib import Path\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom test.conftest import start_ls_context\n\nfrom . import ERLANG_LS_UNAVAILABLE, ERLANG_LS_UNAVAILABLE_REASON\n\n# These marks will be applied to all tests in this module\npytestmark = [\n    pytest.mark.erlang,\n    pytest.mark.skipif(ERLANG_LS_UNAVAILABLE, reason=f\"Erlang LS not available: {ERLANG_LS_UNAVAILABLE_REASON}\"),\n]\n\n\n@pytest.fixture(scope=\"module\")\ndef ls_with_ignored_dirs() -> Generator[SolidLanguageServer, None, None]:\n    \"\"\"Fixture to set up an LS for the erlang test repo with the 'ignored_dir' directory ignored.\"\"\"\n    ignored_paths = [\"_build\", \"ignored_dir\"]\n    with start_ls_context(language=Language.ERLANG, ignored_paths=ignored_paths) as ls:\n        yield ls\n\n\n@pytest.mark.timeout(60)  # Add 60 second timeout\n@pytest.mark.xfail(reason=\"Known timeout issue on Ubuntu CI with Erlang LS server startup\", strict=False)\n@pytest.mark.parametrize(\"ls_with_ignored_dirs\", [Language.ERLANG], indirect=True)\ndef test_symbol_tree_ignores_dir(ls_with_ignored_dirs: SolidLanguageServer):\n    \"\"\"Tests that request_full_symbol_tree ignores the configured directory.\"\"\"\n    root = ls_with_ignored_dirs.request_full_symbol_tree()[0]\n    root_children = root[\"children\"]\n    children_names = {child[\"name\"] for child in root_children}\n\n    # Should have src, include, and test directories, but not _build or ignored_dir\n    expected_dirs = {\"src\", \"include\", \"test\"}\n    found_expected = expected_dirs.intersection(children_names)\n    assert len(found_expected) > 0, f\"Expected some dirs from {expected_dirs} to be in {children_names}\"\n    assert \"_build\" not in children_names, f\"_build should not be in {children_names}\"\n    assert \"ignored_dir\" not in children_names, f\"ignored_dir should not be in {children_names}\"\n\n\n@pytest.mark.timeout(60)  # Add 60 second timeout\n@pytest.mark.xfail(reason=\"Known timeout issue on Ubuntu CI with Erlang LS server startup\", strict=False)\n@pytest.mark.parametrize(\"ls_with_ignored_dirs\", [Language.ERLANG], indirect=True)\ndef test_find_references_ignores_dir(ls_with_ignored_dirs: SolidLanguageServer):\n    \"\"\"Tests that find_references ignores the configured directory.\"\"\"\n    # Location of user record, which might be referenced in ignored_dir\n    definition_file = \"include/records.hrl\"\n\n    # Find the user record definition\n    symbols = ls_with_ignored_dirs.request_document_symbols(definition_file).get_all_symbols_and_roots()\n    user_symbol = None\n    for symbol_group in symbols:\n        user_symbol = next((s for s in symbol_group if \"user\" in s.get(\"name\", \"\").lower()), None)\n        if user_symbol:\n            break\n\n    if not user_symbol or \"selectionRange\" not in user_symbol:\n        pytest.skip(\"User record symbol not found for reference testing\")\n\n    sel_start = user_symbol[\"selectionRange\"][\"start\"]\n    references = ls_with_ignored_dirs.request_references(definition_file, sel_start[\"line\"], sel_start[\"character\"])\n\n    # Assert that _build and ignored_dir do not appear in the references\n    assert not any(\"_build\" in ref[\"relativePath\"] for ref in references), \"_build should be ignored\"\n    assert not any(\"ignored_dir\" in ref[\"relativePath\"] for ref in references), \"ignored_dir should be ignored\"\n\n\n@pytest.mark.timeout(60)  # Add 60 second timeout\n@pytest.mark.xfail(reason=\"Known timeout issue on Ubuntu CI with Erlang LS server startup\", strict=False)\n@pytest.mark.parametrize(\"repo_path\", [Language.ERLANG], indirect=True)\ndef test_refs_and_symbols_with_glob_patterns(repo_path: Path) -> None:\n    \"\"\"Tests that refs and symbols with glob patterns are ignored.\"\"\"\n    ignored_paths = [\"_build*\", \"ignored_*\", \"*.tmp\"]\n    with start_ls_context(language=Language.ERLANG, repo_path=str(repo_path), ignored_paths=ignored_paths) as ls:\n        # Same as in the above tests\n        root = ls.request_full_symbol_tree()[0]\n        root_children = root[\"children\"]\n        children_names = {child[\"name\"] for child in root_children}\n\n        # Should have src, include, and test directories, but not _build or ignored_dir\n        expected_dirs = {\"src\", \"include\", \"test\"}\n        found_expected = expected_dirs.intersection(children_names)\n        assert len(found_expected) > 0, f\"Expected some dirs from {expected_dirs} to be in {children_names}\"\n        assert \"_build\" not in children_names, f\"_build should not be in {children_names} (glob pattern)\"\n        assert \"ignored_dir\" not in children_names, f\"ignored_dir should not be in {children_names} (glob pattern)\"\n\n        # Test that the refs and symbols with glob patterns are ignored\n        definition_file = \"include/records.hrl\"\n\n        # Find the user record definition\n        symbols = ls.request_document_symbols(definition_file).get_all_symbols_and_roots()\n        user_symbol = None\n        for symbol_group in symbols:\n            user_symbol = next((s for s in symbol_group if \"user\" in s.get(\"name\", \"\").lower()), None)\n            if user_symbol:\n                break\n\n        if user_symbol and \"selectionRange\" in user_symbol:\n            sel_start = user_symbol[\"selectionRange\"][\"start\"]\n            references = ls.request_references(definition_file, sel_start[\"line\"], sel_start[\"character\"])\n\n            # Assert that _build and ignored_dir do not appear in references\n            assert not any(\"_build\" in ref[\"relativePath\"] for ref in references), \"_build should be ignored (glob)\"\n            assert not any(\"ignored_dir\" in ref[\"relativePath\"] for ref in references), \"ignored_dir should be ignored (glob)\"\n\n\n@pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\ndef test_default_ignored_directories(language_server: SolidLanguageServer):\n    \"\"\"Test that default Erlang directories are ignored.\"\"\"\n    # Test that Erlang-specific directories are ignored by default\n    assert language_server.is_ignored_dirname(\"_build\"), \"_build should be ignored\"\n    assert language_server.is_ignored_dirname(\"ebin\"), \"ebin should be ignored\"\n    assert language_server.is_ignored_dirname(\"deps\"), \"deps should be ignored\"\n    assert language_server.is_ignored_dirname(\".rebar3\"), \".rebar3 should be ignored\"\n    assert language_server.is_ignored_dirname(\"_checkouts\"), \"_checkouts should be ignored\"\n    assert language_server.is_ignored_dirname(\"node_modules\"), \"node_modules should be ignored\"\n\n    # Test that important directories are not ignored\n    assert not language_server.is_ignored_dirname(\"src\"), \"src should not be ignored\"\n    assert not language_server.is_ignored_dirname(\"include\"), \"include should not be ignored\"\n    assert not language_server.is_ignored_dirname(\"test\"), \"test should not be ignored\"\n    assert not language_server.is_ignored_dirname(\"priv\"), \"priv should not be ignored\"\n\n\n@pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\ndef test_symbol_tree_excludes_build_dirs(language_server: SolidLanguageServer):\n    \"\"\"Test that symbol tree excludes build and dependency directories.\"\"\"\n    symbol_tree = language_server.request_full_symbol_tree()\n\n    if symbol_tree:\n        root = symbol_tree[0]\n        children_names = {child[\"name\"] for child in root.get(\"children\", [])}\n\n        # Build and dependency directories should not appear\n        ignored_dirs = {\"_build\", \"ebin\", \"deps\", \".rebar3\", \"_checkouts\", \"node_modules\"}\n        found_ignored = ignored_dirs.intersection(children_names)\n        assert len(found_ignored) == 0, f\"Found ignored directories in symbol tree: {found_ignored}\"\n\n        # Important directories should appear\n        important_dirs = {\"src\", \"include\", \"test\"}\n        found_important = important_dirs.intersection(children_names)\n        assert len(found_important) > 0, f\"Expected to find important directories: {important_dirs}, got: {children_names}\"\n\n\n@pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\ndef test_ignore_compiled_files(language_server: SolidLanguageServer):\n    \"\"\"Test that compiled Erlang files are ignored.\"\"\"\n    # Test that beam files are ignored\n    assert language_server.is_ignored_filename(\"module.beam\"), \"BEAM files should be ignored\"\n    assert language_server.is_ignored_filename(\"app.beam\"), \"BEAM files should be ignored\"\n\n    # Test that source files are not ignored\n    assert not language_server.is_ignored_filename(\"module.erl\"), \"Erlang source files should not be ignored\"\n    assert not language_server.is_ignored_filename(\"records.hrl\"), \"Header files should not be ignored\"\n\n\n@pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\ndef test_rebar_directories_ignored(language_server: SolidLanguageServer):\n    \"\"\"Test that rebar-specific directories are ignored.\"\"\"\n    # Test rebar3-specific directories\n    assert language_server.is_ignored_dirname(\"_build\"), \"rebar3 _build should be ignored\"\n    assert language_server.is_ignored_dirname(\"_checkouts\"), \"rebar3 _checkouts should be ignored\"\n    assert language_server.is_ignored_dirname(\".rebar3\"), \"rebar3 cache should be ignored\"\n\n    # Test that rebar.lock and rebar.config are not ignored (they are configuration files)\n    assert not language_server.is_ignored_filename(\"rebar.config\"), \"rebar.config should not be ignored\"\n    assert not language_server.is_ignored_filename(\"rebar.lock\"), \"rebar.lock should not be ignored\"\n\n\n@pytest.mark.parametrize(\"ls_with_ignored_dirs\", [Language.ERLANG], indirect=True)\ndef test_document_symbols_ignores_dirs(ls_with_ignored_dirs: SolidLanguageServer):\n    \"\"\"Test that document symbols from ignored directories are not included.\"\"\"\n    # Try to get symbols from a file in ignored directory (should not find it)\n    try:\n        ignored_file = \"ignored_dir/ignored_module.erl\"\n        symbols = ls_with_ignored_dirs.request_document_symbols(ignored_file).get_all_symbols_and_roots()\n        # If we get here, the file was found - symbols should be empty or None\n        if symbols:\n            assert len(symbols) == 0, \"Should not find symbols in ignored directory\"\n    except Exception:\n        # This is expected - the file should not be accessible\n        pass\n\n\n@pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\ndef test_erlang_specific_ignore_patterns(language_server: SolidLanguageServer):\n    \"\"\"Test Erlang-specific ignore patterns work correctly.\"\"\"\n    erlang_ignored_dirs = [\"_build\", \"ebin\", \".rebar3\", \"_checkouts\", \"cover\"]\n\n    # These should be ignored\n    for dirname in erlang_ignored_dirs:\n        assert language_server.is_ignored_dirname(dirname), f\"{dirname} should be ignored\"\n\n    # These should not be ignored\n    erlang_important_dirs = [\"src\", \"include\", \"test\", \"priv\"]\n    for dirname in erlang_important_dirs:\n        assert not language_server.is_ignored_dirname(dirname), f\"{dirname} should not be ignored\"\n"
  },
  {
    "path": "test/solidlsp/erlang/test_erlang_symbol_retrieval.py",
    "content": "\"\"\"\nTests for the Erlang language server symbol-related functionality.\n\nThese tests focus on the following methods:\n- request_containing_symbol\n- request_referencing_symbols\n- request_defining_symbol\n\"\"\"\n\nimport os\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_types import SymbolKind\n\nfrom . import ERLANG_LS_UNAVAILABLE, ERLANG_LS_UNAVAILABLE_REASON\n\n# These marks will be applied to all tests in this module\npytestmark = [\n    pytest.mark.erlang,\n    pytest.mark.skipif(ERLANG_LS_UNAVAILABLE, reason=f\"Erlang LS not available: {ERLANG_LS_UNAVAILABLE_REASON}\"),\n]\n\n\nclass TestErlangLanguageServerSymbols:\n    \"\"\"Test the Erlang language server's symbol-related functionality.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_request_containing_symbol_function(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol for a function.\"\"\"\n        # Test for a position inside the create_user function\n        file_path = os.path.join(\"src\", \"models.erl\")\n\n        # Find the create_user function in the file\n        content = language_server.retrieve_full_file_content(file_path)\n        lines = content.split(\"\\n\")\n        create_user_line = None\n        for i, line in enumerate(lines):\n            if \"create_user(\" in line and \"-spec\" not in line:\n                create_user_line = i + 1  # Go inside the function body\n                break\n\n        if create_user_line is None:\n            pytest.skip(\"Could not find create_user function\")\n\n        containing_symbol = language_server.request_containing_symbol(file_path, create_user_line, 10, include_body=True)\n\n        # Verify that we found the containing symbol\n        if containing_symbol:\n            assert \"create_user\" in containing_symbol[\"name\"]\n            assert containing_symbol[\"kind\"] == SymbolKind.Method or containing_symbol[\"kind\"] == SymbolKind.Function\n            if \"body\" in containing_symbol:\n                assert \"create_user\" in containing_symbol[\"body\"].get_text()\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_request_containing_symbol_module(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol for a module.\"\"\"\n        # Test for a position inside the models module but outside any function\n        file_path = os.path.join(\"src\", \"models.erl\")\n\n        # Find the module definition\n        content = language_server.retrieve_full_file_content(file_path)\n        lines = content.split(\"\\n\")\n        module_line = None\n        for i, line in enumerate(lines):\n            if \"-module(models)\" in line:\n                module_line = i + 2  # Go inside the module\n                break\n\n        if module_line is None:\n            pytest.skip(\"Could not find models module\")\n\n        containing_symbol = language_server.request_containing_symbol(file_path, module_line, 5)\n\n        # Verify that we found the containing symbol\n        if containing_symbol:\n            assert \"models\" in containing_symbol[\"name\"] or \"module\" in containing_symbol[\"name\"].lower()\n            assert containing_symbol[\"kind\"] == SymbolKind.Module or containing_symbol[\"kind\"] == SymbolKind.Class\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_request_containing_symbol_nested(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol with nested scopes.\"\"\"\n        # Test for a position inside a function which is inside a module\n        file_path = os.path.join(\"src\", \"models.erl\")\n\n        # Find a function inside models module\n        content = language_server.retrieve_full_file_content(file_path)\n        lines = content.split(\"\\n\")\n        function_body_line = None\n        for i, line in enumerate(lines):\n            if \"create_user(\" in line and \"-spec\" not in line:\n                # Go deeper into the function body where there might be case expressions\n                for j in range(i + 1, min(i + 10, len(lines))):\n                    if lines[j].strip() and not lines[j].strip().startswith(\"%\"):\n                        function_body_line = j\n                        break\n                break\n\n        if function_body_line is None:\n            pytest.skip(\"Could not find function body\")\n\n        containing_symbol = language_server.request_containing_symbol(file_path, function_body_line, 15)\n\n        # Verify that we found the innermost containing symbol (the function)\n        if containing_symbol:\n            expected_names = [\"create_user\", \"models\"]\n            assert any(name in containing_symbol[\"name\"] for name in expected_names)\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_request_containing_symbol_none(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol for a position with no containing symbol.\"\"\"\n        # Test for a position outside any function/module (e.g., in comments)\n        file_path = os.path.join(\"src\", \"models.erl\")\n        # Line 1-2 are likely module declaration or comments\n        containing_symbol = language_server.request_containing_symbol(file_path, 2, 10)\n\n        # Should return None or an empty dictionary, or the top-level module\n        # This is acceptable behavior for module-level positions\n        assert containing_symbol is None or containing_symbol == {} or \"models\" in str(containing_symbol)\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_request_referencing_symbols_record(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_referencing_symbols for a record.\"\"\"\n        # Test referencing symbols for user record\n        file_path = os.path.join(\"include\", \"records.hrl\")\n\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        user_symbol = None\n        for symbol_group in symbols:\n            user_symbol = next((s for s in symbol_group if \"user\" in s.get(\"name\", \"\")), None)\n            if user_symbol:\n                break\n\n        if not user_symbol or \"selectionRange\" not in user_symbol:\n            pytest.skip(\"User record symbol or its selectionRange not found\")\n\n        sel_start = user_symbol[\"selectionRange\"][\"start\"]\n        ref_symbols = [\n            ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        ]\n\n        if ref_symbols:\n            models_references = [\n                symbol\n                for symbol in ref_symbols\n                if \"location\" in symbol and \"uri\" in symbol[\"location\"] and \"models.erl\" in symbol[\"location\"][\"uri\"]\n            ]\n            # We expect some references from models.erl\n            assert len(models_references) >= 0  # At least attempt to find references\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_request_referencing_symbols_function(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_referencing_symbols for a function.\"\"\"\n        # Test referencing symbols for create_user function\n        file_path = os.path.join(\"src\", \"models.erl\")\n\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        create_user_symbol = None\n        for symbol_group in symbols:\n            create_user_symbol = next((s for s in symbol_group if \"create_user\" in s.get(\"name\", \"\")), None)\n            if create_user_symbol:\n                break\n\n        if not create_user_symbol or \"selectionRange\" not in create_user_symbol:\n            pytest.skip(\"create_user function symbol or its selectionRange not found\")\n\n        sel_start = create_user_symbol[\"selectionRange\"][\"start\"]\n        ref_symbols = [\n            ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        ]\n\n        if ref_symbols:\n            # We might find references from services.erl or test files\n            service_references = [\n                symbol\n                for symbol in ref_symbols\n                if \"location\" in symbol\n                and \"uri\" in symbol[\"location\"]\n                and (\"services.erl\" in symbol[\"location\"][\"uri\"] or \"test\" in symbol[\"location\"][\"uri\"])\n            ]\n            assert len(service_references) >= 0  # At least attempt to find references\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_request_referencing_symbols_none(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_referencing_symbols for a position with no symbol.\"\"\"\n        file_path = os.path.join(\"src\", \"models.erl\")\n        # Line 3 is likely a blank line or comment\n        try:\n            ref_symbols = [ref.symbol for ref in language_server.request_referencing_symbols(file_path, 3, 0)]\n            # If we get here, make sure we got an empty result\n            assert ref_symbols == [] or ref_symbols is None\n        except Exception:\n            # The method might raise an exception for invalid positions\n            # which is acceptable behavior\n            pass\n\n    # Tests for request_defining_symbol\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_request_defining_symbol_function_call(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a function call.\"\"\"\n        # Find a place where models:create_user is called in services.erl\n        file_path = os.path.join(\"src\", \"services.erl\")\n        content = language_server.retrieve_full_file_content(file_path)\n        lines = content.split(\"\\n\")\n        models_call_line = None\n        for i, line in enumerate(lines):\n            if \"models:create_user(\" in line:\n                models_call_line = i\n                break\n\n        if models_call_line is None:\n            pytest.skip(\"Could not find models:create_user call\")\n\n        # Try to find the definition of models:create_user\n        defining_symbol = language_server.request_defining_symbol(file_path, models_call_line, 20)\n\n        if defining_symbol:\n            assert \"create_user\" in defining_symbol.get(\"name\", \"\") or \"models\" in defining_symbol.get(\"name\", \"\")\n            if \"location\" in defining_symbol and \"uri\" in defining_symbol[\"location\"]:\n                assert \"models.erl\" in defining_symbol[\"location\"][\"uri\"]\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_request_defining_symbol_record_usage(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a record usage.\"\"\"\n        # Find a place where #user{} record is used in models.erl\n        file_path = os.path.join(\"src\", \"models.erl\")\n        content = language_server.retrieve_full_file_content(file_path)\n        lines = content.split(\"\\n\")\n        record_usage_line = None\n        for i, line in enumerate(lines):\n            if \"#user{\" in line:\n                record_usage_line = i\n                break\n\n        if record_usage_line is None:\n            pytest.skip(\"Could not find #user{} record usage\")\n\n        defining_symbol = language_server.request_defining_symbol(file_path, record_usage_line, 10)\n\n        if defining_symbol:\n            assert \"user\" in defining_symbol.get(\"name\", \"\").lower()\n            if \"location\" in defining_symbol and \"uri\" in defining_symbol[\"location\"]:\n                assert \"records.hrl\" in defining_symbol[\"location\"][\"uri\"]\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_request_defining_symbol_module_call(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a module function call.\"\"\"\n        # Find a place where utils:validate_input is called\n        file_path = os.path.join(\"src\", \"models.erl\")\n        content = language_server.retrieve_full_file_content(file_path)\n        lines = content.split(\"\\n\")\n        utils_call_line = None\n        for i, line in enumerate(lines):\n            if \"validate_email(\" in line:\n                utils_call_line = i\n                break\n\n        if utils_call_line is None:\n            pytest.skip(\"Could not find function call in models.erl\")\n\n        defining_symbol = language_server.request_defining_symbol(file_path, utils_call_line, 15)\n\n        if defining_symbol:\n            assert \"validate\" in defining_symbol.get(\"name\", \"\") or \"email\" in defining_symbol.get(\"name\", \"\")\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_request_defining_symbol_none(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a position with no symbol.\"\"\"\n        # Test for a position with no symbol (e.g., whitespace or comment)\n        file_path = os.path.join(\"src\", \"models.erl\")\n        # Line 3 is likely a blank line or comment\n        defining_symbol = language_server.request_defining_symbol(file_path, 3, 0)\n\n        # Should return None or empty\n        assert defining_symbol is None or defining_symbol == {}\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_symbol_methods_integration(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test integration between different symbol methods.\"\"\"\n        file_path = os.path.join(\"src\", \"models.erl\")\n\n        # Find create_user function definition\n        content = language_server.retrieve_full_file_content(file_path)\n        lines = content.split(\"\\n\")\n        create_user_line = None\n        for i, line in enumerate(lines):\n            if \"create_user(\" in line and \"-spec\" not in line:\n                create_user_line = i\n                break\n\n        if create_user_line is None:\n            pytest.skip(\"Could not find create_user function\")\n\n        # Test containing symbol\n        containing = language_server.request_containing_symbol(file_path, create_user_line + 2, 10)\n\n        if containing:\n            # Test that we can find references to this symbol\n            if \"location\" in containing and \"range\" in containing[\"location\"]:\n                start_pos = containing[\"location\"][\"range\"][\"start\"]\n                refs = [\n                    ref.symbol for ref in language_server.request_referencing_symbols(file_path, start_pos[\"line\"], start_pos[\"character\"])\n                ]\n                # We should find some references or none (both are valid outcomes)\n                assert isinstance(refs, list)\n\n    @pytest.mark.timeout(60)  # Add 60 second timeout\n    @pytest.mark.xfail(\n        reason=\"Known intermittent timeout issue in Erlang LS in CI environments. \"\n        \"May pass locally but can timeout on slower CI systems.\",\n        strict=False,\n    )\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_symbol_tree_structure(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that symbol tree structure is correctly built.\"\"\"\n        symbol_tree = language_server.request_full_symbol_tree()\n\n        # Should get a tree structure\n        assert len(symbol_tree) > 0\n\n        # Should have our test repository structure\n        root = symbol_tree[0]\n        assert \"children\" in root\n\n        # Look for src directory\n        src_dir = None\n        for child in root[\"children\"]:\n            if child[\"name\"] == \"src\":\n                src_dir = child\n                break\n\n        if src_dir:\n            # Check for our Erlang modules\n            file_names = [child[\"name\"] for child in src_dir.get(\"children\", [])]\n            expected_modules = [\"models\", \"services\", \"utils\", \"app\"]\n            found_modules = [name for name in expected_modules if any(name in fname for fname in file_names)]\n            assert len(found_modules) > 0, f\"Expected to find some modules from {expected_modules}, but got {file_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_request_dir_overview(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_dir_overview functionality.\"\"\"\n        src_overview = language_server.request_dir_overview(\"src\")\n\n        # Should get an overview of the src directory\n        assert src_overview is not None\n        overview_keys = list(src_overview.keys()) if hasattr(src_overview, \"keys\") else []\n        src_files = [key for key in overview_keys if key.startswith(\"src/\") or \"src\" in key]\n        assert len(src_files) > 0, f\"Expected to find src/ files in overview keys: {overview_keys}\"\n\n        # Should contain information about our modules\n        overview_text = str(src_overview).lower()\n        expected_terms = [\"models\", \"services\", \"user\", \"create_user\", \"gen_server\"]\n        found_terms = [term for term in expected_terms if term in overview_text]\n        assert len(found_terms) > 0, f\"Expected to find some terms from {expected_terms} in overview\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_containing_symbol_of_record_field(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test containing symbol for record field access.\"\"\"\n        file_path = os.path.join(\"src\", \"models.erl\")\n\n        # Find a record field access like User#user.name\n        content = language_server.retrieve_full_file_content(file_path)\n        lines = content.split(\"\\n\")\n        record_field_line = None\n        for i, line in enumerate(lines):\n            if \"#user{\" in line and (\"name\" in line or \"email\" in line or \"id\" in line):\n                record_field_line = i\n                break\n\n        if record_field_line is None:\n            pytest.skip(\"Could not find record field access\")\n\n        containing_symbol = language_server.request_containing_symbol(file_path, record_field_line, 10)\n\n        if containing_symbol:\n            # Should be contained within a function\n            assert \"name\" in containing_symbol\n            expected_names = [\"create_user\", \"update_user\", \"format_user_info\"]\n            assert any(name in containing_symbol[\"name\"] for name in expected_names)\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_containing_symbol_of_spec(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test containing symbol for function specs.\"\"\"\n        file_path = os.path.join(\"src\", \"models.erl\")\n\n        # Find a -spec directive\n        content = language_server.retrieve_full_file_content(file_path)\n        lines = content.split(\"\\n\")\n        spec_line = None\n        for i, line in enumerate(lines):\n            if line.strip().startswith(\"-spec\") and \"create_user\" in line:\n                spec_line = i\n                break\n\n        if spec_line is None:\n            pytest.skip(\"Could not find -spec directive\")\n\n        containing_symbol = language_server.request_containing_symbol(file_path, spec_line, 5)\n\n        if containing_symbol:\n            # Should be contained within the module or the function it specifies\n            assert \"name\" in containing_symbol\n            expected_names = [\"models\", \"create_user\"]\n            assert any(name in containing_symbol[\"name\"] for name in expected_names)\n\n    @pytest.mark.timeout(60)  # Add 60 second timeout\n    @pytest.mark.xfail(\n        reason=\"Known intermittent timeout issue in Erlang LS in CI environments. \"\n        \"May pass locally but can timeout on slower CI systems, especially macOS. \"\n        \"Similar to known Next LS timeout issues.\",\n        strict=False,\n    )\n    @pytest.mark.parametrize(\"language_server\", [Language.ERLANG], indirect=True)\n    def test_referencing_symbols_across_files(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding references across different files.\"\"\"\n        # Test that we can find references to models module functions in services.erl\n        file_path = os.path.join(\"src\", \"models.erl\")\n\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        create_user_symbol = None\n        for symbol_group in symbols:\n            create_user_symbol = next((s for s in symbol_group if \"create_user\" in s.get(\"name\", \"\")), None)\n            if create_user_symbol:\n                break\n\n        if not create_user_symbol or \"selectionRange\" not in create_user_symbol:\n            pytest.skip(\"create_user function symbol not found\")\n\n        sel_start = create_user_symbol[\"selectionRange\"][\"start\"]\n        ref_symbols = [\n            ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        ]\n\n        # Look for cross-file references\n        cross_file_refs = [\n            symbol\n            for symbol in ref_symbols\n            if \"location\" in symbol and \"uri\" in symbol[\"location\"] and not symbol[\"location\"][\"uri\"].endswith(\"models.erl\")\n        ]\n\n        # We might find references in services.erl or test files\n        if cross_file_refs:\n            assert len(cross_file_refs) > 0, \"Should find some cross-file references\"\n"
  },
  {
    "path": "test/solidlsp/fortran/__init__.py",
    "content": "# Fortran language server tests\n"
  },
  {
    "path": "test/solidlsp/fortran/test_fortran_basic.py",
    "content": "\"\"\"\nBasic tests for Fortran language server integration.\n\nThese tests validate some low-level LSP functionality and high-level Serena APIs.\nNote: These tests require fortls to be installed: pip install fortls\n\"\"\"\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_types import SymbolKind\nfrom solidlsp.ls_utils import SymbolUtils\n\n# Mark all tests in this module as fortran tests\npytestmark = pytest.mark.fortran\n\n\nclass TestFortranLanguageServer:\n    \"\"\"Test Fortran language server functionality.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.FORTRAN], indirect=True)\n    def test_find_symbol(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding symbols using request_full_symbol_tree.\"\"\"\n        symbols = language_server.request_full_symbol_tree()\n\n        # Verify program symbol\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"test_program\"), \"test_program not found in symbol tree\"\n\n        # Verify module symbol\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"math_utils\"), \"math_utils module not found in symbol tree\"\n\n        # Verify function symbols\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"add_numbers\"), \"add_numbers function not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"multiply_numbers\"), \"multiply_numbers function not found in symbol tree\"\n\n        # Verify subroutine symbol\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"print_result\"), \"print_result subroutine not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.FORTRAN], indirect=True)\n    def test_request_document_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that document symbols can be retrieved from Fortran files.\"\"\"\n        # Test main.f90 - should have a program symbol\n        main_symbols, _ = language_server.request_document_symbols(\"main.f90\").get_all_symbols_and_roots()\n        program_names = [s.get(\"name\") for s in main_symbols]\n        assert \"test_program\" in program_names, f\"Program 'test_program' not found in main.f90. Found: {program_names}\"\n\n        # Test modules/math_utils.f90 - should have module and function symbols\n        module_symbols, _ = language_server.request_document_symbols(\"modules/math_utils.f90\").get_all_symbols_and_roots()\n        all_names = [s.get(\"name\") for s in module_symbols]\n        assert \"math_utils\" in all_names, f\"Module 'math_utils' not found. Found: {all_names}\"\n        assert \"add_numbers\" in all_names, f\"Function 'add_numbers' not found. Found: {all_names}\"\n        assert \"multiply_numbers\" in all_names, f\"Function 'multiply_numbers' not found. Found: {all_names}\"\n        assert \"print_result\" in all_names, f\"Subroutine 'print_result' not found. Found: {all_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.FORTRAN], indirect=True)\n    def test_find_references_cross_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding references across files using low-level request_references.\n\n        This tests the LSP textDocument/references capability.\n        \"\"\"\n        file_path = \"modules/math_utils.f90\"\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Find the add_numbers function\n        add_numbers_symbol = None\n        for sym in symbols[0]:\n            if sym.get(\"name\") == \"add_numbers\":\n                add_numbers_symbol = sym\n                break\n\n        assert add_numbers_symbol is not None, \"Could not find 'add_numbers' function symbol in math_utils.f90\"\n\n        # Use selectionRange to query for references\n        # Note: FortranLanguageServer automatically fixes fortls's incorrect selectionRange\n        sel_start = add_numbers_symbol[\"selectionRange\"][\"start\"]\n\n        # Query from the function name position using corrected selectionRange\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n\n        # Should find references (usage in main.f90 + definition in math_utils.f90)\n        assert len(refs) > 0, \"Should find references to add_numbers function\"\n\n        # Verify that main.f90 references the function\n        main_refs = [ref for ref in refs if \"main.f90\" in ref.get(\"relativePath\", \"\")]\n        assert (\n            len(main_refs) > 0\n        ), f\"Expected to find reference in main.f90, but found references in: {[ref.get('relativePath') for ref in refs]}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.FORTRAN], indirect=True)\n    def test_find_definition_cross_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding definition across files using request_definition.\"\"\"\n        # In main.f90, line 7 (0-indexed: line 6) contains: result = add_numbers(5.0, 3.0)\n        # We want to find the definition of add_numbers in modules/math_utils.f90\n        main_file = \"main.f90\"\n\n        # Position on 'add_numbers' usage (approximately column 13)\n        definition_location_list = language_server.request_definition(main_file, 6, 13)\n\n        if not definition_location_list:\n            pytest.skip(\"fortls does not support cross-file go-to-definition for this case\")\n\n        assert len(definition_location_list) >= 1, \"Should find at least one definition\"\n        definition_location = definition_location_list[0]\n\n        # The definition should be in modules/math_utils.f90\n        assert \"math_utils.f90\" in definition_location.get(\n            \"uri\", \"\"\n        ), f\"Expected definition to be in math_utils.f90, but found in: {definition_location.get('uri')}\"\n\n        # Verify the definition is around the correct line (line 4, 0-indexed)\n        assert (\n            definition_location[\"range\"][\"start\"][\"line\"] == 4\n        ), f\"Expected definition at line 4, but found at line {definition_location['range']['start']['line']}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.FORTRAN], indirect=True)\n    def test_request_referencing_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding symbols that reference a function - Serena's high-level API.\n\n        This tests request_referencing_symbols which returns not just locations but also\n        the containing symbols that have the references. This is different from\n        test_find_references_cross_file which only returns locations.\n\n        Note: FortranLanguageServer automatically fixes fortls's incorrect selectionRange.\n        \"\"\"\n        # Get the add_numbers function symbol from math_utils.f90\n        file_path = \"modules/math_utils.f90\"\n        symbols, _ = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Find the add_numbers function\n        add_numbers_symbol = None\n        for sym in symbols:\n            if sym.get(\"name\") == \"add_numbers\":\n                add_numbers_symbol = sym\n                break\n\n        assert add_numbers_symbol is not None, \"Could not find 'add_numbers' function symbol\"\n\n        # Use selectionRange to query for referencing symbols\n        # FortranLanguageServer automatically corrects fortls's incorrect selectionRange\n        sel_start = add_numbers_symbol[\"selectionRange\"][\"start\"]\n        referencing_symbols = language_server.request_referencing_symbols(file_path, sel_start[\"line\"], sel_start[\"character\"])\n\n        # Should find referencing symbols (not just locations, but symbols containing the references)\n        assert len(referencing_symbols) > 0, \"Should find referencing symbols when querying from function name position\"\n\n        # Extract the symbols from ReferenceInSymbol objects\n        # This is what makes this test different from test_find_references_cross_file:\n        # we're testing that we get back SYMBOLS (with name, kind, location) not just locations\n        ref_symbols = [ref.symbol for ref in referencing_symbols]\n\n        # Verify we got valid symbol structures with all required fields\n        for symbol in ref_symbols:\n            assert \"name\" in symbol, f\"Symbol should have a name: {symbol}\"\n            assert \"kind\" in symbol, f\"Symbol should have a kind: {symbol}\"\n            # Each symbol should have location information\n            assert \"location\" in symbol, f\"Symbol should have location: {symbol}\"\n\n        # Note: fortls may not return all cross-file references through request_referencing_symbols\n        # because it depends on finding containing symbols for each reference. We verify that\n        # the API works and returns valid symbols with proper structure.\n\n    @pytest.mark.parametrize(\"language_server\", [Language.FORTRAN], indirect=True)\n    def test_request_defining_symbol(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding the defining symbol - Serena's high-level API.\n\n        This is similar to test_find_definition_cross_file but uses the high-level\n        request_defining_symbol which returns a full symbol with metadata, not just a location.\n        \"\"\"\n        # In main.f90, line 7 (0-indexed: line 6) contains: result = add_numbers(5.0, 3.0)\n        # We want to find the definition of add_numbers\n        main_file = \"main.f90\"\n\n        # Get the position of add_numbers usage in main.f90\n        # Position on 'add_numbers' (approximately column 13)\n        defining_symbol = language_server.request_defining_symbol(main_file, 6, 13)\n\n        if defining_symbol is None:\n            pytest.skip(\"fortls does not support cross-file go-to-definition for this case\")\n\n        # Should find the add_numbers function with full symbol information\n        assert defining_symbol.get(\"name\") == \"add_numbers\", f\"Expected to find 'add_numbers' but got '{defining_symbol.get('name')}'\"\n\n        # Check if we have location information\n        if \"location\" not in defining_symbol or \"relativePath\" not in defining_symbol[\"location\"]:\n            pytest.skip(\"fortls found the symbol but doesn't provide complete location information\")\n\n        # The definition should be in modules/math_utils.f90\n        defining_path = defining_symbol[\"location\"][\"relativePath\"]\n        assert \"math_utils.f90\" in defining_path, f\"Expected definition to be in math_utils.f90, but found in: {defining_path}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.FORTRAN], indirect=True)\n    def test_request_containing_symbol(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding the containing symbol for a position in the code.\"\"\"\n        # Test finding the containing symbol for a position inside the add_numbers function\n        file_path = \"modules/math_utils.f90\"\n\n        # Line 8 (0-indexed: line 7) is inside the add_numbers function: \"sum = a + b\"\n        containing_symbol = language_server.request_containing_symbol(file_path, 7, 10, include_body=False)\n\n        if containing_symbol is None:\n            pytest.skip(\"fortls does not support request_containing_symbol or couldn't find the containing symbol\")\n\n        # Should find the add_numbers function as the containing symbol\n        assert (\n            containing_symbol.get(\"name\") == \"add_numbers\"\n        ), f\"Expected containing symbol 'add_numbers', got '{containing_symbol.get('name')}'\"\n\n        # Verify the symbol kind is Function\n        assert (\n            containing_symbol.get(\"kind\") == SymbolKind.Function.value\n        ), f\"Expected Function kind ({SymbolKind.Function.value}), got {containing_symbol.get('kind')}\"\n\n        # Verify location information exists\n        assert \"location\" in containing_symbol, \"Containing symbol should have location information\"\n        location = containing_symbol[\"location\"]\n        assert \"range\" in location, \"Location should contain range information\"\n        assert \"start\" in location[\"range\"] and \"end\" in location[\"range\"], \"Range should have start and end positions\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.FORTRAN], indirect=True)\n    def test_type_and_interface_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that type definitions and interfaces are properly recognized with corrected selectionRange.\n\n        This verifies that the regex pattern correctly handles:\n        - Simple type definitions (type Name)\n        - Type with double colon (type :: Name)\n        - Type with extends (type, extends(Base) :: Derived)\n        - Named interfaces\n\n        fortls returns these as SymbolKind.Class (11) for types and SymbolKind.Interface (5) for interfaces.\n        \"\"\"\n        file_path = \"modules/geometry.f90\"\n        symbols, _ = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Find type and interface symbols\n        type_names = []\n        interface_names = []\n        for sym in symbols:\n            if sym.get(\"kind\") == SymbolKind.Class.value:  # Type definitions\n                type_names.append(sym.get(\"name\"))\n            elif sym.get(\"kind\") == SymbolKind.Interface.value:  # Interfaces\n                interface_names.append(sym.get(\"name\"))\n\n        # Verify type definitions are found\n        assert \"Point2D\" in type_names, f\"Simple type 'Point2D' not found. Found types: {type_names}\"\n        assert \"Circle\" in type_names, f\"Type with :: syntax 'Circle' not found. Found types: {type_names}\"\n        assert \"Point3D\" in type_names, f\"Type with extends 'Point3D' not found. Found types: {type_names}\"\n\n        # Verify interface is found\n        assert \"distance\" in interface_names, f\"Interface 'distance' not found. Found interfaces: {interface_names}\"\n\n        # Verify selectionRange is corrected for a type symbol\n        point3d_symbol = None\n        for sym in symbols:\n            if sym.get(\"name\") == \"Point3D\":\n                point3d_symbol = sym\n                break\n\n        assert point3d_symbol is not None, \"Could not find 'Point3D' type symbol\"\n\n        # Use corrected selectionRange to find references\n        # This tests that the fix works for types (not just functions)\n        sel_start = point3d_symbol[\"selectionRange\"][\"start\"]\n\n        # Verify selectionRange points to identifier name, not line start\n        # Line for \"type, extends(Point2D) :: Point3D\" has Point3D at position > 0\n        assert (\n            sel_start[\"character\"] > 0\n        ), f\"selectionRange should point to identifier, not line start. Got character: {sel_start['character']}\"\n\n        # Test that we can find references using the corrected position\n        _refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        # refs might be empty if Point3D isn't used elsewhere, but the call should not fail\n        # The important thing is that it doesn't error due to wrong character position\n"
  },
  {
    "path": "test/solidlsp/fsharp/test_fsharp_basic.py",
    "content": "import os\nimport threading\nfrom typing import Any\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_utils import SymbolUtils\nfrom test.conftest import is_ci\n\n\n@pytest.mark.fsharp\nclass TestFSharpLanguageServer:\n    @pytest.mark.parametrize(\"language_server\", [Language.FSHARP], indirect=True)\n    def test_find_symbol(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding symbols in the full symbol tree.\"\"\"\n        symbols = language_server.request_full_symbol_tree()\n\n        # Check for main program module symbols\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Program\"), \"Program module not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"main\"), \"main function not found in symbol tree\"\n\n        # Check for Calculator module symbols\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Calculator\"), \"Calculator module not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"add\"), \"add function not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"CalculatorClass\"), \"CalculatorClass not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.FSHARP], indirect=True)\n    def test_get_document_symbols_program(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test getting document symbols from the main Program.fs file.\"\"\"\n        file_path = os.path.join(\"Program.fs\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()[0]\n\n        # Look for expected functions and modules\n        symbol_names = [s.get(\"name\") for s in symbols]\n        assert \"main\" in symbol_names, \"main function not found in Program.fs symbols\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.FSHARP], indirect=True)\n    def test_get_document_symbols_calculator(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test getting document symbols from Calculator.fs file.\"\"\"\n        file_path = os.path.join(\"Calculator.fs\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()[0]\n\n        # Look for expected functions\n        symbol_names = [s.get(\"name\") for s in symbols]\n        expected_symbols = [\"add\", \"subtract\", \"multiply\", \"divide\", \"square\", \"factorial\", \"CalculatorClass\"]\n\n        for expected in expected_symbols:\n            assert expected in symbol_names, f\"{expected} function not found in Calculator.fs symbols\"\n\n    @pytest.mark.xfail(is_ci, reason=\"Test is flaky\")  # TODO: Re-enable if the LS can be made more reliable #1040\n    @pytest.mark.parametrize(\"language_server\", [Language.FSHARP], indirect=True)\n    def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding references using symbol selection range.\"\"\"\n        file_path = os.path.join(\"Calculator.fs\")\n        symbols = language_server.request_document_symbols(file_path)\n\n        # Find the 'add' function symbol\n        add_symbol = None\n\n        for sym in symbols.iter_symbols():\n            if sym.get(\"name\") == \"add\":\n                add_symbol = sym\n                break\n\n        assert add_symbol is not None, \"Could not find 'add' function symbol in Calculator.fs\"\n\n        # Try to find references to the add function\n        sel_start = add_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"] + 1)\n\n        # The add function should be referenced in Program.fs\n        assert any(\"Program.fs\" in ref.get(\"relativePath\", \"\") for ref in refs), \"Program.fs should reference add function\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.FSHARP], indirect=True)\n    def test_nested_module_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test getting symbols from nested Models namespace.\"\"\"\n        file_path = os.path.join(\"Models\", \"Person.fs\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()[0]\n\n        # Check for expected types and modules\n        symbol_names = [s.get(\"name\") for s in symbols]\n        expected_symbols = [\"Person\", \"PersonModule\", \"Address\", \"Employee\"]\n\n        for expected in expected_symbols:\n            assert expected in symbol_names, f\"{expected} not found in Person.fs symbols\"\n\n    @pytest.mark.xfail(is_ci, reason=\"Test is flaky\")  # TODO: Re-enable if the LS can be made more reliable #1040\n    @pytest.mark.parametrize(\"language_server\", [Language.FSHARP], indirect=True)\n    def test_find_referencing_symbols_across_files(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding references to Calculator functions across files.\"\"\"\n        # Find the subtract function in Calculator.fs\n        file_path = os.path.join(\"Calculator.fs\")\n        symbols = language_server.request_document_symbols(file_path)\n\n        subtract_symbol = None\n        for sym in symbols.iter_symbols():\n            if sym.get(\"name\") == \"subtract\":\n                subtract_symbol = sym\n                break\n\n        assert subtract_symbol is not None, \"Could not find 'subtract' function symbol\"\n\n        # Find references to subtract function\n        sel_start = subtract_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"] + 1)\n\n        # The subtract function should be referenced in Program.fs\n        assert any(\"Program.fs\" in ref.get(\"relativePath\", \"\") for ref in refs), \"Program.fs should reference subtract function\"\n\n    @pytest.mark.xfail(is_ci, reason=\"Test is flaky\")  # TODO: Re-enable if the LS can be made more reliable #1040\n    @pytest.mark.parametrize(\"language_server\", [Language.FSHARP], indirect=True)\n    def test_go_to_definition(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test go-to-definition functionality.\"\"\"\n        # Test going to definition of 'add' function from Program.fs\n        program_file = os.path.join(\"Program.fs\")\n\n        # Try to find definition of 'add' function used in Program.fs\n        # This would typically be at the line where 'add 5 3' is called\n        definitions = language_server.request_definition(program_file, 10, 20)  # Approximate position\n\n        # We should get at least some definitions\n        assert len(definitions) >= 0, \"Should get definitions (even if empty for complex cases)\"\n\n    @pytest.mark.xfail(is_ci, reason=\"Test is flaky\")  # TODO: Re-enable if the LS can be made more reliable #1040\n    @pytest.mark.parametrize(\"language_server\", [Language.FSHARP], indirect=True)\n    def test_hover_information(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test hover information functionality.\"\"\"\n        file_path = os.path.join(\"Calculator.fs\")\n\n        # Try to get hover information for a function\n        hover_info = language_server.request_hover(file_path, 5, 10)  # Approximate position of a function\n\n        # Hover info might be None or contain information\n        # This is acceptable as it depends on the LSP server's capabilities and timing\n        assert hover_info is None or isinstance(hover_info, dict), \"Hover info should be None or dict\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.FSHARP], indirect=True)\n    def test_completion(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test code completion functionality.\"\"\"\n        file_path = os.path.join(\"Program.fs\")\n\n        # Use threading for cross-platform timeout (signal.SIGALRM is Unix-only)\n        result: dict[str, Any] = dict(value=None)\n        exception: dict[str, Any] = dict(value=None)\n\n        def run_completion():\n            try:\n                result[\"value\"] = language_server.request_completions(file_path, 15, 10)\n            except Exception as e:\n                exception[\"value\"] = e\n\n        thread = threading.Thread(target=run_completion, daemon=True)\n        thread.start()\n        thread.join(timeout=5)  # 5 second timeout\n\n        if thread.is_alive():\n            # Completion timed out, but this is acceptable for F# in some cases\n            # The important thing is that the language server doesn't crash\n            return\n\n        if exception[\"value\"]:\n            raise exception[\"value\"]\n\n        assert isinstance(result[\"value\"], list), \"Completions should be a list\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.FSHARP], indirect=True)\n    def test_diagnostics(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test getting diagnostics (errors, warnings) from F# files.\"\"\"\n        file_path = os.path.join(\"Program.fs\")\n\n        # FsAutoComplete uses publishDiagnostics notifications instead of textDocument/diagnostic requests\n        # So we'll test that the language server can handle files without crashing\n        # In real usage, diagnostics would come through the publishDiagnostics notification handler\n\n        # Test that we can at least work with the file (open/close cycle)\n        with language_server.open_file(file_path) as _:\n            # If we can open and close the file without errors, basic diagnostics support is working\n            pass\n\n        # This is a successful test - FsAutoComplete is working with F# files\n        assert True, \"F# language server can handle files successfully\"\n"
  },
  {
    "path": "test/solidlsp/go/test_go_basic.py",
    "content": "import os\nfrom pathlib import Path\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_utils import SymbolUtils\n\n\n@pytest.mark.go\nclass TestGoLanguageServer:\n    @pytest.mark.parametrize(\"language_server\", [Language.GO], indirect=True)\n    def test_find_symbol(self, language_server: SolidLanguageServer) -> None:\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"main\"), \"main function not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Helper\"), \"Helper function not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"DemoStruct\"), \"DemoStruct not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.GO], indirect=True)\n    def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:\n        file_path = os.path.join(\"main.go\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        helper_symbol = None\n        for sym in symbols[0]:\n            if sym.get(\"name\") == \"Helper\":\n                helper_symbol = sym\n                break\n        assert helper_symbol is not None, \"Could not find 'Helper' function symbol in main.go\"\n        sel_start = helper_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        assert any(\"main.go\" in ref.get(\"uri\", \"\") for ref in refs), \"Expected at least one reference result to point at main.go\"\n\n\ndef _filter_symbols_by_name_in_repo(symbols: list | None, target_name: str, repo_name: str = \"test_repo\") -> list:\n    \"\"\"Filter workspace symbols to exact name matches in the test repo.\"\"\"\n    if symbols is None:\n        return []\n    return [s for s in symbols if s.get(\"name\") == target_name and repo_name in s.get(\"location\", {}).get(\"uri\", \"\")]\n\n\n@pytest.mark.go\nclass TestGoBuildTags:\n    \"\"\"Tests for Go build tag/constraint support.\"\"\"\n\n    def _copy_go_fixture(self, tmp_path: Path) -> Path:\n        \"\"\"Copy Go fixture repo into tmp_path.\"\"\"\n        import shutil\n\n        from test.conftest import get_repo_path\n\n        fixture_path = get_repo_path(Language.GO)\n        target_path = tmp_path / \"test_repo\"\n\n        shutil.copytree(fixture_path, target_path)\n        return target_path\n\n    def test_default_context_contains_xnotfoo(self, tmp_path: Path) -> None:\n        \"\"\"Default build context should contain XNotFoo and not XFoo.\"\"\"\n        from test.conftest import start_ls_context\n\n        repo_path = self._copy_go_fixture(tmp_path)\n\n        with start_ls_context(Language.GO, repo_path=str(repo_path), solidlsp_dir=tmp_path) as ls:\n            xnotfoo_symbols = ls.request_workspace_symbol(\"XNotFoo\")\n            xfoo_symbols = ls.request_workspace_symbol(\"XFoo\")\n\n            xnotfoo_matches = _filter_symbols_by_name_in_repo(xnotfoo_symbols, \"XNotFoo\")\n            xfoo_matches = _filter_symbols_by_name_in_repo(xfoo_symbols, \"XFoo\")\n\n            assert len(xnotfoo_matches) > 0, \"Default context should contain XNotFoo\"\n            assert len(xfoo_matches) == 0, \"Default context should NOT contain XFoo\"\n\n    def test_foo_context_contains_xfoo(self, tmp_path: Path) -> None:\n        \"\"\"Build context with -tags=foo should contain XFoo and not XNotFoo.\"\"\"\n        from test.conftest import start_ls_context\n\n        repo_path = self._copy_go_fixture(tmp_path)\n\n        ls_settings = {\n            Language.GO: {\n                \"gopls_settings\": {\n                    \"buildFlags\": [\"-tags=foo\"],\n                },\n            },\n        }\n\n        with start_ls_context(Language.GO, repo_path=str(repo_path), ls_specific_settings=ls_settings, solidlsp_dir=tmp_path) as ls:\n            xfoo_symbols = ls.request_workspace_symbol(\"XFoo\")\n            xnotfoo_symbols = ls.request_workspace_symbol(\"XNotFoo\")\n\n            xfoo_matches = _filter_symbols_by_name_in_repo(xfoo_symbols, \"XFoo\")\n            xnotfoo_matches = _filter_symbols_by_name_in_repo(xnotfoo_symbols, \"XNotFoo\")\n\n            assert len(xfoo_matches) > 0, \"Foo context should contain XFoo\"\n            assert len(xnotfoo_matches) == 0, \"Foo context should NOT contain XNotFoo\"\n\n    def test_disk_cache_is_invalidated_on_build_context_switch(self, tmp_path: Path) -> None:\n        \"\"\"Go build context switches must not reuse persisted SolidLSP document-symbol caches.\"\"\"\n        import pickle\n\n        from test.conftest import start_ls_context\n\n        repo_path = self._copy_go_fixture(tmp_path)\n\n        ls_settings_foo = {\n            Language.GO: {\n                \"gopls_settings\": {\n                    \"buildFlags\": [\"-tags=foo\"],\n                },\n            },\n        }\n\n        main_go = os.path.join(\"main.go\")\n\n        def _assert_caches_loaded_and_clean(ls: SolidLanguageServer) -> None:\n            # White-box assertions: SolidLanguageServer currently has no public API to verify that\n            # caches were loaded from disk vs created lazily on first request.\n            assert ls._raw_document_symbols_cache, \"Expected raw document-symbol cache to load from disk\"\n            assert ls._document_symbols_cache, \"Expected document-symbol cache to load from disk\"\n            assert not ls._raw_document_symbols_cache_is_modified\n            assert not ls._document_symbols_cache_is_modified\n\n        def _assert_caches_empty(ls: SolidLanguageServer) -> None:\n            assert ls._raw_document_symbols_cache == {}\n            assert ls._document_symbols_cache == {}\n\n        def _assert_caches_modified(ls: SolidLanguageServer) -> None:\n            assert ls._raw_document_symbols_cache_is_modified\n            assert ls._document_symbols_cache_is_modified\n\n        # Run 1 (default context): populate caches and persist them to disk.\n        with start_ls_context(Language.GO, repo_path=str(repo_path), solidlsp_dir=tmp_path) as ls_default:\n            _ = ls_default.request_document_symbols(main_go)\n\n            default_raw_cache_version = ls_default._raw_document_symbols_cache_version()\n            default_doc_cache_version = ls_default._document_symbols_cache_version()\n\n            ls_default.save_cache()\n            cache_dir = ls_default.cache_dir\n\n            cache_files = [p for p in cache_dir.rglob(\"*\") if p.is_file()]\n            assert cache_files, f\"Expected SolidLSP to create cache artifacts under {cache_dir}\"\n\n            versioned_cache_files: list[tuple[Path, object]] = []\n            for p in cache_files:\n                try:\n                    with p.open(\"rb\") as f:\n                        data = pickle.load(f)\n                except Exception:\n                    continue\n                if isinstance(data, dict) and \"__cache_version\" in data:\n                    versioned_cache_files.append((p, data[\"__cache_version\"]))\n\n            assert versioned_cache_files, f\"Expected at least one SolidLSP cache file with a __cache_version under {cache_dir}\"\n            saved_versions = {v for _, v in versioned_cache_files}\n            assert (\n                default_raw_cache_version in saved_versions or default_doc_cache_version in saved_versions\n            ), \"Expected at least one persisted cache to match the default-context cache version\"\n\n        # Run 2 (default context again): prove that persisted caches are actually loaded and used.\n        with start_ls_context(Language.GO, repo_path=str(repo_path), solidlsp_dir=tmp_path) as ls_default_again:\n            assert ls_default_again.cache_dir == cache_dir\n\n            _assert_caches_loaded_and_clean(ls_default_again)\n\n            _ = ls_default_again.request_document_symbols(main_go)\n\n            # A cache hit should not mark caches as modified.\n            assert not ls_default_again._raw_document_symbols_cache_is_modified\n            assert not ls_default_again._document_symbols_cache_is_modified\n\n        # Run 3 (foo context): the same on-disk cache directory exists, but MUST be treated as stale.\n        with start_ls_context(\n            Language.GO,\n            repo_path=str(repo_path),\n            ls_specific_settings=ls_settings_foo,\n            solidlsp_dir=tmp_path,\n        ) as ls_foo:\n            assert ls_foo.cache_dir == cache_dir\n\n            foo_raw_cache_version = ls_foo._raw_document_symbols_cache_version()\n            foo_doc_cache_version = ls_foo._document_symbols_cache_version()\n\n            assert foo_raw_cache_version != default_raw_cache_version\n            assert foo_doc_cache_version != default_doc_cache_version\n\n            # Different build context => persisted caches must not be loaded.\n            _assert_caches_empty(ls_foo)\n\n            _ = ls_foo.request_document_symbols(main_go)\n\n            # A cache miss should repopulate and mark caches modified.\n            _assert_caches_modified(ls_foo)\n"
  },
  {
    "path": "test/solidlsp/groovy/test_groovy_basic.py",
    "content": "import os\nfrom pathlib import Path\n\nimport pytest\n\nfrom serena.constants import SERENA_MANAGED_DIR_NAME\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language, LanguageServerConfig\nfrom solidlsp.ls_utils import SymbolUtils\nfrom solidlsp.settings import SolidLSPSettings\n\n\n@pytest.mark.groovy\nclass TestGroovyLanguageServer:\n    language_server: SolidLanguageServer | None = None\n    test_repo_path: Path = Path(__file__).parent.parent.parent / \"resources\" / \"repos\" / \"groovy\" / \"test_repo\"\n\n    @classmethod\n    def setup_class(cls):\n        \"\"\"\n        Set up test class with Groovy test repository.\n        \"\"\"\n        if not cls.test_repo_path.exists():\n            pytest.skip(\"Groovy test repository not found\")\n\n        # Use JAR path from environment variable\n        ls_jar_path = os.environ.get(\"GROOVY_LS_JAR_PATH\")\n        if not ls_jar_path or not os.path.exists(ls_jar_path):\n            pytest.skip(\n                \"Groovy Language Server JAR not found. Set GROOVY_LS_JAR_PATH environment variable to run tests.\",\n                allow_module_level=True,\n            )\n\n        # Get JAR options from environment variable\n        ls_jar_options = os.environ.get(\"GROOVY_LS_JAR_OPTIONS\", \"\")\n        ls_java_home_path = os.environ.get(\"GROOVY_LS_JAVA_HOME_PATH\")\n\n        groovy_settings = {\"ls_jar_path\": ls_jar_path, \"ls_jar_options\": ls_jar_options}\n        if ls_java_home_path:\n            groovy_settings[\"ls_java_home_path\"] = ls_java_home_path\n\n        # Create language server directly with Groovy-specific settings\n        repo_path = str(cls.test_repo_path)\n        config = LanguageServerConfig(code_language=Language.GROOVY, ignored_paths=[], trace_lsp_communication=False)\n\n        project_data_path = os.path.join(repo_path, SERENA_MANAGED_DIR_NAME)\n        solidlsp_settings = SolidLSPSettings(\n            solidlsp_dir=str(Path.home() / \".serena\"),\n            project_data_path=project_data_path,\n            ls_specific_settings={Language.GROOVY: groovy_settings},\n        )\n\n        cls.language_server = SolidLanguageServer.create(config, repo_path, solidlsp_settings=solidlsp_settings)\n        cls.language_server.start()\n\n    @classmethod\n    def teardown_class(cls):\n        \"\"\"\n        Clean up language server.\n        \"\"\"\n        if cls.language_server is not None:\n            cls.language_server.stop()\n\n    def test_find_symbol(self) -> None:\n        assert self.language_server is not None\n        symbols = self.language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Main\"), \"Main class not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Utils\"), \"Utils class not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Model\"), \"Model class not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"ModelUser\"), \"ModelUser class not found in symbol tree\"\n\n    def test_find_referencing_class_symbols(self) -> None:\n        assert self.language_server is not None\n        file_path = os.path.join(\"src\", \"main\", \"groovy\", \"com\", \"example\", \"Utils.groovy\")\n        refs = self.language_server.request_references(file_path, 3, 6)\n        assert any(\"Main.groovy\" in ref.get(\"relativePath\", \"\") for ref in refs), \"Utils should be referenced from Main.groovy\"\n\n        file_path = os.path.join(\"src\", \"main\", \"groovy\", \"com\", \"example\", \"Model.groovy\")\n        symbols = self.language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        model_symbol = None\n        for sym in symbols[0]:\n            if sym.get(\"name\") == \"com.example.Model\" and sym.get(\"kind\") == 5:\n                model_symbol = sym\n                break\n        assert model_symbol is not None, \"Could not find 'Model' class symbol in Model.groovy\"\n\n        if \"selectionRange\" in model_symbol:\n            sel_start = model_symbol[\"selectionRange\"][\"start\"]\n        else:\n            sel_start = model_symbol[\"range\"][\"start\"]\n        refs = self.language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n\n        main_refs = [ref for ref in refs if \"Main.groovy\" in ref.get(\"relativePath\", \"\")]\n        assert len(main_refs) >= 2, f\"Model should be referenced from Main.groovy at least 2 times, found {len(main_refs)}\"\n\n        model_user_refs = [ref for ref in refs if \"ModelUser.groovy\" in ref.get(\"relativePath\", \"\")]\n        assert len(model_user_refs) >= 1, f\"Model should be referenced from ModelUser.groovy at least 1 time, found {len(model_user_refs)}\"\n\n    def test_overview_methods(self) -> None:\n        assert self.language_server is not None\n        symbols = self.language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Main\"), \"Main missing from overview\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Utils\"), \"Utils missing from overview\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Model\"), \"Model missing from overview\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"ModelUser\"), \"ModelUser missing from overview\"\n"
  },
  {
    "path": "test/solidlsp/haskell/__init__.py",
    "content": "# Haskell language server tests\n"
  },
  {
    "path": "test/solidlsp/haskell/test_haskell_basic.py",
    "content": "\"\"\"\nRigorous tests for Haskell Language Server integration with Serena.\n\nTests prove that Serena's symbol tools can:\n1. Discover all expected symbols with precise matching\n2. Track cross-file references accurately\n3. Identify data type structures and record fields\n4. Navigate between definitions and usages\n\nTest Repository Structure:\n- src/Calculator.hs: Calculator data type, arithmetic functions (add, subtract, multiply, divide, calculate)\n- src/Helper.hs: Helper functions (validateNumber, isPositive, isNegative, absolute)\n- app/Main.hs: Main entry point using Calculator and Helper modules\n\"\"\"\n\nimport sys\n\nimport pytest\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\n\n@pytest.mark.haskell\n@pytest.mark.skipif(sys.platform == \"win32\", reason=\"HLS not installed on Windows CI\")\nclass TestHaskellLanguageServer:\n    @pytest.mark.parametrize(\"language_server\", [Language.HASKELL], indirect=True)\n    def test_calculator_module_symbols(self, language_server: SolidLanguageServer):\n        \"\"\"\n        Test precise symbol discovery in Calculator.hs.\n\n        Verifies that Serena can identify:\n        - Data type definition (Calculator with record fields)\n        - All exported functions with correct names\n        - Module structure\n        \"\"\"\n        all_symbols, _ = language_server.request_document_symbols(\"src/Calculator.hs\").get_all_symbols_and_roots()\n        symbol_names = {s[\"name\"] for s in all_symbols}\n\n        # Verify exact set of expected top-level symbols\n        expected_symbols = {\n            \"Calculator\",  # Data type\n            \"add\",  # Function: Int -> Int -> Int\n            \"subtract\",  # Function: Int -> Int -> Int\n            \"multiply\",  # Function: Int -> Int -> Int\n            \"divide\",  # Function: Int -> Int -> Maybe Int\n            \"calculate\",  # Function: Calculator -> String -> Int -> Int -> Maybe Int\n        }\n\n        # Verify all expected symbols are present\n        missing = expected_symbols - symbol_names\n        assert not missing, f\"Missing expected symbols in Calculator.hs: {missing}\"\n\n        # Verify Calculator data type exists\n        calculator_symbol = next((s for s in all_symbols if s[\"name\"] == \"Calculator\"), None)\n        assert calculator_symbol is not None, \"Calculator data type not found\"\n\n        # The Calculator should be identified as a data type\n        # HLS may use different SymbolKind values (1=File, 5=Class, 23=Struct)\n        assert calculator_symbol[\"kind\"] in [\n            1,\n            5,\n            23,\n        ], f\"Calculator should be a data type (kind 1, 5, or 23), got kind {calculator_symbol['kind']}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HASKELL], indirect=True)\n    def test_helper_module_symbols(self, language_server: SolidLanguageServer):\n        \"\"\"\n        Test precise symbol discovery in Helper.hs.\n\n        Verifies Serena identifies all helper functions that are imported\n        and used by Calculator module.\n        \"\"\"\n        all_symbols, _ = language_server.request_document_symbols(\"src/Helper.hs\").get_all_symbols_and_roots()\n        symbol_names = {s[\"name\"] for s in all_symbols}\n\n        # Verify expected helper functions (module name may also appear)\n        expected_symbols = {\n            \"validateNumber\",  # Function used by Calculator.add and Calculator.subtract\n            \"isPositive\",  # Predicate function\n            \"isNegative\",  # Predicate function used by absolute\n            \"absolute\",  # Function that uses isNegative\n        }\n\n        # All expected symbols should be present (module name is optional)\n        missing = expected_symbols - symbol_names\n        assert not missing, f\"Missing expected symbols in Helper.hs: {missing}\"\n\n        # Verify no unexpected symbols beyond the module name\n        extra = symbol_names - expected_symbols - {\"Helper\"}\n        assert not extra, f\"Unexpected symbols in Helper.hs: {extra}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HASKELL], indirect=True)\n    def test_main_module_imports(self, language_server: SolidLanguageServer):\n        \"\"\"\n        Test that Main.hs properly references both Calculator and Helper modules.\n\n        Verifies Serena can identify cross-module dependencies.\n        \"\"\"\n        all_symbols, _ = language_server.request_document_symbols(\"app/Main.hs\").get_all_symbols_and_roots()\n        symbol_names = {s[\"name\"] for s in all_symbols}\n\n        # Main.hs should have the main function\n        assert \"main\" in symbol_names, \"Main.hs should contain 'main' function\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HASKELL], indirect=True)\n    def test_cross_file_references_validateNumber(self, language_server: SolidLanguageServer):\n        \"\"\"\n        Test cross-file reference tracking for validateNumber function.\n\n        validateNumber is defined in Helper.hs:9 and used in:\n        - Calculator.hs:21 (in add function)\n        - Calculator.hs:25 (in subtract function)\n\n        This proves Serena can track function usage across module boundaries.\n        \"\"\"\n        # Get references to validateNumber (defined at line 9, 0-indexed = line 8)\n        references = language_server.request_references(\"src/Helper.hs\", line=8, column=0)\n\n        # Should find at least: definition in Helper.hs + 2 usages in Calculator.hs\n        assert len(references) >= 2, f\"Expected at least 2 references to validateNumber (used in add and subtract), got {len(references)}\"\n\n        # Verify we have references in Calculator.hs\n        reference_paths = [ref[\"relativePath\"] for ref in references]\n        calculator_refs = [path for path in reference_paths if \"Calculator.hs\" in path]\n\n        assert len(calculator_refs) >= 2, (\n            f\"Expected at least 2 references in Calculator.hs (add and subtract functions), \"\n            f\"got {len(calculator_refs)} references in Calculator.hs\"\n        )\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HASKELL], indirect=True)\n    def test_within_file_references_isNegative(self, language_server: SolidLanguageServer):\n        \"\"\"\n        Test within-file reference tracking for isNegative function.\n\n        isNegative is defined in Helper.hs:17 and used in Helper.hs:22 (absolute function).\n        This proves Serena can track intra-module function calls.\n        \"\"\"\n        # isNegative defined at line 17 (0-indexed = line 16)\n        references = language_server.request_references(\"src/Helper.hs\", line=16, column=0)\n\n        # Should find: definition + usage in absolute function\n        assert len(references) >= 1, f\"Expected at least 1 reference to isNegative (used in absolute), got {len(references)}\"\n\n        # All references should be in Helper.hs\n        reference_paths = [ref[\"relativePath\"] for ref in references]\n        assert all(\n            \"Helper.hs\" in path for path in reference_paths\n        ), f\"All isNegative references should be in Helper.hs, got: {reference_paths}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HASKELL], indirect=True)\n    def test_function_references_from_main(self, language_server: SolidLanguageServer):\n        \"\"\"\n        Test that functions used in Main.hs can be traced back to their definitions.\n\n        Main.hs:12 calls 'add' from Calculator module.\n        Main.hs:25 calls 'isPositive' from Helper module.\n        Main.hs:26 calls 'absolute' from Helper module.\n\n        This proves Serena can track cross-module function calls from executable code.\n        \"\"\"\n        # Test 'add' function references (defined in Calculator.hs:20, 0-indexed = line 19)\n        add_refs = language_server.request_references(\"src/Calculator.hs\", line=19, column=0)\n\n        # Should find references in Main.hs and possibly Calculator.hs (calculate function uses it)\n        assert len(add_refs) >= 1, f\"Expected at least 1 reference to 'add', got {len(add_refs)}\"\n\n        add_ref_paths = [ref[\"relativePath\"] for ref in add_refs]\n        # Should have at least one reference in Main.hs or Calculator.hs\n        assert any(\n            \"Main.hs\" in path or \"Calculator.hs\" in path for path in add_ref_paths\n        ), f\"Expected 'add' to be referenced in Main.hs or Calculator.hs, got: {add_ref_paths}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HASKELL], indirect=True)\n    def test_multiply_function_usage_in_calculate(self, language_server: SolidLanguageServer):\n        \"\"\"\n        Test that multiply function usage is tracked within Calculator module.\n\n        multiply is defined in Calculator.hs:28 and used in:\n        - Calculator.hs:41 (in calculate function via pattern matching)\n        - Main.hs:20 (via calculate call with \"multiply\" operator)\n\n        This proves Serena can track function references even when called indirectly.\n        \"\"\"\n        # multiply defined at line 28 (0-indexed = line 27)\n        multiply_refs = language_server.request_references(\"src/Calculator.hs\", line=27, column=0)\n\n        # Should find at least the usage in calculate function\n        assert len(multiply_refs) >= 1, f\"Expected at least 1 reference to 'multiply', got {len(multiply_refs)}\"\n\n        # Should have reference in Calculator.hs (calculate function)\n        multiply_ref_paths = [ref[\"relativePath\"] for ref in multiply_refs]\n        assert any(\n            \"Calculator.hs\" in path for path in multiply_ref_paths\n        ), f\"Expected 'multiply' to be referenced in Calculator.hs, got: {multiply_ref_paths}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HASKELL], indirect=True)\n    def test_data_type_constructor_references(self, language_server: SolidLanguageServer):\n        \"\"\"\n        Test that Calculator data type constructor usage is tracked.\n\n        Calculator is defined in Calculator.hs:14 and used in:\n        - Main.hs:8 (constructor call: Calculator \"TestCalc\" 1)\n        - Calculator.hs:37 (type signature for calculate function)\n\n        This proves Serena can track data type constructor references.\n        \"\"\"\n        # Calculator data type defined at line 14 (0-indexed = line 13)\n        calculator_refs = language_server.request_references(\"src/Calculator.hs\", line=13, column=5)\n\n        # Should find usage in Main.hs\n        assert len(calculator_refs) >= 1, f\"Expected at least 1 reference to Calculator constructor, got {len(calculator_refs)}\"\n\n        # Should have at least one reference in Main.hs or Calculator.hs\n        calc_ref_paths = [ref[\"relativePath\"] for ref in calculator_refs]\n        assert any(\n            \"Main.hs\" in path or \"Calculator.hs\" in path for path in calc_ref_paths\n        ), f\"Expected Calculator to be referenced in Main.hs or Calculator.hs, got: {calc_ref_paths}\"\n"
  },
  {
    "path": "test/solidlsp/hlsl/__init__.py",
    "content": "\n"
  },
  {
    "path": "test/solidlsp/hlsl/test_hlsl_basic.py",
    "content": "\"\"\"\nBasic tests for HLSL language server integration (shader-language-server).\n\nThis module tests Language.HLSL using shader-language-server from antaalt/shader-sense.\nTests are skipped if the language server is not available.\n\"\"\"\n\nfrom typing import Any\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_exceptions import SolidLSPException\nfrom solidlsp.ls_utils import SymbolUtils\n\n\ndef _find_symbol_by_name(language_server: SolidLanguageServer, file_path: str, name: str) -> dict[str, Any] | None:\n    \"\"\"Find a top-level symbol by name in a file's document symbols.\"\"\"\n    symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n    return next((s for s in symbols[0] if s.get(\"name\") == name), None)\n\n\n# ── Symbol Discovery ─────────────────────────────────────────────\n\n\n@pytest.mark.hlsl\nclass TestHlslSymbols:\n    \"\"\"Tests for document symbol extraction.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HLSL], indirect=True)\n    def test_find_struct(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"VertexInput struct should appear in common.hlsl symbols.\"\"\"\n        symbol = _find_symbol_by_name(language_server, \"common.hlsl\", \"VertexInput\")\n        assert symbol is not None, \"Expected 'VertexInput' struct in document symbols\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HLSL], indirect=True)\n    def test_find_function(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"SafeNormalize function should appear in common.hlsl.\"\"\"\n        symbol = _find_symbol_by_name(language_server, \"common.hlsl\", \"SafeNormalize\")\n        assert symbol is not None, \"Expected 'SafeNormalize' function in document symbols\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HLSL], indirect=True)\n    def test_find_cbuffer_members(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Cbuffer members should appear as variables in compute_test.hlsl.\n\n        Note: shader-language-server reports cbuffer members as individual\n        variables (kind 13), not the cbuffer name itself as a symbol.\n        \"\"\"\n        symbol = _find_symbol_by_name(language_server, \"compute_test.hlsl\", \"TextureSize\")\n        assert symbol is not None, \"Expected 'TextureSize' cbuffer member in document symbols\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HLSL], indirect=True)\n    def test_find_compute_kernel(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"CSMain kernel should appear in compute_test.hlsl.\"\"\"\n        symbol = _find_symbol_by_name(language_server, \"compute_test.hlsl\", \"CSMain\")\n        assert symbol is not None, \"Expected 'CSMain' compute kernel in document symbols\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HLSL], indirect=True)\n    def test_full_symbol_tree(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Full symbol tree should contain symbols from multiple files.\"\"\"\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"VertexInput\"), \"VertexInput not in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"CalculateDiffuse\"), \"CalculateDiffuse not in symbol tree\"\n\n\n# ── Go-to-Definition ─────────────────────────────────────────────\n\n\n@pytest.mark.hlsl\nclass TestHlslDefinition:\n    \"\"\"Tests for go-to-definition capability.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HLSL], indirect=True)\n    def test_goto_definition_cross_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Navigating to SafeNormalize call in lighting.hlsl should resolve to common.hlsl.\n\n        lighting.hlsl line 22 (0-indexed): \"    float3 halfVec = SafeNormalize(-lightDir + viewDir);\"\n        SafeNormalize starts at column 21.\n        \"\"\"\n        definitions = language_server.request_definition(\"lighting.hlsl\", 22, 21)\n        assert len(definitions) >= 1, f\"Expected at least 1 definition, got {len(definitions)}\"\n        def_paths = [d.get(\"relativePath\", d.get(\"uri\", \"\")) for d in definitions]\n        assert any(\"common.hlsl\" in p for p in def_paths), f\"Expected definition in common.hlsl, got: {def_paths}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HLSL], indirect=True)\n    def test_goto_definition_cross_file_remap(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Navigating to Remap call in compute_test.hlsl should resolve to common.hlsl.\n\n        compute_test.hlsl line 20 (0-indexed): \"        Remap(color.r, 0.0, 1.0, 0.2, 0.8),\"\n        Remap starts at column 8.\n        \"\"\"\n        definitions = language_server.request_definition(\"compute_test.hlsl\", 20, 8)\n        assert len(definitions) >= 1, f\"Expected at least 1 definition, got {len(definitions)}\"\n        def_paths = [d.get(\"relativePath\", d.get(\"uri\", \"\")) for d in definitions]\n        assert any(\"common.hlsl\" in p for p in def_paths), f\"Expected definition in common.hlsl, got: {def_paths}\"\n\n\n# ── References ────────────────────────────────────────────────────\n\n\n@pytest.mark.hlsl\nclass TestHlslReferences:\n    \"\"\"Tests for find-references capability.\n\n    shader-language-server does not advertise referencesProvider, so\n    request_references is expected to return an empty list.\n    \"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HLSL], indirect=True)\n    def test_references_not_supported(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"References request should raise because shader-language-server does not support it.\n\n        common.hlsl line 17 (0-indexed): \"float3 SafeNormalize(float3 v)\"\n        SafeNormalize starts at column 7.\n        \"\"\"\n        with pytest.raises(SolidLSPException, match=\"Method not found\"):\n            language_server.request_references(\"common.hlsl\", 17, 7)\n\n\n# ── Hover ─────────────────────────────────────────────────────────\n\n\ndef _extract_hover_text(hover_info: dict[str, Any]) -> str:\n    \"\"\"Extract the text content from an LSP hover response.\"\"\"\n    contents = hover_info[\"contents\"]\n    if isinstance(contents, dict):\n        return contents.get(\"value\", \"\")\n    elif isinstance(contents, str):\n        return contents\n    return str(contents)\n\n\n@pytest.mark.hlsl\nclass TestHlslHover:\n    \"\"\"Tests for hover information.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HLSL], indirect=True)\n    def test_hover_on_function(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Hovering over SafeNormalize definition should return info.\n\n        common.hlsl line 17 (0-indexed): \"float3 SafeNormalize(float3 v)\"\n        SafeNormalize starts at column 7.\n        \"\"\"\n        hover_info = language_server.request_hover(\"common.hlsl\", 17, 7)\n        assert hover_info is not None, \"Hover should return information for SafeNormalize\"\n        assert \"contents\" in hover_info, \"Hover should have contents\"\n        hover_text = _extract_hover_text(hover_info)\n        assert len(hover_text) > 0, \"Hover text should not be empty\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HLSL], indirect=True)\n    def test_hover_on_struct(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Hovering over VertexInput should return struct info.\n\n        common.hlsl line 3 (0-indexed): \"struct VertexInput\"\n        VertexInput starts at column 7.\n        \"\"\"\n        hover_info = language_server.request_hover(\"common.hlsl\", 3, 7)\n        assert hover_info is not None, \"Hover should return information for VertexInput\"\n        assert \"contents\" in hover_info, \"Hover should have contents\"\n"
  },
  {
    "path": "test/solidlsp/hlsl/test_hlsl_full_index.py",
    "content": "\"\"\"\nRegression tests for HLSL full symbol tree indexing.\n\nThese tests verify that request_full_symbol_tree() correctly indexes all files,\nincluding .hlsl includes in subdirectories. This catches bugs where files are\nsilently dropped during workspace-wide indexing.\n\"\"\"\n\nfrom typing import Any\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_types import SymbolKind\nfrom solidlsp.ls_utils import SymbolUtils\n\n\ndef _collect_file_names(symbols: list[dict[str, Any]]) -> set[str]:\n    \"\"\"Recursively collect the names of all File-kind symbols in the tree.\"\"\"\n    names: set[str] = set()\n    for sym in symbols:\n        if sym.get(\"kind\") == SymbolKind.File:\n            names.add(sym[\"name\"])\n        if \"children\" in sym:\n            names.update(_collect_file_names(sym[\"children\"]))\n    return names\n\n\nEXPECTED_FILES = {\"common\", \"lighting\", \"compute_test\", \"terrain_sdf\"}\n\nTERRAIN_SDF_UNIQUE_SYMBOLS = {\"SampleSDF\", \"CalculateGradient\", \"SDFBrickData\"}\n\n\n@pytest.mark.hlsl\nclass TestHlslFullIndex:\n    \"\"\"Tests for full symbol tree indexing completeness.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HLSL], indirect=True)\n    def test_all_files_indexed_in_symbol_tree(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Every .hlsl file in the test repo must appear as a File symbol in the tree.\"\"\"\n        symbols = language_server.request_full_symbol_tree()\n        file_names = _collect_file_names(symbols)\n        missing = EXPECTED_FILES - file_names\n        assert not missing, f\"Files missing from full symbol tree: {missing}. Found: {file_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HLSL], indirect=True)\n    def test_subdirectory_file_symbols_present(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Symbols unique to terrain/terrain_sdf.hlsl must appear in the full tree.\"\"\"\n        symbols = language_server.request_full_symbol_tree()\n        for name in TERRAIN_SDF_UNIQUE_SYMBOLS:\n            assert SymbolUtils.symbol_tree_contains_name(\n                symbols, name\n            ), f\"Expected '{name}' from terrain/terrain_sdf.hlsl in full symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.HLSL], indirect=True)\n    def test_include_file_document_symbols_directly(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"request_document_symbols on terrain/terrain_sdf.hlsl should return its symbols.\"\"\"\n        doc_symbols = language_server.request_document_symbols(\"terrain/terrain_sdf.hlsl\")\n        all_symbols = doc_symbols.get_all_symbols_and_roots()\n        symbol_names = {s.get(\"name\") for s in all_symbols[0]}\n        for name in TERRAIN_SDF_UNIQUE_SYMBOLS:\n            assert name in symbol_names, f\"Expected '{name}' in document symbols for terrain/terrain_sdf.hlsl, got: {symbol_names}\"\n"
  },
  {
    "path": "test/solidlsp/java/test_java_basic.py",
    "content": "import os\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_utils import SymbolUtils\nfrom test.conftest import language_tests_enabled\n\npytestmark = [pytest.mark.java, pytest.mark.skipif(not language_tests_enabled(Language.JAVA), reason=\"Java tests disabled\")]\n\n\nclass TestJavaLanguageServer:\n    @pytest.mark.parametrize(\"language_server\", [Language.JAVA], indirect=True)\n    def test_find_symbol(self, language_server: SolidLanguageServer) -> None:\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Main\"), \"Main class not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Utils\"), \"Utils class not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Model\"), \"Model class not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.JAVA], indirect=True)\n    def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:\n        # Use correct Maven/Java file paths\n        file_path = os.path.join(\"src\", \"main\", \"java\", \"test_repo\", \"Utils.java\")\n        refs = language_server.request_references(file_path, 4, 20)\n        assert any(\"Main.java\" in ref.get(\"relativePath\", \"\") for ref in refs), \"Main should reference Utils.printHello\"\n\n        # Dynamically determine the correct line/column for the 'Model' class name\n        file_path = os.path.join(\"src\", \"main\", \"java\", \"test_repo\", \"Model.java\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        model_symbol = None\n        for sym in symbols[0]:\n            if sym.get(\"name\") == \"Model\" and sym.get(\"kind\") == 5:  # 5 = Class\n                model_symbol = sym\n                break\n        assert model_symbol is not None, \"Could not find 'Model' class symbol in Model.java\"\n        # Use selectionRange if present, otherwise fall back to range\n        if \"selectionRange\" in model_symbol:\n            sel_start = model_symbol[\"selectionRange\"][\"start\"]\n        else:\n            sel_start = model_symbol[\"range\"][\"start\"]\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        assert any(\n            \"Main.java\" in ref.get(\"relativePath\", \"\") for ref in refs\n        ), \"Main should reference Model (tried all positions in selectionRange)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.JAVA], indirect=True)\n    def test_overview_methods(self, language_server: SolidLanguageServer) -> None:\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Main\"), \"Main missing from overview\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Utils\"), \"Utils missing from overview\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Model\"), \"Model missing from overview\"\n"
  },
  {
    "path": "test/solidlsp/julia/test_julia_basic.py",
    "content": "import pytest\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\n\n@pytest.mark.julia\nclass TestJuliaLanguageServer:\n    @pytest.mark.parametrize(\"language_server\", [Language.JULIA], indirect=True)\n    def test_julia_symbols(self, language_server: SolidLanguageServer):\n        \"\"\"\n        Test if we can find the top-level symbols in the main.jl file.\n        \"\"\"\n        all_symbols, _ = language_server.request_document_symbols(\"main.jl\").get_all_symbols_and_roots()\n        symbol_names = {s[\"name\"] for s in all_symbols}\n        assert \"calculate_sum\" in symbol_names\n        assert \"main\" in symbol_names\n\n    @pytest.mark.parametrize(\"language_server\", [Language.JULIA], indirect=True)\n    def test_julia_within_file_references(self, language_server: SolidLanguageServer):\n        \"\"\"\n        Test finding references to a function within the same file.\n        \"\"\"\n        # Find references to 'calculate_sum' - the function name starts at line 2, column 9\n        # LSP uses 0-based indexing\n        references = language_server.request_references(\"main.jl\", line=2, column=9)\n\n        # Should find at least the definition and the call site\n        assert len(references) >= 1, f\"Expected at least 1 reference, got {len(references)}\"\n\n        # Verify at least one reference is in main.jl\n        reference_paths = [ref[\"relativePath\"] for ref in references]\n        assert \"main.jl\" in reference_paths\n\n    @pytest.mark.parametrize(\"language_server\", [Language.JULIA], indirect=True)\n    def test_julia_cross_file_references(self, language_server: SolidLanguageServer):\n        \"\"\"\n        Test finding references to a function defined in another file.\n        \"\"\"\n        # The 'say_hello' function name starts at line 1, column 13 in lib/helper.jl\n        # LSP uses 0-based indexing\n        references = language_server.request_references(\"lib/helper.jl\", line=1, column=13)\n\n        # Should find at least the call site in main.jl\n        assert len(references) >= 1, f\"Expected at least 1 reference, got {len(references)}\"\n\n        # Verify at least one reference points to the usage\n        reference_paths = [ref[\"relativePath\"] for ref in references]\n        # The reference might be in either file (definition or usage)\n        assert \"main.jl\" in reference_paths or \"lib/helper.jl\" in reference_paths\n"
  },
  {
    "path": "test/solidlsp/kotlin/test_kotlin_basic.py",
    "content": "import os\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_utils import SymbolUtils\nfrom test.conftest import is_ci\n\n\n# Kotlin LSP (IntelliJ-based, pre-alpha v261) crashes on JVM restart under CI resource constraints\n# (2 CPUs, 7GB RAM). First start succeeds but subsequent starts fail with cancelled (-32800).\n# Tests pass reliably on developer machines. See PR #1061 for investigation details.\n@pytest.mark.skipif(is_ci, reason=\"Kotlin LSP JVM restart is unstable on CI runners\")\n@pytest.mark.kotlin\nclass TestKotlinLanguageServer:\n    @pytest.mark.parametrize(\"language_server\", [Language.KOTLIN], indirect=True)\n    def test_find_symbol(self, language_server: SolidLanguageServer) -> None:\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Main\"), \"Main class not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Utils\"), \"Utils class not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Model\"), \"Model class not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.KOTLIN], indirect=True)\n    def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:\n        # Use correct Kotlin file paths\n        file_path = os.path.join(\"src\", \"main\", \"kotlin\", \"test_repo\", \"Utils.kt\")\n        refs = language_server.request_references(file_path, 3, 12)\n        assert any(\"Main.kt\" in ref.get(\"relativePath\", \"\") for ref in refs), \"Main should reference Utils.printHello\"\n\n        # Dynamically determine the correct line/column for the 'Model' class name\n        file_path = os.path.join(\"src\", \"main\", \"kotlin\", \"test_repo\", \"Model.kt\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        model_symbol = None\n        for sym in symbols[0]:\n            print(sym)\n            print(\"\\n\")\n            if sym.get(\"name\") == \"Model\" and sym.get(\"kind\") == 23:  # 23 = Class\n                model_symbol = sym\n                break\n        assert model_symbol is not None, \"Could not find 'Model' class symbol in Model.kt\"\n        # Use selectionRange if present, otherwise fall back to range\n        if \"selectionRange\" in model_symbol:\n            sel_start = model_symbol[\"selectionRange\"][\"start\"]\n        else:\n            sel_start = model_symbol[\"range\"][\"start\"]\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        assert any(\n            \"Main.kt\" in ref.get(\"relativePath\", \"\") for ref in refs\n        ), \"Main should reference Model (tried all positions in selectionRange)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.KOTLIN], indirect=True)\n    def test_overview_methods(self, language_server: SolidLanguageServer) -> None:\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Main\"), \"Main missing from overview\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Utils\"), \"Utils missing from overview\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Model\"), \"Model missing from overview\"\n"
  },
  {
    "path": "test/solidlsp/lean4/test_lean4_basic.py",
    "content": "\"\"\"\nTests for Lean 4 Language Server integration with Serena.\n\nTests prove that Serena's symbol tools can:\n1. Start the Lean 4 language server\n2. Discover all expected symbols with precise matching\n3. Track within-file references\n4. Track cross-file references\n\nTest Repository Structure:\n- Helper.lean: Calculator structure, arithmetic functions (add, subtract), predicates (isPositive, absolute)\n- Main.lean: Main entry point using Helper, plus multiply and calculate functions\n\"\"\"\n\nimport pytest\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\n\n@pytest.mark.lean4\nclass TestLean4LanguageServer:\n    @pytest.mark.parametrize(\"language_server\", [Language.LEAN4], indirect=True)\n    def test_ls_is_running(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that the Lean 4 language server starts successfully.\"\"\"\n        assert language_server.is_running()\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LEAN4], indirect=True)\n    def test_helper_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"\n        Test symbol discovery in Helper.lean.\n\n        Verifies that Serena can identify:\n        - Structure definition (Calculator)\n        - All functions (add, subtract, isPositive, absolute)\n        \"\"\"\n        all_symbols, _ = language_server.request_document_symbols(\"Helper.lean\").get_all_symbols_and_roots()\n        symbol_names = {s[\"name\"] for s in all_symbols}\n\n        expected_symbols = {\n            \"Calculator\",\n            \"add\",\n            \"subtract\",\n            \"isPositive\",\n            \"absolute\",\n        }\n\n        missing = expected_symbols - symbol_names\n        assert not missing, f\"Missing expected symbols in Helper.lean: {missing}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LEAN4], indirect=True)\n    def test_main_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"\n        Test symbol discovery in Main.lean.\n\n        Verifies that Serena can identify locally defined functions.\n        \"\"\"\n        all_symbols, _ = language_server.request_document_symbols(\"Main.lean\").get_all_symbols_and_roots()\n        symbol_names = {s[\"name\"] for s in all_symbols}\n\n        expected_symbols = {\n            \"multiply\",\n            \"calculate\",\n            \"main\",\n        }\n\n        missing = expected_symbols - symbol_names\n        assert not missing, f\"Missing expected symbols in Main.lean: {missing}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LEAN4], indirect=True)\n    def test_within_file_references(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"\n        Test within-file reference tracking for isPositive.\n\n        isPositive is defined in Helper.lean line 11 (0-indexed) and used by absolute on line 15.\n        \"\"\"\n        # isPositive defined at line 11, column 4\n        references = language_server.request_references(\"Helper.lean\", line=11, column=4)\n\n        assert len(references) >= 1, f\"Expected at least 1 reference to isPositive (used in absolute), got {len(references)}\"\n\n        # Check that isPositive is referenced within Helper.lean at line 15 (absolute calls isPositive)\n        ref_locations = [(ref[\"relativePath\"], ref[\"range\"][\"start\"][\"line\"]) for ref in references]\n        helper_refs = [(path, line) for path, line in ref_locations if \"Helper.lean\" in path]\n        assert any(\n            line == 15 for _, line in helper_refs\n        ), f\"Expected isPositive reference at Helper.lean:15 (in absolute), got: {ref_locations}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LEAN4], indirect=True)\n    def test_cross_file_references_add(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"\n        Test cross-file reference tracking for add function.\n\n        add is defined in Helper.lean line 5 (0-indexed) and used in Main.lean on lines 7 and 15.\n        \"\"\"\n        # add defined at line 5, column 4\n        references = language_server.request_references(\"Helper.lean\", line=5, column=4)\n\n        assert len(references) >= 1, f\"Expected at least 1 reference to add in Main.lean, got {len(references)}\"\n\n        # Check for references in Main.lean with specific lines\n        ref_locations = [(ref[\"relativePath\"], ref[\"range\"][\"start\"][\"line\"]) for ref in references]\n        main_refs = [(path, line) for path, line in ref_locations if \"Main.lean\" in path]\n        assert len(main_refs) >= 1, f\"Expected at least 1 reference to add in Main.lean, got: {ref_locations}\"\n        main_ref_lines = {line for _, line in main_refs}\n        # add is used in Main.lean line 7 (in calculate) and line 15 (in main)\n        assert (\n            7 in main_ref_lines or 15 in main_ref_lines\n        ), f\"Expected add references at Main.lean lines 7 or 15, got lines: {main_ref_lines}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LEAN4], indirect=True)\n    def test_cross_file_references_calculator(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"\n        Test cross-file reference tracking for Calculator structure.\n\n        Calculator is defined in Helper.lean line 0 (0-indexed) and used in Main.lean lines 5 and 13.\n        \"\"\"\n        # Calculator defined at line 0, column 10\n        references = language_server.request_references(\"Helper.lean\", line=0, column=10)\n\n        assert len(references) >= 1, f\"Expected at least 1 reference to Calculator in Main.lean, got {len(references)}\"\n\n        ref_locations = [(ref[\"relativePath\"], ref[\"range\"][\"start\"][\"line\"]) for ref in references]\n        main_refs = [(path, line) for path, line in ref_locations if \"Main.lean\" in path]\n        assert len(main_refs) >= 1, f\"Expected at least 1 reference to Calculator in Main.lean, got: {ref_locations}\"\n        main_ref_lines = {line for _, line in main_refs}\n        # Calculator is used in Main.lean line 5 (calculate signature) and line 13 (let c : Calculator)\n        assert (\n            5 in main_ref_lines or 13 in main_ref_lines\n        ), f\"Expected Calculator references at Main.lean lines 5 or 13, got lines: {main_ref_lines}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LEAN4], indirect=True)\n    def test_go_to_definition_within_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"\n        Test go-to-definition within a file.\n\n        In Main.lean line 19, calculate is called: 'match calculate c \"multiply\" 6 7 with'.\n        calculate is defined at Main.lean line 5.\n        \"\"\"\n        # calculate usage in Main.lean line 19, 'calculate' starts at col 8\n        definitions = language_server.request_definition(\"Main.lean\", line=19, column=8)\n\n        assert len(definitions) >= 1, f\"Expected at least 1 definition for calculate, got {len(definitions)}\"\n\n        def_location = definitions[0]\n        assert def_location[\"uri\"].endswith(\"Main.lean\"), f\"Expected definition in Main.lean, got: {def_location['uri']}\"\n        assert def_location[\"range\"][\"start\"][\"line\"] == 5, f\"Expected definition at line 5, got: {def_location['range']['start']['line']}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LEAN4], indirect=True)\n    def test_go_to_definition_across_files(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"\n        Test go-to-definition across files.\n\n        In Main.lean line 15, add is called: 'add 5 3'.\n        add is defined in Helper.lean line 5.\n        \"\"\"\n        # add usage in Main.lean line 15, 'add' starts at col 19\n        definitions = language_server.request_definition(\"Main.lean\", line=15, column=19)\n\n        assert len(definitions) >= 1, f\"Expected at least 1 definition for add, got {len(definitions)}\"\n\n        def_location = definitions[0]\n        assert def_location[\"uri\"].endswith(\"Helper.lean\"), f\"Expected definition in Helper.lean, got: {def_location['uri']}\"\n        assert def_location[\"range\"][\"start\"][\"line\"] == 5, f\"Expected definition at line 5, got: {def_location['range']['start']['line']}\"\n"
  },
  {
    "path": "test/solidlsp/lua/test_lua_basic.py",
    "content": "\"\"\"\nTests for the Lua language server implementation.\n\nThese tests validate symbol finding and cross-file reference capabilities\nfor Lua modules and functions.\n\"\"\"\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_types import SymbolKind\n\n\n@pytest.mark.lua\nclass TestLuaLanguageServer:\n    \"\"\"Test Lua language server symbol finding and cross-file references.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LUA], indirect=True)\n    def test_find_symbols_in_calculator(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding specific functions in calculator.lua.\"\"\"\n        symbols = language_server.request_document_symbols(\"src/calculator.lua\").get_all_symbols_and_roots()\n\n        assert symbols is not None\n        assert len(symbols) > 0\n\n        # Extract function names from the returned structure\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n        function_names = set()\n        for symbol in symbol_list:\n            if isinstance(symbol, dict):\n                name = symbol.get(\"name\", \"\")\n                # Handle both plain names and module-prefixed names\n                if \".\" in name:\n                    name = name.split(\".\")[-1]\n                if symbol.get(\"kind\") == SymbolKind.Function:\n                    function_names.add(name)\n\n        # Verify exact calculator functions exist\n        expected_functions = {\"add\", \"subtract\", \"multiply\", \"divide\", \"factorial\"}\n        found_functions = function_names & expected_functions\n        assert found_functions == expected_functions, f\"Expected exactly {expected_functions}, found {found_functions}\"\n\n        # Verify specific functions\n        assert \"add\" in function_names, \"add function not found\"\n        assert \"multiply\" in function_names, \"multiply function not found\"\n        assert \"factorial\" in function_names, \"factorial function not found\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LUA], indirect=True)\n    def test_find_symbols_in_utils(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding specific functions in utils.lua.\"\"\"\n        symbols = language_server.request_document_symbols(\"src/utils.lua\").get_all_symbols_and_roots()\n\n        assert symbols is not None\n        assert len(symbols) > 0\n\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n        function_names = set()\n        all_symbols = set()\n\n        for symbol in symbol_list:\n            if isinstance(symbol, dict):\n                name = symbol.get(\"name\", \"\")\n                all_symbols.add(name)\n                # Handle both plain names and module-prefixed names\n                if \".\" in name:\n                    name = name.split(\".\")[-1]\n                if symbol.get(\"kind\") == SymbolKind.Function:\n                    function_names.add(name)\n\n        # Verify exact string utility functions\n        expected_utils = {\"trim\", \"split\", \"starts_with\", \"ends_with\"}\n        found_utils = function_names & expected_utils\n        assert found_utils == expected_utils, f\"Expected exactly {expected_utils}, found {found_utils}\"\n\n        # Verify exact table utility functions\n        table_utils = {\"deep_copy\", \"table_contains\", \"table_merge\"}\n        found_table_utils = function_names & table_utils\n        assert found_table_utils == table_utils, f\"Expected exactly {table_utils}, found {found_table_utils}\"\n\n        # Check for Logger class/table\n        assert \"Logger\" in all_symbols or any(\"Logger\" in s for s in all_symbols), \"Logger not found in symbols\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LUA], indirect=True)\n    def test_find_symbols_in_main(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding functions in main.lua.\"\"\"\n        symbols = language_server.request_document_symbols(\"main.lua\").get_all_symbols_and_roots()\n\n        assert symbols is not None\n        assert len(symbols) > 0\n\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n        function_names = set()\n\n        for symbol in symbol_list:\n            if isinstance(symbol, dict) and symbol.get(\"kind\") == SymbolKind.Function:\n                function_names.add(symbol.get(\"name\", \"\"))\n\n        # Verify exact main functions exist\n        expected_funcs = {\"print_banner\", \"test_calculator\", \"test_utils\"}\n        found_funcs = function_names & expected_funcs\n        assert found_funcs == expected_funcs, f\"Expected exactly {expected_funcs}, found {found_funcs}\"\n\n        assert \"test_calculator\" in function_names, \"test_calculator function not found\"\n        assert \"test_utils\" in function_names, \"test_utils function not found\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LUA], indirect=True)\n    def test_cross_file_references_calculator_add(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding cross-file references to calculator.add function.\"\"\"\n        symbols = language_server.request_document_symbols(\"src/calculator.lua\").get_all_symbols_and_roots()\n\n        assert symbols is not None\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n\n        # Find the add function\n        add_symbol = None\n        for sym in symbol_list:\n            if isinstance(sym, dict):\n                name = sym.get(\"name\", \"\")\n                if \"add\" in name or name == \"add\":\n                    add_symbol = sym\n                    break\n\n        assert add_symbol is not None, \"add function not found in calculator.lua\"\n\n        # Get references to the add function\n        range_info = add_symbol.get(\"selectionRange\", add_symbol.get(\"range\"))\n        assert range_info is not None, \"add function has no range information\"\n\n        range_start = range_info[\"start\"]\n        refs = language_server.request_references(\"src/calculator.lua\", range_start[\"line\"], range_start[\"character\"])\n\n        assert refs is not None\n        assert isinstance(refs, list)\n        # add function appears in: main.lua (lines 16, 71), test_calculator.lua (lines 22, 23, 24)\n        # Note: The declaration itself may or may not be included as a reference\n        assert len(refs) >= 5, f\"Should find at least 5 references to calculator.add, found {len(refs)}\"\n\n        # Verify exact reference locations\n        ref_files: dict[str, list[int]] = {}\n        for ref in refs:\n            filename = ref.get(\"uri\", \"\").split(\"/\")[-1]\n            if filename not in ref_files:\n                ref_files[filename] = []\n            ref_files[filename].append(ref[\"range\"][\"start\"][\"line\"])\n\n        # The declaration may or may not be included\n        if \"calculator.lua\" in ref_files:\n            assert (\n                5 in ref_files[\"calculator.lua\"]\n            ), f\"If declaration is included, it should be at line 6 (0-indexed: 5), found at {ref_files['calculator.lua']}\"\n\n        # Check main.lua has usages\n        assert \"main.lua\" in ref_files, \"Should find add usages in main.lua\"\n        assert (\n            15 in ref_files[\"main.lua\"] or 70 in ref_files[\"main.lua\"]\n        ), f\"Should find add usage in main.lua, found at lines {ref_files.get('main.lua', [])}\"\n\n        # Check for cross-file references from main.lua\n        main_refs = [ref for ref in refs if \"main.lua\" in ref.get(\"uri\", \"\")]\n        assert len(main_refs) > 0, \"calculator.add should be called in main.lua\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LUA], indirect=True)\n    def test_cross_file_references_utils_trim(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding cross-file references to utils.trim function.\"\"\"\n        symbols = language_server.request_document_symbols(\"src/utils.lua\").get_all_symbols_and_roots()\n\n        assert symbols is not None\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n\n        # Find the trim function\n        trim_symbol = None\n        for sym in symbol_list:\n            if isinstance(sym, dict):\n                name = sym.get(\"name\", \"\")\n                if \"trim\" in name or name == \"trim\":\n                    trim_symbol = sym\n                    break\n\n        assert trim_symbol is not None, \"trim function not found in utils.lua\"\n\n        # Get references to the trim function\n        range_info = trim_symbol.get(\"selectionRange\", trim_symbol.get(\"range\"))\n        assert range_info is not None, \"trim function has no range information\"\n\n        range_start = range_info[\"start\"]\n        refs = language_server.request_references(\"src/utils.lua\", range_start[\"line\"], range_start[\"character\"])\n\n        assert refs is not None\n        assert isinstance(refs, list)\n        # trim function appears in: usage (line 32 in main.lua)\n        # Note: The declaration itself may or may not be included as a reference\n        assert len(refs) >= 1, f\"Should find at least 1 reference to utils.trim, found {len(refs)}\"\n\n        # Verify exact reference locations\n        ref_files: dict[str, list[int]] = {}\n        for ref in refs:\n            filename = ref.get(\"uri\", \"\").split(\"/\")[-1]\n            if filename not in ref_files:\n                ref_files[filename] = []\n            ref_files[filename].append(ref[\"range\"][\"start\"][\"line\"])\n\n        # The declaration may or may not be included\n        if \"utils.lua\" in ref_files:\n            assert (\n                5 in ref_files[\"utils.lua\"]\n            ), f\"If declaration is included, it should be at line 6 (0-indexed: 5), found at {ref_files['utils.lua']}\"\n\n        # Check main.lua has usage\n        assert \"main.lua\" in ref_files, \"Should find trim usage in main.lua\"\n        assert (\n            31 in ref_files[\"main.lua\"]\n        ), f\"Should find trim usage at line 32 (0-indexed: 31) in main.lua, found at lines {ref_files.get('main.lua', [])}\"\n\n        # Check for cross-file references from main.lua\n        main_refs = [ref for ref in refs if \"main.lua\" in ref.get(\"uri\", \"\")]\n        assert len(main_refs) > 0, \"utils.trim should be called in main.lua\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LUA], indirect=True)\n    def test_hover_information(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test hover information for symbols.\"\"\"\n        # Get hover info for a function\n        hover_info = language_server.request_hover(\"src/calculator.lua\", 5, 10)  # Position near add function\n\n        assert hover_info is not None, \"Should provide hover information\"\n\n        # Hover info could be a dict with 'contents' or a string\n        if isinstance(hover_info, dict):\n            assert \"contents\" in hover_info or \"value\" in hover_info, \"Hover should have contents\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LUA], indirect=True)\n    def test_full_symbol_tree(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that full symbol tree is not empty.\"\"\"\n        symbols = language_server.request_full_symbol_tree()\n\n        assert symbols is not None\n        assert len(symbols) > 0, \"Symbol tree should not be empty\"\n\n        # The tree should have at least one root node\n        root = symbols[0]\n        assert isinstance(root, dict), \"Root should be a dict\"\n        assert \"name\" in root, \"Root should have a name\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LUA], indirect=True)\n    def test_references_between_test_and_source(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding references from test files to source files.\"\"\"\n        # Check if test_calculator.lua references calculator module\n        test_symbols = language_server.request_document_symbols(\"tests/test_calculator.lua\").get_all_symbols_and_roots()\n\n        assert test_symbols is not None\n        assert len(test_symbols) > 0\n\n        # The test file should have some content that references calculator\n        symbol_list = test_symbols[0] if isinstance(test_symbols, tuple) else test_symbols\n        assert len(symbol_list) > 0, \"test_calculator.lua should have symbols\"\n"
  },
  {
    "path": "test/solidlsp/luau/__init__.py",
    "content": ""
  },
  {
    "path": "test/solidlsp/luau/test_luau_basic.py",
    "content": "\"\"\"\nTests for the Luau language server implementation.\n\nThese tests validate symbol finding, within-file references,\nand cross-file reference capabilities for Luau modules and functions.\n\"\"\"\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\n\n@pytest.mark.luau\nclass TestLuauLanguageServer:\n    \"\"\"Test Luau language server symbol finding and cross-file references.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LUAU], indirect=True)\n    def test_find_symbols_in_init(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding specific functions in init.luau.\"\"\"\n        symbols = language_server.request_document_symbols(\"src/init.luau\").get_all_symbols_and_roots()\n\n        assert symbols is not None\n        assert len(symbols) > 0\n\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n        symbol_names = set()\n        for symbol in symbol_list:\n            if isinstance(symbol, dict):\n                name = symbol.get(\"name\", \"\")\n                symbol_names.add(name)\n\n        assert \"createConfig\" in symbol_names, f\"createConfig not found in symbols: {symbol_names}\"\n        assert \"main\" in symbol_names, f\"main not found in symbols: {symbol_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LUAU], indirect=True)\n    def test_find_symbols_in_module(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding specific functions in module.luau.\"\"\"\n        symbols = language_server.request_document_symbols(\"src/module.luau\").get_all_symbols_and_roots()\n\n        assert symbols is not None\n        assert len(symbols) > 0\n\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n        symbol_names = set()\n        for symbol in symbol_list:\n            if isinstance(symbol, dict):\n                name = symbol.get(\"name\", \"\")\n                symbol_names.add(name)\n\n        assert \"process\" in symbol_names, f\"process not found in symbols: {symbol_names}\"\n        assert \"helper\" in symbol_names, f\"helper not found in symbols: {symbol_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LUAU], indirect=True)\n    def test_find_references_within_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding within-file references to createConfig in init.luau.\n\n        createConfig is defined at line 8 (0-indexed) and referenced at lines 17 and 23.\n        \"\"\"\n        symbols = language_server.request_document_symbols(\"src/init.luau\").get_all_symbols_and_roots()\n\n        assert symbols is not None\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n\n        # Find the createConfig function symbol\n        create_config_symbol = None\n        for sym in symbol_list:\n            if isinstance(sym, dict) and sym.get(\"name\") == \"createConfig\":\n                create_config_symbol = sym\n                break\n\n        assert create_config_symbol is not None, \"createConfig function not found in init.luau\"\n\n        range_info = create_config_symbol.get(\"selectionRange\", create_config_symbol.get(\"range\"))\n        assert range_info is not None, \"createConfig has no range information\"\n\n        range_start = range_info[\"start\"]\n        refs = language_server.request_references(\"src/init.luau\", range_start[\"line\"], range_start[\"character\"])\n\n        assert refs is not None\n        assert isinstance(refs, list)\n        # createConfig appears multiple times within init.luau:\n        # definition (line 8), usage in main (line 17), and return table (line 23)\n        assert len(refs) >= 2, f\"Should find at least 2 references to createConfig, found {len(refs)}\"\n\n        # Verify that references are in init.luau\n        ref_files = set()\n        for ref in refs:\n            filename = ref.get(\"uri\", \"\").split(\"/\")[-1]\n            ref_files.add(filename)\n\n        assert \"init.luau\" in ref_files, f\"Expected references in init.luau, found in: {ref_files}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LUAU], indirect=True)\n    def test_find_references_across_files(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding cross-file references to process function.\n\n        process is defined in module.luau and used in init.luau via module.process().\n        \"\"\"\n        symbols = language_server.request_document_symbols(\"src/module.luau\").get_all_symbols_and_roots()\n\n        assert symbols is not None\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n\n        # Find the process function symbol\n        process_symbol = None\n        for sym in symbol_list:\n            if isinstance(sym, dict) and sym.get(\"name\") == \"process\":\n                process_symbol = sym\n                break\n\n        assert process_symbol is not None, \"process function not found in module.luau\"\n\n        range_info = process_symbol.get(\"selectionRange\", process_symbol.get(\"range\"))\n        assert range_info is not None, \"process function has no range information\"\n\n        range_start = range_info[\"start\"]\n        refs = language_server.request_references(\"src/module.luau\", range_start[\"line\"], range_start[\"character\"])\n\n        assert refs is not None\n        assert isinstance(refs, list)\n        assert len(refs) >= 1, f\"Should find at least 1 reference to process, found {len(refs)}\"\n\n        # Collect reference files and lines\n        ref_info: dict[str, list[int]] = {}\n        for ref in refs:\n            filename = ref.get(\"uri\", \"\").split(\"/\")[-1]\n            if filename not in ref_info:\n                ref_info[filename] = []\n            ref_info[filename].append(ref[\"range\"][\"start\"][\"line\"])\n\n        # The definition in module.luau may or may not be included\n        # We expect at least the reference in module.luau return table (line 9)\n        assert \"module.luau\" in ref_info, f\"Expected references in module.luau, found in: {set(ref_info.keys())}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.LUAU], indirect=True)\n    def test_find_definition(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding definition of createConfig from its usage in main().\n\n        createConfig is used at line 17, column 20 (0-indexed) in init.luau.\n        Its definition should be at line 8 in init.luau.\n        \"\"\"\n        # Line 17 (0-indexed): `    local config = createConfig(\"test\", 42)`\n        # createConfig starts at column 20\n        definition_locations = language_server.request_definition(\"src/init.luau\", 17, 20)\n\n        assert definition_locations, f\"Expected non-empty definition list but got {definition_locations}\"\n        assert len(definition_locations) >= 1\n\n        definition = definition_locations[0]\n        assert definition[\"uri\"].endswith(\"init.luau\"), f\"Definition should be in init.luau, got: {definition['uri']}\"\n        # createConfig is defined at line 8 (0-indexed): `local function createConfig(...)`\n        assert definition[\"range\"][\"start\"][\"line\"] == 8, f\"Definition should be at line 8, got line {definition['range']['start']['line']}\"\n"
  },
  {
    "path": "test/solidlsp/luau/test_luau_dependency_provider.py",
    "content": "\"\"\"Tests for the Luau language server dependency provider.\"\"\"\n\nimport io\nimport zipfile\nfrom pathlib import Path\nfrom unittest.mock import patch\n\nimport pytest\n\nfrom solidlsp.language_servers.luau_lsp import LuauLanguageServer\nfrom solidlsp.settings import SolidLSPSettings\n\n\ndef _make_provider(\n    tmp_path: Path,\n    custom_settings: dict[str, str] | None = None,\n) -> LuauLanguageServer.DependencyProvider:\n    return LuauLanguageServer.DependencyProvider(\n        custom_settings=SolidLSPSettings.CustomLSSettings(custom_settings or {}),\n        ls_resources_dir=str(tmp_path),\n    )\n\n\nclass _FakeResponse:\n    def __init__(self, content: bytes) -> None:\n        self.content = content\n\n    def raise_for_status(self) -> None:\n        return\n\n    def iter_content(self, chunk_size: int = 8192):\n        yield self.content\n\n    def __enter__(self) -> \"_FakeResponse\":\n        return self\n\n    def __exit__(self, exc_type, exc, tb) -> None:\n        return None\n\n\n@pytest.mark.luau\nclass TestLuauDependencyProvider:\n    def test_create_launch_command_uses_ls_path_override_and_adds_assets(self, tmp_path: Path) -> None:\n        provider = _make_provider(tmp_path, {\"ls_path\": \"/custom/luau-lsp\"})\n\n        with patch.object(\n            provider,\n            \"_get_or_install_core_dependency\",\n            side_effect=AssertionError(\"_get_or_install_core_dependency should not be called when ls_path is set\"),\n        ):\n            with patch.object(\n                provider,\n                \"_resolve_support_files\",\n                return_value=(\"/tmp/globalTypes.d.luau\", \"/tmp/en-us.json\"),\n            ):\n                assert provider.create_launch_command() == [\n                    \"/custom/luau-lsp\",\n                    \"lsp\",\n                    \"--definitions:@roblox=/tmp/globalTypes.d.luau\",\n                    \"--docs=/tmp/en-us.json\",\n                ]\n\n    def test_resolve_support_files_defaults_to_roblox_mode(self, tmp_path: Path) -> None:\n        provider = _make_provider(tmp_path)\n\n        with patch.object(\n            provider,\n            \"_download_roblox_support_files\",\n            return_value=(\"/tmp/globalTypes.PluginSecurity.d.luau\", \"/tmp/en-us.json\"),\n        ) as download_roblox_support_files:\n            with patch.object(\n                provider,\n                \"_download_standard_docs\",\n                side_effect=AssertionError(\"_download_standard_docs should not be called in roblox mode\"),\n            ):\n                assert provider._resolve_support_files() == (\n                    \"/tmp/globalTypes.PluginSecurity.d.luau\",\n                    \"/tmp/en-us.json\",\n                )\n\n        download_roblox_support_files.assert_called_once_with(\"PluginSecurity\")\n\n    def test_resolve_support_files_uses_standard_mode_docs_only(self, tmp_path: Path) -> None:\n        provider = _make_provider(tmp_path, {\"platform\": \"standard\"})\n\n        with patch.object(provider, \"_download_standard_docs\", return_value=\"/tmp/luau-en-us.json\") as download_standard_docs:\n            with patch.object(\n                provider,\n                \"_download_roblox_support_files\",\n                side_effect=AssertionError(\"_download_roblox_support_files should not be called in standard mode\"),\n            ):\n                assert provider._resolve_support_files() == (\n                    None,\n                    \"/tmp/luau-en-us.json\",\n                )\n\n        download_standard_docs.assert_called_once_with()\n\n    def test_get_or_install_core_dependency_uses_system_binary(self, tmp_path: Path) -> None:\n        provider = _make_provider(tmp_path)\n\n        with patch(\"solidlsp.language_servers.luau_lsp.shutil.which\", return_value=\"/usr/bin/luau-lsp\"):\n            with patch.object(\n                provider,\n                \"_download_luau_lsp\",\n                side_effect=AssertionError(\"_download_luau_lsp should not be called when luau-lsp is on PATH\"),\n            ):\n                assert provider._get_or_install_core_dependency() == \"/usr/bin/luau-lsp\"\n\n    def test_download_luau_lsp_extracts_binary_into_ls_resources_dir(self, tmp_path: Path) -> None:\n        provider = _make_provider(tmp_path)\n\n        archive = io.BytesIO()\n        with zipfile.ZipFile(archive, \"w\") as zip_file:\n            zip_file.writestr(\"nested/luau-lsp\", \"#!/bin/sh\\n\")\n\n        with patch(\"solidlsp.language_servers.luau_lsp.platform.system\", return_value=\"Linux\"):\n            with patch(\"solidlsp.language_servers.luau_lsp.platform.machine\", return_value=\"aarch64\"):\n                with patch(\"solidlsp.language_servers.luau_lsp.requests.get\", return_value=_FakeResponse(archive.getvalue())):\n                    binary_path = provider._download_luau_lsp()\n\n        resolved_binary = Path(binary_path)\n        assert resolved_binary.exists()\n        assert resolved_binary.name == \"luau-lsp\"\n        assert str(resolved_binary).startswith(str(tmp_path))\n\n    def test_download_roblox_support_files_writes_into_ls_resources_dir(self, tmp_path: Path) -> None:\n        provider = _make_provider(tmp_path)\n\n        with patch(\n            \"solidlsp.language_servers.luau_lsp.requests.get\",\n            side_effect=[_FakeResponse(b\"types\"), _FakeResponse(b\"docs\")],\n        ):\n            definitions_path, docs_path = provider._download_roblox_support_files(\"LocalUserSecurity\")\n\n        assert definitions_path == str(tmp_path / \"globalTypes.LocalUserSecurity.d.luau\")\n        assert docs_path == str(tmp_path / \"en-us.json\")\n        assert (tmp_path / \"globalTypes.LocalUserSecurity.d.luau\").read_bytes() == b\"types\"\n        assert (tmp_path / \"en-us.json\").read_bytes() == b\"docs\"\n\n    def test_download_standard_docs_writes_into_ls_resources_dir(self, tmp_path: Path) -> None:\n        provider = _make_provider(tmp_path, {\"platform\": \"standard\"})\n\n        with patch(\"solidlsp.language_servers.luau_lsp.requests.get\", return_value=_FakeResponse(b\"docs\")):\n            docs_path = provider._download_standard_docs()\n\n        assert docs_path == str(tmp_path / \"luau-en-us.json\")\n        assert (tmp_path / \"luau-en-us.json\").read_bytes() == b\"docs\"\n\n    def test_workspace_configuration_uses_configured_platform(self) -> None:\n        config = LuauLanguageServer._get_workspace_configuration(SolidLSPSettings.CustomLSSettings({\"platform\": \"standard\"}))\n        assert config == {\"platform\": {\"type\": \"standard\"}}\n\n    def test_invalid_platform_raises(self, tmp_path: Path) -> None:\n        provider = _make_provider(tmp_path, {\"platform\": \"invalid\"})\n\n        with pytest.raises(ValueError, match=\"Unsupported Luau platform\"):\n            provider._resolve_support_files()\n\n    def test_invalid_roblox_security_level_raises(self, tmp_path: Path) -> None:\n        provider = _make_provider(tmp_path, {\"roblox_security_level\": \"invalid\"})\n\n        with pytest.raises(ValueError, match=\"Unsupported Luau Roblox security level\"):\n            provider._resolve_support_files()\n"
  },
  {
    "path": "test/solidlsp/markdown/__init__.py",
    "content": "\"\"\"Tests for markdown language server functionality.\"\"\"\n"
  },
  {
    "path": "test/solidlsp/markdown/test_markdown_basic.py",
    "content": "\"\"\"\nBasic integration tests for the markdown language server functionality.\n\nThese tests validate the functionality of the language server APIs\nlike request_document_symbols using the markdown test repository.\n\"\"\"\n\nimport pytest\n\nfrom serena.symbol import LanguageServerSymbol\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_types import SymbolKind\n\n\n@pytest.mark.markdown\nclass TestMarkdownLanguageServerBasics:\n    \"\"\"Test basic functionality of the markdown language server.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.MARKDOWN], indirect=True)\n    def test_markdown_language_server_initialization(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that markdown language server can be initialized successfully.\"\"\"\n        assert language_server is not None\n        assert language_server.language == Language.MARKDOWN\n\n    @pytest.mark.parametrize(\"language_server\", [Language.MARKDOWN], indirect=True)\n    def test_markdown_request_document_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_document_symbols for markdown files.\"\"\"\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"README.md\").get_all_symbols_and_roots()\n\n        heading_names = [symbol[\"name\"] for symbol in all_symbols]\n\n        # Should detect headings from README.md\n        assert \"Test Repository\" in heading_names or len(all_symbols) > 0, \"Should find at least one heading\"\n\n        # Verify that markdown headings are remapped from String to Namespace\n        for symbol in all_symbols:\n            assert (\n                symbol[\"kind\"] == SymbolKind.Namespace\n            ), f\"Heading '{symbol['name']}' should have kind Namespace, got {SymbolKind(symbol['kind']).name}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.MARKDOWN], indirect=True)\n    def test_markdown_request_symbols_from_guide(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test symbol detection in guide.md file.\"\"\"\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"guide.md\").get_all_symbols_and_roots()\n\n        # At least some headings should be found\n        assert len(all_symbols) > 0, f\"Should find headings in guide.md, found {len(all_symbols)}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.MARKDOWN], indirect=True)\n    def test_markdown_request_symbols_from_api(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test symbol detection in api.md file.\"\"\"\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"api.md\").get_all_symbols_and_roots()\n\n        # Should detect headings from api.md\n        assert len(all_symbols) > 0, f\"Should find headings in api.md, found {len(all_symbols)}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.MARKDOWN], indirect=True)\n    def test_markdown_request_document_symbols_with_body(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_document_symbols with body extraction.\"\"\"\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"README.md\").get_all_symbols_and_roots()\n\n        # Should have found some symbols\n        assert len(all_symbols) > 0, \"Should find symbols in README.md\"\n\n        # Note: Not all markdown LSPs provide body information for symbols\n        # This test is more lenient and just verifies the API works\n        assert all_symbols is not None, \"Should return symbols even if body extraction is limited\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.MARKDOWN], indirect=True)\n    def test_markdown_headings_not_low_level(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that markdown headings are not classified as low-level symbols.\n\n        Verifies the fix for the issue where Marksman's SymbolKind.String (15)\n        caused all headings to be filtered out of get_symbols_overview.\n        \"\"\"\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"README.md\").get_all_symbols_and_roots()\n        assert len(all_symbols) > 0, \"Should find headings in README.md\"\n\n        for symbol in all_symbols:\n            ls_symbol = LanguageServerSymbol(symbol)\n            assert (\n                not ls_symbol.is_low_level()\n            ), f\"Heading '{symbol['name']}' should not be low-level (kind={SymbolKind(symbol['kind']).name})\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.MARKDOWN], indirect=True)\n    def test_markdown_nested_headings_remapped(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that nested headings (h1-h5) are all remapped from String to Namespace.\"\"\"\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"api.md\").get_all_symbols_and_roots()\n\n        # api.md has deeply nested headings (h1 through h5)\n        assert len(all_symbols) > 5, \"api.md should have many headings\"\n\n        for symbol in all_symbols:\n            assert symbol[\"kind\"] == SymbolKind.Namespace, f\"Nested heading '{symbol['name']}' should be remapped to Namespace\"\n"
  },
  {
    "path": "test/solidlsp/matlab/__init__.py",
    "content": "# MATLAB language server tests\n"
  },
  {
    "path": "test/solidlsp/matlab/test_matlab_basic.py",
    "content": "\"\"\"\nBasic integration tests for the MATLAB language server functionality.\n\nThese tests validate the functionality of the language server APIs\nlike request_document_symbols using the MATLAB test repository.\n\nRequirements:\n    - MATLAB R2021b or later must be installed\n    - MATLAB_PATH environment variable should be set to MATLAB installation directory\n    - Node.js and npm must be installed\n\"\"\"\n\nimport os\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\n# Skip all tests if MATLAB is not available\npytestmark = pytest.mark.matlab\n\n# Check if MATLAB is available\nMATLAB_AVAILABLE = os.environ.get(\"MATLAB_PATH\") is not None or any(\n    os.path.exists(p)\n    for p in [\n        \"/Applications/MATLAB_R2024b.app\",\n        \"/Applications/MATLAB_R2025b.app\",\n        \"/Volumes/S1/Applications/MATLAB_R2024b.app\",\n        \"/Volumes/S1/Applications/MATLAB_R2025b.app\",\n    ]\n)\n\n\n@pytest.mark.skipif(not MATLAB_AVAILABLE, reason=\"MATLAB installation not found\")\nclass TestMatlabLanguageServerBasics:\n    \"\"\"Test basic functionality of the MATLAB language server.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.MATLAB], indirect=True)\n    def test_matlab_language_server_initialization(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that MATLAB language server can be initialized successfully.\"\"\"\n        assert language_server is not None\n        assert language_server.language == Language.MATLAB\n\n    @pytest.mark.parametrize(\"language_server\", [Language.MATLAB], indirect=True)\n    def test_matlab_request_document_symbols_class(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_document_symbols for MATLAB class file.\"\"\"\n        # Test getting symbols from Calculator.m (class file)\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"Calculator.m\").get_all_symbols_and_roots()\n\n        # Extract class symbols (LSP Symbol Kind 5 for class)\n        class_symbols = [symbol for symbol in all_symbols if symbol.get(\"kind\") == 5]\n        class_names = [symbol[\"name\"] for symbol in class_symbols]\n\n        # Should find the Calculator class\n        assert \"Calculator\" in class_names, \"Should find Calculator class\"\n\n        # Extract method symbols (LSP Symbol Kind 6 for method or 12 for function)\n        method_symbols = [symbol for symbol in all_symbols if symbol.get(\"kind\") in [6, 12]]\n        method_names = [symbol[\"name\"] for symbol in method_symbols]\n\n        # Should find key methods\n        expected_methods = [\"add\", \"subtract\", \"multiply\", \"divide\"]\n        for method in expected_methods:\n            assert method in method_names, f\"Should find {method} method in Calculator class\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.MATLAB], indirect=True)\n    def test_matlab_request_document_symbols_function(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_document_symbols for MATLAB function file.\"\"\"\n        # Test getting symbols from lib/mathUtils.m (function file)\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"lib/mathUtils.m\").get_all_symbols_and_roots()\n\n        # Extract function symbols (LSP Symbol Kind 12 for function)\n        function_symbols = [symbol for symbol in all_symbols if symbol.get(\"kind\") == 12]\n        function_names = [symbol[\"name\"] for symbol in function_symbols]\n\n        # Should find the main mathUtils function\n        assert \"mathUtils\" in function_names, \"Should find mathUtils function\"\n\n        # Should also find nested/local functions\n        expected_local_functions = [\"computeFactorial\", \"computeFibonacci\", \"checkPrime\", \"computeStats\"]\n        for func in expected_local_functions:\n            assert func in function_names, f\"Should find {func} local function\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.MATLAB], indirect=True)\n    def test_matlab_request_document_symbols_script(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_document_symbols for MATLAB script file.\"\"\"\n        # Test getting symbols from main.m (script file)\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"main.m\").get_all_symbols_and_roots()\n\n        # Scripts may have variables and sections, but less structured symbols\n        # Just verify we can get symbols without errors\n        assert all_symbols is not None\n\n\n@pytest.mark.skipif(not MATLAB_AVAILABLE, reason=\"MATLAB installation not found\")\nclass TestMatlabLanguageServerReferences:\n    \"\"\"Test find references functionality of the MATLAB language server.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.MATLAB], indirect=True)\n    def test_matlab_find_references_within_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding references within a single MATLAB file.\"\"\"\n        # Find references to 'result' variable in Calculator.m\n        # This is a basic test to verify references work\n        references = language_server.request_references(\"Calculator.m\", 25, 12)  # 'result' in add method\n\n        # Should find at least the definition\n        assert references is not None\n\n    @pytest.mark.parametrize(\"language_server\", [Language.MATLAB], indirect=True)\n    def test_matlab_find_references_cross_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding references across MATLAB files.\"\"\"\n        # Find references to Calculator class used in main.m\n        references = language_server.request_references(\"main.m\", 11, 8)  # 'Calculator' reference\n\n        # Should find references in both main.m and Calculator.m\n        assert references is not None\n"
  },
  {
    "path": "test/solidlsp/nix/test_nix_basic.py",
    "content": "\"\"\"\nTests for the Nix language server implementation using nixd.\n\nThese tests validate symbol finding and cross-file reference capabilities for Nix expressions.\n\"\"\"\n\nimport platform\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom test.conftest import is_ci\n\n# Skip all Nix tests on Windows as Nix doesn't support Windows\npytestmark = pytest.mark.skipif(platform.system() == \"Windows\", reason=\"Nix and nil are not available on Windows\")\n\n\n@pytest.mark.nix\nclass TestNixLanguageServer:\n    \"\"\"Test Nix language server symbol finding capabilities.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.NIX], indirect=True)\n    def test_find_symbols_in_default_nix(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding specific symbols in default.nix.\"\"\"\n        symbols = language_server.request_document_symbols(\"default.nix\").get_all_symbols_and_roots()\n\n        assert symbols is not None\n        assert len(symbols) > 0\n\n        # Extract symbol names from the returned structure\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n        symbol_names = {sym.get(\"name\") for sym in symbol_list if isinstance(sym, dict)}\n\n        # Verify specific function exists\n        assert \"makeGreeting\" in symbol_names, \"makeGreeting function not found\"\n\n        # Verify exact attribute sets are found\n        expected_attrs = {\"listUtils\", \"stringUtils\"}\n        found_attrs = symbol_names & expected_attrs\n        assert found_attrs == expected_attrs, f\"Expected exactly {expected_attrs}, found {found_attrs}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.NIX], indirect=True)\n    def test_find_symbols_in_utils(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding symbols in lib/utils.nix.\"\"\"\n        symbols = language_server.request_document_symbols(\"lib/utils.nix\").get_all_symbols_and_roots()\n\n        assert symbols is not None\n        assert len(symbols) > 0\n\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n        symbol_names = {sym.get(\"name\") for sym in symbol_list if isinstance(sym, dict)}\n\n        # Verify exact utility modules are found\n        expected_modules = {\"math\", \"strings\", \"lists\", \"attrs\"}\n        found_modules = symbol_names & expected_modules\n        assert found_modules == expected_modules, f\"Expected exactly {expected_modules}, found {found_modules}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.NIX], indirect=True)\n    def test_find_symbols_in_flake(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding symbols in flake.nix.\"\"\"\n        symbols = language_server.request_document_symbols(\"flake.nix\").get_all_symbols_and_roots()\n\n        assert symbols is not None\n        assert len(symbols) > 0\n\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n        symbol_names = {sym.get(\"name\") for sym in symbol_list if isinstance(sym, dict)}\n\n        # Flakes must have either inputs or outputs\n        assert \"inputs\" in symbol_names or \"outputs\" in symbol_names, \"Flake must have inputs or outputs\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.NIX], indirect=True)\n    def test_find_symbols_in_module(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding symbols in a NixOS module.\"\"\"\n        symbols = language_server.request_document_symbols(\"modules/example.nix\").get_all_symbols_and_roots()\n\n        assert symbols is not None\n        assert len(symbols) > 0\n\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n        symbol_names = {sym.get(\"name\") for sym in symbol_list if isinstance(sym, dict)}\n\n        # NixOS modules must have either options or config\n        assert \"options\" in symbol_names or \"config\" in symbol_names, \"Module must have options or config\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.NIX], indirect=True)\n    def test_find_references_within_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding references within the same file.\"\"\"\n        symbols = language_server.request_document_symbols(\"default.nix\").get_all_symbols_and_roots()\n\n        assert symbols is not None\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n\n        # Find makeGreeting function\n        greeting_symbol = None\n        for sym in symbol_list:\n            if sym.get(\"name\") == \"makeGreeting\":\n                greeting_symbol = sym\n                break\n\n        assert greeting_symbol is not None, \"makeGreeting function not found\"\n        assert \"range\" in greeting_symbol, \"Symbol must have range information\"\n\n        range_start = greeting_symbol[\"range\"][\"start\"]\n        refs = language_server.request_references(\"default.nix\", range_start[\"line\"], range_start[\"character\"])\n\n        assert refs is not None\n        assert isinstance(refs, list)\n        # nixd finds at least the inherit statement (line 67)\n        assert len(refs) >= 1, f\"Should find at least 1 reference to makeGreeting, found {len(refs)}\"\n\n        # Verify makeGreeting is referenced at expected locations\n        if refs:\n            ref_lines = sorted([ref[\"range\"][\"start\"][\"line\"] for ref in refs])\n            # Check if we found the inherit (line 67, 0-indexed: 66)\n            assert 66 in ref_lines, f\"Should find makeGreeting inherit at line 67, found at lines {[l+1 for l in ref_lines]}\"\n\n    @pytest.mark.xfail(is_ci, reason=\"Test is flaky\")  # TODO: Re-enable if the hover test becomes more stable (#1040)\n    @pytest.mark.parametrize(\"language_server\", [Language.NIX], indirect=True)\n    def test_hover_information(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test hover information for symbols.\"\"\"\n        # Get hover info for makeGreeting function\n        hover_info = language_server.request_hover(\"default.nix\", 12, 5)  # Position at makeGreeting\n\n        assert hover_info is not None, \"Should provide hover information\"\n\n        if isinstance(hover_info, dict) and len(hover_info) > 0:\n            # If hover info is provided, it should have proper structure\n            assert \"contents\" in hover_info or \"value\" in hover_info, \"Hover should have contents or value\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.NIX], indirect=True)\n    def test_cross_file_references_utils_import(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding cross-file references for imported utils.\"\"\"\n        # Find references to 'utils' which is imported in default.nix from lib/utils.nix\n        # Line 10 in default.nix: utils = import ./lib/utils.nix { inherit lib; };\n        refs = language_server.request_references(\"default.nix\", 9, 2)  # Position of 'utils'\n\n        assert refs is not None\n        assert isinstance(refs, list)\n\n        # Should find references within default.nix where utils is used\n        default_refs = [ref for ref in refs if \"default.nix\" in ref.get(\"uri\", \"\")]\n        # utils is: imported (line 10), used in listUtils.unique (line 24), inherited in exports (line 69)\n        assert len(default_refs) >= 2, f\"Should find at least 2 references to utils in default.nix, found {len(default_refs)}\"\n\n        # Verify utils is referenced at expected locations (0-indexed)\n        if default_refs:\n            ref_lines = sorted([ref[\"range\"][\"start\"][\"line\"] for ref in default_refs])\n            # Check for key references - at least the import (line 10) or usage (line 24)\n            assert (\n                9 in ref_lines or 23 in ref_lines\n            ), f\"Should find utils import or usage, found references at lines {[l+1 for l in ref_lines]}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.NIX], indirect=True)\n    def test_verify_imports_exist(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Verify that our test files have proper imports set up.\"\"\"\n        # Verify that default.nix imports utils from lib/utils.nix\n        symbols = language_server.request_document_symbols(\"default.nix\").get_all_symbols_and_roots()\n\n        assert symbols is not None\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n\n        # Check that makeGreeting exists (defined in default.nix)\n        symbol_names = {sym.get(\"name\") for sym in symbol_list if isinstance(sym, dict)}\n        assert \"makeGreeting\" in symbol_names, \"makeGreeting should be found in default.nix\"\n\n        # Verify lib/utils.nix has the expected structure\n        utils_symbols = language_server.request_document_symbols(\"lib/utils.nix\").get_all_symbols_and_roots()\n        assert utils_symbols is not None\n        utils_list = utils_symbols[0] if isinstance(utils_symbols, tuple) else utils_symbols\n        utils_names = {sym.get(\"name\") for sym in utils_list if isinstance(sym, dict)}\n\n        # Verify key functions exist in utils\n        assert \"math\" in utils_names, \"math should be found in lib/utils.nix\"\n        assert \"strings\" in utils_names, \"strings should be found in lib/utils.nix\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.NIX], indirect=True)\n    def test_go_to_definition_cross_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test go-to-definition from default.nix to lib/utils.nix.\"\"\"\n        # Line 24 in default.nix: unique = utils.lists.unique;\n        # Test go-to-definition for 'utils'\n        definitions = language_server.request_definition(\"default.nix\", 23, 14)  # Position of 'utils'\n\n        assert definitions is not None\n        assert isinstance(definitions, list)\n\n        if len(definitions) > 0:\n            # Should point to the import statement or utils.nix\n            assert any(\n                \"utils\" in def_item.get(\"uri\", \"\") or \"default.nix\" in def_item.get(\"uri\", \"\") for def_item in definitions\n            ), \"Definition should relate to utils import or utils.nix file\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.NIX], indirect=True)\n    def test_definition_navigation_in_flake(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test definition navigation in flake.nix.\"\"\"\n        # Test that we can navigate to definitions within flake.nix\n        # Line 69: default = hello-custom;\n        definitions = language_server.request_definition(\"flake.nix\", 68, 20)  # Position of 'hello-custom'\n\n        assert definitions is not None\n        assert isinstance(definitions, list)\n        # nixd should find the definition of hello-custom in the same file\n        if len(definitions) > 0:\n            assert any(\n                \"flake.nix\" in def_item.get(\"uri\", \"\") for def_item in definitions\n            ), \"Should find hello-custom definition in flake.nix\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.NIX], indirect=True)\n    def test_full_symbol_tree(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that full symbol tree is not empty.\"\"\"\n        symbols = language_server.request_full_symbol_tree()\n\n        assert symbols is not None\n        assert len(symbols) > 0, \"Symbol tree should not be empty\"\n\n        # The tree should have at least one root node\n        root = symbols[0]\n        assert isinstance(root, dict), \"Root should be a dict\"\n        assert \"name\" in root, \"Root should have a name\"\n"
  },
  {
    "path": "test/solidlsp/ocaml/test_cross_file_refs.py",
    "content": "\"\"\"\nTest cross-file references for OCaml.\n\nCross-file references require OCaml >= 5.2 and ocaml-lsp-server >= 1.23.0.\nOn environments without these (e.g. Windows CI with OCaml 4.14), only\nsame-file references are asserted.\n\"\"\"\n\nimport logging\nimport os\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.language_servers.ocaml_lsp_server import OcamlLanguageServer\nfrom solidlsp.ls_config import Language\n\nlog = logging.getLogger(__name__)\n\n\n@pytest.mark.ocaml\nclass TestCrossFileReferences:\n    @pytest.mark.parametrize(\"language_server\", [Language.OCAML], indirect=True)\n    def test_fib_has_cross_file_references(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that fib function references are found across multiple files.\n\n        The `fib` function is defined in lib/test_repo.ml and used in:\n        - lib/test_repo.ml (definition + 2 recursive calls)\n        - bin/main.ml (1 call)\n        - test/test_test_repo.ml (5 references)\n\n        Total: 9 references across 3 files.\n        \"\"\"\n        file_path = os.path.join(\"lib\", \"test_repo.ml\")\n\n        fib_line = 7\n        fib_char = 8\n\n        refs = language_server.request_references(file_path, fib_line, fib_char)\n\n        lib_refs = [ref for ref in refs if \"lib/test_repo.ml\" in ref.get(\"uri\", \"\")]\n        bin_refs = [ref for ref in refs if \"bin/main.ml\" in ref.get(\"uri\", \"\")]\n        test_refs = [ref for ref in refs if \"test/test_test_repo.ml\" in ref.get(\"uri\", \"\")]\n\n        log.info(\"Cross-file references result:\")\n        log.info(f\"Total references found: {len(refs)}\")\n        log.info(f\"  lib/test_repo.ml: {len(lib_refs)}\")\n        log.info(f\"  bin/main.ml: {len(bin_refs)}\")\n        log.info(f\"  test/test_test_repo.ml: {len(test_refs)}\")\n\n        for ref in refs:\n            uri = ref.get(\"uri\", \"\")\n            filename = uri.split(\"/\")[-1]\n            line = ref.get(\"range\", {}).get(\"start\", {}).get(\"line\", -1)\n            log.info(f\"    {filename}:{line}\")\n\n        # Same-file references always work\n        assert len(lib_refs) >= 3, f\"Expected at least 3 references in lib/test_repo.ml (definition + 2 recursive), but got {len(lib_refs)}\"\n\n        # Cross-file references require OCaml >= 5.2 and ocaml-lsp-server >= 1.23.0\n        if isinstance(language_server, OcamlLanguageServer) and language_server.supports_cross_file_references:\n            assert len(refs) >= 9, (\n                f\"Expected at least 9 total references (3 in lib + 1 in bin + 5 in test), \"\n                f\"but got {len(refs)}. Cross-file references are NOT working!\"\n            )\n\n            assert len(bin_refs) >= 1, (\n                f\"Expected at least 1 reference in bin/main.ml, but got {len(bin_refs)}. \"\n                \"Cross-file references are NOT working - bin/main.ml not found!\"\n            )\n\n            assert len(test_refs) >= 1, (\n                f\"Expected at least 1 reference in test/test_test_repo.ml, but got {len(test_refs)}. \"\n                \"Cross-file references are NOT working - test file not found!\"\n            )\n"
  },
  {
    "path": "test/solidlsp/ocaml/test_ocaml_basic.py",
    "content": "import os\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_utils import SymbolUtils\n\n\n@pytest.mark.ocaml\nclass TestOCamlLanguageServer:\n    @pytest.mark.parametrize(\"language_server\", [Language.OCAML], indirect=True)\n    def test_find_symbol(self, language_server: SolidLanguageServer) -> None:\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"DemoModule\"), \"DemoModule not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"fib\"), \"fib not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"someFunction\"), \"someFunction function not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.OCAML], indirect=True)\n    def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:\n        file_path = os.path.join(\"lib\", \"test_repo.ml\")\n\n        # Use the correct character position for 'fib' function name\n        # Line 8: \"let rec fib n =\" - 'fib' starts at character 8 (0-indexed)\n        fib_line = 7  # 0-indexed line number\n        fib_char = 8  # 0-indexed character position\n\n        refs = language_server.request_references(file_path, fib_line, fib_char)\n\n        # Should find at least 3 references: definition + 2 recursive calls in same file\n        assert len(refs) >= 3, f\"Expected at least 3 references to fib (definition + 2 recursive), found {len(refs)}\"\n\n        # All references should be in lib/test_repo.ml (same file as definition)\n        # Use forward slashes for URI matching (URIs always use /)\n        lib_refs = [ref for ref in refs if \"lib/test_repo.ml\" in ref.get(\"uri\", \"\")]\n        assert len(lib_refs) >= 3, f\"Expected at least 3 references in lib/test_repo.ml, found {len(lib_refs)}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.OCAML], indirect=True)\n    def test_mixed_ocaml_modules(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that the language server can find symbols from OCaml modules\"\"\"\n        # Test that full symbol tree includes symbols from various file types\n        all_symbols = language_server.request_full_symbol_tree()\n\n        # Should find symbols from main OCaml files\n        assert SymbolUtils.symbol_tree_contains_name(all_symbols, \"fib\"), \"Should find fib from .ml file\"\n        assert SymbolUtils.symbol_tree_contains_name(all_symbols, \"DemoModule\"), \"Should find DemoModule from .ml file\"\n        assert SymbolUtils.symbol_tree_contains_name(all_symbols, \"someFunction\"), \"Should find someFunction from DemoModule\"\n        assert SymbolUtils.symbol_tree_contains_name(all_symbols, \"num_domains\"), \"Should find num_domains constant\"\n\n    def test_reason_file_patterns(self) -> None:\n        \"\"\"Test that OCaml language configuration recognizes Reason file extensions\"\"\"\n        from solidlsp.ls_config import Language\n\n        ocaml_lang = Language.OCAML\n        file_matcher = ocaml_lang.get_source_fn_matcher()\n\n        # Test OCaml extensions\n        assert file_matcher.is_relevant_filename(\"test.ml\"), \"Should match .ml files\"\n        assert file_matcher.is_relevant_filename(\"test.mli\"), \"Should match .mli files\"\n\n        # Test Reason extensions\n        assert file_matcher.is_relevant_filename(\"test.re\"), \"Should match .re files\"\n        assert file_matcher.is_relevant_filename(\"test.rei\"), \"Should match .rei files\"\n\n        # Test non-matching extensions\n        assert not file_matcher.is_relevant_filename(\"test.py\"), \"Should not match .py files\"\n        assert not file_matcher.is_relevant_filename(\"test.js\"), \"Should not match .js files\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.OCAML], indirect=True)\n    def test_module_hierarchy_navigation(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test navigation within module hierarchy including DemoModule.\"\"\"\n        file_path = os.path.join(\"lib\", \"test_repo.ml\")\n\n        # Use correct position for 'DemoModule' (line 1, char 7)\n        # Line 1: \"module DemoModule = struct\" - 'DemoModule' starts around char 7\n        module_line = 0  # 0-indexed\n        module_char = 7  # 0-indexed\n\n        refs = language_server.request_references(file_path, module_line, module_char)\n\n        # Should find at least 1 reference (the definition)\n        assert len(refs) >= 1, f\"Expected at least 1 reference to DemoModule, found {len(refs)}\"\n\n        # Check that references are found - use forward slashes for URI matching\n        lib_refs = [ref for ref in refs if \"lib/test_repo.ml\" in ref.get(\"uri\", \"\")]\n        assert len(lib_refs) >= 1, f\"Expected at least 1 reference in lib/test_repo.ml, found {len(lib_refs)}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.OCAML], indirect=True)\n    def test_let_binding_references(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding references to let-bound values across files.\"\"\"\n        file_path = os.path.join(\"lib\", \"test_repo.ml\")\n\n        # Use correct position for 'num_domains' (line 12, char 4)\n        # Line 12: \"let num_domains = 2\" - 'num_domains' starts around char 4\n        num_domains_line = 11  # 0-indexed\n        num_domains_char = 4  # 0-indexed\n\n        refs = language_server.request_references(file_path, num_domains_line, num_domains_char)\n\n        # Should find at least 1 reference (the definition)\n        assert len(refs) >= 1, f\"Expected at least 1 reference to num_domains, found {len(refs)}\"\n\n        # Check that reference is found in the definition file - use forward slashes\n        ml_refs = [ref for ref in refs if \"lib/test_repo.ml\" in ref.get(\"uri\", \"\")]\n        assert len(ml_refs) >= 1, f\"Expected at least 1 reference in lib/test_repo.ml, found {len(ml_refs)}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.OCAML], indirect=True)\n    def test_recursive_function_analysis(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that recursive function calls are properly identified within the definition file.\"\"\"\n        file_path = os.path.join(\"lib\", \"test_repo.ml\")\n\n        # Use correct position for 'fib' function name (line 8, char 8)\n        fib_line = 7  # 0-indexed\n        fib_char = 8  # 0-indexed\n\n        refs = language_server.request_references(file_path, fib_line, fib_char)\n\n        # Filter to references within the definition file only - use forward slashes\n        same_file_refs = [ref for ref in refs if \"lib/test_repo.ml\" in ref.get(\"uri\", \"\")]\n\n        # Should find at least 3 references in test_repo.ml: definition + 2 recursive calls\n        # On OCaml 5.2+ with cross-file refs, there may be more total refs but same-file count stays the same\n        assert (\n            len(same_file_refs) >= 3\n        ), f\"Expected at least 3 references in test_repo.ml (definition + 2 recursive), found {len(same_file_refs)}\"\n\n        # Verify references are on different lines (definition + recursive calls)\n        ref_lines = [ref.get(\"range\", {}).get(\"start\", {}).get(\"line\", -1) for ref in same_file_refs]\n        unique_lines = len(set(ref_lines))\n        assert unique_lines >= 2, f\"Recursive calls should appear on multiple lines, found {unique_lines} unique lines\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.OCAML], indirect=True)\n    def test_open_statement_resolution(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that open statements allow unqualified access to module contents.\"\"\"\n        # In bin/main.ml, fib is called without Test_repo prefix due to 'open Test_repo'\n        all_symbols = language_server.request_full_symbol_tree()\n\n        # Should be able to find fib through symbol tree\n        fib_accessible = SymbolUtils.symbol_tree_contains_name(all_symbols, \"fib\")\n        assert fib_accessible, \"fib should be accessible through open statement\"\n\n        # DemoModule should also be accessible\n        demo_module_accessible = SymbolUtils.symbol_tree_contains_name(all_symbols, \"DemoModule\")\n        assert demo_module_accessible, \"DemoModule should be accessible\"\n\n        # Verify we have access to both qualified and unqualified symbols\n        assert len(all_symbols) > 0, \"Should find symbols from OCaml files\"\n\n        # Test that the language server recognizes the open statement context\n        file_path = os.path.join(\"bin\", \"main.ml\")\n        symbols, _roots = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        assert len(symbols) > 0, \"Should find symbols in main.ml that use opened modules\"\n"
  },
  {
    "path": "test/solidlsp/pascal/__init__.py",
    "content": "def _check_pascal_available() -> bool:\n    \"\"\"Check if Pascal language server (pasls) is available.\n\n    Note: pasls will be auto-downloaded if not present, so Pascal\n    support is always available.\n    \"\"\"\n    return True\n\n\nPASCAL_AVAILABLE = _check_pascal_available()\n\n\ndef is_pascal_available() -> bool:\n    \"\"\"Return True if Pascal language server can be used.\"\"\"\n    return PASCAL_AVAILABLE\n"
  },
  {
    "path": "test/solidlsp/pascal/test_pascal_auto_update.py",
    "content": "\"\"\"\nUnit tests for the Pascal language server auto-update functionality.\n\nThese tests validate the version comparison, checksum verification,\nand other helper methods without requiring network access or the\nactual Pascal language server.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport hashlib\nimport os\nimport tarfile\nimport tempfile\nimport time\n\nimport pytest\n\nfrom solidlsp.language_servers.pascal_server import PascalLanguageServer\n\npytestmark = [pytest.mark.pascal]\n\n\nclass TestVersionNormalization:\n    \"\"\"Test version string normalization.\"\"\"\n\n    def test_normalize_version_with_v_prefix(self) -> None:\n        \"\"\"Test that 'v' prefix is stripped.\"\"\"\n        assert PascalLanguageServer._normalize_version(\"v1.0.0\") == \"1.0.0\"\n\n    def test_normalize_version_with_capital_v_prefix(self) -> None:\n        \"\"\"Test that 'V' prefix is stripped.\"\"\"\n        assert PascalLanguageServer._normalize_version(\"V1.0.0\") == \"1.0.0\"\n\n    def test_normalize_version_without_prefix(self) -> None:\n        \"\"\"Test version without prefix is unchanged.\"\"\"\n        assert PascalLanguageServer._normalize_version(\"1.0.0\") == \"1.0.0\"\n\n    def test_normalize_version_with_whitespace(self) -> None:\n        \"\"\"Test that whitespace is stripped.\"\"\"\n        assert PascalLanguageServer._normalize_version(\"  v1.0.0  \") == \"1.0.0\"\n\n    def test_normalize_version_empty(self) -> None:\n        \"\"\"Test empty version returns empty string.\"\"\"\n        assert PascalLanguageServer._normalize_version(\"\") == \"\"\n\n    def test_normalize_version_none(self) -> None:\n        \"\"\"Test None returns empty string.\"\"\"\n        assert PascalLanguageServer._normalize_version(None) == \"\"\n\n\nclass TestVersionComparison:\n    \"\"\"Test version comparison logic.\"\"\"\n\n    def test_newer_version_major(self) -> None:\n        \"\"\"Test detection of newer major version.\"\"\"\n        assert PascalLanguageServer._is_newer_version(\"v2.0.0\", \"v1.0.0\") is True\n\n    def test_newer_version_minor(self) -> None:\n        \"\"\"Test detection of newer minor version.\"\"\"\n        assert PascalLanguageServer._is_newer_version(\"v1.1.0\", \"v1.0.0\") is True\n\n    def test_newer_version_patch(self) -> None:\n        \"\"\"Test detection of newer patch version.\"\"\"\n        assert PascalLanguageServer._is_newer_version(\"v1.0.1\", \"v1.0.0\") is True\n\n    def test_same_version(self) -> None:\n        \"\"\"Test same version returns False.\"\"\"\n        assert PascalLanguageServer._is_newer_version(\"v1.0.0\", \"v1.0.0\") is False\n\n    def test_older_version(self) -> None:\n        \"\"\"Test older version returns False.\"\"\"\n        assert PascalLanguageServer._is_newer_version(\"v1.0.0\", \"v2.0.0\") is False\n\n    def test_latest_none_returns_false(self) -> None:\n        \"\"\"Test None latest version returns False.\"\"\"\n        assert PascalLanguageServer._is_newer_version(None, \"v1.0.0\") is False\n\n    def test_local_none_returns_true(self) -> None:\n        \"\"\"Test None local version returns True (first install).\"\"\"\n        assert PascalLanguageServer._is_newer_version(\"v1.0.0\", None) is True\n\n    def test_both_none_returns_false(self) -> None:\n        \"\"\"Test both None returns False.\"\"\"\n        assert PascalLanguageServer._is_newer_version(None, None) is False\n\n    def test_version_with_different_lengths(self) -> None:\n        \"\"\"Test versions with different number of parts.\"\"\"\n        assert PascalLanguageServer._is_newer_version(\"v1.0.1\", \"v1.0\") is True\n        assert PascalLanguageServer._is_newer_version(\"v1.0\", \"v1.0.1\") is False\n\n    def test_version_with_prerelease(self) -> None:\n        \"\"\"Test versions with prerelease suffixes.\"\"\"\n        # Prerelease suffix is ignored, only numeric parts are compared\n        assert PascalLanguageServer._is_newer_version(\"v1.1.0-beta\", \"v1.0.0\") is True\n\n\nclass TestSHA256Checksum:\n    \"\"\"Test SHA256 checksum calculation and verification.\"\"\"\n\n    def test_calculate_sha256(self) -> None:\n        \"\"\"Test SHA256 calculation for a known content.\"\"\"\n        with tempfile.NamedTemporaryFile(mode=\"wb\", delete=False) as f:\n            f.write(b\"test content\")\n            temp_path = f.name\n\n        try:\n            result = PascalLanguageServer._calculate_sha256(temp_path)\n            expected = hashlib.sha256(b\"test content\").hexdigest()\n            assert result == expected\n        finally:\n            os.unlink(temp_path)\n\n    def test_verify_checksum_correct(self) -> None:\n        \"\"\"Test checksum verification with correct checksum.\"\"\"\n        with tempfile.NamedTemporaryFile(mode=\"wb\", delete=False) as f:\n            f.write(b\"test content\")\n            temp_path = f.name\n\n        try:\n            expected = hashlib.sha256(b\"test content\").hexdigest()\n            assert PascalLanguageServer._verify_checksum(temp_path, expected) is True\n        finally:\n            os.unlink(temp_path)\n\n    def test_verify_checksum_incorrect(self) -> None:\n        \"\"\"Test checksum verification with incorrect checksum.\"\"\"\n        with tempfile.NamedTemporaryFile(mode=\"wb\", delete=False) as f:\n            f.write(b\"test content\")\n            temp_path = f.name\n\n        try:\n            wrong_checksum = \"0\" * 64\n            assert PascalLanguageServer._verify_checksum(temp_path, wrong_checksum) is False\n        finally:\n            os.unlink(temp_path)\n\n    def test_verify_checksum_case_insensitive(self) -> None:\n        \"\"\"Test checksum verification is case insensitive.\"\"\"\n        with tempfile.NamedTemporaryFile(mode=\"wb\", delete=False) as f:\n            f.write(b\"test content\")\n            temp_path = f.name\n\n        try:\n            expected = hashlib.sha256(b\"test content\").hexdigest().upper()\n            assert PascalLanguageServer._verify_checksum(temp_path, expected) is True\n        finally:\n            os.unlink(temp_path)\n\n\nclass TestTarfileSafety:\n    \"\"\"Test tarfile path traversal protection.\"\"\"\n\n    def test_safe_tar_member_normal_path(self) -> None:\n        \"\"\"Test normal path is considered safe.\"\"\"\n        member = tarfile.TarInfo(name=\"pasls\")\n        assert PascalLanguageServer._is_safe_tar_member(member, \"/tmp/target\") is True\n\n    def test_safe_tar_member_nested_path(self) -> None:\n        \"\"\"Test nested path is considered safe.\"\"\"\n        member = tarfile.TarInfo(name=\"subdir/pasls\")\n        assert PascalLanguageServer._is_safe_tar_member(member, \"/tmp/target\") is True\n\n    def test_unsafe_tar_member_path_traversal(self) -> None:\n        \"\"\"Test path traversal is detected.\"\"\"\n        member = tarfile.TarInfo(name=\"../etc/passwd\")\n        assert PascalLanguageServer._is_safe_tar_member(member, \"/tmp/target\") is False\n\n    def test_unsafe_tar_member_hidden_traversal(self) -> None:\n        \"\"\"Test hidden path traversal in nested path.\"\"\"\n        member = tarfile.TarInfo(name=\"subdir/../../etc/passwd\")\n        assert PascalLanguageServer._is_safe_tar_member(member, \"/tmp/target\") is False\n\n    def test_safe_tar_member_similar_name(self) -> None:\n        \"\"\"Test path containing '..' in filename (not directory) is safe.\"\"\"\n        member = tarfile.TarInfo(name=\"file..name\")\n        assert PascalLanguageServer._is_safe_tar_member(member, \"/tmp/target\") is True\n\n\nclass TestMetadataManagement:\n    \"\"\"Test metadata directory and file management.\"\"\"\n\n    def test_meta_dir_creates_directory(self) -> None:\n        \"\"\"Test _meta_dir creates directory if not exists.\"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            meta_path = PascalLanguageServer._meta_dir(temp_dir)\n            assert os.path.exists(meta_path)\n            assert meta_path == os.path.join(temp_dir, PascalLanguageServer.META_DIR)\n\n    def test_meta_file_returns_correct_path(self) -> None:\n        \"\"\"Test _meta_file returns correct path.\"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            meta_file = PascalLanguageServer._meta_file(temp_dir, \"version\")\n            expected = os.path.join(temp_dir, PascalLanguageServer.META_DIR, \"version\")\n            assert meta_file == expected\n\n\nclass TestUpdateCheckTiming:\n    \"\"\"Test update check timing logic.\"\"\"\n\n    def test_should_check_update_no_last_check(self) -> None:\n        \"\"\"Test should check when no last_check file exists.\"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            assert PascalLanguageServer._should_check_update(temp_dir) is True\n\n    def test_should_check_update_recent_check(self) -> None:\n        \"\"\"Test should not check when recently checked.\"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            # Create meta dir and last_check file with current time\n            meta_dir = PascalLanguageServer._meta_dir(temp_dir)\n            last_check_file = os.path.join(meta_dir, \"last_check\")\n            with open(last_check_file, \"w\") as f:\n                f.write(str(time.time()))\n\n            assert PascalLanguageServer._should_check_update(temp_dir) is False\n\n    def test_should_check_update_old_check(self) -> None:\n        \"\"\"Test should check when last check was > 24 hours ago.\"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            # Create meta dir and last_check file with old time\n            meta_dir = PascalLanguageServer._meta_dir(temp_dir)\n            last_check_file = os.path.join(meta_dir, \"last_check\")\n            old_time = time.time() - (PascalLanguageServer.UPDATE_CHECK_INTERVAL + 3600)\n            with open(last_check_file, \"w\") as f:\n                f.write(str(old_time))\n\n            assert PascalLanguageServer._should_check_update(temp_dir) is True\n\n    def test_update_last_check_creates_file(self) -> None:\n        \"\"\"Test _update_last_check creates timestamp file.\"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            PascalLanguageServer._update_last_check(temp_dir)\n            last_check_file = PascalLanguageServer._meta_file(temp_dir, \"last_check\")\n            assert os.path.exists(last_check_file)\n\n            with open(last_check_file) as f:\n                timestamp = float(f.read().strip())\n            assert abs(timestamp - time.time()) < 5  # within 5 seconds\n\n\nclass TestVersionPersistence:\n    \"\"\"Test local version persistence.\"\"\"\n\n    def test_save_and_get_local_version(self) -> None:\n        \"\"\"Test saving and retrieving local version.\"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            PascalLanguageServer._save_local_version(temp_dir, \"v1.0.0\")\n            version = PascalLanguageServer._get_local_version(temp_dir)\n            assert version == \"v1.0.0\"\n\n    def test_get_local_version_not_exists(self) -> None:\n        \"\"\"Test getting version when file doesn't exist.\"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            version = PascalLanguageServer._get_local_version(temp_dir)\n            assert version is None\n"
  },
  {
    "path": "test/solidlsp/pascal/test_pascal_basic.py",
    "content": "\"\"\"\nBasic integration tests for the Pascal language server functionality.\n\nThese tests validate the functionality of the language server APIs\nlike request_document_symbols using the Pascal test repository.\n\nUses genericptr/pascal-language-server which returns SymbolInformation[] format:\n- Returns classes, structs, enums, typedefs, functions/procedures\n- Uses correct SymbolKind values: Class=5, Function=12, Method=6, Struct=23\n- Method names don't include parent class prefix; uses containerName instead\n\"\"\"\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_types import SymbolKind\nfrom test.conftest import language_tests_enabled\n\npytestmark = [\n    pytest.mark.pascal,\n    pytest.mark.skipif(not language_tests_enabled(Language.PASCAL), reason=\"Pascal tests are disabled (pasls/fpc not available)\"),\n]\n\n\n@pytest.mark.pascal\nclass TestPascalLanguageServerBasics:\n    \"\"\"Test basic functionality of the Pascal language server.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PASCAL], indirect=True)\n    def test_pascal_language_server_initialization(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that Pascal language server can be initialized successfully.\"\"\"\n        assert language_server is not None\n        assert language_server.language == Language.PASCAL\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PASCAL], indirect=True)\n    def test_pascal_request_document_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_document_symbols for Pascal files.\n\n        genericptr pasls returns proper SymbolKind values:\n        - Standalone functions: kind=12 (Function)\n        - Classes: kind=5 (Class)\n        \"\"\"\n        # Test getting symbols from main.pas\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"main.pas\").get_all_symbols_and_roots()\n\n        # Should have symbols\n        assert len(all_symbols) > 0, \"Should have symbols in main.pas\"\n\n        # Should detect standalone functions (SymbolKind.Function = 12)\n        function_symbols = [s for s in all_symbols if s.get(\"kind\") == SymbolKind.Function]\n        function_names = [s[\"name\"] for s in function_symbols]\n\n        assert \"CalculateSum\" in function_names, \"Should find CalculateSum function\"\n        assert \"PrintMessage\" in function_names, \"Should find PrintMessage procedure\"\n\n        # Should detect classes (SymbolKind.Class = 5)\n        class_symbols = [s for s in all_symbols if s.get(\"kind\") == SymbolKind.Class]\n        class_names = [s[\"name\"] for s in class_symbols]\n\n        assert \"TUser\" in class_names, \"Should find TUser class\"\n        assert \"TUserManager\" in class_names, \"Should find TUserManager class\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PASCAL], indirect=True)\n    def test_pascal_class_methods(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test detection of class methods in Pascal files.\n\n        pasls returns class methods with SymbolKind.Method (kind 6), not Function (kind 12).\n        \"\"\"\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"main.pas\").get_all_symbols_and_roots()\n\n        # Get all method symbols (pasls returns class methods as SymbolKind.Method = 6)\n        method_symbols = [s for s in all_symbols if s.get(\"kind\") == SymbolKind.Method]\n        method_names = [s[\"name\"] for s in method_symbols]\n\n        # Should detect TUser methods\n        expected_tuser_methods = [\"Create\", \"Destroy\", \"GetInfo\", \"UpdateAge\"]\n        for method in expected_tuser_methods:\n            found = method in method_names\n            assert found, f\"Should find method '{method}'\"\n\n        # Should detect TUserManager methods\n        expected_manager_methods = [\"Create\", \"Destroy\", \"AddUser\", \"GetUserCount\", \"FindUserByName\"]\n        for method in expected_manager_methods:\n            found = method in method_names\n            assert found, f\"Should find method '{method}'\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PASCAL], indirect=True)\n    def test_pascal_helper_unit_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test function detection in Helper unit.\"\"\"\n        # Test with lib/helper.pas\n        helper_all_symbols, _helper_root_symbols = language_server.request_document_symbols(\"lib/helper.pas\").get_all_symbols_and_roots()\n\n        # Should have symbols\n        assert len(helper_all_symbols) > 0, \"Helper unit should have symbols\"\n\n        # Extract function symbols\n        function_symbols = [s for s in helper_all_symbols if s.get(\"kind\") == SymbolKind.Function]\n        function_names = [s[\"name\"] for s in function_symbols]\n\n        # Should detect standalone functions\n        expected_functions = [\"GetHelperMessage\", \"MultiplyNumbers\", \"LogMessage\"]\n        for func_name in expected_functions:\n            assert func_name in function_names, f\"Should find {func_name} function in Helper unit\"\n\n        # Should also detect THelper class methods (returned as SymbolKind.Method = 6)\n        method_symbols = [s for s in helper_all_symbols if s.get(\"kind\") == SymbolKind.Method]\n        method_names = [s[\"name\"] for s in method_symbols]\n        assert \"FormatString\" in method_names, \"Should find FormatString method\"\n        assert \"IsEven\" in method_names, \"Should find IsEven method\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PASCAL], indirect=True)\n    def test_pascal_cross_file_references(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that Pascal LSP can handle cross-file references.\"\"\"\n        # main.pas uses Helper unit\n        main_symbols, _main_roots = language_server.request_document_symbols(\"main.pas\").get_all_symbols_and_roots()\n        helper_symbols, _helper_roots = language_server.request_document_symbols(\"lib/helper.pas\").get_all_symbols_and_roots()\n\n        # Verify both files have symbols\n        assert len(main_symbols) > 0, \"main.pas should have symbols\"\n        assert len(helper_symbols) > 0, \"helper.pas should have symbols\"\n\n        # Verify GetHelperMessage is in Helper unit\n        helper_function_names = [s[\"name\"] for s in helper_symbols if s.get(\"kind\") == SymbolKind.Function]\n        assert \"GetHelperMessage\" in helper_function_names, \"Helper unit should export GetHelperMessage\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PASCAL], indirect=True)\n    def test_pascal_symbol_locations(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that symbols have correct location information.\n\n        Note: genericptr pasls returns the interface declaration location (line ~41),\n        not the implementation location (line ~115).\n        \"\"\"\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"main.pas\").get_all_symbols_and_roots()\n\n        # Find CalculateSum function\n        calc_symbols = [s for s in all_symbols if s.get(\"name\") == \"CalculateSum\"]\n        assert len(calc_symbols) > 0, \"Should find CalculateSum\"\n\n        calc_symbol = calc_symbols[0]\n\n        # Verify it has location information (SymbolInformation format uses location.range)\n        if \"location\" in calc_symbol:\n            location = calc_symbol[\"location\"]\n            assert \"range\" in location, \"Location should have range\"\n            assert \"start\" in location[\"range\"], \"Range should have start\"\n            assert \"line\" in location[\"range\"][\"start\"], \"Start should have line\"\n            line = location[\"range\"][\"start\"][\"line\"]\n        else:\n            # DocumentSymbol format uses range directly\n            assert \"range\" in calc_symbol, \"Symbol should have range\"\n            assert \"start\" in calc_symbol[\"range\"], \"Range should have start\"\n            line = calc_symbol[\"range\"][\"start\"][\"line\"]\n\n        # CalculateSum is declared at line 41 in main.pas (0-indexed would be 40)\n        # genericptr pasls returns interface declaration location\n        assert 35 <= line <= 45, f\"CalculateSum should be around line 41 (interface), got {line}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PASCAL], indirect=True)\n    def test_pascal_namespace_symbol(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that genericptr pasls returns Interface namespace symbol.\"\"\"\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"main.pas\").get_all_symbols_and_roots()\n\n        # genericptr pasls adds an \"Interface\" namespace symbol\n        symbol_names = [s[\"name\"] for s in all_symbols]\n\n        # The Interface section should be represented\n        # Note: This depends on pasls configuration\n        assert len(all_symbols) > 0, \"Should have symbols\"\n        # Interface namespace may or may not be present depending on pasls configuration\n        _ = symbol_names  # used for potential future assertions\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PASCAL], indirect=True)\n    def test_pascal_hover_with_doc_comments(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that hover returns documentation comments.\n\n        CalculateSum has /// style doc comments that should appear in hover.\n        \"\"\"\n        # CalculateSum is declared at line 46 (1-indexed), so line 45 (0-indexed)\n        hover = language_server.request_hover(\"main.pas\", 45, 12)\n\n        assert hover is not None, \"Hover should return a result\"\n\n        # Extract hover content - handle both dict and object formats\n        if isinstance(hover, dict):\n            contents = hover.get(\"contents\", {})\n            value = contents.get(\"value\", \"\") if isinstance(contents, dict) else str(contents)\n        else:\n            value = hover.contents.value if hasattr(hover.contents, \"value\") else str(hover.contents)\n\n        # Should contain the function signature\n        assert \"CalculateSum\" in value, f\"Hover should show function name. Got: {value[:500]}\"\n\n        # Should contain the doc comment\n        assert \"Calculates the sum\" in value, f\"Hover should include doc comment. Got: {value[:500]}\"\n"
  },
  {
    "path": "test/solidlsp/perl/test_perl_basic.py",
    "content": "import platform\nfrom pathlib import Path\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\n\n@pytest.mark.perl\n@pytest.mark.skipif(platform.system() == \"Windows\", reason=\"Perl::LanguageServer does not support native Windows operation\")\nclass TestPerlLanguageServer:\n    \"\"\"\n    Tests for Perl::LanguageServer integration.\n\n    Perl::LanguageServer provides comprehensive LSP support for Perl including:\n    - Document symbols (functions, variables)\n    - Go to definition (including cross-file)\n    - Find references (including cross-file) - this was not available in PLS\n    \"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PERL], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.PERL], indirect=True)\n    def test_ls_is_running(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that the language server starts and stops successfully.\"\"\"\n        # The fixture already handles start and stop\n        assert language_server.is_running()\n        assert Path(language_server.language_server.repository_root_path).resolve() == repo_path.resolve()\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PERL], indirect=True)\n    def test_document_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that document symbols are correctly identified.\"\"\"\n        # Request document symbols\n        all_symbols, _ = language_server.request_document_symbols(\"main.pl\").get_all_symbols_and_roots()\n\n        assert all_symbols, \"Expected to find symbols in main.pl\"\n        assert len(all_symbols) > 0, \"Expected at least one symbol\"\n\n        # DEBUG: Print all symbols\n        print(\"\\n=== All symbols in main.pl ===\")\n        for s in all_symbols:\n            line = s.get(\"range\", {}).get(\"start\", {}).get(\"line\", \"?\")\n            print(f\"Line {line}: {s.get('name')} (kind={s.get('kind')})\")\n\n        # Check that we can find function symbols\n        function_symbols = [s for s in all_symbols if s.get(\"kind\") == 12]  # 12 = Function/Method\n        assert len(function_symbols) >= 2, f\"Expected at least 2 functions (greet, use_helper_function), found {len(function_symbols)}\"\n\n        function_names = [s.get(\"name\") for s in function_symbols]\n        assert \"greet\" in function_names, f\"Expected 'greet' function in symbols, found: {function_names}\"\n        assert \"use_helper_function\" in function_names, f\"Expected 'use_helper_function' in symbols, found: {function_names}\"\n\n    # @pytest.mark.skip(reason=\"Perl::LanguageServer cross-file definition tracking needs configuration\")\n    @pytest.mark.parametrize(\"language_server\", [Language.PERL], indirect=True)\n    def test_find_definition_across_files(self, language_server: SolidLanguageServer) -> None:\n        definition_location_list = language_server.request_definition(\"main.pl\", 17, 0)\n\n        assert len(definition_location_list) == 1\n        definition_location = definition_location_list[0]\n        print(f\"Found definition: {definition_location}\")\n        assert definition_location[\"uri\"].endswith(\"helper.pl\")\n        assert definition_location[\"range\"][\"start\"][\"line\"] == 4  # add method on line 2 (0-indexed 1)\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PERL], indirect=True)\n    def test_find_references_across_files(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding references to a function across multiple files.\"\"\"\n        reference_locations = language_server.request_references(\"helper.pl\", 4, 5)\n\n        assert len(reference_locations) >= 2, f\"Expected at least 2 references to helper_function, found {len(reference_locations)}\"\n\n        main_pl_refs = [ref for ref in reference_locations if ref[\"uri\"].endswith(\"main.pl\")]\n        assert len(main_pl_refs) >= 2, f\"Expected at least 2 references in main.pl, found {len(main_pl_refs)}\"\n\n        main_pl_lines = sorted([ref[\"range\"][\"start\"][\"line\"] for ref in main_pl_refs])\n        assert 17 in main_pl_lines, f\"Expected reference at line 18 (0-indexed 17), found: {main_pl_lines}\"\n        assert 20 in main_pl_lines, f\"Expected reference at line 21 (0-indexed 20), found: {main_pl_lines}\"\n"
  },
  {
    "path": "test/solidlsp/php/test_php_basic.py",
    "content": "from pathlib import Path\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom test.conftest import is_ci, is_windows, language_tests_enabled\n\n_php_servers: list[Language] = [Language.PHP]\nif language_tests_enabled(Language.PHP_PHPACTOR):\n    if not (is_windows and is_ci):  # TODO: Phpactor tests are flaky in Windows CI and can even cause hangs #1040\n        _php_servers.append(Language.PHP_PHPACTOR)\n\n\n@pytest.mark.php\nclass TestPhpLanguageServers:\n    @pytest.mark.parametrize(\"language_server\", _php_servers, indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.PHP], indirect=True)\n    def test_ls_is_running(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that the language server starts and stops successfully.\"\"\"\n        assert language_server.is_running()\n        assert Path(language_server.language_server.repository_root_path).resolve() == repo_path.resolve()\n\n    @pytest.mark.parametrize(\"language_server\", _php_servers, indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.PHP], indirect=True)\n    def test_find_definition_within_file(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        # In index.php:\n        # Line 9 (1-indexed): $greeting = greet($userName);\n        # Line 11 (1-indexed): echo $greeting;\n        # We want to find the definition of $greeting (defined on line 9)\n        # from its usage in echo $greeting; on line 11.\n        # LSP is 0-indexed: definition on line 8, usage on line 10.\n        # $greeting in echo $greeting;  (e c h o   $ g r e e t i n g)\n        #                           ^ char 5\n        # Intelephense uses line 10 (0-indexed), Phpactor uses line 11 (0-indexed)\n        if language_server.language_server.language == Language.PHP_PHPACTOR:\n            definition_location_list = language_server.request_definition(str(repo_path / \"index.php\"), 11, 6)\n        else:\n            definition_location_list = language_server.request_definition(str(repo_path / \"index.php\"), 10, 6)\n\n        assert definition_location_list, f\"Expected non-empty definition_location_list but got {definition_location_list=}\"\n        if language_server.language_server.language == Language.PHP_PHPACTOR:\n            assert len(definition_location_list) >= 1\n        else:\n            assert len(definition_location_list) == 1\n        definition_location = definition_location_list[0]\n        assert definition_location[\"uri\"].endswith(\"index.php\")\n        # Definition of $greeting is on line 10 (1-indexed) / line 9 (0-indexed), char 0\n        assert definition_location[\"range\"][\"start\"][\"line\"] == 9\n        if language_server.language_server.language != Language.PHP_PHPACTOR:\n            assert definition_location[\"range\"][\"start\"][\"character\"] == 0\n\n    @pytest.mark.parametrize(\"language_server\", _php_servers, indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.PHP], indirect=True)\n    def test_find_definition_across_files(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        # Intelephense uses line 12 (0-indexed), Phpactor uses line 13 (0-indexed)\n        if language_server.language_server.language == Language.PHP_PHPACTOR:\n            definition_location_list = language_server.request_definition(str(repo_path / \"index.php\"), 13, 5)\n        else:\n            definition_location_list = language_server.request_definition(str(repo_path / \"index.php\"), 12, 5)\n\n        assert definition_location_list, f\"Expected non-empty definition_location_list but got {definition_location_list=}\"\n        if language_server.language_server.language == Language.PHP_PHPACTOR:\n            assert len(definition_location_list) >= 1\n        else:\n            assert len(definition_location_list) == 1\n        definition_location = definition_location_list[0]\n        assert definition_location[\"uri\"].endswith(\"helper.php\")\n        assert definition_location[\"range\"][\"start\"][\"line\"] == 2\n        if language_server.language_server.language != Language.PHP_PHPACTOR:\n            assert definition_location[\"range\"][\"start\"][\"character\"] == 0\n\n    @pytest.mark.parametrize(\"language_server\", _php_servers, indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.PHP], indirect=True)\n    def test_find_definition_simple_variable(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        file_path = str(repo_path / \"simple_var.php\")\n\n        # In simple_var.php:\n        # Line 2 (1-indexed): $localVar = \"test\";\n        # Line 3 (1-indexed): echo $localVar;\n        # LSP is 0-indexed: definition on line 1, usage on line 2\n        # Find definition of $localVar (char 5 on line 3 / 0-indexed: line 2, char 5)\n        # $localVar in echo $localVar;  (e c h o   $ l o c a l V a r)\n        #                           ^ char 5\n        definition_location_list = language_server.request_definition(file_path, 2, 6)  # cursor on 'l' in $localVar\n\n        assert definition_location_list, f\"Expected non-empty definition_location_list but got {definition_location_list=}\"\n        if language_server.language_server.language == Language.PHP_PHPACTOR:\n            assert len(definition_location_list) >= 1\n        else:\n            assert len(definition_location_list) == 1\n        definition_location = definition_location_list[0]\n        assert definition_location[\"uri\"].endswith(\"simple_var.php\")\n        assert definition_location[\"range\"][\"start\"][\"line\"] == 1  # Definition of $localVar (0-indexed)\n        if language_server.language_server.language != Language.PHP_PHPACTOR:\n            assert definition_location[\"range\"][\"start\"][\"character\"] == 0  # $localVar (0-indexed)\n\n    @pytest.mark.parametrize(\"language_server\", _php_servers, indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.PHP], indirect=True)\n    def test_find_references_within_file(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        index_php_path = str(repo_path / \"index.php\")\n\n        # In index.php (0-indexed lines):\n        # Line 9: $greeting = greet($userName); // Definition of $greeting\n        # Line 11: echo $greeting;            // Usage of $greeting\n        # Find references for $greeting from its usage in \"echo $greeting;\" (line 11, char 6 for 'g')\n        references = language_server.request_references(index_php_path, 11, 6)\n\n        assert references, f\"Expected non-empty references for $greeting but got {references=}\"\n\n        if language_server.language_server.language == Language.PHP_PHPACTOR:\n            actual_locations = [\n                {\n                    \"uri_suffix\": loc[\"uri\"].split(\"/\")[-1],\n                    \"line\": loc[\"range\"][\"start\"][\"line\"],\n                }\n                for loc in references\n            ]\n\n            # Check that at least one reference points to $greeting usage in index.php\n            matching = [loc for loc in actual_locations if loc[\"uri_suffix\"] == \"index.php\" and loc[\"line\"] == 11]\n            assert matching, f\"Expected reference to $greeting on line 11 of index.php, got {actual_locations}\"\n        else:\n            # Intelephense, when asked for references from usage, seems to only return the usage itself.\n            assert len(references) == 1, \"Expected to find 1 reference for $greeting (the usage itself)\"\n\n            expected_locations = [{\"uri_suffix\": \"index.php\", \"line\": 11, \"character\": 5}]  # Usage: echo $greeting (points to $)\n\n            # Convert actual references to a comparable format and sort\n            actual_locations = sorted(\n                [\n                    {\n                        \"uri_suffix\": loc[\"uri\"].split(\"/\")[-1],\n                        \"line\": loc[\"range\"][\"start\"][\"line\"],\n                        \"character\": loc[\"range\"][\"start\"][\"character\"],\n                    }\n                    for loc in references\n                ],\n                key=lambda x: (x[\"uri_suffix\"], x[\"line\"], x[\"character\"]),\n            )\n\n            expected_locations = sorted(expected_locations, key=lambda x: (x[\"uri_suffix\"], x[\"line\"], x[\"character\"]))\n\n            assert actual_locations == expected_locations\n\n    @pytest.mark.parametrize(\"language_server\", _php_servers, indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.PHP], indirect=True)\n    def test_find_references_across_files(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        helper_php_path = str(repo_path / \"helper.php\")\n        # In index.php (0-indexed lines):\n        # Line 13: helperFunction(); // Usage of helperFunction\n        # Find references for helperFunction from its definition\n        references = language_server.request_references(helper_php_path, 2, len(\"function \"))\n\n        assert references, f\"Expected non-empty references for helperFunction but got {references=}\"\n\n        if language_server.language_server.language == Language.PHP_PHPACTOR:\n            actual_locations_comparable = []\n            for loc in references:\n                actual_locations_comparable.append(\n                    {\n                        \"uri_suffix\": loc[\"uri\"].split(\"/\")[-1],\n                        \"line\": loc[\"range\"][\"start\"][\"line\"],\n                    }\n                )\n\n            # Check that helperFunction usage in index.php line 13 is found\n            matching = [loc for loc in actual_locations_comparable if loc[\"uri_suffix\"] == \"index.php\" and loc[\"line\"] == 13]\n            assert matching, f\"Usage of helperFunction in index.php (line 13) not found in {actual_locations_comparable}\"\n        else:\n            # Intelephense might return 1 (usage) or 2 (usage + definition) references.\n            # Let's check for at least the usage in index.php\n            # Definition is in helper.php, line 2, char 0 (based on previous findings)\n            # Usage is in index.php, line 13, char 0\n            actual_locations_comparable = []\n            for loc in references:\n                actual_locations_comparable.append(\n                    {\n                        \"uri_suffix\": loc[\"uri\"].split(\"/\")[-1],\n                        \"line\": loc[\"range\"][\"start\"][\"line\"],\n                        \"character\": loc[\"range\"][\"start\"][\"character\"],\n                    }\n                )\n\n            usage_in_index_php = {\"uri_suffix\": \"index.php\", \"line\": 13, \"character\": 0}\n            assert usage_in_index_php in actual_locations_comparable, \"Usage of helperFunction in index.php not found\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PHP], indirect=True)\n    def test_find_symbol(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that document symbols are properly retrieved after Intelephense capability fix.\"\"\"\n        from solidlsp.ls_utils import SymbolUtils\n\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"helperFunction\"), \"helperFunction not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"greet\"), \"greet function not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PHP], indirect=True)\n    def test_document_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that document symbols are properly retrieved for a specific file.\"\"\"\n        doc_symbols = language_server.request_document_symbols(\"helper.php\")\n        all_symbols = doc_symbols.get_all_symbols_and_roots()\n        symbol_names = [sym.get(\"name\") for sym in all_symbols[0] if sym.get(\"name\")]\n        assert \"helperFunction\" in symbol_names, f\"helperFunction not found in document symbols. Found: {symbol_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PHP], indirect=True)\n    def test_document_symbols_hierarchical_structure(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Verify Intelephense returns hierarchical DocumentSymbol format.\n\n        When hierarchicalDocumentSymbolSupport is declared in client capabilities,\n        Intelephense returns DocumentSymbol[] where class methods appear as children\n        of their parent class. Without this declaration, it falls back to a flat\n        SymbolInformation[] list where all symbols appear at root level with no\n        parent-child relationships.\n        \"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"sample.php\").get_all_symbols_and_roots()\n\n        root_names = [s.get(\"name\") for s in root_symbols]\n        assert \"Animal\" in root_names, f\"Animal class not found at root level. Roots: {root_names}\"\n        assert \"Dog\" in root_names, f\"Dog class not found at root level. Roots: {root_names}\"\n        assert \"Cat\" in root_names, f\"Cat class not found at root level. Roots: {root_names}\"\n\n        # Verify Dog has method children — this is the key assertion for hierarchical support.\n        # With a flat response, Dog would have no children and all methods would be at root level.\n        dog_symbol = next((s for s in root_symbols if s.get(\"name\") == \"Dog\"), None)\n        assert dog_symbol is not None, \"Dog class not found in root symbols\"\n        dog_children = dog_symbol.get(\"children\", [])\n        dog_child_names = [c.get(\"name\") for c in dog_children]\n        assert (\n            len(dog_child_names) > 0\n        ), f\"Dog class has no children — hierarchicalDocumentSymbolSupport is not working. All root symbols: {root_names}\"\n        expected_methods = {\"greet\", \"fetch\", \"getBreed\", \"describe\"}\n        missing = expected_methods - set(dog_child_names)\n        assert not missing, f\"Dog class missing expected methods: {missing}. Children found: {dog_child_names}\"\n\n        # Methods must NOT appear at root level (that would indicate the flat fallback format).\n        assert \"greet\" not in root_names, f\"greet should be a child of Dog, not at root level. Roots: {root_names}\"\n        assert \"fetch\" not in root_names, f\"fetch should be a child of Dog, not at root level. Roots: {root_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PHP], indirect=True)\n    def test_full_symbol_tree_within_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Verify request_full_symbol_tree scoped to a PHP file returns correct symbols.\n\n        This validates that Intelephense responds correctly when symbols are requested\n        for a single file, including class/method hierarchy in sample.php.\n        \"\"\"\n        from solidlsp.ls_utils import SymbolUtils\n\n        symbols = language_server.request_full_symbol_tree(within_relative_path=\"sample.php\")\n\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Dog\"), \"Dog not found in sample.php symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Animal\"), \"Animal not found in sample.php symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"greet\"), \"greet method not found in sample.php symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"fetch\"), \"fetch method not found in sample.php symbol tree\"\n\n        # Methods must appear as children of Dog, not as root-level symbols\n        dog_root = next((s for s in symbols if s.get(\"name\") == \"Dog\"), None)\n        if dog_root is not None:\n            assert SymbolUtils.symbol_tree_contains_name([dog_root], \"greet\"), \"greet should be nested under Dog in symbol tree\"\n"
  },
  {
    "path": "test/solidlsp/powershell/__init__.py",
    "content": "# PowerShell language server tests\n"
  },
  {
    "path": "test/solidlsp/powershell/test_powershell_basic.py",
    "content": "\"\"\"\nBasic integration tests for the PowerShell language server functionality.\n\nThese tests validate the functionality of the language server APIs\nlike request_document_symbols using the PowerShell test repository.\n\"\"\"\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\n\n@pytest.mark.powershell\nclass TestPowerShellLanguageServerBasics:\n    \"\"\"Test basic functionality of the PowerShell language server.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.POWERSHELL], indirect=True)\n    def test_powershell_language_server_initialization(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that PowerShell language server can be initialized successfully.\"\"\"\n        assert language_server is not None\n        assert language_server.language == Language.POWERSHELL\n\n    @pytest.mark.parametrize(\"language_server\", [Language.POWERSHELL], indirect=True)\n    def test_powershell_request_document_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_document_symbols for PowerShell files.\"\"\"\n        # Test getting symbols from main.ps1\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"main.ps1\").get_all_symbols_and_roots()\n\n        # Extract function symbols (LSP Symbol Kind 12)\n        function_symbols = [symbol for symbol in all_symbols if symbol.get(\"kind\") == 12]\n        function_names = [symbol[\"name\"] for symbol in function_symbols]\n\n        # PSES returns function names in format \"function FuncName ()\" - check for function name substring\n        def has_function(name: str) -> bool:\n            return any(name in fn for fn in function_names)\n\n        # Should detect the main functions from main.ps1\n        assert has_function(\"Greet-User\"), f\"Should find Greet-User function in {function_names}\"\n        assert has_function(\"Process-Items\"), f\"Should find Process-Items function in {function_names}\"\n        assert has_function(\"Main\"), f\"Should find Main function in {function_names}\"\n        assert len(function_symbols) >= 3, f\"Should find at least 3 functions, found {len(function_symbols)}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.POWERSHELL], indirect=True)\n    def test_powershell_utils_functions(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test function detection in utils.ps1 file.\"\"\"\n        # Test with utils.ps1\n        utils_all_symbols, _utils_root_symbols = language_server.request_document_symbols(\"utils.ps1\").get_all_symbols_and_roots()\n\n        utils_function_symbols = [symbol for symbol in utils_all_symbols if symbol.get(\"kind\") == 12]\n        utils_function_names = [symbol[\"name\"] for symbol in utils_function_symbols]\n\n        # PSES returns function names in format \"function FuncName ()\" - check for function name substring\n        def has_function(name: str) -> bool:\n            return any(name in fn for fn in utils_function_names)\n\n        # Should detect functions from utils.ps1\n        expected_utils_functions = [\n            \"Convert-ToUpperCase\",\n            \"Convert-ToLowerCase\",\n            \"Remove-Whitespace\",\n            \"Backup-File\",\n            \"Test-ArrayContains\",\n            \"Write-LogMessage\",\n            \"Test-ValidEmail\",\n            \"Test-IsNumber\",\n        ]\n\n        for func_name in expected_utils_functions:\n            assert has_function(func_name), f\"Should find {func_name} function in utils.ps1, got {utils_function_names}\"\n\n        assert len(utils_function_symbols) >= 8, f\"Should find at least 8 functions in utils.ps1, found {len(utils_function_symbols)}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.POWERSHELL], indirect=True)\n    def test_powershell_function_with_parameters(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that functions with CmdletBinding and parameters are detected correctly.\"\"\"\n        all_symbols, _root_symbols = language_server.request_document_symbols(\"main.ps1\").get_all_symbols_and_roots()\n\n        function_symbols = [symbol for symbol in all_symbols if symbol.get(\"kind\") == 12]\n\n        # Find Greet-User function which has parameters\n        # PSES returns function names in format \"function FuncName ()\"\n        greet_user_symbol = next((sym for sym in function_symbols if \"Greet-User\" in sym[\"name\"]), None)\n        assert greet_user_symbol is not None, f\"Should find Greet-User function in {[s['name'] for s in function_symbols]}\"\n\n        # Find Process-Items function which has array parameter\n        process_items_symbol = next((sym for sym in function_symbols if \"Process-Items\" in sym[\"name\"]), None)\n        assert process_items_symbol is not None, f\"Should find Process-Items function in {[s['name'] for s in function_symbols]}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.POWERSHELL], indirect=True)\n    def test_powershell_all_function_detection(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that all expected functions are detected across both files.\"\"\"\n        # Get symbols from main.ps1\n        main_all_symbols, _main_root_symbols = language_server.request_document_symbols(\"main.ps1\").get_all_symbols_and_roots()\n        main_functions = [symbol for symbol in main_all_symbols if symbol.get(\"kind\") == 12]\n        main_function_names = [func[\"name\"] for func in main_functions]\n\n        # Get symbols from utils.ps1\n        utils_all_symbols, _utils_root_symbols = language_server.request_document_symbols(\"utils.ps1\").get_all_symbols_and_roots()\n        utils_functions = [symbol for symbol in utils_all_symbols if symbol.get(\"kind\") == 12]\n        utils_function_names = [func[\"name\"] for func in utils_functions]\n\n        # PSES returns function names in format \"function FuncName ()\" - check for function name substring\n        def has_main_function(name: str) -> bool:\n            return any(name in fn for fn in main_function_names)\n\n        def has_utils_function(name: str) -> bool:\n            return any(name in fn for fn in utils_function_names)\n\n        # Verify main.ps1 functions\n        expected_main = [\"Greet-User\", \"Process-Items\", \"Main\"]\n        for expected_func in expected_main:\n            assert has_main_function(expected_func), f\"Should detect {expected_func} function in main.ps1, got {main_function_names}\"\n\n        # Verify utils.ps1 functions\n        expected_utils = [\n            \"Convert-ToUpperCase\",\n            \"Convert-ToLowerCase\",\n            \"Remove-Whitespace\",\n            \"Backup-File\",\n            \"Test-ArrayContains\",\n            \"Write-LogMessage\",\n            \"Test-ValidEmail\",\n            \"Test-IsNumber\",\n        ]\n        for expected_func in expected_utils:\n            assert has_utils_function(expected_func), f\"Should detect {expected_func} function in utils.ps1, got {utils_function_names}\"\n\n        # Verify total counts\n        assert len(main_functions) >= 3, f\"Should find at least 3 functions in main.ps1, found {len(main_functions)}\"\n        assert len(utils_functions) >= 8, f\"Should find at least 8 functions in utils.ps1, found {len(utils_functions)}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.POWERSHELL], indirect=True)\n    def test_powershell_find_references_within_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding references to a function within the same file.\"\"\"\n        main_path = \"main.ps1\"\n\n        # Get symbols to find the Greet-User function which is called from Main\n        all_symbols, _root_symbols = language_server.request_document_symbols(main_path).get_all_symbols_and_roots()\n\n        # Find Greet-User function definition\n        function_symbols = [s for s in all_symbols if s.get(\"kind\") == 12]\n        greet_user_symbol = next((s for s in function_symbols if \"Greet-User\" in s[\"name\"]), None)\n        assert greet_user_symbol is not None, f\"Should find Greet-User function in {[s['name'] for s in function_symbols]}\"\n\n        # Find references to Greet-User (should be called from Main function at line 91)\n        sel_start = greet_user_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(main_path, sel_start[\"line\"], sel_start[\"character\"])\n\n        # Should find at least the call site in Main function\n        assert refs is not None and len(refs) >= 1, f\"Should find references to Greet-User, got {refs}\"\n        assert any(\n            \"main.ps1\" in ref.get(\"uri\", ref.get(\"relativePath\", \"\")) for ref in refs\n        ), f\"Should find reference in main.ps1, got {refs}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.POWERSHELL], indirect=True)\n    def test_powershell_find_definition_across_files(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding definition of functions across files (main.ps1 -> utils.ps1).\"\"\"\n        # main.ps1 calls Convert-ToUpperCase from utils.ps1 at line 99 (0-indexed: 98)\n        # The call is: $upperName = Convert-ToUpperCase -InputString $User\n        # We'll request definition from the call site in main.ps1\n        main_path = \"main.ps1\"\n\n        # Find definition of Convert-ToUpperCase from its usage in main.ps1\n        # Line 99 (1-indexed) = line 98 (0-indexed), character position ~16 for \"Convert-ToUpperCase\"\n        definition_locations = language_server.request_definition(main_path, 98, 18)\n\n        # Should find the definition in utils.ps1\n        assert (\n            definition_locations is not None and len(definition_locations) >= 1\n        ), f\"Should find definition of Convert-ToUpperCase, got {definition_locations}\"\n        assert any(\n            \"utils.ps1\" in loc.get(\"uri\", \"\") for loc in definition_locations\n        ), f\"Should find definition in utils.ps1, got {definition_locations}\"\n"
  },
  {
    "path": "test/solidlsp/python/test_python_basic.py",
    "content": "\"\"\"\nBasic integration tests for the language server functionality.\n\nThese tests validate the functionality of the language server APIs\nlike request_references using the test repository.\n\"\"\"\n\nimport os\n\nimport pytest\n\nfrom serena.project import Project\nfrom serena.util.text_utils import LineType\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\n\n@pytest.mark.python\nclass TestPythonLanguageServerBasics:\n    \"\"\"Test basic functionality of the language server.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_references_user_class(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_references on the User class.\"\"\"\n        # Get references to the User class in models.py\n        file_path = os.path.join(\"test_repo\", \"models.py\")\n        # Line 31 contains the User class definition\n        # Use selectionRange only\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        user_symbol = next((s for s in symbols[0] if s.get(\"name\") == \"User\"), None)\n        if not user_symbol or \"selectionRange\" not in user_symbol:\n            raise AssertionError(\"User symbol or its selectionRange not found\")\n        sel_start = user_symbol[\"selectionRange\"][\"start\"]\n        references = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        assert len(references) > 1, \"User class should be referenced in multiple files (using selectionRange if present)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_references_item_class(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_references on the Item class.\"\"\"\n        # Get references to the Item class in models.py\n        file_path = os.path.join(\"test_repo\", \"models.py\")\n        # Line 56 contains the Item class definition\n        # Use selectionRange only\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        item_symbol = next((s for s in symbols[0] if s.get(\"name\") == \"Item\"), None)\n        if not item_symbol or \"selectionRange\" not in item_symbol:\n            raise AssertionError(\"Item symbol or its selectionRange not found\")\n        sel_start = item_symbol[\"selectionRange\"][\"start\"]\n        references = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        services_references = [ref for ref in references if \"services.py\" in ref[\"uri\"]]\n        assert len(services_references) > 0, \"At least one reference should be in services.py (using selectionRange if present)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_references_function_parameter(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_references on a function parameter.\"\"\"\n        # Get references to the id parameter in get_user method\n        file_path = os.path.join(\"test_repo\", \"services.py\")\n        # Line 24 contains the get_user method with id parameter\n        # Use selectionRange only\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        get_user_symbol = next((s for s in symbols[0] if s.get(\"name\") == \"get_user\"), None)\n        if not get_user_symbol or \"selectionRange\" not in get_user_symbol:\n            raise AssertionError(\"get_user symbol or its selectionRange not found\")\n        sel_start = get_user_symbol[\"selectionRange\"][\"start\"]\n        references = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        assert len(references) > 0, \"id parameter should be referenced within the method (using selectionRange if present)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_references_create_user_method(self, language_server: SolidLanguageServer) -> None:\n        # Get references to the create_user method in UserService\n        file_path = os.path.join(\"test_repo\", \"services.py\")\n        # Line 15 contains the create_user method definition\n        # Use selectionRange only\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        create_user_symbol = next((s for s in symbols[0] if s.get(\"name\") == \"create_user\"), None)\n        if not create_user_symbol or \"selectionRange\" not in create_user_symbol:\n            raise AssertionError(\"create_user symbol or its selectionRange not found\")\n        sel_start = create_user_symbol[\"selectionRange\"][\"start\"]\n        references = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        assert len(references) > 1, \"Should get valid references for create_user (using selectionRange if present)\"\n\n\nclass TestProjectBasics:\n    @pytest.mark.parametrize(\"project\", [Language.PYTHON], indirect=True)\n    def test_retrieve_content_around_line(self, project: Project) -> None:\n        \"\"\"Test retrieve_content_around_line functionality with various scenarios.\"\"\"\n        file_path = os.path.join(\"test_repo\", \"models.py\")\n\n        # Scenario 1: Just a single line (User class definition)\n        line_31 = project.retrieve_content_around_line(file_path, 31)\n        assert len(line_31.lines) == 1\n        assert \"class User(BaseModel):\" in line_31.lines[0].line_content\n        assert line_31.lines[0].line_number == 31\n        assert line_31.lines[0].match_type == LineType.MATCH\n\n        # Scenario 2: Context above and below\n        with_context_around_user = project.retrieve_content_around_line(file_path, 31, 2, 2)\n        assert len(with_context_around_user.lines) == 5\n        # Check line content\n        assert \"class User(BaseModel):\" in with_context_around_user.matched_lines[0].line_content\n        assert with_context_around_user.num_matched_lines == 1\n        assert \"    User model representing a system user.\" in with_context_around_user.lines[4].line_content\n        # Check line numbers\n        assert with_context_around_user.lines[0].line_number == 29\n        assert with_context_around_user.lines[1].line_number == 30\n        assert with_context_around_user.lines[2].line_number == 31\n        assert with_context_around_user.lines[3].line_number == 32\n        assert with_context_around_user.lines[4].line_number == 33\n        # Check match types\n        assert with_context_around_user.lines[0].match_type == LineType.BEFORE_MATCH\n        assert with_context_around_user.lines[1].match_type == LineType.BEFORE_MATCH\n        assert with_context_around_user.lines[2].match_type == LineType.MATCH\n        assert with_context_around_user.lines[3].match_type == LineType.AFTER_MATCH\n        assert with_context_around_user.lines[4].match_type == LineType.AFTER_MATCH\n\n        # Scenario 3a: Only context above\n        with_context_above = project.retrieve_content_around_line(file_path, 31, 3, 0)\n        assert len(with_context_above.lines) == 4\n        assert \"return cls(id=id, name=name)\" in with_context_above.lines[0].line_content\n        assert \"class User(BaseModel):\" in with_context_above.matched_lines[0].line_content\n        assert with_context_above.num_matched_lines == 1\n        # Check line numbers\n        assert with_context_above.lines[0].line_number == 28\n        assert with_context_above.lines[1].line_number == 29\n        assert with_context_above.lines[2].line_number == 30\n        assert with_context_above.lines[3].line_number == 31\n        # Check match types\n        assert with_context_above.lines[0].match_type == LineType.BEFORE_MATCH\n        assert with_context_above.lines[1].match_type == LineType.BEFORE_MATCH\n        assert with_context_above.lines[2].match_type == LineType.BEFORE_MATCH\n        assert with_context_above.lines[3].match_type == LineType.MATCH\n\n        # Scenario 3b: Only context below\n        with_context_below = project.retrieve_content_around_line(file_path, 31, 0, 3)\n        assert len(with_context_below.lines) == 4\n        assert \"class User(BaseModel):\" in with_context_below.matched_lines[0].line_content\n        assert with_context_below.num_matched_lines == 1\n        assert with_context_below.lines[0].line_number == 31\n        assert with_context_below.lines[1].line_number == 32\n        assert with_context_below.lines[2].line_number == 33\n        assert with_context_below.lines[3].line_number == 34\n        # Check match types\n        assert with_context_below.lines[0].match_type == LineType.MATCH\n        assert with_context_below.lines[1].match_type == LineType.AFTER_MATCH\n        assert with_context_below.lines[2].match_type == LineType.AFTER_MATCH\n        assert with_context_below.lines[3].match_type == LineType.AFTER_MATCH\n\n        # Scenario 4a: Edge case - context above but line is at 0\n        first_line_with_context_around = project.retrieve_content_around_line(file_path, 0, 2, 1)\n        assert len(first_line_with_context_around.lines) <= 4  # Should have at most 4 lines (line 0 + 1 below + up to 2 above)\n        assert first_line_with_context_around.lines[0].line_number <= 2  # First line should be at most line 2\n        # Check match type for the target line\n        for line in first_line_with_context_around.lines:\n            if line.line_number == 0:\n                assert line.match_type == LineType.MATCH\n            elif line.line_number < 0:\n                assert line.match_type == LineType.BEFORE_MATCH\n            else:\n                assert line.match_type == LineType.AFTER_MATCH\n\n        # Scenario 4b: Edge case - context above but line is at 1\n        second_line_with_context_above = project.retrieve_content_around_line(file_path, 1, 3, 1)\n        assert len(second_line_with_context_above.lines) <= 5  # Should have at most 5 lines (line 1 + 1 below + up to 3 above)\n        assert second_line_with_context_above.lines[0].line_number <= 1  # First line should be at most line 1\n        # Check match type for the target line\n        for line in second_line_with_context_above.lines:\n            if line.line_number == 1:\n                assert line.match_type == LineType.MATCH\n            elif line.line_number < 1:\n                assert line.match_type == LineType.BEFORE_MATCH\n            else:\n                assert line.match_type == LineType.AFTER_MATCH\n\n        # Scenario 4c: Edge case - context below but line is at the end of file\n        # First get the total number of lines in the file\n        all_content = project.read_file(file_path)\n        total_lines = len(all_content.split(\"\\n\"))\n\n        last_line_with_context_around = project.retrieve_content_around_line(file_path, total_lines - 1, 1, 3)\n        assert len(last_line_with_context_around.lines) <= 5  # Should have at most 5 lines (last line + 1 above + up to 3 below)\n        assert last_line_with_context_around.lines[-1].line_number >= total_lines - 4  # Last line should be at least total_lines - 4\n        # Check match type for the target line\n        for line in last_line_with_context_around.lines:\n            if line.line_number == total_lines - 1:\n                assert line.match_type == LineType.MATCH\n            elif line.line_number < total_lines - 1:\n                assert line.match_type == LineType.BEFORE_MATCH\n            else:\n                assert line.match_type == LineType.AFTER_MATCH\n\n    @pytest.mark.parametrize(\"project\", [Language.PYTHON], indirect=True)\n    def test_search_files_for_pattern(self, project: Project) -> None:\n        \"\"\"Test search_files_for_pattern with various patterns and glob filters.\"\"\"\n        # Test 1: Search for class definitions across all files\n        class_pattern = r\"class\\s+\\w+\\s*(?:\\([^{]*\\)|:)\"\n        matches = project.search_source_files_for_pattern(class_pattern)\n        assert len(matches) > 0\n        # Should find multiple classes like User, Item, BaseModel, etc.\n        assert len(matches) >= 5\n\n        # Test 2: Search for specific class with include glob\n        user_class_pattern = r\"class\\s+User\\s*(?:\\([^{]*\\)|:)\"\n        matches = project.search_source_files_for_pattern(user_class_pattern, paths_include_glob=\"**/models.py\")\n        assert len(matches) == 1  # Should only find User class in models.py\n        assert matches[0].source_file_path is not None\n        assert \"models.py\" in matches[0].source_file_path\n\n        # Test 3: Search for method definitions with exclude glob\n        method_pattern = r\"def\\s+\\w+\\s*\\([^)]*\\):\"\n        matches = project.search_source_files_for_pattern(method_pattern, paths_exclude_glob=\"**/models.py\")\n        assert len(matches) > 0\n        # Should find methods in services.py but not in models.py\n        assert all(match.source_file_path is not None and \"models.py\" not in match.source_file_path for match in matches)\n\n        # Test 4: Search for specific method with both include and exclude globs\n        create_user_pattern = r\"def\\s+create_user\\s*\\([^)]*\\)(?:\\s*->[^:]+)?:\"\n        matches = project.search_source_files_for_pattern(\n            create_user_pattern, paths_include_glob=\"**/*.py\", paths_exclude_glob=\"**/models.py\"\n        )\n        assert len(matches) == 1  # Should only find create_user in services.py\n        assert matches[0].source_file_path is not None\n        assert \"services.py\" in matches[0].source_file_path\n\n        # Test 5: Search for a pattern that should appear in multiple files\n        init_pattern = r\"def\\s+__init__\\s*\\([^)]*\\):\"\n        matches = project.search_source_files_for_pattern(init_pattern)\n        assert len(matches) > 1  # Should find __init__ in multiple classes\n        # Should find __init__ in both models.py and services.py\n        assert any(match.source_file_path is not None and \"models.py\" in match.source_file_path for match in matches)\n        assert any(match.source_file_path is not None and \"services.py\" in match.source_file_path for match in matches)\n\n        # Test 6: Search with a pattern that should have no matches\n        no_match_pattern = r\"def\\s+this_method_does_not_exist\\s*\\([^)]*\\):\"\n        matches = project.search_source_files_for_pattern(no_match_pattern)\n        assert len(matches) == 0\n"
  },
  {
    "path": "test/solidlsp/python/test_retrieval_with_ignored_dirs.py",
    "content": "from collections.abc import Generator\nfrom pathlib import Path\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom test.conftest import start_ls_context\n\n# This mark will be applied to all tests in this module\npytestmark = pytest.mark.python\n\n\n@pytest.fixture(scope=\"module\")\ndef ls_with_ignored_dirs() -> Generator[SolidLanguageServer, None, None]:\n    \"\"\"Fixture to set up an LS for the python test repo with the 'scripts' directory ignored.\"\"\"\n    ignored_paths = [\"scripts\", \"custom_test\"]\n    with start_ls_context(language=Language.PYTHON, ignored_paths=ignored_paths) as ls:\n        yield ls\n\n\n@pytest.mark.parametrize(\"ls_with_ignored_dirs\", [Language.PYTHON], indirect=True)\ndef test_symbol_tree_ignores_dir(ls_with_ignored_dirs: SolidLanguageServer):\n    \"\"\"Tests that request_full_symbol_tree ignores the configured directory.\"\"\"\n    root = ls_with_ignored_dirs.request_full_symbol_tree()[0]\n    root_children = root[\"children\"]\n    children_names = {child[\"name\"] for child in root_children}\n    assert children_names == {\"test_repo\", \"examples\"}\n\n\n@pytest.mark.parametrize(\"ls_with_ignored_dirs\", [Language.PYTHON], indirect=True)\ndef test_find_references_ignores_dir(ls_with_ignored_dirs: SolidLanguageServer):\n    \"\"\"Tests that find_references ignores the configured directory.\"\"\"\n    # Location of Item, which is referenced in scripts\n    definition_file = \"test_repo/models.py\"\n    definition_line = 56\n    definition_col = 6\n\n    references = ls_with_ignored_dirs.request_references(definition_file, definition_line, definition_col)\n\n    # assert that scripts does not appear in the references\n    assert not any(\"scripts\" in ref[\"relativePath\"] for ref in references)\n\n\n@pytest.mark.parametrize(\"repo_path\", [Language.PYTHON], indirect=True)\ndef test_refs_and_symbols_with_glob_patterns(repo_path: Path) -> None:\n    \"\"\"Tests that refs and symbols with glob patterns are ignored.\"\"\"\n    ignored_paths = [\"*ipts\", \"custom_t*\"]\n    with start_ls_context(language=Language.PYTHON, repo_path=str(repo_path), ignored_paths=ignored_paths) as ls:\n        # same as in the above tests\n        root = ls.request_full_symbol_tree()[0]\n        root_children = root[\"children\"]\n        children_names = {child[\"name\"] for child in root_children}\n        assert children_names == {\"test_repo\", \"examples\"}\n\n        # test that the refs and symbols with glob patterns are ignored\n        definition_file = \"test_repo/models.py\"\n        definition_line = 56\n        definition_col = 6\n\n        references = ls.request_references(definition_file, definition_line, definition_col)\n        assert not any(\"scripts\" in ref[\"relativePath\"] for ref in references)\n"
  },
  {
    "path": "test/solidlsp/python/test_symbol_retrieval.py",
    "content": "\"\"\"\nTests for the language server symbol-related functionality.\n\nThese tests focus on the following methods:\n- request_containing_symbol\n- request_referencing_symbols\n\"\"\"\n\nimport os\n\nimport pytest\n\nfrom serena.symbol import LanguageServerSymbol\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_types import SymbolKind\n\npytestmark = pytest.mark.python\n\n\nclass TestLanguageServerSymbols:\n    \"\"\"Test the language server's symbol-related functionality.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_containing_symbol_function(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol for a function.\"\"\"\n        # Test for a position inside the create_user method\n        file_path = os.path.join(\"test_repo\", \"services.py\")\n        # Line 17 is inside the create_user method body\n        containing_symbol = language_server.request_containing_symbol(file_path, 17, 20, include_body=True)\n\n        # Verify that we found the containing symbol\n        assert containing_symbol is not None\n        assert containing_symbol[\"name\"] == \"create_user\"\n        assert containing_symbol[\"kind\"] == SymbolKind.Method\n        if \"body\" in containing_symbol:\n            assert containing_symbol[\"body\"].get_text().strip().startswith(\"def create_user(self\")\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_references_to_variables(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_referencing_symbols for a variable.\"\"\"\n        file_path = os.path.join(\"test_repo\", \"variables.py\")\n        # Line 75 contains the field status that is later modified\n        ref_symbols = [ref.symbol for ref in language_server.request_referencing_symbols(file_path, 74, 4)]\n\n        assert len(ref_symbols) > 0\n        ref_lines = [ref[\"location\"][\"range\"][\"start\"][\"line\"] for ref in ref_symbols if \"location\" in ref and \"range\" in ref[\"location\"]]\n        ref_names = [ref[\"name\"] for ref in ref_symbols]\n        assert 87 in ref_lines\n        assert 95 in ref_lines\n        assert \"dataclass_instance\" in ref_names\n        assert \"second_dataclass\" in ref_names\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_containing_symbol_class(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol for a class.\"\"\"\n        # Test for a position inside the UserService class but outside any method\n        file_path = os.path.join(\"test_repo\", \"services.py\")\n        # Line 9 is the class definition line for UserService\n        containing_symbol = language_server.request_containing_symbol(file_path, 9, 7)\n\n        # Verify that we found the containing symbol\n        assert containing_symbol is not None\n        assert containing_symbol[\"name\"] == \"UserService\"\n        assert containing_symbol[\"kind\"] == SymbolKind.Class\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_containing_symbol_nested(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol with nested scopes.\"\"\"\n        # Test for a position inside a method which is inside a class\n        file_path = os.path.join(\"test_repo\", \"services.py\")\n        # Line 18 is inside the create_user method inside UserService class\n        containing_symbol = language_server.request_containing_symbol(file_path, 18, 25)\n\n        # Verify that we found the innermost containing symbol (the method)\n        assert containing_symbol is not None\n        assert containing_symbol[\"name\"] == \"create_user\"\n        assert containing_symbol[\"kind\"] == SymbolKind.Method\n\n        # Get the parent containing symbol\n        if \"location\" in containing_symbol and \"range\" in containing_symbol[\"location\"]:\n            parent_symbol = language_server.request_containing_symbol(\n                file_path,\n                containing_symbol[\"location\"][\"range\"][\"start\"][\"line\"],\n                containing_symbol[\"location\"][\"range\"][\"start\"][\"character\"] - 1,\n            )\n\n            # Verify that the parent is the class\n            assert parent_symbol is not None\n            assert parent_symbol[\"name\"] == \"UserService\"\n            assert parent_symbol[\"kind\"] == SymbolKind.Class\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_containing_symbol_none(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol for a position with no containing symbol.\"\"\"\n        # Test for a position outside any function/class (e.g., in imports)\n        file_path = os.path.join(\"test_repo\", \"services.py\")\n        # Line 1 is in imports, not inside any function or class\n        containing_symbol = language_server.request_containing_symbol(file_path, 1, 10)\n\n        # Should return None or an empty dictionary\n        assert containing_symbol is None or containing_symbol == {}\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_referencing_symbols_function(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_referencing_symbols for a function.\"\"\"\n        # Test referencing symbols for create_user function\n        file_path = os.path.join(\"test_repo\", \"services.py\")\n        # Line 15 contains the create_user function definition\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        create_user_symbol = next((s for s in symbols[0] if s.get(\"name\") == \"create_user\"), None)\n        if not create_user_symbol or \"selectionRange\" not in create_user_symbol:\n            raise AssertionError(\"create_user symbol or its selectionRange not found\")\n        sel_start = create_user_symbol[\"selectionRange\"][\"start\"]\n        ref_symbols = [\n            ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        ]\n        assert len(ref_symbols) > 0, \"No referencing symbols found for create_user (selectionRange)\"\n\n        # Verify the structure of referencing symbols\n        for symbol in ref_symbols:\n            assert \"name\" in symbol\n            assert \"kind\" in symbol\n            if \"location\" in symbol and \"range\" in symbol[\"location\"]:\n                assert \"start\" in symbol[\"location\"][\"range\"]\n                assert \"end\" in symbol[\"location\"][\"range\"]\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_referencing_symbols_class(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_referencing_symbols for a class.\"\"\"\n        # Test referencing symbols for User class\n        file_path = os.path.join(\"test_repo\", \"models.py\")\n        # Line 31 contains the User class definition\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        user_symbol = next((s for s in symbols[0] if s.get(\"name\") == \"User\"), None)\n        if not user_symbol or \"selectionRange\" not in user_symbol:\n            raise AssertionError(\"User symbol or its selectionRange not found\")\n        sel_start = user_symbol[\"selectionRange\"][\"start\"]\n        ref_symbols = [\n            ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        ]\n        services_references = [\n            symbol\n            for symbol in ref_symbols\n            if \"location\" in symbol and \"uri\" in symbol[\"location\"] and \"services.py\" in symbol[\"location\"][\"uri\"]\n        ]\n        assert len(services_references) > 0, \"No referencing symbols from services.py for User (selectionRange)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_referencing_symbols_parameter(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_referencing_symbols for a function parameter.\"\"\"\n        # Test referencing symbols for id parameter in get_user\n        file_path = os.path.join(\"test_repo\", \"services.py\")\n        # Line 24 contains the get_user method with id parameter\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        get_user_symbol = next((s for s in symbols[0] if s.get(\"name\") == \"get_user\"), None)\n        if not get_user_symbol or \"selectionRange\" not in get_user_symbol:\n            raise AssertionError(\"get_user symbol or its selectionRange not found\")\n        sel_start = get_user_symbol[\"selectionRange\"][\"start\"]\n        ref_symbols = [\n            ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        ]\n        method_refs = [\n            symbol\n            for symbol in ref_symbols\n            if \"location\" in symbol and \"range\" in symbol[\"location\"] and symbol[\"location\"][\"range\"][\"start\"][\"line\"] > sel_start[\"line\"]\n        ]\n        assert len(method_refs) > 0, \"No referencing symbols within method body for get_user (selectionRange)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_referencing_symbols_none(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_referencing_symbols for a position with no symbol.\"\"\"\n        # For positions with no symbol, the method might throw an error or return None/empty list\n        # We'll modify our test to handle this by using a try-except block\n\n        file_path = os.path.join(\"test_repo\", \"services.py\")\n        # Line 3 is a blank line or comment\n        try:\n            ref_symbols = [ref.symbol for ref in language_server.request_referencing_symbols(file_path, 3, 0)]\n            # If we get here, make sure we got an empty result\n            assert ref_symbols == [] or ref_symbols is None\n        except Exception:\n            # The method might raise an exception for invalid positions\n            # which is acceptable behavior\n            pass\n\n    # Tests for request_defining_symbol\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_defining_symbol_variable(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a variable usage.\"\"\"\n        # Test finding the definition of a symbol in the create_user method\n        file_path = os.path.join(\"test_repo\", \"services.py\")\n        # Line 21 contains self.users[id] = user\n        defining_symbol = language_server.request_defining_symbol(file_path, 21, 10)\n\n        # Verify that we found the defining symbol\n        # The defining symbol method returns a dictionary with information about the defining symbol\n        assert defining_symbol is not None\n        assert defining_symbol.get(\"name\") == \"create_user\"\n\n        # Verify the location and kind of the symbol\n        # SymbolKind.Method = 6 for a method\n        assert defining_symbol.get(\"kind\") == SymbolKind.Method.value\n        if \"location\" in defining_symbol and \"uri\" in defining_symbol[\"location\"]:\n            assert \"services.py\" in defining_symbol[\"location\"][\"uri\"]\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_defining_symbol_imported_class(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for an imported class.\"\"\"\n        # Test finding the definition of the 'User' class used in the UserService.create_user method\n        file_path = os.path.join(\"test_repo\", \"services.py\")\n        # Line 20 references 'User' which was imported from models\n        defining_symbol = language_server.request_defining_symbol(file_path, 20, 15)\n\n        # Verify that we found the defining symbol - this should be the User class from models\n        assert defining_symbol is not None\n        assert defining_symbol.get(\"name\") == \"User\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_defining_symbol_method_call(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a method call.\"\"\"\n        # Create an example file path for a file that calls UserService.create_user\n        examples_file_path = os.path.join(\"examples\", \"user_management.py\")\n\n        # Find the line number where create_user is called\n        # This could vary, so we'll use a relative position that makes sense\n        defining_symbol = language_server.request_defining_symbol(examples_file_path, 10, 30)\n\n        # Verify that we found the defining symbol - should be the create_user method\n        # Because this might fail if the structure isn't exactly as expected, we'll use try-except\n        try:\n            assert defining_symbol is not None\n            assert defining_symbol.get(\"name\") == \"create_user\"\n            # The defining symbol should be in the services.py file\n            if \"location\" in defining_symbol and \"uri\" in defining_symbol[\"location\"]:\n                assert \"services.py\" in defining_symbol[\"location\"][\"uri\"]\n        except AssertionError:\n            # If the file structure doesn't match what we expect, we can't guarantee this test\n            # will pass, so we'll consider it a warning rather than a failure\n            import warnings\n\n            warnings.warn(\"Could not verify method call definition - file structure may differ from expected\")\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_defining_symbol_none(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a position with no symbol.\"\"\"\n        # Test for a position with no symbol (e.g., whitespace or comment)\n        file_path = os.path.join(\"test_repo\", \"services.py\")\n        # Line 3 is a blank line\n        defining_symbol = language_server.request_defining_symbol(file_path, 3, 0)\n\n        # Should return None for positions with no symbol\n        assert defining_symbol is None\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_containing_symbol_variable(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol where the symbol is a variable.\"\"\"\n        # Test for a position inside a variable definition\n        file_path = os.path.join(\"test_repo\", \"services.py\")\n        # Line 74 defines the 'user' variable\n        containing_symbol = language_server.request_containing_symbol(file_path, 73, 1)\n\n        # Verify that we found the containing symbol\n        assert containing_symbol is not None\n        assert containing_symbol[\"name\"] == \"user_var_str\"\n        assert containing_symbol[\"kind\"] == SymbolKind.Variable\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_defining_symbol_nested_function(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a nested function or closure.\"\"\"\n        # Use the existing nested.py file which contains nested classes and methods\n        file_path = os.path.join(\"test_repo\", \"nested.py\")\n\n        # Test 1: Find definition of nested method - line with 'b = OuterClass().NestedClass().find_me()'\n        defining_symbol = language_server.request_defining_symbol(file_path, 15, 35)  # Position of find_me() call\n\n        # This should resolve to the find_me method in the NestedClass\n        assert defining_symbol is not None\n        assert defining_symbol.get(\"name\") == \"find_me\"\n        assert defining_symbol.get(\"kind\") == SymbolKind.Method.value\n\n        # Test 2: Find definition of the nested class\n        defining_symbol = language_server.request_defining_symbol(file_path, 15, 18)  # Position of NestedClass\n\n        # This should resolve to the NestedClass\n        assert defining_symbol is not None\n        assert defining_symbol.get(\"name\") == \"NestedClass\"\n        assert defining_symbol.get(\"kind\") == SymbolKind.Class.value\n\n        # Test 3: Find definition of a method-local function\n        defining_symbol = language_server.request_defining_symbol(file_path, 9, 15)  # Position inside func_within_func\n\n        # This is challenging for many language servers and may fail\n        try:\n            assert defining_symbol is not None\n            assert defining_symbol.get(\"name\") == \"func_within_func\"\n        except (AssertionError, TypeError, KeyError):\n            # This is expected to potentially fail in many implementations\n            import warnings\n\n            warnings.warn(\"Could not resolve nested class method definition - implementation limitation\")\n\n        # Test 2: Find definition of the nested class\n        defining_symbol = language_server.request_defining_symbol(file_path, 15, 18)  # Position of NestedClass\n\n        # This should resolve to the NestedClass\n        assert defining_symbol is not None\n        assert defining_symbol.get(\"name\") == \"NestedClass\"\n        assert defining_symbol.get(\"kind\") == SymbolKind.Class.value\n\n        # Test 3: Find definition of a method-local function\n        defining_symbol = language_server.request_defining_symbol(file_path, 9, 15)  # Position inside func_within_func\n\n        # This is challenging for many language servers and may fail\n        assert defining_symbol is not None\n        assert defining_symbol.get(\"name\") == \"func_within_func\"\n        assert defining_symbol.get(\"kind\") == SymbolKind.Function.value\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_symbol_methods_integration(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test the integration between different symbol-related methods.\"\"\"\n        # This test demonstrates using the various symbol methods together\n        # by finding a symbol and then checking its definition\n\n        file_path = os.path.join(\"test_repo\", \"services.py\")\n\n        # First approach: Use a method from the UserService class\n        # Step 1: Find a method we know exists\n        containing_symbol = language_server.request_containing_symbol(file_path, 15, 8)  # create_user method\n        assert containing_symbol is not None\n        assert containing_symbol[\"name\"] == \"create_user\"\n\n        # Step 2: Get the defining symbol for the same position\n        # This should be the same method\n        defining_symbol = language_server.request_defining_symbol(file_path, 15, 8)\n        assert defining_symbol is not None\n        assert defining_symbol[\"name\"] == \"create_user\"\n\n        # Step 3: Verify that they refer to the same symbol\n        assert defining_symbol[\"kind\"] == containing_symbol[\"kind\"]\n        if \"location\" in defining_symbol and \"location\" in containing_symbol:\n            assert defining_symbol[\"location\"][\"uri\"] == containing_symbol[\"location\"][\"uri\"]\n\n        # The integration test is successful if we've gotten this far,\n        # as it demonstrates the integration between request_containing_symbol and request_defining_symbol\n\n        # Try to get the container information for our method, but be flexible\n        # since implementations may vary\n        container_name = defining_symbol.get(\"containerName\", None)\n        if container_name and \"UserService\" in container_name:\n            # If containerName contains UserService, that's a valid implementation\n            pass\n        else:\n            # Try an alternative approach - looking for the containing class\n            try:\n                # Look for the class symbol in the file\n                for line in range(5, 12):  # Approximate range where UserService class should be defined\n                    symbol = language_server.request_containing_symbol(file_path, line, 5)  # column 5 should be within class definition\n                    if symbol and symbol.get(\"name\") == \"UserService\" and symbol.get(\"kind\") == SymbolKind.Class.value:\n                        # Found the class - this is also a valid implementation\n                        break\n            except Exception:\n                # Just log a warning - this is an alternative verification and not essential\n                import warnings\n\n                warnings.warn(\"Could not verify container hierarchy - implementation detail\")\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_symbol_tree_structure(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that the symbol tree structure is correctly built.\"\"\"\n        # Get all symbols in the test file\n        repo_structure = language_server.request_full_symbol_tree()\n        assert len(repo_structure) == 1\n        # Assert that the root symbol is the test_repo directory\n        assert repo_structure[0][\"name\"] == \"test_repo\"\n        assert repo_structure[0][\"kind\"] == SymbolKind.Package\n        assert \"children\" in repo_structure[0]\n        # Assert that the children are the top-level packages\n        child_names = {child[\"name\"] for child in repo_structure[0][\"children\"]}\n        child_kinds = {child[\"kind\"] for child in repo_structure[0][\"children\"]}\n        assert child_names == {\"test_repo\", \"custom_test\", \"examples\", \"scripts\"}\n        assert child_kinds == {SymbolKind.Package}\n        examples_package = next(child for child in repo_structure[0][\"children\"] if child[\"name\"] == \"examples\")\n        # assert that children are __init__ and user_management\n        assert {child[\"name\"] for child in examples_package[\"children\"]} == {\"__init__\", \"user_management\"}\n        assert {child[\"kind\"] for child in examples_package[\"children\"]} == {SymbolKind.File}\n\n        # assert that tree of user_management node is same as retrieved directly\n        user_management_node = next(child for child in examples_package[\"children\"] if child[\"name\"] == \"user_management\")\n        if \"location\" in user_management_node and \"relativePath\" in user_management_node[\"location\"]:\n            user_management_rel_path = user_management_node[\"location\"][\"relativePath\"]\n            assert user_management_rel_path == os.path.join(\"examples\", \"user_management.py\")\n            _, user_management_roots = language_server.request_document_symbols(\n                os.path.join(\"examples\", \"user_management.py\")\n            ).get_all_symbols_and_roots()\n            assert user_management_roots == user_management_node[\"children\"]\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_symbol_tree_structure_subdir(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that the symbol tree structure is correctly built.\"\"\"\n        # Get all symbols in the test file\n        examples_package_roots = language_server.request_full_symbol_tree(within_relative_path=\"examples\")\n        assert len(examples_package_roots) == 1\n        examples_package = examples_package_roots[0]\n        assert examples_package[\"name\"] == \"examples\"\n        assert examples_package[\"kind\"] == SymbolKind.Package\n        # assert that children are __init__ and user_management\n        assert {child[\"name\"] for child in examples_package[\"children\"]} == {\"__init__\", \"user_management\"}\n        assert {child[\"kind\"] for child in examples_package[\"children\"]} == {SymbolKind.File}\n\n        # assert that tree of user_management node is same as retrieved directly\n        user_management_node = next(child for child in examples_package[\"children\"] if child[\"name\"] == \"user_management\")\n        if \"location\" in user_management_node and \"relativePath\" in user_management_node[\"location\"]:\n            user_management_rel_path = user_management_node[\"location\"][\"relativePath\"]\n            assert user_management_rel_path == os.path.join(\"examples\", \"user_management.py\")\n            _, user_management_roots = language_server.request_document_symbols(\n                os.path.join(\"examples\", \"user_management.py\")\n            ).get_all_symbols_and_roots()\n            assert user_management_roots == user_management_node[\"children\"]\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_dir_overview(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that request_dir_overview returns correct symbol information for files in a directory.\"\"\"\n        # Get overview of the examples directory\n        overview = language_server.request_dir_overview(\"test_repo\")\n\n        # Verify that we have entries for both files\n        assert os.path.join(\"test_repo\", \"nested.py\") in overview\n\n        # Get the symbols for user_management.py\n        services_symbols = overview[os.path.join(\"test_repo\", \"services.py\")]\n        assert len(services_symbols) > 0\n\n        # Check for specific symbols from services.py\n        expected_symbols = {\n            \"UserService\",\n            \"ItemService\",\n            \"create_service_container\",\n            \"user_var_str\",\n            \"user_service\",\n        }\n        retrieved_symbols = {symbol[\"name\"] for symbol in services_symbols if \"name\" in symbol}\n        assert expected_symbols.issubset(retrieved_symbols)\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_request_document_overview(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that request_document_overview returns correct symbol information for a file.\"\"\"\n        # Get overview of the user_management.py file\n        overview = language_server.request_document_overview(os.path.join(\"examples\", \"user_management.py\"))\n\n        # Verify that we have entries for both files\n        symbol_names = {LanguageServerSymbol(s_info).name for s_info in overview}\n        assert {\"UserStats\", \"UserManager\", \"process_user_data\", \"main\"}.issubset(symbol_names)\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_containing_symbol_of_var_is_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that the containing symbol of a variable is the file itself.\"\"\"\n        # Get the containing symbol of a variable in a file\n        file_path = os.path.join(\"test_repo\", \"services.py\")\n        # import of typing\n        references_to_typing = [\n            ref.symbol\n            for ref in language_server.request_referencing_symbols(file_path, 4, 6, include_imports=False, include_file_symbols=True)\n        ]\n        assert {ref[\"kind\"] for ref in references_to_typing} == {SymbolKind.File}\n\n        # now include bodies\n        references_to_typing = [\n            ref.symbol\n            for ref in language_server.request_referencing_symbols(\n                file_path, 4, 6, include_imports=False, include_file_symbols=True, include_body=True\n            )\n        ]\n        assert {ref[\"kind\"] for ref in references_to_typing} == {SymbolKind.File}\n        assert references_to_typing[0][\"body\"]\n"
  },
  {
    "path": "test/solidlsp/r/__init__.py",
    "content": "# Empty init file for R tests\n"
  },
  {
    "path": "test/solidlsp/r/test_r_basic.py",
    "content": "\"\"\"\nBasic tests for R Language Server integration\n\"\"\"\n\nimport os\nfrom pathlib import Path\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\n\n@pytest.mark.r\nclass TestRLanguageServer:\n    \"\"\"Test basic functionality of the R language server.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.R], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.R], indirect=True)\n    def test_server_initialization(self, language_server: SolidLanguageServer, repo_path: Path):\n        \"\"\"Test that the R language server initializes properly.\"\"\"\n        assert language_server is not None\n        assert language_server.language_id == \"r\"\n        assert language_server.is_running()\n        assert Path(language_server.language_server.repository_root_path).resolve() == repo_path.resolve()\n\n    @pytest.mark.parametrize(\"language_server\", [Language.R], indirect=True)\n    def test_symbol_retrieval(self, language_server: SolidLanguageServer):\n        \"\"\"Test R document symbol extraction.\"\"\"\n        all_symbols, _root_symbols = language_server.request_document_symbols(os.path.join(\"R\", \"utils.R\")).get_all_symbols_and_roots()\n\n        # Should find the three exported functions\n        function_symbols = [s for s in all_symbols if s.get(\"kind\") == 12]  # Function kind\n        assert len(function_symbols) >= 3\n\n        # Check that we found the expected functions\n        function_names = {s.get(\"name\") for s in function_symbols}\n        expected_functions = {\"calculate_mean\", \"process_data\", \"create_data_frame\"}\n        assert expected_functions.issubset(function_names), f\"Expected functions {expected_functions} but found {function_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.R], indirect=True)\n    def test_find_definition_across_files(self, language_server: SolidLanguageServer):\n        \"\"\"Test finding function definitions across files.\"\"\"\n        analysis_file = os.path.join(\"examples\", \"analysis.R\")\n\n        # In analysis.R line 7: create_data_frame(n = 50)\n        # The function create_data_frame is defined in R/utils.R\n        # Find definition of create_data_frame function call (0-indexed: line 6)\n        definition_location_list = language_server.request_definition(analysis_file, 6, 17)  # cursor on 'create_data_frame'\n\n        assert definition_location_list, f\"Expected non-empty definition_location_list but got {definition_location_list=}\"\n        assert len(definition_location_list) >= 1\n        definition_location = definition_location_list[0]\n        assert definition_location[\"uri\"].endswith(\"utils.R\")\n        # Definition should be around line 37 (0-indexed: 36) where create_data_frame is defined\n        assert definition_location[\"range\"][\"start\"][\"line\"] >= 35\n\n    @pytest.mark.parametrize(\"language_server\", [Language.R], indirect=True)\n    def test_find_references_across_files(self, language_server: SolidLanguageServer):\n        \"\"\"Test finding function references across files.\"\"\"\n        analysis_file = os.path.join(\"examples\", \"analysis.R\")\n\n        # Test from usage side: find references to calculate_mean from its usage in analysis.R\n        # In analysis.R line 13: calculate_mean(clean_data$value)\n        # calculate_mean function call is at line 13 (0-indexed: line 12)\n        references = language_server.request_references(analysis_file, 12, 15)  # cursor on 'calculate_mean'\n\n        assert references, f\"Expected non-empty references for calculate_mean but got {references=}\"\n\n        # Must find the definition in utils.R (cross-file reference)\n        reference_files = [ref[\"uri\"] for ref in references]\n        assert any(uri.endswith(\"utils.R\") for uri in reference_files), \"Cross-file reference to definition in utils.R not found\"\n\n        # Verify we actually found the right location in utils.R\n        utils_refs = [ref for ref in references if ref[\"uri\"].endswith(\"utils.R\")]\n        assert len(utils_refs) >= 1, \"Should find at least one reference in utils.R\"\n        utils_ref = utils_refs[0]\n        # Should be around line 6 where calculate_mean is defined (0-indexed: line 5)\n        assert (\n            utils_ref[\"range\"][\"start\"][\"line\"] == 5\n        ), f\"Expected reference at line 5 in utils.R, got line {utils_ref['range']['start']['line']}\"\n\n    def test_file_matching(self):\n        \"\"\"Test that R files are properly matched.\"\"\"\n        from solidlsp.ls_config import Language\n\n        matcher = Language.R.get_source_fn_matcher()\n\n        assert matcher.is_relevant_filename(\"script.R\")\n        assert matcher.is_relevant_filename(\"analysis.r\")\n        assert not matcher.is_relevant_filename(\"script.py\")\n        assert not matcher.is_relevant_filename(\"README.md\")\n\n    def test_r_language_enum(self):\n        \"\"\"Test R language enum value.\"\"\"\n        assert Language.R == \"r\"\n        assert str(Language.R) == \"r\"\n"
  },
  {
    "path": "test/solidlsp/rego/test_rego_basic.py",
    "content": "\"\"\"Tests for Rego language server (Regal) functionality.\"\"\"\n\nimport os\n\nimport pytest\n\nfrom solidlsp.ls import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_utils import SymbolUtils\n\n\n@pytest.mark.rego\nclass TestRegoLanguageServer:\n    \"\"\"Test Regal language server functionality for Rego.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.REGO], indirect=True)\n    def test_request_document_symbols_authz(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that document symbols can be retrieved from authz.rego.\"\"\"\n        file_path = os.path.join(\"policies\", \"authz.rego\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        assert symbols is not None\n        assert len(symbols) > 0\n\n        # Extract symbol names\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n        symbol_names = {sym.get(\"name\") for sym in symbol_list if isinstance(sym, dict)}\n\n        # Verify specific Rego rules/functions are found\n        assert \"allow\" in symbol_names, \"allow rule not found\"\n        assert \"allow_read\" in symbol_names, \"allow_read rule not found\"\n        assert \"is_admin\" in symbol_names, \"is_admin function not found\"\n        assert \"admin_roles\" in symbol_names, \"admin_roles constant not found\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.REGO], indirect=True)\n    def test_request_document_symbols_helpers(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that document symbols can be retrieved from helpers.rego.\"\"\"\n        file_path = os.path.join(\"utils\", \"helpers.rego\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        assert symbols is not None\n        assert len(symbols) > 0\n\n        # Extract symbol names\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n        symbol_names = {sym.get(\"name\") for sym in symbol_list if isinstance(sym, dict)}\n\n        # Verify specific helper functions are found\n        assert \"is_valid_user\" in symbol_names, \"is_valid_user function not found\"\n        assert \"is_valid_email\" in symbol_names, \"is_valid_email function not found\"\n        assert \"is_valid_username\" in symbol_names, \"is_valid_username function not found\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.REGO], indirect=True)\n    def test_find_symbol_full_tree(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding symbols across entire workspace using symbol tree.\"\"\"\n        symbols = language_server.request_full_symbol_tree()\n\n        # Use SymbolUtils to check for expected symbols\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"allow\"), \"allow rule not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"is_valid_user\"), \"is_valid_user function not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"is_admin\"), \"is_admin function not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.REGO], indirect=True)\n    def test_request_definition_within_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test go-to-definition for symbols within the same file.\"\"\"\n        # In authz.rego, check_permission references admin_roles\n        file_path = os.path.join(\"policies\", \"authz.rego\")\n\n        # Get document symbols\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n\n        # Find the is_admin symbol which references admin_roles\n        is_admin_symbol = next((s for s in symbol_list if s.get(\"name\") == \"is_admin\"), None)\n        assert is_admin_symbol is not None, \"is_admin symbol should always be found in authz.rego\"\n        assert \"range\" in is_admin_symbol, \"is_admin symbol should have a range\"\n\n        # Request definition from within is_admin (line 25, which references admin_roles at line 21)\n        # Line 25 is: admin_roles[_] == user.role\n        line = is_admin_symbol[\"range\"][\"start\"][\"line\"] + 1\n        char = 4  # Position at \"admin_roles\"\n\n        definitions = language_server.request_definition(file_path, line, char)\n        assert definitions is not None and len(definitions) > 0, \"Should find definition for admin_roles\"\n\n        # Verify the definition points to admin_roles in the same file\n        assert any(\"authz.rego\" in defn.get(\"relativePath\", \"\") for defn in definitions), \"Definition should be in authz.rego\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.REGO], indirect=True)\n    def test_request_definition_across_files(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test go-to-definition for symbols across files (cross-file references).\"\"\"\n        # In authz.rego line 11, the allow rule calls utils.is_valid_user\n        # This function is defined in utils/helpers.rego\n        file_path = os.path.join(\"policies\", \"authz.rego\")\n\n        # Get document symbols\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n\n        # Find the allow symbol\n        allow_symbol = next((s for s in symbol_list if s.get(\"name\") == \"allow\"), None)\n        assert allow_symbol is not None, \"allow symbol should always be found in authz.rego\"\n        assert \"range\" in allow_symbol, \"allow symbol should have a range\"\n\n        # Request definition from line 11 where utils.is_valid_user is called\n        # Line 11: utils.is_valid_user(input.user)\n        line = 10  # 0-indexed, so line 11 in file is line 10 in LSP\n        char = 7  # Position at \"is_valid_user\" in \"utils.is_valid_user\"\n\n        definitions = language_server.request_definition(file_path, line, char)\n        assert definitions is not None and len(definitions) > 0, \"Should find cross-file definition for is_valid_user\"\n\n        # Verify the definition points to helpers.rego (cross-file)\n        assert any(\n            \"helpers.rego\" in defn.get(\"relativePath\", \"\") for defn in definitions\n        ), \"Definition should be in utils/helpers.rego (cross-file reference)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.REGO], indirect=True)\n    def test_find_symbols_validation(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding symbols in validation.rego which has imports.\"\"\"\n        file_path = os.path.join(\"policies\", \"validation.rego\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        assert symbols is not None\n        assert len(symbols) > 0\n\n        # Extract symbol names\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n        symbol_names = {sym.get(\"name\") for sym in symbol_list if isinstance(sym, dict)}\n\n        # Verify expected symbols\n        assert \"validate_user_input\" in symbol_names, \"validate_user_input rule not found\"\n        assert \"has_valid_credentials\" in symbol_names, \"has_valid_credentials function not found\"\n        assert \"validate_request\" in symbol_names, \"validate_request rule not found\"\n"
  },
  {
    "path": "test/solidlsp/ruby/test_ruby_basic.py",
    "content": "import os\nfrom pathlib import Path\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_utils import SymbolUtils\n\n\n@pytest.mark.ruby\nclass TestRubyLanguageServer:\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_find_symbol(self, language_server: SolidLanguageServer) -> None:\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"DemoClass\"), \"DemoClass not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"helper_function\"), \"helper_function not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"print_value\"), \"print_value not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:\n        file_path = os.path.join(\"main.rb\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        helper_symbol = None\n        for sym in symbols[0]:\n            if sym.get(\"name\") == \"helper_function\":\n                helper_symbol = sym\n                break\n        print(helper_symbol)\n        assert helper_symbol is not None, \"Could not find 'helper_function' symbol in main.rb\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.RUBY], indirect=True)\n    def test_find_definition_across_files(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        # Test finding Calculator.add method definition from line 17: Calculator.new.add(demo.value, 10)\n        definition_location_list = language_server.request_definition(\n            str(repo_path / \"main.rb\"), 16, 17\n        )  # add method at line 17 (0-indexed 16), position 17\n\n        assert len(definition_location_list) == 1\n        definition_location = definition_location_list[0]\n        print(f\"Found definition: {definition_location}\")\n        assert definition_location[\"uri\"].endswith(\"lib.rb\")\n        assert definition_location[\"range\"][\"start\"][\"line\"] == 1  # add method on line 2 (0-indexed 1)\n"
  },
  {
    "path": "test/solidlsp/ruby/test_ruby_symbol_retrieval.py",
    "content": "\"\"\"\nTests for the Ruby language server symbol-related functionality.\n\nThese tests focus on the following methods:\n- request_containing_symbol\n- request_referencing_symbols\n- request_defining_symbol\n- request_document_symbols integration\n\"\"\"\n\nimport os\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_types import SymbolKind\n\npytestmark = pytest.mark.ruby\n\n\nclass TestRubyLanguageServerSymbols:\n    \"\"\"Test the Ruby language server's symbol-related functionality.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_containing_symbol_method(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol for a method.\"\"\"\n        # Test for a position inside the create_user method\n        file_path = os.path.join(\"services.rb\")\n        # Look for a position inside the create_user method body\n        containing_symbol = language_server.request_containing_symbol(file_path, 11, 10, include_body=True)\n\n        # Verify that we found the containing symbol\n        assert containing_symbol is not None, \"Should find containing symbol for method position\"\n        assert containing_symbol[\"name\"] == \"create_user\", f\"Expected 'create_user', got '{containing_symbol['name']}'\"\n        assert (\n            containing_symbol[\"kind\"] == SymbolKind.Method.value\n        ), f\"Expected Method kind ({SymbolKind.Method.value}), got {containing_symbol['kind']}\"\n\n        # Verify location information\n        assert \"location\" in containing_symbol, \"Containing symbol should have location information\"\n        location = containing_symbol[\"location\"]\n        assert \"range\" in location, \"Location should contain range information\"\n        assert \"start\" in location[\"range\"], \"Range should have start position\"\n        assert \"end\" in location[\"range\"], \"Range should have end position\"\n\n        # Verify container information\n        if \"containerName\" in containing_symbol:\n            assert containing_symbol[\"containerName\"] in [\n                \"Services::UserService\",\n                \"UserService\",\n            ], f\"Expected UserService container, got '{containing_symbol['containerName']}'\"\n\n        # Verify body content if available\n        if \"body\" in containing_symbol:\n            body = containing_symbol[\"body\"].get_text()\n            assert \"def create_user\" in body, \"Method body should contain method definition\"\n            assert len(body.strip()) > 0, \"Method body should not be empty\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_containing_symbol_class(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol for a class.\"\"\"\n        # Test for a position inside the UserService class but outside any method\n        file_path = os.path.join(\"services.rb\")\n        # Line around the class definition\n        containing_symbol = language_server.request_containing_symbol(file_path, 5, 5)\n\n        # Verify that we found the containing symbol\n        assert containing_symbol is not None, \"Should find containing symbol for class position\"\n        assert containing_symbol[\"name\"] == \"UserService\", f\"Expected 'UserService', got '{containing_symbol['name']}'\"\n        assert (\n            containing_symbol[\"kind\"] == SymbolKind.Class.value\n        ), f\"Expected Class kind ({SymbolKind.Class.value}), got {containing_symbol['kind']}\"\n\n        # Verify location information exists\n        assert \"location\" in containing_symbol, \"Class symbol should have location information\"\n        location = containing_symbol[\"location\"]\n        assert \"range\" in location, \"Location should contain range\"\n        assert \"start\" in location[\"range\"] and \"end\" in location[\"range\"], \"Range should have start and end positions\"\n\n        # Verify the class is properly nested in the Services module\n        if \"containerName\" in containing_symbol:\n            assert (\n                containing_symbol[\"containerName\"] == \"Services\"\n            ), f\"Expected 'Services' as container, got '{containing_symbol['containerName']}'\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_containing_symbol_module(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol for a module context.\"\"\"\n        # Test that we can find the Services module in document symbols\n        file_path = os.path.join(\"services.rb\")\n        symbols, _roots = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Verify Services module appears in document symbols\n        services_module = None\n        for symbol in symbols:\n            if symbol.get(\"name\") == \"Services\" and symbol.get(\"kind\") == SymbolKind.Module:\n                services_module = symbol\n                break\n\n        assert services_module is not None, \"Services module not found in document symbols\"\n\n        # Test that UserService class has Services as container\n        # Position inside UserService class\n        containing_symbol = language_server.request_containing_symbol(file_path, 4, 8)\n        assert containing_symbol is not None\n        assert containing_symbol[\"name\"] == \"UserService\"\n        assert containing_symbol[\"kind\"] == SymbolKind.Class\n        # Verify the module context is preserved in containerName (if supported by the language server)\n        # ruby-lsp doesn't provide containerName, but Solargraph does\n        if \"containerName\" in containing_symbol:\n            assert containing_symbol.get(\"containerName\") == \"Services\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_containing_symbol_nested_class(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol with nested classes.\"\"\"\n        # Test for a position inside a nested class method\n        file_path = os.path.join(\"nested.rb\")\n        # Position inside NestedClass.find_me method\n        containing_symbol = language_server.request_containing_symbol(file_path, 20, 10)\n\n        # Verify that we found the innermost containing symbol\n        assert containing_symbol is not None\n        assert containing_symbol[\"name\"] == \"find_me\"\n        assert containing_symbol[\"kind\"] == SymbolKind.Method\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_containing_symbol_none(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol for a position with no containing symbol.\"\"\"\n        # Test for a position outside any class/method (e.g., in requires)\n        file_path = os.path.join(\"services.rb\")\n        # Line 1 is a require statement, not inside any class or method\n        containing_symbol = language_server.request_containing_symbol(file_path, 1, 5)\n\n        # Should return None or an empty dictionary\n        assert containing_symbol is None or containing_symbol == {}\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_referencing_symbols_method(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_referencing_symbols for a method.\"\"\"\n        # Test referencing symbols for create_user method\n        file_path = os.path.join(\"services.rb\")\n        # Line containing the create_user method definition\n        symbols, _roots = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        create_user_symbol = None\n\n        # Find create_user method in the document symbols (Ruby returns flat list)\n        for symbol in symbols:\n            if symbol.get(\"name\") == \"create_user\":\n                create_user_symbol = symbol\n                break\n\n        if not create_user_symbol or \"selectionRange\" not in create_user_symbol:\n            pytest.skip(\"create_user symbol or its selectionRange not found\")\n\n        sel_start = create_user_symbol[\"selectionRange\"][\"start\"]\n        ref_symbols = [\n            ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        ]\n\n        # We might not have references in our simple test setup, so just verify structure\n        for symbol in ref_symbols:\n            assert \"name\" in symbol\n            assert \"kind\" in symbol\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_referencing_symbols_class(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_referencing_symbols for a class.\"\"\"\n        # Test referencing symbols for User class\n        file_path = os.path.join(\"models.rb\")\n        # Find User class in document symbols\n        symbols, _roots = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        user_symbol = None\n\n        for symbol in symbols:\n            if symbol.get(\"name\") == \"User\":\n                user_symbol = symbol\n                break\n\n        if not user_symbol or \"selectionRange\" not in user_symbol:\n            pytest.skip(\"User symbol or its selectionRange not found\")\n\n        sel_start = user_symbol[\"selectionRange\"][\"start\"]\n        ref_symbols = [\n            ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        ]\n\n        # Verify structure of referencing symbols\n        for symbol in ref_symbols:\n            assert \"name\" in symbol\n            assert \"kind\" in symbol\n            if \"location\" in symbol and \"range\" in symbol[\"location\"]:\n                assert \"start\" in symbol[\"location\"][\"range\"]\n                assert \"end\" in symbol[\"location\"][\"range\"]\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_defining_symbol_variable(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a variable usage.\"\"\"\n        # Test finding the definition of a variable in a method\n        file_path = os.path.join(\"services.rb\")\n        # Look for @users variable usage\n        defining_symbol = language_server.request_defining_symbol(file_path, 12, 10)\n\n        # This test might fail if the language server doesn't support it well\n        if defining_symbol is not None:\n            assert \"name\" in defining_symbol\n            assert \"kind\" in defining_symbol\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_defining_symbol_class(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a class reference.\"\"\"\n        # Test finding the definition of the User class used in services\n        file_path = os.path.join(\"services.rb\")\n        # Line that references User class\n        defining_symbol = language_server.request_defining_symbol(file_path, 11, 15)\n\n        # This might not work perfectly in all Ruby language servers\n        if defining_symbol is not None:\n            assert \"name\" in defining_symbol\n            # The name might be \"User\" or the method that contains it\n            assert defining_symbol.get(\"name\") is not None\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_defining_symbol_none(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a position with no symbol.\"\"\"\n        # Test for a position with no symbol (e.g., whitespace or comment)\n        file_path = os.path.join(\"services.rb\")\n        # Line 3 is likely a blank line or comment\n        defining_symbol = language_server.request_defining_symbol(file_path, 3, 0)\n\n        # Should return None for positions with no symbol\n        assert defining_symbol is None or defining_symbol == {}\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_defining_symbol_nested_class(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for nested class access.\"\"\"\n        # Test finding definition of NestedClass\n        file_path = os.path.join(\"nested.rb\")\n        # Position where NestedClass is referenced\n        defining_symbol = language_server.request_defining_symbol(file_path, 44, 25)\n\n        # This is challenging for many language servers\n        if defining_symbol is not None:\n            assert \"name\" in defining_symbol\n            assert defining_symbol.get(\"name\") in [\"NestedClass\", \"OuterClass\"]\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_symbol_methods_integration(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test the integration between different symbol-related methods.\"\"\"\n        file_path = os.path.join(\"models.rb\")\n\n        # Step 1: Find a method we know exists\n        containing_symbol = language_server.request_containing_symbol(file_path, 8, 5)  # inside initialize method\n        if containing_symbol is not None:\n            assert containing_symbol[\"name\"] == \"initialize\"\n\n            # Step 2: Get the defining symbol for the same position\n            defining_symbol = language_server.request_defining_symbol(file_path, 8, 5)\n            if defining_symbol is not None:\n                assert defining_symbol[\"name\"] == \"initialize\"\n\n                # Step 3: Verify that they refer to the same symbol type\n                assert defining_symbol[\"kind\"] == containing_symbol[\"kind\"]\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_symbol_tree_structure_basic(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that the symbol tree structure includes Ruby symbols.\"\"\"\n        # Get all symbols in the test repository\n        repo_structure = language_server.request_full_symbol_tree()\n        assert len(repo_structure) >= 1\n\n        # Look for our Ruby files in the structure\n        found_ruby_files = False\n        for root in repo_structure:\n            if \"children\" in root:\n                for child in root[\"children\"]:\n                    if child.get(\"name\") in [\"models\", \"services\", \"nested\"]:\n                        found_ruby_files = True\n                        break\n\n        # We should find at least some Ruby files in the symbol tree\n        assert found_ruby_files, \"Ruby files not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_document_symbols_detailed(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test document symbols for detailed Ruby file structure.\"\"\"\n        file_path = os.path.join(\"models.rb\")\n        symbols, roots = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Verify we have symbols\n        assert len(symbols) > 0 or len(roots) > 0\n\n        # Look for expected class names\n        symbol_names = set()\n        all_symbols = symbols if symbols else roots\n\n        for symbol in all_symbols:\n            symbol_names.add(symbol.get(\"name\"))\n            # Add children names too\n            if \"children\" in symbol:\n                for child in symbol[\"children\"]:\n                    symbol_names.add(child.get(\"name\"))\n\n        # We should find at least some of our defined classes/methods\n        expected_symbols = {\"User\", \"Item\", \"Order\", \"ItemHelpers\"}\n        found_symbols = symbol_names.intersection(expected_symbols)\n        assert len(found_symbols) > 0, f\"Expected symbols not found. Found: {symbol_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_module_and_class_hierarchy(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test symbol detection for modules and nested class hierarchies.\"\"\"\n        file_path = os.path.join(\"nested.rb\")\n        symbols, roots = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Verify we can detect the nested structure\n        assert len(symbols) > 0 or len(roots) > 0\n\n        # Look for OuterClass and its nested elements\n        symbol_names = set()\n        all_symbols = symbols if symbols else roots\n\n        for symbol in all_symbols:\n            symbol_names.add(symbol.get(\"name\"))\n            if \"children\" in symbol:\n                for child in symbol[\"children\"]:\n                    symbol_names.add(child.get(\"name\"))\n                    # Check deeply nested too\n                    if \"children\" in child:\n                        for grandchild in child[\"children\"]:\n                            symbol_names.add(grandchild.get(\"name\"))\n\n        # Should find the outer class at minimum\n        assert \"OuterClass\" in symbol_names, f\"OuterClass not found in symbols: {symbol_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_references_to_variables(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_referencing_symbols for a variable with detailed verification.\"\"\"\n        file_path = os.path.join(\"variables.rb\")\n        # Test references to @status variable in DataContainer class (around line 9)\n        ref_symbols = [ref.symbol for ref in language_server.request_referencing_symbols(file_path, 8, 4)]\n\n        if len(ref_symbols) > 0:\n            # Verify we have references\n            assert len(ref_symbols) > 0, \"Should find references to @status variable\"\n\n            # Check that we have location information\n            ref_with_locations = [ref for ref in ref_symbols if \"location\" in ref and \"range\" in ref[\"location\"]]\n            assert len(ref_with_locations) > 0, \"References should include location information\"\n\n            # Verify line numbers are reasonable (should be within the file)\n            ref_lines = [ref[\"location\"][\"range\"][\"start\"][\"line\"] for ref in ref_with_locations]\n            assert all(line >= 0 for line in ref_lines), \"Reference lines should be valid\"\n\n            # Check for specific reference locations we expect\n            # Lines where @status is modified/accessed\n            expected_line_ranges = [(20, 40), (45, 70)]  # Approximate ranges\n            found_in_expected_range = any(any(start <= line <= end for start, end in expected_line_ranges) for line in ref_lines)\n            assert found_in_expected_range, f\"Expected references in ranges {expected_line_ranges}, found lines: {ref_lines}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_referencing_symbols_parameter(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_referencing_symbols for a method parameter.\"\"\"\n        # Test referencing symbols for a method parameter in get_user method\n        file_path = os.path.join(\"services.rb\")\n        # Find get_user method and test parameter references\n        symbols, _roots = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        get_user_symbol = None\n\n        for symbol in symbols:\n            if symbol.get(\"name\") == \"get_user\":\n                get_user_symbol = symbol\n                break\n\n        if not get_user_symbol or \"selectionRange\" not in get_user_symbol:\n            pytest.skip(\"get_user symbol or its selectionRange not found\")\n\n        # Test parameter reference within method body\n        method_start_line = get_user_symbol[\"selectionRange\"][\"start\"][\"line\"]\n        ref_symbols = [\n            ref.symbol\n            for ref in language_server.request_referencing_symbols(file_path, method_start_line + 1, 10)  # Position within method body\n        ]\n\n        # Verify structure of referencing symbols\n        for symbol in ref_symbols:\n            assert \"name\" in symbol, \"Symbol should have name\"\n            assert \"kind\" in symbol, \"Symbol should have kind\"\n            if \"location\" in symbol and \"range\" in symbol[\"location\"]:\n                range_info = symbol[\"location\"][\"range\"]\n                assert \"start\" in range_info, \"Range should have start\"\n                assert \"end\" in range_info, \"Range should have end\"\n                # Verify line number is valid (references can be before method definition too)\n                assert range_info[\"start\"][\"line\"] >= 0, \"Reference line should be valid\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_referencing_symbols_none(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_referencing_symbols for a position with no symbol.\"\"\"\n        # Test for a position with no symbol (comment or blank line)\n        file_path = os.path.join(\"services.rb\")\n\n        # Try multiple positions that should have no symbols\n        test_positions = [(1, 0), (2, 0)]  # Comment/require lines\n\n        for line, char in test_positions:\n            try:\n                ref_symbols = [ref.symbol for ref in language_server.request_referencing_symbols(file_path, line, char)]\n                # If we get here, make sure we got an empty result or minimal results\n                if ref_symbols:\n                    # Some language servers might return minimal info, verify it's reasonable\n                    assert len(ref_symbols) <= 3, f\"Expected few/no references at line {line}, got {len(ref_symbols)}\"\n\n            except Exception as e:\n                # Some language servers throw exceptions for invalid positions, which is acceptable\n                assert (\n                    \"symbol\" in str(e).lower() or \"position\" in str(e).lower() or \"reference\" in str(e).lower()\n                ), f\"Exception should be related to symbol/position/reference issues, got: {e}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_dir_overview(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that request_dir_overview returns correct symbol information for files in a directory.\"\"\"\n        # Get overview of the test repo directory\n        overview = language_server.request_dir_overview(\".\")\n\n        # Verify that we have entries for our main files\n        expected_files = [\"services.rb\", \"models.rb\", \"variables.rb\", \"nested.rb\"]\n        found_files = []\n\n        for file_path in overview.keys():\n            for expected in expected_files:\n                if expected in file_path:\n                    found_files.append(expected)\n                    break\n\n        assert len(found_files) >= 2, f\"Should find at least 2 expected files, found: {found_files}\"\n\n        # Test specific symbols from services.rb if it exists\n        services_file_key = None\n        for file_path in overview.keys():\n            if \"services.rb\" in file_path:\n                services_file_key = file_path\n                break\n\n        if services_file_key:\n            services_symbols = overview[services_file_key]\n            assert len(services_symbols) > 0, \"services.rb should have symbols\"\n\n            # Check for expected symbols with detailed verification\n            symbol_names = [s[0] for s in services_symbols if isinstance(s, tuple) and len(s) > 0]\n            if not symbol_names:  # If not tuples, try different format\n                symbol_names = [s.get(\"name\") for s in services_symbols if hasattr(s, \"get\")]\n\n            expected_symbols = [\"Services\", \"UserService\", \"ItemService\"]\n            found_expected = [name for name in expected_symbols if name in symbol_names]\n            assert len(found_expected) >= 1, f\"Should find at least one expected symbol, found: {found_expected} in {symbol_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_document_overview(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that request_document_overview returns correct symbol information for a file.\"\"\"\n        # Get overview of the user_management.rb file\n        file_path = os.path.join(\"examples\", \"user_management.rb\")\n        overview = language_server.request_document_overview(file_path)\n\n        # Verify that we have symbol information\n        assert len(overview) > 0, \"Document overview should contain symbols\"\n\n        # Look for expected symbols from the file\n        symbol_names = set()\n        for s_info in overview:\n            if isinstance(s_info, tuple) and len(s_info) > 0:\n                symbol_names.add(s_info[0])\n            elif hasattr(s_info, \"get\"):\n                symbol_names.add(s_info.get(\"name\"))\n            elif isinstance(s_info, str):\n                symbol_names.add(s_info)\n\n        # We should find some of our defined classes/methods\n        expected_symbols = {\"UserStats\", \"UserManager\", \"process_user_data\", \"main\"}\n        found_symbols = symbol_names.intersection(expected_symbols)\n        assert len(found_symbols) > 0, f\"Expected to find some symbols from {expected_symbols}, found: {symbol_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_containing_symbol_variable(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol where the target is a variable.\"\"\"\n        # Test for a position inside a variable definition or usage\n        file_path = os.path.join(\"variables.rb\")\n        # Position around a variable assignment (e.g., @status = \"pending\")\n        containing_symbol = language_server.request_containing_symbol(file_path, 10, 5)\n\n        # Verify that we found a containing symbol (likely the method or class)\n        if containing_symbol is not None:\n            assert \"name\" in containing_symbol, \"Containing symbol should have a name\"\n            assert \"kind\" in containing_symbol, \"Containing symbol should have a kind\"\n            # The containing symbol should be a method, class, or similar construct\n            expected_kinds = [SymbolKind.Method, SymbolKind.Class, SymbolKind.Function, SymbolKind.Constructor]\n            assert containing_symbol[\"kind\"] in [\n                k.value for k in expected_kinds\n            ], f\"Expected containing symbol to be method/class/function, got kind: {containing_symbol['kind']}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_containing_symbol_function(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol for a function (not method).\"\"\"\n        # Test for a position inside a standalone function\n        file_path = os.path.join(\"variables.rb\")\n        # Position inside the demonstrate_variable_usage function\n        containing_symbol = language_server.request_containing_symbol(file_path, 100, 10)\n\n        if containing_symbol is not None:\n            assert containing_symbol[\"name\"] in [\n                \"demonstrate_variable_usage\",\n                \"main\",\n            ], f\"Expected function name, got: {containing_symbol['name']}\"\n            assert containing_symbol[\"kind\"] in [\n                SymbolKind.Function.value,\n                SymbolKind.Method.value,\n            ], f\"Expected function or method kind, got: {containing_symbol['kind']}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_containing_symbol_nested(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_containing_symbol with nested scopes.\"\"\"\n        # Test for a position inside a method which is inside a class\n        file_path = os.path.join(\"services.rb\")\n        # Position inside create_user method within UserService class\n        containing_symbol = language_server.request_containing_symbol(file_path, 12, 15)\n\n        # Verify that we found the innermost containing symbol (the method)\n        assert containing_symbol is not None\n        assert containing_symbol[\"name\"] == \"create_user\"\n        assert containing_symbol[\"kind\"] == SymbolKind.Method\n\n        # Verify the container context is preserved\n        if \"containerName\" in containing_symbol:\n            assert \"UserService\" in containing_symbol[\"containerName\"]\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_symbol_tree_structure_subdir(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that the symbol tree structure correctly handles subdirectories.\"\"\"\n        # Get symbols within the examples subdirectory\n        examples_structure = language_server.request_full_symbol_tree(within_relative_path=\"examples\")\n\n        if len(examples_structure) > 0:\n            # Should find the examples directory structure\n            assert len(examples_structure) >= 1, \"Should find examples directory structure\"\n\n            # Look for the user_management file in the structure\n            found_user_management = False\n            for root in examples_structure:\n                if \"children\" in root:\n                    for child in root[\"children\"]:\n                        if \"user_management\" in child.get(\"name\", \"\"):\n                            found_user_management = True\n                            # Verify the structure includes symbol information\n                            if \"children\" in child:\n                                child_names = [c.get(\"name\") for c in child[\"children\"]]\n                                expected_names = [\"UserStats\", \"UserManager\", \"process_user_data\"]\n                                found_expected = [name for name in expected_names if name in child_names]\n                                assert (\n                                    len(found_expected) > 0\n                                ), f\"Should find symbols in user_management, expected {expected_names}, found {child_names}\"\n                            break\n\n            if not found_user_management:\n                pytest.skip(\"user_management file not found in examples subdirectory structure\")\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_defining_symbol_imported_class(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for an imported/required class.\"\"\"\n        # Test finding the definition of a class used from another file\n        file_path = os.path.join(\"examples\", \"user_management.rb\")\n        # Position where Services::UserService is referenced\n        defining_symbol = language_server.request_defining_symbol(file_path, 25, 20)\n\n        # This might not work perfectly in all Ruby language servers due to require complexity\n        if defining_symbol is not None:\n            assert \"name\" in defining_symbol\n            # The defining symbol should relate to UserService or Services\n            # The defining symbol should relate to UserService, Services, or the containing class\n            # Different language servers may resolve this differently\n            expected_names = [\"UserService\", \"Services\", \"new\", \"UserManager\"]\n            assert defining_symbol.get(\"name\") in expected_names, f\"Expected one of {expected_names}, got: {defining_symbol.get('name')}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_defining_symbol_method_call(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a method call.\"\"\"\n        # Test finding the definition of a method being called\n        file_path = os.path.join(\"examples\", \"user_management.rb\")\n        # Position at a method call like create_user\n        defining_symbol = language_server.request_defining_symbol(file_path, 30, 15)\n\n        # Verify that we can find method definitions\n        if defining_symbol is not None:\n            assert \"name\" in defining_symbol\n            assert \"kind\" in defining_symbol\n            # Should be a method or constructor\n            assert defining_symbol.get(\"kind\") in [SymbolKind.Method.value, SymbolKind.Constructor.value, SymbolKind.Function.value]\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_request_defining_symbol_nested_function(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_defining_symbol for a nested function or block.\"\"\"\n        # Test finding definition within nested contexts\n        file_path = os.path.join(\"nested.rb\")\n        # Position inside or referencing nested functionality\n        defining_symbol = language_server.request_defining_symbol(file_path, 15, 10)\n\n        # This is challenging for many language servers\n        if defining_symbol is not None:\n            assert \"name\" in defining_symbol\n            assert \"kind\" in defining_symbol\n            # Could be method, function, or variable depending on implementation\n            valid_kinds = [SymbolKind.Method.value, SymbolKind.Function.value, SymbolKind.Variable.value, SymbolKind.Class.value]\n            assert defining_symbol.get(\"kind\") in valid_kinds\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUBY], indirect=True)\n    def test_containing_symbol_of_var_is_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that the containing symbol of a file-level variable is handled appropriately.\"\"\"\n        # Test behavior with file-level variables or constants\n        file_path = os.path.join(\"variables.rb\")\n        # Position at file-level variable/constant\n        containing_symbol = language_server.request_containing_symbol(file_path, 5, 5)\n\n        # Different language servers handle file-level symbols differently\n        # Some return None, others return file-level containers\n        if containing_symbol is not None:\n            # If we get a symbol, verify its structure\n            assert \"name\" in containing_symbol\n            assert \"kind\" in containing_symbol\n"
  },
  {
    "path": "test/solidlsp/rust/test_rust_2024_edition.py",
    "content": "import os\nfrom collections.abc import Iterator\nfrom pathlib import Path\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_utils import SymbolUtils\nfrom test.conftest import start_ls_context\n\n\n@pytest.fixture(scope=\"class\")\ndef rust_language_server() -> Iterator[SolidLanguageServer]:\n    \"\"\"Set up the test class with the Rust 2024 edition test repository.\"\"\"\n    test_repo_2024_path = TestRust2024EditionLanguageServer.test_repo_2024_path\n\n    if not test_repo_2024_path.exists():\n        pytest.skip(\"Rust 2024 edition test repository not found\")\n\n    # Create and start the language server for the 2024 edition repo\n    with start_ls_context(Language.RUST, str(test_repo_2024_path)) as ls:\n        yield ls\n\n\n@pytest.mark.rust\nclass TestRust2024EditionLanguageServer:\n    test_repo_2024_path = Path(__file__).parent.parent.parent / \"resources\" / \"repos\" / \"rust\" / \"test_repo_2024\"\n\n    def test_find_references_raw(self, rust_language_server) -> None:\n        # Test finding references to the 'add' function defined in main.rs\n        file_path = os.path.join(\"src\", \"main.rs\")\n        symbols = rust_language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        add_symbol = None\n        for sym in symbols[0]:\n            if sym.get(\"name\") == \"add\":\n                add_symbol = sym\n                break\n        assert add_symbol is not None, \"Could not find 'add' function symbol in main.rs\"\n        sel_start = add_symbol[\"selectionRange\"][\"start\"]\n        refs = rust_language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        # The add function should be referenced within main.rs itself (in the main function)\n        assert any(\"main.rs\" in ref.get(\"relativePath\", \"\") for ref in refs), \"main.rs should reference add function\"\n\n    def test_find_symbol(self, rust_language_server) -> None:\n        symbols = rust_language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"main\"), \"main function not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"add\"), \"add function not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"multiply\"), \"multiply function not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Calculator\"), \"Calculator struct not found in symbol tree\"\n\n    def test_find_referencing_symbols_multiply(self, rust_language_server) -> None:\n        # Find references to 'multiply' function defined in lib.rs\n        file_path = os.path.join(\"src\", \"lib.rs\")\n        symbols = rust_language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        multiply_symbol = None\n        for sym in symbols[0]:\n            if sym.get(\"name\") == \"multiply\":\n                multiply_symbol = sym\n                break\n        assert multiply_symbol is not None, \"Could not find 'multiply' function symbol in lib.rs\"\n        sel_start = multiply_symbol[\"selectionRange\"][\"start\"]\n        refs = rust_language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        # The multiply function exists but may not be referenced anywhere, which is fine\n        # This test just verifies we can find the symbol and request references without error\n        assert isinstance(refs, list), \"Should return a list of references (even if empty)\"\n\n    def test_find_calculator_struct_and_impl(self, rust_language_server) -> None:\n        # Test finding the Calculator struct and its impl block\n        file_path = os.path.join(\"src\", \"lib.rs\")\n        symbols = rust_language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Find the Calculator struct\n        calculator_struct = None\n        calculator_impl = None\n        for sym in symbols[0]:\n            if sym.get(\"name\") == \"Calculator\" and sym.get(\"kind\") == 23:  # Struct kind\n                calculator_struct = sym\n            elif sym.get(\"name\") == \"Calculator\" and sym.get(\"kind\") == 11:  # Interface/Impl kind\n                calculator_impl = sym\n\n        assert calculator_struct is not None, \"Could not find 'Calculator' struct symbol in lib.rs\"\n\n        # The struct should have the 'result' field\n        struct_children = calculator_struct.get(\"children\", [])\n        field_names = [child.get(\"name\") for child in struct_children]\n        assert \"result\" in field_names, \"Calculator struct should have 'result' field\"\n\n        # Find the impl block and check its methods\n        if calculator_impl is not None:\n            impl_children = calculator_impl.get(\"children\", [])\n            method_names = [child.get(\"name\") for child in impl_children]\n            assert \"new\" in method_names, \"Calculator impl should have 'new' method\"\n            assert \"add\" in method_names, \"Calculator impl should have 'add' method\"\n            assert \"get_result\" in method_names, \"Calculator impl should have 'get_result' method\"\n\n    def test_overview_methods(self, rust_language_server) -> None:\n        symbols = rust_language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"main\"), \"main missing from overview\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"add\"), \"add missing from overview\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"multiply\"), \"multiply missing from overview\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"Calculator\"), \"Calculator missing from overview\"\n\n    def test_rust_2024_edition_specific(self) -> None:\n        # Verify we're actually working with the 2024 edition repository\n        cargo_toml_path = self.test_repo_2024_path / \"Cargo.toml\"\n        assert cargo_toml_path.exists(), \"Cargo.toml should exist in test repository\"\n\n        with open(cargo_toml_path) as f:\n            content = f.read()\n            assert 'edition = \"2024\"' in content, \"Should be using Rust 2024 edition\"\n"
  },
  {
    "path": "test/solidlsp/rust/test_rust_analyzer_detection.py",
    "content": "\"\"\"\nTests for rust-analyzer detection logic.\n\nThese tests describe the expected behavior of RustAnalyzer._ensure_rust_analyzer_installed():\n\n1. Rustup should be checked FIRST (avoids picking up incorrect PATH aliases)\n2. Common installation locations (Homebrew, cargo, Scoop) should be checked as fallback\n3. System PATH should be checked last (can pick up incompatible versions)\n4. Error messages should list all searched locations\n5. Windows-specific paths should be checked on Windows\n\nWHY these tests matter:\n- Users install rust-analyzer via Homebrew, cargo, Scoop, or system packages - not just rustup\n- macOS Homebrew installs to /opt/homebrew/bin (Apple Silicon) or /usr/local/bin (Intel)\n- Windows users install via Scoop, Chocolatey, or cargo\n- Detection failing means Serena is unusable for Rust, even when rust-analyzer is correctly installed\n- Without these tests, the detection logic can silently break for non-rustup users\n\"\"\"\n\nimport os\nimport pathlib\nimport sys\nfrom unittest.mock import MagicMock, patch\n\nimport pytest\n\n# Platform detection for skipping platform-specific tests\nIS_WINDOWS = sys.platform == \"win32\"\nIS_UNIX = sys.platform != \"win32\"\n\n\nclass TestRustAnalyzerDetection:\n    \"\"\"Unit tests for rust-analyzer binary detection logic.\"\"\"\n\n    @pytest.mark.rust\n    def test_detect_from_path_as_last_resort(self):\n        \"\"\"\n        GIVEN rustup is not available\n        AND rust-analyzer is NOT in common locations (Homebrew, cargo)\n        AND rust-analyzer IS in system PATH\n        WHEN _ensure_rust_analyzer_installed is called\n        THEN it should return the path from shutil.which as last resort\n\n        WHY: PATH is checked last to avoid picking up incorrect aliases.\n        Users with rust-analyzer in PATH but not via rustup/common locations\n        should still work.\n        \"\"\"\n        from solidlsp.language_servers.rust_analyzer import RustAnalyzer\n\n        # Mock rustup to be unavailable\n        with patch.object(RustAnalyzer.DependencyProvider, \"_get_rust_analyzer_via_rustup\", return_value=None):\n            # Mock common locations to NOT exist\n            with patch(\"os.path.isfile\", return_value=False):\n                # Mock PATH to have rust-analyzer\n                with patch(\"shutil.which\") as mock_which:\n                    mock_which.return_value = \"/custom/bin/rust-analyzer\"\n                    with patch(\"os.access\", return_value=True):\n                        # Need isfile to return True for PATH result only\n                        def selective_isfile(path):\n                            return path == \"/custom/bin/rust-analyzer\"\n\n                        with patch(\"os.path.isfile\", side_effect=selective_isfile):\n                            result = RustAnalyzer.DependencyProvider._ensure_rust_analyzer_installed()\n\n        assert result == \"/custom/bin/rust-analyzer\"\n        mock_which.assert_called_with(\"rust-analyzer\")\n\n    @pytest.mark.rust\n    @pytest.mark.skipif(IS_WINDOWS, reason=\"Homebrew paths only apply to macOS/Linux\")\n    def test_detect_from_homebrew_apple_silicon_path(self):\n        \"\"\"\n        GIVEN rustup is NOT available\n        AND rust-analyzer is installed via Homebrew on Apple Silicon Mac\n        AND it is NOT in PATH (shutil.which returns None)\n        WHEN _ensure_rust_analyzer_installed is called\n        THEN it should find /opt/homebrew/bin/rust-analyzer\n\n        WHY: Apple Silicon Macs use /opt/homebrew/bin for Homebrew.\n        This path should be checked as fallback when rustup is unavailable.\n        \"\"\"\n        from solidlsp.language_servers.rust_analyzer import RustAnalyzer\n\n        def mock_isfile(path):\n            return path == \"/opt/homebrew/bin/rust-analyzer\"\n\n        def mock_access(path, mode):\n            return path == \"/opt/homebrew/bin/rust-analyzer\"\n\n        with patch.object(RustAnalyzer.DependencyProvider, \"_get_rust_analyzer_via_rustup\", return_value=None):\n            with patch(\"shutil.which\", return_value=None):\n                with patch(\"os.path.isfile\", side_effect=mock_isfile):\n                    with patch(\"os.access\", side_effect=mock_access):\n                        result = RustAnalyzer.DependencyProvider._ensure_rust_analyzer_installed()\n\n        assert result == \"/opt/homebrew/bin/rust-analyzer\"\n\n    @pytest.mark.rust\n    @pytest.mark.skipif(IS_WINDOWS, reason=\"Homebrew paths only apply to macOS/Linux\")\n    def test_detect_from_homebrew_intel_path(self):\n        \"\"\"\n        GIVEN rustup is NOT available\n        AND rust-analyzer is installed via Homebrew on Intel Mac\n        AND it is NOT in PATH\n        WHEN _ensure_rust_analyzer_installed is called\n        THEN it should find /usr/local/bin/rust-analyzer\n\n        WHY: Intel Macs use /usr/local/bin for Homebrew.\n        Linux systems may also install to this location.\n        \"\"\"\n        from solidlsp.language_servers.rust_analyzer import RustAnalyzer\n\n        def mock_isfile(path):\n            return path == \"/usr/local/bin/rust-analyzer\"\n\n        def mock_access(path, mode):\n            return path == \"/usr/local/bin/rust-analyzer\"\n\n        with patch.object(RustAnalyzer.DependencyProvider, \"_get_rust_analyzer_via_rustup\", return_value=None):\n            with patch(\"shutil.which\", return_value=None):\n                with patch(\"os.path.isfile\", side_effect=mock_isfile):\n                    with patch(\"os.access\", side_effect=mock_access):\n                        result = RustAnalyzer.DependencyProvider._ensure_rust_analyzer_installed()\n\n        assert result == \"/usr/local/bin/rust-analyzer\"\n\n    @pytest.mark.rust\n    @pytest.mark.skipif(IS_WINDOWS, reason=\"Unix cargo path - Windows has separate test\")\n    def test_detect_from_cargo_install_path(self):\n        \"\"\"\n        GIVEN rustup is NOT available\n        AND rust-analyzer is installed via `cargo install rust-analyzer`\n        AND it is NOT in PATH or Homebrew locations\n        WHEN _ensure_rust_analyzer_installed is called\n        THEN it should find ~/.cargo/bin/rust-analyzer\n\n        WHY: `cargo install rust-analyzer` is a common installation method.\n        The binary lands in ~/.cargo/bin which may not be in PATH.\n        \"\"\"\n        from solidlsp.language_servers.rust_analyzer import RustAnalyzer\n\n        cargo_path = os.path.expanduser(\"~/.cargo/bin/rust-analyzer\")\n\n        def mock_isfile(path):\n            return path == cargo_path\n\n        def mock_access(path, mode):\n            return path == cargo_path\n\n        with patch.object(RustAnalyzer.DependencyProvider, \"_get_rust_analyzer_via_rustup\", return_value=None):\n            with patch(\"shutil.which\", return_value=None):\n                with patch(\"os.path.isfile\", side_effect=mock_isfile):\n                    with patch(\"os.access\", side_effect=mock_access):\n                        result = RustAnalyzer.DependencyProvider._ensure_rust_analyzer_installed()\n\n        assert result == cargo_path\n\n    @pytest.mark.rust\n    def test_detect_from_rustup_when_available(self):\n        \"\"\"\n        GIVEN rustup has rust-analyzer installed\n        WHEN _ensure_rust_analyzer_installed is called\n        THEN it should return the rustup path\n\n        WHY: Rustup is checked FIRST to avoid picking up incorrect aliases from PATH.\n        This ensures compatibility with the toolchain.\n        \"\"\"\n        from solidlsp.language_servers.rust_analyzer import RustAnalyzer\n\n        with patch(\"shutil.which\", return_value=None):\n            with patch(\"os.path.isfile\", return_value=False):\n                with patch.object(\n                    RustAnalyzer.DependencyProvider,\n                    \"_get_rust_analyzer_via_rustup\",\n                    return_value=\"/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rust-analyzer\",\n                ):\n                    result = RustAnalyzer.DependencyProvider._ensure_rust_analyzer_installed()\n\n        assert \"rustup\" in result or \".rustup\" in result\n\n    @pytest.mark.rust\n    @pytest.mark.skipif(IS_WINDOWS, reason=\"Unix error messages - Windows has separate test\")\n    def test_error_message_lists_searched_locations_when_not_found(self):\n        \"\"\"\n        GIVEN rust-analyzer is NOT installed anywhere\n        AND rustup is NOT installed\n        WHEN _ensure_rust_analyzer_installed is called\n        THEN it should raise RuntimeError with helpful message listing searched locations\n\n        WHY: Users need to know WHERE Serena looked so they can fix their installation.\n        The old error \"Neither rust-analyzer nor rustup is installed\" was unhelpful.\n        \"\"\"\n        from solidlsp.language_servers.rust_analyzer import RustAnalyzer\n\n        with patch(\"shutil.which\", return_value=None):\n            with patch(\"os.path.isfile\", return_value=False):\n                with patch.object(RustAnalyzer.DependencyProvider, \"_get_rust_analyzer_via_rustup\", return_value=None):\n                    with patch.object(RustAnalyzer.DependencyProvider, \"_get_rustup_version\", return_value=None):\n                        with pytest.raises(RuntimeError) as exc_info:\n                            RustAnalyzer.DependencyProvider._ensure_rust_analyzer_installed()\n\n        error_message = str(exc_info.value)\n        # Error should list the locations that were searched (Unix paths)\n        assert \"/opt/homebrew/bin/rust-analyzer\" in error_message or \"Homebrew\" in error_message\n        assert \"cargo\" in error_message.lower() or \".cargo/bin\" in error_message\n        # Error should suggest installation methods\n        assert \"rustup\" in error_message.lower() or \"Rustup\" in error_message\n\n    @pytest.mark.rust\n    def test_detection_priority_prefers_rustup_over_path_and_common_locations(self):\n        \"\"\"\n        GIVEN rust-analyzer is available via rustup\n        AND rust-analyzer also exists in PATH and common locations\n        WHEN _ensure_rust_analyzer_installed is called\n        THEN it should return the rustup version\n\n        WHY: Rustup provides version management and ensures compatibility.\n        Using PATH directly can pick up incorrect aliases or incompatible versions\n        that cause LSP crashes (as discovered in CI failures).\n        \"\"\"\n        from solidlsp.language_servers.rust_analyzer import RustAnalyzer\n\n        rustup_path = \"/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rust-analyzer\"\n\n        # Rustup has rust-analyzer, PATH also has it, common locations also exist\n        with patch.object(RustAnalyzer.DependencyProvider, \"_get_rust_analyzer_via_rustup\", return_value=rustup_path):\n            with patch(\"shutil.which\", return_value=\"/custom/path/rust-analyzer\"):\n                with patch(\"os.path.isfile\", return_value=True):\n                    with patch(\"os.access\", return_value=True):\n                        result = RustAnalyzer.DependencyProvider._ensure_rust_analyzer_installed()\n\n        # Should use rustup version, NOT PATH or common locations\n        assert result == rustup_path\n\n    @pytest.mark.rust\n    @pytest.mark.skipif(IS_WINDOWS, reason=\"Uses Unix paths - Windows has different behavior\")\n    def test_skips_nonexecutable_files(self):\n        \"\"\"\n        GIVEN a file exists at a detection path but is NOT executable\n        WHEN _ensure_rust_analyzer_installed is called\n        THEN it should skip that path and continue checking others\n\n        WHY: A non-executable file (e.g., broken symlink, wrong permissions)\n        should not be returned as a valid rust-analyzer path.\n        \"\"\"\n        from solidlsp.language_servers.rust_analyzer import RustAnalyzer\n\n        def mock_isfile(path):\n            # File exists at Homebrew location but not executable\n            return path == \"/opt/homebrew/bin/rust-analyzer\"\n\n        def mock_access(path, mode):\n            # Homebrew location exists but not executable\n            if path == \"/opt/homebrew/bin/rust-analyzer\":\n                return False\n            # Cargo location is executable\n            if path == os.path.expanduser(\"~/.cargo/bin/rust-analyzer\"):\n                return True\n            return False\n\n        def mock_isfile_for_cargo(path):\n            return path in [\"/opt/homebrew/bin/rust-analyzer\", os.path.expanduser(\"~/.cargo/bin/rust-analyzer\")]\n\n        with patch.object(RustAnalyzer.DependencyProvider, \"_get_rust_analyzer_via_rustup\", return_value=None):\n            with patch(\"shutil.which\", return_value=None):\n                with patch(\"os.path.isfile\", side_effect=mock_isfile_for_cargo):\n                    with patch(\"os.access\", side_effect=mock_access):\n                        result = RustAnalyzer.DependencyProvider._ensure_rust_analyzer_installed()\n\n        # Should skip non-executable Homebrew and use cargo\n        assert result == os.path.expanduser(\"~/.cargo/bin/rust-analyzer\")\n\n    @pytest.mark.rust\n    def test_detect_from_scoop_shims_path_on_windows(self):\n        \"\"\"\n        GIVEN rustup is NOT available\n        AND rust-analyzer is installed via Scoop on Windows\n        AND it is NOT in PATH\n        WHEN _ensure_rust_analyzer_installed is called\n        THEN it should find ~/scoop/shims/rust-analyzer.exe\n\n        WHY: Scoop is a popular package manager for Windows.\n        The binary lands in ~/scoop/shims which may not be in PATH.\n        \"\"\"\n        from solidlsp.language_servers.rust_analyzer import RustAnalyzer\n\n        home = pathlib.Path.home()\n        scoop_path = str(home / \"scoop\" / \"shims\" / \"rust-analyzer.exe\")\n\n        def mock_isfile(path):\n            return path == scoop_path\n\n        def mock_access(path, mode):\n            return path == scoop_path\n\n        with patch.object(RustAnalyzer.DependencyProvider, \"_get_rust_analyzer_via_rustup\", return_value=None):\n            with patch(\"platform.system\", return_value=\"Windows\"):\n                with patch(\"shutil.which\", return_value=None):\n                    with patch(\"os.path.isfile\", side_effect=mock_isfile):\n                        with patch(\"os.access\", side_effect=mock_access):\n                            result = RustAnalyzer.DependencyProvider._ensure_rust_analyzer_installed()\n\n        assert result == scoop_path\n\n    @pytest.mark.rust\n    def test_detect_from_cargo_path_on_windows(self):\n        \"\"\"\n        GIVEN rustup is NOT available\n        AND rust-analyzer is installed via cargo on Windows\n        AND it is NOT in PATH or Scoop locations\n        WHEN _ensure_rust_analyzer_installed is called\n        THEN it should find ~/.cargo/bin/rust-analyzer.exe\n\n        WHY: `cargo install rust-analyzer` works on Windows.\n        The binary has .exe extension and lands in ~/.cargo/bin.\n        \"\"\"\n        from solidlsp.language_servers.rust_analyzer import RustAnalyzer\n\n        home = pathlib.Path.home()\n        cargo_path = str(home / \".cargo\" / \"bin\" / \"rust-analyzer.exe\")\n\n        def mock_isfile(path):\n            return path == cargo_path\n\n        def mock_access(path, mode):\n            return path == cargo_path\n\n        with patch.object(RustAnalyzer.DependencyProvider, \"_get_rust_analyzer_via_rustup\", return_value=None):\n            with patch(\"platform.system\", return_value=\"Windows\"):\n                with patch(\"shutil.which\", return_value=None):\n                    with patch(\"os.path.isfile\", side_effect=mock_isfile):\n                        with patch(\"os.access\", side_effect=mock_access):\n                            result = RustAnalyzer.DependencyProvider._ensure_rust_analyzer_installed()\n\n        assert result == cargo_path\n\n    @pytest.mark.rust\n    def test_windows_error_message_suggests_windows_package_managers(self):\n        \"\"\"\n        GIVEN rust-analyzer is NOT installed anywhere on Windows\n        AND rustup is NOT installed\n        WHEN _ensure_rust_analyzer_installed is called\n        THEN it should raise RuntimeError with Windows-specific installation suggestions\n\n        WHY: Windows users need Windows-specific package manager suggestions\n        (Scoop, Chocolatey) instead of Homebrew/apt.\n        \"\"\"\n        from solidlsp.language_servers.rust_analyzer import RustAnalyzer\n\n        with patch(\"platform.system\", return_value=\"Windows\"):\n            with patch(\"shutil.which\", return_value=None):\n                with patch(\"os.path.isfile\", return_value=False):\n                    with patch.object(RustAnalyzer.DependencyProvider, \"_get_rust_analyzer_via_rustup\", return_value=None):\n                        with patch.object(RustAnalyzer.DependencyProvider, \"_get_rustup_version\", return_value=None):\n                            with pytest.raises(RuntimeError) as exc_info:\n                                RustAnalyzer.DependencyProvider._ensure_rust_analyzer_installed()\n\n        error_message = str(exc_info.value)\n        # Error should suggest Windows-specific package managers\n        assert \"Scoop\" in error_message or \"scoop\" in error_message\n        assert \"Chocolatey\" in error_message or \"choco\" in error_message\n        # Should NOT suggest Homebrew on Windows\n        assert \"Homebrew\" not in error_message and \"brew\" not in error_message\n\n    @pytest.mark.rust\n    def test_auto_install_via_rustup_when_not_found(self):\n        \"\"\"\n        GIVEN rust-analyzer is NOT installed anywhere\n        AND rustup IS installed\n        WHEN _ensure_rust_analyzer_installed is called\n        AND rustup component add succeeds\n        THEN it should return the rustup-installed path\n\n        WHY: Serena should auto-install rust-analyzer via rustup when possible.\n        This matches the original behavior and enables CI to work without pre-installing.\n        \"\"\"\n        from solidlsp.language_servers.rust_analyzer import RustAnalyzer\n\n        with patch(\"shutil.which\", return_value=None):\n            with patch(\"os.path.isfile\", return_value=False):\n                with patch.object(RustAnalyzer.DependencyProvider, \"_get_rust_analyzer_via_rustup\") as mock_rustup_path:\n                    # First call returns None (not installed), second returns path (after install)\n                    mock_rustup_path.side_effect = [None, \"/home/user/.rustup/toolchains/stable/bin/rust-analyzer\"]\n                    with patch.object(RustAnalyzer.DependencyProvider, \"_get_rustup_version\", return_value=\"1.70.0\"):\n                        with patch(\"subprocess.run\") as mock_run:\n                            mock_run.return_value = MagicMock(returncode=0, stdout=\"\", stderr=\"\")\n                            result = RustAnalyzer.DependencyProvider._ensure_rust_analyzer_installed()\n\n        assert result == \"/home/user/.rustup/toolchains/stable/bin/rust-analyzer\"\n        mock_run.assert_called_once()\n        assert mock_run.call_args[0][0] == [\"rustup\", \"component\", \"add\", \"rust-analyzer\"]\n\n    @pytest.mark.rust\n    def test_auto_install_failure_falls_through_to_common_paths(self):\n        \"\"\"\n        GIVEN rust-analyzer is NOT installed anywhere\n        AND rustup IS installed\n        WHEN _ensure_rust_analyzer_installed is called\n        AND rustup component add FAILS\n        THEN it should fall through to common paths and eventually raise helpful error\n\n        WHY: The new resilient behavior tries all fallback options before failing.\n        When rustup auto-install fails, we try common paths (Homebrew, cargo, etc.)\n        as a last resort. This is more robust than failing immediately.\n        The error message should still help users install rust-analyzer.\n        \"\"\"\n        from solidlsp.language_servers.rust_analyzer import RustAnalyzer\n\n        with patch(\"shutil.which\", return_value=None):\n            with patch(\"os.path.isfile\", return_value=False):\n                with patch.object(RustAnalyzer.DependencyProvider, \"_get_rust_analyzer_via_rustup\", return_value=None):\n                    with patch.object(RustAnalyzer.DependencyProvider, \"_get_rustup_version\", return_value=\"1.70.0\"):\n                        with patch(\"subprocess.run\") as mock_run:\n                            mock_run.return_value = MagicMock(\n                                returncode=1, stdout=\"\", stderr=\"error: component 'rust-analyzer' is not available\"\n                            )\n                            with pytest.raises(RuntimeError) as exc_info:\n                                RustAnalyzer.DependencyProvider._ensure_rust_analyzer_installed()\n\n        error_message = str(exc_info.value)\n        # Error should provide helpful installation instructions\n        assert \"rust-analyzer is not installed\" in error_message.lower()\n        assert \"rustup\" in error_message.lower()  # Should suggest rustup installation\n\n    @pytest.mark.rust\n    def test_auto_install_success_but_binary_not_found_falls_through(self):\n        \"\"\"\n        GIVEN rust-analyzer is NOT installed anywhere\n        AND rustup IS installed\n        WHEN _ensure_rust_analyzer_installed is called\n        AND rustup component add SUCCEEDS\n        BUT the binary is still not found after installation\n        THEN it should fall through to common paths and eventually raise helpful error\n\n        WHY: Even if rustup install reports success but binary isn't found,\n        we try common paths as fallback. The final error provides installation\n        guidance to help users resolve the issue.\n        \"\"\"\n        from solidlsp.language_servers.rust_analyzer import RustAnalyzer\n\n        with patch(\"shutil.which\", return_value=None):\n            with patch(\"os.path.isfile\", return_value=False):\n                with patch.object(RustAnalyzer.DependencyProvider, \"_get_rust_analyzer_via_rustup\", return_value=None):\n                    with patch.object(RustAnalyzer.DependencyProvider, \"_get_rustup_version\", return_value=\"1.70.0\"):\n                        with patch(\"subprocess.run\") as mock_run:\n                            mock_run.return_value = MagicMock(returncode=0, stdout=\"\", stderr=\"\")\n                            with pytest.raises(RuntimeError) as exc_info:\n                                RustAnalyzer.DependencyProvider._ensure_rust_analyzer_installed()\n\n        error_message = str(exc_info.value)\n        # Error should indicate rust-analyzer is not available and provide install instructions\n        assert \"rust-analyzer is not installed\" in error_message.lower()\n        assert \"searched locations\" in error_message.lower()  # Should show what was checked\n\n\nclass TestRustAnalyzerDetectionIntegration:\n    \"\"\"\n    Integration tests that verify detection works on the current system.\n    These tests are skipped if rust-analyzer is not installed.\n    \"\"\"\n\n    @pytest.mark.rust\n    def test_detection_finds_installed_rust_analyzer(self):\n        \"\"\"\n        GIVEN rust-analyzer is installed on this system (via any method)\n        WHEN _ensure_rust_analyzer_installed is called\n        THEN it should return a valid path\n\n        This test verifies the detection logic works end-to-end on the current system.\n        \"\"\"\n        import shutil\n\n        from solidlsp.language_servers.rust_analyzer import RustAnalyzer\n\n        # Skip if rust-analyzer is not installed at all\n        if not shutil.which(\"rust-analyzer\"):\n            # Check common locations\n            common_paths = [\n                \"/opt/homebrew/bin/rust-analyzer\",\n                \"/usr/local/bin/rust-analyzer\",\n                os.path.expanduser(\"~/.cargo/bin/rust-analyzer\"),\n            ]\n            if not any(os.path.isfile(p) and os.access(p, os.X_OK) for p in common_paths):\n                pytest.skip(\"rust-analyzer not installed on this system\")\n\n        result = RustAnalyzer.DependencyProvider._ensure_rust_analyzer_installed()\n\n        assert result is not None\n        assert os.path.isfile(result)\n        assert os.access(result, os.X_OK)\n"
  },
  {
    "path": "test/solidlsp/rust/test_rust_basic.py",
    "content": "import os\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_utils import SymbolUtils\n\n\n@pytest.mark.rust\nclass TestRustLanguageServer:\n    @pytest.mark.parametrize(\"language_server\", [Language.RUST], indirect=True)\n    def test_find_references_raw(self, language_server: SolidLanguageServer) -> None:\n        # Directly test the request_references method for the add function\n        file_path = os.path.join(\"src\", \"lib.rs\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        add_symbol = None\n        for sym in symbols[0]:\n            if sym.get(\"name\") == \"add\":\n                add_symbol = sym\n                break\n        assert add_symbol is not None, \"Could not find 'add' function symbol in lib.rs\"\n        sel_start = add_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        assert any(\n            \"main.rs\" in ref.get(\"relativePath\", \"\") for ref in refs\n        ), \"main.rs should reference add (raw, tried all positions in selectionRange)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUST], indirect=True)\n    def test_find_symbol(self, language_server: SolidLanguageServer) -> None:\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"main\"), \"main function not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"add\"), \"add function not found in symbol tree\"\n        # Add more as needed based on test_repo\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUST], indirect=True)\n    def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:\n        # Find references to 'add' defined in lib.rs, should be referenced from main.rs\n        file_path = os.path.join(\"src\", \"lib.rs\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        add_symbol = None\n        for sym in symbols[0]:\n            if sym.get(\"name\") == \"add\":\n                add_symbol = sym\n                break\n        assert add_symbol is not None, \"Could not find 'add' function symbol in lib.rs\"\n        sel_start = add_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        assert any(\n            \"main.rs\" in ref.get(\"relativePath\", \"\") for ref in refs\n        ), \"main.rs should reference add (tried all positions in selectionRange)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.RUST], indirect=True)\n    def test_overview_methods(self, language_server: SolidLanguageServer) -> None:\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"main\"), \"main missing from overview\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"add\"), \"add missing from overview\"\n"
  },
  {
    "path": "test/solidlsp/scala/test_metals_db_utils.py",
    "content": "\"\"\"\nUnit tests for the metals_db_utils module.\n\nTests the detection of Metals H2 database status and stale lock handling.\n\"\"\"\n\nimport os\nfrom pathlib import Path\nfrom unittest.mock import MagicMock, patch\n\nimport pytest\n\nfrom solidlsp.util.metals_db_utils import (\n    MetalsDbStatus,\n    check_metals_db_status,\n    cleanup_stale_lock,\n    is_metals_process_alive,\n    parse_h2_lock_file,\n)\n\n\n@pytest.mark.scala\nclass TestParseH2LockFile:\n    \"\"\"Tests for parse_h2_lock_file function.\"\"\"\n\n    def test_returns_none_when_file_does_not_exist(self, tmp_path: Path) -> None:\n        \"\"\"Should return None when lock file doesn't exist.\"\"\"\n        lock_path = tmp_path / \"nonexistent.lock.db\"\n        result = parse_h2_lock_file(lock_path)\n        assert result is None\n\n    def test_parses_server_format_lock_file(self, tmp_path: Path) -> None:\n        \"\"\"Should parse lock file with server:host:port format.\"\"\"\n        lock_path = tmp_path / \"metals.mv.db.lock.db\"\n        lock_path.write_text(\"server:localhost:9092\\n\")\n\n        result = parse_h2_lock_file(lock_path)\n\n        assert result is not None\n        assert result.port == 9092\n        assert result.lock_path == lock_path\n\n    def test_parses_port_only_format(self, tmp_path: Path) -> None:\n        \"\"\"Should extract port from content containing a port number.\"\"\"\n        lock_path = tmp_path / \"metals.mv.db.lock.db\"\n        lock_path.write_text(\"some content 9123 more content\\n\")\n\n        result = parse_h2_lock_file(lock_path)\n\n        assert result is not None\n        assert result.port == 9123\n\n    def test_parses_pid_format(self, tmp_path: Path) -> None:\n        \"\"\"Should extract PID from lock file content.\"\"\"\n        lock_path = tmp_path / \"metals.mv.db.lock.db\"\n        lock_path.write_text(\"pid=12345\\nserver:localhost:9092\\n\")\n\n        result = parse_h2_lock_file(lock_path)\n\n        assert result is not None\n        assert result.pid == 12345\n        assert result.port == 9092\n\n    def test_handles_unreadable_file(self, tmp_path: Path) -> None:\n        \"\"\"Should return None for unreadable files.\"\"\"\n        lock_path = tmp_path / \"metals.mv.db.lock.db\"\n        lock_path.write_text(\"content\")\n        # Make file unreadable (Unix only)\n        if os.name != \"nt\":\n            lock_path.chmod(0o000)\n            try:\n                result = parse_h2_lock_file(lock_path)\n                assert result is None\n            finally:\n                lock_path.chmod(0o644)\n\n    def test_truncates_raw_content(self, tmp_path: Path) -> None:\n        \"\"\"Should truncate raw_content to 200 chars.\"\"\"\n        lock_path = tmp_path / \"metals.mv.db.lock.db\"\n        long_content = \"x\" * 500\n        lock_path.write_text(long_content)\n\n        result = parse_h2_lock_file(lock_path)\n\n        assert result is not None\n        assert len(result.raw_content) == 200\n\n\n@pytest.mark.scala\nclass TestIsMetalsProcessAlive:\n    \"\"\"Tests for is_metals_process_alive function.\"\"\"\n\n    def test_returns_false_for_nonexistent_process(self) -> None:\n        \"\"\"Should return False for a PID that doesn't exist.\"\"\"\n        # Use a very high PID that's unlikely to exist\n        result = is_metals_process_alive(999999999)\n        assert result is False\n\n    def test_returns_true_for_metals_process(self) -> None:\n        \"\"\"Should return True for a running Metals process.\"\"\"\n        import psutil\n\n        with patch.object(psutil, \"Process\") as mock_process_class:\n            mock_proc = MagicMock()\n            mock_proc.is_running.return_value = True\n            mock_proc.cmdline.return_value = [\n                \"java\",\n                \"-Dmetals.client=vscode\",\n                \"-jar\",\n                \"metals.jar\",\n            ]\n            mock_process_class.return_value = mock_proc\n\n            result = is_metals_process_alive(12345)\n\n            assert result is True\n\n    def test_returns_false_for_non_metals_java_process(self) -> None:\n        \"\"\"Should return False for a Java process that isn't Metals.\"\"\"\n        import psutil\n\n        with patch.object(psutil, \"Process\") as mock_process_class:\n            mock_proc = MagicMock()\n            mock_proc.is_running.return_value = True\n            mock_proc.cmdline.return_value = [\n                \"java\",\n                \"-jar\",\n                \"some-other-app.jar\",\n            ]\n            mock_process_class.return_value = mock_proc\n\n            result = is_metals_process_alive(12345)\n\n            assert result is False\n\n    def test_returns_false_for_non_running_process(self) -> None:\n        \"\"\"Should return False for a process that's not running.\"\"\"\n        import psutil\n\n        with patch.object(psutil, \"Process\") as mock_process_class:\n            mock_proc = MagicMock()\n            mock_proc.is_running.return_value = False\n            mock_process_class.return_value = mock_proc\n\n            result = is_metals_process_alive(12345)\n\n            assert result is False\n\n    def test_handles_no_such_process(self) -> None:\n        \"\"\"Should return False when process doesn't exist.\"\"\"\n        import psutil\n\n        with patch.object(psutil, \"Process\") as mock_process_class:\n            mock_process_class.side_effect = psutil.NoSuchProcess(12345)\n\n            result = is_metals_process_alive(12345)\n\n            assert result is False\n\n\n@pytest.mark.scala\nclass TestCheckMetalsDbStatus:\n    \"\"\"Tests for check_metals_db_status function.\"\"\"\n\n    def test_returns_no_database_when_metals_dir_missing(self, tmp_path: Path) -> None:\n        \"\"\"Should return NO_DATABASE when .metals directory doesn't exist.\"\"\"\n        status, lock_info = check_metals_db_status(tmp_path)\n\n        assert status == MetalsDbStatus.NO_DATABASE\n        assert lock_info is None\n\n    def test_returns_no_database_when_db_missing(self, tmp_path: Path) -> None:\n        \"\"\"Should return NO_DATABASE when database file doesn't exist.\"\"\"\n        metals_dir = tmp_path / \".metals\"\n        metals_dir.mkdir()\n\n        status, lock_info = check_metals_db_status(tmp_path)\n\n        assert status == MetalsDbStatus.NO_DATABASE\n        assert lock_info is None\n\n    def test_returns_no_lock_when_lock_file_missing(self, tmp_path: Path) -> None:\n        \"\"\"Should return NO_LOCK when database exists but lock doesn't.\"\"\"\n        metals_dir = tmp_path / \".metals\"\n        metals_dir.mkdir()\n        db_path = metals_dir / \"metals.mv.db\"\n        db_path.touch()\n\n        status, lock_info = check_metals_db_status(tmp_path)\n\n        assert status == MetalsDbStatus.NO_LOCK\n        assert lock_info is None\n\n    def test_returns_active_instance_when_process_alive(self, tmp_path: Path) -> None:\n        \"\"\"Should return ACTIVE_INSTANCE when lock holder is running.\"\"\"\n        import solidlsp.util.metals_db_utils as metals_utils\n\n        metals_dir = tmp_path / \".metals\"\n        metals_dir.mkdir()\n        db_path = metals_dir / \"metals.mv.db\"\n        db_path.touch()\n        lock_path = metals_dir / \"metals.mv.db.lock.db\"\n        lock_path.write_text(\"pid=12345\\nserver:localhost:9092\\n\")\n\n        with patch.object(metals_utils, \"is_metals_process_alive\", return_value=True):\n            status, lock_info = check_metals_db_status(tmp_path)\n\n        assert status == MetalsDbStatus.ACTIVE_INSTANCE\n        assert lock_info is not None\n        assert lock_info.is_stale is False\n\n    def test_returns_stale_lock_when_process_dead(self, tmp_path: Path) -> None:\n        \"\"\"Should return STALE_LOCK when lock holder is not running.\"\"\"\n        import solidlsp.util.metals_db_utils as metals_utils\n\n        metals_dir = tmp_path / \".metals\"\n        metals_dir.mkdir()\n        db_path = metals_dir / \"metals.mv.db\"\n        db_path.touch()\n        lock_path = metals_dir / \"metals.mv.db.lock.db\"\n        lock_path.write_text(\"pid=12345\\nserver:localhost:9092\\n\")\n\n        with patch.object(metals_utils, \"is_metals_process_alive\", return_value=False):\n            status, lock_info = check_metals_db_status(tmp_path)\n\n        assert status == MetalsDbStatus.STALE_LOCK\n        assert lock_info is not None\n        assert lock_info.is_stale is True\n\n\n@pytest.mark.scala\nclass TestCleanupStaleLock:\n    \"\"\"Tests for cleanup_stale_lock function.\"\"\"\n\n    def test_removes_lock_file(self, tmp_path: Path) -> None:\n        \"\"\"Should successfully remove a lock file.\"\"\"\n        lock_path = tmp_path / \"metals.mv.db.lock.db\"\n        lock_path.touch()\n\n        result = cleanup_stale_lock(lock_path)\n\n        assert result is True\n        assert not lock_path.exists()\n\n    def test_returns_true_when_file_already_removed(self, tmp_path: Path) -> None:\n        \"\"\"Should return True when file doesn't exist.\"\"\"\n        lock_path = tmp_path / \"nonexistent.lock.db\"\n\n        result = cleanup_stale_lock(lock_path)\n\n        assert result is True\n\n    def test_returns_false_on_permission_error(self, tmp_path: Path) -> None:\n        \"\"\"Should return False when file can't be removed due to permissions.\"\"\"\n        if os.name == \"nt\":\n            pytest.skip(\"Permission test not reliable on Windows\")\n\n        lock_path = tmp_path / \"metals.mv.db.lock.db\"\n        lock_path.touch()\n        # Make parent directory read-only\n        tmp_path.chmod(0o555)\n\n        try:\n            result = cleanup_stale_lock(lock_path)\n            assert result is False\n            assert lock_path.exists()\n        finally:\n            tmp_path.chmod(0o755)\n"
  },
  {
    "path": "test/solidlsp/scala/test_scala_language_server.py",
    "content": "# type: ignore\nimport os\n\nimport pytest\n\nfrom solidlsp.language_servers.scala_language_server import ScalaLanguageServer\nfrom solidlsp.ls_config import Language, LanguageServerConfig\nfrom solidlsp.settings import SolidLSPSettings\n\npytest.skip(\"Scala must be compiled for these tests to run through, which is a huge hassle\", allow_module_level=True)\n\nMAIN_FILE_PATH = os.path.join(\"src\", \"main\", \"scala\", \"com\", \"example\", \"Main.scala\")\n\npytestmark = pytest.mark.scala\n\n\n@pytest.fixture(scope=\"module\")\ndef scala_ls():\n    repo_root = os.path.abspath(\"test/resources/repos/scala\")\n    config = LanguageServerConfig(code_language=Language.SCALA)\n    solidlsp_settings = SolidLSPSettings()\n    ls = ScalaLanguageServer(config, repo_root, solidlsp_settings)\n\n    with ls.start_server():\n        yield ls\n\n\ndef test_scala_document_symbols(scala_ls):\n    \"\"\"Test document symbols for Main.scala\"\"\"\n    symbols, _ = scala_ls.request_document_symbols(MAIN_FILE_PATH).get_all_symbols_and_roots()\n    symbol_names = [s[\"name\"] for s in symbols]\n    assert symbol_names[0] == \"com.example\"\n    assert symbol_names[1] == \"Main\"\n    assert symbol_names[2] == \"main\"\n    assert symbol_names[3] == \"result\"\n    assert symbol_names[4] == \"sum\"\n    assert symbol_names[5] == \"add\"\n    assert symbol_names[6] == \"someMethod\"\n    assert symbol_names[7] == \"str\"\n    assert symbol_names[8] == \"Config\"\n    assert symbol_names[9] == \"field1\"  # confirm https://github.com/oraios/serena/issues/688\n\n\ndef test_scala_references_within_same_file(scala_ls):\n    \"\"\"Test finding references within the same file.\"\"\"\n    definitions = scala_ls.request_definition(MAIN_FILE_PATH, 12, 23)\n    first_def = definitions[0]\n    assert first_def[\"uri\"].endswith(\"Main.scala\")\n    assert first_def[\"range\"][\"start\"][\"line\"] == 16\n    assert first_def[\"range\"][\"start\"][\"character\"] == 6\n    assert first_def[\"range\"][\"end\"][\"line\"] == 16\n    assert first_def[\"range\"][\"end\"][\"character\"] == 9\n\n\ndef test_scala_find_definition_and_references_across_files(scala_ls):\n    definitions = scala_ls.request_definition(MAIN_FILE_PATH, 8, 25)\n    assert len(definitions) == 1\n\n    first_def = definitions[0]\n    assert first_def[\"uri\"].endswith(\"Utils.scala\")\n    assert first_def[\"range\"][\"start\"][\"line\"] == 7\n    assert first_def[\"range\"][\"start\"][\"character\"] == 6\n    assert first_def[\"range\"][\"end\"][\"line\"] == 7\n    assert first_def[\"range\"][\"end\"][\"character\"] == 14\n"
  },
  {
    "path": "test/solidlsp/scala/test_scala_stale_lock_handling.py",
    "content": "\"\"\"\nTests for ScalaLanguageServer stale lock detection and handling modes.\n\nThese tests verify the ScalaLanguageServer's behavior when detecting stale Metals locks.\nThey use mocking to avoid requiring an actual Scala project or Metals server.\n\"\"\"\n\nimport logging\nfrom pathlib import Path\nfrom typing import Any\nfrom unittest.mock import MagicMock, patch\n\nimport pytest\nfrom _pytest.logging import LogCaptureFixture\n\nfrom solidlsp.language_servers.scala_language_server import ScalaLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.settings import SolidLSPSettings\nfrom solidlsp.util.metals_db_utils import MetalsDbStatus, MetalsLockInfo\n\npytestmark = pytest.mark.scala\n\n\nclass TestStaleLockHandling:\n    \"\"\"Tests for ScalaLanguageServer stale lock detection and handling modes.\"\"\"\n\n    @pytest.fixture\n    def sample_lock_info(self, tmp_path: Path) -> MetalsLockInfo:\n        \"\"\"Create a sample MetalsLockInfo for testing.\"\"\"\n        lock_path = tmp_path / \".metals\" / \"metals.mv.db.lock.db\"\n        return MetalsLockInfo(\n            pid=12345,\n            port=9092,\n            lock_path=lock_path,\n            is_stale=True,\n            raw_content=\"SERVER:localhost:9092:12345\",\n        )\n\n    @pytest.fixture\n    def mock_setup_dependencies(self) -> Any:\n        \"\"\"Mock _setup_runtime_dependencies to avoid needing Java/Coursier.\"\"\"\n        return patch.object(\n            ScalaLanguageServer,\n            \"_setup_runtime_dependencies\",\n            return_value=[\"/fake/metals\"],\n        )\n\n    def test_auto_clean_mode_cleans_stale_lock(\n        self,\n        tmp_path: Path,\n        sample_lock_info: MetalsLockInfo,\n        mock_setup_dependencies: Any,\n        caplog: LogCaptureFixture,\n    ) -> None:\n        \"\"\"Test AUTO_CLEAN mode removes stale lock and proceeds.\"\"\"\n        cleanup_mock = MagicMock(return_value=True)\n\n        with (\n            patch(\n                \"solidlsp.util.metals_db_utils.check_metals_db_status\",\n                return_value=(MetalsDbStatus.STALE_LOCK, sample_lock_info),\n            ),\n            patch(\n                \"solidlsp.util.metals_db_utils.cleanup_stale_lock\",\n                cleanup_mock,\n            ),\n            mock_setup_dependencies,\n            patch.object(ScalaLanguageServer, \"__init__\", lambda self, *args, **kwargs: None),\n        ):\n            # Create instance without calling __init__\n            ls = object.__new__(ScalaLanguageServer)\n            settings = SolidLSPSettings(ls_specific_settings={Language.SCALA: {\"on_stale_lock\": \"auto-clean\"}})\n\n            # Call the method under test\n            ls._check_metals_db_status(str(tmp_path), settings)\n\n            # Verify cleanup was called\n            cleanup_mock.assert_called_once_with(sample_lock_info.lock_path)\n\n    def test_warn_mode_logs_warning_without_cleanup(\n        self,\n        tmp_path: Path,\n        sample_lock_info: MetalsLockInfo,\n        mock_setup_dependencies: Any,\n        caplog: LogCaptureFixture,\n    ) -> None:\n        \"\"\"Test WARN mode logs warning but does not clean up.\"\"\"\n        cleanup_mock = MagicMock(return_value=True)\n\n        with (\n            patch(\n                \"solidlsp.util.metals_db_utils.check_metals_db_status\",\n                return_value=(MetalsDbStatus.STALE_LOCK, sample_lock_info),\n            ),\n            patch(\n                \"solidlsp.util.metals_db_utils.cleanup_stale_lock\",\n                cleanup_mock,\n            ),\n            mock_setup_dependencies,\n            caplog.at_level(logging.WARNING),\n        ):\n            ls = object.__new__(ScalaLanguageServer)\n            settings = SolidLSPSettings(ls_specific_settings={Language.SCALA: {\"on_stale_lock\": \"warn\"}})\n\n            ls._check_metals_db_status(str(tmp_path), settings)\n\n            # Verify cleanup was NOT called\n            cleanup_mock.assert_not_called()\n\n            # Verify warning was logged\n            assert any(\"Stale Metals lock detected\" in record.message for record in caplog.records)\n\n    def test_fail_mode_raises_exception(\n        self,\n        tmp_path: Path,\n        sample_lock_info: MetalsLockInfo,\n        mock_setup_dependencies: Any,\n    ) -> None:\n        \"\"\"Test FAIL mode raises MetalsStaleLockError.\"\"\"\n        from solidlsp.ls_exceptions import MetalsStaleLockError\n\n        with (\n            patch(\n                \"solidlsp.util.metals_db_utils.check_metals_db_status\",\n                return_value=(MetalsDbStatus.STALE_LOCK, sample_lock_info),\n            ),\n            mock_setup_dependencies,\n            pytest.raises(MetalsStaleLockError) as exc_info,\n        ):\n            ls = object.__new__(ScalaLanguageServer)\n            settings = SolidLSPSettings(ls_specific_settings={Language.SCALA: {\"on_stale_lock\": \"fail\"}})\n\n            ls._check_metals_db_status(str(tmp_path), settings)\n\n        assert str(sample_lock_info.lock_path) in str(exc_info.value)\n\n    def test_active_instance_logs_info_when_enabled(\n        self,\n        tmp_path: Path,\n        mock_setup_dependencies: Any,\n        caplog: LogCaptureFixture,\n    ) -> None:\n        \"\"\"Test ACTIVE_INSTANCE logs info message when log_multi_instance_notice is true.\"\"\"\n        active_lock_info = MetalsLockInfo(\n            pid=99999,\n            port=9092,\n            lock_path=tmp_path / \".metals\" / \"metals.mv.db.lock.db\",\n            is_stale=False,\n            raw_content=\"SERVER:localhost:9092:99999\",\n        )\n\n        with (\n            patch(\n                \"solidlsp.util.metals_db_utils.check_metals_db_status\",\n                return_value=(MetalsDbStatus.ACTIVE_INSTANCE, active_lock_info),\n            ),\n            mock_setup_dependencies,\n            caplog.at_level(logging.INFO),\n        ):\n            ls = object.__new__(ScalaLanguageServer)\n            settings = SolidLSPSettings(\n                ls_specific_settings={\n                    Language.SCALA: {\n                        \"on_stale_lock\": \"auto-clean\",\n                        \"log_multi_instance_notice\": True,\n                    }\n                }\n            )\n\n            ls._check_metals_db_status(str(tmp_path), settings)\n\n            # Verify info about multi-instance was logged\n            assert any(\"Another Metals instance detected\" in record.message for record in caplog.records)\n\n    def test_active_instance_silent_when_notice_disabled(\n        self,\n        tmp_path: Path,\n        mock_setup_dependencies: Any,\n        caplog: LogCaptureFixture,\n    ) -> None:\n        \"\"\"Test ACTIVE_INSTANCE does not log when log_multi_instance_notice is false.\"\"\"\n        active_lock_info = MetalsLockInfo(\n            pid=99999,\n            port=9092,\n            lock_path=tmp_path / \".metals\" / \"metals.mv.db.lock.db\",\n            is_stale=False,\n            raw_content=\"SERVER:localhost:9092:99999\",\n        )\n\n        with (\n            patch(\n                \"solidlsp.util.metals_db_utils.check_metals_db_status\",\n                return_value=(MetalsDbStatus.ACTIVE_INSTANCE, active_lock_info),\n            ),\n            mock_setup_dependencies,\n            caplog.at_level(logging.INFO),\n        ):\n            ls = object.__new__(ScalaLanguageServer)\n            settings = SolidLSPSettings(\n                ls_specific_settings={\n                    Language.SCALA: {\n                        \"on_stale_lock\": \"auto-clean\",\n                        \"log_multi_instance_notice\": False,\n                    }\n                }\n            )\n\n            ls._check_metals_db_status(str(tmp_path), settings)\n\n            # Verify no multi-instance message was logged\n            assert not any(\"Another Metals instance detected\" in record.message for record in caplog.records)\n\n    def test_no_database_proceeds_silently(\n        self,\n        tmp_path: Path,\n        mock_setup_dependencies: Any,\n        caplog: LogCaptureFixture,\n    ) -> None:\n        \"\"\"Test NO_DATABASE status proceeds without any special handling.\"\"\"\n        with (\n            patch(\n                \"solidlsp.util.metals_db_utils.check_metals_db_status\",\n                return_value=(MetalsDbStatus.NO_DATABASE, None),\n            ),\n            mock_setup_dependencies,\n            caplog.at_level(logging.DEBUG),\n        ):\n            ls = object.__new__(ScalaLanguageServer)\n            settings = SolidLSPSettings(ls_specific_settings={Language.SCALA: {\"on_stale_lock\": \"auto-clean\"}})\n\n            # Should complete without error\n            ls._check_metals_db_status(str(tmp_path), settings)\n\n            # No stale lock or multi-instance messages\n            assert not any(\"Stale\" in record.message for record in caplog.records)\n            assert not any(\"Another Metals instance\" in record.message for record in caplog.records)\n\n    def test_no_lock_proceeds_silently(\n        self,\n        tmp_path: Path,\n        mock_setup_dependencies: Any,\n        caplog: LogCaptureFixture,\n    ) -> None:\n        \"\"\"Test NO_LOCK status proceeds without any special handling.\"\"\"\n        with (\n            patch(\n                \"solidlsp.util.metals_db_utils.check_metals_db_status\",\n                return_value=(MetalsDbStatus.NO_LOCK, None),\n            ),\n            mock_setup_dependencies,\n            caplog.at_level(logging.DEBUG),\n        ):\n            ls = object.__new__(ScalaLanguageServer)\n            settings = SolidLSPSettings(ls_specific_settings={Language.SCALA: {\"on_stale_lock\": \"auto-clean\"}})\n\n            # Should complete without error\n            ls._check_metals_db_status(str(tmp_path), settings)\n\n            # No stale lock or multi-instance messages\n            assert not any(\"Stale\" in record.message for record in caplog.records)\n            assert not any(\"Another Metals instance\" in record.message for record in caplog.records)\n"
  },
  {
    "path": "test/solidlsp/solidity/__init__.py",
    "content": ""
  },
  {
    "path": "test/solidlsp/solidity/test_solidity_basic.py",
    "content": "\"\"\"\nBasic integration tests for the Solidity language server.\n\nTests validate symbol detection and reference finding using the Solidity test repository,\nwhich contains a simple ERC-20 Token contract, a SafeMath library, and an IERC20 interface.\n\"\"\"\n\nimport re\nfrom pathlib import Path\nfrom typing import Optional\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\n\ndef _find_identifier_position(file_path: Path, symbol_name: str) -> Optional[tuple[int, int]]:\n    \"\"\"Return the (line, column) of the first occurrence of *symbol_name* as an identifier.\n\n    Scans the file for a word-boundary match of *symbol_name* so that the position\n    returned is the exact location of the identifier, regardless of what range the\n    language server reports for the surrounding symbol.  Returns None if not found.\n    \"\"\"\n    pattern = re.compile(r\"\\b\" + re.escape(symbol_name) + r\"\\b\")\n    with file_path.open(encoding=\"utf-8\") as fh:\n        for line_idx, line in enumerate(fh):\n            m = pattern.search(line)\n            if m:\n                return line_idx, m.start()\n    return None\n\n\n@pytest.mark.solidity\nclass TestSolidityLanguageServerBasics:\n    \"\"\"Test basic functionality of the Solidity language server.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SOLIDITY], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.SOLIDITY], indirect=True)\n    def test_solidity_language_server_initialization(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that the Solidity language server starts and initializes correctly.\"\"\"\n        assert language_server is not None\n        assert language_server.language == Language.SOLIDITY\n        assert language_server.is_running()\n        assert Path(language_server.language_server.repository_root_path).resolve() == repo_path.resolve()\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SOLIDITY], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.SOLIDITY], indirect=True)\n    def test_token_contract_symbols(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that document symbols are found in Token.sol.\n\n        Verifies contract, state variables, errors, events, and function symbols.\n        \"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"contracts/Token.sol\").get_all_symbols_and_roots()\n\n        assert all_symbols is not None, \"Should return symbols for Token.sol\"\n        assert len(all_symbols) > 0, f\"Should find symbols in Token.sol, found {len(all_symbols)}\"\n\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n\n        # Contract-level symbol\n        assert \"Token\" in symbol_names, \"Should detect the Token contract\"\n\n        # State variables\n        assert \"name\" in symbol_names, \"Should detect the 'name' state variable\"\n        assert \"symbol\" in symbol_names, \"Should detect the 'symbol' state variable\"\n        assert \"decimals\" in symbol_names, \"Should detect the 'decimals' state variable\"\n\n        # Custom errors\n        assert \"ZeroAddress\" in symbol_names, \"Should detect the 'ZeroAddress' custom error\"\n        assert \"InsufficientBalance\" in symbol_names, \"Should detect the 'InsufficientBalance' custom error\"\n\n        # Functions\n        assert \"totalSupply\" in symbol_names, \"Should detect the 'totalSupply' function\"\n        assert \"balanceOf\" in symbol_names, \"Should detect the 'balanceOf' function\"\n        assert \"transfer\" in symbol_names, \"Should detect the 'transfer' function\"\n        assert \"approve\" in symbol_names, \"Should detect the 'approve' function\"\n        assert \"transferFrom\" in symbol_names, \"Should detect the 'transferFrom' function\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SOLIDITY], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.SOLIDITY], indirect=True)\n    def test_interface_symbols(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that document symbols are found in IERC20.sol.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"contracts/interfaces/IERC20.sol\").get_all_symbols_and_roots()\n\n        assert all_symbols is not None, \"Should return symbols for IERC20.sol\"\n        assert len(all_symbols) > 0, f\"Should find symbols in IERC20.sol, found {len(all_symbols)}\"\n\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n\n        # Interface\n        assert \"IERC20\" in symbol_names, \"Should detect the IERC20 interface\"\n\n        # Events\n        assert \"Transfer\" in symbol_names, \"Should detect the Transfer event\"\n        assert \"Approval\" in symbol_names, \"Should detect the Approval event\"\n\n        # View functions\n        assert \"totalSupply\" in symbol_names, \"Should detect totalSupply\"\n        assert \"balanceOf\" in symbol_names, \"Should detect balanceOf\"\n        assert \"allowance\" in symbol_names, \"Should detect allowance\"\n\n        # Mutating functions\n        assert \"transfer\" in symbol_names, \"Should detect transfer\"\n        assert \"approve\" in symbol_names, \"Should detect approve\"\n        assert \"transferFrom\" in symbol_names, \"Should detect transferFrom\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SOLIDITY], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.SOLIDITY], indirect=True)\n    def test_library_symbols(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that document symbols are found in SafeMath.sol.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"contracts/lib/SafeMath.sol\").get_all_symbols_and_roots()\n\n        assert all_symbols is not None, \"Should return symbols for SafeMath.sol\"\n        assert len(all_symbols) > 0, f\"Should find symbols in SafeMath.sol, found {len(all_symbols)}\"\n\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n\n        # Library\n        assert \"SafeMath\" in symbol_names, \"Should detect the SafeMath library\"\n\n        # Library functions\n        assert \"add\" in symbol_names, \"Should detect the 'add' function\"\n        assert \"sub\" in symbol_names, \"Should detect the 'sub' function\"\n        assert \"mul\" in symbol_names, \"Should detect the 'mul' function\"\n        assert \"div\" in symbol_names, \"Should detect the 'div' function\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SOLIDITY], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.SOLIDITY], indirect=True)\n    def test_within_file_references(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test finding within-file references to the _transfer helper in Token.sol.\"\"\"\n        # Use the file to find the exact identifier position: the Solidity LSP reports\n        # the symbol range starting at the preceding whitespace/comment block, not the\n        # function keyword, so we locate '_transfer' directly in the source.\n        pos = _find_identifier_position(repo_path / \"contracts/Token.sol\", \"_transfer\")\n        assert pos is not None, \"Should find '_transfer' identifier in Token.sol\"\n        definition_line, definition_char = pos\n\n        references = language_server.request_references(\"contracts/Token.sol\", definition_line, definition_char)\n\n        assert references is not None, \"Should return references for '_transfer'\"\n        assert (\n            len(references) >= 2\n        ), f\"'_transfer' should have at least 2 references (callers), found {len(references)}\"  # called in transfer() and transferFrom()\n\n        ref_files = {ref.get(\"uri\", \"\") for ref in references}\n        assert any(\"Token.sol\" in uri for uri in ref_files), \"References should include Token.sol\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SOLIDITY], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.SOLIDITY], indirect=True)\n    def test_cross_file_references(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test finding cross-file references: IERC20.transfer implemented in Token.sol.\"\"\"\n        # Use 'transfer' in the interface — Token.sol inherits IERC20 and overrides it,\n        # so the LSP resolves the implementation site in Token.sol as a cross-file reference.\n        pos = _find_identifier_position(repo_path / \"contracts/interfaces/IERC20.sol\", \"transfer\")\n        assert pos is not None, \"Should find 'transfer' identifier in IERC20.sol\"\n        definition_line, definition_char = pos\n\n        references = language_server.request_references(\"contracts/interfaces/IERC20.sol\", definition_line, definition_char)\n\n        assert references is not None, \"Should return cross-file references for IERC20.transfer\"\n        assert len(references) >= 1, f\"IERC20.transfer should be referenced at least once (in Token.sol), found {len(references)}\"\n\n        ref_files = {ref.get(\"uri\", \"\") for ref in references}\n        assert any(\"Token.sol\" in uri for uri in ref_files), \"IERC20.transfer references should include Token.sol\"\n"
  },
  {
    "path": "test/solidlsp/swift/test_swift_basic.py",
    "content": "\"\"\"\nBasic integration tests for the Swift language server functionality.\n\nThese tests validate the functionality of the language server APIs\nlike request_references using the Swift test repository.\n\"\"\"\n\nimport os\nimport platform\n\nimport pytest\n\nfrom serena.project import Project\nfrom serena.util.text_utils import LineType\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom test.conftest import is_ci\n\n# Skip Swift tests on Windows due to complex GitHub Actions configuration\nWINDOWS_SKIP = platform.system() == \"Windows\"\nWINDOWS_SKIP_REASON = \"GitHub Actions configuration for Swift on Windows is complex, skipping for now.\"\n\npytestmark = [pytest.mark.swift, pytest.mark.skipif(WINDOWS_SKIP, reason=WINDOWS_SKIP_REASON)]\n\n\nclass TestSwiftLanguageServerBasics:\n    \"\"\"Test basic functionality of the Swift language server.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SWIFT], indirect=True)\n    def test_goto_definition_calculator_class(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test goto_definition on Calculator class usage.\"\"\"\n        file_path = os.path.join(\"src\", \"main.swift\")\n\n        # Find the Calculator usage at line 5: let calculator = Calculator()\n        # Position should be at the \"Calculator()\" call\n        definitions = language_server.request_definition(file_path, 4, 23)  # Position at Calculator() call\n        assert isinstance(definitions, list), \"Definitions should be a list\"\n        assert len(definitions) > 0, \"Should find definition for Calculator class\"\n\n        # Verify the definition points to the Calculator class definition\n        calculator_def = definitions[0]\n        assert calculator_def.get(\"uri\", \"\").endswith(\"main.swift\"), \"Definition should be in main.swift\"\n\n        # The Calculator class is defined starting at line 16\n        start_line = calculator_def.get(\"range\", {}).get(\"start\", {}).get(\"line\")\n        assert start_line == 15, f\"Calculator class definition should be at line 16, got {start_line + 1}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SWIFT], indirect=True)\n    def test_goto_definition_user_struct(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test goto_definition on User struct usage.\"\"\"\n        file_path = os.path.join(\"src\", \"main.swift\")\n\n        # Find the User usage at line 9: let user = User(name: \"Alice\", age: 30)\n        # Position should be at the \"User(...)\" call\n        definitions = language_server.request_definition(file_path, 8, 18)  # Position at User(...) call\n        assert isinstance(definitions, list), \"Definitions should be a list\"\n        assert len(definitions) > 0, \"Should find definition for User struct\"\n\n        # Verify the definition points to the User struct definition\n        user_def = definitions[0]\n        assert user_def.get(\"uri\", \"\").endswith(\"main.swift\"), \"Definition should be in main.swift\"\n\n        # The User struct is defined starting at line 26\n        start_line = user_def.get(\"range\", {}).get(\"start\", {}).get(\"line\")\n        assert start_line == 25, f\"User struct definition should be at line 26, got {start_line + 1}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SWIFT], indirect=True)\n    def test_goto_definition_calculator_method(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test goto_definition on Calculator method usage.\"\"\"\n        file_path = os.path.join(\"src\", \"main.swift\")\n\n        # Find the add method usage at line 6: let result = calculator.add(5, 3)\n        # Position should be at the \"add\" method call\n        definitions = language_server.request_definition(file_path, 5, 28)  # Position at add method call\n        assert isinstance(definitions, list), \"Definitions should be a list\"\n\n        # Verify the definition points to the add method definition\n        add_def = definitions[0]\n        assert add_def.get(\"uri\", \"\").endswith(\"main.swift\"), \"Definition should be in main.swift\"\n\n        # The add method is defined starting at line 17\n        start_line = add_def.get(\"range\", {}).get(\"start\", {}).get(\"line\")\n        assert start_line == 16, f\"add method definition should be at line 17, got {start_line + 1}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SWIFT], indirect=True)\n    def test_goto_definition_cross_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test goto_definition across files - Utils struct.\"\"\"\n        utils_file = os.path.join(\"src\", \"utils.swift\")\n\n        # First, let's check if Utils is used anywhere (it might not be in this simple test)\n        # We'll test goto_definition on Utils struct itself\n        symbols = language_server.request_document_symbols(utils_file).get_all_symbols_and_roots()\n        utils_symbol = next(s for s in symbols[0] if s.get(\"name\") == \"Utils\")\n\n        sel_start = utils_symbol[\"selectionRange\"][\"start\"]\n        definitions = language_server.request_definition(utils_file, sel_start[\"line\"], sel_start[\"character\"])\n        assert isinstance(definitions, list), \"Definitions should be a list\"\n\n        # Should find the Utils struct definition itself\n        utils_def = definitions[0]\n        assert utils_def.get(\"uri\", \"\").endswith(\"utils.swift\"), \"Definition should be in utils.swift\"\n\n    @pytest.mark.xfail(is_ci, reason=\"Test is flaky in CI\")  # See #1040\n    @pytest.mark.parametrize(\"language_server\", [Language.SWIFT], indirect=True)\n    def test_request_references_calculator_class(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_references on the Calculator class.\"\"\"\n        # Get references to the Calculator class in main.swift\n        file_path = os.path.join(\"src\", \"main.swift\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        calculator_symbol = next(s for s in symbols[0] if s.get(\"name\") == \"Calculator\")\n\n        sel_start = calculator_symbol[\"selectionRange\"][\"start\"]\n        references = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        assert isinstance(references, list), \"References should be a list\"\n        assert len(references) > 0, \"Calculator class should be referenced\"\n\n        # Validate that Calculator is referenced in the main function\n        calculator_refs = [ref for ref in references if ref.get(\"uri\", \"\").endswith(\"main.swift\")]\n        assert len(calculator_refs) > 0, \"Calculator class should be referenced in main.swift\"\n\n        # Check that one reference is at line 5 (let calculator = Calculator())\n        line_5_refs = [ref for ref in calculator_refs if ref.get(\"range\", {}).get(\"start\", {}).get(\"line\") == 4]\n        assert len(line_5_refs) > 0, \"Calculator should be referenced at line 5\"\n\n    @pytest.mark.xfail(is_ci, reason=\"Test is flaky in CI\")  # See #1040\n    @pytest.mark.parametrize(\"language_server\", [Language.SWIFT], indirect=True)\n    def test_request_references_user_struct(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_references on the User struct.\"\"\"\n        # Get references to the User struct in main.swift\n        file_path = os.path.join(\"src\", \"main.swift\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        user_symbol = next(s for s in symbols[0] if s.get(\"name\") == \"User\")\n\n        sel_start = user_symbol[\"selectionRange\"][\"start\"]\n        references = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        assert isinstance(references, list), \"References should be a list\"\n\n        # Validate that User is referenced in the main function\n        user_refs = [ref for ref in references if ref.get(\"uri\", \"\").endswith(\"main.swift\")]\n        assert len(user_refs) > 0, \"User struct should be referenced in main.swift\"\n\n        # Check that one reference is at line 9 (let user = User(...))\n        line_9_refs = [ref for ref in user_refs if ref.get(\"range\", {}).get(\"start\", {}).get(\"line\") == 8]\n        assert len(line_9_refs) > 0, \"User should be referenced at line 9\"\n\n    @pytest.mark.xfail(is_ci, reason=\"Test is flaky in CI\")  # See #1040\n    @pytest.mark.parametrize(\"language_server\", [Language.SWIFT], indirect=True)\n    def test_request_references_utils_struct(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_references on the Utils struct.\"\"\"\n        # Get references to the Utils struct in utils.swift\n        file_path = os.path.join(\"src\", \"utils.swift\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        utils_symbol = next((s for s in symbols[0] if s.get(\"name\") == \"Utils\"), None)\n        if not utils_symbol or \"selectionRange\" not in utils_symbol:\n            raise AssertionError(\"Utils symbol or its selectionRange not found\")\n        sel_start = utils_symbol[\"selectionRange\"][\"start\"]\n        references = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        assert isinstance(references, list), \"References should be a list\"\n        assert len(references) > 0, \"Utils struct should be referenced\"\n\n        # Validate that Utils is referenced in main.swift\n        utils_refs = [ref for ref in references if ref.get(\"uri\", \"\").endswith(\"main.swift\")]\n        assert len(utils_refs) > 0, \"Utils struct should be referenced in main.swift\"\n\n        # Check that one reference is at line 12 (Utils.calculateArea call)\n        line_12_refs = [ref for ref in utils_refs if ref.get(\"range\", {}).get(\"start\", {}).get(\"line\") == 11]\n        assert len(line_12_refs) > 0, \"Utils should be referenced at line 12\"\n\n\nclass TestSwiftProjectBasics:\n    @pytest.mark.parametrize(\"project\", [Language.SWIFT], indirect=True)\n    def test_retrieve_content_around_line(self, project: Project) -> None:\n        \"\"\"Test retrieve_content_around_line functionality with various scenarios.\"\"\"\n        file_path = os.path.join(\"src\", \"main.swift\")\n\n        # Scenario 1: Find Calculator class definition\n        calculator_line = None\n        for line_num in range(1, 50):  # Search first 50 lines\n            try:\n                line_content = project.retrieve_content_around_line(file_path, line_num)\n                if line_content.lines and \"class Calculator\" in line_content.lines[0].line_content:\n                    calculator_line = line_num\n                    break\n            except:\n                continue\n\n        assert calculator_line is not None, \"Calculator class not found\"\n        line_calc = project.retrieve_content_around_line(file_path, calculator_line)\n        assert len(line_calc.lines) == 1\n        assert \"class Calculator\" in line_calc.lines[0].line_content\n        assert line_calc.lines[0].line_number == calculator_line\n        assert line_calc.lines[0].match_type == LineType.MATCH\n\n        # Scenario 2: Context above and below Calculator class\n        with_context_around_calculator = project.retrieve_content_around_line(file_path, calculator_line, 2, 2)\n        assert len(with_context_around_calculator.lines) == 5\n        assert \"class Calculator\" in with_context_around_calculator.matched_lines[0].line_content\n        assert with_context_around_calculator.num_matched_lines == 1\n\n        # Scenario 3: Search for struct definitions\n        struct_pattern = r\"struct\\s+\\w+\"\n        matches = project.search_source_files_for_pattern(struct_pattern)\n        assert len(matches) > 0, \"Should find struct definitions\"\n        # Should find User struct\n        user_matches = [m for m in matches if \"User\" in str(m)]\n        assert len(user_matches) > 0, \"Should find User struct\"\n\n        # Scenario 4: Search for class definitions\n        class_pattern = r\"class\\s+\\w+\"\n        matches = project.search_source_files_for_pattern(class_pattern)\n        assert len(matches) > 0, \"Should find class definitions\"\n        # Should find Calculator and Circle classes\n        calculator_matches = [m for m in matches if \"Calculator\" in str(m)]\n        circle_matches = [m for m in matches if \"Circle\" in str(m)]\n        assert len(calculator_matches) > 0, \"Should find Calculator class\"\n        assert len(circle_matches) > 0, \"Should find Circle class\"\n\n        # Scenario 5: Search for enum definitions\n        enum_pattern = r\"enum\\s+\\w+\"\n        matches = project.search_source_files_for_pattern(enum_pattern)\n        assert len(matches) > 0, \"Should find enum definitions\"\n        # Should find Status enum\n        status_matches = [m for m in matches if \"Status\" in str(m)]\n        assert len(status_matches) > 0, \"Should find Status enum\"\n"
  },
  {
    "path": "test/solidlsp/systemverilog/__init__.py",
    "content": ""
  },
  {
    "path": "test/solidlsp/systemverilog/test_systemverilog_basic.py",
    "content": "\"\"\"\nBasic tests for SystemVerilog language server integration (verible-verilog-ls).\n\nThis module tests Language.SYSTEMVERILOG using verible-verilog-ls.\nTests are skipped if the language server is not available.\n\"\"\"\n\nfrom typing import Any\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_utils import SymbolUtils\n\n\ndef _find_symbol_by_name(language_server: SolidLanguageServer, file_path: str, name: str) -> dict[str, Any] | None:\n    \"\"\"Find a top-level symbol by name in a file's document symbols.\"\"\"\n    symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n    return next((s for s in symbols[0] if s.get(\"name\") == name), None)\n\n\ndef _get_symbol_selection_start(language_server: SolidLanguageServer, file_path: str, name: str) -> tuple[int, int]:\n    \"\"\"Get the (line, character) of a symbol's selectionRange start.\"\"\"\n    symbol = _find_symbol_by_name(language_server, file_path, name)\n    assert symbol is not None, f\"Could not find symbol '{name}' in {file_path}\"\n    assert \"selectionRange\" in symbol, f\"Symbol '{name}' has no selectionRange in {file_path}\"\n    sel_start = symbol[\"selectionRange\"][\"start\"]\n    return sel_start[\"line\"], sel_start[\"character\"]\n\n\n@pytest.mark.systemverilog\nclass TestSystemVerilogSymbols:\n    \"\"\"Tests for document symbol extraction.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SYSTEMVERILOG], indirect=True)\n    def test_find_symbol(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that symbol tree contains expected modules.\"\"\"\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"counter\"), \"Module 'counter' not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SYSTEMVERILOG], indirect=True)\n    def test_get_document_symbols(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test document symbols for counter.sv.\"\"\"\n        symbol = _find_symbol_by_name(language_server, \"counter.sv\", \"counter\")\n        assert symbol is not None, \"Expected 'counter' in document symbols\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SYSTEMVERILOG], indirect=True)\n    def test_find_top_module(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that top module is found (cross-file instantiation test).\"\"\"\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"top\"), \"Module 'top' not found in symbol tree\"\n\n\n@pytest.mark.systemverilog\nclass TestSystemVerilogDefinition:\n    \"\"\"Tests for go-to-definition functionality.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SYSTEMVERILOG], indirect=True)\n    def test_goto_definition(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test go to definition from signal usage to its declaration.\n\n        Navigating from 'count' usage in always_ff (line 13) should jump\n        to the output port declaration (line 7, char 29).\n        \"\"\"\n        # counter.sv line 13 (0-indexed): \"            count <= '0;\"\n        # 'count' at char 12\n        definitions = language_server.request_definition(\"counter.sv\", 13, 12)\n        assert len(definitions) >= 1, f\"Expected at least 1 definition, got {len(definitions)}\"\n        def_in_counter = [d for d in definitions if \"counter.sv\" in (d.get(\"relativePath\") or \"\")]\n        assert len(def_in_counter) >= 1, f\"Expected definition in counter.sv, got: {[d.get('relativePath') for d in definitions]}\"\n        assert (\n            def_in_counter[0][\"range\"][\"start\"][\"line\"] == 7\n        ), f\"Expected definition at line 7 (output port count), got line {def_in_counter[0]['range']['start']['line']}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SYSTEMVERILOG], indirect=True)\n    def test_goto_definition_cross_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test go to definition from module instantiation in top.sv to counter.sv.\n\n        This is the key cross-file test: navigating from an instantiation\n        (counter in top.sv) to its definition (counter.sv).\n        \"\"\"\n        # top.sv line 17 (0-indexed: 16): \"    counter #(.WIDTH(8)) u_counter (\"\n        # \"counter\" starts at column 4\n        definitions = language_server.request_definition(\"top.sv\", 16, 4)\n        assert len(definitions) >= 1, f\"Expected at least 1 definition, got {len(definitions)}\"\n        def_paths = [d.get(\"relativePath\", \"\") for d in definitions]\n        assert any(\"counter.sv\" in p for p in def_paths), f\"Expected definition in counter.sv, got: {def_paths}\"\n        counter_defs = [d for d in definitions if \"counter.sv\" in (d.get(\"relativePath\") or \"\")]\n        assert (\n            counter_defs[0][\"range\"][\"start\"][\"line\"] == 1\n        ), f\"Expected definition at line 1 (module counter), got line {counter_defs[0]['range']['start']['line']}\"\n\n\n@pytest.mark.systemverilog\nclass TestSystemVerilogReferences:\n    \"\"\"Tests for find-references functionality.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SYSTEMVERILOG], indirect=True)\n    def test_find_references(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding within-file references to a port signal.\n\n        The 'count' output port is declared on line 7 and used in the\n        always_ff block on lines 13 and 15 (twice), giving 3 within-file\n        references — all inside counter.sv.\n        \"\"\"\n        # counter.sv line 8 (0-indexed: 7): \"    output logic [WIDTH-1:0] count\"\n        # 'count' starts at char 29\n        references = language_server.request_references(\"counter.sv\", 7, 29)\n        assert len(references) >= 1, f\"Expected at least 1 reference, got {len(references)}\"\n        ref_paths = [r.get(\"relativePath\", \"\") for r in references]\n        refs_in_counter = [r for r in references if \"counter.sv\" in (r.get(\"relativePath\") or \"\")]\n        assert len(refs_in_counter) >= 1, f\"Expected within-file references in counter.sv, got paths: {ref_paths}\"\n        ref_lines = sorted(r[\"range\"][\"start\"][\"line\"] for r in refs_in_counter)\n        # Line 13: count <= '0;  Line 15: count <= count + 1'b1; (two refs)\n        assert 13 in ref_lines, f\"Expected reference at line 13 (count <= '0), got lines: {ref_lines}\"\n        assert 15 in ref_lines, f\"Expected reference at line 15 (count <= count + 1'b1), got lines: {ref_lines}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SYSTEMVERILOG], indirect=True)\n    def test_find_references_cross_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that references to counter include its instantiation in top.sv.\n\n        Similar to Rust (lib.rs → main.rs) and C# (Program.cs → Models/Person.cs),\n        this verifies that cross-file references are found.\n        \"\"\"\n        line, char = _get_symbol_selection_start(language_server, \"counter.sv\", \"counter\")\n        references = language_server.request_references(\"counter.sv\", line, char)\n        ref_paths = [ref.get(\"relativePath\", \"\") for ref in references]\n        assert any(\"top.sv\" in p for p in ref_paths), f\"Expected reference from top.sv, got: {ref_paths}\"\n        refs_in_top = [r for r in references if \"top.sv\" in (r.get(\"relativePath\") or \"\")]\n        # top.sv line 17 (0-indexed: 16): \"    counter #(.WIDTH(8)) u_counter (\"\n        assert (\n            refs_in_top[0][\"range\"][\"start\"][\"line\"] == 16\n        ), f\"Expected cross-file reference at line 16 (counter instantiation), got line {refs_in_top[0]['range']['start']['line']}\"\n\n\ndef _extract_hover_text(hover_info: dict[str, Any]) -> str:\n    \"\"\"Extract the text content from an LSP hover response.\"\"\"\n    contents = hover_info[\"contents\"]\n    if isinstance(contents, dict):\n        return contents.get(\"value\", \"\")\n    elif isinstance(contents, str):\n        return contents\n    return str(contents)\n\n\n@pytest.mark.systemverilog\nclass TestSystemVerilogHover:\n    \"\"\"Tests for hover information.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SYSTEMVERILOG], indirect=True)\n    def test_hover(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test hover information (experimental in verible, requires --lsp_enable_hover).\"\"\"\n        line, char = _get_symbol_selection_start(language_server, \"counter.sv\", \"counter\")\n        hover_info = language_server.request_hover(\"counter.sv\", line, char)\n        assert hover_info is not None, \"Hover should return information for counter module\"\n        assert \"contents\" in hover_info, \"Hover should have contents\"\n        hover_text = _extract_hover_text(hover_info)\n        assert len(hover_text) > 0, \"Hover text should not be empty\"\n        assert \"counter\" in hover_text.lower(), f\"Hover should mention 'counter', got: {hover_text}\"\n        assert \"module\" in hover_text.lower(), f\"Hover should identify 'counter' as a module, got: {hover_text}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SYSTEMVERILOG], indirect=True)\n    def test_hover_includes_type_information(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that hover includes type information for a port signal.\n\n        Hovering on 'count' output port should return its name and type\n        (logic [WIDTH-1:0]), distinct from module-level hover.\n        \"\"\"\n        # counter.sv line 8 (0-indexed: 7): \"    output logic [WIDTH-1:0] count\"\n        # 'count' starts at char 29\n        hover_info = language_server.request_hover(\"counter.sv\", 7, 29)\n        assert hover_info is not None, \"Hover should return information for 'count' port\"\n        assert \"contents\" in hover_info, \"Hover should have contents\"\n        hover_text = _extract_hover_text(hover_info)\n        assert \"count\" in hover_text.lower(), f\"Hover should mention 'count', got: {hover_text}\"\n        assert \"logic\" in hover_text.lower(), f\"Hover should include type 'logic', got: {hover_text}\"\n\n\ndef _extract_changes(workspace_edit: dict[str, Any]) -> dict[str, list[dict[str, Any]]]:\n    \"\"\"Extract file URI → edits mapping from a WorkspaceEdit, handling both formats.\"\"\"\n    changes = workspace_edit.get(\"changes\", {})\n    if not changes:\n        doc_changes = workspace_edit.get(\"documentChanges\", [])\n        assert len(doc_changes) > 0, \"WorkspaceEdit should have 'changes' or 'documentChanges'\"\n        changes = {dc[\"textDocument\"][\"uri\"]: dc[\"edits\"] for dc in doc_changes if \"textDocument\" in dc and \"edits\" in dc}\n    return changes\n\n\n@pytest.mark.systemverilog\nclass TestSystemVerilogRename:\n    \"\"\"Tests for rename functionality.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SYSTEMVERILOG], indirect=True)\n    def test_rename_signal_within_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test renaming a port signal from its declaration updates within-file occurrences.\n\n        The 'count' output port (line 7, char 29) is used in the always_ff\n        block on lines 13 and 15. Renaming from the declaration site produces\n        edits for all occurrences within counter.sv.\n        \"\"\"\n        workspace_edit = language_server.request_rename_symbol_edit(\"counter.sv\", 7, 29, \"cnt\")\n        assert workspace_edit is not None, \"Rename should be supported for port signal 'count'\"\n\n        changes = _extract_changes(workspace_edit)\n        counter_edits = [edits for uri, edits in changes.items() if \"counter.sv\" in uri]\n        assert len(counter_edits) >= 1, f\"Should have edits for counter.sv, got: {list(changes.keys())}\"\n\n        edits = counter_edits[0]\n        assert len(edits) >= 2, f\"Expected at least 2 edits (declaration + usage), got {len(edits)}\"\n        edit_lines = sorted(e[\"range\"][\"start\"][\"line\"] for e in edits)\n        assert 7 in edit_lines, f\"Expected edit at line 7 (port declaration), got lines: {edit_lines}\"\n        assert 13 in edit_lines, f\"Expected edit at line 13 (count <= '0), got lines: {edit_lines}\"\n        assert 15 in edit_lines, f\"Expected edit at line 15 (count <= count + 1'b1), got lines: {edit_lines}\"\n        for edit in edits:\n            assert edit[\"newText\"] == \"cnt\", f\"Expected newText 'cnt', got {edit['newText']}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SYSTEMVERILOG], indirect=True)\n    def test_rename_signal_cross_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test renaming a port signal from a usage site includes cross-file edits.\n\n        Renaming 'count' from usage in always_ff (line 13, char 12) should\n        produce edits in counter.sv (declaration + usages) and also in top.sv\n        where the port is connected (.count(count) at line 20).\n        \"\"\"\n        workspace_edit = language_server.request_rename_symbol_edit(\"counter.sv\", 13, 12, \"cnt\")\n        assert workspace_edit is not None, \"Rename should be supported for signal 'count' from usage site\"\n\n        changes = _extract_changes(workspace_edit)\n        counter_uris = [uri for uri in changes if \"counter.sv\" in uri]\n        top_uris = [uri for uri in changes if \"top.sv\" in uri]\n        assert len(counter_uris) >= 1, f\"Expected edits in counter.sv, got: {list(changes.keys())}\"\n        assert len(top_uris) >= 1, f\"Expected cross-file edits in top.sv, got: {list(changes.keys())}\"\n\n        for uri, edits in changes.items():\n            for edit in edits:\n                assert edit[\"newText\"] == \"cnt\", f\"Expected 'cnt' in {uri}, got {edit['newText']}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.SYSTEMVERILOG], indirect=True)\n    def test_rename_module_name(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test renaming a module name at its declaration.\n\n        The 'counter' module declaration (line 1, char 7) is renamed to\n        'my_counter'. Verible renames the identifier at the definition site.\n        \"\"\"\n        line, char = _get_symbol_selection_start(language_server, \"counter.sv\", \"counter\")\n        workspace_edit = language_server.request_rename_symbol_edit(\"counter.sv\", line, char, \"my_counter\")\n        assert workspace_edit is not None, \"Rename should be supported for module 'counter'\"\n\n        changes = _extract_changes(workspace_edit)\n        assert len(changes) > 0, \"WorkspaceEdit should have changes\"\n        counter_edits = [edits for uri, edits in changes.items() if \"counter.sv\" in uri]\n        assert len(counter_edits) >= 1, f\"Should have edits for counter.sv, got: {list(changes.keys())}\"\n\n        edits = counter_edits[0]\n        edit_lines = sorted(e[\"range\"][\"start\"][\"line\"] for e in edits)\n        assert 1 in edit_lines, f\"Expected edit at line 1 (module declaration), got lines: {edit_lines}\"\n        decl_edits = [e for e in edits if e[\"range\"][\"start\"][\"line\"] == 1]\n        assert (\n            decl_edits[0][\"range\"][\"start\"][\"character\"] == 7\n        ), f\"Expected edit at char 7, got char {decl_edits[0]['range']['start']['character']}\"\n        for uri, file_edits in changes.items():\n            for edit in file_edits:\n                assert edit[\"newText\"] == \"my_counter\", f\"Expected 'my_counter', got {edit['newText']}\"\n"
  },
  {
    "path": "test/solidlsp/systemverilog/test_systemverilog_detection.py",
    "content": "\"\"\"\nTests for verible-verilog-ls detection logic.\n\nThese tests describe the expected behavior of SystemVerilogLanguageServer.DependencyProvider._get_or_install_core_dependency():\n\n1. System PATH should be checked FIRST (prefers user-installed verible)\n2. Runtime download should be fallback when not in PATH\n3. Version information should be logged when available\n4. Version check failures should be handled gracefully\n5. Helpful error messages when verible is not available on unsupported platforms\n\nWHY these tests matter:\n- Users install verible via conda, Homebrew, system packages, or GitHub releases\n- Detection failing means Serena is unusable for SystemVerilog, even when verible is correctly installed\n- Without these tests, the detection logic can silently break for users with system installations\n- Version logging helps debug compatibility issues\n\"\"\"\n\nimport os\nimport shutil\nimport subprocess\nimport tempfile\nfrom unittest.mock import MagicMock, Mock, patch\n\nimport pytest\n\nfrom solidlsp.language_servers.systemverilog_server import SystemVerilogLanguageServer\nfrom solidlsp.settings import SolidLSPSettings\n\nDEFAULT_VERIBLE_VERSION = \"v0.0-4051-g9fdb4057\"\n\n\nclass TestVeribleVerilogLsDetection:\n    \"\"\"Unit tests for verible-verilog-ls binary detection logic.\"\"\"\n\n    @pytest.mark.systemverilog\n    def test_detect_from_path_returns_system_verible(self):\n        \"\"\"\n        GIVEN verible-verilog-ls is in system PATH\n        WHEN _get_or_install_core_dependency is called\n        THEN it returns the system path without downloading\n\n        WHY: Users with system-installed verible (via conda, Homebrew, apt)\n        should use that version instead of downloading. This is faster and\n        respects user's environment management.\n        \"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            custom_settings = SolidLSPSettings.CustomLSSettings({})\n            provider = SystemVerilogLanguageServer.DependencyProvider(custom_settings, temp_dir)\n\n            with patch(\"shutil.which\") as mock_which:\n                mock_which.return_value = \"/usr/local/bin/verible-verilog-ls\"\n                with patch(\"subprocess.run\") as mock_run:\n                    mock_run.return_value = MagicMock(\n                        returncode=0,\n                        stdout=\"Verible v0.0-4051-g9fdb4057 (2024-01-01)\\nCommit: 9fdb4057\",\n                        stderr=\"\",\n                    )\n                    result = provider._get_or_install_core_dependency()\n\n        assert result == \"/usr/local/bin/verible-verilog-ls\"\n        mock_which.assert_called_once_with(\"verible-verilog-ls\")\n        mock_run.assert_called_once()\n        assert mock_run.call_args[0][0] == [\"/usr/local/bin/verible-verilog-ls\", \"--version\"]\n\n    @pytest.mark.systemverilog\n    def test_detect_from_path_logs_version(self):\n        \"\"\"\n        GIVEN verible-verilog-ls is in PATH with version output\n        WHEN detected\n        THEN version info is logged\n\n        WHY: Version information helps debug compatibility issues.\n        Users and developers need to know which verible version is being used.\n        \"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            custom_settings = SolidLSPSettings.CustomLSSettings({})\n            provider = SystemVerilogLanguageServer.DependencyProvider(custom_settings, temp_dir)\n\n            with patch(\"shutil.which\", return_value=\"/usr/bin/verible-verilog-ls\"):\n                with patch(\"subprocess.run\") as mock_run:\n                    mock_run.return_value = MagicMock(returncode=0, stdout=\"Verible v0.0-4051-g9fdb4057\", stderr=\"\")\n                    with patch(\"solidlsp.language_servers.systemverilog_server.log\") as mock_log:\n                        result = provider._get_or_install_core_dependency()\n\n            # Verify version check was called\n            assert mock_run.call_args[0][0] == [\"/usr/bin/verible-verilog-ls\", \"--version\"]\n            # Verify version was logged\n            assert mock_log.info.called\n            log_message = mock_log.info.call_args[0][0]\n            assert \"Verible v0.0-4051\" in log_message\n            assert result == \"/usr/bin/verible-verilog-ls\"\n\n    @pytest.mark.systemverilog\n    def test_detect_from_path_handles_version_failure_gracefully(self):\n        \"\"\"\n        GIVEN verible-verilog-ls is in PATH but --version fails (returncode=1)\n        WHEN detected\n        THEN it still returns the system path (graceful degradation)\n\n        WHY: Some verible builds might not support --version or have different flags.\n        Detection should not fail just because version check fails - the binary\n        might still work fine for LSP operations.\n        \"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            custom_settings = SolidLSPSettings.CustomLSSettings({})\n            provider = SystemVerilogLanguageServer.DependencyProvider(custom_settings, temp_dir)\n\n            with patch(\"shutil.which\", return_value=\"/custom/bin/verible-verilog-ls\"):\n                with patch(\"subprocess.run\") as mock_run:\n                    # Version check fails\n                    mock_run.return_value = MagicMock(returncode=1, stdout=\"\", stderr=\"Unknown option: --version\")\n                    result = provider._get_or_install_core_dependency()\n\n        # Should still return the path despite version check failure\n        assert result == \"/custom/bin/verible-verilog-ls\"\n\n    @pytest.mark.systemverilog\n    def test_detect_from_path_handles_version_timeout_gracefully(self):\n        \"\"\"\n        GIVEN verible-verilog-ls is in PATH but --version times out\n        WHEN detected\n        THEN it still returns the system path (graceful degradation)\n\n        WHY: Version check has a timeout to avoid hanging. If it times out,\n        we should still use the detected binary.\n        \"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            custom_settings = SolidLSPSettings.CustomLSSettings({})\n            provider = SystemVerilogLanguageServer.DependencyProvider(custom_settings, temp_dir)\n\n            with patch(\"shutil.which\", return_value=\"/opt/verible/bin/verible-verilog-ls\"):\n                with patch(\"subprocess.run\") as mock_run:\n                    # Version check times out\n                    mock_run.side_effect = subprocess.TimeoutExpired(cmd=[\"verible-verilog-ls\", \"--version\"], timeout=5)\n                    result = provider._get_or_install_core_dependency()\n\n        # Should still return the path despite timeout\n        assert result == \"/opt/verible/bin/verible-verilog-ls\"\n\n    @pytest.mark.systemverilog\n    def test_error_message_when_not_found_anywhere(self):\n        \"\"\"\n        GIVEN verible is NOT in PATH AND platform is unsupported\n        WHEN _get_or_install_core_dependency is called\n        THEN raises FileNotFoundError with helpful installation instructions\n\n        WHY: Users need clear guidance on how to install verible when it's missing.\n        Error message should mention conda, Homebrew, and GitHub releases.\n        \"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            custom_settings = SolidLSPSettings.CustomLSSettings({})\n            provider = SystemVerilogLanguageServer.DependencyProvider(custom_settings, temp_dir)\n\n            with patch(\"shutil.which\", return_value=None):\n                # Mock RuntimeDependencyCollection to raise RuntimeError for unsupported platform\n                with patch(\"solidlsp.language_servers.systemverilog_server.RuntimeDependencyCollection\") as mock_deps_class:\n                    mock_deps = Mock()\n                    mock_deps.get_single_dep_for_current_platform.side_effect = RuntimeError(\"Unsupported platform\")\n                    mock_deps_class.return_value = mock_deps\n\n                    with pytest.raises(FileNotFoundError) as exc_info:\n                        provider._get_or_install_core_dependency()\n\n        error_message = str(exc_info.value)\n        # Error should mention installation methods\n        assert \"conda\" in error_message.lower()\n        assert \"Homebrew\" in error_message or \"brew\" in error_message.lower()\n        assert \"GitHub\" in error_message or \"github.com\" in error_message.lower()\n        assert \"verible\" in error_message.lower()\n\n    @pytest.mark.systemverilog\n    def test_downloads_when_not_in_path(self):\n        \"\"\"\n        GIVEN verible is NOT in PATH AND platform IS supported AND binary exists after download\n        WHEN _get_or_install_core_dependency is called\n        THEN returns the downloaded executable path\n\n        WHY: When verible is not installed system-wide and platform is supported,\n        Serena should auto-download it. This enables zero-setup experience.\n        \"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            custom_settings = SolidLSPSettings.CustomLSSettings({})\n            provider = SystemVerilogLanguageServer.DependencyProvider(custom_settings, temp_dir)\n\n            expected_path = os.path.join(temp_dir, \"verible-ls\", f\"verible-{DEFAULT_VERIBLE_VERSION}\", \"bin\", \"verible-verilog-ls\")\n\n            with patch(\"shutil.which\", return_value=None):\n                with patch(\"solidlsp.language_servers.systemverilog_server.RuntimeDependencyCollection\") as mock_deps_class:\n                    # Create mock dependency and collection\n                    mock_dep = Mock()\n                    mock_dep.url = \"https://github.com/chipsalliance/verible/releases/download/v0.0-4051/verible.tar.gz\"\n\n                    mock_deps = Mock()\n                    mock_deps.get_single_dep_for_current_platform.return_value = mock_dep\n                    mock_deps.binary_path.return_value = expected_path\n                    mock_deps.install.return_value = expected_path\n\n                    mock_deps_class.return_value = mock_deps\n\n                    with patch(\"os.path.exists\") as mock_exists:\n                        # Before download: binary doesn't exist yet → after download: binary exists\n                        mock_exists.side_effect = [False, True]\n\n                        with patch(\"os.chmod\"):\n                            result = provider._get_or_install_core_dependency()\n\n            assert result == expected_path\n            mock_deps.install.assert_called_once()\n\n    @pytest.mark.systemverilog\n    def test_detection_prefers_path_over_download(self):\n        \"\"\"\n        GIVEN verible is in PATH AND download would also work\n        WHEN _get_or_install_core_dependency is called\n        THEN PATH version is used (download never attempted)\n\n        WHY: System-installed verible should always take precedence.\n        This respects user's environment and avoids unnecessary downloads.\n        \"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            custom_settings = SolidLSPSettings.CustomLSSettings({})\n            provider = SystemVerilogLanguageServer.DependencyProvider(custom_settings, temp_dir)\n\n            with patch(\"shutil.which\", return_value=\"/usr/bin/verible-verilog-ls\"):\n                with patch(\"subprocess.run\") as mock_run:\n                    mock_run.return_value = MagicMock(returncode=0, stdout=\"Verible v0.0-4051\", stderr=\"\")\n\n                    with patch(\"solidlsp.language_servers.systemverilog_server.RuntimeDependencyCollection\") as mock_deps_class:\n                        result = provider._get_or_install_core_dependency()\n\n                        # RuntimeDependencyCollection should never be instantiated\n                        mock_deps_class.assert_not_called()\n\n            assert result == \"/usr/bin/verible-verilog-ls\"\n\n    @pytest.mark.systemverilog\n    def test_download_fails_if_binary_not_found_after_install(self):\n        \"\"\"\n        GIVEN verible is NOT in PATH AND platform IS supported\n        WHEN download completes BUT binary still doesn't exist at expected path\n        THEN raises FileNotFoundError\n\n        WHY: If download/extraction fails silently, we should catch it and report clearly.\n        \"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            custom_settings = SolidLSPSettings.CustomLSSettings({})\n            provider = SystemVerilogLanguageServer.DependencyProvider(custom_settings, temp_dir)\n\n            expected_path = os.path.join(temp_dir, \"verible-ls\", f\"verible-{DEFAULT_VERIBLE_VERSION}\", \"bin\", \"verible-verilog-ls\")\n\n            with patch(\"shutil.which\", return_value=None):\n                with patch(\"solidlsp.language_servers.systemverilog_server.RuntimeDependencyCollection\") as mock_deps_class:\n                    mock_dep = Mock()\n                    mock_deps = Mock()\n                    mock_deps.get_single_dep_for_current_platform.return_value = mock_dep\n                    mock_deps.binary_path.return_value = expected_path\n                    mock_deps.install.return_value = expected_path\n                    mock_deps_class.return_value = mock_deps\n\n                    # Binary never appears after install\n                    with patch(\"os.path.exists\", return_value=False):\n                        with pytest.raises(FileNotFoundError) as exc_info:\n                            provider._get_or_install_core_dependency()\n\n            error_message = str(exc_info.value)\n            assert \"verible-verilog-ls not found\" in error_message\n            assert expected_path in error_message\n\n    @pytest.mark.systemverilog\n    def test_uses_already_downloaded_binary_without_reinstalling(self):\n        \"\"\"\n        GIVEN verible is NOT in PATH AND platform IS supported\n        AND binary already exists at download location\n        WHEN _get_or_install_core_dependency is called\n        THEN returns existing path without downloading again\n\n        WHY: Avoid redundant downloads if verible was already downloaded in previous session.\n        This speeds up subsequent runs.\n        \"\"\"\n        with tempfile.TemporaryDirectory() as temp_dir:\n            custom_settings = SolidLSPSettings.CustomLSSettings({})\n            provider = SystemVerilogLanguageServer.DependencyProvider(custom_settings, temp_dir)\n\n            expected_path = os.path.join(temp_dir, \"verible-ls\", f\"verible-{DEFAULT_VERIBLE_VERSION}\", \"bin\", \"verible-verilog-ls\")\n\n            with patch(\"shutil.which\", return_value=None):\n                with patch(\"solidlsp.language_servers.systemverilog_server.RuntimeDependencyCollection\") as mock_deps_class:\n                    mock_dep = Mock()\n                    mock_deps = Mock()\n                    mock_deps.get_single_dep_for_current_platform.return_value = mock_dep\n                    mock_deps.binary_path.return_value = expected_path\n                    mock_deps_class.return_value = mock_deps\n\n                    # Binary already exists\n                    with patch(\"os.path.exists\", return_value=True):\n                        with patch(\"os.chmod\"):\n                            result = provider._get_or_install_core_dependency()\n\n            # Should NOT call install since binary already exists\n            mock_deps.install.assert_not_called()\n            assert result == expected_path\n\n\nclass TestVeribleVerilogLsDetectionIntegration:\n    \"\"\"\n    Integration tests that verify detection works on the current system.\n    These tests are skipped if verible-verilog-ls is not installed.\n    \"\"\"\n\n    @pytest.mark.systemverilog\n    def test_integration_finds_installed_verible(self):\n        \"\"\"\n        GIVEN verible-verilog-ls is installed on this system (via any method)\n        WHEN _get_or_install_core_dependency is called\n        THEN it returns a valid executable path\n\n        This test verifies the detection logic works end-to-end on the current system.\n        \"\"\"\n        # Skip if verible-verilog-ls is not installed\n        if not shutil.which(\"verible-verilog-ls\"):\n            pytest.skip(\"verible-verilog-ls not installed on this system\")\n\n        with tempfile.TemporaryDirectory() as temp_dir:\n            custom_settings = SolidLSPSettings.CustomLSSettings({})\n            provider = SystemVerilogLanguageServer.DependencyProvider(custom_settings, temp_dir)\n\n            result = provider._get_or_install_core_dependency()\n\n        assert result is not None\n        assert os.path.isfile(result)\n        assert os.access(result, os.X_OK)\n"
  },
  {
    "path": "test/solidlsp/terraform/test_terraform_basic.py",
    "content": "\"\"\"\nBasic integration tests for the Terraform language server functionality.\n\nThese tests validate the functionality of the language server APIs\nlike request_references using the test repository.\n\"\"\"\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\n\n@pytest.mark.terraform\nclass TestLanguageServerBasics:\n    \"\"\"Test basic functionality of the Terraform language server.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TERRAFORM], indirect=True)\n    def test_basic_definition(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test basic definition lookup functionality.\"\"\"\n        # Simple test to verify the language server is working\n        file_path = \"main.tf\"\n        # Just try to get document symbols - this should work without hanging\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        assert len(symbols) > 0, \"Should find at least some symbols in main.tf\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TERRAFORM], indirect=True)\n    def test_request_references_aws_instance(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_references on an aws_instance resource.\"\"\"\n        # Get references to an aws_instance resource in main.tf\n        file_path = \"main.tf\"\n        # Find aws_instance resources\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        aws_instance_symbol = next((s for s in symbols[0] if s.get(\"name\") == 'resource \"aws_instance\" \"web_server\"'), None)\n        if not aws_instance_symbol or \"selectionRange\" not in aws_instance_symbol:\n            raise AssertionError(\"aws_instance symbol or its selectionRange not found\")\n        sel_start = aws_instance_symbol[\"selectionRange\"][\"start\"]\n        references = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        assert len(references) >= 1, \"aws_instance should be referenced at least once\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TERRAFORM], indirect=True)\n    def test_request_references_variable(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test request_references on a variable.\"\"\"\n        # Get references to a variable in variables.tf\n        file_path = \"variables.tf\"\n        # Find variable definitions\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        var_symbol = next((s for s in symbols[0] if s.get(\"name\") == 'variable \"instance_type\"'), None)\n        if not var_symbol or \"selectionRange\" not in var_symbol:\n            raise AssertionError(\"variable symbol or its selectionRange not found\")\n        sel_start = var_symbol[\"selectionRange\"][\"start\"]\n        references = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        assert len(references) >= 1, \"variable should be referenced at least once\"\n"
  },
  {
    "path": "test/solidlsp/test_ls_common.py",
    "content": "import os\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\n\nclass TestLanguageServerCommonFunctionality:\n    \"\"\"Test common functionality of SolidLanguageServer base implementation (not language-specific behaviour).\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.PYTHON], indirect=True)\n    def test_open_file_cache_invalidate(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"\n        Tests that the file buffer cache is invalidated when the file is changed on disk.\n        \"\"\"\n        file_path = os.path.join(language_server.repository_root_path, \"test_open_file.py\")\n        test_string1 = \"# foo\"\n        test_string2 = \"# bar\"\n\n        with open(file_path, \"w\") as f:\n            f.write(test_string1)\n\n        try:\n            with language_server.open_file(file_path) as fb:\n                assert fb.contents == test_string1\n\n                # apply external change to file\n                with open(file_path, \"w\") as f:\n                    f.write(test_string2)\n\n                # Explicitly bump mtime into the future so the cache sees a change.\n                # Relying on natural mtime advancement is flaky because many filesystems\n                # (ext4, tmpfs) have only 1-second mtime granularity, and both writes\n                # can land in the same second.\n                stat = os.stat(file_path)\n                os.utime(file_path, (stat.st_atime, stat.st_mtime + 2))\n\n                # check that the file buffer has been invalidated and reloaded\n                assert fb.contents == test_string2\n\n        finally:\n            os.remove(file_path)\n"
  },
  {
    "path": "test/solidlsp/test_lsp_protocol_handler_server.py",
    "content": "\"\"\"\nTests for JSON-RPC 2.0 params field handling in LSP protocol.\n\nThese tests verify the correct handling of the params field in LSP requests and notifications,\nspecifically ensuring:\n- Void-type methods (shutdown, exit) omit params field entirely\n- Methods with explicit params include them unchanged\n- Methods with None params receive params: {} for Delphi/FPC compatibility\n\nReference: JSON-RPC 2.0 spec - params field is optional but must be object/array when present.\n\"\"\"\n\nfrom typing import Any\n\nimport pytest\n\nfrom solidlsp.lsp_protocol_handler.server import make_notification, make_request\n\n# =============================================================================\n# Shared Assertion Helpers (DRY extraction per AI Panel recommendation)\n# =============================================================================\n\n\ndef assert_jsonrpc_structure(\n    result: dict[str, Any],\n    expected_method: str,\n    expected_keys: set[str],\n    *,\n    expected_id: Any | None = None,\n) -> None:\n    \"\"\"Verify JSON-RPC 2.0 structural requirements with 5-point error messages.\n\n    Args:\n        result: The dict returned by make_request/make_notification\n        expected_method: The method name that should be in the result\n        expected_keys: Exact set of keys that should be present\n        expected_id: If provided, verify the id field matches (for requests)\n\n    \"\"\"\n    # Verify jsonrpc field\n    assert \"jsonrpc\" in result, (\n        f\"STRUCTURE ERROR: Missing required 'jsonrpc' field.\\n\"\n        f\"Expected: jsonrpc='2.0'\\n\"\n        f\"Actual keys: {list(result.keys())}\\n\"\n        f\"GUIDANCE: All JSON-RPC 2.0 messages must include jsonrpc field.\"\n    )\n    assert result[\"jsonrpc\"] == \"2.0\", (\n        f\"STRUCTURE ERROR: Invalid jsonrpc version.\\n\"\n        f\"Expected: '2.0'\\n\"\n        f\"Actual: {result['jsonrpc']!r}\\n\"\n        f\"GUIDANCE: JSON-RPC 2.0 requires jsonrpc='2.0' exactly.\"\n    )\n\n    # Verify method field\n    assert \"method\" in result, (\n        f\"STRUCTURE ERROR: Missing required 'method' field.\\n\"\n        f\"Expected: method='{expected_method}'\\n\"\n        f\"Actual keys: {list(result.keys())}\\n\"\n        f\"GUIDANCE: All requests/notifications must include method field.\"\n    )\n    assert result[\"method\"] == expected_method, (\n        f\"STRUCTURE ERROR: Method mismatch.\\n\"\n        f\"Expected: '{expected_method}'\\n\"\n        f\"Actual: {result['method']!r}\\n\"\n        f\"GUIDANCE: Method field must match the requested method name.\"\n    )\n\n    # Verify id field if expected (requests only)\n    if expected_id is not None:\n        assert \"id\" in result, (\n            f\"STRUCTURE ERROR: Missing required 'id' field for request.\\n\"\n            f\"Expected: id={expected_id!r}\\n\"\n            f\"Actual keys: {list(result.keys())}\\n\"\n            f\"GUIDANCE: JSON-RPC 2.0 requests must include id field.\"\n        )\n        assert result[\"id\"] == expected_id, (\n            f\"STRUCTURE ERROR: Request ID mismatch.\\n\"\n            f\"Expected: {expected_id!r}\\n\"\n            f\"Actual: {result['id']!r}\\n\"\n            f\"GUIDANCE: Request ID must be preserved exactly as provided.\"\n        )\n\n    # Verify exact key set\n    actual_keys = set(result.keys())\n    if actual_keys != expected_keys:\n        extra = sorted(actual_keys - expected_keys)\n        missing = sorted(expected_keys - actual_keys)\n        pytest.fail(\n            f\"STRUCTURE ERROR: Key set mismatch for method '{expected_method}'.\\n\"\n            f\"Expected keys: {sorted(expected_keys)}\\n\"\n            f\"Actual keys: {sorted(actual_keys)}\\n\"\n            f\"Extra keys: {extra}\\n\"\n            f\"Missing keys: {missing}\\n\"\n            f\"GUIDANCE: Verify key construction logic for Void-type vs normal methods.\"\n        )\n\n\ndef assert_params_omitted(result: dict[str, Any], method: str, req_id: str, input_params: Any = None) -> None:\n    \"\"\"Assert that params field is NOT present (for Void-type methods).\n\n    Args:\n        result: The dict returned by make_request/make_notification\n        method: Method name for error message context\n        req_id: Requirement ID (e.g., 'REQ-1', 'REQ-AI-PANEL-GAP')\n        input_params: If provided, shows what params were passed (for explicit params tests)\n\n    \"\"\"\n    if \"params\" in result:\n        input_note = f\"\\nInput params: {input_params}\" if input_params is not None else \"\"\n        pytest.fail(\n            f\"{req_id} VIOLATED: {method} method MUST omit params field entirely.{input_note}\\n\"\n            f\"Expected: No 'params' key in result\\n\"\n            f\"Actual: params={result.get('params')!r}\\n\"\n            f\"Actual keys: {list(result.keys())}\\n\"\n            f\"REASON: HLS/rust-analyzer Void types reject any params field (even empty object).\\n\"\n            f\"GUIDANCE: Void-type constraint takes precedence - implementation must omit params entirely.\"\n        )\n\n\ndef assert_params_equal(result: dict[str, Any], expected_params: Any, req_id: str) -> None:\n    \"\"\"Assert that params field equals expected value.\n\n    Args:\n        result: The dict returned by make_request/make_notification\n        expected_params: The exact params value expected\n        req_id: Requirement ID for error message context\n\n    \"\"\"\n    if \"params\" not in result:\n        pytest.fail(\n            f\"{req_id} VIOLATED: params field missing.\\n\"\n            f\"Expected: params={expected_params!r}\\n\"\n            f\"Actual keys: {list(result.keys())}\\n\"\n            f\"GUIDANCE: Non-Void methods must include params field.\"\n        )\n    if result[\"params\"] != expected_params:\n        pytest.fail(\n            f\"{req_id} VIOLATED: params value mismatch.\\n\"\n            f\"Expected: {expected_params!r}\\n\"\n            f\"Actual: {result['params']!r}\\n\"\n            f\"GUIDANCE: Params must be included exactly as provided (or {{}} for None).\"\n        )\n\n\nclass TestMakeNotificationParamsHandling:\n    \"\"\"Test make_notification() params field handling per JSON-RPC 2.0 spec.\"\"\"\n\n    def test_shutdown_method_omits_params_entirely(self) -> None:\n        \"\"\"REQ-1: Void-type method 'shutdown' MUST omit params field entirely.\"\"\"\n        result = make_notification(\"shutdown\", None)\n        assert_jsonrpc_structure(result, \"shutdown\", {\"jsonrpc\", \"method\"})\n        assert_params_omitted(result, \"shutdown\", \"REQ-1\")\n\n    def test_exit_method_omits_params_entirely(self) -> None:\n        \"\"\"REQ-1: Void-type method 'exit' MUST omit params field entirely.\"\"\"\n        result = make_notification(\"exit\", None)\n        assert_jsonrpc_structure(result, \"exit\", {\"jsonrpc\", \"method\"})\n        assert_params_omitted(result, \"exit\", \"REQ-1\")\n\n    def test_notification_with_explicit_params_dict(self) -> None:\n        \"\"\"REQ-2: Methods with explicit params MUST include them unchanged.\"\"\"\n        test_params = {\"uri\": \"file:///test.py\", \"languageId\": \"python\"}\n        result = make_notification(\"textDocument/didOpen\", test_params)\n        assert_jsonrpc_structure(result, \"textDocument/didOpen\", {\"jsonrpc\", \"method\", \"params\"})\n        assert_params_equal(result, test_params, \"REQ-2\")\n\n    def test_notification_with_explicit_params_list(self) -> None:\n        \"\"\"REQ-2: Methods with explicit params (list) MUST include them unchanged.\"\"\"\n        test_params = [\"arg1\", \"arg2\", \"arg3\"]\n        result = make_notification(\"custom/method\", test_params)\n        assert_jsonrpc_structure(result, \"custom/method\", {\"jsonrpc\", \"method\", \"params\"})\n        assert_params_equal(result, test_params, \"REQ-2\")\n\n    def test_notification_with_none_params_sends_empty_dict(self) -> None:\n        \"\"\"REQ-3: Methods with None params MUST send params: {} (Delphi/FPC compat).\"\"\"\n        result = make_notification(\"textDocument/didChange\", None)\n        assert_jsonrpc_structure(result, \"textDocument/didChange\", {\"jsonrpc\", \"method\", \"params\"})\n        assert_params_equal(result, {}, \"REQ-3\")\n\n    def test_notification_with_empty_dict_params(self) -> None:\n        \"\"\"REQ-2: Explicit empty dict params MUST be included unchanged.\"\"\"\n        result = make_notification(\"custom/notify\", {})\n        assert_jsonrpc_structure(result, \"custom/notify\", {\"jsonrpc\", \"method\", \"params\"})\n        assert_params_equal(result, {}, \"REQ-2\")\n\n\nclass TestMakeRequestParamsHandling:\n    \"\"\"Test make_request() params field handling per JSON-RPC 2.0 spec.\"\"\"\n\n    def test_shutdown_request_omits_params_entirely(self) -> None:\n        \"\"\"REQ-1: Void-type method 'shutdown' MUST omit params field entirely (requests).\"\"\"\n        result = make_request(\"shutdown\", request_id=1, params=None)\n        assert_jsonrpc_structure(result, \"shutdown\", {\"jsonrpc\", \"method\", \"id\"}, expected_id=1)\n        assert_params_omitted(result, \"shutdown\", \"REQ-1\")\n\n    def test_request_with_explicit_params_dict(self) -> None:\n        \"\"\"REQ-2: Requests with explicit params MUST include them unchanged.\"\"\"\n        test_params = {\"textDocument\": {\"uri\": \"file:///test.py\"}, \"position\": {\"line\": 10, \"character\": 5}}\n        result = make_request(\"textDocument/hover\", request_id=42, params=test_params)\n        assert_jsonrpc_structure(result, \"textDocument/hover\", {\"jsonrpc\", \"method\", \"id\", \"params\"}, expected_id=42)\n        assert_params_equal(result, test_params, \"REQ-2\")\n\n    def test_request_with_none_params_sends_empty_dict(self) -> None:\n        \"\"\"REQ-3: Requests with None params MUST send params: {} (Delphi/FPC compat).\"\"\"\n        result = make_request(\"workspace/configuration\", request_id=100, params=None)\n        assert_jsonrpc_structure(result, \"workspace/configuration\", {\"jsonrpc\", \"method\", \"id\", \"params\"}, expected_id=100)\n        assert_params_equal(result, {}, \"REQ-3\")\n\n    def test_request_id_preservation(self) -> None:\n        \"\"\"Verify request_id is correctly included in result (string ID).\"\"\"\n        test_id = \"unique-request-123\"\n        result = make_request(\"custom/request\", request_id=test_id, params={\"key\": \"value\"})\n        assert_jsonrpc_structure(result, \"custom/request\", {\"jsonrpc\", \"method\", \"id\", \"params\"}, expected_id=test_id)\n\n    def test_request_with_explicit_params_list(self) -> None:\n        \"\"\"REQ-2: Requests with explicit params (list) MUST include them unchanged.\"\"\"\n        test_params = [1, 2, 3]\n        result = make_request(\"custom/sum\", request_id=99, params=test_params)\n        assert_jsonrpc_structure(result, \"custom/sum\", {\"jsonrpc\", \"method\", \"id\", \"params\"}, expected_id=99)\n        assert_params_equal(result, test_params, \"REQ-2\")\n\n\nclass TestVoidMethodsExhaustive:\n    \"\"\"Test all methods that should be treated as Void-type (no params).\"\"\"\n\n    def test_shutdown_request_ignores_explicit_params_dict(self) -> None:\n        \"\"\"REQ-AI-PANEL-GAP: shutdown MUST omit params even when caller explicitly provides params.\"\"\"\n        explicit_params = {\"key\": \"value\", \"another\": \"param\"}\n        result = make_request(\"shutdown\", request_id=1, params=explicit_params)\n        assert_jsonrpc_structure(result, \"shutdown\", {\"jsonrpc\", \"method\", \"id\"}, expected_id=1)\n        assert_params_omitted(result, \"shutdown\", \"REQ-AI-PANEL-GAP\", input_params=explicit_params)\n\n    def test_exit_notification_ignores_explicit_params(self) -> None:\n        \"\"\"REQ-AI-PANEL-GAP: exit MUST omit params even when caller explicitly provides params.\"\"\"\n        explicit_params = {\"unexpected\": \"params\"}\n        result = make_notification(\"exit\", explicit_params)\n        assert_jsonrpc_structure(result, \"exit\", {\"jsonrpc\", \"method\"})\n        assert_params_omitted(result, \"exit\", \"REQ-AI-PANEL-GAP\", input_params=explicit_params)\n\n    def test_only_shutdown_and_exit_are_void_methods(self) -> None:\n        \"\"\"REQ-BOUNDARY: Verify EXACTLY shutdown/exit are Void-type - no more, no less.\"\"\"\n        # Positive verification: shutdown and exit MUST omit params\n        shutdown_notif = make_notification(\"shutdown\", None)\n        exit_notif = make_notification(\"exit\", None)\n        shutdown_req = make_request(\"shutdown\", 1, None)\n\n        assert \"params\" not in shutdown_notif, \"shutdown notification should omit params\"\n        assert \"params\" not in exit_notif, \"exit notification should omit params\"\n        assert \"params\" not in shutdown_req, \"shutdown request should omit params\"\n\n        # Negative verification: other methods MUST include params (even when None -> {})\n        non_void_methods = [\n            \"initialize\",\n            \"initialized\",\n            \"textDocument/didOpen\",\n            \"textDocument/didChange\",\n            \"textDocument/didClose\",\n            \"workspace/didChangeConfiguration\",\n            \"workspace/didChangeWatchedFiles\",\n        ]\n\n        for method in non_void_methods:\n            result_notif = make_notification(method, None)\n            result_req = make_request(method, 1, None)\n\n            if \"params\" not in result_notif:\n                pytest.fail(\n                    f\"BOUNDARY VIOLATION: '{method}' notification treated as Void-type.\\n\"\n                    f\"Expected: params field present (should be {{}})\\n\"\n                    f\"Actual keys: {list(result_notif.keys())}\\n\"\n                    f\"GUIDANCE: Only 'shutdown' and 'exit' should omit params field.\"\n                )\n            assert_params_equal(result_notif, {}, f\"REQ-3 ({method} notification)\")\n\n            if \"params\" not in result_req:\n                pytest.fail(\n                    f\"BOUNDARY VIOLATION: '{method}' request treated as Void-type.\\n\"\n                    f\"Expected: params field present (should be {{}})\\n\"\n                    f\"Actual keys: {list(result_req.keys())}\\n\"\n                    f\"GUIDANCE: Only 'shutdown' and 'exit' should omit params field.\"\n                )\n            assert_params_equal(result_req, {}, f\"REQ-3 ({method} request)\")\n"
  },
  {
    "path": "test/solidlsp/test_rename_didopen.py",
    "content": "from unittest.mock import MagicMock\n\nfrom solidlsp.ls import SolidLanguageServer\n\n\nclass DummyLanguageServer(SolidLanguageServer):\n    def _start_server(self) -> None:\n        raise AssertionError(\"Not used in this test\")\n\n\ndef test_request_rename_symbol_edit_opens_file_before_rename(tmp_path) -> None:\n    (tmp_path / \"index.ts\").write_text(\"export const x = 1;\\n\", encoding=\"utf-8\")\n\n    events: list[str] = []\n\n    notify = MagicMock()\n    notify.did_open_text_document.side_effect = lambda *_args, **_kwargs: events.append(\"didOpen\")\n    notify.did_close_text_document.side_effect = lambda *_args, **_kwargs: events.append(\"didClose\")\n\n    send = MagicMock()\n    send.rename.side_effect = lambda *_args, **_kwargs: events.append(\"rename\")\n\n    server = MagicMock()\n    server.notify = notify\n    server.send = send\n\n    language_server = object.__new__(DummyLanguageServer)\n    language_server.repository_root_path = str(tmp_path)\n    language_server.server_started = True\n    language_server.open_file_buffers = {}\n    language_server._encoding = \"utf-8\"\n    language_server.language_id = \"typescript\"\n    language_server.server = server\n\n    result = language_server.request_rename_symbol_edit(\n        relative_file_path=\"index.ts\",\n        line=0,\n        column=0,\n        new_name=\"y\",\n    )\n    assert result is None\n    assert events == [\"didOpen\", \"rename\", \"didClose\"]\n"
  },
  {
    "path": "test/solidlsp/toml/__init__.py",
    "content": "\"\"\"TOML language server tests.\"\"\"\n"
  },
  {
    "path": "test/solidlsp/toml/test_toml_basic.py",
    "content": "\"\"\"\nBasic integration tests for the TOML language server functionality.\n\nThese tests validate the functionality of the Taplo language server APIs\nlike request_document_symbols using the TOML test repository.\n\"\"\"\n\nfrom pathlib import Path\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\n\n@pytest.mark.toml\nclass TestTomlLanguageServerBasics:\n    \"\"\"Test basic functionality of the TOML language server (Taplo).\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_toml_language_server_initialization(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that TOML language server can be initialized successfully.\"\"\"\n        assert language_server is not None\n        assert language_server.language == Language.TOML\n        assert language_server.is_running()\n        assert Path(language_server.language_server.repository_root_path).resolve() == repo_path.resolve()\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_toml_cargo_file_symbols(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test document symbols detection in Cargo.toml with specific symbol verification.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"Cargo.toml\").get_all_symbols_and_roots()\n\n        assert all_symbols is not None, \"Should return symbols for Cargo.toml\"\n        assert len(all_symbols) > 0, f\"Should find symbols in Cargo.toml, found {len(all_symbols)}\"\n\n        # Verify specific top-level table names are detected\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n        assert \"package\" in symbol_names, \"Should detect 'package' table in Cargo.toml\"\n        assert \"dependencies\" in symbol_names, \"Should detect 'dependencies' table in Cargo.toml\"\n        assert \"dev-dependencies\" in symbol_names, \"Should detect 'dev-dependencies' table in Cargo.toml\"\n        assert \"features\" in symbol_names, \"Should detect 'features' table in Cargo.toml\"\n        assert \"workspace\" in symbol_names, \"Should detect 'workspace' table in Cargo.toml\"\n\n        # Verify nested symbols exist (keys under 'package')\n        assert \"name\" in symbol_names, \"Should detect nested 'name' key\"\n        assert \"version\" in symbol_names, \"Should detect nested 'version' key\"\n        assert \"edition\" in symbol_names, \"Should detect nested 'edition' key\"\n\n        # Check symbol kind for tables - Taplo uses kind 19 (object) for TOML tables\n        package_symbol = next((s for s in all_symbols if s.get(\"name\") == \"package\"), None)\n        assert package_symbol is not None, \"Should find 'package' symbol\"\n        assert package_symbol.get(\"kind\") == 19, \"Top-level table should have kind 19 (object)\"\n\n        dependencies_symbol = next((s for s in all_symbols if s.get(\"name\") == \"dependencies\"), None)\n        assert dependencies_symbol is not None, \"Should find 'dependencies' symbol\"\n        assert dependencies_symbol.get(\"kind\") == 19, \"'dependencies' table should have kind 19 (object)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_toml_pyproject_file_symbols(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test document symbols detection in pyproject.toml.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"pyproject.toml\").get_all_symbols_and_roots()\n\n        assert all_symbols is not None, \"Should return symbols for pyproject.toml\"\n        assert len(all_symbols) > 0, f\"Should find symbols in pyproject.toml, found {len(all_symbols)}\"\n\n        # Verify specific top-level table names\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n        assert \"project\" in symbol_names, \"Should detect 'project' table\"\n        assert \"build-system\" in symbol_names, \"Should detect 'build-system' table\"\n\n        # Verify tool sections (nested tables)\n        # These could appear as 'tool' or 'tool.ruff' depending on Taplo's parsing\n        has_tool_section = any(\"tool\" in name for name in symbol_names if name)\n        assert has_tool_section, \"Should detect tool sections\"\n\n        # Verify nested keys under project\n        assert \"name\" in symbol_names, \"Should detect 'name' under project\"\n        assert \"version\" in symbol_names, \"Should detect 'version' under project\"\n        assert \"requires-python\" in symbol_names or \"dependencies\" in symbol_names, \"Should detect project dependencies\"\n\n        # Check symbol kind for tables - Taplo uses kind 19 (object) for TOML tables\n        project_symbol = next((s for s in all_symbols if s.get(\"name\") == \"project\"), None)\n        assert project_symbol is not None, \"Should find 'project' symbol\"\n        assert project_symbol.get(\"kind\") == 19, \"'project' table should have kind 19 (object)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_toml_symbol_kinds(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that TOML symbols have appropriate LSP kinds for different value types.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"Cargo.toml\").get_all_symbols_and_roots()\n\n        assert all_symbols is not None\n        assert len(all_symbols) > 0\n\n        # Check boolean symbol kind (lto = true at line 22)\n        # LSP kind 17 = boolean\n        lto_symbol = next((s for s in all_symbols if s.get(\"name\") == \"lto\"), None)\n        assert lto_symbol is not None, \"Should find 'lto' boolean symbol\"\n        assert lto_symbol.get(\"kind\") == 17, \"'lto' should have kind 17 (boolean)\"\n\n        # Check number symbol kind (opt-level = 3 at line 23)\n        # LSP kind 16 = number\n        opt_level_symbol = next((s for s in all_symbols if s.get(\"name\") == \"opt-level\"), None)\n        assert opt_level_symbol is not None, \"Should find 'opt-level' number symbol\"\n        assert opt_level_symbol.get(\"kind\") == 16, \"'opt-level' should have kind 16 (number)\"\n\n        # Check string symbol kind (name = \"test_project\" at line 2)\n        # LSP kind 15 = string\n        name_symbols = [s for s in all_symbols if s.get(\"name\") == \"name\"]\n        assert len(name_symbols) > 0, \"Should find 'name' symbols\"\n        # At least one should be a string\n        string_name_symbol = next((s for s in name_symbols if s.get(\"kind\") == 15), None)\n        assert string_name_symbol is not None, \"Should find 'name' with kind 15 (string)\"\n\n        # Check array symbol kind (default = [\"feature1\"] at line 17)\n        # LSP kind 18 = array\n        default_symbol = next((s for s in all_symbols if s.get(\"name\") == \"default\"), None)\n        assert default_symbol is not None, \"Should find 'default' array symbol\"\n        assert default_symbol.get(\"kind\") == 18, \"'default' should have kind 18 (array)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_toml_symbols_with_body(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test request_document_symbols with body extraction.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"Cargo.toml\").get_all_symbols_and_roots()\n\n        assert all_symbols is not None, \"Should return symbols for Cargo.toml\"\n        assert len(all_symbols) > 0, \"Should have symbols\"\n\n        # Find the 'package' symbol and verify its body\n        package_symbol = next((s for s in all_symbols if s.get(\"name\") == \"package\"), None)\n        assert package_symbol is not None, \"Should find 'package' symbol\"\n\n        # Check that body exists and contains expected content\n        # Note: Taplo includes the section header in the body\n        assert \"body\" in package_symbol, \"'package' symbol should have body\"\n        package_body = package_symbol[\"body\"].get_text()\n        assert 'name = \"test_project\"' in package_body, \"Body should contain 'name' field\"\n        assert 'version = \"0.1.0\"' in package_body, \"Body should contain 'version' field\"\n        assert 'edition = \"2021\"' in package_body, \"Body should contain 'edition' field\"\n\n        # Find the dependencies symbol and check its body\n        deps_symbol = next((s for s in all_symbols if s.get(\"name\") == \"dependencies\"), None)\n        assert deps_symbol is not None, \"Should find 'dependencies' symbol\"\n        assert \"body\" in deps_symbol, \"'dependencies' symbol should have body\"\n        deps_body = deps_symbol[\"body\"].get_text()\n        assert \"serde\" in deps_body, \"Body should contain serde dependency\"\n        assert \"tokio\" in deps_body, \"Body should contain tokio dependency\"\n\n        # Find the top-level [features] section (not the nested 'features' in serde dependency)\n        # The [features] section should be kind 19 (object) and at line 15 (0-indexed)\n        features_symbols = [s for s in all_symbols if s.get(\"name\") == \"features\"]\n        # Find the top-level one - should be kind 19 (object) with children\n        features_symbol = next(\n            (s for s in features_symbols if s.get(\"kind\") == 19 and s.get(\"children\")),\n            None,\n        )\n        assert features_symbol is not None, \"Should find top-level 'features' table symbol\"\n        assert \"body\" in features_symbol, \"'features' symbol should have body\"\n        features_body = features_symbol[\"body\"].get_text()\n        assert \"default\" in features_body, \"Body should contain 'default' feature\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_toml_symbol_ranges(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that symbols have proper range information.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"Cargo.toml\").get_all_symbols_and_roots()\n\n        assert all_symbols is not None\n        assert len(all_symbols) > 0\n\n        # Check the 'package' symbol range - should start at line 0 (0-indexed, actual line 1)\n        package_symbol = next((s for s in all_symbols if s.get(\"name\") == \"package\"), None)\n        assert package_symbol is not None, \"Should find 'package' symbol\"\n        assert \"range\" in package_symbol, \"'package' symbol should have range\"\n\n        package_range = package_symbol[\"range\"]\n        assert \"start\" in package_range, \"Range should have start\"\n        assert \"end\" in package_range, \"Range should have end\"\n        assert package_range[\"start\"][\"line\"] == 0, \"'package' should start at line 0 (0-indexed, actual line 1)\"\n        # Package block spans from line 1 to line 7 in file (1-indexed)\n        # In 0-indexed LSP coordinates: line 0 (start) to line 6 or 7 (end)\n        assert package_range[\"end\"][\"line\"] >= 6, \"'package' should end at or after line 6 (0-indexed)\"\n\n        # Check a nested symbol range - 'name' under package at line 2 (1-indexed), line 1 (0-indexed)\n        name_symbols = [s for s in all_symbols if s.get(\"name\") == \"name\"]\n        assert len(name_symbols) > 0, \"Should find 'name' symbols\"\n        # Find the one under 'package' (should be at line 1 in 0-indexed)\n        package_name = next((s for s in name_symbols if s[\"range\"][\"start\"][\"line\"] == 1), None)\n        assert package_name is not None, \"Should find 'name' under 'package'\"\n\n        # Check the dependencies range - starts at line 9 (1-indexed), line 8 (0-indexed)\n        deps_symbol = next((s for s in all_symbols if s.get(\"name\") == \"dependencies\"), None)\n        assert deps_symbol is not None, \"Should find 'dependencies' symbol\"\n        deps_range = deps_symbol[\"range\"]\n        assert deps_range[\"start\"][\"line\"] == 8, \"'dependencies' should start at line 8 (0-indexed, actual line 9)\"\n\n        # Check that range includes line and character positions\n        assert \"line\" in package_range[\"start\"], \"Start should have line\"\n        assert \"character\" in package_range[\"start\"], \"Start should have character\"\n        assert \"line\" in package_range[\"end\"], \"End should have line\"\n        assert \"character\" in package_range[\"end\"], \"End should have character\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_toml_nested_table_symbols(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test detection of nested table symbols like profile.release and tool.ruff.\"\"\"\n        # Test Cargo.toml for profile.release\n        cargo_symbols, _ = language_server.request_document_symbols(\"Cargo.toml\").get_all_symbols_and_roots()\n\n        assert cargo_symbols is not None\n        symbol_names = [sym.get(\"name\") for sym in cargo_symbols]\n\n        # Should detect profile.release or profile section\n        has_profile = any(\"profile\" in name for name in symbol_names if name)\n        assert has_profile, \"Should detect profile section in Cargo.toml\"\n\n        # Test pyproject.toml for tool sections\n        pyproject_symbols, _ = language_server.request_document_symbols(\"pyproject.toml\").get_all_symbols_and_roots()\n\n        assert pyproject_symbols is not None\n        pyproject_names = [sym.get(\"name\") for sym in pyproject_symbols]\n\n        # Should detect tool.ruff, tool.mypy sections\n        has_ruff = any(\"ruff\" in name for name in pyproject_names if name)\n        has_mypy = any(\"mypy\" in name for name in pyproject_names if name)\n        assert has_ruff or has_mypy, \"Should detect tool sections in pyproject.toml\"\n\n        # Verify pyproject has expected boolean: strict = true\n        strict_symbol = next((s for s in pyproject_symbols if s.get(\"name\") == \"strict\"), None)\n        if strict_symbol:\n            assert strict_symbol.get(\"kind\") == 17, \"'strict' should have kind 17 (boolean)\"\n"
  },
  {
    "path": "test/solidlsp/toml/test_toml_edge_cases.py",
    "content": "\"\"\"\nTests for TOML language server edge cases and advanced features.\n\nThese tests cover:\n- Inline tables\n- Multiline strings\n- Arrays of tables\n- Nested tables\n- Various TOML data types\n\"\"\"\n\nfrom pathlib import Path\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\npytestmark = pytest.mark.toml\n\n\nclass TestTomlEdgeCases:\n    \"\"\"Test TOML language server handling of edge cases and advanced features.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_inline_table_detection(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that inline tables are properly detected.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"config.toml\").get_all_symbols_and_roots()\n\n        assert all_symbols is not None\n        assert len(all_symbols) > 0\n\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n\n        # The inline table 'endpoint' should be detected\n        assert \"endpoint\" in symbol_names, \"Should detect 'endpoint' inline table\"\n\n        # Find the endpoint symbol and check its properties\n        endpoint_symbol = next((s for s in all_symbols if s.get(\"name\") == \"endpoint\"), None)\n        assert endpoint_symbol is not None\n        # Inline tables should be kind 19 (object)\n        assert endpoint_symbol.get(\"kind\") == 19, \"Inline table should have kind 19 (object)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_nested_table_detection(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that deeply nested tables are properly detected.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"config.toml\").get_all_symbols_and_roots()\n\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n\n        # Should detect nested tables like server.ssl and database.pool\n        has_ssl = any(\"ssl\" in str(name).lower() for name in symbol_names if name)\n        has_pool = any(\"pool\" in str(name).lower() for name in symbol_names if name)\n\n        assert has_ssl, f\"Should detect 'server.ssl' nested table, got: {symbol_names}\"\n        assert has_pool, f\"Should detect 'database.pool' nested table, got: {symbol_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_array_of_tables_detection(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that [[array_of_tables]] syntax is properly detected.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"config.toml\").get_all_symbols_and_roots()\n\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n\n        # Should detect [[endpoints]] array of tables\n        assert \"endpoints\" in symbol_names, f\"Should detect '[[endpoints]]' array of tables, got: {symbol_names}\"\n\n        # Find the endpoints symbol\n        endpoints_symbol = next((s for s in all_symbols if s.get(\"name\") == \"endpoints\"), None)\n        assert endpoints_symbol is not None\n\n        # Array of tables should be kind 18 (array)\n        assert endpoints_symbol.get(\"kind\") == 18, \"Array of tables should have kind 18 (array)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_multiline_string_handling(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that multiline strings are handled correctly.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"config.toml\").get_all_symbols_and_roots()\n\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n\n        # Should detect connection_string and multiline fields\n        assert \"connection_string\" in symbol_names, \"Should detect 'connection_string' with multiline value\"\n        assert \"multiline\" in symbol_names, \"Should detect 'multiline' literal string\"\n\n        # Find connection_string and verify it's a string type\n        conn_symbol = next((s for s in all_symbols if s.get(\"name\") == \"connection_string\"), None)\n        assert conn_symbol is not None\n        # String type should be kind 15\n        assert conn_symbol.get(\"kind\") == 15, \"Multiline string should have kind 15 (string)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_array_value_detection(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that array values are properly detected.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"config.toml\").get_all_symbols_and_roots()\n\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n\n        # Should detect 'outputs' and 'methods' arrays\n        assert \"outputs\" in symbol_names, \"Should detect 'outputs' array\"\n        assert \"methods\" in symbol_names, \"Should detect 'methods' array\"\n\n        # Find outputs array and verify kind\n        outputs_symbol = next((s for s in all_symbols if s.get(\"name\") == \"outputs\"), None)\n        assert outputs_symbol is not None\n        # Arrays should have kind 18\n        assert outputs_symbol.get(\"kind\") == 18, \"'outputs' should have kind 18 (array)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_float_value_detection(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that float values are properly detected.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"config.toml\").get_all_symbols_and_roots()\n\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n\n        # Should detect 'timeout' which has a float value (30.5)\n        assert \"timeout\" in symbol_names, \"Should detect 'timeout' float value\"\n\n        # Find timeout and verify it's a number\n        timeout_symbol = next((s for s in all_symbols if s.get(\"name\") == \"timeout\"), None)\n        assert timeout_symbol is not None\n        # Numbers should have kind 16\n        assert timeout_symbol.get(\"kind\") == 16, \"'timeout' should have kind 16 (number)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_datetime_value_detection(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that datetime values are detected.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"config.toml\").get_all_symbols_and_roots()\n\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n\n        # Should detect metadata section with datetime values\n        assert \"metadata\" in symbol_names, \"Should detect 'metadata' section\"\n        assert \"created\" in symbol_names, \"Should detect 'created' datetime field\"\n        assert \"updated\" in symbol_names, \"Should detect 'updated' datetime field\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_symbol_body_with_inline_table(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that symbol bodies include inline table content.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"config.toml\").get_all_symbols_and_roots()\n\n        # Find the endpoint symbol with body\n        endpoint_symbol = next((s for s in all_symbols if s.get(\"name\") == \"endpoint\"), None)\n        assert endpoint_symbol is not None\n\n        if \"body\" in endpoint_symbol:\n            body = endpoint_symbol[\"body\"].get_text()\n            # Body should contain the inline table syntax\n            assert \"url\" in body or \"version\" in body, f\"Body should contain inline table contents, got: {body}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_symbol_ranges_in_config(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that symbol ranges are correct in config.toml.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"config.toml\").get_all_symbols_and_roots()\n\n        # Find the server symbol\n        server_symbol = next((s for s in all_symbols if s.get(\"name\") == \"server\"), None)\n        assert server_symbol is not None\n        assert \"range\" in server_symbol\n\n        # Server should start near the beginning (line 2 is [server], 0-indexed: line 2)\n        server_range = server_symbol[\"range\"]\n        assert server_range[\"start\"][\"line\"] >= 0, \"Server should start at or near the beginning\"\n        assert server_range[\"end\"][\"line\"] > server_range[\"start\"][\"line\"], \"Server block should span multiple lines\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_comment_handling(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that comments don't interfere with symbol detection.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"config.toml\").get_all_symbols_and_roots()\n\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n\n        # File has comments but symbols should still be detected correctly\n        expected_sections = {\"server\", \"database\", \"logging\", \"endpoints\", \"metadata\", \"messages\"}\n        found_sections = expected_sections.intersection(set(symbol_names))\n\n        assert len(found_sections) >= 4, f\"Should find most sections despite comments, found: {found_sections}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_special_characters_in_strings(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that strings with escape sequences are handled.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"config.toml\").get_all_symbols_and_roots()\n\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n\n        # Should detect the messages section with special strings\n        assert \"messages\" in symbol_names, \"Should detect 'messages' section\"\n        assert \"with_escapes\" in symbol_names, \"Should detect 'with_escapes' field\"\n        assert \"welcome\" in symbol_names, \"Should detect 'welcome' field\"\n\n\nclass TestTomlDependencyTables:\n    \"\"\"Test handling of dependency-style tables common in Cargo.toml and pyproject.toml.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_complex_dependency_inline_table(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test detection of complex inline table dependencies like serde = { version = \"1.0\", features = [\"derive\"] }.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"Cargo.toml\").get_all_symbols_and_roots()\n\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n\n        # Should detect serde and tokio dependencies\n        assert \"serde\" in symbol_names, \"Should detect 'serde' dependency\"\n        assert \"tokio\" in symbol_names, \"Should detect 'tokio' dependency\"\n\n        # Find serde symbol\n        serde_symbol = next((s for s in all_symbols if s.get(\"name\") == \"serde\"), None)\n        assert serde_symbol is not None\n\n        # Dependency with inline table should be kind 19 (object)\n        assert serde_symbol.get(\"kind\") == 19, \"Complex dependency should have kind 19 (object)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_simple_dependency_string(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test detection of simple string dependencies like proptest = \"1.0\".\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"Cargo.toml\").get_all_symbols_and_roots()\n\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n\n        # Should detect proptest dev-dependency\n        assert \"proptest\" in symbol_names, \"Should detect 'proptest' dependency\"\n\n        # Find proptest symbol\n        proptest_symbol = next((s for s in all_symbols if s.get(\"name\") == \"proptest\"), None)\n        assert proptest_symbol is not None\n\n        # Simple string dependency should be kind 15 (string)\n        assert proptest_symbol.get(\"kind\") == 15, \"Simple string dependency should have kind 15 (string)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_pyproject_dependencies_array(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test detection of pyproject.toml dependencies array.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"pyproject.toml\").get_all_symbols_and_roots()\n\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n\n        # Should detect dependencies array\n        assert \"dependencies\" in symbol_names, \"Should detect 'dependencies' array\"\n\n        # Find dependencies symbol\n        deps_symbol = next((s for s in all_symbols if s.get(\"name\") == \"dependencies\"), None)\n        assert deps_symbol is not None\n\n        # Dependencies array should be kind 18 (array)\n        assert deps_symbol.get(\"kind\") == 18, \"Dependencies array should have kind 18 (array)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_optional_dependencies_table(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test detection of optional-dependencies in pyproject.toml.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"pyproject.toml\").get_all_symbols_and_roots()\n\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n\n        # Should detect optional-dependencies or its nested form\n        has_optional_deps = any(\"optional\" in str(name).lower() for name in symbol_names if name)\n        has_dev = \"dev\" in symbol_names\n\n        assert has_optional_deps or has_dev, f\"Should detect optional-dependencies or dev group, got: {symbol_names}\"\n"
  },
  {
    "path": "test/solidlsp/toml/test_toml_ignored_dirs.py",
    "content": "\"\"\"\nTests for TOML language server directory ignoring functionality.\n\nThese tests validate that the Taplo language server correctly ignores\nTOML-specific directories like target, .cargo, and node_modules.\n\"\"\"\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\npytestmark = pytest.mark.toml\n\n\n@pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\nclass TestTomlIgnoredDirectories:\n    \"\"\"Test TOML-specific directory ignoring behavior.\"\"\"\n\n    def test_default_ignored_directories(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that default TOML directories are ignored.\"\"\"\n        # Test that TOML/Rust/Node-specific directories are ignored by default\n        assert language_server.is_ignored_dirname(\"target\"), \"target should be ignored\"\n        assert language_server.is_ignored_dirname(\".cargo\"), \".cargo should be ignored\"\n        assert language_server.is_ignored_dirname(\"node_modules\"), \"node_modules should be ignored\"\n\n        # Directories starting with . are ignored by base class\n        assert language_server.is_ignored_dirname(\".git\"), \".git should be ignored\"\n        assert language_server.is_ignored_dirname(\".venv\"), \".venv should be ignored\"\n\n    def test_important_directories_not_ignored(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that important directories are not ignored.\"\"\"\n        # Common project directories should not be ignored\n        assert not language_server.is_ignored_dirname(\"src\"), \"src should not be ignored\"\n        assert not language_server.is_ignored_dirname(\"crates\"), \"crates should not be ignored\"\n        assert not language_server.is_ignored_dirname(\"lib\"), \"lib should not be ignored\"\n        assert not language_server.is_ignored_dirname(\"tests\"), \"tests should not be ignored\"\n        assert not language_server.is_ignored_dirname(\"config\"), \"config should not be ignored\"\n\n    def test_cargo_related_directories(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test Cargo/Rust-related directory handling.\"\"\"\n        # Rust build directories should be ignored\n        assert language_server.is_ignored_dirname(\"target\"), \"target (Rust build) should be ignored\"\n        assert language_server.is_ignored_dirname(\".cargo\"), \".cargo should be ignored\"\n\n        # But important Rust directories should not be ignored\n        assert not language_server.is_ignored_dirname(\"benches\"), \"benches should not be ignored\"\n        assert not language_server.is_ignored_dirname(\"examples\"), \"examples should not be ignored\"\n\n    def test_various_cache_directories(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test various cache and temporary directories are ignored.\"\"\"\n        # Directories starting with . are ignored by base class\n        assert language_server.is_ignored_dirname(\".cache\"), \".cache should be ignored\"\n\n        # IDE directories (start with .)\n        assert language_server.is_ignored_dirname(\".idea\"), \".idea should be ignored\"\n        assert language_server.is_ignored_dirname(\".vscode\"), \".vscode should be ignored\"\n\n        # Note: __pycache__ is NOT ignored by TOML server (only Python servers ignore it)\n        assert not language_server.is_ignored_dirname(\"__pycache__\"), \"__pycache__ is not TOML-specific\"\n"
  },
  {
    "path": "test/solidlsp/toml/test_toml_symbol_retrieval.py",
    "content": "\"\"\"\nTests for TOML language server symbol retrieval functionality.\n\nThese tests focus on advanced symbol operations:\n- request_containing_symbol\n- request_document_overview\n- request_full_symbol_tree\n- request_dir_overview\n\"\"\"\n\nfrom pathlib import Path\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\npytestmark = pytest.mark.toml\n\n\nclass TestTomlSymbolRetrieval:\n    \"\"\"Test advanced symbol retrieval functionality for TOML files.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_request_containing_symbol_behavior(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test request_containing_symbol behavior for TOML files.\n\n        Note: Taplo LSP doesn't support definition/containing symbol lookups for TOML files\n        since TOML is a configuration format, not code. This test verifies the behavior.\n        \"\"\"\n        # Line 2 (0-indexed: 1) is inside the [package] table\n        containing_symbol = language_server.request_containing_symbol(\"Cargo.toml\", 1, 5)\n\n        # Taplo doesn't support containing symbol lookup - returns None\n        # This is expected behavior for a configuration file format\n        assert containing_symbol is None, \"TOML LSP doesn't support containing symbol lookup\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_request_document_overview_cargo(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test request_document_overview for Cargo.toml.\"\"\"\n        overview = language_server.request_document_overview(\"Cargo.toml\")\n\n        assert overview is not None\n        assert len(overview) > 0\n\n        # Get symbol names from overview\n        symbol_names = {symbol.get(\"name\") for symbol in overview if \"name\" in symbol}\n\n        # Verify expected top-level tables appear\n        expected_tables = {\"package\", \"dependencies\", \"dev-dependencies\", \"features\", \"workspace\"}\n        assert expected_tables.issubset(symbol_names), f\"Missing expected tables in overview: {expected_tables - symbol_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_request_document_overview_pyproject(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test request_document_overview for pyproject.toml.\"\"\"\n        overview = language_server.request_document_overview(\"pyproject.toml\")\n\n        assert overview is not None\n        assert len(overview) > 0\n\n        # Get symbol names from overview\n        symbol_names = {symbol.get(\"name\") for symbol in overview if \"name\" in symbol}\n\n        # Verify expected top-level tables appear\n        assert \"project\" in symbol_names, \"Should detect 'project' table\"\n        assert \"build-system\" in symbol_names, \"Should detect 'build-system' table\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_request_full_symbol_tree(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test request_full_symbol_tree returns TOML files.\"\"\"\n        symbol_tree = language_server.request_full_symbol_tree()\n\n        assert symbol_tree is not None\n        assert len(symbol_tree) > 0\n\n        # The root should be test_repo\n        root = symbol_tree[0]\n        assert root[\"name\"] == \"test_repo\"\n        assert \"children\" in root\n\n        # Children should include TOML files\n        child_names = {child[\"name\"] for child in root.get(\"children\", [])}\n        # Note: File names are stripped of extension in some cases\n        assert (\n            \"Cargo\" in child_names or \"Cargo.toml\" in child_names or any(\"cargo\" in name.lower() for name in child_names)\n        ), f\"Should find Cargo.toml in tree, got: {child_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_request_dir_overview(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test request_dir_overview returns symbols for TOML files.\"\"\"\n        overview = language_server.request_dir_overview(\".\")\n\n        assert overview is not None\n        assert len(overview) > 0\n\n        # Should have entries for both Cargo.toml and pyproject.toml\n        file_paths = list(overview.keys())\n        assert any(\"Cargo.toml\" in path for path in file_paths), f\"Should find Cargo.toml in overview, got: {file_paths}\"\n        assert any(\"pyproject.toml\" in path for path in file_paths), f\"Should find pyproject.toml in overview, got: {file_paths}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_symbol_hierarchy_in_cargo(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that symbol hierarchy is properly preserved in Cargo.toml.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"Cargo.toml\").get_all_symbols_and_roots()\n\n        # Find the 'package' table\n        package_symbol = next((s for s in root_symbols if s.get(\"name\") == \"package\"), None)\n        assert package_symbol is not None, \"Should find 'package' as root symbol\"\n\n        # Verify it has children (nested keys)\n        assert \"children\" in package_symbol, \"'package' should have children\"\n        child_names = {child.get(\"name\") for child in package_symbol.get(\"children\", [])}\n\n        # Package should have name, version, edition at minimum\n        assert \"name\" in child_names, \"'package' should have 'name' child\"\n        assert \"version\" in child_names, \"'package' should have 'version' child\"\n        assert \"edition\" in child_names, \"'package' should have 'edition' child\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_symbol_hierarchy_in_pyproject(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that symbol hierarchy is properly preserved in pyproject.toml.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"pyproject.toml\").get_all_symbols_and_roots()\n\n        # Find the 'project' table\n        project_symbol = next((s for s in root_symbols if s.get(\"name\") == \"project\"), None)\n        assert project_symbol is not None, \"Should find 'project' as root symbol\"\n\n        # Verify it has children\n        assert \"children\" in project_symbol, \"'project' should have children\"\n        child_names = {child.get(\"name\") for child in project_symbol.get(\"children\", [])}\n\n        # Project should have name, version, dependencies at minimum\n        assert \"name\" in child_names, \"'project' should have 'name' child\"\n        assert \"version\" in child_names, \"'project' should have 'version' child\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_tool_section_hierarchy(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that tool sections in pyproject.toml are properly structured.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"pyproject.toml\").get_all_symbols_and_roots()\n\n        # Get all symbol names\n        all_names = [s.get(\"name\") for s in all_symbols]\n\n        # Should detect tool.ruff, tool.mypy, or tool.pytest\n        has_ruff = any(\"ruff\" in name.lower() for name in all_names if name)\n        has_mypy = any(\"mypy\" in name.lower() for name in all_names if name)\n        has_pytest = any(\"pytest\" in name.lower() for name in all_names if name)\n\n        assert has_ruff or has_mypy or has_pytest, f\"Should detect tool sections, got names: {all_names}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TOML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.TOML], indirect=True)\n    def test_array_of_tables_symbol(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that [[bin]] array of tables is detected.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"Cargo.toml\").get_all_symbols_and_roots()\n\n        # Get all symbol names\n        all_names = [s.get(\"name\") for s in all_symbols]\n\n        # Should detect bin array of tables\n        has_bin = \"bin\" in all_names\n        assert has_bin, f\"Should detect [[bin]] array of tables, got names: {all_names}\"\n\n        # Find the bin symbol and verify its structure\n        bin_symbol = next((s for s in all_symbols if s.get(\"name\") == \"bin\"), None)\n        assert bin_symbol is not None, \"Should find bin symbol\"\n\n        # Array of tables should be kind 18 (array)\n        assert bin_symbol.get(\"kind\") == 18, \"[[bin]] should have kind 18 (array)\"\n\n        # Children of array of tables are indexed by position ('0', '1', etc.)\n        if \"children\" in bin_symbol:\n            bin_children = bin_symbol.get(\"children\", [])\n            assert len(bin_children) > 0, \"[[bin]] should have at least one child element\"\n            # First child is index '0'\n            first_child = bin_children[0]\n            assert first_child.get(\"name\") == \"0\", f\"First array element should be named '0', got: {first_child.get('name')}\"\n\n            # The '0' element should contain name and path as grandchildren\n            if \"children\" in first_child:\n                grandchild_names = {gc.get(\"name\") for gc in first_child.get(\"children\", [])}\n                assert \"name\" in grandchild_names, f\"[[bin]] element should have 'name' field, got: {grandchild_names}\"\n                assert \"path\" in grandchild_names, f\"[[bin]] element should have 'path' field, got: {grandchild_names}\"\n"
  },
  {
    "path": "test/solidlsp/typescript/test_typescript_basic.py",
    "content": "import os\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_utils import SymbolUtils\n\n\n@pytest.mark.typescript\nclass TestTypescriptLanguageServer:\n    @pytest.mark.parametrize(\"language_server\", [Language.TYPESCRIPT], indirect=True)\n    def test_find_symbol(self, language_server: SolidLanguageServer) -> None:\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"DemoClass\"), \"DemoClass not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"helperFunction\"), \"helperFunction not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"printValue\"), \"printValue method not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.TYPESCRIPT], indirect=True)\n    def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:\n        file_path = os.path.join(\"index.ts\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        helper_symbol = None\n        for sym in symbols[0]:\n            if sym.get(\"name\") == \"helperFunction\":\n                helper_symbol = sym\n                break\n        assert helper_symbol is not None, \"Could not find 'helperFunction' symbol in index.ts\"\n        sel_start = helper_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n        assert any(\n            \"index.ts\" in ref.get(\"relativePath\", \"\") for ref in refs\n        ), \"index.ts should reference helperFunction (tried all positions in selectionRange)\"\n"
  },
  {
    "path": "test/solidlsp/util/test_zip.py",
    "content": "import sys\nimport zipfile\nfrom pathlib import Path\n\nimport pytest\n\nfrom solidlsp.util.zip import SafeZipExtractor\n\n\n@pytest.fixture\ndef temp_zip_file(tmp_path: Path) -> Path:\n    \"\"\"Create a temporary ZIP file for testing.\"\"\"\n    zip_path = tmp_path / \"test.zip\"\n    with zipfile.ZipFile(zip_path, \"w\") as zipf:\n        zipf.writestr(\"file1.txt\", \"Hello World 1\")\n        zipf.writestr(\"file2.txt\", \"Hello World 2\")\n        zipf.writestr(\"folder/file3.txt\", \"Hello World 3\")\n    return zip_path\n\n\ndef test_extract_all_success(temp_zip_file: Path, tmp_path: Path) -> None:\n    \"\"\"All files should extract without error.\"\"\"\n    dest_dir = tmp_path / \"extracted\"\n    extractor = SafeZipExtractor(temp_zip_file, dest_dir, verbose=False)\n    extractor.extract_all()\n\n    assert (dest_dir / \"file1.txt\").read_text() == \"Hello World 1\"\n    assert (dest_dir / \"file2.txt\").read_text() == \"Hello World 2\"\n    assert (dest_dir / \"folder\" / \"file3.txt\").read_text() == \"Hello World 3\"\n\n\ndef test_include_patterns(temp_zip_file: Path, tmp_path: Path) -> None:\n    \"\"\"Only files matching include_patterns should be extracted.\"\"\"\n    dest_dir = tmp_path / \"extracted\"\n    extractor = SafeZipExtractor(temp_zip_file, dest_dir, verbose=False, include_patterns=[\"*.txt\"])\n    extractor.extract_all()\n\n    assert (dest_dir / \"file1.txt\").exists()\n    assert (dest_dir / \"file2.txt\").exists()\n    assert (dest_dir / \"folder\" / \"file3.txt\").exists()\n\n\ndef test_exclude_patterns(temp_zip_file: Path, tmp_path: Path) -> None:\n    \"\"\"Files matching exclude_patterns should be skipped.\"\"\"\n    dest_dir = tmp_path / \"extracted\"\n    extractor = SafeZipExtractor(temp_zip_file, dest_dir, verbose=False, exclude_patterns=[\"file2.txt\"])\n    extractor.extract_all()\n\n    assert (dest_dir / \"file1.txt\").exists()\n    assert not (dest_dir / \"file2.txt\").exists()\n    assert (dest_dir / \"folder\" / \"file3.txt\").exists()\n\n\ndef test_include_and_exclude_patterns(temp_zip_file: Path, tmp_path: Path) -> None:\n    \"\"\"Exclude should override include if both match.\"\"\"\n    dest_dir = tmp_path / \"extracted\"\n    extractor = SafeZipExtractor(\n        temp_zip_file,\n        dest_dir,\n        verbose=False,\n        include_patterns=[\"*.txt\"],\n        exclude_patterns=[\"file1.txt\"],\n    )\n    extractor.extract_all()\n\n    assert not (dest_dir / \"file1.txt\").exists()\n    assert (dest_dir / \"file2.txt\").exists()\n    assert (dest_dir / \"folder\" / \"file3.txt\").exists()\n\n\ndef test_skip_on_error(monkeypatch, temp_zip_file: Path, tmp_path: Path) -> None:\n    \"\"\"Should skip a file that raises an error and continue extracting others.\"\"\"\n    dest_dir = tmp_path / \"extracted\"\n\n    original_open = zipfile.ZipFile.open\n\n    def failing_open(self, member, *args, **kwargs):\n        if member.filename == \"file2.txt\":\n            raise OSError(\"Simulated failure\")\n        return original_open(self, member, *args, **kwargs)\n\n    # Patch the method on the class, not on an instance\n    monkeypatch.setattr(zipfile.ZipFile, \"open\", failing_open)\n\n    extractor = SafeZipExtractor(temp_zip_file, dest_dir, verbose=False)\n    extractor.extract_all()\n\n    assert (dest_dir / \"file1.txt\").exists()\n    assert not (dest_dir / \"file2.txt\").exists()\n    assert (dest_dir / \"folder\" / \"file3.txt\").exists()\n\n\n@pytest.mark.skipif(not sys.platform.startswith(\"win\"), reason=\"Windows-only test\")\ndef test_long_path_normalization(temp_zip_file: Path, tmp_path: Path) -> None:\n    r\"\"\"Ensure _normalize_path adds \\\\?\\\\ prefix on Windows.\"\"\"\n    dest_dir = tmp_path / (\"a\" * 250)  # Simulate long path\n    extractor = SafeZipExtractor(temp_zip_file, dest_dir, verbose=False)\n    norm_path = extractor._normalize_path(dest_dir / \"file.txt\")\n    assert str(norm_path).startswith(\"\\\\\\\\?\\\\\")\n"
  },
  {
    "path": "test/solidlsp/vue/__init__.py",
    "content": "\"\"\"Vue language server tests.\"\"\"\n\nimport shutil\n\n\ndef _test_npm_available() -> str:\n    \"\"\"Test if npm is available and return error reason if not.\"\"\"\n    # Check if npm is installed\n    if not shutil.which(\"npm\"):\n        return \"npm is not installed or not in PATH\"\n    return \"\"  # No error, npm is available\n\n\nNPM_UNAVAILABLE_REASON = _test_npm_available()\nNPM_UNAVAILABLE = bool(NPM_UNAVAILABLE_REASON)\n"
  },
  {
    "path": "test/solidlsp/vue/test_vue_basic.py",
    "content": "import os\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_utils import SymbolUtils\n\n\n@pytest.mark.vue\nclass TestVueLanguageServer:\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_vue_files_in_symbol_tree(self, language_server: SolidLanguageServer) -> None:\n        symbols = language_server.request_full_symbol_tree()\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"App\"), \"App not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"CalculatorButton\"), \"CalculatorButton not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"CalculatorInput\"), \"CalculatorInput not found in symbol tree\"\n        assert SymbolUtils.symbol_tree_contains_name(symbols, \"CalculatorDisplay\"), \"CalculatorDisplay not found in symbol tree\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:\n        store_file = os.path.join(\"src\", \"stores\", \"calculator.ts\")\n        symbols = language_server.request_document_symbols(store_file).get_all_symbols_and_roots()\n\n        # Find useCalculatorStore function\n        store_symbol = None\n        for sym in symbols[0]:\n            if sym.get(\"name\") == \"useCalculatorStore\":\n                store_symbol = sym\n                break\n\n        assert store_symbol is not None, \"useCalculatorStore function not found\"\n\n        # Get references\n        sel_start = store_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(store_file, sel_start[\"line\"], sel_start[\"character\"])\n\n        # Should have multiple references: definition + usage in App.vue, CalculatorInput.vue, CalculatorDisplay.vue\n        assert len(refs) >= 4, f\"useCalculatorStore should have at least 4 references (definition + 3 usages), got {len(refs)}\"\n\n        # Verify we have references from .vue files\n        vue_refs = [ref for ref in refs if \".vue\" in ref.get(\"relativePath\", \"\")]\n        assert len(vue_refs) >= 3, f\"Should have at least 3 Vue component references, got {len(vue_refs)}\"\n\n\n@pytest.mark.vue\nclass TestVueDualLspArchitecture:\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_typescript_server_coordination(self, language_server: SolidLanguageServer) -> None:\n        ts_file = os.path.join(\"src\", \"stores\", \"calculator.ts\")\n        ts_symbols = language_server.request_document_symbols(ts_file).get_all_symbols_and_roots()\n        ts_symbol_names = [s.get(\"name\") for s in ts_symbols[0]]\n\n        assert len(ts_symbols[0]) >= 5, f\"TypeScript server should return multiple symbols for calculator.ts, got {len(ts_symbols[0])}\"\n        assert \"useCalculatorStore\" in ts_symbol_names, \"TypeScript server should extract store function\"\n\n        # Verify Vue server can parse .vue files\n        vue_file = os.path.join(\"src\", \"App.vue\")\n        vue_symbols = language_server.request_document_symbols(vue_file).get_all_symbols_and_roots()\n        vue_symbol_names = [s.get(\"name\") for s in vue_symbols[0]]\n\n        assert len(vue_symbols[0]) >= 15, f\"Vue server should return at least 15 symbols for App.vue, got {len(vue_symbols[0])}\"\n        assert \"appTitle\" in vue_symbol_names, \"Vue server should extract ref declarations from script setup\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_cross_file_references_vue_to_typescript(self, language_server: SolidLanguageServer) -> None:\n        store_file = os.path.join(\"src\", \"stores\", \"calculator.ts\")\n        store_symbols = language_server.request_document_symbols(store_file).get_all_symbols_and_roots()\n\n        store_symbol = None\n        for sym in store_symbols[0]:\n            if sym.get(\"name\") == \"useCalculatorStore\":\n                store_symbol = sym\n                break\n\n        if not store_symbol or \"selectionRange\" not in store_symbol:\n            pytest.skip(\"useCalculatorStore symbol not found - test fixture may need updating\")\n\n        # Request references for this symbol\n        sel_start = store_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(store_file, sel_start[\"line\"], sel_start[\"character\"])\n\n        # Verify we found references: definition + usage in App.vue, CalculatorInput.vue, CalculatorDisplay.vue\n        assert len(refs) >= 4, f\"useCalculatorStore should have at least 4 references (definition + 3 usages), found {len(refs)} references\"\n\n        # Verify references include .vue files (components that import the store)\n        vue_refs = [ref for ref in refs if \".vue\" in ref.get(\"uri\", \"\")]\n        assert (\n            len(vue_refs) >= 3\n        ), f\"Should find at least 3 references in Vue components, found {len(vue_refs)}: {[ref.get('uri', '') for ref in vue_refs]}\"\n\n        # Verify specific components that use the store\n        expected_vue_files = [\"App.vue\", \"CalculatorInput.vue\", \"CalculatorDisplay.vue\"]\n        found_components = []\n        for expected_file in expected_vue_files:\n            matching_refs = [ref for ref in vue_refs if expected_file in ref.get(\"uri\", \"\")]\n            if matching_refs:\n                found_components.append(expected_file)\n\n        assert len(found_components) > 0, (\n            f\"Should find references in at least one component that uses the store. \"\n            f\"Expected any of {expected_vue_files}, found references in: {[ref.get('uri', '') for ref in vue_refs]}\"\n        )\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_cross_file_references_typescript_to_vue(self, language_server: SolidLanguageServer) -> None:\n        types_file = os.path.join(\"src\", \"types\", \"index.ts\")\n        types_symbols = language_server.request_document_symbols(types_file).get_all_symbols_and_roots()\n        types_symbol_names = [s.get(\"name\") for s in types_symbols[0]]\n\n        # Operation type is used in calculator.ts and CalculatorInput.vue\n        assert \"Operation\" in types_symbol_names, \"Operation type should exist in types file\"\n\n        operation_symbol = None\n        for sym in types_symbols[0]:\n            if sym.get(\"name\") == \"Operation\":\n                operation_symbol = sym\n                break\n\n        if not operation_symbol or \"selectionRange\" not in operation_symbol:\n            pytest.skip(\"Operation type symbol not found - test fixture may need updating\")\n\n        # Request references for the Operation type\n        sel_start = operation_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(types_file, sel_start[\"line\"], sel_start[\"character\"])\n\n        # Verify we found references: definition + usage in calculator.ts and Vue files\n        assert len(refs) >= 2, f\"Operation type should have at least 2 references (definition + usages), found {len(refs)} references\"\n\n        # The Operation type should be referenced in both .ts files (calculator.ts) and potentially .vue files\n        all_ref_uris = [ref.get(\"uri\", \"\") for ref in refs]\n        has_ts_refs = any(\".ts\" in uri and \"types\" not in uri for uri in all_ref_uris)\n\n        assert (\n            has_ts_refs\n        ), f\"Operation type should be referenced in TypeScript files like calculator.ts. Found references in: {all_ref_uris}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_reference_deduplication(self, language_server: SolidLanguageServer) -> None:\n        store_file = os.path.join(\"src\", \"stores\", \"calculator.ts\")\n        store_symbols = language_server.request_document_symbols(store_file).get_all_symbols_and_roots()\n\n        # Find a commonly-used symbol (useCalculatorStore)\n        store_symbol = None\n        for sym in store_symbols[0]:\n            if sym.get(\"name\") == \"useCalculatorStore\":\n                store_symbol = sym\n                break\n\n        if not store_symbol or \"selectionRange\" not in store_symbol:\n            pytest.skip(\"useCalculatorStore symbol not found - test fixture may need updating\")\n\n        # Request references\n        sel_start = store_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(store_file, sel_start[\"line\"], sel_start[\"character\"])\n\n        # Check for duplicate references (same file, line, and character)\n        seen_locations = set()\n        duplicates = []\n\n        for ref in refs:\n            # Create a unique key for this reference location\n            uri = ref.get(\"uri\", \"\")\n            if \"range\" in ref:\n                line = ref[\"range\"][\"start\"][\"line\"]\n                character = ref[\"range\"][\"start\"][\"character\"]\n                location_key = (uri, line, character)\n\n                if location_key in seen_locations:\n                    duplicates.append(location_key)\n                else:\n                    seen_locations.add(location_key)\n\n        assert len(duplicates) == 0, (\n            f\"Found {len(duplicates)} duplicate reference locations. \"\n            f\"The dual-LSP architecture should deduplicate references from both servers. \"\n            f\"Duplicates: {duplicates}\"\n        )\n\n\n@pytest.mark.vue\nclass TestVueEdgeCases:\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_symbol_tree_structure(self, language_server: SolidLanguageServer) -> None:\n        full_tree = language_server.request_full_symbol_tree()\n\n        # Helper to extract all file paths from symbol tree\n        def extract_paths_from_tree(symbols, paths=None):\n            \"\"\"Recursively extract file paths from symbol tree.\"\"\"\n            if paths is None:\n                paths = []\n\n            if isinstance(symbols, list):\n                for symbol in symbols:\n                    extract_paths_from_tree(symbol, paths)\n            elif isinstance(symbols, dict):\n                # Check if this symbol has a location\n                if \"location\" in symbols and \"uri\" in symbols[\"location\"]:\n                    uri = symbols[\"location\"][\"uri\"]\n                    # Extract the path after file://\n                    if uri.startswith(\"file://\"):\n                        file_path = uri[7:]  # Remove \"file://\"\n                        paths.append(file_path)\n\n                # Recurse into children\n                if \"children\" in symbols:\n                    extract_paths_from_tree(symbols[\"children\"], paths)\n\n            return paths\n\n        all_paths = extract_paths_from_tree(full_tree)\n\n        # Verify we have files from expected directories\n        # Note: Symbol tree may include duplicate paths (one per symbol in file)\n        components_files = list({p for p in all_paths if \"components\" in p and \".vue\" in p})\n        stores_files = list({p for p in all_paths if \"stores\" in p and \".ts\" in p})\n        composables_files = list({p for p in all_paths if \"composables\" in p and \".ts\" in p})\n\n        assert len(components_files) == 3, (\n            f\"Symbol tree should include exactly 3 unique Vue components (CalculatorButton, CalculatorInput, CalculatorDisplay). \"\n            f\"Found {len(components_files)} unique component files: {[p.split('/')[-1] for p in sorted(components_files)]}\"\n        )\n\n        assert len(stores_files) == 1, (\n            f\"Symbol tree should include exactly 1 unique store file (calculator.ts). \"\n            f\"Found {len(stores_files)} unique store files: {[p.split('/')[-1] for p in sorted(stores_files)]}\"\n        )\n\n        assert len(composables_files) == 2, (\n            f\"Symbol tree should include exactly 2 unique composable files (useFormatter.ts, useTheme.ts). \"\n            f\"Found {len(composables_files)} unique composable files: {[p.split('/')[-1] for p in sorted(composables_files)]}\"\n        )\n\n        # Verify specific expected files exist in the tree\n        expected_files = [\n            \"CalculatorButton.vue\",\n            \"CalculatorInput.vue\",\n            \"CalculatorDisplay.vue\",\n            \"App.vue\",\n            \"calculator.ts\",\n            \"useFormatter.ts\",\n            \"useTheme.ts\",\n        ]\n\n        for expected_file in expected_files:\n            matching_files = [p for p in all_paths if expected_file in p]\n            assert len(matching_files) > 0, f\"Expected file '{expected_file}' should be in symbol tree. All paths: {all_paths}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_document_overview(self, language_server: SolidLanguageServer) -> None:\n        app_file = os.path.join(\"src\", \"App.vue\")\n        overview = language_server.request_document_overview(app_file)\n\n        # Overview should return a list of top-level symbols\n        assert isinstance(overview, list), f\"Overview should be a list, got: {type(overview)}\"\n        assert len(overview) >= 1, f\"App.vue should have at least 1 top-level symbol in overview, got {len(overview)}\"\n\n        # Extract symbol names from overview\n        symbol_names = [s.get(\"name\") for s in overview if isinstance(s, dict)]\n\n        # Vue LSP returns SFC structure (template/script/style sections) for .vue files\n        # This is expected behavior - overview shows the file's high-level structure\n        assert (\n            len(symbol_names) >= 1\n        ), f\"Should have at least 1 symbol name in overview (e.g., 'App' or SFC section), got {len(symbol_names)}: {symbol_names}\"\n\n        # Test overview for a TypeScript file\n        store_file = os.path.join(\"src\", \"stores\", \"calculator.ts\")\n        store_overview = language_server.request_document_overview(store_file)\n\n        assert isinstance(store_overview, list), f\"Store overview should be a list, got: {type(store_overview)}\"\n        assert len(store_overview) >= 1, f\"calculator.ts should have at least 1 top-level symbol in overview, got {len(store_overview)}\"\n\n        store_symbol_names = [s.get(\"name\") for s in store_overview if isinstance(s, dict)]\n        assert (\n            \"useCalculatorStore\" in store_symbol_names\n        ), f\"useCalculatorStore should be in store file overview. Found {len(store_symbol_names)} symbols: {store_symbol_names}\"\n\n        # Test overview for another Vue component\n        button_file = os.path.join(\"src\", \"components\", \"CalculatorButton.vue\")\n        button_overview = language_server.request_document_overview(button_file)\n\n        assert isinstance(button_overview, list), f\"Button overview should be a list, got: {type(button_overview)}\"\n        assert (\n            len(button_overview) >= 1\n        ), f\"CalculatorButton.vue should have at least 1 top-level symbol in overview, got {len(button_overview)}\"\n\n        # For Vue files, overview provides SFC structure which is useful for navigation\n        # The detailed symbols are available via request_document_symbols\n        button_symbol_names = [s.get(\"name\") for s in button_overview if isinstance(s, dict)]\n        assert len(button_symbol_names) >= 1, (\n            f\"CalculatorButton.vue should have at least 1 symbol in overview (e.g., 'CalculatorButton' or SFC section). \"\n            f\"Found {len(button_symbol_names)} symbols: {button_symbol_names}\"\n        )\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_directory_overview(self, language_server: SolidLanguageServer) -> None:\n        components_dir = os.path.join(\"src\", \"components\")\n        dir_overview = language_server.request_dir_overview(components_dir)\n\n        # Directory overview should be a dict mapping file paths to symbol lists\n        assert isinstance(dir_overview, dict), f\"Directory overview should be a dict, got: {type(dir_overview)}\"\n        assert len(dir_overview) == 3, f\"src/components directory should have exactly 3 files in overview, got {len(dir_overview)}\"\n\n        # Verify all component files are included\n        expected_components = [\"CalculatorButton.vue\", \"CalculatorInput.vue\", \"CalculatorDisplay.vue\"]\n\n        for expected_component in expected_components:\n            # Find files that match this component name\n            matching_files = [path for path in dir_overview.keys() if expected_component in path]\n            assert len(matching_files) == 1, (\n                f\"Component '{expected_component}' should appear exactly once in directory overview. \"\n                f\"Found {len(matching_files)} matches. All files: {list(dir_overview.keys())}\"\n            )\n\n            # Verify the matched file has symbols\n            file_path = matching_files[0]\n            symbols = dir_overview[file_path]\n            assert isinstance(symbols, list), f\"Symbols for {file_path} should be a list, got {type(symbols)}\"\n            assert len(symbols) >= 1, f\"Component {expected_component} should have at least 1 symbol in overview, got {len(symbols)}\"\n\n        # Test overview for stores directory\n        stores_dir = os.path.join(\"src\", \"stores\")\n        stores_overview = language_server.request_dir_overview(stores_dir)\n\n        assert isinstance(stores_overview, dict), f\"Stores overview should be a dict, got: {type(stores_overview)}\"\n        assert (\n            len(stores_overview) == 1\n        ), f\"src/stores directory should have exactly 1 file (calculator.ts) in overview, got {len(stores_overview)}\"\n\n        # Verify calculator.ts is included\n        calculator_files = [path for path in stores_overview.keys() if \"calculator.ts\" in path]\n        assert len(calculator_files) == 1, (\n            f\"calculator.ts should appear exactly once in stores directory overview. \"\n            f\"Found {len(calculator_files)} matches. All files: {list(stores_overview.keys())}\"\n        )\n\n        # Verify the store file has symbols\n        store_path = calculator_files[0]\n        store_symbols = stores_overview[store_path]\n        store_symbol_names = [s.get(\"name\") for s in store_symbols if isinstance(s, dict)]\n        assert (\n            \"useCalculatorStore\" in store_symbol_names\n        ), f\"calculator.ts should have useCalculatorStore in overview. Found {len(store_symbol_names)} symbols: {store_symbol_names}\"\n\n        # Test overview for composables directory\n        composables_dir = os.path.join(\"src\", \"composables\")\n        composables_overview = language_server.request_dir_overview(composables_dir)\n\n        assert isinstance(composables_overview, dict), f\"Composables overview should be a dict, got: {type(composables_overview)}\"\n        assert (\n            len(composables_overview) == 2\n        ), f\"src/composables directory should have exactly 2 files in overview, got {len(composables_overview)}\"\n\n        # Verify composable files are included\n        expected_composables = [\"useFormatter.ts\", \"useTheme.ts\"]\n        for expected_composable in expected_composables:\n            matching_files = [path for path in composables_overview.keys() if expected_composable in path]\n            assert len(matching_files) == 1, (\n                f\"Composable '{expected_composable}' should appear exactly once in directory overview. \"\n                f\"Found {len(matching_files)} matches. All files: {list(composables_overview.keys())}\"\n            )\n"
  },
  {
    "path": "test/solidlsp/vue/test_vue_error_cases.py",
    "content": "import os\nimport sys\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\npytestmark = pytest.mark.vue\n\nIS_WINDOWS = sys.platform == \"win32\"\n\n\nclass TypeScriptServerBehavior:\n    \"\"\"Platform-specific TypeScript language server behavior for invalid positions.\n\n    On Windows: TS server returns empty results for invalid positions\n    On macOS/Linux: TS server raises exceptions with \"Bad line number\" or \"Debug Failure\"\n    \"\"\"\n\n    @staticmethod\n    def raises_on_invalid_position() -> bool:\n        return not IS_WINDOWS\n\n    @staticmethod\n    def returns_empty_on_invalid_position() -> bool:\n        return IS_WINDOWS\n\n\nclass TestVueInvalidPositions:\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_negative_line_number(self, language_server: SolidLanguageServer) -> None:\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        result = language_server.request_containing_symbol(file_path, -1, 0)\n\n        assert result is None or result == {}, f\"Negative line number should return None or empty dict, got: {result}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_negative_character_number(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting containing symbol with negative character number.\n\n        Expected behavior: Should return None or empty dict, not crash.\n        \"\"\"\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        # Request containing symbol at invalid negative character\n        result = language_server.request_containing_symbol(file_path, 10, -1)\n\n        # Should handle gracefully - return None or empty dict\n        assert result is None or result == {}, f\"Negative character number should return None or empty dict, got: {result}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_line_number_beyond_file_length(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting containing symbol beyond file length.\n\n        Expected behavior: Raises IndexError when trying to access line beyond file bounds.\n        This happens in the wrapper code before even reaching the language server.\n        \"\"\"\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        # Request containing symbol at line 99999 (way beyond file length)\n        # The wrapper code will raise an IndexError when checking if the line is empty\n        with pytest.raises(IndexError) as exc_info:\n            language_server.request_containing_symbol(file_path, 99999, 0)\n\n        # Verify it's an index error for list access\n        assert \"list index out of range\" in str(exc_info.value), f\"Expected 'list index out of range' error, got: {exc_info.value}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_character_number_beyond_line_length(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting containing symbol beyond line length.\n\n        Expected behavior: Should return None or empty dict, not crash.\n        \"\"\"\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        # Request containing symbol at character 99999 (way beyond line length)\n        result = language_server.request_containing_symbol(file_path, 10, 99999)\n\n        # Should handle gracefully - return None or empty dict\n        assert result is None or result == {}, f\"Character beyond line length should return None or empty dict, got: {result}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_references_at_negative_line(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting references with negative line number.\"\"\"\n        from solidlsp.ls_exceptions import SolidLSPException\n\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        if TypeScriptServerBehavior.returns_empty_on_invalid_position():\n            result = language_server.request_references(file_path, -1, 0)\n            assert result == [], f\"Expected empty list on Windows, got: {result}\"\n        else:\n            with pytest.raises(SolidLSPException) as exc_info:\n                language_server.request_references(file_path, -1, 0)\n            assert \"Bad line number\" in str(exc_info.value) or \"Debug Failure\" in str(exc_info.value)\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_definition_at_invalid_position(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting definition at invalid position.\"\"\"\n        from solidlsp.ls_exceptions import SolidLSPException\n\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        if TypeScriptServerBehavior.returns_empty_on_invalid_position():\n            result = language_server.request_definition(file_path, -1, 0)\n            assert result == [], f\"Expected empty list on Windows, got: {result}\"\n        else:\n            with pytest.raises(SolidLSPException) as exc_info:\n                language_server.request_definition(file_path, -1, 0)\n            assert \"Bad line number\" in str(exc_info.value) or \"Debug Failure\" in str(exc_info.value)\n\n\nclass TestVueNonExistentFiles:\n    \"\"\"Tests for handling non-existent files.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_document_symbols_nonexistent_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting document symbols from non-existent file.\n\n        Expected behavior: Should raise FileNotFoundError or return empty result.\n        \"\"\"\n        nonexistent_file = os.path.join(\"src\", \"components\", \"NonExistent.vue\")\n\n        # Should raise an appropriate exception or return empty result\n        try:\n            result = language_server.request_document_symbols(nonexistent_file)\n            # If no exception, verify result is empty or indicates file not found\n            symbols = result.get_all_symbols_and_roots()\n            assert len(symbols[0]) == 0, f\"Non-existent file should return empty symbols, got {len(symbols[0])} symbols\"\n        except (FileNotFoundError, Exception) as e:\n            # Expected - file doesn't exist\n            assert True, f\"Appropriately raised exception for non-existent file: {e}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_containing_symbol_nonexistent_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting containing symbol from non-existent file.\n\n        Expected behavior: Should raise FileNotFoundError or return None.\n        \"\"\"\n        nonexistent_file = os.path.join(\"src\", \"components\", \"NonExistent.vue\")\n\n        # Should raise an appropriate exception or return None\n        try:\n            result = language_server.request_containing_symbol(nonexistent_file, 10, 10)\n            # If no exception, verify result indicates file not found\n            assert result is None or result == {}, f\"Non-existent file should return None or empty dict, got: {result}\"\n        except (FileNotFoundError, Exception) as e:\n            # Expected - file doesn't exist\n            assert True, f\"Appropriately raised exception for non-existent file: {e}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_references_nonexistent_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting references from non-existent file.\n\n        Expected behavior: Should raise FileNotFoundError or return empty list.\n        \"\"\"\n        nonexistent_file = os.path.join(\"src\", \"components\", \"NonExistent.vue\")\n\n        # Should raise an appropriate exception or return empty list\n        try:\n            result = language_server.request_references(nonexistent_file, 10, 10)\n            # If no exception, verify result is empty\n            assert result is None or isinstance(result, list), f\"Non-existent file should return None or list, got: {result}\"\n            if isinstance(result, list):\n                assert len(result) == 0, f\"Non-existent file should return empty list, got {len(result)} references\"\n        except (FileNotFoundError, Exception) as e:\n            # Expected - file doesn't exist\n            assert True, f\"Appropriately raised exception for non-existent file: {e}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_definition_nonexistent_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting definition from non-existent file.\n\n        Expected behavior: Should raise FileNotFoundError or return empty list.\n        \"\"\"\n        nonexistent_file = os.path.join(\"src\", \"components\", \"NonExistent.vue\")\n\n        # Should raise an appropriate exception or return empty list\n        try:\n            result = language_server.request_definition(nonexistent_file, 10, 10)\n            # If no exception, verify result is empty\n            assert isinstance(result, list), f\"request_definition should return a list, got: {type(result)}\"\n            assert len(result) == 0, f\"Non-existent file should return empty list, got {len(result)} definitions\"\n        except (FileNotFoundError, Exception) as e:\n            # Expected - file doesn't exist\n            assert True, f\"Appropriately raised exception for non-existent file: {e}\"\n\n\nclass TestVueUndefinedSymbols:\n    \"\"\"Tests for handling undefined or unreferenced symbols.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_references_for_unreferenced_symbol(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting references for a symbol that has no references.\n\n        Expected behavior: Should return empty list (only the definition itself if include_self=True).\n        \"\"\"\n        # Find a symbol that likely has no external references\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorButton.vue\")\n\n        # Get document symbols\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        # Find pressCount - this is exposed but may not be referenced elsewhere\n        press_count_symbol = next((s for s in symbols[0] if s.get(\"name\") == \"pressCount\"), None)\n\n        if not press_count_symbol or \"selectionRange\" not in press_count_symbol:\n            pytest.skip(\"pressCount symbol not found - test fixture may need updating\")\n\n        # Request references without include_self\n        sel_start = press_count_symbol[\"selectionRange\"][\"start\"]\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n\n        # Should return a list (may be empty or contain only definition)\n        assert isinstance(refs, list), f\"request_references should return a list, got {type(refs)}\"\n\n        # For an unreferenced symbol, should have 0-1 references (0 without include_self, 1 with)\n        # The exact count depends on the language server implementation\n        assert len(refs) <= 5, (\n            f\"pressCount should have few or no external references. \"\n            f\"Got {len(refs)} references. This is not necessarily an error, just documenting behavior.\"\n        )\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_containing_symbol_at_whitespace_only_line(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting containing symbol at a whitespace-only line.\n\n        Expected behavior: Should return None, empty dict, or the parent symbol.\n        \"\"\"\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        # Try position at line 1 (typically a blank line or template start in Vue SFCs)\n        result = language_server.request_containing_symbol(file_path, 1, 0)\n\n        # Should handle gracefully - return None, empty dict, or a valid parent symbol\n        assert (\n            result is None or result == {} or isinstance(result, dict)\n        ), f\"Whitespace line should return None, empty dict, or valid symbol. Got: {result}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_definition_at_keyword_position(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting definition at language keyword position.\n\n        Expected behavior: Should return empty list or handle gracefully.\n        \"\"\"\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        # Try to get definition at a keyword like \"const\", \"import\", etc.\n        # Line 2 typically has \"import\" statement - try position on \"import\" keyword\n        result = language_server.request_definition(file_path, 2, 0)\n\n        # Should handle gracefully - return empty list or valid definitions\n        assert isinstance(result, list), f\"request_definition should return a list, got {type(result)}\"\n\n\nclass TestVueEdgeCasePositions:\n    \"\"\"Tests for edge case positions (0,0 and file boundaries).\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_containing_symbol_at_file_start(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting containing symbol at position (0,0).\n\n        Expected behavior: Should return None, empty dict, or a valid symbol.\n        This position typically corresponds to the start of the file (e.g., <template> tag).\n        \"\"\"\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        # Request containing symbol at position 0,0 (file start)\n        result = language_server.request_containing_symbol(file_path, 0, 0)\n\n        # Should handle gracefully\n        assert (\n            result is None or result == {} or isinstance(result, dict)\n        ), f\"Position 0,0 should return None, empty dict, or valid symbol. Got: {result}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_references_at_file_start(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting references at position (0,0).\n\n        Expected behavior: Should return None or empty list.\n        \"\"\"\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        # Request references at position 0,0 (file start)\n        result = language_server.request_references(file_path, 0, 0)\n\n        # Should handle gracefully\n        assert result is None or isinstance(result, list), f\"Position 0,0 should return None or list. Got: {type(result)}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_definition_at_file_start(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting definition at position (0,0).\n\n        Expected behavior: Should return empty list.\n        \"\"\"\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        # Request definition at position 0,0 (file start)\n        result = language_server.request_definition(file_path, 0, 0)\n\n        # Should handle gracefully\n        assert isinstance(result, list), f\"request_definition should return a list. Got: {type(result)}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_containing_symbol_in_template_section(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting containing symbol in the template section.\n\n        Expected behavior: Template positions typically have no containing symbol (return None or empty).\n        The Vue language server may not track template symbols the same way as script symbols.\n        \"\"\"\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        # Position likely in template section (early in file, before <script setup>)\n        # Exact line depends on file structure, but line 5-10 is often template\n        result = language_server.request_containing_symbol(file_path, 5, 10)\n\n        # Should handle gracefully - template doesn't have containing symbols in the same way\n        assert (\n            result is None or result == {} or isinstance(result, dict)\n        ), f\"Template position should return None, empty dict, or valid symbol. Got: {result}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_zero_character_positions(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting symbols at character position 0 (start of lines).\n\n        Expected behavior: Should handle gracefully, may or may not find symbols.\n        \"\"\"\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        # Test multiple lines at character 0\n        for line in [0, 10, 20, 30]:\n            result = language_server.request_containing_symbol(file_path, line, 0)\n\n            # Should handle gracefully\n            assert (\n                result is None or result == {} or isinstance(result, dict)\n            ), f\"Line {line}, character 0 should return None, empty dict, or valid symbol. Got: {result}\"\n\n\nclass TestVueTypescriptFileErrors:\n    \"\"\"Tests for error handling in TypeScript files within Vue projects.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_typescript_file_invalid_position(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting symbols from TypeScript file at invalid position.\n\n        Expected behavior: Should handle gracefully.\n        \"\"\"\n        file_path = os.path.join(\"src\", \"stores\", \"calculator.ts\")\n\n        # Request containing symbol at invalid position\n        result = language_server.request_containing_symbol(file_path, -1, -1)\n\n        # Should handle gracefully\n        assert result is None or result == {}, f\"Invalid position in .ts file should return None or empty dict. Got: {result}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_typescript_file_beyond_bounds(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting symbols from TypeScript file beyond file bounds.\n\n        Expected behavior: Raises IndexError when trying to access line beyond file bounds.\n        \"\"\"\n        file_path = os.path.join(\"src\", \"stores\", \"calculator.ts\")\n\n        # Request containing symbol beyond file bounds\n        # The wrapper code will raise an IndexError when checking if the line is empty\n        with pytest.raises(IndexError) as exc_info:\n            language_server.request_containing_symbol(file_path, 99999, 99999)\n\n        # Verify it's an index error for list access\n        assert \"list index out of range\" in str(exc_info.value), f\"Expected 'list index out of range' error, got: {exc_info.value}\"\n\n\nclass TestVueReferenceEdgeCases:\n    \"\"\"Tests for edge cases in reference finding.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_referencing_symbols_at_invalid_position(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting referencing symbols at invalid position.\"\"\"\n        from solidlsp.ls_exceptions import SolidLSPException\n\n        file_path = os.path.join(\"src\", \"stores\", \"calculator.ts\")\n\n        if TypeScriptServerBehavior.returns_empty_on_invalid_position():\n            result = list(language_server.request_referencing_symbols(file_path, -1, -1, include_self=False))\n            assert result == [], f\"Expected empty list on Windows, got: {result}\"\n        else:\n            with pytest.raises(SolidLSPException) as exc_info:\n                list(language_server.request_referencing_symbols(file_path, -1, -1, include_self=False))\n            assert \"Bad line number\" in str(exc_info.value) or \"Debug Failure\" in str(exc_info.value)\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_defining_symbol_at_invalid_position(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting defining symbol at invalid position.\"\"\"\n        from solidlsp.ls_exceptions import SolidLSPException\n\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        if TypeScriptServerBehavior.returns_empty_on_invalid_position():\n            result = language_server.request_defining_symbol(file_path, -1, -1)\n            assert result is None, f\"Expected None on Windows, got: {result}\"\n        else:\n            with pytest.raises(SolidLSPException) as exc_info:\n                language_server.request_defining_symbol(file_path, -1, -1)\n            assert \"Bad line number\" in str(exc_info.value) or \"Debug Failure\" in str(exc_info.value)\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_referencing_symbols_beyond_file_bounds(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test requesting referencing symbols beyond file bounds.\"\"\"\n        from solidlsp.ls_exceptions import SolidLSPException\n\n        file_path = os.path.join(\"src\", \"stores\", \"calculator.ts\")\n\n        if TypeScriptServerBehavior.returns_empty_on_invalid_position():\n            result = list(language_server.request_referencing_symbols(file_path, 99999, 99999, include_self=False))\n            assert result == [], f\"Expected empty list on Windows, got: {result}\"\n        else:\n            with pytest.raises(SolidLSPException) as exc_info:\n                list(language_server.request_referencing_symbols(file_path, 99999, 99999, include_self=False))\n            assert \"Bad line number\" in str(exc_info.value) or \"Debug Failure\" in str(exc_info.value)\n"
  },
  {
    "path": "test/solidlsp/vue/test_vue_rename.py",
    "content": "import os\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\npytestmark = pytest.mark.vue\n\n\nclass TestVueRename:\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_rename_function_within_single_file(self, language_server: SolidLanguageServer) -> None:\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        handle_digit_symbol = next((s for s in symbols[0] if s.get(\"name\") == \"handleDigit\"), None)\n\n        if not handle_digit_symbol or \"selectionRange\" not in handle_digit_symbol:\n            pytest.skip(\"handleDigit symbol not found - test fixture may need updating\")\n\n        sel_start = handle_digit_symbol[\"selectionRange\"][\"start\"]\n\n        workspace_edit = language_server.request_rename_symbol_edit(file_path, sel_start[\"line\"], sel_start[\"character\"], \"processDigit\")\n\n        assert workspace_edit is not None, \"Should return WorkspaceEdit for rename operation\"\n\n        has_changes = \"changes\" in workspace_edit and workspace_edit[\"changes\"]\n        has_document_changes = \"documentChanges\" in workspace_edit and workspace_edit[\"documentChanges\"]\n\n        assert has_changes or has_document_changes, \"WorkspaceEdit should contain either 'changes' or 'documentChanges'\"\n\n        if has_changes:\n            changes = workspace_edit[\"changes\"]\n            assert len(changes) > 0, \"Should have at least one file with changes\"\n\n            calculator_input_files = [uri for uri in changes.keys() if \"CalculatorInput.vue\" in uri]\n            assert len(calculator_input_files) > 0, f\"Should have edits for CalculatorInput.vue. Found edits for: {list(changes.keys())}\"\n\n            file_edits = changes[calculator_input_files[0]]\n            assert len(file_edits) > 0, \"Should have at least one TextEdit for the renamed symbol\"\n\n            for edit in file_edits:\n                assert \"range\" in edit, \"TextEdit should have a range\"\n                assert \"newText\" in edit, \"TextEdit should have newText\"\n                assert edit[\"newText\"] == \"processDigit\", f\"newText should be 'processDigit', got {edit['newText']}\"\n\n                assert \"start\" in edit[\"range\"], \"Range should have start position\"\n                assert \"end\" in edit[\"range\"], \"Range should have end position\"\n                assert \"line\" in edit[\"range\"][\"start\"], \"Start position should have line number\"\n                assert \"character\" in edit[\"range\"][\"start\"], \"Start position should have character offset\"\n\n        elif has_document_changes:\n            document_changes = workspace_edit[\"documentChanges\"]\n            assert isinstance(document_changes, list), \"documentChanges should be a list\"\n            assert len(document_changes) > 0, \"Should have at least one document change\"\n\n            calculator_input_changes = [dc for dc in document_changes if \"CalculatorInput.vue\" in dc.get(\"textDocument\", {}).get(\"uri\", \"\")]\n            assert len(calculator_input_changes) > 0, \"Should have edits for CalculatorInput.vue\"\n\n            for change in calculator_input_changes:\n                assert \"textDocument\" in change, \"Document change should have textDocument\"\n                assert \"edits\" in change, \"Document change should have edits\"\n\n                edits = change[\"edits\"]\n                assert len(edits) > 0, \"Should have at least one TextEdit for the renamed symbol\"\n\n                for edit in edits:\n                    assert \"range\" in edit, \"TextEdit should have a range\"\n                    assert \"newText\" in edit, \"TextEdit should have newText\"\n                    assert edit[\"newText\"] == \"processDigit\", f\"newText should be 'processDigit', got {edit['newText']}\"\n\n                    assert \"start\" in edit[\"range\"], \"Range should have start position\"\n                    assert \"end\" in edit[\"range\"], \"Range should have end position\"\n                    assert \"line\" in edit[\"range\"][\"start\"], \"Start position should have line number\"\n                    assert \"character\" in edit[\"range\"][\"start\"], \"Start position should have character offset\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_rename_composable_function_cross_file(self, language_server: SolidLanguageServer) -> None:\n        composable_file = os.path.join(\"src\", \"composables\", \"useFormatter.ts\")\n\n        symbols = language_server.request_document_symbols(composable_file).get_all_symbols_and_roots()\n        use_formatter_symbol = next((s for s in symbols[0] if s.get(\"name\") == \"useFormatter\"), None)\n\n        if not use_formatter_symbol or \"selectionRange\" not in use_formatter_symbol:\n            pytest.skip(\"useFormatter symbol not found - test fixture may need updating\")\n\n        sel_start = use_formatter_symbol[\"selectionRange\"][\"start\"]\n\n        workspace_edit = language_server.request_rename_symbol_edit(\n            composable_file, sel_start[\"line\"], sel_start[\"character\"], \"useNumberFormatter\"\n        )\n\n        assert workspace_edit is not None, \"Should return WorkspaceEdit for cross-file rename\"\n\n        has_changes = \"changes\" in workspace_edit and workspace_edit[\"changes\"]\n        has_document_changes = \"documentChanges\" in workspace_edit and workspace_edit[\"documentChanges\"]\n\n        assert has_changes or has_document_changes, \"WorkspaceEdit should contain either 'changes' or 'documentChanges'\"\n\n        if has_changes:\n            changes = workspace_edit[\"changes\"]\n            assert len(changes) > 0, \"Should have at least one file with changes\"\n\n            composable_files = [uri for uri in changes.keys() if \"useFormatter.ts\" in uri]\n            assert len(composable_files) > 0, f\"Should have edits for useFormatter.ts (definition). Found edits for: {list(changes.keys())}\"\n\n            for uri, edits in changes.items():\n                assert len(edits) > 0, f\"File {uri} should have at least one edit\"\n\n                for edit in edits:\n                    assert \"range\" in edit, f\"TextEdit in {uri} should have a range\"\n                    assert \"newText\" in edit, f\"TextEdit in {uri} should have newText\"\n                    assert edit[\"newText\"] == \"useNumberFormatter\", f\"newText should be 'useNumberFormatter', got {edit['newText']}\"\n                    assert \"start\" in edit[\"range\"], f\"Range in {uri} should have start position\"\n                    assert \"end\" in edit[\"range\"], f\"Range in {uri} should have end position\"\n\n        elif has_document_changes:\n            document_changes = workspace_edit[\"documentChanges\"]\n            assert isinstance(document_changes, list), \"documentChanges should be a list\"\n            assert len(document_changes) > 0, \"Should have at least one document change\"\n\n            composable_changes = [dc for dc in document_changes if \"useFormatter.ts\" in dc.get(\"textDocument\", {}).get(\"uri\", \"\")]\n            assert (\n                len(composable_changes) > 0\n            ), f\"Should have edits for useFormatter.ts (definition). Found changes for: {[dc.get('textDocument', {}).get('uri', '') for dc in document_changes]}\"\n\n            for change in document_changes:\n                assert \"textDocument\" in change, \"Document change should have textDocument\"\n                assert \"edits\" in change, \"Document change should have edits\"\n\n                uri = change[\"textDocument\"][\"uri\"]\n                edits = change[\"edits\"]\n                assert len(edits) > 0, f\"File {uri} should have at least one edit\"\n\n                for edit in edits:\n                    assert \"range\" in edit, f\"TextEdit in {uri} should have a range\"\n                    assert \"newText\" in edit, f\"TextEdit in {uri} should have newText\"\n                    assert edit[\"newText\"] == \"useNumberFormatter\", f\"newText should be 'useNumberFormatter', got {edit['newText']}\"\n                    assert \"start\" in edit[\"range\"], f\"Range in {uri} should have start position\"\n                    assert \"end\" in edit[\"range\"], f\"Range in {uri} should have end position\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_rename_verifies_correct_file_paths_and_ranges(self, language_server: SolidLanguageServer) -> None:\n        file_path = os.path.join(\"src\", \"App.vue\")\n\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        app_title_symbol = next((s for s in symbols[0] if s.get(\"name\") == \"appTitle\"), None)\n\n        if not app_title_symbol or \"selectionRange\" not in app_title_symbol:\n            pytest.skip(\"appTitle symbol not found - test fixture may need updating\")\n\n        sel_start = app_title_symbol[\"selectionRange\"][\"start\"]\n\n        workspace_edit = language_server.request_rename_symbol_edit(\n            file_path, sel_start[\"line\"], sel_start[\"character\"], \"applicationTitle\"\n        )\n\n        assert workspace_edit is not None, \"Should return WorkspaceEdit for rename operation\"\n        assert isinstance(workspace_edit, dict), \"WorkspaceEdit should be a dictionary\"\n\n        has_changes = \"changes\" in workspace_edit and workspace_edit[\"changes\"]\n        has_document_changes = \"documentChanges\" in workspace_edit and workspace_edit[\"documentChanges\"]\n\n        assert has_changes or has_document_changes, \"WorkspaceEdit must have 'changes' or 'documentChanges'\"\n\n        if has_changes:\n            changes = workspace_edit[\"changes\"]\n\n            assert isinstance(changes, dict), \"changes should be a dict mapping URIs to TextEdit lists\"\n\n            assert len(changes) > 0, \"Should have edits for at least one file\"\n\n            for uri, edits in changes.items():\n                assert isinstance(uri, str), f\"URI should be a string, got {type(uri)}\"\n                assert uri.startswith(\"file://\"), f\"URI should start with 'file://', got {uri}\"\n\n                assert isinstance(edits, list), f\"Edits for {uri} should be a list, got {type(edits)}\"\n                assert len(edits) > 0, f\"Should have at least one edit for {uri}\"\n\n                for idx, edit in enumerate(edits):\n                    assert isinstance(edit, dict), f\"Edit {idx} in {uri} should be a dict, got {type(edit)}\"\n\n                    assert \"range\" in edit, f\"Edit {idx} in {uri} missing 'range'\"\n                    assert \"newText\" in edit, f\"Edit {idx} in {uri} missing 'newText'\"\n\n                    range_obj = edit[\"range\"]\n                    assert \"start\" in range_obj, f\"Edit {idx} range in {uri} missing 'start'\"\n                    assert \"end\" in range_obj, f\"Edit {idx} range in {uri} missing 'end'\"\n\n                    for pos_name in [\"start\", \"end\"]:\n                        pos = range_obj[pos_name]\n                        assert \"line\" in pos, f\"Edit {idx} range {pos_name} in {uri} missing 'line'\"\n                        assert \"character\" in pos, f\"Edit {idx} range {pos_name} in {uri} missing 'character'\"\n                        assert isinstance(pos[\"line\"], int), f\"Line should be int, got {type(pos['line'])}\"\n                        assert isinstance(pos[\"character\"], int), f\"Character should be int, got {type(pos['character'])}\"\n                        assert pos[\"line\"] >= 0, f\"Line number should be >= 0, got {pos['line']}\"\n                        assert pos[\"character\"] >= 0, f\"Character offset should be >= 0, got {pos['character']}\"\n\n                    assert isinstance(edit[\"newText\"], str), f\"newText should be string, got {type(edit['newText'])}\"\n                    assert edit[\"newText\"] == \"applicationTitle\", f\"newText should be 'applicationTitle', got {edit['newText']}\"\n\n        elif has_document_changes:\n            document_changes = workspace_edit[\"documentChanges\"]\n            assert isinstance(document_changes, list), \"documentChanges should be a list\"\n            assert len(document_changes) > 0, \"Should have at least one document change\"\n\n            for change in document_changes:\n                assert isinstance(change, dict), \"Each document change should be a dict\"\n                assert \"textDocument\" in change, \"Document change should have textDocument\"\n                assert \"edits\" in change, \"Document change should have edits\"\n\n                text_doc = change[\"textDocument\"]\n                assert \"uri\" in text_doc, \"textDocument should have uri\"\n                assert text_doc[\"uri\"].startswith(\"file://\"), f\"URI should start with 'file://', got {text_doc['uri']}\"\n\n                edits = change[\"edits\"]\n                assert isinstance(edits, list), \"edits should be a list\"\n                assert len(edits) > 0, \"Should have at least one edit\"\n\n                for idx, edit in enumerate(edits):\n                    assert isinstance(edit, dict), f\"Edit {idx} in {text_doc['uri']} should be a dict, got {type(edit)}\"\n\n                    assert \"range\" in edit, f\"Edit {idx} in {text_doc['uri']} missing 'range'\"\n                    assert \"newText\" in edit, f\"Edit {idx} in {text_doc['uri']} missing 'newText'\"\n\n                    range_obj = edit[\"range\"]\n                    assert \"start\" in range_obj, f\"Edit {idx} range in {text_doc['uri']} missing 'start'\"\n                    assert \"end\" in range_obj, f\"Edit {idx} range in {text_doc['uri']} missing 'end'\"\n\n                    for pos_name in [\"start\", \"end\"]:\n                        pos = range_obj[pos_name]\n                        assert \"line\" in pos, f\"Edit {idx} range {pos_name} in {text_doc['uri']} missing 'line'\"\n                        assert \"character\" in pos, f\"Edit {idx} range {pos_name} in {text_doc['uri']} missing 'character'\"\n                        assert isinstance(pos[\"line\"], int), f\"Line should be int, got {type(pos['line'])}\"\n                        assert isinstance(pos[\"character\"], int), f\"Character should be int, got {type(pos['character'])}\"\n                        assert pos[\"line\"] >= 0, f\"Line number should be >= 0, got {pos['line']}\"\n                        assert pos[\"character\"] >= 0, f\"Character offset should be >= 0, got {pos['character']}\"\n\n                    assert isinstance(edit[\"newText\"], str), f\"newText should be string, got {type(edit['newText'])}\"\n                    assert edit[\"newText\"] == \"applicationTitle\", f\"newText should be 'applicationTitle', got {edit['newText']}\"\n"
  },
  {
    "path": "test/solidlsp/vue/test_vue_symbol_retrieval.py",
    "content": "import os\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_types import SymbolKind\n\npytestmark = pytest.mark.vue\n\n\nclass TestVueSymbolRetrieval:\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_request_containing_symbol_script_setup_function(self, language_server: SolidLanguageServer) -> None:\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        # First, get the document symbols to find the handleDigit function\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        handle_digit_symbol = next((s for s in symbols[0] if s.get(\"name\") == \"handleDigit\"), None)\n\n        if not handle_digit_symbol or \"range\" not in handle_digit_symbol:\n            pytest.skip(\"handleDigit symbol not found - test fixture may need updating\")\n\n        # Get a position inside the handleDigit function body\n        # We'll use a line a few lines after the function start\n        func_start_line = handle_digit_symbol[\"range\"][\"start\"][\"line\"]\n        position_inside_func = func_start_line + 1\n        position_character = 4\n\n        # Request the containing symbol for this position\n        containing_symbol = language_server.request_containing_symbol(\n            file_path, position_inside_func, position_character, include_body=True\n        )\n\n        # Verify we found the correct containing symbol\n        assert containing_symbol is not None, \"Should find containing symbol inside handleDigit function\"\n        assert containing_symbol[\"name\"] == \"handleDigit\", f\"Expected handleDigit, got {containing_symbol.get('name')}\"\n        assert containing_symbol[\"kind\"] in [\n            SymbolKind.Function,\n            SymbolKind.Method,\n            SymbolKind.Variable,\n        ], f\"Expected function-like kind, got {containing_symbol.get('kind')}\"\n\n        # Verify the body is included if available\n        if \"body\" in containing_symbol:\n            assert \"handleDigit\" in containing_symbol[\"body\"].get_text(), \"Function body should contain function name\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_request_containing_symbol_computed_property(self, language_server: SolidLanguageServer) -> None:\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        # Find the formattedDisplay computed property\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        formatted_display_symbol = next((s for s in symbols[0] if s.get(\"name\") == \"formattedDisplay\"), None)\n\n        if not formatted_display_symbol or \"range\" not in formatted_display_symbol:\n            pytest.skip(\"formattedDisplay computed property not found - test fixture may need updating\")\n\n        # Get a position inside the computed property body\n        computed_start_line = formatted_display_symbol[\"range\"][\"start\"][\"line\"]\n        position_inside_computed = computed_start_line + 1\n        position_character = 4\n\n        # Request the containing symbol for this position\n        containing_symbol = language_server.request_containing_symbol(\n            file_path, position_inside_computed, position_character, include_body=True\n        )\n\n        # Verify we found the correct containing symbol\n        # The language server returns the arrow function inside computed() rather than\n        # the variable name. This is technically correct from LSP's perspective.\n        assert containing_symbol is not None, \"Should find containing symbol inside computed property\"\n        assert containing_symbol[\"name\"] in [\n            \"formattedDisplay\",\n            \"computed() callback\",\n        ], f\"Expected formattedDisplay or computed() callback, got {containing_symbol.get('name')}\"\n        assert containing_symbol[\"kind\"] in [\n            SymbolKind.Property,\n            SymbolKind.Variable,\n            SymbolKind.Function,\n        ], f\"Expected property/variable/function kind for computed, got {containing_symbol.get('kind')}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_request_containing_symbol_no_containing_symbol(self, language_server: SolidLanguageServer) -> None:\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        # Position in the import statements at the top of the script setup\n        # Line 1-6 contain imports in CalculatorInput.vue\n        import_line = 2\n        import_character = 10\n\n        # Request containing symbol for a position in the imports\n        containing_symbol = language_server.request_containing_symbol(file_path, import_line, import_character)\n\n        # Should return None or empty dictionary for positions without containing symbol\n        assert (\n            containing_symbol is None or containing_symbol == {}\n        ), f\"Expected None or empty dict for import position, got {containing_symbol}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_request_referencing_symbols_store_function(self, language_server: SolidLanguageServer) -> None:\n        store_file = os.path.join(\"src\", \"stores\", \"calculator.ts\")\n\n        # Find the 'add' action in the calculator store\n        symbols = language_server.request_document_symbols(store_file).get_all_symbols_and_roots()\n        add_symbol = next((s for s in symbols[0] if s.get(\"name\") == \"add\"), None)\n\n        if not add_symbol or \"selectionRange\" not in add_symbol:\n            pytest.skip(\"add action not found in calculator store - test fixture may need updating\")\n\n        # Request referencing symbols for the add action (include_self=True to get at least the definition)\n        sel_start = add_symbol[\"selectionRange\"][\"start\"]\n        ref_symbols = [\n            ref.symbol\n            for ref in language_server.request_referencing_symbols(store_file, sel_start[\"line\"], sel_start[\"character\"], include_self=True)\n        ]\n\n        assert isinstance(ref_symbols, list), f\"request_referencing_symbols should return a list, got {type(ref_symbols)}\"\n\n        for symbol in ref_symbols:\n            assert \"name\" in symbol, \"Referencing symbol should have a name\"\n            assert \"kind\" in symbol, \"Referencing symbol should have a kind\"\n\n        vue_refs = [\n            symbol for symbol in ref_symbols if \"location\" in symbol and \"uri\" in symbol[\"location\"] and \".vue\" in symbol[\"location\"][\"uri\"]\n        ]\n\n        if len(vue_refs) > 0:\n            calculator_input_refs = [\n                ref\n                for ref in vue_refs\n                if \"location\" in ref and \"uri\" in ref[\"location\"] and \"CalculatorInput.vue\" in ref[\"location\"][\"uri\"]\n            ]\n            for ref in calculator_input_refs:\n                assert \"name\" in ref, \"Reference should have name\"\n                assert \"location\" in ref, \"Reference should have location\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_request_referencing_symbols_composable(self, language_server: SolidLanguageServer) -> None:\n        composable_file = os.path.join(\"src\", \"composables\", \"useFormatter.ts\")\n\n        # Find the useFormatter composable function\n        symbols = language_server.request_document_symbols(composable_file).get_all_symbols_and_roots()\n        use_formatter_symbol = next((s for s in symbols[0] if s.get(\"name\") == \"useFormatter\"), None)\n\n        if not use_formatter_symbol or \"selectionRange\" not in use_formatter_symbol:\n            pytest.skip(\"useFormatter composable not found - test fixture may need updating\")\n\n        # Request referencing symbols for the composable\n        sel_start = use_formatter_symbol[\"selectionRange\"][\"start\"]\n        ref_symbols = [\n            ref.symbol for ref in language_server.request_referencing_symbols(composable_file, sel_start[\"line\"], sel_start[\"character\"])\n        ]\n\n        # Verify we found references - useFormatter is imported and used in CalculatorInput.vue\n        assert (\n            len(ref_symbols) >= 1\n        ), f\"useFormatter should have at least 1 reference (used in CalculatorInput.vue), found {len(ref_symbols)} references\"\n\n        # Check for references in Vue components\n        vue_refs = [\n            symbol for symbol in ref_symbols if \"location\" in symbol and \"uri\" in symbol[\"location\"] and \".vue\" in symbol[\"location\"][\"uri\"]\n        ]\n\n        # CalculatorInput.vue imports and uses useFormatter\n        assert len(vue_refs) >= 1, f\"Should find at least 1 Vue component reference to useFormatter, found {len(vue_refs)}\"\n\n        # Verify we found reference in CalculatorInput.vue specifically\n        has_calculator_input_ref = any(\n            \"CalculatorInput.vue\" in ref[\"location\"][\"uri\"] for ref in vue_refs if \"location\" in ref and \"uri\" in ref[\"location\"]\n        )\n        assert has_calculator_input_ref, (\n            f\"Should find reference to useFormatter in CalculatorInput.vue. \"\n            f\"Found references in: {[ref['location']['uri'] for ref in vue_refs if 'location' in ref and 'uri' in ref['location']]}\"\n        )\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_vue_component_cross_references(self, language_server: SolidLanguageServer) -> None:\n        input_file = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n        button_file = os.path.join(\"src\", \"components\", \"CalculatorButton.vue\")\n\n        definitions = language_server.request_definition(input_file, 4, 10)\n\n        assert len(definitions) == 1, f\"Should find exactly 1 definition for CalculatorButton import, got {len(definitions)}\"\n        assert (\n            \"CalculatorButton.vue\" in definitions[0][\"relativePath\"]\n        ), f\"Definition should point to CalculatorButton.vue, got {definitions[0]['relativePath']}\"\n\n        refs = language_server.request_references(input_file, 4, 10)\n\n        assert len(refs) >= 2, (\n            f\"Should find at least 2 references to CalculatorButton (import + template usages). \"\n            f\"In CalculatorInput.vue, CalculatorButton is imported and used ~7 times in template. Found {len(refs)} references\"\n        )\n\n        button_symbols = language_server.request_document_symbols(button_file).get_all_symbols_and_roots()\n        symbol_names = [s.get(\"name\") for s in button_symbols[0]]\n\n        assert \"Props\" in symbol_names, \"CalculatorButton.vue should have Props interface\"\n        assert \"handleClick\" in symbol_names, \"CalculatorButton.vue should have handleClick function\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_request_defining_symbol_import_resolution(self, language_server: SolidLanguageServer) -> None:\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        # Find the import position for useCalculatorStore\n        # In CalculatorInput.vue (0-indexed lines):\n        # Line 2: import { useCalculatorStore } from '@/stores/calculator'\n        # Line 8: const store = useCalculatorStore()\n        # We'll request definition at the position of \"useCalculatorStore\" in the usage line\n        defining_symbol = language_server.request_defining_symbol(file_path, 8, 18)\n\n        if defining_symbol is None:\n            # Some language servers may not support go-to-definition at usage sites\n            # Try at line 2 (import statement) instead\n            defining_symbol = language_server.request_defining_symbol(file_path, 2, 18)\n\n        # Verify we found a defining symbol\n        assert defining_symbol is not None, \"Should find defining symbol for useCalculatorStore\"\n        assert \"name\" in defining_symbol, \"Defining symbol should have a name\"\n        assert defining_symbol.get(\"name\") in [\n            \"useCalculatorStore\",\n            \"calculator\",\n        ], f\"Expected useCalculatorStore or calculator, got {defining_symbol.get('name')}\"\n\n        # Verify it points to the store file\n        if \"location\" in defining_symbol and \"uri\" in defining_symbol[\"location\"]:\n            assert (\n                \"calculator.ts\" in defining_symbol[\"location\"][\"uri\"]\n            ), f\"Should point to calculator.ts, got {defining_symbol['location']['uri']}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.VUE], indirect=True)\n    def test_request_defining_symbol_component_import(self, language_server: SolidLanguageServer) -> None:\n        file_path = os.path.join(\"src\", \"components\", \"CalculatorInput.vue\")\n\n        definitions = language_server.request_definition(file_path, 4, 10)\n\n        assert len(definitions) > 0, \"Should find definition for CalculatorButton import\"\n\n        definition = definitions[0]\n        assert definition[\"relativePath\"] is not None, \"Definition should have a relative path\"\n        assert (\n            \"CalculatorButton.vue\" in definition[\"relativePath\"]\n        ), f\"Should point to CalculatorButton.vue, got {definition['relativePath']}\"\n\n        assert definition[\"range\"][\"start\"][\"line\"] == 0, \"Definition should point to start of .vue file\"\n\n        defining_symbol = language_server.request_defining_symbol(file_path, 4, 10)\n        assert defining_symbol is None or \"name\" in defining_symbol, \"If defining_symbol is found, it should have a name\"\n"
  },
  {
    "path": "test/solidlsp/yaml_ls/__init__.py",
    "content": ""
  },
  {
    "path": "test/solidlsp/yaml_ls/test_yaml_basic.py",
    "content": "\"\"\"\nBasic integration tests for the YAML language server functionality.\n\nThese tests validate the functionality of the language server APIs\nlike request_document_symbols using the YAML test repository.\n\"\"\"\n\nfrom pathlib import Path\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\n\n\n@pytest.mark.yaml\nclass TestYAMLLanguageServerBasics:\n    \"\"\"Test basic functionality of the YAML language server.\"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.YAML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.YAML], indirect=True)\n    def test_yaml_language_server_initialization(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that YAML language server can be initialized successfully.\"\"\"\n        assert language_server is not None\n        assert language_server.language == Language.YAML\n        assert language_server.is_running()\n        assert Path(language_server.language_server.repository_root_path).resolve() == repo_path.resolve()\n\n    @pytest.mark.parametrize(\"language_server\", [Language.YAML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.YAML], indirect=True)\n    def test_yaml_config_file_symbols(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test document symbols detection in config.yaml with specific symbol verification.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"config.yaml\").get_all_symbols_and_roots()\n\n        assert all_symbols is not None, \"Should return symbols for config.yaml\"\n        assert len(all_symbols) > 0, f\"Should find symbols in config.yaml, found {len(all_symbols)}\"\n\n        # Verify specific top-level keys are detected\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n        assert \"app\" in symbol_names, \"Should detect 'app' key in config.yaml\"\n        assert \"database\" in symbol_names, \"Should detect 'database' key in config.yaml\"\n        assert \"logging\" in symbol_names, \"Should detect 'logging' key in config.yaml\"\n        assert \"features\" in symbol_names, \"Should detect 'features' key in config.yaml\"\n\n        # Verify nested symbols exist (child keys under 'app')\n        assert \"name\" in symbol_names, \"Should detect nested 'name' key\"\n        assert \"port\" in symbol_names, \"Should detect nested 'port' key\"\n        assert \"debug\" in symbol_names, \"Should detect nested 'debug' key\"\n\n        # Check symbol kinds are appropriate (LSP kinds: 2=module/namespace, 15=string, 16=number, 17=boolean)\n        app_symbol = next((s for s in all_symbols if s.get(\"name\") == \"app\"), None)\n        assert app_symbol is not None, \"Should find 'app' symbol\"\n        assert app_symbol.get(\"kind\") == 2, \"Top-level object should have kind 2 (module/namespace)\"\n\n        port_symbol = next((s for s in all_symbols if s.get(\"name\") == \"port\"), None)\n        assert port_symbol is not None, \"Should find 'port' symbol\"\n        assert port_symbol.get(\"kind\") == 16, \"'port' should have kind 16 (number)\"\n\n        debug_symbol = next((s for s in all_symbols if s.get(\"name\") == \"debug\"), None)\n        assert debug_symbol is not None, \"Should find 'debug' symbol\"\n        assert debug_symbol.get(\"kind\") == 17, \"'debug' should have kind 17 (boolean)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.YAML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.YAML], indirect=True)\n    def test_yaml_services_file_symbols(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test symbol detection in services.yml Docker Compose file.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"services.yml\").get_all_symbols_and_roots()\n\n        assert all_symbols is not None, \"Should return symbols for services.yml\"\n        assert len(all_symbols) > 0, f\"Should find symbols in services.yml, found {len(all_symbols)}\"\n\n        # Verify specific top-level keys from Docker Compose file\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n        assert \"version\" in symbol_names, \"Should detect 'version' key\"\n        assert \"services\" in symbol_names, \"Should detect 'services' key\"\n        assert \"networks\" in symbol_names, \"Should detect 'networks' key\"\n        assert \"volumes\" in symbol_names, \"Should detect 'volumes' key\"\n\n        # Verify service names\n        assert \"web\" in symbol_names, \"Should detect 'web' service\"\n        assert \"api\" in symbol_names, \"Should detect 'api' service\"\n        assert \"database\" in symbol_names, \"Should detect 'database' service\"\n\n        # Check that arrays are properly detected\n        ports_symbols = [s for s in all_symbols if s.get(\"name\") == \"ports\"]\n        assert len(ports_symbols) > 0, \"Should find 'ports' arrays in services\"\n        # Arrays should have kind 18\n        for ports_sym in ports_symbols:\n            assert ports_sym.get(\"kind\") == 18, \"'ports' should have kind 18 (array)\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.YAML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.YAML], indirect=True)\n    def test_yaml_data_file_symbols(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test symbol detection in data.yaml file with array structures.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"data.yaml\").get_all_symbols_and_roots()\n\n        assert all_symbols is not None, \"Should return symbols for data.yaml\"\n        assert len(all_symbols) > 0, f\"Should find symbols in data.yaml, found {len(all_symbols)}\"\n\n        # Verify top-level keys\n        symbol_names = [sym.get(\"name\") for sym in all_symbols]\n        assert \"users\" in symbol_names, \"Should detect 'users' array\"\n        assert \"projects\" in symbol_names, \"Should detect 'projects' array\"\n\n        # Verify array elements (indexed by position)\n        # data.yaml has user entries and project entries\n        assert \"id\" in symbol_names, \"Should detect 'id' fields in array elements\"\n        assert \"name\" in symbol_names, \"Should detect 'name' fields\"\n        assert \"email\" in symbol_names, \"Should detect 'email' fields\"\n        assert \"roles\" in symbol_names, \"Should detect 'roles' arrays\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.YAML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.YAML], indirect=True)\n    def test_yaml_symbols_with_body(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test request_document_symbols with body extraction.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"config.yaml\").get_all_symbols_and_roots()\n\n        assert all_symbols is not None, \"Should return symbols for config.yaml\"\n        assert len(all_symbols) > 0, \"Should have symbols\"\n\n        # Find the 'app' symbol and verify its body\n        app_symbol = next((s for s in all_symbols if s.get(\"name\") == \"app\"), None)\n        assert app_symbol is not None, \"Should find 'app' symbol\"\n\n        # Check that body exists and contains expected content\n        assert \"body\" in app_symbol, \"'app' symbol should have body\"\n        app_body = app_symbol[\"body\"].get_text()\n        assert \"app:\" in app_body, \"Body should start with 'app:'\"\n        assert \"name: test-application\" in app_body, \"Body should contain 'name' field\"\n        assert \"version: 1.0.0\" in app_body, \"Body should contain 'version' field\"\n        assert \"port: 8080\" in app_body, \"Body should contain 'port' field\"\n        assert \"debug: true\" in app_body, \"Body should contain 'debug' field\"\n\n        # Find a simple string value symbol and verify its body\n        name_symbols = [s for s in all_symbols if s.get(\"name\") == \"name\" and \"body\" in s]\n        assert len(name_symbols) > 0, \"Should find 'name' symbols with bodies\"\n        # At least one should contain \"test-application\"\n        assert any(\"test-application\" in s[\"body\"].get_text() for s in name_symbols), \"Should find name with test-application\"\n\n        # Find the database symbol and check its body\n        database_symbol = next((s for s in all_symbols if s.get(\"name\") == \"database\"), None)\n        assert database_symbol is not None, \"Should find 'database' symbol\"\n        assert \"body\" in database_symbol, \"'database' symbol should have body\"\n        db_body = database_symbol[\"body\"].get_text()\n        assert \"database:\" in db_body, \"Body should start with 'database:'\"\n        assert \"host: localhost\" in db_body, \"Body should contain host configuration\"\n        assert \"port: 5432\" in db_body, \"Body should contain port configuration\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.YAML], indirect=True)\n    @pytest.mark.parametrize(\"repo_path\", [Language.YAML], indirect=True)\n    def test_yaml_symbol_ranges(self, language_server: SolidLanguageServer, repo_path: Path) -> None:\n        \"\"\"Test that symbols have proper range information.\"\"\"\n        all_symbols, root_symbols = language_server.request_document_symbols(\"config.yaml\").get_all_symbols_and_roots()\n\n        assert all_symbols is not None\n        assert len(all_symbols) > 0\n\n        # Check the 'app' symbol range\n        app_symbol = next((s for s in all_symbols if s.get(\"name\") == \"app\"), None)\n        assert app_symbol is not None, \"Should find 'app' symbol\"\n        assert \"range\" in app_symbol, \"'app' symbol should have range\"\n\n        app_range = app_symbol[\"range\"]\n        assert \"start\" in app_range, \"Range should have start\"\n        assert \"end\" in app_range, \"Range should have end\"\n        assert app_range[\"start\"][\"line\"] == 1, \"'app' should start at line 1 (0-indexed, actual line 2)\"\n        # The app block spans from line 2 to line 7 in the file (1-indexed)\n        # In 0-indexed LSP coordinates: line 1 (start) to line 6 (end)\n        assert app_range[\"end\"][\"line\"] == 6, \"'app' should end at line 6 (0-indexed)\"\n\n        # Check a nested symbol range\n        port_symbols = [s for s in all_symbols if s.get(\"name\") == \"port\"]\n        assert len(port_symbols) > 0, \"Should find 'port' symbols\"\n        # Find the one under 'app' (should be at line 4 in 0-indexed, actual line 5)\n        app_port = next((s for s in port_symbols if s[\"range\"][\"start\"][\"line\"] == 4), None)\n        assert app_port is not None, \"Should find 'port' under 'app'\"\n        assert app_port[\"range\"][\"start\"][\"character\"] == 2, \"'port' should be indented 2 spaces\"\n"
  },
  {
    "path": "test/solidlsp/zig/test_zig_basic.py",
    "content": "\"\"\"\nBasic integration tests for Zig language server functionality.\n\nThese tests validate symbol finding and navigation capabilities using the Zig Language Server (ZLS).\nNote: ZLS requires files to be open in the editor to find cross-file references (performance optimization).\n\"\"\"\n\nimport os\nimport sys\n\nimport pytest\n\nfrom solidlsp import SolidLanguageServer\nfrom solidlsp.ls_config import Language\nfrom solidlsp.ls_types import SymbolKind\n\n\n@pytest.mark.zig\n@pytest.mark.skipif(\n    sys.platform == \"win32\", reason=\"ZLS is disabled on Windows - cross-file references don't work reliably. Reason unknown.\"\n)\nclass TestZigLanguageServer:\n    \"\"\"Test Zig language server symbol finding and navigation capabilities.\n\n    NOTE: All tests are skipped on Windows as ZLS is disabled on that platform\n    due to unreliable cross-file reference functionality. Reason unknown.\n    \"\"\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ZIG], indirect=True)\n    def test_find_symbols_in_main(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding specific symbols in main.zig.\"\"\"\n        file_path = os.path.join(\"src\", \"main.zig\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        assert symbols is not None\n        assert len(symbols) > 0\n\n        # Extract symbol names from the returned structure\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n        symbol_names = {sym.get(\"name\") for sym in symbol_list if isinstance(sym, dict)}\n\n        # Verify specific symbols exist\n        assert \"main\" in symbol_names, \"main function not found\"\n        assert \"greeting\" in symbol_names, \"greeting function not found\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ZIG], indirect=True)\n    def test_find_symbols_in_calculator(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding Calculator struct and its methods.\"\"\"\n        file_path = os.path.join(\"src\", \"calculator.zig\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        assert symbols is not None\n        assert len(symbols) > 0\n\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n\n        # Find Calculator struct\n        calculator_symbol = None\n        for sym in symbol_list:\n            if sym.get(\"name\") == \"Calculator\":\n                calculator_symbol = sym\n                break\n\n        assert calculator_symbol is not None, \"Calculator struct not found\"\n        # ZLS may use different symbol kinds for structs (14 = Namespace, 5 = Class, 23 = Struct)\n        assert calculator_symbol.get(\"kind\") in [\n            SymbolKind.Class,\n            SymbolKind.Struct,\n            SymbolKind.Namespace,\n            5,\n            14,\n            23,\n        ], \"Calculator should be a struct/class/namespace\"\n\n        # Check for Calculator methods (init, add, subtract, etc.)\n        # Methods might be in children or at the same level\n        all_symbols = []\n        for sym in symbol_list:\n            all_symbols.append(sym.get(\"name\"))\n            if \"children\" in sym:\n                for child in sym[\"children\"]:\n                    all_symbols.append(child.get(\"name\"))\n\n        # Verify exact calculator methods exist\n        expected_methods = {\"init\", \"add\", \"subtract\", \"multiply\", \"divide\"}\n        found_methods = set(all_symbols) & expected_methods\n        assert found_methods == expected_methods, f\"Expected exactly {expected_methods}, found: {found_methods}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ZIG], indirect=True)\n    def test_find_symbols_in_math_utils(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding functions in math_utils.zig.\"\"\"\n        file_path = os.path.join(\"src\", \"math_utils.zig\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        assert symbols is not None\n        assert len(symbols) > 0\n\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n        symbol_names = {sym.get(\"name\") for sym in symbol_list if isinstance(sym, dict)}\n\n        # Verify math utility functions exist\n        assert \"factorial\" in symbol_names, \"factorial function not found\"\n        assert \"isPrime\" in symbol_names, \"isPrime function not found\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ZIG], indirect=True)\n    def test_find_references_within_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding references within the same file.\"\"\"\n        file_path = os.path.join(\"src\", \"calculator.zig\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n\n        # Find Calculator struct\n        calculator_symbol = None\n        for sym in symbol_list:\n            if sym.get(\"name\") == \"Calculator\":\n                calculator_symbol = sym\n                break\n\n        assert calculator_symbol is not None, \"Calculator struct not found\"\n\n        # Find references to Calculator within the same file\n        sel_range = calculator_symbol.get(\"selectionRange\", calculator_symbol.get(\"range\"))\n        assert sel_range is not None, \"Calculator symbol has no range information\"\n\n        sel_start = sel_range[\"start\"]\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n\n        assert refs is not None\n        assert isinstance(refs, list)\n        # ZLS finds references within the same file\n        # Calculator is used in 4 test usages (lines 45, 51, 57, 63)\n        # Note: ZLS may not include the declaration itself as a reference\n        assert len(refs) >= 4, f\"Should find at least 4 Calculator references within calculator.zig, found {len(refs)}\"\n\n        # Verify we found the test usages\n        ref_lines = sorted([ref[\"range\"][\"start\"][\"line\"] for ref in refs])\n        test_lines = [44, 50, 56, 62]  # 0-indexed: tests at lines 45, 51, 57, 63\n        for line in test_lines:\n            assert line in ref_lines, f\"Should find Calculator reference at line {line + 1}, found at lines {[l + 1 for l in ref_lines]}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ZIG], indirect=True)\n    @pytest.mark.skipif(\n        sys.platform == \"win32\", reason=\"ZLS cross-file references don't work reliably on Windows - URI path handling issues\"\n    )\n    def test_cross_file_references_with_open_files(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"\n        Test finding cross-file references with files open.\n\n        ZLS limitation: Cross-file references (textDocument/references) only work when\n        target files are open. This is a performance optimization in ZLS.\n\n        NOTE: Disabled on Windows as cross-file references cannot be made to work reliably\n        due to URI path handling differences between Windows and Unix systems.\n        \"\"\"\n        import time\n\n        # Open the files that contain references to enable cross-file search\n        with language_server.open_file(\"build.zig\"):\n            with language_server.open_file(os.path.join(\"src\", \"main.zig\")):\n                with language_server.open_file(os.path.join(\"src\", \"calculator.zig\")):\n                    # Give ZLS a moment to analyze the open files\n                    time.sleep(1)\n\n                    # Find Calculator struct\n                    symbols = language_server.request_document_symbols(os.path.join(\"src\", \"calculator.zig\")).get_all_symbols_and_roots()\n                    symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n\n                    calculator_symbol = None\n                    for sym in symbol_list:\n                        if sym.get(\"name\") == \"Calculator\":\n                            calculator_symbol = sym\n                            break\n\n                    assert calculator_symbol is not None, \"Calculator struct not found\"\n\n                    sel_range = calculator_symbol.get(\"selectionRange\", calculator_symbol.get(\"range\"))\n                    assert sel_range is not None, \"Calculator symbol has no range information\"\n\n                    # Find references to Calculator\n                    sel_start = sel_range[\"start\"]\n                    refs = language_server.request_references(\n                        os.path.join(\"src\", \"calculator.zig\"), sel_start[\"line\"], sel_start[\"character\"]\n                    )\n\n                    assert refs is not None\n                    assert isinstance(refs, list)\n\n                    # With files open, ZLS should find cross-file references\n                    main_refs = [ref for ref in refs if \"main.zig\" in ref.get(\"uri\", \"\")]\n\n                    assert len(main_refs) >= 1, f\"Should find at least 1 Calculator reference in main.zig, found {len(main_refs)}\"\n\n                    # Verify exact location in main.zig (line 8, 0-indexed: 7)\n                    main_ref_line = main_refs[0][\"range\"][\"start\"][\"line\"]\n                    assert (\n                        main_ref_line == 7\n                    ), f\"Calculator reference in main.zig should be at line 8 (0-indexed: 7), found at line {main_ref_line + 1}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ZIG], indirect=True)\n    def test_cross_file_references_within_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"\n        Test that ZLS finds references within the same file.\n\n        Note: ZLS is designed to be lightweight and only analyzes files that are explicitly opened.\n        Cross-file references require manually opening the relevant files first.\n        \"\"\"\n        # Find references to Calculator from calculator.zig\n        file_path = os.path.join(\"src\", \"calculator.zig\")\n        symbols = language_server.request_document_symbols(file_path).get_all_symbols_and_roots()\n        symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols\n\n        calculator_symbol = None\n        for sym in symbol_list:\n            if sym.get(\"name\") == \"Calculator\":\n                calculator_symbol = sym\n                break\n\n        assert calculator_symbol is not None, \"Calculator struct not found\"\n\n        sel_range = calculator_symbol.get(\"selectionRange\", calculator_symbol.get(\"range\"))\n        assert sel_range is not None, \"Calculator symbol has no range information\"\n\n        sel_start = sel_range[\"start\"]\n        refs = language_server.request_references(file_path, sel_start[\"line\"], sel_start[\"character\"])\n\n        assert refs is not None\n        assert isinstance(refs, list)\n\n        # ZLS finds references within the same file\n        # Calculator is used in 4 test usages (lines 45, 51, 57, 63)\n        # Note: ZLS may not include the declaration itself as a reference\n        assert len(refs) >= 4, f\"Should find at least 4 Calculator references within calculator.zig, found {len(refs)}\"\n\n        # Verify we found the test usages\n        ref_lines = sorted([ref[\"range\"][\"start\"][\"line\"] for ref in refs])\n        test_lines = [44, 50, 56, 62]  # 0-indexed: tests at lines 45, 51, 57, 63\n        for line in test_lines:\n            assert line in ref_lines, f\"Should find Calculator reference at line {line + 1}, found at lines {[l + 1 for l in ref_lines]}\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ZIG], indirect=True)\n    @pytest.mark.skipif(\n        sys.platform == \"win32\", reason=\"ZLS cross-file references don't work reliably on Windows - URI path handling issues\"\n    )\n    def test_go_to_definition_cross_file(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"\n        Test go-to-definition from main.zig to calculator.zig.\n\n        ZLS capability: Go-to-definition (textDocument/definition) works cross-file\n        WITHOUT requiring files to be open.\n\n        NOTE: Disabled on Windows as cross-file references cannot be made to work reliably\n        due to URI path handling differences between Windows and Unix systems.\n        \"\"\"\n        file_path = os.path.join(\"src\", \"main.zig\")\n\n        # Line 8: const calc = calculator.Calculator.init();\n        # Test go-to-definition for Calculator\n        definitions = language_server.request_definition(file_path, 7, 25)  # Position of \"Calculator\"\n\n        assert definitions is not None\n        assert isinstance(definitions, list)\n        assert len(definitions) > 0, \"Should find definition of Calculator\"\n\n        # Should point to calculator.zig\n        calc_def = definitions[0]\n        assert \"calculator.zig\" in calc_def.get(\"uri\", \"\"), \"Definition should be in calculator.zig\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ZIG], indirect=True)\n    @pytest.mark.skipif(\n        sys.platform == \"win32\", reason=\"ZLS cross-file references don't work reliably on Windows - URI path handling issues\"\n    )\n    def test_cross_file_function_usage(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test finding usage of functions from math_utils in main.zig.\n\n        NOTE: Disabled on Windows as cross-file references cannot be made to work reliably\n        due to URI path handling differences between Windows and Unix systems.\n        \"\"\"\n        # Line 23 in main.zig: const factorial_result = math_utils.factorial(5);\n        definitions = language_server.request_definition(os.path.join(\"src\", \"main.zig\"), 22, 40)  # Position of \"factorial\"\n\n        assert definitions is not None\n        assert isinstance(definitions, list)\n\n        if len(definitions) > 0:\n            # Should find factorial definition in math_utils.zig\n            math_def = [d for d in definitions if \"math_utils.zig\" in d.get(\"uri\", \"\")]\n            assert len(math_def) > 0, \"Should find factorial definition in math_utils.zig\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ZIG], indirect=True)\n    def test_verify_cross_file_imports(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Verify that our test files have proper cross-file imports.\"\"\"\n        # Verify main.zig imports\n        main_symbols = language_server.request_document_symbols(os.path.join(\"src\", \"main.zig\")).get_all_symbols_and_roots()\n        assert main_symbols is not None\n        main_list = main_symbols[0] if isinstance(main_symbols, tuple) else main_symbols\n        main_names = {sym.get(\"name\") for sym in main_list if isinstance(sym, dict)}\n\n        # main.zig should have main and greeting functions\n        assert \"main\" in main_names, \"main function should be in main.zig\"\n        assert \"greeting\" in main_names, \"greeting function should be in main.zig\"\n\n        # Verify calculator.zig exports Calculator\n        calc_symbols = language_server.request_document_symbols(os.path.join(\"src\", \"calculator.zig\")).get_all_symbols_and_roots()\n        assert calc_symbols is not None\n        calc_list = calc_symbols[0] if isinstance(calc_symbols, tuple) else calc_symbols\n        calc_names = {sym.get(\"name\") for sym in calc_list if isinstance(sym, dict)}\n        assert \"Calculator\" in calc_names, \"Calculator struct should be in calculator.zig\"\n\n        # Verify math_utils.zig exports functions\n        math_symbols = language_server.request_document_symbols(os.path.join(\"src\", \"math_utils.zig\")).get_all_symbols_and_roots()\n        assert math_symbols is not None\n        math_list = math_symbols[0] if isinstance(math_symbols, tuple) else math_symbols\n        math_names = {sym.get(\"name\") for sym in math_list if isinstance(sym, dict)}\n        assert \"factorial\" in math_names, \"factorial function should be in math_utils.zig\"\n        assert \"isPrime\" in math_names, \"isPrime function should be in math_utils.zig\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ZIG], indirect=True)\n    def test_hover_information(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test hover information for symbols.\"\"\"\n        file_path = os.path.join(\"src\", \"main.zig\")\n\n        # Get hover info for the main function\n        hover_info = language_server.request_hover(file_path, 4, 8)  # Position of \"main\" function\n\n        assert hover_info is not None, \"Should provide hover information for main function\"\n\n        # Hover info could be a dict with 'contents' or a string\n        if isinstance(hover_info, dict):\n            assert \"contents\" in hover_info or \"value\" in hover_info, \"Hover should have contents\"\n\n    @pytest.mark.parametrize(\"language_server\", [Language.ZIG], indirect=True)\n    def test_full_symbol_tree(self, language_server: SolidLanguageServer) -> None:\n        \"\"\"Test that full symbol tree is not empty.\"\"\"\n        symbols = language_server.request_full_symbol_tree()\n\n        assert symbols is not None\n        assert len(symbols) > 0, \"Symbol tree should not be empty\"\n\n        # The tree should have at least one root node\n        root = symbols[0]\n        assert isinstance(root, dict), \"Root should be a dict\"\n        assert \"name\" in root, \"Root should have a name\"\n"
  }
]