@@ -70,13 +70,27 @@ public async Task<bool> HasSuggestedActionsAsync(
7070 return await Task . Run ( ( ) =>
7171 {
7272 DiagnosticLogger . Log ( "=== HasSuggestedActionsAsync called ===" ) ;
73+
74+ // VS seems to be passing the line span instead of cursor span
75+ // Use the caret position if available, otherwise fall back to range
7376 var triggerPoint = range . Start ;
77+ if ( textView != null && textView . Caret != null )
78+ {
79+ triggerPoint = textView . Caret . Position . BufferPosition ;
80+ DiagnosticLogger . Log ( $ "Using caret position: { triggerPoint . Position } ") ;
81+ }
82+ else
83+ {
84+ DiagnosticLogger . Log ( $ "Using range start: { triggerPoint . Position } ") ;
85+ }
86+
7487 var line = triggerPoint . GetContainingLine ( ) ;
7588 var lineText = line . GetText ( ) ;
7689 var lineStart = line . Start . Position ;
7790
7891 DiagnosticLogger . Log ( $ "Line text: '{ lineText } '") ;
7992 DiagnosticLogger . Log ( $ "Trigger position: { triggerPoint . Position } ") ;
93+ DiagnosticLogger . Log ( $ "Line start position: { lineStart } ") ;
8094
8195 // Check if we're in a Serilog call
8296 var serilogMatch = SerilogCallDetector . FindSerilogCall ( lineText ) ;
@@ -102,11 +116,12 @@ public async Task<bool> HasSuggestedActionsAsync(
102116 string template ;
103117 int templateStartPosition ;
104118 int templateEndPosition ;
105-
119+
106120 if ( serilogCallLine == line )
107121 {
108122 // Same-line scenario: template starts on the same line as the Serilog call
109123 var templateMatch = FindTemplateString ( lineText , serilogMatch . Index + serilogMatch . Length ) ;
124+ DiagnosticLogger . Log ( $ "FindTemplateString result: { ( templateMatch . HasValue ? $ "Found at [{ templateMatch . Value . Item1 } , { templateMatch . Value . Item2 } ]" : "Not found" ) } ") ;
110125 if ( ! templateMatch . HasValue )
111126 {
112127 // No complete template found on this line - check if it's a multi-line template starting here
@@ -129,11 +144,18 @@ public async Task<bool> HasSuggestedActionsAsync(
129144 template = lineText . Substring ( templateStart , templateEnd - templateStart ) ;
130145 templateStartPosition = lineStart + templateStart ;
131146 templateEndPosition = lineStart + templateEnd ;
132-
147+
148+ DiagnosticLogger . Log ( $ "Template found: '{ template } '") ;
149+ DiagnosticLogger . Log ( $ "Template position: [{ templateStartPosition } , { templateEndPosition } ]") ;
150+
133151 // Check if cursor is within template
134152 var positionInLine = triggerPoint . Position - lineStart ;
153+ DiagnosticLogger . Log ( $ "Position in line: { positionInLine } , template range in line: [{ templateStart } , { templateEnd } ]") ;
135154 if ( positionInLine < templateStart || positionInLine > templateEnd )
155+ {
156+ DiagnosticLogger . Log ( "Cursor is outside template bounds" ) ;
136157 return false ;
158+ }
137159 }
138160 }
139161 else
@@ -154,13 +176,29 @@ public async Task<bool> HasSuggestedActionsAsync(
154176
155177 // Parse template to find properties
156178 var properties = _parser . Parse ( template ) . ToList ( ) ;
157-
179+ DiagnosticLogger . Log ( $ "Found { properties . Count } properties in template") ;
180+
158181 // Find which property the cursor is on
159182 var cursorPosInTemplate = triggerPoint . Position - templateStartPosition ;
160- var property = properties . FirstOrDefault ( p =>
161- cursorPosInTemplate >= p . BraceStartIndex &&
183+ DiagnosticLogger . Log ( $ "Cursor position in template: { cursorPosInTemplate } ") ;
184+
185+ var property = properties . FirstOrDefault ( p =>
186+ cursorPosInTemplate >= p . BraceStartIndex &&
162187 cursorPosInTemplate <= p . BraceEndIndex ) ;
163188
189+ if ( property != null )
190+ {
191+ DiagnosticLogger . Log ( $ "Found property: { property . Name } at [{ property . BraceStartIndex } , { property . BraceEndIndex } ]") ;
192+ }
193+ else
194+ {
195+ DiagnosticLogger . Log ( "No property found at cursor position" ) ;
196+ foreach ( var p in properties )
197+ {
198+ DiagnosticLogger . Log ( $ " Property '{ p . Name } ' at [{ p . BraceStartIndex } , { p . BraceEndIndex } ]") ;
199+ }
200+ }
201+
164202 return property != null ;
165203 } , cancellationToken ) ;
166204 }
@@ -177,7 +215,14 @@ public IEnumerable<SuggestedActionSet> GetSuggestedActions(
177215 SnapshotSpan range ,
178216 CancellationToken cancellationToken )
179217 {
218+ // VS seems to be passing the line span instead of cursor span
219+ // Use the caret position if available, otherwise fall back to range
180220 var triggerPoint = range . Start ;
221+ if ( textView != null && textView . Caret != null )
222+ {
223+ triggerPoint = textView . Caret . Position . BufferPosition ;
224+ }
225+
181226 var line = triggerPoint . GetContainingLine ( ) ;
182227 var lineText = line . GetText ( ) ;
183228 var lineStart = line . Start . Position ;
0 commit comments