Skip to content

Commit

Permalink
refactor: 优化打印语句
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 224efbd commit d109310
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
a = "a"
console.log "🚀 ~ file: no-print-log.copy.coffee:2 ~ a:" + " " + a
console.log "🚀 ~ file: no-print-log.copy.coffee:2 ~ a: " + a
2 changes: 1 addition & 1 deletion sampleWorkspace/default-settings/no-print-log.result.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
std::string a = "a";
std::cout << "🚀 ~ file: no-print-log.copy.cpp:2 ~ a:" << " " << a << std::endl;
std::cout << "🚀 ~ file: no-print-log.copy.cpp:2 ~ a: " << a << std::endl;
2 changes: 1 addition & 1 deletion sampleWorkspace/default-settings/no-print-log.result.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
string a = "a";
Console.WriteLine("🚀 ~ file: no-print-log.copy.cs:2 ~ a:" + " " + a);
Console.WriteLine("🚀 ~ file: no-print-log.copy.cs:2 ~ a: " + a);
2 changes: 1 addition & 1 deletion sampleWorkspace/default-settings/no-print-log.result.java
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
String a = "a";
System.out.println("🚀 ~ file: no-print-log.copy.java:2 ~ a:" + " " + a);
System.out.println("🚀 ~ file: no-print-log.copy.java:2 ~ a: " + a);
2 changes: 1 addition & 1 deletion sampleWorkspace/default-settings/no-print-log.result.kt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
val a = "a"
println("🚀 ~ file: no-print-log.copy.kt:2 ~ a:" + " " + a)
println("🚀 ~ file: no-print-log.copy.kt:2 ~ a: " + a)
2 changes: 1 addition & 1 deletion sampleWorkspace/default-settings/no-print-log.result.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
$a = "a";
echo "🚀 ~ file: no-print-log.result.php:2 ~ \$a:" . " " . $a;
echo "🚀 ~ file: no-print-log.copy.php:2 ~ \$a: " . $a;
2 changes: 1 addition & 1 deletion sampleWorkspace/default-settings/no-print-log.result.pl
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
my $a = "a";
print "🚀 ~ file: no-print-log.copy.pl:2 ~ \$a:" . " " . $a;
print "🚀 ~ file: no-print-log.copy.pl:2 ~ \$a: " . $a;
2 changes: 1 addition & 1 deletion sampleWorkspace/default-settings/no-print-log.result.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
a = "a"
puts "🚀 ~ file: no-print-log.copy.rb:2 ~ a:" + " " + a
puts "🚀 ~ file: no-print-log.copy.rb:2 ~ a: " + a
2 changes: 1 addition & 1 deletion sampleWorkspace/default-settings/no-print-log.result.scala
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
val a = "a"
println("🚀 ~ file: no-print-log.copy.scala:2 ~ a: " + " " + a)
println("🚀 ~ file: no-print-log.copy.scala:2 ~ a: " + a)
6 changes: 4 additions & 2 deletions src/debug-message/GeneralDebugMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ export class GeneralDebugMessage extends DebugMessage {
? `file: ${fileName}:${lineOfLogMsg} ${delimiterInsideMessage} `
: '';
// 处理 Rust 特殊情况
const rustSpecial = lp?.getLanguageId() === 'rust' ? ' {}' : '';
const extraSpace = lp?.getExtraSpace();

Check failure on line 119 in src/debug-message/GeneralDebugMessage.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

src/test/unit/debug-message/GeneralDebugMessage.spec.ts > DebugMessage > insertMessage > 应该在指定行插入调试日志

TypeError: lp?.getExtraSpace is not a function ❯ GeneralDebugMessage.generateDebugMessage src/debug-message/GeneralDebugMessage.ts:119:28 ❯ GeneralDebugMessage.generateAndInsertDebugMessage src/debug-message/GeneralDebugMessage.ts:140:42 ❯ src/test/unit/debug-message/GeneralDebugMessage.spec.ts:67:20
const concatString = lp?.getConcatenatedString();
const variable = lp?.variableToString(selectedVar);
// 构建 content
const content = `${quote}${logMessagePrefix}${prefix}${fileNameAndLineNum}${selectedVar}${logMessageSuffix}${rustSpecial}${quote}${lp?.getConcatenatedString()}${lp?.variableToString(selectedVar)}`;
const content = `${quote}${logMessagePrefix}${prefix}${fileNameAndLineNum}${selectedVar}${logMessageSuffix}${extraSpace}${quote}${concatString}${variable}`;
return lp?.getPrintStatement(content, logFunctionByLanguageId, semicolon);
}

Expand Down
33 changes: 30 additions & 3 deletions src/debug-message/LanguageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,33 @@ export class GeneralLanguageProcessor implements LanguageProcessor {
}
}

public getExtraSpace(): string {
switch (this.languageId) {
case 'javascript':
case 'typescript':
case 'go':
case 'swift':
case 'python':
case 'lua':
case 'shellscript':
return '';
case 'java':
case 'kotlin':
case 'scala':
case 'csharp':
case 'coffeescript':
case 'ruby':
case 'perl':
case 'php':
case 'cpp':
return ' ';
case 'rust':
return ' {}';
default:
return '';
}
}

public getConcatenatedString(): string {
switch (this.languageId) {
case 'javascript':
Expand All @@ -149,14 +176,14 @@ export class GeneralLanguageProcessor implements LanguageProcessor {
case 'csharp':
case 'coffeescript':
case 'ruby':
return ' + " " + ';
return ' + ';
case 'shellscript':
return ' ';
case 'perl':
case 'php':
return ' . " " . ';
return ' . ';
case 'cpp':
return ' << " " << ';
return ' << ';
default:
return ', ';
}
Expand Down
1 change: 1 addition & 0 deletions src/debug-message/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface LanguageProcessor {
getPrintString(): string;
getPrintStatement(variableName: string, logFunctionByLanguageId?: string, semicolon?: string): string;
getSingleLineCommentSymbol(): string;
getExtraSpace(): string;
getConcatenatedString(): string;
variableToString(variableName: string): string;
}

0 comments on commit d109310

Please sign in to comment.