|
@@ -4,7 +4,7 @@ import * as fs from "fs";
|
|
import { GDDocumentLinkProvider } from "./document_link_provider";
|
|
import { GDDocumentLinkProvider } from "./document_link_provider";
|
|
import { ScenePreviewProvider } from "./scene_preview_provider";
|
|
import { ScenePreviewProvider } from "./scene_preview_provider";
|
|
import GDScriptLanguageClient, { ClientStatus } from "./lsp/GDScriptLanguageClient";
|
|
import GDScriptLanguageClient, { ClientStatus } from "./lsp/GDScriptLanguageClient";
|
|
-import { get_configuration, set_configuration, find_file, set_context } from "./utils";
|
|
|
|
|
|
+import { get_configuration, set_configuration, find_file, set_context, find_project_file } from "./utils";
|
|
|
|
|
|
const CONFIG_CONTAINER = "godot_tools";
|
|
const CONFIG_CONTAINER = "godot_tools";
|
|
const TOOL_NAME = "GodotTools";
|
|
const TOOL_NAME = "GodotTools";
|
|
@@ -16,12 +16,6 @@ export class GodotTools {
|
|
private linkProvider: GDDocumentLinkProvider = null;
|
|
private linkProvider: GDDocumentLinkProvider = null;
|
|
private scenePreviewManager: ScenePreviewProvider = null;
|
|
private scenePreviewManager: ScenePreviewProvider = 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 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) {
|
|
@@ -62,16 +56,6 @@ export class GodotTools {
|
|
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();
|
|
}
|
|
}
|
|
@@ -81,15 +65,22 @@ export class GodotTools {
|
|
}
|
|
}
|
|
|
|
|
|
private open_workspace_with_editor(params = "") {
|
|
private open_workspace_with_editor(params = "") {
|
|
-
|
|
|
|
- return new Promise<void>((resolve, reject) => {
|
|
|
|
|
|
+ return new Promise<void>(async (resolve, reject) => {
|
|
let valid = false;
|
|
let valid = false;
|
|
- if (this.project_dir) {
|
|
|
|
- let cfg = this.project_file;
|
|
|
|
- valid = (fs.existsSync(cfg) && fs.statSync(cfg).isFile());
|
|
|
|
- }
|
|
|
|
|
|
+ let project_dir = '';
|
|
|
|
+ let project_file = '';
|
|
|
|
+
|
|
|
|
+ if (vscode.workspace.workspaceFolders != undefined) {
|
|
|
|
+ const files = await vscode.workspace.findFiles("**/project.godot");
|
|
|
|
+ if (files) {
|
|
|
|
+ project_file = files[0].fsPath;
|
|
|
|
+ project_dir = path.dirname(project_file);
|
|
|
|
+ let cfg = project_file;
|
|
|
|
+ valid = (fs.existsSync(cfg) && fs.statSync(cfg).isFile());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
if (valid) {
|
|
if (valid) {
|
|
- this.run_editor(`--path "${this.project_dir}" ${params}`).then(() => resolve()).catch(err => {
|
|
|
|
|
|
+ this.run_editor(`--path "${project_dir}" ${params}`).then(() => resolve()).catch(err => {
|
|
reject(err);
|
|
reject(err);
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
@@ -99,18 +90,20 @@ export class GodotTools {
|
|
}
|
|
}
|
|
|
|
|
|
private copy_resource_path(uri: vscode.Uri) {
|
|
private copy_resource_path(uri: vscode.Uri) {
|
|
- if (!this.project_dir) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
if (!uri) {
|
|
if (!uri) {
|
|
uri = vscode.window.activeTextEditor.document.uri;
|
|
uri = vscode.window.activeTextEditor.document.uri;
|
|
}
|
|
}
|
|
|
|
|
|
- let relative_path = path.normalize(path.relative(this.project_dir, uri.fsPath));
|
|
|
|
|
|
+ const project_dir = path.dirname(find_project_file(uri.fsPath));
|
|
|
|
+ if (project_dir === null) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let relative_path = path.normalize(path.relative(project_dir, uri.fsPath));
|
|
relative_path = relative_path.split(path.sep).join(path.posix.sep);
|
|
relative_path = relative_path.split(path.sep).join(path.posix.sep);
|
|
relative_path = "res://" + relative_path;
|
|
relative_path = "res://" + relative_path;
|
|
|
|
|
|
|
|
+ logger.log(relative_path)
|
|
vscode.env.clipboard.writeText(relative_path);
|
|
vscode.env.clipboard.writeText(relative_path);
|
|
}
|
|
}
|
|
|
|
|