88import com .intellij .openapi .application .ReadAction ;
99import com .intellij .openapi .components .Service ;
1010import com .intellij .openapi .diagnostic .Logger ;
11+ import com .intellij .openapi .editor .Caret ;
1112import com .intellij .openapi .editor .Document ;
13+ import com .intellij .openapi .editor .Editor ;
1214import com .intellij .openapi .fileEditor .FileDocumentManager ;
1315import com .intellij .openapi .fileEditor .FileEditorManager ;
1416import 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 ;
0 commit comments