mirror of
https://github.com/godotengine/godot-vscode-plugin.git
synced 2025-12-31 13:48:24 +03:00
Add project root configuration settings (#37)
* Add project root configuration settings * Add run scene support for custom godot project directory
This commit is contained in:
committed by
Geequlim
parent
4b3282cf03
commit
ec7e1013aa
@@ -76,6 +76,11 @@
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Show node pathes of of workspace in the code completion"
|
||||
},
|
||||
"GodotTools.godotProjectRoot": {
|
||||
"type": "strng",
|
||||
"default": "",
|
||||
"description": "Relate path to the godot project"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -15,16 +15,19 @@ import config from '../config';
|
||||
import {isStr, getSelectedContent, getStrContent} from './utils';
|
||||
|
||||
class GDScriptDefinitionProivder implements DefinitionProvider {
|
||||
constructor() {
|
||||
private _rootFolder : string = "";
|
||||
|
||||
constructor(rootFolder: string) {
|
||||
this._rootFolder = rootFolder;
|
||||
}
|
||||
|
||||
provideDefinition(document: TextDocument, position: Position, token: CancellationToken): Definition | Thenable < Definition > {
|
||||
const getDefinitions = (content: string):Location[]| Location => {
|
||||
if(content.startsWith("res://")) {
|
||||
content = content.replace("res://", "");
|
||||
if(workspace && workspace.rootPath)
|
||||
content = path.join(workspace.rootPath, content)
|
||||
if(workspace && workspace.rootPath) {
|
||||
content = path.join(this._rootFolder, content);
|
||||
}
|
||||
return new Location(Uri.file(content), new Range(0,0,0,0));
|
||||
}
|
||||
else if(fs.existsSync(content) && fs.statSync(content).isFile()) {
|
||||
|
||||
@@ -19,6 +19,7 @@ class ToolManager {
|
||||
private _disposable: vscode.Disposable;
|
||||
private _context: vscode.ExtensionContext;
|
||||
private _projectFile : string = "engine.cfg";
|
||||
private _rootDir : string = "";
|
||||
private _biuitinDocFile : string = "doc/classes.json";
|
||||
|
||||
|
||||
@@ -31,6 +32,7 @@ class ToolManager {
|
||||
this._biuitinDocFile = "doc/classes-3.0.json";
|
||||
completionDollar = true;
|
||||
}
|
||||
this._rootDir = path.join(this.workspaceDir, vscode.workspace.getConfiguration("GodotTools").get("godotProjectRoot", ""));
|
||||
if (vscode.workspace && this.workspaceDir) {
|
||||
vscode.workspace.registerTextDocumentContentProvider('godotdoc', new GDScriptDocumentContentProvider());
|
||||
this.workspaceDir = this.workspaceDir.replace(/\\/g, "/");
|
||||
@@ -44,7 +46,7 @@ class ToolManager {
|
||||
this.workspacesymbolprovider = new GDScriptWorkspaceSymbolProvider();
|
||||
vscode.languages.registerWorkspaceSymbolProvider(this.workspacesymbolprovider);
|
||||
// definition provider
|
||||
vscode.languages.registerDefinitionProvider('gdscript', new GDScriptDefinitionProivder());
|
||||
vscode.languages.registerDefinitionProvider('gdscript', new GDScriptDefinitionProivder(this._rootDir));
|
||||
// hover provider
|
||||
vscode.languages.registerHoverProvider('gdscript', new GDScriptHoverProvider());
|
||||
// code completion provider
|
||||
@@ -117,7 +119,7 @@ class ToolManager {
|
||||
const name = l.substring(0, l.indexOf("="));
|
||||
|
||||
let gdpath = l.substring(l.indexOf("res://") + "res://".length, l.indexOf(".gd") + ".gd".length);
|
||||
gdpath = path.join(self.workspaceDir, gdpath);
|
||||
gdpath = path.join(this._rootDir, gdpath);
|
||||
let showgdpath = vscode.workspace.asRelativePath(gdpath);
|
||||
|
||||
let doc = "Auto loaded instance of " + `[${showgdpath}](${vscode.Uri.file(gdpath).toString()})`;
|
||||
@@ -167,15 +169,15 @@ class ToolManager {
|
||||
private openWorkspaceWithEditor(params = "") {
|
||||
let workspaceValid = false
|
||||
if (this.workspaceDir) {
|
||||
let cfg = path.join(this.workspaceDir, this._projectFile);
|
||||
if (fs.existsSync(cfg) && fs.statSync(cfg).isFile())
|
||||
let cfg = path.join(this._rootDir, this._projectFile);
|
||||
if (fs.existsSync(cfg) && fs.statSync(cfg).isFile())
|
||||
workspaceValid = true;
|
||||
}
|
||||
if (workspaceValid) {
|
||||
let pathFlag = "-path";
|
||||
if (vscode.workspace.getConfiguration("GodotTools").get("godotVersion", 2.1) >= 3)
|
||||
pathFlag = "--path";
|
||||
this.runEditor(`${pathFlag} ${this.workspaceDir} ${params}`);
|
||||
this.runEditor(`${pathFlag} ${this._rootDir} ${params}`);
|
||||
}
|
||||
else
|
||||
vscode.window.showErrorMessage("Current workspace is not a godot project");
|
||||
@@ -196,7 +198,8 @@ class ToolManager {
|
||||
private runCurrentScene() {
|
||||
let scenePath = null
|
||||
if (vscode.window.activeTextEditor)
|
||||
scenePath = vscode.workspace.asRelativePath(vscode.window.activeTextEditor.document.uri);
|
||||
scenePath = path.relative(this._rootDir, vscode.window.activeTextEditor.document.uri.fsPath);
|
||||
scenePath = scenePath.replace(/\\/g, "/");
|
||||
if (scenePath.endsWith(".gd")) {
|
||||
const scriptPath = scenePath;
|
||||
scenePath = config.scriptSceneMap[config.normalizePath(scenePath)];
|
||||
|
||||
Reference in New Issue
Block a user