Compare commits
3 Commits
feat/hover
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
21d776dfc0
|
|||
|
|
3b45888622 | ||
|
|
cc5b25d5c3 |
40
.gitea/ISSUE_TEMPLATE/bug_report.md
Normal file
40
.gitea/ISSUE_TEMPLATE/bug_report.md
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ""
|
||||
labels: ""
|
||||
assignees: ""
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
|
||||
- OS: [e.g. iOS]
|
||||
- Browser [e.g. chrome, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Smartphone (please complete the following information):**
|
||||
|
||||
- Device: [e.g. iPhone6]
|
||||
- OS: [e.g. iOS8.1]
|
||||
- Browser [e.g. stock browser, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
19
.gitea/ISSUE_TEMPLATE/feature_request.md
Normal file
19
.gitea/ISSUE_TEMPLATE/feature_request.md
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ""
|
||||
labels: ""
|
||||
assignees: ""
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
20
.gitea/actions/setup-pixi/action.yml
Normal file
20
.gitea/actions/setup-pixi/action.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
name: "Setup Pixi"
|
||||
description: "setup pixi"
|
||||
|
||||
inputs:
|
||||
environments:
|
||||
description: "The pixi environments to install (e.g. default, docs, test)"
|
||||
required: false
|
||||
default: "default"
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Setup Pixi
|
||||
uses: prefix-dev/setup-pixi@v0.9.3
|
||||
with:
|
||||
pixi-version: v0.67.0
|
||||
environments: ${{ inputs.environments }}
|
||||
activate-environment: true
|
||||
cache: true
|
||||
locked: true
|
||||
44
.gitea/workflows/benchmark.yml
Normal file
44
.gitea/workflows/benchmark.yml
Normal file
@@ -0,0 +1,44 @@
|
||||
name: benchmark
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
benchmark:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-24.04, macos-15, windows-2025]
|
||||
runs-on: ${{ matrix.os }}
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: ./.github/actions/setup-pixi
|
||||
|
||||
- name: Build scan_benchmark
|
||||
run: |
|
||||
pixi run cmake-config RelWithDebInfo ON -- -DCLICE_ENABLE_BENCHMARK=ON
|
||||
cmake --build build/RelWithDebInfo --target scan_benchmark
|
||||
|
||||
- name: Clone LLVM
|
||||
run: git clone --depth 1 https://github.com/llvm/llvm-project.git
|
||||
|
||||
- name: Generate CDB
|
||||
run: |
|
||||
cmake -B llvm-build -G Ninja \
|
||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
||||
-DCMAKE_TOOLCHAIN_FILE="$(pwd)/cmake/toolchain.cmake" \
|
||||
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb;mlir;polly;flang;bolt" \
|
||||
-DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind" \
|
||||
llvm-project/llvm
|
||||
|
||||
- name: Run benchmark
|
||||
run: ./build/RelWithDebInfo/bin/scan_benchmark --runs 20 llvm-build/compile_commands.json
|
||||
|
||||
- name: Stop sccache server
|
||||
if: runner.os == 'Windows'
|
||||
run: pixi run -- sccache --stop-server || true
|
||||
446
.gitea/workflows/build-llvm.yml
Normal file
446
.gitea/workflows/build-llvm.yml
Normal file
@@ -0,0 +1,446 @@
|
||||
name: build llvm
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
llvm_version:
|
||||
description: "LLVM version to build (e.g., 21.1.8)"
|
||||
required: true
|
||||
type: string
|
||||
skip_upload:
|
||||
description: "Skip upload and PR creation (build-only mode)"
|
||||
required: false
|
||||
type: boolean
|
||||
default: false
|
||||
skip_pr:
|
||||
description: "Skip PR creation (upload only, no PR)"
|
||||
required: false
|
||||
type: boolean
|
||||
default: false
|
||||
pull_request:
|
||||
# if you want to run this workflow, change the branch name to main,
|
||||
# if you want to turn off it, change it to non existent branch.
|
||||
branches: [main-turn-off]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
# Native builds
|
||||
- os: windows-2025
|
||||
llvm_mode: RelWithDebInfo
|
||||
lto: OFF
|
||||
- os: windows-2025
|
||||
llvm_mode: RelWithDebInfo
|
||||
lto: ON
|
||||
- os: ubuntu-24.04
|
||||
llvm_mode: Debug
|
||||
lto: OFF
|
||||
- os: ubuntu-24.04
|
||||
llvm_mode: RelWithDebInfo
|
||||
lto: OFF
|
||||
- os: ubuntu-24.04
|
||||
llvm_mode: RelWithDebInfo
|
||||
lto: ON
|
||||
- os: macos-15
|
||||
llvm_mode: Debug
|
||||
lto: OFF
|
||||
- os: macos-15
|
||||
llvm_mode: RelWithDebInfo
|
||||
lto: OFF
|
||||
- os: macos-15
|
||||
llvm_mode: RelWithDebInfo
|
||||
lto: ON
|
||||
|
||||
# Cross-compilation builds
|
||||
# macOS x64 (from arm64 macos-15)
|
||||
- os: macos-15
|
||||
llvm_mode: RelWithDebInfo
|
||||
lto: OFF
|
||||
target_triple: x86_64-apple-darwin
|
||||
- os: macos-15
|
||||
llvm_mode: RelWithDebInfo
|
||||
lto: ON
|
||||
target_triple: x86_64-apple-darwin
|
||||
|
||||
# Linux aarch64 (from x64 ubuntu-24.04)
|
||||
- os: ubuntu-24.04
|
||||
llvm_mode: RelWithDebInfo
|
||||
lto: OFF
|
||||
target_triple: aarch64-linux-gnu
|
||||
pixi_env: cross-linux-aarch64
|
||||
- os: ubuntu-24.04
|
||||
llvm_mode: RelWithDebInfo
|
||||
lto: ON
|
||||
target_triple: aarch64-linux-gnu
|
||||
pixi_env: cross-linux-aarch64
|
||||
|
||||
# Windows arm64 (from x64 windows-2025)
|
||||
- os: windows-2025
|
||||
llvm_mode: RelWithDebInfo
|
||||
lto: OFF
|
||||
target_triple: aarch64-pc-windows-msvc
|
||||
pixi_env: cross-windows-arm64
|
||||
- os: windows-2025
|
||||
llvm_mode: RelWithDebInfo
|
||||
lto: ON
|
||||
target_triple: aarch64-pc-windows-msvc
|
||||
pixi_env: cross-windows-arm64
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Free Disk Space
|
||||
if: runner.os == 'Linux'
|
||||
uses: jlumbroso/free-disk-space@main
|
||||
|
||||
- name: Increase Swap Space
|
||||
if: runner.os == 'Linux'
|
||||
run: |
|
||||
echo "===== Initial Status ====="
|
||||
sudo swapon --show
|
||||
free -h
|
||||
|
||||
echo "===== Creating Swap File ====="
|
||||
sudo swapoff -a
|
||||
sudo fallocate -l 16G /mnt/swapfile
|
||||
sudo chmod 600 /mnt/swapfile
|
||||
sudo mkswap /mnt/swapfile
|
||||
sudo swapon /mnt/swapfile
|
||||
|
||||
echo "===== Final Status ====="
|
||||
sudo swapon --show
|
||||
free -h
|
||||
df -h
|
||||
|
||||
- uses: ./.github/actions/setup-pixi
|
||||
with:
|
||||
environments: ${{ matrix.pixi_env || 'package' }}
|
||||
|
||||
- name: Clone llvm-project
|
||||
shell: bash
|
||||
run: |
|
||||
VERSION="${{ inputs.llvm_version || '21.1.8' }}"
|
||||
echo "Cloning LLVM ${VERSION}..."
|
||||
git clone --branch "llvmorg-${VERSION}" --depth 1 https://github.com/llvm/llvm-project.git .llvm
|
||||
|
||||
- name: Validate distribution components
|
||||
shell: bash
|
||||
run: |
|
||||
python3 scripts/validate-llvm-components.py \
|
||||
--llvm-src=.llvm \
|
||||
--components-file=scripts/llvm-components.json
|
||||
|
||||
- name: Build LLVM (install-distribution)
|
||||
shell: bash
|
||||
run: |
|
||||
ENV="${{ matrix.pixi_env || 'package' }}"
|
||||
EXTRA_ARGS=""
|
||||
if [[ -n "${{ matrix.target_triple }}" ]]; then
|
||||
EXTRA_ARGS="--target-triple=${{ matrix.target_triple }}"
|
||||
fi
|
||||
pixi run -e "$ENV" build-llvm \
|
||||
--llvm-src=.llvm \
|
||||
--mode="${{ matrix.llvm_mode }}" \
|
||||
--lto="${{ matrix.lto }}" \
|
||||
--build-dir=build \
|
||||
${EXTRA_ARGS}
|
||||
|
||||
- name: Build clice using installed LLVM
|
||||
if: ${{ !matrix.target_triple }}
|
||||
shell: bash
|
||||
run: |
|
||||
pixi run cmake-config ${{ matrix.llvm_mode }} ON -- \
|
||||
"-DCLICE_ENABLE_LTO=${{ matrix.lto }}" \
|
||||
"-DLLVM_INSTALL_PATH=.llvm/build-install"
|
||||
pixi run cmake-build ${{ matrix.llvm_mode }}
|
||||
|
||||
- name: Build clice using installed LLVM (cross-compile)
|
||||
if: ${{ matrix.target_triple }}
|
||||
shell: bash
|
||||
run: |
|
||||
ENV="${{ matrix.pixi_env || 'package' }}"
|
||||
pixi run -e "$ENV" cmake-config ${{ matrix.llvm_mode }} ON -- \
|
||||
"-DCLICE_ENABLE_LTO=${{ matrix.lto }}" \
|
||||
"-DCLICE_TARGET_TRIPLE=${{ matrix.target_triple }}" \
|
||||
"-DLLVM_INSTALL_PATH=.llvm/build-install"
|
||||
pixi run -e "$ENV" cmake-build ${{ matrix.llvm_mode }}
|
||||
|
||||
- name: Verify cross-compiled binary architecture
|
||||
if: ${{ matrix.target_triple && runner.os != 'Windows' }}
|
||||
shell: bash
|
||||
run: |
|
||||
BINARY="build/${{ matrix.llvm_mode }}/bin/clice"
|
||||
echo "Binary info:"
|
||||
file "$BINARY"
|
||||
case "${{ matrix.target_triple }}" in
|
||||
aarch64-linux-gnu) file "$BINARY" | grep -q "aarch64" ;;
|
||||
x86_64-apple-darwin) file "$BINARY" | grep -q "x86_64" ;;
|
||||
esac
|
||||
|
||||
- name: Upload cross-compiled clice for functional test
|
||||
if: ${{ matrix.target_triple && matrix.lto == 'OFF' }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: cross-clice-${{ matrix.target_triple }}-${{ matrix.llvm_mode }}
|
||||
path: |
|
||||
build/${{ matrix.llvm_mode }}/bin/
|
||||
build/${{ matrix.llvm_mode }}/lib/
|
||||
if-no-files-found: error
|
||||
retention-days: 1
|
||||
|
||||
- name: Run tests
|
||||
if: ${{ !matrix.target_triple }}
|
||||
shell: bash
|
||||
run: pixi run test ${{ matrix.llvm_mode }}
|
||||
|
||||
# Prune is only supported for native builds (requires linking clice to test).
|
||||
# Cross-compiled targets reuse the native prune manifest of the same OS.
|
||||
- name: Prune LLVM static libraries (Debug/RelWithDebInfo no LTO)
|
||||
if: (!matrix.target_triple) && (matrix.llvm_mode == 'Debug' || (matrix.llvm_mode == 'RelWithDebInfo' && matrix.lto == 'OFF'))
|
||||
shell: bash
|
||||
run: |
|
||||
MANIFEST="pruned-libs-${{ matrix.os }}.json"
|
||||
echo "LLVM_PRUNED_MANIFEST=${MANIFEST}" >> "${GITHUB_ENV}"
|
||||
python3 scripts/prune-llvm-bin.py \
|
||||
--action discover \
|
||||
--install-dir ".llvm/build-install/lib" \
|
||||
--build-dir "build/${{ matrix.llvm_mode }}" \
|
||||
--max-attempts 60 \
|
||||
--sleep-seconds 60 \
|
||||
--manifest "${MANIFEST}"
|
||||
|
||||
- name: Upload pruned-libs manifest
|
||||
if: (!matrix.target_triple) && matrix.llvm_mode == 'RelWithDebInfo' && matrix.lto == 'OFF'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: llvm-pruned-libs-${{ matrix.os }}
|
||||
path: ${{ env.LLVM_PRUNED_MANIFEST }}
|
||||
if-no-files-found: error
|
||||
compression-level: 0
|
||||
|
||||
- name: Apply pruned-libs manifest (RelWithDebInfo + LTO, native only)
|
||||
if: (!matrix.target_triple) && matrix.llvm_mode == 'RelWithDebInfo' && matrix.lto == 'ON'
|
||||
shell: bash
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
MANIFEST="pruned-libs-${{ matrix.os }}.json"
|
||||
python3 scripts/prune-llvm-bin.py \
|
||||
--action apply \
|
||||
--manifest "${MANIFEST}" \
|
||||
--install-dir ".llvm/build-install/lib" \
|
||||
--build-dir "build/${{ matrix.llvm_mode }}" \
|
||||
--gh-run-id "${{ github.run_id }}" \
|
||||
--gh-artifact "llvm-pruned-libs-${{ matrix.os }}" \
|
||||
--gh-download-dir "artifacts" \
|
||||
--max-attempts 60 \
|
||||
--sleep-seconds 60
|
||||
|
||||
# For cross-compiled LTO builds, apply the native prune manifest.
|
||||
# The unused library set is arch-independent (same API surface).
|
||||
- name: Apply pruned-libs manifest (cross-compile + LTO)
|
||||
if: matrix.target_triple && matrix.lto == 'ON'
|
||||
shell: bash
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
MANIFEST="pruned-libs-${{ matrix.os }}.json"
|
||||
python3 scripts/prune-llvm-bin.py \
|
||||
--action apply \
|
||||
--manifest "${MANIFEST}" \
|
||||
--install-dir ".llvm/build-install/lib" \
|
||||
--build-dir "build/${{ matrix.llvm_mode }}" \
|
||||
--gh-run-id "${{ github.run_id }}" \
|
||||
--gh-artifact "llvm-pruned-libs-${{ matrix.os }}" \
|
||||
--gh-download-dir "artifacts" \
|
||||
--max-attempts 60 \
|
||||
--sleep-seconds 60
|
||||
|
||||
- name: Package LLVM install directory
|
||||
shell: bash
|
||||
run: |
|
||||
MODE_TAG="releasedbg"
|
||||
if [[ "${{ matrix.llvm_mode }}" == "Debug" ]]; then
|
||||
MODE_TAG="debug"
|
||||
fi
|
||||
|
||||
# Determine arch/platform/toolchain from target triple or runner OS
|
||||
if [[ -n "${{ matrix.target_triple }}" ]]; then
|
||||
case "${{ matrix.target_triple }}" in
|
||||
x86_64-apple-darwin)
|
||||
ARCH="x64"; PLATFORM="macos"; TOOLCHAIN="clang" ;;
|
||||
aarch64-linux-gnu)
|
||||
ARCH="aarch64"; PLATFORM="linux"; TOOLCHAIN="gnu" ;;
|
||||
aarch64-pc-windows-msvc)
|
||||
ARCH="aarch64"; PLATFORM="windows"; TOOLCHAIN="msvc" ;;
|
||||
esac
|
||||
else
|
||||
ARCH="x64"
|
||||
PLATFORM="linux"
|
||||
TOOLCHAIN="gnu"
|
||||
if [[ "${{ matrix.os }}" == windows-* ]]; then
|
||||
PLATFORM="windows"
|
||||
TOOLCHAIN="msvc"
|
||||
elif [[ "${{ matrix.os }}" == macos-* ]]; then
|
||||
ARCH="arm64"
|
||||
PLATFORM="macos"
|
||||
TOOLCHAIN="clang"
|
||||
fi
|
||||
fi
|
||||
|
||||
SUFFIX=""
|
||||
if [[ "${{ matrix.lto }}" == "ON" ]]; then
|
||||
SUFFIX="-lto"
|
||||
fi
|
||||
if [[ "${{ matrix.llvm_mode }}" == "Debug" && "${{ matrix.os }}" != windows-* ]]; then
|
||||
SUFFIX="${SUFFIX}-asan"
|
||||
fi
|
||||
|
||||
ARCHIVE="${ARCH}-${PLATFORM}-${TOOLCHAIN}-${MODE_TAG}${SUFFIX}.tar.xz"
|
||||
|
||||
set -eo pipefail
|
||||
tar -C .llvm -cf - build-install | xz -T0 -9 -c > "${ARCHIVE}"
|
||||
echo "LLVM_INSTALL_ARCHIVE=${ARCHIVE}" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Upload LLVM install artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ env.LLVM_INSTALL_ARCHIVE }}
|
||||
path: ${{ env.LLVM_INSTALL_ARCHIVE }}
|
||||
if-no-files-found: error
|
||||
|
||||
test-cross:
|
||||
needs: build
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: macos-15-intel
|
||||
llvm_mode: RelWithDebInfo
|
||||
target_triple: x86_64-apple-darwin
|
||||
- os: ubuntu-24.04-arm
|
||||
llvm_mode: RelWithDebInfo
|
||||
target_triple: aarch64-linux-gnu
|
||||
- os: windows-11-arm
|
||||
llvm_mode: RelWithDebInfo
|
||||
target_triple: aarch64-pc-windows-msvc
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: ./.github/actions/setup-pixi
|
||||
with:
|
||||
environments: test-run
|
||||
|
||||
- name: Download cross-compiled clice
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: cross-clice-${{ matrix.target_triple }}-${{ matrix.llvm_mode }}
|
||||
path: build/${{ matrix.llvm_mode }}/
|
||||
|
||||
- name: Make binaries executable
|
||||
if: runner.os != 'Windows'
|
||||
run: chmod +x build/${{ matrix.llvm_mode }}/bin/*
|
||||
|
||||
- name: Run tests
|
||||
run: pixi run -e test-run test ${{ matrix.llvm_mode }}
|
||||
|
||||
upload:
|
||||
needs: build
|
||||
if: ${{ !cancelled() && inputs.llvm_version && !inputs.skip_upload }}
|
||||
runs-on: ubuntu-24.04
|
||||
permissions:
|
||||
contents: read
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Download all build artifacts
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: scripts/download-llvm.sh "${{ github.run_id }}"
|
||||
|
||||
- name: Upload to clice-llvm
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.UPLOAD_LLVM }}
|
||||
TARGET_REPO: clice-io/clice-llvm
|
||||
run: python3 scripts/upload-llvm.py "${{ inputs.llvm_version }}" "${TARGET_REPO}" "${{ github.run_id }}"
|
||||
|
||||
- name: Save manifest for update-clice job
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: llvm-manifest-final
|
||||
path: artifacts/llvm-manifest.json
|
||||
if-no-files-found: error
|
||||
compression-level: 0
|
||||
|
||||
update-clice:
|
||||
needs: upload
|
||||
if: ${{ !inputs.skip_pr }}
|
||||
runs-on: ubuntu-24.04
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Download manifest
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: llvm-manifest-final
|
||||
path: .
|
||||
|
||||
- name: Update manifest and version
|
||||
run: |
|
||||
python3 scripts/update-llvm-version.py \
|
||||
--version "${{ inputs.llvm_version }}" \
|
||||
--manifest-src llvm-manifest.json \
|
||||
--manifest-dest config/llvm-manifest.json \
|
||||
--package-cmake cmake/package.cmake
|
||||
|
||||
- name: Create or update PR
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
VERSION="${{ inputs.llvm_version }}"
|
||||
BRANCH="chore/update-llvm-${VERSION}"
|
||||
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||
RELEASE_URL="https://github.com/clice-io/clice-llvm/releases/tag/${VERSION}"
|
||||
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||
git checkout -b "${BRANCH}"
|
||||
git add config/llvm-manifest.json cmake/package.cmake
|
||||
git commit -m "chore: update LLVM to ${VERSION}"
|
||||
git push --force-with-lease origin "${BRANCH}"
|
||||
|
||||
# Check if PR already exists for this branch
|
||||
EXISTING_PR=$(gh pr list --head "${BRANCH}" --json number --jq '.[0].number // empty')
|
||||
|
||||
BODY="$(cat <<EOF
|
||||
## Summary
|
||||
- Update LLVM prebuilt binaries to version ${VERSION}
|
||||
- Updated \`config/llvm-manifest.json\` with new SHA256 hashes
|
||||
- Updated \`cmake/package.cmake\` version string
|
||||
|
||||
**Artifacts:** [clice-llvm release](${RELEASE_URL})
|
||||
**Build:** [workflow run](${RUN_URL})
|
||||
|
||||
> Auto-generated by build-llvm workflow
|
||||
EOF
|
||||
)"
|
||||
|
||||
if [[ -n "${EXISTING_PR}" ]]; then
|
||||
echo "Updating existing PR #${EXISTING_PR}"
|
||||
gh pr edit "${EXISTING_PR}" --body "${BODY}"
|
||||
else
|
||||
gh pr create \
|
||||
--title "chore: update LLVM to ${VERSION}" \
|
||||
--body "${BODY}" \
|
||||
--base main
|
||||
fi
|
||||
40
.gitea/workflows/check-format.yml
Normal file
40
.gitea/workflows/check-format.yml
Normal file
@@ -0,0 +1,40 @@
|
||||
name: format
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
check-format:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: ./.github/actions/setup-pixi
|
||||
with:
|
||||
environments: format
|
||||
|
||||
- name: Validate update-llvm-version.py can still patch package.cmake
|
||||
run: |
|
||||
python3 scripts/update-llvm-version.py --check \
|
||||
--manifest-dest config/llvm-manifest.json \
|
||||
--package-cmake cmake/package.cmake
|
||||
|
||||
- name: Run formatter
|
||||
run: pixi run format
|
||||
continue-on-error: true
|
||||
|
||||
- name: Auto correct
|
||||
uses: huacnlee/autocorrect-action@v2
|
||||
with:
|
||||
args: --lint ./docs
|
||||
continue-on-error: true
|
||||
|
||||
- name: Check diff
|
||||
run: |
|
||||
if ! git diff --quiet; then
|
||||
echo "::error::Formatting changes detected. Please run 'pixi run format' and commit the result."
|
||||
git --no-pager diff --stat
|
||||
git --no-pager diff
|
||||
exit 1
|
||||
fi
|
||||
30
.gitea/workflows/deploy-docs.yml
Normal file
30
.gitea/workflows/deploy-docs.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
name: deploy
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
deploy-docs:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: ./.github/actions/setup-pixi
|
||||
with:
|
||||
environments: node
|
||||
|
||||
- name: Build docs
|
||||
run: pixi run build-docs
|
||||
|
||||
- name: Deploy to GitHub Pages
|
||||
uses: peaceiris/actions-gh-pages@v4
|
||||
if: github.ref == 'refs/heads/main'
|
||||
with:
|
||||
personal_token: ${{ secrets.PUBLISH_DOCS }}
|
||||
external_repository: clice-io/docs
|
||||
publish_dir: ./docs/.vitepress/dist
|
||||
destination_dir: clice
|
||||
keep_files: true
|
||||
137
.gitea/workflows/main.yml
Normal file
137
.gitea/workflows/main.yml
Normal file
@@ -0,0 +1,137 @@
|
||||
name: main
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
tags: ["v*"]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
|
||||
|
||||
jobs:
|
||||
changes:
|
||||
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pull-requests: read
|
||||
outputs:
|
||||
format: ${{ steps.filter.outputs.format }}
|
||||
docs: ${{ steps.filter.outputs.docs }}
|
||||
clice: ${{ steps.filter.outputs.clice }}
|
||||
vscode: ${{ steps.filter.outputs.vscode }}
|
||||
cmake: ${{ steps.filter.outputs.cmake }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dorny/paths-filter@v3
|
||||
id: filter
|
||||
with:
|
||||
filters: |
|
||||
format:
|
||||
- '**/*.{h,c,cpp,hpp,ts,js,lua,md,yml,yaml}'
|
||||
docs:
|
||||
- 'docs/**'
|
||||
- '.github/workflows/deploy-docs.yml'
|
||||
clice:
|
||||
- 'src/**'
|
||||
- 'include/**'
|
||||
- 'CMakeLists.txt'
|
||||
- '.github/workflows/publish-clice.yml'
|
||||
vscode:
|
||||
- 'editors/vscode/**'
|
||||
- '.github/workflows/publish-vscode.yml'
|
||||
cmake:
|
||||
- 'CMakeLists.txt'
|
||||
- 'src/**'
|
||||
- 'include/**'
|
||||
- 'tests/**'
|
||||
- 'config/**'
|
||||
- '.github/workflows/test-cmake.yml'
|
||||
|
||||
conventional-commit:
|
||||
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check conventional commit format
|
||||
env:
|
||||
IS_PR: ${{ github.event_name == 'pull_request' }}
|
||||
PR_TITLE: ${{ github.event.pull_request.title }}
|
||||
COMMIT_MSG: ${{ github.event.head_commit.message }}
|
||||
run: |
|
||||
pattern='^(feat|fix|refactor|chore|build|ci|docs|test|perf|style|revert)(\(.+\))?: .+'
|
||||
if [[ "$IS_PR" == "true" ]]; then
|
||||
subject="$PR_TITLE"
|
||||
label="PR title"
|
||||
else
|
||||
subject=$(echo "$COMMIT_MSG" | head -n1)
|
||||
label="Commit message"
|
||||
fi
|
||||
if [[ ! "$subject" =~ $pattern ]]; then
|
||||
echo "::error::$label must follow conventional commit format: type(scope)?: description"
|
||||
echo " Valid types: feat, fix, refactor, chore, build, ci, docs, test, perf, style, revert"
|
||||
echo " Got: '$subject'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
format:
|
||||
needs: changes
|
||||
if: ${{ needs.changes.outputs.format == 'true' }}
|
||||
uses: ./.github/workflows/check-format.yml
|
||||
|
||||
deploy:
|
||||
needs: changes
|
||||
if: ${{ needs.changes.outputs.docs == 'true' }}
|
||||
permissions:
|
||||
contents: write
|
||||
uses: ./.github/workflows/deploy-docs.yml
|
||||
secrets: inherit
|
||||
|
||||
# clice:
|
||||
# needs: changes
|
||||
# if: ${{ needs.changes.outputs.clice == 'true' }}
|
||||
# uses: ./.github/workflows/publish-clice.yml
|
||||
|
||||
vscode:
|
||||
needs: changes
|
||||
if: ${{ needs.changes.outputs.vscode == 'true' }}
|
||||
uses: ./.github/workflows/publish-vscode.yml
|
||||
|
||||
cmake:
|
||||
needs: changes
|
||||
if: ${{ needs.changes.outputs.cmake == 'true' }}
|
||||
uses: ./.github/workflows/test-cmake.yml
|
||||
|
||||
release-clice:
|
||||
permissions:
|
||||
contents: write
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
uses: ./.github/workflows/publish-clice.yml
|
||||
secrets: inherit
|
||||
|
||||
release-vscode:
|
||||
permissions:
|
||||
contents: write
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
uses: ./.github/workflows/publish-vscode.yml
|
||||
secrets: inherit
|
||||
|
||||
checks-passed:
|
||||
if: ${{ always() && !startsWith(github.ref, 'refs/tags/') }}
|
||||
needs:
|
||||
- conventional-commit
|
||||
- format
|
||||
- deploy
|
||||
# - clice
|
||||
- vscode
|
||||
- cmake
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check results
|
||||
uses: re-actors/alls-green@release/v1
|
||||
with:
|
||||
allowed-skips: conventional-commit,format,deploy,clice,vscode,cmake
|
||||
jobs: ${{ toJSON(needs) }}
|
||||
100
.gitea/workflows/publish-clice.yml
Normal file
100
.gitea/workflows/publish-clice.yml
Normal file
@@ -0,0 +1,100 @@
|
||||
name: clice
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
publish-clice:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
# Native builds
|
||||
- os: windows-2025
|
||||
artifact_name: clice.zip
|
||||
asset_name: clice-x64-windows-msvc.zip
|
||||
symbol_artifact_name: clice-symbol.zip
|
||||
symbol_asset_name: clice-x64-windows-msvc-symbol.zip
|
||||
|
||||
- os: ubuntu-24.04
|
||||
artifact_name: clice.tar.gz
|
||||
asset_name: clice-x86_64-linux-gnu.tar.gz
|
||||
symbol_artifact_name: clice-symbol.tar.gz
|
||||
symbol_asset_name: clice-x86_64-linux-gnu-symbol.tar.gz
|
||||
|
||||
- os: macos-15
|
||||
artifact_name: clice.tar.gz
|
||||
asset_name: clice-arm64-macos-darwin.tar.gz
|
||||
symbol_artifact_name: clice-symbol.tar.gz
|
||||
symbol_asset_name: clice-arm64-macos-darwin-symbol.tar.gz
|
||||
|
||||
# Cross-compilation builds
|
||||
- os: macos-15
|
||||
target_triple: x86_64-apple-darwin
|
||||
pixi_env: cross-macos-x64
|
||||
artifact_name: clice.tar.gz
|
||||
asset_name: clice-x86_64-macos-darwin.tar.gz
|
||||
symbol_artifact_name: clice-symbol.tar.gz
|
||||
symbol_asset_name: clice-x86_64-macos-darwin-symbol.tar.gz
|
||||
|
||||
- os: ubuntu-24.04
|
||||
target_triple: aarch64-linux-gnu
|
||||
pixi_env: cross-linux-aarch64
|
||||
artifact_name: clice.tar.gz
|
||||
asset_name: clice-aarch64-linux-gnu.tar.gz
|
||||
symbol_artifact_name: clice-symbol.tar.gz
|
||||
symbol_asset_name: clice-aarch64-linux-gnu-symbol.tar.gz
|
||||
|
||||
- os: windows-2025
|
||||
target_triple: aarch64-pc-windows-msvc
|
||||
pixi_env: cross-windows-arm64
|
||||
artifact_name: clice.zip
|
||||
asset_name: clice-aarch64-windows-msvc.zip
|
||||
symbol_artifact_name: clice-symbol.zip
|
||||
symbol_asset_name: clice-aarch64-windows-msvc-symbol.zip
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: ./.github/actions/setup-pixi
|
||||
with:
|
||||
environments: ${{ matrix.pixi_env || 'package' }}
|
||||
|
||||
- name: Package (native)
|
||||
if: ${{ !matrix.target_triple }}
|
||||
run: pixi run package
|
||||
|
||||
- name: Package (cross-compile)
|
||||
if: ${{ matrix.target_triple }}
|
||||
run: |
|
||||
ENV="${{ matrix.pixi_env }}"
|
||||
pixi run -e "$ENV" package-config -- \
|
||||
"-DCLICE_TARGET_TRIPLE=${{ matrix.target_triple }}"
|
||||
pixi run -e "$ENV" cmake-build
|
||||
|
||||
- name: Upload Main Package to Release
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
file: build/RelWithDebInfo/${{ matrix.artifact_name }}
|
||||
asset_name: ${{ matrix.asset_name }}
|
||||
tag: ${{ github.ref }}
|
||||
overwrite: true
|
||||
|
||||
- name: Upload Symbol Package to Release
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
file: build/RelWithDebInfo/${{ matrix.symbol_artifact_name }}
|
||||
asset_name: ${{ matrix.symbol_asset_name }}
|
||||
tag: ${{ github.ref }}
|
||||
overwrite: true
|
||||
38
.gitea/workflows/publish-vscode.yml
Normal file
38
.gitea/workflows/publish-vscode.yml
Normal file
@@ -0,0 +1,38 @@
|
||||
name: vscode
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
publish-vscode:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: editors/vscode
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: ./.github/actions/setup-pixi
|
||||
with:
|
||||
environments: node
|
||||
|
||||
- name: Publish and Package to Marketplace
|
||||
env:
|
||||
VSCE_PAT: ${{ secrets.VSCE_PAT }}
|
||||
run: |
|
||||
FLAG="${{ contains(github.ref_name, '-') && '--pre-release' || '' }}"
|
||||
pixi run build-vscode $FLAG
|
||||
|
||||
if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
|
||||
pixi run publish-vscode -p "$VSCE_PAT" $FLAG
|
||||
fi
|
||||
|
||||
- name: Upload .vsix to Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
with:
|
||||
files: "editors/vscode/*.vsix"
|
||||
tag_name: ${{ github.ref }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
170
.gitea/workflows/test-cmake.yml
Normal file
170
.gitea/workflows/test-cmake.yml
Normal file
@@ -0,0 +1,170 @@
|
||||
name: cmake
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
|
||||
env:
|
||||
CCACHE_DIR: ${{ github.workspace }}/.cache/ccache
|
||||
SCCACHE_DIR: ${{ github.workspace }}/.cache/sccache
|
||||
CCACHE_BASEDIR: ${{ github.workspace }}
|
||||
SCCACHE_BASEDIRS: ${{ github.workspace }}
|
||||
CCACHE_COMPILERCHECK: content
|
||||
CCACHE_MAXSIZE: 2G
|
||||
SCCACHE_CACHE_SIZE: 2G
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
# Native builds
|
||||
- os: windows-2025
|
||||
build_type: RelWithDebInfo
|
||||
- os: ubuntu-24.04
|
||||
build_type: Debug
|
||||
- os: ubuntu-24.04
|
||||
build_type: RelWithDebInfo
|
||||
- os: macos-15
|
||||
build_type: Debug
|
||||
- os: macos-15
|
||||
build_type: RelWithDebInfo
|
||||
# Cross-compile (build only; tests run on native runners)
|
||||
- os: macos-15
|
||||
build_type: RelWithDebInfo
|
||||
target_triple: x86_64-apple-darwin
|
||||
build_only: true
|
||||
- os: ubuntu-24.04
|
||||
build_type: RelWithDebInfo
|
||||
target_triple: aarch64-linux-gnu
|
||||
build_only: true
|
||||
pixi_env: cross-linux-aarch64
|
||||
- os: windows-2025
|
||||
build_type: RelWithDebInfo
|
||||
target_triple: aarch64-pc-windows-msvc
|
||||
build_only: true
|
||||
pixi_env: cross-windows-arm64
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: ./.github/actions/setup-pixi
|
||||
with:
|
||||
environments: ${{ matrix.pixi_env || 'default' }}
|
||||
|
||||
- name: Restore compiler cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ runner.os == 'Windows' && '.cache/sccache' || '.cache/ccache' }}
|
||||
key: ${{ runner.os }}-${{ matrix.build_type }}-${{ matrix.target_triple || 'native' }}-ccache-${{ github.sha }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-${{ matrix.build_type }}-${{ matrix.target_triple || 'native' }}-ccache-
|
||||
|
||||
- name: Zero cache stats
|
||||
run: |
|
||||
ENV="${{ matrix.pixi_env || 'default' }}"
|
||||
if [ "$RUNNER_OS" = "Windows" ]; then
|
||||
pixi run -e "$ENV" -- sccache --stop-server || true
|
||||
pixi run -e "$ENV" -- sccache --zero-stats || true
|
||||
else
|
||||
pixi run -e "$ENV" -- ccache --zero-stats || true
|
||||
fi
|
||||
shell: bash
|
||||
|
||||
- name: Build (native)
|
||||
if: ${{ !matrix.target_triple }}
|
||||
run: pixi run build ${{ matrix.build_type }} ON
|
||||
|
||||
- name: Build (cross-compile)
|
||||
if: ${{ matrix.target_triple }}
|
||||
shell: bash
|
||||
run: |
|
||||
ENV="${{ matrix.pixi_env || 'default' }}"
|
||||
pixi run -e "$ENV" cmake-config ${{ matrix.build_type }} OFF -- \
|
||||
"-DCLICE_TARGET_TRIPLE=${{ matrix.target_triple }}"
|
||||
pixi run -e "$ENV" cmake-build ${{ matrix.build_type }}
|
||||
|
||||
- name: Upload cross-compiled binaries
|
||||
if: ${{ matrix.build_only }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: cross-build-${{ matrix.target_triple }}
|
||||
path: |
|
||||
build/${{ matrix.build_type }}/bin/
|
||||
build/${{ matrix.build_type }}/lib/
|
||||
if-no-files-found: error
|
||||
retention-days: 1
|
||||
|
||||
- name: Unit tests
|
||||
if: ${{ !matrix.build_only }}
|
||||
timeout-minutes: 5
|
||||
run: pixi run unit-test ${{ matrix.build_type }}
|
||||
|
||||
- name: Integration tests
|
||||
if: ${{ !matrix.build_only }}
|
||||
timeout-minutes: 20
|
||||
run: pixi run integration-test ${{ matrix.build_type }}
|
||||
|
||||
- name: Smoke tests
|
||||
if: ${{ !matrix.build_only }}
|
||||
timeout-minutes: 15
|
||||
run: pixi run smoke-test ${{ matrix.build_type }}
|
||||
|
||||
- name: Print cache stats and stop server
|
||||
if: always()
|
||||
run: |
|
||||
ENV="${{ matrix.pixi_env || 'default' }}"
|
||||
if [ "$RUNNER_OS" = "Windows" ]; then
|
||||
pixi run -e "$ENV" -- sccache --show-stats
|
||||
pixi run -e "$ENV" -- sccache --stop-server || true
|
||||
else
|
||||
pixi run -e "$ENV" -- ccache --show-stats
|
||||
fi
|
||||
shell: bash
|
||||
|
||||
test-cross:
|
||||
needs: build
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: macos-15-intel
|
||||
build_type: RelWithDebInfo
|
||||
target_triple: x86_64-apple-darwin
|
||||
- os: ubuntu-24.04-arm
|
||||
build_type: RelWithDebInfo
|
||||
target_triple: aarch64-linux-gnu
|
||||
- os: windows-11-arm
|
||||
build_type: RelWithDebInfo
|
||||
target_triple: aarch64-pc-windows-msvc
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: ./.github/actions/setup-pixi
|
||||
with:
|
||||
environments: test-run
|
||||
|
||||
- name: Download cross-compiled binaries
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: cross-build-${{ matrix.target_triple }}
|
||||
path: build/${{ matrix.build_type }}/
|
||||
|
||||
- name: Make binaries executable
|
||||
if: runner.os != 'Windows'
|
||||
run: chmod +x build/${{ matrix.build_type }}/bin/*
|
||||
|
||||
- name: Unit tests
|
||||
timeout-minutes: 5
|
||||
run: pixi run -e test-run unit-test ${{ matrix.build_type }}
|
||||
|
||||
- name: Integration tests
|
||||
timeout-minutes: 20
|
||||
run: pixi run -e test-run integration-test ${{ matrix.build_type }}
|
||||
|
||||
- name: Smoke tests
|
||||
timeout-minutes: 10
|
||||
run: pixi run -e test-run smoke-test ${{ matrix.build_type }}
|
||||
38
.gitea/workflows/upload-llvm.yml
Normal file
38
.gitea/workflows/upload-llvm.yml
Normal file
@@ -0,0 +1,38 @@
|
||||
name: upload-llvm
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
# if you want to run this workflow, change the branch name to main,
|
||||
# if you want to turn off it, change it to non existent branch.
|
||||
branches: [main-turn-off]
|
||||
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
workflow_id:
|
||||
description: "Workflow run ID to pull artifacts from"
|
||||
required: true
|
||||
type: string
|
||||
version:
|
||||
description: "Release version/tag to publish (e.g., v1.2.3)"
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
upload:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Download artifacts from workflow
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: scripts/download-llvm.sh "${{ inputs.workflow_id }}"
|
||||
|
||||
- name: Recreate release with artifacts
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.UPLOAD_LLVM }}
|
||||
TARGET_REPO: clice-io/clice-llvm
|
||||
run: python3 scripts/upload-llvm.py "${{ inputs.version }}" "${TARGET_REPO}" "${{ inputs.workflow_id }}"
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -68,8 +68,7 @@ tests/unit/Local/
|
||||
.pixi/*
|
||||
!.pixi/config.toml
|
||||
|
||||
.codex/
|
||||
.codex
|
||||
.claude/*
|
||||
!.claude/CLAUDE.md
|
||||
!.claude/commands/
|
||||
openspec/
|
||||
|
||||
@@ -41,7 +41,7 @@ set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "" FORCE)
|
||||
FetchContent_Declare(
|
||||
kotatsu
|
||||
GIT_REPOSITORY https://github.com/clice-io/kotatsu
|
||||
GIT_TAG e024f3b427a554502c4aa015952800a03ca4384b
|
||||
GIT_TAG 73814044ce8142f4438a3028f44668675fc09fff
|
||||
)
|
||||
|
||||
set(KOTA_ENABLE_ZEST ON)
|
||||
|
||||
@@ -161,7 +161,7 @@ depends-on = [{ task = "lint-cpp", args = ["{{ type }}"] }]
|
||||
|
||||
[feature.test.tasks.unit-test]
|
||||
args = [{ arg = "type", default = "RelWithDebInfo" }]
|
||||
cmd = './build/{{ type }}/bin/unit_tests --test-dir="./tests/data"'
|
||||
cmd = './build/{{ type }}/bin/unit_tests --test-dir="./tests/data" --snapshot-dir="./tests/snapshots" --corpus-dir="./tests/corpus" --verbose'
|
||||
|
||||
[feature.test.tasks.integration-test]
|
||||
args = [{ arg = "type", default = "RelWithDebInfo" }]
|
||||
@@ -257,7 +257,7 @@ format-markdown = "fd -H -e md -x prettier --write"
|
||||
format-json = "fd -H -e json -E package-lock.json -x prettier --write"
|
||||
format-toml = "fd -H -e toml -x tombi format"
|
||||
format-yaml = """
|
||||
fd -H -e yaml -e yml -E pnpm-lock.yaml -x prettier --write && \
|
||||
fd -H -e yaml -e yml -E pnpm-lock.yaml -E '*.snap.yml' -x prettier --write && \
|
||||
fd -H "^\\.clang-(format|tidy)$" -x prettier --write --parser yaml
|
||||
"""
|
||||
format = { depends-on = [
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "support/logging.h"
|
||||
|
||||
#include "kota/meta/enum.h"
|
||||
#include "llvm/ADT/DenseSet.h"
|
||||
#include "llvm/ADT/ScopeExit.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
@@ -17,6 +18,7 @@
|
||||
#include "llvm/TargetParser/Host.h"
|
||||
#include "clang/Driver/Compilation.h"
|
||||
#include "clang/Driver/Driver.h"
|
||||
#include "clang/Driver/Options.h"
|
||||
#include "clang/Driver/Tool.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
@@ -470,11 +472,32 @@ std::vector<const char*> query_clang_toolchain(const QueryParams& params) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for(auto arg: args) {
|
||||
if(arg == "-###"sv) {
|
||||
// FIXME: the system compiler may be newer than our embedded LLVM,
|
||||
// producing cc1 flags we don't recognize. Filter them out here.
|
||||
// Long-term we should unify the command pipeline so the driver
|
||||
// version always matches the embedded LLVM.
|
||||
auto& table = clang::driver::getDriverOptTable();
|
||||
auto cc1_args = llvm::ArrayRef(args).drop_front(2);
|
||||
unsigned missing_index = 0, missing_count = 0;
|
||||
auto parsed = table.ParseArgs(cc1_args, missing_index, missing_count);
|
||||
|
||||
llvm::DenseSet<unsigned> unknown_indices;
|
||||
for(auto* a: parsed) {
|
||||
if(a->getOption().getKind() == llvm::opt::Option::UnknownClass) {
|
||||
unknown_indices.insert(a->getIndex());
|
||||
}
|
||||
}
|
||||
|
||||
result.emplace_back(params.callback(args[0]));
|
||||
result.emplace_back(params.callback(args[1]));
|
||||
for(unsigned i = 0; i < cc1_args.size(); ++i) {
|
||||
if(unknown_indices.contains(i)) {
|
||||
continue;
|
||||
}
|
||||
result.emplace_back(params.callback(arg));
|
||||
if(cc1_args[i] == "-###"sv) {
|
||||
continue;
|
||||
}
|
||||
result.emplace_back(params.callback(cc1_args[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,18 +93,9 @@ auto symbol_detail(clang::ASTContext& context, const clang::NamedDecl& decl) ->
|
||||
return detail;
|
||||
}
|
||||
|
||||
struct InternalSymbol {
|
||||
std::string name;
|
||||
std::string detail;
|
||||
SymbolKind kind = SymbolKind::Invalid;
|
||||
LocalSourceRange range;
|
||||
LocalSourceRange selection_range;
|
||||
std::vector<InternalSymbol> children;
|
||||
};
|
||||
|
||||
struct SymbolFrame {
|
||||
std::vector<InternalSymbol> symbols;
|
||||
std::vector<InternalSymbol>* cursor = &symbols;
|
||||
std::vector<DocumentSymbol> symbols;
|
||||
std::vector<DocumentSymbol>* cursor = &symbols;
|
||||
};
|
||||
|
||||
class DocumentSymbolCollector : public FilteredASTVisitor<DocumentSymbolCollector> {
|
||||
@@ -143,7 +134,7 @@ public:
|
||||
return ok;
|
||||
}
|
||||
|
||||
auto collect() -> std::vector<InternalSymbol> {
|
||||
auto collect() -> std::vector<DocumentSymbol> {
|
||||
TraverseDecl(unit.tu());
|
||||
return std::move(result.symbols);
|
||||
}
|
||||
@@ -174,8 +165,8 @@ private:
|
||||
SymbolFrame result;
|
||||
};
|
||||
|
||||
void sort_symbols(std::vector<InternalSymbol>& symbols) {
|
||||
std::ranges::sort(symbols, [](const InternalSymbol& lhs, const InternalSymbol& rhs) {
|
||||
void sort_symbols(std::vector<DocumentSymbol>& symbols) {
|
||||
std::ranges::sort(symbols, [](const DocumentSymbol& lhs, const DocumentSymbol& rhs) {
|
||||
if(lhs.range.begin != rhs.range.begin) {
|
||||
return lhs.range.begin < rhs.range.begin;
|
||||
}
|
||||
@@ -187,7 +178,7 @@ void sort_symbols(std::vector<InternalSymbol>& symbols) {
|
||||
}
|
||||
}
|
||||
|
||||
auto to_protocol_symbol(const InternalSymbol& symbol, const PositionMapper& converter)
|
||||
auto to_protocol_symbol(const DocumentSymbol& symbol, const PositionMapper& converter)
|
||||
-> protocol::DocumentSymbol {
|
||||
protocol::DocumentSymbol result{
|
||||
.name = symbol.name,
|
||||
@@ -215,10 +206,15 @@ auto to_protocol_symbol(const InternalSymbol& symbol, const PositionMapper& conv
|
||||
|
||||
} // namespace
|
||||
|
||||
auto document_symbols(CompilationUnitRef unit) -> std::vector<DocumentSymbol> {
|
||||
auto result = DocumentSymbolCollector(unit).collect();
|
||||
sort_symbols(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
auto document_symbols(CompilationUnitRef unit, PositionEncoding encoding)
|
||||
-> std::vector<protocol::DocumentSymbol> {
|
||||
auto internal = DocumentSymbolCollector(unit).collect();
|
||||
sort_symbols(internal);
|
||||
auto internal = document_symbols(unit);
|
||||
|
||||
PositionMapper converter(unit.interested_content(), encoding);
|
||||
std::vector<protocol::DocumentSymbol> symbols;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "compile/compilation.h"
|
||||
#include "compile/compilation_unit.h"
|
||||
#include "semantic/symbol_kind.h"
|
||||
|
||||
#include "kota/ipc/lsp/position.h"
|
||||
#include "kota/ipc/lsp/protocol.h"
|
||||
@@ -59,18 +60,66 @@ struct InlayHintsOptions {
|
||||
|
||||
struct SignatureHelpOptions {};
|
||||
|
||||
auto semantic_tokens(CompilationUnitRef unit, PositionEncoding encoding = PositionEncoding::UTF16)
|
||||
struct SemanticToken {
|
||||
LocalSourceRange range;
|
||||
SymbolKind kind = SymbolKind::Invalid;
|
||||
std::uint32_t modifiers = 0;
|
||||
};
|
||||
|
||||
struct FoldingRange {
|
||||
LocalSourceRange range;
|
||||
std::optional<protocol::FoldingRangeKind> kind;
|
||||
std::string collapsed_text;
|
||||
};
|
||||
|
||||
struct DocumentSymbol {
|
||||
std::string name;
|
||||
std::string detail;
|
||||
SymbolKind kind = SymbolKind::Invalid;
|
||||
LocalSourceRange range;
|
||||
LocalSourceRange selection_range;
|
||||
std::vector<DocumentSymbol> children;
|
||||
};
|
||||
|
||||
enum class HintCategory : std::uint8_t {
|
||||
Parameter,
|
||||
DefaultArgument,
|
||||
Type,
|
||||
Designator,
|
||||
BlockEnd,
|
||||
};
|
||||
|
||||
struct InlayHint {
|
||||
std::uint32_t offset = 0;
|
||||
HintCategory kind = HintCategory::Type;
|
||||
std::string label;
|
||||
bool padding_left = false;
|
||||
bool padding_right = false;
|
||||
};
|
||||
|
||||
auto semantic_tokens(CompilationUnitRef unit) -> std::vector<SemanticToken>;
|
||||
auto semantic_tokens(CompilationUnitRef unit, PositionEncoding encoding)
|
||||
-> protocol::SemanticTokens;
|
||||
|
||||
auto folding_ranges(CompilationUnitRef unit) -> std::vector<FoldingRange>;
|
||||
auto folding_ranges(CompilationUnitRef unit, PositionEncoding encoding)
|
||||
-> std::vector<protocol::FoldingRange>;
|
||||
|
||||
auto document_symbols(CompilationUnitRef unit) -> std::vector<DocumentSymbol>;
|
||||
auto document_symbols(CompilationUnitRef unit, PositionEncoding encoding)
|
||||
-> std::vector<protocol::DocumentSymbol>;
|
||||
|
||||
auto inlay_hints(CompilationUnitRef unit,
|
||||
LocalSourceRange target,
|
||||
const InlayHintsOptions& options = {}) -> std::vector<InlayHint>;
|
||||
auto inlay_hints(CompilationUnitRef unit,
|
||||
LocalSourceRange target,
|
||||
const InlayHintsOptions& options,
|
||||
PositionEncoding encoding) -> std::vector<protocol::InlayHint>;
|
||||
|
||||
auto document_links(CompilationUnitRef unit, PositionEncoding encoding = PositionEncoding::UTF16)
|
||||
-> std::vector<protocol::DocumentLink>;
|
||||
|
||||
auto document_symbols(CompilationUnitRef unit, PositionEncoding encoding = PositionEncoding::UTF16)
|
||||
-> std::vector<protocol::DocumentSymbol>;
|
||||
|
||||
auto folding_ranges(CompilationUnitRef unit, PositionEncoding encoding = PositionEncoding::UTF16)
|
||||
-> std::vector<protocol::FoldingRange>;
|
||||
|
||||
auto diagnostics(CompilationUnitRef unit, PositionEncoding encoding = PositionEncoding::UTF16)
|
||||
-> std::vector<protocol::Diagnostic>;
|
||||
|
||||
@@ -89,12 +138,6 @@ auto hover(CompilationUnitRef unit,
|
||||
const HoverOptions& options = {},
|
||||
PositionEncoding encoding = PositionEncoding::UTF16) -> std::optional<protocol::Hover>;
|
||||
|
||||
auto inlay_hints(CompilationUnitRef unit,
|
||||
LocalSourceRange target,
|
||||
const InlayHintsOptions& options = {},
|
||||
PositionEncoding encoding = PositionEncoding::UTF16)
|
||||
-> std::vector<protocol::InlayHint>;
|
||||
|
||||
auto signature_help(CompilationParams& params, const SignatureHelpOptions& options = {})
|
||||
-> protocol::SignatureHelp;
|
||||
|
||||
|
||||
@@ -53,12 +53,6 @@ auto to_kind(FoldingKind kind) -> protocol::FoldingRangeKind {
|
||||
return protocol::FoldingRangeKind(protocol::FoldingRangeKind::region);
|
||||
}
|
||||
|
||||
struct RawFoldingRange {
|
||||
LocalSourceRange range;
|
||||
std::optional<protocol::FoldingRangeKind> kind;
|
||||
std::string collapsed_text;
|
||||
};
|
||||
|
||||
class FoldingRangeCollector : public FilteredASTVisitor<FoldingRangeCollector> {
|
||||
public:
|
||||
explicit FoldingRangeCollector(CompilationUnitRef unit) : FilteredASTVisitor(unit, true) {}
|
||||
@@ -185,7 +179,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
auto collect() -> std::vector<RawFoldingRange> {
|
||||
auto collect() -> std::vector<FoldingRange> {
|
||||
TraverseDecl(unit.tu());
|
||||
|
||||
auto directives_it = unit.directives().find(unit.interested_file());
|
||||
@@ -193,7 +187,7 @@ public:
|
||||
collect_directives(directives_it->second);
|
||||
}
|
||||
|
||||
std::ranges::sort(ranges, [](const RawFoldingRange& lhs, const RawFoldingRange& rhs) {
|
||||
std::ranges::sort(ranges, [](const FoldingRange& lhs, const FoldingRange& rhs) {
|
||||
if(lhs.range.begin != rhs.range.begin) {
|
||||
return lhs.range.begin < rhs.range.begin;
|
||||
}
|
||||
@@ -343,14 +337,18 @@ private:
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<RawFoldingRange> ranges;
|
||||
std::vector<FoldingRange> ranges;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
auto folding_ranges(CompilationUnitRef unit) -> std::vector<FoldingRange> {
|
||||
return FoldingRangeCollector(unit).collect();
|
||||
}
|
||||
|
||||
auto folding_ranges(CompilationUnitRef unit, PositionEncoding encoding)
|
||||
-> std::vector<protocol::FoldingRange> {
|
||||
auto collected = FoldingRangeCollector(unit).collect();
|
||||
auto collected = folding_ranges(unit);
|
||||
PositionMapper converter(unit.interested_content(), encoding);
|
||||
|
||||
std::vector<protocol::FoldingRange> result;
|
||||
|
||||
@@ -26,22 +26,6 @@ using llvm::dyn_cast_or_null;
|
||||
// For now, inlay hints are always anchored at the left or right of their range.
|
||||
enum class HintSide { Left, Right };
|
||||
|
||||
enum class HintCategory : std::uint8_t {
|
||||
Parameter,
|
||||
DefaultArgument,
|
||||
Type,
|
||||
Designator,
|
||||
BlockEnd,
|
||||
};
|
||||
|
||||
struct RawInlayHint {
|
||||
std::uint32_t offset = 0;
|
||||
HintCategory kind = HintCategory::Type;
|
||||
std::string label;
|
||||
bool padding_left = false;
|
||||
bool padding_right = false;
|
||||
};
|
||||
|
||||
bool is_expanded_from_param_pack(const clang::ParmVarDecl* param) {
|
||||
return ast::underlying_pack_type(param) != nullptr;
|
||||
}
|
||||
@@ -123,7 +107,7 @@ struct Callee {
|
||||
|
||||
class Builder {
|
||||
public:
|
||||
Builder(std::vector<RawInlayHint>& result,
|
||||
Builder(std::vector<InlayHint>& result,
|
||||
CompilationUnitRef unit,
|
||||
LocalSourceRange restrict_range,
|
||||
const InlayHintsOptions& options) :
|
||||
@@ -499,7 +483,7 @@ public:
|
||||
bool pad_left = prefix.consume_front(" ");
|
||||
bool pad_right = suffix.consume_back(" ");
|
||||
|
||||
RawInlayHint hint{
|
||||
InlayHint hint{
|
||||
.offset = offset,
|
||||
.kind = kind,
|
||||
.label = (prefix + label + suffix).str(),
|
||||
@@ -554,7 +538,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<RawInlayHint>& result;
|
||||
std::vector<InlayHint>& result;
|
||||
CompilationUnitRef unit;
|
||||
LocalSourceRange restrict_range;
|
||||
const InlayHintsOptions& options;
|
||||
@@ -913,36 +897,43 @@ private:
|
||||
|
||||
} // namespace
|
||||
|
||||
auto inlay_hints(CompilationUnitRef unit,
|
||||
LocalSourceRange target,
|
||||
const InlayHintsOptions& options,
|
||||
PositionEncoding encoding) -> std::vector<protocol::InlayHint> {
|
||||
auto inlay_hints(CompilationUnitRef unit, LocalSourceRange target, const InlayHintsOptions& options)
|
||||
-> std::vector<InlayHint> {
|
||||
if(!options.enabled) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<RawInlayHint> raw_hints;
|
||||
std::vector<InlayHint> raw_hints;
|
||||
|
||||
Builder builder(raw_hints, unit, target, options);
|
||||
Visitor visitor(builder, unit, target, options);
|
||||
visitor.TraverseDecl(unit.tu());
|
||||
|
||||
std::ranges::sort(raw_hints, [](const RawInlayHint& lhs, const RawInlayHint& rhs) {
|
||||
std::ranges::sort(raw_hints, [](const InlayHint& lhs, const InlayHint& rhs) {
|
||||
return std::tie(lhs.offset, lhs.label, lhs.kind, lhs.padding_left, lhs.padding_right) <
|
||||
std::tie(rhs.offset, rhs.label, rhs.kind, rhs.padding_left, rhs.padding_right);
|
||||
});
|
||||
auto unique_begin =
|
||||
std::ranges::unique(raw_hints, [](const RawInlayHint& lhs, const RawInlayHint& rhs) {
|
||||
std::ranges::unique(raw_hints, [](const InlayHint& lhs, const InlayHint& rhs) {
|
||||
return lhs.offset == rhs.offset && lhs.kind == rhs.kind && lhs.label == rhs.label &&
|
||||
lhs.padding_left == rhs.padding_left && lhs.padding_right == rhs.padding_right;
|
||||
});
|
||||
raw_hints.erase(unique_begin.begin(), unique_begin.end());
|
||||
|
||||
return raw_hints;
|
||||
}
|
||||
|
||||
auto inlay_hints(CompilationUnitRef unit,
|
||||
LocalSourceRange target,
|
||||
const InlayHintsOptions& options,
|
||||
PositionEncoding encoding) -> std::vector<protocol::InlayHint> {
|
||||
auto collected = inlay_hints(unit, target, options);
|
||||
|
||||
PositionMapper converter(unit.interested_content(), encoding);
|
||||
std::vector<protocol::InlayHint> hints;
|
||||
hints.reserve(raw_hints.size());
|
||||
hints.reserve(collected.size());
|
||||
|
||||
for(const auto& hint: raw_hints) {
|
||||
for(const auto& hint: collected) {
|
||||
protocol::InlayHint out{
|
||||
.position = *converter.to_position(hint.offset),
|
||||
.label = hint.label,
|
||||
|
||||
@@ -18,12 +18,6 @@ namespace clice::feature {
|
||||
|
||||
namespace {
|
||||
|
||||
struct RawToken {
|
||||
LocalSourceRange range;
|
||||
SymbolKind kind = SymbolKind::Invalid;
|
||||
std::uint32_t modifiers = 0;
|
||||
};
|
||||
|
||||
void add_modifier(std::uint32_t& modifiers, SymbolModifiers::Kind kind) {
|
||||
modifiers |= SymbolModifiers::to_mask(kind);
|
||||
}
|
||||
@@ -40,6 +34,34 @@ bool is_dependent(const clang::Decl* D) {
|
||||
return isa<clang::UnresolvedUsingValueDecl>(D);
|
||||
}
|
||||
|
||||
/// Whether a declaration name is backed by source text that should be highlighted.
|
||||
bool can_highlight_name(clang::DeclarationName name) {
|
||||
switch(name.getNameKind()) {
|
||||
case clang::DeclarationName::Identifier: {
|
||||
auto* info = name.getAsIdentifierInfo();
|
||||
return info && !info->getName().empty();
|
||||
}
|
||||
|
||||
case clang::DeclarationName::CXXConstructorName:
|
||||
case clang::DeclarationName::CXXDestructorName: {
|
||||
return true;
|
||||
}
|
||||
|
||||
case clang::DeclarationName::CXXConversionFunctionName:
|
||||
case clang::DeclarationName::CXXOperatorName:
|
||||
case clang::DeclarationName::CXXDeductionGuideName:
|
||||
case clang::DeclarationName::CXXLiteralOperatorName:
|
||||
case clang::DeclarationName::CXXUsingDirective:
|
||||
case clang::DeclarationName::ObjCZeroArgSelector:
|
||||
case clang::DeclarationName::ObjCOneArgSelector:
|
||||
case clang::DeclarationName::ObjCMultiArgSelector: {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::unreachable();
|
||||
}
|
||||
|
||||
/// Returns true if `decl` is considered to be from a default/system library.
|
||||
/// This currently checks the systemness of the file by include type, although
|
||||
/// different heuristics may be used in the future (e.g. sysroot paths).
|
||||
@@ -166,7 +188,7 @@ class SemanticTokensCollector : public SemanticVisitor<SemanticTokensCollector>
|
||||
public:
|
||||
explicit SemanticTokensCollector(CompilationUnitRef unit) : SemanticVisitor(unit, true) {}
|
||||
|
||||
auto collect() -> std::vector<RawToken> {
|
||||
auto collect() -> std::vector<SemanticToken> {
|
||||
highlight_lexical(unit.interested_file());
|
||||
run();
|
||||
highlight_modules();
|
||||
@@ -177,6 +199,10 @@ public:
|
||||
void handleDeclOccurrence(const clang::NamedDecl* decl,
|
||||
RelationKind relation,
|
||||
clang::SourceLocation location) {
|
||||
if(relation.isReference() && !can_highlight_name(decl->getDeclName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::uint32_t modifiers = 0;
|
||||
if(relation.is_one_of(RelationKind::Definition)) {
|
||||
// todo: clangd add both Declaration and Definition modifiers for definitions.
|
||||
@@ -398,7 +424,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
static void resolve_conflict(RawToken& last, const RawToken& current) {
|
||||
static void resolve_conflict(SemanticToken& last, const SemanticToken& current) {
|
||||
if(last.kind == SymbolKind::Conflict) {
|
||||
return;
|
||||
}
|
||||
@@ -414,14 +440,14 @@ private:
|
||||
}
|
||||
|
||||
void merge_tokens() {
|
||||
std::ranges::sort(tokens, [](const RawToken& lhs, const RawToken& rhs) {
|
||||
std::ranges::sort(tokens, [](const SemanticToken& lhs, const SemanticToken& rhs) {
|
||||
if(lhs.range.begin != rhs.range.begin) {
|
||||
return lhs.range.begin < rhs.range.begin;
|
||||
}
|
||||
return lhs.range.end < rhs.range.end;
|
||||
});
|
||||
|
||||
std::vector<RawToken> merged;
|
||||
std::vector<SemanticToken> merged;
|
||||
merged.reserve(tokens.size());
|
||||
|
||||
for(const auto& token: tokens) {
|
||||
@@ -448,7 +474,7 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
std::vector<RawToken> tokens;
|
||||
std::vector<SemanticToken> tokens;
|
||||
};
|
||||
|
||||
class SemanticTokenEncoder {
|
||||
@@ -458,7 +484,7 @@ public:
|
||||
protocol::SemanticTokens& output) :
|
||||
content(content), converter(content, encoding), output(output) {}
|
||||
|
||||
void append(const RawToken& token) {
|
||||
void append(const SemanticToken& token) {
|
||||
if(!token.range.valid() || token.range.end <= token.range.begin ||
|
||||
token.range.end > content.size()) {
|
||||
return;
|
||||
@@ -542,10 +568,14 @@ private:
|
||||
|
||||
} // namespace
|
||||
|
||||
auto semantic_tokens(CompilationUnitRef unit) -> std::vector<SemanticToken> {
|
||||
SemanticTokensCollector collector(unit);
|
||||
return collector.collect();
|
||||
}
|
||||
|
||||
auto semantic_tokens(CompilationUnitRef unit, PositionEncoding encoding)
|
||||
-> protocol::SemanticTokens {
|
||||
SemanticTokensCollector collector(unit);
|
||||
auto tokens = collector.collect();
|
||||
auto tokens = semantic_tokens(unit);
|
||||
|
||||
protocol::SemanticTokens result;
|
||||
result.data.reserve(tokens.size() * 5);
|
||||
|
||||
@@ -245,26 +245,33 @@ void StatefulWorker::register_handlers() {
|
||||
co_return kota::codec::RawValue{"[]"};
|
||||
case K::SemanticTokens:
|
||||
co_return co_await with_ast(params.path, [&](DocumentEntry& doc) {
|
||||
return to_raw(feature::semantic_tokens(doc.unit));
|
||||
return to_raw(
|
||||
feature::semantic_tokens(doc.unit, feature::PositionEncoding::UTF16));
|
||||
});
|
||||
case K::InlayHints:
|
||||
co_return co_await with_ast(params.path, [&](DocumentEntry& doc) {
|
||||
auto range = params.range;
|
||||
if(range.begin == static_cast<uint32_t>(-1))
|
||||
range = LocalSourceRange{0, static_cast<uint32_t>(doc.text.size())};
|
||||
return to_raw(feature::inlay_hints(doc.unit, range));
|
||||
return to_raw(feature::inlay_hints(doc.unit,
|
||||
range,
|
||||
{},
|
||||
feature::PositionEncoding::UTF16));
|
||||
});
|
||||
case K::FoldingRange:
|
||||
co_return co_await with_ast(params.path, [&](DocumentEntry& doc) {
|
||||
return to_raw(feature::folding_ranges(doc.unit));
|
||||
return to_raw(
|
||||
feature::folding_ranges(doc.unit, feature::PositionEncoding::UTF16));
|
||||
});
|
||||
case K::DocumentSymbol:
|
||||
co_return co_await with_ast(params.path, [&](DocumentEntry& doc) {
|
||||
return to_raw(feature::document_symbols(doc.unit));
|
||||
return to_raw(
|
||||
feature::document_symbols(doc.unit, feature::PositionEncoding::UTF16));
|
||||
});
|
||||
case K::DocumentLink:
|
||||
co_return co_await with_ast(params.path, [&](DocumentEntry& doc) {
|
||||
return to_raw(feature::document_links(doc.unit));
|
||||
return to_raw(
|
||||
feature::document_links(doc.unit, feature::PositionEncoding::UTF16));
|
||||
});
|
||||
case K::CodeAction:
|
||||
// TODO: Implement code actions
|
||||
|
||||
@@ -156,13 +156,13 @@ std::optional<Config> Config::load(llvm::StringRef path, llvm::StringRef workspa
|
||||
}
|
||||
|
||||
std::optional<Config> Config::load_from_json(llvm::StringRef json, llvm::StringRef workspace_root) {
|
||||
auto result = kota::codec::json::from_json<Config>(json);
|
||||
Config config{};
|
||||
auto result = kota::codec::json::from_json(json, config);
|
||||
if(!result) {
|
||||
LOG_WARN("Failed to parse initializationOptions JSON: {}", result.error().message());
|
||||
LOG_WARN("Failed to parse initializationOptions JSON: {}", result.error().message);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto config = std::move(*result);
|
||||
config.apply_defaults(workspace_root);
|
||||
LOG_INFO("Loaded config from initializationOptions");
|
||||
return config;
|
||||
|
||||
36
tests/corpus/statements/if/basic_if.cpp
Normal file
36
tests/corpus/statements/if/basic_if.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// basic if and if-else
|
||||
namespace basic_if {
|
||||
|
||||
int abs_val(int x) {
|
||||
if(x < 0)
|
||||
return -x;
|
||||
return x;
|
||||
}
|
||||
|
||||
const char* sign(int x) {
|
||||
if(x > 0) {
|
||||
return "positive";
|
||||
} else if(x < 0) {
|
||||
return "negative";
|
||||
} else {
|
||||
return "zero";
|
||||
}
|
||||
}
|
||||
|
||||
// dangling else: else binds to nearest if
|
||||
int nested_if(int a, int b) {
|
||||
if(a > 0)
|
||||
if(b > 0)
|
||||
return 1;
|
||||
else
|
||||
return 2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void test() {
|
||||
[[maybe_unused]] int r1 = abs_val(-3);
|
||||
[[maybe_unused]] auto r2 = sign(5);
|
||||
[[maybe_unused]] int r3 = nested_if(1, -1);
|
||||
}
|
||||
|
||||
} // namespace basic_if
|
||||
@@ -0,0 +1,14 @@
|
||||
---
|
||||
source: document_symbol_tests.cpp
|
||||
created_at: 2026-05-20
|
||||
input_file: statements/if/basic_if.cpp
|
||||
---
|
||||
- { name: "basic_if", kind: Namespace, range: "1:0-35:1", selection_range: "1:10-1:18" }
|
||||
- { name: "abs_val", kind: Function, range: "3:0-7:1", selection_range: "3:4-3:11", detail: "int (int)" }
|
||||
- { name: "sign", kind: Function, range: "9:0-17:1", selection_range: "9:12-9:16", detail: "const char *(int)" }
|
||||
- { name: "nested_if", kind: Function, range: "20:0-27:1", selection_range: "20:4-20:13", detail: "int (int, int)" }
|
||||
- { name: "test", kind: Function, range: "29:0-33:1", selection_range: "29:5-29:9", detail: "void ()" }
|
||||
- { name: "r1", kind: Variable, range: "30:21-30:41", selection_range: "30:25-30:27", detail: "int" }
|
||||
- { name: "r2", kind: Variable, range: "31:21-31:38", selection_range: "31:26-31:28", detail: "const char *" }
|
||||
- { name: "r3", kind: Variable, range: "32:21-32:46", selection_range: "32:25-32:27", detail: "int" }
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
source: folding_range_tests.cpp
|
||||
created_at: 2026-05-20
|
||||
input_file: statements/if/basic_if.cpp
|
||||
---
|
||||
- { range: "1:19-35:1", kind: namespace, collapsed_text: "{...}" }
|
||||
- { range: "3:19-7:1", kind: functionBody, collapsed_text: "{...}" }
|
||||
- { range: "9:24-17:1", kind: functionBody, collapsed_text: "{...}" }
|
||||
- { range: "20:28-27:1", kind: functionBody, collapsed_text: "{...}" }
|
||||
- { range: "29:12-33:1", kind: functionBody, collapsed_text: "{...}" }
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
source: inlay_hint_tests.cpp
|
||||
created_at: 2026-05-20
|
||||
input_file: statements/if/basic_if.cpp
|
||||
---
|
||||
- { pos: "30:38", kind: Parameter, label: "x:", padding_right: true }
|
||||
- { pos: "31:28", kind: Type, label: ": const char *" }
|
||||
- { pos: "31:36", kind: Parameter, label: "x:", padding_right: true }
|
||||
- { pos: "32:40", kind: Parameter, label: "a:", padding_right: true }
|
||||
- { pos: "32:43", kind: Parameter, label: "b:", padding_right: true }
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
---
|
||||
source: semantic_tokens_tests.cpp
|
||||
created_at: 2026-05-20
|
||||
input_file: statements/if/basic_if.cpp
|
||||
---
|
||||
- { loc: "0:0", text: "// basic if and if-else", kind: Comment }
|
||||
- { loc: "1:0", text: "namespace", kind: Keyword }
|
||||
- { loc: "1:10", text: "basic_if", kind: Namespace, modifiers: [Definition] }
|
||||
- { loc: "3:0", text: "int", kind: Keyword }
|
||||
- { loc: "3:4", text: "abs_val", kind: Function, modifiers: [Definition] }
|
||||
- { loc: "3:12", text: "int", kind: Keyword }
|
||||
- { loc: "3:16", text: "x", kind: Parameter, modifiers: [Definition] }
|
||||
- { loc: "4:4", text: "if", kind: Keyword }
|
||||
- { loc: "4:7", text: "x", kind: Parameter }
|
||||
- { loc: "4:11", text: "0", kind: Number }
|
||||
- { loc: "5:8", text: "return", kind: Keyword }
|
||||
- { loc: "5:16", text: "x", kind: Parameter }
|
||||
- { loc: "6:4", text: "return", kind: Keyword }
|
||||
- { loc: "6:11", text: "x", kind: Parameter }
|
||||
- { loc: "9:0", text: "const", kind: Keyword }
|
||||
- { loc: "9:6", text: "char", kind: Keyword }
|
||||
- { loc: "9:12", text: "sign", kind: Function, modifiers: [Definition, Readonly] }
|
||||
- { loc: "9:17", text: "int", kind: Keyword }
|
||||
- { loc: "9:21", text: "x", kind: Parameter, modifiers: [Definition] }
|
||||
- { loc: "10:4", text: "if", kind: Keyword }
|
||||
- { loc: "10:7", text: "x", kind: Parameter }
|
||||
- { loc: "10:11", text: "0", kind: Number }
|
||||
- { loc: "11:8", text: "return", kind: Keyword }
|
||||
- { loc: "11:15", text: "\"positive\"", kind: String }
|
||||
- { loc: "12:6", text: "else", kind: Keyword }
|
||||
- { loc: "12:11", text: "if", kind: Keyword }
|
||||
- { loc: "12:14", text: "x", kind: Parameter }
|
||||
- { loc: "12:18", text: "0", kind: Number }
|
||||
- { loc: "13:8", text: "return", kind: Keyword }
|
||||
- { loc: "13:15", text: "\"negative\"", kind: String }
|
||||
- { loc: "14:6", text: "else", kind: Keyword }
|
||||
- { loc: "15:8", text: "return", kind: Keyword }
|
||||
- { loc: "15:15", text: "\"zero\"", kind: String }
|
||||
- { loc: "19:0", text: "// dangling else: else binds to nearest if", kind: Comment }
|
||||
- { loc: "20:0", text: "int", kind: Keyword }
|
||||
- { loc: "20:4", text: "nested_if", kind: Function, modifiers: [Definition] }
|
||||
- { loc: "20:14", text: "int", kind: Keyword }
|
||||
- { loc: "20:18", text: "a", kind: Parameter, modifiers: [Definition] }
|
||||
- { loc: "20:21", text: "int", kind: Keyword }
|
||||
- { loc: "20:25", text: "b", kind: Parameter, modifiers: [Definition] }
|
||||
- { loc: "21:4", text: "if", kind: Keyword }
|
||||
- { loc: "21:7", text: "a", kind: Parameter }
|
||||
- { loc: "21:11", text: "0", kind: Number }
|
||||
- { loc: "22:8", text: "if", kind: Keyword }
|
||||
- { loc: "22:11", text: "b", kind: Parameter }
|
||||
- { loc: "22:15", text: "0", kind: Number }
|
||||
- { loc: "23:12", text: "return", kind: Keyword }
|
||||
- { loc: "23:19", text: "1", kind: Number }
|
||||
- { loc: "24:8", text: "else", kind: Keyword }
|
||||
- { loc: "25:12", text: "return", kind: Keyword }
|
||||
- { loc: "25:19", text: "2", kind: Number }
|
||||
- { loc: "26:4", text: "return", kind: Keyword }
|
||||
- { loc: "26:11", text: "0", kind: Number }
|
||||
- { loc: "29:0", text: "void", kind: Keyword }
|
||||
- { loc: "29:5", text: "test", kind: Function, modifiers: [Definition] }
|
||||
- { loc: "30:21", text: "int", kind: Keyword }
|
||||
- { loc: "30:25", text: "r1", kind: Variable, modifiers: [Definition] }
|
||||
- { loc: "30:30", text: "abs_val", kind: Function }
|
||||
- { loc: "30:39", text: "3", kind: Number }
|
||||
- { loc: "31:21", text: "auto", kind: Keyword }
|
||||
- { loc: "31:26", text: "r2", kind: Variable, modifiers: [Definition, Readonly] }
|
||||
- { loc: "31:31", text: "sign", kind: Function, modifiers: [Readonly] }
|
||||
- { loc: "31:36", text: "5", kind: Number }
|
||||
- { loc: "32:21", text: "int", kind: Keyword }
|
||||
- { loc: "32:25", text: "r3", kind: Variable, modifiers: [Definition] }
|
||||
- { loc: "32:30", text: "nested_if", kind: Function }
|
||||
- { loc: "32:40", text: "1", kind: Number }
|
||||
- { loc: "32:44", text: "1", kind: Number }
|
||||
- { loc: "35:3", text: "// namespace basic_if", kind: Comment }
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
---
|
||||
source: tu_index_tests.cpp
|
||||
created_at: 2026-05-20
|
||||
input_file: statements/if/basic_if.cpp
|
||||
---
|
||||
- { loc: "1:10", kind: Namespace, text: "basic_if", relations: [Definition] }
|
||||
- { loc: "3:4", kind: Function, text: "abs_val", relations: [Definition] }
|
||||
- { loc: "3:16", kind: Parameter, text: "x", relations: [Definition] }
|
||||
- { loc: "4:7", kind: Parameter, text: "x", relations: [Reference] }
|
||||
- { loc: "5:16", kind: Parameter, text: "x", relations: [Reference] }
|
||||
- { loc: "6:11", kind: Parameter, text: "x", relations: [Reference] }
|
||||
- { loc: "9:12", kind: Function, text: "sign", relations: [Definition] }
|
||||
- { loc: "9:21", kind: Parameter, text: "x", relations: [Definition] }
|
||||
- { loc: "10:7", kind: Parameter, text: "x", relations: [Reference] }
|
||||
- { loc: "12:14", kind: Parameter, text: "x", relations: [Reference] }
|
||||
- { loc: "20:4", kind: Function, text: "nested_if", relations: [Definition] }
|
||||
- { loc: "20:18", kind: Parameter, text: "a", relations: [Definition] }
|
||||
- { loc: "20:25", kind: Parameter, text: "b", relations: [Definition] }
|
||||
- { loc: "21:7", kind: Parameter, text: "a", relations: [Reference] }
|
||||
- { loc: "22:11", kind: Parameter, text: "b", relations: [Reference] }
|
||||
- { loc: "29:5", kind: Function, text: "test", relations: [Definition] }
|
||||
- { loc: "30:25", kind: Variable, text: "r1", relations: [Definition] }
|
||||
- { loc: "30:30", kind: Function, text: "abs_val", relations: [Reference] }
|
||||
- { loc: "31:26", kind: Variable, text: "r2", relations: [Definition] }
|
||||
- { loc: "31:31", kind: Function, text: "sign", relations: [Reference] }
|
||||
- { loc: "32:25", kind: Variable, text: "r3", relations: [Definition] }
|
||||
- { loc: "32:30", kind: Function, text: "nested_if", relations: [Reference] }
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace {
|
||||
|
||||
namespace protocol = kota::ipc::protocol;
|
||||
|
||||
TEST_SUITE(DocumentLink, Tester) {
|
||||
TEST_SUITE(document_link, Tester) {
|
||||
|
||||
std::vector<protocol::DocumentLink> links;
|
||||
|
||||
@@ -136,7 +136,7 @@ ABCDE
|
||||
EXPECT_LINK(0, "0", TestVFS::path("data.bin"));
|
||||
}
|
||||
|
||||
}; // TEST_SUITE(DocumentLink)
|
||||
}; // TEST_SUITE(document_link)
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <cstddef>
|
||||
#include <format>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
@@ -7,13 +8,15 @@
|
||||
#include "test/tester.h"
|
||||
#include "feature/feature.h"
|
||||
|
||||
#include "kota/meta/enum.h"
|
||||
|
||||
namespace clice::testing {
|
||||
|
||||
namespace {
|
||||
|
||||
namespace protocol = kota::ipc::protocol;
|
||||
|
||||
TEST_SUITE(DocumentSymbol, Tester) {
|
||||
TEST_SUITE(document_symbol, Tester) {
|
||||
|
||||
std::vector<protocol::DocumentSymbol> symbols;
|
||||
|
||||
@@ -180,7 +183,57 @@ VAR(test)
|
||||
ASSERT_EQ(total_size(symbols), 3U);
|
||||
}
|
||||
|
||||
}; // TEST_SUITE(DocumentSymbol)
|
||||
void format_document_symbols(std::string& out,
|
||||
const feature::PositionMapper& mapper,
|
||||
llvm::ArrayRef<feature::DocumentSymbol> nodes,
|
||||
int depth) {
|
||||
auto pad = std::string(depth * 2, ' ');
|
||||
for(auto& node: nodes) {
|
||||
auto kind = kota::meta::enum_name(static_cast<SymbolKind::Kind>(node.kind), "Unknown");
|
||||
auto start = mapper.to_position(node.range.begin);
|
||||
auto end = mapper.to_position(node.range.end);
|
||||
if(!start || !end)
|
||||
continue;
|
||||
auto sel_start = mapper.to_position(node.selection_range.begin);
|
||||
auto sel_end = mapper.to_position(node.selection_range.end);
|
||||
out += std::format("- {}{{ name: {}, kind: {}, range: \"{}:{}-{}:{}\"",
|
||||
pad,
|
||||
yaml_str(node.name),
|
||||
kind,
|
||||
start->line,
|
||||
start->character,
|
||||
end->line,
|
||||
end->character);
|
||||
if(sel_start && sel_end) {
|
||||
out += std::format(", selection_range: \"{}:{}-{}:{}\"",
|
||||
sel_start->line,
|
||||
sel_start->character,
|
||||
sel_end->line,
|
||||
sel_end->character);
|
||||
}
|
||||
if(!node.detail.empty()) {
|
||||
out += std::format(", detail: {}", yaml_str(node.detail));
|
||||
}
|
||||
out += " }\n";
|
||||
if(!node.children.empty()) {
|
||||
format_document_symbols(out, mapper, node.children, depth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(snapshot) {
|
||||
ASSERT_SNAPSHOT_GLOB(corpus_dir, "**/*.cpp", [&](std::string_view path) -> std::string {
|
||||
if(!compile_file(path))
|
||||
return "COMPILE_ERROR";
|
||||
auto content = unit->interested_content();
|
||||
feature::PositionMapper mapper(content, feature::PositionEncoding::UTF8);
|
||||
std::string result;
|
||||
format_document_symbols(result, mapper, feature::document_symbols(*unit), 0);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
}; // TEST_SUITE(document_symbol)
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace {
|
||||
|
||||
namespace protocol = kota::ipc::protocol;
|
||||
|
||||
TEST_SUITE(FoldingRange, Tester) {
|
||||
TEST_SUITE(folding_range, Tester) {
|
||||
|
||||
std::vector<protocol::FoldingRange> ranges;
|
||||
|
||||
@@ -429,7 +429,36 @@ $(1)#pragma region level1
|
||||
)cpp");
|
||||
}
|
||||
|
||||
}; // TEST_SUITE(FoldingRange)
|
||||
TEST_CASE(snapshot) {
|
||||
ASSERT_SNAPSHOT_GLOB(corpus_dir, "**/*.cpp", [&](std::string_view path) -> std::string {
|
||||
if(!compile_file(path))
|
||||
return "COMPILE_ERROR";
|
||||
auto ranges = feature::folding_ranges(*unit);
|
||||
feature::PositionMapper mapper(unit->interested_content(), feature::PositionEncoding::UTF8);
|
||||
std::string result;
|
||||
for(auto& r: ranges) {
|
||||
auto start = mapper.to_position(r.range.begin);
|
||||
auto end = mapper.to_position(r.range.end);
|
||||
if(!start || !end)
|
||||
continue;
|
||||
result += std::format("- {{ range: \"{}:{}-{}:{}\"",
|
||||
start->line,
|
||||
start->character,
|
||||
end->line,
|
||||
end->character);
|
||||
if(r.kind.has_value()) {
|
||||
result += std::format(", kind: {}", static_cast<const std::string&>(*r.kind));
|
||||
}
|
||||
if(!r.collapsed_text.empty()) {
|
||||
result += std::format(", collapsed_text: {}", yaml_str(r.collapsed_text));
|
||||
}
|
||||
result += " }\n";
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
}; // TEST_SUITE(folding_range)
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
#include <format>
|
||||
#include <string>
|
||||
|
||||
#include "test/test.h"
|
||||
#include "test/tester.h"
|
||||
#include "feature/feature.h"
|
||||
|
||||
#include "kota/meta/enum.h"
|
||||
|
||||
namespace clice::testing {
|
||||
|
||||
namespace {
|
||||
|
||||
namespace protocol = kota::ipc::protocol;
|
||||
|
||||
TEST_SUITE(InlayHint, Tester) {
|
||||
TEST_SUITE(inlay_hint, Tester) {
|
||||
|
||||
std::vector<protocol::InlayHint> hints;
|
||||
llvm::DenseMap<std::uint32_t, protocol::InlayHint> hints_map;
|
||||
@@ -1529,6 +1532,38 @@ TEST_CASE(Dependent, skip = true) {
|
||||
EXPECT_HINT("2", "par3:");
|
||||
}
|
||||
|
||||
}; // TEST_SUITE(InlayHint)
|
||||
TEST_CASE(snapshot) {
|
||||
ASSERT_SNAPSHOT_GLOB(corpus_dir, "**/*.cpp", [&](std::string_view path) -> std::string {
|
||||
if(!compile_file(path))
|
||||
return "COMPILE_ERROR";
|
||||
auto content = unit->interested_content();
|
||||
LocalSourceRange range(0, content.size());
|
||||
auto hints = feature::inlay_hints(*unit, range);
|
||||
feature::PositionMapper mapper(content, feature::PositionEncoding::UTF8);
|
||||
std::string result;
|
||||
for(auto& hint: hints) {
|
||||
auto pos = mapper.to_position(hint.offset);
|
||||
if(!pos)
|
||||
continue;
|
||||
auto kind = kota::meta::enum_name(hint.kind, "Unknown");
|
||||
result += std::format("- {{ pos: \"{}:{}\", kind: {}, label: {}",
|
||||
pos->line,
|
||||
pos->character,
|
||||
kind,
|
||||
yaml_str(hint.label));
|
||||
if(hint.padding_left) {
|
||||
result += ", padding_left: true";
|
||||
}
|
||||
if(hint.padding_right) {
|
||||
result += ", padding_right: true";
|
||||
}
|
||||
result += " }\n";
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
}; // TEST_SUITE(inlay_hint)
|
||||
|
||||
} // namespace
|
||||
} // namespace clice::testing
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "feature/feature.h"
|
||||
#include "semantic/symbol_kind.h"
|
||||
|
||||
#include "kota/meta/enum.h"
|
||||
|
||||
namespace clice::testing {
|
||||
|
||||
namespace {
|
||||
@@ -99,7 +101,7 @@ auto decode_relative_tokens(const protocol::SemanticTokens& tokens) -> std::vect
|
||||
return result;
|
||||
}
|
||||
|
||||
TEST_SUITE(SemanticTokens, Tester) {
|
||||
TEST_SUITE(semantic_tokens, Tester) {
|
||||
|
||||
protocol::SemanticTokens tokens;
|
||||
std::vector<DecodedToken> decoded;
|
||||
@@ -138,6 +140,10 @@ void EXPECT_TOKEN(llvm::StringRef name,
|
||||
ASSERT_EQ(token->modifiers, expected_modifiers);
|
||||
}
|
||||
|
||||
void EXPECT_NO_TOKEN(llvm::StringRef name) {
|
||||
ASSERT_TRUE(find_by_range(name) == nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE(BasicLexicalKinds) {
|
||||
run_utf8(R"cpp(
|
||||
@d1[#define] @m0[FOO]
|
||||
@@ -264,6 +270,44 @@ int main() {
|
||||
EXPECT_TOKEN("x3", SymbolKind::Variable, 0);
|
||||
}
|
||||
|
||||
TEST_CASE(IneligibleOperatorReferenceIsSuppressed) {
|
||||
run_utf8(R"cpp(
|
||||
struct S {};
|
||||
|
||||
S operator+(S lhs, S rhs);
|
||||
|
||||
void use(S lhs, S rhs) {
|
||||
(void)(lhs @plus[+] rhs);
|
||||
}
|
||||
)cpp");
|
||||
|
||||
EXPECT_NO_TOKEN("plus");
|
||||
}
|
||||
|
||||
TEST_CASE(ConstructorAndDestructorNamesRemainHighlighted) {
|
||||
run_utf8(R"cpp(
|
||||
struct S {
|
||||
@ctor_decl[S]();
|
||||
@dtor_decl[~]S();
|
||||
};
|
||||
|
||||
S::@ctor_def[S]() {}
|
||||
|
||||
void use(S* value) {
|
||||
value->@dtor_ref[~]S();
|
||||
}
|
||||
)cpp");
|
||||
|
||||
auto declaration = modifier_mask({SymbolModifiers::Declaration});
|
||||
auto definition = modifier_mask({SymbolModifiers::Definition});
|
||||
auto special_member = modifier_mask({SymbolModifiers::ConstructorOrDestructor});
|
||||
|
||||
EXPECT_TOKEN("ctor_decl", SymbolKind::Method, declaration | special_member);
|
||||
EXPECT_TOKEN("dtor_decl", SymbolKind::Method, declaration | special_member);
|
||||
EXPECT_TOKEN("ctor_def", SymbolKind::Method, definition | special_member);
|
||||
EXPECT_TOKEN("dtor_ref", SymbolKind::Method, special_member);
|
||||
}
|
||||
|
||||
TEST_CASE(LegacyVarDeclTemplates) {
|
||||
run_utf8(R"cpp(
|
||||
extern int @x1[x];
|
||||
@@ -539,7 +583,53 @@ void f() {
|
||||
EXPECT_TOKEN("v2", SymbolKind::Variable, definition);
|
||||
}
|
||||
|
||||
}; // TEST_SUITE(SemanticTokens)
|
||||
TEST_CASE(snapshot) {
|
||||
ASSERT_SNAPSHOT_GLOB(corpus_dir, "**/*.cpp", [&](std::string_view path) -> std::string {
|
||||
if(!compile_file(path))
|
||||
return "COMPILE_ERROR";
|
||||
auto content = unit->interested_content();
|
||||
auto tokens = feature::semantic_tokens(*unit);
|
||||
feature::PositionMapper mapper(content, feature::PositionEncoding::UTF8);
|
||||
std::string result;
|
||||
for(auto& token: tokens) {
|
||||
if(!token.range.valid() || token.range.end <= token.range.begin ||
|
||||
token.range.end > content.size())
|
||||
continue;
|
||||
|
||||
auto pos = mapper.to_position(token.range.begin);
|
||||
if(!pos)
|
||||
continue;
|
||||
|
||||
auto text = content.substr(token.range.begin, token.range.length());
|
||||
auto kind = kota::meta::enum_name(static_cast<SymbolKind::Kind>(token.kind), "Unknown");
|
||||
|
||||
result += std::format("- {{ loc: \"{}:{}\", text: {}, kind: {}",
|
||||
pos->line,
|
||||
pos->character,
|
||||
yaml_str(text),
|
||||
kind);
|
||||
|
||||
std::string mods;
|
||||
for(std::uint32_t i = 0; i < 32; ++i) {
|
||||
if(token.modifiers & (1u << i)) {
|
||||
auto name = kota::meta::enum_name(static_cast<SymbolModifiers::Kind>(i));
|
||||
if(!name.empty()) {
|
||||
if(!mods.empty())
|
||||
mods += ", ";
|
||||
mods += name;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!mods.empty()) {
|
||||
result += std::format(", modifiers: [{}]", mods);
|
||||
}
|
||||
result += " }\n";
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
}; // TEST_SUITE(semantic_tokens)
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
#include <algorithm>
|
||||
#include <format>
|
||||
#include <set>
|
||||
|
||||
#include "test/test.h"
|
||||
#include "test/tester.h"
|
||||
#include "feature/feature.h"
|
||||
#include "index/tu_index.h"
|
||||
|
||||
#include "kota/meta/enum.h"
|
||||
|
||||
namespace clice::testing {
|
||||
namespace {
|
||||
|
||||
TEST_SUITE(TUIndex, Tester) {
|
||||
TEST_SUITE(tu_index, Tester) {
|
||||
|
||||
index::TUIndex tu_index;
|
||||
|
||||
@@ -500,6 +505,64 @@ TEST_CASE(SymbolKinds) {
|
||||
check_kind("ns", SymbolKind::Namespace);
|
||||
}
|
||||
|
||||
}; // TEST_SUITE(TUIndex)
|
||||
TEST_CASE(snapshot) {
|
||||
ASSERT_SNAPSHOT_GLOB(corpus_dir, "**/*.cpp", [&](std::string_view path) -> std::string {
|
||||
if(!compile_file(path))
|
||||
return "COMPILE_ERROR";
|
||||
auto idx = index::TUIndex::build(*unit);
|
||||
auto content = unit->interested_content();
|
||||
feature::PositionMapper mapper(content, feature::PositionEncoding::UTF8);
|
||||
std::string result;
|
||||
|
||||
auto sorted = idx.main_file_index.occurrences;
|
||||
std::ranges::sort(sorted, [](auto& lhs, auto& rhs) {
|
||||
return std::tuple(lhs.range.begin, lhs.range.end, lhs.target) <
|
||||
std::tuple(rhs.range.begin, rhs.range.end, rhs.target);
|
||||
});
|
||||
|
||||
for(auto& occ: sorted) {
|
||||
auto text = content.substr(occ.range.begin, occ.range.end - occ.range.begin);
|
||||
auto pos = mapper.to_position(occ.range.begin);
|
||||
if(!pos)
|
||||
continue;
|
||||
|
||||
auto sym_it = idx.symbols.find(occ.target);
|
||||
std::string_view kind_name = "?";
|
||||
if(sym_it != idx.symbols.end()) {
|
||||
kind_name =
|
||||
kota::meta::enum_name(static_cast<SymbolKind::Kind>(sym_it->second.kind),
|
||||
"Unknown");
|
||||
}
|
||||
|
||||
result += std::format("- {{ loc: \"{}:{}\", kind: {}, text: {}",
|
||||
pos->line,
|
||||
pos->character,
|
||||
kind_name,
|
||||
yaml_str(text));
|
||||
|
||||
auto rel_it = idx.main_file_index.relations.find(occ.target);
|
||||
if(rel_it != idx.main_file_index.relations.end()) {
|
||||
std::string rels;
|
||||
for(auto& rel: rel_it->second) {
|
||||
if(rel.range != occ.range)
|
||||
continue;
|
||||
if(!rels.empty())
|
||||
rels += ", ";
|
||||
rels += kota::meta::enum_name(static_cast<RelationKind::Kind>(rel.kind), "?");
|
||||
}
|
||||
if(!rels.empty()) {
|
||||
result += std::format(", relations: [{}]", rels);
|
||||
}
|
||||
}
|
||||
|
||||
result += " }\n";
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
}; // TEST_SUITE(tu_index)
|
||||
|
||||
} // namespace
|
||||
} // namespace clice::testing
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <string>
|
||||
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
@@ -5,6 +7,12 @@
|
||||
|
||||
namespace clice::testing {
|
||||
|
||||
/// Set by --test-dir from the command line; empty if not specified.
|
||||
inline std::string test_dir;
|
||||
|
||||
/// Set by --corpus-dir from the command line; empty if not specified.
|
||||
inline std::string corpus_dir;
|
||||
|
||||
#ifdef _WIN32
|
||||
constexpr inline bool Windows = true;
|
||||
#else
|
||||
|
||||
@@ -230,6 +230,17 @@ bool Tester::compile_with_modules(llvm::StringRef standard) {
|
||||
return try_compile();
|
||||
}
|
||||
|
||||
bool Tester::compile_file(llvm::StringRef path, llvm::StringRef standard) {
|
||||
auto buffer = llvm::MemoryBuffer::getFile(path);
|
||||
if(!buffer) {
|
||||
LOG_ERROR("Failed to read file: {}", path);
|
||||
return false;
|
||||
}
|
||||
auto filename = llvm::sys::path::filename(path);
|
||||
add_main(filename, (*buffer)->getBuffer());
|
||||
return compile(standard);
|
||||
}
|
||||
|
||||
std::uint32_t Tester::point(llvm::StringRef name, llvm::StringRef file) {
|
||||
if(file.empty()) {
|
||||
file = src_path;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <format>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -63,6 +64,9 @@ struct Tester {
|
||||
|
||||
bool compile_with_modules(llvm::StringRef standard = "-std=c++20");
|
||||
|
||||
/// Read a file from disk and compile it directly (no VFS content needed).
|
||||
bool compile_file(llvm::StringRef path, llvm::StringRef standard = "-std=c++20");
|
||||
|
||||
/// Driver path: uses CompilationDatabase + toolchain cache, has system headers.
|
||||
void prepare_driver(llvm::StringRef standard = "-std=c++20");
|
||||
|
||||
@@ -85,4 +89,28 @@ struct Tester {
|
||||
void clear();
|
||||
};
|
||||
|
||||
inline std::string yaml_str(llvm::StringRef s) {
|
||||
std::string result;
|
||||
result.reserve(s.size() + 2);
|
||||
result += '"';
|
||||
for(char c: s) {
|
||||
switch(c) {
|
||||
case '"': result += "\\\""; break;
|
||||
case '\\': result += "\\\\"; break;
|
||||
case '\n': result += "\\n"; break;
|
||||
case '\r': result += "\\r"; break;
|
||||
case '\t': result += "\\t"; break;
|
||||
default:
|
||||
if(static_cast<unsigned char>(c) < 0x20) {
|
||||
result += std::format("\\x{:02x}", static_cast<unsigned char>(c));
|
||||
} else {
|
||||
result += c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
result += '"';
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace clice::testing
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "test/platform.h"
|
||||
#include "support/logging.h"
|
||||
|
||||
#include "kota/deco/deco.h"
|
||||
@@ -11,23 +12,20 @@ namespace {
|
||||
using kota::deco::decl::KVStyle;
|
||||
|
||||
struct TestOptions {
|
||||
DecoKV(style = KVStyle::JoinedOrSeparate,
|
||||
names = {"--test-filter", "--test-filter="},
|
||||
help = "Filter tests by name",
|
||||
required = false)
|
||||
<std::string> test_filter;
|
||||
kota::zest::Options zest;
|
||||
|
||||
DecoKV(style = KVStyle::JoinedOrSeparate,
|
||||
names = {"--log-level", "--log-level="},
|
||||
help = "Log level: trace/debug/info/warn/err",
|
||||
required = false)
|
||||
DecoKVStyled(KVStyle::JoinedOrSeparate, help = "log level: trace/debug/info/warn/err";
|
||||
required = false)
|
||||
<std::string> log_level;
|
||||
|
||||
DecoKV(style = KVStyle::JoinedOrSeparate,
|
||||
names = {"--test-dir", "--test-dir="},
|
||||
help = "Test data directory",
|
||||
required = false)
|
||||
DecoKVStyled(KVStyle::JoinedOrSeparate, meta_var = "<DIR>"; help = "test data directory";
|
||||
required = false)
|
||||
<std::string> test_dir;
|
||||
|
||||
DecoKVStyled(KVStyle::JoinedOrSeparate, meta_var = "<DIR>";
|
||||
help = "corpus directory for snapshot glob tests";
|
||||
required = false)
|
||||
<std::string> corpus_dir;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@@ -36,13 +34,20 @@ int main(int argc, const char** argv) {
|
||||
auto args = kota::deco::util::argvify(argc, argv);
|
||||
auto parsed = kota::deco::cli::parse<TestOptions>(args);
|
||||
|
||||
std::string_view filter = {};
|
||||
if(parsed.has_value() && parsed->options.test_filter.has_value()) {
|
||||
filter = *parsed->options.test_filter;
|
||||
if(!parsed.has_value()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(parsed.has_value() && parsed->options.log_level.has_value()) {
|
||||
auto level = *parsed->options.log_level;
|
||||
auto& opts = parsed->options;
|
||||
|
||||
if(opts.test_dir.has_value())
|
||||
clice::testing::test_dir = *opts.test_dir;
|
||||
|
||||
if(opts.corpus_dir.has_value())
|
||||
clice::testing::corpus_dir = *opts.corpus_dir;
|
||||
|
||||
if(opts.log_level.has_value()) {
|
||||
auto level = *opts.log_level;
|
||||
if(level == "trace") {
|
||||
clice::logging::options.level = clice::logging::Level::trace;
|
||||
} else if(level == "debug") {
|
||||
@@ -58,5 +63,5 @@ int main(int argc, const char** argv) {
|
||||
|
||||
clice::logging::stderr_logger("test", clice::logging::options);
|
||||
|
||||
return kota::zest::Runner::instance().run_tests(filter);
|
||||
return kota::zest::run_tests(std::move(opts.zest));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user