mirror of
https://github.com/github/codeql.git
synced 2026-01-29 22:32:58 +01:00
Merge pull request #520 from sauyon/add-diagnosticfile
Add a new diagnostics file class and use it for errors
This commit is contained in:
@@ -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(), _, _, _, _) }
|
||||
ExtractedOrExternalFile getFile() { hasLocationInfo(result.getAbsolutePath(), _, _, _, _) }
|
||||
|
||||
/**
|
||||
* Holds if this element is at the specified location.
|
||||
|
||||
@@ -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 are referred to as locations for errors. */
|
||||
class ExtractedOrExternalFile 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 ExtractedOrExternalFile {
|
||||
File() {
|
||||
// getAChild is specifically for the Go AST 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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user