Skip to content

Commit

Permalink
fix: resolve the null line
Browse files Browse the repository at this point in the history
  • Loading branch information
daodaolee committed Aug 28, 2023
1 parent fd65617 commit b340ccb
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
46 changes: 46 additions & 0 deletions README-zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Tree Log

<center>

<img src="res/icon.svg" width=80>

</center>

<center>

<a href="https://marketplace.visualstudio.com/items?itemName=daodaolea.tree-log" target="__blank"><img src="https://img.shields.io/visual-studio-marketplace/v/daodaolea.tree-log.svg?color=eee&amp;label=VS%20Code%20Marketplace&logo=visual-studio-code" alt="Visual Studio Marketplace Version" /></a>

</center>

一个自动生成树形格式的 console.log 语句的插件。默认的树头是随机 Emoji 符号,可以自定义。

<center>

![shot](res/shot.png)

</center>

## 特性

<center>

![shot](res/shot.gif)

</center>

你可以选择变量后使用快捷键 `alt` + `c` 自动生成控制台语句,也可以使用 `ctrl` + `alt` + `c` 删除文件的控制台语句。

你还可以使用 `命令面板`,搜索 `Add Tree Log` 来生成它们,或者搜索 `Delete Tree Log` 来删除。

当然,你也可以在选择变量后右键,选择 `Tree Log` 进行操作。



## 设置

你可以通过 `Settings.json` 添加文本,来自定义树头(命令面板 -> 首选项:打开设置 (JSON))

比如:

* `tree-log.suffix`: "a custom text"

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

<center>

<img src="res/icon.svg" width=80>

[中文文档](/README-zh.md)

</center>

<center>

<a href="https://marketplace.visualstudio.com/items?itemName=daodaolea.tree-log" target="__blank"><img src="https://img.shields.io/visual-studio-marketplace/v/daodaolea.tree-log.svg?color=eee&amp;label=VS%20Code%20Marketplace&logo=visual-studio-code" alt="Visual Studio Marketplace Version" /></a>

</center>
Expand Down
Binary file modified res/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions res/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions src/core.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import * as vscode from 'vscode'
import { getRandomEmoji } from './util'

const editor = vscode.window.activeTextEditor
import { getRandomEmoji } from './util'

export function addLog() {
const editor = vscode.window.activeTextEditor
if (!editor)
return

const textArray: string[] = []
const selectRanges = editor.selections
selectRanges.forEach((range) => {
let text = editor.document.getText(range)
let insertText = 'console.log('
if (text) {
text = text.replace(/'/g, '"')
const suffix = vscode.workspace.getConfiguration().get('tree-log.suffix')
const emoji = getRandomEmoji()
insertText = `console.log(' ${suffix || emoji}', '\\n', '├──', '${text}', '\\n', '└──', ${text}, '\\n')`
const insertText = `console.log(' ${suffix || emoji}', '\\n', '├──', '${text}', '\\n', '└──', ${text}, '\\n')`
textArray.push(insertText)
}
textArray.push(insertText)
})

vscode.commands.executeCommand('editor.action.insertLineAfter')
Expand All @@ -38,6 +37,7 @@ export function addLog() {
}

export function deleteLog() {
const editor = vscode.window.activeTextEditor
const logRegex = /(console.(log|debug|info|warn|error|assert|dir|dirxml|trace|group|groupEnd|time|timeEnd|profile|profileEnd|count)\((.*)\)| log\((.*)\));?/g
if (!editor)
return
Expand Down

0 comments on commit b340ccb

Please sign in to comment.