Explorar el Código

Additional fixes:
- Unload project based plugins and reload them when a project is opened. This is done so any cached changes are flushed.
- Update duktape.d.ts to expose the “modLoaded” array
- fix TS compiler output so it displays on both dark theme and light theme
- fix issue where navigating to a line number wasn’t always working

Shaddock Heath hace 8 años
padre
commit
e9ee0ec703

+ 6 - 3
Script/AtomicEditor/hostExtensions/coreExtensions/ProjectBasedExtensionLoader.ts

@@ -112,9 +112,12 @@ export default class ProjectBasedExtensionLoader implements Editor.HostExtension
                         extensionPath = extensionPath.substring(0, extensionPath.length - 3);
 
                         console.log(`Detected project extension at: ${extensionPath} `);
-                        // Note: duktape does not yet support unloading modules,
-                        // but will return the same object when passed a path the second time.
-                        let resourceServiceModule = require(ProjectBasedExtensionLoader.duktapeRequirePrefix + extensionPath);
+                        const moduleName = ProjectBasedExtensionLoader.duktapeRequirePrefix + extensionPath;
+
+                        // Make sure that we delete the module from the module cache first so if there are any
+                        // changes, they get reflected
+                        delete Duktape.modLoaded[moduleName];
+                        let resourceServiceModule = require(moduleName);
 
                         // Handle situation where the service is either exposed by a typescript default export
                         // or as the module.export (depends on if it is being written in typescript, javascript, es6, etc.)

+ 16 - 4
Script/AtomicEditor/hostExtensions/languageExtensions/TypescriptLanguageExtension.ts

@@ -103,7 +103,7 @@ export default class TypescriptLanguageExtension implements Editor.HostExtension
         Atomic.fileSystem.scanDir(ToolCore.toolSystem.project.resourcePath, "*.js", Atomic.SCAN_FILES, true).forEach(filename => {
             let fn = Atomic.addTrailingSlash(ToolCore.toolSystem.project.resourcePath) + filename;
             // if the .js file matches up to a .ts file already loaded, then skip it
-            let tsfn = filename.replace("\.js$", ".ts");
+            let tsfn = filename.replace(/\.js$/, ".ts");
             if (projectFiles.indexOf(tsfn) == -1) {
                 hasJsFiles = true;
                 projectFiles.push(fn);
@@ -453,6 +453,17 @@ export default class TypescriptLanguageExtension implements Editor.HostExtension
         let links = {};
         let linkId = 0;
 
+        // choose different colors based upon if we are in a dark theme or light theme
+        let successColor = "#00ff00";
+        let errorColor = "#e3e02b";
+        let infoColor = "#888888";
+        const currentSkin = this.serviceRegistry.projectServices.getApplicationPreference("uiData", "skinPath", "");
+        if (currentSkin.indexOf("light") != -1) {
+            successColor = "#006600";
+            errorColor = "#7f5f04";
+            infoColor = "#333333";
+        }
+
         let messageArray = results.annotations.filter(result => {
             // If we are compiling the lib.d.ts or some other built-in library and it was successful, then
             // we really don't need to display that result since it's just noise.  Only display it if it fails
@@ -464,11 +475,11 @@ export default class TypescriptLanguageExtension implements Editor.HostExtension
 
             // Clean up the path for display
             let file = result.file.replace(ToolCore.toolSystem.project.projectPath, "");
-            let message = `<color #888888>${file}: </color>`;
+            let message = `<color ${infoColor}>${file}: </color>`;
             if (result.type == "success") {
-                message += `<color #00ff00>${result.text}</color>`;
+                message += `<color ${successColor}>${result.text}</color>`;
             } else {
-                message += `<color #e3e02b>${result.text} at line ${result.row + 1} col ${result.column}</color> <widget TBSkinImage: skin: MagnifierBitmap, text:"..." id: link${linkId}>`;
+                message += `<color ${errorColor}>${result.text} at line ${result.row + 1} col ${result.column}</color> <widget TBSkinImage: skin: MagnifierBitmap, text:"..." id: link${linkId}>`;
                 links["link" + linkId] = result;
                 linkId++;
             }
@@ -495,6 +506,7 @@ export default class TypescriptLanguageExtension implements Editor.HostExtension
                 } else {
                     let diag = links[ev.target.id];
                     if (diag) {
+                        console.log(`Load editor: ${diag.file}:${diag.row + 1}`);
                         this.serviceRegistry.uiServices.loadResourceEditor(diag.file, diag.row + 1);
                     }
                 }

+ 23 - 8
Script/AtomicEditor/ui/frames/ResourceFrame.ts

@@ -88,7 +88,7 @@ class ResourceFrame extends ScriptWidget {
 
         if (this.editors[path]) {
 
-            this.navigateToResource(path);
+            this.navigateToResource(path, ev.lineNumber);
 
             return;
 
@@ -117,7 +117,10 @@ class ResourceFrame extends ScriptWidget {
 
         var editor = this.editors[fullpath];
 
-        if (this.currentResourceEditor == editor) return;
+        if (this.currentResourceEditor == editor) {
+            this.setCursorPositionInEditor(editor, lineNumber, tokenPos);
+            return;
+        }
 
         var root = this.tabcontainer.contentRoot;
 
@@ -135,18 +138,30 @@ class ResourceFrame extends ScriptWidget {
 
             editor.setFocus();
 
-            // this cast could be better
-            var ext = Atomic.getExtension(fullpath);
+            this.setCursorPositionInEditor(editor, lineNumber, tokenPos);
+        }
+
+    }
 
-            if (ext == ".js" && lineNumber != -1) {
+    /**
+     * 
+     * Set the cursor to the correct line number in the editor
+     * @param {Editor.ResourceEditor} editor
+     * @param {any} [lineNumber=-1]
+     * @param {any} [tokenPos=-1]
+     * 
+     * @memberOf ResourceFrame
+     */
+    setCursorPositionInEditor(editor: Editor.ResourceEditor, lineNumber = -1, tokenPos = -1) {
+        if (editor instanceof Editor.JSResourceEditor) {
+            if (lineNumber != -1) {
                 (<Editor.JSResourceEditor>editor).gotoLineNumber(lineNumber);
             }
-            else if (ext == ".js" && tokenPos != -1) {
+
+            if (tokenPos != -1) {
                 (<Editor.JSResourceEditor>editor).gotoTokenPos(tokenPos);
             }
-
         }
-
     }
 
     handleCloseResource(ev: Editor.EditorResourceCloseEvent) {

+ 7 - 0
Script/TypeScript/duktape.d.ts

@@ -11,6 +11,13 @@ declare var console: Console;
 declare function require(filename: string): any;
 
 declare interface DuktapeModule {
+    /**
+     * List of modules that have been loaded via the "require" statement
+     * 
+     * @type {string[]}
+     * @memberOf DuktapeModule
+     */
+    modLoaded: string[];
     modSearch(id: string, require, exports, module);
 }