Skip to content

Commit 0159eec

Browse files
committed
Cleanup locator
1 parent e8fe39e commit 0159eec

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

packages/debugger/src/locator/locator.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,36 @@ const LOC_ATTR_REGEX_WIN = /^((?:\\?[^\s][^/\\:\"\?\*<>\|]+)+):([0-9]+):([0-9]+
3535
const LOC_ATTR_REGEX_UNIX = /^((?:(?:\.\/|\.\.\/|\/)?(?:\.?\w+\/)*)(?:\.?\w+\.?\w+)):([0-9]+):([0-9]+)$/
3636

3737
export function getLocationAttr(element: Element): LocationAttr | null {
38+
3839
let attr = element.getAttribute(LOCATION_ATTRIBUTE_NAME)
3940
if (!attr) return null
41+
4042
let is_windows = /(win32|win64|windows|wince)/i.test(navigator.userAgent)
4143
let regex = is_windows ? LOC_ATTR_REGEX_WIN : LOC_ATTR_REGEX_UNIX
4244
return regex.test(attr) ? attr as LocationAttr : null
4345
}
4446

45-
const targetIDEMap: Record<TargetIDE, (data: SourceCodeData) => string> = {
46-
vscode: ({projectPath, file, line, column}) =>
47-
`vscode://file/${projectPath}/${file}:${line}:${column}`,
48-
'vscode-insiders': ({projectPath, file: filePath, line, column}) =>
49-
`vscode-insiders://file/${projectPath}/${filePath}:${line}:${column}`,
50-
atom: ({projectPath, file: filePath, line, column}) =>
51-
`atom://core/open/file?filename=${projectPath}/${filePath}&line=${line}&column=${column}`,
52-
webstorm: ({projectPath, file: filePath, line, column}) =>
53-
`webstorm://open?file=${projectPath}/${filePath}&line=${line}&column=${column}`,
54-
}
55-
5647
function getTargetURL(target: TargetIDE | TargetURLFunction, data: SourceCodeData): string | void {
48+
5749
if (typeof target === 'function') return target(data)
58-
return targetIDEMap[target](data)
50+
51+
let {projectPath, file, line, column} = data
52+
switch (target) {
53+
case 'vscode': return `vscode://file/${projectPath}/${file}:${line}:${column}`
54+
case 'vscode-insiders': return `vscode-insiders://file/${projectPath}/${file}:${line}:${column}`
55+
case 'atom': return `atom://core/open/file?filename=${projectPath}/${file}&line=${line}&column=${column}`
56+
case 'webstorm': return `webstorm://open?file=${projectPath}/${file}&line=${line}&column=${column}`
57+
}
5958
}
6059

6160
export const getProjectPath = (): string | undefined => (window as any)[WINDOW_PROJECTPATH_PROPERTY]
6261

63-
export function getSourceCodeData(
64-
location: SourceLocation,
65-
): SourceCodeData | undefined {
62+
export function getSourceCodeData(location: SourceLocation): SourceCodeData | undefined {
6663

67-
let projectPath: string | undefined = getProjectPath()
68-
if (projectPath == null) return
64+
let project_path = getProjectPath()
65+
if (project_path == null) return
6966

70-
return {...location, projectPath}
67+
return {...location, projectPath: project_path}
7168
}
7269

7370
/**

0 commit comments

Comments
 (0)