Browse Source

better support for autoloads

Geequlim 8 years ago
parent
commit
1ca963f72f
3 changed files with 19 additions and 6 deletions
  1. 2 0
      src/gdscript/definitionprovider.ts
  2. 2 1
      src/gdscript/hoverprovider.ts
  3. 15 5
      src/tool_manager.ts

+ 2 - 0
src/gdscript/definitionprovider.ts

@@ -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[] = [];

+ 2 - 1
src/gdscript/hoverprovider.ts

@@ -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;
                         }

+ 15 - 5
src/tool_manager.ts

@@ -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);