All posts by Klever Loza Vega

About Klever Loza Vega

I am a computer programming student at Seneca College. I'll be starting my first coop term at Seneca's Centre for Development of Open Technology (CDOT) in January 2015.

The Beginning of Something Awesome

New Task

Having completed our Brackets HTMLHinter extension, our team has moved on to a new task. The task involves stripping out the default editor from Thimble and replacing it with Brackets. Doing so gives us a lot more flexibility and enhancements than what Thimble currently provides.

Benefits

For instance, we would have all the enhancements that Brackets currently has: inline colour preview, inline colour picker, inline image preview, element highlight, among other features. Adding a new feature would be easy as it can be done via an extension. Our goal is to modify the least amount of Brackets source code possible. This way, if there is an update on Brackets, we can pull the latest changes and greatly reduce the risk of conflicts. If Brackets introduces a new feature, we would get it for free. Another benefit is the fact that there will be no need to download or install anything, everything would just work on the browser. In fact, it would work on any device that has a browser; including tablets and mobile devices.

Work So Far

The first part of the project is called Bramble and it’s a branch of the original Brackets code. Essentially, Bramble is a stripped down version of Brackets. One of the first things we did was to strip most of the UI from Brackets and leave just the editor. We created an extension (hideUI) to do this, again, to keep the original code intact. We also moved from using a web socket connection to using a post message one. We made two extensions (thimbleProxy and brackets-browser-livedev) that use post message connections. There was also back-end work done to have Bramble talk to Thimble and vice versa.

Work In Progress

An ongoing task is to try and make the project as small as possible. That way it would load faster and provide a smoother experience. Especially for people with slower internet connections. Another ‘work in progress’ is getting multiple files to preview properly. Currently, one HTML file previews properly. However, when more files are introduced some bugs are exposed. This is especially true with CSS and JavaScript files.

Moving Forward

Our team successfully replaced the default editor in Thimble for our Bramble project. The product is called Super Thimble for the time being. It’s currently being tested on by our team. We hope to have Mozilla pick this up and possibly replace the current Thimble in the future.

Extension Update

During week 3 our team worked on finishing up our Brackets extension. It is now called HTMLHinter. We improved from our previous design by implementing the following features:

  • The error message now only shows if the button or the line number with the error is clicked
  • The error message now has styling
  • When an error exists, the mouse cursor changes to ‘pointer‘ type when over the gutter
  • When an error exists and the mouse is over the gutter, a message appears telling the user to click the button for more information

Screen Shot Final Brackets Extension

Overall, I learned a lot working on my first project at CDOT. For the time being, we are done working on this extension and are moving on to other Bracket projects.

Week 2

Week 2

Throughout my second week of working at CDOT I continued to work on the Brackets extension project. I also became more familiar with Git and GitHub. More importantly, I learned a proper way of working, collaboratively, on GitHub.

Git and GitHub

Git is a distributed version control system software. Among other features, it helps keep track of our work and revert back to previous states, if needed, in a snap. GitHub is a Git repository hosting service. It allows us to work collaboratively on a project with people all around the world. The official Git documentation is a great place to start learning about Git. GitHub also has a guide on how to setup and get stared with GitHub.

Issues

As we continued to work on the Brackets project, my colleagues and I realized that we weren’t working as efficiently as we could. We were all working off one master repository, pushing and pulling constantly and fixing many things at once. This made it difficult to tell what had been changed and who made that change. This is where issues and bug tracking comes in handy.

We were introduced to the Issues feature on GitHub. Essentially, it keeps track of tasks to be done and/or bugs to be fixed in a project. Once created, they can be assigned to people and they can work on it. Once the task is completed, the person assigned would initiate pull request, the code would (hopefully) be approved, and that issue would be closed. This keeps the work process clean and tidy.

Workflow

Unfortunately, we didn’t follow this procedure from the beginning. Our code started to become quite messy. Thankfully, apart from the issues feature, our colleague also suggested we follow a proper workflow plan. The plan he suggested goes like this:

  1. If working off somebody else’s repository – make a fork to your account and clone it to your desktop.
  2. Make another branch and work from there. The point is to keep your master branch clean and in sync with the upstream master branch. It is suggested you make a different branch for each issue/task you’re working on.
  3. Once you’ve made changes and committed, push the changes to your branch on GitHub.
  4. If you navigate to your branch on GitHub it will most likely prompt you to do a pull request automatically. If not, you can always do one manually.
  5. Once the pull request is sent it has to be approved by the owner of the master branch you forked from.

You would follow these steps over as necessary. Of course the preceding steps assume you’re working in a perfect world without any problems. However, that’s not always the case as we found out this week.

Rebasing

When we were trying to do a pull request to the upstream master branch we ran into a problem. The problem had to do with the commit history. The solution was to do a rebase. The point of this rebase was to change the order of commits by altering the commit history. Warning! Messing with the commit history can cause problems later on so make sure you know what you’re doing. It’s best to read the documentation and decide which is the best solution for your situation. These are the steps we took to solve our problem:

  1. Make sure your master branch is synchronized with the upstream master branch.
  2. Switch over to the branch that was giving you problems, the command is:
    git checkout your-other-branch
  3. Run
    git rebase -i master

    Here you’re rebasing your other branch with your master branch.

  4. You will then be presented with a screen containing all the commits from your other branch that are not in your master branch. Here, follow the prompt and decide which commit you want to pick and which one(s) you want rename, squash, etc.
  5. If it fails – like it happened to us – you most likely have a merge conflict. Fix this conflict and type
     git rebase --continue

    Hopefully it succeeds this time.

From here you can continue to do a pull request as you normally would.

Project

This week we continued to work on our extension project. We now have a red button beside the line number where an error was found. Clicking on this button displays the error. Clicking on it again hides the error. Fixing the error removes both the button and the error message. Our extension now highlights the wrong HTML code rather than underlining it. Lastly, the syntax is now checked when the document is changed (i.e. code is added, deleted, copied or pasted) as opposed to when a key is pressed, as it did before. This makes the extension more efficient. For instance, the syntax won’t be checked when the cursor keys are pressed like it did before.

Sample week 2
Sample showing the red button beside the line number, the highlighted text and the error.

And so it begins…

Week 1
I’ve just finished my first week at CDOT and so far it’s been great. My two colleges and I were given our first task for the term: make a Brackets extension that will check the syntax of HTML entered in the editor and display any errors, if any. This is similar to what Thimble already does.

Thimble

Thimble is text editor, created by Mozilla, where you can write, edit, and preview HTML code all within a browser. It also has the capability to publish and share webpages you’ve created in it. Thimble automatically highlights any HTML that is written wrong or is incomplete. It does this using an HTML parser called slowparse. Our project involves trying to bring over that functionality to brackets.

Brackets

Brackets is an open source text editor built by Adobe. It’s essentially a web application as it’s written in HTML, CSS, and JavaScript. Brackets has a neat feature that allows you to Live Preview your code on your browser as you write it. There’s no need to refresh the browser every time you make a change to your code.

Hacking Brackets and Extensions

Since Brackets is open source, we have many advantages. For instance, we not only have access to Brackets’ source code but we can also make changes to it. Brackets also supports extensions. There are many extensions that are already made. If there isn’t an extension that suits your needs, you can just create one yourself. Brackets makes it really easy to make your own extension. There are many other guides out there that help with making your own extensions. However, one guide that has been very useful to me has been Writing Brackets extension – Part 1 and Part 2. Part 2 was particularly helpful as it deals with tracking events in Brackets; something that I need for the project I’m working on.

The Project

My part of the project deals with getting errors underlined and tracking changes made to the document via keyboard events. So far, I’ve found a way to both underline incorrect text in red and remove it. I also have the keyboard event working. That is, the extension checks, using slowparse, the document syntax every time a key is pressed. Since Brackets can edit different file types, I’ve added code to check syntax only on documents that have the .html extension. So, if a JavaScript file is loaded on Brackets it won’t try and check the syntax for that file.

Screen Shot 2015-01-13 at 10.30.41 PM

Problems

Early on I found myself stuck trying to understand how the Brackets API and CodeMirror work – CodeMirror is the text editor that Brackets uses. There was a lot of documentation to read and it was difficult to figure out what actually applied to my problem and what didn’t. I was having problems getting the text to underline. There was a lot of trial and error with different functions and configurations until finally, largely thanks to a longer-serving colleague, it worked!

Here’s the code that underlines text that worked for me:

/*jslint vars: true, plusplus: true, devel: true, nomen: true,
  regexp: true, indent: 4, maxerr: 50 */
/*global define, CodeMirror, brackets, less, $, document */

define(function (require, exports, module) {
  "use strict";

  var EditorManager = brackets.getModule("editor/EditorManager"),
     ExtensionUtils = brackets.getModule("utils/ExtensionUtils");

  ExtensionUtils.loadStyleSheet(module, "main.less");

  //Function that underlines the given lines
  function markErrors(lineStart, lineEnd, charStart, charEnd) {
     var editor = EditorManager.getFocusedEditor();

  var marked = editor._codeMirror.markText({line: lineStart, ch: charStart},
               {line: lineEnd, ch: charEnd}, {className: "error-highlight"});

  }
});

What I Learned

Ask for help! I was so caught up trying to solve my problem that I didn’t realize all the time that had passed. Time that could have been put towards other things had I asked for help earlier on.
The way we solved my text underlining problem was by using the Chrome Developer Tools integrated in Brackets – you can get there by clicking on the Debug tab and clicking on Show Developer Tools. I learned a couple of things using the developer tools:

  • First you can use it to debug your code by putting the console.log() function in your code and seeing the result on the console. This can be useful to track the order that your code is executed and if it goes into a certain function or not.
  • Secondly, if you console.log an object you can actually see, by clicking on a small tab in the console, all the attributes and functions associated with that object.
  • Lastly, just because the console shows an error doesn’t, necessarily, mean that your code won’t continue to run! The error could be occurring at and earlier point than, say, the function you’re working on. There were often times when I saw the error and spent some time trying to fix it, only to find out it had nothing to do with the function I was working on! The error was completely unrelated to what I was working on.

Apart from this, I’ve also become more familiar with Git and GitHub. More importantly, I’ve learned the importance of proper planning and having a good work flow – more on this next week.

Next Week

My colleagues and I hope to finish the extension by the end of week 2. We’re also hoping to have a GUI that displays the type of error found in the code, similar to Thimble.