Add a new diagnostics file class and use it for errors

This commit is contained in:
Sauyon Lee
2021-04-02 01:52:50 -07:00
committed by Chris Smowton
parent 46b5f11457
commit 4462948cfc
2 changed files with 16 additions and 18 deletions

View File

@@ -19,7 +19,7 @@ class Error extends @error {
int getIndex() { errors(this, _, _, _, _, _, _, _, result) }
/** Gets the file in which this error was reported, if it can be determined. */
File getFile() { hasLocationInfo(result.getAbsolutePath(), _, _, _, _) }
DiagnosticFile getFile() { hasLocationInfo(result.getAbsolutePath(), _, _, _, _) }
/**
* Holds if this element is at the specified location.

View File

@@ -177,25 +177,12 @@ class Folder extends Container, @folder {
override string getURL() { result = "folder://" + getAbsolutePath() }
}
/** A file. */
class File extends Container, @file, Documentable, ExprParent, GoModExprParent, DeclParent,
ScopeNode {
string path;
File() {
files(this, path, _, _, _) and
(
// Exclude `.go` files that have not been extracted. Non-extracted files only exist in the `files`
// table if we are reporting compilation errors relating to them in the `diagnostics` table.
not path.matches("%.go")
or
exists(this.getAChild())
)
}
/** Any file, including files that have not been extracted but must exist as locations for errors. */
class DiagnosticFile extends Container, @file, Documentable, ExprParent, GoModExprParent,
DeclParent, ScopeNode {
override Location getLocation() { has_location(this, result) }
override string getAbsolutePath() { result = path }
override string getAbsolutePath() { files(this, result, _, _, _) }
/** Gets the number of lines in this file. */
int getNumberOfLines() { numlines(this, result, _, _) }
@@ -266,3 +253,14 @@ class File extends Container, @file, Documentable, ExprParent, GoModExprParent,
override string getAPrimaryQlClass() { result = "File" }
}
/** A file that has been extracted. */
class File extends DiagnosticFile {
File() {
// getAChild is specifically for the Go SAT and so does not apply to non-go files
// we care about all non-go extracted files, as only go files can have `@file` entries due to requiring a file entry for diagnostic errors
not this.getExtension() = "go"
or
exists(this.getAChild())
}
}