Skip to content

Commit a0c9d9f

Browse files
committed
feat: support for multiline comment for languages that use default regex
1 parent 0ca5b22 commit a0c9d9f

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/server/code-parse/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const parseFile = (
2929

3030
if (parseCodeCrumbs) {
3131
const codecrumbsList = codecrumbsParser.getCrumbs(code, itemPath);
32-
// console.log(codecrumbsList)
3332
if (codecrumbsList.length) {
3433
item.fileCode = code;
3534
item.children = codecrumbsList;

src/server/code-parse/language/default/codecrumbs.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const lineNumber = require('line-number');
2-
const isUndefined = require('lodash/isUndefined');
2+
const compact = require('lodash/compact');
33
const { CC_NODE_TYPE, NO_TRAIL_FLOW } = require('../../../shared-constants');
44

55
const CRUMB_REGEX = /cc|codecrumb/;
@@ -58,17 +58,22 @@ const setupGetCommentsFromCode = regex => fileCode => {
5858
return [];
5959
}
6060

61-
const result = regex.exec(fileCode) || [];
61+
const result = compact(regex.exec(fileCode)) || [];
6262

6363
return result.reduce((comments, value) => {
64-
if (isUndefined(value)) {
65-
return comments;
66-
}
67-
6864
const matchLineNumber = lineNumber(fileCode, regex);
69-
const nodeLines = [matchLineNumber, matchLineNumber];
7065

71-
return [...comments, { value, nodeLines }];
66+
const parseRes = matchLineNumber.filter((val) => val.match == value)[0]
67+
68+
if(parseRes) {
69+
const number = parseRes["number"]
70+
71+
const nodeLines = [1, 1];
72+
73+
return [...comments, { value, nodeLines }];
74+
} else {
75+
return comments;
76+
}
7277

7378
}, []);
7479
};

0 commit comments

Comments
 (0)