|
@@ -11,8 +11,12 @@ export class GodotTools {
|
|
private reconnection_attempts = 0;
|
|
private reconnection_attempts = 0;
|
|
private context: vscode.ExtensionContext;
|
|
private context: vscode.ExtensionContext;
|
|
private client: GDScriptLanguageClient = null;
|
|
private client: GDScriptLanguageClient = null;
|
|
|
|
+ // deprecated, need to replace with "vscode.workspace.workspaceFolders", but
|
|
|
|
+ // that's an array and not a single value
|
|
private workspace_dir = vscode.workspace.rootPath;
|
|
private workspace_dir = vscode.workspace.rootPath;
|
|
- private project_file = "project.godot";
|
|
|
|
|
|
+ private project_file_name = "project.godot";
|
|
|
|
+ private project_file = "";
|
|
|
|
+ private project_dir = ""
|
|
private connection_status: vscode.StatusBarItem = null;
|
|
private connection_status: vscode.StatusBarItem = null;
|
|
|
|
|
|
constructor(p_context: vscode.ExtensionContext) {
|
|
constructor(p_context: vscode.ExtensionContext) {
|
|
@@ -38,11 +42,23 @@ export class GodotTools {
|
|
});
|
|
});
|
|
vscode.commands.registerCommand("godot-tool.check_status", this.check_client_status.bind(this));
|
|
vscode.commands.registerCommand("godot-tool.check_status", this.check_client_status.bind(this));
|
|
vscode.commands.registerCommand("godot-tool.set_scene_file", this.set_scene_file.bind(this));
|
|
vscode.commands.registerCommand("godot-tool.set_scene_file", this.set_scene_file.bind(this));
|
|
|
|
+ vscode.commands.registerCommand("godot-tool.copy_resource_path_context", this.copy_resource_path.bind(this));
|
|
|
|
+ vscode.commands.registerCommand("godot-tool.copy_resource_path", this.copy_resource_path.bind(this));
|
|
|
|
|
|
this.connection_status.text = "$(sync) Initializing";
|
|
this.connection_status.text = "$(sync) Initializing";
|
|
this.connection_status.command = "godot-tool.check_status";
|
|
this.connection_status.command = "godot-tool.check_status";
|
|
this.connection_status.show();
|
|
this.connection_status.show();
|
|
|
|
|
|
|
|
+ // TODO: maybe cache this result somehow
|
|
|
|
+ const klaw = require('klaw');
|
|
|
|
+ klaw(this.workspace_dir)
|
|
|
|
+ .on('data', item => {
|
|
|
|
+ if (path.basename(item.path) == this.project_file_name) {
|
|
|
|
+ this.project_dir = path.dirname(item.path);
|
|
|
|
+ this.project_file = item.path;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
this.reconnection_attempts = 0;
|
|
this.reconnection_attempts = 0;
|
|
this.client.connect_to_server();
|
|
this.client.connect_to_server();
|
|
}
|
|
}
|
|
@@ -55,12 +71,12 @@ export class GodotTools {
|
|
|
|
|
|
return new Promise<void>((resolve, reject) => {
|
|
return new Promise<void>((resolve, reject) => {
|
|
let valid = false;
|
|
let valid = false;
|
|
- if (this.workspace_dir) {
|
|
|
|
- let cfg = path.join(this.workspace_dir, this.project_file);
|
|
|
|
|
|
+ if (this.project_dir) {
|
|
|
|
+ let cfg = this.project_file;
|
|
valid = (fs.existsSync(cfg) && fs.statSync(cfg).isFile());
|
|
valid = (fs.existsSync(cfg) && fs.statSync(cfg).isFile());
|
|
}
|
|
}
|
|
if (valid) {
|
|
if (valid) {
|
|
- this.run_editor(`--path "${this.workspace_dir}" ${params}`).then(() => resolve()).catch(err => {
|
|
|
|
|
|
+ this.run_editor(`--path "${this.project_dir}" ${params}`).then(() => resolve()).catch(err => {
|
|
reject(err);
|
|
reject(err);
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
@@ -69,6 +85,22 @@ export class GodotTools {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private copy_resource_path(uri: vscode.Uri) {
|
|
|
|
+ if (!this.project_dir) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!uri) {
|
|
|
|
+ uri = vscode.window.activeTextEditor.document.uri
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let relative_path = path.normalize(path.relative(this.project_dir, uri.fsPath));
|
|
|
|
+ relative_path = relative_path.split(path.sep).join(path.posix.sep);
|
|
|
|
+ relative_path = 'res://' + relative_path;
|
|
|
|
+
|
|
|
|
+ vscode.env.clipboard.writeText(relative_path);
|
|
|
|
+ }
|
|
|
|
+
|
|
private set_scene_file(uri: vscode.Uri) {
|
|
private set_scene_file(uri: vscode.Uri) {
|
|
let right_clicked_scene_path = uri.fsPath
|
|
let right_clicked_scene_path = uri.fsPath
|
|
let scene_config = get_configuration("scene_file_config");
|
|
let scene_config = get_configuration("scene_file_config");
|