Skip to content

Commit 3630623

Browse files
committed
support source paths in Location objects
Location objects only contained the full path and the path relative to the search directories. This commit includes a new field for the source path, which contains the path relative to the `source-root`. #feat fix #798
1 parent ef4ff12 commit 3630623

File tree

118 files changed

+1467
-1443
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+1467
-1443
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ if (MRDOCS_BUILD_TESTS)
440440
DEPENDS mrdocs.rnc)
441441
add_custom_target(mrdocs_rng ALL DEPENDS mrdocs.rng)
442442

443-
file(GLOB_RECURSE XML_SOURCES CONFIGURE_DEPENDS test-files/*.xml)
443+
file(GLOB_RECURSE XML_SOURCES CONFIGURE_DEPENDS test-files/golden-tests/*.xml)
444444
add_test(NAME xml-lint
445445
COMMAND ${LIBXML2_XMLLINT_EXECUTABLE} --dropdtd --noout
446446
--relaxng ${CMAKE_CURRENT_BINARY_DIR}/mrdocs.rng ${XML_SOURCES}

docs/modules/ROOT/pages/generators.adoc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -862,25 +862,25 @@ The location object has the following properties:
862862
|===
863863
|Property |Type| Description
864864

865-
| `path`
865+
| `fullPath`
866866
| `string`
867-
| The path of the source file.
867+
| The full path of the source file.
868868

869-
| `file`
869+
| `shortPath`
870870
| `string`
871-
| The filename of the source file.
871+
| The path of the source file relative to the search directories.
872+
873+
| `sourcePath`
874+
| `string`
875+
| The path of the source file relative to the `source-root`.
872876

873877
| `line`
874878
| `integer`
875-
| The line number of the symbol.
876-
877-
| `kind`
878-
| `string`
879-
| The kind of file (e.g., `source`, `system`, `other`).
879+
| The line number of the symbol at this location.
880880

881881
| `documented`
882882
| `bool`
883-
| Whether the symbol is documented.
883+
| Whether the symbol is documented at this location.
884884
|===
885885

886886
[#tparam-fields]

docs/mrdocs.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
},
226226
"source-root": {
227227
"default": "<config-dir>",
228-
"description": "Path to the root directory of the source code. This path is used as a default for input files and a base for relative paths formed from absolute paths.",
228+
"description": "Path to the root directory of the source code. This path is used as a default for input files and a base for relative paths formed from absolute paths. This should typically be the root directory of the git project, as relative paths formed from it can be used to create links to these source files in the repository. Templates use the `base-url` option to create links to the source code.",
229229
"title": "Path to the root directory of the source code",
230230
"type": "string"
231231
},

include/mrdocs/Metadata/Source.hpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ struct MRDOCS_DECL
5151
{
5252
/** The full file path
5353
*/
54-
std::string Path;
54+
std::string FullPath;
5555

56-
/** Name of the file
56+
/** The file path relative to one of the search directories
5757
*/
58-
std::string Filename;
58+
std::string ShortPath;
59+
60+
/** The file path relative to the source-root directory
61+
*/
62+
std::string SourcePath;
5963

6064
/** Line number within the file
6165
*/
@@ -68,12 +72,14 @@ struct MRDOCS_DECL
6872
//--------------------------------------------
6973

7074
Location(
71-
std::string_view const filepath = {},
72-
std::string_view const filename = {},
75+
std::string_view const full_path = {},
76+
std::string_view const short_path = {},
77+
std::string_view const source_path = {},
7378
unsigned const line = 0,
7479
bool const documented = false)
75-
: Path(filepath)
76-
, Filename(filename)
80+
: FullPath(full_path)
81+
, ShortPath(short_path)
82+
, SourcePath(source_path)
7783
, LineNumber(line)
7884
, Documented(documented)
7985
{
@@ -92,7 +98,7 @@ struct LocationEmptyPredicate
9298
constexpr bool operator()(
9399
Location const& loc) const noexcept
94100
{
95-
return loc.Filename.empty();
101+
return loc.ShortPath.empty();
96102
}
97103
};
98104

mrdocs.rnc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ grammar
326326
Location =
327327
element file
328328
{
329-
attribute path {text},
329+
# attribute full-path {text},
330+
attribute short-path {text},
331+
attribute source-path {text},
330332
attribute line {text},
331333
attribute class {"def"} ?,
332334
empty

share/mrdocs/addons/generator/common/partials/location/source.hbs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
1212
--}}
1313
Declared in {{#>markup/code~}}
14-
{{ str "<" }}{{#unless (and @root.config.base-url (eq dcl.kind "source"))~}}
15-
{{dcl.file}}
14+
{{ str "<" }}{{#if (and @root.config.base-url dcl.shortPath dcl.sourcePath)~}}
15+
{{#>markup/a href=(concat @root.config.base-url dcl.sourcePath '#L' dcl.line)}}{{dcl.shortPath}}{{/markup/a}}
1616
{{~else~}}
17-
{{#>markup/a href=(concat @root.config.base-url dcl.file '#L' dcl.line)}}{{dcl.file}}{{/markup/a}}
18-
{{~/unless~}}{{ str ">" }}
17+
{{dcl.shortPath}}
18+
{{~/if~}}{{ str ">" }}
1919
{{~/markup/code}}

src/lib/AST/ASTVisitor.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ populate(
696696
{
697697
return;
698698
}
699-
I.DefLoc.emplace(file->full_path, file->short_path, line, documented);
699+
I.DefLoc.emplace(file->full_path, file->short_path, file->source_path, line, documented);
700700
}
701701
else
702702
{
@@ -705,13 +705,13 @@ populate(
705705
[line, file](const Location& l)
706706
{
707707
return l.LineNumber == line &&
708-
l.Path == file->full_path;
708+
l.FullPath == file->full_path;
709709
});
710710
if (existing != I.Loc.end())
711711
{
712712
return;
713713
}
714-
I.Loc.emplace_back(file->full_path, file->short_path, line, documented);
714+
I.Loc.emplace_back(file->full_path, file->short_path, file->source_path, line, documented);
715715
}
716716
}
717717

@@ -2762,6 +2762,15 @@ buildFileInfo(std::string_view const file_path)
27622762
return tryGetRelativePosixPath(posixPrefix);
27632763
};
27642764

2765+
// Populate file relative to source-root
2766+
if (files::isAbsolute(config_->sourceRoot))
2767+
{
2768+
if (auto shortPath = tryGetRelativePath(config_->sourceRoot))
2769+
{
2770+
file_info.source_path = std::string(*shortPath);
2771+
}
2772+
}
2773+
27652774
// Find the best match for the file path in the search directories
27662775
for (HeaderSearch& HS = sema_.getPreprocessor().getHeaderSearchInfo();
27672776
DirectoryLookup const& DL : HS.search_dir_range())
@@ -2780,14 +2789,11 @@ buildFileInfo(std::string_view const file_path)
27802789
}
27812790
}
27822791

2783-
// Fallback to sourceRoot
2784-
if (files::isAbsolute(config_->sourceRoot))
2792+
// Fallback to the source root
2793+
if (!file_info.source_path.empty())
27852794
{
2786-
if (auto shortPath = tryGetRelativePath(config_->sourceRoot))
2787-
{
2788-
file_info.short_path = std::string(*shortPath);
2789-
return file_info;
2790-
}
2795+
file_info.short_path = file_info.source_path;
2796+
return file_info;
27912797
}
27922798

27932799
// Fallback to system search paths in PATH

src/lib/AST/ASTVisitor.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class ASTVisitor
9595
// The file path relative to a search directory.
9696
std::string short_path;
9797

98+
// The file path relative to the source-root directory.
99+
std::string source_path;
100+
98101
// Whether this file passes the file filters
99102
std::optional<bool> passesFilters;
100103
};

src/lib/Gen/xml/XMLWriter.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,14 @@ XMLWriter::
626626
writeSourceInfo(
627627
SourceInfo const& I)
628628
{
629-
if(I.DefLoc)
629+
if (I.DefLoc)
630+
{
630631
writeLocation(*I.DefLoc, true);
631-
for(auto const& loc : I.Loc)
632+
}
633+
for (auto const& loc: I.Loc)
634+
{
632635
writeLocation(loc, false);
636+
}
633637
}
634638

635639
void
@@ -639,9 +643,11 @@ writeLocation(
639643
bool def)
640644
{
641645
tags_.write("file", {}, {
642-
{ "path", loc.Filename },
646+
// { "full-path", loc.FullPath },
647+
{ "short-path", loc.ShortPath },
648+
{ "source-path", loc.SourcePath },
643649
{ "line", std::to_string(loc.LineNumber) },
644-
{ "class", "def", def } });
650+
{ "class", "def", def }});
645651
}
646652

647653
//------------------------------------------------

src/lib/Lib/ConfigOptions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
{
4343
"name": "source-root",
4444
"brief": "Path to the root directory of the source code",
45-
"details": "Path to the root directory of the source code. This path is used as a default for input files and a base for relative paths formed from absolute paths.",
45+
"details": "Path to the root directory of the source code. This path is used as a default for input files and a base for relative paths formed from absolute paths. This should typically be the root directory of the git project, as relative paths formed from it can be used to create links to these source files in the repository. Templates use the `base-url` option to create links to the source code.",
4646
"type": "dir-path",
4747
"default": "<config-dir>",
4848
"relative-to": "<config-dir>",

0 commit comments

Comments
 (0)