Skip to content

Commit

Permalink
feat: 简化调试日志删除
Browse files Browse the repository at this point in the history
果然简单的才是最好用的

Co-authored-by: ygqygq2 <[email protected]>
  • Loading branch information
ygqygq2 committed Feb 23, 2024
1 parent 6e0cbfd commit a0d9561
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 38 deletions.
41 changes: 18 additions & 23 deletions src/commands/deleteAllLogMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,27 @@ export function deleteAllLogMessagesCommand(): Command {
logMessagePrefix,
delimiterInsideMessage,
);
console.log(
'🚀 ~ file: deleteAllLogMessages.ts:29 ~ logMessages:',
JSON.stringify(logMessages),
);

// 遍历所有日志消息,删除日志消息
editor.edit((editBuilder) => {
logMessages.forEach(({ lines }) => {
const firstLine = lines[0];
const lastLine = lines[lines.length - 1];
const lineBeforeFirstLine = new vscode.Range(
new vscode.Position(firstLine.start.line - 1, 0),
new vscode.Position(firstLine.end.line - 1, 0),
);
const lineAfterLastLine = new vscode.Range(
new vscode.Position(lastLine.start.line + 1, 0),
new vscode.Position(lastLine.end.line + 1, 0),
);
// 如果当前行是空行,则删除
if (document.lineAt(lineBeforeFirstLine.start).text === '') {
editBuilder.delete(lineBeforeFirstLine);
}
if (document.lineAt(lineAfterLastLine.start).text === '') {
editBuilder.delete(lineAfterLastLine);
}
// 删除所有日志消息
lines.forEach((line: vscode.Range) => {
editBuilder.delete(line);
editor
.edit((editBuilder) => {
logMessages.forEach(({ lines }) => {
lines.forEach((line: vscode.Range) => {
editBuilder.delete(line);
});
});
})
.then((success) => {
if (success) {
vscode.window.showInformationMessage('TurboConsoleLog: Delete debug log successes.');
} else {
vscode.window.showErrorMessage('TurboConsoleLog: Delete debug log failed.');
}
});
});
},
};
}
2 changes: 1 addition & 1 deletion src/commands/displayLogMessage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import { Command, ExtensionProperties } from '../typings';
import { getTabSize } from '../utils';
import { getTabSize } from '../utils/getTabSize';
import { instanceDebugMessage } from '@/utils/instanceDebugMessage';

// 插入调试日志/更新调试日志行号
Expand Down
2 changes: 1 addition & 1 deletion src/debug-message/DebugMessage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Position, TextDocument, TextEditorEdit } from 'vscode';
import { closingContextLine } from '@/utils';
import { omit } from 'lodash';
import { BracketType, ExtensionProperties, Message } from '../typings';
import { LanguageProcessor } from './types';
import { closingContextLine } from '@/utils/closingContextLine';

// 导出抽象类DebugMessage
export abstract class DebugMessage {
Expand Down
2 changes: 1 addition & 1 deletion src/test/unit/utils/getTabSize.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getTabSize } from '@/utils';
import { getTabSize } from '@/utils/getTabSize';
import { expectTypeOf } from 'expect-type';
import { describe, expect, it } from 'vitest';

Expand Down
41 changes: 41 additions & 0 deletions src/utils/checkRangeOverlapping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Message } from '@/typings';
import { TextEditor } from 'vscode';

export const checkRangeOverlapping = (logMessages: Message[], editor: TextEditor) => {
const rangeToCheck = editor.selections[0];
const overlappingMessages = logMessages.filter(({ lines }) => {
return lines.some((lineRange) => {
const intersectionRange = lineRange.intersection(rangeToCheck);
if (intersectionRange !== undefined) {
console.log('范围重叠的信息:');
console.log(
'范围A:',
lineRange.start.line,
lineRange.start.character,
'-',
lineRange.end.line,
lineRange.end.character,
);
console.log(
'范围B:',
rangeToCheck.start.line,
rangeToCheck.start.character,
'-',
rangeToCheck.end.line,
rangeToCheck.end.character,
);
console.log(
'重叠范围:',
intersectionRange.start.line,
intersectionRange.start.character,
'-',
intersectionRange.end.line,
intersectionRange.end.character,
);
}
return intersectionRange !== undefined;
});
});

return overlappingMessages.length > 0;
};
12 changes: 0 additions & 12 deletions src/utils/index.ts

This file was deleted.

0 comments on commit a0d9561

Please sign in to comment.