Skip to content

Commit db35abd

Browse files
authored
Merge pull request #32 from github/getFileBySourceArchiveName
Replace getEncodedFile with getFileBySourceArchiveName predicate
2 parents 5f1e373 + 5771e47 commit db35abd

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

ql/src/printAst.ql

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,23 @@ external string selectedSourceFile();
2020
* output of `.getFile()` on locatable entities.
2121
*/
2222
cached
23-
File getEncodedFile(string name) { result.getAbsolutePath().replaceAll(":", "_") = name }
23+
File getFileBySourceArchiveName(string name) {
24+
// The name provided for a file in the source archive by the VS Code extension
25+
// has some differences from the absolute path in the database:
26+
// 1. colons are replaced by underscores
27+
// 2. there's a leading slash, even for Windows paths: "C:/foo/bar" ->
28+
// "/C_/foo/bar"
29+
// 3. double slashes in UNC prefixes are replaced with a single slash
30+
// We can handle 2 and 3 together by unconditionally adding a leading slash
31+
// before replacing double slashes.
32+
name = ("/" + result.getAbsolutePath().replaceAll(":", "_")).replaceAll("//", "/")
33+
}
2434

2535
/**
2636
* Overrides the configuration to print only nodes in the selected source file.
2737
*/
2838
class Cfg extends PrintAstConfiguration {
2939
override predicate shouldPrintNode(AstNode n) {
30-
n.getLocation().getFile() = getEncodedFile(selectedSourceFile())
40+
n.getLocation().getFile() = getFileBySourceArchiveName(selectedSourceFile())
3141
}
3242
}

0 commit comments

Comments
 (0)