@@ -49,6 +49,7 @@ export async function queryFileStaticAnalysis(
4949 const [ fileText ] = sanitizeFileWithQueryParameters (
5050 document . getText ( ) , options . queryParameterInfo , logger ,
5151 )
52+ logger . info ( `fileText.length: ${ fileText . length } ` )
5253
5354 try {
5455 const extensionCheck = await pgClient . query ( `
@@ -101,17 +102,18 @@ export async function queryFileStaticAnalysis(
101102 await pgClient . query ( "BEGIN" )
102103 if ( options . isComplete ) {
103104 const message = ( error as Error ) . message
104- logger . error ( `StaticAnalysisError: ${ message } (${ document . uri } )` )
105+ logger . error ( `StaticAnalysisError (1) : ${ message } (${ document . uri } )` )
105106 }
106107 }
107108
108109 try {
109- for ( const { functionName, location, relname } of triggerInfos ) {
110+ for ( const triggerInfo of triggerInfos ) {
111+ const { functionName, stmtLocation, relname } = triggerInfo
110112 logger . warn ( `
111113 trigger:::
112114 relname: ${ relname }
113115 functionName: ${ functionName }
114- location : ${ location } ` )
116+ stmtLocation : ${ stmtLocation } ` )
115117
116118 const result = await pgClient . query (
117119 `
@@ -138,37 +140,54 @@ export async function queryFileStaticAnalysis(
138140 continue
139141 }
140142
141- extractError ( rows , location )
143+ extractError ( rows , stmtLocation )
142144 }
143145 }
144146 catch ( error : unknown ) {
145147 await pgClient . query ( "ROLLBACK to validated_syntax" )
146148 await pgClient . query ( "BEGIN" )
147149 if ( options . isComplete ) {
148150 const message = ( error as Error ) . message
149- logger . error ( `StaticAnalysisError: ${ message } (${ document . uri } )` )
151+ logger . error ( `StaticAnalysisError (2) : ${ message } (${ document . uri } )` )
150152 }
151153 }
152154
153155 return errors
154156
155- function extractError ( rows : StaticAnalysisErrorRow [ ] , location : number | undefined ) {
157+ function extractError (
158+ rows : StaticAnalysisErrorRow [ ] ,
159+ location : number | undefined ,
160+ ) {
156161 rows . forEach (
157- ( row ) => {
158- const range = ( ( ) => {
159- return ( location === undefined )
160- ? getTextAllRange ( document )
161- : getLineRangeFromBuffer (
162- fileText ,
163- location ,
164- row . lineno ? row . lineno - 1 : 0 ,
165- ) ?? getTextAllRange ( document )
166- } ) ( )
167-
168- errors . push ( {
169- level : row . level , range, message : row . message ,
170- } )
171- } ,
172- )
162+ ( row ) => {
163+ let range : Range
164+ // FIXME getLineRangeFromBuffer
165+ // range may be larger than byte count for some cases at the end of the doc and throw err reading length of undefined.
166+ // both fileText.length and location from parsed stmt are correct
167+ try {
168+ range = ( ( ) => {
169+ return ( location === undefined )
170+ ? getTextAllRange ( document )
171+ : getLineRangeFromBuffer (
172+ fileText ,
173+ location ,
174+ row . lineno ? row . lineno - 1 : 0 ,
175+ ) ?? getTextAllRange ( document )
176+ } ) ( )
177+ } catch ( error : unknown ) {
178+ logger . error ( `Could not extract error from row.
179+ message: ${ JSON . stringify ( row . message ) }
180+ lineno: ${ row . lineno }
181+ location: ${ location } ` )
182+ range = getTextAllRange ( document )
183+ }
184+ errors . push ( {
185+ level : row . level , range, message : row . message ,
186+ } )
187+
188+ }
189+ ,
190+ )
191+
173192 }
174193}
0 commit comments