Skip to content

Commit 6db17ed

Browse files
committed
Moved link validation to method for readability
1 parent 33d0ad6 commit 6db17ed

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

server/src/capabilities/capabilities.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -287,24 +287,7 @@ export class ScopeItemCapability {
287287
if (this.type === ScopeType.REFERENCE) {
288288
// Link to declaration if it exists.
289289
this.resolveLinks();
290-
if (!this.link) {
291-
// TODO:
292-
// References to variables should get a diagnostic if they aren't declared.
293-
// -- No option explicit: Hint with code action to declare.
294-
// GET before declared gets a warning.
295-
// -- Option explicit: Error with code action to declare.
296-
// -- Subsequent explicit declaration should raise duplicate declaration (current bahaviour).
297-
// -- All declarations with no GET references get a warning.
298-
// References to function or sub calls should raise an error if they aren't declared.
299-
// -- Must always throw even when option explicit not present.
300-
// -- Nothing required on first reference as declaration may come later.
301-
const severity = this.isOptionExplicitScope
302-
? DiagnosticSeverity.Error
303-
: DiagnosticSeverity.Hint;
304-
const _ = this.assignmentType & AssignmentType.CALL
305-
? this.pushDiagnostic(SubOrFunctionNotDefinedDiagnostic, this, this.name)
306-
: this.pushDiagnostic(VariableNotDefinedDiagnostic, this, this.name, severity);
307-
}
290+
this.validateLink();
308291
} else {
309292
// Diagnostic checks on declarations.
310293
const ancestors = this.getParentChain();
@@ -546,6 +529,27 @@ export class ScopeItemCapability {
546529
this.linkThisToItem(foundDeclarations[0]);
547530
}
548531

532+
private validateLink() {
533+
if (!this.link) {
534+
// TODO:
535+
// References to variables should get a diagnostic if they aren't declared.
536+
// -- No option explicit: Hint with code action to declare.
537+
// GET before declared gets a warning.
538+
// -- Option explicit: Error with code action to declare.
539+
// -- Subsequent explicit declaration should raise duplicate declaration (current bahaviour).
540+
// -- All declarations with no GET references get a warning.
541+
// References to function or sub calls should raise an error if they aren't declared.
542+
// -- Must always throw even when option explicit not present.
543+
// -- Nothing required on first reference as declaration may come later.
544+
const severity = this.isOptionExplicitScope
545+
? DiagnosticSeverity.Error
546+
: DiagnosticSeverity.Hint;
547+
const _ = this.assignmentType & AssignmentType.CALL
548+
? this.pushDiagnostic(SubOrFunctionNotDefinedDiagnostic, this, this.name)
549+
: this.pushDiagnostic(VariableNotDefinedDiagnostic, this, this.name, severity);
550+
}
551+
}
552+
549553
private linkThisToItem(linkItem?: ScopeItemCapability): void {
550554
if (!linkItem) {
551555
return;

0 commit comments

Comments
 (0)