MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / comment_marks

Method comment_marks

codegraph-kernel/src/tsjs/extractors.rs:1011–1037  ·  view source on GitHub ↗

commentMarks: every byte offset in the source where a comment could begin, each `//` and `/*`, in order; read once for the file. A stretch of source with none holds no comment, so a literal of plain values is told from one somebody documented without visiting a member. More than the comments (`'a//b'` in a string is one), never fewer. The `//` of `https://` is left out: no comment that documents a

(&self)

Source from the content-addressed store, hash-verified

1009 /// `https://` is left out: no comment that documents a member follows a `:`
1010 /// directly, and a table of URLs is the commonest literal with a `//`.
1011 fn comment_marks(&self) -> &[u32] {
1012 self.comment_marks.get_or_init(|| {
1013 let src = self.src;
1014 let bytes = src.as_bytes();
1015 let mut marks = Vec::new();
1016 let mut from = 0usize;
1017 // `/`, `*` and `:` are single bytes that no longer character holds,
1018 // so every `from` is a character boundary.
1019 while let Some(found) = src[from..].find('/') {
1020 let at = from + found;
1021 match bytes.get(at + 1) {
1022 Some(b'*') => {
1023 marks.push(at as u32);
1024 from = at + 2;
1025 }
1026 Some(b'/') => {
1027 if at == 0 || bytes[at - 1] != b':' {
1028 marks.push(at as u32);
1029 }
1030 from = at + 2;
1031 }
1032 _ => from = at + 1,
1033 }
1034 }
1035 marks
1036 })
1037 }
1038
1039 /// mayHoldComment: whether a comment could begin in `[start, end)`.
1040 fn may_hold_comment(&self, start: usize, end: usize) -> bool {

Callers 1

may_hold_commentMethod · 0.80

Calls 2

pushMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected