Skip to content

Commit

Permalink
feat: 增加 coffeescript 支持
Browse files Browse the repository at this point in the history
Co-authored-by: ygqygq2 <[email protected]>
  • Loading branch information
ygqygq2 committed Apr 22, 2024
1 parent 79ca6cb commit eb297e3
Show file tree
Hide file tree
Showing 66 changed files with 505 additions and 303 deletions.
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"words": [
"cout",
"endl"
"endl",
"mathiasfrohlich"
]
}
9 changes: 7 additions & 2 deletions .github/workflows/dev-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Development and Testing
on:
push:
branches:
- '*'
jobs:
build:
strategy:
Expand All @@ -25,9 +27,12 @@ jobs:
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: pnpm i --frozen-lockfile --ignore-scripts
- run: xvfb-run -a pnpm test:suite
- run: |
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/dbus/system_bus_socket
sudo systemctl start dbus
xvfb-run -a pnpm test:suite:mocha
if: runner.os == 'Linux'
- run: pnpm test:suite
- run: pnpm test:suite:mocha
if: runner.os != 'Linux'
- run: pnpm run test:coverage
- run: vsce package --no-dependencies
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sampleWorkspace/
38 changes: 32 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,47 @@
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"args": ["--disable-extensions", "--extensionDevelopmentPath=${workspaceFolder}"],
"runtimeExecutable": "${execPath}",
"args": [
"${workspaceRoot}/sampleWorkspace/test.code-workspace",
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
"preLaunchTask": "${defaultBuildTask}",
"sourceMaps": true
},
{
"name": "Test: e2e",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"testConfiguration": "${workspaceFolder}/.vscode-test-debug.mjs",
"args": [
"${workspaceFolder}/sampleWorkspace/test.code-workspace",
"--extensionDevelopmentPath=${workspaceFolder}",
],
"env": {
"TS_NODE_PROJECT": "${workspaceFolder}/tsconfig.mocha.json"
},
"preLaunchTask": "npm: test-compile",
"sourceMaps": true
},
{
"name": "Test: All",
"name": "Test: e2e use mocha",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"${workspaceFolder}/sampleWorkspace/test.code-workspace",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/testsRunner"
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"env": {
"TS_NODE_PROJECT": "${workspaceFolder}/tsconfig.json"
},
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
"preLaunchTask": "npm: test-compile",
"sourceMaps": true
},
{
"type": "node",
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ All notable changes to the "turbo-console-log" extension will be documented in t

## 新增功能 🌱

- feat: 增加 coffeescript 支持

# [3.0.6]

## 新增功能 🌱

- feat: 增加几个语言支持

# [3.0.5]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Properties:
- swift
- shellscript
- lua
- coffeescript

## License

Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "turbo-print-log",
"displayName": "Turbo Console Log for more language",
"description": "选中变量,根据不同语言增加一行变量打印日志",
"version": "3.0.6",
"version": "3.0.7",
"publisher": "ygqygq2",
"engines": {
"vscode": "^1.85.0"
"vscode": "^1.88.0"
},
"icon": "images/icon.png",
"categories": [
Expand Down Expand Up @@ -153,10 +153,10 @@
"package": "vsce package --no-dependencies",
"publish": "vsce publish --no-dependencies",
"clean": "rimraf out/",
"test-compile": "npm run clean && tsc -p ./ && npm run compile",
"test": "npm run test-compile && vscode-test",
"test-grep": "vscode-test -f",
"test:suite:mocha": "tsc -p ./ && node out/test/runTests.js",
"test-compile": "npm run clean && tsc -p tsconfig.mocha.json && npm run compile",
"test": "TS_NODE_PROJECT=tsconfig.mocha.json vscode-test",
"test-grep": "TS_NODE_PROJECT=tsconfig.mocha.json vscode-test -f",
"test:suite:mocha": "TS_NODE_PROJECT=tsconfig.mocha.json npm run test-compile && node out/test/runTests.js",
"test:suite": "vitest suite --watch=false",
"test:unit": "vitest unit --watch=false",
"test:coverage": "vitest run --coverage",
Expand All @@ -174,7 +174,7 @@
"@types/node": "^20.12.7",
"@types/sinon": "^17.0.3",
"@types/tmp": "^0.2.6",
"@types/vscode": "^1.85.0",
"@types/vscode": "^1.88.0",
"@typescript-eslint/eslint-plugin": "^7.7.0",
"@typescript-eslint/parser": "^7.7.0",
"@vitest/coverage-v8": "^1.5.0",
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions sampleWorkspace/default-settings/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"turboConsoleLog.wrapLogMessage": false,
"turboConsoleLog.logMessagePrefix": "🚀",
"turboConsoleLog.logMessageSuffix": ":",
"turboConsoleLog.includeFileNameAndLineNum": false,
"turboConsoleLog.addSemicolonInTheEnd": false,
"turboConsoleLog.insertEmptyLineBeforeLogMessage": true,
"turboConsoleLog.insertEmptyLineAfterLogMessage": false,
"turboConsoleLog.delimiterInsideMessage": "~",
"turboConsoleLog.quote": "\""
}
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = "a"
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std::string a = "a";
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
string a = "a";
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a := "a"
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
String a = "a";
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const a = 'a';
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val a = "a"
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local a = "a"
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$a = "a";
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
my $a = "a";
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = "a"
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = "a"
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a = "a"
console.log "🚀 ~ file: no-print-log.copy.coffee:2 ~ a:" + " " + a
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
std::string a = "a";
std::cout << "🚀 ~ file: no-print-log.copy.cpp:2 ~ a:" << " " << a << std::endl;
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
string a = "a";
Console.WriteLine("🚀 ~ file: no-print-log.copy.cs:2 ~ a:" + " " + a);
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a := "a"
fmt.Println("🚀 ~ file: no-print-log.copy.go:2 ~ a:", a)
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
String a = "a";
System.out.println("🚀 ~ file: no-print-log.copy.java:2 ~ a:" + " " + a);
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const a = 'a';
console.log("🚀 ~ file: no-print-log.copy.js:2 ~ a:", a)
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
val a = "a"
println("🚀 ~ file: no-print-log.copy.kt:2 ~ a:" + " " + a)
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
local a = "a"
print("🚀 ~ file: no-print-log.copy.lua:2 ~ a:", a)
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$a = "a";
echo "🚀 ~ file: no-print-log.result.php:2 ~ \$a:" . " " . $a;
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
my $a = "a";
print "🚀 ~ file: no-print-log.copy.pl:2 ~ \$a:" . " " . $a;
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a = "a"
print("🚀 ~ file: no-print-log.copy.py:2 ~ a:", a)
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a = "a"
puts "🚀 ~ file: no-print-log.copy.rb:2 ~ a:" + " " + a
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let a = "a";
println!("🚀 ~ file: no-print-log.copy.rs:2 ~ a: {}", a);
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
val a = "a"
println("🚀 ~ file: no-print-log.copy.scala:2 ~ a: " + " " + a)
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a="a"
echo "🚀 ~ file: no-print-log.copy.sh:2 ~ a:" ${a}
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var a = "a"
print("🚀 ~ file: no-print-log.copy.swift:2 ~ a:", a)
2 changes: 2 additions & 0 deletions sampleWorkspace/default-settings/no-print-log.result.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const a = 'a';
console.log("🚀 ~ file: no-print-log.copy.ts:2 ~ a:", a)
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let a = "a";
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val a = "a"
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a="a"
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var a = "a"
1 change: 1 addition & 0 deletions sampleWorkspace/default-settings/no-print-log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const a = 'a';
10 changes: 5 additions & 5 deletions sampleWorkspace/test.code-workspace
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"folders": [
{ "path": "file-header" },
{ "path": "file-header-project" },
{ "path": "function-comment-for-ts" },
{ "path": "function-comment-for-go" },
{ "path": "default-settings" },
{ "path": "workspace" },
],
"settings": {},
"settings": {
"mathiasfrohlich.kotlin": true,
"scala-lang.scala": true
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion src/commands/commentAllLogMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function commentAllLogMessagesCommand(): Command {

const document: vscode.TextDocument = editor.document;
// 检测所有log消息
const logMessages: Message[] = debugMessage.detectAll(
const logMessages: Message[] = debugMessage.detectAllDebugLine(
document,
logFunctionToUse(),
logMessagePrefix,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/deleteAllLogMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function deleteAllLogMessagesCommand(): Command {
const document: vscode.TextDocument = editor.document;
// 检测所有日志消息
const logFunctionByLanguageId = debugMessage?.getLanguageProcessor().getLogFunction(logFunction);
const logMessages: Message[] = debugMessage.detectAll(
const logMessages: Message[] = debugMessage.detectAllDebugLine(
document,
logFunctionByLanguageId,
logMessagePrefix,
Expand Down
21 changes: 13 additions & 8 deletions src/commands/displayLogMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { logger } from '@/extension';
import { instanceDebugMessage } from '@/utils/instanceDebugMessage';

import { Command, ExtensionProperties } from '../typings';
import { getTabSize } from '../utils/getTabSize';

// 插入调试日志/更新调试日志行号
export function displayLogMessageCommand(): Command {
Expand All @@ -24,8 +23,6 @@ export function displayLogMessageCommand(): Command {
return;
}
const { debugMessage } = instanceDebugMessage(editor);
// 获取tab大小
const tabSize: number | string = getTabSize(editor.options.tabSize);
// 获取文档
const document: vscode.TextDocument = editor.document;
// 遍历当前选择的范围
Expand All @@ -34,13 +31,22 @@ export function displayLogMessageCommand(): Command {
const selection: vscode.Selection = editor.selections[index];

// 获取当前选择文本
// if rangeUnderCursor is undefined, `document.getText(undefined)` will return the entire file.
// 如果rangeUnderCursor为undefined,则返回整个文档
const selectedVar =
(selection && document.getText(selection)) ||
(() => {
// 获取当前光标所在单词范围
const rangeUnderCursor = document.getWordRangeAtPosition(selection.active);
let rangeUnderCursor = document.getWordRangeAtPosition(selection.active);
if (!rangeUnderCursor) {
// 如果没有找到匹配的单词,那么向后查找,直到找到一个空格或引号
let position = selection.active;
while (position.character < document.lineAt(position.line).text.length) {
position = position.translate(0, 1);
rangeUnderCursor = document.getWordRangeAtPosition(position, /\$\w+|\w+/);
if (rangeUnderCursor) {
break;
}
}
}
return (rangeUnderCursor && document.getText(rangeUnderCursor)) || '';
})();
// 获取当前光标所在行
Expand All @@ -51,12 +57,11 @@ export function displayLogMessageCommand(): Command {
logger.info('Insert debug log');
await editor.edit((editBuilder) => {
// 调用debugMessage.insertMessage函数
debugMessage.insertMessage(
debugMessage.generateAndInsertDebugMessage(
editBuilder,
document,
selectedVar,
lineOfSelectedVar,
tabSize,
extensionProperties,
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/commands/uncommentAllLogMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function uncommentAllLogMessagesCommand(): Command {

// 检测所有日志消息
const logFunctionByLanguageId = debugMessage?.getLanguageProcessor().getLogFunction(logFunction);
const logMessages: Message[] = debugMessage.detectAll(
const logMessages: Message[] = debugMessage.detectAllDebugLine(
document,
logFunctionByLanguageId,
logMessagePrefix,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/updateLineNumAllLogMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function updateLineNumAllLogMessagesCommand(): Command {

// 检测所有日志消息
const logFunctionByLanguageId = debugMessage?.getLanguageProcessor().getLogFunction(logFunction);
const logMessages: Message[] = debugMessage.detectAll(
const logMessages: Message[] = debugMessage.detectAllDebugLine(
document,
logFunctionByLanguageId,
logMessagePrefix,
Expand Down
5 changes: 2 additions & 3 deletions src/debug-message/DebugMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ export abstract class DebugMessage {
}

// 返回消息
abstract insertMessage(
abstract generateAndInsertDebugMessage(
textEditor: TextEditorEdit,
document: TextDocument,
selectedVar: string,
lineOfSelectedVar: number,
tabSize: number,
extensionProperties: ExtensionProperties,
): void;

// 检测消息
abstract detectAll(
abstract detectAllDebugLine(
document: TextDocument,
logFunctionByLanguageId: string,
logMessagePrefix: string,
Expand Down
Loading

0 comments on commit eb297e3

Please sign in to comment.