Skip to content

Commit 6fdc932

Browse files
committed
Bug fix #91
1 parent b0d2b71 commit 6fdc932

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

server/src/capabilities/capabilities.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { FoldingRange, FoldingRangeKind } from '../capabilities/folding';
1717
import { SemanticToken, SemanticTokenModifiers, SemanticTokenTypes } from '../capabilities/semanticTokens';
1818
import { BaseRuleSyntaxElement, BaseIdentifyableSyntaxElement, BaseSyntaxElement, Context, HasSemanticTokenCapability } from '../project/elements/base';
1919
import { 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

2323
abstract 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 */

server/src/project/workspace.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ export class Workspace implements IWorkspace {
153153

154154
if (previousDocument) {
155155
Services.projectScope.invalidate(
156-
previousDocument.uri,
157-
previousDocument.range
156+
previousDocument.uri
158157
);
159158
}
160159

server/src/utils/helpers.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ export function isPositionInsideRange(position: Position, range: Range): boolean
9494
* @param inner The range to test as enveloped.
9595
* @param outer The range to test as enveloping.
9696
*/
97-
export function isRangeInsideRange(inner: Range, outer: Range): boolean {
97+
export function isRangeInsideRange(inner?: Range, outer?: Range): boolean {
98+
// Test we have ranges.
99+
if (!inner || !outer) {
100+
return false;
101+
}
102+
98103
// Test characters on single-line ranges.
99104
const isSingleLine = inner.start.line === inner.end.line
100105
&& outer.start.line === outer.end.line
@@ -107,4 +112,12 @@ export function isRangeInsideRange(inner: Range, outer: Range): boolean {
107112
// Test lines on multi-line ranges.
108113
return inner.start.line >= outer.start.line
109114
&& inner.end.line <= outer.end.line;
115+
}
116+
117+
export function rangeEquals(r1?: Range, r2?: Range): boolean {
118+
return !!r1 && !!r2
119+
&& r1.start.line === r2.start.line
120+
&& r1.start.character === r2.start.character
121+
&& r1.end.line === r2.end.line
122+
&& r1.end.character === r2.end.character;
110123
}

0 commit comments

Comments
 (0)