Skip to content

Commit

Permalink
default to cpp domain/highlighting in /// content
Browse files Browse the repository at this point in the history
  • Loading branch information
bkietz committed Nov 4, 2024
1 parent 599431f commit 2c4d935
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cmake_modules/test_.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/// distinct test case using the same test body. In the scope of
/// the test body, the parameter is declared as
///
/// .. cpp:var:: Parameter const &parameter
/// .. var:: Parameter const &parameter
///
/// If parameters are read from an initializer list or other
/// range then this is analogous to a
Expand Down Expand Up @@ -82,7 +82,7 @@
/// // Expected: three == five
/// // Actual: 3 vs 5
///
/// :cpp:expr:`EXPECT_(...)` produces an expression rather than a statement.
/// :expr:`EXPECT_(...)` produces an expression rather than a statement.
/// It is contextually convertible to ``bool``, truthy iff the condition
/// was truthy. If additional context needs to be added to a failed
/// expectation, a lambda can be provided which will only be called
Expand Down Expand Up @@ -135,11 +135,11 @@
/// };
///
/// This may be omitted, in which case no state will be shared.
/// If it is provided it must precede all :cpp:expr:`TEST_(...)`
/// If it is provided it must precede all :expr:`TEST_(...)`
/// definitions (this is checked at runtime).
///
/// A pointer to the constructed state ``struct`` is accessible
/// in test bodies by calling :cpp:expr:`suite_state()`.
/// in test bodies by calling :expr:`suite_state()`.
///
/// .. code-block::
///
Expand Down
7 changes: 7 additions & 0 deletions cmake_modules/trike/test_trike.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def test_basic(tmp_path):
using cHAR = char;
} // namespace baz
/// e
enum Enum {
/// s
SCOPED
};
""",
)
file_content = trike.comment_scan(path, clang_args=[])
Expand Down Expand Up @@ -126,6 +132,7 @@ def test_basic(tmp_path):
clang_cursor_kind="TYPE_ALIAS_DECL",
),
),
0
]
assert file_content.floating_comments == [
trike.Comment(
Expand Down
20 changes: 19 additions & 1 deletion cmake_modules/trike/trike/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import dataclass
from contextlib import contextmanager
from pathlib import Path

import sphinx.util.logging
Expand Down Expand Up @@ -427,6 +428,22 @@ class PutDirective(SphinxDirective):
required_arguments = 2
optional_arguments = 1000

@contextmanager
def default_cpp(self):
tmp = {}
tmp["highlight_language"] = self.env.temp_data.get("highlight_language", None)
self.env.temp_data["highlight_language"] = "cpp"
tmp["default_domain"] = self.env.temp_data.get("default_domain", None)
self.env.temp_data["default_domain"] = self.env.domains.get("cpp")
try:
yield
finally:
for key, value in tmp.items():
if value is None:
del self.env.temp_data[key]
else:
self.env.temp_data[key] = value

def run(self) -> list[Node]:
directive = self.arguments[0]
namespace = self.env.temp_data.get("cpp:namespace_stack", [""])[-1]
Expand Down Expand Up @@ -456,7 +473,8 @@ def run(self) -> list[Node]:
*(f" {line}" for line in comment.stripped_text),
]
)
return self.parse_text_to_nodes(text)
with self.default_cpp():
return self.parse_text_to_nodes(text)

message = f"found no declaration matching `{declaration}`\n {context=}"
for m in difflib.get_close_matches(declaration, declarations.keys()):
Expand Down

0 comments on commit 2c4d935

Please sign in to comment.