-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add debugger and task provider (#360)
* Bump version 2.2.2 * add debug adapter * add task provider * use existing getRenpyExecutablePath function * allow debugger to launch without launch.json requires a renpy-language file to be open * use renpy debugger for run project command instead of requiring an extension to supports the cmd type for debuggers * register task provider with context.subscriptions * update logger convention in debugger --------- Co-authored-by: Daniel Luque <[email protected]>
- Loading branch information
1 parent
d39231e
commit 560137f
Showing
5 changed files
with
271 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as vscode from "vscode"; | ||
import { DebugSession, TerminatedEvent } from "@vscode/debugadapter"; | ||
import { getWorkspaceFolder } from "./workspace"; | ||
import { Configuration } from "./configuration"; | ||
import { logToast } from "./logger"; | ||
import { isValidExecutable } from "./extension"; | ||
|
||
function getTerminal(name: string): vscode.Terminal { | ||
let i: number; | ||
for (i = 0; i < vscode.window.terminals.length; i++) { | ||
if (vscode.window.terminals[i].name === name) { | ||
return vscode.window.terminals[i]; | ||
} | ||
} | ||
return vscode.window.createTerminal(name); | ||
} | ||
|
||
export class RenpyAdapterDescriptorFactory implements vscode.DebugAdapterDescriptorFactory { | ||
createDebugAdapterDescriptor(session: vscode.DebugSession): vscode.ProviderResult<vscode.DebugAdapterDescriptor> { | ||
return new vscode.DebugAdapterInlineImplementation(new RenpyDebugSession(session.configuration.command, session.configuration.args)); | ||
} | ||
} | ||
|
||
class RenpyDebugSession extends DebugSession { | ||
private command = "run"; | ||
private args?: string[]; | ||
|
||
public constructor(command: string, args?: string[]) { | ||
super(); | ||
this.command = command; | ||
if (args) { | ||
this.args = args; | ||
} | ||
} | ||
|
||
protected override initializeRequest(): void { | ||
const terminal = getTerminal("Ren'py Debug"); | ||
terminal.show(); | ||
let program = Configuration.getRenpyExecutablePath(); | ||
|
||
if (!isValidExecutable(program)) { | ||
logToast(vscode.LogLevel.Error, "Ren'Py executable location not configured or is invalid."); | ||
return; | ||
} | ||
|
||
program += " " + getWorkspaceFolder(); | ||
if (this.command) { | ||
program += " " + this.command; | ||
} | ||
if (this.args) { | ||
program += " " + this.args.join(" "); | ||
} | ||
terminal.sendText(program); | ||
this.sendEvent(new TerminatedEvent()); | ||
} | ||
} | ||
|
||
export class RenpyConfigurationProvider implements vscode.DebugConfigurationProvider { | ||
resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration): vscode.ProviderResult<vscode.DebugConfiguration> { | ||
if (!config.type && !config.request && !config.name) { | ||
const editor = vscode.window.activeTextEditor; | ||
if (editor && editor.document.languageId === "renpy") { | ||
config.type = "renpy"; | ||
config.request = "launch"; | ||
config.name = "Ren'Py: Launch"; | ||
config.command = "run"; | ||
config.args = []; | ||
} | ||
} | ||
return config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.