11import { createRemoteFileRef } from "../common/location-link-utils" ;
2- import {
3- isUrlValueResolvable ,
4- UrlValue ,
5- UrlValueResolvable ,
6- } from "./raw-result-types" ;
2+ import { isUrlValueResolvable , UrlValue } from "./raw-result-types" ;
73import {
84 LineColumnLocation ,
95 UrlValue as BqrsUrlValue ,
@@ -18,82 +14,6 @@ export function isEmptyPath(uriStr: string) {
1814 return ! uriStr || uriStr === "file:/" ;
1915}
2016
21- /**
22- * The CodeQL filesystem libraries use this pattern in `getURL()` predicates
23- * to describe the location of an entire filesystem resource.
24- * Such locations appear as `StringLocation`s instead of `FivePartLocation`s.
25- *
26- * Folder resources also get similar URLs, but with the `folder` scheme.
27- * They are deliberately ignored here, since there is no suitable location to show the user.
28- */
29- const FILE_LOCATION_REGEX = / f i l e : \/ \/ ( .+ ) : ( [ 0 - 9 ] + ) : ( [ 0 - 9 ] + ) : ( [ 0 - 9 ] + ) : ( [ 0 - 9 ] + ) / ;
30- /**
31- * Gets a resolvable source file location for the specified `LocationValue`, if possible.
32- * @param loc The location to test.
33- */
34- export function tryGetResolvableLocation (
35- loc : BqrsUrlValue | undefined ,
36- ) : UrlValueResolvable | undefined {
37- let resolvedLoc : UrlValueResolvable | undefined ;
38- if ( loc === undefined ) {
39- resolvedLoc = undefined ;
40- } else if ( isWholeFileLoc ( loc ) ) {
41- resolvedLoc = {
42- type : "wholeFileLocation" ,
43- uri : loc . uri ,
44- } ;
45- } else if ( isLineColumnLoc ( loc ) ) {
46- resolvedLoc = {
47- type : "lineColumnLocation" ,
48- uri : loc . uri ,
49- startLine : loc . startLine ,
50- startColumn : loc . startColumn ,
51- endLine : loc . endLine ,
52- endColumn : loc . endColumn ,
53- } ;
54- } else if ( isStringLoc ( loc ) ) {
55- resolvedLoc = tryGetLocationFromString ( loc ) ;
56- } else {
57- resolvedLoc = undefined ;
58- }
59-
60- return resolvedLoc ;
61- }
62-
63- export function tryGetLocationFromString (
64- loc : string ,
65- ) : UrlValueResolvable | undefined {
66- const matches = FILE_LOCATION_REGEX . exec ( loc ) ;
67- if ( matches && matches . length > 1 && matches [ 1 ] ) {
68- if ( isWholeFileMatch ( matches ) ) {
69- return {
70- type : "wholeFileLocation" ,
71- uri : matches [ 1 ] ,
72- } ;
73- } else {
74- return {
75- type : "lineColumnLocation" ,
76- uri : matches [ 1 ] ,
77- startLine : Number ( matches [ 2 ] ) ,
78- startColumn : Number ( matches [ 3 ] ) ,
79- endLine : Number ( matches [ 4 ] ) ,
80- endColumn : Number ( matches [ 5 ] ) ,
81- } ;
82- }
83- } else {
84- return undefined ;
85- }
86- }
87-
88- function isWholeFileMatch ( matches : RegExpExecArray ) : boolean {
89- return (
90- matches [ 2 ] === "0" &&
91- matches [ 3 ] === "0" &&
92- matches [ 4 ] === "0" &&
93- matches [ 5 ] === "0"
94- ) ;
95- }
96-
9717export function isLineColumnLoc ( loc : BqrsUrlValue ) : loc is LineColumnLocation {
9818 return (
9919 typeof loc !== "string" &&
@@ -115,20 +35,6 @@ export function isStringLoc(loc: BqrsUrlValue): loc is string {
11535 return typeof loc === "string" ;
11636}
11737
118- export function tryGetBqrsRemoteLocation (
119- loc : BqrsUrlValue | undefined ,
120- fileLinkPrefix : string ,
121- sourceLocationPrefix : string | undefined ,
122- ) : string | undefined {
123- const resolvedLoc = tryGetResolvableLocation ( loc ) ;
124-
125- return tryGetRemoteLocation (
126- resolvedLoc ,
127- fileLinkPrefix ,
128- sourceLocationPrefix ,
129- ) ;
130- }
131-
13238export function tryGetRemoteLocation (
13339 loc : UrlValue | undefined ,
13440 fileLinkPrefix : string ,
0 commit comments