Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup llvm binary
if: matrix.os == 'ubuntu-24.04'
run: |
mkdir -p ./.llvm
curl -L "https://github.com/clice-project/llvm-binary/releases/download/20.0.0/x86_64-linux-gnu-debug.tar.xz" | tar -xJ -C ./.llvm

- name: Setup llvm binary
if: matrix.os == 'windows-2025'
run: |
curl -O -L "https://github.com/clice-project/llvm-binary/releases/download/20.0.0/x64-windows-msvc-release.7z"
7z x x64-windows-msvc-release.7z "-o.llvm"

- name: Setup llvm binary
if: matrix.os == 'ubuntu-24.04'
run: |
mkdir -p ./.llvm
curl -L "https://github.com/clice-project/llvm-binary/releases/download/20.0.0/x86_64-linux-gnu-debug.tar.xz" | tar -xJ -C ./.llvm

- name: Setup llvm binary
if: matrix.os == 'macos-15'
Expand All @@ -84,6 +84,12 @@ jobs:
if: matrix.os == 'windows-2025'
uses: ilammy/msvc-dev-cmd@v1

- name: Build clice (release)
if: matrix.os == 'windows-2025'
run: |
cmake --preset release
cmake --build --preset release

- name: Build clice (debug)
if: matrix.os == 'ubuntu-24.04'
run: |
Expand All @@ -97,16 +103,17 @@ jobs:
cmake --preset debug
cmake --build --preset debug -v

- name: Build clice (release)
if: matrix.os == 'windows-2025'
run: |
cmake --preset release
cmake --build --preset release

- name: Install Python dependencies
run: pip install pytest pytest-asyncio pytest-xdist

- name: Run tests
if: matrix.os == 'windows-2025'
run: |
./build/bin/unit_tests.exe --test-dir="./tests/data" --resource-dir="./.llvm/lib/clang/20"
pytest -s tests/integration --executable=./build/bin/clice.exe

- name: Run tests
if: matrix.os == 'ubuntu-24.04' || matrix.os == 'macos-15'
run: |
./build/bin/unit_tests --test-dir="./tests/data" --resource-dir="./.llvm/lib/clang/20"
pytest -s tests/integration --executable=./build/bin/clice
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
temp/
*build*/
.cache/
.clice/
.llvm*/
.xmake/
.vscode/
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.20)
project(CLICE_PROJECT LANGUAGES CXX)
project(CLICE_PROJECT LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
8 changes: 8 additions & 0 deletions src/Server/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ async::Task<> Scheduler::buildPCH(std::string path, std::string content) {
std::string content) -> async::Task<> {
CompilationParams params;
params.arguments = scheduler.database.get_command(path, true).arguments;
if(!fs::exists(config::cache.dir)) {
auto error = fs::create_directories(config::cache.dir);
if(error) {
log::warn("Fail to create directory for PCH building: {}", config::cache.dir);
co_return;
}
}

params.outPath = path::join(config::cache.dir, path::filename(path) + ".pch");
params.add_remapped_file(path, content, bound);

Expand Down
20 changes: 18 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,24 @@ def pytest_addoption(parser):

@pytest.fixture(scope="session")
def executable(request):
path = request.config.getoption("--executable")
return Path(path).resolve()
executable = request.config.getoption("--executable")
if executable is None:
pytest.exit(
"Error: You must specify the 'clice' executable path using "
"'--executable=<path/to/clice>' in pytest arguments, "
"or configure it in your pytest.ini/conftest.py.",
returncode=64
)

path = Path(executable)
if not path.exists():
pytest.exit(
f"Error: 'clice' executable not found at '{executable}'. "
"Please ensure the path is correct and the file exists.",
returncode=64
)

return path.resolve()


@pytest.fixture(scope="session")
Expand Down
28 changes: 28 additions & 0 deletions tests/fixtures/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
class LSPClient(LSPTransport):
def __init__(self, commands, mode="stdio", host="127.0.0.1", port=2087):
super().__init__(commands, mode, host, port)
self.workspace = ""
self.opening_files: dict[Path, str] = {}

async def initialize(self, workspace: str):
self.workspace = workspace
Expand All @@ -18,3 +20,29 @@ async def initialize(self, workspace: str):
async def exit(self):
await self.send_notification("exit")
await self.stop()

def get_abs_path(self, relative_path):
return Path(self.workspace, relative_path)

async def did_open(self, relative_path: str):
path = self.get_abs_path(relative_path)

content = ""
with open(path, encoding="utf-8") as file:
content = file.read()

if path in self.opening_files:
raise f"Cannot open same file multiple times: {path}"

self.opening_files[path] = content

params = {
"textDocument": {
"uri": path.as_uri(),
"languageId": "cpp",
"version": 0,
"text": content,
}
}

await self.send_notification("textDocument/didOpen", params)
1 change: 0 additions & 1 deletion tests/fixtures/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def __init__(self, commands: list[str], mode="stdio", host="127.0.0.1", port=208
self.mode = mode
self.host = host
self.port = port
self.workspace = ""

self.process: asyncio.subprocess.Process = None
self.reader: asyncio.StreamReader = None
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/test_file_operation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys
import pytest
import asyncio
from ..fixtures.client import LSPClient


@pytest.mark.asyncio
async def test_did_open(executable, test_data_dir):
client = LSPClient([
executable, "--mode=pipe"
])
await client.start()

await client.initialize(test_data_dir / "hello_world")
await client.did_open("main.cpp")
await asyncio.sleep(3)
await client.exit()
File renamed without changes.