Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launching the editor opens a new custom terminal #561

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@
"default": "godot4",
"description": "The absolute path to the Godot 4 editor executable"
},
"godotTools.editor.verbose": {
"type": "boolean",
"default": false,
"description": "Whether to launch the Godot Editor with the --verbose flag"
},
"godotTools.editor.revealTerminal": {
"type": "boolean",
"default": true,
"description": "Whether to reveal the terminal when launching the Godot Editor"
},
"godotTools.lsp.serverProtocol": {
"type": [
"string"
Expand Down
59 changes: 56 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from "path";
import * as vscode from "vscode";
import { attemptSettingsUpdate } from "./utils";
import { attemptSettingsUpdate, get_extension_uri } from "./utils";
import {
GDInlayHintsProvider,
GDHoverProvider,
Expand All @@ -15,7 +15,6 @@ import { ClientConnectionManager } from "./lsp";
import { ScenePreviewProvider } from "./scene_tools";
import { GodotDebugger } from "./debugger";
import { FormattingProvider } from "./formatter";
import { exec, execSync } from "child_process";
import {
get_configuration,
find_file,
Expand All @@ -27,6 +26,7 @@ import {
verify_godot_version,
} from "./utils";
import { prompt_for_godot_executable } from "./utils/prompts";
import { killSubProcesses, subProcess } from "./utils/subspawn";

interface Extension {
context?: vscode.ExtensionContext;
Expand Down Expand Up @@ -157,7 +157,24 @@ async function open_workspace_with_editor() {

switch (result.status) {
case "SUCCESS": {
exec(`${godotPath} --path "${projectDir}" -e`);
let command = `${godotPath} --path "${projectDir}" -e`;
if (get_configuration("editor.verbose")) {
command += " -v";
}
const existingTerminal = vscode.window.terminals.find(t => t.name === "Godot Editor");
if (existingTerminal) {
existingTerminal.dispose();
}
const options: vscode.ExtensionTerminalOptions = {
name: "Godot Editor",
iconPath: get_extension_uri("resources/godot_icon.svg"),
pty: new GodotEditorTerminal(command),
isTransient: true,
};
const terminal = vscode.window.createTerminal(options);
if (get_configuration("editor.revealTerminal")) {
terminal.show();
}
break;
}
case "WRONG_VERSION": {
Expand All @@ -172,3 +189,39 @@ async function open_workspace_with_editor() {
}
}
}

class GodotEditorTerminal implements vscode.Pseudoterminal {
private writeEmitter = new vscode.EventEmitter<string>();
onDidWrite: vscode.Event<string> = this.writeEmitter.event;
private closeEmitter = new vscode.EventEmitter<number>();
onDidClose?: vscode.Event<number> = this.closeEmitter.event;

constructor(private command: string) { }

open(initialDimensions: vscode.TerminalDimensions | undefined): void {
const proc = subProcess("GodotEditor", this.command, { shell: true, detached: true });
this.writeEmitter.fire("Starting Godot Editor process...\r\n");

proc.stdout.on("data", (data) => {
const out = data.toString().trim();
if (out) {
this.writeEmitter.fire(data + "\r\n");
}
});

proc.stderr.on("data", (data) => {
const out = data.toString().trim();
if (out) {
this.writeEmitter.fire(data + "\r\n");
}
});

proc.on("close", (code) => {
this.writeEmitter.fire(`Godot Editor stopped with exit code: ${code}\r\n`);
});
}

close(): void {
killSubProcesses("GodotEditor");
}
}