Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed Jul 24, 2024
1 parent 47607ea commit ebcc62e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 152 deletions.
108 changes: 56 additions & 52 deletions packages/canyon-platform/src/components/CanyonReport/ShikiDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,33 @@ const ShikiDetail = ({ defaultValue, filecoverage, theme }) => {

Object.entries(statementStats).forEach(([stName, count]) => {
const meta = statementMeta[stName];
const type = count > 0 ? 'yes' : 'no';
const startCol = meta.start.column;
let endCol = meta.end.column + 1;
const startLine = meta.start.line;
const endLine = meta.end.line;

if (type === 'no' && structuredText[startLine]) {
if (endLine !== startLine) {
endCol = structuredText[startLine].length;
if (meta) {
const type = count > 0 ? 'yes' : 'no';
const startCol = meta.start.column;
let endCol = meta.end.column + 1;
const startLine = meta.start.line;
const endLine = meta.end.line;

if (type === 'no' && structuredText[startLine]) {
if (endLine !== startLine) {
endCol = structuredText[startLine].length;
}
// 转化为字符的起始

let start = 0;
let end = 0;

for (let i = 0; i < startLine - 1; i++) {
start += structuredText[i].length + 1;
}
for (let i = 0; i < endLine - 1; i++) {
end += structuredText[i].length + 1;
}

start += startCol;
end += endCol;
statementDecorations.push([start, end]);
}
// 转化为字符的起始

let start = 0;
let end = 0;

for (let i = 0; i < startLine - 1; i++) {
start += structuredText[i].length + 1;
}
for (let i = 0; i < endLine - 1; i++) {
end += structuredText[i].length + 1;
}

start += startCol;
end += endCol;
statementDecorations.push([start, end]);
}
});

Expand All @@ -52,35 +54,37 @@ const ShikiDetail = ({ defaultValue, filecoverage, theme }) => {
const fnMeta = filecoverage.fnMap;
Object.entries(fnStats).forEach(([fName, count]) => {
const meta = fnMeta[fName];
const type = count > 0 ? 'yes' : 'no';
// Some versions of the instrumenter in the wild populate 'func'
// but not 'decl':
const decl = meta.decl || meta.loc;
const startCol = decl.start.column;
let endCol = decl.end.column + 1;
const startLine = decl.start.line;
const endLine = decl.end.line;

if (type === 'no' && structuredText[startLine]) {
if (endLine !== startLine) {
endCol = structuredText[startLine].length;
if (meta) {
const type = count > 0 ? 'yes' : 'no';
// Some versions of the instrumenter in the wild populate 'func'
// but not 'decl':
const decl = meta.decl || meta.loc;
const startCol = decl.start.column;
let endCol = decl.end.column + 1;
const startLine = decl.start.line;
const endLine = decl.end.line;

if (type === 'no' && structuredText[startLine]) {
if (endLine !== startLine) {
endCol = structuredText[startLine].length;
}

// 转化为字符的起始

let start = 0;
let end = 0;

for (let i = 0; i < startLine - 1; i++) {
start += structuredText[i].length + 1;
}
for (let i = 0; i < endLine - 1; i++) {
end += structuredText[i].length + 1;
}

start += startCol;
end += endCol;
fnDecorations.push([start, end]);
}

// 转化为字符的起始

let start = 0;
let end = 0;

for (let i = 0; i < startLine - 1; i++) {
start += structuredText[i].length + 1;
}
for (let i = 0; i < endLine - 1; i++) {
end += structuredText[i].length + 1;
}

start += startCol;
end += endCol;
fnDecorations.push([start, end]);
}
});

Expand Down
100 changes: 0 additions & 100 deletions packages/canyon-platform/src/components/CanyonReport/helper.tsx
Original file line number Diff line number Diff line change
@@ -1,103 +1,3 @@
// 批注语句

export function annotateStatements(fileCoverage: any) {
const annotateStatementsList: any[] = [];
const statementStats = fileCoverage.s;
const statementMeta = fileCoverage.statementMap;
Object.entries(statementStats).forEach(([stName, count]: any) => {
const meta = statementMeta[stName];
// TODO可能是错位等问题导致的map和hit数据对不上
if (meta) {
const type = count > 0 ? 'yes' : 'no';
const startCol = meta.start.column;
const endCol = meta.end.column + 1;
const startLine = meta.start.line;
const endLine = meta.end.line;
if (type === 'no') {
annotateStatementsList.push({
startLine,
endLine,
startCol,
endCol,
type,
});
}
}
});
return annotateStatementsList;
}

export function annotateFunctions(fileCoverage, structuredText) {
const fnStats = fileCoverage.f;
const fnMeta = fileCoverage.fnMap;
if (!fnStats) {
return [];
}
const list = [];
Object.entries(fnStats).forEach(([fName, count]) => {
const meta = fnMeta[fName];
const type = count > 0 ? 'yes' : 'no';
// Some versions of the instrumenter in the wild populate 'func'
// but not 'decl':
const decl = meta.decl || meta.loc;
const startCol = decl.start.column;
let endCol = decl.end.column + 1;
const startLine = decl.start.line;
const endLine = decl.end.line;
if (type === 'no') {
if (endLine !== startLine) {
console.log('???????');
endCol = structuredText[startLine - 1].length;
}
list.push({
startLine,
endLine,
startCol,
endCol,
type,
});
}
});
return list;
}

export function convertingProductionFunctions(
startEnds: { start: number; end: number }[],
sourcecode: string,
) {
// codeLines是源码的每一行
const codeLines = sourcecode.split('\n');

const result = [];

for (let g = 0; g < startEnds.length; g++) {
const xy = [];
let count = 0;
for (let i = 0; i < codeLines.length; i++) {
const line = codeLines[i];
// 注意这块,需要加1,因为split('\n')的时候,每一行的末尾是没有\n的
for (let j = 0; j < line.length + 1; j++) {
if (count === startEnds[g].start || count === startEnds[g].end) {
xy.push({
l: i + 1,
c: j + 1,
});
}
count++;
}
}
result.push(xy);
}
return result.map((i) => {
return {
startLine: i[0].l,
startCol: i[0].c,
endLine: i[1].l,
endCol: i[1].c,
};
});
}

export function coreFn(
fileCoverage: any,
fileDetail: string,
Expand Down

0 comments on commit ebcc62e

Please sign in to comment.