Skip to content
Open
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
64 changes: 62 additions & 2 deletions src/solidlsp/ls_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,68 @@ def get_source_fn_matcher(self) -> FilenameMatcher:
return FilenameMatcher("*.rb", "*.erb")
case self.RUBY_SOLARGRAPH:
return FilenameMatcher("*.rb")
case self.CPP | self.CPP_CCLS:
return FilenameMatcher("*.cpp", "*.h", "*.hpp", "*.c", "*.hxx", "*.cc", "*.cxx")
case self.CPP:
# From llvm-project/clang/lib/Driver/Types.cpp types::lookupTypeForExtension:
return FilenameMatcher(
# C
"*.c",
"*.C",
"*.h",
"*.H",
# C++
"*.c++",
"*.C++",
"*.cc",
"*.CC",
"*.cp",
"*.cpp",
"*.CPP",
"*.cxx",
"*.CXX",
"*.hpp",
"*.hxx",
# Objective-C
"*.m",
"*.M",
"*.mm",
# C++20 module interface files
"*.c++m",
"*.cppm",
"*.cxxm",
"*.ixx",
# CUDA
"*.cu",
# HIP
"*.hip",
# OpenCL
"*.cl",
"*.clcpp",
)
case self.CPP_CCLS:
# From llvm-project/clang/lib/Driver/Types.cpp types::lookupTypeForExtension:
return FilenameMatcher(
# C
"*.c",
"*.C",
"*.h",
"*.H",
# C++
"*.c++",
"*.C++",
"*.cc",
"*.CC",
"*.cp",
"*.cpp",
"*.CPP",
"*.cxx",
"*.CXX",
"*.hpp",
"*.hxx",
# Objective-C
"*.m",
"*.M",
"*.mm",
)
case self.KOTLIN:
return FilenameMatcher("*.kt", "*.kts")
case self.DART:
Expand Down
3 changes: 3 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ def _determine_disabled_languages() -> list[Language]:

# Disable CPP_CCLS tests if ccls is not available
ccls_tests_enabled = _sh.which("ccls") is not None
# Skip ccls tests on Windows since no recent binary is available and version
# 0.20220729 from chocolatey crashes when parsing the test files.
ccls_tests_enabled = ccls_tests_enabled and not is_windows
if not ccls_tests_enabled:
result.append(Language.CPP_CCLS)

Expand Down
7 changes: 7 additions & 0 deletions test/resources/repos/cpp/test_repo/C/a.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "b.h"

int main()
{
int x = add(3, 4);
return x;
}
3 changes: 3 additions & 0 deletions test/resources/repos/cpp/test_repo/C/b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

int add(int a, int b);
16 changes: 16 additions & 0 deletions test/resources/repos/cpp/test_repo/CUDA/a.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <cstdio>
#include <cstdlib>

__global__ auto
cuda_hello() -> void
{
printf("Hello World from GPU!\n");
}

auto
main() -> int
{
cuda_hello<<<1, 1>>>();
cudaDeviceSynchronize();
return EXIT_SUCCESS;
}
9 changes: 9 additions & 0 deletions test/resources/repos/cpp/test_repo/CXX20/a.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <cstdlib>

import b;

auto
main() noexcept -> int
{
return EXIT_SUCCESS;
}
17 changes: 17 additions & 0 deletions test/resources/repos/cpp/test_repo/CXX20/b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module;

#include <cstdint>

module b;

auto
add(auto x, auto y) -> decltype(x + y)
{
return x + y;
}

auto
add_f32(float x, float y) -> float
{
return add(x, y);
}
16 changes: 16 additions & 0 deletions test/resources/repos/cpp/test_repo/CXX20/b.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module;

#include <cstdint>

export module b;

export auto
add(auto x, auto y) -> decltype(x + y);

export auto
add_f32(float x, float y) -> float;

auto
add_u32(std::int32_t x, std::int32_t y) -> std::int32_t {
return x + y;
}
10 changes: 10 additions & 0 deletions test/resources/repos/cpp/test_repo/HIP/a.hip
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// -*- mode: C -*-

#include <hip/hip_runtime.h>

__global__
void add_vectors(const float* A, const float* B, float* C)
{
auto const idx = blockIdx.x * blockDim.x + threadIdx.x;
C[idx] = A[idx] + B[idx];
}
7 changes: 7 additions & 0 deletions test/resources/repos/cpp/test_repo/Objective-C/a.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@interface Hello
- (void)hello;
@end

int main(int argc, const char * argv[]) {
return 0;
}
8 changes: 8 additions & 0 deletions test/resources/repos/cpp/test_repo/OpenCL/a.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// -*- mode: C -*-

__kernel
void add_vectors(__global const float *A, __global const float *B, __global float *C)
{
int idx = get_global_id(0);
C[idx] = A[idx] + B[idx];
}
37 changes: 36 additions & 1 deletion test/resources/repos/cpp/test_repo/compile_commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,40 @@
"directory": ".",
"command": "g++ -std=c++17 -I . -c b.cpp",
"file": "b.cpp"
},
{
"directory": "C",
"command": "clang -std=gnu23 -c a.c",
"file": "a.c"
},
{
"directory": "CUDA",
"command": "nvcc -std=c++20 -c a.cu",
"file": "a.cu"
},
{
"directory": "CXX20",
"command": "clang++ -std=gnu++20 -fmodule-file=b=b.pcm -c a.cpp",
"file": "a.cpp"
},
{
"directory": "CXX20",
"command": "clang++ -std=gnu++20 -fmodule-file=b=b.pcm -c b.cpp",
"file": "b.cpp"
},
{
"directory": "CXX20",
"command": "clang++ -std=gnu++20 -c b.cppm",
"file": "b.cppm"
},
{
"directory": "OpenCL",
"command": "clang -std=cl3.0 -c a.cl",
"file": "a.cl"
},
{
"directory": "HIP",
"command": "hipcc -c a.hip",
"file": "a.hip"
}
]
]
6 changes: 3 additions & 3 deletions test/serena/test_serena_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def serena_config():
Language.CLOJURE,
Language.FSHARP,
Language.POWERSHELL,
Language.CPP_CCLS,
Language.CPP,
Language.HAXE,
Language.LEAN4,
Language.MSL,
Expand Down Expand Up @@ -200,7 +200,7 @@ def test_find_symbol_within_php_file(self, serena_agent: SerenaAgent) -> None:
pytest.param(Language.CLOJURE, "greet", "Function", clj.CORE_PATH, marks=pytest.mark.clojure),
pytest.param(Language.CSHARP, "Calculator", "Class", "Program.cs", marks=pytest.mark.csharp),
pytest.param(Language.POWERSHELL, "Greet-User", "Function", "main.ps1", marks=pytest.mark.powershell),
pytest.param(Language.CPP_CCLS, "add", "Function", "b.cpp", marks=pytest.mark.cpp),
pytest.param(Language.CPP, "add", "Function", "b.cpp", marks=pytest.mark.cpp),
pytest.param(Language.HAXE, "Main", "Class", "Main.hx", marks=pytest.mark.haxe),
pytest.param(Language.LEAN4, "add", "Method", "Helper.lean", marks=pytest.mark.lean4),
pytest.param(Language.MSL, "greet", "Function", "main.mrc", marks=pytest.mark.msl),
Expand Down Expand Up @@ -303,7 +303,7 @@ def contains_ref_with_relative_path(refs, relative_path):
),
pytest.param(Language.CSHARP, "Calculator", "Program.cs", "Program.cs", marks=pytest.mark.csharp),
pytest.param(Language.POWERSHELL, "Greet-User", "main.ps1", "main.ps1", marks=pytest.mark.powershell),
pytest.param(Language.CPP_CCLS, "add", "b.cpp", "a.cpp", marks=pytest.mark.cpp),
pytest.param(Language.CPP, "add", "b.cpp", "a.cpp", marks=pytest.mark.cpp),
pytest.param(
Language.HAXE,
"addNumbers",
Expand Down
24 changes: 24 additions & 0 deletions test/solidlsp/cpp/test_ccls_languages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os

import pytest

from solidlsp.ls_config import Language
from test.conftest import start_ls_context


@pytest.mark.cpp
class TestCCLSLanguages:
@pytest.mark.parametrize(
"lang, unit, names",
[
("C", "a.c", {"main"}),
("Objective-C", "a.m", {"main", "Hello", "-hello"}),
],
)
def test_get_document_symbols(self, lang: str, unit: str, names: set[str]) -> None:
with start_ls_context(Language.CPP) as ccls:
path = os.path.join(lang, unit)
symbols = ccls.request_document_symbols(path).get_all_symbols_and_roots()
symbols = symbols[0] if symbols and isinstance(symbols[0], list) else symbols
symbols = {s.get("name") for s in symbols}
assert names == symbols, f"Expected '{names}' in document symbols, got: {symbols}"
30 changes: 30 additions & 0 deletions test/solidlsp/cpp/test_clangd_languages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os

import pytest

from solidlsp.ls_config import Language
from test.conftest import start_ls_context


@pytest.mark.cpp
class TestClangdLanguages:
@pytest.mark.parametrize(
"lang, unit, names",
[
("C", "a.c", {"main"}),
("CUDA", "a.cu", {"main", "cuda_hello"}),
("CXX20", "a.cpp", {"main"}),
("CXX20", "b.cpp", {"add", "add_f32"}),
("CXX20", "b.cppm", {"add", "add_f32", "add_u32"}),
("HIP", "a.hip", {"add_vectors"}),
("OpenCL", "a.cl", {"add_vectors"}),
("Objective-C", "a.m", {"main", "Hello", "-hello"}),
],
)
def test_get_document_symbols(self, lang: str, unit: str, names: set[str]) -> None:
with start_ls_context(Language.CPP) as clangd:
path = os.path.join(lang, unit)
symbols = clangd.request_document_symbols(path).get_all_symbols_and_roots()
symbols = symbols[0] if symbols and isinstance(symbols[0], list) else symbols
symbols = {s.get("name") for s in symbols}
assert names == symbols, f"Expected '{names}' in document symbols, got: {symbols}"
9 changes: 2 additions & 7 deletions test/solidlsp/cpp/test_cpp_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@
from solidlsp import SolidLanguageServer
from solidlsp.ls_config import Language
from solidlsp.ls_utils import SymbolUtils
from test.conftest import get_repo_path, start_ls_context
from test.conftest import get_repo_path, language_tests_enabled, start_ls_context
from test.solidlsp.conftest import format_symbol_for_assert, has_malformed_name, request_all_symbols


def _ccls_available() -> bool:
return shutil.which("ccls") is not None


_cpp_servers: list[Language] = [Language.CPP]
if _ccls_available():
if language_tests_enabled(Language.CPP_CCLS):
_cpp_servers.append(Language.CPP_CCLS)


Expand Down
Loading