瀏覽代碼

Add more 3.0 support
Release 0.2.8

geequlim 8 年之前
父節點
當前提交
43e31f04cb
共有 5 個文件被更改,包括 20712 次插入79 次删除
  1. 1 1
      CHANGELOG.md
  2. 6 7
      README.md
  3. 20622 0
      doc/classes-3.0.json
  4. 2 2
      package.json
  5. 81 69
      src/tool_manager.ts

+ 1 - 1
CHANGELOG.md

@@ -2,8 +2,8 @@
 
 
 ### 0.2.8
 ### 0.2.8
 * Add godot 3.0 project support with configuration `GodotTools.parseTextScene` >= 3
 * Add godot 3.0 project support with configuration `GodotTools.parseTextScene` >= 3
-* Remove `GodotTools.editorServerPort` configuration
 * Add configuration `GodotTools.parseTextScene` to allow disable node path parsing
 * Add configuration `GodotTools.parseTextScene` to allow disable node path parsing
+* Remove `GodotTools.editorServerPort` configuration
 
 
 ### 0.2.7
 ### 0.2.7
 
 

+ 6 - 7
README.md

@@ -40,6 +40,11 @@ The [Godot Tools](https://github.com/GodotExplorer/godot-tools) and the go to [e
 
 
 ## Release Notes
 ## Release Notes
 
 
+### 0.2.8
+* Add godot 3.0 project support with configuration `GodotTools.parseTextScene` >= 3
+* Add configuration `GodotTools.parseTextScene` to allow disable node path parsing
+* Remove `GodotTools.editorServerPort` configuration
+
 ### 0.2.7
 ### 0.2.7
 
 
 * Fix some error with syntax checking
 * Fix some error with syntax checking
@@ -76,13 +81,7 @@ The [Godot Tools](https://github.com/GodotExplorer/godot-tools) and the go to [e
 * The pulugin is compiled with latest VSCode thanks @arrkiin
 * The pulugin is compiled with latest VSCode thanks @arrkiin
 * Add key bindings for open workspace with godot editor with `F7` and update workspace symbols with `F8`
 * Add key bindings for open workspace with godot editor with `F7` and update workspace symbols with `F8`
 
 
-### 0.2.5
-
-* Run games within VSCode terminals
-* Add key bindings for `F5 to run the workspace` and `F6 to run the edting scene`
-* Fix a lot of bugs with unused vaiable cheching
-* Move workspace symbols state notice to status bar
-
+[Full change log](CHANGELOG.md)
 
 
 ## TODOS:
 ## TODOS:
 * Convert official BBCode documentation into Markdown and render it to HTML with documentation previewer pages
 * Convert official BBCode documentation into Markdown and render it to HTML with documentation previewer pages

文件差異過大導致無法顯示
+ 20622 - 0
doc/classes-3.0.json


+ 2 - 2
package.json

@@ -2,8 +2,8 @@
   "name": "godot-tools",
   "name": "godot-tools",
   "displayName": "Godot Tools",
   "displayName": "Godot Tools",
   "icon": "icon.png",
   "icon": "icon.png",
-  "description": "\"Tools for game development with godot game engine\"",
-  "version": "0.2.7",
+  "description": "Tools for game development with godot game engine",
+  "version": "0.2.8",
   "publisher": "geequlim",
   "publisher": "geequlim",
   "repository": "https://github.com/GodotExplorer/godot-tools",
   "repository": "https://github.com/GodotExplorer/godot-tools",
   "license": "MIT",
   "license": "MIT",

+ 81 - 69
src/tool_manager.ts

@@ -18,18 +18,24 @@ class ToolManager {
   private workspacesymbolprovider: GDScriptWorkspaceSymbolProvider = null;
   private workspacesymbolprovider: GDScriptWorkspaceSymbolProvider = null;
   private _disposable: vscode.Disposable;
   private _disposable: vscode.Disposable;
   private _context: vscode.ExtensionContext;
   private _context: vscode.ExtensionContext;
+  private _projectFile : string = "engine.cfg";
+  private _biuitinDocFile : string = "doc/classes.json";
+
 
 
   constructor(context: vscode.ExtensionContext) {
   constructor(context: vscode.ExtensionContext) {
     this._context = context;
     this._context = context;
     this.workspaceDir = vscode.workspace.rootPath;
     this.workspaceDir = vscode.workspace.rootPath;
-    if(vscode.workspace && this.workspaceDir) {
+    let completionDollar = false;
+    if (vscode.workspace.getConfiguration("GodotTools").get("godotVersion", 2.1) >= 3) {
+      this._projectFile = "project.godot";
+      this._biuitinDocFile = "doc/classes-3.0.json";
+      completionDollar = true;
+    }
+    if (vscode.workspace && this.workspaceDir) {
       vscode.workspace.registerTextDocumentContentProvider('godotdoc', new GDScriptDocumentContentProvider());
       vscode.workspace.registerTextDocumentContentProvider('godotdoc', new GDScriptDocumentContentProvider());
       this.workspaceDir = this.workspaceDir.replace(/\\/g, "/");
       this.workspaceDir = this.workspaceDir.replace(/\\/g, "/");
       this.loadWorkspaceSymbols();
       this.loadWorkspaceSymbols();
     }
     }
-    if(0) { // TODO: EditorServer validate
-      this.validate();
-    }
     this.loadClasses();
     this.loadClasses();
     // documentation symbol provider
     // documentation symbol provider
     this.symbolprovider = new GDScriptSymbolProvider();
     this.symbolprovider = new GDScriptSymbolProvider();
@@ -42,21 +48,17 @@ class ToolManager {
     // hover provider
     // hover provider
     vscode.languages.registerHoverProvider('gdscript', new GDScriptHoverProvider());
     vscode.languages.registerHoverProvider('gdscript', new GDScriptHoverProvider());
     // code completion provider
     // code completion provider
-    const completionDollar = (
-      vscode.workspace.getConfiguration("GodotTools").get("parseTextScene", false)
-      && (vscode.workspace.getConfiguration("GodotTools").get("godotVersion", 2.1) >= 3.0)
-    );
     if (completionDollar)
     if (completionDollar)
-        vscode.languages.registerCompletionItemProvider('gdscript', new GDScriptCompletionItemProvider(), '.', '"', "'", "$");
+      vscode.languages.registerCompletionItemProvider('gdscript', new GDScriptCompletionItemProvider(), '.', '"', "'", "$");
     else
     else
-        vscode.languages.registerCompletionItemProvider('gdscript', new GDScriptCompletionItemProvider(), '.', '"', "'");
+      vscode.languages.registerCompletionItemProvider('gdscript', new GDScriptCompletionItemProvider(), '.', '"', "'");
     // signature help provider
     // signature help provider
     vscode.languages.registerSignatureHelpProvider('gdscript', new GDScriptSignatureHelpProvider(), '(', ',');
     vscode.languages.registerSignatureHelpProvider('gdscript', new GDScriptSignatureHelpProvider(), '(', ',');
     // Commands
     // Commands
     this._disposable = vscode.Disposable.from(
     this._disposable = vscode.Disposable.from(
       vscode.commands.registerCommand('godot.updateWorkspaceSymbols', this.loadWorkspaceSymbols.bind(this)),
       vscode.commands.registerCommand('godot.updateWorkspaceSymbols', this.loadWorkspaceSymbols.bind(this)),
-      vscode.commands.registerCommand('godot.runWorkspace', ()=>{this.openWorkspaceWithEditor()}),
-      vscode.commands.registerCommand('godot.openWithEditor', ()=>{this.openWorkspaceWithEditor("-e")}),
+      vscode.commands.registerCommand('godot.runWorkspace', () => { this.openWorkspaceWithEditor() }),
+      vscode.commands.registerCommand('godot.openWithEditor', () => { this.openWorkspaceWithEditor("-e") }),
       vscode.commands.registerCommand('godot.runCurrentScene', this.runCurrentScene.bind(this)),
       vscode.commands.registerCommand('godot.runCurrentScene', this.runCurrentScene.bind(this)),
       vscode.commands.registerCommand('godot.provideInitialDebugConfigurations', this.getDefaultDebugConfig.bind(this))
       vscode.commands.registerCommand('godot.provideInitialDebugConfigurations', this.getDefaultDebugConfig.bind(this))
     );
     );
@@ -64,46 +66,60 @@ class ToolManager {
 
 
   validate() {
   validate() {
     const self = this;
     const self = this;
-    godotRequest({action: "editor", command: "projectdir"}).then((res: any)=>{
+    godotRequest({
+      action: "editor",
+      command: "projectdir"
+    }).then((res: any) => {
       let path = res.path;
       let path = res.path;
-      if(path && path.length> 0 && path.endsWith("/"))
-        path = path.substring(0, path.length-1)
-      if( path.toLowerCase() == self.workspaceDir.toLowerCase())
+      if (path && path.length > 0 && path.endsWith("/"))
+        path = path.substring(0, path.length - 1)
+      if (path.toLowerCase() == self.workspaceDir.toLowerCase())
         vscode.window.showInformationMessage("Connected to godot editor server");
         vscode.window.showInformationMessage("Connected to godot editor server");
       else {
       else {
         vscode.window.showWarningMessage("The opened project is not same with godot editor");
         vscode.window.showWarningMessage("The opened project is not same with godot editor");
       }
       }
-    }).catch(e=>{
-        vscode.window.showErrorMessage("Failed connect to godot editor server");
+    }).catch(e => {
+      vscode.window.showErrorMessage("Failed connect to godot editor server");
     });
     });
   }
   }
 
 
-  loadAllSymbols(): Promise<any> {
+  loadAllSymbols(): Promise < any > {
     const self = this;
     const self = this;
     return new Promise((resolve, reject) => {
     return new Promise((resolve, reject) => {
-      glob( self.workspaceDir +"/**/*.gd", (err, files)=>{
-        if(!err) {
+      glob(self.workspaceDir + "/**/*.gd", (err, files) => {
+        if (!err) {
           const symbols = {};
           const symbols = {};
-          for(let i=0; i< files.length; i++)
+          for (let i = 0; i < files.length; i++)
             symbols[config.normalizePath(files[i])] = config.loadSymbolsFromFile(files[i]);
             symbols[config.normalizePath(files[i])] = config.loadSymbolsFromFile(files[i]);
           // load autoloads from engin.cfg
           // load autoloads from engin.cfg
-          const engincfg = path.join(self.workspaceDir, "engine.cfg");
-          if(fs.existsSync(engincfg) && fs.statSync(engincfg).isFile()) {
+          const engincfg = path.join(self.workspaceDir, this._projectFile);
+          if (fs.existsSync(engincfg) && fs.statSync(engincfg).isFile()) {
             try {
             try {
-              const script = { constants: {}, functions: {}, variables: {}, signals: {}, classes: {}, base: "Object", native: "Object", constpathes: {}, documents: {}, constvalues: {}};
+              const script = {
+                constants: {},
+                functions: {},
+                variables: {},
+                signals: {},
+                classes: {},
+                base: "Object",
+                native: "Object",
+                constpathes: {},
+                documents: {},
+                constvalues: {}
+              };
               let content: string = fs.readFileSync(engincfg, 'utf-8');
               let content: string = fs.readFileSync(engincfg, 'utf-8');
-              if(content && content.indexOf("[autoload]") != -1) {
-                content = content.substring(content.indexOf("[autoload]")+"[autoload]".length, content.length);
+              if (content && content.indexOf("[autoload]") != -1) {
+                content = content.substring(content.indexOf("[autoload]") + "[autoload]".length, content.length);
                 content = content.substring(0, content.indexOf("["));
                 content = content.substring(0, content.indexOf("["));
                 const lines = content.split(/\r?\n/);
                 const lines = content.split(/\r?\n/);
-                lines.map((l)=>{
-                  if(l.indexOf("=") != 0) {
+                lines.map((l) => {
+                  if (l.indexOf("=") != 0) {
                     const name = l.substring(0, l.indexOf("="));
                     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);
+
+                    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 showgdpath = vscode.workspace.asRelativePath(gdpath);
-                    
+
                     let doc = "Auto loaded instance of " + `[${showgdpath}](${vscode.Uri.file(gdpath).toString()})`;
                     let doc = "Auto loaded instance of " + `[${showgdpath}](${vscode.Uri.file(gdpath).toString()})`;
                     doc = doc.replace(/"/g, " ");
                     doc = doc.replace(/"/g, " ");
 
 
@@ -120,18 +136,17 @@ class ToolManager {
             }
             }
           }
           }
           resolve(symbols);
           resolve(symbols);
-        }
-        else
+        } else
           reject(err);
           reject(err);
       });
       });
     });
     });
   }
   }
 
 
   private loadAllNodesInWorkspace() {
   private loadAllNodesInWorkspace() {
-    glob( this.workspaceDir +"/**/*.tscn", (err, files)=>{
-      if(!err) {
+    glob(this.workspaceDir + "/**/*.tscn", (err, files) => {
+      if (!err) {
         const symbols = {};
         const symbols = {};
-        for(let i=0; i< files.length; i++)
+        for (let i = 0; i < files.length; i++)
           config.loadScene(files[i]);
           config.loadScene(files[i]);
       }
       }
     });
     });
@@ -139,35 +154,34 @@ class ToolManager {
 
 
   private loadWorkspaceSymbols() {
   private loadWorkspaceSymbols() {
     if (vscode.workspace.getConfiguration("GodotTools").get("parseTextScene", false)) {
     if (vscode.workspace.getConfiguration("GodotTools").get("parseTextScene", false)) {
-        this.loadAllNodesInWorkspace();
+      this.loadAllNodesInWorkspace();
     }
     }
-    this.loadAllSymbols().then(symbols=>{
-        vscode.window.setStatusBarMessage("$(check) Workspace symbols", 5000);
-        config.setAllSymbols(symbols);
-    }).catch(e=>{
-        vscode.window.setStatusBarMessage("$(x) Workspace symbols", 5000);
+    this.loadAllSymbols().then(symbols => {
+      vscode.window.setStatusBarMessage("$(check) Workspace symbols", 5000);
+      config.setAllSymbols(symbols);
+    }).catch(e => {
+      vscode.window.setStatusBarMessage("$(x) Workspace symbols", 5000);
     });
     });
   }
   }
 
 
-  private openWorkspaceWithEditor(params="") {
+  private openWorkspaceWithEditor(params = "") {
     let workspaceValid = false
     let workspaceValid = false
-    if(this.workspaceDir) {
-      let cfg = path.join(this.workspaceDir, "engine.cfg");
-      if( fs.existsSync(cfg) && fs.statSync(cfg).isFile())
+    if (this.workspaceDir) {
+    let cfg = path.join(this.workspaceDir, this._projectFile);
+      if (fs.existsSync(cfg) && fs.statSync(cfg).isFile())
         workspaceValid = true;
         workspaceValid = true;
     }
     }
-    if(workspaceValid)
+    if (workspaceValid)
       this.runEditor(`-path ${this.workspaceDir} ${params}`);
       this.runEditor(`-path ${this.workspaceDir} ${params}`);
     else
     else
       vscode.window.showErrorMessage("Current workspace is not a godot project");
       vscode.window.showErrorMessage("Current workspace is not a godot project");
   }
   }
 
 
-  private runEditor(params="") {
+  private runEditor(params = "") {
     const editorPath = vscode.workspace.getConfiguration("GodotTools").get("editorPath", "")
     const editorPath = vscode.workspace.getConfiguration("GodotTools").get("editorPath", "")
-    if(!fs.existsSync(editorPath) || !fs.statSync(editorPath).isFile()) {
+    if (!fs.existsSync(editorPath) || !fs.statSync(editorPath).isFile()) {
       vscode.window.showErrorMessage("Invalid editor path to run the project");
       vscode.window.showErrorMessage("Invalid editor path to run the project");
-    }
-    else {
+    } else {
       let terminal = vscode.window.createTerminal("Godot");
       let terminal = vscode.window.createTerminal("Godot");
       let cmmand = `${editorPath} ${params}`;
       let cmmand = `${editorPath} ${params}`;
       terminal.sendText(cmmand, true);
       terminal.sendText(cmmand, true);
@@ -177,28 +191,27 @@ class ToolManager {
 
 
   private runCurrentScene() {
   private runCurrentScene() {
     let scenePath = null
     let scenePath = null
-    if(vscode.window.activeTextEditor)
+    if (vscode.window.activeTextEditor)
       scenePath = vscode.workspace.asRelativePath(vscode.window.activeTextEditor.document.uri);
       scenePath = vscode.workspace.asRelativePath(vscode.window.activeTextEditor.document.uri);
-    if(scenePath.endsWith(".gd")) {
+    if (scenePath.endsWith(".gd")) {
       const scriptPath = scenePath;
       const scriptPath = scenePath;
       scenePath = config.scriptSceneMap[config.normalizePath(scenePath)];
       scenePath = config.scriptSceneMap[config.normalizePath(scenePath)];
-      if(!scenePath && vscode.window.activeTextEditor.document.getText().match(/\s+extends SceneTree\s/g))
+      if (!scenePath && vscode.window.activeTextEditor.document.getText().match(/\s+extends SceneTree\s/g))
         scenePath = scriptPath;
         scenePath = scriptPath;
     }
     }
-    if(scenePath) {
-      if(scenePath.endsWith(".gd"))
+    if (scenePath) {
+      if (scenePath.endsWith(".gd"))
         scenePath = ` -s res://${scenePath} `;
         scenePath = ` -s res://${scenePath} `;
       else
       else
         scenePath = ` res://${scenePath} `;
         scenePath = ` res://${scenePath} `;
       this.openWorkspaceWithEditor(scenePath);
       this.openWorkspaceWithEditor(scenePath);
-    }
-    else
+    } else
       vscode.window.showErrorMessage("Current document is not a scene file");
       vscode.window.showErrorMessage("Current document is not a scene file");
   }
   }
 
 
   private getDefaultDebugConfig() {
   private getDefaultDebugConfig() {
     const editorPath = vscode.workspace.getConfiguration("GodotTools").get("editorPath", "")
     const editorPath = vscode.workspace.getConfiguration("GodotTools").get("editorPath", "")
-    if(this.workspaceDir) {
+    if (this.workspaceDir) {
       const config = {
       const config = {
         version: '0.2.3',
         version: '0.2.3',
         configurations: [{
         configurations: [{
@@ -212,20 +225,19 @@ class ToolManager {
         }]
         }]
       }
       }
       return JSON.stringify(config, null, '\t');
       return JSON.stringify(config, null, '\t');
-    }
-    else {
+    } else {
       vscode.window.showErrorMessage("Cannot create launch without godot project workspace");
       vscode.window.showErrorMessage("Cannot create launch without godot project workspace");
       return ""
       return ""
     }
     }
   }
   }
 
 
   loadClasses() {
   loadClasses() {
-    let done :boolean = false;
-    if(this.workspaceDir)
+    let done: boolean = false;
+    if (this.workspaceDir)
       done = config.loadClasses(path.join(this.workspaceDir, ".vscode", "classes.json"));
       done = config.loadClasses(path.join(this.workspaceDir, ".vscode", "classes.json"));
-    if(!done)
-      done = config.loadClasses(path.join(this._context.extensionPath, "doc", "classes.json"));
-    if(!done)
+    if (!done)
+      done = config.loadClasses(path.join(this._context.extensionPath, this._biuitinDocFile));
+    if (!done)
       vscode.window.showErrorMessage("Load GDScript documentations failed");
       vscode.window.showErrorMessage("Load GDScript documentations failed");
   }
   }
 
 
@@ -234,4 +246,4 @@ class ToolManager {
   }
   }
 };
 };
 
 
-export default ToolManager;
+export default ToolManager;

部分文件因文件數量過多而無法顯示