Skip to content

Commit dbcf1e1

Browse files
authored
Merge pull request #520 from sauyon/add-diagnosticfile
Add a new diagnostics file class and use it for errors
2 parents 46b5f11 + 80fe738 commit dbcf1e1

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

ql/src/semmle/go/Errors.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Error extends @error {
1919
int getIndex() { errors(this, _, _, _, _, _, _, _, result) }
2020

2121
/** Gets the file in which this error was reported, if it can be determined. */
22-
File getFile() { hasLocationInfo(result.getAbsolutePath(), _, _, _, _) }
22+
ExtractedOrExternalFile getFile() { hasLocationInfo(result.getAbsolutePath(), _, _, _, _) }
2323

2424
/**
2525
* Holds if this element is at the specified location.

ql/src/semmle/go/Files.qll

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,25 +177,12 @@ class Folder extends Container, @folder {
177177
override string getURL() { result = "folder://" + getAbsolutePath() }
178178
}
179179

180-
/** A file. */
181-
class File extends Container, @file, Documentable, ExprParent, GoModExprParent, DeclParent,
182-
ScopeNode {
183-
string path;
184-
185-
File() {
186-
files(this, path, _, _, _) and
187-
(
188-
// Exclude `.go` files that have not been extracted. Non-extracted files only exist in the `files`
189-
// table if we are reporting compilation errors relating to them in the `diagnostics` table.
190-
not path.matches("%.go")
191-
or
192-
exists(this.getAChild())
193-
)
194-
}
195-
180+
/** Any file, including files that have not been extracted but are referred to as locations for errors. */
181+
class ExtractedOrExternalFile extends Container, @file, Documentable, ExprParent, GoModExprParent,
182+
DeclParent, ScopeNode {
196183
override Location getLocation() { has_location(this, result) }
197184

198-
override string getAbsolutePath() { result = path }
185+
override string getAbsolutePath() { files(this, result, _, _, _) }
199186

200187
/** Gets the number of lines in this file. */
201188
int getNumberOfLines() { numlines(this, result, _, _) }
@@ -266,3 +253,14 @@ class File extends Container, @file, Documentable, ExprParent, GoModExprParent,
266253

267254
override string getAPrimaryQlClass() { result = "File" }
268255
}
256+
257+
/** A file that has been extracted. */
258+
class File extends ExtractedOrExternalFile {
259+
File() {
260+
// getAChild is specifically for the Go AST and so does not apply to non-go files
261+
// 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
262+
not this.getExtension() = "go"
263+
or
264+
exists(this.getAChild())
265+
}
266+
}

0 commit comments

Comments
 (0)