Add files using upload-large-folder tool
Browse files- projects/ui/serena-new/test/solidlsp/erlang/test_erlang_symbol_retrieval.py +445 -0
- projects/ui/serena-new/test/solidlsp/go/test_go_basic.py +33 -0
- projects/ui/serena-new/test/solidlsp/java/test_java_basic.py +50 -0
- projects/ui/serena-new/test/solidlsp/kotlin/test_kotlin_basic.py +52 -0
- projects/ui/serena-new/test/solidlsp/lua/test_lua_basic.py +255 -0
- projects/ui/serena-new/test/solidlsp/nix/test_nix_basic.py +218 -0
- projects/ui/serena-new/test/solidlsp/php/test_php_basic.py +135 -0
- projects/ui/serena-new/test/solidlsp/python/test_python_basic.py +235 -0
- projects/ui/serena-new/test/solidlsp/python/test_retrieval_with_ignored_dirs.py +67 -0
- projects/ui/serena-new/test/solidlsp/python/test_symbol_retrieval.py +472 -0
- projects/ui/serena-new/test/solidlsp/r/__init__.py +1 -0
- projects/ui/serena-new/test/solidlsp/r/test_r_basic.py +97 -0
- projects/ui/serena-new/test/solidlsp/ruby/test_ruby_basic.py +44 -0
- projects/ui/serena-new/test/solidlsp/ruby/test_ruby_symbol_retrieval.py +625 -0
- projects/ui/serena-new/test/solidlsp/rust/test_rust_2024_edition.py +112 -0
- projects/ui/serena-new/test/solidlsp/rust/test_rust_basic.py +57 -0
- projects/ui/serena-new/test/solidlsp/swift/test_swift_basic.py +222 -0
- projects/ui/serena-new/test/solidlsp/terraform/test_terraform_basic.py +53 -0
- projects/ui/serena-new/test/solidlsp/typescript/test_typescript_basic.py +33 -0
- projects/ui/serena-new/test/solidlsp/util/test_zip.py +99 -0
projects/ui/serena-new/test/solidlsp/erlang/test_erlang_symbol_retrieval.py
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Tests for the Erlang language server symbol-related functionality.
|
| 3 |
+
|
| 4 |
+
These tests focus on the following methods:
|
| 5 |
+
- request_containing_symbol
|
| 6 |
+
- request_referencing_symbols
|
| 7 |
+
- request_defining_symbol
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
import pytest
|
| 13 |
+
|
| 14 |
+
from solidlsp import SolidLanguageServer
|
| 15 |
+
from solidlsp.ls_config import Language
|
| 16 |
+
from solidlsp.ls_types import SymbolKind
|
| 17 |
+
|
| 18 |
+
from . import ERLANG_LS_UNAVAILABLE, ERLANG_LS_UNAVAILABLE_REASON
|
| 19 |
+
|
| 20 |
+
# These marks will be applied to all tests in this module
|
| 21 |
+
pytestmark = [
|
| 22 |
+
pytest.mark.erlang,
|
| 23 |
+
pytest.mark.skipif(ERLANG_LS_UNAVAILABLE, reason=f"Erlang LS not available: {ERLANG_LS_UNAVAILABLE_REASON}"),
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class TestErlangLanguageServerSymbols:
|
| 28 |
+
"""Test the Erlang language server's symbol-related functionality."""
|
| 29 |
+
|
| 30 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 31 |
+
def test_request_containing_symbol_function(self, language_server: SolidLanguageServer) -> None:
|
| 32 |
+
"""Test request_containing_symbol for a function."""
|
| 33 |
+
# Test for a position inside the create_user function
|
| 34 |
+
file_path = os.path.join("src", "models.erl")
|
| 35 |
+
|
| 36 |
+
# Find the create_user function in the file
|
| 37 |
+
content = language_server.retrieve_full_file_content(file_path)
|
| 38 |
+
lines = content.split("\n")
|
| 39 |
+
create_user_line = None
|
| 40 |
+
for i, line in enumerate(lines):
|
| 41 |
+
if "create_user(" in line and "-spec" not in line:
|
| 42 |
+
create_user_line = i + 1 # Go inside the function body
|
| 43 |
+
break
|
| 44 |
+
|
| 45 |
+
if create_user_line is None:
|
| 46 |
+
pytest.skip("Could not find create_user function")
|
| 47 |
+
|
| 48 |
+
containing_symbol = language_server.request_containing_symbol(file_path, create_user_line, 10, include_body=True)
|
| 49 |
+
|
| 50 |
+
# Verify that we found the containing symbol
|
| 51 |
+
if containing_symbol:
|
| 52 |
+
assert "create_user" in containing_symbol["name"]
|
| 53 |
+
assert containing_symbol["kind"] == SymbolKind.Method or containing_symbol["kind"] == SymbolKind.Function
|
| 54 |
+
if "body" in containing_symbol:
|
| 55 |
+
assert "create_user" in containing_symbol["body"]
|
| 56 |
+
|
| 57 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 58 |
+
def test_request_containing_symbol_module(self, language_server: SolidLanguageServer) -> None:
|
| 59 |
+
"""Test request_containing_symbol for a module."""
|
| 60 |
+
# Test for a position inside the models module but outside any function
|
| 61 |
+
file_path = os.path.join("src", "models.erl")
|
| 62 |
+
|
| 63 |
+
# Find the module definition
|
| 64 |
+
content = language_server.retrieve_full_file_content(file_path)
|
| 65 |
+
lines = content.split("\n")
|
| 66 |
+
module_line = None
|
| 67 |
+
for i, line in enumerate(lines):
|
| 68 |
+
if "-module(models)" in line:
|
| 69 |
+
module_line = i + 2 # Go inside the module
|
| 70 |
+
break
|
| 71 |
+
|
| 72 |
+
if module_line is None:
|
| 73 |
+
pytest.skip("Could not find models module")
|
| 74 |
+
|
| 75 |
+
containing_symbol = language_server.request_containing_symbol(file_path, module_line, 5)
|
| 76 |
+
|
| 77 |
+
# Verify that we found the containing symbol
|
| 78 |
+
if containing_symbol:
|
| 79 |
+
assert "models" in containing_symbol["name"] or "module" in containing_symbol["name"].lower()
|
| 80 |
+
assert containing_symbol["kind"] == SymbolKind.Module or containing_symbol["kind"] == SymbolKind.Class
|
| 81 |
+
|
| 82 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 83 |
+
def test_request_containing_symbol_nested(self, language_server: SolidLanguageServer) -> None:
|
| 84 |
+
"""Test request_containing_symbol with nested scopes."""
|
| 85 |
+
# Test for a position inside a function which is inside a module
|
| 86 |
+
file_path = os.path.join("src", "models.erl")
|
| 87 |
+
|
| 88 |
+
# Find a function inside models module
|
| 89 |
+
content = language_server.retrieve_full_file_content(file_path)
|
| 90 |
+
lines = content.split("\n")
|
| 91 |
+
function_body_line = None
|
| 92 |
+
for i, line in enumerate(lines):
|
| 93 |
+
if "create_user(" in line and "-spec" not in line:
|
| 94 |
+
# Go deeper into the function body where there might be case expressions
|
| 95 |
+
for j in range(i + 1, min(i + 10, len(lines))):
|
| 96 |
+
if lines[j].strip() and not lines[j].strip().startswith("%"):
|
| 97 |
+
function_body_line = j
|
| 98 |
+
break
|
| 99 |
+
break
|
| 100 |
+
|
| 101 |
+
if function_body_line is None:
|
| 102 |
+
pytest.skip("Could not find function body")
|
| 103 |
+
|
| 104 |
+
containing_symbol = language_server.request_containing_symbol(file_path, function_body_line, 15)
|
| 105 |
+
|
| 106 |
+
# Verify that we found the innermost containing symbol (the function)
|
| 107 |
+
if containing_symbol:
|
| 108 |
+
expected_names = ["create_user", "models"]
|
| 109 |
+
assert any(name in containing_symbol["name"] for name in expected_names)
|
| 110 |
+
|
| 111 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 112 |
+
def test_request_containing_symbol_none(self, language_server: SolidLanguageServer) -> None:
|
| 113 |
+
"""Test request_containing_symbol for a position with no containing symbol."""
|
| 114 |
+
# Test for a position outside any function/module (e.g., in comments)
|
| 115 |
+
file_path = os.path.join("src", "models.erl")
|
| 116 |
+
# Line 1-2 are likely module declaration or comments
|
| 117 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 2, 10)
|
| 118 |
+
|
| 119 |
+
# Should return None or an empty dictionary, or the top-level module
|
| 120 |
+
# This is acceptable behavior for module-level positions
|
| 121 |
+
assert containing_symbol is None or containing_symbol == {} or "models" in str(containing_symbol)
|
| 122 |
+
|
| 123 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 124 |
+
def test_request_referencing_symbols_record(self, language_server: SolidLanguageServer) -> None:
|
| 125 |
+
"""Test request_referencing_symbols for a record."""
|
| 126 |
+
# Test referencing symbols for user record
|
| 127 |
+
file_path = os.path.join("include", "records.hrl")
|
| 128 |
+
|
| 129 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 130 |
+
user_symbol = None
|
| 131 |
+
for symbol_group in symbols:
|
| 132 |
+
user_symbol = next((s for s in symbol_group if "user" in s.get("name", "")), None)
|
| 133 |
+
if user_symbol:
|
| 134 |
+
break
|
| 135 |
+
|
| 136 |
+
if not user_symbol or "selectionRange" not in user_symbol:
|
| 137 |
+
pytest.skip("User record symbol or its selectionRange not found")
|
| 138 |
+
|
| 139 |
+
sel_start = user_symbol["selectionRange"]["start"]
|
| 140 |
+
ref_symbols = [
|
| 141 |
+
ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start["line"], sel_start["character"])
|
| 142 |
+
]
|
| 143 |
+
|
| 144 |
+
if ref_symbols:
|
| 145 |
+
models_references = [
|
| 146 |
+
symbol
|
| 147 |
+
for symbol in ref_symbols
|
| 148 |
+
if "location" in symbol and "uri" in symbol["location"] and "models.erl" in symbol["location"]["uri"]
|
| 149 |
+
]
|
| 150 |
+
# We expect some references from models.erl
|
| 151 |
+
assert len(models_references) >= 0 # At least attempt to find references
|
| 152 |
+
|
| 153 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 154 |
+
def test_request_referencing_symbols_function(self, language_server: SolidLanguageServer) -> None:
|
| 155 |
+
"""Test request_referencing_symbols for a function."""
|
| 156 |
+
# Test referencing symbols for create_user function
|
| 157 |
+
file_path = os.path.join("src", "models.erl")
|
| 158 |
+
|
| 159 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 160 |
+
create_user_symbol = None
|
| 161 |
+
for symbol_group in symbols:
|
| 162 |
+
create_user_symbol = next((s for s in symbol_group if "create_user" in s.get("name", "")), None)
|
| 163 |
+
if create_user_symbol:
|
| 164 |
+
break
|
| 165 |
+
|
| 166 |
+
if not create_user_symbol or "selectionRange" not in create_user_symbol:
|
| 167 |
+
pytest.skip("create_user function symbol or its selectionRange not found")
|
| 168 |
+
|
| 169 |
+
sel_start = create_user_symbol["selectionRange"]["start"]
|
| 170 |
+
ref_symbols = [
|
| 171 |
+
ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start["line"], sel_start["character"])
|
| 172 |
+
]
|
| 173 |
+
|
| 174 |
+
if ref_symbols:
|
| 175 |
+
# We might find references from services.erl or test files
|
| 176 |
+
service_references = [
|
| 177 |
+
symbol
|
| 178 |
+
for symbol in ref_symbols
|
| 179 |
+
if "location" in symbol
|
| 180 |
+
and "uri" in symbol["location"]
|
| 181 |
+
and ("services.erl" in symbol["location"]["uri"] or "test" in symbol["location"]["uri"])
|
| 182 |
+
]
|
| 183 |
+
assert len(service_references) >= 0 # At least attempt to find references
|
| 184 |
+
|
| 185 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 186 |
+
def test_request_referencing_symbols_none(self, language_server: SolidLanguageServer) -> None:
|
| 187 |
+
"""Test request_referencing_symbols for a position with no symbol."""
|
| 188 |
+
file_path = os.path.join("src", "models.erl")
|
| 189 |
+
# Line 3 is likely a blank line or comment
|
| 190 |
+
try:
|
| 191 |
+
ref_symbols = [ref.symbol for ref in language_server.request_referencing_symbols(file_path, 3, 0)]
|
| 192 |
+
# If we get here, make sure we got an empty result
|
| 193 |
+
assert ref_symbols == [] or ref_symbols is None
|
| 194 |
+
except Exception:
|
| 195 |
+
# The method might raise an exception for invalid positions
|
| 196 |
+
# which is acceptable behavior
|
| 197 |
+
pass
|
| 198 |
+
|
| 199 |
+
# Tests for request_defining_symbol
|
| 200 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 201 |
+
def test_request_defining_symbol_function_call(self, language_server: SolidLanguageServer) -> None:
|
| 202 |
+
"""Test request_defining_symbol for a function call."""
|
| 203 |
+
# Find a place where models:create_user is called in services.erl
|
| 204 |
+
file_path = os.path.join("src", "services.erl")
|
| 205 |
+
content = language_server.retrieve_full_file_content(file_path)
|
| 206 |
+
lines = content.split("\n")
|
| 207 |
+
models_call_line = None
|
| 208 |
+
for i, line in enumerate(lines):
|
| 209 |
+
if "models:create_user(" in line:
|
| 210 |
+
models_call_line = i
|
| 211 |
+
break
|
| 212 |
+
|
| 213 |
+
if models_call_line is None:
|
| 214 |
+
pytest.skip("Could not find models:create_user call")
|
| 215 |
+
|
| 216 |
+
# Try to find the definition of models:create_user
|
| 217 |
+
defining_symbol = language_server.request_defining_symbol(file_path, models_call_line, 20)
|
| 218 |
+
|
| 219 |
+
if defining_symbol:
|
| 220 |
+
assert "create_user" in defining_symbol.get("name", "") or "models" in defining_symbol.get("name", "")
|
| 221 |
+
if "location" in defining_symbol and "uri" in defining_symbol["location"]:
|
| 222 |
+
assert "models.erl" in defining_symbol["location"]["uri"]
|
| 223 |
+
|
| 224 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 225 |
+
def test_request_defining_symbol_record_usage(self, language_server: SolidLanguageServer) -> None:
|
| 226 |
+
"""Test request_defining_symbol for a record usage."""
|
| 227 |
+
# Find a place where #user{} record is used in models.erl
|
| 228 |
+
file_path = os.path.join("src", "models.erl")
|
| 229 |
+
content = language_server.retrieve_full_file_content(file_path)
|
| 230 |
+
lines = content.split("\n")
|
| 231 |
+
record_usage_line = None
|
| 232 |
+
for i, line in enumerate(lines):
|
| 233 |
+
if "#user{" in line:
|
| 234 |
+
record_usage_line = i
|
| 235 |
+
break
|
| 236 |
+
|
| 237 |
+
if record_usage_line is None:
|
| 238 |
+
pytest.skip("Could not find #user{} record usage")
|
| 239 |
+
|
| 240 |
+
defining_symbol = language_server.request_defining_symbol(file_path, record_usage_line, 10)
|
| 241 |
+
|
| 242 |
+
if defining_symbol:
|
| 243 |
+
assert "user" in defining_symbol.get("name", "").lower()
|
| 244 |
+
if "location" in defining_symbol and "uri" in defining_symbol["location"]:
|
| 245 |
+
assert "records.hrl" in defining_symbol["location"]["uri"]
|
| 246 |
+
|
| 247 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 248 |
+
def test_request_defining_symbol_module_call(self, language_server: SolidLanguageServer) -> None:
|
| 249 |
+
"""Test request_defining_symbol for a module function call."""
|
| 250 |
+
# Find a place where utils:validate_input is called
|
| 251 |
+
file_path = os.path.join("src", "models.erl")
|
| 252 |
+
content = language_server.retrieve_full_file_content(file_path)
|
| 253 |
+
lines = content.split("\n")
|
| 254 |
+
utils_call_line = None
|
| 255 |
+
for i, line in enumerate(lines):
|
| 256 |
+
if "validate_email(" in line:
|
| 257 |
+
utils_call_line = i
|
| 258 |
+
break
|
| 259 |
+
|
| 260 |
+
if utils_call_line is None:
|
| 261 |
+
pytest.skip("Could not find function call in models.erl")
|
| 262 |
+
|
| 263 |
+
defining_symbol = language_server.request_defining_symbol(file_path, utils_call_line, 15)
|
| 264 |
+
|
| 265 |
+
if defining_symbol:
|
| 266 |
+
assert "validate" in defining_symbol.get("name", "") or "email" in defining_symbol.get("name", "")
|
| 267 |
+
|
| 268 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 269 |
+
def test_request_defining_symbol_none(self, language_server: SolidLanguageServer) -> None:
|
| 270 |
+
"""Test request_defining_symbol for a position with no symbol."""
|
| 271 |
+
# Test for a position with no symbol (e.g., whitespace or comment)
|
| 272 |
+
file_path = os.path.join("src", "models.erl")
|
| 273 |
+
# Line 3 is likely a blank line or comment
|
| 274 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 3, 0)
|
| 275 |
+
|
| 276 |
+
# Should return None or empty
|
| 277 |
+
assert defining_symbol is None or defining_symbol == {}
|
| 278 |
+
|
| 279 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 280 |
+
def test_symbol_methods_integration(self, language_server: SolidLanguageServer) -> None:
|
| 281 |
+
"""Test integration between different symbol methods."""
|
| 282 |
+
file_path = os.path.join("src", "models.erl")
|
| 283 |
+
|
| 284 |
+
# Find create_user function definition
|
| 285 |
+
content = language_server.retrieve_full_file_content(file_path)
|
| 286 |
+
lines = content.split("\n")
|
| 287 |
+
create_user_line = None
|
| 288 |
+
for i, line in enumerate(lines):
|
| 289 |
+
if "create_user(" in line and "-spec" not in line:
|
| 290 |
+
create_user_line = i
|
| 291 |
+
break
|
| 292 |
+
|
| 293 |
+
if create_user_line is None:
|
| 294 |
+
pytest.skip("Could not find create_user function")
|
| 295 |
+
|
| 296 |
+
# Test containing symbol
|
| 297 |
+
containing = language_server.request_containing_symbol(file_path, create_user_line + 2, 10)
|
| 298 |
+
|
| 299 |
+
if containing:
|
| 300 |
+
# Test that we can find references to this symbol
|
| 301 |
+
if "location" in containing and "range" in containing["location"]:
|
| 302 |
+
start_pos = containing["location"]["range"]["start"]
|
| 303 |
+
refs = [
|
| 304 |
+
ref.symbol for ref in language_server.request_referencing_symbols(file_path, start_pos["line"], start_pos["character"])
|
| 305 |
+
]
|
| 306 |
+
# We should find some references or none (both are valid outcomes)
|
| 307 |
+
assert isinstance(refs, list)
|
| 308 |
+
|
| 309 |
+
@pytest.mark.timeout(120) # Add explicit timeout for this complex test
|
| 310 |
+
@pytest.mark.xfail(
|
| 311 |
+
reason="Known intermittent timeout issue in Erlang LS in CI environments. "
|
| 312 |
+
"May pass locally but can timeout on slower CI systems.",
|
| 313 |
+
strict=False,
|
| 314 |
+
)
|
| 315 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 316 |
+
def test_symbol_tree_structure(self, language_server: SolidLanguageServer) -> None:
|
| 317 |
+
"""Test that symbol tree structure is correctly built."""
|
| 318 |
+
symbol_tree = language_server.request_full_symbol_tree()
|
| 319 |
+
|
| 320 |
+
# Should get a tree structure
|
| 321 |
+
assert len(symbol_tree) > 0
|
| 322 |
+
|
| 323 |
+
# Should have our test repository structure
|
| 324 |
+
root = symbol_tree[0]
|
| 325 |
+
assert "children" in root
|
| 326 |
+
|
| 327 |
+
# Look for src directory
|
| 328 |
+
src_dir = None
|
| 329 |
+
for child in root["children"]:
|
| 330 |
+
if child["name"] == "src":
|
| 331 |
+
src_dir = child
|
| 332 |
+
break
|
| 333 |
+
|
| 334 |
+
if src_dir:
|
| 335 |
+
# Check for our Erlang modules
|
| 336 |
+
file_names = [child["name"] for child in src_dir.get("children", [])]
|
| 337 |
+
expected_modules = ["models", "services", "utils", "app"]
|
| 338 |
+
found_modules = [name for name in expected_modules if any(name in fname for fname in file_names)]
|
| 339 |
+
assert len(found_modules) > 0, f"Expected to find some modules from {expected_modules}, but got {file_names}"
|
| 340 |
+
|
| 341 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 342 |
+
def test_request_dir_overview(self, language_server: SolidLanguageServer) -> None:
|
| 343 |
+
"""Test request_dir_overview functionality."""
|
| 344 |
+
src_overview = language_server.request_dir_overview("src")
|
| 345 |
+
|
| 346 |
+
# Should get an overview of the src directory
|
| 347 |
+
assert src_overview is not None
|
| 348 |
+
overview_keys = list(src_overview.keys()) if hasattr(src_overview, "keys") else []
|
| 349 |
+
src_files = [key for key in overview_keys if key.startswith("src/") or "src" in key]
|
| 350 |
+
assert len(src_files) > 0, f"Expected to find src/ files in overview keys: {overview_keys}"
|
| 351 |
+
|
| 352 |
+
# Should contain information about our modules
|
| 353 |
+
overview_text = str(src_overview).lower()
|
| 354 |
+
expected_terms = ["models", "services", "user", "create_user", "gen_server"]
|
| 355 |
+
found_terms = [term for term in expected_terms if term in overview_text]
|
| 356 |
+
assert len(found_terms) > 0, f"Expected to find some terms from {expected_terms} in overview"
|
| 357 |
+
|
| 358 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 359 |
+
def test_containing_symbol_of_record_field(self, language_server: SolidLanguageServer) -> None:
|
| 360 |
+
"""Test containing symbol for record field access."""
|
| 361 |
+
file_path = os.path.join("src", "models.erl")
|
| 362 |
+
|
| 363 |
+
# Find a record field access like User#user.name
|
| 364 |
+
content = language_server.retrieve_full_file_content(file_path)
|
| 365 |
+
lines = content.split("\n")
|
| 366 |
+
record_field_line = None
|
| 367 |
+
for i, line in enumerate(lines):
|
| 368 |
+
if "#user{" in line and ("name" in line or "email" in line or "id" in line):
|
| 369 |
+
record_field_line = i
|
| 370 |
+
break
|
| 371 |
+
|
| 372 |
+
if record_field_line is None:
|
| 373 |
+
pytest.skip("Could not find record field access")
|
| 374 |
+
|
| 375 |
+
containing_symbol = language_server.request_containing_symbol(file_path, record_field_line, 10)
|
| 376 |
+
|
| 377 |
+
if containing_symbol:
|
| 378 |
+
# Should be contained within a function
|
| 379 |
+
assert "name" in containing_symbol
|
| 380 |
+
expected_names = ["create_user", "update_user", "format_user_info"]
|
| 381 |
+
assert any(name in containing_symbol["name"] for name in expected_names)
|
| 382 |
+
|
| 383 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 384 |
+
def test_containing_symbol_of_spec(self, language_server: SolidLanguageServer) -> None:
|
| 385 |
+
"""Test containing symbol for function specs."""
|
| 386 |
+
file_path = os.path.join("src", "models.erl")
|
| 387 |
+
|
| 388 |
+
# Find a -spec directive
|
| 389 |
+
content = language_server.retrieve_full_file_content(file_path)
|
| 390 |
+
lines = content.split("\n")
|
| 391 |
+
spec_line = None
|
| 392 |
+
for i, line in enumerate(lines):
|
| 393 |
+
if line.strip().startswith("-spec") and "create_user" in line:
|
| 394 |
+
spec_line = i
|
| 395 |
+
break
|
| 396 |
+
|
| 397 |
+
if spec_line is None:
|
| 398 |
+
pytest.skip("Could not find -spec directive")
|
| 399 |
+
|
| 400 |
+
containing_symbol = language_server.request_containing_symbol(file_path, spec_line, 5)
|
| 401 |
+
|
| 402 |
+
if containing_symbol:
|
| 403 |
+
# Should be contained within the module or the function it specifies
|
| 404 |
+
assert "name" in containing_symbol
|
| 405 |
+
expected_names = ["models", "create_user"]
|
| 406 |
+
assert any(name in containing_symbol["name"] for name in expected_names)
|
| 407 |
+
|
| 408 |
+
@pytest.mark.timeout(90) # Add explicit timeout
|
| 409 |
+
@pytest.mark.xfail(
|
| 410 |
+
reason="Known intermittent timeout issue in Erlang LS in CI environments. "
|
| 411 |
+
"May pass locally but can timeout on slower CI systems, especially macOS. "
|
| 412 |
+
"Similar to known Next LS timeout issues.",
|
| 413 |
+
strict=False,
|
| 414 |
+
)
|
| 415 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 416 |
+
def test_referencing_symbols_across_files(self, language_server: SolidLanguageServer) -> None:
|
| 417 |
+
"""Test finding references across different files."""
|
| 418 |
+
# Test that we can find references to models module functions in services.erl
|
| 419 |
+
file_path = os.path.join("src", "models.erl")
|
| 420 |
+
|
| 421 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 422 |
+
create_user_symbol = None
|
| 423 |
+
for symbol_group in symbols:
|
| 424 |
+
create_user_symbol = next((s for s in symbol_group if "create_user" in s.get("name", "")), None)
|
| 425 |
+
if create_user_symbol:
|
| 426 |
+
break
|
| 427 |
+
|
| 428 |
+
if not create_user_symbol or "selectionRange" not in create_user_symbol:
|
| 429 |
+
pytest.skip("create_user function symbol not found")
|
| 430 |
+
|
| 431 |
+
sel_start = create_user_symbol["selectionRange"]["start"]
|
| 432 |
+
ref_symbols = [
|
| 433 |
+
ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start["line"], sel_start["character"])
|
| 434 |
+
]
|
| 435 |
+
|
| 436 |
+
# Look for cross-file references
|
| 437 |
+
cross_file_refs = [
|
| 438 |
+
symbol
|
| 439 |
+
for symbol in ref_symbols
|
| 440 |
+
if "location" in symbol and "uri" in symbol["location"] and not symbol["location"]["uri"].endswith("models.erl")
|
| 441 |
+
]
|
| 442 |
+
|
| 443 |
+
# We might find references in services.erl or test files
|
| 444 |
+
if cross_file_refs:
|
| 445 |
+
assert len(cross_file_refs) > 0, "Should find some cross-file references"
|
projects/ui/serena-new/test/solidlsp/go/test_go_basic.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
from solidlsp import SolidLanguageServer
|
| 6 |
+
from solidlsp.ls_config import Language
|
| 7 |
+
from solidlsp.ls_utils import SymbolUtils
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@pytest.mark.go
|
| 11 |
+
class TestGoLanguageServer:
|
| 12 |
+
@pytest.mark.parametrize("language_server", [Language.GO], indirect=True)
|
| 13 |
+
def test_find_symbol(self, language_server: SolidLanguageServer) -> None:
|
| 14 |
+
symbols = language_server.request_full_symbol_tree()
|
| 15 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "main"), "main function not found in symbol tree"
|
| 16 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Helper"), "Helper function not found in symbol tree"
|
| 17 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "DemoStruct"), "DemoStruct not found in symbol tree"
|
| 18 |
+
|
| 19 |
+
@pytest.mark.parametrize("language_server", [Language.GO], indirect=True)
|
| 20 |
+
def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:
|
| 21 |
+
file_path = os.path.join("main.go")
|
| 22 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 23 |
+
helper_symbol = None
|
| 24 |
+
for sym in symbols[0]:
|
| 25 |
+
if sym.get("name") == "Helper":
|
| 26 |
+
helper_symbol = sym
|
| 27 |
+
break
|
| 28 |
+
assert helper_symbol is not None, "Could not find 'Helper' function symbol in main.go"
|
| 29 |
+
sel_start = helper_symbol["selectionRange"]["start"]
|
| 30 |
+
refs = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 31 |
+
assert any(
|
| 32 |
+
"main.go" in ref.get("relativePath", "") for ref in refs
|
| 33 |
+
), "main.go should reference Helper (tried all positions in selectionRange)"
|
projects/ui/serena-new/test/solidlsp/java/test_java_basic.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
from solidlsp import SolidLanguageServer
|
| 6 |
+
from solidlsp.ls_config import Language
|
| 7 |
+
from solidlsp.ls_utils import SymbolUtils
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@pytest.mark.java
|
| 11 |
+
class TestJavaLanguageServer:
|
| 12 |
+
@pytest.mark.parametrize("language_server", [Language.JAVA], indirect=True)
|
| 13 |
+
def test_find_symbol(self, language_server: SolidLanguageServer) -> None:
|
| 14 |
+
symbols = language_server.request_full_symbol_tree()
|
| 15 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Main"), "Main class not found in symbol tree"
|
| 16 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Utils"), "Utils class not found in symbol tree"
|
| 17 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Model"), "Model class not found in symbol tree"
|
| 18 |
+
|
| 19 |
+
@pytest.mark.parametrize("language_server", [Language.JAVA], indirect=True)
|
| 20 |
+
def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:
|
| 21 |
+
# Use correct Maven/Java file paths
|
| 22 |
+
file_path = os.path.join("src", "main", "java", "test_repo", "Utils.java")
|
| 23 |
+
refs = language_server.request_references(file_path, 4, 20)
|
| 24 |
+
assert any("Main.java" in ref.get("relativePath", "") for ref in refs), "Main should reference Utils.printHello"
|
| 25 |
+
|
| 26 |
+
# Dynamically determine the correct line/column for the 'Model' class name
|
| 27 |
+
file_path = os.path.join("src", "main", "java", "test_repo", "Model.java")
|
| 28 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 29 |
+
model_symbol = None
|
| 30 |
+
for sym in symbols[0]:
|
| 31 |
+
if sym.get("name") == "Model" and sym.get("kind") == 5: # 5 = Class
|
| 32 |
+
model_symbol = sym
|
| 33 |
+
break
|
| 34 |
+
assert model_symbol is not None, "Could not find 'Model' class symbol in Model.java"
|
| 35 |
+
# Use selectionRange if present, otherwise fall back to range
|
| 36 |
+
if "selectionRange" in model_symbol:
|
| 37 |
+
sel_start = model_symbol["selectionRange"]["start"]
|
| 38 |
+
else:
|
| 39 |
+
sel_start = model_symbol["range"]["start"]
|
| 40 |
+
refs = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 41 |
+
assert any(
|
| 42 |
+
"Main.java" in ref.get("relativePath", "") for ref in refs
|
| 43 |
+
), "Main should reference Model (tried all positions in selectionRange)"
|
| 44 |
+
|
| 45 |
+
@pytest.mark.parametrize("language_server", [Language.JAVA], indirect=True)
|
| 46 |
+
def test_overview_methods(self, language_server: SolidLanguageServer) -> None:
|
| 47 |
+
symbols = language_server.request_full_symbol_tree()
|
| 48 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Main"), "Main missing from overview"
|
| 49 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Utils"), "Utils missing from overview"
|
| 50 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Model"), "Model missing from overview"
|
projects/ui/serena-new/test/solidlsp/kotlin/test_kotlin_basic.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
from solidlsp import SolidLanguageServer
|
| 6 |
+
from solidlsp.ls_config import Language
|
| 7 |
+
from solidlsp.ls_utils import SymbolUtils
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@pytest.mark.kotlin
|
| 11 |
+
class TestKotlinLanguageServer:
|
| 12 |
+
@pytest.mark.parametrize("language_server", [Language.KOTLIN], indirect=True)
|
| 13 |
+
def test_find_symbol(self, language_server: SolidLanguageServer) -> None:
|
| 14 |
+
symbols = language_server.request_full_symbol_tree()
|
| 15 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Main"), "Main class not found in symbol tree"
|
| 16 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Utils"), "Utils class not found in symbol tree"
|
| 17 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Model"), "Model class not found in symbol tree"
|
| 18 |
+
|
| 19 |
+
@pytest.mark.parametrize("language_server", [Language.KOTLIN], indirect=True)
|
| 20 |
+
def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:
|
| 21 |
+
# Use correct Kotlin file paths
|
| 22 |
+
file_path = os.path.join("src", "main", "kotlin", "test_repo", "Utils.kt")
|
| 23 |
+
refs = language_server.request_references(file_path, 3, 12)
|
| 24 |
+
assert any("Main.kt" in ref.get("relativePath", "") for ref in refs), "Main should reference Utils.printHello"
|
| 25 |
+
|
| 26 |
+
# Dynamically determine the correct line/column for the 'Model' class name
|
| 27 |
+
file_path = os.path.join("src", "main", "kotlin", "test_repo", "Model.kt")
|
| 28 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 29 |
+
model_symbol = None
|
| 30 |
+
for sym in symbols[0]:
|
| 31 |
+
print(sym)
|
| 32 |
+
print("\n")
|
| 33 |
+
if sym.get("name") == "Model" and sym.get("kind") == 23: # 23 = Class
|
| 34 |
+
model_symbol = sym
|
| 35 |
+
break
|
| 36 |
+
assert model_symbol is not None, "Could not find 'Model' class symbol in Model.kt"
|
| 37 |
+
# Use selectionRange if present, otherwise fall back to range
|
| 38 |
+
if "selectionRange" in model_symbol:
|
| 39 |
+
sel_start = model_symbol["selectionRange"]["start"]
|
| 40 |
+
else:
|
| 41 |
+
sel_start = model_symbol["range"]["start"]
|
| 42 |
+
refs = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 43 |
+
assert any(
|
| 44 |
+
"Main.kt" in ref.get("relativePath", "") for ref in refs
|
| 45 |
+
), "Main should reference Model (tried all positions in selectionRange)"
|
| 46 |
+
|
| 47 |
+
@pytest.mark.parametrize("language_server", [Language.KOTLIN], indirect=True)
|
| 48 |
+
def test_overview_methods(self, language_server: SolidLanguageServer) -> None:
|
| 49 |
+
symbols = language_server.request_full_symbol_tree()
|
| 50 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Main"), "Main missing from overview"
|
| 51 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Utils"), "Utils missing from overview"
|
| 52 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Model"), "Model missing from overview"
|
projects/ui/serena-new/test/solidlsp/lua/test_lua_basic.py
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Tests for the Lua language server implementation.
|
| 3 |
+
|
| 4 |
+
These tests validate symbol finding and cross-file reference capabilities
|
| 5 |
+
for Lua modules and functions.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import pytest
|
| 9 |
+
|
| 10 |
+
from solidlsp import SolidLanguageServer
|
| 11 |
+
from solidlsp.ls_config import Language
|
| 12 |
+
from solidlsp.ls_types import SymbolKind
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@pytest.mark.lua
|
| 16 |
+
class TestLuaLanguageServer:
|
| 17 |
+
"""Test Lua language server symbol finding and cross-file references."""
|
| 18 |
+
|
| 19 |
+
@pytest.mark.parametrize("language_server", [Language.LUA], indirect=True)
|
| 20 |
+
def test_find_symbols_in_calculator(self, language_server: SolidLanguageServer) -> None:
|
| 21 |
+
"""Test finding specific functions in calculator.lua."""
|
| 22 |
+
symbols = language_server.request_document_symbols("src/calculator.lua")
|
| 23 |
+
|
| 24 |
+
assert symbols is not None
|
| 25 |
+
assert len(symbols) > 0
|
| 26 |
+
|
| 27 |
+
# Extract function names from the returned structure
|
| 28 |
+
symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols
|
| 29 |
+
function_names = set()
|
| 30 |
+
for symbol in symbol_list:
|
| 31 |
+
if isinstance(symbol, dict):
|
| 32 |
+
name = symbol.get("name", "")
|
| 33 |
+
# Handle both plain names and module-prefixed names
|
| 34 |
+
if "." in name:
|
| 35 |
+
name = name.split(".")[-1]
|
| 36 |
+
if symbol.get("kind") == SymbolKind.Function:
|
| 37 |
+
function_names.add(name)
|
| 38 |
+
|
| 39 |
+
# Verify exact calculator functions exist
|
| 40 |
+
expected_functions = {"add", "subtract", "multiply", "divide", "factorial"}
|
| 41 |
+
found_functions = function_names & expected_functions
|
| 42 |
+
assert found_functions == expected_functions, f"Expected exactly {expected_functions}, found {found_functions}"
|
| 43 |
+
|
| 44 |
+
# Verify specific functions
|
| 45 |
+
assert "add" in function_names, "add function not found"
|
| 46 |
+
assert "multiply" in function_names, "multiply function not found"
|
| 47 |
+
assert "factorial" in function_names, "factorial function not found"
|
| 48 |
+
|
| 49 |
+
@pytest.mark.parametrize("language_server", [Language.LUA], indirect=True)
|
| 50 |
+
def test_find_symbols_in_utils(self, language_server: SolidLanguageServer) -> None:
|
| 51 |
+
"""Test finding specific functions in utils.lua."""
|
| 52 |
+
symbols = language_server.request_document_symbols("src/utils.lua")
|
| 53 |
+
|
| 54 |
+
assert symbols is not None
|
| 55 |
+
assert len(symbols) > 0
|
| 56 |
+
|
| 57 |
+
symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols
|
| 58 |
+
function_names = set()
|
| 59 |
+
all_symbols = set()
|
| 60 |
+
|
| 61 |
+
for symbol in symbol_list:
|
| 62 |
+
if isinstance(symbol, dict):
|
| 63 |
+
name = symbol.get("name", "")
|
| 64 |
+
all_symbols.add(name)
|
| 65 |
+
# Handle both plain names and module-prefixed names
|
| 66 |
+
if "." in name:
|
| 67 |
+
name = name.split(".")[-1]
|
| 68 |
+
if symbol.get("kind") == SymbolKind.Function:
|
| 69 |
+
function_names.add(name)
|
| 70 |
+
|
| 71 |
+
# Verify exact string utility functions
|
| 72 |
+
expected_utils = {"trim", "split", "starts_with", "ends_with"}
|
| 73 |
+
found_utils = function_names & expected_utils
|
| 74 |
+
assert found_utils == expected_utils, f"Expected exactly {expected_utils}, found {found_utils}"
|
| 75 |
+
|
| 76 |
+
# Verify exact table utility functions
|
| 77 |
+
table_utils = {"deep_copy", "table_contains", "table_merge"}
|
| 78 |
+
found_table_utils = function_names & table_utils
|
| 79 |
+
assert found_table_utils == table_utils, f"Expected exactly {table_utils}, found {found_table_utils}"
|
| 80 |
+
|
| 81 |
+
# Check for Logger class/table
|
| 82 |
+
assert "Logger" in all_symbols or any("Logger" in s for s in all_symbols), "Logger not found in symbols"
|
| 83 |
+
|
| 84 |
+
@pytest.mark.parametrize("language_server", [Language.LUA], indirect=True)
|
| 85 |
+
def test_find_symbols_in_main(self, language_server: SolidLanguageServer) -> None:
|
| 86 |
+
"""Test finding functions in main.lua."""
|
| 87 |
+
symbols = language_server.request_document_symbols("main.lua")
|
| 88 |
+
|
| 89 |
+
assert symbols is not None
|
| 90 |
+
assert len(symbols) > 0
|
| 91 |
+
|
| 92 |
+
symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols
|
| 93 |
+
function_names = set()
|
| 94 |
+
|
| 95 |
+
for symbol in symbol_list:
|
| 96 |
+
if isinstance(symbol, dict) and symbol.get("kind") == SymbolKind.Function:
|
| 97 |
+
function_names.add(symbol.get("name", ""))
|
| 98 |
+
|
| 99 |
+
# Verify exact main functions exist
|
| 100 |
+
expected_funcs = {"print_banner", "test_calculator", "test_utils"}
|
| 101 |
+
found_funcs = function_names & expected_funcs
|
| 102 |
+
assert found_funcs == expected_funcs, f"Expected exactly {expected_funcs}, found {found_funcs}"
|
| 103 |
+
|
| 104 |
+
assert "test_calculator" in function_names, "test_calculator function not found"
|
| 105 |
+
assert "test_utils" in function_names, "test_utils function not found"
|
| 106 |
+
|
| 107 |
+
@pytest.mark.parametrize("language_server", [Language.LUA], indirect=True)
|
| 108 |
+
def test_cross_file_references_calculator_add(self, language_server: SolidLanguageServer) -> None:
|
| 109 |
+
"""Test finding cross-file references to calculator.add function."""
|
| 110 |
+
symbols = language_server.request_document_symbols("src/calculator.lua")
|
| 111 |
+
|
| 112 |
+
assert symbols is not None
|
| 113 |
+
symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols
|
| 114 |
+
|
| 115 |
+
# Find the add function
|
| 116 |
+
add_symbol = None
|
| 117 |
+
for sym in symbol_list:
|
| 118 |
+
if isinstance(sym, dict):
|
| 119 |
+
name = sym.get("name", "")
|
| 120 |
+
if "add" in name or name == "add":
|
| 121 |
+
add_symbol = sym
|
| 122 |
+
break
|
| 123 |
+
|
| 124 |
+
assert add_symbol is not None, "add function not found in calculator.lua"
|
| 125 |
+
|
| 126 |
+
# Get references to the add function
|
| 127 |
+
range_info = add_symbol.get("selectionRange", add_symbol.get("range"))
|
| 128 |
+
assert range_info is not None, "add function has no range information"
|
| 129 |
+
|
| 130 |
+
range_start = range_info["start"]
|
| 131 |
+
refs = language_server.request_references("src/calculator.lua", range_start["line"], range_start["character"])
|
| 132 |
+
|
| 133 |
+
assert refs is not None
|
| 134 |
+
assert isinstance(refs, list)
|
| 135 |
+
# add function appears in: main.lua (lines 16, 71), test_calculator.lua (lines 22, 23, 24)
|
| 136 |
+
# Note: The declaration itself may or may not be included as a reference
|
| 137 |
+
assert len(refs) >= 5, f"Should find at least 5 references to calculator.add, found {len(refs)}"
|
| 138 |
+
|
| 139 |
+
# Verify exact reference locations
|
| 140 |
+
ref_files = {}
|
| 141 |
+
for ref in refs:
|
| 142 |
+
filename = ref.get("uri", "").split("/")[-1]
|
| 143 |
+
if filename not in ref_files:
|
| 144 |
+
ref_files[filename] = []
|
| 145 |
+
ref_files[filename].append(ref["range"]["start"]["line"])
|
| 146 |
+
|
| 147 |
+
# The declaration may or may not be included
|
| 148 |
+
if "calculator.lua" in ref_files:
|
| 149 |
+
assert (
|
| 150 |
+
5 in ref_files["calculator.lua"]
|
| 151 |
+
), f"If declaration is included, it should be at line 6 (0-indexed: 5), found at {ref_files['calculator.lua']}"
|
| 152 |
+
|
| 153 |
+
# Check main.lua has usages
|
| 154 |
+
assert "main.lua" in ref_files, "Should find add usages in main.lua"
|
| 155 |
+
assert (
|
| 156 |
+
15 in ref_files["main.lua"] or 70 in ref_files["main.lua"]
|
| 157 |
+
), f"Should find add usage in main.lua, found at lines {ref_files.get('main.lua', [])}"
|
| 158 |
+
|
| 159 |
+
# Check for cross-file references from main.lua
|
| 160 |
+
main_refs = [ref for ref in refs if "main.lua" in ref.get("uri", "")]
|
| 161 |
+
assert len(main_refs) > 0, "calculator.add should be called in main.lua"
|
| 162 |
+
|
| 163 |
+
@pytest.mark.parametrize("language_server", [Language.LUA], indirect=True)
|
| 164 |
+
def test_cross_file_references_utils_trim(self, language_server: SolidLanguageServer) -> None:
|
| 165 |
+
"""Test finding cross-file references to utils.trim function."""
|
| 166 |
+
symbols = language_server.request_document_symbols("src/utils.lua")
|
| 167 |
+
|
| 168 |
+
assert symbols is not None
|
| 169 |
+
symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols
|
| 170 |
+
|
| 171 |
+
# Find the trim function
|
| 172 |
+
trim_symbol = None
|
| 173 |
+
for sym in symbol_list:
|
| 174 |
+
if isinstance(sym, dict):
|
| 175 |
+
name = sym.get("name", "")
|
| 176 |
+
if "trim" in name or name == "trim":
|
| 177 |
+
trim_symbol = sym
|
| 178 |
+
break
|
| 179 |
+
|
| 180 |
+
assert trim_symbol is not None, "trim function not found in utils.lua"
|
| 181 |
+
|
| 182 |
+
# Get references to the trim function
|
| 183 |
+
range_info = trim_symbol.get("selectionRange", trim_symbol.get("range"))
|
| 184 |
+
assert range_info is not None, "trim function has no range information"
|
| 185 |
+
|
| 186 |
+
range_start = range_info["start"]
|
| 187 |
+
refs = language_server.request_references("src/utils.lua", range_start["line"], range_start["character"])
|
| 188 |
+
|
| 189 |
+
assert refs is not None
|
| 190 |
+
assert isinstance(refs, list)
|
| 191 |
+
# trim function appears in: usage (line 32 in main.lua)
|
| 192 |
+
# Note: The declaration itself may or may not be included as a reference
|
| 193 |
+
assert len(refs) >= 1, f"Should find at least 1 reference to utils.trim, found {len(refs)}"
|
| 194 |
+
|
| 195 |
+
# Verify exact reference locations
|
| 196 |
+
ref_files = {}
|
| 197 |
+
for ref in refs:
|
| 198 |
+
filename = ref.get("uri", "").split("/")[-1]
|
| 199 |
+
if filename not in ref_files:
|
| 200 |
+
ref_files[filename] = []
|
| 201 |
+
ref_files[filename].append(ref["range"]["start"]["line"])
|
| 202 |
+
|
| 203 |
+
# The declaration may or may not be included
|
| 204 |
+
if "utils.lua" in ref_files:
|
| 205 |
+
assert (
|
| 206 |
+
5 in ref_files["utils.lua"]
|
| 207 |
+
), f"If declaration is included, it should be at line 6 (0-indexed: 5), found at {ref_files['utils.lua']}"
|
| 208 |
+
|
| 209 |
+
# Check main.lua has usage
|
| 210 |
+
assert "main.lua" in ref_files, "Should find trim usage in main.lua"
|
| 211 |
+
assert (
|
| 212 |
+
31 in ref_files["main.lua"]
|
| 213 |
+
), f"Should find trim usage at line 32 (0-indexed: 31) in main.lua, found at lines {ref_files.get('main.lua', [])}"
|
| 214 |
+
|
| 215 |
+
# Check for cross-file references from main.lua
|
| 216 |
+
main_refs = [ref for ref in refs if "main.lua" in ref.get("uri", "")]
|
| 217 |
+
assert len(main_refs) > 0, "utils.trim should be called in main.lua"
|
| 218 |
+
|
| 219 |
+
@pytest.mark.parametrize("language_server", [Language.LUA], indirect=True)
|
| 220 |
+
def test_hover_information(self, language_server: SolidLanguageServer) -> None:
|
| 221 |
+
"""Test hover information for symbols."""
|
| 222 |
+
# Get hover info for a function
|
| 223 |
+
hover_info = language_server.request_hover("src/calculator.lua", 5, 10) # Position near add function
|
| 224 |
+
|
| 225 |
+
assert hover_info is not None, "Should provide hover information"
|
| 226 |
+
|
| 227 |
+
# Hover info could be a dict with 'contents' or a string
|
| 228 |
+
if isinstance(hover_info, dict):
|
| 229 |
+
assert "contents" in hover_info or "value" in hover_info, "Hover should have contents"
|
| 230 |
+
|
| 231 |
+
@pytest.mark.parametrize("language_server", [Language.LUA], indirect=True)
|
| 232 |
+
def test_full_symbol_tree(self, language_server: SolidLanguageServer) -> None:
|
| 233 |
+
"""Test that full symbol tree is not empty."""
|
| 234 |
+
symbols = language_server.request_full_symbol_tree()
|
| 235 |
+
|
| 236 |
+
assert symbols is not None
|
| 237 |
+
assert len(symbols) > 0, "Symbol tree should not be empty"
|
| 238 |
+
|
| 239 |
+
# The tree should have at least one root node
|
| 240 |
+
root = symbols[0]
|
| 241 |
+
assert isinstance(root, dict), "Root should be a dict"
|
| 242 |
+
assert "name" in root, "Root should have a name"
|
| 243 |
+
|
| 244 |
+
@pytest.mark.parametrize("language_server", [Language.LUA], indirect=True)
|
| 245 |
+
def test_references_between_test_and_source(self, language_server: SolidLanguageServer) -> None:
|
| 246 |
+
"""Test finding references from test files to source files."""
|
| 247 |
+
# Check if test_calculator.lua references calculator module
|
| 248 |
+
test_symbols = language_server.request_document_symbols("tests/test_calculator.lua")
|
| 249 |
+
|
| 250 |
+
assert test_symbols is not None
|
| 251 |
+
assert len(test_symbols) > 0
|
| 252 |
+
|
| 253 |
+
# The test file should have some content that references calculator
|
| 254 |
+
symbol_list = test_symbols[0] if isinstance(test_symbols, tuple) else test_symbols
|
| 255 |
+
assert len(symbol_list) > 0, "test_calculator.lua should have symbols"
|
projects/ui/serena-new/test/solidlsp/nix/test_nix_basic.py
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Tests for the Nix language server implementation using nixd.
|
| 3 |
+
|
| 4 |
+
These tests validate symbol finding and cross-file reference capabilities for Nix expressions.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import platform
|
| 8 |
+
|
| 9 |
+
import pytest
|
| 10 |
+
|
| 11 |
+
from solidlsp import SolidLanguageServer
|
| 12 |
+
from solidlsp.ls_config import Language
|
| 13 |
+
|
| 14 |
+
# Skip all Nix tests on Windows as Nix doesn't support Windows
|
| 15 |
+
pytestmark = pytest.mark.skipif(platform.system() == "Windows", reason="Nix and nil are not available on Windows")
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
@pytest.mark.nix
|
| 19 |
+
class TestNixLanguageServer:
|
| 20 |
+
"""Test Nix language server symbol finding capabilities."""
|
| 21 |
+
|
| 22 |
+
@pytest.mark.parametrize("language_server", [Language.NIX], indirect=True)
|
| 23 |
+
def test_find_symbols_in_default_nix(self, language_server: SolidLanguageServer) -> None:
|
| 24 |
+
"""Test finding specific symbols in default.nix."""
|
| 25 |
+
symbols = language_server.request_document_symbols("default.nix")
|
| 26 |
+
|
| 27 |
+
assert symbols is not None
|
| 28 |
+
assert len(symbols) > 0
|
| 29 |
+
|
| 30 |
+
# Extract symbol names from the returned structure
|
| 31 |
+
symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols
|
| 32 |
+
symbol_names = {sym.get("name") for sym in symbol_list if isinstance(sym, dict)}
|
| 33 |
+
|
| 34 |
+
# Verify specific function exists
|
| 35 |
+
assert "makeGreeting" in symbol_names, "makeGreeting function not found"
|
| 36 |
+
|
| 37 |
+
# Verify exact attribute sets are found
|
| 38 |
+
expected_attrs = {"listUtils", "stringUtils"}
|
| 39 |
+
found_attrs = symbol_names & expected_attrs
|
| 40 |
+
assert found_attrs == expected_attrs, f"Expected exactly {expected_attrs}, found {found_attrs}"
|
| 41 |
+
|
| 42 |
+
@pytest.mark.parametrize("language_server", [Language.NIX], indirect=True)
|
| 43 |
+
def test_find_symbols_in_utils(self, language_server: SolidLanguageServer) -> None:
|
| 44 |
+
"""Test finding symbols in lib/utils.nix."""
|
| 45 |
+
symbols = language_server.request_document_symbols("lib/utils.nix")
|
| 46 |
+
|
| 47 |
+
assert symbols is not None
|
| 48 |
+
assert len(symbols) > 0
|
| 49 |
+
|
| 50 |
+
symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols
|
| 51 |
+
symbol_names = {sym.get("name") for sym in symbol_list if isinstance(sym, dict)}
|
| 52 |
+
|
| 53 |
+
# Verify exact utility modules are found
|
| 54 |
+
expected_modules = {"math", "strings", "lists", "attrs"}
|
| 55 |
+
found_modules = symbol_names & expected_modules
|
| 56 |
+
assert found_modules == expected_modules, f"Expected exactly {expected_modules}, found {found_modules}"
|
| 57 |
+
|
| 58 |
+
@pytest.mark.parametrize("language_server", [Language.NIX], indirect=True)
|
| 59 |
+
def test_find_symbols_in_flake(self, language_server: SolidLanguageServer) -> None:
|
| 60 |
+
"""Test finding symbols in flake.nix."""
|
| 61 |
+
symbols = language_server.request_document_symbols("flake.nix")
|
| 62 |
+
|
| 63 |
+
assert symbols is not None
|
| 64 |
+
assert len(symbols) > 0
|
| 65 |
+
|
| 66 |
+
symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols
|
| 67 |
+
symbol_names = {sym.get("name") for sym in symbol_list if isinstance(sym, dict)}
|
| 68 |
+
|
| 69 |
+
# Flakes must have either inputs or outputs
|
| 70 |
+
assert "inputs" in symbol_names or "outputs" in symbol_names, "Flake must have inputs or outputs"
|
| 71 |
+
|
| 72 |
+
@pytest.mark.parametrize("language_server", [Language.NIX], indirect=True)
|
| 73 |
+
def test_find_symbols_in_module(self, language_server: SolidLanguageServer) -> None:
|
| 74 |
+
"""Test finding symbols in a NixOS module."""
|
| 75 |
+
symbols = language_server.request_document_symbols("modules/example.nix")
|
| 76 |
+
|
| 77 |
+
assert symbols is not None
|
| 78 |
+
assert len(symbols) > 0
|
| 79 |
+
|
| 80 |
+
symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols
|
| 81 |
+
symbol_names = {sym.get("name") for sym in symbol_list if isinstance(sym, dict)}
|
| 82 |
+
|
| 83 |
+
# NixOS modules must have either options or config
|
| 84 |
+
assert "options" in symbol_names or "config" in symbol_names, "Module must have options or config"
|
| 85 |
+
|
| 86 |
+
@pytest.mark.parametrize("language_server", [Language.NIX], indirect=True)
|
| 87 |
+
def test_find_references_within_file(self, language_server: SolidLanguageServer) -> None:
|
| 88 |
+
"""Test finding references within the same file."""
|
| 89 |
+
symbols = language_server.request_document_symbols("default.nix")
|
| 90 |
+
|
| 91 |
+
assert symbols is not None
|
| 92 |
+
symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols
|
| 93 |
+
|
| 94 |
+
# Find makeGreeting function
|
| 95 |
+
greeting_symbol = None
|
| 96 |
+
for sym in symbol_list:
|
| 97 |
+
if sym.get("name") == "makeGreeting":
|
| 98 |
+
greeting_symbol = sym
|
| 99 |
+
break
|
| 100 |
+
|
| 101 |
+
assert greeting_symbol is not None, "makeGreeting function not found"
|
| 102 |
+
assert "range" in greeting_symbol, "Symbol must have range information"
|
| 103 |
+
|
| 104 |
+
range_start = greeting_symbol["range"]["start"]
|
| 105 |
+
refs = language_server.request_references("default.nix", range_start["line"], range_start["character"])
|
| 106 |
+
|
| 107 |
+
assert refs is not None
|
| 108 |
+
assert isinstance(refs, list)
|
| 109 |
+
# nixd finds at least the inherit statement (line 67)
|
| 110 |
+
assert len(refs) >= 1, f"Should find at least 1 reference to makeGreeting, found {len(refs)}"
|
| 111 |
+
|
| 112 |
+
# Verify makeGreeting is referenced at expected locations
|
| 113 |
+
if refs:
|
| 114 |
+
ref_lines = sorted([ref["range"]["start"]["line"] for ref in refs])
|
| 115 |
+
# Check if we found the inherit (line 67, 0-indexed: 66)
|
| 116 |
+
assert 66 in ref_lines, f"Should find makeGreeting inherit at line 67, found at lines {[l+1 for l in ref_lines]}"
|
| 117 |
+
|
| 118 |
+
@pytest.mark.parametrize("language_server", [Language.NIX], indirect=True)
|
| 119 |
+
def test_hover_information(self, language_server: SolidLanguageServer) -> None:
|
| 120 |
+
"""Test hover information for symbols."""
|
| 121 |
+
# Get hover info for makeGreeting function
|
| 122 |
+
hover_info = language_server.request_hover("default.nix", 9, 5) # Position near makeGreeting
|
| 123 |
+
|
| 124 |
+
assert hover_info is not None, "Should provide hover information"
|
| 125 |
+
|
| 126 |
+
if isinstance(hover_info, dict) and len(hover_info) > 0:
|
| 127 |
+
# If hover info is provided, it should have proper structure
|
| 128 |
+
assert "contents" in hover_info or "value" in hover_info, "Hover should have contents or value"
|
| 129 |
+
|
| 130 |
+
@pytest.mark.parametrize("language_server", [Language.NIX], indirect=True)
|
| 131 |
+
def test_cross_file_references_utils_import(self, language_server: SolidLanguageServer) -> None:
|
| 132 |
+
"""Test finding cross-file references for imported utils."""
|
| 133 |
+
# Find references to 'utils' which is imported in default.nix from lib/utils.nix
|
| 134 |
+
# Line 10 in default.nix: utils = import ./lib/utils.nix { inherit lib; };
|
| 135 |
+
refs = language_server.request_references("default.nix", 9, 2) # Position of 'utils'
|
| 136 |
+
|
| 137 |
+
assert refs is not None
|
| 138 |
+
assert isinstance(refs, list)
|
| 139 |
+
|
| 140 |
+
# Should find references within default.nix where utils is used
|
| 141 |
+
default_refs = [ref for ref in refs if "default.nix" in ref.get("uri", "")]
|
| 142 |
+
# utils is: imported (line 10), used in listUtils.unique (line 24), inherited in exports (line 69)
|
| 143 |
+
assert len(default_refs) >= 2, f"Should find at least 2 references to utils in default.nix, found {len(default_refs)}"
|
| 144 |
+
|
| 145 |
+
# Verify utils is referenced at expected locations (0-indexed)
|
| 146 |
+
if default_refs:
|
| 147 |
+
ref_lines = sorted([ref["range"]["start"]["line"] for ref in default_refs])
|
| 148 |
+
# Check for key references - at least the import (line 10) or usage (line 24)
|
| 149 |
+
assert (
|
| 150 |
+
9 in ref_lines or 23 in ref_lines
|
| 151 |
+
), f"Should find utils import or usage, found references at lines {[l+1 for l in ref_lines]}"
|
| 152 |
+
|
| 153 |
+
@pytest.mark.parametrize("language_server", [Language.NIX], indirect=True)
|
| 154 |
+
def test_verify_imports_exist(self, language_server: SolidLanguageServer) -> None:
|
| 155 |
+
"""Verify that our test files have proper imports set up."""
|
| 156 |
+
# Verify that default.nix imports utils from lib/utils.nix
|
| 157 |
+
symbols = language_server.request_document_symbols("default.nix")
|
| 158 |
+
|
| 159 |
+
assert symbols is not None
|
| 160 |
+
symbol_list = symbols[0] if isinstance(symbols, tuple) else symbols
|
| 161 |
+
|
| 162 |
+
# Check that makeGreeting exists (defined in default.nix)
|
| 163 |
+
symbol_names = {sym.get("name") for sym in symbol_list if isinstance(sym, dict)}
|
| 164 |
+
assert "makeGreeting" in symbol_names, "makeGreeting should be found in default.nix"
|
| 165 |
+
|
| 166 |
+
# Verify lib/utils.nix has the expected structure
|
| 167 |
+
utils_symbols = language_server.request_document_symbols("lib/utils.nix")
|
| 168 |
+
assert utils_symbols is not None
|
| 169 |
+
utils_list = utils_symbols[0] if isinstance(utils_symbols, tuple) else utils_symbols
|
| 170 |
+
utils_names = {sym.get("name") for sym in utils_list if isinstance(sym, dict)}
|
| 171 |
+
|
| 172 |
+
# Verify key functions exist in utils
|
| 173 |
+
assert "math" in utils_names, "math should be found in lib/utils.nix"
|
| 174 |
+
assert "strings" in utils_names, "strings should be found in lib/utils.nix"
|
| 175 |
+
|
| 176 |
+
@pytest.mark.parametrize("language_server", [Language.NIX], indirect=True)
|
| 177 |
+
def test_go_to_definition_cross_file(self, language_server: SolidLanguageServer) -> None:
|
| 178 |
+
"""Test go-to-definition from default.nix to lib/utils.nix."""
|
| 179 |
+
# Line 24 in default.nix: unique = utils.lists.unique;
|
| 180 |
+
# Test go-to-definition for 'utils'
|
| 181 |
+
definitions = language_server.request_definition("default.nix", 23, 14) # Position of 'utils'
|
| 182 |
+
|
| 183 |
+
assert definitions is not None
|
| 184 |
+
assert isinstance(definitions, list)
|
| 185 |
+
|
| 186 |
+
if len(definitions) > 0:
|
| 187 |
+
# Should point to the import statement or utils.nix
|
| 188 |
+
assert any(
|
| 189 |
+
"utils" in def_item.get("uri", "") or "default.nix" in def_item.get("uri", "") for def_item in definitions
|
| 190 |
+
), "Definition should relate to utils import or utils.nix file"
|
| 191 |
+
|
| 192 |
+
@pytest.mark.parametrize("language_server", [Language.NIX], indirect=True)
|
| 193 |
+
def test_definition_navigation_in_flake(self, language_server: SolidLanguageServer) -> None:
|
| 194 |
+
"""Test definition navigation in flake.nix."""
|
| 195 |
+
# Test that we can navigate to definitions within flake.nix
|
| 196 |
+
# Line 69: default = hello-custom;
|
| 197 |
+
definitions = language_server.request_definition("flake.nix", 68, 20) # Position of 'hello-custom'
|
| 198 |
+
|
| 199 |
+
assert definitions is not None
|
| 200 |
+
assert isinstance(definitions, list)
|
| 201 |
+
# nixd should find the definition of hello-custom in the same file
|
| 202 |
+
if len(definitions) > 0:
|
| 203 |
+
assert any(
|
| 204 |
+
"flake.nix" in def_item.get("uri", "") for def_item in definitions
|
| 205 |
+
), "Should find hello-custom definition in flake.nix"
|
| 206 |
+
|
| 207 |
+
@pytest.mark.parametrize("language_server", [Language.NIX], indirect=True)
|
| 208 |
+
def test_full_symbol_tree(self, language_server: SolidLanguageServer) -> None:
|
| 209 |
+
"""Test that full symbol tree is not empty."""
|
| 210 |
+
symbols = language_server.request_full_symbol_tree()
|
| 211 |
+
|
| 212 |
+
assert symbols is not None
|
| 213 |
+
assert len(symbols) > 0, "Symbol tree should not be empty"
|
| 214 |
+
|
| 215 |
+
# The tree should have at least one root node
|
| 216 |
+
root = symbols[0]
|
| 217 |
+
assert isinstance(root, dict), "Root should be a dict"
|
| 218 |
+
assert "name" in root, "Root should have a name"
|
projects/ui/serena-new/test/solidlsp/php/test_php_basic.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
from solidlsp import SolidLanguageServer
|
| 6 |
+
from solidlsp.ls_config import Language
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@pytest.mark.php
|
| 10 |
+
class TestPhpLanguageServer:
|
| 11 |
+
@pytest.mark.parametrize("language_server", [Language.PHP], indirect=True)
|
| 12 |
+
@pytest.mark.parametrize("repo_path", [Language.PHP], indirect=True)
|
| 13 |
+
def test_ls_is_running(self, language_server: SolidLanguageServer, repo_path: Path) -> None:
|
| 14 |
+
"""Test that the language server starts and stops successfully."""
|
| 15 |
+
# The fixture already handles start and stop
|
| 16 |
+
assert language_server.is_running()
|
| 17 |
+
assert Path(language_server.language_server.repository_root_path).resolve() == repo_path.resolve()
|
| 18 |
+
|
| 19 |
+
@pytest.mark.parametrize("language_server", [Language.PHP], indirect=True)
|
| 20 |
+
@pytest.mark.parametrize("repo_path", [Language.PHP], indirect=True)
|
| 21 |
+
def test_find_definition_within_file(self, language_server: SolidLanguageServer, repo_path: Path) -> None:
|
| 22 |
+
|
| 23 |
+
# In index.php:
|
| 24 |
+
# Line 9 (1-indexed): $greeting = greet($userName);
|
| 25 |
+
# Line 11 (1-indexed): echo $greeting;
|
| 26 |
+
# We want to find the definition of $greeting (defined on line 9)
|
| 27 |
+
# from its usage in echo $greeting; on line 11.
|
| 28 |
+
# LSP is 0-indexed: definition on line 8, usage on line 10.
|
| 29 |
+
# $greeting in echo $greeting; is at char 5 on line 11 (0-indexed: line 10, char 5)
|
| 30 |
+
# e c h o $ g r e e t i n g
|
| 31 |
+
# ^ char 5
|
| 32 |
+
definition_location_list = language_server.request_definition(str(repo_path / "index.php"), 10, 6) # cursor on 'g' in $greeting
|
| 33 |
+
|
| 34 |
+
assert definition_location_list, f"Expected non-empty definition_location_list but got {definition_location_list=}"
|
| 35 |
+
assert len(definition_location_list) == 1
|
| 36 |
+
definition_location = definition_location_list[0]
|
| 37 |
+
assert definition_location["uri"].endswith("index.php")
|
| 38 |
+
# Definition of $greeting is on line 10 (1-indexed) / line 9 (0-indexed), char 0
|
| 39 |
+
assert definition_location["range"]["start"]["line"] == 9
|
| 40 |
+
assert definition_location["range"]["start"]["character"] == 0
|
| 41 |
+
|
| 42 |
+
@pytest.mark.parametrize("language_server", [Language.PHP], indirect=True)
|
| 43 |
+
@pytest.mark.parametrize("repo_path", [Language.PHP], indirect=True)
|
| 44 |
+
def test_find_definition_across_files(self, language_server: SolidLanguageServer, repo_path: Path) -> None:
|
| 45 |
+
definition_location_list = language_server.request_definition(str(repo_path / "index.php"), 12, 5) # helperFunction
|
| 46 |
+
|
| 47 |
+
assert definition_location_list, f"Expected non-empty definition_location_list but got {definition_location_list=}"
|
| 48 |
+
assert len(definition_location_list) == 1
|
| 49 |
+
definition_location = definition_location_list[0]
|
| 50 |
+
assert definition_location["uri"].endswith("helper.php")
|
| 51 |
+
assert definition_location["range"]["start"]["line"] == 2
|
| 52 |
+
assert definition_location["range"]["start"]["character"] == 0
|
| 53 |
+
|
| 54 |
+
@pytest.mark.parametrize("language_server", [Language.PHP], indirect=True)
|
| 55 |
+
@pytest.mark.parametrize("repo_path", [Language.PHP], indirect=True)
|
| 56 |
+
def test_find_definition_simple_variable(self, language_server: SolidLanguageServer, repo_path: Path) -> None:
|
| 57 |
+
file_path = str(repo_path / "simple_var.php")
|
| 58 |
+
|
| 59 |
+
# In simple_var.php:
|
| 60 |
+
# Line 2 (1-indexed): $localVar = "test";
|
| 61 |
+
# Line 3 (1-indexed): echo $localVar;
|
| 62 |
+
# LSP is 0-indexed: definition on line 1, usage on line 2
|
| 63 |
+
# Find definition of $localVar (char 5 on line 3 / 0-indexed: line 2, char 5)
|
| 64 |
+
# $localVar in echo $localVar; (e c h o $ l o c a l V a r)
|
| 65 |
+
# ^ char 5
|
| 66 |
+
definition_location_list = language_server.request_definition(file_path, 2, 6) # cursor on 'l' in $localVar
|
| 67 |
+
|
| 68 |
+
assert definition_location_list, f"Expected non-empty definition_location_list but got {definition_location_list=}"
|
| 69 |
+
assert len(definition_location_list) == 1
|
| 70 |
+
definition_location = definition_location_list[0]
|
| 71 |
+
assert definition_location["uri"].endswith("simple_var.php")
|
| 72 |
+
assert definition_location["range"]["start"]["line"] == 1 # Definition of $localVar (0-indexed)
|
| 73 |
+
assert definition_location["range"]["start"]["character"] == 0 # $localVar (0-indexed)
|
| 74 |
+
|
| 75 |
+
@pytest.mark.parametrize("language_server", [Language.PHP], indirect=True)
|
| 76 |
+
@pytest.mark.parametrize("repo_path", [Language.PHP], indirect=True)
|
| 77 |
+
def test_find_references_within_file(self, language_server: SolidLanguageServer, repo_path: Path) -> None:
|
| 78 |
+
index_php_path = str(repo_path / "index.php")
|
| 79 |
+
|
| 80 |
+
# In index.php (0-indexed lines):
|
| 81 |
+
# Line 9: $greeting = greet($userName); // Definition of $greeting
|
| 82 |
+
# Line 11: echo $greeting; // Usage of $greeting
|
| 83 |
+
# Find references for $greeting from its usage in "echo $greeting;" (line 11, char 6 for 'g')
|
| 84 |
+
references = language_server.request_references(index_php_path, 11, 6)
|
| 85 |
+
|
| 86 |
+
assert references
|
| 87 |
+
# Intelephense, when asked for references from usage, seems to only return the usage itself.
|
| 88 |
+
assert len(references) == 1, "Expected to find 1 reference for $greeting (the usage itself)"
|
| 89 |
+
|
| 90 |
+
expected_locations = [{"uri_suffix": "index.php", "line": 11, "character": 5}] # Usage: echo $greeting (points to $)
|
| 91 |
+
|
| 92 |
+
# Convert actual references to a comparable format and sort
|
| 93 |
+
actual_locations = sorted(
|
| 94 |
+
[
|
| 95 |
+
{
|
| 96 |
+
"uri_suffix": loc["uri"].split("/")[-1],
|
| 97 |
+
"line": loc["range"]["start"]["line"],
|
| 98 |
+
"character": loc["range"]["start"]["character"],
|
| 99 |
+
}
|
| 100 |
+
for loc in references
|
| 101 |
+
],
|
| 102 |
+
key=lambda x: (x["uri_suffix"], x["line"], x["character"]),
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
expected_locations = sorted(expected_locations, key=lambda x: (x["uri_suffix"], x["line"], x["character"]))
|
| 106 |
+
|
| 107 |
+
assert actual_locations == expected_locations
|
| 108 |
+
|
| 109 |
+
@pytest.mark.parametrize("language_server", [Language.PHP], indirect=True)
|
| 110 |
+
@pytest.mark.parametrize("repo_path", [Language.PHP], indirect=True)
|
| 111 |
+
def test_find_references_across_files(self, language_server: SolidLanguageServer, repo_path: Path) -> None:
|
| 112 |
+
helper_php_path = str(repo_path / "helper.php")
|
| 113 |
+
# In index.php (0-indexed lines):
|
| 114 |
+
# Line 13: helperFunction(); // Usage of helperFunction
|
| 115 |
+
# Find references for helperFunction from its definition
|
| 116 |
+
references = language_server.request_references(helper_php_path, 2, len("function "))
|
| 117 |
+
|
| 118 |
+
assert references, f"Expected non-empty references for helperFunction but got {references=}"
|
| 119 |
+
# Intelephense might return 1 (usage) or 2 (usage + definition) references.
|
| 120 |
+
# Let's check for at least the usage in index.php
|
| 121 |
+
# Definition is in helper.php, line 2, char 0 (based on previous findings)
|
| 122 |
+
# Usage is in index.php, line 13, char 0
|
| 123 |
+
|
| 124 |
+
actual_locations_comparable = []
|
| 125 |
+
for loc in references:
|
| 126 |
+
actual_locations_comparable.append(
|
| 127 |
+
{
|
| 128 |
+
"uri_suffix": loc["uri"].split("/")[-1],
|
| 129 |
+
"line": loc["range"]["start"]["line"],
|
| 130 |
+
"character": loc["range"]["start"]["character"],
|
| 131 |
+
}
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
usage_in_index_php = {"uri_suffix": "index.php", "line": 13, "character": 0}
|
| 135 |
+
assert usage_in_index_php in actual_locations_comparable, "Usage of helperFunction in index.php not found"
|
projects/ui/serena-new/test/solidlsp/python/test_python_basic.py
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Basic integration tests for the language server functionality.
|
| 3 |
+
|
| 4 |
+
These tests validate the functionality of the language server APIs
|
| 5 |
+
like request_references using the test repository.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
import pytest
|
| 11 |
+
|
| 12 |
+
from serena.project import Project
|
| 13 |
+
from serena.text_utils import LineType
|
| 14 |
+
from solidlsp import SolidLanguageServer
|
| 15 |
+
from solidlsp.ls_config import Language
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
@pytest.mark.python
|
| 19 |
+
class TestLanguageServerBasics:
|
| 20 |
+
"""Test basic functionality of the language server."""
|
| 21 |
+
|
| 22 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 23 |
+
def test_request_references_user_class(self, language_server: SolidLanguageServer) -> None:
|
| 24 |
+
"""Test request_references on the User class."""
|
| 25 |
+
# Get references to the User class in models.py
|
| 26 |
+
file_path = os.path.join("test_repo", "models.py")
|
| 27 |
+
# Line 31 contains the User class definition
|
| 28 |
+
# Use selectionRange only
|
| 29 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 30 |
+
user_symbol = next((s for s in symbols[0] if s.get("name") == "User"), None)
|
| 31 |
+
if not user_symbol or "selectionRange" not in user_symbol:
|
| 32 |
+
raise AssertionError("User symbol or its selectionRange not found")
|
| 33 |
+
sel_start = user_symbol["selectionRange"]["start"]
|
| 34 |
+
references = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 35 |
+
assert len(references) > 1, "User class should be referenced in multiple files (using selectionRange if present)"
|
| 36 |
+
|
| 37 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 38 |
+
def test_request_references_item_class(self, language_server: SolidLanguageServer) -> None:
|
| 39 |
+
"""Test request_references on the Item class."""
|
| 40 |
+
# Get references to the Item class in models.py
|
| 41 |
+
file_path = os.path.join("test_repo", "models.py")
|
| 42 |
+
# Line 56 contains the Item class definition
|
| 43 |
+
# Use selectionRange only
|
| 44 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 45 |
+
item_symbol = next((s for s in symbols[0] if s.get("name") == "Item"), None)
|
| 46 |
+
if not item_symbol or "selectionRange" not in item_symbol:
|
| 47 |
+
raise AssertionError("Item symbol or its selectionRange not found")
|
| 48 |
+
sel_start = item_symbol["selectionRange"]["start"]
|
| 49 |
+
references = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 50 |
+
services_references = [ref for ref in references if "services.py" in ref["uri"]]
|
| 51 |
+
assert len(services_references) > 0, "At least one reference should be in services.py (using selectionRange if present)"
|
| 52 |
+
|
| 53 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 54 |
+
def test_request_references_function_parameter(self, language_server: SolidLanguageServer) -> None:
|
| 55 |
+
"""Test request_references on a function parameter."""
|
| 56 |
+
# Get references to the id parameter in get_user method
|
| 57 |
+
file_path = os.path.join("test_repo", "services.py")
|
| 58 |
+
# Line 24 contains the get_user method with id parameter
|
| 59 |
+
# Use selectionRange only
|
| 60 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 61 |
+
get_user_symbol = next((s for s in symbols[0] if s.get("name") == "get_user"), None)
|
| 62 |
+
if not get_user_symbol or "selectionRange" not in get_user_symbol:
|
| 63 |
+
raise AssertionError("get_user symbol or its selectionRange not found")
|
| 64 |
+
sel_start = get_user_symbol["selectionRange"]["start"]
|
| 65 |
+
references = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 66 |
+
assert len(references) > 0, "id parameter should be referenced within the method (using selectionRange if present)"
|
| 67 |
+
|
| 68 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 69 |
+
def test_request_references_create_user_method(self, language_server: SolidLanguageServer) -> None:
|
| 70 |
+
# Get references to the create_user method in UserService
|
| 71 |
+
file_path = os.path.join("test_repo", "services.py")
|
| 72 |
+
# Line 15 contains the create_user method definition
|
| 73 |
+
# Use selectionRange only
|
| 74 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 75 |
+
create_user_symbol = next((s for s in symbols[0] if s.get("name") == "create_user"), None)
|
| 76 |
+
if not create_user_symbol or "selectionRange" not in create_user_symbol:
|
| 77 |
+
raise AssertionError("create_user symbol or its selectionRange not found")
|
| 78 |
+
sel_start = create_user_symbol["selectionRange"]["start"]
|
| 79 |
+
references = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 80 |
+
assert len(references) > 1, "Should get valid references for create_user (using selectionRange if present)"
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
class TestProjectBasics:
|
| 84 |
+
@pytest.mark.parametrize("project", [Language.PYTHON], indirect=True)
|
| 85 |
+
def test_retrieve_content_around_line(self, project: Project) -> None:
|
| 86 |
+
"""Test retrieve_content_around_line functionality with various scenarios."""
|
| 87 |
+
file_path = os.path.join("test_repo", "models.py")
|
| 88 |
+
|
| 89 |
+
# Scenario 1: Just a single line (User class definition)
|
| 90 |
+
line_31 = project.retrieve_content_around_line(file_path, 31)
|
| 91 |
+
assert len(line_31.lines) == 1
|
| 92 |
+
assert "class User(BaseModel):" in line_31.lines[0].line_content
|
| 93 |
+
assert line_31.lines[0].line_number == 31
|
| 94 |
+
assert line_31.lines[0].match_type == LineType.MATCH
|
| 95 |
+
|
| 96 |
+
# Scenario 2: Context above and below
|
| 97 |
+
with_context_around_user = project.retrieve_content_around_line(file_path, 31, 2, 2)
|
| 98 |
+
assert len(with_context_around_user.lines) == 5
|
| 99 |
+
# Check line content
|
| 100 |
+
assert "class User(BaseModel):" in with_context_around_user.matched_lines[0].line_content
|
| 101 |
+
assert with_context_around_user.num_matched_lines == 1
|
| 102 |
+
assert " User model representing a system user." in with_context_around_user.lines[4].line_content
|
| 103 |
+
# Check line numbers
|
| 104 |
+
assert with_context_around_user.lines[0].line_number == 29
|
| 105 |
+
assert with_context_around_user.lines[1].line_number == 30
|
| 106 |
+
assert with_context_around_user.lines[2].line_number == 31
|
| 107 |
+
assert with_context_around_user.lines[3].line_number == 32
|
| 108 |
+
assert with_context_around_user.lines[4].line_number == 33
|
| 109 |
+
# Check match types
|
| 110 |
+
assert with_context_around_user.lines[0].match_type == LineType.BEFORE_MATCH
|
| 111 |
+
assert with_context_around_user.lines[1].match_type == LineType.BEFORE_MATCH
|
| 112 |
+
assert with_context_around_user.lines[2].match_type == LineType.MATCH
|
| 113 |
+
assert with_context_around_user.lines[3].match_type == LineType.AFTER_MATCH
|
| 114 |
+
assert with_context_around_user.lines[4].match_type == LineType.AFTER_MATCH
|
| 115 |
+
|
| 116 |
+
# Scenario 3a: Only context above
|
| 117 |
+
with_context_above = project.retrieve_content_around_line(file_path, 31, 3, 0)
|
| 118 |
+
assert len(with_context_above.lines) == 4
|
| 119 |
+
assert "return cls(id=id, name=name)" in with_context_above.lines[0].line_content
|
| 120 |
+
assert "class User(BaseModel):" in with_context_above.matched_lines[0].line_content
|
| 121 |
+
assert with_context_above.num_matched_lines == 1
|
| 122 |
+
# Check line numbers
|
| 123 |
+
assert with_context_above.lines[0].line_number == 28
|
| 124 |
+
assert with_context_above.lines[1].line_number == 29
|
| 125 |
+
assert with_context_above.lines[2].line_number == 30
|
| 126 |
+
assert with_context_above.lines[3].line_number == 31
|
| 127 |
+
# Check match types
|
| 128 |
+
assert with_context_above.lines[0].match_type == LineType.BEFORE_MATCH
|
| 129 |
+
assert with_context_above.lines[1].match_type == LineType.BEFORE_MATCH
|
| 130 |
+
assert with_context_above.lines[2].match_type == LineType.BEFORE_MATCH
|
| 131 |
+
assert with_context_above.lines[3].match_type == LineType.MATCH
|
| 132 |
+
|
| 133 |
+
# Scenario 3b: Only context below
|
| 134 |
+
with_context_below = project.retrieve_content_around_line(file_path, 31, 0, 3)
|
| 135 |
+
assert len(with_context_below.lines) == 4
|
| 136 |
+
assert "class User(BaseModel):" in with_context_below.matched_lines[0].line_content
|
| 137 |
+
assert with_context_below.num_matched_lines == 1
|
| 138 |
+
assert with_context_below.lines[0].line_number == 31
|
| 139 |
+
assert with_context_below.lines[1].line_number == 32
|
| 140 |
+
assert with_context_below.lines[2].line_number == 33
|
| 141 |
+
assert with_context_below.lines[3].line_number == 34
|
| 142 |
+
# Check match types
|
| 143 |
+
assert with_context_below.lines[0].match_type == LineType.MATCH
|
| 144 |
+
assert with_context_below.lines[1].match_type == LineType.AFTER_MATCH
|
| 145 |
+
assert with_context_below.lines[2].match_type == LineType.AFTER_MATCH
|
| 146 |
+
assert with_context_below.lines[3].match_type == LineType.AFTER_MATCH
|
| 147 |
+
|
| 148 |
+
# Scenario 4a: Edge case - context above but line is at 0
|
| 149 |
+
first_line_with_context_around = project.retrieve_content_around_line(file_path, 0, 2, 1)
|
| 150 |
+
assert len(first_line_with_context_around.lines) <= 4 # Should have at most 4 lines (line 0 + 1 below + up to 2 above)
|
| 151 |
+
assert first_line_with_context_around.lines[0].line_number <= 2 # First line should be at most line 2
|
| 152 |
+
# Check match type for the target line
|
| 153 |
+
for line in first_line_with_context_around.lines:
|
| 154 |
+
if line.line_number == 0:
|
| 155 |
+
assert line.match_type == LineType.MATCH
|
| 156 |
+
elif line.line_number < 0:
|
| 157 |
+
assert line.match_type == LineType.BEFORE_MATCH
|
| 158 |
+
else:
|
| 159 |
+
assert line.match_type == LineType.AFTER_MATCH
|
| 160 |
+
|
| 161 |
+
# Scenario 4b: Edge case - context above but line is at 1
|
| 162 |
+
second_line_with_context_above = project.retrieve_content_around_line(file_path, 1, 3, 1)
|
| 163 |
+
assert len(second_line_with_context_above.lines) <= 5 # Should have at most 5 lines (line 1 + 1 below + up to 3 above)
|
| 164 |
+
assert second_line_with_context_above.lines[0].line_number <= 1 # First line should be at most line 1
|
| 165 |
+
# Check match type for the target line
|
| 166 |
+
for line in second_line_with_context_above.lines:
|
| 167 |
+
if line.line_number == 1:
|
| 168 |
+
assert line.match_type == LineType.MATCH
|
| 169 |
+
elif line.line_number < 1:
|
| 170 |
+
assert line.match_type == LineType.BEFORE_MATCH
|
| 171 |
+
else:
|
| 172 |
+
assert line.match_type == LineType.AFTER_MATCH
|
| 173 |
+
|
| 174 |
+
# Scenario 4c: Edge case - context below but line is at the end of file
|
| 175 |
+
# First get the total number of lines in the file
|
| 176 |
+
all_content = project.read_file(file_path)
|
| 177 |
+
total_lines = len(all_content.split("\n"))
|
| 178 |
+
|
| 179 |
+
last_line_with_context_around = project.retrieve_content_around_line(file_path, total_lines - 1, 1, 3)
|
| 180 |
+
assert len(last_line_with_context_around.lines) <= 5 # Should have at most 5 lines (last line + 1 above + up to 3 below)
|
| 181 |
+
assert last_line_with_context_around.lines[-1].line_number >= total_lines - 4 # Last line should be at least total_lines - 4
|
| 182 |
+
# Check match type for the target line
|
| 183 |
+
for line in last_line_with_context_around.lines:
|
| 184 |
+
if line.line_number == total_lines - 1:
|
| 185 |
+
assert line.match_type == LineType.MATCH
|
| 186 |
+
elif line.line_number < total_lines - 1:
|
| 187 |
+
assert line.match_type == LineType.BEFORE_MATCH
|
| 188 |
+
else:
|
| 189 |
+
assert line.match_type == LineType.AFTER_MATCH
|
| 190 |
+
|
| 191 |
+
@pytest.mark.parametrize("project", [Language.PYTHON], indirect=True)
|
| 192 |
+
def test_search_files_for_pattern(self, project: Project) -> None:
|
| 193 |
+
"""Test search_files_for_pattern with various patterns and glob filters."""
|
| 194 |
+
# Test 1: Search for class definitions across all files
|
| 195 |
+
class_pattern = r"class\s+\w+\s*(?:\([^{]*\)|:)"
|
| 196 |
+
matches = project.search_source_files_for_pattern(class_pattern)
|
| 197 |
+
assert len(matches) > 0
|
| 198 |
+
# Should find multiple classes like User, Item, BaseModel, etc.
|
| 199 |
+
assert len(matches) >= 5
|
| 200 |
+
|
| 201 |
+
# Test 2: Search for specific class with include glob
|
| 202 |
+
user_class_pattern = r"class\s+User\s*(?:\([^{]*\)|:)"
|
| 203 |
+
matches = project.search_source_files_for_pattern(user_class_pattern, paths_include_glob="**/models.py")
|
| 204 |
+
assert len(matches) == 1 # Should only find User class in models.py
|
| 205 |
+
assert matches[0].source_file_path is not None
|
| 206 |
+
assert "models.py" in matches[0].source_file_path
|
| 207 |
+
|
| 208 |
+
# Test 3: Search for method definitions with exclude glob
|
| 209 |
+
method_pattern = r"def\s+\w+\s*\([^)]*\):"
|
| 210 |
+
matches = project.search_source_files_for_pattern(method_pattern, paths_exclude_glob="**/models.py")
|
| 211 |
+
assert len(matches) > 0
|
| 212 |
+
# Should find methods in services.py but not in models.py
|
| 213 |
+
assert all(match.source_file_path is not None and "models.py" not in match.source_file_path for match in matches)
|
| 214 |
+
|
| 215 |
+
# Test 4: Search for specific method with both include and exclude globs
|
| 216 |
+
create_user_pattern = r"def\s+create_user\s*\([^)]*\)(?:\s*->[^:]+)?:"
|
| 217 |
+
matches = project.search_source_files_for_pattern(
|
| 218 |
+
create_user_pattern, paths_include_glob="**/*.py", paths_exclude_glob="**/models.py"
|
| 219 |
+
)
|
| 220 |
+
assert len(matches) == 1 # Should only find create_user in services.py
|
| 221 |
+
assert matches[0].source_file_path is not None
|
| 222 |
+
assert "services.py" in matches[0].source_file_path
|
| 223 |
+
|
| 224 |
+
# Test 5: Search for a pattern that should appear in multiple files
|
| 225 |
+
init_pattern = r"def\s+__init__\s*\([^)]*\):"
|
| 226 |
+
matches = project.search_source_files_for_pattern(init_pattern)
|
| 227 |
+
assert len(matches) > 1 # Should find __init__ in multiple classes
|
| 228 |
+
# Should find __init__ in both models.py and services.py
|
| 229 |
+
assert any(match.source_file_path is not None and "models.py" in match.source_file_path for match in matches)
|
| 230 |
+
assert any(match.source_file_path is not None and "services.py" in match.source_file_path for match in matches)
|
| 231 |
+
|
| 232 |
+
# Test 6: Search with a pattern that should have no matches
|
| 233 |
+
no_match_pattern = r"def\s+this_method_does_not_exist\s*\([^)]*\):"
|
| 234 |
+
matches = project.search_source_files_for_pattern(no_match_pattern)
|
| 235 |
+
assert len(matches) == 0
|
projects/ui/serena-new/test/solidlsp/python/test_retrieval_with_ignored_dirs.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Generator
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
from solidlsp import SolidLanguageServer
|
| 7 |
+
from solidlsp.ls_config import Language
|
| 8 |
+
from test.conftest import create_ls
|
| 9 |
+
|
| 10 |
+
# This mark will be applied to all tests in this module
|
| 11 |
+
pytestmark = pytest.mark.python
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@pytest.fixture(scope="module")
|
| 15 |
+
def ls_with_ignored_dirs() -> Generator[SolidLanguageServer, None, None]:
|
| 16 |
+
"""Fixture to set up an LS for the python test repo with the 'scripts' directory ignored."""
|
| 17 |
+
ignored_paths = ["scripts", "custom_test"]
|
| 18 |
+
ls = create_ls(ignored_paths=ignored_paths, language=Language.PYTHON)
|
| 19 |
+
ls.start()
|
| 20 |
+
try:
|
| 21 |
+
yield ls
|
| 22 |
+
finally:
|
| 23 |
+
ls.stop()
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@pytest.mark.parametrize("ls_with_ignored_dirs", [Language.PYTHON], indirect=True)
|
| 27 |
+
def test_symbol_tree_ignores_dir(ls_with_ignored_dirs: SolidLanguageServer):
|
| 28 |
+
"""Tests that request_full_symbol_tree ignores the configured directory."""
|
| 29 |
+
root = ls_with_ignored_dirs.request_full_symbol_tree()[0]
|
| 30 |
+
root_children = root["children"]
|
| 31 |
+
children_names = {child["name"] for child in root_children}
|
| 32 |
+
assert children_names == {"test_repo", "examples"}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
@pytest.mark.parametrize("ls_with_ignored_dirs", [Language.PYTHON], indirect=True)
|
| 36 |
+
def test_find_references_ignores_dir(ls_with_ignored_dirs: SolidLanguageServer):
|
| 37 |
+
"""Tests that find_references ignores the configured directory."""
|
| 38 |
+
# Location of Item, which is referenced in scripts
|
| 39 |
+
definition_file = "test_repo/models.py"
|
| 40 |
+
definition_line = 56
|
| 41 |
+
definition_col = 6
|
| 42 |
+
|
| 43 |
+
references = ls_with_ignored_dirs.request_references(definition_file, definition_line, definition_col)
|
| 44 |
+
|
| 45 |
+
# assert that scripts does not appear in the references
|
| 46 |
+
assert not any("scripts" in ref["relativePath"] for ref in references)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
@pytest.mark.parametrize("repo_path", [Language.PYTHON], indirect=True)
|
| 50 |
+
def test_refs_and_symbols_with_glob_patterns(repo_path: Path) -> None:
|
| 51 |
+
"""Tests that refs and symbols with glob patterns are ignored."""
|
| 52 |
+
ignored_paths = ["*ipts", "custom_t*"]
|
| 53 |
+
ls = create_ls(ignored_paths=ignored_paths, repo_path=str(repo_path), language=Language.PYTHON)
|
| 54 |
+
ls.start()
|
| 55 |
+
# same as in the above tests
|
| 56 |
+
root = ls.request_full_symbol_tree()[0]
|
| 57 |
+
root_children = root["children"]
|
| 58 |
+
children_names = {child["name"] for child in root_children}
|
| 59 |
+
assert children_names == {"test_repo", "examples"}
|
| 60 |
+
|
| 61 |
+
# test that the refs and symbols with glob patterns are ignored
|
| 62 |
+
definition_file = "test_repo/models.py"
|
| 63 |
+
definition_line = 56
|
| 64 |
+
definition_col = 6
|
| 65 |
+
|
| 66 |
+
references = ls.request_references(definition_file, definition_line, definition_col)
|
| 67 |
+
assert not any("scripts" in ref["relativePath"] for ref in references)
|
projects/ui/serena-new/test/solidlsp/python/test_symbol_retrieval.py
ADDED
|
@@ -0,0 +1,472 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Tests for the language server symbol-related functionality.
|
| 3 |
+
|
| 4 |
+
These tests focus on the following methods:
|
| 5 |
+
- request_containing_symbol
|
| 6 |
+
- request_referencing_symbols
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
|
| 11 |
+
import pytest
|
| 12 |
+
|
| 13 |
+
from serena.symbol import LanguageServerSymbol
|
| 14 |
+
from solidlsp import SolidLanguageServer
|
| 15 |
+
from solidlsp.ls_config import Language
|
| 16 |
+
from solidlsp.ls_types import SymbolKind
|
| 17 |
+
|
| 18 |
+
pytestmark = pytest.mark.python
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class TestLanguageServerSymbols:
|
| 22 |
+
"""Test the language server's symbol-related functionality."""
|
| 23 |
+
|
| 24 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 25 |
+
def test_request_containing_symbol_function(self, language_server: SolidLanguageServer) -> None:
|
| 26 |
+
"""Test request_containing_symbol for a function."""
|
| 27 |
+
# Test for a position inside the create_user method
|
| 28 |
+
file_path = os.path.join("test_repo", "services.py")
|
| 29 |
+
# Line 17 is inside the create_user method body
|
| 30 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 17, 20, include_body=True)
|
| 31 |
+
|
| 32 |
+
# Verify that we found the containing symbol
|
| 33 |
+
assert containing_symbol is not None
|
| 34 |
+
assert containing_symbol["name"] == "create_user"
|
| 35 |
+
assert containing_symbol["kind"] == SymbolKind.Method
|
| 36 |
+
if "body" in containing_symbol:
|
| 37 |
+
assert containing_symbol["body"].strip().startswith("def create_user(self")
|
| 38 |
+
|
| 39 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 40 |
+
def test_references_to_variables(self, language_server: SolidLanguageServer) -> None:
|
| 41 |
+
"""Test request_referencing_symbols for a variable."""
|
| 42 |
+
file_path = os.path.join("test_repo", "variables.py")
|
| 43 |
+
# Line 75 contains the field status that is later modified
|
| 44 |
+
ref_symbols = [ref.symbol for ref in language_server.request_referencing_symbols(file_path, 74, 4)]
|
| 45 |
+
|
| 46 |
+
assert len(ref_symbols) > 0
|
| 47 |
+
ref_lines = [ref["location"]["range"]["start"]["line"] for ref in ref_symbols if "location" in ref and "range" in ref["location"]]
|
| 48 |
+
ref_names = [ref["name"] for ref in ref_symbols]
|
| 49 |
+
assert 87 in ref_lines
|
| 50 |
+
assert 95 in ref_lines
|
| 51 |
+
assert "dataclass_instance" in ref_names
|
| 52 |
+
assert "second_dataclass" in ref_names
|
| 53 |
+
|
| 54 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 55 |
+
def test_request_containing_symbol_class(self, language_server: SolidLanguageServer) -> None:
|
| 56 |
+
"""Test request_containing_symbol for a class."""
|
| 57 |
+
# Test for a position inside the UserService class but outside any method
|
| 58 |
+
file_path = os.path.join("test_repo", "services.py")
|
| 59 |
+
# Line 9 is the class definition line for UserService
|
| 60 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 9, 7)
|
| 61 |
+
|
| 62 |
+
# Verify that we found the containing symbol
|
| 63 |
+
assert containing_symbol is not None
|
| 64 |
+
assert containing_symbol["name"] == "UserService"
|
| 65 |
+
assert containing_symbol["kind"] == SymbolKind.Class
|
| 66 |
+
|
| 67 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 68 |
+
def test_request_containing_symbol_nested(self, language_server: SolidLanguageServer) -> None:
|
| 69 |
+
"""Test request_containing_symbol with nested scopes."""
|
| 70 |
+
# Test for a position inside a method which is inside a class
|
| 71 |
+
file_path = os.path.join("test_repo", "services.py")
|
| 72 |
+
# Line 18 is inside the create_user method inside UserService class
|
| 73 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 18, 25)
|
| 74 |
+
|
| 75 |
+
# Verify that we found the innermost containing symbol (the method)
|
| 76 |
+
assert containing_symbol is not None
|
| 77 |
+
assert containing_symbol["name"] == "create_user"
|
| 78 |
+
assert containing_symbol["kind"] == SymbolKind.Method
|
| 79 |
+
|
| 80 |
+
# Get the parent containing symbol
|
| 81 |
+
if "location" in containing_symbol and "range" in containing_symbol["location"]:
|
| 82 |
+
parent_symbol = language_server.request_containing_symbol(
|
| 83 |
+
file_path,
|
| 84 |
+
containing_symbol["location"]["range"]["start"]["line"],
|
| 85 |
+
containing_symbol["location"]["range"]["start"]["character"] - 1,
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
# Verify that the parent is the class
|
| 89 |
+
assert parent_symbol is not None
|
| 90 |
+
assert parent_symbol["name"] == "UserService"
|
| 91 |
+
assert parent_symbol["kind"] == SymbolKind.Class
|
| 92 |
+
|
| 93 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 94 |
+
def test_request_containing_symbol_none(self, language_server: SolidLanguageServer) -> None:
|
| 95 |
+
"""Test request_containing_symbol for a position with no containing symbol."""
|
| 96 |
+
# Test for a position outside any function/class (e.g., in imports)
|
| 97 |
+
file_path = os.path.join("test_repo", "services.py")
|
| 98 |
+
# Line 1 is in imports, not inside any function or class
|
| 99 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 1, 10)
|
| 100 |
+
|
| 101 |
+
# Should return None or an empty dictionary
|
| 102 |
+
assert containing_symbol is None or containing_symbol == {}
|
| 103 |
+
|
| 104 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 105 |
+
def test_request_referencing_symbols_function(self, language_server: SolidLanguageServer) -> None:
|
| 106 |
+
"""Test request_referencing_symbols for a function."""
|
| 107 |
+
# Test referencing symbols for create_user function
|
| 108 |
+
file_path = os.path.join("test_repo", "services.py")
|
| 109 |
+
# Line 15 contains the create_user function definition
|
| 110 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 111 |
+
create_user_symbol = next((s for s in symbols[0] if s.get("name") == "create_user"), None)
|
| 112 |
+
if not create_user_symbol or "selectionRange" not in create_user_symbol:
|
| 113 |
+
raise AssertionError("create_user symbol or its selectionRange not found")
|
| 114 |
+
sel_start = create_user_symbol["selectionRange"]["start"]
|
| 115 |
+
ref_symbols = [
|
| 116 |
+
ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start["line"], sel_start["character"])
|
| 117 |
+
]
|
| 118 |
+
assert len(ref_symbols) > 0, "No referencing symbols found for create_user (selectionRange)"
|
| 119 |
+
|
| 120 |
+
# Verify the structure of referencing symbols
|
| 121 |
+
for symbol in ref_symbols:
|
| 122 |
+
assert "name" in symbol
|
| 123 |
+
assert "kind" in symbol
|
| 124 |
+
if "location" in symbol and "range" in symbol["location"]:
|
| 125 |
+
assert "start" in symbol["location"]["range"]
|
| 126 |
+
assert "end" in symbol["location"]["range"]
|
| 127 |
+
|
| 128 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 129 |
+
def test_request_referencing_symbols_class(self, language_server: SolidLanguageServer) -> None:
|
| 130 |
+
"""Test request_referencing_symbols for a class."""
|
| 131 |
+
# Test referencing symbols for User class
|
| 132 |
+
file_path = os.path.join("test_repo", "models.py")
|
| 133 |
+
# Line 31 contains the User class definition
|
| 134 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 135 |
+
user_symbol = next((s for s in symbols[0] if s.get("name") == "User"), None)
|
| 136 |
+
if not user_symbol or "selectionRange" not in user_symbol:
|
| 137 |
+
raise AssertionError("User symbol or its selectionRange not found")
|
| 138 |
+
sel_start = user_symbol["selectionRange"]["start"]
|
| 139 |
+
ref_symbols = [
|
| 140 |
+
ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start["line"], sel_start["character"])
|
| 141 |
+
]
|
| 142 |
+
services_references = [
|
| 143 |
+
symbol
|
| 144 |
+
for symbol in ref_symbols
|
| 145 |
+
if "location" in symbol and "uri" in symbol["location"] and "services.py" in symbol["location"]["uri"]
|
| 146 |
+
]
|
| 147 |
+
assert len(services_references) > 0, "No referencing symbols from services.py for User (selectionRange)"
|
| 148 |
+
|
| 149 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 150 |
+
def test_request_referencing_symbols_parameter(self, language_server: SolidLanguageServer) -> None:
|
| 151 |
+
"""Test request_referencing_symbols for a function parameter."""
|
| 152 |
+
# Test referencing symbols for id parameter in get_user
|
| 153 |
+
file_path = os.path.join("test_repo", "services.py")
|
| 154 |
+
# Line 24 contains the get_user method with id parameter
|
| 155 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 156 |
+
get_user_symbol = next((s for s in symbols[0] if s.get("name") == "get_user"), None)
|
| 157 |
+
if not get_user_symbol or "selectionRange" not in get_user_symbol:
|
| 158 |
+
raise AssertionError("get_user symbol or its selectionRange not found")
|
| 159 |
+
sel_start = get_user_symbol["selectionRange"]["start"]
|
| 160 |
+
ref_symbols = [
|
| 161 |
+
ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start["line"], sel_start["character"])
|
| 162 |
+
]
|
| 163 |
+
method_refs = [
|
| 164 |
+
symbol
|
| 165 |
+
for symbol in ref_symbols
|
| 166 |
+
if "location" in symbol and "range" in symbol["location"] and symbol["location"]["range"]["start"]["line"] > sel_start["line"]
|
| 167 |
+
]
|
| 168 |
+
assert len(method_refs) > 0, "No referencing symbols within method body for get_user (selectionRange)"
|
| 169 |
+
|
| 170 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 171 |
+
def test_request_referencing_symbols_none(self, language_server: SolidLanguageServer) -> None:
|
| 172 |
+
"""Test request_referencing_symbols for a position with no symbol."""
|
| 173 |
+
# For positions with no symbol, the method might throw an error or return None/empty list
|
| 174 |
+
# We'll modify our test to handle this by using a try-except block
|
| 175 |
+
|
| 176 |
+
file_path = os.path.join("test_repo", "services.py")
|
| 177 |
+
# Line 3 is a blank line or comment
|
| 178 |
+
try:
|
| 179 |
+
ref_symbols = [ref.symbol for ref in language_server.request_referencing_symbols(file_path, 3, 0)]
|
| 180 |
+
# If we get here, make sure we got an empty result
|
| 181 |
+
assert ref_symbols == [] or ref_symbols is None
|
| 182 |
+
except Exception:
|
| 183 |
+
# The method might raise an exception for invalid positions
|
| 184 |
+
# which is acceptable behavior
|
| 185 |
+
pass
|
| 186 |
+
|
| 187 |
+
# Tests for request_defining_symbol
|
| 188 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 189 |
+
def test_request_defining_symbol_variable(self, language_server: SolidLanguageServer) -> None:
|
| 190 |
+
"""Test request_defining_symbol for a variable usage."""
|
| 191 |
+
# Test finding the definition of a symbol in the create_user method
|
| 192 |
+
file_path = os.path.join("test_repo", "services.py")
|
| 193 |
+
# Line 21 contains self.users[id] = user
|
| 194 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 21, 10)
|
| 195 |
+
|
| 196 |
+
# Verify that we found the defining symbol
|
| 197 |
+
# The defining symbol method returns a dictionary with information about the defining symbol
|
| 198 |
+
assert defining_symbol is not None
|
| 199 |
+
assert defining_symbol.get("name") == "create_user"
|
| 200 |
+
|
| 201 |
+
# Verify the location and kind of the symbol
|
| 202 |
+
# SymbolKind.Method = 6 for a method
|
| 203 |
+
assert defining_symbol.get("kind") == SymbolKind.Method.value
|
| 204 |
+
if "location" in defining_symbol and "uri" in defining_symbol["location"]:
|
| 205 |
+
assert "services.py" in defining_symbol["location"]["uri"]
|
| 206 |
+
|
| 207 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 208 |
+
def test_request_defining_symbol_imported_class(self, language_server: SolidLanguageServer) -> None:
|
| 209 |
+
"""Test request_defining_symbol for an imported class."""
|
| 210 |
+
# Test finding the definition of the 'User' class used in the UserService.create_user method
|
| 211 |
+
file_path = os.path.join("test_repo", "services.py")
|
| 212 |
+
# Line 20 references 'User' which was imported from models
|
| 213 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 20, 15)
|
| 214 |
+
|
| 215 |
+
# Verify that we found the defining symbol - this should be the User class from models
|
| 216 |
+
assert defining_symbol is not None
|
| 217 |
+
assert defining_symbol.get("name") == "User"
|
| 218 |
+
|
| 219 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 220 |
+
def test_request_defining_symbol_method_call(self, language_server: SolidLanguageServer) -> None:
|
| 221 |
+
"""Test request_defining_symbol for a method call."""
|
| 222 |
+
# Create an example file path for a file that calls UserService.create_user
|
| 223 |
+
examples_file_path = os.path.join("examples", "user_management.py")
|
| 224 |
+
|
| 225 |
+
# Find the line number where create_user is called
|
| 226 |
+
# This could vary, so we'll use a relative position that makes sense
|
| 227 |
+
defining_symbol = language_server.request_defining_symbol(examples_file_path, 10, 30)
|
| 228 |
+
|
| 229 |
+
# Verify that we found the defining symbol - should be the create_user method
|
| 230 |
+
# Because this might fail if the structure isn't exactly as expected, we'll use try-except
|
| 231 |
+
try:
|
| 232 |
+
assert defining_symbol is not None
|
| 233 |
+
assert defining_symbol.get("name") == "create_user"
|
| 234 |
+
# The defining symbol should be in the services.py file
|
| 235 |
+
if "location" in defining_symbol and "uri" in defining_symbol["location"]:
|
| 236 |
+
assert "services.py" in defining_symbol["location"]["uri"]
|
| 237 |
+
except AssertionError:
|
| 238 |
+
# If the file structure doesn't match what we expect, we can't guarantee this test
|
| 239 |
+
# will pass, so we'll consider it a warning rather than a failure
|
| 240 |
+
import warnings
|
| 241 |
+
|
| 242 |
+
warnings.warn("Could not verify method call definition - file structure may differ from expected")
|
| 243 |
+
|
| 244 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 245 |
+
def test_request_defining_symbol_none(self, language_server: SolidLanguageServer) -> None:
|
| 246 |
+
"""Test request_defining_symbol for a position with no symbol."""
|
| 247 |
+
# Test for a position with no symbol (e.g., whitespace or comment)
|
| 248 |
+
file_path = os.path.join("test_repo", "services.py")
|
| 249 |
+
# Line 3 is a blank line
|
| 250 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 3, 0)
|
| 251 |
+
|
| 252 |
+
# Should return None for positions with no symbol
|
| 253 |
+
assert defining_symbol is None
|
| 254 |
+
|
| 255 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 256 |
+
def test_request_containing_symbol_variable(self, language_server: SolidLanguageServer) -> None:
|
| 257 |
+
"""Test request_containing_symbol where the symbol is a variable."""
|
| 258 |
+
# Test for a position inside a variable definition
|
| 259 |
+
file_path = os.path.join("test_repo", "services.py")
|
| 260 |
+
# Line 74 defines the 'user' variable
|
| 261 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 73, 1)
|
| 262 |
+
|
| 263 |
+
# Verify that we found the containing symbol
|
| 264 |
+
assert containing_symbol is not None
|
| 265 |
+
assert containing_symbol["name"] == "user_var_str"
|
| 266 |
+
assert containing_symbol["kind"] == SymbolKind.Variable
|
| 267 |
+
|
| 268 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 269 |
+
def test_request_defining_symbol_nested_function(self, language_server: SolidLanguageServer) -> None:
|
| 270 |
+
"""Test request_defining_symbol for a nested function or closure."""
|
| 271 |
+
# Use the existing nested.py file which contains nested classes and methods
|
| 272 |
+
file_path = os.path.join("test_repo", "nested.py")
|
| 273 |
+
|
| 274 |
+
# Test 1: Find definition of nested method - line with 'b = OuterClass().NestedClass().find_me()'
|
| 275 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 15, 35) # Position of find_me() call
|
| 276 |
+
|
| 277 |
+
# This should resolve to the find_me method in the NestedClass
|
| 278 |
+
assert defining_symbol is not None
|
| 279 |
+
assert defining_symbol.get("name") == "find_me"
|
| 280 |
+
assert defining_symbol.get("kind") == SymbolKind.Method.value
|
| 281 |
+
|
| 282 |
+
# Test 2: Find definition of the nested class
|
| 283 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 15, 18) # Position of NestedClass
|
| 284 |
+
|
| 285 |
+
# This should resolve to the NestedClass
|
| 286 |
+
assert defining_symbol is not None
|
| 287 |
+
assert defining_symbol.get("name") == "NestedClass"
|
| 288 |
+
assert defining_symbol.get("kind") == SymbolKind.Class.value
|
| 289 |
+
|
| 290 |
+
# Test 3: Find definition of a method-local function
|
| 291 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 9, 15) # Position inside func_within_func
|
| 292 |
+
|
| 293 |
+
# This is challenging for many language servers and may fail
|
| 294 |
+
try:
|
| 295 |
+
assert defining_symbol is not None
|
| 296 |
+
assert defining_symbol.get("name") == "func_within_func"
|
| 297 |
+
except (AssertionError, TypeError, KeyError):
|
| 298 |
+
# This is expected to potentially fail in many implementations
|
| 299 |
+
import warnings
|
| 300 |
+
|
| 301 |
+
warnings.warn("Could not resolve nested class method definition - implementation limitation")
|
| 302 |
+
|
| 303 |
+
# Test 2: Find definition of the nested class
|
| 304 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 15, 18) # Position of NestedClass
|
| 305 |
+
|
| 306 |
+
# This should resolve to the NestedClass
|
| 307 |
+
assert defining_symbol is not None
|
| 308 |
+
assert defining_symbol.get("name") == "NestedClass"
|
| 309 |
+
assert defining_symbol.get("kind") == SymbolKind.Class.value
|
| 310 |
+
|
| 311 |
+
# Test 3: Find definition of a method-local function
|
| 312 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 9, 15) # Position inside func_within_func
|
| 313 |
+
|
| 314 |
+
# This is challenging for many language servers and may fail
|
| 315 |
+
assert defining_symbol is not None
|
| 316 |
+
assert defining_symbol.get("name") == "func_within_func"
|
| 317 |
+
assert defining_symbol.get("kind") == SymbolKind.Function.value
|
| 318 |
+
|
| 319 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 320 |
+
def test_symbol_methods_integration(self, language_server: SolidLanguageServer) -> None:
|
| 321 |
+
"""Test the integration between different symbol-related methods."""
|
| 322 |
+
# This test demonstrates using the various symbol methods together
|
| 323 |
+
# by finding a symbol and then checking its definition
|
| 324 |
+
|
| 325 |
+
file_path = os.path.join("test_repo", "services.py")
|
| 326 |
+
|
| 327 |
+
# First approach: Use a method from the UserService class
|
| 328 |
+
# Step 1: Find a method we know exists
|
| 329 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 15, 8) # create_user method
|
| 330 |
+
assert containing_symbol is not None
|
| 331 |
+
assert containing_symbol["name"] == "create_user"
|
| 332 |
+
|
| 333 |
+
# Step 2: Get the defining symbol for the same position
|
| 334 |
+
# This should be the same method
|
| 335 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 15, 8)
|
| 336 |
+
assert defining_symbol is not None
|
| 337 |
+
assert defining_symbol["name"] == "create_user"
|
| 338 |
+
|
| 339 |
+
# Step 3: Verify that they refer to the same symbol
|
| 340 |
+
assert defining_symbol["kind"] == containing_symbol["kind"]
|
| 341 |
+
if "location" in defining_symbol and "location" in containing_symbol:
|
| 342 |
+
assert defining_symbol["location"]["uri"] == containing_symbol["location"]["uri"]
|
| 343 |
+
|
| 344 |
+
# The integration test is successful if we've gotten this far,
|
| 345 |
+
# as it demonstrates the integration between request_containing_symbol and request_defining_symbol
|
| 346 |
+
|
| 347 |
+
# Try to get the container information for our method, but be flexible
|
| 348 |
+
# since implementations may vary
|
| 349 |
+
container_name = defining_symbol.get("containerName", None)
|
| 350 |
+
if container_name and "UserService" in container_name:
|
| 351 |
+
# If containerName contains UserService, that's a valid implementation
|
| 352 |
+
pass
|
| 353 |
+
else:
|
| 354 |
+
# Try an alternative approach - looking for the containing class
|
| 355 |
+
try:
|
| 356 |
+
# Look for the class symbol in the file
|
| 357 |
+
for line in range(5, 12): # Approximate range where UserService class should be defined
|
| 358 |
+
symbol = language_server.request_containing_symbol(file_path, line, 5) # column 5 should be within class definition
|
| 359 |
+
if symbol and symbol.get("name") == "UserService" and symbol.get("kind") == SymbolKind.Class.value:
|
| 360 |
+
# Found the class - this is also a valid implementation
|
| 361 |
+
break
|
| 362 |
+
except Exception:
|
| 363 |
+
# Just log a warning - this is an alternative verification and not essential
|
| 364 |
+
import warnings
|
| 365 |
+
|
| 366 |
+
warnings.warn("Could not verify container hierarchy - implementation detail")
|
| 367 |
+
|
| 368 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 369 |
+
def test_symbol_tree_structure(self, language_server: SolidLanguageServer) -> None:
|
| 370 |
+
"""Test that the symbol tree structure is correctly built."""
|
| 371 |
+
# Get all symbols in the test file
|
| 372 |
+
repo_structure = language_server.request_full_symbol_tree()
|
| 373 |
+
assert len(repo_structure) == 1
|
| 374 |
+
# Assert that the root symbol is the test_repo directory
|
| 375 |
+
assert repo_structure[0]["name"] == "test_repo"
|
| 376 |
+
assert repo_structure[0]["kind"] == SymbolKind.Package
|
| 377 |
+
assert "children" in repo_structure[0]
|
| 378 |
+
# Assert that the children are the top-level packages
|
| 379 |
+
child_names = {child["name"] for child in repo_structure[0]["children"]}
|
| 380 |
+
child_kinds = {child["kind"] for child in repo_structure[0]["children"]}
|
| 381 |
+
assert child_names == {"test_repo", "custom_test", "examples", "scripts"}
|
| 382 |
+
assert child_kinds == {SymbolKind.Package}
|
| 383 |
+
examples_package = next(child for child in repo_structure[0]["children"] if child["name"] == "examples")
|
| 384 |
+
# assert that children are __init__ and user_management
|
| 385 |
+
assert {child["name"] for child in examples_package["children"]} == {"__init__", "user_management"}
|
| 386 |
+
assert {child["kind"] for child in examples_package["children"]} == {SymbolKind.File}
|
| 387 |
+
|
| 388 |
+
# assert that tree of user_management node is same as retrieved directly
|
| 389 |
+
user_management_node = next(child for child in examples_package["children"] if child["name"] == "user_management")
|
| 390 |
+
if "location" in user_management_node and "relativePath" in user_management_node["location"]:
|
| 391 |
+
user_management_rel_path = user_management_node["location"]["relativePath"]
|
| 392 |
+
assert user_management_rel_path == os.path.join("examples", "user_management.py")
|
| 393 |
+
_, user_management_roots = language_server.request_document_symbols(os.path.join("examples", "user_management.py"))
|
| 394 |
+
assert user_management_roots == user_management_node["children"]
|
| 395 |
+
|
| 396 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 397 |
+
def test_symbol_tree_structure_subdir(self, language_server: SolidLanguageServer) -> None:
|
| 398 |
+
"""Test that the symbol tree structure is correctly built."""
|
| 399 |
+
# Get all symbols in the test file
|
| 400 |
+
examples_package_roots = language_server.request_full_symbol_tree(within_relative_path="examples")
|
| 401 |
+
assert len(examples_package_roots) == 1
|
| 402 |
+
examples_package = examples_package_roots[0]
|
| 403 |
+
assert examples_package["name"] == "examples"
|
| 404 |
+
assert examples_package["kind"] == SymbolKind.Package
|
| 405 |
+
# assert that children are __init__ and user_management
|
| 406 |
+
assert {child["name"] for child in examples_package["children"]} == {"__init__", "user_management"}
|
| 407 |
+
assert {child["kind"] for child in examples_package["children"]} == {SymbolKind.File}
|
| 408 |
+
|
| 409 |
+
# assert that tree of user_management node is same as retrieved directly
|
| 410 |
+
user_management_node = next(child for child in examples_package["children"] if child["name"] == "user_management")
|
| 411 |
+
if "location" in user_management_node and "relativePath" in user_management_node["location"]:
|
| 412 |
+
user_management_rel_path = user_management_node["location"]["relativePath"]
|
| 413 |
+
assert user_management_rel_path == os.path.join("examples", "user_management.py")
|
| 414 |
+
_, user_management_roots = language_server.request_document_symbols(os.path.join("examples", "user_management.py"))
|
| 415 |
+
assert user_management_roots == user_management_node["children"]
|
| 416 |
+
|
| 417 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 418 |
+
def test_request_dir_overview(self, language_server: SolidLanguageServer) -> None:
|
| 419 |
+
"""Test that request_dir_overview returns correct symbol information for files in a directory."""
|
| 420 |
+
# Get overview of the examples directory
|
| 421 |
+
overview = language_server.request_dir_overview("test_repo")
|
| 422 |
+
|
| 423 |
+
# Verify that we have entries for both files
|
| 424 |
+
assert os.path.join("test_repo", "nested.py") in overview
|
| 425 |
+
|
| 426 |
+
# Get the symbols for user_management.py
|
| 427 |
+
services_symbols = overview[os.path.join("test_repo", "services.py")]
|
| 428 |
+
assert len(services_symbols) > 0
|
| 429 |
+
|
| 430 |
+
# Check for specific symbols from services.py
|
| 431 |
+
expected_symbols = {
|
| 432 |
+
"UserService",
|
| 433 |
+
"ItemService",
|
| 434 |
+
"create_service_container",
|
| 435 |
+
"user_var_str",
|
| 436 |
+
"user_service",
|
| 437 |
+
}
|
| 438 |
+
retrieved_symbols = {symbol["name"] for symbol in services_symbols if "name" in symbol}
|
| 439 |
+
assert expected_symbols.issubset(retrieved_symbols)
|
| 440 |
+
|
| 441 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 442 |
+
def test_request_document_overview(self, language_server: SolidLanguageServer) -> None:
|
| 443 |
+
"""Test that request_document_overview returns correct symbol information for a file."""
|
| 444 |
+
# Get overview of the user_management.py file
|
| 445 |
+
overview = language_server.request_document_overview(os.path.join("examples", "user_management.py"))
|
| 446 |
+
|
| 447 |
+
# Verify that we have entries for both files
|
| 448 |
+
symbol_names = {LanguageServerSymbol(s_info).name for s_info in overview}
|
| 449 |
+
assert {"UserStats", "UserManager", "process_user_data", "main"}.issubset(symbol_names)
|
| 450 |
+
|
| 451 |
+
@pytest.mark.parametrize("language_server", [Language.PYTHON], indirect=True)
|
| 452 |
+
def test_containing_symbol_of_var_is_file(self, language_server: SolidLanguageServer) -> None:
|
| 453 |
+
"""Test that the containing symbol of a variable is the file itself."""
|
| 454 |
+
# Get the containing symbol of a variable in a file
|
| 455 |
+
file_path = os.path.join("test_repo", "services.py")
|
| 456 |
+
# import of typing
|
| 457 |
+
references_to_typing = [
|
| 458 |
+
ref.symbol
|
| 459 |
+
for ref in language_server.request_referencing_symbols(file_path, 4, 6, include_imports=False, include_file_symbols=True)
|
| 460 |
+
]
|
| 461 |
+
assert {ref["kind"] for ref in references_to_typing} == {SymbolKind.File}
|
| 462 |
+
assert {ref["body"] for ref in references_to_typing} == {""}
|
| 463 |
+
|
| 464 |
+
# now include bodies
|
| 465 |
+
references_to_typing = [
|
| 466 |
+
ref.symbol
|
| 467 |
+
for ref in language_server.request_referencing_symbols(
|
| 468 |
+
file_path, 4, 6, include_imports=False, include_file_symbols=True, include_body=True
|
| 469 |
+
)
|
| 470 |
+
]
|
| 471 |
+
assert {ref["kind"] for ref in references_to_typing} == {SymbolKind.File}
|
| 472 |
+
assert references_to_typing[0]["body"]
|
projects/ui/serena-new/test/solidlsp/r/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Empty init file for R tests
|
projects/ui/serena-new/test/solidlsp/r/test_r_basic.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Basic tests for R Language Server integration
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
import pytest
|
| 9 |
+
|
| 10 |
+
from solidlsp import SolidLanguageServer
|
| 11 |
+
from solidlsp.ls_config import Language
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@pytest.mark.r
|
| 15 |
+
class TestRLanguageServer:
|
| 16 |
+
"""Test basic functionality of the R language server."""
|
| 17 |
+
|
| 18 |
+
@pytest.mark.parametrize("language_server", [Language.R], indirect=True)
|
| 19 |
+
@pytest.mark.parametrize("repo_path", [Language.R], indirect=True)
|
| 20 |
+
def test_server_initialization(self, language_server: SolidLanguageServer, repo_path: Path):
|
| 21 |
+
"""Test that the R language server initializes properly."""
|
| 22 |
+
assert language_server is not None
|
| 23 |
+
assert language_server.language_id == "r"
|
| 24 |
+
assert language_server.is_running()
|
| 25 |
+
assert Path(language_server.language_server.repository_root_path).resolve() == repo_path.resolve()
|
| 26 |
+
|
| 27 |
+
@pytest.mark.parametrize("language_server", [Language.R], indirect=True)
|
| 28 |
+
def test_symbol_retrieval(self, language_server: SolidLanguageServer):
|
| 29 |
+
"""Test R document symbol extraction."""
|
| 30 |
+
all_symbols, root_symbols = language_server.request_document_symbols(os.path.join("R", "utils.R"))
|
| 31 |
+
|
| 32 |
+
# Should find the three exported functions
|
| 33 |
+
function_symbols = [s for s in all_symbols if s.get("kind") == 12] # Function kind
|
| 34 |
+
assert len(function_symbols) >= 3
|
| 35 |
+
|
| 36 |
+
# Check that we found the expected functions
|
| 37 |
+
function_names = {s.get("name") for s in function_symbols}
|
| 38 |
+
expected_functions = {"calculate_mean", "process_data", "create_data_frame"}
|
| 39 |
+
assert expected_functions.issubset(function_names), f"Expected functions {expected_functions} but found {function_names}"
|
| 40 |
+
|
| 41 |
+
@pytest.mark.parametrize("language_server", [Language.R], indirect=True)
|
| 42 |
+
def test_find_definition_across_files(self, language_server: SolidLanguageServer):
|
| 43 |
+
"""Test finding function definitions across files."""
|
| 44 |
+
analysis_file = os.path.join("examples", "analysis.R")
|
| 45 |
+
|
| 46 |
+
# In analysis.R line 7: create_data_frame(n = 50)
|
| 47 |
+
# The function create_data_frame is defined in R/utils.R
|
| 48 |
+
# Find definition of create_data_frame function call (0-indexed: line 6)
|
| 49 |
+
definition_location_list = language_server.request_definition(analysis_file, 6, 17) # cursor on 'create_data_frame'
|
| 50 |
+
|
| 51 |
+
assert definition_location_list, f"Expected non-empty definition_location_list but got {definition_location_list=}"
|
| 52 |
+
assert len(definition_location_list) >= 1
|
| 53 |
+
definition_location = definition_location_list[0]
|
| 54 |
+
assert definition_location["uri"].endswith("utils.R")
|
| 55 |
+
# Definition should be around line 37 (0-indexed: 36) where create_data_frame is defined
|
| 56 |
+
assert definition_location["range"]["start"]["line"] >= 35
|
| 57 |
+
|
| 58 |
+
@pytest.mark.parametrize("language_server", [Language.R], indirect=True)
|
| 59 |
+
def test_find_references_across_files(self, language_server: SolidLanguageServer):
|
| 60 |
+
"""Test finding function references across files."""
|
| 61 |
+
analysis_file = os.path.join("examples", "analysis.R")
|
| 62 |
+
|
| 63 |
+
# Test from usage side: find references to calculate_mean from its usage in analysis.R
|
| 64 |
+
# In analysis.R line 13: calculate_mean(clean_data$value)
|
| 65 |
+
# calculate_mean function call is at line 13 (0-indexed: line 12)
|
| 66 |
+
references = language_server.request_references(analysis_file, 12, 15) # cursor on 'calculate_mean'
|
| 67 |
+
|
| 68 |
+
assert references, f"Expected non-empty references for calculate_mean but got {references=}"
|
| 69 |
+
|
| 70 |
+
# Must find the definition in utils.R (cross-file reference)
|
| 71 |
+
reference_files = [ref["uri"] for ref in references]
|
| 72 |
+
assert any(uri.endswith("utils.R") for uri in reference_files), "Cross-file reference to definition in utils.R not found"
|
| 73 |
+
|
| 74 |
+
# Verify we actually found the right location in utils.R
|
| 75 |
+
utils_refs = [ref for ref in references if ref["uri"].endswith("utils.R")]
|
| 76 |
+
assert len(utils_refs) >= 1, "Should find at least one reference in utils.R"
|
| 77 |
+
utils_ref = utils_refs[0]
|
| 78 |
+
# Should be around line 6 where calculate_mean is defined (0-indexed: line 5)
|
| 79 |
+
assert (
|
| 80 |
+
utils_ref["range"]["start"]["line"] == 5
|
| 81 |
+
), f"Expected reference at line 5 in utils.R, got line {utils_ref['range']['start']['line']}"
|
| 82 |
+
|
| 83 |
+
def test_file_matching(self):
|
| 84 |
+
"""Test that R files are properly matched."""
|
| 85 |
+
from solidlsp.ls_config import Language
|
| 86 |
+
|
| 87 |
+
matcher = Language.R.get_source_fn_matcher()
|
| 88 |
+
|
| 89 |
+
assert matcher.is_relevant_filename("script.R")
|
| 90 |
+
assert matcher.is_relevant_filename("analysis.r")
|
| 91 |
+
assert not matcher.is_relevant_filename("script.py")
|
| 92 |
+
assert not matcher.is_relevant_filename("README.md")
|
| 93 |
+
|
| 94 |
+
def test_r_language_enum(self):
|
| 95 |
+
"""Test R language enum value."""
|
| 96 |
+
assert Language.R == "r"
|
| 97 |
+
assert str(Language.R) == "r"
|
projects/ui/serena-new/test/solidlsp/ruby/test_ruby_basic.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
from solidlsp import SolidLanguageServer
|
| 7 |
+
from solidlsp.ls_config import Language
|
| 8 |
+
from solidlsp.ls_utils import SymbolUtils
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@pytest.mark.ruby
|
| 12 |
+
class TestRubyLanguageServer:
|
| 13 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 14 |
+
def test_find_symbol(self, language_server: SolidLanguageServer) -> None:
|
| 15 |
+
symbols = language_server.request_full_symbol_tree()
|
| 16 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "DemoClass"), "DemoClass not found in symbol tree"
|
| 17 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "helper_function"), "helper_function not found in symbol tree"
|
| 18 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "print_value"), "print_value not found in symbol tree"
|
| 19 |
+
|
| 20 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 21 |
+
def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:
|
| 22 |
+
file_path = os.path.join("main.rb")
|
| 23 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 24 |
+
helper_symbol = None
|
| 25 |
+
for sym in symbols[0]:
|
| 26 |
+
if sym.get("name") == "helper_function":
|
| 27 |
+
helper_symbol = sym
|
| 28 |
+
break
|
| 29 |
+
print(helper_symbol)
|
| 30 |
+
assert helper_symbol is not None, "Could not find 'helper_function' symbol in main.rb"
|
| 31 |
+
|
| 32 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 33 |
+
@pytest.mark.parametrize("repo_path", [Language.RUBY], indirect=True)
|
| 34 |
+
def test_find_definition_across_files(self, language_server: SolidLanguageServer, repo_path: Path) -> None:
|
| 35 |
+
# Test finding Calculator.add method definition from line 17: Calculator.new.add(demo.value, 10)
|
| 36 |
+
definition_location_list = language_server.request_definition(
|
| 37 |
+
str(repo_path / "main.rb"), 16, 17
|
| 38 |
+
) # add method at line 17 (0-indexed 16), position 17
|
| 39 |
+
|
| 40 |
+
assert len(definition_location_list) == 1
|
| 41 |
+
definition_location = definition_location_list[0]
|
| 42 |
+
print(f"Found definition: {definition_location}")
|
| 43 |
+
assert definition_location["uri"].endswith("lib.rb")
|
| 44 |
+
assert definition_location["range"]["start"]["line"] == 1 # add method on line 2 (0-indexed 1)
|
projects/ui/serena-new/test/solidlsp/ruby/test_ruby_symbol_retrieval.py
ADDED
|
@@ -0,0 +1,625 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Tests for the Ruby language server symbol-related functionality.
|
| 3 |
+
|
| 4 |
+
These tests focus on the following methods:
|
| 5 |
+
- request_containing_symbol
|
| 6 |
+
- request_referencing_symbols
|
| 7 |
+
- request_defining_symbol
|
| 8 |
+
- request_document_symbols integration
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import os
|
| 12 |
+
|
| 13 |
+
import pytest
|
| 14 |
+
|
| 15 |
+
from solidlsp import SolidLanguageServer
|
| 16 |
+
from solidlsp.ls_config import Language
|
| 17 |
+
from solidlsp.ls_types import SymbolKind
|
| 18 |
+
|
| 19 |
+
pytestmark = pytest.mark.ruby
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class TestRubyLanguageServerSymbols:
|
| 23 |
+
"""Test the Ruby language server's symbol-related functionality."""
|
| 24 |
+
|
| 25 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 26 |
+
def test_request_containing_symbol_method(self, language_server: SolidLanguageServer) -> None:
|
| 27 |
+
"""Test request_containing_symbol for a method."""
|
| 28 |
+
# Test for a position inside the create_user method
|
| 29 |
+
file_path = os.path.join("services.rb")
|
| 30 |
+
# Look for a position inside the create_user method body
|
| 31 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 11, 10, include_body=True)
|
| 32 |
+
|
| 33 |
+
# Verify that we found the containing symbol
|
| 34 |
+
assert containing_symbol is not None, "Should find containing symbol for method position"
|
| 35 |
+
assert containing_symbol["name"] == "create_user", f"Expected 'create_user', got '{containing_symbol['name']}'"
|
| 36 |
+
assert (
|
| 37 |
+
containing_symbol["kind"] == SymbolKind.Method.value
|
| 38 |
+
), f"Expected Method kind ({SymbolKind.Method.value}), got {containing_symbol['kind']}"
|
| 39 |
+
|
| 40 |
+
# Verify location information
|
| 41 |
+
assert "location" in containing_symbol, "Containing symbol should have location information"
|
| 42 |
+
location = containing_symbol["location"]
|
| 43 |
+
assert "range" in location, "Location should contain range information"
|
| 44 |
+
assert "start" in location["range"], "Range should have start position"
|
| 45 |
+
assert "end" in location["range"], "Range should have end position"
|
| 46 |
+
|
| 47 |
+
# Verify container information
|
| 48 |
+
if "containerName" in containing_symbol:
|
| 49 |
+
assert containing_symbol["containerName"] in [
|
| 50 |
+
"Services::UserService",
|
| 51 |
+
"UserService",
|
| 52 |
+
], f"Expected UserService container, got '{containing_symbol['containerName']}'"
|
| 53 |
+
|
| 54 |
+
# Verify body content if available
|
| 55 |
+
if "body" in containing_symbol:
|
| 56 |
+
body = containing_symbol["body"]
|
| 57 |
+
assert "def create_user" in body, "Method body should contain method definition"
|
| 58 |
+
assert len(body.strip()) > 0, "Method body should not be empty"
|
| 59 |
+
|
| 60 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 61 |
+
def test_request_containing_symbol_class(self, language_server: SolidLanguageServer) -> None:
|
| 62 |
+
"""Test request_containing_symbol for a class."""
|
| 63 |
+
# Test for a position inside the UserService class but outside any method
|
| 64 |
+
file_path = os.path.join("services.rb")
|
| 65 |
+
# Line around the class definition
|
| 66 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 5, 5)
|
| 67 |
+
|
| 68 |
+
# Verify that we found the containing symbol
|
| 69 |
+
assert containing_symbol is not None, "Should find containing symbol for class position"
|
| 70 |
+
assert containing_symbol["name"] == "UserService", f"Expected 'UserService', got '{containing_symbol['name']}'"
|
| 71 |
+
assert (
|
| 72 |
+
containing_symbol["kind"] == SymbolKind.Class.value
|
| 73 |
+
), f"Expected Class kind ({SymbolKind.Class.value}), got {containing_symbol['kind']}"
|
| 74 |
+
|
| 75 |
+
# Verify location information exists
|
| 76 |
+
assert "location" in containing_symbol, "Class symbol should have location information"
|
| 77 |
+
location = containing_symbol["location"]
|
| 78 |
+
assert "range" in location, "Location should contain range"
|
| 79 |
+
assert "start" in location["range"] and "end" in location["range"], "Range should have start and end positions"
|
| 80 |
+
|
| 81 |
+
# Verify the class is properly nested in the Services module
|
| 82 |
+
if "containerName" in containing_symbol:
|
| 83 |
+
assert (
|
| 84 |
+
containing_symbol["containerName"] == "Services"
|
| 85 |
+
), f"Expected 'Services' as container, got '{containing_symbol['containerName']}'"
|
| 86 |
+
|
| 87 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 88 |
+
def test_request_containing_symbol_module(self, language_server: SolidLanguageServer) -> None:
|
| 89 |
+
"""Test request_containing_symbol for a module context."""
|
| 90 |
+
# Test that we can find the Services module in document symbols
|
| 91 |
+
file_path = os.path.join("services.rb")
|
| 92 |
+
symbols, roots = language_server.request_document_symbols(file_path)
|
| 93 |
+
|
| 94 |
+
# Verify Services module appears in document symbols
|
| 95 |
+
services_module = None
|
| 96 |
+
for symbol in symbols:
|
| 97 |
+
if symbol.get("name") == "Services" and symbol.get("kind") == SymbolKind.Module:
|
| 98 |
+
services_module = symbol
|
| 99 |
+
break
|
| 100 |
+
|
| 101 |
+
assert services_module is not None, "Services module not found in document symbols"
|
| 102 |
+
|
| 103 |
+
# Test that UserService class has Services as container
|
| 104 |
+
# Position inside UserService class
|
| 105 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 4, 8)
|
| 106 |
+
assert containing_symbol is not None
|
| 107 |
+
assert containing_symbol["name"] == "UserService"
|
| 108 |
+
assert containing_symbol["kind"] == SymbolKind.Class
|
| 109 |
+
# Verify the module context is preserved in containerName (if supported by the language server)
|
| 110 |
+
# ruby-lsp doesn't provide containerName, but Solargraph does
|
| 111 |
+
if "containerName" in containing_symbol:
|
| 112 |
+
assert containing_symbol.get("containerName") == "Services"
|
| 113 |
+
|
| 114 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 115 |
+
def test_request_containing_symbol_nested_class(self, language_server: SolidLanguageServer) -> None:
|
| 116 |
+
"""Test request_containing_symbol with nested classes."""
|
| 117 |
+
# Test for a position inside a nested class method
|
| 118 |
+
file_path = os.path.join("nested.rb")
|
| 119 |
+
# Position inside NestedClass.find_me method
|
| 120 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 20, 10)
|
| 121 |
+
|
| 122 |
+
# Verify that we found the innermost containing symbol
|
| 123 |
+
assert containing_symbol is not None
|
| 124 |
+
assert containing_symbol["name"] == "find_me"
|
| 125 |
+
assert containing_symbol["kind"] == SymbolKind.Method
|
| 126 |
+
|
| 127 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 128 |
+
def test_request_containing_symbol_none(self, language_server: SolidLanguageServer) -> None:
|
| 129 |
+
"""Test request_containing_symbol for a position with no containing symbol."""
|
| 130 |
+
# Test for a position outside any class/method (e.g., in requires)
|
| 131 |
+
file_path = os.path.join("services.rb")
|
| 132 |
+
# Line 1 is a require statement, not inside any class or method
|
| 133 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 1, 5)
|
| 134 |
+
|
| 135 |
+
# Should return None or an empty dictionary
|
| 136 |
+
assert containing_symbol is None or containing_symbol == {}
|
| 137 |
+
|
| 138 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 139 |
+
def test_request_referencing_symbols_method(self, language_server: SolidLanguageServer) -> None:
|
| 140 |
+
"""Test request_referencing_symbols for a method."""
|
| 141 |
+
# Test referencing symbols for create_user method
|
| 142 |
+
file_path = os.path.join("services.rb")
|
| 143 |
+
# Line containing the create_user method definition
|
| 144 |
+
symbols, roots = language_server.request_document_symbols(file_path)
|
| 145 |
+
create_user_symbol = None
|
| 146 |
+
|
| 147 |
+
# Find create_user method in the document symbols (Ruby returns flat list)
|
| 148 |
+
for symbol in symbols:
|
| 149 |
+
if symbol.get("name") == "create_user":
|
| 150 |
+
create_user_symbol = symbol
|
| 151 |
+
break
|
| 152 |
+
|
| 153 |
+
if not create_user_symbol or "selectionRange" not in create_user_symbol:
|
| 154 |
+
pytest.skip("create_user symbol or its selectionRange not found")
|
| 155 |
+
|
| 156 |
+
sel_start = create_user_symbol["selectionRange"]["start"]
|
| 157 |
+
ref_symbols = [
|
| 158 |
+
ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start["line"], sel_start["character"])
|
| 159 |
+
]
|
| 160 |
+
|
| 161 |
+
# We might not have references in our simple test setup, so just verify structure
|
| 162 |
+
for symbol in ref_symbols:
|
| 163 |
+
assert "name" in symbol
|
| 164 |
+
assert "kind" in symbol
|
| 165 |
+
|
| 166 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 167 |
+
def test_request_referencing_symbols_class(self, language_server: SolidLanguageServer) -> None:
|
| 168 |
+
"""Test request_referencing_symbols for a class."""
|
| 169 |
+
# Test referencing symbols for User class
|
| 170 |
+
file_path = os.path.join("models.rb")
|
| 171 |
+
# Find User class in document symbols
|
| 172 |
+
symbols, roots = language_server.request_document_symbols(file_path)
|
| 173 |
+
user_symbol = None
|
| 174 |
+
|
| 175 |
+
for symbol in symbols:
|
| 176 |
+
if symbol.get("name") == "User":
|
| 177 |
+
user_symbol = symbol
|
| 178 |
+
break
|
| 179 |
+
|
| 180 |
+
if not user_symbol or "selectionRange" not in user_symbol:
|
| 181 |
+
pytest.skip("User symbol or its selectionRange not found")
|
| 182 |
+
|
| 183 |
+
sel_start = user_symbol["selectionRange"]["start"]
|
| 184 |
+
ref_symbols = [
|
| 185 |
+
ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start["line"], sel_start["character"])
|
| 186 |
+
]
|
| 187 |
+
|
| 188 |
+
# Verify structure of referencing symbols
|
| 189 |
+
for symbol in ref_symbols:
|
| 190 |
+
assert "name" in symbol
|
| 191 |
+
assert "kind" in symbol
|
| 192 |
+
if "location" in symbol and "range" in symbol["location"]:
|
| 193 |
+
assert "start" in symbol["location"]["range"]
|
| 194 |
+
assert "end" in symbol["location"]["range"]
|
| 195 |
+
|
| 196 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 197 |
+
def test_request_defining_symbol_variable(self, language_server: SolidLanguageServer) -> None:
|
| 198 |
+
"""Test request_defining_symbol for a variable usage."""
|
| 199 |
+
# Test finding the definition of a variable in a method
|
| 200 |
+
file_path = os.path.join("services.rb")
|
| 201 |
+
# Look for @users variable usage
|
| 202 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 12, 10)
|
| 203 |
+
|
| 204 |
+
# This test might fail if the language server doesn't support it well
|
| 205 |
+
if defining_symbol is not None:
|
| 206 |
+
assert "name" in defining_symbol
|
| 207 |
+
assert "kind" in defining_symbol
|
| 208 |
+
|
| 209 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 210 |
+
def test_request_defining_symbol_class(self, language_server: SolidLanguageServer) -> None:
|
| 211 |
+
"""Test request_defining_symbol for a class reference."""
|
| 212 |
+
# Test finding the definition of the User class used in services
|
| 213 |
+
file_path = os.path.join("services.rb")
|
| 214 |
+
# Line that references User class
|
| 215 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 11, 15)
|
| 216 |
+
|
| 217 |
+
# This might not work perfectly in all Ruby language servers
|
| 218 |
+
if defining_symbol is not None:
|
| 219 |
+
assert "name" in defining_symbol
|
| 220 |
+
# The name might be "User" or the method that contains it
|
| 221 |
+
assert defining_symbol.get("name") is not None
|
| 222 |
+
|
| 223 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 224 |
+
def test_request_defining_symbol_none(self, language_server: SolidLanguageServer) -> None:
|
| 225 |
+
"""Test request_defining_symbol for a position with no symbol."""
|
| 226 |
+
# Test for a position with no symbol (e.g., whitespace or comment)
|
| 227 |
+
file_path = os.path.join("services.rb")
|
| 228 |
+
# Line 3 is likely a blank line or comment
|
| 229 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 3, 0)
|
| 230 |
+
|
| 231 |
+
# Should return None for positions with no symbol
|
| 232 |
+
assert defining_symbol is None or defining_symbol == {}
|
| 233 |
+
|
| 234 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 235 |
+
def test_request_defining_symbol_nested_class(self, language_server: SolidLanguageServer) -> None:
|
| 236 |
+
"""Test request_defining_symbol for nested class access."""
|
| 237 |
+
# Test finding definition of NestedClass
|
| 238 |
+
file_path = os.path.join("nested.rb")
|
| 239 |
+
# Position where NestedClass is referenced
|
| 240 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 44, 25)
|
| 241 |
+
|
| 242 |
+
# This is challenging for many language servers
|
| 243 |
+
if defining_symbol is not None:
|
| 244 |
+
assert "name" in defining_symbol
|
| 245 |
+
assert defining_symbol.get("name") in ["NestedClass", "OuterClass"]
|
| 246 |
+
|
| 247 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 248 |
+
def test_symbol_methods_integration(self, language_server: SolidLanguageServer) -> None:
|
| 249 |
+
"""Test the integration between different symbol-related methods."""
|
| 250 |
+
file_path = os.path.join("models.rb")
|
| 251 |
+
|
| 252 |
+
# Step 1: Find a method we know exists
|
| 253 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 8, 5) # inside initialize method
|
| 254 |
+
if containing_symbol is not None:
|
| 255 |
+
assert containing_symbol["name"] == "initialize"
|
| 256 |
+
|
| 257 |
+
# Step 2: Get the defining symbol for the same position
|
| 258 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 8, 5)
|
| 259 |
+
if defining_symbol is not None:
|
| 260 |
+
assert defining_symbol["name"] == "initialize"
|
| 261 |
+
|
| 262 |
+
# Step 3: Verify that they refer to the same symbol type
|
| 263 |
+
assert defining_symbol["kind"] == containing_symbol["kind"]
|
| 264 |
+
|
| 265 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 266 |
+
def test_symbol_tree_structure_basic(self, language_server: SolidLanguageServer) -> None:
|
| 267 |
+
"""Test that the symbol tree structure includes Ruby symbols."""
|
| 268 |
+
# Get all symbols in the test repository
|
| 269 |
+
repo_structure = language_server.request_full_symbol_tree()
|
| 270 |
+
assert len(repo_structure) >= 1
|
| 271 |
+
|
| 272 |
+
# Look for our Ruby files in the structure
|
| 273 |
+
found_ruby_files = False
|
| 274 |
+
for root in repo_structure:
|
| 275 |
+
if "children" in root:
|
| 276 |
+
for child in root["children"]:
|
| 277 |
+
if child.get("name") in ["models", "services", "nested"]:
|
| 278 |
+
found_ruby_files = True
|
| 279 |
+
break
|
| 280 |
+
|
| 281 |
+
# We should find at least some Ruby files in the symbol tree
|
| 282 |
+
assert found_ruby_files, "Ruby files not found in symbol tree"
|
| 283 |
+
|
| 284 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 285 |
+
def test_document_symbols_detailed(self, language_server: SolidLanguageServer) -> None:
|
| 286 |
+
"""Test document symbols for detailed Ruby file structure."""
|
| 287 |
+
file_path = os.path.join("models.rb")
|
| 288 |
+
symbols, roots = language_server.request_document_symbols(file_path)
|
| 289 |
+
|
| 290 |
+
# Verify we have symbols
|
| 291 |
+
assert len(symbols) > 0 or len(roots) > 0
|
| 292 |
+
|
| 293 |
+
# Look for expected class names
|
| 294 |
+
symbol_names = set()
|
| 295 |
+
all_symbols = symbols if symbols else roots
|
| 296 |
+
|
| 297 |
+
for symbol in all_symbols:
|
| 298 |
+
symbol_names.add(symbol.get("name"))
|
| 299 |
+
# Add children names too
|
| 300 |
+
if "children" in symbol:
|
| 301 |
+
for child in symbol["children"]:
|
| 302 |
+
symbol_names.add(child.get("name"))
|
| 303 |
+
|
| 304 |
+
# We should find at least some of our defined classes/methods
|
| 305 |
+
expected_symbols = {"User", "Item", "Order", "ItemHelpers"}
|
| 306 |
+
found_symbols = symbol_names.intersection(expected_symbols)
|
| 307 |
+
assert len(found_symbols) > 0, f"Expected symbols not found. Found: {symbol_names}"
|
| 308 |
+
|
| 309 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 310 |
+
def test_module_and_class_hierarchy(self, language_server: SolidLanguageServer) -> None:
|
| 311 |
+
"""Test symbol detection for modules and nested class hierarchies."""
|
| 312 |
+
file_path = os.path.join("nested.rb")
|
| 313 |
+
symbols, roots = language_server.request_document_symbols(file_path)
|
| 314 |
+
|
| 315 |
+
# Verify we can detect the nested structure
|
| 316 |
+
assert len(symbols) > 0 or len(roots) > 0
|
| 317 |
+
|
| 318 |
+
# Look for OuterClass and its nested elements
|
| 319 |
+
symbol_names = set()
|
| 320 |
+
all_symbols = symbols if symbols else roots
|
| 321 |
+
|
| 322 |
+
for symbol in all_symbols:
|
| 323 |
+
symbol_names.add(symbol.get("name"))
|
| 324 |
+
if "children" in symbol:
|
| 325 |
+
for child in symbol["children"]:
|
| 326 |
+
symbol_names.add(child.get("name"))
|
| 327 |
+
# Check deeply nested too
|
| 328 |
+
if "children" in child:
|
| 329 |
+
for grandchild in child["children"]:
|
| 330 |
+
symbol_names.add(grandchild.get("name"))
|
| 331 |
+
|
| 332 |
+
# Should find the outer class at minimum
|
| 333 |
+
assert "OuterClass" in symbol_names, f"OuterClass not found in symbols: {symbol_names}"
|
| 334 |
+
|
| 335 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 336 |
+
def test_references_to_variables(self, language_server: SolidLanguageServer) -> None:
|
| 337 |
+
"""Test request_referencing_symbols for a variable with detailed verification."""
|
| 338 |
+
file_path = os.path.join("variables.rb")
|
| 339 |
+
# Test references to @status variable in DataContainer class (around line 9)
|
| 340 |
+
ref_symbols = [ref.symbol for ref in language_server.request_referencing_symbols(file_path, 8, 4)]
|
| 341 |
+
|
| 342 |
+
if len(ref_symbols) > 0:
|
| 343 |
+
# Verify we have references
|
| 344 |
+
assert len(ref_symbols) > 0, "Should find references to @status variable"
|
| 345 |
+
|
| 346 |
+
# Check that we have location information
|
| 347 |
+
ref_with_locations = [ref for ref in ref_symbols if "location" in ref and "range" in ref["location"]]
|
| 348 |
+
assert len(ref_with_locations) > 0, "References should include location information"
|
| 349 |
+
|
| 350 |
+
# Verify line numbers are reasonable (should be within the file)
|
| 351 |
+
ref_lines = [ref["location"]["range"]["start"]["line"] for ref in ref_with_locations]
|
| 352 |
+
assert all(line >= 0 for line in ref_lines), "Reference lines should be valid"
|
| 353 |
+
|
| 354 |
+
# Check for specific reference locations we expect
|
| 355 |
+
# Lines where @status is modified/accessed
|
| 356 |
+
expected_line_ranges = [(20, 40), (45, 70)] # Approximate ranges
|
| 357 |
+
found_in_expected_range = any(any(start <= line <= end for start, end in expected_line_ranges) for line in ref_lines)
|
| 358 |
+
assert found_in_expected_range, f"Expected references in ranges {expected_line_ranges}, found lines: {ref_lines}"
|
| 359 |
+
|
| 360 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 361 |
+
def test_request_referencing_symbols_parameter(self, language_server: SolidLanguageServer) -> None:
|
| 362 |
+
"""Test request_referencing_symbols for a method parameter."""
|
| 363 |
+
# Test referencing symbols for a method parameter in get_user method
|
| 364 |
+
file_path = os.path.join("services.rb")
|
| 365 |
+
# Find get_user method and test parameter references
|
| 366 |
+
symbols, roots = language_server.request_document_symbols(file_path)
|
| 367 |
+
get_user_symbol = None
|
| 368 |
+
|
| 369 |
+
for symbol in symbols:
|
| 370 |
+
if symbol.get("name") == "get_user":
|
| 371 |
+
get_user_symbol = symbol
|
| 372 |
+
break
|
| 373 |
+
|
| 374 |
+
if not get_user_symbol or "selectionRange" not in get_user_symbol:
|
| 375 |
+
pytest.skip("get_user symbol or its selectionRange not found")
|
| 376 |
+
|
| 377 |
+
# Test parameter reference within method body
|
| 378 |
+
method_start_line = get_user_symbol["selectionRange"]["start"]["line"]
|
| 379 |
+
ref_symbols = [
|
| 380 |
+
ref.symbol
|
| 381 |
+
for ref in language_server.request_referencing_symbols(file_path, method_start_line + 1, 10) # Position within method body
|
| 382 |
+
]
|
| 383 |
+
|
| 384 |
+
# Verify structure of referencing symbols
|
| 385 |
+
for symbol in ref_symbols:
|
| 386 |
+
assert "name" in symbol, "Symbol should have name"
|
| 387 |
+
assert "kind" in symbol, "Symbol should have kind"
|
| 388 |
+
if "location" in symbol and "range" in symbol["location"]:
|
| 389 |
+
range_info = symbol["location"]["range"]
|
| 390 |
+
assert "start" in range_info, "Range should have start"
|
| 391 |
+
assert "end" in range_info, "Range should have end"
|
| 392 |
+
# Verify line number is valid (references can be before method definition too)
|
| 393 |
+
assert range_info["start"]["line"] >= 0, "Reference line should be valid"
|
| 394 |
+
|
| 395 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 396 |
+
def test_request_referencing_symbols_none(self, language_server: SolidLanguageServer) -> None:
|
| 397 |
+
"""Test request_referencing_symbols for a position with no symbol."""
|
| 398 |
+
# Test for a position with no symbol (comment or blank line)
|
| 399 |
+
file_path = os.path.join("services.rb")
|
| 400 |
+
|
| 401 |
+
# Try multiple positions that should have no symbols
|
| 402 |
+
test_positions = [(1, 0), (2, 0)] # Comment/require lines
|
| 403 |
+
|
| 404 |
+
for line, char in test_positions:
|
| 405 |
+
try:
|
| 406 |
+
ref_symbols = [ref.symbol for ref in language_server.request_referencing_symbols(file_path, line, char)]
|
| 407 |
+
# If we get here, make sure we got an empty result or minimal results
|
| 408 |
+
if ref_symbols:
|
| 409 |
+
# Some language servers might return minimal info, verify it's reasonable
|
| 410 |
+
assert len(ref_symbols) <= 3, f"Expected few/no references at line {line}, got {len(ref_symbols)}"
|
| 411 |
+
|
| 412 |
+
except Exception as e:
|
| 413 |
+
# Some language servers throw exceptions for invalid positions, which is acceptable
|
| 414 |
+
assert (
|
| 415 |
+
"symbol" in str(e).lower() or "position" in str(e).lower() or "reference" in str(e).lower()
|
| 416 |
+
), f"Exception should be related to symbol/position/reference issues, got: {e}"
|
| 417 |
+
|
| 418 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 419 |
+
def test_request_dir_overview(self, language_server: SolidLanguageServer) -> None:
|
| 420 |
+
"""Test that request_dir_overview returns correct symbol information for files in a directory."""
|
| 421 |
+
# Get overview of the test repo directory
|
| 422 |
+
overview = language_server.request_dir_overview(".")
|
| 423 |
+
|
| 424 |
+
# Verify that we have entries for our main files
|
| 425 |
+
expected_files = ["services.rb", "models.rb", "variables.rb", "nested.rb"]
|
| 426 |
+
found_files = []
|
| 427 |
+
|
| 428 |
+
for file_path in overview.keys():
|
| 429 |
+
for expected in expected_files:
|
| 430 |
+
if expected in file_path:
|
| 431 |
+
found_files.append(expected)
|
| 432 |
+
break
|
| 433 |
+
|
| 434 |
+
assert len(found_files) >= 2, f"Should find at least 2 expected files, found: {found_files}"
|
| 435 |
+
|
| 436 |
+
# Test specific symbols from services.rb if it exists
|
| 437 |
+
services_file_key = None
|
| 438 |
+
for file_path in overview.keys():
|
| 439 |
+
if "services.rb" in file_path:
|
| 440 |
+
services_file_key = file_path
|
| 441 |
+
break
|
| 442 |
+
|
| 443 |
+
if services_file_key:
|
| 444 |
+
services_symbols = overview[services_file_key]
|
| 445 |
+
assert len(services_symbols) > 0, "services.rb should have symbols"
|
| 446 |
+
|
| 447 |
+
# Check for expected symbols with detailed verification
|
| 448 |
+
symbol_names = [s[0] for s in services_symbols if isinstance(s, tuple) and len(s) > 0]
|
| 449 |
+
if not symbol_names: # If not tuples, try different format
|
| 450 |
+
symbol_names = [s.get("name") for s in services_symbols if hasattr(s, "get")]
|
| 451 |
+
|
| 452 |
+
expected_symbols = ["Services", "UserService", "ItemService"]
|
| 453 |
+
found_expected = [name for name in expected_symbols if name in symbol_names]
|
| 454 |
+
assert len(found_expected) >= 1, f"Should find at least one expected symbol, found: {found_expected} in {symbol_names}"
|
| 455 |
+
|
| 456 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 457 |
+
def test_request_document_overview(self, language_server: SolidLanguageServer) -> None:
|
| 458 |
+
"""Test that request_document_overview returns correct symbol information for a file."""
|
| 459 |
+
# Get overview of the user_management.rb file
|
| 460 |
+
file_path = os.path.join("examples", "user_management.rb")
|
| 461 |
+
overview = language_server.request_document_overview(file_path)
|
| 462 |
+
|
| 463 |
+
# Verify that we have symbol information
|
| 464 |
+
assert len(overview) > 0, "Document overview should contain symbols"
|
| 465 |
+
|
| 466 |
+
# Look for expected symbols from the file
|
| 467 |
+
symbol_names = set()
|
| 468 |
+
for s_info in overview:
|
| 469 |
+
if isinstance(s_info, tuple) and len(s_info) > 0:
|
| 470 |
+
symbol_names.add(s_info[0])
|
| 471 |
+
elif hasattr(s_info, "get"):
|
| 472 |
+
symbol_names.add(s_info.get("name"))
|
| 473 |
+
elif isinstance(s_info, str):
|
| 474 |
+
symbol_names.add(s_info)
|
| 475 |
+
|
| 476 |
+
# We should find some of our defined classes/methods
|
| 477 |
+
expected_symbols = {"UserStats", "UserManager", "process_user_data", "main"}
|
| 478 |
+
found_symbols = symbol_names.intersection(expected_symbols)
|
| 479 |
+
assert len(found_symbols) > 0, f"Expected to find some symbols from {expected_symbols}, found: {symbol_names}"
|
| 480 |
+
|
| 481 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 482 |
+
def test_request_containing_symbol_variable(self, language_server: SolidLanguageServer) -> None:
|
| 483 |
+
"""Test request_containing_symbol where the target is a variable."""
|
| 484 |
+
# Test for a position inside a variable definition or usage
|
| 485 |
+
file_path = os.path.join("variables.rb")
|
| 486 |
+
# Position around a variable assignment (e.g., @status = "pending")
|
| 487 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 10, 5)
|
| 488 |
+
|
| 489 |
+
# Verify that we found a containing symbol (likely the method or class)
|
| 490 |
+
if containing_symbol is not None:
|
| 491 |
+
assert "name" in containing_symbol, "Containing symbol should have a name"
|
| 492 |
+
assert "kind" in containing_symbol, "Containing symbol should have a kind"
|
| 493 |
+
# The containing symbol should be a method, class, or similar construct
|
| 494 |
+
expected_kinds = [SymbolKind.Method, SymbolKind.Class, SymbolKind.Function, SymbolKind.Constructor]
|
| 495 |
+
assert containing_symbol["kind"] in [
|
| 496 |
+
k.value for k in expected_kinds
|
| 497 |
+
], f"Expected containing symbol to be method/class/function, got kind: {containing_symbol['kind']}"
|
| 498 |
+
|
| 499 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 500 |
+
def test_request_containing_symbol_function(self, language_server: SolidLanguageServer) -> None:
|
| 501 |
+
"""Test request_containing_symbol for a function (not method)."""
|
| 502 |
+
# Test for a position inside a standalone function
|
| 503 |
+
file_path = os.path.join("variables.rb")
|
| 504 |
+
# Position inside the demonstrate_variable_usage function
|
| 505 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 100, 10)
|
| 506 |
+
|
| 507 |
+
if containing_symbol is not None:
|
| 508 |
+
assert containing_symbol["name"] in [
|
| 509 |
+
"demonstrate_variable_usage",
|
| 510 |
+
"main",
|
| 511 |
+
], f"Expected function name, got: {containing_symbol['name']}"
|
| 512 |
+
assert containing_symbol["kind"] in [
|
| 513 |
+
SymbolKind.Function.value,
|
| 514 |
+
SymbolKind.Method.value,
|
| 515 |
+
], f"Expected function or method kind, got: {containing_symbol['kind']}"
|
| 516 |
+
|
| 517 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 518 |
+
def test_request_containing_symbol_nested(self, language_server: SolidLanguageServer) -> None:
|
| 519 |
+
"""Test request_containing_symbol with nested scopes."""
|
| 520 |
+
# Test for a position inside a method which is inside a class
|
| 521 |
+
file_path = os.path.join("services.rb")
|
| 522 |
+
# Position inside create_user method within UserService class
|
| 523 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 12, 15)
|
| 524 |
+
|
| 525 |
+
# Verify that we found the innermost containing symbol (the method)
|
| 526 |
+
assert containing_symbol is not None
|
| 527 |
+
assert containing_symbol["name"] == "create_user"
|
| 528 |
+
assert containing_symbol["kind"] == SymbolKind.Method
|
| 529 |
+
|
| 530 |
+
# Verify the container context is preserved
|
| 531 |
+
if "containerName" in containing_symbol:
|
| 532 |
+
assert "UserService" in containing_symbol["containerName"]
|
| 533 |
+
|
| 534 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 535 |
+
def test_symbol_tree_structure_subdir(self, language_server: SolidLanguageServer) -> None:
|
| 536 |
+
"""Test that the symbol tree structure correctly handles subdirectories."""
|
| 537 |
+
# Get symbols within the examples subdirectory
|
| 538 |
+
examples_structure = language_server.request_full_symbol_tree(within_relative_path="examples")
|
| 539 |
+
|
| 540 |
+
if len(examples_structure) > 0:
|
| 541 |
+
# Should find the examples directory structure
|
| 542 |
+
assert len(examples_structure) >= 1, "Should find examples directory structure"
|
| 543 |
+
|
| 544 |
+
# Look for the user_management file in the structure
|
| 545 |
+
found_user_management = False
|
| 546 |
+
for root in examples_structure:
|
| 547 |
+
if "children" in root:
|
| 548 |
+
for child in root["children"]:
|
| 549 |
+
if "user_management" in child.get("name", ""):
|
| 550 |
+
found_user_management = True
|
| 551 |
+
# Verify the structure includes symbol information
|
| 552 |
+
if "children" in child:
|
| 553 |
+
child_names = [c.get("name") for c in child["children"]]
|
| 554 |
+
expected_names = ["UserStats", "UserManager", "process_user_data"]
|
| 555 |
+
found_expected = [name for name in expected_names if name in child_names]
|
| 556 |
+
assert (
|
| 557 |
+
len(found_expected) > 0
|
| 558 |
+
), f"Should find symbols in user_management, expected {expected_names}, found {child_names}"
|
| 559 |
+
break
|
| 560 |
+
|
| 561 |
+
if not found_user_management:
|
| 562 |
+
pytest.skip("user_management file not found in examples subdirectory structure")
|
| 563 |
+
|
| 564 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 565 |
+
def test_request_defining_symbol_imported_class(self, language_server: SolidLanguageServer) -> None:
|
| 566 |
+
"""Test request_defining_symbol for an imported/required class."""
|
| 567 |
+
# Test finding the definition of a class used from another file
|
| 568 |
+
file_path = os.path.join("examples", "user_management.rb")
|
| 569 |
+
# Position where Services::UserService is referenced
|
| 570 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 25, 20)
|
| 571 |
+
|
| 572 |
+
# This might not work perfectly in all Ruby language servers due to require complexity
|
| 573 |
+
if defining_symbol is not None:
|
| 574 |
+
assert "name" in defining_symbol
|
| 575 |
+
# The defining symbol should relate to UserService or Services
|
| 576 |
+
# The defining symbol should relate to UserService, Services, or the containing class
|
| 577 |
+
# Different language servers may resolve this differently
|
| 578 |
+
expected_names = ["UserService", "Services", "new", "UserManager"]
|
| 579 |
+
assert defining_symbol.get("name") in expected_names, f"Expected one of {expected_names}, got: {defining_symbol.get('name')}"
|
| 580 |
+
|
| 581 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 582 |
+
def test_request_defining_symbol_method_call(self, language_server: SolidLanguageServer) -> None:
|
| 583 |
+
"""Test request_defining_symbol for a method call."""
|
| 584 |
+
# Test finding the definition of a method being called
|
| 585 |
+
file_path = os.path.join("examples", "user_management.rb")
|
| 586 |
+
# Position at a method call like create_user
|
| 587 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 30, 15)
|
| 588 |
+
|
| 589 |
+
# Verify that we can find method definitions
|
| 590 |
+
if defining_symbol is not None:
|
| 591 |
+
assert "name" in defining_symbol
|
| 592 |
+
assert "kind" in defining_symbol
|
| 593 |
+
# Should be a method or constructor
|
| 594 |
+
assert defining_symbol.get("kind") in [SymbolKind.Method.value, SymbolKind.Constructor.value, SymbolKind.Function.value]
|
| 595 |
+
|
| 596 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 597 |
+
def test_request_defining_symbol_nested_function(self, language_server: SolidLanguageServer) -> None:
|
| 598 |
+
"""Test request_defining_symbol for a nested function or block."""
|
| 599 |
+
# Test finding definition within nested contexts
|
| 600 |
+
file_path = os.path.join("nested.rb")
|
| 601 |
+
# Position inside or referencing nested functionality
|
| 602 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 15, 10)
|
| 603 |
+
|
| 604 |
+
# This is challenging for many language servers
|
| 605 |
+
if defining_symbol is not None:
|
| 606 |
+
assert "name" in defining_symbol
|
| 607 |
+
assert "kind" in defining_symbol
|
| 608 |
+
# Could be method, function, or variable depending on implementation
|
| 609 |
+
valid_kinds = [SymbolKind.Method.value, SymbolKind.Function.value, SymbolKind.Variable.value, SymbolKind.Class.value]
|
| 610 |
+
assert defining_symbol.get("kind") in valid_kinds
|
| 611 |
+
|
| 612 |
+
@pytest.mark.parametrize("language_server", [Language.RUBY], indirect=True)
|
| 613 |
+
def test_containing_symbol_of_var_is_file(self, language_server: SolidLanguageServer) -> None:
|
| 614 |
+
"""Test that the containing symbol of a file-level variable is handled appropriately."""
|
| 615 |
+
# Test behavior with file-level variables or constants
|
| 616 |
+
file_path = os.path.join("variables.rb")
|
| 617 |
+
# Position at file-level variable/constant
|
| 618 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 5, 5)
|
| 619 |
+
|
| 620 |
+
# Different language servers handle file-level symbols differently
|
| 621 |
+
# Some return None, others return file-level containers
|
| 622 |
+
if containing_symbol is not None:
|
| 623 |
+
# If we get a symbol, verify its structure
|
| 624 |
+
assert "name" in containing_symbol
|
| 625 |
+
assert "kind" in containing_symbol
|
projects/ui/serena-new/test/solidlsp/rust/test_rust_2024_edition.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
from solidlsp.ls_config import Language
|
| 7 |
+
from solidlsp.ls_utils import SymbolUtils
|
| 8 |
+
from test.conftest import create_ls
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@pytest.mark.rust
|
| 12 |
+
class TestRust2024EditionLanguageServer:
|
| 13 |
+
@classmethod
|
| 14 |
+
def setup_class(cls):
|
| 15 |
+
"""Set up the test class with the Rust 2024 edition test repository."""
|
| 16 |
+
cls.test_repo_2024_path = Path(__file__).parent.parent.parent / "resources" / "repos" / "rust" / "test_repo_2024"
|
| 17 |
+
|
| 18 |
+
if not cls.test_repo_2024_path.exists():
|
| 19 |
+
pytest.skip("Rust 2024 edition test repository not found")
|
| 20 |
+
|
| 21 |
+
# Create and start the language server for the 2024 edition repo
|
| 22 |
+
cls.language_server = create_ls(Language.RUST, str(cls.test_repo_2024_path))
|
| 23 |
+
cls.language_server.start()
|
| 24 |
+
|
| 25 |
+
@classmethod
|
| 26 |
+
def teardown_class(cls):
|
| 27 |
+
"""Clean up the language server."""
|
| 28 |
+
if hasattr(cls, "language_server"):
|
| 29 |
+
cls.language_server.stop()
|
| 30 |
+
|
| 31 |
+
def test_find_references_raw(self) -> None:
|
| 32 |
+
# Test finding references to the 'add' function defined in main.rs
|
| 33 |
+
file_path = os.path.join("src", "main.rs")
|
| 34 |
+
symbols = self.language_server.request_document_symbols(file_path)
|
| 35 |
+
add_symbol = None
|
| 36 |
+
for sym in symbols[0]:
|
| 37 |
+
if sym.get("name") == "add":
|
| 38 |
+
add_symbol = sym
|
| 39 |
+
break
|
| 40 |
+
assert add_symbol is not None, "Could not find 'add' function symbol in main.rs"
|
| 41 |
+
sel_start = add_symbol["selectionRange"]["start"]
|
| 42 |
+
refs = self.language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 43 |
+
# The add function should be referenced within main.rs itself (in the main function)
|
| 44 |
+
assert any("main.rs" in ref.get("relativePath", "") for ref in refs), "main.rs should reference add function"
|
| 45 |
+
|
| 46 |
+
def test_find_symbol(self) -> None:
|
| 47 |
+
symbols = self.language_server.request_full_symbol_tree()
|
| 48 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "main"), "main function not found in symbol tree"
|
| 49 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "add"), "add function not found in symbol tree"
|
| 50 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "multiply"), "multiply function not found in symbol tree"
|
| 51 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Calculator"), "Calculator struct not found in symbol tree"
|
| 52 |
+
|
| 53 |
+
def test_find_referencing_symbols_multiply(self) -> None:
|
| 54 |
+
# Find references to 'multiply' function defined in lib.rs
|
| 55 |
+
file_path = os.path.join("src", "lib.rs")
|
| 56 |
+
symbols = self.language_server.request_document_symbols(file_path)
|
| 57 |
+
multiply_symbol = None
|
| 58 |
+
for sym in symbols[0]:
|
| 59 |
+
if sym.get("name") == "multiply":
|
| 60 |
+
multiply_symbol = sym
|
| 61 |
+
break
|
| 62 |
+
assert multiply_symbol is not None, "Could not find 'multiply' function symbol in lib.rs"
|
| 63 |
+
sel_start = multiply_symbol["selectionRange"]["start"]
|
| 64 |
+
refs = self.language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 65 |
+
# The multiply function exists but may not be referenced anywhere, which is fine
|
| 66 |
+
# This test just verifies we can find the symbol and request references without error
|
| 67 |
+
assert isinstance(refs, list), "Should return a list of references (even if empty)"
|
| 68 |
+
|
| 69 |
+
def test_find_calculator_struct_and_impl(self) -> None:
|
| 70 |
+
# Test finding the Calculator struct and its impl block
|
| 71 |
+
file_path = os.path.join("src", "lib.rs")
|
| 72 |
+
symbols = self.language_server.request_document_symbols(file_path)
|
| 73 |
+
|
| 74 |
+
# Find the Calculator struct
|
| 75 |
+
calculator_struct = None
|
| 76 |
+
calculator_impl = None
|
| 77 |
+
for sym in symbols[0]:
|
| 78 |
+
if sym.get("name") == "Calculator" and sym.get("kind") == 23: # Struct kind
|
| 79 |
+
calculator_struct = sym
|
| 80 |
+
elif sym.get("name") == "Calculator" and sym.get("kind") == 11: # Interface/Impl kind
|
| 81 |
+
calculator_impl = sym
|
| 82 |
+
|
| 83 |
+
assert calculator_struct is not None, "Could not find 'Calculator' struct symbol in lib.rs"
|
| 84 |
+
|
| 85 |
+
# The struct should have the 'result' field
|
| 86 |
+
struct_children = calculator_struct.get("children", [])
|
| 87 |
+
field_names = [child.get("name") for child in struct_children]
|
| 88 |
+
assert "result" in field_names, "Calculator struct should have 'result' field"
|
| 89 |
+
|
| 90 |
+
# Find the impl block and check its methods
|
| 91 |
+
if calculator_impl is not None:
|
| 92 |
+
impl_children = calculator_impl.get("children", [])
|
| 93 |
+
method_names = [child.get("name") for child in impl_children]
|
| 94 |
+
assert "new" in method_names, "Calculator impl should have 'new' method"
|
| 95 |
+
assert "add" in method_names, "Calculator impl should have 'add' method"
|
| 96 |
+
assert "get_result" in method_names, "Calculator impl should have 'get_result' method"
|
| 97 |
+
|
| 98 |
+
def test_overview_methods(self) -> None:
|
| 99 |
+
symbols = self.language_server.request_full_symbol_tree()
|
| 100 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "main"), "main missing from overview"
|
| 101 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "add"), "add missing from overview"
|
| 102 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "multiply"), "multiply missing from overview"
|
| 103 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Calculator"), "Calculator missing from overview"
|
| 104 |
+
|
| 105 |
+
def test_rust_2024_edition_specific(self) -> None:
|
| 106 |
+
# Verify we're actually working with the 2024 edition repository
|
| 107 |
+
cargo_toml_path = self.test_repo_2024_path / "Cargo.toml"
|
| 108 |
+
assert cargo_toml_path.exists(), "Cargo.toml should exist in test repository"
|
| 109 |
+
|
| 110 |
+
with open(cargo_toml_path) as f:
|
| 111 |
+
content = f.read()
|
| 112 |
+
assert 'edition = "2024"' in content, "Should be using Rust 2024 edition"
|
projects/ui/serena-new/test/solidlsp/rust/test_rust_basic.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
from solidlsp import SolidLanguageServer
|
| 6 |
+
from solidlsp.ls_config import Language
|
| 7 |
+
from solidlsp.ls_utils import SymbolUtils
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@pytest.mark.rust
|
| 11 |
+
class TestRustLanguageServer:
|
| 12 |
+
@pytest.mark.parametrize("language_server", [Language.RUST], indirect=True)
|
| 13 |
+
def test_find_references_raw(self, language_server: SolidLanguageServer) -> None:
|
| 14 |
+
# Directly test the request_references method for the add function
|
| 15 |
+
file_path = os.path.join("src", "lib.rs")
|
| 16 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 17 |
+
add_symbol = None
|
| 18 |
+
for sym in symbols[0]:
|
| 19 |
+
if sym.get("name") == "add":
|
| 20 |
+
add_symbol = sym
|
| 21 |
+
break
|
| 22 |
+
assert add_symbol is not None, "Could not find 'add' function symbol in lib.rs"
|
| 23 |
+
sel_start = add_symbol["selectionRange"]["start"]
|
| 24 |
+
refs = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 25 |
+
assert any(
|
| 26 |
+
"main.rs" in ref.get("relativePath", "") for ref in refs
|
| 27 |
+
), "main.rs should reference add (raw, tried all positions in selectionRange)"
|
| 28 |
+
|
| 29 |
+
@pytest.mark.parametrize("language_server", [Language.RUST], indirect=True)
|
| 30 |
+
def test_find_symbol(self, language_server: SolidLanguageServer) -> None:
|
| 31 |
+
symbols = language_server.request_full_symbol_tree()
|
| 32 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "main"), "main function not found in symbol tree"
|
| 33 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "add"), "add function not found in symbol tree"
|
| 34 |
+
# Add more as needed based on test_repo
|
| 35 |
+
|
| 36 |
+
@pytest.mark.parametrize("language_server", [Language.RUST], indirect=True)
|
| 37 |
+
def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:
|
| 38 |
+
# Find references to 'add' defined in lib.rs, should be referenced from main.rs
|
| 39 |
+
file_path = os.path.join("src", "lib.rs")
|
| 40 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 41 |
+
add_symbol = None
|
| 42 |
+
for sym in symbols[0]:
|
| 43 |
+
if sym.get("name") == "add":
|
| 44 |
+
add_symbol = sym
|
| 45 |
+
break
|
| 46 |
+
assert add_symbol is not None, "Could not find 'add' function symbol in lib.rs"
|
| 47 |
+
sel_start = add_symbol["selectionRange"]["start"]
|
| 48 |
+
refs = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 49 |
+
assert any(
|
| 50 |
+
"main.rs" in ref.get("relativePath", "") for ref in refs
|
| 51 |
+
), "main.rs should reference add (tried all positions in selectionRange)"
|
| 52 |
+
|
| 53 |
+
@pytest.mark.parametrize("language_server", [Language.RUST], indirect=True)
|
| 54 |
+
def test_overview_methods(self, language_server: SolidLanguageServer) -> None:
|
| 55 |
+
symbols = language_server.request_full_symbol_tree()
|
| 56 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "main"), "main missing from overview"
|
| 57 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "add"), "add missing from overview"
|
projects/ui/serena-new/test/solidlsp/swift/test_swift_basic.py
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Basic integration tests for the Swift language server functionality.
|
| 3 |
+
|
| 4 |
+
These tests validate the functionality of the language server APIs
|
| 5 |
+
like request_references using the Swift test repository.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import os
|
| 9 |
+
import platform
|
| 10 |
+
|
| 11 |
+
import pytest
|
| 12 |
+
|
| 13 |
+
from serena.project import Project
|
| 14 |
+
from serena.text_utils import LineType
|
| 15 |
+
from solidlsp import SolidLanguageServer
|
| 16 |
+
from solidlsp.ls_config import Language
|
| 17 |
+
|
| 18 |
+
# Skip Swift tests on Windows due to complex GitHub Actions configuration
|
| 19 |
+
WINDOWS_SKIP = platform.system() == "Windows"
|
| 20 |
+
WINDOWS_SKIP_REASON = "GitHub Actions configuration for Swift on Windows is complex, skipping for now."
|
| 21 |
+
|
| 22 |
+
pytestmark = [pytest.mark.swift, pytest.mark.skipif(WINDOWS_SKIP, reason=WINDOWS_SKIP_REASON)]
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class TestSwiftLanguageServerBasics:
|
| 26 |
+
"""Test basic functionality of the Swift language server."""
|
| 27 |
+
|
| 28 |
+
@pytest.mark.parametrize("language_server", [Language.SWIFT], indirect=True)
|
| 29 |
+
def test_goto_definition_calculator_class(self, language_server: SolidLanguageServer) -> None:
|
| 30 |
+
"""Test goto_definition on Calculator class usage."""
|
| 31 |
+
file_path = os.path.join("src", "main.swift")
|
| 32 |
+
|
| 33 |
+
# Find the Calculator usage at line 5: let calculator = Calculator()
|
| 34 |
+
# Position should be at the "Calculator()" call
|
| 35 |
+
definitions = language_server.request_definition(file_path, 4, 23) # Position at Calculator() call
|
| 36 |
+
assert isinstance(definitions, list), "Definitions should be a list"
|
| 37 |
+
assert len(definitions) > 0, "Should find definition for Calculator class"
|
| 38 |
+
|
| 39 |
+
# Verify the definition points to the Calculator class definition
|
| 40 |
+
calculator_def = definitions[0]
|
| 41 |
+
assert calculator_def.get("uri", "").endswith("main.swift"), "Definition should be in main.swift"
|
| 42 |
+
|
| 43 |
+
# The Calculator class is defined starting at line 16
|
| 44 |
+
start_line = calculator_def.get("range", {}).get("start", {}).get("line")
|
| 45 |
+
assert start_line == 15, f"Calculator class definition should be at line 16, got {start_line + 1}"
|
| 46 |
+
|
| 47 |
+
@pytest.mark.parametrize("language_server", [Language.SWIFT], indirect=True)
|
| 48 |
+
def test_goto_definition_user_struct(self, language_server: SolidLanguageServer) -> None:
|
| 49 |
+
"""Test goto_definition on User struct usage."""
|
| 50 |
+
file_path = os.path.join("src", "main.swift")
|
| 51 |
+
|
| 52 |
+
# Find the User usage at line 9: let user = User(name: "Alice", age: 30)
|
| 53 |
+
# Position should be at the "User(...)" call
|
| 54 |
+
definitions = language_server.request_definition(file_path, 8, 18) # Position at User(...) call
|
| 55 |
+
assert isinstance(definitions, list), "Definitions should be a list"
|
| 56 |
+
assert len(definitions) > 0, "Should find definition for User struct"
|
| 57 |
+
|
| 58 |
+
# Verify the definition points to the User struct definition
|
| 59 |
+
user_def = definitions[0]
|
| 60 |
+
assert user_def.get("uri", "").endswith("main.swift"), "Definition should be in main.swift"
|
| 61 |
+
|
| 62 |
+
# The User struct is defined starting at line 26
|
| 63 |
+
start_line = user_def.get("range", {}).get("start", {}).get("line")
|
| 64 |
+
assert start_line == 25, f"User struct definition should be at line 26, got {start_line + 1}"
|
| 65 |
+
|
| 66 |
+
@pytest.mark.parametrize("language_server", [Language.SWIFT], indirect=True)
|
| 67 |
+
def test_goto_definition_calculator_method(self, language_server: SolidLanguageServer) -> None:
|
| 68 |
+
"""Test goto_definition on Calculator method usage."""
|
| 69 |
+
file_path = os.path.join("src", "main.swift")
|
| 70 |
+
|
| 71 |
+
# Find the add method usage at line 6: let result = calculator.add(5, 3)
|
| 72 |
+
# Position should be at the "add" method call
|
| 73 |
+
definitions = language_server.request_definition(file_path, 5, 28) # Position at add method call
|
| 74 |
+
assert isinstance(definitions, list), "Definitions should be a list"
|
| 75 |
+
|
| 76 |
+
# Verify the definition points to the add method definition
|
| 77 |
+
add_def = definitions[0]
|
| 78 |
+
assert add_def.get("uri", "").endswith("main.swift"), "Definition should be in main.swift"
|
| 79 |
+
|
| 80 |
+
# The add method is defined starting at line 17
|
| 81 |
+
start_line = add_def.get("range", {}).get("start", {}).get("line")
|
| 82 |
+
assert start_line == 16, f"add method definition should be at line 17, got {start_line + 1}"
|
| 83 |
+
|
| 84 |
+
@pytest.mark.parametrize("language_server", [Language.SWIFT], indirect=True)
|
| 85 |
+
def test_goto_definition_cross_file(self, language_server: SolidLanguageServer) -> None:
|
| 86 |
+
"""Test goto_definition across files - Utils struct."""
|
| 87 |
+
utils_file = os.path.join("src", "utils.swift")
|
| 88 |
+
|
| 89 |
+
# First, let's check if Utils is used anywhere (it might not be in this simple test)
|
| 90 |
+
# We'll test goto_definition on Utils struct itself
|
| 91 |
+
symbols = language_server.request_document_symbols(utils_file)
|
| 92 |
+
utils_symbol = next((s for s in symbols[0] if s.get("name") == "Utils"), None)
|
| 93 |
+
|
| 94 |
+
sel_start = utils_symbol["selectionRange"]["start"]
|
| 95 |
+
definitions = language_server.request_definition(utils_file, sel_start["line"], sel_start["character"])
|
| 96 |
+
assert isinstance(definitions, list), "Definitions should be a list"
|
| 97 |
+
|
| 98 |
+
# Should find the Utils struct definition itself
|
| 99 |
+
utils_def = definitions[0]
|
| 100 |
+
assert utils_def.get("uri", "").endswith("utils.swift"), "Definition should be in utils.swift"
|
| 101 |
+
|
| 102 |
+
@pytest.mark.parametrize("language_server", [Language.SWIFT], indirect=True)
|
| 103 |
+
def test_request_references_calculator_class(self, language_server: SolidLanguageServer) -> None:
|
| 104 |
+
"""Test request_references on the Calculator class."""
|
| 105 |
+
# Get references to the Calculator class in main.swift
|
| 106 |
+
file_path = os.path.join("src", "main.swift")
|
| 107 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 108 |
+
|
| 109 |
+
calculator_symbol = next((s for s in symbols[0] if s.get("name") == "Calculator"), None)
|
| 110 |
+
|
| 111 |
+
sel_start = calculator_symbol["selectionRange"]["start"]
|
| 112 |
+
references = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 113 |
+
assert isinstance(references, list), "References should be a list"
|
| 114 |
+
assert len(references) > 0, "Calculator class should be referenced"
|
| 115 |
+
|
| 116 |
+
# Validate that Calculator is referenced in the main function
|
| 117 |
+
calculator_refs = [ref for ref in references if ref.get("uri", "").endswith("main.swift")]
|
| 118 |
+
assert len(calculator_refs) > 0, "Calculator class should be referenced in main.swift"
|
| 119 |
+
|
| 120 |
+
# Check that one reference is at line 5 (let calculator = Calculator())
|
| 121 |
+
line_5_refs = [ref for ref in calculator_refs if ref.get("range", {}).get("start", {}).get("line") == 4]
|
| 122 |
+
assert len(line_5_refs) > 0, "Calculator should be referenced at line 5"
|
| 123 |
+
|
| 124 |
+
@pytest.mark.parametrize("language_server", [Language.SWIFT], indirect=True)
|
| 125 |
+
def test_request_references_user_struct(self, language_server: SolidLanguageServer) -> None:
|
| 126 |
+
"""Test request_references on the User struct."""
|
| 127 |
+
# Get references to the User struct in main.swift
|
| 128 |
+
file_path = os.path.join("src", "main.swift")
|
| 129 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 130 |
+
|
| 131 |
+
user_symbol = next((s for s in symbols[0] if s.get("name") == "User"), None)
|
| 132 |
+
|
| 133 |
+
sel_start = user_symbol["selectionRange"]["start"]
|
| 134 |
+
references = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 135 |
+
assert isinstance(references, list), "References should be a list"
|
| 136 |
+
|
| 137 |
+
# Validate that User is referenced in the main function
|
| 138 |
+
user_refs = [ref for ref in references if ref.get("uri", "").endswith("main.swift")]
|
| 139 |
+
assert len(user_refs) > 0, "User struct should be referenced in main.swift"
|
| 140 |
+
|
| 141 |
+
# Check that one reference is at line 9 (let user = User(...))
|
| 142 |
+
line_9_refs = [ref for ref in user_refs if ref.get("range", {}).get("start", {}).get("line") == 8]
|
| 143 |
+
assert len(line_9_refs) > 0, "User should be referenced at line 9"
|
| 144 |
+
|
| 145 |
+
@pytest.mark.parametrize("language_server", [Language.SWIFT], indirect=True)
|
| 146 |
+
def test_request_references_utils_struct(self, language_server: SolidLanguageServer) -> None:
|
| 147 |
+
"""Test request_references on the Utils struct."""
|
| 148 |
+
# Get references to the Utils struct in utils.swift
|
| 149 |
+
file_path = os.path.join("src", "utils.swift")
|
| 150 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 151 |
+
utils_symbol = next((s for s in symbols[0] if s.get("name") == "Utils"), None)
|
| 152 |
+
if not utils_symbol or "selectionRange" not in utils_symbol:
|
| 153 |
+
raise AssertionError("Utils symbol or its selectionRange not found")
|
| 154 |
+
sel_start = utils_symbol["selectionRange"]["start"]
|
| 155 |
+
references = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 156 |
+
assert isinstance(references, list), "References should be a list"
|
| 157 |
+
assert len(references) > 0, "Utils struct should be referenced"
|
| 158 |
+
|
| 159 |
+
# Validate that Utils is referenced in main.swift
|
| 160 |
+
utils_refs = [ref for ref in references if ref.get("uri", "").endswith("main.swift")]
|
| 161 |
+
assert len(utils_refs) > 0, "Utils struct should be referenced in main.swift"
|
| 162 |
+
|
| 163 |
+
# Check that one reference is at line 12 (Utils.calculateArea call)
|
| 164 |
+
line_12_refs = [ref for ref in utils_refs if ref.get("range", {}).get("start", {}).get("line") == 11]
|
| 165 |
+
assert len(line_12_refs) > 0, "Utils should be referenced at line 12"
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
class TestSwiftProjectBasics:
|
| 169 |
+
@pytest.mark.parametrize("project", [Language.SWIFT], indirect=True)
|
| 170 |
+
def test_retrieve_content_around_line(self, project: Project) -> None:
|
| 171 |
+
"""Test retrieve_content_around_line functionality with various scenarios."""
|
| 172 |
+
file_path = os.path.join("src", "main.swift")
|
| 173 |
+
|
| 174 |
+
# Scenario 1: Find Calculator class definition
|
| 175 |
+
calculator_line = None
|
| 176 |
+
for line_num in range(1, 50): # Search first 50 lines
|
| 177 |
+
try:
|
| 178 |
+
line_content = project.retrieve_content_around_line(file_path, line_num)
|
| 179 |
+
if line_content.lines and "class Calculator" in line_content.lines[0].line_content:
|
| 180 |
+
calculator_line = line_num
|
| 181 |
+
break
|
| 182 |
+
except:
|
| 183 |
+
continue
|
| 184 |
+
|
| 185 |
+
assert calculator_line is not None, "Calculator class not found"
|
| 186 |
+
line_calc = project.retrieve_content_around_line(file_path, calculator_line)
|
| 187 |
+
assert len(line_calc.lines) == 1
|
| 188 |
+
assert "class Calculator" in line_calc.lines[0].line_content
|
| 189 |
+
assert line_calc.lines[0].line_number == calculator_line
|
| 190 |
+
assert line_calc.lines[0].match_type == LineType.MATCH
|
| 191 |
+
|
| 192 |
+
# Scenario 2: Context above and below Calculator class
|
| 193 |
+
with_context_around_calculator = project.retrieve_content_around_line(file_path, calculator_line, 2, 2)
|
| 194 |
+
assert len(with_context_around_calculator.lines) == 5
|
| 195 |
+
assert "class Calculator" in with_context_around_calculator.matched_lines[0].line_content
|
| 196 |
+
assert with_context_around_calculator.num_matched_lines == 1
|
| 197 |
+
|
| 198 |
+
# Scenario 3: Search for struct definitions
|
| 199 |
+
struct_pattern = r"struct\s+\w+"
|
| 200 |
+
matches = project.search_source_files_for_pattern(struct_pattern)
|
| 201 |
+
assert len(matches) > 0, "Should find struct definitions"
|
| 202 |
+
# Should find User struct
|
| 203 |
+
user_matches = [m for m in matches if "User" in str(m)]
|
| 204 |
+
assert len(user_matches) > 0, "Should find User struct"
|
| 205 |
+
|
| 206 |
+
# Scenario 4: Search for class definitions
|
| 207 |
+
class_pattern = r"class\s+\w+"
|
| 208 |
+
matches = project.search_source_files_for_pattern(class_pattern)
|
| 209 |
+
assert len(matches) > 0, "Should find class definitions"
|
| 210 |
+
# Should find Calculator and Circle classes
|
| 211 |
+
calculator_matches = [m for m in matches if "Calculator" in str(m)]
|
| 212 |
+
circle_matches = [m for m in matches if "Circle" in str(m)]
|
| 213 |
+
assert len(calculator_matches) > 0, "Should find Calculator class"
|
| 214 |
+
assert len(circle_matches) > 0, "Should find Circle class"
|
| 215 |
+
|
| 216 |
+
# Scenario 5: Search for enum definitions
|
| 217 |
+
enum_pattern = r"enum\s+\w+"
|
| 218 |
+
matches = project.search_source_files_for_pattern(enum_pattern)
|
| 219 |
+
assert len(matches) > 0, "Should find enum definitions"
|
| 220 |
+
# Should find Status enum
|
| 221 |
+
status_matches = [m for m in matches if "Status" in str(m)]
|
| 222 |
+
assert len(status_matches) > 0, "Should find Status enum"
|
projects/ui/serena-new/test/solidlsp/terraform/test_terraform_basic.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Basic integration tests for the Terraform language server functionality.
|
| 3 |
+
|
| 4 |
+
These tests validate the functionality of the language server APIs
|
| 5 |
+
like request_references using the test repository.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import pytest
|
| 9 |
+
|
| 10 |
+
from solidlsp import SolidLanguageServer
|
| 11 |
+
from solidlsp.ls_config import Language
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@pytest.mark.terraform
|
| 15 |
+
class TestLanguageServerBasics:
|
| 16 |
+
"""Test basic functionality of the Terraform language server."""
|
| 17 |
+
|
| 18 |
+
@pytest.mark.parametrize("language_server", [Language.TERRAFORM], indirect=True)
|
| 19 |
+
def test_basic_definition(self, language_server: SolidLanguageServer) -> None:
|
| 20 |
+
"""Test basic definition lookup functionality."""
|
| 21 |
+
# Simple test to verify the language server is working
|
| 22 |
+
file_path = "main.tf"
|
| 23 |
+
# Just try to get document symbols - this should work without hanging
|
| 24 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 25 |
+
assert len(symbols) > 0, "Should find at least some symbols in main.tf"
|
| 26 |
+
|
| 27 |
+
@pytest.mark.parametrize("language_server", [Language.TERRAFORM], indirect=True)
|
| 28 |
+
def test_request_references_aws_instance(self, language_server: SolidLanguageServer) -> None:
|
| 29 |
+
"""Test request_references on an aws_instance resource."""
|
| 30 |
+
# Get references to an aws_instance resource in main.tf
|
| 31 |
+
file_path = "main.tf"
|
| 32 |
+
# Find aws_instance resources
|
| 33 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 34 |
+
aws_instance_symbol = next((s for s in symbols[0] if s.get("name") == 'resource "aws_instance" "web_server"'), None)
|
| 35 |
+
if not aws_instance_symbol or "selectionRange" not in aws_instance_symbol:
|
| 36 |
+
raise AssertionError("aws_instance symbol or its selectionRange not found")
|
| 37 |
+
sel_start = aws_instance_symbol["selectionRange"]["start"]
|
| 38 |
+
references = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 39 |
+
assert len(references) >= 1, "aws_instance should be referenced at least once"
|
| 40 |
+
|
| 41 |
+
@pytest.mark.parametrize("language_server", [Language.TERRAFORM], indirect=True)
|
| 42 |
+
def test_request_references_variable(self, language_server: SolidLanguageServer) -> None:
|
| 43 |
+
"""Test request_references on a variable."""
|
| 44 |
+
# Get references to a variable in variables.tf
|
| 45 |
+
file_path = "variables.tf"
|
| 46 |
+
# Find variable definitions
|
| 47 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 48 |
+
var_symbol = next((s for s in symbols[0] if s.get("name") == 'variable "instance_type"'), None)
|
| 49 |
+
if not var_symbol or "selectionRange" not in var_symbol:
|
| 50 |
+
raise AssertionError("variable symbol or its selectionRange not found")
|
| 51 |
+
sel_start = var_symbol["selectionRange"]["start"]
|
| 52 |
+
references = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 53 |
+
assert len(references) >= 1, "variable should be referenced at least once"
|
projects/ui/serena-new/test/solidlsp/typescript/test_typescript_basic.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
from solidlsp import SolidLanguageServer
|
| 6 |
+
from solidlsp.ls_config import Language
|
| 7 |
+
from solidlsp.ls_utils import SymbolUtils
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@pytest.mark.typescript
|
| 11 |
+
class TestTypescriptLanguageServer:
|
| 12 |
+
@pytest.mark.parametrize("language_server", [Language.TYPESCRIPT], indirect=True)
|
| 13 |
+
def test_find_symbol(self, language_server: SolidLanguageServer) -> None:
|
| 14 |
+
symbols = language_server.request_full_symbol_tree()
|
| 15 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "DemoClass"), "DemoClass not found in symbol tree"
|
| 16 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "helperFunction"), "helperFunction not found in symbol tree"
|
| 17 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "printValue"), "printValue method not found in symbol tree"
|
| 18 |
+
|
| 19 |
+
@pytest.mark.parametrize("language_server", [Language.TYPESCRIPT], indirect=True)
|
| 20 |
+
def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:
|
| 21 |
+
file_path = os.path.join("index.ts")
|
| 22 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 23 |
+
helper_symbol = None
|
| 24 |
+
for sym in symbols[0]:
|
| 25 |
+
if sym.get("name") == "helperFunction":
|
| 26 |
+
helper_symbol = sym
|
| 27 |
+
break
|
| 28 |
+
assert helper_symbol is not None, "Could not find 'helperFunction' symbol in index.ts"
|
| 29 |
+
sel_start = helper_symbol["selectionRange"]["start"]
|
| 30 |
+
refs = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 31 |
+
assert any(
|
| 32 |
+
"index.ts" in ref.get("relativePath", "") for ref in refs
|
| 33 |
+
), "index.ts should reference helperFunction (tried all positions in selectionRange)"
|
projects/ui/serena-new/test/solidlsp/util/test_zip.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import zipfile
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
import pytest
|
| 6 |
+
|
| 7 |
+
from solidlsp.util.zip import SafeZipExtractor
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@pytest.fixture
|
| 11 |
+
def temp_zip_file(tmp_path: Path) -> Path:
|
| 12 |
+
"""Create a temporary ZIP file for testing."""
|
| 13 |
+
zip_path = tmp_path / "test.zip"
|
| 14 |
+
with zipfile.ZipFile(zip_path, "w") as zipf:
|
| 15 |
+
zipf.writestr("file1.txt", "Hello World 1")
|
| 16 |
+
zipf.writestr("file2.txt", "Hello World 2")
|
| 17 |
+
zipf.writestr("folder/file3.txt", "Hello World 3")
|
| 18 |
+
return zip_path
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def test_extract_all_success(temp_zip_file: Path, tmp_path: Path) -> None:
|
| 22 |
+
"""All files should extract without error."""
|
| 23 |
+
dest_dir = tmp_path / "extracted"
|
| 24 |
+
extractor = SafeZipExtractor(temp_zip_file, dest_dir, verbose=False)
|
| 25 |
+
extractor.extract_all()
|
| 26 |
+
|
| 27 |
+
assert (dest_dir / "file1.txt").read_text() == "Hello World 1"
|
| 28 |
+
assert (dest_dir / "file2.txt").read_text() == "Hello World 2"
|
| 29 |
+
assert (dest_dir / "folder" / "file3.txt").read_text() == "Hello World 3"
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def test_include_patterns(temp_zip_file: Path, tmp_path: Path) -> None:
|
| 33 |
+
"""Only files matching include_patterns should be extracted."""
|
| 34 |
+
dest_dir = tmp_path / "extracted"
|
| 35 |
+
extractor = SafeZipExtractor(temp_zip_file, dest_dir, verbose=False, include_patterns=["*.txt"])
|
| 36 |
+
extractor.extract_all()
|
| 37 |
+
|
| 38 |
+
assert (dest_dir / "file1.txt").exists()
|
| 39 |
+
assert (dest_dir / "file2.txt").exists()
|
| 40 |
+
assert (dest_dir / "folder" / "file3.txt").exists()
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def test_exclude_patterns(temp_zip_file: Path, tmp_path: Path) -> None:
|
| 44 |
+
"""Files matching exclude_patterns should be skipped."""
|
| 45 |
+
dest_dir = tmp_path / "extracted"
|
| 46 |
+
extractor = SafeZipExtractor(temp_zip_file, dest_dir, verbose=False, exclude_patterns=["file2.txt"])
|
| 47 |
+
extractor.extract_all()
|
| 48 |
+
|
| 49 |
+
assert (dest_dir / "file1.txt").exists()
|
| 50 |
+
assert not (dest_dir / "file2.txt").exists()
|
| 51 |
+
assert (dest_dir / "folder" / "file3.txt").exists()
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def test_include_and_exclude_patterns(temp_zip_file: Path, tmp_path: Path) -> None:
|
| 55 |
+
"""Exclude should override include if both match."""
|
| 56 |
+
dest_dir = tmp_path / "extracted"
|
| 57 |
+
extractor = SafeZipExtractor(
|
| 58 |
+
temp_zip_file,
|
| 59 |
+
dest_dir,
|
| 60 |
+
verbose=False,
|
| 61 |
+
include_patterns=["*.txt"],
|
| 62 |
+
exclude_patterns=["file1.txt"],
|
| 63 |
+
)
|
| 64 |
+
extractor.extract_all()
|
| 65 |
+
|
| 66 |
+
assert not (dest_dir / "file1.txt").exists()
|
| 67 |
+
assert (dest_dir / "file2.txt").exists()
|
| 68 |
+
assert (dest_dir / "folder" / "file3.txt").exists()
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def test_skip_on_error(monkeypatch, temp_zip_file: Path, tmp_path: Path) -> None:
|
| 72 |
+
"""Should skip a file that raises an error and continue extracting others."""
|
| 73 |
+
dest_dir = tmp_path / "extracted"
|
| 74 |
+
|
| 75 |
+
original_open = zipfile.ZipFile.open
|
| 76 |
+
|
| 77 |
+
def failing_open(self, member, *args, **kwargs):
|
| 78 |
+
if member.filename == "file2.txt":
|
| 79 |
+
raise OSError("Simulated failure")
|
| 80 |
+
return original_open(self, member, *args, **kwargs)
|
| 81 |
+
|
| 82 |
+
# Patch the method on the class, not on an instance
|
| 83 |
+
monkeypatch.setattr(zipfile.ZipFile, "open", failing_open)
|
| 84 |
+
|
| 85 |
+
extractor = SafeZipExtractor(temp_zip_file, dest_dir, verbose=False)
|
| 86 |
+
extractor.extract_all()
|
| 87 |
+
|
| 88 |
+
assert (dest_dir / "file1.txt").exists()
|
| 89 |
+
assert not (dest_dir / "file2.txt").exists()
|
| 90 |
+
assert (dest_dir / "folder" / "file3.txt").exists()
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
@pytest.mark.skipif(not sys.platform.startswith("win"), reason="Windows-only test")
|
| 94 |
+
def test_long_path_normalization(temp_zip_file: Path, tmp_path: Path) -> None:
|
| 95 |
+
r"""Ensure _normalize_path adds \\?\\ prefix on Windows."""
|
| 96 |
+
dest_dir = tmp_path / ("a" * 250) # Simulate long path
|
| 97 |
+
extractor = SafeZipExtractor(temp_zip_file, dest_dir, verbose=False)
|
| 98 |
+
norm_path = extractor._normalize_path(dest_dir / "file.txt")
|
| 99 |
+
assert str(norm_path).startswith("\\\\?\\")
|