summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-source-loc.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-02-23 12:36:46 -0500
committerGitHub <noreply@github.com>2021-02-23 12:36:46 -0500
commit55a5ccc559b34b8d2eb9c7b7a2d9efbae40619c2 (patch)
tree105e60200bc4f6ac13a1845b448886d777a7398a /source/slang/slang-source-loc.cpp
parent4bf01b04cb6bf1df8d4fb2ec5eee0a912ec679dc (diff)
Documentation markup extraction (#1724)
* #include an absolute path didn't work - because paths were taken to always be relative. * WIP extracting source documentation. * WIP doc extraction. * More stuff around doc markup extraction. * More WIP around doc extraction. * Fix some indexing issues. * Initial doc extraction working. * Renaming of types in markup extraction process. * Extracting markup content. Removing indenting. Other fixes and improvements around document tools. * WIP support for documentation system. * Remove some commented out sections. * Remove some comments that no longer apply. * Improvements around SourceFile - such that more granularity around line ops. Made some functionality explicitly work without source. Improved Doc types nameing.
Diffstat (limited to 'source/slang/slang-source-loc.cpp')
-rw-r--r--source/slang/slang-source-loc.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/source/slang/slang-source-loc.cpp b/source/slang/slang-source-loc.cpp
index 4b9e16b8e..3f9f8ad31 100644
--- a/source/slang/slang-source-loc.cpp
+++ b/source/slang/slang-source-loc.cpp
@@ -279,6 +279,55 @@ const List<uint32_t>& SourceFile::getLineBreakOffsets()
return m_lineBreakOffsets;
}
+SourceFile::OffsetRange SourceFile::getOffsetRangeAtLineIndex(Index lineIndex)
+{
+ const List<uint32_t>& offsets = getLineBreakOffsets();
+ const Index count = offsets.getCount();
+
+ if (lineIndex >= count - 1)
+ {
+ // Work out the line start
+ const uint32_t offsetEnd = uint32_t(getContentSize());
+ const uint32_t offsetStart = (lineIndex >= count) ? offsetEnd : offsets[lineIndex];
+ // The line is the span from start, to the end of the content
+ return OffsetRange{ offsetStart, offsetEnd };
+ }
+ else
+ {
+ const uint32_t offsetStart = offsets[lineIndex];
+ const uint32_t offsetEnd = offsets[lineIndex + 1];
+ return OffsetRange { offsetStart, offsetEnd };
+ }
+}
+
+UnownedStringSlice SourceFile::getLineAtIndex(Index lineIndex)
+{
+ const OffsetRange range = getOffsetRangeAtLineIndex(lineIndex);
+
+ if (range.isValid() && hasContent())
+ {
+ const UnownedStringSlice content = getContent();
+ SLANG_ASSERT(range.end <= uint32_t(content.getLength()));
+
+ const char*const text = content.begin();
+ return UnownedStringSlice(text + range.start, text + range.end);
+ }
+
+ return UnownedStringSlice();
+}
+
+UnownedStringSlice SourceFile::getLineContainingOffset(uint32_t offset)
+{
+ const Index lineIndex = calcLineIndexFromOffset(offset);
+ return getLineAtIndex(lineIndex);
+}
+
+bool SourceFile::isOffsetOnLine(uint32_t offset, Index lineIndex)
+{
+ const OffsetRange range = getOffsetRangeAtLineIndex(lineIndex);
+ return range.isValid() && range.containsInclusive(offset);
+}
+
int SourceFile::calcLineIndexFromOffset(int offset)
{
SLANG_ASSERT(UInt(offset) <= getContentSize());