1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
import logging
from typing import TYPE_CHECKING
import pytest
from debian.debian_support import DpkgArchTable
from debputy._deb_options_profiles import DebBuildOptionsAndProfiles
from debputy.architecture_support import DpkgArchitectureBuildProcessValuesTable
from debputy.lsp.debputy_ls import DebputyLanguageServer
from debputy.packages import DctrlParser
from debputy.plugin.api.feature_set import PluginProvidedFeatureSet
from debputy.util import setup_logging, change_log_level
if TYPE_CHECKING:
import lsprotocol.types as types
else:
import debputy.lsprotocol.types as types
try:
from pygls.server import LanguageServer
HAS_PYGLS = True
except ImportError:
HAS_PYGLS = False
@pytest.fixture(scope="session", autouse=True)
def enable_logging() -> None:
setup_logging(log_only_to_stderr=True, reconfigure_logging=True)
change_log_level(logging.INFO)
@pytest.fixture
def lsp_dctrl_parser(
dpkg_arch_query: DpkgArchTable,
amd64_dpkg_architecture_variables: DpkgArchitectureBuildProcessValuesTable,
no_profiles_or_build_options: DebBuildOptionsAndProfiles,
) -> DctrlParser:
return DctrlParser(
frozenset(),
frozenset(),
True,
True,
amd64_dpkg_architecture_variables,
dpkg_arch_query,
no_profiles_or_build_options,
)
@pytest.fixture()
def ls(
debputy_plugin_feature_set: PluginProvidedFeatureSet,
lsp_dctrl_parser: DctrlParser,
) -> "DebputyLanguageServer":
if not HAS_PYGLS:
pytest.skip("Missing pygls")
ls = DebputyLanguageServer("debputy", "v<test>")
ls.lsp.lsp_initialize(
types.InitializeParams(
types.ClientCapabilities(
general=types.GeneralClientCapabilities(
position_encodings=[types.PositionEncodingKind.Utf32],
)
)
)
)
ls.plugin_feature_set = debputy_plugin_feature_set
ls.dctrl_parser = lsp_dctrl_parser
return ls
|