mirror of
https://github.com/godotengine/godot-vscode-plugin.git
synced 2025-12-31 13:48:24 +03:00
better support for autoloads
This commit is contained in:
@@ -36,6 +36,8 @@ class GDScriptDefinitionProivder implements DefinitionProvider {
|
||||
// check from workspace
|
||||
for (let path of Object.keys(workspaceSymbols)) {
|
||||
const script = workspaceSymbols[path];
|
||||
if(path == "autoload" && script.constpathes && script.constpathes[content])
|
||||
path = script.constpathes[content];
|
||||
let scriptitems: Location[] = [];
|
||||
const checkDifinition = (items)=>{
|
||||
const _items: Location[] = [];
|
||||
|
||||
@@ -53,7 +53,8 @@ class GDScriptHoverProvider implements HoverProvider {
|
||||
_items.push({language:'gdscript', value:`${type} ${name}${signature}`});
|
||||
let doc = script.documents[name];
|
||||
doc = doc?doc+"\r\n\r\n":"";
|
||||
doc += `*Defined in [${dfile}](${Uri.file(path).toString()})*`
|
||||
if(path != "autoload")
|
||||
doc += `*Defined in [${dfile}](${Uri.file(path).toString()})*`;
|
||||
_items.push(doc)
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import config from './config';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
const cmd = require('node-cmd');
|
||||
|
||||
class ToolManager {
|
||||
|
||||
private workspaceDir: string = "";
|
||||
@@ -84,22 +83,33 @@ class ToolManager {
|
||||
const engincfg = path.join(self.workspaceDir, "engine.cfg");
|
||||
if(fs.existsSync(engincfg) && fs.statSync(engincfg).isFile()) {
|
||||
try {
|
||||
const script = { constants: {}, functions: {}, variables: {}, signals: {}, classes: {}, base: "Object", native: "Object"};
|
||||
const script = { constants: {}, functions: {}, variables: {}, signals: {}, classes: {}, base: "Object", native: "Object", constpathes: {}, documents: {}, constvalues: {}};
|
||||
let content: string = fs.readFileSync(engincfg, 'utf-8');
|
||||
if(content && content.indexOf("[autoload]") != -1) {
|
||||
content = content.substring(content.indexOf("[autoload]")+"[autoload]".length, content.length);
|
||||
content = content.substring(0, content.indexOf("["));
|
||||
const lines = content.split(/\r?\n/);
|
||||
lines.map(l=>{
|
||||
lines.map((l)=>{
|
||||
if(l.indexOf("=") != 0) {
|
||||
const name = l.substring(0, l.indexOf("="));
|
||||
script.constants[name] = new vscode.Range(0, 0, 0,0);
|
||||
|
||||
let gdpath = l.substring(l.indexOf("res://")+"res://".length, l.indexOf(".gd")+".gd".length);
|
||||
gdpath = path.join( self.workspaceDir, gdpath);
|
||||
let showgdpath = vscode.workspace.asRelativePath(gdpath);
|
||||
|
||||
let doc = "Auto loaded instance of " + `[${showgdpath}](${vscode.Uri.file(gdpath).toString()})`;
|
||||
doc = doc.replace(/"/g, " ");
|
||||
|
||||
script.constants[name] = new vscode.Range(0, 0, 0, 0);
|
||||
script.constvalues[name] = "autoload";
|
||||
script.documents[name] = doc;
|
||||
script.constpathes[name] = gdpath;
|
||||
}
|
||||
});
|
||||
}
|
||||
symbols["autoload"] = script;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
resolve(symbols);
|
||||
|
||||
Reference in New Issue
Block a user