Browse Source

Work on formatting compile results by coloring the error messages as well as displaying those files that successfully compiled

Shaddock Heath 9 years ago
parent
commit
dadd8e9233

+ 19 - 6
Script/AtomicEditor/hostExtensions/languageExtensions/TypscriptLanguageExtension.ts

@@ -241,11 +241,7 @@ export default class TypescriptLanguageExtension implements Editor.HostExtension
                     this.rebuildMenu();
                     return true;
                 case "compileproject":
-                    const editor = this.serviceRegistry.uiServices.getCurrentResourceEditor();
-                    if (editor && editor.typeName == "JSResourceEditor") {
-                        const jsEditor = <Editor.JSResourceEditor>editor;
-                        jsEditor.webView.webClient.executeJavaScript(`TypeScript_DoFullCompile();`);
-                    }
+                    this.doFullCompile();
                     return true;
             }
         }
@@ -264,13 +260,30 @@ export default class TypescriptLanguageExtension implements Editor.HostExtension
         }
     }
 
+    /**
+     * Perform a full compile of the TypeScript
+     */
+    doFullCompile() {
+        const editor = this.serviceRegistry.uiServices.getCurrentResourceEditor();
+        if (editor && editor.typeName == "JSResourceEditor") {
+            const jsEditor = <Editor.JSResourceEditor>editor;
+            jsEditor.webView.webClient.executeJavaScript(`TypeScript_DoFullCompile();`);
+        }
+    }
+
     /**
      * Display the results of the compilation step
      * @param  {any[]} annotations
      */
     displayCompileResults(annotations: any[]) {
         let messageArray = annotations.map((result) => {
-            return `${result.text} at line ${result.row} col ${result.column} in ${result.file}`;
+            let message = `<color #888888>${result.file}: </color>`;
+            if (result.type == "success") {
+                message += `<color #00ff00>${result.text}</color>`;
+            } else {
+                message += `<color #e3e02b>${result.text} at line ${result.row} col ${result.column}</color>`;
+            }
+            return message;
         });
 
         if (messageArray.length == 0) {

+ 12 - 11
Script/AtomicWebViewEditor/clientExtensions/languageExtensions/typescript/workerprocess/TypescriptLanguageService.ts

@@ -241,10 +241,10 @@ export class TypescriptLanguageService {
      * Compile the provided file to javascript with full type checking etc
      * @param  {string}  a list of file names to compile
      * @param  {ts.CompilerOptions} options for the compiler
+     * @param  {function} optional callback which will be called for every file compiled and will provide any errors
      */
-    compile(files: string[], options?: ts.CompilerOptions): ts.Diagnostic[] {
+    compile(files: string[], options?: ts.CompilerOptions, progress?: (filename:string, errors: ts.Diagnostic[]) => void): ts.Diagnostic[] {
         let start = new Date().getTime();
-
         options = options || this.compilerOptions;
 
         //Make sure we have these files in the project
@@ -254,18 +254,19 @@ export class TypescriptLanguageService {
 
         let errors: ts.Diagnostic[] = [];
 
+        // if we have a 0 length for files, let's compile all files
         if (files.length == 0) {
-            // We haven't passed any files in, so let's compile them all
-            this.projectFiles.forEach(filename => {
-                errors = errors.concat(this.compileFile(filename));
-            });
-        } else {
-            // Only compile the files that are newly edited
-            files.forEach(filename => {
-                errors = errors.concat(this.compileFile(filename));
-            });
+            files = this.projectFiles;
         }
 
+        files.forEach(filename => {
+            let currentErrors = this.compileFile(filename);
+            errors = errors.concat(currentErrors);
+            if (progress) {
+                progress(filename, currentErrors);
+            }
+        });
+
         console.log(`${this.name}: Compiling complete after ${new Date().getTime() - start} ms`);
         return errors;
     }

+ 23 - 12
Script/AtomicWebViewEditor/clientExtensions/languageExtensions/typescript/workerprocess/TypescriptLanguageServiceWebWorker.ts

@@ -399,18 +399,29 @@ export default class TypescriptLanguageServiceWebWorker {
      */
     doFullCompile(port: MessagePort) {
         this.fs.setCommunicationPort(port);
-        let errors = this.languageService.compile([]);
-
-        let results = errors.map(diagnostic => {
-            let lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
-            let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
-            return {
-                file: diagnostic.file.fileName,
-                row: lineChar.line,
-                column: lineChar.character,
-                text: message,
-                type: diagnostic.category == 1 ? "error" : "warning"
-            };
+        let results = [];
+        this.languageService.compile([], this.languageService.compilerOptions, (filename, errors) => {
+            if (errors.length > 0) {
+                results = results.concat(errors.map(diagnostic => {
+                    let lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
+                    let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
+                    return {
+                        file: diagnostic.file.fileName,
+                        row: lineChar.line,
+                        column: lineChar.character,
+                        text: message,
+                        type: diagnostic.category == 1 ? "error" : "warning"
+                    };
+                }));
+            } else {
+                results.push({
+                    file: filename,
+                    row: 0,
+                    column: 0,
+                    text: "Success",
+                    type: "success"
+                });
+            }
         });
 
         let message: WorkerProcessTypes.FullCompileResultsMessageData = {