sphinx-lua-ls 0.0.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,166 @@
1
+ import pathlib
2
+ import re
3
+
4
+ import sphinx.addnodes
5
+ import sphinx.application
6
+ import sphinx.config
7
+ import sphinx.environment
8
+ import sphinx.errors
9
+ import sphinx.ext.intersphinx
10
+ from sphinx.errors import ConfigError
11
+ from sphinx.util.display import progress_message
12
+
13
+ import sphinx_lua_ls.autodoc
14
+ import sphinx_lua_ls.domain
15
+ from sphinx_lua_ls import doctree, intersphinx, lua_ls
16
+ from sphinx_lua_ls._version import __version__, __version_tuple__
17
+
18
+
19
+ def check_options(
20
+ app: sphinx.application.Sphinx,
21
+ config: sphinx.config.Config,
22
+ ):
23
+ lua_version = config["lua_ls_lua_version"]
24
+ if not isinstance(lua_version, str):
25
+ raise ConfigError(
26
+ f"expected lua_ls_lua_version to be a str, got {type(lua_version)} instead"
27
+ )
28
+ if not re.match(r"\d+(\.\d+)*", lua_version):
29
+ raise ConfigError(f"incorrect lua_ls_lua_version: {lua_version}")
30
+
31
+ project_root = config["lua_ls_project_root"]
32
+ if project_root is None:
33
+ project_root = ""
34
+ if not isinstance(lua_version, (str, pathlib.Path)):
35
+ raise ConfigError(
36
+ f"expected lua_ls_project_root to be a str, got {type(project_root)} instead"
37
+ )
38
+ try:
39
+ project_root = config["lua_ls_project_root"] = (
40
+ pathlib.Path(app.srcdir, project_root).expanduser().resolve()
41
+ )
42
+ except ValueError as e:
43
+ raise ConfigError(f"incorrect lua_ls_project_root: {e}") from None
44
+
45
+ project_directories = config["lua_ls_project_directories"]
46
+ if project_directories is None:
47
+ project_directories = config["lua_ls_project_directories"] = []
48
+ if not isinstance(project_directories, list):
49
+ raise ConfigError(
50
+ f"expected lua_ls_project_directories to be a list, got {type(project_directories)} instead"
51
+ )
52
+ for i, project_directory in enumerate(project_directories):
53
+ if not isinstance(project_directory, (str, pathlib.Path)):
54
+ raise ConfigError(
55
+ f"expected lua_ls_project_directories[{i}] to be a list, got {type(project_directory)} instead"
56
+ )
57
+ try:
58
+ project_directories[i] = (
59
+ pathlib.Path(project_root, project_directory).expanduser().resolve()
60
+ )
61
+ except ValueError as e:
62
+ raise ConfigError(
63
+ f"incorrect lua_ls_project_directories[{i}]: {e}"
64
+ ) from None
65
+
66
+ auto_install = config["lua_ls_auto_install"]
67
+ if not isinstance(auto_install, bool):
68
+ raise ConfigError(
69
+ f"expected lua_ls_auto_install to be a bool, got {type(auto_install)} instead"
70
+ )
71
+
72
+ auto_install_location = config["lua_ls_auto_install_location"]
73
+ if auto_install_location is not None:
74
+ if not isinstance(auto_install_location, (str, pathlib.Path)):
75
+ raise ConfigError(
76
+ f"expected lua_ls_auto_install_location to be a str, got {type(auto_install_location)} instead"
77
+ )
78
+ try:
79
+ auto_install_location = config["auto_install_location"] = (
80
+ pathlib.Path(auto_install_location).expanduser().resolve()
81
+ )
82
+ except ValueError as e:
83
+ raise ConfigError(f"incorrect lua_ls_auto_install_location: {e}") from None
84
+
85
+ min_version = config["lua_ls_min_version"]
86
+ if not isinstance(min_version, str):
87
+ raise ConfigError(
88
+ f"expected lua_ls_min_version to be a str, got {type(min_version)} instead"
89
+ )
90
+ if not re.match(r"\d+(\.\d+)*", min_version):
91
+ raise ConfigError(f"incorrect lua_ls_min_version: {min_version}")
92
+
93
+ default_options = config["lua_ls_default_options"]
94
+ if default_options is None:
95
+ default_options = config["lua_ls_default_options"] = {}
96
+ if not isinstance(default_options, dict):
97
+ raise ConfigError(
98
+ f"expected lua_ls_default_options to be a dict, got {type(default_options)} instead"
99
+ )
100
+ for name, value in default_options.items():
101
+ parser = sphinx_lua_ls.autodoc.AutoObjectDirective.option_spec.get(name, None)
102
+ if parser is None:
103
+ raise ConfigError(f"unknown option in lua_ls_default_options: {name}")
104
+ if value is not None and not isinstance(value, str):
105
+ raise ConfigError(
106
+ f"expected lua_ls_default_options[{name!r} to be a string, got {type(value)} instead"
107
+ )
108
+ try:
109
+ default_options[name] = parser(value)
110
+ except Exception as e:
111
+ raise ConfigError(
112
+ f"incorrect option {name} in lua_ls_default_options: {e}"
113
+ ) from None
114
+
115
+
116
+ @progress_message("running lua language server")
117
+ def run_lua_ls(
118
+ app: sphinx.application.Sphinx,
119
+ env: sphinx.environment.BuildEnvironment,
120
+ docnames: list[str],
121
+ ):
122
+ root_dir = app.config["lua_ls_project_root"]
123
+ project_directories = app.config["lua_ls_project_directories"] or [root_dir]
124
+
125
+ try:
126
+ runner = lua_ls.resolve(
127
+ min_version=app.config["lua_ls_min_version"],
128
+ cwd=root_dir,
129
+ reporter=lua_ls.SphinxProgressReporter(app.verbosity),
130
+ install=app.config["lua_ls_auto_install"],
131
+ cache_path=app.config["lua_ls_auto_install_location"],
132
+ )
133
+ except lua_ls.LuaLsError as e:
134
+ raise sphinx.errors.ExtensionError(str(e))
135
+
136
+ parser = doctree.Parser()
137
+ for dir in project_directories:
138
+ parser.parse(runner.run(dir))
139
+
140
+ setattr(env, "lua_ls_doc_root", parser.root)
141
+
142
+
143
+ def setup(app: sphinx.application.Sphinx):
144
+ app.add_domain(sphinx_lua_ls.domain.LuaDomain)
145
+
146
+ app.add_config_value("lua_ls_project_root", None, rebuild="env")
147
+ app.add_config_value("lua_ls_project_directories", None, rebuild="env")
148
+ app.add_config_value("lua_ls_auto_install", True, rebuild="")
149
+ app.add_config_value("lua_ls_auto_install_location", None, rebuild="")
150
+ app.add_config_value("lua_ls_min_version", "3.0.0", rebuild="env")
151
+ app.add_config_value("lua_ls_lua_version", "5.4", rebuild="env")
152
+ app.add_config_value("lua_ls_default_options", None, rebuild="env")
153
+
154
+ app.add_directive_to_domain(
155
+ "lua", "autoobject", sphinx_lua_ls.autodoc.AutoObjectDirective
156
+ )
157
+
158
+ app.connect("config-inited", check_options)
159
+ app.connect("env-before-read-docs", run_lua_ls)
160
+ app.connect("missing-reference", intersphinx.resolve_std_reference)
161
+
162
+ return {
163
+ "version": __version__,
164
+ "parallel_read_safe": True,
165
+ "parallel_write_safe": True,
166
+ }
@@ -0,0 +1,21 @@
1
+ # file generated by setuptools-scm
2
+ # don't change, don't track in version control
3
+
4
+ __all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
5
+
6
+ TYPE_CHECKING = False
7
+ if TYPE_CHECKING:
8
+ from typing import Tuple
9
+ from typing import Union
10
+
11
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
12
+ else:
13
+ VERSION_TUPLE = object
14
+
15
+ version: str
16
+ __version__: str
17
+ __version_tuple__: VERSION_TUPLE
18
+ version_tuple: VERSION_TUPLE
19
+
20
+ __version__ = version = '0.0.4'
21
+ __version_tuple__ = version_tuple = (0, 0, 4)