Skip to content

Commit 4be7657

Browse files
committed
Some documentation and misspelling fixes
1 parent 040f0b9 commit 4be7657

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

src/cmake_language_server/api.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ def __init__(self, cmake: str, build: Path):
4545
self._generated_list_parsed = False
4646

4747
def query(self) -> bool:
48+
""" Use CMake's file API to get JSON information about the build tree
49+
50+
Generates a JSON request file for the current build tree and runs
51+
CMake on the build tree. Deletes the request file immediately
52+
after.
53+
"""
4854
if not self.cmake_cache.exists():
4955
return False
5056

@@ -77,6 +83,11 @@ def query(self) -> bool:
7783
return True
7884

7985
def read_reply(self) -> bool:
86+
""" Reads the CMake file API reply file and updates internal state
87+
88+
Reads the result of the previous query file and updates
89+
the targets, the cache entries and the cmake files.
90+
"""
8091
reply = self._build / ".cmake" / "api" / "v1" / "reply"
8192
indices = sorted(reply.glob("index-*.json"))
8293
if not indices:
@@ -124,15 +135,15 @@ def _read_cache(self, cachepath: Path):
124135
self._cached_variables[name] = "\n\n".join(doc)
125136

126137
def _read_cmake_files(self, jsonpath: Path):
127-
"""inspect generated list files"""
138+
"""inspect CMake list files that are used during build generation"""
128139

129140
if not self._builtin_variables or self._generated_list_parsed:
130141
return
131142

132143
with jsonpath.open() as fp:
133144
cmake_files = json.load(fp)
134145

135-
# inspect generated list files
146+
# Inspect generated list files: Get the values of variables in each script
136147
with tempfile.TemporaryDirectory() as tmpdirname:
137148
tmplist = Path(tmpdirname) / "dump.cmake"
138149
with tmplist.open("w") as fp:
@@ -203,6 +214,11 @@ def parse_doc(self) -> None:
203214
self._parse_modules()
204215

205216
def _parse_commands(self) -> None:
217+
""" Load docs for builtin cmake functions
218+
219+
Loads the documentation for builtin cmake functions from the result
220+
of `$ cmake --help-commands`.
221+
"""
206222
p = subprocess.run(
207223
[self._cmake, "--help-commands"],
208224
stdout=subprocess.PIPE,
@@ -231,6 +247,11 @@ def _parse_commands(self) -> None:
231247
self._builtin_commands[command] = "```cmake\n" + signature + "\n```"
232248

233249
def _parse_variables(self) -> None:
250+
""" Load docs for builtin cmake variables
251+
252+
Loads the documentation for builtin cmake variables from
253+
the result of `$ cmake --help-variables`.
254+
"""
234255
p = subprocess.run(
235256
[self._cmake, "--help-variables"],
236257
stdout=subprocess.PIPE,
@@ -265,6 +286,11 @@ def _parse_variables(self) -> None:
265286
self._builtin_variables[variable] = doc
266287

267288
def _parse_modules(self) -> None:
289+
""" Loads docs for all modules in the cmake distribution
290+
291+
Loads the documentation for cmake modules included in the
292+
distribution from the result of `$ cmake --help-modules`.
293+
"""
268294
p = subprocess.run(
269295
[self._cmake, "--help-modules"],
270296
stdout=subprocess.PIPE,

src/cmake_language_server/formatter.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
class Formatter(object):
7-
indnt: str
7+
indent: str
88
lower_identifier: bool
99

1010
def __init__(self, indent=" ", lower_identifier=True):
@@ -13,7 +13,7 @@ def __init__(self, indent=" ", lower_identifier=True):
1313

1414
def format(self, tokens: TokenList) -> str:
1515
cmds: List[str] = [""]
16-
indnet_level = 0
16+
indent_level = 0
1717
for token in tokens:
1818
if isinstance(token, tuple):
1919
raw_identifier = token[0]
@@ -27,18 +27,18 @@ def format(self, tokens: TokenList) -> str:
2727
"endmacro",
2828
"endfunction",
2929
):
30-
if indnet_level > 0:
31-
indnet_level -= 1
32-
cmds[-1] = self.indent * indnet_level
30+
if indent_level > 0:
31+
indent_level -= 1
32+
cmds[-1] = self.indent * indent_level
3333
cmds[-1] += identifier if self.lower_identifier else raw_identifier
3434
args = self._format_args(token[1])
3535
if len(args) < 2:
3636
cmds[-1] += "(" + "".join(args) + ")"
3737
else:
3838
cmds[-1] += "(\n"
3939
for arg in args:
40-
cmds[-1] += self.indent * (indnet_level + 1) + arg + "\n"
41-
cmds[-1] += self.indent * indnet_level + ")"
40+
cmds[-1] += self.indent * (indent_level + 1) + arg + "\n"
41+
cmds[-1] += self.indent * indent_level + ")"
4242
if identifier in (
4343
"if",
4444
"elseif",
@@ -48,14 +48,14 @@ def format(self, tokens: TokenList) -> str:
4848
"macro",
4949
"function",
5050
):
51-
indnet_level += 1
51+
indent_level += 1
5252
elif token == "\n":
5353
cmds.append("")
5454
elif token[0] == "#":
5555
if cmds[-1]:
5656
cmds[-1] += token
5757
else:
58-
cmds[-1] = self.indent * indnet_level + token
58+
cmds[-1] = self.indent * indent_level + token
5959
elif cmds[-1]:
6060
cmds[-1] += token
6161

0 commit comments

Comments
 (0)