-
-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathextension.ts
110 lines (107 loc) Β· 5.32 KB
/
extension.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import * as vscode from 'vscode'
import { WorkspaceFolder, DebugConfiguration, ProviderResult, CancellationToken } from 'vscode'
import { LaunchRequestArguments } from './phpDebug'
import * as which from 'which'
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.debug.registerDebugConfigurationProvider('php', {
async resolveDebugConfiguration(
folder: WorkspaceFolder | undefined,
debugConfiguration: DebugConfiguration & LaunchRequestArguments,
token?: CancellationToken
): Promise<ProviderResult<DebugConfiguration>> {
if (!debugConfiguration.type && !debugConfiguration.request && !debugConfiguration.name) {
const editor = vscode.window.activeTextEditor
if (editor && editor.document.languageId === 'php') {
debugConfiguration.type = 'php'
debugConfiguration.name = 'Launch (dynamic)'
debugConfiguration.request = 'launch'
debugConfiguration.program = '${file}'
debugConfiguration.cwd = '${fileDirname}'
debugConfiguration.port = 0
debugConfiguration.runtimeArgs = ['-dxdebug.start_with_request=yes']
debugConfiguration.env = {
XDEBUG_MODE: 'debug,develop',
XDEBUG_CONFIG: 'client_port=${port}',
}
// debugConfiguration.stopOnEntry = true
}
}
if (
(debugConfiguration.program || debugConfiguration.runtimeArgs) &&
!debugConfiguration.runtimeExecutable
) {
// See if we have runtimeExecutable configured
const conf = vscode.workspace.getConfiguration('php.debug')
const executablePath = conf.get<string>('executablePath')
if (executablePath) {
debugConfiguration.runtimeExecutable = executablePath
}
// See if it's in path
if (!debugConfiguration.runtimeExecutable) {
try {
await which.default('php')
} catch (e) {
const selected = await vscode.window.showErrorMessage(
'PHP executable not found. Install PHP and add it to your PATH or set the php.debug.executablePath setting',
'Open settings'
)
if (selected === 'Open settings') {
await vscode.commands.executeCommand('workbench.action.openGlobalSettings', {
query: 'php.debug.executablePath',
})
return undefined
}
}
}
}
if (debugConfiguration.proxy?.enable === true) {
// Proxy configuration
if (!debugConfiguration.proxy.key) {
const conf = vscode.workspace.getConfiguration('php.debug')
const ideKey = conf.get<string>('ideKey')
if (ideKey) {
debugConfiguration.proxy.key = ideKey
}
}
}
return debugConfiguration
},
})
)
context.subscriptions.push(
vscode.languages.registerEvaluatableExpressionProvider('php', {
// eslint-disable-next-line @typescript-eslint/require-await
async provideEvaluatableExpression(
document: vscode.TextDocument,
position: vscode.Position,
token: CancellationToken
): Promise<ProviderResult<vscode.EvaluatableExpression>> {
// see https://www.php.net/manual/en/language.variables.basics.php
// const wordRange = document.getWordRangeAtPosition(position, /\$([a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)((->(?1))|\[(\d+|'[^']+'|"[^"]+"|(?0))\])*/)
const wordRange = document.getWordRangeAtPosition(
position,
/\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*(->[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)*/
)
if (wordRange) {
return new vscode.EvaluatableExpression(wordRange)
}
return undefined // nothing evaluatable found under mouse
},
})
)
context.subscriptions.push(
vscode.commands.registerCommand('php.debug.debugPhpFile', async (uri: vscode.Uri) => {
await vscode.debug.startDebugging(undefined, { type: '', name: '', request: '' })
})
)
context.subscriptions.push(
vscode.commands.registerCommand('php.debug.startWithStopOnEntry', async (uri: vscode.Uri) => {
await vscode.commands.executeCommand('workbench.action.debug.start', {
config: {
stopOnEntry: true,
},
})
})
)
}