Posts

Adding A New HTML Feature!

In order to support HTML files we created a new htmlObject class that implements the "IPreviewObject" interface. For the local HTML files, we decided to allow the option to open to resoure (code) file in a new tab. To do so we created a new command, very much similar to the text and css command: This command is called in the "getLocalHtmlMarkdownString" function. (more explenation in this tutorial) For the external html path we decided to support 3 previews: 1. open in external browser 2. open in "internal" browser (webview panel)- we used the  commandUriNewTab command we already made for previewing images in a new tab in order to view the rendered html content as a web page. The "getHtmlContent" methos in this object looks like this: 3. open resource html file (the html code)- we created a new command which calls the "getHtmlResource" function. This function sends a GET request in order to get the url resource. When the response arrive...

Testing

Image
We started looking and trying to figure out how tests work and how we should incorporate them into our project. First, we searched in vscode extension API a little imformation. We have seen that once you create a new plugin, it contains a folder of tests that you can change according to specific needs ( https://code.visualstudio.com/api/working-with-extensions/testing-extension ). In addition, VSCode testing files work with mocha, however after a brief review and recommendations we received from experienced people, we preferred to try and work with jest. We started by trying to write a test for one feature, hoping to succeed and move on from there. For starters, we created a test file for cssObject named cssObject.spec.ts. We wrote a first test to check the integrity of the object's constructor. To do this, we created an instance of the object that activates the function within the constructor (validationObject), and with jest.spyOn function we kind of "sp...

Little Bug Fix

Image
After the big refactoring and redesigning we made, there are a few more things we have left to do: 1. Currently, once the cursor is on a certain URL, the hover panel will change accordingly. So, if we hover over URLs that the cursor is not on them we will still be presented with the last hover panel that was created. That is a bug and we need to fix it. 2. We need to make a unit testing (we dont know how to do that, so we need to learn a bit more) 3. Try and use other VSCODE extensions to support previewing PDFs and HTML (the web page, not the HTML file). To fix (1) we added a new condition to the "push" call (in the activate finction, in extension.ts). We check if the line the cursor is on is the same as the line we hover over. If so, call the "updateHoverPanel" function (which makes a markdown string for the hover panel according to the current URL format). If not, update the hover panel content (the markdown string) to an empty string. W...

Turorial- How to add a new feature

Image
In this Post we will explain how to make and integrate a new feature to our extension. ** ALL VARIABLES EXPLANATIONS ARE AT THE BOTTOM Let's say we want to support text files. The first thing we will need to do is to create a new file- we name it "TextObject". We then import the "utils" and "IPreviewObject" files. We create a new (export deafult) class caled "TextObject" which implements IPreviewObject. Now, we need to implement the interface's 3 functions: 1. validatePotentialUrl- we check if the current potential URL has a ".txt" extension. if so- we update the current URL to the potential URL, and the currentPreviewObject to a textObject. 2. GetHtmlContent- returns an empty string because we dont need a webview panel for this feature. 3. makeMrkdownString- this function will need to create a string that will allow to open a text file in a new tab when clicking on a certain button. To do so, w...

Refactoring and Dividing to files

Image
  Currently, after extracting the current line the validation functions are executed one after the other. Like so:    It means that if someone were to add another feature he will need to add his validation function to this call sequence of validation functions. This may lead to long sequence of function calls and also requires him to access our code directly. So the goal is to allow other people to add new features to our extension in an easy and reuseable way. We decided to make a new object (class) that holds a list of functions will be invoked one by one without the object knowing anything about the functions besides there signature. If someone wants to add their validation function to the sequence all he needs is to know this new validation object. This new object is named "validationObject" and it has 3 functions: 1. invokeValidationFunctions - this function goes over the functions in the list (" validateFunctionArray") and execute each one. 2. addValidateFunct...

Publishing First Beta & Refactoring The Code

Image
We figured it was time to publish a first beta of our extension to VSCODE marketplace. We made some little adjustments like renaming some variables, for more readable code, and fixed a few major bugs, and then we published it using this tutorial .  You can find our extension on this link . *A big bug we had was that the last hover panel continude to show when hovering on defferent lines that are not a URL. Our problem was fixed by updating the current URL variable to UNDEFINED and the markdown string to an empty string, like so: Now that we published our first working extension, we wanted to focus more on the code and the design. Firstly, we decided it would be smarter to extract the relevant line and check what is it's format rather then what we made so far- which is to send the whole document to each extraction function. We created a new function called "extractCurrentLine" which does the following: 1. The function receives the document text ...