@@ -21,8 +21,8 @@ function addMethodDescriptionTemplate() {
2121 let line = vscode . window . activeTextEditor . document . lineAt ( i ) ;
2222 let trimedLine = line . text . toLowerCase ( ) . replace ( / \s / g, '' ) ;
2323 if (
24- trimedLine . startsWith ( 'method' ) ||
25- trimedLine . startsWith ( 'classmethod' )
24+ line . text . toLowerCase ( ) . startsWith ( 'method' ) ||
25+ line . text . toLowerCase ( ) . startsWith ( 'classmethod' )
2626 ) {
2727 let offset = 1 ;
2828 let lineString = line . text ;
@@ -78,7 +78,6 @@ function addMethodDescriptionTemplate() {
7878
7979 // add paremeter description
8080 template += globalFunctions . makeParamterTemplate ( startLine ) ;
81-
8281 //if has return value
8382 if ( startLine . split ( ')' ) [ 1 ] . toLowerCase ( ) . includes ( 'as' ) ) {
8483 // Add return description
@@ -112,7 +111,6 @@ function addMethodDescriptionTemplate() {
112111
113112 //get classname
114113 let className = globalFunctions . getClassName ( ) ;
115-
116114 //get method name
117115 let methodName = startLine . split ( ' ' ) [ 1 ] ;
118116 if ( methodName . includes ( '(' ) ) methodName = methodName . split ( '(' ) [ 0 ] ;
@@ -224,16 +222,106 @@ function addInlineComments() {
224222function openDocumentation ( ) {
225223 if ( ! globalFunctions . preConditions ( ) ) return ;
226224
227- let selection = vscode . window . activeTextEditor . selection ;
225+ const selection = vscode . window . activeTextEditor . selection ;
228226
229227 let searchString =
230228 vscode . window . activeTextEditor . document . getText ( selection ) ;
231229 if ( selection . isEmpty ) {
232- searchString = vscode . window . activeTextEditor . document . getText (
230+ let wordRange =
231+ vscode . window . activeTextEditor . document . getWordRangeAtPosition (
232+ selection . start
233+ ) ;
234+
235+ searchString =
236+ vscode . window . activeTextEditor . document . getText ( wordRange ) ;
237+
238+ // get character before
239+ if ( wordRange . start . character != 0 ) {
240+ let characterBefore =
241+ vscode . window . activeTextEditor . document . getText (
242+ new vscode . Range (
243+ new vscode . Position (
244+ wordRange . start . line ,
245+ wordRange . start . character - 1
246+ ) ,
247+ wordRange . start
248+ )
249+ ) ;
250+ while ( characterBefore == '.' ) {
251+ wordRange =
252+ vscode . window . activeTextEditor . document . getWordRangeAtPosition (
253+ new vscode . Position (
254+ wordRange . start . line ,
255+ wordRange . start . character - 1
256+ )
257+ ) ;
258+ searchString =
259+ vscode . window . activeTextEditor . document . getText ( wordRange ) +
260+ '.' +
261+ searchString ;
262+ if ( wordRange . start . character == 0 ) break ;
263+ characterBefore =
264+ vscode . window . activeTextEditor . document . getText (
265+ new vscode . Range (
266+ new vscode . Position (
267+ wordRange . start . line ,
268+ wordRange . start . character - 1
269+ ) ,
270+ wordRange . start
271+ )
272+ ) ;
273+ }
274+ }
275+ wordRange =
233276 vscode . window . activeTextEditor . document . getWordRangeAtPosition (
234277 selection . start
235- )
236- ) ;
278+ ) ;
279+ if (
280+ wordRange . end . character !=
281+ vscode . window . activeTextEditor . document . lineAt ( wordRange . end . line )
282+ . range . end . character
283+ ) {
284+ let characterAfter =
285+ vscode . window . activeTextEditor . document . getText (
286+ new vscode . Range (
287+ wordRange . end ,
288+ new vscode . Position (
289+ wordRange . end . line ,
290+ wordRange . end . character + 1
291+ )
292+ )
293+ ) ;
294+ while ( characterAfter == '.' ) {
295+ wordRange =
296+ vscode . window . activeTextEditor . document . getWordRangeAtPosition (
297+ new vscode . Position (
298+ wordRange . end . line ,
299+ wordRange . end . character + 1
300+ )
301+ ) ;
302+ searchString =
303+ searchString +
304+ '.' +
305+ vscode . window . activeTextEditor . document . getText ( wordRange ) ;
306+ if (
307+ wordRange . end . character ==
308+ vscode . window . activeTextEditor . document . lineAt (
309+ wordRange . end . line
310+ ) . range . end . character
311+ )
312+ break ;
313+ characterAfter =
314+ vscode . window . activeTextEditor . document . getText (
315+ new vscode . Range (
316+ wordRange . end ,
317+ new vscode . Position (
318+ wordRange . end . line ,
319+ wordRange . end . character + 1
320+ )
321+ )
322+ ) ;
323+ }
324+ }
237325 }
238326
239327 if (
@@ -359,7 +447,7 @@ async function getHTMLFromURL(url) {
359447 const response = await axios . get ( url ) ;
360448 return response . data ;
361449 } catch ( error ) {
362- console . error ( 'Error fetching HTML:' , error . message ) ;
450+ vscode . window . showErrorMessage ( 'Error fetching HTML:' + error . message ) ;
363451 return null ;
364452 }
365453}
0 commit comments