package som.langserv.lint;

import java.util.Collection;

import som.langserv.structure.DocumentStructures;


public class LintUseNeedsDefine implements WorkspaceLinter {

  @Override
  public void lint(final Collection<DocumentStructures> structures) {
    // iterate over all references, and make sure there's a matching define
    boolean defined = false;
    if (!defined) {
    }
  }
}

@@ -49,16 +49,147 @@
 lection;
+%0Aimport java.util.HashSet;%0Aimport java.util.Set;%0A%0Aimport org.eclipse.lsp4j.Diagnostic;%0Aimport org.eclipse.lsp4j.DiagnosticSeverity;
 %0A%0Aimport
@@ -232,16 +232,65 @@
 ctures;%0A
+import som.langserv.structure.LanguageElementId;%0A
 %0A%0Apublic
@@ -438,125 +438,1049 @@
  // 
-iterate over all references, and make sure there's a matching define%0A    boolean defined = false;%0A    if (!defined) %7B
+collect everything that's defined%0A    Set%3CLanguageElementId%3E allDefinedElements = new HashSet%3C%3E();%0A    for (var s : structures) %7B%0A      var defs = s.getAllDefinitions();%0A      if (defs == null) %7B%0A        continue;%0A      %7D%0A      allDefinedElements.addAll(defs.keySet());%0A    %7D%0A%0A    // now check everything that's referenced,%0A    // and report anything for which we do not have a definition%0A    for (var s : structures) %7B%0A      var allRefs = s.getAllReferences();%0A      if (allRefs == null) %7B%0A        continue;%0A      %7D%0A%0A      for (var ref : allRefs.entrySet()) %7B%0A        LanguageElementId id = ref.getKey();%0A        if (!allDefinedElements.contains(id)) %7B%0A          for (var r : ref.getValue()) %7B%0A            Diagnostic diag = new Diagnostic();%0A            diag.setRange(r.getRange());%0A            diag.setMessage(%22%60%22 + id.getName()%0A                + %22%60 does not seem to be defined, which might cause run-time errors.%22);%0A            diag.setSeverity(DiagnosticSeverity.Warning);%0A            s.addDiagnostic(diag);%0A          %7D%0A        %7D%0A      %7D
 %0A   

Implement language-agnostic use-needs-define linter