Add files using upload-large-folder tool
Browse files- projects/ui/serena-new/test/serena/config/test_serena_config.py +138 -0
- projects/ui/serena-new/test/serena/util/test_exception.py +116 -0
- projects/ui/serena-new/test/serena/util/test_file_system.py +708 -0
- projects/ui/serena-new/test/solidlsp/bash/__init__.py +0 -0
- projects/ui/serena-new/test/solidlsp/bash/test_bash_basic.py +121 -0
- projects/ui/serena-new/test/solidlsp/clojure/__init__.py +17 -0
- projects/ui/serena-new/test/solidlsp/clojure/test_clojure_basic.py +222 -0
- projects/ui/serena-new/test/solidlsp/csharp/test_csharp_basic.py +307 -0
- projects/ui/serena-new/test/solidlsp/dart/__init__.py +0 -0
- projects/ui/serena-new/test/solidlsp/dart/test_dart_basic.py +357 -0
- projects/ui/serena-new/test/solidlsp/elixir/__init__.py +28 -0
- projects/ui/serena-new/test/solidlsp/elixir/conftest.py +174 -0
- projects/ui/serena-new/test/solidlsp/elixir/test_elixir_basic.py +112 -0
- projects/ui/serena-new/test/solidlsp/elixir/test_elixir_ignored_dirs.py +142 -0
- projects/ui/serena-new/test/solidlsp/elixir/test_elixir_integration.py +160 -0
- projects/ui/serena-new/test/solidlsp/elixir/test_elixir_symbol_retrieval.py +342 -0
- projects/ui/serena-new/test/solidlsp/erlang/__init__.py +33 -0
- projects/ui/serena-new/test/solidlsp/erlang/conftest.py +174 -0
- projects/ui/serena-new/test/solidlsp/erlang/test_erlang_basic.py +43 -0
- projects/ui/serena-new/test/solidlsp/erlang/test_erlang_ignored_dirs.py +227 -0
projects/ui/serena-new/test/serena/config/test_serena_config.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import shutil
|
| 2 |
+
import tempfile
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
import pytest
|
| 6 |
+
|
| 7 |
+
from serena.config.serena_config import ProjectConfig
|
| 8 |
+
from solidlsp.ls_config import Language
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class TestProjectConfigAutogenerate:
|
| 12 |
+
"""Test class for ProjectConfig autogeneration functionality."""
|
| 13 |
+
|
| 14 |
+
def setup_method(self):
|
| 15 |
+
"""Set up test environment before each test method."""
|
| 16 |
+
# Create a temporary directory for testing
|
| 17 |
+
self.test_dir = tempfile.mkdtemp()
|
| 18 |
+
self.project_path = Path(self.test_dir)
|
| 19 |
+
|
| 20 |
+
def teardown_method(self):
|
| 21 |
+
"""Clean up test environment after each test method."""
|
| 22 |
+
# Remove the temporary directory
|
| 23 |
+
shutil.rmtree(self.test_dir)
|
| 24 |
+
|
| 25 |
+
def test_autogenerate_empty_directory(self):
|
| 26 |
+
"""Test that autogenerate raises ValueError with helpful message for empty directory."""
|
| 27 |
+
with pytest.raises(ValueError) as exc_info:
|
| 28 |
+
ProjectConfig.autogenerate(self.project_path, save_to_disk=False)
|
| 29 |
+
|
| 30 |
+
error_message = str(exc_info.value)
|
| 31 |
+
# Check that the error message contains all the key information
|
| 32 |
+
assert "No source files found" in error_message
|
| 33 |
+
assert str(self.project_path.resolve()) in error_message
|
| 34 |
+
assert "To use Serena with this project" in error_message
|
| 35 |
+
assert "Add source files in one of the supported languages" in error_message
|
| 36 |
+
assert "Create a project configuration file manually" in error_message
|
| 37 |
+
assert str(Path(".serena") / "project.yml") in error_message
|
| 38 |
+
assert "Example project.yml:" in error_message
|
| 39 |
+
assert f"project_name: {self.project_path.name}" in error_message
|
| 40 |
+
assert "language: python" in error_message
|
| 41 |
+
|
| 42 |
+
def test_autogenerate_with_python_files(self):
|
| 43 |
+
"""Test successful autogeneration with Python source files."""
|
| 44 |
+
# Create a Python file
|
| 45 |
+
python_file = self.project_path / "main.py"
|
| 46 |
+
python_file.write_text("def hello():\n print('Hello, world!')\n")
|
| 47 |
+
|
| 48 |
+
# Run autogenerate
|
| 49 |
+
config = ProjectConfig.autogenerate(self.project_path, save_to_disk=False)
|
| 50 |
+
|
| 51 |
+
# Verify the configuration
|
| 52 |
+
assert config.project_name == self.project_path.name
|
| 53 |
+
assert config.language == Language.PYTHON
|
| 54 |
+
|
| 55 |
+
def test_autogenerate_with_multiple_languages(self):
|
| 56 |
+
"""Test autogeneration picks dominant language when multiple are present."""
|
| 57 |
+
# Create files for multiple languages
|
| 58 |
+
(self.project_path / "main.py").write_text("print('Python')")
|
| 59 |
+
(self.project_path / "util.py").write_text("def util(): pass")
|
| 60 |
+
(self.project_path / "small.js").write_text("console.log('JS');")
|
| 61 |
+
|
| 62 |
+
# Run autogenerate - should pick Python as dominant
|
| 63 |
+
config = ProjectConfig.autogenerate(self.project_path, save_to_disk=False)
|
| 64 |
+
|
| 65 |
+
assert config.language == Language.PYTHON
|
| 66 |
+
|
| 67 |
+
def test_autogenerate_saves_to_disk(self):
|
| 68 |
+
"""Test that autogenerate can save the configuration to disk."""
|
| 69 |
+
# Create a Go file
|
| 70 |
+
go_file = self.project_path / "main.go"
|
| 71 |
+
go_file.write_text("package main\n\nfunc main() {}\n")
|
| 72 |
+
|
| 73 |
+
# Run autogenerate with save_to_disk=True
|
| 74 |
+
config = ProjectConfig.autogenerate(self.project_path, save_to_disk=True)
|
| 75 |
+
|
| 76 |
+
# Verify the configuration file was created
|
| 77 |
+
config_path = self.project_path / ".serena" / "project.yml"
|
| 78 |
+
assert config_path.exists()
|
| 79 |
+
|
| 80 |
+
# Verify the content
|
| 81 |
+
assert config.language == Language.GO
|
| 82 |
+
|
| 83 |
+
def test_autogenerate_nonexistent_path(self):
|
| 84 |
+
"""Test that autogenerate raises FileNotFoundError for non-existent path."""
|
| 85 |
+
non_existent = self.project_path / "does_not_exist"
|
| 86 |
+
|
| 87 |
+
with pytest.raises(FileNotFoundError) as exc_info:
|
| 88 |
+
ProjectConfig.autogenerate(non_existent, save_to_disk=False)
|
| 89 |
+
|
| 90 |
+
assert "Project root not found" in str(exc_info.value)
|
| 91 |
+
|
| 92 |
+
def test_autogenerate_with_gitignored_files_only(self):
|
| 93 |
+
"""Test autogenerate behavior when only gitignored files exist."""
|
| 94 |
+
# Create a .gitignore that ignores all Python files
|
| 95 |
+
gitignore = self.project_path / ".gitignore"
|
| 96 |
+
gitignore.write_text("*.py\n")
|
| 97 |
+
|
| 98 |
+
# Create Python files that will be ignored
|
| 99 |
+
(self.project_path / "ignored.py").write_text("print('ignored')")
|
| 100 |
+
|
| 101 |
+
# Should still raise ValueError as no source files are detected
|
| 102 |
+
with pytest.raises(ValueError) as exc_info:
|
| 103 |
+
ProjectConfig.autogenerate(self.project_path, save_to_disk=False)
|
| 104 |
+
|
| 105 |
+
assert "No source files found" in str(exc_info.value)
|
| 106 |
+
|
| 107 |
+
def test_autogenerate_custom_project_name(self):
|
| 108 |
+
"""Test autogenerate with custom project name."""
|
| 109 |
+
# Create a TypeScript file
|
| 110 |
+
ts_file = self.project_path / "index.ts"
|
| 111 |
+
ts_file.write_text("const greeting: string = 'Hello';\n")
|
| 112 |
+
|
| 113 |
+
# Run autogenerate with custom name
|
| 114 |
+
custom_name = "my-custom-project"
|
| 115 |
+
config = ProjectConfig.autogenerate(self.project_path, project_name=custom_name, save_to_disk=False)
|
| 116 |
+
|
| 117 |
+
assert config.project_name == custom_name
|
| 118 |
+
assert config.language == Language.TYPESCRIPT
|
| 119 |
+
|
| 120 |
+
def test_autogenerate_error_message_format(self):
|
| 121 |
+
"""Test the specific format of the error message for better user experience."""
|
| 122 |
+
with pytest.raises(ValueError) as exc_info:
|
| 123 |
+
ProjectConfig.autogenerate(self.project_path, save_to_disk=False)
|
| 124 |
+
|
| 125 |
+
error_lines = str(exc_info.value).split("\n")
|
| 126 |
+
|
| 127 |
+
# Verify the structure of the error message
|
| 128 |
+
assert len(error_lines) >= 8 # Should have multiple lines of helpful information
|
| 129 |
+
|
| 130 |
+
# Check for numbered instructions
|
| 131 |
+
assert any("1." in line for line in error_lines)
|
| 132 |
+
assert any("2." in line for line in error_lines)
|
| 133 |
+
|
| 134 |
+
# Check for supported languages list
|
| 135 |
+
assert any("Python" in line and "TypeScript" in line for line in error_lines)
|
| 136 |
+
|
| 137 |
+
# Check example includes comment about language options
|
| 138 |
+
assert any("# or typescript, java, csharp" in line for line in error_lines)
|
projects/ui/serena-new/test/serena/util/test_exception.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from unittest.mock import MagicMock, Mock, patch
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
from serena.util.exception import is_headless_environment, show_fatal_exception_safe
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class TestHeadlessEnvironmentDetection:
|
| 10 |
+
"""Test class for headless environment detection functionality."""
|
| 11 |
+
|
| 12 |
+
def test_is_headless_no_display(self):
|
| 13 |
+
"""Test that environment without DISPLAY is detected as headless on Linux."""
|
| 14 |
+
with patch("sys.platform", "linux"):
|
| 15 |
+
with patch.dict(os.environ, {}, clear=True):
|
| 16 |
+
assert is_headless_environment() is True
|
| 17 |
+
|
| 18 |
+
def test_is_headless_ssh_connection(self):
|
| 19 |
+
"""Test that SSH sessions are detected as headless."""
|
| 20 |
+
with patch("sys.platform", "linux"):
|
| 21 |
+
with patch.dict(os.environ, {"SSH_CONNECTION": "192.168.1.1 22 192.168.1.2 22", "DISPLAY": ":0"}):
|
| 22 |
+
assert is_headless_environment() is True
|
| 23 |
+
|
| 24 |
+
with patch.dict(os.environ, {"SSH_CLIENT": "192.168.1.1 22 22", "DISPLAY": ":0"}):
|
| 25 |
+
assert is_headless_environment() is True
|
| 26 |
+
|
| 27 |
+
def test_is_headless_wsl(self):
|
| 28 |
+
"""Test that WSL environment is detected as headless."""
|
| 29 |
+
# Skip this test on Windows since os.uname doesn't exist
|
| 30 |
+
if not hasattr(os, "uname"):
|
| 31 |
+
pytest.skip("os.uname not available on this platform")
|
| 32 |
+
|
| 33 |
+
with patch("sys.platform", "linux"):
|
| 34 |
+
with patch("os.uname") as mock_uname:
|
| 35 |
+
mock_uname.return_value = Mock(release="5.15.153.1-microsoft-standard-WSL2")
|
| 36 |
+
with patch.dict(os.environ, {"DISPLAY": ":0"}):
|
| 37 |
+
assert is_headless_environment() is True
|
| 38 |
+
|
| 39 |
+
def test_is_headless_docker(self):
|
| 40 |
+
"""Test that Docker containers are detected as headless."""
|
| 41 |
+
with patch("sys.platform", "linux"):
|
| 42 |
+
# Test with CI environment variable
|
| 43 |
+
with patch.dict(os.environ, {"CI": "true", "DISPLAY": ":0"}):
|
| 44 |
+
assert is_headless_environment() is True
|
| 45 |
+
|
| 46 |
+
# Test with CONTAINER environment variable
|
| 47 |
+
with patch.dict(os.environ, {"CONTAINER": "docker", "DISPLAY": ":0"}):
|
| 48 |
+
assert is_headless_environment() is True
|
| 49 |
+
|
| 50 |
+
# Test with .dockerenv file
|
| 51 |
+
with patch("os.path.exists") as mock_exists:
|
| 52 |
+
mock_exists.return_value = True
|
| 53 |
+
with patch.dict(os.environ, {"DISPLAY": ":0"}):
|
| 54 |
+
assert is_headless_environment() is True
|
| 55 |
+
|
| 56 |
+
def test_is_not_headless_windows(self):
|
| 57 |
+
"""Test that Windows is never detected as headless."""
|
| 58 |
+
with patch("sys.platform", "win32"):
|
| 59 |
+
# Even without DISPLAY, Windows should not be headless
|
| 60 |
+
with patch.dict(os.environ, {}, clear=True):
|
| 61 |
+
assert is_headless_environment() is False
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class TestShowFatalExceptionSafe:
|
| 65 |
+
"""Test class for safe fatal exception display functionality."""
|
| 66 |
+
|
| 67 |
+
@patch("serena.util.exception.is_headless_environment", return_value=True)
|
| 68 |
+
@patch("serena.util.exception.log")
|
| 69 |
+
def test_show_fatal_exception_safe_headless(self, mock_log, mock_is_headless):
|
| 70 |
+
"""Test that GUI is not attempted in headless environment."""
|
| 71 |
+
test_exception = ValueError("Test error")
|
| 72 |
+
|
| 73 |
+
# The import should never happen in headless mode
|
| 74 |
+
with patch("serena.gui_log_viewer.show_fatal_exception") as mock_show_gui:
|
| 75 |
+
show_fatal_exception_safe(test_exception)
|
| 76 |
+
mock_show_gui.assert_not_called()
|
| 77 |
+
|
| 78 |
+
# Verify debug log about skipping GUI
|
| 79 |
+
mock_log.debug.assert_called_once_with("Skipping GUI error display in headless environment")
|
| 80 |
+
|
| 81 |
+
@patch("serena.util.exception.is_headless_environment", return_value=False)
|
| 82 |
+
@patch("serena.util.exception.log")
|
| 83 |
+
def test_show_fatal_exception_safe_with_gui(self, mock_log, mock_is_headless):
|
| 84 |
+
"""Test that GUI is attempted when not in headless environment."""
|
| 85 |
+
test_exception = ValueError("Test error")
|
| 86 |
+
|
| 87 |
+
# Mock the GUI function
|
| 88 |
+
with patch("serena.gui_log_viewer.show_fatal_exception") as mock_show_gui:
|
| 89 |
+
show_fatal_exception_safe(test_exception)
|
| 90 |
+
mock_show_gui.assert_called_once_with(test_exception)
|
| 91 |
+
|
| 92 |
+
@patch("serena.util.exception.is_headless_environment", return_value=False)
|
| 93 |
+
@patch("serena.util.exception.log")
|
| 94 |
+
def test_show_fatal_exception_safe_gui_failure(self, mock_log, mock_is_headless):
|
| 95 |
+
"""Test graceful handling when GUI display fails."""
|
| 96 |
+
test_exception = ValueError("Test error")
|
| 97 |
+
gui_error = ImportError("No module named 'tkinter'")
|
| 98 |
+
|
| 99 |
+
# Mock the GUI function to raise an exception
|
| 100 |
+
with patch("serena.gui_log_viewer.show_fatal_exception", side_effect=gui_error):
|
| 101 |
+
show_fatal_exception_safe(test_exception)
|
| 102 |
+
|
| 103 |
+
# Verify debug log about GUI failure
|
| 104 |
+
mock_log.debug.assert_called_with(f"Failed to show GUI error dialog: {gui_error}")
|
| 105 |
+
|
| 106 |
+
def test_show_fatal_exception_safe_prints_to_stderr(self):
|
| 107 |
+
"""Test that exceptions are always printed to stderr."""
|
| 108 |
+
test_exception = ValueError("Test error message")
|
| 109 |
+
|
| 110 |
+
with patch("sys.stderr", new_callable=MagicMock) as mock_stderr:
|
| 111 |
+
with patch("serena.util.exception.is_headless_environment", return_value=True):
|
| 112 |
+
with patch("serena.util.exception.log"):
|
| 113 |
+
show_fatal_exception_safe(test_exception)
|
| 114 |
+
|
| 115 |
+
# Verify print was called with the correct arguments
|
| 116 |
+
mock_stderr.write.assert_any_call("Fatal exception: Test error message")
|
projects/ui/serena-new/test/serena/util/test_file_system.py
ADDED
|
@@ -0,0 +1,708 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
import tempfile
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
# Assuming the gitignore parser code is in a module named 'gitignore_parser'
|
| 7 |
+
from serena.util.file_system import GitignoreParser, GitignoreSpec
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class TestGitignoreParser:
|
| 11 |
+
"""Test class for GitignoreParser functionality."""
|
| 12 |
+
|
| 13 |
+
def setup_method(self):
|
| 14 |
+
"""Set up test environment before each test method."""
|
| 15 |
+
# Create a temporary directory for testing
|
| 16 |
+
self.test_dir = tempfile.mkdtemp()
|
| 17 |
+
self.repo_path = Path(self.test_dir)
|
| 18 |
+
|
| 19 |
+
# Create test repository structure
|
| 20 |
+
self._create_repo_structure()
|
| 21 |
+
|
| 22 |
+
def teardown_method(self):
|
| 23 |
+
"""Clean up test environment after each test method."""
|
| 24 |
+
# Remove the temporary directory
|
| 25 |
+
shutil.rmtree(self.test_dir)
|
| 26 |
+
|
| 27 |
+
def _create_repo_structure(self):
|
| 28 |
+
"""
|
| 29 |
+
Create a test repository structure with multiple gitignore files.
|
| 30 |
+
|
| 31 |
+
Structure:
|
| 32 |
+
repo/
|
| 33 |
+
├── .gitignore
|
| 34 |
+
├── file1.txt
|
| 35 |
+
├── test.log
|
| 36 |
+
├── src/
|
| 37 |
+
│ ├── .gitignore
|
| 38 |
+
│ ├── main.py
|
| 39 |
+
│ ├── test.log
|
| 40 |
+
│ ├── build/
|
| 41 |
+
│ │ └── output.o
|
| 42 |
+
│ └── lib/
|
| 43 |
+
│ ├── .gitignore
|
| 44 |
+
│ └── cache.tmp
|
| 45 |
+
└── docs/
|
| 46 |
+
├── .gitignore
|
| 47 |
+
├── api.md
|
| 48 |
+
└── temp/
|
| 49 |
+
└── draft.md
|
| 50 |
+
"""
|
| 51 |
+
# Create directories
|
| 52 |
+
(self.repo_path / "src").mkdir()
|
| 53 |
+
(self.repo_path / "src" / "build").mkdir()
|
| 54 |
+
(self.repo_path / "src" / "lib").mkdir()
|
| 55 |
+
(self.repo_path / "docs").mkdir()
|
| 56 |
+
(self.repo_path / "docs" / "temp").mkdir()
|
| 57 |
+
|
| 58 |
+
# Create files
|
| 59 |
+
(self.repo_path / "file1.txt").touch()
|
| 60 |
+
(self.repo_path / "test.log").touch()
|
| 61 |
+
(self.repo_path / "src" / "main.py").touch()
|
| 62 |
+
(self.repo_path / "src" / "test.log").touch()
|
| 63 |
+
(self.repo_path / "src" / "build" / "output.o").touch()
|
| 64 |
+
(self.repo_path / "src" / "lib" / "cache.tmp").touch()
|
| 65 |
+
(self.repo_path / "docs" / "api.md").touch()
|
| 66 |
+
(self.repo_path / "docs" / "temp" / "draft.md").touch()
|
| 67 |
+
|
| 68 |
+
# Create root .gitignore
|
| 69 |
+
root_gitignore = self.repo_path / ".gitignore"
|
| 70 |
+
root_gitignore.write_text(
|
| 71 |
+
"""# Root gitignore
|
| 72 |
+
*.log
|
| 73 |
+
/build/
|
| 74 |
+
"""
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
# Create src/.gitignore
|
| 78 |
+
src_gitignore = self.repo_path / "src" / ".gitignore"
|
| 79 |
+
src_gitignore.write_text(
|
| 80 |
+
"""# Source gitignore
|
| 81 |
+
*.o
|
| 82 |
+
build/
|
| 83 |
+
!important.log
|
| 84 |
+
"""
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
# Create src/lib/.gitignore (deeply nested)
|
| 88 |
+
src_lib_gitignore = self.repo_path / "src" / "lib" / ".gitignore"
|
| 89 |
+
src_lib_gitignore.write_text(
|
| 90 |
+
"""# Library gitignore
|
| 91 |
+
*.tmp
|
| 92 |
+
*.cache
|
| 93 |
+
"""
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
# Create docs/.gitignore
|
| 97 |
+
docs_gitignore = self.repo_path / "docs" / ".gitignore"
|
| 98 |
+
docs_gitignore.write_text(
|
| 99 |
+
"""# Docs gitignore
|
| 100 |
+
temp/
|
| 101 |
+
*.tmp
|
| 102 |
+
"""
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
def test_initialization(self):
|
| 106 |
+
"""Test GitignoreParser initialization."""
|
| 107 |
+
parser = GitignoreParser(str(self.repo_path))
|
| 108 |
+
|
| 109 |
+
assert parser.repo_root == str(self.repo_path.absolute())
|
| 110 |
+
assert len(parser.get_ignore_specs()) == 4
|
| 111 |
+
|
| 112 |
+
def test_find_gitignore_files(self):
|
| 113 |
+
"""Test finding all gitignore files in repository, including deeply nested ones."""
|
| 114 |
+
parser = GitignoreParser(str(self.repo_path))
|
| 115 |
+
|
| 116 |
+
# Get file paths from specs
|
| 117 |
+
gitignore_files = [spec.file_path for spec in parser.get_ignore_specs()]
|
| 118 |
+
|
| 119 |
+
# Convert to relative paths for easier testing
|
| 120 |
+
rel_paths = [os.path.relpath(f, self.repo_path) for f in gitignore_files]
|
| 121 |
+
rel_paths.sort()
|
| 122 |
+
|
| 123 |
+
assert len(rel_paths) == 4
|
| 124 |
+
assert ".gitignore" in rel_paths
|
| 125 |
+
assert os.path.join("src", ".gitignore") in rel_paths
|
| 126 |
+
assert os.path.join("src", "lib", ".gitignore") in rel_paths # Deeply nested
|
| 127 |
+
assert os.path.join("docs", ".gitignore") in rel_paths
|
| 128 |
+
|
| 129 |
+
def test_parse_patterns_root_directory(self):
|
| 130 |
+
"""Test parsing gitignore patterns in root directory."""
|
| 131 |
+
# Create a simple test case with only root gitignore
|
| 132 |
+
test_dir = self.repo_path / "test_root"
|
| 133 |
+
test_dir.mkdir()
|
| 134 |
+
|
| 135 |
+
gitignore = test_dir / ".gitignore"
|
| 136 |
+
gitignore.write_text(
|
| 137 |
+
"""*.log
|
| 138 |
+
build/
|
| 139 |
+
/temp.txt
|
| 140 |
+
"""
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
parser = GitignoreParser(str(test_dir))
|
| 144 |
+
specs = parser.get_ignore_specs()
|
| 145 |
+
|
| 146 |
+
assert len(specs) == 1
|
| 147 |
+
patterns = specs[0].patterns
|
| 148 |
+
|
| 149 |
+
assert "*.log" in patterns
|
| 150 |
+
assert "build/" in patterns
|
| 151 |
+
assert "/temp.txt" in patterns
|
| 152 |
+
|
| 153 |
+
def test_parse_patterns_subdirectory(self):
|
| 154 |
+
"""Test parsing gitignore patterns in subdirectory."""
|
| 155 |
+
# Create a test case with subdirectory gitignore
|
| 156 |
+
test_dir = self.repo_path / "test_sub"
|
| 157 |
+
test_dir.mkdir()
|
| 158 |
+
subdir = test_dir / "src"
|
| 159 |
+
subdir.mkdir()
|
| 160 |
+
|
| 161 |
+
gitignore = subdir / ".gitignore"
|
| 162 |
+
gitignore.write_text(
|
| 163 |
+
"""*.o
|
| 164 |
+
/build/
|
| 165 |
+
test.log
|
| 166 |
+
"""
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
parser = GitignoreParser(str(test_dir))
|
| 170 |
+
specs = parser.get_ignore_specs()
|
| 171 |
+
|
| 172 |
+
assert len(specs) == 1
|
| 173 |
+
patterns = specs[0].patterns
|
| 174 |
+
|
| 175 |
+
# Non-anchored pattern should get ** prefix
|
| 176 |
+
assert "src/**/*.o" in patterns
|
| 177 |
+
# Anchored pattern should not get ** prefix
|
| 178 |
+
assert "src/build/" in patterns
|
| 179 |
+
# Non-anchored pattern without slash
|
| 180 |
+
assert "src/**/test.log" in patterns
|
| 181 |
+
|
| 182 |
+
def test_should_ignore_root_patterns(self):
|
| 183 |
+
"""Test ignoring files based on root .gitignore."""
|
| 184 |
+
parser = GitignoreParser(str(self.repo_path))
|
| 185 |
+
|
| 186 |
+
# Files that should be ignored
|
| 187 |
+
assert parser.should_ignore("test.log")
|
| 188 |
+
assert parser.should_ignore(str(self.repo_path / "test.log"))
|
| 189 |
+
|
| 190 |
+
# Files that should NOT be ignored
|
| 191 |
+
assert not parser.should_ignore("file1.txt")
|
| 192 |
+
assert not parser.should_ignore("src/main.py")
|
| 193 |
+
|
| 194 |
+
def test_should_ignore_subdirectory_patterns(self):
|
| 195 |
+
"""Test ignoring files based on subdirectory .gitignore files."""
|
| 196 |
+
parser = GitignoreParser(str(self.repo_path))
|
| 197 |
+
|
| 198 |
+
# .o files in src should be ignored
|
| 199 |
+
assert parser.should_ignore("src/build/output.o")
|
| 200 |
+
|
| 201 |
+
# build/ directory in src should be ignored
|
| 202 |
+
assert parser.should_ignore("src/build/")
|
| 203 |
+
|
| 204 |
+
# temp/ directory in docs should be ignored
|
| 205 |
+
assert parser.should_ignore("docs/temp/draft.md")
|
| 206 |
+
|
| 207 |
+
# But temp/ outside docs should not be ignored by docs/.gitignore
|
| 208 |
+
assert not parser.should_ignore("temp/file.txt")
|
| 209 |
+
|
| 210 |
+
# Test deeply nested .gitignore in src/lib/
|
| 211 |
+
# .tmp files in src/lib should be ignored
|
| 212 |
+
assert parser.should_ignore("src/lib/cache.tmp")
|
| 213 |
+
|
| 214 |
+
# .cache files in src/lib should also be ignored
|
| 215 |
+
assert parser.should_ignore("src/lib/data.cache")
|
| 216 |
+
|
| 217 |
+
# But .tmp files outside src/lib should not be ignored by src/lib/.gitignore
|
| 218 |
+
assert not parser.should_ignore("src/other.tmp")
|
| 219 |
+
|
| 220 |
+
def test_anchored_vs_non_anchored_patterns(self):
|
| 221 |
+
"""Test the difference between anchored and non-anchored patterns."""
|
| 222 |
+
# Create new test structure
|
| 223 |
+
test_dir = self.repo_path / "test_anchored"
|
| 224 |
+
test_dir.mkdir()
|
| 225 |
+
(test_dir / "src").mkdir()
|
| 226 |
+
(test_dir / "src" / "subdir").mkdir()
|
| 227 |
+
(test_dir / "src" / "subdir" / "deep").mkdir()
|
| 228 |
+
|
| 229 |
+
# Create src/.gitignore with both anchored and non-anchored patterns
|
| 230 |
+
gitignore = test_dir / "src" / ".gitignore"
|
| 231 |
+
gitignore.write_text(
|
| 232 |
+
"""/temp.txt
|
| 233 |
+
data.json
|
| 234 |
+
"""
|
| 235 |
+
)
|
| 236 |
+
|
| 237 |
+
# Create test files
|
| 238 |
+
(test_dir / "src" / "temp.txt").touch()
|
| 239 |
+
(test_dir / "src" / "data.json").touch()
|
| 240 |
+
(test_dir / "src" / "subdir" / "temp.txt").touch()
|
| 241 |
+
(test_dir / "src" / "subdir" / "data.json").touch()
|
| 242 |
+
(test_dir / "src" / "subdir" / "deep" / "data.json").touch()
|
| 243 |
+
|
| 244 |
+
parser = GitignoreParser(str(test_dir))
|
| 245 |
+
|
| 246 |
+
# Anchored pattern /temp.txt should only match in src/
|
| 247 |
+
assert parser.should_ignore("src/temp.txt")
|
| 248 |
+
assert not parser.should_ignore("src/subdir/temp.txt")
|
| 249 |
+
|
| 250 |
+
# Non-anchored pattern data.json should match anywhere under src/
|
| 251 |
+
assert parser.should_ignore("src/data.json")
|
| 252 |
+
assert parser.should_ignore("src/subdir/data.json")
|
| 253 |
+
assert parser.should_ignore("src/subdir/deep/data.json")
|
| 254 |
+
|
| 255 |
+
def test_root_anchored_patterns(self):
|
| 256 |
+
"""Test anchored patterns in root .gitignore only match root-level files."""
|
| 257 |
+
# Create new test structure for root anchored patterns
|
| 258 |
+
test_dir = self.repo_path / "test_root_anchored"
|
| 259 |
+
test_dir.mkdir()
|
| 260 |
+
(test_dir / "src").mkdir()
|
| 261 |
+
(test_dir / "docs").mkdir()
|
| 262 |
+
(test_dir / "src" / "nested").mkdir()
|
| 263 |
+
|
| 264 |
+
# Create root .gitignore with anchored patterns
|
| 265 |
+
gitignore = test_dir / ".gitignore"
|
| 266 |
+
gitignore.write_text(
|
| 267 |
+
"""/config.json
|
| 268 |
+
/temp.log
|
| 269 |
+
/build
|
| 270 |
+
*.pyc
|
| 271 |
+
"""
|
| 272 |
+
)
|
| 273 |
+
|
| 274 |
+
# Create test files at root level
|
| 275 |
+
(test_dir / "config.json").touch()
|
| 276 |
+
(test_dir / "temp.log").touch()
|
| 277 |
+
(test_dir / "build").mkdir()
|
| 278 |
+
(test_dir / "file.pyc").touch()
|
| 279 |
+
|
| 280 |
+
# Create same-named files in subdirectories
|
| 281 |
+
(test_dir / "src" / "config.json").touch()
|
| 282 |
+
(test_dir / "src" / "temp.log").touch()
|
| 283 |
+
(test_dir / "src" / "build").mkdir()
|
| 284 |
+
(test_dir / "src" / "file.pyc").touch()
|
| 285 |
+
(test_dir / "docs" / "config.json").touch()
|
| 286 |
+
(test_dir / "docs" / "temp.log").touch()
|
| 287 |
+
(test_dir / "src" / "nested" / "config.json").touch()
|
| 288 |
+
(test_dir / "src" / "nested" / "temp.log").touch()
|
| 289 |
+
(test_dir / "src" / "nested" / "build").mkdir()
|
| 290 |
+
|
| 291 |
+
parser = GitignoreParser(str(test_dir))
|
| 292 |
+
|
| 293 |
+
# Anchored patterns should only match root-level files
|
| 294 |
+
assert parser.should_ignore("config.json")
|
| 295 |
+
assert not parser.should_ignore("src/config.json")
|
| 296 |
+
assert not parser.should_ignore("docs/config.json")
|
| 297 |
+
assert not parser.should_ignore("src/nested/config.json")
|
| 298 |
+
|
| 299 |
+
assert parser.should_ignore("temp.log")
|
| 300 |
+
assert not parser.should_ignore("src/temp.log")
|
| 301 |
+
assert not parser.should_ignore("docs/temp.log")
|
| 302 |
+
assert not parser.should_ignore("src/nested/temp.log")
|
| 303 |
+
|
| 304 |
+
assert parser.should_ignore("build")
|
| 305 |
+
assert not parser.should_ignore("src/build")
|
| 306 |
+
assert not parser.should_ignore("src/nested/build")
|
| 307 |
+
|
| 308 |
+
# Non-anchored patterns should match everywhere
|
| 309 |
+
assert parser.should_ignore("file.pyc")
|
| 310 |
+
assert parser.should_ignore("src/file.pyc")
|
| 311 |
+
|
| 312 |
+
def test_mixed_anchored_and_non_anchored_root_patterns(self):
|
| 313 |
+
"""Test mix of anchored and non-anchored patterns in root .gitignore."""
|
| 314 |
+
test_dir = self.repo_path / "test_mixed_patterns"
|
| 315 |
+
test_dir.mkdir()
|
| 316 |
+
(test_dir / "app").mkdir()
|
| 317 |
+
(test_dir / "tests").mkdir()
|
| 318 |
+
(test_dir / "app" / "modules").mkdir()
|
| 319 |
+
|
| 320 |
+
# Create root .gitignore with mixed patterns
|
| 321 |
+
gitignore = test_dir / ".gitignore"
|
| 322 |
+
gitignore.write_text(
|
| 323 |
+
"""/secrets.env
|
| 324 |
+
/dist/
|
| 325 |
+
node_modules/
|
| 326 |
+
*.tmp
|
| 327 |
+
/app/local.config
|
| 328 |
+
debug.log
|
| 329 |
+
"""
|
| 330 |
+
)
|
| 331 |
+
|
| 332 |
+
# Create test files and directories
|
| 333 |
+
(test_dir / "secrets.env").touch()
|
| 334 |
+
(test_dir / "dist").mkdir()
|
| 335 |
+
(test_dir / "node_modules").mkdir()
|
| 336 |
+
(test_dir / "file.tmp").touch()
|
| 337 |
+
(test_dir / "app" / "local.config").touch()
|
| 338 |
+
(test_dir / "debug.log").touch()
|
| 339 |
+
|
| 340 |
+
# Create same files in subdirectories
|
| 341 |
+
(test_dir / "app" / "secrets.env").touch()
|
| 342 |
+
(test_dir / "app" / "dist").mkdir()
|
| 343 |
+
(test_dir / "app" / "node_modules").mkdir()
|
| 344 |
+
(test_dir / "app" / "file.tmp").touch()
|
| 345 |
+
(test_dir / "app" / "debug.log").touch()
|
| 346 |
+
(test_dir / "tests" / "secrets.env").touch()
|
| 347 |
+
(test_dir / "tests" / "node_modules").mkdir()
|
| 348 |
+
(test_dir / "tests" / "debug.log").touch()
|
| 349 |
+
(test_dir / "app" / "modules" / "local.config").touch()
|
| 350 |
+
|
| 351 |
+
parser = GitignoreParser(str(test_dir))
|
| 352 |
+
|
| 353 |
+
# Anchored patterns should only match at root
|
| 354 |
+
assert parser.should_ignore("secrets.env")
|
| 355 |
+
assert not parser.should_ignore("app/secrets.env")
|
| 356 |
+
assert not parser.should_ignore("tests/secrets.env")
|
| 357 |
+
|
| 358 |
+
assert parser.should_ignore("dist")
|
| 359 |
+
assert not parser.should_ignore("app/dist")
|
| 360 |
+
|
| 361 |
+
assert parser.should_ignore("app/local.config")
|
| 362 |
+
assert not parser.should_ignore("app/modules/local.config")
|
| 363 |
+
|
| 364 |
+
# Non-anchored patterns should match everywhere
|
| 365 |
+
assert parser.should_ignore("node_modules")
|
| 366 |
+
assert parser.should_ignore("app/node_modules")
|
| 367 |
+
assert parser.should_ignore("tests/node_modules")
|
| 368 |
+
|
| 369 |
+
assert parser.should_ignore("file.tmp")
|
| 370 |
+
assert parser.should_ignore("app/file.tmp")
|
| 371 |
+
|
| 372 |
+
assert parser.should_ignore("debug.log")
|
| 373 |
+
assert parser.should_ignore("app/debug.log")
|
| 374 |
+
assert parser.should_ignore("tests/debug.log")
|
| 375 |
+
|
| 376 |
+
def test_negation_patterns(self):
|
| 377 |
+
"""Test negation patterns are parsed correctly."""
|
| 378 |
+
test_dir = self.repo_path / "test_negation"
|
| 379 |
+
test_dir.mkdir()
|
| 380 |
+
|
| 381 |
+
gitignore = test_dir / ".gitignore"
|
| 382 |
+
gitignore.write_text(
|
| 383 |
+
"""*.log
|
| 384 |
+
!important.log
|
| 385 |
+
!src/keep.log
|
| 386 |
+
"""
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
parser = GitignoreParser(str(test_dir))
|
| 390 |
+
specs = parser.get_ignore_specs()
|
| 391 |
+
|
| 392 |
+
assert len(specs) == 1
|
| 393 |
+
patterns = specs[0].patterns
|
| 394 |
+
|
| 395 |
+
assert "*.log" in patterns
|
| 396 |
+
assert "!important.log" in patterns
|
| 397 |
+
assert "!src/keep.log" in patterns
|
| 398 |
+
|
| 399 |
+
def test_comments_and_empty_lines(self):
|
| 400 |
+
"""Test that comments and empty lines are ignored."""
|
| 401 |
+
test_dir = self.repo_path / "test_comments"
|
| 402 |
+
test_dir.mkdir()
|
| 403 |
+
|
| 404 |
+
gitignore = test_dir / ".gitignore"
|
| 405 |
+
gitignore.write_text(
|
| 406 |
+
"""# This is a comment
|
| 407 |
+
*.log
|
| 408 |
+
|
| 409 |
+
# Another comment
|
| 410 |
+
# Indented comment
|
| 411 |
+
|
| 412 |
+
build/
|
| 413 |
+
"""
|
| 414 |
+
)
|
| 415 |
+
|
| 416 |
+
parser = GitignoreParser(str(test_dir))
|
| 417 |
+
specs = parser.get_ignore_specs()
|
| 418 |
+
|
| 419 |
+
assert len(specs) == 1
|
| 420 |
+
patterns = specs[0].patterns
|
| 421 |
+
|
| 422 |
+
assert len(patterns) == 2
|
| 423 |
+
assert "*.log" in patterns
|
| 424 |
+
assert "build/" in patterns
|
| 425 |
+
|
| 426 |
+
def test_escaped_characters(self):
|
| 427 |
+
"""Test escaped special characters."""
|
| 428 |
+
test_dir = self.repo_path / "test_escaped"
|
| 429 |
+
test_dir.mkdir()
|
| 430 |
+
|
| 431 |
+
gitignore = test_dir / ".gitignore"
|
| 432 |
+
gitignore.write_text(
|
| 433 |
+
"""\\#not-a-comment.txt
|
| 434 |
+
\\!not-negation.txt
|
| 435 |
+
"""
|
| 436 |
+
)
|
| 437 |
+
|
| 438 |
+
parser = GitignoreParser(str(test_dir))
|
| 439 |
+
specs = parser.get_ignore_specs()
|
| 440 |
+
|
| 441 |
+
assert len(specs) == 1
|
| 442 |
+
patterns = specs[0].patterns
|
| 443 |
+
|
| 444 |
+
assert "#not-a-comment.txt" in patterns
|
| 445 |
+
assert "!not-negation.txt" in patterns
|
| 446 |
+
|
| 447 |
+
def test_escaped_negation_patterns(self):
|
| 448 |
+
test_dir = self.repo_path / "test_escaped_negation"
|
| 449 |
+
test_dir.mkdir()
|
| 450 |
+
|
| 451 |
+
gitignore = test_dir / ".gitignore"
|
| 452 |
+
gitignore.write_text(
|
| 453 |
+
"""*.log
|
| 454 |
+
\\!not-negation.log
|
| 455 |
+
!actual-negation.log
|
| 456 |
+
"""
|
| 457 |
+
)
|
| 458 |
+
|
| 459 |
+
parser = GitignoreParser(str(test_dir))
|
| 460 |
+
specs = parser.get_ignore_specs()
|
| 461 |
+
|
| 462 |
+
assert len(specs) == 1
|
| 463 |
+
patterns = specs[0].patterns
|
| 464 |
+
|
| 465 |
+
# Key assertions: escaped exclamation becomes literal, real negation preserved
|
| 466 |
+
assert "!not-negation.log" in patterns # escaped -> literal
|
| 467 |
+
assert "!actual-negation.log" in patterns # real negation preserved
|
| 468 |
+
|
| 469 |
+
# Test the actual behavioral difference between escaped and real negation:
|
| 470 |
+
# *.log pattern should ignore test.log
|
| 471 |
+
assert parser.should_ignore("test.log")
|
| 472 |
+
|
| 473 |
+
# Escaped negation file should still be ignored by *.log pattern
|
| 474 |
+
assert parser.should_ignore("!not-negation.log")
|
| 475 |
+
|
| 476 |
+
# Actual negation should override the *.log pattern
|
| 477 |
+
assert not parser.should_ignore("actual-negation.log")
|
| 478 |
+
|
| 479 |
+
def test_glob_patterns(self):
|
| 480 |
+
"""Test various glob patterns work correctly."""
|
| 481 |
+
test_dir = self.repo_path / "test_glob"
|
| 482 |
+
test_dir.mkdir()
|
| 483 |
+
|
| 484 |
+
gitignore = test_dir / ".gitignore"
|
| 485 |
+
gitignore.write_text(
|
| 486 |
+
"""*.pyc
|
| 487 |
+
**/*.tmp
|
| 488 |
+
src/*.o
|
| 489 |
+
!src/important.o
|
| 490 |
+
[Tt]est*
|
| 491 |
+
"""
|
| 492 |
+
)
|
| 493 |
+
|
| 494 |
+
# Create test files
|
| 495 |
+
(test_dir / "src").mkdir()
|
| 496 |
+
(test_dir / "src" / "nested").mkdir()
|
| 497 |
+
(test_dir / "file.pyc").touch()
|
| 498 |
+
(test_dir / "src" / "file.pyc").touch()
|
| 499 |
+
(test_dir / "file.tmp").touch()
|
| 500 |
+
(test_dir / "src" / "nested" / "file.tmp").touch()
|
| 501 |
+
(test_dir / "src" / "file.o").touch()
|
| 502 |
+
(test_dir / "src" / "important.o").touch()
|
| 503 |
+
(test_dir / "Test.txt").touch()
|
| 504 |
+
(test_dir / "test.log").touch()
|
| 505 |
+
|
| 506 |
+
parser = GitignoreParser(str(test_dir))
|
| 507 |
+
|
| 508 |
+
# *.pyc should match everywhere
|
| 509 |
+
assert parser.should_ignore("file.pyc")
|
| 510 |
+
assert parser.should_ignore("src/file.pyc")
|
| 511 |
+
|
| 512 |
+
# **/*.tmp should match all .tmp files
|
| 513 |
+
assert parser.should_ignore("file.tmp")
|
| 514 |
+
assert parser.should_ignore("src/nested/file.tmp")
|
| 515 |
+
|
| 516 |
+
# src/*.o should only match .o files directly in src/
|
| 517 |
+
assert parser.should_ignore("src/file.o")
|
| 518 |
+
|
| 519 |
+
# Character class patterns
|
| 520 |
+
assert parser.should_ignore("Test.txt")
|
| 521 |
+
assert parser.should_ignore("test.log")
|
| 522 |
+
|
| 523 |
+
def test_empty_gitignore(self):
|
| 524 |
+
"""Test handling of empty gitignore files."""
|
| 525 |
+
test_dir = self.repo_path / "test_empty"
|
| 526 |
+
test_dir.mkdir()
|
| 527 |
+
|
| 528 |
+
gitignore = test_dir / ".gitignore"
|
| 529 |
+
gitignore.write_text("")
|
| 530 |
+
|
| 531 |
+
parser = GitignoreParser(str(test_dir))
|
| 532 |
+
|
| 533 |
+
# Should not crash and should return empty list
|
| 534 |
+
assert len(parser.get_ignore_specs()) == 0
|
| 535 |
+
|
| 536 |
+
def test_malformed_gitignore(self):
|
| 537 |
+
"""Test handling of malformed gitignore content."""
|
| 538 |
+
test_dir = self.repo_path / "test_malformed"
|
| 539 |
+
test_dir.mkdir()
|
| 540 |
+
|
| 541 |
+
gitignore = test_dir / ".gitignore"
|
| 542 |
+
gitignore.write_text(
|
| 543 |
+
"""# Only comments and empty lines
|
| 544 |
+
|
| 545 |
+
# More comments
|
| 546 |
+
|
| 547 |
+
"""
|
| 548 |
+
)
|
| 549 |
+
|
| 550 |
+
parser = GitignoreParser(str(test_dir))
|
| 551 |
+
|
| 552 |
+
# Should handle gracefully
|
| 553 |
+
assert len(parser.get_ignore_specs()) == 0
|
| 554 |
+
|
| 555 |
+
def test_reload(self):
|
| 556 |
+
"""Test reloading gitignore files."""
|
| 557 |
+
test_dir = self.repo_path / "test_reload"
|
| 558 |
+
test_dir.mkdir()
|
| 559 |
+
|
| 560 |
+
# Create initial gitignore
|
| 561 |
+
gitignore = test_dir / ".gitignore"
|
| 562 |
+
gitignore.write_text("*.log")
|
| 563 |
+
|
| 564 |
+
parser = GitignoreParser(str(test_dir))
|
| 565 |
+
assert len(parser.get_ignore_specs()) == 1
|
| 566 |
+
assert parser.should_ignore("test.log")
|
| 567 |
+
|
| 568 |
+
# Modify gitignore
|
| 569 |
+
gitignore.write_text("*.tmp")
|
| 570 |
+
|
| 571 |
+
# Without reload, should still use old patterns
|
| 572 |
+
assert parser.should_ignore("test.log")
|
| 573 |
+
assert not parser.should_ignore("test.tmp")
|
| 574 |
+
|
| 575 |
+
# After reload, should use new patterns
|
| 576 |
+
parser.reload()
|
| 577 |
+
assert not parser.should_ignore("test.log")
|
| 578 |
+
assert parser.should_ignore("test.tmp")
|
| 579 |
+
|
| 580 |
+
def test_gitignore_spec_matches(self):
|
| 581 |
+
"""Test GitignoreSpec.matches method."""
|
| 582 |
+
spec = GitignoreSpec("/path/to/.gitignore", ["*.log", "build/", "!important.log"])
|
| 583 |
+
|
| 584 |
+
assert spec.matches("test.log")
|
| 585 |
+
assert spec.matches("build/output.o")
|
| 586 |
+
assert spec.matches("src/test.log")
|
| 587 |
+
|
| 588 |
+
# Note: Negation patterns in pathspec work differently than in git
|
| 589 |
+
# This is a limitation of the pathspec library
|
| 590 |
+
|
| 591 |
+
def test_subdirectory_gitignore_pattern_scoping(self):
|
| 592 |
+
"""Test that subdirectory .gitignore patterns are scoped correctly."""
|
| 593 |
+
# Create test structure: foo/ with subdirectory bar/
|
| 594 |
+
test_dir = self.repo_path / "test_subdir_scoping"
|
| 595 |
+
test_dir.mkdir()
|
| 596 |
+
(test_dir / "foo").mkdir()
|
| 597 |
+
(test_dir / "foo" / "bar").mkdir()
|
| 598 |
+
|
| 599 |
+
# Create files in various locations
|
| 600 |
+
(test_dir / "foo.txt").touch() # root level
|
| 601 |
+
(test_dir / "foo" / "foo.txt").touch() # in foo/
|
| 602 |
+
(test_dir / "foo" / "bar" / "foo.txt").touch() # in foo/bar/
|
| 603 |
+
|
| 604 |
+
# Test case 1: foo.txt in foo/.gitignore should only ignore in foo/ subtree
|
| 605 |
+
gitignore = test_dir / "foo" / ".gitignore"
|
| 606 |
+
gitignore.write_text("foo.txt\n")
|
| 607 |
+
|
| 608 |
+
parser = GitignoreParser(str(test_dir))
|
| 609 |
+
|
| 610 |
+
# foo.txt at root should NOT be ignored by foo/.gitignore
|
| 611 |
+
assert not parser.should_ignore("foo.txt"), "Root foo.txt should not be ignored by foo/.gitignore"
|
| 612 |
+
|
| 613 |
+
# foo.txt in foo/ should be ignored
|
| 614 |
+
assert parser.should_ignore("foo/foo.txt"), "foo/foo.txt should be ignored"
|
| 615 |
+
|
| 616 |
+
# foo.txt in foo/bar/ should be ignored (within foo/ subtree)
|
| 617 |
+
assert parser.should_ignore("foo/bar/foo.txt"), "foo/bar/foo.txt should be ignored"
|
| 618 |
+
|
| 619 |
+
def test_anchored_pattern_in_subdirectory(self):
|
| 620 |
+
"""Test that anchored patterns in subdirectory only match immediate children."""
|
| 621 |
+
test_dir = self.repo_path / "test_anchored_subdir"
|
| 622 |
+
test_dir.mkdir()
|
| 623 |
+
(test_dir / "foo").mkdir()
|
| 624 |
+
(test_dir / "foo" / "bar").mkdir()
|
| 625 |
+
|
| 626 |
+
# Create files
|
| 627 |
+
(test_dir / "foo.txt").touch() # root level
|
| 628 |
+
(test_dir / "foo" / "foo.txt").touch() # in foo/
|
| 629 |
+
(test_dir / "foo" / "bar" / "foo.txt").touch() # in foo/bar/
|
| 630 |
+
|
| 631 |
+
# Test case 2: /foo.txt in foo/.gitignore should only match foo/foo.txt
|
| 632 |
+
gitignore = test_dir / "foo" / ".gitignore"
|
| 633 |
+
gitignore.write_text("/foo.txt\n")
|
| 634 |
+
|
| 635 |
+
parser = GitignoreParser(str(test_dir))
|
| 636 |
+
|
| 637 |
+
# foo.txt at root should NOT be ignored
|
| 638 |
+
assert not parser.should_ignore("foo.txt"), "Root foo.txt should not be ignored"
|
| 639 |
+
|
| 640 |
+
# foo.txt directly in foo/ should be ignored
|
| 641 |
+
assert parser.should_ignore("foo/foo.txt"), "foo/foo.txt should be ignored by /foo.txt pattern"
|
| 642 |
+
|
| 643 |
+
# foo.txt in foo/bar/ should NOT be ignored (anchored pattern only matches immediate children)
|
| 644 |
+
assert not parser.should_ignore("foo/bar/foo.txt"), "foo/bar/foo.txt should NOT be ignored by /foo.txt pattern"
|
| 645 |
+
|
| 646 |
+
def test_double_star_pattern_scoping(self):
|
| 647 |
+
"""Test that **/pattern in subdirectory only applies within that subtree."""
|
| 648 |
+
test_dir = self.repo_path / "test_doublestar_scope"
|
| 649 |
+
test_dir.mkdir()
|
| 650 |
+
(test_dir / "foo").mkdir()
|
| 651 |
+
(test_dir / "foo" / "bar").mkdir()
|
| 652 |
+
(test_dir / "other").mkdir()
|
| 653 |
+
|
| 654 |
+
# Create files
|
| 655 |
+
(test_dir / "foo.txt").touch() # root level
|
| 656 |
+
(test_dir / "foo" / "foo.txt").touch() # in foo/
|
| 657 |
+
(test_dir / "foo" / "bar" / "foo.txt").touch() # in foo/bar/
|
| 658 |
+
(test_dir / "other" / "foo.txt").touch() # in other/
|
| 659 |
+
|
| 660 |
+
# Test case 3: **/foo.txt in foo/.gitignore should only ignore within foo/ subtree
|
| 661 |
+
gitignore = test_dir / "foo" / ".gitignore"
|
| 662 |
+
gitignore.write_text("**/foo.txt\n")
|
| 663 |
+
|
| 664 |
+
parser = GitignoreParser(str(test_dir))
|
| 665 |
+
|
| 666 |
+
# foo.txt at root should NOT be ignored
|
| 667 |
+
assert not parser.should_ignore("foo.txt"), "Root foo.txt should not be ignored by foo/.gitignore"
|
| 668 |
+
|
| 669 |
+
# foo.txt in foo/ should be ignored
|
| 670 |
+
assert parser.should_ignore("foo/foo.txt"), "foo/foo.txt should be ignored"
|
| 671 |
+
|
| 672 |
+
# foo.txt in foo/bar/ should be ignored (within foo/ subtree)
|
| 673 |
+
assert parser.should_ignore("foo/bar/foo.txt"), "foo/bar/foo.txt should be ignored"
|
| 674 |
+
|
| 675 |
+
# foo.txt in other/ should NOT be ignored (outside foo/ subtree)
|
| 676 |
+
assert not parser.should_ignore("other/foo.txt"), "other/foo.txt should NOT be ignored by foo/.gitignore"
|
| 677 |
+
|
| 678 |
+
def test_anchored_double_star_pattern(self):
|
| 679 |
+
"""Test that /**/pattern in subdirectory works correctly."""
|
| 680 |
+
test_dir = self.repo_path / "test_anchored_doublestar"
|
| 681 |
+
test_dir.mkdir()
|
| 682 |
+
(test_dir / "foo").mkdir()
|
| 683 |
+
(test_dir / "foo" / "bar").mkdir()
|
| 684 |
+
(test_dir / "other").mkdir()
|
| 685 |
+
|
| 686 |
+
# Create files
|
| 687 |
+
(test_dir / "foo.txt").touch() # root level
|
| 688 |
+
(test_dir / "foo" / "foo.txt").touch() # in foo/
|
| 689 |
+
(test_dir / "foo" / "bar" / "foo.txt").touch() # in foo/bar/
|
| 690 |
+
(test_dir / "other" / "foo.txt").touch() # in other/
|
| 691 |
+
|
| 692 |
+
# Test case 4: /**/foo.txt in foo/.gitignore should correctly ignore only within foo/ subtree
|
| 693 |
+
gitignore = test_dir / "foo" / ".gitignore"
|
| 694 |
+
gitignore.write_text("/**/foo.txt\n")
|
| 695 |
+
|
| 696 |
+
parser = GitignoreParser(str(test_dir))
|
| 697 |
+
|
| 698 |
+
# foo.txt at root should NOT be ignored
|
| 699 |
+
assert not parser.should_ignore("foo.txt"), "Root foo.txt should not be ignored"
|
| 700 |
+
|
| 701 |
+
# foo.txt in foo/ should be ignored
|
| 702 |
+
assert parser.should_ignore("foo/foo.txt"), "foo/foo.txt should be ignored"
|
| 703 |
+
|
| 704 |
+
# foo.txt in foo/bar/ should be ignored (within foo/ subtree)
|
| 705 |
+
assert parser.should_ignore("foo/bar/foo.txt"), "foo/bar/foo.txt should be ignored"
|
| 706 |
+
|
| 707 |
+
# foo.txt in other/ should NOT be ignored (outside foo/ subtree)
|
| 708 |
+
assert not parser.should_ignore("other/foo.txt"), "other/foo.txt should NOT be ignored by foo/.gitignore"
|
projects/ui/serena-new/test/solidlsp/bash/__init__.py
ADDED
|
File without changes
|
projects/ui/serena-new/test/solidlsp/bash/test_bash_basic.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Basic integration tests for the bash language server functionality.
|
| 3 |
+
|
| 4 |
+
These tests validate the functionality of the language server APIs
|
| 5 |
+
like request_document_symbols using the bash 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.bash
|
| 15 |
+
class TestBashLanguageServerBasics:
|
| 16 |
+
"""Test basic functionality of the bash language server."""
|
| 17 |
+
|
| 18 |
+
@pytest.mark.parametrize("language_server", [Language.BASH], indirect=True)
|
| 19 |
+
def test_bash_language_server_initialization(self, language_server: SolidLanguageServer) -> None:
|
| 20 |
+
"""Test that bash language server can be initialized successfully."""
|
| 21 |
+
assert language_server is not None
|
| 22 |
+
assert language_server.language == Language.BASH
|
| 23 |
+
|
| 24 |
+
@pytest.mark.parametrize("language_server", [Language.BASH], indirect=True)
|
| 25 |
+
def test_bash_request_document_symbols(self, language_server: SolidLanguageServer) -> None:
|
| 26 |
+
"""Test request_document_symbols for bash files."""
|
| 27 |
+
# Test getting symbols from main.sh
|
| 28 |
+
all_symbols, root_symbols = language_server.request_document_symbols("main.sh", include_body=False)
|
| 29 |
+
|
| 30 |
+
# Extract function symbols (LSP Symbol Kind 12)
|
| 31 |
+
function_symbols = [symbol for symbol in all_symbols if symbol.get("kind") == 12]
|
| 32 |
+
function_names = [symbol["name"] for symbol in function_symbols]
|
| 33 |
+
|
| 34 |
+
# Should detect all 3 functions from main.sh
|
| 35 |
+
assert "greet_user" in function_names, "Should find greet_user function"
|
| 36 |
+
assert "process_items" in function_names, "Should find process_items function"
|
| 37 |
+
assert "main" in function_names, "Should find main function"
|
| 38 |
+
assert len(function_symbols) >= 3, f"Should find at least 3 functions, found {len(function_symbols)}"
|
| 39 |
+
|
| 40 |
+
@pytest.mark.parametrize("language_server", [Language.BASH], indirect=True)
|
| 41 |
+
def test_bash_request_document_symbols_with_body(self, language_server: SolidLanguageServer) -> None:
|
| 42 |
+
"""Test request_document_symbols with body extraction."""
|
| 43 |
+
# Test with include_body=True
|
| 44 |
+
all_symbols, root_symbols = language_server.request_document_symbols("main.sh", include_body=True)
|
| 45 |
+
|
| 46 |
+
function_symbols = [symbol for symbol in all_symbols if symbol.get("kind") == 12]
|
| 47 |
+
|
| 48 |
+
# Find greet_user function and check it has body
|
| 49 |
+
greet_user_symbol = next((sym for sym in function_symbols if sym["name"] == "greet_user"), None)
|
| 50 |
+
assert greet_user_symbol is not None, "Should find greet_user function"
|
| 51 |
+
|
| 52 |
+
if "body" in greet_user_symbol:
|
| 53 |
+
body = greet_user_symbol["body"]
|
| 54 |
+
assert "function greet_user()" in body, "Function body should contain function definition"
|
| 55 |
+
assert "case" in body.lower(), "Function body should contain case statement"
|
| 56 |
+
|
| 57 |
+
@pytest.mark.parametrize("language_server", [Language.BASH], indirect=True)
|
| 58 |
+
def test_bash_utils_functions(self, language_server: SolidLanguageServer) -> None:
|
| 59 |
+
"""Test function detection in utils.sh file."""
|
| 60 |
+
# Test with utils.sh as well
|
| 61 |
+
utils_all_symbols, utils_root_symbols = language_server.request_document_symbols("utils.sh", include_body=False)
|
| 62 |
+
|
| 63 |
+
utils_function_symbols = [symbol for symbol in utils_all_symbols if symbol.get("kind") == 12]
|
| 64 |
+
utils_function_names = [symbol["name"] for symbol in utils_function_symbols]
|
| 65 |
+
|
| 66 |
+
# Should detect functions from utils.sh
|
| 67 |
+
expected_utils_functions = [
|
| 68 |
+
"to_uppercase",
|
| 69 |
+
"to_lowercase",
|
| 70 |
+
"trim_whitespace",
|
| 71 |
+
"backup_file",
|
| 72 |
+
"contains_element",
|
| 73 |
+
"log_message",
|
| 74 |
+
"is_valid_email",
|
| 75 |
+
"is_number",
|
| 76 |
+
]
|
| 77 |
+
|
| 78 |
+
for func_name in expected_utils_functions:
|
| 79 |
+
assert func_name in utils_function_names, f"Should find {func_name} function in utils.sh"
|
| 80 |
+
|
| 81 |
+
assert len(utils_function_symbols) >= 8, f"Should find at least 8 functions in utils.sh, found {len(utils_function_symbols)}"
|
| 82 |
+
|
| 83 |
+
@pytest.mark.parametrize("language_server", [Language.BASH], indirect=True)
|
| 84 |
+
def test_bash_function_syntax_patterns(self, language_server: SolidLanguageServer) -> None:
|
| 85 |
+
"""Test that LSP detects different bash function syntax patterns correctly."""
|
| 86 |
+
# Test main.sh (has both 'function' keyword and traditional syntax)
|
| 87 |
+
main_all_symbols, main_root_symbols = language_server.request_document_symbols("main.sh", include_body=False)
|
| 88 |
+
main_functions = [symbol for symbol in main_all_symbols if symbol.get("kind") == 12]
|
| 89 |
+
main_function_names = [func["name"] for func in main_functions]
|
| 90 |
+
|
| 91 |
+
# Test utils.sh (all use 'function' keyword)
|
| 92 |
+
utils_all_symbols, utils_root_symbols = language_server.request_document_symbols("utils.sh", include_body=False)
|
| 93 |
+
utils_functions = [symbol for symbol in utils_all_symbols if symbol.get("kind") == 12]
|
| 94 |
+
utils_function_names = [func["name"] for func in utils_functions]
|
| 95 |
+
|
| 96 |
+
# Verify LSP detects both syntax patterns
|
| 97 |
+
# main() uses traditional syntax: main() {
|
| 98 |
+
assert "main" in main_function_names, "LSP should detect traditional function syntax"
|
| 99 |
+
|
| 100 |
+
# Functions with 'function' keyword: function name() {
|
| 101 |
+
assert "greet_user" in main_function_names, "LSP should detect function keyword syntax"
|
| 102 |
+
assert "process_items" in main_function_names, "LSP should detect function keyword syntax"
|
| 103 |
+
|
| 104 |
+
# Verify all expected utils functions are detected by LSP
|
| 105 |
+
expected_utils = [
|
| 106 |
+
"to_uppercase",
|
| 107 |
+
"to_lowercase",
|
| 108 |
+
"trim_whitespace",
|
| 109 |
+
"backup_file",
|
| 110 |
+
"contains_element",
|
| 111 |
+
"log_message",
|
| 112 |
+
"is_valid_email",
|
| 113 |
+
"is_number",
|
| 114 |
+
]
|
| 115 |
+
|
| 116 |
+
for expected_func in expected_utils:
|
| 117 |
+
assert expected_func in utils_function_names, f"LSP should detect {expected_func} function"
|
| 118 |
+
|
| 119 |
+
# Verify total counts match expectations
|
| 120 |
+
assert len(main_functions) >= 3, f"Should find at least 3 functions in main.sh, found {len(main_functions)}"
|
| 121 |
+
assert len(utils_functions) >= 8, f"Should find at least 8 functions in utils.sh, found {len(utils_functions)}"
|
projects/ui/serena-new/test/solidlsp/clojure/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
|
| 3 |
+
from solidlsp.language_servers.clojure_lsp import verify_clojure_cli
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def _test_clojure_cli() -> bool:
|
| 7 |
+
try:
|
| 8 |
+
verify_clojure_cli()
|
| 9 |
+
return False
|
| 10 |
+
except (FileNotFoundError, RuntimeError):
|
| 11 |
+
return True
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
CLI_FAIL = _test_clojure_cli()
|
| 15 |
+
TEST_APP_PATH = Path("src") / "test_app"
|
| 16 |
+
CORE_PATH = str(TEST_APP_PATH / "core.clj")
|
| 17 |
+
UTILS_PATH = str(TEST_APP_PATH / "utils.clj")
|
projects/ui/serena-new/test/solidlsp/clojure/test_clojure_basic.py
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
from serena.project import Project
|
| 4 |
+
from solidlsp.ls import SolidLanguageServer
|
| 5 |
+
from solidlsp.ls_config import Language
|
| 6 |
+
from solidlsp.ls_types import UnifiedSymbolInformation
|
| 7 |
+
|
| 8 |
+
from . import CLI_FAIL, CORE_PATH, UTILS_PATH
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@pytest.mark.clojure
|
| 12 |
+
@pytest.mark.skipif(CLI_FAIL, reason=f"Clojure CLI not available: {CLI_FAIL}")
|
| 13 |
+
class TestLanguageServerBasics:
|
| 14 |
+
@pytest.mark.parametrize("language_server", [Language.CLOJURE], indirect=True)
|
| 15 |
+
def test_basic_definition(self, language_server: SolidLanguageServer):
|
| 16 |
+
"""
|
| 17 |
+
Test finding definition of 'greet' function call in core.clj
|
| 18 |
+
"""
|
| 19 |
+
result = language_server.request_definition(CORE_PATH, 20, 12) # Position of 'greet' in (greet "World")
|
| 20 |
+
|
| 21 |
+
assert isinstance(result, list)
|
| 22 |
+
assert len(result) >= 1
|
| 23 |
+
|
| 24 |
+
definition = result[0]
|
| 25 |
+
assert definition["relativePath"] == CORE_PATH
|
| 26 |
+
assert definition["range"]["start"]["line"] == 2, "Should find the definition of greet function at line 2"
|
| 27 |
+
|
| 28 |
+
@pytest.mark.parametrize("language_server", [Language.CLOJURE], indirect=True)
|
| 29 |
+
def test_cross_file_references(self, language_server: SolidLanguageServer):
|
| 30 |
+
"""
|
| 31 |
+
Test finding references to 'multiply' function from core.clj
|
| 32 |
+
"""
|
| 33 |
+
result = language_server.request_references(CORE_PATH, 12, 6)
|
| 34 |
+
|
| 35 |
+
assert isinstance(result, list) and len(result) >= 2, "Should find definition + usage in utils.clj"
|
| 36 |
+
|
| 37 |
+
usage_found = any(
|
| 38 |
+
item["relativePath"] == UTILS_PATH and item["range"]["start"]["line"] == 6 # multiply usage in calculate-area
|
| 39 |
+
for item in result
|
| 40 |
+
)
|
| 41 |
+
assert usage_found, "Should find multiply usage in utils.clj"
|
| 42 |
+
|
| 43 |
+
@pytest.mark.parametrize("language_server", [Language.CLOJURE], indirect=True)
|
| 44 |
+
def test_completions(self, language_server: SolidLanguageServer):
|
| 45 |
+
with language_server.open_file(UTILS_PATH):
|
| 46 |
+
# After "core/" in calculate-area
|
| 47 |
+
result = language_server.request_completions(UTILS_PATH, 6, 8)
|
| 48 |
+
|
| 49 |
+
assert isinstance(result, list) and len(result) > 0
|
| 50 |
+
|
| 51 |
+
completion_texts = [item["completionText"] for item in result]
|
| 52 |
+
assert any("multiply" in text for text in completion_texts), "Should find 'multiply' function in completions after 'core/'"
|
| 53 |
+
|
| 54 |
+
@pytest.mark.parametrize("language_server", [Language.CLOJURE], indirect=True)
|
| 55 |
+
def test_document_symbols(self, language_server: SolidLanguageServer):
|
| 56 |
+
symbols, _ = language_server.request_document_symbols(CORE_PATH)
|
| 57 |
+
|
| 58 |
+
assert isinstance(symbols, list) and len(symbols) >= 4, "greet, add, multiply, -main functions"
|
| 59 |
+
|
| 60 |
+
# Check that we find the expected function symbols
|
| 61 |
+
symbol_names = [symbol["name"] for symbol in symbols]
|
| 62 |
+
expected_functions = ["greet", "add", "multiply", "-main"]
|
| 63 |
+
|
| 64 |
+
for func_name in expected_functions:
|
| 65 |
+
assert func_name in symbol_names, f"Should find {func_name} function in symbols"
|
| 66 |
+
|
| 67 |
+
@pytest.mark.parametrize("language_server", [Language.CLOJURE], indirect=True)
|
| 68 |
+
def test_hover(self, language_server: SolidLanguageServer):
|
| 69 |
+
"""Test hover on greet function"""
|
| 70 |
+
result = language_server.request_hover(CORE_PATH, 2, 7)
|
| 71 |
+
|
| 72 |
+
assert result is not None, "Hover should return information for greet function"
|
| 73 |
+
assert "contents" in result
|
| 74 |
+
# Should contain function signature or documentation
|
| 75 |
+
contents = result["contents"]
|
| 76 |
+
if isinstance(contents, str):
|
| 77 |
+
assert "greet" in contents.lower()
|
| 78 |
+
elif isinstance(contents, dict) and "value" in contents:
|
| 79 |
+
assert "greet" in contents["value"].lower()
|
| 80 |
+
else:
|
| 81 |
+
assert False, f"Unexpected contents format: {type(contents)}"
|
| 82 |
+
|
| 83 |
+
@pytest.mark.parametrize("language_server", [Language.CLOJURE], indirect=True)
|
| 84 |
+
def test_workspace_symbols(self, language_server: SolidLanguageServer):
|
| 85 |
+
# Search for functions containing "add"
|
| 86 |
+
result = language_server.request_workspace_symbol("add")
|
| 87 |
+
|
| 88 |
+
assert isinstance(result, list) and len(result) > 0, "Should find at least one symbol containing 'add'"
|
| 89 |
+
|
| 90 |
+
# Should find the 'add' function
|
| 91 |
+
symbol_names = [symbol["name"] for symbol in result]
|
| 92 |
+
assert any("add" in name.lower() for name in symbol_names), f"Should find 'add' function in symbols: {symbol_names}"
|
| 93 |
+
|
| 94 |
+
@pytest.mark.parametrize("language_server", [Language.CLOJURE], indirect=True)
|
| 95 |
+
def test_namespace_functions(self, language_server: SolidLanguageServer):
|
| 96 |
+
"""Test definition lookup for core/greet usage in utils.clj"""
|
| 97 |
+
# Position of 'greet' in core/greet call
|
| 98 |
+
result = language_server.request_definition(UTILS_PATH, 11, 25)
|
| 99 |
+
|
| 100 |
+
assert isinstance(result, list)
|
| 101 |
+
assert len(result) >= 1
|
| 102 |
+
|
| 103 |
+
definition = result[0]
|
| 104 |
+
assert definition["relativePath"] == CORE_PATH, "Should find the definition of greet in core.clj"
|
| 105 |
+
|
| 106 |
+
@pytest.mark.parametrize("language_server", [Language.CLOJURE], indirect=True)
|
| 107 |
+
def test_request_references_with_content(self, language_server: SolidLanguageServer):
|
| 108 |
+
"""Test references to multiply function with content"""
|
| 109 |
+
references = language_server.request_references(CORE_PATH, 12, 6)
|
| 110 |
+
result = [
|
| 111 |
+
language_server.retrieve_content_around_line(ref1["relativePath"], ref1["range"]["start"]["line"], 3, 0) for ref1 in references
|
| 112 |
+
]
|
| 113 |
+
|
| 114 |
+
assert result is not None, "Should find references with content"
|
| 115 |
+
assert isinstance(result, list)
|
| 116 |
+
assert len(result) >= 2, "Should find definition + usage in utils.clj"
|
| 117 |
+
|
| 118 |
+
for ref in result:
|
| 119 |
+
assert ref.source_file_path is not None, "Each reference should have a source file path"
|
| 120 |
+
content_str = ref.to_display_string()
|
| 121 |
+
assert len(content_str) > 0, "Content should not be empty"
|
| 122 |
+
|
| 123 |
+
# Verify we find the reference in utils.clj with context
|
| 124 |
+
utils_refs = [ref for ref in result if ref.source_file_path and "utils.clj" in ref.source_file_path]
|
| 125 |
+
assert len(utils_refs) > 0, "Should find reference in utils.clj"
|
| 126 |
+
|
| 127 |
+
# The context should contain the calculate-area function
|
| 128 |
+
utils_content = utils_refs[0].to_display_string()
|
| 129 |
+
assert "calculate-area" in utils_content
|
| 130 |
+
|
| 131 |
+
@pytest.mark.parametrize("language_server", [Language.CLOJURE], indirect=True)
|
| 132 |
+
def test_request_full_symbol_tree(self, language_server: SolidLanguageServer):
|
| 133 |
+
"""Test retrieving the full symbol tree for project overview
|
| 134 |
+
We just check that we find some expected symbols.
|
| 135 |
+
"""
|
| 136 |
+
result = language_server.request_full_symbol_tree()
|
| 137 |
+
|
| 138 |
+
assert result is not None, "Should return symbol tree"
|
| 139 |
+
assert isinstance(result, list), "Symbol tree should be a list"
|
| 140 |
+
assert len(result) > 0, "Should find symbols in the project"
|
| 141 |
+
|
| 142 |
+
def traverse_symbols(symbols, indent=0):
|
| 143 |
+
"""Recursively traverse symbols to print their structure"""
|
| 144 |
+
info = []
|
| 145 |
+
for s in symbols:
|
| 146 |
+
name = getattr(s, "name", "NO_NAME")
|
| 147 |
+
kind = getattr(s, "kind", "NO_KIND")
|
| 148 |
+
info.append(f"{' ' * indent}Symbol: {name}, Kind: {kind}")
|
| 149 |
+
if hasattr(s, "children") and s.children:
|
| 150 |
+
info.append(" " * indent + "Children:")
|
| 151 |
+
info.extend(traverse_symbols(s.children, indent + 2))
|
| 152 |
+
return info
|
| 153 |
+
|
| 154 |
+
def list_all_symbols(symbols: list[UnifiedSymbolInformation]):
|
| 155 |
+
found = []
|
| 156 |
+
for symbol in symbols:
|
| 157 |
+
found.append(symbol["name"])
|
| 158 |
+
found.extend(list_all_symbols(symbol["children"]))
|
| 159 |
+
return found
|
| 160 |
+
|
| 161 |
+
all_symbol_names = list_all_symbols(result)
|
| 162 |
+
|
| 163 |
+
expected_symbols = ["greet", "add", "multiply", "-main", "calculate-area", "format-greeting", "sum-list"]
|
| 164 |
+
found_expected = [name for name in expected_symbols if any(name in symbol_name for symbol_name in all_symbol_names)]
|
| 165 |
+
|
| 166 |
+
if len(found_expected) < 7:
|
| 167 |
+
pytest.fail(
|
| 168 |
+
f"Expected to find at least 3 symbols from {expected_symbols}, but found: {found_expected}.\n"
|
| 169 |
+
f"All symbol names: {all_symbol_names}\n"
|
| 170 |
+
f"Symbol tree structure:\n{traverse_symbols(result)}"
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
@pytest.mark.parametrize("language_server", [Language.CLOJURE], indirect=True)
|
| 174 |
+
def test_request_referencing_symbols(self, language_server: SolidLanguageServer):
|
| 175 |
+
"""Test finding symbols that reference a given symbol
|
| 176 |
+
Finds references to the 'multiply' function.
|
| 177 |
+
"""
|
| 178 |
+
result = language_server.request_referencing_symbols(CORE_PATH, 12, 6)
|
| 179 |
+
assert isinstance(result, list) and len(result) > 0, "Should find at least one referencing symbol"
|
| 180 |
+
found_relevant_references = False
|
| 181 |
+
for ref in result:
|
| 182 |
+
if hasattr(ref, "symbol") and "calculate-area" in ref.symbol["name"]:
|
| 183 |
+
found_relevant_references = True
|
| 184 |
+
break
|
| 185 |
+
|
| 186 |
+
assert found_relevant_references, f"Should have found calculate-area referencing multiply, but got: {result}"
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
class TestProjectBasics:
|
| 190 |
+
@pytest.mark.parametrize("project", [Language.CLOJURE], indirect=True)
|
| 191 |
+
def test_retrieve_content_around_line(self, project: Project):
|
| 192 |
+
"""Test retrieving content around specific lines"""
|
| 193 |
+
# Test retrieving content around the greet function definition (line 2)
|
| 194 |
+
result = project.retrieve_content_around_line(CORE_PATH, 2, 2)
|
| 195 |
+
|
| 196 |
+
assert result is not None, "Should retrieve content around line 2"
|
| 197 |
+
content_str = result.to_display_string()
|
| 198 |
+
assert "greet" in content_str, "Should contain the greet function definition"
|
| 199 |
+
assert "defn" in content_str, "Should contain defn keyword"
|
| 200 |
+
|
| 201 |
+
# Test retrieving content around multiply function (around line 13)
|
| 202 |
+
result = project.retrieve_content_around_line(CORE_PATH, 13, 1)
|
| 203 |
+
|
| 204 |
+
assert result is not None, "Should retrieve content around line 13"
|
| 205 |
+
content_str = result.to_display_string()
|
| 206 |
+
assert "multiply" in content_str, "Should contain multiply function"
|
| 207 |
+
|
| 208 |
+
@pytest.mark.parametrize("project", [Language.CLOJURE], indirect=True)
|
| 209 |
+
def test_search_files_for_pattern(self, project: Project) -> None:
|
| 210 |
+
result = project.search_source_files_for_pattern("defn.*greet")
|
| 211 |
+
|
| 212 |
+
assert result is not None, "Pattern search should return results"
|
| 213 |
+
assert len(result) > 0, "Should find at least one match for 'defn.*greet'"
|
| 214 |
+
|
| 215 |
+
core_matches = [match for match in result if match.source_file_path and "core.clj" in match.source_file_path]
|
| 216 |
+
assert len(core_matches) > 0, "Should find greet function in core.clj"
|
| 217 |
+
|
| 218 |
+
result = project.search_source_files_for_pattern(":require")
|
| 219 |
+
|
| 220 |
+
assert result is not None, "Should find require statements"
|
| 221 |
+
utils_matches = [match for match in result if match.source_file_path and "utils.clj" in match.source_file_path]
|
| 222 |
+
assert len(utils_matches) > 0, "Should find require statement in utils.clj"
|
projects/ui/serena-new/test/solidlsp/csharp/test_csharp_basic.py
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import tempfile
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import cast
|
| 5 |
+
from unittest.mock import Mock, patch
|
| 6 |
+
|
| 7 |
+
import pytest
|
| 8 |
+
|
| 9 |
+
from solidlsp import SolidLanguageServer
|
| 10 |
+
from solidlsp.language_servers.csharp_language_server import (
|
| 11 |
+
CSharpLanguageServer,
|
| 12 |
+
breadth_first_file_scan,
|
| 13 |
+
find_solution_or_project_file,
|
| 14 |
+
)
|
| 15 |
+
from solidlsp.ls_config import Language, LanguageServerConfig
|
| 16 |
+
from solidlsp.ls_utils import SymbolUtils
|
| 17 |
+
from solidlsp.settings import SolidLSPSettings
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@pytest.mark.csharp
|
| 21 |
+
class TestCSharpLanguageServer:
|
| 22 |
+
@pytest.mark.parametrize("language_server", [Language.CSHARP], indirect=True)
|
| 23 |
+
def test_find_symbol(self, language_server: SolidLanguageServer) -> None:
|
| 24 |
+
"""Test finding symbols in the full symbol tree."""
|
| 25 |
+
symbols = language_server.request_full_symbol_tree()
|
| 26 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Program"), "Program class not found in symbol tree"
|
| 27 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Calculator"), "Calculator class not found in symbol tree"
|
| 28 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Add"), "Add method not found in symbol tree"
|
| 29 |
+
|
| 30 |
+
@pytest.mark.parametrize("language_server", [Language.CSHARP], indirect=True)
|
| 31 |
+
def test_get_document_symbols(self, language_server: SolidLanguageServer) -> None:
|
| 32 |
+
"""Test getting document symbols from a C# file."""
|
| 33 |
+
file_path = os.path.join("Program.cs")
|
| 34 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 35 |
+
|
| 36 |
+
# Check that we have symbols
|
| 37 |
+
assert len(symbols) > 0
|
| 38 |
+
|
| 39 |
+
# Flatten the symbols if they're nested
|
| 40 |
+
if isinstance(symbols[0], list):
|
| 41 |
+
symbols = symbols[0]
|
| 42 |
+
|
| 43 |
+
# Look for expected classes
|
| 44 |
+
class_names = [s.get("name") for s in symbols if s.get("kind") == 5] # 5 is class
|
| 45 |
+
assert "Program" in class_names
|
| 46 |
+
assert "Calculator" in class_names
|
| 47 |
+
|
| 48 |
+
@pytest.mark.parametrize("language_server", [Language.CSHARP], indirect=True)
|
| 49 |
+
def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:
|
| 50 |
+
"""Test finding references using symbol selection range."""
|
| 51 |
+
file_path = os.path.join("Program.cs")
|
| 52 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 53 |
+
add_symbol = None
|
| 54 |
+
# Handle nested symbol structure
|
| 55 |
+
symbol_list = symbols[0] if symbols and isinstance(symbols[0], list) else symbols
|
| 56 |
+
for sym in symbol_list:
|
| 57 |
+
if sym.get("name") == "Add":
|
| 58 |
+
add_symbol = sym
|
| 59 |
+
break
|
| 60 |
+
assert add_symbol is not None, "Could not find 'Add' method symbol in Program.cs"
|
| 61 |
+
sel_start = add_symbol["selectionRange"]["start"]
|
| 62 |
+
refs = language_server.request_references(file_path, sel_start["line"], sel_start["character"] + 1)
|
| 63 |
+
assert any(
|
| 64 |
+
"Program.cs" in ref.get("relativePath", "") for ref in refs
|
| 65 |
+
), "Program.cs should reference Add method (tried all positions in selectionRange)"
|
| 66 |
+
|
| 67 |
+
@pytest.mark.parametrize("language_server", [Language.CSHARP], indirect=True)
|
| 68 |
+
def test_nested_namespace_symbols(self, language_server: SolidLanguageServer) -> None:
|
| 69 |
+
"""Test getting symbols from nested namespace."""
|
| 70 |
+
file_path = os.path.join("Models", "Person.cs")
|
| 71 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 72 |
+
|
| 73 |
+
# Check that we have symbols
|
| 74 |
+
assert len(symbols) > 0
|
| 75 |
+
|
| 76 |
+
# Flatten the symbols if they're nested
|
| 77 |
+
if isinstance(symbols[0], list):
|
| 78 |
+
symbols = symbols[0]
|
| 79 |
+
|
| 80 |
+
# Check that we have the Person class
|
| 81 |
+
assert any(s.get("name") == "Person" and s.get("kind") == 5 for s in symbols)
|
| 82 |
+
|
| 83 |
+
# Check for properties and methods
|
| 84 |
+
symbol_names = [s.get("name") for s in symbols]
|
| 85 |
+
assert "Name" in symbol_names
|
| 86 |
+
assert "Age" in symbol_names
|
| 87 |
+
assert "Email" in symbol_names
|
| 88 |
+
assert "ToString" in symbol_names
|
| 89 |
+
assert "IsAdult" in symbol_names
|
| 90 |
+
|
| 91 |
+
@pytest.mark.parametrize("language_server", [Language.CSHARP], indirect=True)
|
| 92 |
+
def test_find_referencing_symbols_across_files(self, language_server: SolidLanguageServer) -> None:
|
| 93 |
+
"""Test finding references to Calculator.Subtract method across files."""
|
| 94 |
+
# First, find the Subtract method in Program.cs
|
| 95 |
+
file_path = os.path.join("Program.cs")
|
| 96 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 97 |
+
|
| 98 |
+
# Flatten the symbols if they're nested
|
| 99 |
+
symbol_list = symbols[0] if symbols and isinstance(symbols[0], list) else symbols
|
| 100 |
+
|
| 101 |
+
subtract_symbol = None
|
| 102 |
+
for sym in symbol_list:
|
| 103 |
+
if sym.get("name") == "Subtract":
|
| 104 |
+
subtract_symbol = sym
|
| 105 |
+
break
|
| 106 |
+
|
| 107 |
+
assert subtract_symbol is not None, "Could not find 'Subtract' method symbol in Program.cs"
|
| 108 |
+
|
| 109 |
+
# Get references to the Subtract method
|
| 110 |
+
sel_start = subtract_symbol["selectionRange"]["start"]
|
| 111 |
+
refs = language_server.request_references(file_path, sel_start["line"], sel_start["character"] + 1)
|
| 112 |
+
|
| 113 |
+
# Should find references in both Program.cs and Models/Person.cs
|
| 114 |
+
ref_files = cast(list[str], [ref.get("relativePath", "") for ref in refs])
|
| 115 |
+
print(f"Found references: {refs}")
|
| 116 |
+
print(f"Reference files: {ref_files}")
|
| 117 |
+
|
| 118 |
+
# Check that we have references from both files
|
| 119 |
+
assert any("Program.cs" in ref_file for ref_file in ref_files), "Should find reference in Program.cs"
|
| 120 |
+
assert any(
|
| 121 |
+
os.path.join("Models", "Person.cs") in ref_file for ref_file in ref_files
|
| 122 |
+
), "Should find reference in Models/Person.cs where Calculator.Subtract is called"
|
| 123 |
+
|
| 124 |
+
# check for a second time, since the first call may trigger initialization and change the state of the LS
|
| 125 |
+
refs_second_call = language_server.request_references(file_path, sel_start["line"], sel_start["character"] + 1)
|
| 126 |
+
assert refs_second_call == refs, "Second call to request_references should return the same results"
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
@pytest.mark.csharp
|
| 130 |
+
class TestCSharpSolutionProjectOpening:
|
| 131 |
+
"""Test C# language server solution and project opening functionality."""
|
| 132 |
+
|
| 133 |
+
def test_breadth_first_file_scan(self):
|
| 134 |
+
"""Test that breadth_first_file_scan finds files in breadth-first order."""
|
| 135 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 136 |
+
temp_path = Path(temp_dir)
|
| 137 |
+
|
| 138 |
+
# Create test directory structure
|
| 139 |
+
(temp_path / "file1.txt").touch()
|
| 140 |
+
(temp_path / "subdir1").mkdir()
|
| 141 |
+
(temp_path / "subdir1" / "file2.txt").touch()
|
| 142 |
+
(temp_path / "subdir2").mkdir()
|
| 143 |
+
(temp_path / "subdir2" / "file3.txt").touch()
|
| 144 |
+
(temp_path / "subdir1" / "subdir3").mkdir()
|
| 145 |
+
(temp_path / "subdir1" / "subdir3" / "file4.txt").touch()
|
| 146 |
+
|
| 147 |
+
# Scan files
|
| 148 |
+
files = list(breadth_first_file_scan(str(temp_path)))
|
| 149 |
+
filenames = [os.path.basename(f) for f in files]
|
| 150 |
+
|
| 151 |
+
# Should find all files
|
| 152 |
+
assert len(files) == 4
|
| 153 |
+
assert "file1.txt" in filenames
|
| 154 |
+
assert "file2.txt" in filenames
|
| 155 |
+
assert "file3.txt" in filenames
|
| 156 |
+
assert "file4.txt" in filenames
|
| 157 |
+
|
| 158 |
+
# file1.txt should be found first (breadth-first)
|
| 159 |
+
assert filenames[0] == "file1.txt"
|
| 160 |
+
|
| 161 |
+
def test_find_solution_or_project_file_with_solution(self):
|
| 162 |
+
"""Test that find_solution_or_project_file prefers .sln files."""
|
| 163 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 164 |
+
temp_path = Path(temp_dir)
|
| 165 |
+
|
| 166 |
+
# Create both .sln and .csproj files
|
| 167 |
+
solution_file = temp_path / "MySolution.sln"
|
| 168 |
+
project_file = temp_path / "MyProject.csproj"
|
| 169 |
+
solution_file.touch()
|
| 170 |
+
project_file.touch()
|
| 171 |
+
|
| 172 |
+
result = find_solution_or_project_file(str(temp_path))
|
| 173 |
+
|
| 174 |
+
# Should prefer .sln file
|
| 175 |
+
assert result == str(solution_file)
|
| 176 |
+
|
| 177 |
+
def test_find_solution_or_project_file_with_project_only(self):
|
| 178 |
+
"""Test that find_solution_or_project_file falls back to .csproj files."""
|
| 179 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 180 |
+
temp_path = Path(temp_dir)
|
| 181 |
+
|
| 182 |
+
# Create only .csproj file
|
| 183 |
+
project_file = temp_path / "MyProject.csproj"
|
| 184 |
+
project_file.touch()
|
| 185 |
+
|
| 186 |
+
result = find_solution_or_project_file(str(temp_path))
|
| 187 |
+
|
| 188 |
+
# Should return .csproj file
|
| 189 |
+
assert result == str(project_file)
|
| 190 |
+
|
| 191 |
+
def test_find_solution_or_project_file_with_nested_files(self):
|
| 192 |
+
"""Test that find_solution_or_project_file finds files in subdirectories."""
|
| 193 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 194 |
+
temp_path = Path(temp_dir)
|
| 195 |
+
|
| 196 |
+
# Create nested structure
|
| 197 |
+
(temp_path / "src").mkdir()
|
| 198 |
+
solution_file = temp_path / "src" / "MySolution.sln"
|
| 199 |
+
solution_file.touch()
|
| 200 |
+
|
| 201 |
+
result = find_solution_or_project_file(str(temp_path))
|
| 202 |
+
|
| 203 |
+
# Should find nested .sln file
|
| 204 |
+
assert result == str(solution_file)
|
| 205 |
+
|
| 206 |
+
def test_find_solution_or_project_file_returns_none_when_no_files(self):
|
| 207 |
+
"""Test that find_solution_or_project_file returns None when no .sln or .csproj files exist."""
|
| 208 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 209 |
+
temp_path = Path(temp_dir)
|
| 210 |
+
|
| 211 |
+
# Create some other files
|
| 212 |
+
(temp_path / "readme.txt").touch()
|
| 213 |
+
(temp_path / "other.cs").touch()
|
| 214 |
+
|
| 215 |
+
result = find_solution_or_project_file(str(temp_path))
|
| 216 |
+
|
| 217 |
+
# Should return None
|
| 218 |
+
assert result is None
|
| 219 |
+
|
| 220 |
+
def test_find_solution_or_project_file_prefers_solution_breadth_first(self):
|
| 221 |
+
"""Test that solution files are preferred even when deeper in the tree."""
|
| 222 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 223 |
+
temp_path = Path(temp_dir)
|
| 224 |
+
|
| 225 |
+
# Create .csproj at root and .sln in subdirectory
|
| 226 |
+
project_file = temp_path / "MyProject.csproj"
|
| 227 |
+
project_file.touch()
|
| 228 |
+
|
| 229 |
+
(temp_path / "src").mkdir()
|
| 230 |
+
solution_file = temp_path / "src" / "MySolution.sln"
|
| 231 |
+
solution_file.touch()
|
| 232 |
+
|
| 233 |
+
result = find_solution_or_project_file(str(temp_path))
|
| 234 |
+
|
| 235 |
+
# Should still prefer .sln file even though it's deeper
|
| 236 |
+
assert result == str(solution_file)
|
| 237 |
+
|
| 238 |
+
@patch("solidlsp.language_servers.csharp_language_server.CSharpLanguageServer._ensure_server_installed")
|
| 239 |
+
@patch("solidlsp.language_servers.csharp_language_server.CSharpLanguageServer._start_server")
|
| 240 |
+
def test_csharp_language_server_logs_solution_discovery(self, mock_start_server, mock_ensure_server_installed):
|
| 241 |
+
"""Test that CSharpLanguageServer logs solution/project discovery during initialization."""
|
| 242 |
+
mock_ensure_server_installed.return_value = ("/usr/bin/dotnet", "/path/to/server.dll")
|
| 243 |
+
|
| 244 |
+
# Create test directory with solution file
|
| 245 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 246 |
+
temp_path = Path(temp_dir)
|
| 247 |
+
solution_file = temp_path / "TestSolution.sln"
|
| 248 |
+
solution_file.touch()
|
| 249 |
+
|
| 250 |
+
# Mock logger to capture log messages
|
| 251 |
+
mock_logger = Mock()
|
| 252 |
+
mock_config = Mock(spec=LanguageServerConfig)
|
| 253 |
+
mock_config.ignored_paths = []
|
| 254 |
+
|
| 255 |
+
# Create CSharpLanguageServer instance
|
| 256 |
+
mock_settings = Mock(spec=SolidLSPSettings)
|
| 257 |
+
mock_settings.ls_resources_dir = "/tmp/test_ls_resources"
|
| 258 |
+
mock_settings.project_data_relative_path = "project_data"
|
| 259 |
+
CSharpLanguageServer(mock_config, mock_logger, str(temp_path), mock_settings)
|
| 260 |
+
|
| 261 |
+
# Verify that logger was called with solution file discovery
|
| 262 |
+
mock_logger.log.assert_any_call(f"Found solution/project file: {solution_file}", 20) # logging.INFO
|
| 263 |
+
|
| 264 |
+
@patch("solidlsp.language_servers.csharp_language_server.CSharpLanguageServer._ensure_server_installed")
|
| 265 |
+
@patch("solidlsp.language_servers.csharp_language_server.CSharpLanguageServer._start_server")
|
| 266 |
+
def test_csharp_language_server_logs_no_solution_warning(self, mock_start_server, mock_ensure_server_installed):
|
| 267 |
+
"""Test that CSharpLanguageServer logs warning when no solution/project files are found."""
|
| 268 |
+
# Mock the server installation
|
| 269 |
+
mock_ensure_server_installed.return_value = ("/usr/bin/dotnet", "/path/to/server.dll")
|
| 270 |
+
|
| 271 |
+
# Create empty test directory
|
| 272 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 273 |
+
temp_path = Path(temp_dir)
|
| 274 |
+
|
| 275 |
+
# Mock logger to capture log messages
|
| 276 |
+
mock_logger = Mock()
|
| 277 |
+
mock_config = Mock(spec=LanguageServerConfig)
|
| 278 |
+
mock_config.ignored_paths = []
|
| 279 |
+
|
| 280 |
+
# Create CSharpLanguageServer instance
|
| 281 |
+
mock_settings = Mock(spec=SolidLSPSettings)
|
| 282 |
+
mock_settings.ls_resources_dir = "/tmp/test_ls_resources"
|
| 283 |
+
mock_settings.project_data_relative_path = "project_data"
|
| 284 |
+
CSharpLanguageServer(mock_config, mock_logger, str(temp_path), mock_settings)
|
| 285 |
+
|
| 286 |
+
# Verify that logger was called with warning about no solution/project files
|
| 287 |
+
mock_logger.log.assert_any_call(
|
| 288 |
+
"No .sln or .csproj file found, language server will attempt auto-discovery", 30 # logging.WARNING
|
| 289 |
+
)
|
| 290 |
+
|
| 291 |
+
def test_solution_and_project_opening_with_real_test_repo(self):
|
| 292 |
+
"""Test solution and project opening with the actual C# test repository."""
|
| 293 |
+
# Get the C# test repo path
|
| 294 |
+
test_repo_path = Path(__file__).parent.parent.parent / "resources" / "repos" / "csharp" / "test_repo"
|
| 295 |
+
|
| 296 |
+
if not test_repo_path.exists():
|
| 297 |
+
pytest.skip("C# test repository not found")
|
| 298 |
+
|
| 299 |
+
# Test solution/project discovery in the real test repo
|
| 300 |
+
result = find_solution_or_project_file(str(test_repo_path))
|
| 301 |
+
|
| 302 |
+
# Should find either .sln or .csproj file
|
| 303 |
+
assert result is not None
|
| 304 |
+
assert result.endswith((".sln", ".csproj"))
|
| 305 |
+
|
| 306 |
+
# Verify the file actually exists
|
| 307 |
+
assert os.path.exists(result)
|
projects/ui/serena-new/test/solidlsp/dart/__init__.py
ADDED
|
File without changes
|
projects/ui/serena-new/test/solidlsp/dart/test_dart_basic.py
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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_types import SymbolKind
|
| 9 |
+
from solidlsp.ls_utils import SymbolUtils
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@pytest.mark.dart
|
| 13 |
+
class TestDartLanguageServer:
|
| 14 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 15 |
+
@pytest.mark.parametrize("repo_path", [Language.DART], indirect=True)
|
| 16 |
+
def test_ls_is_running(self, language_server: SolidLanguageServer, repo_path: Path) -> None:
|
| 17 |
+
"""Test that the language server starts and stops successfully."""
|
| 18 |
+
# The fixture already handles start and stop
|
| 19 |
+
assert language_server.is_running()
|
| 20 |
+
assert Path(language_server.language_server.repository_root_path).resolve() == repo_path.resolve()
|
| 21 |
+
|
| 22 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 23 |
+
@pytest.mark.parametrize("repo_path", [Language.DART], indirect=True)
|
| 24 |
+
def test_find_definition_within_file(self, language_server: SolidLanguageServer, repo_path: Path) -> None:
|
| 25 |
+
"""Test finding definition of a method within the same file."""
|
| 26 |
+
# In lib/main.dart:
|
| 27 |
+
# Line 105: final result1 = calc.add(5, 3); // Reference to add method
|
| 28 |
+
# Line 12: int add(int a, int b) { // Definition of add method
|
| 29 |
+
# Find definition of 'add' method from its usage
|
| 30 |
+
main_dart_path = str(repo_path / "lib" / "main.dart")
|
| 31 |
+
|
| 32 |
+
# Position: calc.add(5, 3) - cursor on 'add'
|
| 33 |
+
# Line 105 (1-indexed) = line 104 (0-indexed), char position around 22
|
| 34 |
+
definition_location_list = language_server.request_definition(main_dart_path, 104, 22)
|
| 35 |
+
|
| 36 |
+
assert definition_location_list, f"Expected non-empty definition_location_list but got {definition_location_list=}"
|
| 37 |
+
assert len(definition_location_list) >= 1
|
| 38 |
+
definition_location = definition_location_list[0]
|
| 39 |
+
assert definition_location["uri"].endswith("main.dart")
|
| 40 |
+
# Definition of add method should be around line 11 (0-indexed)
|
| 41 |
+
# But language server may return different positions
|
| 42 |
+
assert definition_location["range"]["start"]["line"] >= 0
|
| 43 |
+
|
| 44 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 45 |
+
@pytest.mark.parametrize("repo_path", [Language.DART], indirect=True)
|
| 46 |
+
def test_find_definition_across_files(self, language_server: SolidLanguageServer, repo_path: Path) -> None:
|
| 47 |
+
"""Test finding definition across different files."""
|
| 48 |
+
# Test finding definition of MathHelper class which is in helper.dart
|
| 49 |
+
# In lib/main.dart line 50: MathHelper.power(step1, 2)
|
| 50 |
+
main_dart_path = str(repo_path / "lib" / "main.dart")
|
| 51 |
+
|
| 52 |
+
# Position: MathHelper.power(step1, 2) - cursor on 'MathHelper'
|
| 53 |
+
# Line 50 (1-indexed) = line 49 (0-indexed), char position around 18
|
| 54 |
+
definition_location_list = language_server.request_definition(main_dart_path, 49, 18)
|
| 55 |
+
|
| 56 |
+
# Skip the test if language server doesn't find cross-file references
|
| 57 |
+
# This is acceptable for a basic test - the important thing is that LS is working
|
| 58 |
+
if not definition_location_list:
|
| 59 |
+
pytest.skip("Language server doesn't support cross-file definition lookup for this case")
|
| 60 |
+
|
| 61 |
+
assert len(definition_location_list) >= 1
|
| 62 |
+
definition_location = definition_location_list[0]
|
| 63 |
+
assert definition_location["uri"].endswith("helper.dart")
|
| 64 |
+
assert definition_location["range"]["start"]["line"] >= 0
|
| 65 |
+
|
| 66 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 67 |
+
@pytest.mark.parametrize("repo_path", [Language.DART], indirect=True)
|
| 68 |
+
def test_find_definition_class_method(self, language_server: SolidLanguageServer, repo_path: Path) -> None:
|
| 69 |
+
"""Test finding definition of a class method."""
|
| 70 |
+
# In lib/main.dart:
|
| 71 |
+
# Line 50: final step2 = MathHelper.power(step1, 2); // Reference to MathHelper.power method
|
| 72 |
+
# In lib/helper.dart:
|
| 73 |
+
# Line 14: static double power(double base, int exponent) { // Definition of power method
|
| 74 |
+
main_dart_path = str(repo_path / "lib" / "main.dart")
|
| 75 |
+
|
| 76 |
+
# Position: MathHelper.power(step1, 2) - cursor on 'power'
|
| 77 |
+
# Line 50 (1-indexed) = line 49 (0-indexed), char position around 30
|
| 78 |
+
definition_location_list = language_server.request_definition(main_dart_path, 49, 30)
|
| 79 |
+
|
| 80 |
+
assert definition_location_list, f"Expected non-empty definition_location_list but got {definition_location_list=}"
|
| 81 |
+
assert len(definition_location_list) >= 1
|
| 82 |
+
definition_location = definition_location_list[0]
|
| 83 |
+
assert definition_location["uri"].endswith("helper.dart")
|
| 84 |
+
# Definition of power method should be around line 13 (0-indexed)
|
| 85 |
+
assert 12 <= definition_location["range"]["start"]["line"] <= 16
|
| 86 |
+
|
| 87 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 88 |
+
@pytest.mark.parametrize("repo_path", [Language.DART], indirect=True)
|
| 89 |
+
def test_find_references_within_file(self, language_server: SolidLanguageServer, repo_path: Path) -> None:
|
| 90 |
+
"""Test finding references to a method within the same file."""
|
| 91 |
+
main_dart_path = str(repo_path / "lib" / "main.dart")
|
| 92 |
+
|
| 93 |
+
# Find references to the 'add' method from its definition
|
| 94 |
+
# Line 12: int add(int a, int b) { // Definition of add method
|
| 95 |
+
# Line 105: final result1 = calc.add(5, 3); // Usage of add method
|
| 96 |
+
references = language_server.request_references(main_dart_path, 11, 6) # cursor on 'add' in definition
|
| 97 |
+
|
| 98 |
+
assert references, f"Expected non-empty references but got {references=}"
|
| 99 |
+
# Should find at least the usage of add method
|
| 100 |
+
assert len(references) >= 1
|
| 101 |
+
|
| 102 |
+
# Check that we have a reference in main.dart
|
| 103 |
+
main_dart_references = [ref for ref in references if ref["uri"].endswith("main.dart")]
|
| 104 |
+
assert len(main_dart_references) >= 1
|
| 105 |
+
|
| 106 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 107 |
+
@pytest.mark.parametrize("repo_path", [Language.DART], indirect=True)
|
| 108 |
+
def test_find_references_across_files(self, language_server: SolidLanguageServer, repo_path: Path) -> None:
|
| 109 |
+
"""Test finding references across different files."""
|
| 110 |
+
helper_dart_path = str(repo_path / "lib" / "helper.dart")
|
| 111 |
+
|
| 112 |
+
# Find references to the 'subtract' function from its definition in helper.dart
|
| 113 |
+
# Definition is in helper.dart, usage is in main.dart
|
| 114 |
+
references = language_server.request_references(helper_dart_path, 4, 4) # cursor on 'subtract' in definition
|
| 115 |
+
|
| 116 |
+
assert references, f"Expected non-empty references for subtract function but got {references=}"
|
| 117 |
+
|
| 118 |
+
# Should find references in main.dart
|
| 119 |
+
main_dart_references = [ref for ref in references if ref["uri"].endswith("main.dart")]
|
| 120 |
+
assert len(main_dart_references) >= 1
|
| 121 |
+
|
| 122 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 123 |
+
@pytest.mark.parametrize("repo_path", [Language.DART], indirect=True)
|
| 124 |
+
def test_find_definition_constructor(self, language_server: SolidLanguageServer, repo_path: Path) -> None:
|
| 125 |
+
"""Test finding definition of a constructor call."""
|
| 126 |
+
main_dart_path = str(repo_path / "lib" / "main.dart")
|
| 127 |
+
|
| 128 |
+
# In lib/main.dart:
|
| 129 |
+
# Line 104: final calc = Calculator(); // Reference to Calculator constructor
|
| 130 |
+
# Line 4: class Calculator { // Definition of Calculator class
|
| 131 |
+
definition_location_list = language_server.request_definition(main_dart_path, 103, 18) # cursor on 'Calculator'
|
| 132 |
+
|
| 133 |
+
assert definition_location_list, f"Expected non-empty definition_location_list but got {definition_location_list=}"
|
| 134 |
+
assert len(definition_location_list) >= 1
|
| 135 |
+
definition_location = definition_location_list[0]
|
| 136 |
+
assert definition_location["uri"].endswith("main.dart")
|
| 137 |
+
# Definition of Calculator class should be around line 3 (0-indexed)
|
| 138 |
+
assert 3 <= definition_location["range"]["start"]["line"] <= 7
|
| 139 |
+
|
| 140 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 141 |
+
@pytest.mark.parametrize("repo_path", [Language.DART], indirect=True)
|
| 142 |
+
def test_find_definition_import(self, language_server: SolidLanguageServer, repo_path: Path) -> None:
|
| 143 |
+
"""Test finding definition through imports."""
|
| 144 |
+
models_dart_path = str(repo_path / "lib" / "models.dart")
|
| 145 |
+
|
| 146 |
+
# Test finding definition of User class name where it's used
|
| 147 |
+
# In lib/models.dart line 27 (constructor): User(this.id, this.name, this.email, this._age);
|
| 148 |
+
definition_location_list = language_server.request_definition(models_dart_path, 26, 2) # cursor on 'User' in constructor
|
| 149 |
+
|
| 150 |
+
# Skip if language server doesn't find definition in this case
|
| 151 |
+
if not definition_location_list:
|
| 152 |
+
pytest.skip("Language server doesn't support definition lookup for this case")
|
| 153 |
+
|
| 154 |
+
assert len(definition_location_list) >= 1
|
| 155 |
+
definition_location = definition_location_list[0]
|
| 156 |
+
# Language server might return SDK files instead of local files
|
| 157 |
+
# This is acceptable behavior - the important thing is that it found a definition
|
| 158 |
+
assert "dart" in definition_location["uri"].lower()
|
| 159 |
+
|
| 160 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 161 |
+
def test_find_symbol(self, language_server: SolidLanguageServer) -> None:
|
| 162 |
+
"""Test finding symbols in the full symbol tree."""
|
| 163 |
+
symbols = language_server.request_full_symbol_tree()
|
| 164 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "Calculator"), "Calculator class not found in symbol tree"
|
| 165 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "add"), "add method not found in symbol tree"
|
| 166 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "subtract"), "subtract function not found in symbol tree"
|
| 167 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "MathHelper"), "MathHelper class not found in symbol tree"
|
| 168 |
+
assert SymbolUtils.symbol_tree_contains_name(symbols, "User"), "User class not found in symbol tree"
|
| 169 |
+
|
| 170 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 171 |
+
def test_find_referencing_symbols(self, language_server: SolidLanguageServer) -> None:
|
| 172 |
+
"""Test finding references using symbol selection range."""
|
| 173 |
+
file_path = os.path.join("lib", "main.dart")
|
| 174 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 175 |
+
|
| 176 |
+
# Handle nested symbol structure - symbols can be nested in lists
|
| 177 |
+
symbol_list = symbols[0] if symbols and isinstance(symbols[0], list) else symbols
|
| 178 |
+
|
| 179 |
+
# Find the 'add' method symbol in Calculator class
|
| 180 |
+
add_symbol = None
|
| 181 |
+
for sym in symbol_list:
|
| 182 |
+
if sym.get("name") == "add":
|
| 183 |
+
add_symbol = sym
|
| 184 |
+
break
|
| 185 |
+
# Check for nested symbols (methods inside classes)
|
| 186 |
+
if "children" in sym and sym.get("name") == "Calculator":
|
| 187 |
+
for child in sym["children"]:
|
| 188 |
+
if child.get("name") == "add":
|
| 189 |
+
add_symbol = child
|
| 190 |
+
break
|
| 191 |
+
if add_symbol:
|
| 192 |
+
break
|
| 193 |
+
|
| 194 |
+
assert add_symbol is not None, "Could not find 'add' method symbol in main.dart"
|
| 195 |
+
sel_start = add_symbol["selectionRange"]["start"]
|
| 196 |
+
refs = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 197 |
+
|
| 198 |
+
# Check that we found references - at least one should be in main.dart
|
| 199 |
+
assert any(
|
| 200 |
+
"main.dart" in ref.get("relativePath", "") or "main.dart" in ref.get("uri", "") for ref in refs
|
| 201 |
+
), "main.dart should reference add method (tried all positions in selectionRange)"
|
| 202 |
+
|
| 203 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 204 |
+
def test_request_containing_symbol_method(self, language_server: SolidLanguageServer) -> None:
|
| 205 |
+
"""Test request_containing_symbol for a method."""
|
| 206 |
+
file_path = os.path.join("lib", "main.dart")
|
| 207 |
+
# Line 14 is inside the add method body (around 'final result = a + b;')
|
| 208 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 13, 10, include_body=True)
|
| 209 |
+
|
| 210 |
+
# Verify that we found the containing symbol
|
| 211 |
+
if containing_symbol is not None:
|
| 212 |
+
assert containing_symbol["name"] == "add"
|
| 213 |
+
assert containing_symbol["kind"] == SymbolKind.Method
|
| 214 |
+
if "body" in containing_symbol:
|
| 215 |
+
assert "add" in containing_symbol["body"] or "final result" in containing_symbol["body"]
|
| 216 |
+
|
| 217 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 218 |
+
def test_request_containing_symbol_class(self, language_server: SolidLanguageServer) -> None:
|
| 219 |
+
"""Test request_containing_symbol for a class."""
|
| 220 |
+
file_path = os.path.join("lib", "main.dart")
|
| 221 |
+
# Line 4 is the Calculator class definition line
|
| 222 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 4, 6)
|
| 223 |
+
|
| 224 |
+
# Verify that we found the containing symbol
|
| 225 |
+
if containing_symbol is not None:
|
| 226 |
+
assert containing_symbol["name"] == "Calculator"
|
| 227 |
+
assert containing_symbol["kind"] == SymbolKind.Class
|
| 228 |
+
|
| 229 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 230 |
+
def test_request_containing_symbol_nested(self, language_server: SolidLanguageServer) -> None:
|
| 231 |
+
"""Test request_containing_symbol with nested scopes."""
|
| 232 |
+
file_path = os.path.join("lib", "main.dart")
|
| 233 |
+
# Line 14 is inside the add method inside Calculator class
|
| 234 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 13, 20)
|
| 235 |
+
|
| 236 |
+
# Verify that we found the innermost containing symbol (the method)
|
| 237 |
+
if containing_symbol is not None:
|
| 238 |
+
assert containing_symbol["name"] == "add"
|
| 239 |
+
assert containing_symbol["kind"] == SymbolKind.Method
|
| 240 |
+
|
| 241 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 242 |
+
def test_request_defining_symbol_variable(self, language_server: SolidLanguageServer) -> None:
|
| 243 |
+
"""Test request_defining_symbol for a variable usage."""
|
| 244 |
+
file_path = os.path.join("lib", "main.dart")
|
| 245 |
+
# Line 14 contains 'final result = a + b;' - test position on 'result'
|
| 246 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 13, 10)
|
| 247 |
+
|
| 248 |
+
# The defining symbol might be the variable itself or the containing method
|
| 249 |
+
# This is acceptable behavior - different language servers handle this differently
|
| 250 |
+
if defining_symbol is not None:
|
| 251 |
+
assert defining_symbol.get("name") in ["result", "add"]
|
| 252 |
+
if defining_symbol.get("name") == "add":
|
| 253 |
+
assert defining_symbol.get("kind") == SymbolKind.Method.value
|
| 254 |
+
|
| 255 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 256 |
+
def test_request_defining_symbol_imported_class(self, language_server: SolidLanguageServer) -> None:
|
| 257 |
+
"""Test request_defining_symbol for an imported class/function."""
|
| 258 |
+
file_path = os.path.join("lib", "main.dart")
|
| 259 |
+
# Line 20 references 'subtract' which was imported from helper.dart
|
| 260 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 19, 18)
|
| 261 |
+
|
| 262 |
+
# Verify that we found the defining symbol - this should be the subtract function from helper.dart
|
| 263 |
+
if defining_symbol is not None:
|
| 264 |
+
assert defining_symbol.get("name") == "subtract"
|
| 265 |
+
# Could be Function or Method depending on language server interpretation
|
| 266 |
+
assert defining_symbol.get("kind") in [SymbolKind.Function.value, SymbolKind.Method.value]
|
| 267 |
+
|
| 268 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 269 |
+
def test_request_defining_symbol_class_method(self, language_server: SolidLanguageServer) -> None:
|
| 270 |
+
"""Test request_defining_symbol for a static class method."""
|
| 271 |
+
file_path = os.path.join("lib", "main.dart")
|
| 272 |
+
# Line 50 references MathHelper.power - test position on 'power'
|
| 273 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 49, 30)
|
| 274 |
+
|
| 275 |
+
# Verify that we found the defining symbol - should be the power method
|
| 276 |
+
if defining_symbol is not None:
|
| 277 |
+
assert defining_symbol.get("name") == "power"
|
| 278 |
+
assert defining_symbol.get("kind") == SymbolKind.Method.value
|
| 279 |
+
|
| 280 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 281 |
+
def test_request_document_symbols(self, language_server: SolidLanguageServer) -> None:
|
| 282 |
+
"""Test getting document symbols from a Dart file."""
|
| 283 |
+
file_path = os.path.join("lib", "main.dart")
|
| 284 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 285 |
+
|
| 286 |
+
# Check that we have symbols
|
| 287 |
+
assert len(symbols) > 0
|
| 288 |
+
|
| 289 |
+
# Flatten the symbols if they're nested
|
| 290 |
+
symbol_list = symbols[0] if symbols and isinstance(symbols[0], list) else symbols
|
| 291 |
+
|
| 292 |
+
# Look for expected classes and methods
|
| 293 |
+
symbol_names = [s.get("name") for s in symbol_list]
|
| 294 |
+
assert "Calculator" in symbol_names
|
| 295 |
+
|
| 296 |
+
# Check for nested symbols (methods inside classes) - optional
|
| 297 |
+
calculator_symbol = next((s for s in symbol_list if s.get("name") == "Calculator"), None)
|
| 298 |
+
if calculator_symbol and "children" in calculator_symbol and calculator_symbol["children"]:
|
| 299 |
+
method_names = [child.get("name") for child in calculator_symbol["children"]]
|
| 300 |
+
# If children are populated, we should find the add method
|
| 301 |
+
assert "add" in method_names
|
| 302 |
+
else:
|
| 303 |
+
# Some language servers may not populate children in document symbols
|
| 304 |
+
# This is acceptable behavior - the important thing is we found the class
|
| 305 |
+
pass
|
| 306 |
+
|
| 307 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 308 |
+
def test_request_referencing_symbols_comprehensive(self, language_server: SolidLanguageServer) -> None:
|
| 309 |
+
"""Test comprehensive referencing symbols functionality."""
|
| 310 |
+
file_path = os.path.join("lib", "main.dart")
|
| 311 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 312 |
+
|
| 313 |
+
# Handle nested symbol structure
|
| 314 |
+
symbol_list = symbols[0] if symbols and isinstance(symbols[0], list) else symbols
|
| 315 |
+
|
| 316 |
+
# Find Calculator class and test its references
|
| 317 |
+
calculator_symbol = None
|
| 318 |
+
for sym in symbol_list:
|
| 319 |
+
if sym.get("name") == "Calculator":
|
| 320 |
+
calculator_symbol = sym
|
| 321 |
+
break
|
| 322 |
+
|
| 323 |
+
if calculator_symbol and "selectionRange" in calculator_symbol:
|
| 324 |
+
sel_start = calculator_symbol["selectionRange"]["start"]
|
| 325 |
+
refs = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 326 |
+
|
| 327 |
+
# Should find references to Calculator (constructor calls, etc.)
|
| 328 |
+
if refs:
|
| 329 |
+
# Verify the structure of referencing symbols
|
| 330 |
+
for ref in refs:
|
| 331 |
+
assert "uri" in ref or "relativePath" in ref
|
| 332 |
+
if "range" in ref:
|
| 333 |
+
assert "start" in ref["range"]
|
| 334 |
+
assert "end" in ref["range"]
|
| 335 |
+
|
| 336 |
+
@pytest.mark.parametrize("language_server", [Language.DART], indirect=True)
|
| 337 |
+
def test_cross_file_symbol_resolution(self, language_server: SolidLanguageServer) -> None:
|
| 338 |
+
"""Test symbol resolution across multiple files."""
|
| 339 |
+
helper_file_path = os.path.join("lib", "helper.dart")
|
| 340 |
+
|
| 341 |
+
# Test finding references to subtract function from helper.dart in main.dart
|
| 342 |
+
helper_symbols = language_server.request_document_symbols(helper_file_path)
|
| 343 |
+
symbol_list = helper_symbols[0] if helper_symbols and isinstance(helper_symbols[0], list) else helper_symbols
|
| 344 |
+
|
| 345 |
+
subtract_symbol = next((s for s in symbol_list if s.get("name") == "subtract"), None)
|
| 346 |
+
|
| 347 |
+
if subtract_symbol and "selectionRange" in subtract_symbol:
|
| 348 |
+
sel_start = subtract_symbol["selectionRange"]["start"]
|
| 349 |
+
refs = language_server.request_references(helper_file_path, sel_start["line"], sel_start["character"])
|
| 350 |
+
|
| 351 |
+
# Should find references in main.dart
|
| 352 |
+
main_dart_refs = [ref for ref in refs if "main.dart" in ref.get("uri", "") or "main.dart" in ref.get("relativePath", "")]
|
| 353 |
+
# Note: This may not always work depending on language server capabilities
|
| 354 |
+
# So we don't assert - just verify the structure if we get results
|
| 355 |
+
if main_dart_refs:
|
| 356 |
+
for ref in main_dart_refs:
|
| 357 |
+
assert "range" in ref or "location" in ref
|
projects/ui/serena-new/test/solidlsp/elixir/__init__.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import platform
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def _test_nextls_available() -> str:
|
| 5 |
+
"""Test if Next LS is available and return error reason if not."""
|
| 6 |
+
# Check if we're on Windows (Next LS doesn't support Windows)
|
| 7 |
+
if platform.system() == "Windows":
|
| 8 |
+
return "Next LS does not support Windows"
|
| 9 |
+
|
| 10 |
+
# Try to import and check Elixir availability
|
| 11 |
+
try:
|
| 12 |
+
from solidlsp.language_servers.elixir_tools.elixir_tools import ElixirTools
|
| 13 |
+
|
| 14 |
+
# Check if Elixir is installed
|
| 15 |
+
elixir_version = ElixirTools._get_elixir_version()
|
| 16 |
+
if not elixir_version:
|
| 17 |
+
return "Elixir is not installed or not in PATH"
|
| 18 |
+
|
| 19 |
+
return "" # No error, Next LS should be available
|
| 20 |
+
|
| 21 |
+
except ImportError as e:
|
| 22 |
+
return f"Failed to import ElixirTools: {e}"
|
| 23 |
+
except Exception as e:
|
| 24 |
+
return f"Error checking Next LS availability: {e}"
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
NEXTLS_UNAVAILABLE_REASON = _test_nextls_available()
|
| 28 |
+
NEXTLS_UNAVAILABLE = bool(NEXTLS_UNAVAILABLE_REASON)
|
projects/ui/serena-new/test/solidlsp/elixir/conftest.py
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Elixir-specific test configuration and fixtures.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import subprocess
|
| 7 |
+
import time
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
import pytest
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def ensure_elixir_test_repo_compiled(repo_path: str) -> None:
|
| 14 |
+
"""Ensure the Elixir test repository dependencies are installed and project is compiled.
|
| 15 |
+
|
| 16 |
+
Next LS requires the project to be fully compiled and indexed before providing
|
| 17 |
+
complete references and symbol resolution. This function:
|
| 18 |
+
1. Installs dependencies via 'mix deps.get'
|
| 19 |
+
2. Compiles the project via 'mix compile'
|
| 20 |
+
|
| 21 |
+
This is essential in CI environments where dependencies aren't pre-installed.
|
| 22 |
+
|
| 23 |
+
Args:
|
| 24 |
+
repo_path: Path to the Elixir project root directory
|
| 25 |
+
|
| 26 |
+
"""
|
| 27 |
+
# Check if this looks like an Elixir project
|
| 28 |
+
mix_file = os.path.join(repo_path, "mix.exs")
|
| 29 |
+
if not os.path.exists(mix_file):
|
| 30 |
+
return
|
| 31 |
+
|
| 32 |
+
# Check if already compiled (optimization for repeated runs)
|
| 33 |
+
build_path = os.path.join(repo_path, "_build")
|
| 34 |
+
deps_path = os.path.join(repo_path, "deps")
|
| 35 |
+
|
| 36 |
+
if os.path.exists(build_path) and os.path.exists(deps_path):
|
| 37 |
+
print(f"Elixir test repository already compiled in {repo_path}")
|
| 38 |
+
return
|
| 39 |
+
|
| 40 |
+
try:
|
| 41 |
+
print("Installing dependencies and compiling Elixir test repository for optimal Next LS performance...")
|
| 42 |
+
|
| 43 |
+
# First, install dependencies with increased timeout for CI
|
| 44 |
+
print("=" * 60)
|
| 45 |
+
print("Step 1/2: Installing Elixir dependencies...")
|
| 46 |
+
print("=" * 60)
|
| 47 |
+
start_time = time.time()
|
| 48 |
+
|
| 49 |
+
deps_result = subprocess.run(
|
| 50 |
+
["mix", "deps.get"],
|
| 51 |
+
cwd=repo_path,
|
| 52 |
+
capture_output=True,
|
| 53 |
+
text=True,
|
| 54 |
+
timeout=180,
|
| 55 |
+
check=False, # 3 minutes for dependency installation (CI can be slow)
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
deps_duration = time.time() - start_time
|
| 59 |
+
print(f"Dependencies installation completed in {deps_duration:.2f} seconds")
|
| 60 |
+
|
| 61 |
+
# Always log the output for transparency
|
| 62 |
+
if deps_result.stdout.strip():
|
| 63 |
+
print("Dependencies stdout:")
|
| 64 |
+
print("-" * 40)
|
| 65 |
+
print(deps_result.stdout)
|
| 66 |
+
print("-" * 40)
|
| 67 |
+
|
| 68 |
+
if deps_result.stderr.strip():
|
| 69 |
+
print("Dependencies stderr:")
|
| 70 |
+
print("-" * 40)
|
| 71 |
+
print(deps_result.stderr)
|
| 72 |
+
print("-" * 40)
|
| 73 |
+
|
| 74 |
+
if deps_result.returncode != 0:
|
| 75 |
+
print(f"⚠️ Warning: Dependencies installation failed with exit code {deps_result.returncode}")
|
| 76 |
+
# Continue anyway - some projects might not have dependencies
|
| 77 |
+
else:
|
| 78 |
+
print("✓ Dependencies installed successfully")
|
| 79 |
+
|
| 80 |
+
# Then compile the project with increased timeout for CI
|
| 81 |
+
print("=" * 60)
|
| 82 |
+
print("Step 2/2: Compiling Elixir project...")
|
| 83 |
+
print("=" * 60)
|
| 84 |
+
start_time = time.time()
|
| 85 |
+
|
| 86 |
+
compile_result = subprocess.run(
|
| 87 |
+
["mix", "compile"],
|
| 88 |
+
cwd=repo_path,
|
| 89 |
+
capture_output=True,
|
| 90 |
+
text=True,
|
| 91 |
+
timeout=300,
|
| 92 |
+
check=False, # 5 minutes for compilation (Credo compilation can be slow in CI)
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
compile_duration = time.time() - start_time
|
| 96 |
+
print(f"Compilation completed in {compile_duration:.2f} seconds")
|
| 97 |
+
|
| 98 |
+
# Always log the output for transparency
|
| 99 |
+
if compile_result.stdout.strip():
|
| 100 |
+
print("Compilation stdout:")
|
| 101 |
+
print("-" * 40)
|
| 102 |
+
print(compile_result.stdout)
|
| 103 |
+
print("-" * 40)
|
| 104 |
+
|
| 105 |
+
if compile_result.stderr.strip():
|
| 106 |
+
print("Compilation stderr:")
|
| 107 |
+
print("-" * 40)
|
| 108 |
+
print(compile_result.stderr)
|
| 109 |
+
print("-" * 40)
|
| 110 |
+
|
| 111 |
+
if compile_result.returncode == 0:
|
| 112 |
+
print(f"✓ Elixir test repository compiled successfully in {repo_path}")
|
| 113 |
+
else:
|
| 114 |
+
print(f"⚠️ Warning: Compilation completed with exit code {compile_result.returncode}")
|
| 115 |
+
# Still continue - warnings are often non-fatal
|
| 116 |
+
|
| 117 |
+
print("=" * 60)
|
| 118 |
+
print(f"Total setup time: {time.time() - (start_time - compile_duration - deps_duration):.2f} seconds")
|
| 119 |
+
print("=" * 60)
|
| 120 |
+
|
| 121 |
+
except subprocess.TimeoutExpired as e:
|
| 122 |
+
print("=" * 60)
|
| 123 |
+
print(f"❌ TIMEOUT: Elixir setup timed out after {e.timeout} seconds")
|
| 124 |
+
print(f"Command: {' '.join(e.cmd)}")
|
| 125 |
+
print("This may indicate slow CI environment - Next LS may still work but with reduced functionality")
|
| 126 |
+
|
| 127 |
+
# Try to get partial output if available
|
| 128 |
+
if hasattr(e, "stdout") and e.stdout:
|
| 129 |
+
print("Partial stdout before timeout:")
|
| 130 |
+
print("-" * 40)
|
| 131 |
+
print(e.stdout)
|
| 132 |
+
print("-" * 40)
|
| 133 |
+
if hasattr(e, "stderr") and e.stderr:
|
| 134 |
+
print("Partial stderr before timeout:")
|
| 135 |
+
print("-" * 40)
|
| 136 |
+
print(e.stderr)
|
| 137 |
+
print("-" * 40)
|
| 138 |
+
print("=" * 60)
|
| 139 |
+
|
| 140 |
+
except FileNotFoundError:
|
| 141 |
+
print("❌ ERROR: 'mix' command not found - Elixir test repository may not be compiled")
|
| 142 |
+
print("Please ensure Elixir is installed and available in PATH")
|
| 143 |
+
except Exception as e:
|
| 144 |
+
print(f"❌ ERROR: Failed to prepare Elixir test repository: {e}")
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
@pytest.fixture(scope="session", autouse=True)
|
| 148 |
+
def setup_elixir_test_environment():
|
| 149 |
+
"""Automatically prepare Elixir test environment for all Elixir tests.
|
| 150 |
+
|
| 151 |
+
This fixture runs once per test session and automatically:
|
| 152 |
+
1. Installs dependencies via 'mix deps.get'
|
| 153 |
+
2. Compiles the Elixir test repository via 'mix compile'
|
| 154 |
+
|
| 155 |
+
It uses autouse=True so it runs automatically without needing to be explicitly
|
| 156 |
+
requested by tests. This ensures Next LS has a fully prepared project to work with.
|
| 157 |
+
|
| 158 |
+
Uses generous timeouts (3-5 minutes) to accommodate slow CI environments.
|
| 159 |
+
All output is logged for transparency and debugging.
|
| 160 |
+
"""
|
| 161 |
+
# Get the test repo path relative to this conftest.py file
|
| 162 |
+
test_repo_path = Path(__file__).parent.parent.parent / "resources" / "repos" / "elixir" / "test_repo"
|
| 163 |
+
ensure_elixir_test_repo_compiled(str(test_repo_path))
|
| 164 |
+
return str(test_repo_path)
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
@pytest.fixture(scope="session")
|
| 168 |
+
def elixir_test_repo_path(setup_elixir_test_environment):
|
| 169 |
+
"""Get the path to the prepared Elixir test repository.
|
| 170 |
+
|
| 171 |
+
This fixture depends on setup_elixir_test_environment to ensure dependencies
|
| 172 |
+
are installed and compilation has completed before returning the path.
|
| 173 |
+
"""
|
| 174 |
+
return setup_elixir_test_environment
|
projects/ui/serena-new/test/solidlsp/elixir/test_elixir_basic.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Basic integration tests for the Elixir 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 solidlsp import SolidLanguageServer
|
| 13 |
+
from solidlsp.ls_config import Language
|
| 14 |
+
|
| 15 |
+
from . import NEXTLS_UNAVAILABLE, NEXTLS_UNAVAILABLE_REASON
|
| 16 |
+
|
| 17 |
+
# These marks will be applied to all tests in this module
|
| 18 |
+
pytestmark = [pytest.mark.elixir, pytest.mark.skipif(NEXTLS_UNAVAILABLE, reason=f"Next LS not available: {NEXTLS_UNAVAILABLE_REASON}")]
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class TestElixirBasic:
|
| 22 |
+
"""Basic Elixir language server functionality tests."""
|
| 23 |
+
|
| 24 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 25 |
+
def test_request_references_function_definition(self, language_server: SolidLanguageServer):
|
| 26 |
+
"""Test finding references to a function definition."""
|
| 27 |
+
file_path = os.path.join("lib", "models.ex")
|
| 28 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 29 |
+
|
| 30 |
+
# Find the User module's 'new' function
|
| 31 |
+
user_new_symbol = None
|
| 32 |
+
for symbol in symbols[0]: # Top level symbols
|
| 33 |
+
if symbol.get("name") == "User" and symbol.get("kind") == 2: # Module
|
| 34 |
+
for child in symbol.get("children", []):
|
| 35 |
+
if child.get("name", "").startswith("def new(") and child.get("kind") == 12: # Function
|
| 36 |
+
user_new_symbol = child
|
| 37 |
+
break
|
| 38 |
+
break
|
| 39 |
+
|
| 40 |
+
if not user_new_symbol or "selectionRange" not in user_new_symbol:
|
| 41 |
+
pytest.skip("User.new function or its selectionRange not found")
|
| 42 |
+
|
| 43 |
+
sel_start = user_new_symbol["selectionRange"]["start"]
|
| 44 |
+
references = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 45 |
+
|
| 46 |
+
assert references is not None
|
| 47 |
+
assert len(references) > 0
|
| 48 |
+
|
| 49 |
+
# Should find at least one reference (the definition itself)
|
| 50 |
+
found_definition = any(ref["uri"].endswith("models.ex") for ref in references)
|
| 51 |
+
assert found_definition, "Should find the function definition"
|
| 52 |
+
|
| 53 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 54 |
+
def test_request_references_create_user_function(self, language_server: SolidLanguageServer):
|
| 55 |
+
"""Test finding references to create_user function."""
|
| 56 |
+
file_path = os.path.join("lib", "services.ex")
|
| 57 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 58 |
+
|
| 59 |
+
# Find the UserService module's 'create_user' function
|
| 60 |
+
create_user_symbol = None
|
| 61 |
+
for symbol in symbols[0]: # Top level symbols
|
| 62 |
+
if symbol.get("name") == "UserService" and symbol.get("kind") == 2: # Module
|
| 63 |
+
for child in symbol.get("children", []):
|
| 64 |
+
if child.get("name", "").startswith("def create_user(") and child.get("kind") == 12: # Function
|
| 65 |
+
create_user_symbol = child
|
| 66 |
+
break
|
| 67 |
+
break
|
| 68 |
+
|
| 69 |
+
if not create_user_symbol or "selectionRange" not in create_user_symbol:
|
| 70 |
+
pytest.skip("UserService.create_user function or its selectionRange not found")
|
| 71 |
+
|
| 72 |
+
sel_start = create_user_symbol["selectionRange"]["start"]
|
| 73 |
+
references = language_server.request_references(file_path, sel_start["line"], sel_start["character"])
|
| 74 |
+
|
| 75 |
+
assert references is not None
|
| 76 |
+
assert len(references) > 0
|
| 77 |
+
|
| 78 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 79 |
+
def test_request_referencing_symbols_function(self, language_server: SolidLanguageServer):
|
| 80 |
+
"""Test finding symbols that reference a specific function."""
|
| 81 |
+
file_path = os.path.join("lib", "models.ex")
|
| 82 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 83 |
+
|
| 84 |
+
# Find the User module's 'new' function
|
| 85 |
+
user_new_symbol = None
|
| 86 |
+
for symbol in symbols[0]: # Top level symbols
|
| 87 |
+
if symbol.get("name") == "User" and symbol.get("kind") == 2: # Module
|
| 88 |
+
for child in symbol.get("children", []):
|
| 89 |
+
if child.get("name", "").startswith("def new(") and child.get("kind") == 12: # Function
|
| 90 |
+
user_new_symbol = child
|
| 91 |
+
break
|
| 92 |
+
break
|
| 93 |
+
|
| 94 |
+
if not user_new_symbol or "selectionRange" not in user_new_symbol:
|
| 95 |
+
pytest.skip("User.new function or its selectionRange not found")
|
| 96 |
+
|
| 97 |
+
sel_start = user_new_symbol["selectionRange"]["start"]
|
| 98 |
+
referencing_symbols = language_server.request_referencing_symbols(file_path, sel_start["line"], sel_start["character"])
|
| 99 |
+
|
| 100 |
+
assert referencing_symbols is not None
|
| 101 |
+
|
| 102 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 103 |
+
def test_timeout_enumeration_bug(self, language_server: SolidLanguageServer):
|
| 104 |
+
"""Test that enumeration doesn't timeout (regression test)."""
|
| 105 |
+
# This should complete without timing out
|
| 106 |
+
symbols = language_server.request_document_symbols("lib/models.ex")
|
| 107 |
+
assert symbols is not None
|
| 108 |
+
|
| 109 |
+
# Test multiple symbol requests in succession
|
| 110 |
+
for _ in range(3):
|
| 111 |
+
symbols = language_server.request_document_symbols("lib/services.ex")
|
| 112 |
+
assert symbols is not None
|
projects/ui/serena-new/test/solidlsp/elixir/test_elixir_ignored_dirs.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
from . import NEXTLS_UNAVAILABLE, NEXTLS_UNAVAILABLE_REASON
|
| 11 |
+
|
| 12 |
+
# These marks will be applied to all tests in this module
|
| 13 |
+
pytestmark = [pytest.mark.elixir, pytest.mark.skipif(NEXTLS_UNAVAILABLE, reason=f"Next LS not available: {NEXTLS_UNAVAILABLE_REASON}")]
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@pytest.fixture(scope="module")
|
| 17 |
+
def ls_with_ignored_dirs() -> Generator[SolidLanguageServer, None, None]:
|
| 18 |
+
"""Fixture to set up an LS for the elixir test repo with the 'scripts' directory ignored."""
|
| 19 |
+
ignored_paths = ["scripts", "ignored_dir"]
|
| 20 |
+
ls = create_ls(ignored_paths=ignored_paths, language=Language.ELIXIR)
|
| 21 |
+
ls.start()
|
| 22 |
+
try:
|
| 23 |
+
yield ls
|
| 24 |
+
finally:
|
| 25 |
+
ls.stop()
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
@pytest.mark.parametrize("ls_with_ignored_dirs", [Language.ELIXIR], indirect=True)
|
| 29 |
+
def test_symbol_tree_ignores_dir(ls_with_ignored_dirs: SolidLanguageServer):
|
| 30 |
+
"""Tests that request_full_symbol_tree ignores the configured directory."""
|
| 31 |
+
root = ls_with_ignored_dirs.request_full_symbol_tree()[0]
|
| 32 |
+
root_children = root["children"]
|
| 33 |
+
children_names = {child["name"] for child in root_children}
|
| 34 |
+
|
| 35 |
+
# Should have lib and test directories, but not scripts or ignored_dir
|
| 36 |
+
expected_dirs = {"lib", "test"}
|
| 37 |
+
assert expected_dirs.issubset(children_names), f"Expected {expected_dirs} to be in {children_names}"
|
| 38 |
+
assert "scripts" not in children_names, f"scripts should not be in {children_names}"
|
| 39 |
+
assert "ignored_dir" not in children_names, f"ignored_dir should not be in {children_names}"
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
@pytest.mark.parametrize("ls_with_ignored_dirs", [Language.ELIXIR], indirect=True)
|
| 43 |
+
def test_find_references_ignores_dir(ls_with_ignored_dirs: SolidLanguageServer):
|
| 44 |
+
"""Tests that find_references ignores the configured directory."""
|
| 45 |
+
# Location of User struct, which is referenced in scripts and ignored_dir
|
| 46 |
+
definition_file = "lib/models.ex"
|
| 47 |
+
|
| 48 |
+
# Find the User struct definition
|
| 49 |
+
symbols = ls_with_ignored_dirs.request_document_symbols(definition_file)
|
| 50 |
+
user_symbol = None
|
| 51 |
+
for symbol_group in symbols:
|
| 52 |
+
user_symbol = next((s for s in symbol_group if "User" in s.get("name", "")), None)
|
| 53 |
+
if user_symbol:
|
| 54 |
+
break
|
| 55 |
+
|
| 56 |
+
if not user_symbol or "selectionRange" not in user_symbol:
|
| 57 |
+
pytest.skip("User symbol not found for reference testing")
|
| 58 |
+
|
| 59 |
+
sel_start = user_symbol["selectionRange"]["start"]
|
| 60 |
+
references = ls_with_ignored_dirs.request_references(definition_file, sel_start["line"], sel_start["character"])
|
| 61 |
+
|
| 62 |
+
# Assert that scripts and ignored_dir do not appear in the references
|
| 63 |
+
assert not any("scripts" in ref["relativePath"] for ref in references), "scripts should be ignored"
|
| 64 |
+
assert not any("ignored_dir" in ref["relativePath"] for ref in references), "ignored_dir should be ignored"
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
@pytest.mark.parametrize("repo_path", [Language.ELIXIR], indirect=True)
|
| 68 |
+
def test_refs_and_symbols_with_glob_patterns(repo_path: Path) -> None:
|
| 69 |
+
"""Tests that refs and symbols with glob patterns are ignored."""
|
| 70 |
+
ignored_paths = ["*cripts", "ignored_*"] # codespell:ignore cripts
|
| 71 |
+
ls = create_ls(ignored_paths=ignored_paths, repo_path=str(repo_path), language=Language.ELIXIR)
|
| 72 |
+
ls.start()
|
| 73 |
+
|
| 74 |
+
try:
|
| 75 |
+
# Same as in the above tests
|
| 76 |
+
root = ls.request_full_symbol_tree()[0]
|
| 77 |
+
root_children = root["children"]
|
| 78 |
+
children_names = {child["name"] for child in root_children}
|
| 79 |
+
|
| 80 |
+
# Should have lib and test directories, but not scripts or ignored_dir
|
| 81 |
+
expected_dirs = {"lib", "test"}
|
| 82 |
+
assert expected_dirs.issubset(children_names), f"Expected {expected_dirs} to be in {children_names}"
|
| 83 |
+
assert "scripts" not in children_names, f"scripts should not be in {children_names} (glob pattern)"
|
| 84 |
+
assert "ignored_dir" not in children_names, f"ignored_dir should not be in {children_names} (glob pattern)"
|
| 85 |
+
|
| 86 |
+
# Test that the refs and symbols with glob patterns are ignored
|
| 87 |
+
definition_file = "lib/models.ex"
|
| 88 |
+
|
| 89 |
+
# Find the User struct definition
|
| 90 |
+
symbols = ls.request_document_symbols(definition_file)
|
| 91 |
+
user_symbol = None
|
| 92 |
+
for symbol_group in symbols:
|
| 93 |
+
user_symbol = next((s for s in symbol_group if "User" in s.get("name", "")), None)
|
| 94 |
+
if user_symbol:
|
| 95 |
+
break
|
| 96 |
+
|
| 97 |
+
if user_symbol and "selectionRange" in user_symbol:
|
| 98 |
+
sel_start = user_symbol["selectionRange"]["start"]
|
| 99 |
+
references = ls.request_references(definition_file, sel_start["line"], sel_start["character"])
|
| 100 |
+
|
| 101 |
+
# Assert that scripts and ignored_dir do not appear in references
|
| 102 |
+
assert not any("scripts" in ref["relativePath"] for ref in references), "scripts should be ignored (glob)"
|
| 103 |
+
assert not any("ignored_dir" in ref["relativePath"] for ref in references), "ignored_dir should be ignored (glob)"
|
| 104 |
+
finally:
|
| 105 |
+
ls.stop()
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 109 |
+
def test_default_ignored_directories(language_server: SolidLanguageServer):
|
| 110 |
+
"""Test that default Elixir directories are ignored."""
|
| 111 |
+
# Test that Elixir-specific directories are ignored by default
|
| 112 |
+
assert language_server.is_ignored_dirname("_build"), "_build should be ignored"
|
| 113 |
+
assert language_server.is_ignored_dirname("deps"), "deps should be ignored"
|
| 114 |
+
assert language_server.is_ignored_dirname(".elixir_ls"), ".elixir_ls should be ignored"
|
| 115 |
+
assert language_server.is_ignored_dirname("cover"), "cover should be ignored"
|
| 116 |
+
assert language_server.is_ignored_dirname("node_modules"), "node_modules should be ignored"
|
| 117 |
+
|
| 118 |
+
# Test that important directories are not ignored
|
| 119 |
+
assert not language_server.is_ignored_dirname("lib"), "lib should not be ignored"
|
| 120 |
+
assert not language_server.is_ignored_dirname("test"), "test should not be ignored"
|
| 121 |
+
assert not language_server.is_ignored_dirname("config"), "config should not be ignored"
|
| 122 |
+
assert not language_server.is_ignored_dirname("priv"), "priv should not be ignored"
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 126 |
+
def test_symbol_tree_excludes_build_dirs(language_server: SolidLanguageServer):
|
| 127 |
+
"""Test that symbol tree excludes build and dependency directories."""
|
| 128 |
+
symbol_tree = language_server.request_full_symbol_tree()
|
| 129 |
+
|
| 130 |
+
if symbol_tree:
|
| 131 |
+
root = symbol_tree[0]
|
| 132 |
+
children_names = {child["name"] for child in root.get("children", [])}
|
| 133 |
+
|
| 134 |
+
# Build and dependency directories should not appear
|
| 135 |
+
ignored_dirs = {"_build", "deps", ".elixir_ls", "cover", "node_modules"}
|
| 136 |
+
found_ignored = ignored_dirs.intersection(children_names)
|
| 137 |
+
assert len(found_ignored) == 0, f"Found ignored directories in symbol tree: {found_ignored}"
|
| 138 |
+
|
| 139 |
+
# Important directories should appear
|
| 140 |
+
important_dirs = {"lib", "test"}
|
| 141 |
+
found_important = important_dirs.intersection(children_names)
|
| 142 |
+
assert len(found_important) > 0, f"Expected to find important directories: {important_dirs}, got: {children_names}"
|
projects/ui/serena-new/test/solidlsp/elixir/test_elixir_integration.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Integration tests for Elixir language server with test repository.
|
| 3 |
+
|
| 4 |
+
These tests verify that the language server works correctly with a real Elixir project
|
| 5 |
+
and can perform advanced operations like cross-file symbol resolution.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import os
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
import pytest
|
| 12 |
+
|
| 13 |
+
from serena.project import Project
|
| 14 |
+
from solidlsp import SolidLanguageServer
|
| 15 |
+
from solidlsp.ls_config import Language
|
| 16 |
+
|
| 17 |
+
from . import NEXTLS_UNAVAILABLE, NEXTLS_UNAVAILABLE_REASON
|
| 18 |
+
|
| 19 |
+
# These marks will be applied to all tests in this module
|
| 20 |
+
pytestmark = [pytest.mark.elixir, pytest.mark.skipif(NEXTLS_UNAVAILABLE, reason=f"Next LS not available: {NEXTLS_UNAVAILABLE_REASON}")]
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class TestElixirIntegration:
|
| 24 |
+
"""Integration tests for Elixir language server with test repository."""
|
| 25 |
+
|
| 26 |
+
@pytest.fixture
|
| 27 |
+
def elixir_test_repo_path(self):
|
| 28 |
+
"""Get the path to the Elixir test repository."""
|
| 29 |
+
test_dir = Path(__file__).parent.parent.parent
|
| 30 |
+
return str(test_dir / "resources" / "repos" / "elixir" / "test_repo")
|
| 31 |
+
|
| 32 |
+
def test_elixir_repo_structure(self, elixir_test_repo_path):
|
| 33 |
+
"""Test that the Elixir test repository has the expected structure."""
|
| 34 |
+
repo_path = Path(elixir_test_repo_path)
|
| 35 |
+
|
| 36 |
+
# Check that key files exist
|
| 37 |
+
assert (repo_path / "mix.exs").exists(), "mix.exs should exist"
|
| 38 |
+
assert (repo_path / "lib" / "test_repo.ex").exists(), "main module should exist"
|
| 39 |
+
assert (repo_path / "lib" / "utils.ex").exists(), "utils module should exist"
|
| 40 |
+
assert (repo_path / "lib" / "models.ex").exists(), "models module should exist"
|
| 41 |
+
assert (repo_path / "lib" / "services.ex").exists(), "services module should exist"
|
| 42 |
+
assert (repo_path / "lib" / "examples.ex").exists(), "examples module should exist"
|
| 43 |
+
assert (repo_path / "test" / "test_repo_test.exs").exists(), "test file should exist"
|
| 44 |
+
assert (repo_path / "test" / "models_test.exs").exists(), "models test should exist"
|
| 45 |
+
|
| 46 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 47 |
+
def test_cross_file_symbol_resolution(self, language_server: SolidLanguageServer):
|
| 48 |
+
"""Test that symbols can be resolved across different files."""
|
| 49 |
+
# Test that User struct from models.ex can be found when referenced in services.ex
|
| 50 |
+
services_file = os.path.join("lib", "services.ex")
|
| 51 |
+
|
| 52 |
+
# Find where User is referenced in services.ex
|
| 53 |
+
content = language_server.retrieve_full_file_content(services_file)
|
| 54 |
+
lines = content.split("\n")
|
| 55 |
+
user_reference_line = None
|
| 56 |
+
for i, line in enumerate(lines):
|
| 57 |
+
if "alias TestRepo.Models.{User" in line:
|
| 58 |
+
user_reference_line = i
|
| 59 |
+
break
|
| 60 |
+
|
| 61 |
+
if user_reference_line is None:
|
| 62 |
+
pytest.skip("Could not find User reference in services.ex")
|
| 63 |
+
|
| 64 |
+
# Try to find the definition
|
| 65 |
+
defining_symbol = language_server.request_defining_symbol(services_file, user_reference_line, 30)
|
| 66 |
+
|
| 67 |
+
if defining_symbol and "location" in defining_symbol:
|
| 68 |
+
# Should point to models.ex
|
| 69 |
+
assert "models.ex" in defining_symbol["location"]["uri"]
|
| 70 |
+
|
| 71 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 72 |
+
def test_module_hierarchy_understanding(self, language_server: SolidLanguageServer):
|
| 73 |
+
"""Test that the language server understands Elixir module hierarchy."""
|
| 74 |
+
models_file = os.path.join("lib", "models.ex")
|
| 75 |
+
symbols = language_server.request_document_symbols(models_file)
|
| 76 |
+
|
| 77 |
+
if symbols:
|
| 78 |
+
# Flatten symbol structure
|
| 79 |
+
all_symbols = []
|
| 80 |
+
for symbol_group in symbols:
|
| 81 |
+
if isinstance(symbol_group, list):
|
| 82 |
+
all_symbols.extend(symbol_group)
|
| 83 |
+
else:
|
| 84 |
+
all_symbols.append(symbol_group)
|
| 85 |
+
|
| 86 |
+
symbol_names = [s.get("name", "") for s in all_symbols]
|
| 87 |
+
|
| 88 |
+
# Should understand nested module structure
|
| 89 |
+
expected_modules = ["TestRepo.Models", "User", "Item", "Order"]
|
| 90 |
+
found_modules = [name for name in expected_modules if any(name in symbol_name for symbol_name in symbol_names)]
|
| 91 |
+
assert len(found_modules) > 0, f"Expected modules {expected_modules}, found symbols {symbol_names}"
|
| 92 |
+
|
| 93 |
+
def test_file_extension_matching(self):
|
| 94 |
+
"""Test that the Elixir language recognizes the correct file extensions."""
|
| 95 |
+
language = Language.ELIXIR
|
| 96 |
+
matcher = language.get_source_fn_matcher()
|
| 97 |
+
|
| 98 |
+
# Test Elixir file extensions
|
| 99 |
+
assert matcher.is_relevant_filename("lib/test_repo.ex")
|
| 100 |
+
assert matcher.is_relevant_filename("test/test_repo_test.exs")
|
| 101 |
+
assert matcher.is_relevant_filename("config/config.exs")
|
| 102 |
+
assert matcher.is_relevant_filename("mix.exs")
|
| 103 |
+
assert matcher.is_relevant_filename("lib/models.ex")
|
| 104 |
+
assert matcher.is_relevant_filename("lib/services.ex")
|
| 105 |
+
|
| 106 |
+
# Test non-Elixir files
|
| 107 |
+
assert not matcher.is_relevant_filename("README.md")
|
| 108 |
+
assert not matcher.is_relevant_filename("lib/test_repo.py")
|
| 109 |
+
assert not matcher.is_relevant_filename("package.json")
|
| 110 |
+
assert not matcher.is_relevant_filename("Cargo.toml")
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
class TestElixirProject:
|
| 114 |
+
@pytest.mark.parametrize("project", [Language.ELIXIR], indirect=True)
|
| 115 |
+
def test_comprehensive_symbol_search(self, project: Project):
|
| 116 |
+
"""Test comprehensive symbol search across the entire project."""
|
| 117 |
+
# Search for all function definitions
|
| 118 |
+
function_pattern = r"def\s+\w+\s*[\(\s]"
|
| 119 |
+
function_matches = project.search_source_files_for_pattern(function_pattern)
|
| 120 |
+
|
| 121 |
+
# Should find functions across multiple files
|
| 122 |
+
if function_matches:
|
| 123 |
+
files_with_functions = set()
|
| 124 |
+
for match in function_matches:
|
| 125 |
+
if match.source_file_path:
|
| 126 |
+
files_with_functions.add(os.path.basename(match.source_file_path))
|
| 127 |
+
|
| 128 |
+
# Should find functions in multiple files
|
| 129 |
+
expected_files = {"models.ex", "services.ex", "examples.ex", "utils.ex", "test_repo.ex"}
|
| 130 |
+
found_files = expected_files.intersection(files_with_functions)
|
| 131 |
+
assert len(found_files) > 0, f"Expected functions in {expected_files}, found in {files_with_functions}"
|
| 132 |
+
|
| 133 |
+
# Search for struct definitions
|
| 134 |
+
struct_pattern = r"defstruct\s+\["
|
| 135 |
+
struct_matches = project.search_source_files_for_pattern(struct_pattern)
|
| 136 |
+
|
| 137 |
+
if struct_matches:
|
| 138 |
+
# Should find structs primarily in models.ex
|
| 139 |
+
models_structs = [m for m in struct_matches if m.source_file_path and "models.ex" in m.source_file_path]
|
| 140 |
+
assert len(models_structs) > 0, "Should find struct definitions in models.ex"
|
| 141 |
+
|
| 142 |
+
@pytest.mark.parametrize("project", [Language.ELIXIR], indirect=True)
|
| 143 |
+
def test_protocol_and_implementation_understanding(self, project: Project):
|
| 144 |
+
"""Test that the language server understands Elixir protocols and implementations."""
|
| 145 |
+
# Search for protocol definitions
|
| 146 |
+
protocol_pattern = r"defprotocol\s+\w+"
|
| 147 |
+
protocol_matches = project.search_source_files_for_pattern(protocol_pattern, paths_include_glob="**/models.ex")
|
| 148 |
+
|
| 149 |
+
if protocol_matches:
|
| 150 |
+
# Should find the Serializable protocol
|
| 151 |
+
serializable_matches = [m for m in protocol_matches if "Serializable" in str(m)]
|
| 152 |
+
assert len(serializable_matches) > 0, "Should find Serializable protocol definition"
|
| 153 |
+
|
| 154 |
+
# Search for protocol implementations
|
| 155 |
+
impl_pattern = r"defimpl\s+\w+"
|
| 156 |
+
impl_matches = project.search_source_files_for_pattern(impl_pattern, paths_include_glob="**/models.ex")
|
| 157 |
+
|
| 158 |
+
if impl_matches:
|
| 159 |
+
# Should find multiple implementations
|
| 160 |
+
assert len(impl_matches) >= 3, f"Should find at least 3 protocol implementations, found {len(impl_matches)}"
|
projects/ui/serena-new/test/solidlsp/elixir/test_elixir_symbol_retrieval.py
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Tests for the Elixir 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 NEXTLS_UNAVAILABLE, NEXTLS_UNAVAILABLE_REASON
|
| 19 |
+
|
| 20 |
+
# These marks will be applied to all tests in this module
|
| 21 |
+
pytestmark = [pytest.mark.elixir, pytest.mark.skipif(NEXTLS_UNAVAILABLE, reason=f"Next LS not available: {NEXTLS_UNAVAILABLE_REASON}")]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class TestElixirLanguageServerSymbols:
|
| 25 |
+
"""Test the Elixir language server's symbol-related functionality."""
|
| 26 |
+
|
| 27 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 28 |
+
def test_request_containing_symbol_function(self, language_server: SolidLanguageServer) -> None:
|
| 29 |
+
"""Test request_containing_symbol for a function."""
|
| 30 |
+
# Test for a position inside the create_user function
|
| 31 |
+
file_path = os.path.join("lib", "services.ex")
|
| 32 |
+
|
| 33 |
+
# Find the create_user function in the file
|
| 34 |
+
content = language_server.retrieve_full_file_content(file_path)
|
| 35 |
+
lines = content.split("\n")
|
| 36 |
+
create_user_line = None
|
| 37 |
+
for i, line in enumerate(lines):
|
| 38 |
+
if "def create_user(" in line:
|
| 39 |
+
create_user_line = i + 2 # Go inside the function body
|
| 40 |
+
break
|
| 41 |
+
|
| 42 |
+
if create_user_line is None:
|
| 43 |
+
pytest.skip("Could not find create_user function")
|
| 44 |
+
|
| 45 |
+
containing_symbol = language_server.request_containing_symbol(file_path, create_user_line, 10, include_body=True)
|
| 46 |
+
|
| 47 |
+
# Verify that we found the containing symbol
|
| 48 |
+
if containing_symbol:
|
| 49 |
+
# Next LS returns the full function signature instead of just the function name
|
| 50 |
+
assert containing_symbol["name"] == "def create_user(pid, id, name, email, roles \\\\ [])"
|
| 51 |
+
assert containing_symbol["kind"] == SymbolKind.Method or containing_symbol["kind"] == SymbolKind.Function
|
| 52 |
+
if "body" in containing_symbol:
|
| 53 |
+
assert "def create_user" in containing_symbol["body"]
|
| 54 |
+
|
| 55 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 56 |
+
def test_request_containing_symbol_module(self, language_server: SolidLanguageServer) -> None:
|
| 57 |
+
"""Test request_containing_symbol for a module."""
|
| 58 |
+
# Test for a position inside the UserService module but outside any function
|
| 59 |
+
file_path = os.path.join("lib", "services.ex")
|
| 60 |
+
|
| 61 |
+
# Find the UserService module definition
|
| 62 |
+
content = language_server.retrieve_full_file_content(file_path)
|
| 63 |
+
lines = content.split("\n")
|
| 64 |
+
user_service_line = None
|
| 65 |
+
for i, line in enumerate(lines):
|
| 66 |
+
if "defmodule UserService do" in line:
|
| 67 |
+
user_service_line = i + 1 # Go inside the module
|
| 68 |
+
break
|
| 69 |
+
|
| 70 |
+
if user_service_line is None:
|
| 71 |
+
pytest.skip("Could not find UserService module")
|
| 72 |
+
|
| 73 |
+
containing_symbol = language_server.request_containing_symbol(file_path, user_service_line, 5)
|
| 74 |
+
|
| 75 |
+
# Verify that we found the containing symbol
|
| 76 |
+
if containing_symbol:
|
| 77 |
+
assert "UserService" in containing_symbol["name"]
|
| 78 |
+
assert containing_symbol["kind"] == SymbolKind.Module or containing_symbol["kind"] == SymbolKind.Class
|
| 79 |
+
|
| 80 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 81 |
+
def test_request_containing_symbol_nested(self, language_server: SolidLanguageServer) -> None:
|
| 82 |
+
"""Test request_containing_symbol with nested scopes."""
|
| 83 |
+
# Test for a position inside a function which is inside a module
|
| 84 |
+
file_path = os.path.join("lib", "services.ex")
|
| 85 |
+
|
| 86 |
+
# Find a function inside UserService
|
| 87 |
+
content = language_server.retrieve_full_file_content(file_path)
|
| 88 |
+
lines = content.split("\n")
|
| 89 |
+
function_body_line = None
|
| 90 |
+
for i, line in enumerate(lines):
|
| 91 |
+
if "def create_user(" in line:
|
| 92 |
+
function_body_line = i + 3 # Go deeper into the function body
|
| 93 |
+
break
|
| 94 |
+
|
| 95 |
+
if function_body_line is None:
|
| 96 |
+
pytest.skip("Could not find function body")
|
| 97 |
+
|
| 98 |
+
containing_symbol = language_server.request_containing_symbol(file_path, function_body_line, 15)
|
| 99 |
+
|
| 100 |
+
# Verify that we found the innermost containing symbol (the function)
|
| 101 |
+
if containing_symbol:
|
| 102 |
+
expected_names = ["create_user", "UserService"]
|
| 103 |
+
assert any(name in containing_symbol["name"] for name in expected_names)
|
| 104 |
+
|
| 105 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 106 |
+
def test_request_containing_symbol_none(self, language_server: SolidLanguageServer) -> None:
|
| 107 |
+
"""Test request_containing_symbol for a position with no containing symbol."""
|
| 108 |
+
# Test for a position outside any function/module (e.g., in module doc)
|
| 109 |
+
file_path = os.path.join("lib", "services.ex")
|
| 110 |
+
# Line 1-3 are likely in module documentation or imports
|
| 111 |
+
containing_symbol = language_server.request_containing_symbol(file_path, 2, 10)
|
| 112 |
+
|
| 113 |
+
# Should return None or an empty dictionary, or the top-level module
|
| 114 |
+
# This is acceptable behavior for module-level positions
|
| 115 |
+
assert containing_symbol is None or containing_symbol == {} or "TestRepo.Services" in str(containing_symbol)
|
| 116 |
+
|
| 117 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 118 |
+
def test_request_referencing_symbols_struct(self, language_server: SolidLanguageServer) -> None:
|
| 119 |
+
"""Test request_referencing_symbols for a struct."""
|
| 120 |
+
# Test referencing symbols for User struct
|
| 121 |
+
file_path = os.path.join("lib", "models.ex")
|
| 122 |
+
|
| 123 |
+
symbols = language_server.request_document_symbols(file_path)
|
| 124 |
+
user_symbol = None
|
| 125 |
+
for symbol_group in symbols:
|
| 126 |
+
user_symbol = next((s for s in symbol_group if "User" in s.get("name", "")), None)
|
| 127 |
+
if user_symbol:
|
| 128 |
+
break
|
| 129 |
+
|
| 130 |
+
if not user_symbol or "selectionRange" not in user_symbol:
|
| 131 |
+
pytest.skip("User symbol or its selectionRange not found")
|
| 132 |
+
|
| 133 |
+
sel_start = user_symbol["selectionRange"]["start"]
|
| 134 |
+
ref_symbols = [
|
| 135 |
+
ref.symbol for ref in language_server.request_referencing_symbols(file_path, sel_start["line"], sel_start["character"])
|
| 136 |
+
]
|
| 137 |
+
|
| 138 |
+
if ref_symbols:
|
| 139 |
+
services_references = [
|
| 140 |
+
symbol
|
| 141 |
+
for symbol in ref_symbols
|
| 142 |
+
if "location" in symbol and "uri" in symbol["location"] and "services.ex" in symbol["location"]["uri"]
|
| 143 |
+
]
|
| 144 |
+
# We expect some references from services.ex
|
| 145 |
+
assert len(services_references) >= 0 # At least attempt to find references
|
| 146 |
+
|
| 147 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 148 |
+
def test_request_referencing_symbols_none(self, language_server: SolidLanguageServer) -> None:
|
| 149 |
+
"""Test request_referencing_symbols for a position with no symbol."""
|
| 150 |
+
file_path = os.path.join("lib", "services.ex")
|
| 151 |
+
# Line 3 is likely a blank line or comment
|
| 152 |
+
try:
|
| 153 |
+
ref_symbols = [ref.symbol for ref in language_server.request_referencing_symbols(file_path, 3, 0)]
|
| 154 |
+
# If we get here, make sure we got an empty result
|
| 155 |
+
assert ref_symbols == [] or ref_symbols is None
|
| 156 |
+
except Exception:
|
| 157 |
+
# The method might raise an exception for invalid positions
|
| 158 |
+
# which is acceptable behavior
|
| 159 |
+
pass
|
| 160 |
+
|
| 161 |
+
# Tests for request_defining_symbol
|
| 162 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 163 |
+
def test_request_defining_symbol_function_call(self, language_server: SolidLanguageServer) -> None:
|
| 164 |
+
"""Test request_defining_symbol for a function call."""
|
| 165 |
+
# Find a place where User.new is called in services.ex
|
| 166 |
+
file_path = os.path.join("lib", "services.ex")
|
| 167 |
+
content = language_server.retrieve_full_file_content(file_path)
|
| 168 |
+
lines = content.split("\n")
|
| 169 |
+
user_new_call_line = None
|
| 170 |
+
for i, line in enumerate(lines):
|
| 171 |
+
if "User.new(" in line:
|
| 172 |
+
user_new_call_line = i
|
| 173 |
+
break
|
| 174 |
+
|
| 175 |
+
if user_new_call_line is None:
|
| 176 |
+
pytest.skip("Could not find User.new call")
|
| 177 |
+
|
| 178 |
+
# Try to find the definition of User.new
|
| 179 |
+
defining_symbol = language_server.request_defining_symbol(file_path, user_new_call_line, 15)
|
| 180 |
+
|
| 181 |
+
if defining_symbol:
|
| 182 |
+
assert defining_symbol.get("name") == "new" or "User" in defining_symbol.get("name", "")
|
| 183 |
+
if "location" in defining_symbol and "uri" in defining_symbol["location"]:
|
| 184 |
+
assert "models.ex" in defining_symbol["location"]["uri"]
|
| 185 |
+
|
| 186 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 187 |
+
def test_request_defining_symbol_struct_usage(self, language_server: SolidLanguageServer) -> None:
|
| 188 |
+
"""Test request_defining_symbol for a struct usage."""
|
| 189 |
+
# Find a place where User struct is used in services.ex
|
| 190 |
+
file_path = os.path.join("lib", "services.ex")
|
| 191 |
+
content = language_server.retrieve_full_file_content(file_path)
|
| 192 |
+
lines = content.split("\n")
|
| 193 |
+
user_usage_line = None
|
| 194 |
+
for i, line in enumerate(lines):
|
| 195 |
+
if "alias TestRepo.Models.{User" in line:
|
| 196 |
+
user_usage_line = i
|
| 197 |
+
break
|
| 198 |
+
|
| 199 |
+
if user_usage_line is None:
|
| 200 |
+
pytest.skip("Could not find User struct usage")
|
| 201 |
+
|
| 202 |
+
defining_symbol = language_server.request_defining_symbol(file_path, user_usage_line, 30)
|
| 203 |
+
|
| 204 |
+
if defining_symbol:
|
| 205 |
+
assert "User" in defining_symbol.get("name", "")
|
| 206 |
+
|
| 207 |
+
@pytest.mark.xfail(
|
| 208 |
+
reason="Known intermittent bug in Next LS v0.23.3: Protocol.UndefinedError for :timeout atom. "
|
| 209 |
+
"Occurs in CI environments but may pass locally. "
|
| 210 |
+
"See https://github.com/elixir-tools/next-ls/issues/543",
|
| 211 |
+
strict=False,
|
| 212 |
+
)
|
| 213 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 214 |
+
def test_request_defining_symbol_none(self, language_server: SolidLanguageServer) -> None:
|
| 215 |
+
"""Test request_defining_symbol for a position with no symbol."""
|
| 216 |
+
# Test for a position with no symbol (e.g., whitespace or comment)
|
| 217 |
+
file_path = os.path.join("lib", "services.ex")
|
| 218 |
+
# Line 3 is likely a blank line
|
| 219 |
+
defining_symbol = language_server.request_defining_symbol(file_path, 3, 0)
|
| 220 |
+
|
| 221 |
+
# Should return None or empty
|
| 222 |
+
assert defining_symbol is None or defining_symbol == {}
|
| 223 |
+
|
| 224 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 225 |
+
def test_symbol_methods_integration(self, language_server: SolidLanguageServer) -> None:
|
| 226 |
+
"""Test integration between different symbol methods."""
|
| 227 |
+
file_path = os.path.join("lib", "models.ex")
|
| 228 |
+
|
| 229 |
+
# Find User struct definition
|
| 230 |
+
content = language_server.retrieve_full_file_content(file_path)
|
| 231 |
+
lines = content.split("\n")
|
| 232 |
+
user_struct_line = None
|
| 233 |
+
for i, line in enumerate(lines):
|
| 234 |
+
if "defmodule User do" in line:
|
| 235 |
+
user_struct_line = i
|
| 236 |
+
break
|
| 237 |
+
|
| 238 |
+
if user_struct_line is None:
|
| 239 |
+
pytest.skip("Could not find User struct")
|
| 240 |
+
|
| 241 |
+
# Test containing symbol
|
| 242 |
+
containing = language_server.request_containing_symbol(file_path, user_struct_line + 5, 10)
|
| 243 |
+
|
| 244 |
+
if containing:
|
| 245 |
+
# Test that we can find references to this symbol
|
| 246 |
+
if "location" in containing and "range" in containing["location"]:
|
| 247 |
+
start_pos = containing["location"]["range"]["start"]
|
| 248 |
+
refs = [
|
| 249 |
+
ref.symbol for ref in language_server.request_referencing_symbols(file_path, start_pos["line"], start_pos["character"])
|
| 250 |
+
]
|
| 251 |
+
# We should find some references or none (both are valid outcomes)
|
| 252 |
+
assert isinstance(refs, list)
|
| 253 |
+
|
| 254 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 255 |
+
def test_symbol_tree_structure(self, language_server: SolidLanguageServer) -> None:
|
| 256 |
+
"""Test that symbol tree structure is correctly built."""
|
| 257 |
+
symbol_tree = language_server.request_full_symbol_tree()
|
| 258 |
+
|
| 259 |
+
# Should get a tree structure
|
| 260 |
+
assert len(symbol_tree) > 0
|
| 261 |
+
|
| 262 |
+
# Should have our test repository structure
|
| 263 |
+
root = symbol_tree[0]
|
| 264 |
+
assert "children" in root
|
| 265 |
+
|
| 266 |
+
# Look for lib directory
|
| 267 |
+
lib_dir = None
|
| 268 |
+
for child in root["children"]:
|
| 269 |
+
if child["name"] == "lib":
|
| 270 |
+
lib_dir = child
|
| 271 |
+
break
|
| 272 |
+
|
| 273 |
+
if lib_dir:
|
| 274 |
+
# Next LS returns module names instead of file names (e.g., 'services' instead of 'services.ex')
|
| 275 |
+
file_names = [child["name"] for child in lib_dir.get("children", [])]
|
| 276 |
+
expected_modules = ["models", "services", "examples", "utils", "test_repo"]
|
| 277 |
+
found_modules = [name for name in expected_modules if name in file_names]
|
| 278 |
+
assert len(found_modules) > 0, f"Expected to find some modules from {expected_modules}, but got {file_names}"
|
| 279 |
+
|
| 280 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 281 |
+
def test_request_dir_overview(self, language_server: SolidLanguageServer) -> None:
|
| 282 |
+
"""Test request_dir_overview functionality."""
|
| 283 |
+
lib_overview = language_server.request_dir_overview("lib")
|
| 284 |
+
|
| 285 |
+
# Should get an overview of the lib directory
|
| 286 |
+
assert lib_overview is not None
|
| 287 |
+
# Next LS returns keys like 'lib/services.ex' instead of just 'lib'
|
| 288 |
+
overview_keys = list(lib_overview.keys()) if hasattr(lib_overview, "keys") else []
|
| 289 |
+
lib_files = [key for key in overview_keys if key.startswith("lib/")]
|
| 290 |
+
assert len(lib_files) > 0, f"Expected to find lib/ files in overview keys: {overview_keys}"
|
| 291 |
+
|
| 292 |
+
# Should contain information about our modules
|
| 293 |
+
overview_text = str(lib_overview).lower()
|
| 294 |
+
expected_terms = ["models", "services", "user", "item"]
|
| 295 |
+
found_terms = [term for term in expected_terms if term in overview_text]
|
| 296 |
+
assert len(found_terms) > 0, f"Expected to find some terms from {expected_terms} in overview"
|
| 297 |
+
|
| 298 |
+
# @pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 299 |
+
# def test_request_document_overview(self, language_server: SolidLanguageServer) -> None:
|
| 300 |
+
# """Test request_document_overview functionality."""
|
| 301 |
+
# # COMMENTED OUT: Next LS document overview doesn't contain expected terms
|
| 302 |
+
# # Next LS return value: [('TestRepo.Models', 2, 0, 0)] - only module info, no detailed content
|
| 303 |
+
# # Expected terms like 'user', 'item', 'order', 'struct', 'defmodule' are not present
|
| 304 |
+
# # This appears to be a limitation of Next LS document overview functionality
|
| 305 |
+
# #
|
| 306 |
+
# file_path = os.path.join("lib", "models.ex")
|
| 307 |
+
# doc_overview = language_server.request_document_overview(file_path)
|
| 308 |
+
#
|
| 309 |
+
# # Should get an overview of the models.ex file
|
| 310 |
+
# assert doc_overview is not None
|
| 311 |
+
#
|
| 312 |
+
# # Should contain information about our structs and functions
|
| 313 |
+
# overview_text = str(doc_overview).lower()
|
| 314 |
+
# expected_terms = ["user", "item", "order", "struct", "defmodule"]
|
| 315 |
+
# found_terms = [term for term in expected_terms if term in overview_text]
|
| 316 |
+
# assert len(found_terms) > 0, f"Expected to find some terms from {expected_terms} in overview"
|
| 317 |
+
|
| 318 |
+
@pytest.mark.parametrize("language_server", [Language.ELIXIR], indirect=True)
|
| 319 |
+
def test_containing_symbol_of_module_attribute(self, language_server: SolidLanguageServer) -> None:
|
| 320 |
+
"""Test containing symbol for module attributes."""
|
| 321 |
+
file_path = os.path.join("lib", "models.ex")
|
| 322 |
+
|
| 323 |
+
# Find a module attribute like @type or @doc
|
| 324 |
+
content = language_server.retrieve_full_file_content(file_path)
|
| 325 |
+
lines = content.split("\n")
|
| 326 |
+
attribute_line = None
|
| 327 |
+
for i, line in enumerate(lines):
|
| 328 |
+
if line.strip().startswith("@type") or line.strip().startswith("@doc"):
|
| 329 |
+
attribute_line = i
|
| 330 |
+
break
|
| 331 |
+
|
| 332 |
+
if attribute_line is None:
|
| 333 |
+
pytest.skip("Could not find module attribute")
|
| 334 |
+
|
| 335 |
+
containing_symbol = language_server.request_containing_symbol(file_path, attribute_line, 5)
|
| 336 |
+
|
| 337 |
+
if containing_symbol:
|
| 338 |
+
# Should be contained within a module
|
| 339 |
+
assert "name" in containing_symbol
|
| 340 |
+
# The containing symbol should be a module
|
| 341 |
+
expected_names = ["User", "Item", "Order", "TestRepo.Models"]
|
| 342 |
+
assert any(name in containing_symbol["name"] for name in expected_names)
|
projects/ui/serena-new/test/solidlsp/erlang/__init__.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import platform
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def _test_erlang_ls_available() -> str:
|
| 5 |
+
"""Test if Erlang LS is available and return error reason if not."""
|
| 6 |
+
# Check if we're on Windows (Erlang LS doesn't support Windows)
|
| 7 |
+
if platform.system() == "Windows":
|
| 8 |
+
return "Erlang LS does not support Windows"
|
| 9 |
+
|
| 10 |
+
# Try to import and check Erlang availability
|
| 11 |
+
try:
|
| 12 |
+
from solidlsp.language_servers.erlang_language_server import ErlangLanguageServer
|
| 13 |
+
|
| 14 |
+
# Check if Erlang/OTP is installed
|
| 15 |
+
erlang_version = ErlangLanguageServer._get_erlang_version()
|
| 16 |
+
if not erlang_version:
|
| 17 |
+
return "Erlang/OTP is not installed or not in PATH"
|
| 18 |
+
|
| 19 |
+
# Check if rebar3 is available (commonly used build tool)
|
| 20 |
+
rebar3_available = ErlangLanguageServer._check_rebar3_available()
|
| 21 |
+
if not rebar3_available:
|
| 22 |
+
return "rebar3 is not installed or not in PATH (required for project compilation)"
|
| 23 |
+
|
| 24 |
+
return "" # No error, Erlang LS should be available
|
| 25 |
+
|
| 26 |
+
except ImportError as e:
|
| 27 |
+
return f"Failed to import ErlangLanguageServer: {e}"
|
| 28 |
+
except Exception as e:
|
| 29 |
+
return f"Error checking Erlang LS availability: {e}"
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
ERLANG_LS_UNAVAILABLE_REASON = _test_erlang_ls_available()
|
| 33 |
+
ERLANG_LS_UNAVAILABLE = bool(ERLANG_LS_UNAVAILABLE_REASON)
|
projects/ui/serena-new/test/solidlsp/erlang/conftest.py
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Erlang-specific test configuration and fixtures.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import subprocess
|
| 7 |
+
import time
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
import pytest
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def ensure_erlang_test_repo_compiled(repo_path: str) -> None:
|
| 14 |
+
"""Ensure the Erlang test repository dependencies are installed and project is compiled.
|
| 15 |
+
|
| 16 |
+
Erlang LS requires the project to be fully compiled and indexed before providing
|
| 17 |
+
complete references and symbol resolution. This function:
|
| 18 |
+
1. Installs dependencies via 'rebar3 deps'
|
| 19 |
+
2. Compiles the project via 'rebar3 compile'
|
| 20 |
+
|
| 21 |
+
This is essential in CI environments where dependencies aren't pre-installed.
|
| 22 |
+
|
| 23 |
+
Args:
|
| 24 |
+
repo_path: Path to the Erlang project root directory
|
| 25 |
+
|
| 26 |
+
"""
|
| 27 |
+
# Check if this looks like an Erlang project
|
| 28 |
+
rebar_config = os.path.join(repo_path, "rebar.config")
|
| 29 |
+
if not os.path.exists(rebar_config):
|
| 30 |
+
return
|
| 31 |
+
|
| 32 |
+
# Check if already compiled (optimization for repeated runs)
|
| 33 |
+
build_path = os.path.join(repo_path, "_build")
|
| 34 |
+
deps_path = os.path.join(repo_path, "deps")
|
| 35 |
+
|
| 36 |
+
if os.path.exists(build_path) and os.path.exists(deps_path):
|
| 37 |
+
print(f"Erlang test repository already compiled in {repo_path}")
|
| 38 |
+
return
|
| 39 |
+
|
| 40 |
+
try:
|
| 41 |
+
print("Installing dependencies and compiling Erlang test repository for optimal Erlang LS performance...")
|
| 42 |
+
|
| 43 |
+
# First, install dependencies with increased timeout for CI
|
| 44 |
+
print("=" * 60)
|
| 45 |
+
print("Step 1/2: Installing Erlang dependencies...")
|
| 46 |
+
print("=" * 60)
|
| 47 |
+
start_time = time.time()
|
| 48 |
+
|
| 49 |
+
deps_result = subprocess.run(
|
| 50 |
+
["rebar3", "deps"],
|
| 51 |
+
cwd=repo_path,
|
| 52 |
+
capture_output=True,
|
| 53 |
+
text=True,
|
| 54 |
+
timeout=180,
|
| 55 |
+
check=False, # 3 minutes for dependency installation (CI can be slow)
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
deps_duration = time.time() - start_time
|
| 59 |
+
print(f"Dependencies installation completed in {deps_duration:.2f} seconds")
|
| 60 |
+
|
| 61 |
+
# Always log the output for transparency
|
| 62 |
+
if deps_result.stdout.strip():
|
| 63 |
+
print("Dependencies stdout:")
|
| 64 |
+
print("-" * 40)
|
| 65 |
+
print(deps_result.stdout)
|
| 66 |
+
print("-" * 40)
|
| 67 |
+
|
| 68 |
+
if deps_result.stderr.strip():
|
| 69 |
+
print("Dependencies stderr:")
|
| 70 |
+
print("-" * 40)
|
| 71 |
+
print(deps_result.stderr)
|
| 72 |
+
print("-" * 40)
|
| 73 |
+
|
| 74 |
+
if deps_result.returncode != 0:
|
| 75 |
+
print(f"⚠️ Warning: Dependencies installation failed with exit code {deps_result.returncode}")
|
| 76 |
+
# Continue anyway - some projects might not have dependencies
|
| 77 |
+
else:
|
| 78 |
+
print("✓ Dependencies installed successfully")
|
| 79 |
+
|
| 80 |
+
# Then compile the project with increased timeout for CI
|
| 81 |
+
print("=" * 60)
|
| 82 |
+
print("Step 2/2: Compiling Erlang project...")
|
| 83 |
+
print("=" * 60)
|
| 84 |
+
start_time = time.time()
|
| 85 |
+
|
| 86 |
+
compile_result = subprocess.run(
|
| 87 |
+
["rebar3", "compile"],
|
| 88 |
+
cwd=repo_path,
|
| 89 |
+
capture_output=True,
|
| 90 |
+
text=True,
|
| 91 |
+
timeout=300,
|
| 92 |
+
check=False, # 5 minutes for compilation (Dialyzer can be slow in CI)
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
compile_duration = time.time() - start_time
|
| 96 |
+
print(f"Compilation completed in {compile_duration:.2f} seconds")
|
| 97 |
+
|
| 98 |
+
# Always log the output for transparency
|
| 99 |
+
if compile_result.stdout.strip():
|
| 100 |
+
print("Compilation stdout:")
|
| 101 |
+
print("-" * 40)
|
| 102 |
+
print(compile_result.stdout)
|
| 103 |
+
print("-" * 40)
|
| 104 |
+
|
| 105 |
+
if compile_result.stderr.strip():
|
| 106 |
+
print("Compilation stderr:")
|
| 107 |
+
print("-" * 40)
|
| 108 |
+
print(compile_result.stderr)
|
| 109 |
+
print("-" * 40)
|
| 110 |
+
|
| 111 |
+
if compile_result.returncode == 0:
|
| 112 |
+
print(f"✓ Erlang test repository compiled successfully in {repo_path}")
|
| 113 |
+
else:
|
| 114 |
+
print(f"⚠️ Warning: Compilation completed with exit code {compile_result.returncode}")
|
| 115 |
+
# Still continue - warnings are often non-fatal
|
| 116 |
+
|
| 117 |
+
print("=" * 60)
|
| 118 |
+
print(f"Total setup time: {time.time() - (start_time - compile_duration - deps_duration):.2f} seconds")
|
| 119 |
+
print("=" * 60)
|
| 120 |
+
|
| 121 |
+
except subprocess.TimeoutExpired as e:
|
| 122 |
+
print("=" * 60)
|
| 123 |
+
print(f"❌ TIMEOUT: Erlang setup timed out after {e.timeout} seconds")
|
| 124 |
+
print(f"Command: {' '.join(e.cmd)}")
|
| 125 |
+
print("This may indicate slow CI environment - Erlang LS may still work but with reduced functionality")
|
| 126 |
+
|
| 127 |
+
# Try to get partial output if available
|
| 128 |
+
if hasattr(e, "stdout") and e.stdout:
|
| 129 |
+
print("Partial stdout before timeout:")
|
| 130 |
+
print("-" * 40)
|
| 131 |
+
print(e.stdout)
|
| 132 |
+
print("-" * 40)
|
| 133 |
+
if hasattr(e, "stderr") and e.stderr:
|
| 134 |
+
print("Partial stderr before timeout:")
|
| 135 |
+
print("-" * 40)
|
| 136 |
+
print(e.stderr)
|
| 137 |
+
print("-" * 40)
|
| 138 |
+
print("=" * 60)
|
| 139 |
+
|
| 140 |
+
except FileNotFoundError:
|
| 141 |
+
print("❌ ERROR: 'rebar3' command not found - Erlang test repository may not be compiled")
|
| 142 |
+
print("Please ensure rebar3 is installed and available in PATH")
|
| 143 |
+
except Exception as e:
|
| 144 |
+
print(f"❌ ERROR: Failed to prepare Erlang test repository: {e}")
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
@pytest.fixture(scope="session", autouse=True)
|
| 148 |
+
def setup_erlang_test_environment():
|
| 149 |
+
"""Automatically prepare Erlang test environment for all Erlang tests.
|
| 150 |
+
|
| 151 |
+
This fixture runs once per test session and automatically:
|
| 152 |
+
1. Installs dependencies via 'rebar3 deps'
|
| 153 |
+
2. Compiles the Erlang test repository via 'rebar3 compile'
|
| 154 |
+
|
| 155 |
+
It uses autouse=True so it runs automatically without needing to be explicitly
|
| 156 |
+
requested by tests. This ensures Erlang LS has a fully prepared project to work with.
|
| 157 |
+
|
| 158 |
+
Uses generous timeouts (3-5 minutes) to accommodate slow CI environments.
|
| 159 |
+
All output is logged for transparency and debugging.
|
| 160 |
+
"""
|
| 161 |
+
# Get the test repo path relative to this conftest.py file
|
| 162 |
+
test_repo_path = Path(__file__).parent.parent.parent / "resources" / "repos" / "erlang" / "test_repo"
|
| 163 |
+
ensure_erlang_test_repo_compiled(str(test_repo_path))
|
| 164 |
+
return str(test_repo_path)
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
@pytest.fixture(scope="session")
|
| 168 |
+
def erlang_test_repo_path(setup_erlang_test_environment):
|
| 169 |
+
"""Get the path to the prepared Erlang test repository.
|
| 170 |
+
|
| 171 |
+
This fixture depends on setup_erlang_test_environment to ensure dependencies
|
| 172 |
+
are installed and compilation has completed before returning the path.
|
| 173 |
+
"""
|
| 174 |
+
return setup_erlang_test_environment
|
projects/ui/serena-new/test/solidlsp/erlang/test_erlang_basic.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Basic integration tests for the Erlang 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 |
+
from . import ERLANG_LS_UNAVAILABLE, ERLANG_LS_UNAVAILABLE_REASON
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@pytest.mark.erlang
|
| 17 |
+
@pytest.mark.skipif(ERLANG_LS_UNAVAILABLE, reason=f"Erlang LS not available: {ERLANG_LS_UNAVAILABLE_REASON}")
|
| 18 |
+
class TestErlangLanguageServerBasics:
|
| 19 |
+
"""Test basic functionality of the Erlang language server."""
|
| 20 |
+
|
| 21 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 22 |
+
def test_language_server_initialization(self, language_server: SolidLanguageServer) -> None:
|
| 23 |
+
"""Test that the Erlang language server initializes properly."""
|
| 24 |
+
assert language_server is not None
|
| 25 |
+
assert language_server.language == Language.ERLANG
|
| 26 |
+
|
| 27 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 28 |
+
def test_document_symbols(self, language_server: SolidLanguageServer) -> None:
|
| 29 |
+
"""Test document symbols retrieval for Erlang files."""
|
| 30 |
+
try:
|
| 31 |
+
file_path = "hello.erl"
|
| 32 |
+
symbols_tuple = language_server.request_document_symbols(file_path)
|
| 33 |
+
assert isinstance(symbols_tuple, tuple)
|
| 34 |
+
assert len(symbols_tuple) == 2
|
| 35 |
+
|
| 36 |
+
all_symbols, root_symbols = symbols_tuple
|
| 37 |
+
assert isinstance(all_symbols, list)
|
| 38 |
+
assert isinstance(root_symbols, list)
|
| 39 |
+
except Exception as e:
|
| 40 |
+
if "not fully initialized" in str(e):
|
| 41 |
+
pytest.skip("Erlang language server not fully initialized")
|
| 42 |
+
else:
|
| 43 |
+
raise
|
projects/ui/serena-new/test/solidlsp/erlang/test_erlang_ignored_dirs.py
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
from . import ERLANG_LS_UNAVAILABLE, ERLANG_LS_UNAVAILABLE_REASON
|
| 11 |
+
|
| 12 |
+
# These marks will be applied to all tests in this module
|
| 13 |
+
pytestmark = [
|
| 14 |
+
pytest.mark.erlang,
|
| 15 |
+
pytest.mark.skipif(ERLANG_LS_UNAVAILABLE, reason=f"Erlang LS not available: {ERLANG_LS_UNAVAILABLE_REASON}"),
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
@pytest.fixture(scope="module")
|
| 20 |
+
def ls_with_ignored_dirs() -> Generator[SolidLanguageServer, None, None]:
|
| 21 |
+
"""Fixture to set up an LS for the erlang test repo with the 'ignored_dir' directory ignored."""
|
| 22 |
+
ignored_paths = ["_build", "ignored_dir"]
|
| 23 |
+
ls = create_ls(ignored_paths=ignored_paths, language=Language.ERLANG)
|
| 24 |
+
ls.start()
|
| 25 |
+
try:
|
| 26 |
+
yield ls
|
| 27 |
+
finally:
|
| 28 |
+
try:
|
| 29 |
+
ls.stop(shutdown_timeout=1.0) # Shorter timeout for CI
|
| 30 |
+
except Exception as e:
|
| 31 |
+
print(f"Warning: Error stopping language server: {e}")
|
| 32 |
+
# Force cleanup if needed
|
| 33 |
+
if hasattr(ls, "server") and hasattr(ls.server, "process"):
|
| 34 |
+
try:
|
| 35 |
+
ls.server.process.terminate()
|
| 36 |
+
except:
|
| 37 |
+
pass
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
@pytest.mark.timeout(60) # Add 60 second timeout
|
| 41 |
+
@pytest.mark.xfail(reason="Known timeout issue on Ubuntu CI with Erlang LS server startup", strict=False)
|
| 42 |
+
@pytest.mark.parametrize("ls_with_ignored_dirs", [Language.ERLANG], indirect=True)
|
| 43 |
+
def test_symbol_tree_ignores_dir(ls_with_ignored_dirs: SolidLanguageServer):
|
| 44 |
+
"""Tests that request_full_symbol_tree ignores the configured directory."""
|
| 45 |
+
root = ls_with_ignored_dirs.request_full_symbol_tree()[0]
|
| 46 |
+
root_children = root["children"]
|
| 47 |
+
children_names = {child["name"] for child in root_children}
|
| 48 |
+
|
| 49 |
+
# Should have src, include, and test directories, but not _build or ignored_dir
|
| 50 |
+
expected_dirs = {"src", "include", "test"}
|
| 51 |
+
found_expected = expected_dirs.intersection(children_names)
|
| 52 |
+
assert len(found_expected) > 0, f"Expected some dirs from {expected_dirs} to be in {children_names}"
|
| 53 |
+
assert "_build" not in children_names, f"_build should not be in {children_names}"
|
| 54 |
+
assert "ignored_dir" not in children_names, f"ignored_dir should not be in {children_names}"
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
@pytest.mark.timeout(60) # Add 60 second timeout
|
| 58 |
+
@pytest.mark.xfail(reason="Known timeout issue on Ubuntu CI with Erlang LS server startup", strict=False)
|
| 59 |
+
@pytest.mark.parametrize("ls_with_ignored_dirs", [Language.ERLANG], indirect=True)
|
| 60 |
+
def test_find_references_ignores_dir(ls_with_ignored_dirs: SolidLanguageServer):
|
| 61 |
+
"""Tests that find_references ignores the configured directory."""
|
| 62 |
+
# Location of user record, which might be referenced in ignored_dir
|
| 63 |
+
definition_file = "include/records.hrl"
|
| 64 |
+
|
| 65 |
+
# Find the user record definition
|
| 66 |
+
symbols = ls_with_ignored_dirs.request_document_symbols(definition_file)
|
| 67 |
+
user_symbol = None
|
| 68 |
+
for symbol_group in symbols:
|
| 69 |
+
user_symbol = next((s for s in symbol_group if "user" in s.get("name", "").lower()), None)
|
| 70 |
+
if user_symbol:
|
| 71 |
+
break
|
| 72 |
+
|
| 73 |
+
if not user_symbol or "selectionRange" not in user_symbol:
|
| 74 |
+
pytest.skip("User record symbol not found for reference testing")
|
| 75 |
+
|
| 76 |
+
sel_start = user_symbol["selectionRange"]["start"]
|
| 77 |
+
references = ls_with_ignored_dirs.request_references(definition_file, sel_start["line"], sel_start["character"])
|
| 78 |
+
|
| 79 |
+
# Assert that _build and ignored_dir do not appear in the references
|
| 80 |
+
assert not any("_build" in ref["relativePath"] for ref in references), "_build should be ignored"
|
| 81 |
+
assert not any("ignored_dir" in ref["relativePath"] for ref in references), "ignored_dir should be ignored"
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
@pytest.mark.timeout(90) # Longer timeout for this complex test
|
| 85 |
+
@pytest.mark.xfail(reason="Known timeout issue on Ubuntu CI with Erlang LS server startup", strict=False)
|
| 86 |
+
@pytest.mark.parametrize("repo_path", [Language.ERLANG], indirect=True)
|
| 87 |
+
def test_refs_and_symbols_with_glob_patterns(repo_path: Path) -> None:
|
| 88 |
+
"""Tests that refs and symbols with glob patterns are ignored."""
|
| 89 |
+
ignored_paths = ["_build*", "ignored_*", "*.tmp"]
|
| 90 |
+
ls = create_ls(ignored_paths=ignored_paths, repo_path=str(repo_path), language=Language.ERLANG)
|
| 91 |
+
ls.start()
|
| 92 |
+
|
| 93 |
+
try:
|
| 94 |
+
# Same as in the above tests
|
| 95 |
+
root = ls.request_full_symbol_tree()[0]
|
| 96 |
+
root_children = root["children"]
|
| 97 |
+
children_names = {child["name"] for child in root_children}
|
| 98 |
+
|
| 99 |
+
# Should have src, include, and test directories, but not _build or ignored_dir
|
| 100 |
+
expected_dirs = {"src", "include", "test"}
|
| 101 |
+
found_expected = expected_dirs.intersection(children_names)
|
| 102 |
+
assert len(found_expected) > 0, f"Expected some dirs from {expected_dirs} to be in {children_names}"
|
| 103 |
+
assert "_build" not in children_names, f"_build should not be in {children_names} (glob pattern)"
|
| 104 |
+
assert "ignored_dir" not in children_names, f"ignored_dir should not be in {children_names} (glob pattern)"
|
| 105 |
+
|
| 106 |
+
# Test that the refs and symbols with glob patterns are ignored
|
| 107 |
+
definition_file = "include/records.hrl"
|
| 108 |
+
|
| 109 |
+
# Find the user record definition
|
| 110 |
+
symbols = ls.request_document_symbols(definition_file)
|
| 111 |
+
user_symbol = None
|
| 112 |
+
for symbol_group in symbols:
|
| 113 |
+
user_symbol = next((s for s in symbol_group if "user" in s.get("name", "").lower()), None)
|
| 114 |
+
if user_symbol:
|
| 115 |
+
break
|
| 116 |
+
|
| 117 |
+
if user_symbol and "selectionRange" in user_symbol:
|
| 118 |
+
sel_start = user_symbol["selectionRange"]["start"]
|
| 119 |
+
references = ls.request_references(definition_file, sel_start["line"], sel_start["character"])
|
| 120 |
+
|
| 121 |
+
# Assert that _build and ignored_dir do not appear in references
|
| 122 |
+
assert not any("_build" in ref["relativePath"] for ref in references), "_build should be ignored (glob)"
|
| 123 |
+
assert not any("ignored_dir" in ref["relativePath"] for ref in references), "ignored_dir should be ignored (glob)"
|
| 124 |
+
finally:
|
| 125 |
+
try:
|
| 126 |
+
ls.stop(shutdown_timeout=1.0) # Shorter timeout for CI
|
| 127 |
+
except Exception as e:
|
| 128 |
+
print(f"Warning: Error stopping glob pattern test LS: {e}")
|
| 129 |
+
# Force cleanup if needed
|
| 130 |
+
if hasattr(ls, "server") and hasattr(ls.server, "process"):
|
| 131 |
+
try:
|
| 132 |
+
ls.server.process.terminate()
|
| 133 |
+
except:
|
| 134 |
+
pass
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 138 |
+
def test_default_ignored_directories(language_server: SolidLanguageServer):
|
| 139 |
+
"""Test that default Erlang directories are ignored."""
|
| 140 |
+
# Test that Erlang-specific directories are ignored by default
|
| 141 |
+
assert language_server.is_ignored_dirname("_build"), "_build should be ignored"
|
| 142 |
+
assert language_server.is_ignored_dirname("ebin"), "ebin should be ignored"
|
| 143 |
+
assert language_server.is_ignored_dirname("deps"), "deps should be ignored"
|
| 144 |
+
assert language_server.is_ignored_dirname(".rebar3"), ".rebar3 should be ignored"
|
| 145 |
+
assert language_server.is_ignored_dirname("_checkouts"), "_checkouts should be ignored"
|
| 146 |
+
assert language_server.is_ignored_dirname("node_modules"), "node_modules should be ignored"
|
| 147 |
+
|
| 148 |
+
# Test that important directories are not ignored
|
| 149 |
+
assert not language_server.is_ignored_dirname("src"), "src should not be ignored"
|
| 150 |
+
assert not language_server.is_ignored_dirname("include"), "include should not be ignored"
|
| 151 |
+
assert not language_server.is_ignored_dirname("test"), "test should not be ignored"
|
| 152 |
+
assert not language_server.is_ignored_dirname("priv"), "priv should not be ignored"
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 156 |
+
def test_symbol_tree_excludes_build_dirs(language_server: SolidLanguageServer):
|
| 157 |
+
"""Test that symbol tree excludes build and dependency directories."""
|
| 158 |
+
symbol_tree = language_server.request_full_symbol_tree()
|
| 159 |
+
|
| 160 |
+
if symbol_tree:
|
| 161 |
+
root = symbol_tree[0]
|
| 162 |
+
children_names = {child["name"] for child in root.get("children", [])}
|
| 163 |
+
|
| 164 |
+
# Build and dependency directories should not appear
|
| 165 |
+
ignored_dirs = {"_build", "ebin", "deps", ".rebar3", "_checkouts", "node_modules"}
|
| 166 |
+
found_ignored = ignored_dirs.intersection(children_names)
|
| 167 |
+
assert len(found_ignored) == 0, f"Found ignored directories in symbol tree: {found_ignored}"
|
| 168 |
+
|
| 169 |
+
# Important directories should appear
|
| 170 |
+
important_dirs = {"src", "include", "test"}
|
| 171 |
+
found_important = important_dirs.intersection(children_names)
|
| 172 |
+
assert len(found_important) > 0, f"Expected to find important directories: {important_dirs}, got: {children_names}"
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 176 |
+
def test_ignore_compiled_files(language_server: SolidLanguageServer):
|
| 177 |
+
"""Test that compiled Erlang files are ignored."""
|
| 178 |
+
# Test that beam files are ignored
|
| 179 |
+
assert language_server.is_ignored_filename("module.beam"), "BEAM files should be ignored"
|
| 180 |
+
assert language_server.is_ignored_filename("app.beam"), "BEAM files should be ignored"
|
| 181 |
+
|
| 182 |
+
# Test that source files are not ignored
|
| 183 |
+
assert not language_server.is_ignored_filename("module.erl"), "Erlang source files should not be ignored"
|
| 184 |
+
assert not language_server.is_ignored_filename("records.hrl"), "Header files should not be ignored"
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 188 |
+
def test_rebar_directories_ignored(language_server: SolidLanguageServer):
|
| 189 |
+
"""Test that rebar-specific directories are ignored."""
|
| 190 |
+
# Test rebar3-specific directories
|
| 191 |
+
assert language_server.is_ignored_dirname("_build"), "rebar3 _build should be ignored"
|
| 192 |
+
assert language_server.is_ignored_dirname("_checkouts"), "rebar3 _checkouts should be ignored"
|
| 193 |
+
assert language_server.is_ignored_dirname(".rebar3"), "rebar3 cache should be ignored"
|
| 194 |
+
|
| 195 |
+
# Test that rebar.lock and rebar.config are not ignored (they are configuration files)
|
| 196 |
+
assert not language_server.is_ignored_filename("rebar.config"), "rebar.config should not be ignored"
|
| 197 |
+
assert not language_server.is_ignored_filename("rebar.lock"), "rebar.lock should not be ignored"
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
@pytest.mark.parametrize("ls_with_ignored_dirs", [Language.ERLANG], indirect=True)
|
| 201 |
+
def test_document_symbols_ignores_dirs(ls_with_ignored_dirs: SolidLanguageServer):
|
| 202 |
+
"""Test that document symbols from ignored directories are not included."""
|
| 203 |
+
# Try to get symbols from a file in ignored directory (should not find it)
|
| 204 |
+
try:
|
| 205 |
+
ignored_file = "ignored_dir/ignored_module.erl"
|
| 206 |
+
symbols = ls_with_ignored_dirs.request_document_symbols(ignored_file)
|
| 207 |
+
# If we get here, the file was found - symbols should be empty or None
|
| 208 |
+
if symbols:
|
| 209 |
+
assert len(symbols) == 0, "Should not find symbols in ignored directory"
|
| 210 |
+
except Exception:
|
| 211 |
+
# This is expected - the file should not be accessible
|
| 212 |
+
pass
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
@pytest.mark.parametrize("language_server", [Language.ERLANG], indirect=True)
|
| 216 |
+
def test_erlang_specific_ignore_patterns(language_server: SolidLanguageServer):
|
| 217 |
+
"""Test Erlang-specific ignore patterns work correctly."""
|
| 218 |
+
erlang_ignored_dirs = ["_build", "ebin", ".rebar3", "_checkouts", "cover"]
|
| 219 |
+
|
| 220 |
+
# These should be ignored
|
| 221 |
+
for dirname in erlang_ignored_dirs:
|
| 222 |
+
assert language_server.is_ignored_dirname(dirname), f"{dirname} should be ignored"
|
| 223 |
+
|
| 224 |
+
# These should not be ignored
|
| 225 |
+
erlang_important_dirs = ["src", "include", "test", "priv"]
|
| 226 |
+
for dirname in erlang_important_dirs:
|
| 227 |
+
assert not language_server.is_ignored_dirname(dirname), f"{dirname} should not be ignored"
|