@@ -909,30 +909,16 @@ export async function getClassMemberContext(
909
909
context : "system"
910
910
} ;
911
911
}
912
- else if ( dot > 0 && parsed [ line ] [ dot - 1 ] . l == ld . cos_langindex && parsed [ line ] [ dot - 1 ] . s == ld . cos_param_attrindex ) {
913
- // The token before the dot is a parameter
914
-
915
- const paramcon = await determineParameterClass ( doc , parsed , line , dot - 1 , server ) ;
916
- if ( paramcon !== undefined ) {
917
- result = paramcon ;
918
- }
919
- }
920
912
else if ( dot > 0 && parsed [ line ] [ dot - 1 ] . l == ld . cos_langindex && (
913
+ parsed [ line ] [ dot - 1 ] . s == ld . cos_param_attrindex ||
921
914
parsed [ line ] [ dot - 1 ] . s == ld . cos_localdec_attrindex ||
922
915
parsed [ line ] [ dot - 1 ] . s == ld . cos_localvar_attrindex ||
923
- parsed [ line ] [ dot - 1 ] . s == ld . cos_otw_attrindex
916
+ parsed [ line ] [ dot - 1 ] . s == ld . cos_otw_attrindex ||
917
+ parsed [ line ] [ dot - 1 ] . s == ld . cos_localundec_attrindex
924
918
) ) {
925
- // The token before the dot is a declared local variable, public variable or warning variable
926
-
927
- // First check if it's #Dim'd
928
- let varContext = await determineDeclaredLocalVarClass ( doc , parsed , line , dot - 1 , server , allfiles , inheritedpackages ) ;
929
- if ( varContext === undefined ) {
930
- // If it's not, attempt to determine the class it was set to
931
- varContext = await determineUndeclaredLocalVarClass ( doc , parsed , line , dot - 1 , server , allfiles , inheritedpackages ) ;
932
- }
933
- if ( varContext !== undefined ) {
934
- result = varContext ;
935
- }
919
+ // The token before the dot is a parameter, local variable, public variable or warning variable
920
+ const varClass = await determineVariableClass ( doc , parsed , line , dot - 1 , server , allfiles , inheritedpackages ) ;
921
+ if ( varClass ) result = { baseclass : varClass , context : "instance" } ;
936
922
}
937
923
else if ( dot > 0 && parsed [ line ] [ dot - 1 ] . l == ld . cos_langindex && parsed [ line ] [ dot - 1 ] . s == ld . cos_sysv_attrindex ) {
938
924
// The token before the dot is a system variable
@@ -999,14 +985,6 @@ export async function getClassMemberContext(
999
985
}
1000
986
}
1001
987
}
1002
- else if ( dot > 0 && parsed [ line ] [ dot - 1 ] . l == ld . cos_langindex && parsed [ line ] [ dot - 1 ] . s == ld . cos_localundec_attrindex ) {
1003
- // The token before the dot is an undeclared local variable
1004
-
1005
- const localundeccon = await determineUndeclaredLocalVarClass ( doc , parsed , line , dot - 1 , server , allfiles , inheritedpackages ) ;
1006
- if ( localundeccon !== undefined ) {
1007
- result = localundeccon ;
1008
- }
1009
- }
1010
988
else if ( dot > 0 && parsed [ line ] [ dot - 1 ] . l == ld . cos_langindex && parsed [ line ] [ dot - 1 ] . s == ld . cos_jsonb_attrindex ) {
1011
989
// The token before the dot is a JSON bracket
1012
990
@@ -1653,7 +1631,8 @@ async function parseSetCommand(
1653
1631
! inPostconditional && parsed [ ln ] [ tkn ] . l == ld . cos_langindex &&
1654
1632
(
1655
1633
parsed [ ln ] [ tkn ] . s == ld . cos_otw_attrindex || parsed [ ln ] [ tkn ] . s == ld . cos_localundec_attrindex ||
1656
- parsed [ ln ] [ tkn ] . s == ld . cos_localdec_attrindex || parsed [ ln ] [ tkn ] . s == ld . cos_localvar_attrindex
1634
+ parsed [ ln ] [ tkn ] . s == ld . cos_localdec_attrindex || parsed [ ln ] [ tkn ] . s == ld . cos_localvar_attrindex ||
1635
+ parsed [ ln ] [ tkn ] . s == ld . cos_param_attrindex
1657
1636
) &&
1658
1637
doc . getText ( Range . create ( ln , parsed [ ln ] [ tkn ] . p , ln , parsed [ ln ] [ tkn ] . p + parsed [ ln ] [ tkn ] . c ) ) == selector &&
1659
1638
// Variable isn't followed by a dot or a subscript
@@ -1992,7 +1971,8 @@ async function determineUndeclaredLocalVarClass(
1992
1971
if ( next && parsed [ next [ 0 ] ] [ next [ 1 ] ] . l == ld . cos_langindex &&
1993
1972
(
1994
1973
parsed [ next [ 0 ] ] [ next [ 1 ] ] . s == ld . cos_otw_attrindex || parsed [ next [ 0 ] ] [ next [ 1 ] ] . s == ld . cos_localundec_attrindex ||
1995
- parsed [ next [ 0 ] ] [ next [ 1 ] ] . s == ld . cos_localdec_attrindex || parsed [ next [ 0 ] ] [ next [ 1 ] ] . s == ld . cos_localvar_attrindex
1974
+ parsed [ next [ 0 ] ] [ next [ 1 ] ] . s == ld . cos_localdec_attrindex || parsed [ next [ 0 ] ] [ next [ 1 ] ] . s == ld . cos_localvar_attrindex ||
1975
+ parsed [ next [ 0 ] ] [ next [ 1 ] ] . s == ld . cos_param_attrindex
1996
1976
) &&
1997
1977
doc . getText ( Range . create (
1998
1978
next [ 0 ] , parsed [ next [ 0 ] ] [ next [ 1 ] ] . p ,
@@ -2650,49 +2630,28 @@ export async function getTextForUri(uri: string, server: ServerSpec): Promise<st
2650
2630
* @param line The line that the variable is in.
2651
2631
* @param tkn The token of the variable in the line.
2652
2632
* @param server The server that doc is associated with.
2633
+ *
2634
+ * The following optional parameters are only provided when called via `onDiagnostics()`:
2635
+ * @param allfiles An array of all files in a database.
2636
+ * @param inheritedpackages An array containing packages imported by superclasses of this class.
2653
2637
*/
2654
2638
export async function determineVariableClass (
2655
- doc : TextDocument , parsed : compressedline [ ] ,
2656
- line : number , tkn : number , server : ServerSpec
2639
+ doc : TextDocument , parsed : compressedline [ ] , line : number , tkn : number ,
2640
+ server : ServerSpec , allfiles ?: StudioOpenDialogFile [ ] , inheritedpackages ?: string [ ]
2657
2641
) : Promise < string > {
2658
- let varClass = "" ;
2659
2642
if ( parsed [ line ] [ tkn ] . s == ld . cos_param_attrindex ) {
2660
- // This token is a parameter
2661
-
2662
- // Determine the class of the parameter
2663
- const paramcon = await determineParameterClass ( doc , parsed , line , tkn , server ) ;
2664
- if ( paramcon !== undefined ) {
2665
- // The parameter has a class
2666
- varClass = paramcon . baseclass ;
2667
- }
2668
- } else if (
2669
- parsed [ line ] [ tkn ] . s == ld . cos_localdec_attrindex ||
2670
- parsed [ line ] [ tkn ] . s == ld . cos_localvar_attrindex ||
2671
- parsed [ line ] [ tkn ] . s == ld . cos_otw_attrindex
2672
- ) {
2673
- // This token is a declared local variable, public variable, or warning variable
2674
-
2675
- // First check if it's #Dim'd
2676
- let varContext = await determineDeclaredLocalVarClass ( doc , parsed , line , tkn , server ) ;
2677
- if ( varContext === undefined ) {
2678
- // If it's not, attempt to determine the class it was set to
2679
- varContext = await determineUndeclaredLocalVarClass ( doc , parsed , line , tkn , server ) ;
2680
- }
2681
- if ( varContext !== undefined ) {
2682
- // The declared local variable has a class
2683
- varClass = varContext . baseclass ;
2684
- }
2685
- } else {
2686
- // This token is an undeclared local variable
2687
-
2688
- // Determine the class of the undeclared local variable
2689
- const localundeccon = await determineUndeclaredLocalVarClass ( doc , parsed , line , tkn , server ) ;
2690
- if ( localundeccon !== undefined ) {
2691
- // The undeclared local variable has a class
2692
- varClass = localundeccon . baseclass ;
2693
- }
2694
- }
2695
- return varClass ;
2643
+ // Check if the parameter has a declared type in the formal spec
2644
+ const paramcon = await determineParameterClass ( doc , parsed , line , tkn , server , allfiles , inheritedpackages ) ;
2645
+ if ( paramcon ?. baseclass ) return paramcon . baseclass ;
2646
+ }
2647
+ if ( parsed [ line ] [ tkn ] . s != ld . cos_localundec_attrindex && parsed [ line ] [ tkn ] . s != ld . cos_param_attrindex ) {
2648
+ // Check if the variable is #Dim'd or a known percent variable
2649
+ const varContext = await determineDeclaredLocalVarClass ( doc , parsed , line , tkn , server , allfiles , inheritedpackages ) ;
2650
+ if ( varContext ?. baseclass ) return varContext . baseclass ;
2651
+ }
2652
+ // Fall back to inferring the type from a Set or pass by reference
2653
+ const localundeccon = await determineUndeclaredLocalVarClass ( doc , parsed , line , tkn , server , allfiles , inheritedpackages ) ;
2654
+ return localundeccon ?. baseclass ?? "" ;
2696
2655
}
2697
2656
2698
2657
/** Returns `true` if `keyword` is a valid class member type. */
0 commit comments