Skip to content

Commit 6e33ded

Browse files
committed
增加当前行变量,修复警告数量问题
1 parent ea1ff53 commit 6e33ded

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

src/main/kotlin/com/puddingkc/vrchatstatustask/vrchatstatustask/VRChatStatusService.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import com.intellij.openapi.application.ReadAction;
99
import com.intellij.openapi.components.Service;
1010
import com.intellij.openapi.diagnostic.Logger;
11+
import com.intellij.openapi.editor.Caret;
1112
import com.intellij.openapi.editor.Document;
13+
import com.intellij.openapi.editor.Editor;
1214
import com.intellij.openapi.fileEditor.FileDocumentManager;
1315
import com.intellij.openapi.fileEditor.FileEditorManager;
1416
import com.intellij.openapi.project.Project;
@@ -87,12 +89,38 @@ private void updateVRChat() {
8789
int errors = countHighlights(HighlightSeverity.ERROR);
8890
int warnings = countHighlights(HighlightSeverity.WARNING);
8991

90-
String msg = getString(currentFileName, errors, warnings);
92+
String currentLine = getCurrentLineContent();
93+
int lineNumber = getCurrentLineNumber();
94+
95+
String msg = getString(currentFileName, errors, warnings, currentLine, lineNumber);
9196
sendOsc(msg);
9297
});
9398
}
9499

95-
private @NotNull String getString(String currentFileName, int errors, int warnings) {
100+
private String getCurrentLineContent() {
101+
Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
102+
if (editor == null) return "";
103+
104+
Document document = editor.getDocument();
105+
Caret caret = editor.getCaretModel().getPrimaryCaret();
106+
int lineNumber = caret.getLogicalPosition().line;
107+
108+
if (lineNumber >= document.getLineCount()) return "";
109+
110+
int lineStart = document.getLineStartOffset(lineNumber);
111+
int lineEnd = document.getLineEndOffset(lineNumber);
112+
return document.getText().substring(lineStart, lineEnd).trim();
113+
}
114+
115+
private int getCurrentLineNumber() {
116+
Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
117+
if (editor == null) return 0;
118+
119+
Caret caret = editor.getCaretModel().getPrimaryCaret();
120+
return caret.getLogicalPosition().line + 1;
121+
}
122+
123+
private @NotNull String getString(String currentFileName, int errors, int warnings, String currentLine, int lineNumber) {
96124
VRChatStatusSettings settings = VRChatStatusSettings.getInstance();
97125
String projectName = project.getName();
98126

@@ -103,6 +131,9 @@ private void updateVRChat() {
103131
if (projectName.length() > 19) {
104132
projectName = projectName.substring(0, 19) + "...";
105133
}
134+
if (currentLine.length() > 35) {
135+
currentLine = currentLine.substring(0, 35) + "...";
136+
}
106137
}
107138

108139
String template = settings.messageTemplate;
@@ -111,7 +142,9 @@ private void updateVRChat() {
111142
.replace("{file}", currentFileName)
112143
.replace("{errors}", String.valueOf(errors))
113144
.replace("{warnings}", String.valueOf(warnings))
114-
.replace("{uptime}", getDurationString());
145+
.replace("{uptime}", getDurationString())
146+
.replace("{line}", currentLine)
147+
.replace("{lineNum}", String.valueOf(lineNumber));
115148
}
116149

117150
private int countHighlights(HighlightSeverity severity) {
@@ -125,7 +158,7 @@ private int countHighlights(HighlightSeverity severity) {
125158
if (doc == null) continue;
126159

127160
DaemonCodeAnalyzerEx.processHighlights(doc, project, severity, 0, doc.getTextLength(), info -> {
128-
if (info != null) {
161+
if (info != null && info.getSeverity() == severity) {
129162
total[0]++;
130163
}
131164
return true;

src/main/kotlin/com/puddingkc/vrchatstatustask/vrchatstatustask/configs/VRChatStatusSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public final class VRChatStatusSettings implements PersistentStateComponent<VRCh
2323
2424
💻 工程 : {project}
2525
📝 编辑 : {file}
26+
🧐 当前 : {lineNum} {line}
2627
2728
{errors} Error | {warnings} Warn
2829
[ UPTime {uptime} ]

src/main/kotlin/com/puddingkc/vrchatstatustask/vrchatstatustask/gui/VRChatStatusConfigurable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public class VRChatStatusConfigurable implements Configurable {
7171
panel.add(scrollPane, gbc);
7272

7373
gbc.insets = JBUI.insets(0, 5, 5, 5);
74-
JLabel helpLabel = new JLabel("可用变量: {project}, {file}, {errors}, {warnings}, {uptime}");
74+
JLabel helpLabel = new JLabel("<html>可用变量: {project}, {file}, {errors}, {warnings}, {uptime}, {line}, {lineNum}");
7575
helpLabel.setFont(JBUI.Fonts.smallFont());
7676
helpLabel.setEnabled(false);
7777
gbc.gridx = 1; gbc.gridy = 6;

0 commit comments

Comments
 (0)