@@ -17,7 +17,7 @@ import { FoldingRange, FoldingRangeKind } from '../capabilities/folding';
1717import { SemanticToken , SemanticTokenModifiers , SemanticTokenTypes } from '../capabilities/semanticTokens' ;
1818import { BaseRuleSyntaxElement , BaseIdentifyableSyntaxElement , BaseSyntaxElement , Context , HasSemanticTokenCapability } from '../project/elements/base' ;
1919import { AmbiguousNameDiagnostic , BaseDiagnostic , DuplicateDeclarationDiagnostic , ShadowDeclarationDiagnostic , SubOrFunctionNotDefinedDiagnostic , UnusedDiagnostic , VariableNotDefinedDiagnostic } from './diagnostics' ;
20- import { isPositionInsideRange , isRangeInsideRange } from '../utils/helpers' ;
20+ import { isPositionInsideRange , isRangeInsideRange , rangeEquals } from '../utils/helpers' ;
2121
2222
2323abstract class BaseCapability {
@@ -795,28 +795,23 @@ export class ScopeItemCapability {
795795 * Recursively removes all scopes with the passed in uri and
796796 * within the range bounds, including where it is linked.
797797 */
798- invalidate ( uri : string , range : Range ) : void {
799- const isInvalidScope = ( scope : ScopeItemCapability ) =>
800- scope . locationUri === uri
801- && scope . element ?. context . range
802- && isRangeInsideRange ( scope . element . context . range , range ) ;
803-
798+ invalidate ( uri : string , range ?: Range ) : void {
804799 const cleanScopes = ( scopes ?: ScopeItemCapability [ ] ) => {
805800 if ( scopes === undefined ) {
806801 return undefined ;
807802 }
808803
809804 const result : ScopeItemCapability [ ] = [ ] ;
810805 scopes . forEach ( scope => {
811- if ( isInvalidScope ( scope ) ) {
806+ if ( scope . isLocatedAt ( uri , range ) ) {
812807 Services . logger . debug ( `Invalidating ${ scope . name } ` ) ;
813808
814809 // Clean the backlinks on the linked item if we have one.
815810 if ( scope . link ) scope . link . backlinks = cleanScopes (
816811 scope . link . backlinks ) ;
817812
818813 // Clean the invaludated scope.
819- scope . invalidate ( uri , range ) ;
814+ scope . invalidate ( uri , scope . range ) ;
820815
821816 return ;
822817 }
@@ -857,8 +852,22 @@ export class ScopeItemCapability {
857852
858853 // Do a basic clean on backlinks that doesn't trigger recursion.
859854 if ( this . backlinks ) {
860- this . backlinks = this . backlinks . filter ( scope => ! isInvalidScope ( scope ) ) ;
855+ this . backlinks = this . backlinks
856+ . filter ( scope => ! scope . isLocatedAt ( uri , range ) ) ;
857+ }
858+ }
859+
860+ /** Returns true if the uri matches and, if passed, range is fully inside range. */
861+ isLocatedAt ( uri : string , range ?: Range ) : boolean {
862+ if ( uri !== this . locationUri ) {
863+ return false ;
861864 }
865+
866+ if ( ! range ) {
867+ return true ;
868+ }
869+
870+ return isRangeInsideRange ( this . range , range ) ;
862871 }
863872
864873 /** Returns true for public and false for private */
0 commit comments